Netdev List
 help / color / mirror / Atom feed
From: Ralf Lici <ralf@mandelbit.com>
To: Qiliang Yuan <qiliang.yuan@linux.dev>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>, David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>,
	Nikolay Aleksandrov <razor@blackwall.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v5 1/4] ipv4: draw rt_genid from a sequence shared by all netns
Date: Sun, 22 Nov 2026 10:02:35 +0100	[thread overview]
Message-ID: <20261122090236.42786-1-ralf@mandelbit.com> (raw)
In-Reply-To: <20261121-bug-net-netns-move-rcu-barrier-v5-1-100a3b5d9090@linux.dev>

On Sat, 21 Nov 2026 18:21:19 -0500, Qiliang Yuan <qiliang.yuan@linux.dev> wrote:
> An IPv4 route records the rt_genid of the netns it was created in, and
> rt_is_expired() compares it with the rt_genid of the netns its device
> belongs to when the route is checked. Every netns starts its rt_genid
> at 0 and increments it on each cache flush, so different netns often
> hold the same value.
>
> When a device moves to another netns, routes cached through it remain
> usable until dst_dev_put() points them to blackhole_netdev. For a route
> using a nexthop object this happens in nexthop_free_rcu(), which
> free_fib_info_rcu() queues from inside an RCU callback, so the
> rcu_barrier() in __dev_change_net_namespace() does not wait for it. If
> the rt_genid of the new netns matches the cached one in that window,
> ipv4_dst_check() accepts the route and a socket in the old netns keeps
> sending through a device that now belongs to another netns.
>
> Take every rt_genid bump from one sequence shared by all netns, which
> never hands out 0, the value every netns starts with. Inserting a route
> bumps rt_genid, so the routes a netns caches carry values drawn from the
> sequence, which no other netns holds until it wraps after 2^32 bumps. A
> moved device sends again only once it is up in its new netns, and
> NETDEV_UP flushes the route cache there, so that netns no longer holds 0
> either. Publish each value with a cmpxchg on the rt_genid of the netns,
> drawing again if another bump changed it first, so that a bump stalled
> between drawing and publishing cannot overwrite a newer value and
> rt_genid stays monotonic per netns.
>
> A connected UDP socket in netns A caches a route through a nexthop
> object on a veth. The veth is moved to netns B and brought up with one
> RTM_NEWLINK, then the socket sends 200000 datagrams. B's rt_genid is
> bumped 0 to 20 times before the move, 63 trials:
>
>                                      before   after   change
>   trials sending after move (count)       2       0    -100%
>   datagrams sent after move (count)    1045       0    -100%
>
> Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>

Reviewed-by: Ralf Lici <ralf@mandelbit.com>

-- 
Ralf Lici
Mandelbit Srl

  reply	other threads:[~2026-11-22  9:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 23:21 [PATCH net-next v5 0/4] net: make moving a device to another netns cheaper Qiliang Yuan
2026-11-21 23:21 ` [PATCH net-next v5 1/4] ipv4: draw rt_genid from a sequence shared by all netns Qiliang Yuan
2026-11-22  9:02   ` Ralf Lici [this message]
2026-11-21 23:21 ` [PATCH net-next v5 2/4] ipv6: take fib6_sernum " Qiliang Yuan
2026-11-22  9:03   ` Ralf Lici
2026-11-21 23:21 ` [PATCH net-next v5 3/4] nexthop: release cached routes when a nexthop leaves a group Qiliang Yuan
2026-11-21 23:21 ` [PATCH net-next v5 4/4] net: remove rcu_barrier() from __dev_change_net_namespace() Qiliang Yuan

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=20261122090236.42786-1-ralf@mandelbit.com \
    --to=ralf@mandelbit.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=qiliang.yuan@linux.dev \
    --cc=razor@blackwall.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox