* [PATCH net v2] net: devmem: use READ_ONCE/WRITE_ONCE on binding->dev
@ 2026-03-03 0:32 Bobby Eshleman
2026-03-05 2:20 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Bobby Eshleman @ 2026-03-03 0:32 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Mina Almasry, Kaiyuan Zhang, Stanislav Fomichev
Cc: netdev, linux-kernel, Bobby Eshleman
From: Bobby Eshleman <bobbyeshleman@meta.com>
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: bd61848900bf ("net: devmem: Implement TX path")
Signed-off-by: Bobby Eshleman <bobbyeshleman@meta.com>
---
Changes in v2:
- add ASSERT_EXCLUSIVE_WRITER() to mark write-side critical section
- add READ_ONCE() in validate_xmit_unreadable_skb() too
- Link to v1: https://lore.kernel.org/r/20260223-devmem-membar-fix-v1-1-37dcae1e49f8@meta.com
---
net/core/dev.c | 2 +-
net/core/devmem.c | 6 ++++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index c1a9f7fdcffa..9036fcf9f965 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3987,7 +3987,7 @@ static struct sk_buff *validate_xmit_unreadable_skb(struct sk_buff *skb,
if (shinfo->nr_frags > 0) {
niov = netmem_to_net_iov(skb_frag_netmem(&shinfo->frags[0]));
if (net_is_devmem_iov(niov) &&
- net_devmem_iov_binding(niov)->dev != dev)
+ READ_ONCE(net_devmem_iov_binding(niov)->dev) != dev)
goto out_free;
}
diff --git a/net/core/devmem.c b/net/core/devmem.c
index 8c9aad776bf4..69d79aee07ef 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -396,7 +396,8 @@ struct net_devmem_dmabuf_binding *net_devmem_get_binding(struct sock *sk,
* net_device.
*/
dst_dev = dst_dev_rcu(dst);
- if (unlikely(!dst_dev) || unlikely(dst_dev != binding->dev)) {
+ if (unlikely(!dst_dev) ||
+ unlikely(dst_dev != READ_ONCE(binding->dev))) {
err = -ENODEV;
goto out_unlock;
}
@@ -513,7 +514,8 @@ static void mp_dmabuf_devmem_uninstall(void *mp_priv,
xa_erase(&binding->bound_rxqs, xa_idx);
if (xa_empty(&binding->bound_rxqs)) {
mutex_lock(&binding->lock);
- binding->dev = NULL;
+ ASSERT_EXCLUSIVE_WRITER(binding->dev);
+ WRITE_ONCE(binding->dev, NULL);
mutex_unlock(&binding->lock);
}
break;
---
base-commit: 9439a661c2e80485406ce2c90b107ca17858382d
change-id: 20260223-devmem-membar-fix-3a5cd9618f8a
Best regards,
--
Bobby Eshleman <bobbyeshleman@meta.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net v2] net: devmem: use READ_ONCE/WRITE_ONCE on binding->dev
2026-03-03 0:32 [PATCH net v2] net: devmem: use READ_ONCE/WRITE_ONCE on binding->dev Bobby Eshleman
@ 2026-03-05 2:20 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-05 2:20 UTC (permalink / raw)
To: Bobby Eshleman
Cc: davem, edumazet, kuba, pabeni, horms, almasrymina, kaiyuanz, sdf,
netdev, linux-kernel, bobbyeshleman
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 02 Mar 2026 16:32:56 -0800 you wrote:
> From: Bobby Eshleman <bobbyeshleman@meta.com>
>
> 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.
>
> [...]
Here is the summary with links:
- [net,v2] net: devmem: use READ_ONCE/WRITE_ONCE on binding->dev
https://git.kernel.org/netdev/net/c/40bf00ec2ee2
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-05 2:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-03 0:32 [PATCH net v2] net: devmem: use READ_ONCE/WRITE_ONCE on binding->dev Bobby Eshleman
2026-03-05 2:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox