Commit e93b9fb7 authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

hd: fix locking

hd dance around local irq and HD_IRQ enable without achieving much.
It ends up transferring data from irq handler with both local irq and
HD_IRQ disabled.  The only place it actually does something is while
transferring the first block of a request which it does with HD_IRQ
disabled but local irq enabled.

Unfortunately, the dancing is horribly broken from locking POV.  IRQ
and timeout handlers access block queue without grabbing the queue
lock and running the driver in SMP configuration crashes the whole
machine pretty quickly.

Remove meaningless irq enable/disable dancing and add proper locking
in issue, irq and timeout paths.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent 7090a0a9
...@@ -509,7 +509,6 @@ ok_to_write: ...@@ -509,7 +509,6 @@ ok_to_write:
if (i > 0) { if (i > 0) {
SET_HANDLER(&write_intr); SET_HANDLER(&write_intr);
outsw(HD_DATA, req->buffer, 256); outsw(HD_DATA, req->buffer, 256);
local_irq_enable();
} else { } else {
#if (HD_DELAY > 0) #if (HD_DELAY > 0)
last_req = read_timer(); last_req = read_timer();
...@@ -541,8 +540,7 @@ static void hd_times_out(unsigned long dummy) ...@@ -541,8 +540,7 @@ static void hd_times_out(unsigned long dummy)
if (!CURRENT) if (!CURRENT)
return; return;
disable_irq(HD_IRQ); spin_lock_irq(hd_queue->queue_lock);
local_irq_enable();
reset = 1; reset = 1;
name = CURRENT->rq_disk->disk_name; name = CURRENT->rq_disk->disk_name;
printk("%s: timeout\n", name); printk("%s: timeout\n", name);
...@@ -552,9 +550,8 @@ static void hd_times_out(unsigned long dummy) ...@@ -552,9 +550,8 @@ static void hd_times_out(unsigned long dummy)
#endif #endif
end_request(CURRENT, 0); end_request(CURRENT, 0);
} }
local_irq_disable();
hd_request(); hd_request();
enable_irq(HD_IRQ); spin_unlock_irq(hd_queue->queue_lock);
} }
static int do_special_op(struct hd_i_struct *disk, struct request *req) static int do_special_op(struct hd_i_struct *disk, struct request *req)
...@@ -592,7 +589,6 @@ static void hd_request(void) ...@@ -592,7 +589,6 @@ static void hd_request(void)
return; return;
repeat: repeat:
del_timer(&device_timer); del_timer(&device_timer);
local_irq_enable();
req = CURRENT; req = CURRENT;
if (!req) { if (!req) {
...@@ -601,7 +597,6 @@ repeat: ...@@ -601,7 +597,6 @@ repeat:
} }
if (reset) { if (reset) {
local_irq_disable();
reset_hd(); reset_hd();
return; return;
} }
...@@ -660,9 +655,7 @@ repeat: ...@@ -660,9 +655,7 @@ repeat:
static void do_hd_request(struct request_queue *q) static void do_hd_request(struct request_queue *q)
{ {
disable_irq(HD_IRQ);
hd_request(); hd_request();
enable_irq(HD_IRQ);
} }
static int hd_getgeo(struct block_device *bdev, struct hd_geometry *geo) static int hd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
...@@ -684,12 +677,16 @@ static irqreturn_t hd_interrupt(int irq, void *dev_id) ...@@ -684,12 +677,16 @@ static irqreturn_t hd_interrupt(int irq, void *dev_id)
{ {
void (*handler)(void) = do_hd; void (*handler)(void) = do_hd;
spin_lock(hd_queue->queue_lock);
do_hd = NULL; do_hd = NULL;
del_timer(&device_timer); del_timer(&device_timer);
if (!handler) if (!handler)
handler = unexpected_hd_interrupt; handler = unexpected_hd_interrupt;
handler(); handler();
local_irq_enable();
spin_unlock(hd_queue->queue_lock);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment