Skip to content

Commit 633aa7e

Browse files
committed
Merge tag 'drm-misc-next-2019-10-31' of git://anongit.freedesktop.org/drm/drm-misc into drm-next
drm-misc-next for 5.5: UAPI Changes: -dma-buf: Introduce and revert dma-buf heap (Andrew/John/Sean) Cross-subsystem Changes: - None Core Changes: -dma-buf: add dynamic mapping to allow exporters to choose dma_resv lock state on mmap/munmap (Christian) -vram: add prepare/cleanup fb helpers to vram helpers (Thomas) -ttm: always keep bo's on the lru + ttm cleanups (Christian) -sched: allow a free_job routine to sleep (Steven) -fb_helper: remove unused drm_fb_helper_defio_init() (Thomas) Driver Changes: -bochs/hibmc/vboxvideo: Use new vram helpers for prepare/cleanup fb (Thomas) -amdgpu: Implement dma-buf import/export without drm helpers (Christian) -panfrost: Simplify devfreq integration in driver (Steven) Cc: Christian König <[email protected]> Cc: Thomas Zimmermann <[email protected]> Cc: Steven Price <[email protected]> Cc: Andrew F. Davis <[email protected]> Cc: John Stultz <[email protected]> Cc: Sean Paul <[email protected]> Signed-off-by: Dave Airlie <[email protected]> From: Sean Paul <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/20191031193015.GA243509@art_vandelay
2 parents 57c2af7 + fae7d7d commit 633aa7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+709
-733
lines changed

Documentation/driver-api/dma-buf.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ Kernel Functions and Structures Reference
118118
Reservation Objects
119119
-------------------
120120

121-
.. kernel-doc:: drivers/dma-buf/reservation.c
121+
.. kernel-doc:: drivers/dma-buf/dma-resv.c
122122
:doc: Reservation Object Overview
123123

124-
.. kernel-doc:: drivers/dma-buf/reservation.c
124+
.. kernel-doc:: drivers/dma-buf/dma-resv.c
125125
:export:
126126

127-
.. kernel-doc:: include/linux/reservation.h
127+
.. kernel-doc:: include/linux/dma-resv.h
128128
:internal:
129129

130130
DMA Fences

Documentation/gpu/todo.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ Generic fbdev defio support
206206
---------------------------
207207

208208
The defio support code in the fbdev core has some very specific requirements,
209-
which means drivers need to have a special framebuffer for fbdev. Which prevents
210-
us from using the generic fbdev emulation code everywhere. The main issue is
211-
that it uses some fields in struct page itself, which breaks shmem gem objects
212-
(and other things).
209+
which means drivers need to have a special framebuffer for fbdev. The main
210+
issue is that it uses some fields in struct page itself, which breaks shmem
211+
gem objects (and other things). To support defio, affected drivers require
212+
the use of a shadow buffer, which may add CPU and memory overhead.
213213

214214
Possible solution would be to write our own defio mmap code in the drm fbdev
215215
emulation. It would need to fully wrap the existing mmap ops, forwarding

drivers/dma-buf/dma-buf.c

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen)
4545
size_t ret = 0;
4646

4747
dmabuf = dentry->d_fsdata;
48-
mutex_lock(&dmabuf->lock);
48+
dma_resv_lock(dmabuf->resv, NULL);
4949
if (dmabuf->name)
5050
ret = strlcpy(name, dmabuf->name, DMA_BUF_NAME_LEN);
51-
mutex_unlock(&dmabuf->lock);
51+
dma_resv_unlock(dmabuf->resv);
5252

5353
return dynamic_dname(dentry, buffer, buflen, "/%s:%s",
5454
dentry->d_name.name, ret > 0 ? name : "");
@@ -334,7 +334,7 @@ static long dma_buf_set_name(struct dma_buf *dmabuf, const char __user *buf)
334334
if (IS_ERR(name))
335335
return PTR_ERR(name);
336336

337-
mutex_lock(&dmabuf->lock);
337+
dma_resv_lock(dmabuf->resv, NULL);
338338
if (!list_empty(&dmabuf->attachments)) {
339339
ret = -EBUSY;
340340
kfree(name);
@@ -344,7 +344,7 @@ static long dma_buf_set_name(struct dma_buf *dmabuf, const char __user *buf)
344344
dmabuf->name = name;
345345

346346
out_unlock:
347-
mutex_unlock(&dmabuf->lock);
347+
dma_resv_unlock(dmabuf->resv);
348348
return ret;
349349
}
350350

@@ -403,10 +403,10 @@ static void dma_buf_show_fdinfo(struct seq_file *m, struct file *file)
403403
/* Don't count the temporary reference taken inside procfs seq_show */
404404
seq_printf(m, "count:\t%ld\n", file_count(dmabuf->file) - 1);
405405
seq_printf(m, "exp_name:\t%s\n", dmabuf->exp_name);
406-
mutex_lock(&dmabuf->lock);
406+
dma_resv_lock(dmabuf->resv, NULL);
407407
if (dmabuf->name)
408408
seq_printf(m, "name:\t%s\n", dmabuf->name);
409-
mutex_unlock(&dmabuf->lock);
409+
dma_resv_unlock(dmabuf->resv);
410410
}
411411

412412
static const struct file_operations dma_buf_fops = {
@@ -525,6 +525,10 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
525525
return ERR_PTR(-EINVAL);
526526
}
527527

528+
if (WARN_ON(exp_info->ops->cache_sgt_mapping &&
529+
exp_info->ops->dynamic_mapping))
530+
return ERR_PTR(-EINVAL);
531+
528532
if (!try_module_get(exp_info->owner))
529533
return ERR_PTR(-ENOENT);
530534

@@ -645,10 +649,11 @@ void dma_buf_put(struct dma_buf *dmabuf)
645649
EXPORT_SYMBOL_GPL(dma_buf_put);
646650

647651
/**
648-
* dma_buf_attach - Add the device to dma_buf's attachments list; optionally,
652+
* dma_buf_dynamic_attach - Add the device to dma_buf's attachments list; optionally,
649653
* calls attach() of dma_buf_ops to allow device-specific attach functionality
650-
* @dmabuf: [in] buffer to attach device to.
651-
* @dev: [in] device to be attached.
654+
* @dmabuf: [in] buffer to attach device to.
655+
* @dev: [in] device to be attached.
656+
* @dynamic_mapping: [in] calling convention for map/unmap
652657
*
653658
* Returns struct dma_buf_attachment pointer for this attachment. Attachments
654659
* must be cleaned up by calling dma_buf_detach().
@@ -662,8 +667,9 @@ EXPORT_SYMBOL_GPL(dma_buf_put);
662667
* accessible to @dev, and cannot be moved to a more suitable place. This is
663668
* indicated with the error code -EBUSY.
664669
*/
665-
struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
666-
struct device *dev)
670+
struct dma_buf_attachment *
671+
dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
672+
bool dynamic_mapping)
667673
{
668674
struct dma_buf_attachment *attach;
669675
int ret;
@@ -677,25 +683,69 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
677683

678684
attach->dev = dev;
679685
attach->dmabuf = dmabuf;
680-
681-
mutex_lock(&dmabuf->lock);
686+
attach->dynamic_mapping = dynamic_mapping;
682687

683688
if (dmabuf->ops->attach) {
684689
ret = dmabuf->ops->attach(dmabuf, attach);
685690
if (ret)
686691
goto err_attach;
687692
}
693+
dma_resv_lock(dmabuf->resv, NULL);
688694
list_add(&attach->node, &dmabuf->attachments);
695+
dma_resv_unlock(dmabuf->resv);
689696

690-
mutex_unlock(&dmabuf->lock);
697+
/* When either the importer or the exporter can't handle dynamic
698+
* mappings we cache the mapping here to avoid issues with the
699+
* reservation object lock.
700+
*/
701+
if (dma_buf_attachment_is_dynamic(attach) !=
702+
dma_buf_is_dynamic(dmabuf)) {
703+
struct sg_table *sgt;
704+
705+
if (dma_buf_is_dynamic(attach->dmabuf))
706+
dma_resv_lock(attach->dmabuf->resv, NULL);
707+
708+
sgt = dmabuf->ops->map_dma_buf(attach, DMA_BIDIRECTIONAL);
709+
if (!sgt)
710+
sgt = ERR_PTR(-ENOMEM);
711+
if (IS_ERR(sgt)) {
712+
ret = PTR_ERR(sgt);
713+
goto err_unlock;
714+
}
715+
if (dma_buf_is_dynamic(attach->dmabuf))
716+
dma_resv_unlock(attach->dmabuf->resv);
717+
attach->sgt = sgt;
718+
attach->dir = DMA_BIDIRECTIONAL;
719+
}
691720

692721
return attach;
693722

694723
err_attach:
695724
kfree(attach);
696-
mutex_unlock(&dmabuf->lock);
725+
return ERR_PTR(ret);
726+
727+
err_unlock:
728+
if (dma_buf_is_dynamic(attach->dmabuf))
729+
dma_resv_unlock(attach->dmabuf->resv);
730+
731+
dma_buf_detach(dmabuf, attach);
697732
return ERR_PTR(ret);
698733
}
734+
EXPORT_SYMBOL_GPL(dma_buf_dynamic_attach);
735+
736+
/**
737+
* dma_buf_attach - Wrapper for dma_buf_dynamic_attach
738+
* @dmabuf: [in] buffer to attach device to.
739+
* @dev: [in] device to be attached.
740+
*
741+
* Wrapper to call dma_buf_dynamic_attach() for drivers which still use a static
742+
* mapping.
743+
*/
744+
struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
745+
struct device *dev)
746+
{
747+
return dma_buf_dynamic_attach(dmabuf, dev, false);
748+
}
699749
EXPORT_SYMBOL_GPL(dma_buf_attach);
700750

701751
/**
@@ -711,15 +761,22 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
711761
if (WARN_ON(!dmabuf || !attach))
712762
return;
713763

714-
if (attach->sgt)
764+
if (attach->sgt) {
765+
if (dma_buf_is_dynamic(attach->dmabuf))
766+
dma_resv_lock(attach->dmabuf->resv, NULL);
767+
715768
dmabuf->ops->unmap_dma_buf(attach, attach->sgt, attach->dir);
716769

717-
mutex_lock(&dmabuf->lock);
770+
if (dma_buf_is_dynamic(attach->dmabuf))
771+
dma_resv_unlock(attach->dmabuf->resv);
772+
}
773+
774+
dma_resv_lock(dmabuf->resv, NULL);
718775
list_del(&attach->node);
776+
dma_resv_unlock(dmabuf->resv);
719777
if (dmabuf->ops->detach)
720778
dmabuf->ops->detach(dmabuf, attach);
721779

722-
mutex_unlock(&dmabuf->lock);
723780
kfree(attach);
724781
}
725782
EXPORT_SYMBOL_GPL(dma_buf_detach);
@@ -749,6 +806,9 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
749806
if (WARN_ON(!attach || !attach->dmabuf))
750807
return ERR_PTR(-EINVAL);
751808

809+
if (dma_buf_attachment_is_dynamic(attach))
810+
dma_resv_assert_held(attach->dmabuf->resv);
811+
752812
if (attach->sgt) {
753813
/*
754814
* Two mappings with different directions for the same
@@ -761,6 +821,9 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
761821
return attach->sgt;
762822
}
763823

824+
if (dma_buf_is_dynamic(attach->dmabuf))
825+
dma_resv_assert_held(attach->dmabuf->resv);
826+
764827
sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction);
765828
if (!sg_table)
766829
sg_table = ERR_PTR(-ENOMEM);
@@ -793,9 +856,15 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment *attach,
793856
if (WARN_ON(!attach || !attach->dmabuf || !sg_table))
794857
return;
795858

859+
if (dma_buf_attachment_is_dynamic(attach))
860+
dma_resv_assert_held(attach->dmabuf->resv);
861+
796862
if (attach->sgt == sg_table)
797863
return;
798864

865+
if (dma_buf_is_dynamic(attach->dmabuf))
866+
dma_resv_assert_held(attach->dmabuf->resv);
867+
799868
attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction);
800869
}
801870
EXPORT_SYMBOL_GPL(dma_buf_unmap_attachment);
@@ -1171,13 +1240,10 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused)
11711240
"size", "flags", "mode", "count", "ino");
11721241

11731242
list_for_each_entry(buf_obj, &db_list.head, list_node) {
1174-
ret = mutex_lock_interruptible(&buf_obj->lock);
11751243

1176-
if (ret) {
1177-
seq_puts(s,
1178-
"\tERROR locking buffer object: skipping\n");
1179-
continue;
1180-
}
1244+
ret = dma_resv_lock_interruptible(buf_obj->resv, NULL);
1245+
if (ret)
1246+
goto error_unlock;
11811247

11821248
seq_printf(s, "%08zu\t%08x\t%08x\t%08ld\t%s\t%08lu\t%s\n",
11831249
buf_obj->size,
@@ -1223,19 +1289,23 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused)
12231289
seq_printf(s, "\t%s\n", dev_name(attach_obj->dev));
12241290
attach_count++;
12251291
}
1292+
dma_resv_unlock(buf_obj->resv);
12261293

12271294
seq_printf(s, "Total %d devices attached\n\n",
12281295
attach_count);
12291296

12301297
count++;
12311298
size += buf_obj->size;
1232-
mutex_unlock(&buf_obj->lock);
12331299
}
12341300

12351301
seq_printf(s, "\nTotal %d objects, %zu bytes\n", count, size);
12361302

12371303
mutex_unlock(&db_list.lock);
12381304
return 0;
1305+
1306+
error_unlock:
1307+
mutex_unlock(&db_list.lock);
1308+
return ret;
12391309
}
12401310

12411311
DEFINE_SHOW_ATTRIBUTE(dma_buf_debug);

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ static int reserve_bo_and_vm(struct kgd_mem *mem,
613613
amdgpu_vm_get_pd_bo(vm, &ctx->list, &ctx->vm_pd[0]);
614614

615615
ret = ttm_eu_reserve_buffers(&ctx->ticket, &ctx->list,
616-
false, &ctx->duplicates, true);
616+
false, &ctx->duplicates);
617617
if (!ret)
618618
ctx->reserved = true;
619619
else {
@@ -686,7 +686,7 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
686686
}
687687

688688
ret = ttm_eu_reserve_buffers(&ctx->ticket, &ctx->list,
689-
false, &ctx->duplicates, true);
689+
false, &ctx->duplicates);
690690
if (!ret)
691691
ctx->reserved = true;
692692
else
@@ -1805,8 +1805,7 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info)
18051805
}
18061806

18071807
/* Reserve all BOs and page tables for validation */
1808-
ret = ttm_eu_reserve_buffers(&ticket, &resv_list, false, &duplicates,
1809-
true);
1808+
ret = ttm_eu_reserve_buffers(&ticket, &resv_list, false, &duplicates);
18101809
WARN(!list_empty(&duplicates), "Duplicates should be empty");
18111810
if (ret)
18121811
goto out_free;
@@ -2004,7 +2003,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)
20042003
}
20052004

20062005
ret = ttm_eu_reserve_buffers(&ctx.ticket, &ctx.list,
2007-
false, &duplicate_save, true);
2006+
false, &duplicate_save);
20082007
if (ret) {
20092008
pr_debug("Memory eviction: TTM Reserve Failed. Try again\n");
20102009
goto ttm_reserve_fail;

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
581581
}
582582

583583
r = ttm_eu_reserve_buffers(&p->ticket, &p->validated, true,
584-
&duplicates, false);
584+
&duplicates);
585585
if (unlikely(r != 0)) {
586586
if (r != -ERESTARTSYS)
587587
DRM_ERROR("ttm_eu_reserve_buffers failed.\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,
8080
list_add(&csa_tv.head, &list);
8181
amdgpu_vm_get_pd_bo(vm, &list, &pd);
8282

83-
r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL, false);
83+
r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL);
8484
if (r) {
8585
DRM_ERROR("failed to reserve CSA,PD BOs: err=%d\n", r);
8686
return r;

0 commit comments

Comments
 (0)