Re: [PATCH net v2] tcp: Fix fastreuse cache initialization on first bind

From: Jason Xing

Date: Tue Oct 27 2026 - 02:14:42 EST


On Mon, Oct 26, 2026 at 5:55 PM Zhewei Yuan <yzwlhm@xxxxxxxxx> wrote:
>
> inet_csk_update_fastreuse() initializes the reuse caches only when
> tb->bhash2 is empty, but both inet_csk_get_port() and
> __inet_inherit_port() link tb2 before calling it, so the first-bind
> branch is never taken.
>
> As a result, SO_REUSEADDR binds never get fastreuse=1 and keep
> scanning existing owners, and SO_REUSEPORT starts in STRICT instead
> of ANY.
>
> Initialize the caches when tb2 is the only entry in tb->bhash2 and has
> no owners. Timewait sockets are also linked on tb2->owners, so this is
> equivalent to the old hlist_empty(&tb->owners) test.
>
> Found by manual code inspection and confirmed with GDB. Binding 16000

I thought it was discovered by an LLM.

> SO_REUSEADDR sockets to one address/port in a KVM guest takes 4.18 s
> before and 19.4 ms after this patch. Existing bind/reuse selftests
> pass. Analysis and testing were assisted by an AI tool (Codex).
>
> Fixes: 8002d44fe84d ("tcp: Check hlist_empty(&tb->bhash2) instead of hlist_empty(&tb->owners).")
> Reviewed-by: Eric Dumazet <edumazet@xxxxxxxxxx>
> Signed-off-by: Zhewei Yuan <yzwlhm@xxxxxxxxx>

Reviewed-by: Jason Xing <kerneljasonxing@xxxxxxxxx>

Thanks!