Commit acc7829d authored by Stefano Garzarella's avatar Stefano Garzarella Committed by jiangdongxu
Browse files

vhost-vdpa: use bind_mm/unbind_mm device callbacks

mainline inclusion
from mainline-v6.4-rc1
commit 9067de47
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I86ITO
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9067de4725a299bc1baf11de9f5040fdd0bd05c3



----------------------------------------------------------------------

When the user call VHOST_SET_OWNER ioctl and the vDPA device
has `use_va` set to true, let's call the bind_mm callback.
In this way we can bind the device to the user address space
and directly use the user VA.

The unbind_mm callback is called during the release after
stopping the device.

Signed-off-by: default avatarStefano Garzarella <sgarzare@redhat.com>
Message-Id: <20230404131326.44403-3-sgarzare@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarjiangdongxu <jiangdongxu1@huawei.com>
parent f7a60e7d
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -219,6 +219,28 @@ static int vhost_vdpa_reset(struct vhost_vdpa *v)
	return vdpa_reset(vdpa);
}

static long vhost_vdpa_bind_mm(struct vhost_vdpa *v)
{
	struct vdpa_device *vdpa = v->vdpa;
	const struct vdpa_config_ops *ops = vdpa->config;

	if (!vdpa->use_va || !ops->bind_mm)
		return 0;

	return ops->bind_mm(vdpa, v->vdev.mm);
}

static void vhost_vdpa_unbind_mm(struct vhost_vdpa *v)
{
	struct vdpa_device *vdpa = v->vdpa;
	const struct vdpa_config_ops *ops = vdpa->config;

	if (!vdpa->use_va || !ops->unbind_mm)
		return;

	ops->unbind_mm(vdpa);
}

static long vhost_vdpa_get_device_id(struct vhost_vdpa *v, u8 __user *argp)
{
	struct vdpa_device *vdpa = v->vdpa;
@@ -716,6 +738,17 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
		break;
	}

	if (r)
		goto out;

	switch (cmd) {
	case VHOST_SET_OWNER:
		r = vhost_vdpa_bind_mm(v);
		if (r)
			vhost_dev_reset_owner(d, NULL);
		break;
	}
out:
	mutex_unlock(&d->mutex);
	return r;
}
@@ -1288,6 +1321,7 @@ static int vhost_vdpa_release(struct inode *inode, struct file *filep)
	vhost_vdpa_clean_irq(v);
	vhost_vdpa_reset(v);
	vhost_dev_stop(&v->vdev);
	vhost_vdpa_unbind_mm(v);
	vhost_vdpa_config_put(v);
	vhost_vdpa_cleanup(v);
	mutex_unlock(&d->mutex);