Skip to content

Commit

Permalink
netdev: use acquire-release semantics for change_seq in netdev
Browse files Browse the repository at this point in the history
"rxq_enabled" of netdev is writen in the vhost thread and read by pmd
thread once it observes 'change_seq' is updated. This patch is to keep
order on aarch64 or other weak memory model CPU to ensure 'rxq_enabled' is
observed before 'change_seq'.

Reviewed-by: Gavin Hu <Gavin.Hu@arm.com>
Signed-off-by: Yanqin Wei <Yanqin.Wei@arm.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
  • Loading branch information
Yanqin Wei authored and ovsrobot committed Nov 26, 2019
1 parent 953ef91 commit 5cea949
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/netdev-provider.h
Expand Up @@ -63,7 +63,7 @@ struct netdev {
*
* Minimally, the sequence number is required to change whenever
* 'netdev''s flags, features, ethernet address, or carrier changes. */
uint64_t change_seq;
atomic_uint64_t change_seq;

/* A netdev provider might be unable to change some of the device's
* parameter (n_rxq, mtu) when the device is in use. In this case
Expand Down Expand Up @@ -91,12 +91,17 @@ struct netdev {
static inline void
netdev_change_seq_changed(const struct netdev *netdev_)
{
uint64_t change_seq;
struct netdev *netdev = CONST_CAST(struct netdev *, netdev_);
seq_change(connectivity_seq_get());
netdev->change_seq++;
if (!netdev->change_seq) {
netdev->change_seq++;

atomic_read_relaxed(&netdev->change_seq, &change_seq);
change_seq++;
if (OVS_UNLIKELY(!change_seq)) {
change_seq++;
}
atomic_store_explicit(&netdev->change_seq, change_seq,
memory_order_release);
}

static inline void
Expand Down
7 changes: 6 additions & 1 deletion lib/netdev.c
Expand Up @@ -2039,7 +2039,12 @@ restore_all_flags(void *aux OVS_UNUSED)
uint64_t
netdev_get_change_seq(const struct netdev *netdev)
{
return netdev->change_seq;
uint64_t change_seq;

atomic_read_explicit(&CONST_CAST(struct netdev *, netdev)->change_seq,
&change_seq, memory_order_acquire);

return change_seq;
}

#ifndef _WIN32
Expand Down

0 comments on commit 5cea949

Please sign in to comment.