linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] raid5: fix possible oops in add_stripe_bio when enable pr_debug
@ 2012-09-20  6:34 Jianpeng Ma
  2012-09-20  6:47 ` NeilBrown
  0 siblings, 1 reply; 5+ messages in thread
From: Jianpeng Ma @ 2012-09-20  6:34 UTC (permalink / raw)
  To: Neil Brown; +Cc: linux-raid

In func add_stripe_bio:
>> .....
>>		bip = &sh->dev[dd_idx].toread;
>> ......
>>spin_unlock_irq(&sh->stripe_lock);

>>	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
>>		(unsigned long long)(*bip)->bi_sector,
>>		(unsigned long long)sh->sector, dd_idx);
After spin_unlock_irq, this thread scheded and toread may become null.
So it will be oops.

Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
---
 drivers/md/raid5.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index adda94d..f172b1e 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2356,6 +2356,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
 	struct bio **bip;
 	struct r5conf *conf = sh->raid_conf;
 	int firstwrite=0;
+	sector_t sector = bi->bi_sector;
 
 	pr_debug("adding bi b#%llu to stripe s#%llu\n",
 		(unsigned long long)bi->bi_sector,
@@ -2406,7 +2407,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
 	spin_unlock_irq(&sh->stripe_lock);
 
 	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
-		(unsigned long long)(*bip)->bi_sector,
+		(unsigned long long)sector,
 		(unsigned long long)sh->sector, dd_idx);
 
 	if (conf->mddev->bitmap && firstwrite) {
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] raid5: fix possible oops in add_stripe_bio when enable pr_debug
  2012-09-20  6:34 [PATCH] raid5: fix possible oops in add_stripe_bio when enable pr_debug Jianpeng Ma
@ 2012-09-20  6:47 ` NeilBrown
  2012-09-20  7:17   ` Jianpeng Ma
  0 siblings, 1 reply; 5+ messages in thread
From: NeilBrown @ 2012-09-20  6:47 UTC (permalink / raw)
  To: Jianpeng Ma; +Cc: linux-raid

[-- Attachment #1: Type: text/plain, Size: 1571 bytes --]

On Thu, 20 Sep 2012 14:34:00 +0800 "Jianpeng Ma" <majianpeng@gmail.com> wrote:

> In func add_stripe_bio:
> >> .....
> >>		bip = &sh->dev[dd_idx].toread;
> >> ......
> >>spin_unlock_irq(&sh->stripe_lock);
> 
> >>	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
> >>		(unsigned long long)(*bip)->bi_sector,
> >>		(unsigned long long)sh->sector, dd_idx);
> After spin_unlock_irq, this thread scheded and toread may become null.
> So it will be oops.
> 
> Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
> ---
>  drivers/md/raid5.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index adda94d..f172b1e 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -2356,6 +2356,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
>  	struct bio **bip;
>  	struct r5conf *conf = sh->raid_conf;
>  	int firstwrite=0;
> +	sector_t sector = bi->bi_sector;
>  
>  	pr_debug("adding bi b#%llu to stripe s#%llu\n",
>  		(unsigned long long)bi->bi_sector,
> @@ -2406,7 +2407,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
>  	spin_unlock_irq(&sh->stripe_lock);
>  
>  	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
> -		(unsigned long long)(*bip)->bi_sector,
> +		(unsigned long long)sector,
>  		(unsigned long long)sh->sector, dd_idx);
>  
>  	if (conf->mddev->bitmap && firstwrite) {


how about we just move the spin_unlock_irq after the pr_debug??

NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re: [PATCH] raid5: fix possible oops in add_stripe_bio when enable pr_debug
  2012-09-20  6:47 ` NeilBrown
@ 2012-09-20  7:17   ` Jianpeng Ma
  2012-09-25  6:45     ` NeilBrown
  0 siblings, 1 reply; 5+ messages in thread
From: Jianpeng Ma @ 2012-09-20  7:17 UTC (permalink / raw)
  To: Neil Brown; +Cc: linux-raid

On 2012-09-20 14:47 NeilBrown <neilb@suse.de> Wrote:
>On Thu, 20 Sep 2012 14:34:00 +0800 "Jianpeng Ma" <majianpeng@gmail.com> wrote:
>
>> In func add_stripe_bio:
>> >> .....
>> >>		bip = &sh->dev[dd_idx].toread;
>> >> ......
>> >>spin_unlock_irq(&sh->stripe_lock);
>> 
>> >>	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
>> >>		(unsigned long long)(*bip)->bi_sector,
>> >>		(unsigned long long)sh->sector, dd_idx);
>> After spin_unlock_irq, this thread scheded and toread may become null.
>> So it will be oops.
>> 
>> Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
>> ---
>>  drivers/md/raid5.c |    3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>> 
>> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
>> index adda94d..f172b1e 100644
>> --- a/drivers/md/raid5.c
>> +++ b/drivers/md/raid5.c
>> @@ -2356,6 +2356,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
>>  	struct bio **bip;
>>  	struct r5conf *conf = sh->raid_conf;
>>  	int firstwrite=0;
>> +	sector_t sector = bi->bi_sector;
>>  
>>  	pr_debug("adding bi b#%llu to stripe s#%llu\n",
>>  		(unsigned long long)bi->bi_sector,
>> @@ -2406,7 +2407,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
>>  	spin_unlock_irq(&sh->stripe_lock);
>>  
>>  	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
>> -		(unsigned long long)(*bip)->bi_sector,
>> +		(unsigned long long)sector,
>>  		(unsigned long long)sh->sector, dd_idx);
>>  
>>  	if (conf->mddev->bitmap && firstwrite) {
>
>
>how about we just move the spin_unlock_irq after the pr_debug??
>
ah! Why are you think ? my method only add a parameter.
BTW, in func handle_failed_stripe:
>>if (!test_bit(R5_Wantfill, &sh->dev[i].flags) &&
>>		    (!test_bit(R5_Insync, &sh->dev[i].flags) ||
>>		      test_bit(R5_ReadError, &sh->dev[i].flags))) {
>>			bi = sh->dev[i].toread;
>>			sh->dev[i].toread = NULL;
>>			if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
>>				wake_up(&conf->wait_for_overlap);
Why use stripe_lock to protect toread?

Thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] raid5: fix possible oops in add_stripe_bio when enable pr_debug
  2012-09-20  7:17   ` Jianpeng Ma
@ 2012-09-25  6:45     ` NeilBrown
  2012-09-25  6:50       ` Jianpeng Ma
  0 siblings, 1 reply; 5+ messages in thread
From: NeilBrown @ 2012-09-25  6:45 UTC (permalink / raw)
  To: Jianpeng Ma; +Cc: linux-raid

[-- Attachment #1: Type: text/plain, Size: 2487 bytes --]

On Thu, 20 Sep 2012 15:17:54 +0800 "Jianpeng Ma" <majianpeng@gmail.com> wrote:

> On 2012-09-20 14:47 NeilBrown <neilb@suse.de> Wrote:
> >On Thu, 20 Sep 2012 14:34:00 +0800 "Jianpeng Ma" <majianpeng@gmail.com> wrote:
> >
> >> In func add_stripe_bio:
> >> >> .....
> >> >>		bip = &sh->dev[dd_idx].toread;
> >> >> ......
> >> >>spin_unlock_irq(&sh->stripe_lock);
> >> 
> >> >>	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
> >> >>		(unsigned long long)(*bip)->bi_sector,
> >> >>		(unsigned long long)sh->sector, dd_idx);
> >> After spin_unlock_irq, this thread scheded and toread may become null.
> >> So it will be oops.
> >> 
> >> Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
> >> ---
> >>  drivers/md/raid5.c |    3 ++-
> >>  1 file changed, 2 insertions(+), 1 deletion(-)
> >> 
> >> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> >> index adda94d..f172b1e 100644
> >> --- a/drivers/md/raid5.c
> >> +++ b/drivers/md/raid5.c
> >> @@ -2356,6 +2356,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
> >>  	struct bio **bip;
> >>  	struct r5conf *conf = sh->raid_conf;
> >>  	int firstwrite=0;
> >> +	sector_t sector = bi->bi_sector;
> >>  
> >>  	pr_debug("adding bi b#%llu to stripe s#%llu\n",
> >>  		(unsigned long long)bi->bi_sector,
> >> @@ -2406,7 +2407,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
> >>  	spin_unlock_irq(&sh->stripe_lock);
> >>  
> >>  	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
> >> -		(unsigned long long)(*bip)->bi_sector,
> >> +		(unsigned long long)sector,
> >>  		(unsigned long long)sh->sector, dd_idx);
> >>  
> >>  	if (conf->mddev->bitmap && firstwrite) {
> >
> >
> >how about we just move the spin_unlock_irq after the pr_debug??
> >
> ah! Why are you think ? my method only add a parameter.

Yes.

> BTW, in func handle_failed_stripe:
> >>if (!test_bit(R5_Wantfill, &sh->dev[i].flags) &&
> >>		    (!test_bit(R5_Insync, &sh->dev[i].flags) ||
> >>		      test_bit(R5_ReadError, &sh->dev[i].flags))) {
> >>			bi = sh->dev[i].toread;
> >>			sh->dev[i].toread = NULL;
> >>			if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
> >>				wake_up(&conf->wait_for_overlap);
> Why use stripe_lock to protect toread?

I assume you mean that we should be holding the lock to protect toread, but
we aren't.
I've queued a patch to fix that.

Thanks.
NeilBrown


> 
> Thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re: [PATCH] raid5: fix possible oops in add_stripe_bio when enable pr_debug
  2012-09-25  6:45     ` NeilBrown
@ 2012-09-25  6:50       ` Jianpeng Ma
  0 siblings, 0 replies; 5+ messages in thread
From: Jianpeng Ma @ 2012-09-25  6:50 UTC (permalink / raw)
  To: Neil Brown; +Cc: linux-raid

On 2012-09-25 14:45 NeilBrown <neilb@suse.de> Wrote:
>On Thu, 20 Sep 2012 15:17:54 +0800 "Jianpeng Ma" <majianpeng@gmail.com> wrote:
>
>> On 2012-09-20 14:47 NeilBrown <neilb@suse.de> Wrote:
>> >On Thu, 20 Sep 2012 14:34:00 +0800 "Jianpeng Ma" <majianpeng@gmail.com> wrote:
>> >
>> >> In func add_stripe_bio:
>> >> >> .....
>> >> >>		bip = &sh->dev[dd_idx].toread;
>> >> >> ......
>> >> >>spin_unlock_irq(&sh->stripe_lock);
>> >> 
>> >> >>	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
>> >> >>		(unsigned long long)(*bip)->bi_sector,
>> >> >>		(unsigned long long)sh->sector, dd_idx);
>> >> After spin_unlock_irq, this thread scheded and toread may become null.
>> >> So it will be oops.
>> >> 
>> >> Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
>> >> ---
>> >>  drivers/md/raid5.c |    3 ++-
>> >>  1 file changed, 2 insertions(+), 1 deletion(-)
>> >> 
>> >> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
>> >> index adda94d..f172b1e 100644
>> >> --- a/drivers/md/raid5.c
>> >> +++ b/drivers/md/raid5.c
>> >> @@ -2356,6 +2356,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
>> >>  	struct bio **bip;
>> >>  	struct r5conf *conf = sh->raid_conf;
>> >>  	int firstwrite=0;
>> >> +	sector_t sector = bi->bi_sector;
>> >>  
>> >>  	pr_debug("adding bi b#%llu to stripe s#%llu\n",
>> >>  		(unsigned long long)bi->bi_sector,
>> >> @@ -2406,7 +2407,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
>> >>  	spin_unlock_irq(&sh->stripe_lock);
>> >>  
>> >>  	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
>> >> -		(unsigned long long)(*bip)->bi_sector,
>> >> +		(unsigned long long)sector,
>> >>  		(unsigned long long)sh->sector, dd_idx);
>> >>  
>> >>  	if (conf->mddev->bitmap && firstwrite) {
>> >
>> >
>> >how about we just move the spin_unlock_irq after the pr_debug??
>> >
>> ah! Why are you think ? my method only add a parameter.
>
>Yes.
>
>> BTW, in func handle_failed_stripe:
>> >>if (!test_bit(R5_Wantfill, &sh->dev[i].flags) &&
>> >>		    (!test_bit(R5_Insync, &sh->dev[i].flags) ||
>> >>		      test_bit(R5_ReadError, &sh->dev[i].flags))) {
>> >>			bi = sh->dev[i].toread;
>> >>			sh->dev[i].toread = NULL;
>> >>			if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
>> >>				wake_up(&conf->wait_for_overlap);
>> Why use stripe_lock to protect toread?
>
>I assume you mean that we should be holding the lock to protect toread, but
>we aren't.
>I've queued a patch to fix that.
>
Hi,
	Last Saturday, i sent a patch-set which contained a patch which fix this bug.
You can check your mail!
Thanks!
>Thanks.
>NeilBrown
>

>
>> 
>> Thanks!
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-09-25  6:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-20  6:34 [PATCH] raid5: fix possible oops in add_stripe_bio when enable pr_debug Jianpeng Ma
2012-09-20  6:47 ` NeilBrown
2012-09-20  7:17   ` Jianpeng Ma
2012-09-25  6:45     ` NeilBrown
2012-09-25  6:50       ` Jianpeng Ma

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).