From: Luc Pelletier <lucp.at.work@gmail.com>
To: grive@u256.net
Cc: dev@dpdk.org, stephen@networkplumber.org,
konstantin.ananyev@huawei.com,
Luc Pelletier <lucp.at.work@gmail.com>,
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 [thread overview]
Message-ID: <20221129144832.2750-6-lucp.at.work@gmail.com> (raw)
In-Reply-To: <20221110163410.12734-1-lucp.at.work@gmail.com>
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 <grive@u256.net>
Cc: stable@dpdk.org
Signed-off-by: Luc Pelletier <lucp.at.work@gmail.com>
---
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
next prev parent reply other threads:[~2022-11-29 14:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-10 16:34 [PATCH] failsafe: fix segfault on hotplug event Luc Pelletier
2022-11-10 17:42 ` [PATCH v2] " Luc Pelletier
2022-11-10 23:33 ` Stephen Hemminger
2022-11-16 17:35 ` [PATCH] " Konstantin Ananyev
2022-11-16 21:51 ` Luc Pelletier
2022-11-16 22:25 ` Stephen Hemminger
2022-11-18 16:31 ` Konstantin Ananyev
2022-11-29 14:48 ` [PATCH v3 1/5] " Luc Pelletier
2023-10-31 17:35 ` Stephen Hemminger
2022-11-29 14:48 ` [PATCH v3 3/5] failsafe: fix double release of port Luc Pelletier
2022-11-29 14:48 ` [PATCH v3 4/5] failsafe: use public APIs in fs_link_update Luc Pelletier
2022-11-29 14:48 ` Luc Pelletier [this message]
2022-11-29 15:25 ` [PATCH v4 1/5] failsafe: fix segfault on hotplug event Luc Pelletier
2022-11-29 15:25 ` [PATCH v4 3/5] failsafe: fix double release of port Luc Pelletier
2022-11-29 15:25 ` [PATCH v4 4/5] failsafe: use public APIs in fs_link_update Luc Pelletier
2022-11-29 15:25 ` [PATCH v4 5/5] failsafe: make sub-device remove flag thread-safe Luc Pelletier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221129144832.2750-6-lucp.at.work@gmail.com \
--to=lucp.at.work@gmail.com \
--cc=dev@dpdk.org \
--cc=grive@u256.net \
--cc=konstantin.ananyev@huawei.com \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).