Skip to content

Commit

Permalink
rtnetlink: Make per-netns RTNL dereference helpers to macro.
Browse files Browse the repository at this point in the history
When CONFIG_DEBUG_NET_SMALL_RTNL is off, rtnl_net_dereference() is the
static inline wrapper of rtnl_dereference() returning a plain (void *)
pointer to make sure net is always evaluated as requested in [0].

But, it makes sparse complain [1] when the pointer has __rcu annotation:

  net/ipv4/devinet.c:674:47: sparse: warning: incorrect type in argument 2 (different address spaces)
  net/ipv4/devinet.c:674:47: sparse:    expected void *p
  net/ipv4/devinet.c:674:47: sparse:    got struct in_ifaddr [noderef] __rcu *

Also, if we evaluate net as (void *) in a macro, then the compiler
in turn fails to build due to -Werror=unused-value.

  #define rtnl_net_dereference(net, p)                  \
        ({                                              \
                (void *)net;                            \
                rtnl_dereference(p);                    \
        })

  net/ipv4/devinet.c: In function ‘inet_rtm_deladdr’:
  ./include/linux/rtnetlink.h:154:17: error: statement with no effect [-Werror=unused-value]
    154 |                 (void *)net;                            \
  net/ipv4/devinet.c:674:21: note: in expansion of macro ‘rtnl_net_dereference’
    674 |              (ifa = rtnl_net_dereference(net, *ifap)) != NULL;
        |                     ^~~~~~~~~~~~~~~~~~~~

Let's go back to the original simplest macro.

Note that checkpatch complains about this approach, but it's one-shot and
less noisy than the other two.

  WARNING: Argument 'net' is not used in function-like macro
  torvalds#76: FILE: include/linux/rtnetlink.h:142:
  +#define rtnl_net_dereference(net, p)			\
  +	rtnl_dereference(p)

Fixes: 844e5e7 ("rtnetlink: Add assertion helpers for per-netns RTNL.")
Link: https://lore.kernel.org/netdev/20241004132145.7fd208e9@kernel.org/ [0]
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202410200325.SaEJmyZS-lkp@intel.com/ [1]
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: NipaLocal <nipa@local>
  • Loading branch information
q2ven authored and NipaLocal committed Oct 27, 2024
1 parent 55c3555 commit 83bb324
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions include/linux/rtnetlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,12 @@ static inline void ASSERT_RTNL_NET(struct net *net)
ASSERT_RTNL();
}

static inline void *rcu_dereference_rtnl_net(struct net *net, void *p)
{
return rcu_dereference_rtnl(p);
}

static inline void *rtnl_net_dereference(struct net *net, void *p)
{
return rtnl_dereference(p);
}

static inline void *rcu_replace_pointer_rtnl_net(struct net *net,
void *rp, void *p)
{
return rcu_replace_pointer_rtnl(rp, p);
}
#define rcu_dereference_rtnl_net(net, p) \
rcu_dereference_rtnl(p)
#define rtnl_net_dereference(net, p) \
rtnl_dereference(p)
#define rcu_replace_pointer_rtnl_net(net, rp, p) \
rcu_replace_pointer_rtnl(rp, p)
#endif

static inline struct netdev_queue *dev_ingress_queue(struct net_device *dev)
Expand Down

0 comments on commit 83bb324

Please sign in to comment.