From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Benjamin Block <bblock@linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Niklas Schnelle <schnelle@linux.ibm.com>,
Farhan Ali <alifm@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
linux-s390 <linux-s390@vger.kernel.org>,
Andreas Krebbel <krebbel@linux.ibm.com>,
Julian Ruess <julianr@linux.ibm.com>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Gerd Bayer <gbayer@linux.ibm.com>,
linux-pci <linux-pci@vger.kernel.org>,
Tobias Schumacher <ts@linux.ibm.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
Ionut Nechita <ionut.nechita@windriver.com>,
Ionut Nechita <ionut_n2001@yahoo.com>
Subject: Re: [PATCH 4/4] s390/pci: Use lock guard for pci_rescan_remove_lock
Date: Mon, 9 Mar 2026 09:38:45 +0200 (EET) [thread overview]
Message-ID: <4ad9163b-8ab6-841d-4a58-d10c7f4cdd07@linux.intel.com> (raw)
In-Reply-To: <7be9c8ad56f5ef9366316c3621dece9a10f3eb8b.1772815642.git.bblock@linux.ibm.com>
On Fri, 6 Mar 2026, Benjamin Block wrote:
> There are quite a few places in the s390 architecture code for the PCI
> subsystem where the kernel needs to lock `pci_rescan_remove_lock` now;
> which is done by calling pci_lock_rescan_remove() to lock, and
> pci_unlock_rescan_remove() to unlock the mutex.
>
> Instead of always manually calling both functions, which induces a
> certain amount of visual clutter, and in some cases of errors, cleanup,
> and jumplabels more complexity, use either guard() or scoped_guard()
> depending on the context.
>
> Convert all users in the s390 architecture code for PCI.
>
> Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
> ---
> arch/s390/pci/pci.c | 8 +++----
> arch/s390/pci/pci_bus.c | 3 +--
> arch/s390/pci/pci_event.c | 45 +++++++++++++++++----------------------
> arch/s390/pci/pci_iov.c | 3 +--
> arch/s390/pci/pci_sysfs.c | 9 +++-----
> 5 files changed, 27 insertions(+), 41 deletions(-)
>
> diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
> index fd16e6ad21c1..86ef1e516857 100644
> --- a/arch/s390/pci/pci.c
> +++ b/arch/s390/pci/pci.c
> @@ -632,10 +632,9 @@ void pcibios_release_device(struct pci_dev *pdev)
> {
> struct zpci_dev *zdev = to_zpci(pdev);
>
> - pci_lock_rescan_remove();
> + guard(pci_rescan_remove)();
> zpci_unmap_resources(pdev);
> zpci_zdev_put(zdev);
> - pci_unlock_rescan_remove();
> }
>
> int pcibios_enable_device(struct pci_dev *pdev, int mask)
> @@ -1213,9 +1212,8 @@ static int __init pci_base_init(void)
> if (rc)
> goto out_irq;
>
> - pci_lock_rescan_remove();
> - rc = zpci_scan_devices();
> - pci_unlock_rescan_remove();
> + scoped_guard(pci_rescan_remove)
> + rc = zpci_scan_devices();
> if (rc)
> goto out_find;
>
> diff --git a/arch/s390/pci/pci_bus.c b/arch/s390/pci/pci_bus.c
> index 2b598222c621..c1b48b572e86 100644
> --- a/arch/s390/pci/pci_bus.c
> +++ b/arch/s390/pci/pci_bus.c
> @@ -82,9 +82,8 @@ int zpci_bus_scan_device(struct zpci_dev *zdev)
> if (!pdev)
> return -ENODEV;
>
> - pci_lock_rescan_remove();
> + guard(pci_rescan_remove)();
> pci_bus_add_device(pdev);
> - pci_unlock_rescan_remove();
>
> return 0;
> }
> diff --git a/arch/s390/pci/pci_event.c b/arch/s390/pci/pci_event.c
> index edfaeed737ac..98253706b591 100644
> --- a/arch/s390/pci/pci_event.c
> +++ b/arch/s390/pci/pci_event.c
> @@ -342,9 +342,8 @@ static void __zpci_event_error(struct zpci_ccdf_err *ccdf)
> no_pdev:
> if (zdev)
> mutex_unlock(&zdev->state_lock);
> - pci_lock_rescan_remove();
> + guard(pci_rescan_remove)();
> zpci_zdev_put(zdev);
> - pci_unlock_rescan_remove();
> }
>
> void zpci_event_error(void *data)
> @@ -389,7 +388,6 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
> struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
> bool existing_zdev = !!zdev;
> enum zpci_state state;
> - int rc;
>
> zpci_dbg(3, "avl fid:%x, fh:%x, pec:%x\n",
> ccdf->fid, ccdf->fh, ccdf->pec);
> @@ -403,12 +401,11 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
> zdev = zpci_create_device(ccdf->fid, ccdf->fh, ZPCI_FN_STATE_CONFIGURED);
> if (IS_ERR(zdev))
> break;
> - pci_lock_rescan_remove();
> - rc = zpci_add_device(zdev);
> - pci_unlock_rescan_remove();
> - if (rc) {
> - kfree(zdev);
> - break;
> + scoped_guard(pci_rescan_remove) {
> + if (zpci_add_device(zdev)) {
> + kfree(zdev);
> + break;
> + }
> }
> } else {
> if (zdev->state == ZPCI_FN_STATE_RESERVED)
> @@ -425,12 +422,11 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
> zdev = zpci_create_device(ccdf->fid, ccdf->fh, ZPCI_FN_STATE_STANDBY);
> if (IS_ERR(zdev))
> break;
> - pci_lock_rescan_remove();
> - rc = zpci_add_device(zdev);
> - pci_unlock_rescan_remove();
> - if (rc) {
> - kfree(zdev);
> - break;
> + scoped_guard(pci_rescan_remove) {
> + if (zpci_add_device(zdev)) {
> + kfree(zdev);
> + break;
> + }
> }
> } else {
> if (zdev->state == ZPCI_FN_STATE_RESERVED)
> @@ -459,33 +455,30 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
> /* The 0x0304 event may immediately reserve the device */
> if (!clp_get_state(zdev->fid, &state) &&
> state == ZPCI_FN_STATE_RESERVED) {
> - pci_lock_rescan_remove();
> + guard(pci_rescan_remove)();
> zpci_device_reserved(zdev);
> - pci_unlock_rescan_remove();
> }
> }
> break;
> case 0x0306: /* 0x308 or 0x302 for multiple devices */
> - pci_lock_rescan_remove();
> - zpci_remove_reserved_devices();
> - zpci_scan_devices();
> - pci_unlock_rescan_remove();
> + scoped_guard(pci_rescan_remove) {
> + zpci_remove_reserved_devices();
> + zpci_scan_devices();
> + }
> break;
> case 0x0308: /* Standby -> Reserved */
> if (!zdev)
> break;
> - pci_lock_rescan_remove();
> - zpci_device_reserved(zdev);
> - pci_unlock_rescan_remove();
> + scoped_guard(pci_rescan_remove)
> + zpci_device_reserved(zdev);
Order in this series is weird. Why not introduce *guard() support before
the fix (reorder patches 2 and 3) and then use guard direct here so you
don't have to immediately change the code again to "convert" it to use
*guard() in patch 4?
--
i.
> break;
> default:
> break;
> }
> if (existing_zdev) {
> mutex_unlock(&zdev->state_lock);
> - pci_lock_rescan_remove();
> + guard(pci_rescan_remove)();
> zpci_zdev_put(zdev);
> - pci_unlock_rescan_remove();
> }
> }
>
> diff --git a/arch/s390/pci/pci_iov.c b/arch/s390/pci/pci_iov.c
> index 13050ce5c3e9..1f7e4dd018e7 100644
> --- a/arch/s390/pci/pci_iov.c
> +++ b/arch/s390/pci/pci_iov.c
> @@ -38,10 +38,9 @@ void zpci_iov_map_resources(struct pci_dev *pdev)
>
> void zpci_iov_remove_virtfn(struct pci_dev *pdev, int vfn)
> {
> - pci_lock_rescan_remove();
> + guard(pci_rescan_remove)();
> /* Linux' vfid's start at 0 vfn at 1 */
> pci_iov_remove_virtfn(pdev->physfn, vfn - 1);
> - pci_unlock_rescan_remove();
> }
>
> static int zpci_iov_link_virtfn(struct pci_dev *pdev, struct pci_dev *virtfn, int vfid)
> diff --git a/arch/s390/pci/pci_sysfs.c b/arch/s390/pci/pci_sysfs.c
> index c2444a23e26c..f5027aa95928 100644
> --- a/arch/s390/pci/pci_sysfs.c
> +++ b/arch/s390/pci/pci_sysfs.c
> @@ -98,9 +98,9 @@ static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
> WARN_ON_ONCE(!kn);
>
> /* Device needs to be configured and state must not change */
> - mutex_lock(&zdev->state_lock);
> + guard(mutex)(&zdev->state_lock);
> if (zdev->state != ZPCI_FN_STATE_CONFIGURED)
> - goto out;
> + return count;
>
> /* device_remove_file() serializes concurrent calls ignoring all but
> * the first
> @@ -112,15 +112,12 @@ static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
> * Once it unblocks from pci_lock_rescan_remove() the original pdev
> * will already be removed.
> */
> - pci_lock_rescan_remove();
> + guard(pci_rescan_remove)();
> if (pci_dev_is_added(pdev)) {
> ret = _do_recover(pdev, zdev);
> }
> pci_rescan_bus(zdev->zbus->bus);
> - pci_unlock_rescan_remove();
>
> -out:
> - mutex_unlock(&zdev->state_lock);
> if (kn)
> sysfs_unbreak_active_protection(kn);
> return ret ? ret : count;
>
next prev parent reply other threads:[~2026-03-09 7:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 16:49 [PATCH 0/4] PCI: s390/pci: Fix deadlocks on s390 when releasing zPCI-bus or -device objects Benjamin Block
2026-03-06 16:49 ` [PATCH 1/4] PCI: Move declaration of pci_rescan_remove_lock into public pci.h Benjamin Block
2026-03-06 17:31 ` Keith Busch
2026-03-06 18:01 ` Benjamin Block
2026-03-06 16:49 ` [PATCH 2/4] s390/pci: Fix circular/recursive deadlocks in PCI-bus and -device release Benjamin Block
2026-03-06 16:49 ` [PATCH 3/4] PCI: Provide lock guard for pci_rescan_remove_lock Benjamin Block
2026-03-06 16:49 ` [PATCH 4/4] s390/pci: Use " Benjamin Block
2026-03-09 7:38 ` Ilpo Järvinen [this message]
2026-03-09 10:54 ` Benjamin Block
2026-03-09 15:49 ` Niklas Schnelle
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=4ad9163b-8ab6-841d-4a58-d10c7f4cdd07@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=agordeev@linux.ibm.com \
--cc=alifm@linux.ibm.com \
--cc=bblock@linux.ibm.com \
--cc=bhelgaas@google.com \
--cc=borntraeger@linux.ibm.com \
--cc=gbayer@linux.ibm.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=ionut.nechita@windriver.com \
--cc=ionut_n2001@yahoo.com \
--cc=julianr@linux.ibm.com \
--cc=krebbel@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mjrosato@linux.ibm.com \
--cc=schnelle@linux.ibm.com \
--cc=svens@linux.ibm.com \
--cc=ts@linux.ibm.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
Powered by JetHome