Skip to contentSkip to conversation

mmc: sdhci: check host->cmd is null or not in sdhci_cqe_irq()

PATCH In review Ying-Chun Liu (PaulLiu) 3 participants 5 messages Aug 31, 2022 – Sep 7, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mmc: sdhci: check host->cmd is null or not in sdhci_cqe_irq()

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

If we don't check host->cmd. We will get the following oops when booting from eMMC on RockPi4.

 Unable to handle kernel read from unreadable memory at
   virtual address 0000000000000000
 Call trace:
   sdhci_cqe_irq+0x40/0x254

Ying-Chun Liu (PaulLiu) (1):
mmc: sdhci: check host->cmd is null or not in sdhci_cqe_irq()

 drivers/mmc/host/sdhci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/1 mmc: sdhci: check host->cmd is null or not in sdhci_cqe_irq()

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

If we don't check host->cmd. We will get the following oops when booting from eMMC on RockPi4.

 Unable to handle kernel read from unreadable memory at
   virtual address 0000000000000000
 Call trace:
   sdhci_cqe_irq+0x40/0x254
---
 drivers/mmc/host/sdhci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci.c +2 -2
index 7689ffec5ad1..e0e7768bd6c0 100644
@@ -3928,7 +3928,7 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
 
 	if (intmask & (SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC)) {
 		*cmd_error = -EILSEQ;
-		if (!mmc_op_tuning(host->cmd->opcode))
+		if (host->cmd && !mmc_op_tuning(host->cmd->opcode))
 			sdhci_err_stats_inc(host, CMD_CRC);
 	} else if (intmask & SDHCI_INT_TIMEOUT) {
 		*cmd_error = -ETIMEDOUT;
@@ -3938,7 +3938,7 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
 
 	if (intmask & (SDHCI_INT_DATA_END_BIT | SDHCI_INT_DATA_CRC)) {
 		*data_error = -EILSEQ;
-		if (!mmc_op_tuning(host->cmd->opcode))
+		if (host->cmd && !mmc_op_tuning(host->cmd->opcode))
 			sdhci_err_stats_inc(host, DAT_CRC);
 	} else if (intmask & SDHCI_INT_DATA_TIMEOUT) {
 		*data_error = -ETIMEDOUT;
Signature · 1 line
2.35.1
maintainer
#2 lore raw
Quoted 9 lines · Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

If we don't check host->cmd. We will get the following oops when booting from eMMC on RockPi4.

 Unable to handle kernel read from unreadable memory at
   virtual address 0000000000000000
 Call trace:
   sdhci_cqe_irq+0x40/0x254

Thank you! However, I prefer this patch:

https://lore.kernel.org/linux-mmc/[email protected]/

Quoted 34 lines
---
 drivers/mmc/host/sdhci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci.c +2 -2
index 7689ffec5ad1..e0e7768bd6c0 100644
@@ -3928,7 +3928,7 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
 
 	if (intmask & (SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC)) {
 		*cmd_error = -EILSEQ;
-		if (!mmc_op_tuning(host->cmd->opcode))
+		if (host->cmd && !mmc_op_tuning(host->cmd->opcode))
 			sdhci_err_stats_inc(host, CMD_CRC);
 	} else if (intmask & SDHCI_INT_TIMEOUT) {
 		*cmd_error = -ETIMEDOUT;
@@ -3938,7 +3938,7 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
 
 	if (intmask & (SDHCI_INT_DATA_END_BIT | SDHCI_INT_DATA_CRC)) {
 		*data_error = -EILSEQ;
-		if (!mmc_op_tuning(host->cmd->opcode))
+		if (host->cmd && !mmc_op_tuning(host->cmd->opcode))
 			sdhci_err_stats_inc(host, DAT_CRC);
 	} else if (intmask & SDHCI_INT_DATA_TIMEOUT) {
 		*data_error = -ETIMEDOUT;
#3 lore raw

Hi Adrian,

Quoted 7 lines · Adrian Hunter
Quoted 5 lines · Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

If we don't check host->cmd. We will get the following oops when booting from eMMC on RockPi4.

Quoted 8 lines
Quoted 4 lines
 Unable to handle kernel read from unreadable memory at
   virtual address 0000000000000000
 Call trace:
   sdhci_cqe_irq+0x40/0x254

Thank you! However, I prefer this patch:

https://lore.kernel.org/linux-mmc/[email protected]/

That patch means that we need to do a sdhci_readw() to figure out what command we are running, rather than just checking for a valid pointer. Maybe it's not a big deal as this code isn't executed that often?

Anyway, it's your call to make, I pick the patch that you prefer.

Kind regards
Uffe

Quoted 36 lines
Quoted 35 lines
---
 drivers/mmc/host/sdhci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci.c +2 -2
index 7689ffec5ad1..e0e7768bd6c0 100644
@@ -3928,7 +3928,7 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
 
      if (intmask & (SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC)) {
              *cmd_error = -EILSEQ;
-             if (!mmc_op_tuning(host->cmd->opcode))
+             if (host->cmd && !mmc_op_tuning(host->cmd->opcode))
                      sdhci_err_stats_inc(host, CMD_CRC);
      } else if (intmask & SDHCI_INT_TIMEOUT) {
              *cmd_error = -ETIMEDOUT;
@@ -3938,7 +3938,7 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
 
      if (intmask & (SDHCI_INT_DATA_END_BIT | SDHCI_INT_DATA_CRC)) {
              *data_error = -EILSEQ;
-             if (!mmc_op_tuning(host->cmd->opcode))
+             if (host->cmd && !mmc_op_tuning(host->cmd->opcode))
                      sdhci_err_stats_inc(host, DAT_CRC);
      } else if (intmask & SDHCI_INT_DATA_TIMEOUT) {
              *data_error = -ETIMEDOUT;
maintainer
#4 lore raw
Quoted 15 lines · Ulf Hansson

Hi Adrian,

Quoted 12 lines · Adrian Hunter
Quoted 9 lines · Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

If we don't check host->cmd. We will get the following oops when booting from eMMC on RockPi4.

 Unable to handle kernel read from unreadable memory at
   virtual address 0000000000000000
 Call trace:
   sdhci_cqe_irq+0x40/0x254
Quoted 7 lines
Quoted 3 lines

Thank you! However, I prefer this patch:

https://lore.kernel.org/linux-mmc/[email protected]/

That patch means that we need to do a sdhci_readw() to figure out what command we are running, rather than just checking for a valid pointer. Maybe it's not a big deal as this code isn't executed that often?

That was my thinking, but CQE/CQHCI does not set host->cmd either. It is the same approach taken in sdhci_data_irq() so consistent at least.

Quoted 42 lines

Anyway, it's your call to make, I pick the patch that you prefer.

Kind regards
Uffe

Quoted 36 lines
Quoted 35 lines
---
 drivers/mmc/host/sdhci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci.c +2 -2
index 7689ffec5ad1..e0e7768bd6c0 100644
@@ -3928,7 +3928,7 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
 
      if (intmask & (SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC)) {
              *cmd_error = -EILSEQ;
-             if (!mmc_op_tuning(host->cmd->opcode))
+             if (host->cmd && !mmc_op_tuning(host->cmd->opcode))
                      sdhci_err_stats_inc(host, CMD_CRC);
      } else if (intmask & SDHCI_INT_TIMEOUT) {
              *cmd_error = -ETIMEDOUT;
@@ -3938,7 +3938,7 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
 
      if (intmask & (SDHCI_INT_DATA_END_BIT | SDHCI_INT_DATA_CRC)) {
              *data_error = -EILSEQ;
-             if (!mmc_op_tuning(host->cmd->opcode))
+             if (host->cmd && !mmc_op_tuning(host->cmd->opcode))
                      sdhci_err_stats_inc(host, DAT_CRC);
      } else if (intmask & SDHCI_INT_DATA_TIMEOUT) {
              *data_error = -ETIMEDOUT;