Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2966254ybk; Mon, 18 May 2020 12:17:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmV1i044IZxlR1K8s1fZzUotpwQJ0qO7hKlHLcwB10d/LeWvlZVp1vdH6yqq7gR/ufkhfe X-Received: by 2002:a50:f111:: with SMTP id w17mr12550872edl.41.1589829459063; Mon, 18 May 2020 12:17:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589829459; cv=none; d=google.com; s=arc-20160816; b=a3Wjc2+GpylAeJTtyM2Ntywg0dOwzLp76EcxnMp4shzpHIN+sY2jBLgAKkK0zuGmcy tvCjIOE/nxoOkNN/DKKI9dJDn/zBPlQgDnwE+MZiQQOvQzAGBjN/pOR0ZK6DTeixkX1j awzp3UVgJcB/NHq5KMqot2Ks8Z6QfSXDUEwaF3mJVt5sY54Nz7JFdCjF7BtEvmDyMUxR Jd54TDrKMpJ9tlRBssEECbi2LF8ie+pGAA0+yTCRJMitfp+4S8pd7lXD3NfnEcnegXfS /upyuF9vSLQ2B4rrtCwSr3L1KtIQkTMzZN0YXH6bA2ZJ+bXFeixnu0WdAcIIBV5sGyHp Q9ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=54/2rTVLUiscsmZocSLime6gpqRDI+ZkdfI+aYwg9ko=; b=XpECtgCLxgrlqObZC4FhMWU+ZoBCpLVMUKzQREMj78eUxpDctkZUNOtJ6YZsrSklM9 gIG85oPwN/79s9yK5HYR0Zb0t6Mg+3t8NNCq/InErMreGBLFDF9nohtJ2RX3w5lnXlGY Jcfo0QwMVVAZstZVL4rnJeLvCuZyl1JOyhTViNk1mSVfA3UOr1JXId3a1U4Kb62nSh4N ztMB5V4YMHqd1ZGr2888LgmQXi6KbmGZvfUwO5avMMYH8oo3e/jn/LfzCrEv3Zr0mUhI et1FgdMhVMxrMOAHSSzNez/6BU/NsnjeuXNCbHOS09jH+ku3IoPAHFQlHyPLGy69vpnl s6qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="kR/ao+kd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oq5si7087774ejb.395.2020.05.18.12.17.16; Mon, 18 May 2020 12:17:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="kR/ao+kd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730719AbgERRux (ORCPT + 99 others); Mon, 18 May 2020 13:50:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:53122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730784AbgERRus (ORCPT ); Mon, 18 May 2020 13:50:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3FB3D20674; Mon, 18 May 2020 17:50:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589824247; bh=3AbfgXRjpm4Ncsl15BA9IV9XcKMlw1Wh5sqRyiiVnn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kR/ao+kd86epG8p/uJQNXEaQFFbZE6CNLesbi8RkZudvfeW2U0thveBUMq16u7DD0 PLIJJts8sKmhLAs5hqOG3vz8pdE37SbCQuwB0SbznjYmKVjXoizKk9/eL0ctQv2CGc Cv0XyxytEZYHfLX0xBOArUxhOVym+KAt+WrXvPJo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luo bin , Jakub Kicinski Subject: [PATCH 4.19 16/80] hinic: fix a bug of ndo_stop Date: Mon, 18 May 2020 19:36:34 +0200 Message-Id: <20200518173453.702399842@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518173450.097837707@linuxfoundation.org> References: <20200518173450.097837707@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luo bin [ Upstream commit e8a1b0efd632d1c9db7d4e93da66377c7b524862 ] 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.And 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. Fixes: 51ba902a16e6 ("net-next/hinic: Initialize hw interface") Signed-off-by: Luo bin Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c | 16 ++++++++++++---- drivers/net/ethernet/huawei/hinic/hinic_main.c | 18 +++--------------- 2 files changed, 15 insertions(+), 19 deletions(-) --- a/drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c @@ -54,6 +54,8 @@ #define MGMT_MSG_TIMEOUT 5000 +#define SET_FUNC_PORT_MGMT_TIMEOUT 25000 + #define mgmt_to_pfhwdev(pf_mgmt) \ container_of(pf_mgmt, struct hinic_pfhwdev, pf_to_mgmt) @@ -247,12 +249,13 @@ static int msg_to_mgmt_sync(struct hinic 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; @@ -276,8 +279,9 @@ static int msg_to_mgmt_sync(struct hinic 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; @@ -351,6 +355,7 @@ int hinic_msg_to_mgmt(struct hinic_pf_to { 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"); @@ -362,9 +367,12 @@ int hinic_msg_to_mgmt(struct hinic_pf_to return -EINVAL; } + 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); } /** --- a/drivers/net/ethernet/huawei/hinic/hinic_main.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_main.c @@ -475,7 +475,6 @@ static int hinic_close(struct net_device { struct hinic_dev *nic_dev = netdev_priv(netdev); unsigned int flags; - int err; down(&nic_dev->mgmt_lock); @@ -489,20 +488,9 @@ static int hinic_close(struct net_device up(&nic_dev->mgmt_lock); - 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; - } - - 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_state(nic_dev, HINIC_PORT_DISABLE); + + hinic_port_set_func_state(nic_dev, HINIC_FUNC_PORT_DISABLE); free_rxqs(nic_dev); free_txqs(nic_dev);