mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Cercueil <paul.cercueil@bootlin.com>
To: Lukas Wunner <lukas@wunner.de>
Cc: Qiang Yu <qiang.yu@oss.qualcomm.com>,
	Will Deacon <will@kernel.org>,
	 Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Krzysztof Wilczy??ski <kwilczynski@kernel.org>,
	Manivannan Sadhasivam	 <mani@kernel.org>,
	Rob Herring <robh@kernel.org>,
	Bjorn Helgaas	 <bhelgaas@google.com>,
	Nirmal Patel <nirmal.patel@linux.intel.com>,
	Jonathan Derrick <jonathan.derrick@linux.dev>,
	Frank Li <Frank.Li@nxp.com>,
	Manivannan Sadhasivam	 <manivannan.sadhasivam@oss.qualcomm.com>,
	linux-pci@vger.kernel.org, 	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH RFC v2] PCI: pciehp: Fix AB-BA deadlocks between reset_lock, pci_rescan_remove_lock and pci_slot_mutex
Date: Tue, 01 Dec 2026 11:50:15 +0100	[thread overview]
Message-ID: <4c2839a6fb889d0b66d6b6da03a74bce85849ab6.camel@bootlin.com> (raw)
In-Reply-To: <aw6clF7BdEESiMHc@wunner.de>

Le mardi 01 décembre 2026 à 11:08 +0100, Lukas Wunner a écrit :
> On Tue, Dec 01, 2026 at 10:08:18AM +0100, Paul Cercueil wrote:
> > Le dimanche 29 novembre 2026 à 22:06 +0100, Lukas Wunner a écrit :
> > > Why is it necessary to lock rescan/remove for a reset?
> > > This looks wrong.  I suggest removing pci_lock_rescan_remove()
> > > from pci_host_reset_root_port().
> > 
> > Manivannan said in the v7's cover letter:
> > https://lore.kernel.org/linux-pci/20260310-pci-port-reset-v7-0-9dd00ccc25ab@oss.qualcomm.com/
> > 
> > "Added pci_{lock/unlock}_rescan_remove() to guard pci_bus_error_reset() as
> > the
> > device could be removed in-between due to Native hotplug interrupt."
> > 
> > On the pciehp side,
> > 
> > pciehp_unconfigure_device()
> >   pci_lock_rescan_remove()
> >   pci_stop_and_remove_bus_device()
> >     pci_remove_bus_device()
> >       pci_destroy_dev()
> > 
> > So if you don't get the unscan lock in the reset path, which can happen in
> > parallel, you risk a use-after-free.
> 
> The proper approach to avoid a use after free is to acquire a reference
> on the pci_dev which is at risk of being removed in parallel.
> 
> E.g. in drivers/pci/pcie/aer.c, add_error_device() acquires a reference
> on the error-reporting device and that reference is released in
> aer_process_err_devices().
> 
> It's unclear to me which device you expect to be removed in parallel:
> The Root Port?  That can't happen via pciehp.  The Root Port sits at
> the top of the hierarchy, there's no hotplug-capable port above it
> which pciehp could bind to.
> 
> I guess the Root Port could be removed if the user exercises the "remove"
> attribute in sysfs.  But again, the right way to protect against that is
> to acquire a reference on the Root Port.

Yes, I agree. I was just trying to show why the pci_lock_rescan_remove() was
used there, I am not arguing that it was the best solution.

> But maybe I'm missing something and you want to protect a different device
> than the Root Port against removal?
> 
> I've gone through the review feedback to v6 of Mani's series and I don't
> see anyone reporting a use-after-free, so it's unclear to me why the
> pci_lock_rescan_remove() was added in v7.

I'll send a patch to change it to a reference grab.

Cheers,
-Paul

  reply	other threads:[~2026-12-01 10:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  8:26 Qiang Yu
2026-11-29 21:06 ` Lukas Wunner
2026-12-01  9:08   ` Paul Cercueil
2026-12-01 10:08     ` Lukas Wunner
2026-12-01 10:50       ` Paul Cercueil [this message]
2026-12-01 10:29   ` Qiang Yu
2026-12-01 11:24     ` Lukas Wunner

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=4c2839a6fb889d0b66d6b6da03a74bce85849ab6.camel@bootlin.com \
    --to=paul.cercueil@bootlin.com \
    --cc=Frank.Li@nxp.com \
    --cc=bhelgaas@google.com \
    --cc=jonathan.derrick@linux.dev \
    --cc=kwilczynski@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=lukas@wunner.de \
    --cc=mani@kernel.org \
    --cc=manivannan.sadhasivam@oss.qualcomm.com \
    --cc=nirmal.patel@linux.intel.com \
    --cc=qiang.yu@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=will@kernel.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

all inboxes | Powered by JetHome®