From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Jason Wang" <jasowang@redhat.com>,
peterx@redhat.com, "Eric Auger" <eric.auger@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Eugenio Pérez" <eperezma@redhat.com>
Subject: [PATCH] x86-iommu: Fail flag registration of DEVIOTLB if DT not supported
Date: Tue, 18 Oct 2022 17:54:07 -0400 [thread overview]
Message-ID: <20221018215407.363986-1-peterx@redhat.com> (raw)
All x86 IOMMUs need to fail DEVIOTLB notification registrations if DT is
not supported. Otherwise any device (e.g. vhost) can register with
DEVIOTLB but it'll never receive the notifications, causing device not
operational.
Fixes: b68ba1ca57 ("memory: Add IOMMU_NOTIFIER_DEVIOTLB_UNMAP IOMMUTLBNotificationType")
Reported-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
hw/i386/amd_iommu.c | 8 ++++++++
hw/i386/intel_iommu.c | 7 +++++++
2 files changed, 15 insertions(+)
diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 725f69095b..42486e790f 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -1476,6 +1476,7 @@ static int amdvi_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
Error **errp)
{
AMDVIAddressSpace *as = container_of(iommu, AMDVIAddressSpace, iommu);
+ X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(as->iommu_state);
if (new & IOMMU_NOTIFIER_MAP) {
error_setg(errp,
@@ -1484,6 +1485,13 @@ static int amdvi_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
PCI_FUNC(as->devfn));
return -EINVAL;
}
+
+ if ((new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) && !x86_iommu->dt_supported) {
+ error_setg_errno(errp, ENOTSUP,
+ "Device-iotlb not declared support for vIOMMU");
+ return -ENOTSUP;
+ }
+
return 0;
}
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 6524c2ee32..a07d9631b0 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3057,6 +3057,7 @@ static int vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
{
VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu);
IntelIOMMUState *s = vtd_as->iommu_state;
+ X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s);
/* TODO: add support for VFIO and vhost users */
if (s->snoop_control) {
@@ -3065,6 +3066,12 @@ static int vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
return -ENOTSUP;
}
+ if ((new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) && !x86_iommu->dt_supported) {
+ error_setg_errno(errp, ENOTSUP,
+ "Device-iotlb not declared support for vIOMMU");
+ return -ENOTSUP;
+ }
+
/* Update per-address-space notifier flags */
vtd_as->notifier_flags = new;
--
2.37.3
next reply other threads:[~2022-10-18 21:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-18 21:54 Peter Xu [this message]
2022-10-19 5:45 ` [PATCH] x86-iommu: Fail flag registration of DEVIOTLB if DT not supported Jason Wang
2022-10-19 11:24 ` Eric Auger
2022-10-19 14:01 ` Peter Xu
2022-10-19 14:12 ` Eric Auger
2022-10-19 14:54 ` Peter Xu
2022-10-20 3:58 ` Jason Wang
2022-10-20 16:45 ` Peter Xu
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=20221018215407.363986-1-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=eperezma@redhat.com \
--cc=eric.auger@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).