public inbox for ntb@lists.linux.dev
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Marc Zyngier <maz@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Wei Huang <wei.huang2@amd.com>,
	linux-pci@vger.kernel.org,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Nishanth Menon <nm@ti.com>, Dhruva Gole <d-gole@ti.com>,
	Tero Kristo <kristo@kernel.org>,
	Santosh Shilimkar <ssantosh@kernel.org>,
	Logan Gunthorpe <logang@deltatee.com>,
	Dave Jiang <dave.jiang@intel.com>, Jon Mason <jdmason@kudzu.us>,
	Allen Hubbe <allenbh@gmail.com>,
	ntb@lists.linux.dev, Michael Kelley <mhklinux@outlook.com>,
	Wei Liu <wei.liu@kernel.org>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	linux-hyperv@vger.kernel.org,
	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,
	Jonathan Cameron <Jonathan.Cameron@huwei.com>
Subject: Re: [patch V4 11/14] PCI/MSI: Provide a sane mechanism for TPH
Date: Tue, 17 Jun 2025 18:22:32 -0500	[thread overview]
Message-ID: <20250617232232.GA1175597@bhelgaas> (raw)
In-Reply-To: <20250319105506.683663807@linutronix.de>

On Wed, Mar 19, 2025 at 11:56:57AM +0100, Thomas Gleixner wrote:
> The PCI/TPH driver fiddles with the MSI-X control word of an active
> interrupt completely unserialized against concurrent operations issued
> from the interrupt core. It also brings the PCI/MSI-X internal cached
> control word out of sync.
> 
> Provide a function, which has the required serialization and keeps the
> control word cache in sync.
> 
> Unfortunately this requires to look up and lock the interrupt descriptor,
> which should be only done in the interrupt core code. But confining this
> particular oddity in the PCI/MSI core is the lesser of all evil. A
> interrupt core implementation would require a larger pile of infrastructure
> and indirections for dubious value.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Acked-by: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Wei Huang <wei.huang2@amd.com>
> Cc: linux-pci@vger.kernel.org
> 
> 
> 
> ---
>  drivers/pci/msi/msi.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
>  drivers/pci/pci.h     |    9 +++++++++
>  2 files changed, 56 insertions(+)
> 
> --- a/drivers/pci/msi/msi.c
> +++ b/drivers/pci/msi/msi.c
> @@ -910,6 +910,53 @@ void pci_free_msi_irqs(struct pci_dev *d
>  	}
>  }
>  
> +#ifdef CONFIG_PCIE_TPH
> +/**
> + * pci_msix_write_tph_tag - Update the TPH tag for a given MSI-X vector
> + * @pdev:	The PCIe device to update
> + * @index:	The MSI-X index to update
> + * @tag:	The tag to write
> + *
> + * Returns: 0 on success, error code on failure
> + */
> +int pci_msix_write_tph_tag(struct pci_dev *pdev, unsigned int index, u16 tag)
> +{
> +	struct msi_desc *msi_desc;
> +	struct irq_desc *irq_desc;
> +	unsigned int virq;
> +
> +	if (!pdev->msix_enabled)
> +		return -ENXIO;
> +
> +	guard(msi_descs_lock)(&pdev->dev);
> +	virq = msi_get_virq(&pdev->dev, index);
> +	if (!virq)
> +		return -ENXIO;
> +	/*
> +	 * This is a horrible hack, but short of implementing a PCI
> +	 * specific interrupt chip callback and a huge pile of
> +	 * infrastructure, this is the minor nuissance. It provides the
> +	 * protection against concurrent operations on this entry and keeps
> +	 * the control word cache in sync.
> +	 */
> +	irq_desc = irq_to_desc(virq);
> +	if (!irq_desc)
> +		return -ENXIO;
> +
> +	guard(raw_spinlock_irq)(&irq_desc->lock);
> +	msi_desc = irq_data_get_msi_desc(&irq_desc->irq_data);
> +	if (!msi_desc || msi_desc->pci.msi_attrib.is_virtual)
> +		return -ENXIO;
> +
> +	msi_desc->pci.msix_ctrl &= ~PCI_MSIX_ENTRY_CTRL_ST;
> +	msi_desc->pci.msix_ctrl |= FIELD_PREP(PCI_MSIX_ENTRY_CTRL_ST, tag);
> +	pci_msix_write_vector_ctrl(msi_desc, msi_desc->pci.msix_ctrl);
> +	/* Flush the write */
> +	readl(pci_msix_desc_addr(msi_desc));
> +	return 0;
> +}

Looks like this change might add this warning, which I don't claim to
understand:

  $ make C=2 drivers/pci/msi/msi.o
  drivers/pci/msi/msi.c:928:5: warning: context imbalance in 'pci_msix_write_tph_tag' - wrong count at exit

This appeared in v6.16-rc1 as d5124a9957b2 ("PCI/MSI: Provide a sane
mechanism for TPH")

  reply	other threads:[~2025-06-17 23:22 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-19 10:56 [patch V4 00/14] genirq/msi: Spring cleaning Thomas Gleixner
2025-03-19 10:56 ` [patch V4 01/14] cleanup: Provide retain_ptr() Thomas Gleixner
2025-03-19 20:15   ` James Bottomley
2025-03-19 10:56 ` [patch V4 02/14] genirq/msi: Use lock guards for MSI descriptor locking Thomas Gleixner
2025-03-19 10:56 ` [patch V4 03/14] soc: ti: ti_sci_inta_msi: Switch MSI descriptor locking to guard() Thomas Gleixner
2025-03-19 10:56 ` [patch V4 04/14] NTB/msi: Switch MSI descriptor locking to lock guard() Thomas Gleixner
2025-03-19 10:56 ` [patch V4 05/14] PCI/MSI: Use guard(msi_desc_lock) where applicable Thomas Gleixner
2025-03-19 17:08   ` Bjorn Helgaas
2025-03-19 10:56 ` [patch V4 06/14] PCI/MSI: Set pci_dev::msi_enabled late Thomas Gleixner
2025-03-19 17:08   ` Bjorn Helgaas
2025-03-19 10:56 ` [patch V4 07/14] PCI/MSI: Use __free() for affinity masks Thomas Gleixner
2025-03-19 17:09   ` Bjorn Helgaas
2025-03-19 10:56 ` [patch V4 08/14] PCI/MSI: Switch msi_capability_init() to guard(msi_desc_lock) Thomas Gleixner
2025-03-19 17:09   ` Bjorn Helgaas
2025-03-19 10:56 ` [patch V4 09/14] PCI/MSI: Switch msix_capability_init() " Thomas Gleixner
2025-03-19 17:09   ` Bjorn Helgaas
2025-04-08 12:04   ` commit 7b025f3f85ed causes NULL pointer dereference Bert Karwatzki
2025-04-08 15:09     ` Thomas Gleixner
2025-04-08 15:29       ` Thomas Gleixner
2025-04-08 16:20         ` Bert Karwatzki
2025-04-08 20:22           ` Klara Modin
2025-04-08 20:46           ` Thomas Gleixner
2025-04-09 11:44             ` Aithal, Srikanth
2025-04-09 11:49             ` Andy Shevchenko
2025-04-09 12:49             ` James Bottomley
2025-04-09 18:38               ` Thomas Gleixner
2025-04-09 15:22             ` Venkat Rao Bagalkote
2025-04-09 18:29             ` Borislav Petkov
2025-03-19 10:56 ` [patch V4 10/14] PCI: hv: Switch MSI descriptor locking to guard() Thomas Gleixner
2025-03-19 10:56 ` [patch V4 11/14] PCI/MSI: Provide a sane mechanism for TPH Thomas Gleixner
2025-06-17 23:22   ` Bjorn Helgaas [this message]
2025-06-17 23:25     ` Bjorn Helgaas
2025-03-19 10:56 ` [patch V4 12/14] PCI/TPH: Replace the broken MSI-X control word update Thomas Gleixner
2025-03-19 10:57 ` [patch V4 13/14] scsi: ufs: qcom: Remove the MSI descriptor abuse Thomas Gleixner
2025-03-19 20:40   ` James Bottomley
2025-03-19 10:57 ` [patch V4 14/14] genirq/msi: Rename msi_[un]lock_descs() 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=20250617232232.GA1175597@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Jonathan.Cameron@huwei.com \
    --cc=allenbh@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=d-gole@ti.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=logang@deltatee.com \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=martin.petersen@oracle.com \
    --cc=maz@kernel.org \
    --cc=mhklinux@outlook.com \
    --cc=nm@ti.com \
    --cc=ntb@lists.linux.dev \
    --cc=peterz@infradead.org \
    --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