public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: Daniel Mack <daniel@zonque.org>
Cc: miquel.raynal@bootlin.com, linux-mtd@lists.infradead.org,
	chris.packham@alliedtelesis.co.nz, stable@vger.kernel.org
Subject: Re: [PATCH] mtd: rawnand: marvell: check for RDY bits after enabling the IRQ
Date: Thu, 27 Sep 2018 08:20:33 +0200	[thread overview]
Message-ID: <20180927082033.0b5295de@bbrezillon> (raw)
In-Reply-To: <20180926212353.13399-1-daniel@zonque.org>

Hi Daniel,

On Wed, 26 Sep 2018 23:23:53 +0200
Daniel Mack <daniel@zonque.org> 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 driver
> Cc: stable@vger.kernel.org
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---
>  drivers/mtd/nand/raw/marvell_nand.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/marvell_nand.c b/drivers/mtd/nand/raw/marvell_nand.c
> index 666f34b58dec..e96ec7b9a152 100644
> --- a/drivers/mtd/nand/raw/marvell_nand.c
> +++ b/drivers/mtd/nand/raw/marvell_nand.c
> @@ -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));

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.

>  	marvell_nfc_disable_int(nfc, NDCR_RDYM);
>  	marvell_nfc_clear_int(nfc, NDSR_RDY(0) | NDSR_RDY(1));
>  	if (!ret) {

  parent reply	other threads:[~2018-09-27  6:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-26 21:23 [PATCH] mtd: rawnand: marvell: check for RDY bits after enabling the IRQ Daniel Mack
2018-09-26 23:33 ` Chris Packham
2018-09-26 23:42   ` Chris Packham
2018-09-27  7:13     ` Daniel Mack
2018-09-27 20:36       ` Chris Packham
2018-09-27 21:50         ` Chris Packham
2018-09-27  6:20 ` Boris Brezillon [this message]
2018-09-27  7:14   ` Daniel Mack

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180927082033.0b5295de@bbrezillon \
    --to=boris.brezillon@bootlin.com \
    --cc=chris.packham@alliedtelesis.co.nz \
    --cc=daniel@zonque.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox