Skip to content

Commit 40bf00e

Browse files
beshlemankuba-moo
authored andcommitted
net: devmem: use READ_ONCE/WRITE_ONCE on binding->dev
binding->dev is protected on the write-side in mp_dmabuf_devmem_uninstall() against concurrent writes, but due to the concurrent bare reads in net_devmem_get_binding() and validate_xmit_unreadable_skb() it should be wrapped in a READ_ONCE/WRITE_ONCE pair to make sure no compiler optimizations play with the underlying register in unforeseen ways. Doesn't present a critical bug because the known compiler optimizations don't result in bad behavior. There is no tearing on u64, and load omissions/invented loads would only break if additional binding->dev references were inlined together (they aren't right now). This just more strictly follows the linux memory model (i.e., "Lock-Protected Writes With Lockless Reads" in tools/memory-model/Documentation/access-marking.txt). Fixes: bd61848 ("net: devmem: Implement TX path") Signed-off-by: Bobby Eshleman <bobbyeshleman@meta.com> Link: https://patch.msgid.link/20260302-devmem-membar-fix-v2-1-5b33c9cbc28b@meta.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent a4c2b8b commit 40bf00e

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3987,7 +3987,7 @@ static struct sk_buff *validate_xmit_unreadable_skb(struct sk_buff *skb,
39873987
if (shinfo->nr_frags > 0) {
39883988
niov = netmem_to_net_iov(skb_frag_netmem(&shinfo->frags[0]));
39893989
if (net_is_devmem_iov(niov) &&
3990-
net_devmem_iov_binding(niov)->dev != dev)
3990+
READ_ONCE(net_devmem_iov_binding(niov)->dev) != dev)
39913991
goto out_free;
39923992
}
39933993

net/core/devmem.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ struct net_devmem_dmabuf_binding *net_devmem_get_binding(struct sock *sk,
396396
* net_device.
397397
*/
398398
dst_dev = dst_dev_rcu(dst);
399-
if (unlikely(!dst_dev) || unlikely(dst_dev != binding->dev)) {
399+
if (unlikely(!dst_dev) ||
400+
unlikely(dst_dev != READ_ONCE(binding->dev))) {
400401
err = -ENODEV;
401402
goto out_unlock;
402403
}
@@ -513,7 +514,8 @@ static void mp_dmabuf_devmem_uninstall(void *mp_priv,
513514
xa_erase(&binding->bound_rxqs, xa_idx);
514515
if (xa_empty(&binding->bound_rxqs)) {
515516
mutex_lock(&binding->lock);
516-
binding->dev = NULL;
517+
ASSERT_EXCLUSIVE_WRITER(binding->dev);
518+
WRITE_ONCE(binding->dev, NULL);
517519
mutex_unlock(&binding->lock);
518520
}
519521
break;

0 commit comments

Comments
 (0)