From: CLEMENT MATHIEU--DRIF <clement.mathieu--drif@eviden.com>
To: Zhenzhong Duan <zhenzhong.duan@intel.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "alex.williamson@redhat.com" <alex.williamson@redhat.com>,
"clg@redhat.com" <clg@redhat.com>,
"eric.auger@redhat.com" <eric.auger@redhat.com>,
"mst@redhat.com" <mst@redhat.com>,
"jasowang@redhat.com" <jasowang@redhat.com>,
"yi.l.liu@intel.com" <yi.l.liu@intel.com>
Subject: Re: [PATCH v2 2/3] intel_iommu: Simplify caching mode check with VFIO device
Date: Wed, 1 Oct 2025 06:44:55 +0000 [thread overview]
Message-ID: <a9a033d5a5422da97e808277b0400bd65466dbcf.camel@eviden.com> (raw)
In-Reply-To: <20250929034206.439266-3-zhenzhong.duan@intel.com>
Hi zhenzhong,
Thanks for the respin.
Just a few comments in the commit message.
On Sun, 2025-09-28 at 23:42 -0400, Zhenzhong Duan wrote:
> In early days, we have different tricks to ensure caching-mode=on with VFIO
s/have/had
> device:
>
> 28cf553afe ("intel_iommu: Sanity check vfio-pci config on machine init done")
> c6cbc29d36 ("pc/q35: Disallow vfio-pci hotplug without VT-d caching mode")
>
> There is also a patch of same purpose but for VDPA device:
s/of same/with the same
>
> b8d78277c0 ("intel-iommu: fail MAP notifier without caching mode")
>
> Because without caching mode, MAP notifier won't work correctly since guest
> won't send IOTLB update event when it establishes new mappings in the I/O page
> tables.
>
> Now with host IOMMU device interface between VFIO and vIOMMU, we can simplify
> first two commits above with a small check in set_iommu_device(). This also
> works for future IOMMUFD backed VDPA implementation which may also need caching
> mode on. But for legacy VDPA we still need commit b8d78277c0 as it doesn't
> use host IOMMU device interface.
s/use host/use the host
>
> For coldplug VFIO device:
>
> qemu-system-x86_64: -device vfio-pci,host=0000:3b:00.0,id=hostdev3,bus=root0,iommufd=iommufd0: vfio 0000:3b:00.0: Failed to set vIOMMU: Device assignment is not allowed without enabling caching-mode=on for Intel IOMMU.
>
> For hotplug VFIO device:
>
> if "iommu=off" is configured in guest,
> Error: vfio 0000:3b:00.0: Failed to set vIOMMU: Device assignment is not allowed without enabling caching-mode=on for Intel IOMMU.
> else
> Error: vfio 0000:3b:00.0: memory listener initialization failed: Region vtd-00.0-dmar: device 01.00.0 requires caching mode: Operation not supported
>
> The specialty for hotplug is due to the check in commit b8d78277c0 happen before
> the check in set_iommu_device.
>
> Signed-off-by: Zhenzhong Duan <[zhenzhong.duan@intel.com](mailto:zhenzhong.duan@intel.com)>
> ---
> hw/i386/intel_iommu.c | 40 ++++++----------------------------------
> hw/i386/pc.c | 20 --------------------
> 2 files changed, 6 insertions(+), 54 deletions(-)
>
> diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
> index f04300022e..c634121514 100644
> --- a/hw/i386/intel_iommu.c
> +++ b/hw/i386/intel_iommu.c
> @@ -85,13 +85,6 @@ struct vtd_iotlb_key {
> static void vtd_address_space_refresh_all(IntelIOMMUState *s);
> static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n);
>
> -static void vtd_panic_require_caching_mode(void)
> -{
> - error_report("We need to set caching-mode=on for intel-iommu to enable "
> - "device assignment with IOMMU protection.");
> - exit(1);
> -}
> -
> static void vtd_define_quad(IntelIOMMUState *s, hwaddr addr, uint64_t val,
> uint64_t wmask, uint64_t w1cmask)
> {
> @@ -4378,6 +4371,12 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, void *opaque, int devfn,
>
> assert(hiod);
>
> + if (!s->caching_mode) {
> + error_setg(errp, "Device assignment is not allowed without enabling "
> + "caching-mode=on for Intel IOMMU.");
> + return false;
> + }
> +
> vtd_iommu_lock(s);
>
> if (g_hash_table_lookup(s->vtd_host_iommu_dev, &key)) {
> @@ -4910,32 +4909,6 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp)
> return true;
> }
>
> -static int vtd_machine_done_notify_one(Object *child, void *unused)
> -{
> - IntelIOMMUState *iommu = INTEL_IOMMU_DEVICE(x86_iommu_get_default());
> -
> - /*
> - * We hard-coded here because vfio-pci is the only special case
> - * here. Let's be more elegant in the future when we can, but so
> - * far there seems to be no better way.
> - */
> - if (object_dynamic_cast(child, "vfio-pci") && !iommu->caching_mode) {
> - vtd_panic_require_caching_mode();
> - }
> -
> - return 0;
> -}
> -
> -static void vtd_machine_done_hook(Notifier *notifier, void *unused)
> -{
> - object_child_foreach_recursive(object_get_root(),
> - vtd_machine_done_notify_one, NULL);
> -}
> -
> -static Notifier vtd_machine_done_notify = {
> - .notify = vtd_machine_done_hook,
> -};
> -
> static void vtd_realize(DeviceState *dev, Error **errp)
> {
> MachineState *ms = MACHINE(qdev_get_machine());
> @@ -4990,7 +4963,6 @@ static void vtd_realize(DeviceState *dev, Error **errp)
> pci_setup_iommu(bus, &vtd_iommu_ops, dev);
> /* Pseudo address space under root PCI bus. */
> x86ms->ioapic_as = vtd_host_dma_iommu(bus, s, Q35_PSEUDO_DEVFN_IOAPIC);
> - qemu_add_machine_init_done_notifier(&vtd_machine_done_notify);
> }
>
> static void vtd_class_init(ObjectClass *klass, const void *data)
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index bc048a6d13..01cd9a67db 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -1720,25 +1720,6 @@ static void pc_machine_wakeup(MachineState *machine)
> cpu_synchronize_all_post_reset();
> }
>
> -static bool pc_hotplug_allowed(MachineState *ms, DeviceState *dev, Error **errp)
> -{
> - X86IOMMUState *iommu = x86_iommu_get_default();
> - IntelIOMMUState *intel_iommu;
> -
> - if (iommu &&
> - object_dynamic_cast((Object *)iommu, TYPE_INTEL_IOMMU_DEVICE) &&
> - object_dynamic_cast((Object *)dev, "vfio-pci")) {
> - intel_iommu = INTEL_IOMMU_DEVICE(iommu);
> - if (!intel_iommu->caching_mode) {
> - error_setg(errp, "Device assignment is not allowed without "
> - "enabling caching-mode=on for Intel IOMMU.");
> - return false;
> - }
> - }
> -
> - return true;
> -}
> -
> static void pc_machine_class_init(ObjectClass *oc, const void *data)
> {
> MachineClass *mc = MACHINE_CLASS(oc);
> @@ -1758,7 +1739,6 @@ static void pc_machine_class_init(ObjectClass *oc, const void *data)
> x86mc->apic_xrupt_override = true;
> assert(!mc->get_hotplug_handler);
> mc->get_hotplug_handler = pc_get_hotplug_handler;
> - mc->hotplug_allowed = pc_hotplug_allowed;
> mc->auto_enable_numa_with_memhp = true;
> mc->auto_enable_numa_with_memdev = true;
> mc->has_hotpluggable_cpus = true;
next prev parent reply other threads:[~2025-10-01 6:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 3:42 [PATCH v2 0/3] Enable ESRTPS and simplify caching-mode=on check Zhenzhong Duan
2025-09-29 3:42 ` [PATCH v2 1/3] intel_iommu: Enable Enhanced Set Root Table Pointer Support (ESRTPS) Zhenzhong Duan
2025-09-29 3:42 ` [PATCH v2 2/3] intel_iommu: Simplify caching mode check with VFIO device Zhenzhong Duan
2025-10-01 6:44 ` CLEMENT MATHIEU--DRIF [this message]
2025-10-08 10:20 ` Duan, Zhenzhong
2025-09-29 3:42 ` [PATCH v2 3/3] pci: Fix wrong parameter passing to pci_device_get_iommu_bus_devfn() Zhenzhong Duan
2025-10-01 6:45 ` CLEMENT MATHIEU--DRIF
2025-10-01 7:22 ` Cédric Le Goater
2025-10-08 10:15 ` Duan, Zhenzhong
2025-10-08 11:02 ` CLEMENT MATHIEU--DRIF
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=a9a033d5a5422da97e808277b0400bd65466dbcf.camel@eviden.com \
--to=clement.mathieu--drif@eviden.com \
--cc=alex.williamson@redhat.com \
--cc=clg@redhat.com \
--cc=eric.auger@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yi.l.liu@intel.com \
--cc=zhenzhong.duan@intel.com \
/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).