Netdev List
 help / color / mirror / Atom feed
From: Stefano Garzarella <sgarzare@redhat.com>
To: virtualization@lists.linux-foundation.org
Cc: Jason Wang <jasowang@redhat.com>,
	Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	eperezma@redhat.com, stefanha@redhat.com, netdev@vger.kernel.org,
	Stefano Garzarella <sgarzare@redhat.com>
Subject: [RFC PATCH 2/6] vhost-vdpa: use bind_mm device callback
Date: Wed, 14 Dec 2022 17:30:21 +0100	[thread overview]
Message-ID: <20221214163025.103075-3-sgarzare@redhat.com> (raw)
In-Reply-To: <20221214163025.103075-1-sgarzare@redhat.com>

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.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 drivers/vhost/vdpa.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index b08e07fc7d1f..a775d1a52c77 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -219,6 +219,17 @@ 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, current);
+}
+
 static long vhost_vdpa_get_device_id(struct vhost_vdpa *v, u8 __user *argp)
 {
 	struct vdpa_device *vdpa = v->vdpa;
@@ -276,6 +287,10 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
 		ret = vdpa_reset(vdpa);
 		if (ret)
 			return ret;
+
+		ret = vhost_vdpa_bind_mm(v);
+		if (ret)
+			return ret;
 	} else
 		vdpa_set_status(vdpa, status);
 
@@ -679,6 +694,13 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
 		break;
 	default:
 		r = vhost_dev_ioctl(&v->vdev, cmd, argp);
+		if (!r && cmd == VHOST_SET_OWNER) {
+			r = vhost_vdpa_bind_mm(v);
+			if (r) {
+				vhost_dev_reset_owner(&v->vdev, NULL);
+				break;
+			}
+		}
 		if (r == -ENOIOCTLCMD)
 			r = vhost_vdpa_vring_ioctl(v, cmd, argp);
 		break;
-- 
2.38.1


  parent reply	other threads:[~2022-12-14 16:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14 16:30 [RFC PATCH 0/6] vdpa_sim: add support for user VA Stefano Garzarella
2022-12-14 16:30 ` [RFC PATCH 1/6] vdpa: add bind_mm callback Stefano Garzarella
2022-12-16  6:37   ` Jason Wang
2022-12-16  8:17     ` Stefano Garzarella
2022-12-22  4:18       ` Jason Wang
2022-12-14 16:30 ` Stefano Garzarella [this message]
2022-12-14 16:30 ` [RFC PATCH 3/6] vringh: support VA with iotlb Stefano Garzarella
2022-12-14 16:30 ` [RFC PATCH 4/6] vdpa_sim: make devices agnostic for work management Stefano Garzarella
2022-12-14 16:30 ` [RFC PATCH 5/6] vdpa_sim: use kthread worker Stefano Garzarella
2022-12-14 16:30 ` [RFC PATCH 6/6] vdpa_sim: add support for user VA Stefano Garzarella
2022-12-16  7:26   ` Jason Wang
2022-12-16  8:13     ` Stefano Garzarella
2022-12-21  7:17   ` Eugenio Perez Martin
2022-12-21  9:50     ` Stefano Garzarella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221214163025.103075-3-sgarzare@redhat.com \
    --to=sgarzare@redhat.com \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox