Received: by 10.192.165.156 with SMTP id m28csp42539imm; Tue, 10 Apr 2018 16:01:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx49Jooun+YqfoqDaDdGefZEYKxmeaQu+9jzylWAgpxSmhAv8Jj0g9w0bwBB6qSYCp012z7wi X-Received: by 10.101.98.22 with SMTP id d22mr1651814pgv.344.1523401276691; Tue, 10 Apr 2018 16:01:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523401276; cv=none; d=google.com; s=arc-20160816; b=Uklbp9557v2T5sDvbIccgIWRDLAMpK3109BM8H3nravNTnlEh/C1JayDZf+1rp+4vl pOLSGpsFoJTI7jEz+CW0kOQDr6fVOHuMXXA2rs413utIJb1YOiiCsL+0C4d4VMr2Q/T/ qrqLgV8tAbI8M3t2CLWJEYt54JnMg0DhK1PRPFgY/2zC+S3WjpYe48N/vUGbAWplG00Q ODzjWoD5NosHfxOl3BWXB8RYHh6vfiy4WzKQ48ZQC8ZmmE4DUTpjgcV8+HQUtI9jWaxS UPehYMf5/0cfILtZvJ989yeP+KKlX/oBjB+80AYA4+li9yDuM6rrFW+UryqgbaEjuPjG er4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Sg4y9PeKmgRYlPk3AGd2GgyvDQzYVtggpbswWeOfRNA=; b=HjdyBdQaOV0/ClfXkB5i5iXmxdue3TdMUVGdh+M8tg9eOy8kWMxGLHRyz99JfWRJ9i cNh0bwmnTRUHwQwrHnaTZuUoXSP2ErntoiscY2k3GsADhIUtj5iS7AJO4AofTtrhVPua M2EmX7ujygwoLtxV0fiRnPql8h5p+jRzZLadjWf7l7iQXhmmKqxk1ACz3rTdBbvyY4FH VE/KfvXvif3bBKnInCz4uP6H3mdbEBfQCXQs/MhTR/URea7otRIS4eBQzI01saMW35Se wAjW0QxNNPSmcIuggX5PyeAAZSb104sntXf55mN4PQttHTdr2ZnkeicMmPnzuGG/9AC0 Rzyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q64si2788105pfq.385.2018.04.10.16.00.32; Tue, 10 Apr 2018 16:01:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755773AbeDJWhD (ORCPT + 99 others); Tue, 10 Apr 2018 18:37:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43640 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755758AbeDJWhB (ORCPT ); Tue, 10 Apr 2018 18:37:01 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6B8D5C49; Tue, 10 Apr 2018 22:37:00 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jacob Keller , Andrew Bowers , Jeff Kirsher , Sasha Levin Subject: [PATCH 4.14 068/138] i40evf: dont rely on netif_running() outside rtnl_lock() Date: Wed, 11 Apr 2018 00:24:18 +0200 Message-Id: <20180410212910.008358359@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180410212902.121524696@linuxfoundation.org> References: <20180410212902.121524696@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jacob Keller [ Upstream commit 44b034b406211fc103159f82b9e601e05675c739 ] In i40evf_reset_task we use netif_running() to determine whether or not the device is currently up. This allows us to properly free queue memory and shut down things before we request the hardware reset. It turns out that we cannot be guaranteed of netif_running() returning false until the device is fully up, as the kernel core code sets __LINK_STATE_START prior to calling .ndo_open. Since we're not holding the rtnl_lock(), it's possible that the driver's i40evf_open handler function is currently being called while we're resetting. We can't simply hold the rtnl_lock() while checking netif_running() as this could cause a deadlock with the i40evf_open() function. Additionally, we can't avoid the deadlock by holding the rtnl_lock() over the whole reset path, as this essentially serializes all resets, and can cause massive delays if we have multiple VFs on a system. Instead, lets just check our own internal state __I40EVF_RUNNING state field. This allows us to ensure that the state is correct and is only set after we've finished bringing the device up. Without this change we might free data structures about device queues and other memory before they've been fully allocated. Signed-off-by: Jacob Keller Tested-by: Andrew Bowers Signed-off-by: Jeff Kirsher Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/intel/i40evf/i40evf_main.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) --- a/drivers/net/ethernet/intel/i40evf/i40evf_main.c +++ b/drivers/net/ethernet/intel/i40evf/i40evf_main.c @@ -1775,7 +1775,11 @@ static void i40evf_disable_vf(struct i40 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED; - if (netif_running(adapter->netdev)) { + /* We don't use netif_running() because it may be true prior to + * ndo_open() returning, so we can't assume it means all our open + * tasks have finished, since we're not holding the rtnl_lock here. + */ + if (adapter->state == __I40EVF_RUNNING) { set_bit(__I40E_VSI_DOWN, adapter->vsi.state); netif_carrier_off(adapter->netdev); netif_tx_disable(adapter->netdev); @@ -1833,6 +1837,7 @@ static void i40evf_reset_task(struct wor struct i40evf_mac_filter *f; u32 reg_val; int i = 0, err; + bool running; while (test_and_set_bit(__I40EVF_IN_CLIENT_TASK, &adapter->crit_section)) @@ -1892,7 +1897,13 @@ static void i40evf_reset_task(struct wor } continue_reset: - if (netif_running(netdev)) { + /* We don't use netif_running() because it may be true prior to + * ndo_open() returning, so we can't assume it means all our open + * tasks have finished, since we're not holding the rtnl_lock here. + */ + running = (adapter->state == __I40EVF_RUNNING); + + if (running) { netif_carrier_off(netdev); netif_tx_stop_all_queues(netdev); adapter->link_up = false; @@ -1936,7 +1947,10 @@ continue_reset: mod_timer(&adapter->watchdog_timer, jiffies + 2); - if (netif_running(adapter->netdev)) { + /* We were running when the reset started, so we need to restore some + * state here. + */ + if (running) { /* allocate transmit descriptors */ err = i40evf_setup_all_tx_resources(adapter); if (err)