From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: David Ahern <dsahern@kernel.org>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH net-next 03/13] ipv6: annotate data-races around cnf.mtu6
Date: Mon, 26 Feb 2024 15:50:45 +0000 [thread overview]
Message-ID: <20240226155055.1141336-4-edumazet@google.com> (raw)
In-Reply-To: <20240226155055.1141336-1-edumazet@google.com>
idev->cnf.mtu6 might be read locklessly, add appropriate READ_ONCE()
and WRITE_ONCE() annotations.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
include/net/ip6_route.h | 2 +-
net/ipv6/addrconf.c | 4 ++--
net/ipv6/ndisc.c | 4 ++--
net/ipv6/route.c | 6 +++---
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
index 52a51c69aa9de2fe1e6d351997f5b3d94862521a..a30c6aa9e5cf3e442cd29e2d169ba0b0d46a1f46 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -332,7 +332,7 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst
rcu_read_lock();
idev = __in6_dev_get(dst->dev);
if (idev)
- mtu = idev->cnf.mtu6;
+ mtu = READ_ONCE(idev->cnf.mtu6);
rcu_read_unlock();
out:
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 0d7746b113cc65303b5c2ec223b3331c3598ded6..f1a346dbaceade70fb55fa98b33c47e6824298d3 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -3671,7 +3671,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
if (idev) {
rt6_mtu_change(dev, dev->mtu);
- idev->cnf.mtu6 = dev->mtu;
+ WRITE_ONCE(idev->cnf.mtu6, dev->mtu);
break;
}
@@ -3763,7 +3763,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
if (idev->cnf.mtu6 != dev->mtu &&
dev->mtu >= IPV6_MIN_MTU) {
rt6_mtu_change(dev, dev->mtu);
- idev->cnf.mtu6 = dev->mtu;
+ WRITE_ONCE(idev->cnf.mtu6, dev->mtu);
}
WRITE_ONCE(idev->tstamp, jiffies);
inet6_ifinfo_notify(RTM_NEWLINK, idev);
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 8523f0595b01899a9f6cf82809c1b4bcfc233202..e96d79cd34d27ca304c5f71b6db41b99d2dd8856 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -1578,8 +1578,8 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb)
if (mtu < IPV6_MIN_MTU || mtu > skb->dev->mtu) {
ND_PRINTK(2, warn, "RA: invalid mtu: %d\n", mtu);
- } else if (in6_dev->cnf.mtu6 != mtu) {
- in6_dev->cnf.mtu6 = mtu;
+ } else if (READ_ONCE(in6_dev->cnf.mtu6) != mtu) {
+ WRITE_ONCE(in6_dev->cnf.mtu6, mtu);
fib6_metric_set(rt, RTAX_MTU, mtu);
rt6_mtu_change(skb->dev, mtu);
}
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 707d65bc9c0e5e9b2900063f0ac86c3c5e299088..66c685b0b6199fee3bc39768eab5a6fb831bd2f5 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1596,7 +1596,7 @@ static unsigned int fib6_mtu(const struct fib6_result *res)
rcu_read_lock();
idev = __in6_dev_get(dev);
- mtu = idev->cnf.mtu6;
+ mtu = READ_ONCE(idev->cnf.mtu6);
rcu_read_unlock();
}
@@ -3249,8 +3249,8 @@ u32 ip6_mtu_from_fib6(const struct fib6_result *res,
mtu = IPV6_MIN_MTU;
idev = __in6_dev_get(dev);
- if (idev && idev->cnf.mtu6 > mtu)
- mtu = idev->cnf.mtu6;
+ if (idev)
+ mtu = max_t(u32, mtu, READ_ONCE(idev->cnf.mtu6));
}
mtu = min_t(unsigned int, mtu, IP6_MAX_MTU);
--
2.44.0.rc1.240.g4c46232300-goog
next prev parent reply other threads:[~2024-02-26 15:51 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-26 15:50 [PATCH net-next 00/13] ipv6: lockless accesses to devconf Eric Dumazet
2024-02-26 15:50 ` [PATCH net-next 01/13] ipv6: add ipv6_devconf_read_txrx cacheline_group Eric Dumazet
2024-02-26 15:50 ` [PATCH net-next 02/13] ipv6: annotate data-races around cnf.disable_ipv6 Eric Dumazet
2024-02-26 16:09 ` Jiri Pirko
2024-02-26 16:14 ` Eric Dumazet
2024-02-26 16:18 ` Jiri Pirko
2024-02-26 16:24 ` Eric Dumazet
2024-02-26 16:46 ` Jiri Pirko
2024-02-26 15:50 ` Eric Dumazet [this message]
2024-02-26 15:50 ` [PATCH net-next 04/13] ipv6: annotate data-races around cnf.hop_limit Eric Dumazet
2024-02-26 15:50 ` [PATCH net-next 05/13] ipv6: annotate data-races around cnf.forwarding Eric Dumazet
2024-02-26 15:50 ` [PATCH net-next 06/13] ipv6: annotate data-races in ndisc_router_discovery() Eric Dumazet
2024-02-26 15:50 ` [PATCH net-next 07/13] ipv6: annotate data-races around idev->cnf.ignore_routes_with_linkdown Eric Dumazet
2024-02-26 15:50 ` [PATCH net-next 08/13] ipv6: annotate data-races in rt6_probe() Eric Dumazet
2024-02-26 15:50 ` [PATCH net-next 09/13] ipv6: annotate data-races around devconf->proxy_ndp Eric Dumazet
2024-02-26 15:50 ` [PATCH net-next 10/13] ipv6: annotate data-races around devconf->disable_policy Eric Dumazet
2024-02-26 15:50 ` [PATCH net-next 11/13] ipv6/addrconf: annotate data-races around devconf fields (I) Eric Dumazet
2024-02-26 15:50 ` [PATCH net-next 12/13] ipv6/addrconf: annotate data-races around devconf fields (II) Eric Dumazet
2024-02-26 15:50 ` [PATCH net-next 13/13] ipv6: use xa_array iterator to implement inet6_netconf_dump_devconf() Eric Dumazet
2024-02-26 16:55 ` Jiri Pirko
2024-02-27 11:49 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240226155055.1141336-4-edumazet@google.com \
--to=edumazet@google.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=eric.dumazet@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.