Skip to content

Commit aaf17a3

Browse files
Nitin Rawatgregkh
authored andcommitted
scsi: ufs: ufs-qcom: Fix ESI null pointer dereference
[ Upstream commit 6300d5c ] ESI/MSI is a performance optimization feature that provides dedicated interrupts per MCQ hardware queue. This is optional feature and UFS MCQ should work with and without ESI feature. Commit e46a28c ("scsi: ufs: qcom: Remove the MSI descriptor abuse") brings a regression in ESI (Enhanced System Interrupt) configuration that causes a null pointer dereference when Platform MSI allocation fails. The issue occurs in when platform_device_msi_init_and_alloc_irqs() in ufs_qcom_config_esi() fails (returns -EINVAL) but the current code uses __free() macro for automatic cleanup free MSI resources that were never successfully allocated. Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 Call trace: mutex_lock+0xc/0x54 (P) platform_device_msi_free_irqs_all+0x1c/0x40 ufs_qcom_config_esi+0x1d0/0x220 [ufs_qcom] ufshcd_config_mcq+0x28/0x104 ufshcd_init+0xa3c/0xf40 ufshcd_pltfrm_init+0x504/0x7d4 ufs_qcom_probe+0x20/0x58 [ufs_qcom] Fix by restructuring the ESI configuration to try MSI allocation first, before any other resource allocation and instead use explicit cleanup instead of __free() macro to avoid cleanup of unallocated resources. Tested on SM8750 platform with MCQ enabled, both with and without Platform ESI support. Fixes: e46a28c ("scsi: ufs: qcom: Remove the MSI descriptor abuse") Cc: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Signed-off-by: Nitin Rawat <quic_nitirawa@quicinc.com> Link: https://lore.kernel.org/r/20250811073330.20230-1-quic_nitirawa@quicinc.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f5ba3ae commit aaf17a3

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

drivers/ufs/host/ufs-qcom.c

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,17 +2053,6 @@ static irqreturn_t ufs_qcom_mcq_esi_handler(int irq, void *data)
20532053
return IRQ_HANDLED;
20542054
}
20552055

2056-
static void ufs_qcom_irq_free(struct ufs_qcom_irq *uqi)
2057-
{
2058-
for (struct ufs_qcom_irq *q = uqi; q->irq; q++)
2059-
devm_free_irq(q->hba->dev, q->irq, q->hba);
2060-
2061-
platform_device_msi_free_irqs_all(uqi->hba->dev);
2062-
devm_kfree(uqi->hba->dev, uqi);
2063-
}
2064-
2065-
DEFINE_FREE(ufs_qcom_irq, struct ufs_qcom_irq *, if (_T) ufs_qcom_irq_free(_T))
2066-
20672056
static int ufs_qcom_config_esi(struct ufs_hba *hba)
20682057
{
20692058
struct ufs_qcom_host *host = ufshcd_get_variant(hba);
@@ -2078,18 +2067,18 @@ static int ufs_qcom_config_esi(struct ufs_hba *hba)
20782067
*/
20792068
nr_irqs = hba->nr_hw_queues - hba->nr_queues[HCTX_TYPE_POLL];
20802069

2081-
struct ufs_qcom_irq *qi __free(ufs_qcom_irq) =
2082-
devm_kcalloc(hba->dev, nr_irqs, sizeof(*qi), GFP_KERNEL);
2083-
if (!qi)
2084-
return -ENOMEM;
2085-
/* Preset so __free() has a pointer to hba in all error paths */
2086-
qi[0].hba = hba;
2087-
20882070
ret = platform_device_msi_init_and_alloc_irqs(hba->dev, nr_irqs,
20892071
ufs_qcom_write_msi_msg);
20902072
if (ret) {
2091-
dev_err(hba->dev, "Failed to request Platform MSI %d\n", ret);
2092-
return ret;
2073+
dev_warn(hba->dev, "Platform MSI not supported or failed, continuing without ESI\n");
2074+
return ret; /* Continue without ESI */
2075+
}
2076+
2077+
struct ufs_qcom_irq *qi = devm_kcalloc(hba->dev, nr_irqs, sizeof(*qi), GFP_KERNEL);
2078+
2079+
if (!qi) {
2080+
platform_device_msi_free_irqs_all(hba->dev);
2081+
return -ENOMEM;
20932082
}
20942083

20952084
for (int idx = 0; idx < nr_irqs; idx++) {
@@ -2100,15 +2089,17 @@ static int ufs_qcom_config_esi(struct ufs_hba *hba)
21002089
ret = devm_request_irq(hba->dev, qi[idx].irq, ufs_qcom_mcq_esi_handler,
21012090
IRQF_SHARED, "qcom-mcq-esi", qi + idx);
21022091
if (ret) {
2103-
dev_err(hba->dev, "%s: Fail to request IRQ for %d, err = %d\n",
2092+
dev_err(hba->dev, "%s: Failed to request IRQ for %d, err = %d\n",
21042093
__func__, qi[idx].irq, ret);
2105-
qi[idx].irq = 0;
2094+
/* Free previously allocated IRQs */
2095+
for (int j = 0; j < idx; j++)
2096+
devm_free_irq(hba->dev, qi[j].irq, qi + j);
2097+
platform_device_msi_free_irqs_all(hba->dev);
2098+
devm_kfree(hba->dev, qi);
21062099
return ret;
21072100
}
21082101
}
21092102

2110-
retain_and_null_ptr(qi);
2111-
21122103
if (host->hw_ver.major >= 6) {
21132104
ufshcd_rmwl(hba, ESI_VEC_MASK, FIELD_PREP(ESI_VEC_MASK, MAX_ESI_VEC - 1),
21142105
REG_UFS_CFG3);

0 commit comments

Comments
 (0)