Skip to content

Commit 6d745ef

Browse files
author
Myron Stowe
committed
scsi: ufs: ufs-qcom: Fix ESI null pointer dereference
JIRA: https://issues.redhat.com/browse/RHEL-120705 Upstream Status: 6300d5c commit 6300d5c Author: Nitin Rawat <quic_nitirawa@quicinc.com> Date: Mon Aug 11 13:03:30 2025 +0530 scsi: ufs: ufs-qcom: Fix ESI null pointer dereference 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: Myron Stowe <mstowe@redhat.com>
1 parent ef62513 commit 6d745ef

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
@@ -1782,17 +1782,6 @@ static irqreturn_t ufs_qcom_mcq_esi_handler(int irq, void *data)
17821782
return IRQ_HANDLED;
17831783
}
17841784

1785-
static void ufs_qcom_irq_free(struct ufs_qcom_irq *uqi)
1786-
{
1787-
for (struct ufs_qcom_irq *q = uqi; q->irq; q++)
1788-
devm_free_irq(q->hba->dev, q->irq, q->hba);
1789-
1790-
platform_device_msi_free_irqs_all(uqi->hba->dev);
1791-
devm_kfree(uqi->hba->dev, uqi);
1792-
}
1793-
1794-
DEFINE_FREE(ufs_qcom_irq, struct ufs_qcom_irq *, if (_T) ufs_qcom_irq_free(_T))
1795-
17961785
static int ufs_qcom_config_esi(struct ufs_hba *hba)
17971786
{
17981787
struct ufs_qcom_host *host = ufshcd_get_variant(hba);
@@ -1807,18 +1796,18 @@ static int ufs_qcom_config_esi(struct ufs_hba *hba)
18071796
*/
18081797
nr_irqs = hba->nr_hw_queues - hba->nr_queues[HCTX_TYPE_POLL];
18091798

1810-
struct ufs_qcom_irq *qi __free(ufs_qcom_irq) =
1811-
devm_kcalloc(hba->dev, nr_irqs, sizeof(*qi), GFP_KERNEL);
1812-
if (!qi)
1813-
return -ENOMEM;
1814-
/* Preset so __free() has a pointer to hba in all error paths */
1815-
qi[0].hba = hba;
1816-
18171799
ret = platform_device_msi_init_and_alloc_irqs(hba->dev, nr_irqs,
18181800
ufs_qcom_write_msi_msg);
18191801
if (ret) {
1820-
dev_err(hba->dev, "Failed to request Platform MSI %d\n", ret);
1821-
return ret;
1802+
dev_warn(hba->dev, "Platform MSI not supported or failed, continuing without ESI\n");
1803+
return ret; /* Continue without ESI */
1804+
}
1805+
1806+
struct ufs_qcom_irq *qi = devm_kcalloc(hba->dev, nr_irqs, sizeof(*qi), GFP_KERNEL);
1807+
1808+
if (!qi) {
1809+
platform_device_msi_free_irqs_all(hba->dev);
1810+
return -ENOMEM;
18221811
}
18231812

18241813
for (int idx = 0; idx < nr_irqs; idx++) {
@@ -1829,15 +1818,17 @@ static int ufs_qcom_config_esi(struct ufs_hba *hba)
18291818
ret = devm_request_irq(hba->dev, qi[idx].irq, ufs_qcom_mcq_esi_handler,
18301819
IRQF_SHARED, "qcom-mcq-esi", qi + idx);
18311820
if (ret) {
1832-
dev_err(hba->dev, "%s: Fail to request IRQ for %d, err = %d\n",
1821+
dev_err(hba->dev, "%s: Failed to request IRQ for %d, err = %d\n",
18331822
__func__, qi[idx].irq, ret);
1834-
qi[idx].irq = 0;
1823+
/* Free previously allocated IRQs */
1824+
for (int j = 0; j < idx; j++)
1825+
devm_free_irq(hba->dev, qi[j].irq, qi + j);
1826+
platform_device_msi_free_irqs_all(hba->dev);
1827+
devm_kfree(hba->dev, qi);
18351828
return ret;
18361829
}
18371830
}
18381831

1839-
retain_and_null_ptr(qi);
1840-
18411832
if (host->hw_ver.major >= 6) {
18421833
ufshcd_rmwl(hba, ESI_VEC_MASK, FIELD_PREP(ESI_VEC_MASK, MAX_ESI_VEC - 1),
18431834
REG_UFS_CFG3);

0 commit comments

Comments
 (0)