* [PATCH net] net: fix __this_cpu_add() in preemptible code in dev_xmit_recursion_inc/dec
@ 2026-04-09 3:53 Jiayuan Chen
2026-04-09 7:18 ` Eric Dumazet
0 siblings, 1 reply; 4+ messages in thread
From: Jiayuan Chen @ 2026-04-09 3:53 UTC (permalink / raw)
To: netdev
Cc: Jiayuan Chen, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Andrew Lunn, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Weiming Shi, linux-kernel,
linux-rt-devel
dev_xmit_recursion_inc/dec() use __this_cpu_inc/dec() which requires
migration to be disabled. 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
This triggers the following warning on PREEMPT(full) kernels:
BUG: using __this_cpu_add() in preemptible [00000000]
caller is dev_xmit_recursion_inc include/linux/netdevice.h:3595 [inline]
caller is iptunnel_xmit+0x1cd/0xb80 net/ipv4/ip_tunnel_core.c:72
Tainted: [L]=SOFTLOCKUP
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
check_preemption_disabled+0xd8/0xe0 lib/smp_processor_id.c:47
dev_xmit_recursion_inc include/linux/netdevice.h:3595 [inline]
iptunnel_xmit+0x1cd/0xb80 net/ipv4/ip_tunnel_core.c:72
sctp_v4_xmit+0x75f/0x1060 net/sctp/protocol.c:1073
sctp_packet_transmit+0x22ec/0x3060 net/sctp/output.c:653
sctp_packet_singleton+0x19e/0x370 net/sctp/outqueue.c:783
sctp_outq_flush_ctrl net/sctp/outqueue.c:914 [inline]
sctp_outq_flush+0x315/0x3350 net/sctp/outqueue.c:1212
sctp_cmd_interpreter net/sctp/sm_sideeffect.c:1824 [inline]
sctp_side_effects net/sctp/sm_sideeffect.c:1204 [inline]
sctp_do_sm+0xce1/0x5be0 net/sctp/sm_sideeffect.c:1175
sctp_primitive_ASSOCIATE+0x9c/0xd0 net/sctp/primitive.c:73
__sctp_connect+0x9fc/0xc70 net/sctp/socket.c:1235
sctp_connect net/sctp/socket.c:4818 [inline]
sctp_inet_connect+0x15f/0x220 net/sctp/socket.c:4833
__sys_connect_file+0x141/0x1a0 net/socket.c:2089
__sys_connect+0x141/0x170 net/socket.c:2108
__do_sys_connect net/socket.c:2114 [inline]
__se_sys_connect net/socket.c:2111 [inline]
__x64_sys_connect+0x72/0xb0 net/socket.c:2111
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x106/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Fix this by adding migrate_disable/enable() around the __this_cpu
operations in dev_xmit_recursion_inc/dec() to ensure the per-cpu
variable is accessed on the same CPU throughout the inc/dec pair.
Fixes: 6f1a9140ecda ("net: add xmit recursion limit to tunnel xmit functions")
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
include/linux/netdevice.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 7ca01eb3f7d2..6b1cd5380d70 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3591,14 +3591,19 @@ static inline bool dev_xmit_recursion(void)
XMIT_RECURSION_LIMIT);
}
+/* Non PREEMPT_RT version: inc and dec must run on the same CPU,
+ * migrate_disable is sufficient.
+ */
static inline void dev_xmit_recursion_inc(void)
{
+ migrate_disable();
__this_cpu_inc(softnet_data.xmit.recursion);
}
static inline void dev_xmit_recursion_dec(void)
{
__this_cpu_dec(softnet_data.xmit.recursion);
+ migrate_enable();
}
#else
static inline int dev_recursion_level(void)
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net] net: fix __this_cpu_add() in preemptible code in dev_xmit_recursion_inc/dec
2026-04-09 3:53 [PATCH net] net: fix __this_cpu_add() in preemptible code in dev_xmit_recursion_inc/dec Jiayuan Chen
@ 2026-04-09 7:18 ` Eric Dumazet
2026-04-09 7:50 ` Jiayuan Chen
0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2026-04-09 7:18 UTC (permalink / raw)
To: Jiayuan Chen
Cc: netdev, David S. Miller, Jakub Kicinski, Paolo Abeni,
Simon Horman, Andrew Lunn, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Weiming Shi, linux-kernel,
linux-rt-devel
On Wed, Apr 8, 2026 at 8:54 PM Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
>
> dev_xmit_recursion_inc/dec() use __this_cpu_inc/dec() which requires
> migration to be disabled. 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
>
> This triggers the following warning on PREEMPT(full) kernels:
>
>
> Fix this by adding migrate_disable/enable() around the __this_cpu
> operations in dev_xmit_recursion_inc/dec() to ensure the per-cpu
> variable is accessed on the same CPU throughout the inc/dec pair.
>
> Fixes: 6f1a9140ecda ("net: add xmit recursion limit to tunnel xmit functions")
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> ---
> include/linux/netdevice.h | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> index 7ca01eb3f7d2..6b1cd5380d70 100644
> --- a/include/linux/netdevice.h
> +++ b/include/linux/netdevice.h
> @@ -3591,14 +3591,19 @@ static inline bool dev_xmit_recursion(void)
> XMIT_RECURSION_LIMIT);
> }
>
> +/* Non PREEMPT_RT version: inc and dec must run on the same CPU,
> + * migrate_disable is sufficient.
> + */
> static inline void dev_xmit_recursion_inc(void)
> {
> + migrate_disable();
> __this_cpu_inc(softnet_data.xmit.recursion);
> }
>
> static inline void dev_xmit_recursion_dec(void)
> {
> __this_cpu_dec(softnet_data.xmit.recursion);
> + migrate_enable();
> }
> #else
> static inline int dev_recursion_level(void)
> --
> 2.43.0
This seems wrong.
The migrate_disable() should happen before dev_recursion_level().
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] net: fix __this_cpu_add() in preemptible code in dev_xmit_recursion_inc/dec
2026-04-09 7:18 ` Eric Dumazet
@ 2026-04-09 7:50 ` Jiayuan Chen
2026-04-09 8:10 ` Eric Dumazet
0 siblings, 1 reply; 4+ messages in thread
From: Jiayuan Chen @ 2026-04-09 7:50 UTC (permalink / raw)
To: Eric Dumazet
Cc: netdev, David S. Miller, Jakub Kicinski, Paolo Abeni,
Simon Horman, Andrew Lunn, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Weiming Shi, linux-kernel,
linux-rt-devel
On 4/9/26 3:18 PM, Eric Dumazet wrote:
> On Wed, Apr 8, 2026 at 8:54 PM Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
>> dev_xmit_recursion_inc/dec() use __this_cpu_inc/dec() which requires
>> migration to be disabled. 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
>>
>> This triggers the following warning on PREEMPT(full) kernels:
>>
>>
>> Fix this by adding migrate_disable/enable() around the __this_cpu
>> operations in dev_xmit_recursion_inc/dec() to ensure the per-cpu
>> variable is accessed on the same CPU throughout the inc/dec pair.
>>
>> Fixes: 6f1a9140ecda ("net: add xmit recursion limit to tunnel xmit functions")
>> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
>> ---
>> include/linux/netdevice.h | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>> index 7ca01eb3f7d2..6b1cd5380d70 100644
>> --- a/include/linux/netdevice.h
>> +++ b/include/linux/netdevice.h
>> @@ -3591,14 +3591,19 @@ static inline bool dev_xmit_recursion(void)
>> XMIT_RECURSION_LIMIT);
>> }
>>
>> +/* Non PREEMPT_RT version: inc and dec must run on the same CPU,
>> + * migrate_disable is sufficient.
>> + */
>> static inline void dev_xmit_recursion_inc(void)
>> {
>> + migrate_disable();
>> __this_cpu_inc(softnet_data.xmit.recursion);
>> }
>>
>> static inline void dev_xmit_recursion_dec(void)
>> {
>> __this_cpu_dec(softnet_data.xmit.recursion);
>> + migrate_enable();
>> }
>> #else
>> static inline int dev_recursion_level(void)
>> --
>> 2.43.0
> This seems wrong.
>
> The migrate_disable() should happen before dev_recursion_level().
Thanks
I checked all callers of dev_xmit_recursion_inc(). Most are fine.
The only problematic ones are iptunnel_xmit() and ip6tunnel_xmit(),
I think adding guard(migrate)() at the top of both functions is enough
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] net: fix __this_cpu_add() in preemptible code in dev_xmit_recursion_inc/dec
2026-04-09 7:50 ` Jiayuan Chen
@ 2026-04-09 8:10 ` Eric Dumazet
0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2026-04-09 8:10 UTC (permalink / raw)
To: Jiayuan Chen
Cc: netdev, David S. Miller, Jakub Kicinski, Paolo Abeni,
Simon Horman, Andrew Lunn, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Weiming Shi, linux-kernel,
linux-rt-devel
On Thu, Apr 9, 2026 at 12:50 AM Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
> Thanks
>
> I checked all callers of dev_xmit_recursion_inc(). Most are fine.
>
> The only problematic ones are iptunnel_xmit() and ip6tunnel_xmit(),
>
> I think adding guard(migrate)() at the top of both functions is enough
Seems fine to me, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-09 8:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-09 3:53 [PATCH net] net: fix __this_cpu_add() in preemptible code in dev_xmit_recursion_inc/dec Jiayuan Chen
2026-04-09 7:18 ` Eric Dumazet
2026-04-09 7:50 ` Jiayuan Chen
2026-04-09 8:10 ` Eric Dumazet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox