Re: [PATCH net-next v4 2/4] ipv6: take fib6_sernum from a sequence shared by all netns

From
Ralf Lici <ralf@mandelbit.com>
Date
2026-11-20 17:52:52
Also in
lkml
Reply to
Qiliang Yuan, 2026-11-18
Hi Qiliang,

I stumbled upon this series while looking for what caused a conflict
patchwork reported on one of my series [1], which touches the same code.

On Tue, 17 Nov 2026 21:28:31 -0500, Qiliang Yuan wrote:
2^31 bumps. fib6_new_sernum() callers only hold their own table's
tb6_lock, so two tables of one netns can store their values in either
order, and fib6_sernum is no longer monotonic per netns. It is only
compared for equality, so this costs at most an extra invalidation.
Eric raised this on v1 [2], and for the equality checks I agree: values
are not reused, so a stale value cannot match. What the atomic_set
changes is the ordering. It comes after the full barrier of the cmpxchg,
so nothing orders it before the node stamp in fib6_update_sernum: a
reader can sample the new fn_sernum while still reading the old
generation (this one is allowed on arm64). Nothing in the tree compares
the two today, but my series relies on that order, since it brackets the
lookup and cookie sampling with two reads of the generation.

The late store also loses the guarantee that a reader seeing a value
sees the routing changes published before it. With the per-netns
cmpxchg, each update reads from the previous one. Here, CPU0 can draw 2
and stall while CPU1 links a route, draws 3 and publishes it, and then
CPU0 stores 2. LKMM allows a reader that reads 2 to miss CPU1's route
(x86 and arm64 forbid it in practice), and a per-cpu dst of a nexthop
object allocated from that lookup records 2 and passes rt6_is_valid
until the next bump.

Drawing from the shared sequence but publishing with a cmpxchg on the
per-netns counter keeps both, at the cost of a wasted draw on
contention:

static int fib6_new_sernum(struct net *net)
{
	int old = atomic_read(&net->ipv6.fib6_sernum);
	int new;

	do {
		new = fib6_sernum_draw();
	} while (!atomic_try_cmpxchg(&net->ipv6.fib6_sernum, &old, new));

	return new;
}

where fib6_sernum_draw is your current loop on fib6_sernum_seq. I
checked both cases with LKMM litmus tests: they are reachable with
atomic_set and forbidden with the cmpxchg publish.

1/4 has the same pattern for rt_genid, and IPv4 bumps can run
concurrently too, since xfrm policy insertion does not hold RTNL.

[1] https://lore.kernel.org/netdev/cover.1795166508.git.ralf@mandelbit.com/ (local)
[2] https://lore.kernel.org/netdev/CAL4WiioL+wiv3jgqeT1qiZ2mGWQ+HV+mEQP2K0aFMCpjDvwYDg@mail.gmail.com/ (local)

-- 
Ralf Lici
Mandelbit Srl
Thread (7 messages) 7 messages, 2 authors, last reply 23h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help