Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+18 -24
+3 -4
drivers/xen/gntdev-dmabuf.c
··· 720 720 721 721 /* DMA buffer IOCTL support. */ 722 722 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, 724 724 struct ioctl_gntdev_dmabuf_exp_from_refs __user *u) 725 725 { 726 726 struct ioctl_gntdev_dmabuf_exp_from_refs op; 727 727 u32 *refs; 728 728 long ret; 729 729 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"); 733 732 return -EINVAL; 734 733 } 735 734
+1 -1
drivers/xen/gntdev-dmabuf.h
··· 18 18 19 19 void gntdev_dmabuf_fini(struct gntdev_dmabuf_priv *priv); 20 20 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, 22 22 struct ioctl_gntdev_dmabuf_exp_from_refs __user *u); 23 23 24 24 long gntdev_ioctl_dmabuf_exp_wait_released(struct gntdev_priv *priv,
+14 -19
drivers/xen/gntdev.c
··· 73 73 MODULE_PARM_DESC(limit, 74 74 "Maximum number of grants that may be mapped by one mapping request"); 75 75 76 - /* True in PV mode, false otherwise */ 77 - static int use_ptemod; 78 - 79 76 static void unmap_grant_pages(struct gntdev_grant_map *map, 80 77 int offset, int pages); 81 78 ··· 160 163 NULL == add->pages || 161 164 NULL == add->being_removed) 162 165 goto err; 163 - if (use_ptemod) { 166 + if (xen_pv_domain()) { 164 167 add->kmap_ops = kvmalloc_array(count, sizeof(add->kmap_ops[0]), 165 168 GFP_KERNEL); 166 169 add->kunmap_ops = kvmalloc_array(count, sizeof(add->kunmap_ops[0]), ··· 208 211 add->grants[i].ref = INVALID_GRANT_REF; 209 212 add->map_ops[i].handle = INVALID_GRANT_HANDLE; 210 213 add->unmap_ops[i].handle = INVALID_GRANT_HANDLE; 211 - if (use_ptemod) { 214 + if (xen_pv_domain()) { 212 215 add->kmap_ops[i].handle = INVALID_GRANT_HANDLE; 213 216 add->kunmap_ops[i].handle = INVALID_GRANT_HANDLE; 214 217 } ··· 265 268 if (!refcount_dec_and_test(&map->users)) 266 269 return; 267 270 268 - if (map->pages && !use_ptemod) { 271 + if (map->pages && !xen_pv_domain()) { 269 272 /* 270 273 * Increment the reference count. This ensures that the 271 274 * subsequent call to unmap_grant_pages() will not wind up ··· 295 298 */ 296 299 } 297 300 298 - if (use_ptemod && map->notifier_init) 301 + if (xen_pv_domain() && map->notifier_init) 299 302 mmu_interval_notifier_remove(&map->notifier); 300 303 301 304 if (map->notify.flags & UNMAP_NOTIFY_SEND_EVENT) { ··· 331 334 size_t alloced = 0; 332 335 int i, err = 0; 333 336 334 - if (!use_ptemod) { 337 + if (!xen_pv_domain()) { 335 338 /* Note: it could already be mapped */ 336 339 if (map->map_ops[0].handle != INVALID_GRANT_HANDLE) 337 340 return 0; ··· 386 389 if (map->flags & GNTMAP_device_map) 387 390 map->unmap_ops[i].dev_bus_addr = map->map_ops[i].dev_bus_addr; 388 391 389 - if (use_ptemod) { 392 + if (xen_pv_domain()) { 390 393 if (map->kmap_ops[i].status == GNTST_okay) { 391 394 alloced++; 392 395 map->kunmap_ops[i].handle = map->kmap_ops[i].handle; ··· 418 421 map->unmap_ops[offset+i].handle, 419 422 map->unmap_ops[offset+i].status); 420 423 map->unmap_ops[offset+i].handle = INVALID_GRANT_HANDLE; 421 - if (use_ptemod) { 424 + if (xen_pv_domain()) { 422 425 if (map->kunmap_ops[offset + i].status == GNTST_okay && 423 426 map->kunmap_ops[offset + i].handle != INVALID_GRANT_HANDLE) 424 427 successful_unmaps++; ··· 461 464 } 462 465 463 466 map->unmap_data.unmap_ops = map->unmap_ops + offset; 464 - map->unmap_data.kunmap_ops = use_ptemod ? map->kunmap_ops + offset : NULL; 467 + map->unmap_data.kunmap_ops = xen_pv_domain() ? map->kunmap_ops + offset : NULL; 465 468 map->unmap_data.pages = map->pages + offset; 466 469 map->unmap_data.count = pages; 467 470 map->unmap_data.done = __unmap_grant_pages_done; ··· 1036 1039 1037 1040 #ifdef CONFIG_XEN_GNTDEV_DMABUF 1038 1041 case IOCTL_GNTDEV_DMABUF_EXP_FROM_REFS: 1039 - return gntdev_ioctl_dmabuf_exp_from_refs(priv, use_ptemod, ptr); 1042 + return gntdev_ioctl_dmabuf_exp_from_refs(priv, ptr); 1040 1043 1041 1044 case IOCTL_GNTDEV_DMABUF_EXP_WAIT_RELEASED: 1042 1045 return gntdev_ioctl_dmabuf_exp_wait_released(priv, ptr); ··· 1083 1086 1084 1087 vm_flags_set(vma, VM_DONTEXPAND | VM_DONTDUMP | VM_MIXEDMAP); 1085 1088 1086 - if (use_ptemod) 1089 + if (xen_pv_domain()) 1087 1090 vm_flags_set(vma, VM_DONTCOPY); 1088 1091 1089 1092 vma->vm_private_data = map; ··· 1099 1102 1100 1103 map->pages_vm_start = vma->vm_start; 1101 1104 1102 - if (use_ptemod) { 1105 + if (xen_pv_domain()) { 1103 1106 err = mmu_interval_notifier_insert_locked( 1104 1107 &map->notifier, vma->vm_mm, vma->vm_start, 1105 1108 vma->vm_end - vma->vm_start, &gntdev_mmu_ops); ··· 1110 1113 } 1111 1114 mutex_unlock(&priv->lock); 1112 1115 1113 - if (use_ptemod) { 1116 + if (xen_pv_domain()) { 1114 1117 /* 1115 1118 * gntdev takes the address of the PTE in find_grant_ptes() and 1116 1119 * passes it to the hypervisor in gntdev_map_grant_pages(). The ··· 1136 1139 if (err) 1137 1140 goto out_put_map; 1138 1141 1139 - if (!use_ptemod) { 1142 + if (!xen_pv_domain()) { 1140 1143 err = vm_map_pages_zero(vma, map->pages, map->count); 1141 1144 if (err) 1142 1145 goto out_put_map; ··· 1151 1154 out_unlock_put: 1152 1155 mutex_unlock(&priv->lock); 1153 1156 out_put_map: 1154 - if (use_ptemod) 1157 + if (xen_pv_domain()) 1155 1158 unmap_grant_pages(map, 0, map->count); 1156 1159 gntdev_put_map(priv, map); 1157 1160 return err; ··· 1179 1182 1180 1183 if (!xen_domain()) 1181 1184 return -ENODEV; 1182 - 1183 - use_ptemod = xen_pv_domain(); 1184 1185 1185 1186 err = misc_register(&gntdev_miscdev); 1186 1187 if (err != 0) {