public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Srujana Challa <schalla@marvell.com>
To: <virtualization@lists.linux.dev>, <kvm@vger.kernel.org>
Cc: <mst@redhat.com>, <jasowang@redhat.com>, <eperezma@redhat.com>,
	<ndabilpuram@marvell.com>, <jerinj@marvell.com>
Subject: [PATCH v2 2/2] vhost-vdpa: introduce NO-IOMMU backend feature bit
Date: Fri, 20 Sep 2024 19:35:30 +0530	[thread overview]
Message-ID: <20240920140530.775307-3-schalla@marvell.com> (raw)
In-Reply-To: <20240920140530.775307-1-schalla@marvell.com>

This patch introduces the VHOST_BACKEND_F_NOIOMMU feature flag.
This flag allows userspace to identify if the driver can operate
without an IOMMU, providing more flexibility in environments where
IOMMU is not available or desired.

Key changes include:
    - Addition of the VHOST_BACKEND_F_NOIOMMU feature flag.
    - Updates to vhost_vdpa_unlocked_ioctl to handle the NO-IOMMU
      feature.
The NO-IOMMU mode is enabled if:
    - The vdpa device lacks an IOMMU domain.
    - The system has the required RAWIO permissions.
    - The vdpa device explicitly supports NO-IOMMU mode.

This feature flag indicates to userspace that the driver can safely
operate in NO-IOMMU mode. If the flag is absent, userspace should
assume NO-IOMMU mode is unsupported and take appropriate actions.

Signed-off-by: Srujana Challa <schalla@marvell.com>
---
 drivers/vhost/vdpa.c             | 11 ++++++++++-
 include/uapi/linux/vhost_types.h |  2 ++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index b3085189ea4a..de47349eceff 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -797,7 +797,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
 				 BIT_ULL(VHOST_BACKEND_F_IOTLB_PERSIST) |
 				 BIT_ULL(VHOST_BACKEND_F_SUSPEND) |
 				 BIT_ULL(VHOST_BACKEND_F_RESUME) |
-				 BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK)))
+				 BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK) |
+				 BIT_ULL(VHOST_BACKEND_F_NOIOMMU)))
 			return -EOPNOTSUPP;
 		if ((features & BIT_ULL(VHOST_BACKEND_F_SUSPEND)) &&
 		     !vhost_vdpa_can_suspend(v))
@@ -814,6 +815,12 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
 		if ((features & BIT_ULL(VHOST_BACKEND_F_IOTLB_PERSIST)) &&
 		     !vhost_vdpa_has_persistent_map(v))
 			return -EOPNOTSUPP;
+		if ((features & BIT_ULL(VHOST_BACKEND_F_NOIOMMU)) &&
+		    !v->noiommu_en)
+			return -EOPNOTSUPP;
+		if (!(features & BIT_ULL(VHOST_BACKEND_F_NOIOMMU)) &&
+		    v->noiommu_en)
+			return -EOPNOTSUPP;
 		vhost_set_backend_features(&v->vdev, features);
 		return 0;
 	}
@@ -871,6 +878,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
 			features |= BIT_ULL(VHOST_BACKEND_F_DESC_ASID);
 		if (vhost_vdpa_has_persistent_map(v))
 			features |= BIT_ULL(VHOST_BACKEND_F_IOTLB_PERSIST);
+		if (v->noiommu_en)
+			features |= BIT_ULL(VHOST_BACKEND_F_NOIOMMU);
 		features |= vhost_vdpa_get_backend_features(v);
 		if (copy_to_user(featurep, &features, sizeof(features)))
 			r = -EFAULT;
diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_types.h
index d7656908f730..dda673c3456a 100644
--- a/include/uapi/linux/vhost_types.h
+++ b/include/uapi/linux/vhost_types.h
@@ -192,5 +192,7 @@ struct vhost_vdpa_iova_range {
 #define VHOST_BACKEND_F_DESC_ASID    0x7
 /* IOTLB don't flush memory mapping across device reset */
 #define VHOST_BACKEND_F_IOTLB_PERSIST  0x8
+/* Enables the device to operate in NO-IOMMU mode as well */
+#define VHOST_BACKEND_F_NOIOMMU  0x9
 
 #endif
-- 
2.25.1


  parent reply	other threads:[~2024-09-20 14:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-20 14:05 [PATCH v2 0/2] vhost-vdpa: Add support for NO-IOMMU mode Srujana Challa
2024-09-20 14:05 ` [PATCH v2 1/2] vhost-vdpa: introduce module parameter for no-IOMMU mode Srujana Challa
2024-09-21 17:28   ` kernel test robot
2024-09-20 14:05 ` Srujana Challa [this message]
2024-09-24  7:43   ` [PATCH v2 2/2] vhost-vdpa: introduce NO-IOMMU backend feature bit Jason Wang
2024-09-24 10:01     ` [EXTERNAL] " Srujana Challa
2024-10-01  8:47 ` [PATCH v2 0/2] vhost-vdpa: Add support for NO-IOMMU mode Christoph Hellwig
2024-10-14 13:18   ` [EXTERNAL] " Srujana Challa
2024-10-15  3:48     ` Christoph Hellwig
2024-10-16 17:28       ` Srujana Challa
2024-10-17  6:19         ` Christoph Hellwig
2024-10-17  8:53           ` Srujana Challa
2024-10-18  4:54             ` Jason Wang
2024-10-18  5:24             ` Christoph Hellwig
2024-10-18 13:08               ` Srujana Challa
2024-10-16 17:41       ` Michael S. Tsirkin
2024-10-17  6:16         ` Christoph Hellwig
2024-10-20  0:16           ` Michael S. Tsirkin
2024-10-23  6:58             ` Christoph Hellwig
2024-10-23  8:19               ` Michael S. Tsirkin
2024-10-24  9:05                 ` Christoph Hellwig
2024-11-06 12:38                   ` Srujana Challa
2024-11-06 15:45                     ` Christoph Hellwig
2024-11-07  6:08                       ` Srujana Challa
2024-11-12  7:11                         ` Srujana Challa
2024-11-06 18:11                     ` Michael S. Tsirkin
2024-11-06 18:14                   ` Michael S. Tsirkin

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=20240920140530.775307-3-schalla@marvell.com \
    --to=schalla@marvell.com \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jerinj@marvell.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=ndabilpuram@marvell.com \
    --cc=virtualization@lists.linux.dev \
    /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