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 1/2] vhost-vdpa: introduce module parameter for no-IOMMU mode
Date: Fri, 20 Sep 2024 19:35:29 +0530 [thread overview]
Message-ID: <20240920140530.775307-2-schalla@marvell.com> (raw)
In-Reply-To: <20240920140530.775307-1-schalla@marvell.com>
This commit introduces module parameter
"enable_vhost_vdpa_unsafe_noiommu_mode" to enable an UNSAFE, no-IOMMU
mode in the vhost-vdpa driver. When enabled, this mode provides no
device isolation, no DMA translation, no host kernel protection, and
cannot be used for device assignment to virtual machines.
It requires RAWIO permissions and will taint the kernel.
Signed-off-by: Srujana Challa <schalla@marvell.com>
---
drivers/vhost/vdpa.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 5a49b5a6d496..b3085189ea4a 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -36,6 +36,11 @@ enum {
#define VHOST_VDPA_IOTLB_BUCKETS 16
+bool vhost_vdpa_noiommu;
+module_param_named(enable_vhost_vdpa_unsafe_noiommu_mode,
+ vhost_vdpa_noiommu, bool, 0644);
+MODULE_PARM_DESC(enable_vhost_vdpa_unsafe_noiommu_mode, "Enable UNSAFE, no-IOMMU mode. This mode provides no device isolation, no DMA translation, no host kernel protection, cannot be used for device assignment to virtual machines, requires RAWIO permissions, and will taint the kernel. If you do not know what this is for, step away. (default: false)");
+
struct vhost_vdpa_as {
struct hlist_node hash_link;
struct vhost_iotlb iotlb;
@@ -60,6 +65,7 @@ struct vhost_vdpa {
struct vdpa_iova_range range;
u32 batch_asid;
bool suspended;
+ bool noiommu_en;
};
static DEFINE_IDA(vhost_vdpa_ida);
@@ -910,6 +916,10 @@ static void vhost_vdpa_general_unmap(struct vhost_vdpa *v,
{
struct vdpa_device *vdpa = v->vdpa;
const struct vdpa_config_ops *ops = vdpa->config;
+
+ if (v->noiommu_en)
+ return;
+
if (ops->dma_map) {
ops->dma_unmap(vdpa, asid, map->start, map->size);
} else if (ops->set_map == NULL) {
@@ -1003,6 +1013,9 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,
if (r)
return r;
+ if (v->noiommu_en)
+ goto skip_map;
+
if (ops->dma_map) {
r = ops->dma_map(vdpa, asid, iova, size, pa, perm, opaque);
} else if (ops->set_map) {
@@ -1018,6 +1031,7 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,
return r;
}
+skip_map:
if (!vdpa->use_va)
atomic64_add(PFN_DOWN(size), &dev->mm->pinned_vm);
@@ -1321,12 +1335,26 @@ static int vhost_vdpa_alloc_domain(struct vhost_vdpa *v)
struct vdpa_device *vdpa = v->vdpa;
const struct vdpa_config_ops *ops = vdpa->config;
struct device *dma_dev = vdpa_get_dma_dev(vdpa);
+ struct iommu_domain *domain;
int ret;
/* Device want to do DMA by itself */
if (ops->set_map || ops->dma_map)
return 0;
+ domain = iommu_get_domain_for_dev(dma_dev);
+ if (!domain && vhost_vdpa_noiommu) {
+ if (!capable(CAP_SYS_RAWIO)) {
+ dev_warn_once(&v->dev, "No RAWIO permissions, couldn't support NOIOMMU\n");
+ return -ENOTSUPP;
+ }
+ add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+ dev_warn(&v->dev, "Adding kernel taint for noiommu on device\n");
+ v->noiommu_en = true;
+ return 0;
+ }
+ v->noiommu_en = false;
+
if (!device_iommu_capable(dma_dev, IOMMU_CAP_CACHE_COHERENCY)) {
dev_warn_once(&v->dev,
"Failed to allocate domain, device is not IOMMU cache coherent capable\n");
--
2.25.1
next prev 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 ` Srujana Challa [this message]
2024-09-21 17:28 ` [PATCH v2 1/2] vhost-vdpa: introduce module parameter for no-IOMMU mode kernel test robot
2024-09-20 14:05 ` [PATCH v2 2/2] vhost-vdpa: introduce NO-IOMMU backend feature bit Srujana Challa
2024-09-24 7:43 ` 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-2-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;
as well as URLs for NNTP newsgroup(s).