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 AAFD1A00C3; Tue, 29 Nov 2022 15:51:02 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4020142B8C; Tue, 29 Nov 2022 15:50:41 +0100 (CET) Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by mails.dpdk.org (Postfix) with ESMTP id C429542C4D; Tue, 29 Nov 2022 15:50:34 +0100 (CET) Received: by mail-qk1-f177.google.com with SMTP id k4so9883522qkj.8; Tue, 29 Nov 2022 06:50:34 -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=z08scHU6YsGW9fJPGihyWAEtBdpF8UbFlvJFRsIy3x0=; b=V8oX6RkZZK27smXvPIMWfcFKg4lJ2+taeslJS067brlmWuJ93PjFYqaGtwM63jKrRz F04qJhxxb0b/IfozBpk4+Pff7BChtQuEto8Af/su09w10QuWbglZbBHeLDnRN7nzQmXi kXKU+AsoeN0XMs3fUW1T7J7HE/bO9rLp0MNRfUeaxSiXEn67wkpMkK6FXXBSnoaAWK2X pXKWop/ylzT6U07sAbv2Ai5vghFO/hQ3UsHrmQgkQ67VO9fL2IDhkik+vKY3eUreB1w6 9mT1nVi0QYTz1P/ch6Gcv01fewNpmZD3ThRjEXcBe9ndVKaifBUiR38AFQGViQ/WNVge gDzw== 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=z08scHU6YsGW9fJPGihyWAEtBdpF8UbFlvJFRsIy3x0=; b=eOXEzg0djAu1V9Fk6zmMXyR3C04bVy3kVEN0cl/Hr2sEPaDD6A76XRnDzPoUtECrwb taM0PSKTEghRZ3dNlOcuA1rk/wU/j3DupmeP/Sm4m2aVTf+po32nB36iHMJZvx/GxrsR yuTl9eJB0Znwo20R3Hhr/mAWc6vWWFUDlWlC2r/O1/QWFGo1L7otf+AyM0d14cLxltev rIH6pFMOaI4WfZz8Ss4vbDUs13wex/kFOS2EJy1tC5TufNJwbK0L0KbiFMtq5BAuj4kI J/NSYaIRHxySVqOwbwYEX8UoFDa86AkVtThPbJUDiAG+KMe/BEx75i8jJZaAnrijCjmM 1m7A== X-Gm-Message-State: ANoB5pl2voZqsTyIxzvTFpMqhxreDKJARXN7dZmxjHq++ANnZoBnwh5G 0JNWOi9w2axmL2nDmFuIwlY= X-Google-Smtp-Source: AA0mqf5WK1GPMD5//aJMLijZUKU5HRCMTPnPVU85Y1rJE31X49wGDshHOEvdrn8/LJ8suiwhwBdRlQ== X-Received: by 2002:a05:620a:1e9:b0:6b8:ec83:2922 with SMTP id x9-20020a05620a01e900b006b8ec832922mr51746860qkn.107.1669733434202; Tue, 29 Nov 2022 06:50:34 -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 y14-20020a05620a44ce00b006fb7c42e73asm11068836qkp.21.2022.11.29.06.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 06:50:33 -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 v3 5/5] failsafe: make sub-device remove flag thread-safe Date: Tue, 29 Nov 2022 09:48:33 -0500 Message-Id: <20221129144832.2750-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: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-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 7bd223af37..86d97970bc 100644 --- a/drivers/net/failsafe/failsafe_ops.c +++ b/drivers/net/failsafe/failsafe_ops.c @@ -838,7 +838,7 @@ fs_link_update(struct rte_eth_dev *dev, 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