From: Sasha Levin Date: Mon, 4 Dec 2023 10:40:12 +0000 (-0500) Subject: Fixes for 5.4 X-Git-Tag: v4.14.332~23^2~31 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cded99007e12a856e6e6d3805669ca3dbe32f715;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 5.4 Signed-off-by: Sasha Levin --- diff --git a/queue-5.4/mmc-block-retry-commands-in-cqe-error-recovery.patch b/queue-5.4/mmc-block-retry-commands-in-cqe-error-recovery.patch new file mode 100644 index 00000000000..0561b9dcb5e --- /dev/null +++ b/queue-5.4/mmc-block-retry-commands-in-cqe-error-recovery.patch @@ -0,0 +1,55 @@ +From 894f69a88f6399c06ac3e347b47b837f65b4d2d0 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 3 Nov 2023 10:47:18 +0200 +Subject: mmc: block: Retry commands in CQE error recovery + +From: Adrian Hunter + +[ Upstream commit 8155d1fa3a747baad5caff5f8303321d68ddd48c ] + +It is important that MMC_CMDQ_TASK_MGMT command to discard the queue is +successful because otherwise a subsequent reset might fail to flush the +cache first. Retry it and the previous STOP command. + +Fixes: 72a5af554df8 ("mmc: core: Add support for handling CQE requests") +Cc: stable@vger.kernel.org +Signed-off-by: Adrian Hunter +Reviewed-by: Avri Altman +Link: https://lore.kernel.org/r/20231103084720.6886-5-adrian.hunter@intel.com +Signed-off-by: Ulf Hansson +Signed-off-by: Sasha Levin +--- + drivers/mmc/core/core.c | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c +index c88e991f787be..67c0d1378747d 100644 +--- a/drivers/mmc/core/core.c ++++ b/drivers/mmc/core/core.c +@@ -568,7 +568,7 @@ int mmc_cqe_recovery(struct mmc_host *host) + cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; + cmd.flags &= ~MMC_RSP_CRC; /* Ignore CRC */ + cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT; +- mmc_wait_for_cmd(host, &cmd, 0); ++ mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); + + memset(&cmd, 0, sizeof(cmd)); + cmd.opcode = MMC_CMDQ_TASK_MGMT; +@@ -576,10 +576,13 @@ int mmc_cqe_recovery(struct mmc_host *host) + cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; + cmd.flags &= ~MMC_RSP_CRC; /* Ignore CRC */ + cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT; +- err = mmc_wait_for_cmd(host, &cmd, 0); ++ err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); + + host->cqe_ops->cqe_recovery_finish(host); + ++ if (err) ++ err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); ++ + mmc_retune_release(host); + + return err; +-- +2.42.0 + diff --git a/queue-5.4/mmc-core-convert-comma-to-semicolon.patch b/queue-5.4/mmc-core-convert-comma-to-semicolon.patch new file mode 100644 index 00000000000..528b24ce5d8 --- /dev/null +++ b/queue-5.4/mmc-core-convert-comma-to-semicolon.patch @@ -0,0 +1,50 @@ +From 0b77196f8e7fdd56837c210347723b1f188db28d Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 16 Dec 2020 21:17:37 +0800 +Subject: mmc: core: convert comma to semicolon + +From: Zheng Yongjun + +[ Upstream commit 6b1dc6229aecbcb45e8901576684a8c09e25ad7b ] + +Replace a comma between expression statements by a semicolon. + +Signed-off-by: Zheng Yongjun +Link: https://lore.kernel.org/r/20201216131737.14883-1-zhengyongjun3@huawei.com +Signed-off-by: Ulf Hansson +Stable-dep-of: 8155d1fa3a74 ("mmc: block: Retry commands in CQE error recovery") +Signed-off-by: Sasha Levin +--- + drivers/mmc/core/core.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c +index 7caf9ef27d227..c88e991f787be 100644 +--- a/drivers/mmc/core/core.c ++++ b/drivers/mmc/core/core.c +@@ -564,10 +564,10 @@ int mmc_cqe_recovery(struct mmc_host *host) + host->cqe_ops->cqe_recovery_start(host); + + memset(&cmd, 0, sizeof(cmd)); +- cmd.opcode = MMC_STOP_TRANSMISSION, +- cmd.flags = MMC_RSP_R1B | MMC_CMD_AC, ++ cmd.opcode = MMC_STOP_TRANSMISSION; ++ cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; + cmd.flags &= ~MMC_RSP_CRC; /* Ignore CRC */ +- cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT, ++ cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT; + mmc_wait_for_cmd(host, &cmd, 0); + + memset(&cmd, 0, sizeof(cmd)); +@@ -575,7 +575,7 @@ int mmc_cqe_recovery(struct mmc_host *host) + cmd.arg = 1; /* Discard entire queue */ + cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; + cmd.flags &= ~MMC_RSP_CRC; /* Ignore CRC */ +- cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT, ++ cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT; + err = mmc_wait_for_cmd(host, &cmd, 0); + + host->cqe_ops->cqe_recovery_finish(host); +-- +2.42.0 + diff --git a/queue-5.4/mmc-cqhci-fix-task-clearing-in-cqe-error-recovery.patch b/queue-5.4/mmc-cqhci-fix-task-clearing-in-cqe-error-recovery.patch new file mode 100644 index 00000000000..1f1435e785c --- /dev/null +++ b/queue-5.4/mmc-cqhci-fix-task-clearing-in-cqe-error-recovery.patch @@ -0,0 +1,98 @@ +From ffec87d6efb337b4fc90a99a6a2b46d150ac56ba Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 3 Nov 2023 10:47:20 +0200 +Subject: mmc: cqhci: Fix task clearing in CQE error recovery +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Adrian Hunter + +[ Upstream commit 1de1b77982e1a1df9707cb11f9b1789e6b8919d4 ] + +If a task completion notification (TCN) is received when there is no +outstanding task, the cqhci driver issues a "spurious TCN" warning. This +was observed to happen right after CQE error recovery. + +When an error interrupt is received the driver runs recovery logic. +It halts the controller, clears all pending tasks, and then re-enables +it. On some platforms, like Intel Jasper Lake, a stale task completion +event was observed, regardless of the CQHCI_CLEAR_ALL_TASKS bit being set. + +This results in either: +a) Spurious TC completion event for an empty slot. +b) Corrupted data being passed up the stack, as a result of premature + completion for a newly added task. + +Rather than add a quirk for affected controllers, ensure tasks are cleared +by toggling CQHCI_ENABLE, which would happen anyway if +cqhci_clear_all_tasks() timed out. This is simpler and should be safe and +effective for all controllers. + +Fixes: a4080225f51d ("mmc: cqhci: support for command queue enabled host") +Cc: stable@vger.kernel.org +Reported-by: Kornel Dulęba +Tested-by: Kornel Dulęba +Co-developed-by: Kornel Dulęba +Signed-off-by: Kornel Dulęba +Signed-off-by: Adrian Hunter +Reviewed-by: Avri Altman +Link: https://lore.kernel.org/r/20231103084720.6886-7-adrian.hunter@intel.com +Signed-off-by: Ulf Hansson +Signed-off-by: Sasha Levin +--- + drivers/mmc/host/cqhci.c | 32 ++++++++++++++++---------------- + 1 file changed, 16 insertions(+), 16 deletions(-) + +diff --git a/drivers/mmc/host/cqhci.c b/drivers/mmc/host/cqhci.c +index 29440fd4ff099..10b36b156562a 100644 +--- a/drivers/mmc/host/cqhci.c ++++ b/drivers/mmc/host/cqhci.c +@@ -1011,28 +1011,28 @@ static void cqhci_recovery_finish(struct mmc_host *mmc) + + ok = cqhci_halt(mmc, CQHCI_FINISH_HALT_TIMEOUT); + +- if (!cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT)) +- ok = false; +- + /* + * The specification contradicts itself, by saying that tasks cannot be + * cleared if CQHCI does not halt, but if CQHCI does not halt, it should + * be disabled/re-enabled, but not to disable before clearing tasks. + * Have a go anyway. + */ +- if (!ok) { +- pr_debug("%s: cqhci: disable / re-enable\n", mmc_hostname(mmc)); +- cqcfg = cqhci_readl(cq_host, CQHCI_CFG); +- cqcfg &= ~CQHCI_ENABLE; +- cqhci_writel(cq_host, cqcfg, CQHCI_CFG); +- cqcfg |= CQHCI_ENABLE; +- cqhci_writel(cq_host, cqcfg, CQHCI_CFG); +- /* Be sure that there are no tasks */ +- ok = cqhci_halt(mmc, CQHCI_FINISH_HALT_TIMEOUT); +- if (!cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT)) +- ok = false; +- WARN_ON(!ok); +- } ++ if (!cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT)) ++ ok = false; ++ ++ /* Disable to make sure tasks really are cleared */ ++ cqcfg = cqhci_readl(cq_host, CQHCI_CFG); ++ cqcfg &= ~CQHCI_ENABLE; ++ cqhci_writel(cq_host, cqcfg, CQHCI_CFG); ++ ++ cqcfg = cqhci_readl(cq_host, CQHCI_CFG); ++ cqcfg |= CQHCI_ENABLE; ++ cqhci_writel(cq_host, cqcfg, CQHCI_CFG); ++ ++ cqhci_halt(mmc, CQHCI_FINISH_HALT_TIMEOUT); ++ ++ if (!ok) ++ cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT); + + cqhci_recover_mrqs(cq_host); + +-- +2.42.0 + diff --git a/queue-5.4/mmc-cqhci-increase-recovery-halt-timeout.patch b/queue-5.4/mmc-cqhci-increase-recovery-halt-timeout.patch new file mode 100644 index 00000000000..00ac7c413a2 --- /dev/null +++ b/queue-5.4/mmc-cqhci-increase-recovery-halt-timeout.patch @@ -0,0 +1,45 @@ +From 98c77b28375507792a3b03da8304469923b140c7 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 3 Nov 2023 10:47:16 +0200 +Subject: mmc: cqhci: Increase recovery halt timeout + +From: Adrian Hunter + +[ Upstream commit b578d5d18e929aa7c007a98cce32657145dde219 ] + +Failing to halt complicates the recovery. Additionally, unless the card or +controller are stuck, which is expected to be very rare, then the halt +should succeed, so it is better to wait. Set a large timeout. + +Fixes: a4080225f51d ("mmc: cqhci: support for command queue enabled host") +Cc: stable@vger.kernel.org +Signed-off-by: Adrian Hunter +Reviewed-by: Avri Altman +Link: https://lore.kernel.org/r/20231103084720.6886-3-adrian.hunter@intel.com +Signed-off-by: Ulf Hansson +Signed-off-by: Sasha Levin +--- + drivers/mmc/host/cqhci.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/drivers/mmc/host/cqhci.c b/drivers/mmc/host/cqhci.c +index ec56464eaf23e..42b8038f76300 100644 +--- a/drivers/mmc/host/cqhci.c ++++ b/drivers/mmc/host/cqhci.c +@@ -920,10 +920,10 @@ static bool cqhci_halt(struct mmc_host *mmc, unsigned int timeout) + /* + * After halting we expect to be able to use the command line. We interpret the + * failure to halt to mean the data lines might still be in use (and the upper +- * layers will need to send a STOP command), so we set the timeout based on a +- * generous command timeout. ++ * layers will need to send a STOP command), however failing to halt complicates ++ * the recovery, so set a timeout that would reasonably allow I/O to complete. + */ +-#define CQHCI_START_HALT_TIMEOUT 5 ++#define CQHCI_START_HALT_TIMEOUT 500 + + static void cqhci_recovery_start(struct mmc_host *mmc) + { +-- +2.42.0 + diff --git a/queue-5.4/mmc-cqhci-warn-of-halt-or-task-clear-failure.patch b/queue-5.4/mmc-cqhci-warn-of-halt-or-task-clear-failure.patch new file mode 100644 index 00000000000..33a9497dff0 --- /dev/null +++ b/queue-5.4/mmc-cqhci-warn-of-halt-or-task-clear-failure.patch @@ -0,0 +1,52 @@ +From 96e072913f4b240ed928801c1fb094f4dc94ab1d Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 3 Nov 2023 10:47:19 +0200 +Subject: mmc: cqhci: Warn of halt or task clear failure + +From: Adrian Hunter + +[ Upstream commit 35597bdb04ec27ef3b1cea007dc69f8ff5df75a5 ] + +A correctly operating controller should successfully halt and clear tasks. +Failure may result in errors elsewhere, so promote messages from debug to +warnings. + +Fixes: a4080225f51d ("mmc: cqhci: support for command queue enabled host") +Cc: stable@vger.kernel.org +Signed-off-by: Adrian Hunter +Reviewed-by: Avri Altman +Reviewed-by: Avri Altman +Link: https://lore.kernel.org/r/20231103084720.6886-6-adrian.hunter@intel.com +Signed-off-by: Ulf Hansson +Signed-off-by: Sasha Levin +--- + drivers/mmc/host/cqhci.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/drivers/mmc/host/cqhci.c b/drivers/mmc/host/cqhci.c +index 42b8038f76300..29440fd4ff099 100644 +--- a/drivers/mmc/host/cqhci.c ++++ b/drivers/mmc/host/cqhci.c +@@ -878,8 +878,8 @@ static bool cqhci_clear_all_tasks(struct mmc_host *mmc, unsigned int timeout) + ret = cqhci_tasks_cleared(cq_host); + + if (!ret) +- pr_debug("%s: cqhci: Failed to clear tasks\n", +- mmc_hostname(mmc)); ++ pr_warn("%s: cqhci: Failed to clear tasks\n", ++ mmc_hostname(mmc)); + + return ret; + } +@@ -912,7 +912,7 @@ static bool cqhci_halt(struct mmc_host *mmc, unsigned int timeout) + ret = cqhci_halted(cq_host); + + if (!ret) +- pr_debug("%s: cqhci: Failed to halt\n", mmc_hostname(mmc)); ++ pr_warn("%s: cqhci: Failed to halt\n", mmc_hostname(mmc)); + + return ret; + } +-- +2.42.0 + diff --git a/queue-5.4/series b/queue-5.4/series index 525fbab3090..3148575a5d9 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -91,3 +91,8 @@ scsi-qla2xxx-use-scsi_cmd_to_rq-instead-of-scsi_cmnd.patch scsi-qla2xxx-fix-system-crash-due-to-bad-pointer-acc.patch cpufreq-imx6q-don-t-warn-for-disabling-a-non-existin.patch cpufreq-imx6q-don-t-disable-792-mhz-opp-unnecessaril.patch +mmc-cqhci-increase-recovery-halt-timeout.patch +mmc-cqhci-warn-of-halt-or-task-clear-failure.patch +mmc-cqhci-fix-task-clearing-in-cqe-error-recovery.patch +mmc-core-convert-comma-to-semicolon.patch +mmc-block-retry-commands-in-cqe-error-recovery.patch