* [PATCH net v1] hinic: fix a bug of ndo_stop
@ 2020-05-07 18:22 Luo bin
2020-05-08 21:24 ` Jakub Kicinski
0 siblings, 1 reply; 3+ messages in thread
From: Luo bin @ 2020-05-07 18:22 UTC (permalink / raw)
To: davem
Cc: linux-kernel, netdev, luoxianjun, luobin9, yin.yinshi, cloud.wangxiaoyun
if some function in ndo_stop interface returns failure because of
hardware fault, must go on excuting rest steps rather than return
failure directly, otherwise will cause memory leak
Signed-off-by: Luo bin <luobin9@huawei.com>
---
.../net/ethernet/huawei/hinic/hinic_hw_mgmt.c | 28 ++++++++++++++-----
.../net/ethernet/huawei/hinic/hinic_main.c | 16 ++---------
2 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c b/drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c
index eef855f11a01..e66659bab012 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c
@@ -45,6 +45,10 @@
#define MGMT_MSG_TIMEOUT 5000
+#define SET_FUNC_PORT_MBOX_TIMEOUT 30000
+
+#define SET_FUNC_PORT_MGMT_TIMEOUT 25000
+
#define mgmt_to_pfhwdev(pf_mgmt) \
container_of(pf_mgmt, struct hinic_pfhwdev, pf_to_mgmt)
@@ -238,12 +242,13 @@ static int msg_to_mgmt_sync(struct hinic_pf_to_mgmt *pf_to_mgmt,
u8 *buf_in, u16 in_size,
u8 *buf_out, u16 *out_size,
enum mgmt_direction_type direction,
- u16 resp_msg_id)
+ u16 resp_msg_id, u32 timeout)
{
struct hinic_hwif *hwif = pf_to_mgmt->hwif;
struct pci_dev *pdev = hwif->pdev;
struct hinic_recv_msg *recv_msg;
struct completion *recv_done;
+ unsigned long timeo;
u16 msg_id;
int err;
@@ -267,8 +272,9 @@ static int msg_to_mgmt_sync(struct hinic_pf_to_mgmt *pf_to_mgmt,
goto unlock_sync_msg;
}
- if (!wait_for_completion_timeout(recv_done,
- msecs_to_jiffies(MGMT_MSG_TIMEOUT))) {
+ timeo = msecs_to_jiffies(timeout ? timeout : MGMT_MSG_TIMEOUT);
+
+ if (!wait_for_completion_timeout(recv_done, timeo)) {
dev_err(&pdev->dev, "MGMT timeout, MSG id = %d\n", msg_id);
err = -ETIMEDOUT;
goto unlock_sync_msg;
@@ -342,6 +348,7 @@ int hinic_msg_to_mgmt(struct hinic_pf_to_mgmt *pf_to_mgmt,
{
struct hinic_hwif *hwif = pf_to_mgmt->hwif;
struct pci_dev *pdev = hwif->pdev;
+ u32 timeout = 0;
if (sync != HINIC_MGMT_MSG_SYNC) {
dev_err(&pdev->dev, "Invalid MGMT msg type\n");
@@ -353,13 +360,20 @@ int hinic_msg_to_mgmt(struct hinic_pf_to_mgmt *pf_to_mgmt,
return -EINVAL;
}
- if (HINIC_IS_VF(hwif))
+ if (HINIC_IS_VF(hwif)) {
+ if (cmd == HINIC_PORT_CMD_SET_FUNC_STATE)
+ timeout = SET_FUNC_PORT_MBOX_TIMEOUT;
+
return hinic_mbox_to_pf(pf_to_mgmt->hwdev, mod, cmd, buf_in,
- in_size, buf_out, out_size, 0);
- else
+ in_size, buf_out, out_size, timeout);
+ } else {
+ if (cmd == HINIC_PORT_CMD_SET_FUNC_STATE)
+ timeout = SET_FUNC_PORT_MGMT_TIMEOUT;
+
return msg_to_mgmt_sync(pf_to_mgmt, mod, cmd, buf_in, in_size,
buf_out, out_size, MGMT_DIRECT_SEND,
- MSG_NOT_RESP);
+ MSG_NOT_RESP, timeout);
+ }
}
/**
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_main.c b/drivers/net/ethernet/huawei/hinic/hinic_main.c
index 3d6569d7bac8..22ee868dd11e 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_main.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_main.c
@@ -487,7 +487,6 @@ static int hinic_close(struct net_device *netdev)
{
struct hinic_dev *nic_dev = netdev_priv(netdev);
unsigned int flags;
- int err;
down(&nic_dev->mgmt_lock);
@@ -504,20 +503,9 @@ static int hinic_close(struct net_device *netdev)
if (!HINIC_IS_VF(nic_dev->hwdev->hwif))
hinic_notify_all_vfs_link_changed(nic_dev->hwdev, 0);
- err = hinic_port_set_func_state(nic_dev, HINIC_FUNC_PORT_DISABLE);
- if (err) {
- netif_err(nic_dev, drv, netdev,
- "Failed to set func port state\n");
- nic_dev->flags |= (flags & HINIC_INTF_UP);
- return err;
- }
+ hinic_port_set_state(nic_dev, HINIC_PORT_DISABLE);
- err = hinic_port_set_state(nic_dev, HINIC_PORT_DISABLE);
- if (err) {
- netif_err(nic_dev, drv, netdev, "Failed to set port state\n");
- nic_dev->flags |= (flags & HINIC_INTF_UP);
- return err;
- }
+ hinic_port_set_func_state(nic_dev, HINIC_FUNC_PORT_DISABLE);
if (nic_dev->flags & HINIC_RSS_ENABLE) {
hinic_rss_deinit(nic_dev);
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v1] hinic: fix a bug of ndo_stop
2020-05-07 18:22 [PATCH net v1] hinic: fix a bug of ndo_stop Luo bin
@ 2020-05-08 21:24 ` Jakub Kicinski
2020-05-09 2:13 ` luobin (L)
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2020-05-08 21:24 UTC (permalink / raw)
To: Luo bin
Cc: davem, linux-kernel, netdev, luoxianjun, yin.yinshi, cloud.wangxiaoyun
On Thu, 7 May 2020 18:22:27 +0000 Luo bin wrote:
> if some function in ndo_stop interface returns failure because of
> hardware fault, must go on excuting rest steps rather than return
> failure directly, otherwise will cause memory leak
>
> Signed-off-by: Luo bin <luobin9@huawei.com>
The code looks good, but would it make sense to split this patch into
two? First one that ignores the return values on close path with these
fixes tags:
Fixes: e2585ea77538 ("net-next/hinic: Add Rx handler")
Fixes: c4d06d2d208a ("net-next/hinic: Add Rx mode and link event handler")
And a separate patch which bumps the timeout for SET_FUNC_STATE? Right
now you don't even mention the timeout changes in the commit message.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v1] hinic: fix a bug of ndo_stop
2020-05-08 21:24 ` Jakub Kicinski
@ 2020-05-09 2:13 ` luobin (L)
0 siblings, 0 replies; 3+ messages in thread
From: luobin (L) @ 2020-05-09 2:13 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, linux-kernel, netdev, luoxianjun, yin.yinshi, cloud.wangxiaoyun
The two modified points are relevant. We bump the timeout for SET_FUNC_STATE
to ensure that cmd won't return failure when hw is busy. Otherwise hw
may stomp
host memory if we free memory regardless of the return value of
SET_FUNC_STATE.
I will mention the timeout changes in the commit message. And the bug
exists since
the first commit, not introduced. Thanks for your review.
On 2020/5/9 5:24, Jakub Kicinski wrote:
> On Thu, 7 May 2020 18:22:27 +0000 Luo bin wrote:
>> if some function in ndo_stop interface returns failure because of
>> hardware fault, must go on excuting rest steps rather than return
>> failure directly, otherwise will cause memory leak
>>
>> Signed-off-by: Luo bin <luobin9@huawei.com>
> The code looks good, but would it make sense to split this patch into
> two? First one that ignores the return values on close path with these
> fixes tags:
>
> Fixes: e2585ea77538 ("net-next/hinic: Add Rx handler")
> Fixes: c4d06d2d208a ("net-next/hinic: Add Rx mode and link event handler")
>
> And a separate patch which bumps the timeout for SET_FUNC_STATE? Right
> now you don't even mention the timeout changes in the commit message.
> .
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-09 2:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07 18:22 [PATCH net v1] hinic: fix a bug of ndo_stop Luo bin
2020-05-08 21:24 ` Jakub Kicinski
2020-05-09 2:13 ` luobin (L)
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.