From: Alex Williamson <alex.williamson@redhat.com>
To: Philipp Stanner <pstanner@redhat.com>
Cc: "Damien Le Moal" <dlemoal@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] PCI: Fix devres regression in pci_intx()
Date: Wed, 4 Sep 2024 12:07:21 -0600 [thread overview]
Message-ID: <20240904120721.25626da9.alex.williamson@redhat.com> (raw)
In-Reply-To: <dcbf9292616816bbce020994adb18e2c32597aeb.camel@redhat.com>
On Wed, 04 Sep 2024 15:37:25 +0200
Philipp Stanner <pstanner@redhat.com> wrote:
> On Wed, 2024-09-04 at 17:25 +0900, Damien Le Moal wrote:
> > On 2024/09/04 16:06, Philipp Stanner wrote:
> > > On Tue, 2024-09-03 at 09:44 -0600, Alex Williamson wrote:
> > > > On Thu, 25 Jul 2024 14:07:30 +0200
> > > > Philipp Stanner <pstanner@redhat.com> wrote:
> > > >
> > > > > pci_intx() is a function that becomes managed if
> > > > > pcim_enable_device()
> > > > > has been called in advance. Commit 25216afc9db5 ("PCI: Add
> > > > > managed
> > > > > pcim_intx()") changed this behavior so that pci_intx() always
> > > > > leads
> > > > > to
> > > > > creation of a separate device resource for itself, whereas
> > > > > earlier,
> > > > > a
> > > > > shared resource was used for all PCI devres operations.
> > > > >
> > > > > Unfortunately, pci_intx() seems to be used in some drivers'
> > > > > remove()
> > > > > paths; in the managed case this causes a device resource to be
> > > > > created
> > > > > on driver detach.
> > > > >
> > > > > Fix the regression by only redirecting pci_intx() to its
> > > > > managed
> > > > > twin
> > > > > pcim_intx() if the pci_command changes.
> > > > >
> > > > > Fixes: 25216afc9db5 ("PCI: Add managed pcim_intx()")
> > > >
> > > > I'm seeing another issue from this, which is maybe a more general
> > > > problem with managed mode. In my case I'm using vfio-pci to
> > > > assign
> > > > an
> > > > ahci controller to a VM.
> > >
> > > "In my case" doesn't mean OOT, does it? I can't fully follow.
> > >
> > > > ahci_init_one() calls pcim_enable_device()
> > > > which sets is_managed = true. I notice that nothing ever sets
> > > > is_managed to false. Therefore now when I call pci_intx() from
> > > > vfio-
> > > > pci
> > > > under spinlock, I get a lockdep warning
> > >
> > > I suppose you see the lockdep warning because the new pcim_intx()
> > > can
> > > now allocate, whereas before 25216afc9db5 it was
> > > pcim_enable_device()
> > > which allocated *everything* related to PCI devres.
> > >
> > > > as I no go through pcim_intx()
> > > > code after 25216afc9db5
> > >
> > > You alwas went through pcim_intx()'s logic. The issue seems to be
> > > that
> > > the allocation step was moved.
> > >
> > > > since the previous driver was managed.
> > >
> > > what do you mean by "previous driver"?
> >
> > The AHCI driver... When attaching a PCI dev to vfio to e.g.
> > passthrough to a VM,
> > the device driver must first be unbound and the device bound to vfio-
> > pci. So we
> > switch from ahci/libata driver to vfio. When vfio tries to enable
> > intx with
> > is_managed still true from the use of the device by ahci, problem
> > happen.
> >
> > >
> > > > It seems
> > > > like we should be setting is_managed to false is the driver
> > > > release
> > > > path, right?
> > >
> > > So the issue seems to be that the same struct pci_dev can be used
> > > by
> > > different drivers, is that correct?
> > >
> > > If so, I think that can be addressed trough having
> > > pcim_disable_device() set is_managed to false as you suggest.
> > >
> > > Another solution can could at least consider would be to use a
> > > GFP_ATOMIC for allocation in get_or_create_intx_devres().
> >
> > If it is allowed to call pci_intx() under a spin_lock, then we need
> > GFP_ATOMIC.
> > If not, then vfio-pci needs to move the call out of the spinlock.
>
> If vfio-pci can get rid of pci_intx() alltogether, that might be a good
> thing. As far as I understood Andy Shevchenko, pci_intx() is outdated.
> There's only a hand full of users anyways.
What's the alternative? vfio-pci has a potentially unique requirement
here, we don't know how to handle the device interrupt, we only forward
it to the userspace driver. As a level triggered interrupt, INTx will
continue to assert until that userspace driver handles the device.
That's obviously unacceptable from a host perspective, so INTx is
masked at the device via pci_intx() where available, or at the
interrupt controller otherwise. The API with the userspace driver
requires that driver to unmask the interrupt, again resulting in a call
to pci_intx() or unmasking the interrupt controller, in order to receive
further interrupts from the device. Thanks,
Alex
next prev parent reply other threads:[~2024-09-04 18:07 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-25 12:07 [PATCH] PCI: Fix devres regression in pci_intx() Philipp Stanner
2024-07-25 14:26 ` Christoph Hellwig
2024-07-25 15:21 ` Philipp Stanner
2024-07-25 15:47 ` Christoph Hellwig
2024-07-25 21:00 ` Bjorn Helgaas
2024-07-26 0:19 ` Damien Le Moal
2024-07-26 18:43 ` pstanner
2024-07-26 18:59 ` Bjorn Helgaas
2024-07-29 11:29 ` Damien Le Moal
2024-07-29 15:45 ` Philipp Stanner
2024-09-03 15:44 ` Alex Williamson
2024-09-04 7:06 ` Philipp Stanner
2024-09-04 8:25 ` Damien Le Moal
2024-09-04 13:37 ` Philipp Stanner
2024-09-04 18:07 ` Alex Williamson [this message]
2024-09-04 20:24 ` Andy Shevchenko
2024-09-04 21:10 ` Alex Williamson
2024-09-05 0:33 ` Damien Le Moal
2024-09-05 1:56 ` Alex Williamson
2024-09-05 7:13 ` Philipp Stanner
2024-09-06 0:37 ` Damien Le Moal
2024-09-06 6:45 ` Philipp Stanner
2024-09-04 12:57 ` Alex Williamson
2024-09-04 13:29 ` Philipp Stanner
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=20240904120721.25626da9.alex.williamson@redhat.com \
--to=alex.williamson@redhat.com \
--cc=bhelgaas@google.com \
--cc=dlemoal@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=pstanner@redhat.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