From patchwork Wed Aug 12 10:10:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shay Agroskin X-Patchwork-Id: 1343606 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazon201209 header.b=e0pIkjgx; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BRQVp0QYVz9sTN for ; Wed, 12 Aug 2020 20:12:34 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727903AbgHLKMd (ORCPT ); Wed, 12 Aug 2020 06:12:33 -0400 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:34417 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727066AbgHLKMc (ORCPT ); Wed, 12 Aug 2020 06:12:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1597227152; x=1628763152; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1uh5TEN61PnHNu1WcbvErdSj2tc/99va2TOc9GBn7l4=; b=e0pIkjgx/dec0Nt3czmWpJE3ZwyKtzRs0N0+mBEmG4jJj1QlVc3Dazgu NLBGtxkNyU6pSeyQtqDgapPIduQ3NMcyLdD5OVm+PFi7SuIiorpWhCgxd cMhkBp/tDP7aKtqcsb+7JudtEcfw7lIuOjhRqU/0Ds6bPFNmvwQDgrUOw U=; IronPort-SDR: vAvU0i1ck2YuvevxQluo7CtHCWWFjFWHRHawEXcoNhwoRlB7HQOOAS2WPZbFTzyI3uDYH8p92d ikRVV1PQEiAQ== X-IronPort-AV: E=Sophos;i="5.76,303,1592870400"; d="scan'208";a="66195425" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-af6a10df.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 12 Aug 2020 10:12:32 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-af6a10df.us-east-1.amazon.com (Postfix) with ESMTPS id 6BEDEA2660; Wed, 12 Aug 2020 10:12:31 +0000 (UTC) Received: from EX13D28EUC001.ant.amazon.com (10.43.164.4) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Aug 2020 10:12:30 +0000 Received: from u4b1e9be9d67d5a.ant.amazon.com (10.43.161.34) by EX13D28EUC001.ant.amazon.com (10.43.164.4) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Aug 2020 10:12:22 +0000 From: Shay Agroskin To: , CC: , , , , , , , , , , , , , , Shay Agroskin Subject: [PATCH V1 net 1/3] net: ena: Prevent reset after device destruction Date: Wed, 12 Aug 2020 13:10:57 +0300 Message-ID: <20200812101059.5501-2-shayagr@amazon.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200812101059.5501-1-shayagr@amazon.com> References: <20200812101059.5501-1-shayagr@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.34] X-ClientProxiedBy: EX13D03UWA001.ant.amazon.com (10.43.160.141) To EX13D28EUC001.ant.amazon.com (10.43.164.4) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The reset work is scheduled by the timer routine whenever it detects that a device reset is required (e.g. when a keep_alive signal is missing). When releasing device resources in ena_destroy() the driver cancels the scheduling of the timer routine without destroying the reset work explicitly. This creates the following bug: The driver is suspended and the ena_suspend() function is called -> This function calls ena_destroy() to free the net device resources -> The driver waits for the timer routine to finish its execution and then cancels it, thus preventing from it to be called again. If, in its final execution, the timer routine schedules a reset, the reset routine might be called after the device resources are freed, which might cause a kernel panic. By changing the reset routine so that it cannot run simultaneously with the destruction routine, we allow the reset routine read the device's state accurately. This is achieved by checking whether ENA_FLAG_TRIGGER_RESET flag is set before resetting the device and making both the destruction function and the flag check are under rtnl lock. The ENA_FLAG_TRIGGER_RESET is cleared at the end of the destruction routine. Also surround the flag check with 'likely' because we expect that the reset routine would be called only when ENA_FLAG_TRIGGER_RESET flag is set. This patch also removes the destruction of the timer and reset services from ena_remove() since the timer is destroyed by the destruction routine and the reset work is handled by this patch. Fixes: 8c5c7abdeb2d ("net: ena: add power management ops to the ENA driver") Signed-off-by: Shay Agroskin --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index 2a6c9725e092..0488fcbf48f7 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -3601,16 +3601,14 @@ static void ena_fw_reset_device(struct work_struct *work) { struct ena_adapter *adapter = container_of(work, struct ena_adapter, reset_task); - struct pci_dev *pdev = adapter->pdev; - if (unlikely(!test_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags))) { - dev_err(&pdev->dev, - "device reset schedule while reset bit is off\n"); - return; - } rtnl_lock(); - ena_destroy_device(adapter, false); - ena_restore_device(adapter); + + if (likely(test_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags))) { + ena_destroy_device(adapter, false); + ena_restore_device(adapter); + } + rtnl_unlock(); } @@ -4389,9 +4387,6 @@ static void __ena_shutoff(struct pci_dev *pdev, bool shutdown) netdev->rx_cpu_rmap = NULL; } #endif /* CONFIG_RFS_ACCEL */ - del_timer_sync(&adapter->timer_service); - - cancel_work_sync(&adapter->reset_task); rtnl_lock(); /* lock released inside the below if-else block */ adapter->reset_reason = ENA_REGS_RESET_SHUTDOWN; From patchwork Wed Aug 12 10:10:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shay Agroskin X-Patchwork-Id: 1343607 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazon201209 header.b=Q3a2Qom4; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BRQVz32xWz9sRK for ; Wed, 12 Aug 2020 20:12:43 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727921AbgHLKMm (ORCPT ); Wed, 12 Aug 2020 06:12:42 -0400 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:34450 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727066AbgHLKMl (ORCPT ); Wed, 12 Aug 2020 06:12:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1597227161; x=1628763161; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fQc6qqOfI/lwu7nYkZ6D71WjAgjtnM97j5OY01xd6NM=; b=Q3a2Qom4WAF36Ig16a87R6XAnj6OOLjh1FU+kHQz/r1LSJfznjJ+QX7f 8T/6tkuLfGJ0OfB8FqATdRxCAVniw7OB0riNdMfSPLUQMDOVkqJZGhubc UkLc63qPBUpFvnNGVt2OvbL0KSxCq3HaIndTNeuFw1xuGnoTYl7nGLVNn I=; IronPort-SDR: 5cm737R2GNl2wDxV3SOQHfieOuUC1Vl4mkUMfy6FyVWMslY12DRTEOy8/c9BpiQVTA8Ue3QijN 5yhAEu7HsqZg== X-IronPort-AV: E=Sophos;i="5.76,303,1592870400"; d="scan'208";a="66195448" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-715bee71.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 12 Aug 2020 10:12:41 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1a-715bee71.us-east-1.amazon.com (Postfix) with ESMTPS id 36E32A23D1; Wed, 12 Aug 2020 10:12:39 +0000 (UTC) Received: from EX13D28EUC001.ant.amazon.com (10.43.164.4) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Aug 2020 10:12:38 +0000 Received: from u4b1e9be9d67d5a.ant.amazon.com (10.43.161.34) by EX13D28EUC001.ant.amazon.com (10.43.164.4) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Aug 2020 10:12:30 +0000 From: Shay Agroskin To: , CC: , , , , , , , , , , , , , , Shay Agroskin Subject: [PATCH V1 net 2/3] net: ena: Change WARN_ON expression in ena_del_napi_in_range() Date: Wed, 12 Aug 2020 13:10:58 +0300 Message-ID: <20200812101059.5501-3-shayagr@amazon.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200812101059.5501-1-shayagr@amazon.com> References: <20200812101059.5501-1-shayagr@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.34] X-ClientProxiedBy: EX13D03UWA001.ant.amazon.com (10.43.160.141) To EX13D28EUC001.ant.amazon.com (10.43.164.4) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The ena_del_napi_in_range() function unregisters the napi handler for rings in a given range. This function had the following WARN_ON macro: WARN_ON(ENA_IS_XDP_INDEX(adapter, i) && adapter->ena_napi[i].xdp_ring); This macro prints the call stack if the expression inside of it is true [1], but the expression inside of it is the wanted situation. The expression checks whether the ring has an XDP queue and its index corresponds to a XDP one. This patch changes the expression to !ENA_IS_XDP_INDEX(adapter, i) && adapter->ena_napi[i].xdp_ring which indicates an unwanted situation. Also, change the structure of the function. The napi handler is unregistered for all rings, and so there's no need to check whether the index is an XDP index or not. By removing this check the code becomes much more readable. [1]: https://elixir.bootlin.com/linux/latest/source/arch/parisc/include/asm/bug.h#L79 Fixes: 8c5c7abdeb2d ("net: ena: add power management ops to the ENA driver") Signed-off-by: Shay Agroskin --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index 0488fcbf48f7..3e12065482c2 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -2180,13 +2180,10 @@ static void ena_del_napi_in_range(struct ena_adapter *adapter, int i; for (i = first_index; i < first_index + count; i++) { - /* Check if napi was initialized before */ - if (!ENA_IS_XDP_INDEX(adapter, i) || - adapter->ena_napi[i].xdp_ring) - netif_napi_del(&adapter->ena_napi[i].napi); - else - WARN_ON(ENA_IS_XDP_INDEX(adapter, i) && - adapter->ena_napi[i].xdp_ring); + netif_napi_del(&adapter->ena_napi[i].napi); + + WARN_ON(!ENA_IS_XDP_INDEX(adapter, i) && + adapter->ena_napi[i].xdp_ring); } } From patchwork Wed Aug 12 10:10:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shay Agroskin X-Patchwork-Id: 1343608 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazon201209 header.b=qHJ6vBA9; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BRQW75z4vz9sRK for ; Wed, 12 Aug 2020 20:12:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbgHLKMv (ORCPT ); Wed, 12 Aug 2020 06:12:51 -0400 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:34471 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727822AbgHLKMt (ORCPT ); Wed, 12 Aug 2020 06:12:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1597227169; x=1628763169; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JSTcKpQGbU4Hlyo6aiY3G4/WOLzVLWrmatTRT63KG1o=; b=qHJ6vBA9MO3NmvbLfbwMdLD/eme2oVLIp3InMUqTK89pdIzyA+5HM5O7 J4BrHLbl+3xQ4JBUpixa45Xbotzh9+Aox+kIwbTG3UlR4roU53n77nkOV MajXXhCd3Peb1CnKlJefjGfGyDBgr3VkmeqMUu/LTnBQPXN1vb/lFSLRI I=; IronPort-SDR: zMC06vIw7jEUWtNfBux05Mb1fmixsAL7TD7y2V2agVD4XJZ6AlU5evr7zntrA6UFwNbUzUUIda A93ugoVtDtEQ== X-IronPort-AV: E=Sophos;i="5.76,303,1592870400"; d="scan'208";a="66195468" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-a70de69e.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 12 Aug 2020 10:12:49 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-a70de69e.us-east-1.amazon.com (Postfix) with ESMTPS id 3AAC9A251D; Wed, 12 Aug 2020 10:12:47 +0000 (UTC) Received: from EX13D28EUC001.ant.amazon.com (10.43.164.4) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Aug 2020 10:12:47 +0000 Received: from u4b1e9be9d67d5a.ant.amazon.com (10.43.161.34) by EX13D28EUC001.ant.amazon.com (10.43.164.4) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Aug 2020 10:12:38 +0000 From: Shay Agroskin To: , CC: , , , , , , , , , , , , , , Shay Agroskin Subject: [PATCH V1 net 3/3] net: ena: Make missed_tx stat incremental Date: Wed, 12 Aug 2020 13:10:59 +0300 Message-ID: <20200812101059.5501-4-shayagr@amazon.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200812101059.5501-1-shayagr@amazon.com> References: <20200812101059.5501-1-shayagr@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.34] X-ClientProxiedBy: EX13D03UWA001.ant.amazon.com (10.43.160.141) To EX13D28EUC001.ant.amazon.com (10.43.164.4) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Most statistics in ena driver are incremented, meaning that a stat's value is a sum of all increases done to it since driver/queue initialization. This patch makes all statistics this way, effectively making missed_tx statistic incremental. Also added a comment regarding rx_drops and tx_drops to make it clearer how these counters are calculated. Fixes: 11095fdb712b ("net: ena: add statistics for missed tx packets") Signed-off-by: Shay Agroskin --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index 3e12065482c2..7a11a759d053 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -3687,7 +3687,7 @@ static int check_missing_comp_in_tx_queue(struct ena_adapter *adapter, } u64_stats_update_begin(&tx_ring->syncp); - tx_ring->tx_stats.missed_tx = missed_tx; + tx_ring->tx_stats.missed_tx += missed_tx; u64_stats_update_end(&tx_ring->syncp); return rc; @@ -4550,6 +4550,9 @@ static void ena_keep_alive_wd(void *adapter_data, tx_drops = ((u64)desc->tx_drops_high << 32) | desc->tx_drops_low; u64_stats_update_begin(&adapter->syncp); + /* These stats are accumulated by the device, so the counters indicate + * all drops since last reset. + */ adapter->dev_stats.rx_drops = rx_drops; adapter->dev_stats.tx_drops = tx_drops; u64_stats_update_end(&adapter->syncp);