WSL2-Linux-Kernel/drivers/net/ethernet/huawei/hinic
Qiao Ma 98f9fcdee3 net: hinic: avoid kernel hung in hinic_get_stats64()
When using hinic device as a bond slave device, and reading device stats
of master bond device, the kernel may hung.

The kernel panic calltrace as follows:
Kernel panic - not syncing: softlockup: hung tasks
Call trace:
  native_queued_spin_lock_slowpath+0x1ec/0x31c
  dev_get_stats+0x60/0xcc
  dev_seq_printf_stats+0x40/0x120
  dev_seq_show+0x1c/0x40
  seq_read_iter+0x3c8/0x4dc
  seq_read+0xe0/0x130
  proc_reg_read+0xa8/0xe0
  vfs_read+0xb0/0x1d4
  ksys_read+0x70/0xfc
  __arm64_sys_read+0x20/0x30
  el0_svc_common+0x88/0x234
  do_el0_svc+0x2c/0x90
  el0_svc+0x1c/0x30
  el0_sync_handler+0xa8/0xb0
  el0_sync+0x148/0x180

And the calltrace of task that actually caused kernel hungs as follows:
  __switch_to+124
  __schedule+548
  schedule+72
  schedule_timeout+348
  __down_common+188
  __down+24
  down+104
  hinic_get_stats64+44 [hinic]
  dev_get_stats+92
  bond_get_stats+172 [bonding]
  dev_get_stats+92
  dev_seq_printf_stats+60
  dev_seq_show+24
  seq_read_iter+964
  seq_read+220
  proc_reg_read+164
  vfs_read+172
  ksys_read+108
  __arm64_sys_read+28
  el0_svc_common+132
  do_el0_svc+40
  el0_svc+24
  el0_sync_handler+164
  el0_sync+324

When getting device stats from bond, kernel will call bond_get_stats().
It first holds the spinlock bond->stats_lock, and then call
hinic_get_stats64() to collect hinic device's stats.
However, hinic_get_stats64() calls `down(&nic_dev->mgmt_lock)` to
protect its critical section, which may schedule current task out.
And if system is under high pressure, the task cannot be woken up
immediately, which eventually triggers kernel hung panic.

Since previous patch has replaced hinic_dev.tx_stats/rx_stats with local
variable in hinic_get_stats64(), there is nothing need to be protected
by lock, so just removing down()/up() is ok.

Fixes: edd384f682 ("net-next/hinic: Add ethtool and stats")
Signed-off-by: Qiao Ma <mqaio@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-07-06 13:09:28 +01:00
..
Kconfig net: hinic: fix DEVLINK build errors 2020-10-03 16:52:19 -07:00
Makefile hinic: add support to query sq info 2020-08-31 12:21:26 -07:00
hinic_common.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
hinic_common.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
hinic_debugfs.c hinic: add support to query function table 2020-08-31 12:21:27 -07:00
hinic_debugfs.h hinic: add support to query function table 2020-08-31 12:21:27 -07:00
hinic_dev.h net: hinic: fix bug that ethtool get wrong stats 2022-07-06 13:09:28 +01:00
hinic_devlink.c hinic: Replace memcpy() with direct assignment 2022-06-17 11:31:18 +01:00
hinic_devlink.h devlink: Make devlink_register to be void 2021-09-22 14:15:12 +01:00
hinic_ethtool.c ethtool: extend ringparam setting/getting API with rx_buf_len 2021-11-22 12:31:49 +00:00
hinic_hw_api_cmd.c net: huawei: hinic: Use devm_kcalloc() instead of devm_kzalloc() 2021-12-08 18:37:28 -08:00
hinic_hw_api_cmd.h hinic: add log in exception handling processes 2020-07-28 17:22:03 -07:00
hinic_hw_cmdq.c net: huawei: hinic: Use devm_kcalloc() instead of devm_kzalloc() 2021-12-08 18:37:28 -08:00
hinic_hw_cmdq.h hinic: add check for mailbox msg from VF 2020-08-04 12:17:06 -07:00
hinic_hw_csr.h hinic: add mailbox function support 2020-04-25 20:46:27 -07:00
hinic_hw_dev.c net: huawei: hinic: Use devm_kcalloc() instead of devm_kzalloc() 2021-12-08 18:37:28 -08:00
hinic_hw_dev.h hinic: add support to query function table 2020-08-31 12:21:27 -07:00
hinic_hw_eqs.c net: huawei: hinic: Use devm_kcalloc() instead of devm_kzalloc() 2021-12-08 18:37:28 -08:00
hinic_hw_eqs.h hinic: modify irq name 2020-09-18 14:34:24 -07:00
hinic_hw_if.c net: huawei: hinic: Fix wrong function name in comments 2021-05-17 14:12:38 -07:00
hinic_hw_if.h hinic: add log in exception handling processes 2020-07-28 17:22:03 -07:00
hinic_hw_io.c net: hinic: Use devm_kcalloc() instead of devm_kzalloc() 2021-12-08 18:37:06 -08:00
hinic_hw_io.h hinic: add support to query sq info 2020-08-31 12:21:26 -07:00
hinic_hw_mbox.c hinic: add check for mailbox msg from VF 2020-08-04 12:17:06 -07:00
hinic_hw_mbox.h hinic: add check for mailbox msg from VF 2020-08-04 12:17:06 -07:00
hinic_hw_mgmt.c net: hinic: add missing destroy_workqueue in hinic_pf_to_mgmt_init 2022-05-16 10:57:00 +01:00
hinic_hw_mgmt.h hinic: add generating mailbox random index support 2020-08-04 12:17:06 -07:00
hinic_hw_qp.c net: huawei: hinic: Fix wrong function name in comments 2021-05-17 14:12:38 -07:00
hinic_hw_qp.h hinic: add support to query rq info 2020-08-31 12:21:27 -07:00
hinic_hw_qp_ctxt.h Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2019-06-17 20:20:36 -07:00
hinic_hw_wq.c hinic: Avoid some over memory allocation 2022-05-22 21:47:57 +01:00
hinic_hw_wq.h hinic: add sriov feature support 2020-04-25 20:46:28 -07:00
hinic_hw_wqe.h hinic: add vlan offload support 2019-06-29 10:28:23 -07:00
hinic_main.c net: hinic: avoid kernel hung in hinic_get_stats64() 2022-07-06 13:09:28 +01:00
hinic_port.c net: hinic: remove unnecessary parentheses 2021-05-13 15:39:10 -07:00
hinic_port.h net: don't include ethtool.h from netdevice.h 2020-11-23 17:27:04 -08:00
hinic_rx.c net: hinic: fix bug that ethtool get wrong stats 2022-07-06 13:09:28 +01:00
hinic_rx.h hinic: implement the statistical interface of ethtool 2019-06-24 07:18:11 -07:00
hinic_sriov.c ethernet: Remove vf rate limit check for drivers 2022-06-10 22:19:32 -07:00
hinic_sriov.h hinic: add three net_device_ops of vf 2020-05-09 15:28:21 -07:00
hinic_tx.c net: hinic: fix bug that ethtool get wrong stats 2022-07-06 13:09:28 +01:00
hinic_tx.h hinic: add self test support 2020-06-28 20:40:58 -07:00