Re: [PATCH net v2] net: fix __this_cpu_add() in preemptible code in dev_xmit_recursion_inc/dec

From: Jakub Kicinski

Date: Sun Apr 12 2026 - 12:34:27 EST


On Fri, 10 Apr 2026 10:06:30 +0800 Jiayuan Chen wrote:
> dev_xmit_recursion_{inc,dec}() use __this_cpu_{inc,dec}() which requires
> the caller to be non-preemptible in order to avoid cpu migration. However,
> some callers like SCTP's UDP encapsulation path invoke iptunnel_xmit()
> from process context without disabling BH or preemption:
>
> sctp_inet_connect -> __sctp_connect -> sctp_do_sm ->
> sctp_outq_flush -> sctp_packet_transmit -> sctp_v4_xmit ->
> udp_tunnel_xmit_skb -> iptunnel_xmit -> dev_xmit_recursion_inc

Eric, weren't there also a bunch of RCU reports because of this path?
Should we perhaps take the RCU read lock here?

> + guard(migrate)();

Sorry but I detest the guard() usage. Please use migrate_disable()

Quoting documentation:

Use of ``guard()`` is discouraged within any function longer than 20
lines, ``scoped_guard()`` is considered more readable. Using normal
lock/unlock is still (weakly) preferred.

See:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#using-device-managed-and-cleanup-h-constructs