Commit 2ea7a5bc authored by Juergen Gross's avatar Juergen Gross
Browse files

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: default avatarJason Andryuk <jason.andryuk@amd.com>
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Message-ID: <20250826145608.10352-4-jgross@suse.com>
parent 0f428312
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -720,16 +720,15 @@ static void dmabuf_imp_release_all(struct gntdev_dmabuf_priv *priv)

/* DMA buffer IOCTL support. */

long gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv, int use_ptemod,
long gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv,
				       struct ioctl_gntdev_dmabuf_exp_from_refs __user *u)
{
	struct ioctl_gntdev_dmabuf_exp_from_refs op;
	u32 *refs;
	long ret;

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

+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ struct gntdev_dmabuf_priv *gntdev_dmabuf_init(struct file *filp);

void gntdev_dmabuf_fini(struct gntdev_dmabuf_priv *priv);

long gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv, int use_ptemod,
long gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv,
				       struct ioctl_gntdev_dmabuf_exp_from_refs __user *u);

long gntdev_ioctl_dmabuf_exp_wait_released(struct gntdev_priv *priv,
+14 −19
Original line number Diff line number Diff line
@@ -73,9 +73,6 @@ module_param(limit, uint, 0644);
MODULE_PARM_DESC(limit,
	"Maximum number of grants that may be mapped by one mapping request");

/* True in PV mode, false otherwise */
static int use_ptemod;

static void unmap_grant_pages(struct gntdev_grant_map *map,
			      int offset, int pages);

@@ -163,7 +160,7 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
	    NULL == add->pages     ||
	    NULL == add->being_removed)
		goto err;
	if (use_ptemod) {
	if (xen_pv_domain()) {
		add->kmap_ops   = kvmalloc_array(count, sizeof(add->kmap_ops[0]),
						 GFP_KERNEL);
		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,
		add->grants[i].ref = INVALID_GRANT_REF;
		add->map_ops[i].handle = INVALID_GRANT_HANDLE;
		add->unmap_ops[i].handle = INVALID_GRANT_HANDLE;
		if (use_ptemod) {
		if (xen_pv_domain()) {
			add->kmap_ops[i].handle = INVALID_GRANT_HANDLE;
			add->kunmap_ops[i].handle = INVALID_GRANT_HANDLE;
		}
@@ -268,7 +265,7 @@ void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map)
	if (!refcount_dec_and_test(&map->users))
		return;

	if (map->pages && !use_ptemod) {
	if (map->pages && !xen_pv_domain()) {
		/*
		 * Increment the reference count.  This ensures that the
		 * 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)
		 */
	}

	if (use_ptemod && map->notifier_init)
	if (xen_pv_domain() && map->notifier_init)
		mmu_interval_notifier_remove(&map->notifier);

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

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

		if (use_ptemod) {
		if (xen_pv_domain()) {
			if (map->kmap_ops[i].status == GNTST_okay) {
				alloced++;
				map->kunmap_ops[i].handle = map->kmap_ops[i].handle;
@@ -421,7 +418,7 @@ static void __unmap_grant_pages_done(int result,
			map->unmap_ops[offset+i].handle,
			map->unmap_ops[offset+i].status);
		map->unmap_ops[offset+i].handle = INVALID_GRANT_HANDLE;
		if (use_ptemod) {
		if (xen_pv_domain()) {
			if (map->kunmap_ops[offset + i].status == GNTST_okay &&
			    map->kunmap_ops[offset + i].handle != INVALID_GRANT_HANDLE)
				successful_unmaps++;
@@ -464,7 +461,7 @@ static void __unmap_grant_pages(struct gntdev_grant_map *map, int offset,
	}

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

#ifdef CONFIG_XEN_GNTDEV_DMABUF
	case IOCTL_GNTDEV_DMABUF_EXP_FROM_REFS:
		return gntdev_ioctl_dmabuf_exp_from_refs(priv, use_ptemod, ptr);
		return gntdev_ioctl_dmabuf_exp_from_refs(priv, ptr);

	case IOCTL_GNTDEV_DMABUF_EXP_WAIT_RELEASED:
		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)

	vm_flags_set(vma, VM_DONTEXPAND | VM_DONTDUMP | VM_MIXEDMAP);

	if (use_ptemod)
	if (xen_pv_domain())
		vm_flags_set(vma, VM_DONTCOPY);

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

	map->pages_vm_start = vma->vm_start;

	if (use_ptemod) {
	if (xen_pv_domain()) {
		err = mmu_interval_notifier_insert_locked(
			&map->notifier, vma->vm_mm, vma->vm_start,
			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)
	}
	mutex_unlock(&priv->lock);

	if (use_ptemod) {
	if (xen_pv_domain()) {
		/*
		 * gntdev takes the address of the PTE in find_grant_ptes() and
		 * 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)
	if (err)
		goto out_put_map;

	if (!use_ptemod) {
	if (!xen_pv_domain()) {
		err = vm_map_pages_zero(vma, map->pages, map->count);
		if (err)
			goto out_put_map;
@@ -1154,7 +1151,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
out_unlock_put:
	mutex_unlock(&priv->lock);
out_put_map:
	if (use_ptemod)
	if (xen_pv_domain())
		unmap_grant_pages(map, 0, map->count);
	gntdev_put_map(priv, map);
	return err;
@@ -1183,8 +1180,6 @@ static int __init gntdev_init(void)
	if (!xen_domain())
		return -ENODEV;

	use_ptemod = xen_pv_domain();

	err = misc_register(&gntdev_miscdev);
	if (err != 0) {
		pr_err("Could not register gntdev device\n");