* [PATCH] mtd/chips: add missing set_current_state() to cfi_{amdstd,staa}_sync()
@ 2008-04-03 19:38 Dmitry Adamushko
2008-04-07 23:15 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Adamushko @ 2008-04-03 19:38 UTC (permalink / raw)
To: linux-mtd; +Cc: dwmw2, linux-kernel
From: Dmitry Adamushko <dmitry.adamushko@gmail.com>
Subject: [mtd/chips] add missing set_current_state() to cfi_{amdstd,staa}_sync()
cfi_amdstd_sync() and cfi_staa_sync() call schedule() without changing
task's state appropriately.
In case of e.g. chip->state == FL_ERASING, cfi_*_sync() will be busy-looping
either redundantly for a fixed interval of time (for SCHED_NORMAL tasks) or
possibly endlessly (for RT tasks and UP).
Signed-off-by: Dmitry Adamushko <dmitry.adamushko@gmail.com>
---
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index d072e87..458d477 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -1763,6 +1763,7 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
default:
/* Not an idle state */
+ set_current_state(TASK_UNINTERRUPTIBLE);
add_wait_queue(&chip->wq, &wait);
spin_unlock(chip->mutex);
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index b344ff8..492e2ab 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -1015,6 +1015,7 @@ static void cfi_staa_sync (struct mtd_info *mtd)
default:
/* Not an idle state */
+ set_current_state(TASK_UNINTERRUPTIBLE);
add_wait_queue(&chip->wq, &wait);
spin_unlock_bh(chip->mutex);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd/chips: add missing set_current_state() to cfi_{amdstd,staa}_sync()
2008-04-03 19:38 [PATCH] mtd/chips: add missing set_current_state() to cfi_{amdstd,staa}_sync() Dmitry Adamushko
@ 2008-04-07 23:15 ` Andrew Morton
2008-04-08 8:21 ` [PATCH] mtd/chips: add missing set_current_state() to cfi_{amdstd, staa}_sync() Dmitry Adamushko
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2008-04-07 23:15 UTC (permalink / raw)
To: Dmitry Adamushko; +Cc: dwmw2, linux-mtd, linux-kernel
On Thu, 03 Apr 2008 21:38:23 +0200
Dmitry Adamushko <dmitry.adamushko@gmail.com> wrote:
> From: Dmitry Adamushko <dmitry.adamushko@gmail.com>
> Subject: [mtd/chips] add missing set_current_state() to cfi_{amdstd,staa}_sync()
>
> cfi_amdstd_sync() and cfi_staa_sync() call schedule() without changing
> task's state appropriately.
>
> In case of e.g. chip->state == FL_ERASING, cfi_*_sync() will be busy-looping
> either redundantly for a fixed interval of time (for SCHED_NORMAL tasks) or
> possibly endlessly (for RT tasks and UP).
>
> Signed-off-by: Dmitry Adamushko <dmitry.adamushko@gmail.com>
>
> ---
>
> diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
> index d072e87..458d477 100644
> --- a/drivers/mtd/chips/cfi_cmdset_0002.c
> +++ b/drivers/mtd/chips/cfi_cmdset_0002.c
> @@ -1763,6 +1763,7 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
>
> default:
> /* Not an idle state */
> + set_current_state(TASK_UNINTERRUPTIBLE);
> add_wait_queue(&chip->wq, &wait);
>
> spin_unlock(chip->mutex);
> diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
> index b344ff8..492e2ab 100644
> --- a/drivers/mtd/chips/cfi_cmdset_0020.c
> +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
> @@ -1015,6 +1015,7 @@ static void cfi_staa_sync (struct mtd_info *mtd)
>
> default:
> /* Not an idle state */
> + set_current_state(TASK_UNINTERRUPTIBLE);
> add_wait_queue(&chip->wq, &wait);
>
> spin_unlock_bh(chip->mutex);
The change certainly looks correct. Has it been runtime tested?
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd/chips: add missing set_current_state() to cfi_{amdstd, staa}_sync()
2008-04-07 23:15 ` Andrew Morton
@ 2008-04-08 8:21 ` Dmitry Adamushko
0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Adamushko @ 2008-04-08 8:21 UTC (permalink / raw)
To: Andrew Morton; +Cc: dwmw2, linux-mtd, linux-kernel
On 08/04/2008, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Thu, 03 Apr 2008 21:38:23 +0200
> Dmitry Adamushko <dmitry.adamushko@gmail.com> wrote:
>
> > From: Dmitry Adamushko <dmitry.adamushko@gmail.com>
> > Subject: [mtd/chips] add missing set_current_state() to cfi_{amdstd,staa}_sync()
> >
> > cfi_amdstd_sync() and cfi_staa_sync() call schedule() without changing
> > task's state appropriately.
> >
> > In case of e.g. chip->state == FL_ERASING, cfi_*_sync() will be busy-looping
> > either redundantly for a fixed interval of time (for SCHED_NORMAL tasks) or
> > possibly endlessly (for RT tasks and UP).
> >
> > Signed-off-by: Dmitry Adamushko <dmitry.adamushko@gmail.com>
> >
> > ---
> >
> > diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
> > index d072e87..458d477 100644
> > --- a/drivers/mtd/chips/cfi_cmdset_0002.c
> > +++ b/drivers/mtd/chips/cfi_cmdset_0002.c
> > @@ -1763,6 +1763,7 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
> >
> > default:
> > /* Not an idle state */
> > + set_current_state(TASK_UNINTERRUPTIBLE);
> > add_wait_queue(&chip->wq, &wait);
> >
> > spin_unlock(chip->mutex);
> > diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
> > index b344ff8..492e2ab 100644
> > --- a/drivers/mtd/chips/cfi_cmdset_0020.c
> > +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
> > @@ -1015,6 +1015,7 @@ static void cfi_staa_sync (struct mtd_info *mtd)
> >
> > default:
> > /* Not an idle state */
> > + set_current_state(TASK_UNINTERRUPTIBLE);
> > add_wait_queue(&chip->wq, &wait);
> >
> > spin_unlock_bh(chip->mutex);
>
>
> The change certainly looks correct. Has it been runtime tested?
It has been tested with an oldish 2.6.8.1 where the problem initially
occured. It was a RT task that happened to close an mtd fd (and
resulting in ->sync() being called) and ran in the middle of the
->erase op... resulting in a "nice" endless loop.
The versions of cfi_{amdstd,staa}_sync() in the mainline look not that
much different from the respective versions in 2.6.8.1.
I guess, it went unnoticed for so long time due to :
(1) apps. don't often directly open/close() fd for mtd partitions;
(2) a race against ->erase() (or smth else) is rare;
(3) if (1) is not true, then an app. is still unlikely to be RT (in
which case, a task just loops until its timeslice is gone).
>
> Thanks.
>
--
Best regards,
Dmitry Adamushko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-04-08 8:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-03 19:38 [PATCH] mtd/chips: add missing set_current_state() to cfi_{amdstd,staa}_sync() Dmitry Adamushko
2008-04-07 23:15 ` Andrew Morton
2008-04-08 8:21 ` [PATCH] mtd/chips: add missing set_current_state() to cfi_{amdstd, staa}_sync() Dmitry Adamushko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).