Skip to contentSkip to conversation

raid5: delete another BUG_ON

PATCH In review Shaohua Li 2 participants 3 messages Apr 14, 2014 – Apr 15, 2014 MD RAID

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 raid5: delete another BUG_ON

I hit another BUG_ON with e240c1839d11152b0355442. In __get_priority_stripe(), stripe count equals to 0 initially. Between atomic_inc and BUG_ON, get_active_stripe() finds the stripe. So the stripe count isn't 1 any more.

---
 drivers/md/raid5.c |    1 -
 1 file changed, 1 deletion(-)
drivers/md/raid5.c +0 -1
Index: linux/drivers/md/raid5.c
===================================================================
@@ -4371,7 +4371,6 @@ static struct stripe_head *__get_priorit
 	}
 	list_del_init(&sh->lru);
 	atomic_inc(&sh->count);
-	BUG_ON(atomic_read(&sh->count) != 1);
 	return sh;
 }
 
#1 lore raw
Quoted 15 lines · On Mon, 14 Apr 2014 14:14:17 +0800 Shaohua Li <[email protected]> wrote:

I hit another BUG_ON with e240c1839d11152b0355442. In __get_priority_stripe(), stripe count equals to 0 initially. Between atomic_inc and BUG_ON, get_active_stripe() finds the stripe. So the stripe count isn't 1 any more.

---
 drivers/md/raid5.c |    1 -
 1 file changed, 1 deletion(-)

Index: linux/drivers/md/raid5.c
===================================================================

drivers/md/raid5.c static struct stripe_head *__get_priorit · line 4376

Quoted 7 lines
drivers/md/raid5.c +0 -1
@@ -4371,7 +4371,6 @@ static struct stripe_head *__get_priorit
 	}
 	list_del_init(&sh->lru);
 	atomic_inc(&sh->count);
-	BUG_ON(atomic_read(&sh->count) != 1);
 	return sh;
 }
 

What if we made those two lines:

  BUG_ON(atomic_inc_return(&sh->count) != 1);

??

NeilBrown

author
#2 lore raw
Quoted 27 lines · NeilBrown
Quoted 15 lines · On Mon, 14 Apr 2014 14:14:17 +0800 Shaohua Li <[email protected]> wrote:

I hit another BUG_ON with e240c1839d11152b0355442. In __get_priority_stripe(), stripe count equals to 0 initially. Between atomic_inc and BUG_ON, get_active_stripe() finds the stripe. So the stripe count isn't 1 any more.

---
 drivers/md/raid5.c |    1 -
 1 file changed, 1 deletion(-)

Index: linux/drivers/md/raid5.c
===================================================================

drivers/md/raid5.c static struct stripe_head *__get_priorit · line 4376

Quoted 7 lines
drivers/md/raid5.c +0 -1
@@ -4371,7 +4371,6 @@ static struct stripe_head *__get_priorit
 	}
 	list_del_init(&sh->lru);
 	atomic_inc(&sh->count);
-	BUG_ON(atomic_read(&sh->count) != 1);
 	return sh;
 }
 

What if we made those two lines:

Quoted 1 line
  BUG_ON(atomic_inc_return(&sh->count) != 1);

Ok if we want to keep the BUG_ON.

Subject: raid5: fix a race of stripe count check

I hit another BUG_ON with e240c1839d11152b0355442. In __get_priority_stripe(), stripe count equals to 0 initially. Between atomic_inc and BUG_ON, get_active_stripe() finds the stripe. So the stripe count isn't 1 any more.

V2: keeps the BUG_ON suggested by Neil.

---
 drivers/md/raid5.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/raid5.c +1 -2
Index: linux/drivers/md/raid5.c
===================================================================
@@ -4370,8 +4370,7 @@ static struct stripe_head *__get_priorit
 		sh->group = NULL;
 	}
 	list_del_init(&sh->lru);
-	atomic_inc(&sh->count);
-	BUG_ON(atomic_read(&sh->count) != 1);
+	BUG_ON(atomic_inc_return(&sh->count) != 1);
 	return sh;
 }