* [PATCH 1/7] zram: fix race between reset and flushing pending work
[not found] <1389611942-15544-1-git-send-email-minchan@kernel.org>
@ 2014-01-13 11:18 ` Minchan Kim
2014-01-13 23:55 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Minchan Kim @ 2014-01-13 11:18 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, Nitin Gupta, Jerome Marchand, Sergey Senozhatsky,
Minchan Kim, stable
Dan and Sergey reported that there is a racy between reset and
flushing of pending work so that it could make oops by freeing
zram->meta in reset while zram_slot_free can access zram->meta
if new request is adding during the race window.
This patch moves flush after taking init_lock so it prevents
new request so that it closes the race.
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
drivers/block/zram/zram_drv.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index f9711c5..213dfc1 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -553,14 +553,14 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
size_t index;
struct zram_meta *meta;
- flush_work(&zram->free_work);
-
down_write(&zram->init_lock);
if (!zram->init_done) {
up_write(&zram->init_lock);
return;
}
+ flush_work(&zram->free_work);
+
meta = zram->meta;
zram->init_done = 0;
--
1.8.4.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/7] zram: fix race between reset and flushing pending work
2014-01-13 11:18 ` [PATCH 1/7] zram: fix race between reset and flushing pending work Minchan Kim
@ 2014-01-13 23:55 ` Andrew Morton
2014-01-14 0:15 ` Minchan Kim
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2014-01-13 23:55 UTC (permalink / raw)
To: Minchan Kim
Cc: linux-kernel, Nitin Gupta, Jerome Marchand, Sergey Senozhatsky,
stable
On Mon, 13 Jan 2014 20:18:56 +0900 Minchan Kim <minchan@kernel.org> wrote:
> Dan and Sergey reported that there is a racy between reset and
> flushing of pending work so that it could make oops by freeing
> zram->meta in reset while zram_slot_free can access zram->meta
> if new request is adding during the race window.
>
> This patch moves flush after taking init_lock so it prevents
> new request so that it closes the race.
>
> ..
>
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -553,14 +553,14 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
> size_t index;
> struct zram_meta *meta;
>
> - flush_work(&zram->free_work);
> -
> down_write(&zram->init_lock);
> if (!zram->init_done) {
> up_write(&zram->init_lock);
> return;
> }
>
> + flush_work(&zram->free_work);
> +
> meta = zram->meta;
> zram->init_done = 0;
This makes zram.lock nest inside zram.init_lock, which afaict is new
behaviour.
That all seems OK and logical - has it been well tested with lockdep?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/7] zram: fix race between reset and flushing pending work
2014-01-13 23:55 ` Andrew Morton
@ 2014-01-14 0:15 ` Minchan Kim
0 siblings, 0 replies; 3+ messages in thread
From: Minchan Kim @ 2014-01-14 0:15 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, Nitin Gupta, Jerome Marchand, Sergey Senozhatsky,
stable
On Mon, Jan 13, 2014 at 03:55:27PM -0800, Andrew Morton wrote:
> On Mon, 13 Jan 2014 20:18:56 +0900 Minchan Kim <minchan@kernel.org> wrote:
>
> > Dan and Sergey reported that there is a racy between reset and
> > flushing of pending work so that it could make oops by freeing
> > zram->meta in reset while zram_slot_free can access zram->meta
> > if new request is adding during the race window.
> >
> > This patch moves flush after taking init_lock so it prevents
> > new request so that it closes the race.
> >
> > ..
> >
> > --- a/drivers/block/zram/zram_drv.c
> > +++ b/drivers/block/zram/zram_drv.c
> > @@ -553,14 +553,14 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
> > size_t index;
> > struct zram_meta *meta;
> >
> > - flush_work(&zram->free_work);
> > -
> > down_write(&zram->init_lock);
> > if (!zram->init_done) {
> > up_write(&zram->init_lock);
> > return;
> > }
> >
> > + flush_work(&zram->free_work);
> > +
> > meta = zram->meta;
> > zram->init_done = 0;
>
> This makes zram.lock nest inside zram.init_lock, which afaict is new
> behaviour.
Originally, it was nested so it's not new. :)
Look at zram_make_request which hold init_lock and then zram_bvec_rw
hold zram->lock.
>
> That all seems OK and logical - has it been well tested with lockdep?
Yeb.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
Kind regards,
Minchan Kim
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-01-14 0:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1389611942-15544-1-git-send-email-minchan@kernel.org>
2014-01-13 11:18 ` [PATCH 1/7] zram: fix race between reset and flushing pending work Minchan Kim
2014-01-13 23:55 ` Andrew Morton
2014-01-14 0:15 ` Minchan Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox