From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DC4ADA0C47 for ; Tue, 10 Aug 2021 17:44:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D1ABE40686; Tue, 10 Aug 2021 17:44:57 +0200 (CEST) Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) by mails.dpdk.org (Postfix) with ESMTP id B84B24014F for ; Tue, 10 Aug 2021 17:44:56 +0200 (CEST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPS id 9CEDD3F107 for ; Tue, 10 Aug 2021 15:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1628610296; bh=gJtgGjngMQU2bvl/vIYoB2TTonu4HmrbfE+rCfmzGAQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JUT3FIL4+IpmukRHtTxrWf/074+lIUHTtY7aHGaBrsHzhXHZE1c3gBKwwpt1dqF0B odmcg57XKo52DXP45CQNXCR/7xSOrwoVvfsFWHoHUIDckLADGynGpohh/JRx001IR+ As9RnWAaZPzqS4IpWcByJcD03BagRSMKdvF070k4zBYHsgvZiBJ3JiIUoIiJErHul9 4CMmEw2GDl4aaKYmLtF1VimCECN03LSitlw2fnhKNn0vYZ3Oe63ogCS2zhXRS2UvLu jHHlcVrAx7LZF6o+Xv/mHK+HTdpmfAfme9+yPUcEQ9VTbqXfOur1gpnboJuNSHqhjy iGMze9lb0xWTw== Received: by mail-ed1-f69.google.com with SMTP id b25-20020a05640202d9b02903be7281a80cso2394605edx.3 for ; Tue, 10 Aug 2021 08:44:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gJtgGjngMQU2bvl/vIYoB2TTonu4HmrbfE+rCfmzGAQ=; b=jjHETDBlV2PZcvOaPSqcgGGsrCce6nQfn1XqTJz727m+Mq6B8OvUBcUeS2u1rIayRe xv9bfZfsfVqJYkOwy8YwAzNTMxOsJ563A+swWoSR89Jp5SOxvuTx3A/+sUkwGfeJM8E6 jHAfTqqByjmAN5ZN6eJygNwH6HT+yw0l0sj16DBKpaY4OwZhl8n1uk63jFAkcLW15jWo SujCEOZDzCjmPnGhdk2zoQfxXbJFVcS6dAMwjz00T+COgI3mIhXfA8f+1ZvNOktVfTIC sSM2TDNTAjTKfOznUuBP/UDi4S4cxFbwmC6V2igcLfEqMenU/jm//eAMkEl3njd4Nq2m sUBA== X-Gm-Message-State: AOAM530rQGlbDYHZRFTsExp0RRvT+ua4Fwi7adV6Um7Bvvd2Rdm/RGJB /Zg0k5YZKlbzh1lcAhHFbC9uGkeyuzOybVHkvdLV5rSiONrvI+E2vQwB2CCliuuDHfWUmFm6waL PWLa/1VzZCDEeT1oprHFK+wEP X-Received: by 2002:a05:6402:26d1:: with SMTP id x17mr5891899edd.126.1628610296363; Tue, 10 Aug 2021 08:44:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuLp4+dDgSXaNKW+NuBrzD8aYE7M/RU6c3KjFjs4pF0sxdDT90qYAFUGOetIrKvPpsSvmMhQ== X-Received: by 2002:a05:6402:26d1:: with SMTP id x17mr5891891edd.126.1628610296178; Tue, 10 Aug 2021 08:44:56 -0700 (PDT) Received: from Keschdeichel.fritz.box ([2001:67c:1560:8007::aac:c4ad]) by smtp.gmail.com with ESMTPSA id s24sm1712089edq.56.2021.08.10.08.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 08:44:55 -0700 (PDT) From: christian.ehrhardt@canonical.com To: Ivan Ilchenko Cc: Andrew Rybchenko , Andy Moreton , dpdk stable Date: Tue, 10 Aug 2021 17:40:06 +0200 Message-Id: <20210810154022.749358-86-christian.ehrhardt@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810154022.749358-1-christian.ehrhardt@canonical.com> References: <20210810154022.749358-1-christian.ehrhardt@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'net/sfc: fix reading adapter state without locking' has been queued to stable release 19.11.10 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to stable release 19.11.10 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 08/12/21. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/cpaelzer/dpdk-stable-queue This queued commit can be viewed at: https://github.com/cpaelzer/dpdk-stable-queue/commit/388d4a9184c7ab3739f45ae1e14d99a48d4826bf Thanks. Christian Ehrhardt --- >From 388d4a9184c7ab3739f45ae1e14d99a48d4826bf Mon Sep 17 00:00:00 2001 From: Ivan Ilchenko Date: Fri, 23 Jul 2021 16:15:06 +0300 Subject: [PATCH] net/sfc: fix reading adapter state without locking [ upstream commit 17b0d7b36777341486efc0959d5ed69cf5af5f26 ] Update MAC stats function reads adapter state with MAC stats locking but without adapter locking. Add adapter locking before calling this function and remove MAC stats locking since there's no point to have it together with adapter locking. The second place MAC stats locking is used is MAC stats reset function. It's called with adapter being already locked so there's no point to use MAC stats locking anymore. Fixes: 1caab2f1e68 ("net/sfc: add basic statistics") Signed-off-by: Ivan Ilchenko Signed-off-by: Andrew Rybchenko Reviewed-by: Andy Moreton --- drivers/net/sfc/sfc.h | 1 - drivers/net/sfc/sfc_ethdev.c | 28 ++++++++++++++++++++-------- drivers/net/sfc/sfc_port.c | 9 +++------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index bce6beefaa..57a901b948 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -141,7 +141,6 @@ struct sfc_port { unsigned int nb_mcast_addrs; uint8_t *mcast_addrs; - rte_spinlock_t mac_stats_lock; uint64_t *mac_stats_buf; unsigned int mac_stats_nb_supported; efsys_mem_t mac_stats_dma_mem; diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index 703139f2c9..93c7ee6322 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -596,7 +596,7 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) uint64_t *mac_stats; int ret; - rte_spinlock_lock(&port->mac_stats_lock); + sfc_adapter_lock(sa); ret = sfc_port_update_mac_stats(sa); if (ret != 0) @@ -669,7 +669,7 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) } unlock: - rte_spinlock_unlock(&port->mac_stats_lock); + sfc_adapter_unlock(sa); SFC_ASSERT(ret >= 0); return -ret; } @@ -681,12 +681,15 @@ sfc_stats_reset(struct rte_eth_dev *dev) struct sfc_port *port = &sa->port; int rc; + sfc_adapter_lock(sa); + if (sa->state != SFC_ADAPTER_STARTED) { /* * The operation cannot be done if port is not started; it * will be scheduled to be done during the next port start */ port->mac_stats_reset_pending = B_TRUE; + sfc_adapter_unlock(sa); return 0; } @@ -694,6 +697,8 @@ sfc_stats_reset(struct rte_eth_dev *dev) if (rc != 0) sfc_err(sa, "failed to reset statistics (rc = %d)", rc); + sfc_adapter_unlock(sa); + SFC_ASSERT(rc >= 0); return -rc; } @@ -709,7 +714,7 @@ sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, unsigned int i; int nstats = 0; - rte_spinlock_lock(&port->mac_stats_lock); + sfc_adapter_lock(sa); rc = sfc_port_update_mac_stats(sa); if (rc != 0) { @@ -731,7 +736,7 @@ sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, } unlock: - rte_spinlock_unlock(&port->mac_stats_lock); + sfc_adapter_unlock(sa); return nstats; } @@ -772,7 +777,7 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, int ret; int rc; - rte_spinlock_lock(&port->mac_stats_lock); + sfc_adapter_lock(sa); if (unlikely(values == NULL) || unlikely(ids == NULL && n < port->mac_stats_nb_supported)) { @@ -802,7 +807,7 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, ret = nb_written; unlock: - rte_spinlock_unlock(&port->mac_stats_lock); + sfc_adapter_unlock(sa); return ret; } @@ -818,9 +823,14 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev, unsigned int nb_written = 0; unsigned int i; + sfc_adapter_lock(sa); + if (unlikely(xstats_names == NULL) || - unlikely((ids == NULL) && (size < port->mac_stats_nb_supported))) - return port->mac_stats_nb_supported; + unlikely((ids == NULL) && (size < port->mac_stats_nb_supported))) { + nb_supported = port->mac_stats_nb_supported; + sfc_adapter_unlock(sa); + return nb_supported; + } for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < size); ++i) { if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) @@ -836,6 +846,8 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev, ++nb_supported; } + sfc_adapter_unlock(sa); + return nb_written; } diff --git a/drivers/net/sfc/sfc_port.c b/drivers/net/sfc/sfc_port.c index 23313e125f..967fd3a266 100644 --- a/drivers/net/sfc/sfc_port.c +++ b/drivers/net/sfc/sfc_port.c @@ -42,7 +42,7 @@ sfc_port_update_mac_stats(struct sfc_adapter *sa) unsigned int nb_attempts = 0; int rc; - SFC_ASSERT(rte_spinlock_is_locked(&port->mac_stats_lock)); + SFC_ASSERT(sfc_adapter_is_locked(sa)); if (sa->state != SFC_ADAPTER_STARTED) return EINVAL; @@ -102,14 +102,13 @@ sfc_port_reset_sw_stats(struct sfc_adapter *sa) int sfc_port_reset_mac_stats(struct sfc_adapter *sa) { - struct sfc_port *port = &sa->port; int rc; - rte_spinlock_lock(&port->mac_stats_lock); + SFC_ASSERT(sfc_adapter_is_locked(sa)); + rc = efx_mac_stats_clear(sa->nic); if (rc == 0) sfc_port_reset_sw_stats(sa); - rte_spinlock_unlock(&port->mac_stats_lock); return rc; } @@ -415,8 +414,6 @@ sfc_port_attach(struct sfc_adapter *sa) goto fail_mcast_addr_list_buf_alloc; } - rte_spinlock_init(&port->mac_stats_lock); - rc = ENOMEM; port->mac_stats_buf = rte_calloc_socket("mac_stats_buf", EFX_MAC_NSTATS, sizeof(uint64_t), 0, -- 2.32.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2021-08-10 15:11:16.327853300 +0200 +++ 0086-net-sfc-fix-reading-adapter-state-without-locking.patch 2021-08-10 15:11:13.102638705 +0200 @@ -1 +1 @@ -From 17b0d7b36777341486efc0959d5ed69cf5af5f26 Mon Sep 17 00:00:00 2001 +From 388d4a9184c7ab3739f45ae1e14d99a48d4826bf Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 17b0d7b36777341486efc0959d5ed69cf5af5f26 ] + @@ -14 +15,0 @@ -Cc: stable@dpdk.org @@ -26 +27 @@ -index 546739bd4a..c7b0e5a30d 100644 +index bce6beefaa..57a901b948 100644 @@ -29 +30 @@ -@@ -130,7 +130,6 @@ struct sfc_port { +@@ -141,7 +141,6 @@ struct sfc_port { @@ -38 +39 @@ -index d4ac61ff76..d5417e5e65 100644 +index 703139f2c9..93c7ee6322 100644 @@ -41 +42 @@ -@@ -613,7 +613,7 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) +@@ -596,7 +596,7 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) @@ -50 +51 @@ -@@ -686,7 +686,7 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) +@@ -669,7 +669,7 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) @@ -59 +60 @@ -@@ -698,12 +698,15 @@ sfc_stats_reset(struct rte_eth_dev *dev) +@@ -681,12 +681,15 @@ sfc_stats_reset(struct rte_eth_dev *dev) @@ -75 +76 @@ -@@ -711,6 +714,8 @@ sfc_stats_reset(struct rte_eth_dev *dev) +@@ -694,6 +697,8 @@ sfc_stats_reset(struct rte_eth_dev *dev) @@ -84 +85 @@ -@@ -726,7 +731,7 @@ sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, +@@ -709,7 +714,7 @@ sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, @@ -93 +94 @@ -@@ -748,7 +753,7 @@ sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, +@@ -731,7 +736,7 @@ sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, @@ -102 +103 @@ -@@ -789,7 +794,7 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, +@@ -772,7 +777,7 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, @@ -111 +112 @@ -@@ -819,7 +824,7 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, +@@ -802,7 +807,7 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, @@ -120 +121 @@ -@@ -835,9 +840,14 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev, +@@ -818,9 +823,14 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev, @@ -137 +138 @@ -@@ -853,6 +863,8 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev, +@@ -836,6 +846,8 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev, @@ -147 +148 @@ -index ac117f9c48..cdc0f94f19 100644 +index 23313e125f..967fd3a266 100644 @@ -150 +151 @@ -@@ -43,7 +43,7 @@ sfc_port_update_mac_stats(struct sfc_adapter *sa) +@@ -42,7 +42,7 @@ sfc_port_update_mac_stats(struct sfc_adapter *sa) @@ -159 +160 @@ -@@ -103,14 +103,13 @@ sfc_port_reset_sw_stats(struct sfc_adapter *sa) +@@ -102,14 +102,13 @@ sfc_port_reset_sw_stats(struct sfc_adapter *sa) @@ -176 +177 @@ -@@ -416,8 +415,6 @@ sfc_port_attach(struct sfc_adapter *sa) +@@ -415,8 +414,6 @@ sfc_port_attach(struct sfc_adapter *sa)