ha->refcount and ha->global_use are changed in place, under the address list lock, on entries that readers can see. A later patch reads them without that lock. Use WRITE_ONCE() for these in-place writes. Writes to entries that are not yet published, or to private snapshot entries, stay plain. i40e writes ha->refcount directly in netdev_hw_addr_refcnt() without the address list lock. That is an existing driver issue and is left for a separate patch. No functional change. Signed-off-by: Yuyang Huang --- net/core/dev_addr_lists.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c index 849d63e51e2a..93765997c28d 100644 --- a/net/core/dev_addr_lists.c +++ b/net/core/dev_addr_lists.c @@ -148,7 +148,7 @@ static int __hw_addr_add_ex(struct netdev_hw_addr_list *list, if (ha->global_use) return 0; else - ha->global_use = true; + WRITE_ONCE(ha->global_use, true); } if (sync) { if (ha->synced && sync_count) @@ -156,7 +156,7 @@ static int __hw_addr_add_ex(struct netdev_hw_addr_list *list, else ha->synced++; } - ha->refcount++; + WRITE_ONCE(ha->refcount, ha->refcount + 1); return 0; } } @@ -193,12 +193,13 @@ static int __hw_addr_del_entry(struct netdev_hw_addr_list *list, return -ENOENT; if (global) - ha->global_use = false; + WRITE_ONCE(ha->global_use, false); if (sync) ha->synced--; - if (--ha->refcount) + WRITE_ONCE(ha->refcount, ha->refcount - 1); + if (ha->refcount) return 0; rb_erase(&ha->node, &list->tree); @@ -266,7 +267,7 @@ static int __hw_addr_sync_one(struct netdev_hw_addr_list *to_list, if (!err) { ha->sync_cnt++; - ha->refcount++; + WRITE_ONCE(ha->refcount, ha->refcount + 1); } return 0; @@ -390,7 +391,7 @@ int __hw_addr_sync_dev(struct netdev_hw_addr_list *list, return err; ha->sync_cnt++; - ha->refcount++; + WRITE_ONCE(ha->refcount, ha->refcount + 1); } return 0; @@ -434,7 +435,7 @@ int __hw_addr_ref_sync_dev(struct netdev_hw_addr_list *list, if (unsync && unsync(dev, ha->addr, ref_cnt)) continue; - ha->refcount = (ref_cnt << 1) + 1; + WRITE_ONCE(ha->refcount, (ref_cnt << 1) + 1); ha->sync_cnt = ref_cnt; __hw_addr_del_entry(list, ha, false, false); } @@ -450,7 +451,7 @@ int __hw_addr_ref_sync_dev(struct netdev_hw_addr_list *list, if (err) return err; - ha->refcount = ref_cnt << 1; + WRITE_ONCE(ha->refcount, ref_cnt << 1); ha->sync_cnt = ref_cnt; } @@ -487,7 +488,7 @@ void __hw_addr_ref_unsync_dev(struct netdev_hw_addr_list *list, if (unsync && unsync(dev, ha->addr, ha->sync_cnt)) continue; - ha->refcount -= ha->sync_cnt - 1; + WRITE_ONCE(ha->refcount, ha->refcount - (ha->sync_cnt - 1)); ha->sync_cnt = 0; __hw_addr_del_entry(list, ha, false, false); } @@ -663,7 +664,7 @@ void __hw_addr_list_reconcile(struct netdev_hw_addr_list *real_list, } real_ha->sync_cnt += delta; - real_ha->refcount += delta; + WRITE_ONCE(real_ha->refcount, real_ha->refcount + delta); if (!real_ha->refcount) { rb_erase(&real_ha->node, &real_list->tree); list_del_rcu(&real_ha->list); -- 2.56.1.915.g69d5ec7298-goog