* [PATCH net 0/3] s390/qeth: fixes 2021-01-07
@ 2021-01-07 17:24 Julian Wiedmann
2021-01-07 17:24 ` [PATCH net 1/3] s390/qeth: fix deadlock during recovery Julian Wiedmann
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Julian Wiedmann @ 2021-01-07 17:24 UTC (permalink / raw)
To: David Miller, Jakub Kicinski
Cc: linux-netdev, linux-s390, Heiko Carstens, Karsten Graul, Julian Wiedmann
Hi Dave & Jakub,
please apply the following patch series to netdev's net tree.
This brings two locking fixes for the device control path.
Also one fix for a path where our .ndo_features_check() attempts to
access a non-existent L2 header.
Thanks,
Julian
Julian Wiedmann (3):
s390/qeth: fix deadlock during recovery
s390/qeth: fix locking for discipline setup / removal
s390/qeth: fix L2 header access in qeth_l3_osa_features_check()
drivers/s390/net/qeth_core.h | 3 ++-
drivers/s390/net/qeth_core_main.c | 38 ++++++++++++++++++++-----------
drivers/s390/net/qeth_l2_main.c | 2 +-
drivers/s390/net/qeth_l3_main.c | 4 ++--
4 files changed, 30 insertions(+), 17 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net 1/3] s390/qeth: fix deadlock during recovery
2021-01-07 17:24 [PATCH net 0/3] s390/qeth: fixes 2021-01-07 Julian Wiedmann
@ 2021-01-07 17:24 ` Julian Wiedmann
2021-01-07 17:24 ` [PATCH net 2/3] s390/qeth: fix locking for discipline setup / removal Julian Wiedmann
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Julian Wiedmann @ 2021-01-07 17:24 UTC (permalink / raw)
To: David Miller, Jakub Kicinski
Cc: linux-netdev, linux-s390, Heiko Carstens, Karsten Graul, Julian Wiedmann
When qeth_dev_layer2_store() - holding the discipline_mutex - waits
inside qeth_l*_remove_device() for a qeth_do_reset() thread to complete,
we can hit a deadlock if qeth_do_reset() concurrently calls
qeth_set_online() and thus tries to aquire the discipline_mutex.
Move the discipline_mutex locking outside of qeth_set_online() and
qeth_set_offline(), and turn the discipline into a parameter so that
callers understand the dependency.
To fix the deadlock, we can now relax the locking:
As already established, qeth_l*_remove_device() waits for
qeth_do_reset() to complete. So qeth_do_reset() itself is under no risk
of having card->discipline ripped out while it's running, and thus
doesn't need to take the discipline_mutex.
Fixes: 9dc48ccc68b9 ("qeth: serialize sysfs-triggered device configurations")
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Reviewed-by: Alexandra Winter <wintera@linux.ibm.com>
---
drivers/s390/net/qeth_core.h | 3 ++-
drivers/s390/net/qeth_core_main.c | 35 +++++++++++++++++++------------
drivers/s390/net/qeth_l2_main.c | 7 +++++--
drivers/s390/net/qeth_l3_main.c | 7 +++++--
4 files changed, 34 insertions(+), 18 deletions(-)
diff --git a/drivers/s390/net/qeth_core.h b/drivers/s390/net/qeth_core.h
index 6f5ddc3eab8c..28f637042d44 100644
--- a/drivers/s390/net/qeth_core.h
+++ b/drivers/s390/net/qeth_core.h
@@ -1079,7 +1079,8 @@ struct qeth_card *qeth_get_card_by_busid(char *bus_id);
void qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
int clear_start_mask);
int qeth_threads_running(struct qeth_card *, unsigned long);
-int qeth_set_offline(struct qeth_card *card, bool resetting);
+int qeth_set_offline(struct qeth_card *card, const struct qeth_discipline *disc,
+ bool resetting);
int qeth_send_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *,
int (*reply_cb)
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index f4b60294a969..d45e223fc521 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -5507,12 +5507,12 @@ static int qeth_hardsetup_card(struct qeth_card *card, bool *carrier_ok)
return rc;
}
-static int qeth_set_online(struct qeth_card *card)
+static int qeth_set_online(struct qeth_card *card,
+ const struct qeth_discipline *disc)
{
bool carrier_ok;
int rc;
- mutex_lock(&card->discipline_mutex);
mutex_lock(&card->conf_mutex);
QETH_CARD_TEXT(card, 2, "setonlin");
@@ -5529,7 +5529,7 @@ static int qeth_set_online(struct qeth_card *card)
/* no need for locking / error handling at this early stage: */
qeth_set_real_num_tx_queues(card, qeth_tx_actual_queues(card));
- rc = card->discipline->set_online(card, carrier_ok);
+ rc = disc->set_online(card, carrier_ok);
if (rc)
goto err_online;
@@ -5537,7 +5537,6 @@ static int qeth_set_online(struct qeth_card *card)
kobject_uevent(&card->gdev->dev.kobj, KOBJ_CHANGE);
mutex_unlock(&card->conf_mutex);
- mutex_unlock(&card->discipline_mutex);
return 0;
err_online:
@@ -5552,15 +5551,14 @@ static int qeth_set_online(struct qeth_card *card)
qdio_free(CARD_DDEV(card));
mutex_unlock(&card->conf_mutex);
- mutex_unlock(&card->discipline_mutex);
return rc;
}
-int qeth_set_offline(struct qeth_card *card, bool resetting)
+int qeth_set_offline(struct qeth_card *card, const struct qeth_discipline *disc,
+ bool resetting)
{
int rc, rc2, rc3;
- mutex_lock(&card->discipline_mutex);
mutex_lock(&card->conf_mutex);
QETH_CARD_TEXT(card, 3, "setoffl");
@@ -5581,7 +5579,7 @@ int qeth_set_offline(struct qeth_card *card, bool resetting)
cancel_work_sync(&card->rx_mode_work);
- card->discipline->set_offline(card);
+ disc->set_offline(card);
qeth_qdio_clear_card(card, 0);
qeth_drain_output_queues(card);
@@ -5602,16 +5600,19 @@ int qeth_set_offline(struct qeth_card *card, bool resetting)
kobject_uevent(&card->gdev->dev.kobj, KOBJ_CHANGE);
mutex_unlock(&card->conf_mutex);
- mutex_unlock(&card->discipline_mutex);
return 0;
}
EXPORT_SYMBOL_GPL(qeth_set_offline);
static int qeth_do_reset(void *data)
{
+ const struct qeth_discipline *disc;
struct qeth_card *card = data;
int rc;
+ /* Lock-free, other users will block until we are done. */
+ disc = card->discipline;
+
QETH_CARD_TEXT(card, 2, "recover1");
if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
return 0;
@@ -5619,8 +5620,8 @@ static int qeth_do_reset(void *data)
dev_warn(&card->gdev->dev,
"A recovery process has been started for the device\n");
- qeth_set_offline(card, true);
- rc = qeth_set_online(card);
+ qeth_set_offline(card, disc, true);
+ rc = qeth_set_online(card, disc);
if (!rc) {
dev_info(&card->gdev->dev,
"Device successfully recovered!\n");
@@ -6647,7 +6648,10 @@ static int qeth_core_set_online(struct ccwgroup_device *gdev)
}
}
- rc = qeth_set_online(card);
+ mutex_lock(&card->discipline_mutex);
+ rc = qeth_set_online(card, card->discipline);
+ mutex_unlock(&card->discipline_mutex);
+
err:
return rc;
}
@@ -6655,8 +6659,13 @@ static int qeth_core_set_online(struct ccwgroup_device *gdev)
static int qeth_core_set_offline(struct ccwgroup_device *gdev)
{
struct qeth_card *card = dev_get_drvdata(&gdev->dev);
+ int rc;
- return qeth_set_offline(card, false);
+ mutex_lock(&card->discipline_mutex);
+ rc = qeth_set_offline(card, card->discipline, false);
+ mutex_unlock(&card->discipline_mutex);
+
+ return rc;
}
static void qeth_core_shutdown(struct ccwgroup_device *gdev)
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 4ed0fb0705a5..37279b1e29f6 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -2207,8 +2207,11 @@ static void qeth_l2_remove_device(struct ccwgroup_device *gdev)
qeth_set_allowed_threads(card, 0, 1);
wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
- if (gdev->state == CCWGROUP_ONLINE)
- qeth_set_offline(card, false);
+ if (gdev->state == CCWGROUP_ONLINE) {
+ mutex_lock(&card->discipline_mutex);
+ qeth_set_offline(card, card->discipline, false);
+ mutex_unlock(&card->discipline_mutex);
+ }
cancel_work_sync(&card->close_dev_work);
if (card->dev->reg_state == NETREG_REGISTERED)
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index d138ac432d01..8d474179ce98 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -1970,8 +1970,11 @@ static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
qeth_set_allowed_threads(card, 0, 1);
wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
- if (cgdev->state == CCWGROUP_ONLINE)
- qeth_set_offline(card, false);
+ if (cgdev->state == CCWGROUP_ONLINE) {
+ mutex_lock(&card->discipline_mutex);
+ qeth_set_offline(card, card->discipline, false);
+ mutex_unlock(&card->discipline_mutex);
+ }
cancel_work_sync(&card->close_dev_work);
if (card->dev->reg_state == NETREG_REGISTERED)
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 2/3] s390/qeth: fix locking for discipline setup / removal
2021-01-07 17:24 [PATCH net 0/3] s390/qeth: fixes 2021-01-07 Julian Wiedmann
2021-01-07 17:24 ` [PATCH net 1/3] s390/qeth: fix deadlock during recovery Julian Wiedmann
@ 2021-01-07 17:24 ` Julian Wiedmann
2021-01-07 17:24 ` [PATCH net 3/3] s390/qeth: fix L2 header access in qeth_l3_osa_features_check() Julian Wiedmann
2021-01-08 3:00 ` [PATCH net 0/3] s390/qeth: fixes 2021-01-07 patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Julian Wiedmann @ 2021-01-07 17:24 UTC (permalink / raw)
To: David Miller, Jakub Kicinski
Cc: linux-netdev, linux-s390, Heiko Carstens, Karsten Graul, Julian Wiedmann
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: 9dc48ccc68b9 ("qeth: serialize sysfs-triggered device configurations")
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Reviewed-by: Alexandra Winter <wintera@linux.ibm.com>
---
drivers/s390/net/qeth_core_main.c | 7 +++++--
drivers/s390/net/qeth_l2_main.c | 5 +----
drivers/s390/net/qeth_l3_main.c | 5 +----
3 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index d45e223fc521..cf18d87da41e 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -6585,6 +6585,7 @@ static int qeth_core_probe_device(struct ccwgroup_device *gdev)
break;
default:
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);
if (rc)
goto err_load;
@@ -6617,10 +6618,12 @@ static void qeth_core_remove_device(struct ccwgroup_device *gdev)
QETH_CARD_TEXT(card, 2, "removedv");
+ mutex_lock(&card->discipline_mutex);
if (card->discipline) {
card->discipline->remove(gdev);
qeth_core_free_discipline(card);
}
+ mutex_unlock(&card->discipline_mutex);
qeth_free_qdio_queues(card);
@@ -6635,6 +6638,7 @@ static int qeth_core_set_online(struct ccwgroup_device *gdev)
int rc = 0;
enum qeth_discipline_id def_discipline;
+ mutex_lock(&card->discipline_mutex);
if (!card->discipline) {
def_discipline = IS_IQD(card) ? QETH_DISCIPLINE_LAYER3 :
QETH_DISCIPLINE_LAYER2;
@@ -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);
- mutex_unlock(&card->discipline_mutex);
err:
+ mutex_unlock(&card->discipline_mutex);
return rc;
}
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 37279b1e29f6..4254caf1d9b6 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -2207,11 +2207,8 @@ static void qeth_l2_remove_device(struct ccwgroup_device *gdev)
qeth_set_allowed_threads(card, 0, 1);
wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
- if (gdev->state == CCWGROUP_ONLINE) {
- mutex_lock(&card->discipline_mutex);
+ if (gdev->state == CCWGROUP_ONLINE)
qeth_set_offline(card, card->discipline, false);
- mutex_unlock(&card->discipline_mutex);
- }
cancel_work_sync(&card->close_dev_work);
if (card->dev->reg_state == NETREG_REGISTERED)
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index 8d474179ce98..6970597bc885 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -1970,11 +1970,8 @@ static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
qeth_set_allowed_threads(card, 0, 1);
wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
- if (cgdev->state == CCWGROUP_ONLINE) {
- mutex_lock(&card->discipline_mutex);
+ if (cgdev->state == CCWGROUP_ONLINE)
qeth_set_offline(card, card->discipline, false);
- mutex_unlock(&card->discipline_mutex);
- }
cancel_work_sync(&card->close_dev_work);
if (card->dev->reg_state == NETREG_REGISTERED)
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 3/3] s390/qeth: fix L2 header access in qeth_l3_osa_features_check()
2021-01-07 17:24 [PATCH net 0/3] s390/qeth: fixes 2021-01-07 Julian Wiedmann
2021-01-07 17:24 ` [PATCH net 1/3] s390/qeth: fix deadlock during recovery Julian Wiedmann
2021-01-07 17:24 ` [PATCH net 2/3] s390/qeth: fix locking for discipline setup / removal Julian Wiedmann
@ 2021-01-07 17:24 ` Julian Wiedmann
2021-01-08 3:00 ` [PATCH net 0/3] s390/qeth: fixes 2021-01-07 patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Julian Wiedmann @ 2021-01-07 17:24 UTC (permalink / raw)
To: David Miller, Jakub Kicinski
Cc: linux-netdev, linux-s390, Heiko Carstens, Karsten Graul, Julian Wiedmann
ip_finish_output_gso() may call .ndo_features_check() even before the
skb has a L2 header. This conflicts with qeth_get_ip_version()'s attempt
to inspect the L2 header via vlan_eth_hdr().
Switch to vlan_get_protocol(), as already used further down in the
common qeth_features_check() path.
Fixes: f13ade199391 ("s390/qeth: run non-offload L3 traffic over common xmit path")
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
---
drivers/s390/net/qeth_l3_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index 6970597bc885..4c2cae7ae9a7 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -1813,7 +1813,7 @@ static netdev_features_t qeth_l3_osa_features_check(struct sk_buff *skb,
struct net_device *dev,
netdev_features_t features)
{
- if (qeth_get_ip_version(skb) != 4)
+ if (vlan_get_protocol(skb) != htons(ETH_P_IP))
features &= ~NETIF_F_HW_VLAN_CTAG_TX;
return qeth_features_check(skb, dev, features);
}
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net 0/3] s390/qeth: fixes 2021-01-07
2021-01-07 17:24 [PATCH net 0/3] s390/qeth: fixes 2021-01-07 Julian Wiedmann
` (2 preceding siblings ...)
2021-01-07 17:24 ` [PATCH net 3/3] s390/qeth: fix L2 header access in qeth_l3_osa_features_check() Julian Wiedmann
@ 2021-01-08 3:00 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-01-08 3:00 UTC (permalink / raw)
To: Julian Wiedmann; +Cc: davem, kuba, netdev, linux-s390, hca, kgraul
Hello:
This series was applied to netdev/net.git (refs/heads/master):
On Thu, 7 Jan 2021 18:24:39 +0100 you wrote:
> Hi Dave & Jakub,
>
> please apply the following patch series to netdev's net tree.
>
> This brings two locking fixes for the device control path.
> Also one fix for a path where our .ndo_features_check() attempts to
> access a non-existent L2 header.
>
> [...]
Here is the summary with links:
- [net,1/3] s390/qeth: fix deadlock during recovery
https://git.kernel.org/netdev/net/c/0b9902c1fcc5
- [net,2/3] s390/qeth: fix locking for discipline setup / removal
https://git.kernel.org/netdev/net/c/b41b554c1ee7
- [net,3/3] s390/qeth: fix L2 header access in qeth_l3_osa_features_check()
https://git.kernel.org/netdev/net/c/f9c4845385c8
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-01-08 3:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-07 17:24 [PATCH net 0/3] s390/qeth: fixes 2021-01-07 Julian Wiedmann
2021-01-07 17:24 ` [PATCH net 1/3] s390/qeth: fix deadlock during recovery Julian Wiedmann
2021-01-07 17:24 ` [PATCH net 2/3] s390/qeth: fix locking for discipline setup / removal Julian Wiedmann
2021-01-07 17:24 ` [PATCH net 3/3] s390/qeth: fix L2 header access in qeth_l3_osa_features_check() Julian Wiedmann
2021-01-08 3:00 ` [PATCH net 0/3] s390/qeth: fixes 2021-01-07 patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.