qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Igor Mammedov <imammedo@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	"Daniel P . Berrange" <berrange@redhat.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	"Michael S . Tsirkin" <mst@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>,
	Eric Auger <eric.auger@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, 28 Oct 2021 10:30:54 +0800	[thread overview]
Message-ID: <YXoLXuoZqxrr8biw@xz-m1.local> (raw)
In-Reply-To: <YXkOGqA02mm/1vQv@xz-m1.local>

On Wed, Oct 27, 2021 at 04:30:18PM +0800, Peter Xu wrote:
> On Tue, Oct 26, 2021 at 05:11:39PM +0200, Igor Mammedov wrote:
> > On Fri, 22 Oct 2021 10:14:29 +0800
> > Peter Xu <peterx@redhat.com> wrote:
> > 
> > > Hi, Alex,
> > > 
> > > On Thu, Oct 21, 2021 at 04:30:39PM -0600, Alex Williamson wrote:
> > > > On Thu, 21 Oct 2021 18:42:59 +0800
> > > > Peter Xu <peterx@redhat.com> wrote:
> > > >   
> > > > > Scan the pci bus to make sure there's no vfio-pci device attached before vIOMMU
> > > > > is realized.  
> > > > 
> > > > Sorry, I'm not onboard with this solution at all.
> > > > 
> > > > It would be really useful though if this commit log or a code comment
> > > > described exactly the incompatibility for which vfio-pci devices are
> > > > being called out here.  Otherwise I see this as a bit of magic voodoo
> > > > that gets lost in lore and copied elsewhere and we're constantly trying
> > > > to figure out specific incompatibilities when vfio-pci devices are
> > > > trying really hard to be "just another device".  
> > > 
> > > Sure, I can enrich the commit message.
> > > 
> > > > 
> > > > I infer from the link of the previous alternate solution that this is
> > > > to do with the fact that vfio devices attach a memory listener to the
> > > > device address space.  
> > > 
> > > IMHO it's not about the memory listeners, I think that' after vfio detected
> > > some vIOMMU memory regions already, which must be based on an vIOMMU address
> > > space being available.  I think the problem is that when realize() vfio-pci we
> > > fetch the dma address space specifically for getting the vfio group, while that
> > > could happen too early, even before vIOMMU is created.
> > > 
> > > > Interestingly that previous cover letter also discusses how vdpa devices
> > > > might have a similar issue, which makes it confusing again that we're calling
> > > > out vfio-pci devices by name rather than for a behavior.  
> > > 
> > > Yes I'll need to see whether this approach will be accepted first.  I think
> > > similar thing could help VDPA but it's not required there because VDPA has
> > > already worked around using pci_device_iommu_address_space().  So potentially
> > > the only one to "fix" is the vfio-pci device using along with vIOMMU, when the
> > > device ordering is specified in the wrong order.  I'll leave the VDPA problem
> > > to Jason to see whether he prefers keeping current code, or switch to a simpler
> > > one.  That should be after this one.
> > > 
> > > > 
> > > > If the behavior here is that vfio-pci devices attach a listener to the
> > > > device address space, then that provides a couple possible options.  We
> > > > could look for devices that have recorded an interest in their address
> > > > space, such as by setting a flag on PCIDevice when someone calls
> > > > pci_device_iommu_address_space(), where we could walk all devices using
> > > > the code in this series to find a device with such a flag.  
> > > 
> > > Right, we can set a flag for all the pci devices that needs to consolidate
> > > pci_device_iommu_address_space() result, however then it'll be vfio-pci only so
> > > far.  Btw, I actually proposed similar things two months ago, and I think Igor
> > > showed concern on that flag being vague on meaning:
> > 
> > (1)
> > > https://lore.kernel.org/qemu-devel/20210906104915.7dd5c934@redhat.com/
> > 
> > > 
> > >   > > Does it need to be a pre_plug hook?  I thought we might just need a flag in the
> > >   > > pci device classes showing that it should be after vIOMMUs, then in vIOMMU
> > >   > > realize functions we walk pci bus to make sure no such device exist?
> > >   > > 
> > >   > > We could have a base vIOMMU class, then that could be in the realize() of the
> > >   > > common class.  
> > >   > 
> > >   > We basically don't know if device needs IOMMU or not and can work
> > >   > with/without it just fine. In this case I'd think about IOMMU as board
> > >   > feature that morphs PCI buses (some of them) (address space, bus numers, ...).
> > >   > So I don't perceive any iommu flag as a device property at all.
> > >   > 
> > >   > As for realize vs pre_plug, the later is the part of abstract realize
> > >   > (see: device_set_realized) and is already used by some PCI infrastructure:
> > >   >   ex: pcie_cap_slot_pre_plug_cb/spapr_pci_pre_plug  
> > > 
> > > I still think that flag will work, that flag should only shows "whether this
> > > device needs to be specified earlier than vIOMMU", but I can get the point from
> > > Igor that it's at least confusing on what does the flag mean.
> > 
> > > Meanwhile I
> > > don't think that flag will be required, as this is not the first time we name a
> > > special device in the code, e.g. pc_machine_device_pre_plug_cb().
> > > intel_iommu.c has it too upon vfio-pci already on making sure caching-mode=on
> > > in vtd_machine_done_notify_one().
> > 
> > I pointed to specifically to _pre_plug() handler and not as
> > implemented here in realize().
> > Reasoning behind it is that some_device_realize() should not poke
> > into other devices, while pc_machine_device_pre_plug_cb() is
> > part of machine code can/may legitimately access its child devices and verify/
> > configure them. (Hence I'd drop my suggested-by with current impl.)
> 
> I see, I didn't try that because I see that q35 even does not have pre_plug()
> installed yet, so I need to add it in the same patchset, am I right?
> 
> Frankly I've also no idea why pc has the pre_plug() but not q35.. But if you
> think that matters then I can try.

I think I know what I'm missing.. there's the pc_get_hotplug_handler() that
conditionally fetch the handler, so when I was trying with q35/VT-d the handler
always returned null..

I'll repost with pre_plug(), thanks.

-- 
Peter Xu



      reply	other threads:[~2021-10-28  2:33 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
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 [this message]

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=YXoLXuoZqxrr8biw@xz-m1.local \
    --to=peterx@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=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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 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).