s390/qeth: fixes 2021-01-07
Subsystems (4)
cover s390/qeth: fixes 2021-01-07
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(-)
Signature · 1 line
2.17.1
PATCH 1/3 s390/qeth: fix deadlock during recovery
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.
--- 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(-)
drivers/s390/net/qeth_core.h +2 -1
@@ -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)
drivers/s390/net/qeth_core_main.c +22 -13
@@ -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)
drivers/s390/net/qeth_l2_main.c +5 -2
@@ -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 )
drivers/s390/net/qeth_l3_main.c +5 -2
@@ -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 )
Signature · 1 line
2.17.1
PATCH 2/3 s390/qeth: fix locking for discipline setup / removal
In reply to Julian WiedmannDue 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.
--- 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(-)
drivers/s390/net/qeth_core_main.c +5 -2
@@ -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; }
drivers/s390/net/qeth_l2_main.c +1 -4
@@ -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 )
drivers/s390/net/qeth_l3_main.c +1 -4
@@ -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 )
Signature · 1 line
2.17.1
PATCH 3/3 s390/qeth: fix L2 header access in qeth_l3_osa_features_check()
In reply to Julian Wiedmannip_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.
--- drivers/s390/net/qeth_l3_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/net/qeth_l3_main.c +1 -1
@@ -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); }
Signature · 1 line
2.17.1
This series was applied to netdev/net.git (refs/heads/master):
Hello:
This series was applied to netdev/net.git (refs/heads/master):
Quoted 9 lines · 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