From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
Marc Zyngier <maz@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>, <linux-pci@vger.kernel.org>,
"Nishanth Menon" <nm@ti.com>, Tero Kristo <kristo@kernel.org>,
Santosh Shilimkar <ssantosh@kernel.org>,
Jon Mason <jdmason@kudzu.us>, Dave Jiang <dave.jiang@intel.com>,
Allen Hubbe <allenbh@gmail.com>, <ntb@lists.linux.dev>,
Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, <linux-hyperv@vger.kernel.org>,
Wei Huang <wei.huang2@amd.com>,
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
<linux-scsi@vger.kernel.org>
Subject: Re: [patch 05/10] PCI/MSI: Switch to MSI descriptor locking to guard()
Date: Tue, 11 Mar 2025 18:10:18 +0000 [thread overview]
Message-ID: <20250311181018.0000477f@huawei.com> (raw)
In-Reply-To: <20250309084110.458224773@linutronix.de>
On Sun, 9 Mar 2025 09:41:49 +0100 (CET)
Thomas Gleixner <tglx@linutronix.de> wrote:
> Convert the code to use the new guard(msi_descs_lock).
>
> No functional change intended.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: linux-pci@vger.kernel.org
This one runs into some of the stuff that the docs say
to not do. I don't there there are bugs in here as such
but it gets harder to reason about and fragile in the long
run. Easy enough to avoid though - see inline.
Jonathan
> --- a/drivers/pci/msi/msi.c
> +++ b/drivers/pci/msi/msi.c
> @@ -351,7 +351,7 @@ static int msi_verify_entries(struct pci
> static int msi_capability_init(struct pci_dev *dev, int nvec,
> struct irq_affinity *affd)
> {
> - struct irq_affinity_desc *masks = NULL;
> + struct irq_affinity_desc *masks __free(kfree) = NULL;
This is a pattern that the cleanup.h docs talk about that
Linus really didn't like in some of the early patches because
of wanting constructors and destructors together.
Maybe use an inline definition as
struct irq_affinity_desc *masks =
affd ? irq_create_affinity_masks(nvec, affd) : NULL;
> struct msi_desc *entry, desc;
> int ret;
>
> @@ -369,7 +369,7 @@ static int msi_capability_init(struct pc
> if (affd)
> masks = irq_create_affinity_masks(nvec, affd);
>
> - msi_lock_descs(&dev->dev);
> + guard(msi_descs_lock)(&dev->dev);
> ret = msi_setup_msi_desc(dev, nvec, masks);
> if (ret)
> goto fail;
This runs against the advice in cleanup.h. It is probably
correct and doesn't hit the undefined paths that motivated
that guidance, but still maybe worth avoiding the mix of
cleanup and goto handling.
Easiest way being to factor out the code after guard to a helper.
> @@ -399,16 +399,13 @@ static int msi_capability_init(struct pc
>
> pcibios_free_irq(dev);
> dev->irq = entry->irq;
> - goto unlock;
> + return 0;
>
> err:
> pci_msi_unmask(&desc, msi_multi_mask(&desc));
> pci_free_msi_irqs(dev);
> fail:
> dev->msi_enabled = 0;
> -unlock:
> - msi_unlock_descs(&dev->dev);
> - kfree(masks);
> return ret;
> }
>
> @@ -669,13 +666,13 @@ static void msix_mask_all(void __iomem *
> static int msix_setup_interrupts(struct pci_dev *dev, struct msix_entry *entries,
> int nvec, struct irq_affinity *affd)
> {
> - struct irq_affinity_desc *masks = NULL;
> + struct irq_affinity_desc *masks __free(kfree) = NULL;
Similar to above.
> int ret;
>
> if (affd)
> masks = irq_create_affinity_masks(nvec, affd);
>
> - msi_lock_descs(&dev->dev);
> + guard(msi_descs_lock)(&dev->dev);
> ret = msix_setup_msi_descs(dev, entries, nvec, masks);
> if (ret)
> goto out_free;
> @@ -690,13 +687,10 @@ static int msix_setup_interrupts(struct
> goto out_free;
>
> msix_update_entries(dev, entries);
> - goto out_unlock;
> + return 0;
>
> out_free:
Here as well.
> pci_free_msi_irqs(dev);
> -out_unlock:
> - msi_unlock_descs(&dev->dev);
> - kfree(masks);
> return ret;
> }
>
> @@ -871,13 +865,13 @@ void __pci_restore_msix_state(struct pci
>
> write_msg = arch_restore_msi_irqs(dev);
>
> - msi_lock_descs(&dev->dev);
> - msi_for_each_desc(entry, &dev->dev, MSI_DESC_ALL) {
> - if (write_msg)
> - __pci_write_msi_msg(entry, &entry->msg);
> - pci_msix_write_vector_ctrl(entry, entry->pci.msix_ctrl);
> + scoped_guard (msi_descs_lock, &dev->dev) {
> + msi_for_each_desc(entry, &dev->dev, MSI_DESC_ALL) {
> + if (write_msg)
> + __pci_write_msi_msg(entry, &entry->msg);
> + pci_msix_write_vector_ctrl(entry, entry->pci.msix_ctrl);
> + }
> }
> - msi_unlock_descs(&dev->dev);
>
> pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0);
> }
>
>
>
next prev parent reply other threads:[~2025-03-11 18:10 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-09 8:41 [patch 00/10] genirq/msi: Spring cleaning Thomas Gleixner
2025-03-09 8:41 ` [patch 01/10] genirq/msi: Make a few functions static Thomas Gleixner
2025-03-11 17:45 ` Jonathan Cameron
2025-03-09 8:41 ` [patch 02/10] genirq/msi: Use lock guards for MSI descriptor locking Thomas Gleixner
2025-03-11 18:00 ` Jonathan Cameron
2025-03-11 21:26 ` Thomas Gleixner
2025-03-12 15:08 ` Jonathan Cameron
2025-03-12 17:46 ` Thomas Gleixner
2025-03-09 8:41 ` [patch 03/10] soc: ti: ti_sci_inta_msi: Switch MSI descriptor locking to guard() Thomas Gleixner
2025-03-11 18:01 ` Jonathan Cameron
2025-03-12 17:59 ` Nishanth Menon
2025-03-13 12:07 ` Dhruva Gole
2025-03-09 8:41 ` [patch 04/10] NTB/msi: Switch MSI descriptor locking to lock guard() Thomas Gleixner
2025-03-10 15:18 ` Dave Jiang
2025-03-10 16:34 ` Logan Gunthorpe
2025-03-11 18:02 ` Jonathan Cameron
2025-03-09 8:41 ` [patch 05/10] PCI/MSI: Switch to MSI descriptor locking to guard() Thomas Gleixner
2025-03-11 18:10 ` Jonathan Cameron [this message]
2025-03-11 21:45 ` Thomas Gleixner
2025-03-12 15:10 ` Jonathan Cameron
2025-03-09 8:41 ` [patch 06/10] PCI: hv: Switch " Thomas Gleixner
2025-03-10 16:52 ` Wei Liu
2025-03-10 20:33 ` Michael Kelley
2025-03-11 18:10 ` Jonathan Cameron
2025-03-09 8:41 ` [patch 07/10] PCI/MSI: Provide a sane mechanism for TPH Thomas Gleixner
2025-03-09 8:41 ` [patch 08/10] PCI/TPH: Replace the broken MSI-X control word update Thomas Gleixner
2025-03-09 8:41 ` [patch 09/10] scsi: ufs: qcom: Remove the MSI descriptor abuse Thomas Gleixner
2025-03-09 8:41 ` [patch 10/10] genirq/msi: Rename msi_[un]lock_descs() Thomas Gleixner
2025-03-09 8:48 ` Xin Li
2025-03-11 18:14 ` Jonathan Cameron
2025-03-10 16:51 ` [patch 00/10] genirq/msi: Spring cleaning Bjorn Helgaas
2025-03-10 17:31 ` Thomas Gleixner
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=20250311181018.0000477f@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=allenbh@gmail.com \
--cc=bhelgaas@google.com \
--cc=dave.jiang@intel.com \
--cc=haiyangz@microsoft.com \
--cc=jdmason@kudzu.us \
--cc=kristo@kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=martin.petersen@oracle.com \
--cc=maz@kernel.org \
--cc=nm@ti.com \
--cc=ntb@lists.linux.dev \
--cc=ssantosh@kernel.org \
--cc=tglx@linutronix.de \
--cc=wei.huang2@amd.com \
--cc=wei.liu@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;
as well as URLs for NNTP newsgroup(s).