From: "Michael S. Tsirkin" <mst@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
"Daniel P . Berrange" <berrange@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>,
Eric Auger <eric.auger@redhat.com>,
Jason Wang <jasowang@redhat.com>,
David Hildenbrand <david@redhat.com>,
qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
Shannon Zhao <shannon.zhaosl@gmail.com>,
Alex Williamson <alex.williamson@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH 8/8] x86-iommu: Fail early if vIOMMU specified after vfio-pci
Date: Thu, 21 Oct 2021 06:49:32 -0400 [thread overview]
Message-ID: <20211021064731-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20211021104259.57754-9-peterx@redhat.com>
On Thu, Oct 21, 2021 at 06:42:59PM +0800, Peter Xu wrote:
> Scan the pci bus to make sure there's no vfio-pci device attached before vIOMMU
> is realized.
>
> Suggested-by: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> hw/i386/x86-iommu.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/hw/i386/x86-iommu.c b/hw/i386/x86-iommu.c
> index 86ad03972e..58abce7edc 100644
> --- a/hw/i386/x86-iommu.c
> +++ b/hw/i386/x86-iommu.c
> @@ -21,6 +21,7 @@
> #include "hw/sysbus.h"
> #include "hw/i386/x86-iommu.h"
> #include "hw/qdev-properties.h"
> +#include "hw/vfio/pci.h"
> #include "hw/i386/pc.h"
> #include "qapi/error.h"
> #include "qemu/error-report.h"
> @@ -103,6 +104,16 @@ IommuType x86_iommu_get_type(void)
> return x86_iommu_default->type;
> }
>
> +static void x86_iommu_pci_dev_hook(PCIBus *bus, PCIDevice *dev, void *opaque)
> +{
> + Error **errp = (Error **)opaque;
> +
> + if (object_dynamic_cast(OBJECT(dev), TYPE_VFIO_PCI)) {
> + error_setg(errp, "Device '%s' must be specified before vIOMMUs",
> + TYPE_VFIO_PCI);
> + }
> +}
> +
> static void x86_iommu_realize(DeviceState *dev, Error **errp)
> {
> X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev);
> @@ -120,6 +131,12 @@ static void x86_iommu_realize(DeviceState *dev, Error **errp)
> return;
> }
>
> + /* Make sure there's no special device plugged before vIOMMU */
> + pci_for_each_device_all(x86_iommu_pci_dev_hook, (void *)errp);
cast not needed here.
> + if (*errp) {
> + return;
> + }
> +
> /* If the user didn't specify IR, choose a default value for it */
> if (x86_iommu->intr_supported == ON_OFF_AUTO_AUTO) {
> x86_iommu->intr_supported = irq_all_kernel ?
> @@ -151,6 +168,7 @@ static Property x86_iommu_properties[] = {
> static void x86_iommu_class_init(ObjectClass *klass, void *data)
> {
> DeviceClass *dc = DEVICE_CLASS(klass);
> +
> dc->realize = x86_iommu_realize;
> device_class_set_props(dc, x86_iommu_properties);
> }
> --
> 2.32.0
next prev parent reply other threads:[~2021-10-21 10:52 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-21 10:42 [PATCH 0/8] pci/iommu: Fail early if vfio-pci detected before vIOMMU Peter Xu
2021-10-21 10:42 ` [PATCH 1/8] pci: Define pci_bus_dev_fn type Peter Xu
2021-10-21 10:53 ` David Hildenbrand
2021-10-21 11:15 ` Eric Auger
2021-10-22 2:16 ` Peter Xu
2021-10-21 11:36 ` Philippe Mathieu-Daudé
2021-10-21 10:42 ` [PATCH 2/8] pci: Export pci_for_each_device_under_bus*() Peter Xu
2021-10-21 10:54 ` David Hildenbrand
2021-10-21 11:32 ` Eric Auger
2021-10-21 11:39 ` Philippe Mathieu-Daudé
2021-10-21 10:42 ` [PATCH 3/8] pci: Use pci_for_each_device_under_bus*() Peter Xu
2021-10-21 10:56 ` David Hildenbrand
2021-10-21 11:34 ` Eric Auger
2021-10-22 2:19 ` Peter Xu
2021-10-21 10:42 ` [PATCH 4/8] pci: Define pci_bus_fn/pci_bus_ret_fn type Peter Xu
2021-10-21 10:57 ` David Hildenbrand
2021-10-21 11:37 ` Eric Auger
2021-10-21 11:44 ` Philippe Mathieu-Daudé
2021-10-21 12:54 ` Philippe Mathieu-Daudé
2021-10-22 2:24 ` Peter Xu
2021-10-21 10:42 ` [PATCH 5/8] pci: Add pci_for_each_root_bus() Peter Xu
2021-10-21 11:00 ` David Hildenbrand
2021-10-21 12:22 ` Eric Auger
2021-10-25 13:16 ` Michael S. Tsirkin
2021-10-28 2:56 ` Peter Xu
2021-10-21 10:42 ` [PATCH 6/8] pci: Use pci_for_each_root_bus() in current code Peter Xu
2021-10-21 11:06 ` David Hildenbrand
2021-10-21 12:28 ` Eric Auger
2021-10-21 10:42 ` [PATCH 7/8] pci: Add pci_for_each_device_all() Peter Xu
2021-10-21 10:54 ` Michael S. Tsirkin
2021-10-22 2:33 ` Peter Xu
2021-10-22 8:43 ` Michael S. Tsirkin
2021-10-25 12:57 ` Peter Xu
2021-10-25 13:13 ` Michael S. Tsirkin
2021-10-21 10:42 ` [PATCH 8/8] x86-iommu: Fail early if vIOMMU specified after vfio-pci Peter Xu
2021-10-21 10:49 ` Michael S. Tsirkin [this message]
2021-10-21 12:38 ` Eric Auger
2021-10-22 2:37 ` Peter Xu
2021-10-21 22:30 ` Alex Williamson
2021-10-22 2:14 ` Peter Xu
2021-10-26 15:11 ` Igor Mammedov
2021-10-26 15:38 ` Alex Williamson
2021-10-27 8:30 ` Peter Xu
2021-10-28 2:30 ` 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=20211021064731-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=david@redhat.com \
--cc=ehabkost@redhat.com \
--cc=eric.auger@redhat.com \
--cc=imammedo@redhat.com \
--cc=jasowang@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=shannon.zhaosl@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.