Skip to content

Commit c8183f5

Browse files
julianwiedmanndavem330
authored andcommitted
s390/qeth: fix potential deadlock on workqueue flush
The L2 bridgeport code uses the coarse 'conf_mutex' for guarding access to its configuration state. This can result in a deadlock when qeth_l2_stop_card() - called under the conf_mutex - blocks on flush_workqueue() to wait for the completion of pending bridgeport workers. Such workers would also need to aquire the conf_mutex, stalling indefinitely. Introduce a lock that specifically guards the bridgeport configuration, so that the workers no longer need the conf_mutex. Wrapping qeth_l2_promisc_to_bridge() in this fine-grained lock then also fixes a theoretical race against a concurrent qeth_bridge_port_role_store() operation. Fixes: c0a2e4d ("s390/qeth: conclude all event processing before offlining a card") Signed-off-by: Julian Wiedmann <[email protected]> Reviewed-by: Alexandra Winter <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 004b394 commit c8183f5

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

drivers/s390/net/qeth_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ struct qeth_card {
839839
struct service_level qeth_service_level;
840840
struct qdio_ssqd_desc ssqd;
841841
debug_info_t *debug;
842+
struct mutex sbp_lock;
842843
struct mutex conf_mutex;
843844
struct mutex discipline_mutex;
844845
struct napi_struct napi;

drivers/s390/net/qeth_l2_main.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,14 @@ static void qeth_l2_set_promisc_mode(struct qeth_card *card)
467467
if (card->info.promisc_mode == enable)
468468
return;
469469

470-
if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
470+
if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) {
471471
qeth_setadp_promisc_mode(card, enable);
472-
else if (card->options.sbp.reflect_promisc)
473-
qeth_l2_promisc_to_bridge(card, enable);
472+
} else {
473+
mutex_lock(&card->sbp_lock);
474+
if (card->options.sbp.reflect_promisc)
475+
qeth_l2_promisc_to_bridge(card, enable);
476+
mutex_unlock(&card->sbp_lock);
477+
}
474478
}
475479

476480
/* New MAC address is added to the hash table and marked to be written on card
@@ -631,6 +635,7 @@ static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
631635
int rc;
632636

633637
qeth_l2_vnicc_set_defaults(card);
638+
mutex_init(&card->sbp_lock);
634639

635640
if (gdev->dev.type == &qeth_generic_devtype) {
636641
rc = qeth_l2_create_device_attributes(&gdev->dev);
@@ -804,10 +809,12 @@ static int qeth_l2_set_online(struct ccwgroup_device *gdev)
804809
} else
805810
card->info.hwtrap = 0;
806811

812+
mutex_lock(&card->sbp_lock);
807813
qeth_bridgeport_query_support(card);
808814
if (card->options.sbp.supported_funcs)
809815
dev_info(&card->gdev->dev,
810816
"The device represents a Bridge Capable Port\n");
817+
mutex_unlock(&card->sbp_lock);
811818

812819
qeth_l2_register_dev_addr(card);
813820

@@ -1162,9 +1169,9 @@ static void qeth_bridge_state_change_worker(struct work_struct *work)
11621169

11631170
/* Role should not change by itself, but if it did, */
11641171
/* information from the hardware is authoritative. */
1165-
mutex_lock(&data->card->conf_mutex);
1172+
mutex_lock(&data->card->sbp_lock);
11661173
data->card->options.sbp.role = entry->role;
1167-
mutex_unlock(&data->card->conf_mutex);
1174+
mutex_unlock(&data->card->sbp_lock);
11681175

11691176
snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
11701177
snprintf(env_role, sizeof(env_role), "ROLE=%s",
@@ -1230,9 +1237,9 @@ static void qeth_bridge_host_event_worker(struct work_struct *work)
12301237
: (data->hostevs.lost_event_mask == 0x02)
12311238
? "Bridge port state change"
12321239
: "Unknown reason");
1233-
mutex_lock(&data->card->conf_mutex);
1240+
mutex_lock(&data->card->sbp_lock);
12341241
data->card->options.sbp.hostnotification = 0;
1235-
mutex_unlock(&data->card->conf_mutex);
1242+
mutex_unlock(&data->card->sbp_lock);
12361243
qeth_bridge_emit_host_event(data->card, anev_abort,
12371244
0, NULL, NULL);
12381245
} else

drivers/s390/net/qeth_l2_sys.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static ssize_t qeth_bridge_port_role_state_show(struct device *dev,
2424
if (qeth_l2_vnicc_is_in_use(card))
2525
return sprintf(buf, "n/a (VNIC characteristics)\n");
2626

27+
mutex_lock(&card->sbp_lock);
2728
if (qeth_card_hw_is_reachable(card) &&
2829
card->options.sbp.supported_funcs)
2930
rc = qeth_bridgeport_query_ports(card,
@@ -57,6 +58,7 @@ static ssize_t qeth_bridge_port_role_state_show(struct device *dev,
5758
else
5859
rc = sprintf(buf, "%s\n", word);
5960
}
61+
mutex_unlock(&card->sbp_lock);
6062

6163
return rc;
6264
}
@@ -91,6 +93,7 @@ static ssize_t qeth_bridge_port_role_store(struct device *dev,
9193
return -EINVAL;
9294

9395
mutex_lock(&card->conf_mutex);
96+
mutex_lock(&card->sbp_lock);
9497

9598
if (qeth_l2_vnicc_is_in_use(card))
9699
rc = -EBUSY;
@@ -104,6 +107,7 @@ static ssize_t qeth_bridge_port_role_store(struct device *dev,
104107
} else
105108
card->options.sbp.role = role;
106109

110+
mutex_unlock(&card->sbp_lock);
107111
mutex_unlock(&card->conf_mutex);
108112

109113
return rc ? rc : count;
@@ -158,6 +162,7 @@ static ssize_t qeth_bridgeport_hostnotification_store(struct device *dev,
158162
return rc;
159163

160164
mutex_lock(&card->conf_mutex);
165+
mutex_lock(&card->sbp_lock);
161166

162167
if (qeth_l2_vnicc_is_in_use(card))
163168
rc = -EBUSY;
@@ -168,6 +173,7 @@ static ssize_t qeth_bridgeport_hostnotification_store(struct device *dev,
168173
} else
169174
card->options.sbp.hostnotification = enable;
170175

176+
mutex_unlock(&card->sbp_lock);
171177
mutex_unlock(&card->conf_mutex);
172178

173179
return rc ? rc : count;
@@ -223,6 +229,7 @@ static ssize_t qeth_bridgeport_reflect_store(struct device *dev,
223229
return -EINVAL;
224230

225231
mutex_lock(&card->conf_mutex);
232+
mutex_lock(&card->sbp_lock);
226233

227234
if (qeth_l2_vnicc_is_in_use(card))
228235
rc = -EBUSY;
@@ -234,6 +241,7 @@ static ssize_t qeth_bridgeport_reflect_store(struct device *dev,
234241
rc = 0;
235242
}
236243

244+
mutex_unlock(&card->sbp_lock);
237245
mutex_unlock(&card->conf_mutex);
238246

239247
return rc ? rc : count;
@@ -269,6 +277,8 @@ void qeth_l2_setup_bridgeport_attrs(struct qeth_card *card)
269277
return;
270278
if (!card->options.sbp.supported_funcs)
271279
return;
280+
281+
mutex_lock(&card->sbp_lock);
272282
if (card->options.sbp.role != QETH_SBP_ROLE_NONE) {
273283
/* Conditional to avoid spurious error messages */
274284
qeth_bridgeport_setrole(card, card->options.sbp.role);
@@ -280,8 +290,10 @@ void qeth_l2_setup_bridgeport_attrs(struct qeth_card *card)
280290
rc = qeth_bridgeport_an_set(card, 1);
281291
if (rc)
282292
card->options.sbp.hostnotification = 0;
283-
} else
293+
} else {
284294
qeth_bridgeport_an_set(card, 0);
295+
}
296+
mutex_unlock(&card->sbp_lock);
285297
}
286298

287299
/* VNIC CHARS support */

0 commit comments

Comments
 (0)