Skip to content

Commit f7105c4

Browse files
CKI Backport BotHangbin Liu
authored andcommitted
ipv6: anycast: Don't use rtnl_dereference().
JIRA: https://issues.redhat.com/browse/RHEL-115325 commit 7b6b53a Author: Kuniyuki Iwashima <kuniyu@google.com> Date: Wed Jul 2 16:01:28 2025 -0700 ipv6: anycast: Don't use rtnl_dereference(). inet6_dev->ac_list is protected by inet6_dev->lock, so rtnl_dereference() is a bit rough annotation. As done in mcast.c, we can use ac_dereference() that checks if inet6_dev->lock is held. Let's replace rtnl_dereference() with a new helper ac_dereference(). Note that now addrconf_join_solict() / addrconf_leave_solict() in __ipv6_dev_ac_inc() / __ipv6_dev_ac_dec() does not need RTNL, so we can remove ASSERT_RTNL() there. Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20250702230210.3115355-12-kuni1840@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
1 parent 0bed115 commit f7105c4

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

net/ipv6/addrconf.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,6 @@ void addrconf_leave_solict(struct inet6_dev *idev, const struct in6_addr *addr)
22512251
__ipv6_dev_mc_dec(idev, &maddr);
22522252
}
22532253

2254-
/* caller must hold RTNL */
22552254
static void addrconf_join_anycast(struct inet6_ifaddr *ifp)
22562255
{
22572256
struct in6_addr addr;
@@ -2264,7 +2263,6 @@ static void addrconf_join_anycast(struct inet6_ifaddr *ifp)
22642263
__ipv6_dev_ac_inc(ifp->idev, &addr);
22652264
}
22662265

2267-
/* caller must hold RTNL */
22682266
static void addrconf_leave_anycast(struct inet6_ifaddr *ifp)
22692267
{
22702268
struct in6_addr addr;

net/ipv6/anycast.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
static struct hlist_head inet6_acaddr_lst[IN6_ADDR_HSIZE];
4848
static DEFINE_SPINLOCK(acaddr_hash_lock);
4949

50+
#define ac_dereference(a, idev) \
51+
rcu_dereference_protected(a, lockdep_is_held(&(idev)->lock))
52+
5053
static int ipv6_dev_ac_dec(struct net_device *dev, const struct in6_addr *addr);
5154

5255
static u32 inet6_acaddr_hash(const struct net *net,
@@ -319,16 +322,14 @@ int __ipv6_dev_ac_inc(struct inet6_dev *idev, const struct in6_addr *addr)
319322
struct net *net;
320323
int err;
321324

322-
ASSERT_RTNL();
323-
324325
write_lock_bh(&idev->lock);
325326
if (idev->dead) {
326327
err = -ENODEV;
327328
goto out;
328329
}
329330

330-
for (aca = rtnl_dereference(idev->ac_list); aca;
331-
aca = rtnl_dereference(aca->aca_next)) {
331+
for (aca = ac_dereference(idev->ac_list, idev); aca;
332+
aca = ac_dereference(aca->aca_next, idev)) {
332333
if (ipv6_addr_equal(&aca->aca_addr, addr)) {
333334
aca->aca_users++;
334335
err = 0;
@@ -380,12 +381,10 @@ int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr)
380381
{
381382
struct ifacaddr6 *aca, *prev_aca;
382383

383-
ASSERT_RTNL();
384-
385384
write_lock_bh(&idev->lock);
386385
prev_aca = NULL;
387-
for (aca = rtnl_dereference(idev->ac_list); aca;
388-
aca = rtnl_dereference(aca->aca_next)) {
386+
for (aca = ac_dereference(idev->ac_list, idev); aca;
387+
aca = ac_dereference(aca->aca_next, idev)) {
389388
if (ipv6_addr_equal(&aca->aca_addr, addr))
390389
break;
391390
prev_aca = aca;
@@ -429,7 +428,7 @@ void ipv6_ac_destroy_dev(struct inet6_dev *idev)
429428
struct ifacaddr6 *aca;
430429

431430
write_lock_bh(&idev->lock);
432-
while ((aca = rtnl_dereference(idev->ac_list)) != NULL) {
431+
while ((aca = ac_dereference(idev->ac_list, idev)) != NULL) {
433432
rcu_assign_pointer(idev->ac_list, aca->aca_next);
434433
write_unlock_bh(&idev->lock);
435434

0 commit comments

Comments
 (0)