Commit b41b554c authored by Julian Wiedmann's avatar Julian Wiedmann Committed by Jakub Kicinski

s390/qeth: fix locking for discipline setup / removal

Due to insufficient locking, qeth_core_set_online() and
qeth_dev_layer2_store() can run in parallel, both attempting to load &
setup the discipline (and stepping on each other toes along the way).
A similar race can also occur between qeth_core_remove_device() and
qeth_dev_layer2_store().

Access to .discipline is meant to be protected by the discipline_mutex,
so add/expand the locking in qeth_core_remove_device() and
qeth_core_set_online().
Adjust the locking in qeth_l*_remove_device() accordingly, as it's now
handled by the callers in a consistent manner.

Based on an initial patch by Ursula Braun.

Fixes: 9dc48ccc ("qeth: serialize sysfs-triggered device configurations")
Signed-off-by: default avatarJulian Wiedmann <jwi@linux.ibm.com>
Reviewed-by: default avatarAlexandra Winter <wintera@linux.ibm.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 0b9902c1
...@@ -6585,6 +6585,7 @@ static int qeth_core_probe_device(struct ccwgroup_device *gdev) ...@@ -6585,6 +6585,7 @@ static int qeth_core_probe_device(struct ccwgroup_device *gdev)
break; break;
default: default:
card->info.layer_enforced = true; card->info.layer_enforced = true;
/* It's so early that we don't need the discipline_mutex yet. */
rc = qeth_core_load_discipline(card, enforced_disc); rc = qeth_core_load_discipline(card, enforced_disc);
if (rc) if (rc)
goto err_load; goto err_load;
...@@ -6617,10 +6618,12 @@ static void qeth_core_remove_device(struct ccwgroup_device *gdev) ...@@ -6617,10 +6618,12 @@ static void qeth_core_remove_device(struct ccwgroup_device *gdev)
QETH_CARD_TEXT(card, 2, "removedv"); QETH_CARD_TEXT(card, 2, "removedv");
mutex_lock(&card->discipline_mutex);
if (card->discipline) { if (card->discipline) {
card->discipline->remove(gdev); card->discipline->remove(gdev);
qeth_core_free_discipline(card); qeth_core_free_discipline(card);
} }
mutex_unlock(&card->discipline_mutex);
qeth_free_qdio_queues(card); qeth_free_qdio_queues(card);
...@@ -6635,6 +6638,7 @@ static int qeth_core_set_online(struct ccwgroup_device *gdev) ...@@ -6635,6 +6638,7 @@ static int qeth_core_set_online(struct ccwgroup_device *gdev)
int rc = 0; int rc = 0;
enum qeth_discipline_id def_discipline; enum qeth_discipline_id def_discipline;
mutex_lock(&card->discipline_mutex);
if (!card->discipline) { if (!card->discipline) {
def_discipline = IS_IQD(card) ? QETH_DISCIPLINE_LAYER3 : def_discipline = IS_IQD(card) ? QETH_DISCIPLINE_LAYER3 :
QETH_DISCIPLINE_LAYER2; QETH_DISCIPLINE_LAYER2;
...@@ -6648,11 +6652,10 @@ static int qeth_core_set_online(struct ccwgroup_device *gdev) ...@@ -6648,11 +6652,10 @@ static int qeth_core_set_online(struct ccwgroup_device *gdev)
} }
} }
mutex_lock(&card->discipline_mutex);
rc = qeth_set_online(card, card->discipline); rc = qeth_set_online(card, card->discipline);
mutex_unlock(&card->discipline_mutex);
err: err:
mutex_unlock(&card->discipline_mutex);
return rc; return rc;
} }
......
...@@ -2207,11 +2207,8 @@ static void qeth_l2_remove_device(struct ccwgroup_device *gdev) ...@@ -2207,11 +2207,8 @@ static void qeth_l2_remove_device(struct ccwgroup_device *gdev)
qeth_set_allowed_threads(card, 0, 1); qeth_set_allowed_threads(card, 0, 1);
wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
if (gdev->state == CCWGROUP_ONLINE) { if (gdev->state == CCWGROUP_ONLINE)
mutex_lock(&card->discipline_mutex);
qeth_set_offline(card, card->discipline, false); qeth_set_offline(card, card->discipline, false);
mutex_unlock(&card->discipline_mutex);
}
cancel_work_sync(&card->close_dev_work); cancel_work_sync(&card->close_dev_work);
if (card->dev->reg_state == NETREG_REGISTERED) if (card->dev->reg_state == NETREG_REGISTERED)
......
...@@ -1970,11 +1970,8 @@ static void qeth_l3_remove_device(struct ccwgroup_device *cgdev) ...@@ -1970,11 +1970,8 @@ static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
qeth_set_allowed_threads(card, 0, 1); qeth_set_allowed_threads(card, 0, 1);
wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
if (cgdev->state == CCWGROUP_ONLINE) { if (cgdev->state == CCWGROUP_ONLINE)
mutex_lock(&card->discipline_mutex);
qeth_set_offline(card, card->discipline, false); qeth_set_offline(card, card->discipline, false);
mutex_unlock(&card->discipline_mutex);
}
cancel_work_sync(&card->close_dev_work); cancel_work_sync(&card->close_dev_work);
if (card->dev->reg_state == NETREG_REGISTERED) if (card->dev->reg_state == NETREG_REGISTERED)
......
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