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 5EBA6A00C3 for ; Tue, 29 Nov 2022 16:25:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DB18D42C4D; Tue, 29 Nov 2022 16:25:35 +0100 (CET) Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) by mails.dpdk.org (Postfix) with ESMTP id B231942D14; Tue, 29 Nov 2022 16:25:32 +0100 (CET) Received: by mail-qk1-f175.google.com with SMTP id k4so9979802qkj.8; Tue, 29 Nov 2022 07:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k2uHIqG3g7gUq17yk5V6mxc9Xr6jjgACuZRgg/Tx7vY=; b=k/6qoZ+vDiC3U0AWHBXLwX6z8lYP1B8swDdikLXJXMkK1JCrcSmfDpbZGt7RwisJxq yOQIX7gZOixYchTgI3cR4STyiwcCGd7KwpxPFpXGRMVMTpqZycFU2xYWpMRHDSj3Tsjb 4nV/BRB8QBpJWLOwP6GWB90ucONMV74H3VuKBKsyT5TEL8usQ7hb5Jadluos5KjN+2Rc L6btua8gHVrBQjwcYFbx+kyDh/0seZXAYH81CcGCR3Y+KWxcA+nLeYSEwPc5DT7LsvOB k1Ar9oTD3CMqOnlYLMJPZsfG5X5DvSA205cWOtK43PvXTZ4eTW/pvWVOb4lWDRdkG4Qk jn2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k2uHIqG3g7gUq17yk5V6mxc9Xr6jjgACuZRgg/Tx7vY=; b=kFvrxHgwSsfpZ0g81nM4ARbrFVTvd5ChK6WuaJ1xteunpFL8p3RP0Fn4pUAUHxxzi2 ixhEEYrt8Vek2bNQBV6yL4v3MYuROJ3bMxGb6UNgZfeKVuEIgVI99CXZXuE0ONuSD5Xx JLepCzqnT9PEp1qGy4locroWgeRxsdW7UBSUH93wN0AWq6/A/RSQLIRTwUNRuhm04W3q 9lUuUvEcVCu/+Khydnl+yGoptXGDK8wMzoCMAbf/o35VYmxgldpr8yFX1Bm5q395fMxC QyUKzHn2Mv5kwEHEjFTNWTu9TMLJUwbCQ+0U34R/TnCdymvv/tndHxh4sCj7qnA5Uk0m q6XA== X-Gm-Message-State: ANoB5plWzj7tDDkWekAljvk0hrkww3R6J5OqwPYv621Dbzcp82MiFQ6p SgpFxuwtbm5wcsjRCKTrB/Q= X-Google-Smtp-Source: AA0mqf5nosOIMlRdx50pJrVLgcO2TyrkDBYG0xtWnSpAdBL1xKst/RrWAbX1UaauO91IKGmfuDUZVQ== X-Received: by 2002:a37:404b:0:b0:6fb:f7a0:9e54 with SMTP id n72-20020a37404b000000b006fbf7a09e54mr33459536qka.125.1669735532123; Tue, 29 Nov 2022 07:25:32 -0800 (PST) Received: from ubuntu.home (bras-base-hullpq2034w-grc-26-74-12-221-152.dsl.bell.ca. [74.12.221.152]) by smtp.gmail.com with ESMTPSA id r2-20020ae9d602000000b006fb11eee465sm10663412qkk.64.2022.11.29.07.25.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 07:25:31 -0800 (PST) From: Luc Pelletier To: grive@u256.net Cc: dev@dpdk.org, stephen@networkplumber.org, konstantin.ananyev@huawei.com, Luc Pelletier , stable@dpdk.org Subject: [PATCH v4 5/5] failsafe: make sub-device remove flag thread-safe Date: Tue, 29 Nov 2022 10:25:17 -0500 Message-Id: <20221129152516.4513-6-lucp.at.work@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221110163410.12734-1-lucp.at.work@gmail.com> References: <20221110163410.12734-1-lucp.at.work@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 For each sub-device, there's a remove flag that's used to indicate if the sub-device has been removed or not. This flag is currently a volatile bit field. Even if it's marked as volatile, a bit field is not thread-safe according to the C standard. The remove flag is now an unsigned int rather than a bit field. We also now use the atomic built-ins to read/write the value of the remove flag to ensure thread-safety. Fixes: 598fb8aec6f6 ("net/failsafe: support device removal") Cc: Gaetan Rivet Cc: stable@dpdk.org Signed-off-by: Luc Pelletier --- drivers/net/failsafe/failsafe_ether.c | 8 ++++---- drivers/net/failsafe/failsafe_ops.c | 2 +- drivers/net/failsafe/failsafe_private.h | 4 ++-- drivers/net/failsafe/failsafe_rxtx.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/failsafe/failsafe_ether.c b/drivers/net/failsafe/failsafe_ether.c index 3bfc446638..9014777e52 100644 --- a/drivers/net/failsafe/failsafe_ether.c +++ b/drivers/net/failsafe/failsafe_ether.c @@ -311,7 +311,7 @@ fs_dev_remove(struct sub_device *sdev) /* the end */ break; } - sdev->remove = 0; + __atomic_store_n(&sdev->remove, 0, __ATOMIC_RELEASE); failsafe_hotplug_alarm_install(fs_dev(sdev)); } @@ -388,7 +388,7 @@ failsafe_dev_remove(struct rte_eth_dev *dev) uint8_t i; FOREACH_SUBDEV(sdev, i, dev) { - if (!sdev->remove) + if (!__atomic_load_n(&sdev->remove, __ATOMIC_ACQUIRE)) continue; /* Active devices must have finished their burst and @@ -556,7 +556,7 @@ failsafe_eth_dev_state_sync(struct rte_eth_dev *dev) err_remove: FOREACH_SUBDEV(sdev, i, dev) if (sdev->state != PRIV(dev)->state) - sdev->remove = 1; + __atomic_store_n(&sdev->remove, 1, __ATOMIC_RELEASE); return ret; } @@ -597,7 +597,7 @@ failsafe_eth_rmv_event_callback(uint16_t port_id __rte_unused, * Async removal, the sub-PMD will try to unregister * the callback at the source of the current thread context. */ - sdev->remove = 1; + __atomic_store_n(&sdev->remove, 1, __ATOMIC_RELEASE); fs_unlock(fs_dev(sdev), 0); return 0; } diff --git a/drivers/net/failsafe/failsafe_ops.c b/drivers/net/failsafe/failsafe_ops.c index b66dfa269b..e65c8a261a 100644 --- a/drivers/net/failsafe/failsafe_ops.c +++ b/drivers/net/failsafe/failsafe_ops.c @@ -837,7 +837,7 @@ fs_link_update(struct rte_eth_dev *dev, if (likely(sdev_link_ret == 0)) { if (TX_SUBDEV(dev) == sdev) ret = rte_eth_linkstatus_set(dev, &link_info); - } else if (sdev->remove == 0 && + } else if (__atomic_load_n(&sdev->remove, __ATOMIC_ACQUIRE) == 0 && rte_eth_dev_is_removed(PORT_ID(sdev)) == 0) { ERROR("Link get failed for sub_device %d with error %d", i, sdev_link_ret); diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h index 3865f2fc34..0577a62ab2 100644 --- a/drivers/net/failsafe/failsafe_private.h +++ b/drivers/net/failsafe/failsafe_private.h @@ -131,7 +131,7 @@ struct sub_device { /* sub device port id*/ uint16_t sdev_port_id; /* shared between processes */ /* flag calling for recollection */ - volatile unsigned int remove:1; + unsigned int remove; /* flow isolation state */ int flow_isolated:1; /* RMV callback registration state */ @@ -490,7 +490,7 @@ static inline int fs_err(struct sub_device *sdev, int err) { /* A device removal shouldn't be reported as an error. */ - if (sdev->remove == 1 || err == -EIO) + if (__atomic_load_n(&sdev->remove, __ATOMIC_ACQUIRE) == 1 || err == -EIO) return rte_errno = 0; return err; } diff --git a/drivers/net/failsafe/failsafe_rxtx.c b/drivers/net/failsafe/failsafe_rxtx.c index 6d8ab0a6e7..c5caab4204 100644 --- a/drivers/net/failsafe/failsafe_rxtx.c +++ b/drivers/net/failsafe/failsafe_rxtx.c @@ -16,7 +16,7 @@ fs_rx_unsafe(struct sub_device *sdev) return (ETH(sdev) == NULL) || (ETH(sdev)->rx_pkt_burst == NULL) || (sdev->state != DEV_STARTED) || - (sdev->remove != 0); + (__atomic_load_n(&sdev->remove, __ATOMIC_ACQUIRE) != 0); } static inline int -- 2.38.1