Re: [PATCH net-next 2/2] macvlan: no longer rely on RTNL in macvlan_fill_info()
From: Kuniyuki Iwashima <kuniyu@google.com>
Date: 2026-07-01 22:14:26
On Wed, Jul 1, 2026 at 5:12 AM Nikolay Aleksandrov [off-list ref] wrote:
On 01/07/2026 11:22, Eric Dumazet wrote:quoted
Add READ_ONCE()/WRITE_ONCE() annotations on vlan->mode, vlan->flags, vlan->bc_queue_len_req and port->bc_cutoff. Fill IFLA_MACVLAN_MACADDR_DATA nested attribute and compute on the fly the precise number of elements we put in it, to fill an accurate IFLA_MACVLAN_MACADDR_COUNT attribute as some user space applications could depend on its value and the attributes order. Signed-off-by: Eric Dumazet <edumazet@google.com> --- drivers/net/macvlan.c | 71 +++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 23 deletions(-)The snippet that sets macaddr_count gave me pause. :) Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
same here :p Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
[snip]quoted
+ + if (READ_ONCE(vlan->macaddr_count) > 0) { nest = nla_nest_start_noflag(skb, IFLA_MACVLAN_MACADDR_DATA); if (nest == NULL) goto nla_put_failure; for (i = 0; i < MACVLAN_HASH_SIZE; i++) { - if (macvlan_fill_info_macaddr(skb, vlan, i)) + cnt = macvlan_fill_info_macaddr(skb, vlan, i); + if (cnt < 0) goto nla_put_failure; + macaddr_count += cnt; } - nla_nest_end(skb, nest); + if (!macaddr_count) + nla_nest_cancel(skb, nest); + else if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; } - if (nla_put_u32(skb, IFLA_MACVLAN_BC_QUEUE_LEN, vlan->bc_queue_len_req)) + *(u32 *)nla_data(attr) = macaddr_count; +