]>
Commit | Line | Data |
---|---|---|
2cb7cef9 BS |
1 | From: Gerald Schaefer <geraldsc@de.ibm.com> |
2 | Subject: dasd: fix race in dasd timer handling | |
3 | References: bnc#482818,LTC#52092 | |
4 | ||
5 | Symptom: DASD driver runs into BUG statement in add_timer | |
6 | Problem: If the timer expires just after we check whether it is | |
7 | still pending and before mod_timer is called, then | |
8 | mod_timer will setup the timer, return zero and add_timer | |
9 | will be called as well although the timer is already set. | |
10 | Solution: Initialize the timer variables at device creation time | |
11 | and remove all timer_pending checks from dasd functions. | |
12 | del_timer and mod_timer will do all the necessary | |
13 | checking themselves and mod_timer will set a timer if it | |
14 | is not already pending. | |
15 | ||
16 | Acked-by: John Jolly <jjolly@suse.de> | |
17 | --- | |
18 | drivers/s390/block/dasd.c | 46 ++++++++++++++++------------------------------ | |
19 | 1 file changed, 16 insertions(+), 30 deletions(-) | |
20 | ||
21 | Index: linux-sles11/drivers/s390/block/dasd.c | |
22 | =================================================================== | |
23 | --- linux-sles11.orig/drivers/s390/block/dasd.c | |
24 | +++ linux-sles11/drivers/s390/block/dasd.c | |
25 | @@ -57,6 +57,8 @@ static void dasd_device_tasklet(struct d | |
26 | static void dasd_block_tasklet(struct dasd_block *); | |
27 | static void do_kick_device(struct work_struct *); | |
28 | static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *); | |
29 | +static void dasd_device_timeout(unsigned long); | |
30 | +static void dasd_block_timeout(unsigned long); | |
31 | ||
32 | /* | |
33 | * SECTION: Operations on the device structure. | |
34 | @@ -99,6 +101,8 @@ struct dasd_device *dasd_alloc_device(vo | |
35 | (unsigned long) device); | |
36 | INIT_LIST_HEAD(&device->ccw_queue); | |
37 | init_timer(&device->timer); | |
38 | + device->timer.function = dasd_device_timeout; | |
39 | + device->timer.data = (unsigned long) device; | |
40 | INIT_WORK(&device->kick_work, do_kick_device); | |
41 | device->state = DASD_STATE_NEW; | |
42 | device->target = DASD_STATE_NEW; | |
43 | @@ -138,6 +142,8 @@ struct dasd_block *dasd_alloc_block(void | |
44 | INIT_LIST_HEAD(&block->ccw_queue); | |
45 | spin_lock_init(&block->queue_lock); | |
46 | init_timer(&block->timer); | |
47 | + block->timer.function = dasd_block_timeout; | |
48 | + block->timer.data = (unsigned long) block; | |
49 | ||
50 | return block; | |
51 | } | |
52 | @@ -923,19 +929,10 @@ static void dasd_device_timeout(unsigned | |
53 | */ | |
54 | void dasd_device_set_timer(struct dasd_device *device, int expires) | |
55 | { | |
56 | - if (expires == 0) { | |
57 | - if (timer_pending(&device->timer)) | |
58 | - del_timer(&device->timer); | |
59 | - return; | |
60 | - } | |
61 | - if (timer_pending(&device->timer)) { | |
62 | - if (mod_timer(&device->timer, jiffies + expires)) | |
63 | - return; | |
64 | - } | |
65 | - device->timer.function = dasd_device_timeout; | |
66 | - device->timer.data = (unsigned long) device; | |
67 | - device->timer.expires = jiffies + expires; | |
68 | - add_timer(&device->timer); | |
69 | + if (expires == 0) | |
70 | + del_timer(&device->timer); | |
71 | + else | |
72 | + mod_timer(&device->timer, jiffies + expires); | |
73 | } | |
74 | ||
75 | /* | |
76 | @@ -943,8 +940,7 @@ void dasd_device_set_timer(struct dasd_d | |
77 | */ | |
78 | void dasd_device_clear_timer(struct dasd_device *device) | |
79 | { | |
80 | - if (timer_pending(&device->timer)) | |
81 | - del_timer(&device->timer); | |
82 | + del_timer(&device->timer); | |
83 | } | |
84 | ||
85 | static void dasd_handle_killed_request(struct ccw_device *cdev, | |
86 | @@ -1594,19 +1590,10 @@ static void dasd_block_timeout(unsigned | |
87 | */ | |
88 | void dasd_block_set_timer(struct dasd_block *block, int expires) | |
89 | { | |
90 | - if (expires == 0) { | |
91 | - if (timer_pending(&block->timer)) | |
92 | - del_timer(&block->timer); | |
93 | - return; | |
94 | - } | |
95 | - if (timer_pending(&block->timer)) { | |
96 | - if (mod_timer(&block->timer, jiffies + expires)) | |
97 | - return; | |
98 | - } | |
99 | - block->timer.function = dasd_block_timeout; | |
100 | - block->timer.data = (unsigned long) block; | |
101 | - block->timer.expires = jiffies + expires; | |
102 | - add_timer(&block->timer); | |
103 | + if (expires == 0) | |
104 | + del_timer(&block->timer); | |
105 | + else | |
106 | + mod_timer(&block->timer, jiffies + expires); | |
107 | } | |
108 | ||
109 | /* | |
110 | @@ -1614,8 +1601,7 @@ void dasd_block_set_timer(struct dasd_bl | |
111 | */ | |
112 | void dasd_block_clear_timer(struct dasd_block *block) | |
113 | { | |
114 | - if (timer_pending(&block->timer)) | |
115 | - del_timer(&block->timer); | |
116 | + del_timer(&block->timer); | |
117 | } | |
118 | ||
119 | /* |