Skip to content

Commit 2ea7a5b

Browse files
committed
drivers/xen/gntdev: use xen_pv_domain() instead of cached value
Eliminate the use_ptemod variable by replacing its use cases with xen_pv_domain(). Instead of passing the xen_pv_domain() return value to gntdev_ioctl_dmabuf_exp_from_refs(), use xen_pv_domain() in that function. Reviewed-by: Jason Andryuk <jason.andryuk@amd.com> Signed-off-by: Juergen Gross <jgross@suse.com> Message-ID: <20250826145608.10352-4-jgross@suse.com>
1 parent 0f42831 commit 2ea7a5b

3 files changed

Lines changed: 18 additions & 24 deletions

File tree

drivers/xen/gntdev-dmabuf.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,16 +720,15 @@ static void dmabuf_imp_release_all(struct gntdev_dmabuf_priv *priv)
720720

721721
/* DMA buffer IOCTL support. */
722722

723-
long gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv, int use_ptemod,
723+
long gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv,
724724
struct ioctl_gntdev_dmabuf_exp_from_refs __user *u)
725725
{
726726
struct ioctl_gntdev_dmabuf_exp_from_refs op;
727727
u32 *refs;
728728
long ret;
729729

730-
if (use_ptemod) {
731-
pr_debug("Cannot provide dma-buf: use_ptemode %d\n",
732-
use_ptemod);
730+
if (xen_pv_domain()) {
731+
pr_debug("Cannot provide dma-buf in a PV domain\n");
733732
return -EINVAL;
734733
}
735734

drivers/xen/gntdev-dmabuf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct gntdev_dmabuf_priv *gntdev_dmabuf_init(struct file *filp);
1818

1919
void gntdev_dmabuf_fini(struct gntdev_dmabuf_priv *priv);
2020

21-
long gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv, int use_ptemod,
21+
long gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv,
2222
struct ioctl_gntdev_dmabuf_exp_from_refs __user *u);
2323

2424
long gntdev_ioctl_dmabuf_exp_wait_released(struct gntdev_priv *priv,

drivers/xen/gntdev.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ module_param(limit, uint, 0644);
7373
MODULE_PARM_DESC(limit,
7474
"Maximum number of grants that may be mapped by one mapping request");
7575

76-
/* True in PV mode, false otherwise */
77-
static int use_ptemod;
78-
7976
static void unmap_grant_pages(struct gntdev_grant_map *map,
8077
int offset, int pages);
8178

@@ -163,7 +160,7 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
163160
NULL == add->pages ||
164161
NULL == add->being_removed)
165162
goto err;
166-
if (use_ptemod) {
163+
if (xen_pv_domain()) {
167164
add->kmap_ops = kvmalloc_array(count, sizeof(add->kmap_ops[0]),
168165
GFP_KERNEL);
169166
add->kunmap_ops = kvmalloc_array(count, sizeof(add->kunmap_ops[0]),
@@ -211,7 +208,7 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
211208
add->grants[i].ref = INVALID_GRANT_REF;
212209
add->map_ops[i].handle = INVALID_GRANT_HANDLE;
213210
add->unmap_ops[i].handle = INVALID_GRANT_HANDLE;
214-
if (use_ptemod) {
211+
if (xen_pv_domain()) {
215212
add->kmap_ops[i].handle = INVALID_GRANT_HANDLE;
216213
add->kunmap_ops[i].handle = INVALID_GRANT_HANDLE;
217214
}
@@ -268,7 +265,7 @@ void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map)
268265
if (!refcount_dec_and_test(&map->users))
269266
return;
270267

271-
if (map->pages && !use_ptemod) {
268+
if (map->pages && !xen_pv_domain()) {
272269
/*
273270
* Increment the reference count. This ensures that the
274271
* subsequent call to unmap_grant_pages() will not wind up
@@ -298,7 +295,7 @@ void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map)
298295
*/
299296
}
300297

301-
if (use_ptemod && map->notifier_init)
298+
if (xen_pv_domain() && map->notifier_init)
302299
mmu_interval_notifier_remove(&map->notifier);
303300

304301
if (map->notify.flags & UNMAP_NOTIFY_SEND_EVENT) {
@@ -334,7 +331,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map)
334331
size_t alloced = 0;
335332
int i, err = 0;
336333

337-
if (!use_ptemod) {
334+
if (!xen_pv_domain()) {
338335
/* Note: it could already be mapped */
339336
if (map->map_ops[0].handle != INVALID_GRANT_HANDLE)
340337
return 0;
@@ -389,7 +386,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map)
389386
if (map->flags & GNTMAP_device_map)
390387
map->unmap_ops[i].dev_bus_addr = map->map_ops[i].dev_bus_addr;
391388

392-
if (use_ptemod) {
389+
if (xen_pv_domain()) {
393390
if (map->kmap_ops[i].status == GNTST_okay) {
394391
alloced++;
395392
map->kunmap_ops[i].handle = map->kmap_ops[i].handle;
@@ -421,7 +418,7 @@ static void __unmap_grant_pages_done(int result,
421418
map->unmap_ops[offset+i].handle,
422419
map->unmap_ops[offset+i].status);
423420
map->unmap_ops[offset+i].handle = INVALID_GRANT_HANDLE;
424-
if (use_ptemod) {
421+
if (xen_pv_domain()) {
425422
if (map->kunmap_ops[offset + i].status == GNTST_okay &&
426423
map->kunmap_ops[offset + i].handle != INVALID_GRANT_HANDLE)
427424
successful_unmaps++;
@@ -464,7 +461,7 @@ static void __unmap_grant_pages(struct gntdev_grant_map *map, int offset,
464461
}
465462

466463
map->unmap_data.unmap_ops = map->unmap_ops + offset;
467-
map->unmap_data.kunmap_ops = use_ptemod ? map->kunmap_ops + offset : NULL;
464+
map->unmap_data.kunmap_ops = xen_pv_domain() ? map->kunmap_ops + offset : NULL;
468465
map->unmap_data.pages = map->pages + offset;
469466
map->unmap_data.count = pages;
470467
map->unmap_data.done = __unmap_grant_pages_done;
@@ -1039,7 +1036,7 @@ static long gntdev_ioctl(struct file *flip,
10391036

10401037
#ifdef CONFIG_XEN_GNTDEV_DMABUF
10411038
case IOCTL_GNTDEV_DMABUF_EXP_FROM_REFS:
1042-
return gntdev_ioctl_dmabuf_exp_from_refs(priv, use_ptemod, ptr);
1039+
return gntdev_ioctl_dmabuf_exp_from_refs(priv, ptr);
10431040

10441041
case IOCTL_GNTDEV_DMABUF_EXP_WAIT_RELEASED:
10451042
return gntdev_ioctl_dmabuf_exp_wait_released(priv, ptr);
@@ -1086,7 +1083,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
10861083

10871084
vm_flags_set(vma, VM_DONTEXPAND | VM_DONTDUMP | VM_MIXEDMAP);
10881085

1089-
if (use_ptemod)
1086+
if (xen_pv_domain())
10901087
vm_flags_set(vma, VM_DONTCOPY);
10911088

10921089
vma->vm_private_data = map;
@@ -1102,7 +1099,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
11021099

11031100
map->pages_vm_start = vma->vm_start;
11041101

1105-
if (use_ptemod) {
1102+
if (xen_pv_domain()) {
11061103
err = mmu_interval_notifier_insert_locked(
11071104
&map->notifier, vma->vm_mm, vma->vm_start,
11081105
vma->vm_end - vma->vm_start, &gntdev_mmu_ops);
@@ -1113,7 +1110,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
11131110
}
11141111
mutex_unlock(&priv->lock);
11151112

1116-
if (use_ptemod) {
1113+
if (xen_pv_domain()) {
11171114
/*
11181115
* gntdev takes the address of the PTE in find_grant_ptes() and
11191116
* passes it to the hypervisor in gntdev_map_grant_pages(). The
@@ -1139,7 +1136,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
11391136
if (err)
11401137
goto out_put_map;
11411138

1142-
if (!use_ptemod) {
1139+
if (!xen_pv_domain()) {
11431140
err = vm_map_pages_zero(vma, map->pages, map->count);
11441141
if (err)
11451142
goto out_put_map;
@@ -1154,7 +1151,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
11541151
out_unlock_put:
11551152
mutex_unlock(&priv->lock);
11561153
out_put_map:
1157-
if (use_ptemod)
1154+
if (xen_pv_domain())
11581155
unmap_grant_pages(map, 0, map->count);
11591156
gntdev_put_map(priv, map);
11601157
return err;
@@ -1183,8 +1180,6 @@ static int __init gntdev_init(void)
11831180
if (!xen_domain())
11841181
return -ENODEV;
11851182

1186-
use_ptemod = xen_pv_domain();
1187-
11881183
err = misc_register(&gntdev_miscdev);
11891184
if (err != 0) {
11901185
pr_err("Could not register gntdev device\n");

0 commit comments

Comments
 (0)