Skip to content

Commit 1511db7

Browse files
beshlemanSasha Levin
authored andcommitted
net: devmem: use READ_ONCE/WRITE_ONCE on binding->dev
[ Upstream commit 40bf00e ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b86ec45 commit 1511db7

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
@@ -3983,7 +3983,7 @@ static struct sk_buff *validate_xmit_unreadable_skb(struct sk_buff *skb,
39833983
if (shinfo->nr_frags > 0) {
39843984
niov = netmem_to_net_iov(skb_frag_netmem(&shinfo->frags[0]));
39853985
if (net_is_devmem_iov(niov) &&
3986-
net_devmem_iov_binding(niov)->dev != dev)
3986+
READ_ONCE(net_devmem_iov_binding(niov)->dev) != dev)
39873987
goto out_free;
39883988
}
39893989

net/core/devmem.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ struct net_devmem_dmabuf_binding *net_devmem_get_binding(struct sock *sk,
387387
* net_device.
388388
*/
389389
dst_dev = dst_dev_rcu(dst);
390-
if (unlikely(!dst_dev) || unlikely(dst_dev != binding->dev)) {
390+
if (unlikely(!dst_dev) ||
391+
unlikely(dst_dev != READ_ONCE(binding->dev))) {
391392
err = -ENODEV;
392393
goto out_unlock;
393394
}
@@ -504,7 +505,8 @@ static void mp_dmabuf_devmem_uninstall(void *mp_priv,
504505
xa_erase(&binding->bound_rxqs, xa_idx);
505506
if (xa_empty(&binding->bound_rxqs)) {
506507
mutex_lock(&binding->lock);
507-
binding->dev = NULL;
508+
ASSERT_EXCLUSIVE_WRITER(binding->dev);
509+
WRITE_ONCE(binding->dev, NULL);
508510
mutex_unlock(&binding->lock);
509511
}
510512
break;

0 commit comments

Comments
 (0)