From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Xiaoming Ni <nixiaoming@huawei.com>
Cc: <richard@nod.at>, <vigneshr@ti.com>,
<tudor.ambarus@microchip.com>, <tglx@linutronix.de>,
<linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
<stable@vger.kernel.org>, <gregkh@linuxfoundation.org>,
<wangle6@huawei.com>
Subject: Re: ping // [PATCH] mtd:cfi_cmdset_0002: fix atomic sleep bug when CONFIG_MTD_XIP=y
Date: Mon, 7 Dec 2020 11:53:30 +0100 [thread overview]
Message-ID: <20201207115228.0a6de398@xps13> (raw)
In-Reply-To: <a02e1364-3b82-039a-4b65-e2a216663dd4@huawei.com>
Hi Xiaoming,
Xiaoming Ni <nixiaoming@huawei.com> wrote on Mon, 7 Dec 2020 18:48:33
+0800:
> ping
>
> On 2020/11/27 21:07, Xiaoming Ni wrote:
> > When CONFIG_MTD_XIP=y, local_irq_disable() is called in xip_disable().
> > To avoid sleep in interrupt context, we need to call local_irq_enable()
> > before schedule().
> >
> > The problem call stack is as follows:
> > bug1:
> > do_write_oneword_retry()
> > xip_disable()
> > local_irq_disable()
> > do_write_oneword_once()
> > schedule()
> > bug2:
> > do_write_buffer()
> > xip_disable()
> > local_irq_disable()
> > do_write_buffer_wait()
> > schedule()
> > bug3:
> > do_erase_chip()
> > xip_disable()
> > local_irq_disable()
> > schedule()
> > bug4:
> > do_erase_oneblock()
> > xip_disable()
> > local_irq_disable()
> > schedule()
> >
> > Fixes: 02b15e343aee ("[MTD] XIP for AMD CFI flash.")
> > Cc: stable@vger.kernel.org # v2.6.13
> > Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
> > ---
> > drivers/mtd/chips/cfi_cmdset_0002.c | 16 ++++++++++++++++
> > 1 file changed, 16 insertions(+)
> >
> > diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
> > index a1f3e1031c3d..12c3776f093a 100644
> > --- a/drivers/mtd/chips/cfi_cmdset_0002.c
> > +++ b/drivers/mtd/chips/cfi_cmdset_0002.c
> > @@ -1682,7 +1682,11 @@ static int __xipram do_write_oneword_once(struct map_info *map,
> > set_current_state(TASK_UNINTERRUPTIBLE);
> > add_wait_queue(&chip->wq, &wait);
> > mutex_unlock(&chip->mutex);
> > + if (IS_ENABLED(CONFIG_MTD_XIP))
> > + local_irq_enable();
> > schedule();
> > + if (IS_ENABLED(CONFIG_MTD_XIP))
> > + local_irq_disable();
The fix really seems strange to me. I will let Vignesh decide but I
think we should consider updating/fixing xip_disable instead.
> > remove_wait_queue(&chip->wq, &wait);
> > timeo = jiffies + (HZ / 2); /* FIXME */
> > mutex_lock(&chip->mutex);
> > @@ -1962,7 +1966,11 @@ static int __xipram do_write_buffer_wait(struct map_info *map,
> > set_current_state(TASK_UNINTERRUPTIBLE);
> > add_wait_queue(&chip->wq, &wait);
> > mutex_unlock(&chip->mutex);
> > + if (IS_ENABLED(CONFIG_MTD_XIP))
> > + local_irq_enable();
> > schedule();
> > + if (IS_ENABLED(CONFIG_MTD_XIP))
> > + local_irq_disable();
> > remove_wait_queue(&chip->wq, &wait);
> > timeo = jiffies + (HZ / 2); /* FIXME */
> > mutex_lock(&chip->mutex);
> > @@ -2461,7 +2469,11 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
> > set_current_state(TASK_UNINTERRUPTIBLE);
> > add_wait_queue(&chip->wq, &wait);
> > mutex_unlock(&chip->mutex);
> > + if (IS_ENABLED(CONFIG_MTD_XIP))
> > + local_irq_enable();
> > schedule();
> > + if (IS_ENABLED(CONFIG_MTD_XIP))
> > + local_irq_disable();
> > remove_wait_queue(&chip->wq, &wait);
> > mutex_lock(&chip->mutex);
> > continue;
> > @@ -2560,7 +2572,11 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
> > set_current_state(TASK_UNINTERRUPTIBLE);
> > add_wait_queue(&chip->wq, &wait);
> > mutex_unlock(&chip->mutex);
> > + if (IS_ENABLED(CONFIG_MTD_XIP))
> > + local_irq_enable();
> > schedule();
> > + if (IS_ENABLED(CONFIG_MTD_XIP))
> > + local_irq_disable();
> > remove_wait_queue(&chip->wq, &wait);
> > mutex_lock(&chip->mutex);
> > continue;
> >
>
Thanks,
Miquèl
next prev parent reply other threads:[~2020-12-07 10:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-27 13:07 [PATCH] mtd:cfi_cmdset_0002: fix atomic sleep bug when CONFIG_MTD_XIP=y Xiaoming Ni
2020-12-07 10:48 ` ping // " Xiaoming Ni
2020-12-07 10:53 ` Miquel Raynal [this message]
2020-12-07 18:59 ` Vignesh Raghavendra
2020-12-08 1:23 ` Xiaoming Ni
2020-12-14 7:16 ` Vignesh Raghavendra
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=20201207115228.0a6de398@xps13 \
--to=miquel.raynal@bootlin.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=nixiaoming@huawei.com \
--cc=richard@nod.at \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tudor.ambarus@microchip.com \
--cc=vigneshr@ti.com \
--cc=wangle6@huawei.com \
/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