public inbox for ntb@lists.linux.dev
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>
Cc: Marc Zyngier <maz@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	 linux-scsi@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>, Bjorn Helgaas <bhelgaas@google.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	 linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org,
	Wei Huang <wei.huang2@amd.com>,
	Jonathan Cameron <Jonathan.Cameron@huwei.com>
Subject: Re: [patch V4 13/14] scsi: ufs: qcom: Remove the MSI descriptor abuse
Date: Wed, 19 Mar 2025 16:40:22 -0400	[thread overview]
Message-ID: <b64fc052da27c0e77afae1db40c8d3b05277cc86.camel@HansenPartnership.com> (raw)
In-Reply-To: <20250319105506.805529593@linutronix.de>

On Wed, 2025-03-19 at 11:57 +0100, Thomas Gleixner wrote:
> The driver abuses the MSI descriptors for internal purposes. Aside of
> core code and MSI providers nothing has to care about their
> existence. They have been encapsulated with a lot of effort because
> this kind of abuse caused all sorts of issues including a
> maintainability nightmare.
> 
> Rewrite the code so it uses dedicated storage to hand the required
> information to the interrupt handler and use a custom cleanup
> function to simplify the error path.
> 
> No functional change intended.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> Cc: linux-scsi@vger.kernel.org
> ---
> V4: Fix inverse NULL pointer check and use __free() for error paths -
> James
> ---
>  drivers/ufs/host/ufs-qcom.c |   85 ++++++++++++++++++++++++---------
> -----------
>  1 file changed, 48 insertions(+), 37 deletions(-)
> 
> --- a/drivers/ufs/host/ufs-qcom.c
> +++ b/drivers/ufs/host/ufs-qcom.c
> @@ -1782,25 +1782,38 @@ static void ufs_qcom_write_msi_msg(struc
>  	ufshcd_mcq_config_esi(hba, msg);
>  }
>  
> +struct ufs_qcom_irq {
> +	unsigned int		irq;
> +	unsigned int		idx;
> +	struct ufs_hba		*hba;
> +};
> +
>  static irqreturn_t ufs_qcom_mcq_esi_handler(int irq, void *data)
>  {
> -	struct msi_desc *desc = data;
> -	struct device *dev = msi_desc_to_dev(desc);
> -	struct ufs_hba *hba = dev_get_drvdata(dev);
> -	u32 id = desc->msi_index;
> -	struct ufs_hw_queue *hwq = &hba->uhq[id];
> +	struct ufs_qcom_irq *qi = data;
> +	struct ufs_hba *hba = qi->hba;
> +	struct ufs_hw_queue *hwq = &hba->uhq[qi->idx];
>  
> -	ufshcd_mcq_write_cqis(hba, 0x1, id);
> +	ufshcd_mcq_write_cqis(hba, 0x1, qi->idx);
>  	ufshcd_mcq_poll_cqe_lock(hba, hwq);
>  
>  	return IRQ_HANDLED;
>  }
>  
> +static void ufs_qcom_irq_free(struct ufs_qcom_irq *uqi)
> +{
> +	for (struct ufs_qcom_irq *q = uqi; q->irq; q++)
> +		devm_free_irq(q->hba->dev, q->irq, q->hba);
> +
> +	platform_device_msi_free_irqs_all(uqi->hba->dev);
> +	devm_kfree(uqi->hba->dev, uqi);
> +}
> +
> +DEFINE_FREE(ufs_qcom_irq, struct ufs_qcom_irq *, if (_T)
> ufs_qcom_irq_free(_T))

So if every __free body basically has a condition check and an external
call, it would be a lot nicer if the macro were coded as something like

#define DEFINE_FREE(_name, _type, _cond, _free) \
	static inline void __free_##_name(void *p) { _type _T =
*(_type *)p; if (_cond(_T)) _free(_T); }

to avoid having to splash the strange _T across the kernel.

Other than that (which isn't your problem, so you can ignore it), the
code looks fine but I can't test it.

Reviewed-by: James Bottomley <James.Bottomley@HansenPartnership.com>


  reply	other threads:[~2025-03-19 20:40 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
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 [this message]
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=b64fc052da27c0e77afae1db40c8d3b05277cc86.camel@HansenPartnership.com \
    --to=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