disk_free_ptbl_rcu_cb() crash
Current Linus tree makes my machine crash in disk_free_ptbl_rcu_cb(), while booting...
commit 7681bfeeccff5ef seems the problem ?
Following patch solves the NULL dereference, but this is only to show you where the problem is, not a real fix, of course.
Thanks
block/genhd.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
block/genhd.c +6 -4
@@ -930,14 +930,16 @@ static void disk_free_ptbl_rcu_cb(struct rcu_head *head)struct disk_part_tbl *ptbl = container_of(head, struct disk_part_tbl, rcu_head);struct gendisk *disk = ptbl->disk; -struct request_queue *q = disk->queue; +struct request_queue *q = disk ? disk->queue :NULL ;unsigned long flags;kfree (ptbl); -spin_lock_irqsave (q->queue_lock, flags); -elv_quiesce_end (q); -spin_unlock_irqrestore (q->queue_lock, flags); +if (q) { +spin_lock_irqsave (q->queue_lock, flags); +elv_quiesce_end (q); +spin_unlock_irqrestore (q->queue_lock, flags); + } }/**
Quoted 7 lines · Eric Dumazet
Current Linus tree makes my machine crash in
disk_free_ptbl_rcu_cb(), while booting...commit
7681bfeeccff5efseems the problem ?Following patch solves the NULL dereference, but this is only to show you where the problem is, not a real fix, of course.
Darn. Your fix is on the right path, you missed one though. I think it's cleaner to move this into the elevator helpers, so that the callers can remain clean.
Can you verify that this works too?
block/elevator.c +23 -8
@@ -590,11 +590,8 @@ void elv_drain_elevator(struct request_queue *q)/* * Call with queue lock held, interrupts disabled */ -void elv_quiesce_start (struct request_queue *q) +void __elv_quiesce_start (struct request_queue *q) { -if (!q->elevator) -return ; -queue_flag_set (QUEUE_FLAG_ELVSWITCH , q);/*
@@ -610,11 +607,31 @@ void elv_quiesce_start(struct request_queue *q) } } -void elv_quiesce_end (struct request_queue *q) +void elv_quiesce_start (struct request_queue *q) +{ +if (q->elevator) { +spin_lock_irq (q->queue_lock); +__elv_quiesce_start (q); +spin_unlock_irq (q->queue_lock); + } +} + +void __elv_quiesce_end (struct request_queue *q) {queue_flag_clear (QUEUE_FLAG_ELVSWITCH , q); } +void elv_quiesce_end (struct request_queue *q) +{ +if (q->elevator) { +unsigned long flags; + +spin_lock_irqsave (q->queue_lock, flags); +__elv_quiesce_end (q); +spin_unlock_irqrestore (q->queue_lock, flags); + } +} +void elv_insert (struct request_queue *q,struct request *rq,int where) {int unplug_it =1 ;
@@ -969,7 +986,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)* Turn on BYPASS and drain all requests w/ elevator private data */ spin_lock_irq (q->queue_lock); -elv_quiesce_start (q); +__elv_quiesce_start (q);/* * Remember old elevator.
@@ -995,9 +1012,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)* finally exit old elevator and turn off BYPASS. */ elevator_exit (old_elevator); -spin_lock_irq (q->queue_lock);elv_quiesce_end (q); -spin_unlock_irq (q->queue_lock);blk_add_trace_msg (q,"elv switch: %s" , e->elevator_type->elevator_name);
block/genhd.c +1 -9
@@ -930,14 +930,9 @@ static void disk_free_ptbl_rcu_cb(struct rcu_head *head)struct disk_part_tbl *ptbl = container_of(head, struct disk_part_tbl, rcu_head);struct gendisk *disk = ptbl->disk; -struct request_queue *q = disk->queue; -unsigned long flags;kfree (ptbl); - -spin_lock_irqsave (q->queue_lock, flags); -elv_quiesce_end (q); -spin_unlock_irqrestore (q->queue_lock, flags); +elv_quiesce_end (disk->queue); }/**
@@ -962,10 +957,7 @@ static void disk_replace_part_tbl(struct gendisk *disk,if (old_ptbl) {rcu_assign_pointer (old_ptbl->last_lookup,NULL ); -spin_lock_irq (q->queue_lock);elv_quiesce_start (q); -spin_unlock_irq (q->queue_lock); -call_rcu (&old_ptbl->rcu_head, disk_free_ptbl_rcu_cb); } }
fs/partitions/check.c +0 -5
@@ -367,16 +367,13 @@ static void delete_partition_rcu_cb(struct rcu_head *head) struct hd_struct *part = container_of(head, struct hd_struct, rcu_head);struct gendisk *disk =part_to_disk (part);struct request_queue *q = disk->queue; -unsigned long flags; part->start_sect =0 ; part->nr_sects =0 ;part_stat_set_all (part,0 );put_device (part_to_dev (part)); -spin_lock_irqsave (q->queue_lock, flags);elv_quiesce_end (q); -spin_unlock_irqrestore (q->queue_lock, flags); }void delete_partition (struct gendisk *disk,int partno)
@@ -398,9 +395,7 @@ void delete_partition(struct gendisk *disk, int partno)kobject_put (part->holder_dir);device_del (part_to_dev (part)); -spin_lock_irq (q->queue_lock);elv_quiesce_start (q); -spin_unlock_irq (q->queue_lock);call_rcu (&part->rcu_head, delete_partition_rcu_cb); }
include/linux/elevator.h +2 -0
@@ -122,7 +122,9 @@ extern void elv_completed_request(struct request_queue *, struct request *);extern int elv_set_request (struct request_queue *,struct request *,gfp_t );extern void elv_put_request (struct request_queue *,struct request *);extern void elv_drain_elevator (struct request_queue *); +extern void __elv_quiesce_start (struct request_queue *);extern void elv_quiesce_start (struct request_queue *); +extern void __elv_quiesce_end (struct request_queue *);extern void elv_quiesce_end (struct request_queue *);/*
Signature · 1 line
Jens Axboe
Quoted 6 lines · Jens Axboe
Quoted 5 lines · Eric Dumazet
Current Linus tree makes my machine crash in
disk_free_ptbl_rcu_cb(), while booting...commit
7681bfeeccff5efseems the problem ?
Quoted 8 lines
Quoted 2 lines
Following patch solves the NULL dereference, but this is only to show you where the problem is, not a real fix, of course.
Darn. Your fix is on the right path, you missed one though. I think it's cleaner to move this into the elevator helpers, so that the callers can remain clean.
Can you verify that this works too?
Sure, I did right now and it works too, thanks !
Quoted 10 lines · Eric Dumazet
Quoted 9 lines · Jens Axboe
Quoted 7 lines · Eric Dumazet
Current Linus tree makes my machine crash in
disk_free_ptbl_rcu_cb(), while booting...commit
7681bfeeccff5efseems the problem ?Following patch solves the NULL dereference, but this is only to show you where the problem is, not a real fix, of course.
Quoted 7 lines
Quoted 5 lines
Darn. Your fix is on the right path, you missed one though. I think it's cleaner to move this into the elevator helpers, so that the callers can remain clean.
Can you verify that this works too?
Sure, I did right now and it works too, thanks !
Thanks for the (very) quick turn-around, I'll get this one expedited as well.
Signature · 1 line
Jens Axboe
Quoted 6 lines · Jens Axboe
Quoted 5 lines · Eric Dumazet
Current Linus tree makes my machine crash in
disk_free_ptbl_rcu_cb(), while booting...commit
7681bfeeccff5efseems the problem ?
Quoted 8 lines
Quoted 2 lines
Following patch solves the NULL dereference, but this is only to show you where the problem is, not a real fix, of course.
Darn. Your fix is on the right path, you missed one though. I think it's cleaner to move this into the elevator helpers, so that the callers can remain clean.
Can you verify that this works too?
Hi Jens,
I am wondering if this fix is safe. Looking at the memstick backtrace in other mail thread, it looks like request queue itself has been freed. So we probably should be checking for request queue being valid before we try to check q->elevator being valid.
P.S. I tried sending the same response from gmail account but it bounced. So if you get this mail twice, please ignore.
Vivek
Quoted 155 lines
block/elevator.c +23
-8@@ -590,11 +590,8 @@ void elv_drain_elevator(struct request_queue *q)/* * Call with queue lock held, interrupts disabled */ -void elv_quiesce_start (struct request_queue *q) +void __elv_quiesce_start (struct request_queue *q) { -if (!q->elevator) -return ; -queue_flag_set (QUEUE_FLAG_ELVSWITCH , q);/* @@ -610,11 +607,31 @@ void elv_quiesce_start(struct request_queue *q) } } -void elv_quiesce_end (struct request_queue *q) +void elv_quiesce_start (struct request_queue *q) +{ +if (q->elevator) { +spin_lock_irq (q->queue_lock); +__elv_quiesce_start (q); +spin_unlock_irq (q->queue_lock); + } +} + +void __elv_quiesce_end (struct request_queue *q) {queue_flag_clear (QUEUE_FLAG_ELVSWITCH , q); } +void elv_quiesce_end (struct request_queue *q) +{ +if (q->elevator) { +unsigned long flags; + +spin_lock_irqsave (q->queue_lock, flags); +__elv_quiesce_end (q); +spin_unlock_irqrestore (q->queue_lock, flags); + } +} +void elv_insert (struct request_queue *q,struct request *rq,int where) {int unplug_it =1 ;@@ -969,7 +986,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)* Turn on BYPASS and drain all requests w/ elevator private data */ spin_lock_irq (q->queue_lock); -elv_quiesce_start (q); +__elv_quiesce_start (q);/* * Remember old elevator. @@ -995,9 +1012,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)* finally exit old elevator and turn off BYPASS. */ elevator_exit (old_elevator); -spin_lock_irq (q->queue_lock);elv_quiesce_end (q); -spin_unlock_irq (q->queue_lock);blk_add_trace_msg (q,"elv switch: %s" , e->elevator_type->elevator_name);block/genhd.c +1
-9@@ -930,14 +930,9 @@ static void disk_free_ptbl_rcu_cb(struct rcu_head *head)struct disk_part_tbl *ptbl = container_of(head, struct disk_part_tbl, rcu_head);struct gendisk *disk = ptbl->disk; -struct request_queue *q = disk->queue; -unsigned long flags;kfree (ptbl); - -spin_lock_irqsave (q->queue_lock, flags); -elv_quiesce_end (q); -spin_unlock_irqrestore (q->queue_lock, flags); +elv_quiesce_end (disk->queue); }/** @@ -962,10 +957,7 @@ static void disk_replace_part_tbl(struct gendisk *disk,if (old_ptbl) {rcu_assign_pointer (old_ptbl->last_lookup,NULL ); -spin_lock_irq (q->queue_lock);elv_quiesce_start (q); -spin_unlock_irq (q->queue_lock); -call_rcu (&old_ptbl->rcu_head, disk_free_ptbl_rcu_cb); } }fs/partitions/check.c +0
-5@@ -367,16 +367,13 @@ static void delete_partition_rcu_cb(struct rcu_head *head) struct hd_struct *part = container_of(head, struct hd_struct, rcu_head);struct gendisk *disk =part_to_disk (part);struct request_queue *q = disk->queue; -unsigned long flags; part->start_sect =0 ; part->nr_sects =0 ;part_stat_set_all (part,0 );put_device (part_to_dev (part)); -spin_lock_irqsave (q->queue_lock, flags);elv_quiesce_end (q); -spin_unlock_irqrestore (q->queue_lock, flags); }void delete_partition (struct gendisk *disk,int partno)@@ -398,9 +395,7 @@ void delete_partition(struct gendisk *disk, int partno)kobject_put (part->holder_dir);device_del (part_to_dev (part)); -spin_lock_irq (q->queue_lock);elv_quiesce_start (q); -spin_unlock_irq (q->queue_lock);call_rcu (&part->rcu_head, delete_partition_rcu_cb); }include/linux/elevator.h +2
-0@@ -122,7 +122,9 @@ extern void elv_completed_request(struct request_queue *, struct request *);extern int elv_set_request (struct request_queue *,struct request *,gfp_t );extern void elv_put_request (struct request_queue *,struct request *);extern void elv_drain_elevator (struct request_queue *); +extern void __elv_quiesce_start (struct request_queue *);extern void elv_quiesce_start (struct request_queue *); +extern void __elv_quiesce_end (struct request_queue *);extern void elv_quiesce_end (struct request_queue *);/* Signature · 8 lines
-- Jens Axboe -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Quoted 14 lines · Vivek Goyal
Quoted 13 lines · Jens Axboe
Quoted 7 lines · Eric Dumazet
Current Linus tree makes my machine crash in
disk_free_ptbl_rcu_cb(), while booting...commit
7681bfeeccff5efseems the problem ?Following patch solves the NULL dereference, but this is only to show you where the problem is, not a real fix, of course.
Darn. Your fix is on the right path, you missed one though. I think it's cleaner to move this into the elevator helpers, so that the callers can remain clean.
Quoted 8 lines
Quoted 1 line
Can you verify that this works too?
Hi Jens,
I am wondering if this fix is safe. Looking at the memstick backtrace in other mail thread, it looks like request queue itself has been freed. So we probably should be checking for request queue being valid before we try to check
q->elevatorbeing valid.
Looking at that trace, it's not yet deleted. But if it's in the to-free path, by the time we invoke the rcu callback and do the quiesce end it could be gone.
Needs a bit of thought, feel free to poke at it today if you have time (because I really do not :-/)
I will ask Linus to revert this commit for now.
Quoted 2 lines
P.S. I tried sending the same response from gmail account but it bounced. So if you get this mail twice, please ignore.
Didn't get it twice.
Signature · 1 line
Jens Axboe