mtd: rawnand: marvell: check for RDY bits after enabling the IRQ
Subsystems (4)
PATCH 1/1 mtd: rawnand: marvell: check for RDY bits after enabling the IRQ
At least on PXA3xx platforms, enabling RDY interrupts in the NDCR register will only cause the IRQ to latch when the RDY lanes are changing, and not in case they are already asserted.
This means that if the controller finished the command in flight before marvell_nfc_wait_op() is called, that function will wait for a change in the bit that can't ever happen as it is already set.
To mitigate this race, check for the RDY bits after the IRQ was enabled, and only sleep on the condition if the controller isn't ready yet.
This fixes a bug that was observed with a NAND chip that holds a UBIFS parition on which file system stress tests were executed. When marvell_nfc_wait_op() reports an error, UBI/UBIFS will eventually mount the filesystem read-only, reporting lots of warnings along the way.
--- drivers/mtd/nand/raw/marvell_nand.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/marvell_nand.c +11 -3
@@ -613,7 +613,8 @@ static int marvell_nfc_wait_cmdd(struct nand_chip *chip)static int marvell_nfc_wait_op (struct nand_chip *chip,unsigned int timeout_ms) {struct marvell_nfc *nfc =to_marvell_nfc (chip->controller); -int ret; +int ret = -EALREADY ; +u32 st;/* Timeout is expressed in ms */ if (!timeout_ms)
@@ -622,8 +623,15 @@ static int marvell_nfc_wait_op(struct nand_chip *chip, unsigned int timeout_ms)init_completion (&nfc->complete);marvell_nfc_enable_int (nfc,NDCR_RDYM ); - ret =wait_for_completion_timeout (&nfc->complete, -msecs_to_jiffies (timeout_ms)); + +/* +* Check if the NDSR_RDY bits have already been set before the +* interrupt was enabled. +*/ + st =readl_relaxed (nfc->regs +NDSR ); +if (!(st & (NDSR_RDY (0 ) |NDSR_RDY (1 )))) + ret =wait_for_completion_timeout (&nfc->complete, +msecs_to_jiffies (timeout_ms));marvell_nfc_disable_int (nfc,NDCR_RDYM );marvell_nfc_clear_int (nfc,NDSR_RDY (0 ) |NDSR_RDY (1 ));if (!ret) {
Signature · 1 line
2.17.1
Hi Daniel,
Quoted 28 lines · Daniel Mack
At least on PXA3xx platforms, enabling RDY interrupts in the NDCR register will only cause the IRQ to latch when the RDY lanes are changing, and not in case they are already asserted.
This means that if the controller finished the command in flight before
marvell_nfc_wait_op()is called, that function will wait for a change in the bit that can't ever happen as it is already set.To mitigate this race, check for the RDY bits after the IRQ was enabled, and only sleep on the condition if the controller isn't ready yet.
This fixes a bug that was observed with a NAND chip that holds a UBIFS parition on which file system stress tests were executed. When
marvell_nfc_wait_op()reports an error, UBI/UBIFS will eventually mount the filesystem read-only, reporting lots of warnings along the way.Fixes 02f26ecf8c77 mtd: nand: add reworked Marvell NAND controller driverSigned-off-by Daniel Mack <[email protected]>--- drivers/mtd/nand/raw/marvell_nand.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/mtd/nand/raw/marvell_nand.c +0
-0
drivers/mtd/nand/raw/marvell_nand.c static int marvell_nfc_wait_cmdd(struct nand_chip *chip) · line 616
Quoted 5 lines
drivers/mtd/nand/raw/marvell_nand.c +1
-1@@ -613,7 +613,8 @@ static int marvell_nfc_wait_cmdd(struct nand_chip *chip)static int marvell_nfc_wait_op (struct nand_chip *chip,unsigned int timeout_ms) {struct marvell_nfc *nfc =to_marvell_nfc (chip->controller); -int ret; +int ret = -EALREADY ;
Won't this cause us to hit the if (!ret) below if we don't end up calling wait_for_completion_timeout()? In fact I did just hit something like this on my Armada-385 based board
marvell-nfc f10d0000.nand-controller: Timeout waiting for RB signal ubi0 warning: do_sync_erase: error -5 while erasing PEB 755, retry
Quoted 23 lines
drivers/mtd/nand/raw/marvell_nand.c +10
-2+u32 st;/* Timeout is expressed in ms */ if (!timeout_ms)@@ -622,8 +623,15 @@ static int marvell_nfc_wait_op(struct nand_chip *chip, unsigned int timeout_ms)init_completion (&nfc->complete);marvell_nfc_enable_int (nfc,NDCR_RDYM ); - ret =wait_for_completion_timeout (&nfc->complete, -msecs_to_jiffies (timeout_ms)); + +/* +* Check if the NDSR_RDY bits have already been set before the +* interrupt was enabled. +*/ + st =readl_relaxed (nfc->regs +NDSR ); +if (!(st & (NDSR_RDY (0 ) |NDSR_RDY (1 )))) + ret =wait_for_completion_timeout (&nfc->complete, +msecs_to_jiffies (timeout_ms));marvell_nfc_disable_int (nfc,NDCR_RDYM );marvell_nfc_clear_int (nfc,NDSR_RDY (0 ) |NDSR_RDY (1 ));if (!ret) {
Chris Packham
Tested-byQuoted 26 lines · Chris Packham
Hi Daniel,
Quoted 23 lines · Daniel Mack
At least on PXA3xx platforms, enabling RDY interrupts in the NDCR register will only cause the IRQ to latch when the RDY lanes are changing, and not in case they are already asserted.
This means that if the controller finished the command in flight before
marvell_nfc_wait_op()is called, that function will wait for a change in the bit that can't ever happen as it is already set.To mitigate this race, check for the RDY bits after the IRQ was enabled, and only sleep on the condition if the controller isn't ready yet.
This fixes a bug that was observed with a NAND chip that holds a UBIFS parition on which file system stress tests were executed. When
marvell_nfc_wait_op()reports an error, UBI/UBIFS will eventually mount the filesystem read-only, reporting lots of warnings along the way.Fixes 02f26ecf8c77 mtd: nand: add reworked Marvell NAND controller driverSigned-off-by Daniel Mack <[email protected]>--- drivers/mtd/nand/raw/marvell_nand.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
Quoted 13 lines
drivers/mtd/nand/raw/marvell_nand.c static int marvell_nfc_wait_cmdd(struct nand_chip *chip) · line 616
Quoted 10 lines
drivers/mtd/nand/raw/marvell_nand.c +1
-1@@ -613,7 +613,8 @@ static int marvell_nfc_wait_cmdd(struct nand_chip *chip)static int marvell_nfc_wait_op (struct nand_chip *chip,unsigned int timeout_ms) {struct marvell_nfc *nfc =to_marvell_nfc (chip->controller); -int ret; +int ret = -EALREADY ;Won't this cause us to hit the if (!ret) below if we don't end up calling
wait_for_completion_timeout()?
Nope boolean logic fail.
Quoted 6 lines
In fact I did just hit something
like this on my Armada-385 based boardmarvell-nfc f10d0000.nand-controller: Timeout waiting for RB signal ubi0 warning:
do_sync_erase: error -5 while erasing PEB 755, retry
But this still might be something else, it doesn't happen regularly. For what it's worth
Quoted 25 lines
Quoted 23 lines
drivers/mtd/nand/raw/marvell_nand.c +10
-2+u32 st;/* Timeout is expressed in ms */ if (!timeout_ms)@@ -622,8 +623,15 @@ static int marvell_nfc_wait_op(struct nand_chip *chip, unsigned int timeout_ms)init_completion (&nfc->complete);marvell_nfc_enable_int (nfc,NDCR_RDYM ); - ret =wait_for_completion_timeout (&nfc->complete, -msecs_to_jiffies (timeout_ms)); + +/* +* Check if the NDSR_RDY bits have already been set before the +* interrupt was enabled. +*/ + st =readl_relaxed (nfc->regs +NDSR ); +if (!(st & (NDSR_RDY (0 ) |NDSR_RDY (1 )))) + ret =wait_for_completion_timeout (&nfc->complete, +msecs_to_jiffies (timeout_ms));marvell_nfc_disable_int (nfc,NDCR_RDYM );marvell_nfc_clear_int (nfc,NDSR_RDY (0 ) |NDSR_RDY (1 ));if (!ret) {
Hi,
Quoted 17 lines · Chris Packham
Quoted 15 lines · Chris Packham
drivers/mtd/nand/raw/marvell_nand.c static int marvell_nfc_wait_cmdd(struct nand_chip *chip) · line 616
Quoted 10 lines · Daniel Mack
drivers/mtd/nand/raw/marvell_nand.c +1
-1@@ -613,7 +613,8 @@ static int marvell_nfc_wait_cmdd(struct nand_chip *chip)static int marvell_nfc_wait_op (struct nand_chip *chip,unsigned int timeout_ms) {struct marvell_nfc *nfc =to_marvell_nfc (chip->controller); -int ret; +int ret = -EALREADY ;Won't this cause us to hit the if (!ret) below if we don't end up calling
wait_for_completion_timeout()?
Quoted 1 line
Nope boolean logic fail.
Yup :)
Quoted 11 lines
Quoted 6 lines
In fact I did just hit something
like this on my Armada-385 based boardmarvell-nfc f10d0000.nand-controller: Timeout waiting for RB signal ubi0 warning:
do_sync_erase: error -5 while erasing PEB 755, retryBut this still might be something else, it doesn't happen regularly. For what it's worth
Tested-by Chris Packham <[email protected]>
Thanks. Did you see the issue that I described without that patch?
Cheers,
Daniel
Quoted 31 lines · Daniel Mack
Hi,
Quoted 17 lines · Chris Packham
Quoted 15 lines · Chris Packham
drivers/mtd/nand/raw/marvell_nand.c static int marvell_nfc_wait_cmdd(struct nand_chip *chip) · line 616
Quoted 10 lines · Daniel Mack
drivers/mtd/nand/raw/marvell_nand.c +1
-1@@ -613,7 +613,8 @@ static int marvell_nfc_wait_cmdd(struct nand_chip *chip)static int marvell_nfc_wait_op (struct nand_chip *chip,unsigned int timeout_ms) {struct marvell_nfc *nfc =to_marvell_nfc (chip->controller); -int ret; +int ret = -EALREADY ;Won't this cause us to hit the if (!ret) below if we don't end up calling
wait_for_completion_timeout()?Quoted 1 line
Nope boolean logic fail.
Yup :)
Quoted 7 lines
Quoted 6 lines
In fact I did just hit something
like this on my Armada-385 based boardmarvell-nfc f10d0000.nand-controller: Timeout waiting for RB signal ubi0 warning:
do_sync_erase: error -5 while erasing PEB 755, retry
Quoted 7 lines
Quoted 4 lines
But this still might be something else, it doesn't happen regularly. For what it's worth
Tested-by Chris Packham <[email protected]>Thanks. Did you see the issue that I described without that patch?
Yes. I've just tried a test without your patch and I see the same thing. I wonder if my R/B configuration is correct.
Quoted 35 lines · Chris Packham
Quoted 34 lines · Daniel Mack
Hi,
Quoted 17 lines · Chris Packham
Quoted 15 lines · Chris Packham
drivers/mtd/nand/raw/marvell_nand.c static int marvell_nfc_wait_cmdd(struct nand_chip *chip) · line 616
Quoted 10 lines · Daniel Mack
drivers/mtd/nand/raw/marvell_nand.c +1
-1@@ -613,7 +613,8 @@ static int marvell_nfc_wait_cmdd(struct nand_chip *chip)static int marvell_nfc_wait_op (struct nand_chip *chip,unsigned int timeout_ms) {struct marvell_nfc *nfc =to_marvell_nfc (chip->controller); -int ret; +int ret = -EALREADY ;Won't this cause us to hit the if (!ret) below if we don't end up calling
wait_for_completion_timeout()?Quoted 1 line
Nope boolean logic fail.
Yup :)
Quoted 10 lines
Quoted 6 lines
In fact I did just hit something
like this on my Armada-385 based boardmarvell-nfc f10d0000.nand-controller: Timeout waiting for RB signal ubi0 warning:
do_sync_erase: error -5 while erasing PEB 755, retryBut this still might be something else, it doesn't happen regularly. For what it's worth
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Tested-by Chris Packham <[email protected]>Thanks. Did you see the issue that I described without that patch?
Yes. I've just tried a test without your patch and I see the same thing. I wonder if my R/B configuration is correct.
Sure enough I was missing the pinctrl configuration so the R/B wasn't quite configured correctly.
Hi Daniel,
Quoted 42 lines · On Wed, 26 Sep 2018 23:23:53 +0200 Daniel Mack <[email protected]> wrote:
At least on PXA3xx platforms, enabling RDY interrupts in the NDCR register will only cause the IRQ to latch when the RDY lanes are changing, and not in case they are already asserted.
This means that if the controller finished the command in flight before
marvell_nfc_wait_op()is called, that function will wait for a change in the bit that can't ever happen as it is already set.To mitigate this race, check for the RDY bits after the IRQ was enabled, and only sleep on the condition if the controller isn't ready yet.
This fixes a bug that was observed with a NAND chip that holds a UBIFS parition on which file system stress tests were executed. When
marvell_nfc_wait_op()reports an error, UBI/UBIFS will eventually mount the filesystem read-only, reporting lots of warnings along the way.Fixes 02f26ecf8c77 mtd: nand: add reworked Marvell NAND controller driverSigned-off-by Daniel Mack <[email protected]>--- drivers/mtd/nand/raw/marvell_nand.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/mtd/nand/raw/marvell_nand.c +2
-2@@ -613,7 +613,8 @@ static int marvell_nfc_wait_cmdd(struct nand_chip *chip)static int marvell_nfc_wait_op (struct nand_chip *chip,unsigned int timeout_ms) {struct marvell_nfc *nfc =to_marvell_nfc (chip->controller); -int ret; +int ret = -EALREADY ; +u32 st;/* Timeout is expressed in ms */ if (!timeout_ms)@@ -622,8 +623,15 @@ static int marvell_nfc_wait_op(struct nand_chip *chip, unsigned int timeout_ms)init_completion (&nfc->complete);marvell_nfc_enable_int (nfc,NDCR_RDYM ); - ret = wait_for_completion_timeout(&nfc->complete,
drivers/mtd/nand/raw/marvell_nand.c static int marvell_nfc_wait_op(struct nand_chip *chip, unsigned int timeout_ms) · line 634
Quoted 10 lines
drivers/mtd/nand/raw/marvell_nand.c +9
-1- msecs_to_jiffies(timeout_ms)); + +/* +* Check if the NDSR_RDY bits have already been set before the +* interrupt was enabled. +*/ + st =readl_relaxed (nfc->regs +NDSR ); +if (!(st & (NDSR_RDY (0 ) |NDSR_RDY (1 )))) + ret =wait_for_completion_timeout (&nfc->complete, +msecs_to_jiffies (timeout_ms));
Or you can just do:
st = readl_relaxed(nfc->regs + NDSR); if (st & (NDSR_RDY(0) | NDSR_RDY(1))) complete(&nfc->complete); ret = wait_for_completion_timeout(&nfc->complete, msecs_to_jiffies(timeout_ms)); ...
Of course, it's less efficient than your version, but I find it clearer than the -EALREADY approach.
Quoted 3 lines
drivers/mtd/nand/raw/marvell_nand.c +0
-0marvell_nfc_disable_int (nfc,NDCR_RDYM );marvell_nfc_clear_int (nfc,NDSR_RDY (0 ) |NDSR_RDY (1 ));if (!ret) {
Hi Boris,
Quoted 18 lines · Boris Brezillon
drivers/mtd/nand/raw/marvell_nand.c static int marvell_nfc_wait_op(struct nand_chip *chip, unsigned int timeout_ms) · line 634
Quoted 12 lines · On Wed, 26 Sep 2018 23:23:53 +0200 Daniel Mack <[email protected]> wrote:
marvell_nfc_enable_int(nfc, NDCR_RDYM);drivers/mtd/nand/raw/marvell_nand.c +9
-2- ret =wait_for_completion_timeout (&nfc->complete, -msecs_to_jiffies (timeout_ms)); + +/* +* Check if the NDSR_RDY bits have already been set before the +* interrupt was enabled. +*/ + st =readl_relaxed (nfc->regs +NDSR ); +if (!(st & (NDSR_RDY (0 ) |NDSR_RDY (1 )))) + ret =wait_for_completion_timeout (&nfc->complete, +msecs_to_jiffies (timeout_ms));Or you can just do:
Quoted 8 lines
st = readl_relaxed(nfc->regs + NDSR); if (st & (NDSR_RDY(0) | NDSR_RDY(1))) complete(&nfc->complete); ret = wait_for_completion_timeout(&nfc->complete, msecs_to_jiffies(timeout_ms)); ...
Ah, yes. Thanks.
Quoted 2 lines
Of course, it's less efficient than your version, but I find it clearer than the
-EALREADYapproach.
Well, this issue usually takes minutes to trigger, so efficiency is not a good argument :)
I'll resend a v2.
Thanks,
Daniel