* [PATCH 3.4] mmc: block: fix a bug of error handling in MMC driver
@ 2013-12-05 16:47 Yoshitake Kobayashi
2013-12-06 12:21 ` Luis Henriques
2013-12-28 22:54 ` Ben Hutchings
0 siblings, 2 replies; 3+ messages in thread
From: Yoshitake Kobayashi @ 2013-12-05 16:47 UTC (permalink / raw)
To: gregkh, stable; +Cc: cjb, linux-kernel, KOBAYASHI Yoshitake
From: KOBAYASHI Yoshitake <yoshitake.kobayashi@toshiba.co.jp>
commit c8760069627ad3b0dbbea170f0c4c58b16e18d3d upstream.
Current MMC driver doesn't handle generic error (bit19 of device
status) in write sequence. As a result, write data gets lost when
generic error occurs. For example, a generic error when updating a
filesystem management information causes a loss of write data and
corrupts the filesystem. In the worst case, the system will never
boot.
This patch includes the following functionality:
1. To enable error checking for the response of CMD12 and CMD13
in write command sequence
2. To retry write sequence when a generic error occurs
[Backported to 3.4-stable]
Signed-off-by: KOBAYASHI Yoshitake <yoshitake.kobayashi@toshiba.co.jp>
Signed-off-by: Chris Ball <cjb@laptop.org>
---
drivers/mmc/card/block.c | 47 +++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 833ff16..91042a2 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -701,7 +701,7 @@ static int mmc_blk_cmd_error(struct request *req, const char *name, int error,
* Otherwise we don't understand what happened, so abort.
*/
static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
- struct mmc_blk_request *brq, int *ecc_err)
+ struct mmc_blk_request *brq, int *ecc_err, int *gen_err)
{
bool prev_cmd_status_valid = true;
u32 status, stop_status = 0;
@@ -739,6 +739,16 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
(brq->cmd.resp[0] & R1_CARD_ECC_FAILED))
*ecc_err = 1;
+ /* Flag General errors */
+ if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
+ if ((status & R1_ERROR) ||
+ (brq->stop.resp[0] & R1_ERROR)) {
+ pr_err("%s: %s: general error sending stop or status command, stop cmd response %#x, card status %#x\n",
+ req->rq_disk->disk_name, __func__,
+ brq->stop.resp[0], status);
+ *gen_err = 1;
+ }
+
/*
* Check the current card state. If it is in some data transfer
* mode, tell it to stop (and hopefully transition back to TRAN.)
@@ -758,6 +768,13 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
return ERR_ABORT;
if (stop_status & R1_CARD_ECC_FAILED)
*ecc_err = 1;
+ if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
+ if (stop_status & R1_ERROR) {
+ pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
+ req->rq_disk->disk_name, __func__,
+ stop_status);
+ *gen_err = 1;
+ }
}
/* Check for set block count errors */
@@ -1007,7 +1024,7 @@ static int mmc_blk_err_check(struct mmc_card *card,
mmc_active);
struct mmc_blk_request *brq = &mq_mrq->brq;
struct request *req = mq_mrq->req;
- int ecc_err = 0;
+ int ecc_err = 0, gen_err = 0;
/*
* sbc.error indicates a problem with the set block count
@@ -1021,7 +1038,7 @@ static int mmc_blk_err_check(struct mmc_card *card,
*/
if (brq->sbc.error || brq->cmd.error || brq->stop.error ||
brq->data.error) {
- switch (mmc_blk_cmd_recovery(card, req, brq, &ecc_err)) {
+ switch (mmc_blk_cmd_recovery(card, req, brq, &ecc_err, &gen_err)) {
case ERR_RETRY:
return MMC_BLK_RETRY;
case ERR_ABORT:
@@ -1051,6 +1068,15 @@ static int mmc_blk_err_check(struct mmc_card *card,
*/
if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
u32 status;
+
+ /* Check stop command response */
+ if (brq->stop.resp[0] & R1_ERROR) {
+ pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
+ req->rq_disk->disk_name, __func__,
+ brq->stop.resp[0]);
+ gen_err = 1;
+ }
+
do {
int err = get_card_status(card, &status, 5);
if (err) {
@@ -1058,6 +1084,14 @@ static int mmc_blk_err_check(struct mmc_card *card,
req->rq_disk->disk_name, err);
return MMC_BLK_CMD_ERR;
}
+
+ if (status & R1_ERROR) {
+ pr_err("%s: %s: general error sending status command, card status %#x\n",
+ req->rq_disk->disk_name, __func__,
+ status);
+ gen_err = 1;
+ }
+
/*
* Some cards mishandle the status bits,
* so make sure to check both the busy
@@ -1067,6 +1101,13 @@ static int mmc_blk_err_check(struct mmc_card *card,
(R1_CURRENT_STATE(status) == R1_STATE_PRG));
}
+ /* if general error occurs, retry the write operation. */
+ if (gen_err) {
+ pr_warning("%s: retrying write for general error\n",
+ req->rq_disk->disk_name);
+ return MMC_BLK_RETRY;
+ }
+
if (brq->data.error) {
pr_err("%s: error %d transferring data, sector %u, nr %u, cmd response %#x, card status %#x\n",
req->rq_disk->disk_name, brq->data.error,
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 3.4] mmc: block: fix a bug of error handling in MMC driver
2013-12-05 16:47 [PATCH 3.4] mmc: block: fix a bug of error handling in MMC driver Yoshitake Kobayashi
@ 2013-12-06 12:21 ` Luis Henriques
2013-12-28 22:54 ` Ben Hutchings
1 sibling, 0 replies; 3+ messages in thread
From: Luis Henriques @ 2013-12-06 12:21 UTC (permalink / raw)
To: Yoshitake Kobayashi; +Cc: gregkh, stable, cjb, linux-kernel
On Fri, Dec 06, 2013 at 01:47:03AM +0900, Yoshitake Kobayashi wrote:
> From: KOBAYASHI Yoshitake <yoshitake.kobayashi@toshiba.co.jp>
>
> commit c8760069627ad3b0dbbea170f0c4c58b16e18d3d upstream.
>
> Current MMC driver doesn't handle generic error (bit19 of device
> status) in write sequence. As a result, write data gets lost when
> generic error occurs. For example, a generic error when updating a
> filesystem management information causes a loss of write data and
> corrupts the filesystem. In the worst case, the system will never
> boot.
>
> This patch includes the following functionality:
> 1. To enable error checking for the response of CMD12 and CMD13
> in write command sequence
> 2. To retry write sequence when a generic error occurs
>
> [Backported to 3.4-stable]
Thank you, I am queuing this backport to the 3.5 kernel as well.
Cheers,
--
Luis
>
> Signed-off-by: KOBAYASHI Yoshitake
> <yoshitake.kobayashi@toshiba.co.jp> Signed-off-by: Chris Ball
> <cjb@laptop.org> --- drivers/mmc/card/block.c | 47
> +++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 44
> insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
> index 833ff16..91042a2 100644
> --- a/drivers/mmc/card/block.c
> +++ b/drivers/mmc/card/block.c
> @@ -701,7 +701,7 @@ static int mmc_blk_cmd_error(struct request *req, const char *name, int error,
> * Otherwise we don't understand what happened, so abort.
> */
> static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
> - struct mmc_blk_request *brq, int *ecc_err)
> + struct mmc_blk_request *brq, int *ecc_err, int *gen_err)
> {
> bool prev_cmd_status_valid = true;
> u32 status, stop_status = 0;
> @@ -739,6 +739,16 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
> (brq->cmd.resp[0] & R1_CARD_ECC_FAILED))
> *ecc_err = 1;
>
> + /* Flag General errors */
> + if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
> + if ((status & R1_ERROR) ||
> + (brq->stop.resp[0] & R1_ERROR)) {
> + pr_err("%s: %s: general error sending stop or status command, stop cmd response %#x, card status %#x\n",
> + req->rq_disk->disk_name, __func__,
> + brq->stop.resp[0], status);
> + *gen_err = 1;
> + }
> +
> /*
> * Check the current card state. If it is in some data transfer
> * mode, tell it to stop (and hopefully transition back to TRAN.)
> @@ -758,6 +768,13 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
> return ERR_ABORT;
> if (stop_status & R1_CARD_ECC_FAILED)
> *ecc_err = 1;
> + if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
> + if (stop_status & R1_ERROR) {
> + pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
> + req->rq_disk->disk_name, __func__,
> + stop_status);
> + *gen_err = 1;
> + }
> }
>
> /* Check for set block count errors */
> @@ -1007,7 +1024,7 @@ static int mmc_blk_err_check(struct mmc_card *card,
> mmc_active);
> struct mmc_blk_request *brq = &mq_mrq->brq;
> struct request *req = mq_mrq->req;
> - int ecc_err = 0;
> + int ecc_err = 0, gen_err = 0;
>
> /*
> * sbc.error indicates a problem with the set block count
> @@ -1021,7 +1038,7 @@ static int mmc_blk_err_check(struct mmc_card *card,
> */
> if (brq->sbc.error || brq->cmd.error || brq->stop.error ||
> brq->data.error) {
> - switch (mmc_blk_cmd_recovery(card, req, brq, &ecc_err)) {
> + switch (mmc_blk_cmd_recovery(card, req, brq, &ecc_err, &gen_err)) {
> case ERR_RETRY:
> return MMC_BLK_RETRY;
> case ERR_ABORT:
> @@ -1051,6 +1068,15 @@ static int mmc_blk_err_check(struct mmc_card *card,
> */
> if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
> u32 status;
> +
> + /* Check stop command response */
> + if (brq->stop.resp[0] & R1_ERROR) {
> + pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
> + req->rq_disk->disk_name, __func__,
> + brq->stop.resp[0]);
> + gen_err = 1;
> + }
> +
> do {
> int err = get_card_status(card, &status, 5);
> if (err) {
> @@ -1058,6 +1084,14 @@ static int mmc_blk_err_check(struct mmc_card *card,
> req->rq_disk->disk_name, err);
> return MMC_BLK_CMD_ERR;
> }
> +
> + if (status & R1_ERROR) {
> + pr_err("%s: %s: general error sending status command, card status %#x\n",
> + req->rq_disk->disk_name, __func__,
> + status);
> + gen_err = 1;
> + }
> +
> /*
> * Some cards mishandle the status bits,
> * so make sure to check both the busy
> @@ -1067,6 +1101,13 @@ static int mmc_blk_err_check(struct mmc_card *card,
> (R1_CURRENT_STATE(status) == R1_STATE_PRG));
> }
>
> + /* if general error occurs, retry the write operation. */
> + if (gen_err) {
> + pr_warning("%s: retrying write for general error\n",
> + req->rq_disk->disk_name);
> + return MMC_BLK_RETRY;
> + }
> +
> if (brq->data.error) {
> pr_err("%s: error %d transferring data, sector %u, nr %u, cmd response %#x, card status %#x\n",
> req->rq_disk->disk_name, brq->data.error,
> --
> 1.7.0.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe stable" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 3.4] mmc: block: fix a bug of error handling in MMC driver
2013-12-05 16:47 [PATCH 3.4] mmc: block: fix a bug of error handling in MMC driver Yoshitake Kobayashi
2013-12-06 12:21 ` Luis Henriques
@ 2013-12-28 22:54 ` Ben Hutchings
1 sibling, 0 replies; 3+ messages in thread
From: Ben Hutchings @ 2013-12-28 22:54 UTC (permalink / raw)
To: Yoshitake Kobayashi; +Cc: gregkh, stable, cjb, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 5480 bytes --]
On Fri, 2013-12-06 at 01:47 +0900, Yoshitake Kobayashi wrote:
> From: KOBAYASHI Yoshitake <yoshitake.kobayashi@toshiba.co.jp>
>
> commit c8760069627ad3b0dbbea170f0c4c58b16e18d3d upstream.
>
> Current MMC driver doesn't handle generic error (bit19 of device
> status) in write sequence. As a result, write data gets lost when
> generic error occurs. For example, a generic error when updating a
> filesystem management information causes a loss of write data and
> corrupts the filesystem. In the worst case, the system will never
> boot.
>
> This patch includes the following functionality:
> 1. To enable error checking for the response of CMD12 and CMD13
> in write command sequence
> 2. To retry write sequence when a generic error occurs
>
> [Backported to 3.4-stable]
>
> Signed-off-by: KOBAYASHI Yoshitake <yoshitake.kobayashi@toshiba.co.jp>
> Signed-off-by: Chris Ball <cjb@laptop.org>
I've also queued this up for 3.2, thanks.
Ben.
> ---
> drivers/mmc/card/block.c | 47 +++++++++++++++++++++++++++++++++++++++++++--
> 1 files changed, 44 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
> index 833ff16..91042a2 100644
> --- a/drivers/mmc/card/block.c
> +++ b/drivers/mmc/card/block.c
> @@ -701,7 +701,7 @@ static int mmc_blk_cmd_error(struct request *req, const char *name, int error,
> * Otherwise we don't understand what happened, so abort.
> */
> static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
> - struct mmc_blk_request *brq, int *ecc_err)
> + struct mmc_blk_request *brq, int *ecc_err, int *gen_err)
> {
> bool prev_cmd_status_valid = true;
> u32 status, stop_status = 0;
> @@ -739,6 +739,16 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
> (brq->cmd.resp[0] & R1_CARD_ECC_FAILED))
> *ecc_err = 1;
>
> + /* Flag General errors */
> + if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
> + if ((status & R1_ERROR) ||
> + (brq->stop.resp[0] & R1_ERROR)) {
> + pr_err("%s: %s: general error sending stop or status command, stop cmd response %#x, card status %#x\n",
> + req->rq_disk->disk_name, __func__,
> + brq->stop.resp[0], status);
> + *gen_err = 1;
> + }
> +
> /*
> * Check the current card state. If it is in some data transfer
> * mode, tell it to stop (and hopefully transition back to TRAN.)
> @@ -758,6 +768,13 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
> return ERR_ABORT;
> if (stop_status & R1_CARD_ECC_FAILED)
> *ecc_err = 1;
> + if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
> + if (stop_status & R1_ERROR) {
> + pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
> + req->rq_disk->disk_name, __func__,
> + stop_status);
> + *gen_err = 1;
> + }
> }
>
> /* Check for set block count errors */
> @@ -1007,7 +1024,7 @@ static int mmc_blk_err_check(struct mmc_card *card,
> mmc_active);
> struct mmc_blk_request *brq = &mq_mrq->brq;
> struct request *req = mq_mrq->req;
> - int ecc_err = 0;
> + int ecc_err = 0, gen_err = 0;
>
> /*
> * sbc.error indicates a problem with the set block count
> @@ -1021,7 +1038,7 @@ static int mmc_blk_err_check(struct mmc_card *card,
> */
> if (brq->sbc.error || brq->cmd.error || brq->stop.error ||
> brq->data.error) {
> - switch (mmc_blk_cmd_recovery(card, req, brq, &ecc_err)) {
> + switch (mmc_blk_cmd_recovery(card, req, brq, &ecc_err, &gen_err)) {
> case ERR_RETRY:
> return MMC_BLK_RETRY;
> case ERR_ABORT:
> @@ -1051,6 +1068,15 @@ static int mmc_blk_err_check(struct mmc_card *card,
> */
> if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
> u32 status;
> +
> + /* Check stop command response */
> + if (brq->stop.resp[0] & R1_ERROR) {
> + pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
> + req->rq_disk->disk_name, __func__,
> + brq->stop.resp[0]);
> + gen_err = 1;
> + }
> +
> do {
> int err = get_card_status(card, &status, 5);
> if (err) {
> @@ -1058,6 +1084,14 @@ static int mmc_blk_err_check(struct mmc_card *card,
> req->rq_disk->disk_name, err);
> return MMC_BLK_CMD_ERR;
> }
> +
> + if (status & R1_ERROR) {
> + pr_err("%s: %s: general error sending status command, card status %#x\n",
> + req->rq_disk->disk_name, __func__,
> + status);
> + gen_err = 1;
> + }
> +
> /*
> * Some cards mishandle the status bits,
> * so make sure to check both the busy
> @@ -1067,6 +1101,13 @@ static int mmc_blk_err_check(struct mmc_card *card,
> (R1_CURRENT_STATE(status) == R1_STATE_PRG));
> }
>
> + /* if general error occurs, retry the write operation. */
> + if (gen_err) {
> + pr_warning("%s: retrying write for general error\n",
> + req->rq_disk->disk_name);
> + return MMC_BLK_RETRY;
> + }
> +
> if (brq->data.error) {
> pr_err("%s: error %d transferring data, sector %u, nr %u, cmd response %#x, card status %#x\n",
> req->rq_disk->disk_name, brq->data.error,
--
Ben Hutchings
Kids! Bringing about Armageddon can be dangerous. Do not attempt it in
your own home. - Terry Pratchett and Neil Gaiman, `Good Omens'
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-12-28 22:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-05 16:47 [PATCH 3.4] mmc: block: fix a bug of error handling in MMC driver Yoshitake Kobayashi
2013-12-06 12:21 ` Luis Henriques
2013-12-28 22:54 ` Ben Hutchings
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox