Skip to content

Commit 457b046

Browse files
committed
accel/amdxdna: Remove mmap and export support for ubuf
Ubuf pages should not be mmaped or exported. Remove the ubuf mmap callback and return -EOPNOTSUPP when exporting ubuf objects. ubuf vmap is also removed for there is not a real use case yet. Fixes: bd72d4a ("accel/amdxdna: Support user space allocated buffer") Reviewed-by: Christian König <christian.koenig@amd.com> Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com> Link: https://patch.msgid.link/20260518155706.937461-1-lizhi.hou@amd.com
1 parent d45d5c8 commit 457b046

3 files changed

Lines changed: 10 additions & 51 deletions

File tree

drivers/accel/amdxdna/amdxdna_gem.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ static struct dma_buf *amdxdna_gem_prime_export(struct drm_gem_object *gobj, int
490490
struct amdxdna_gem_obj *abo = to_xdna_obj(gobj);
491491
DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
492492

493+
if (abo->private_buffer)
494+
return ERR_PTR(-EOPNOTSUPP);
495+
493496
if (abo->dma_buf) {
494497
get_dma_buf(abo->dma_buf);
495498
return abo->dma_buf;
@@ -685,6 +688,7 @@ amdxdna_gem_create_ubuf_object(struct drm_device *dev, struct amdxdna_drm_create
685688
{
686689
struct amdxdna_dev *xdna = to_xdna_dev(dev);
687690
struct amdxdna_drm_va_tbl va_tbl;
691+
struct amdxdna_gem_obj *abo;
688692
struct drm_gem_object *gobj;
689693
struct dma_buf *dma_buf;
690694

@@ -711,7 +715,10 @@ amdxdna_gem_create_ubuf_object(struct drm_device *dev, struct amdxdna_drm_create
711715

712716
dma_buf_put(dma_buf);
713717

714-
return to_xdna_obj(gobj);
718+
abo = to_xdna_obj(gobj);
719+
abo->private_buffer = true;
720+
721+
return abo;
715722
}
716723

717724
struct drm_gem_object *

drivers/accel/amdxdna/amdxdna_gem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct amdxdna_gem_obj {
5454

5555
/* True, if BO is managed by XRT, not application */
5656
bool internal;
57+
/* True, if BO is not exportable */
58+
bool private_buffer;
5759
};
5860

5961
#define to_gobj(obj) (&(obj)->base.base)

drivers/accel/amdxdna/amdxdna_ubuf.c

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -69,60 +69,10 @@ static void amdxdna_ubuf_release(struct dma_buf *dbuf)
6969
kfree(ubuf);
7070
}
7171

72-
static vm_fault_t amdxdna_ubuf_vm_fault(struct vm_fault *vmf)
73-
{
74-
struct vm_area_struct *vma = vmf->vma;
75-
struct amdxdna_ubuf_priv *ubuf;
76-
unsigned long pfn;
77-
pgoff_t pgoff;
78-
79-
ubuf = vma->vm_private_data;
80-
pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
81-
82-
pfn = page_to_pfn(ubuf->pages[pgoff]);
83-
return vmf_insert_pfn(vma, vmf->address, pfn);
84-
}
85-
86-
static const struct vm_operations_struct amdxdna_ubuf_vm_ops = {
87-
.fault = amdxdna_ubuf_vm_fault,
88-
};
89-
90-
static int amdxdna_ubuf_mmap(struct dma_buf *dbuf, struct vm_area_struct *vma)
91-
{
92-
struct amdxdna_ubuf_priv *ubuf = dbuf->priv;
93-
94-
vma->vm_ops = &amdxdna_ubuf_vm_ops;
95-
vma->vm_private_data = ubuf;
96-
vm_flags_set(vma, VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP);
97-
98-
return 0;
99-
}
100-
101-
static int amdxdna_ubuf_vmap(struct dma_buf *dbuf, struct iosys_map *map)
102-
{
103-
struct amdxdna_ubuf_priv *ubuf = dbuf->priv;
104-
void *kva;
105-
106-
kva = vmap(ubuf->pages, ubuf->nr_pages, VM_MAP, PAGE_KERNEL);
107-
if (!kva)
108-
return -EINVAL;
109-
110-
iosys_map_set_vaddr(map, kva);
111-
return 0;
112-
}
113-
114-
static void amdxdna_ubuf_vunmap(struct dma_buf *dbuf, struct iosys_map *map)
115-
{
116-
vunmap(map->vaddr);
117-
}
118-
11972
static const struct dma_buf_ops amdxdna_ubuf_dmabuf_ops = {
12073
.map_dma_buf = amdxdna_ubuf_map,
12174
.unmap_dma_buf = amdxdna_ubuf_unmap,
12275
.release = amdxdna_ubuf_release,
123-
.mmap = amdxdna_ubuf_mmap,
124-
.vmap = amdxdna_ubuf_vmap,
125-
.vunmap = amdxdna_ubuf_vunmap,
12676
};
12777

12878
struct dma_buf *amdxdna_get_ubuf(struct drm_device *dev,

0 commit comments

Comments
 (0)