Netdev List
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@google.com>
To: Eric Dumazet <edumazet@kernel.org>,
	Neal Cardwell <ncardwell@google.com>,
	 "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	 Willem de Bruijn <willemb@google.com>
Cc: Simon Horman <horms@kernel.org>,
	Mina Almasry <almasrymina@google.com>,
	 Kuniyuki Iwashima <kuniyu@google.com>,
	Kuniyuki Iwashima <kuni1840@gmail.com>,
	netdev@vger.kernel.org
Subject: [PATCH v1 net] tcp: Initialise sk->sk_user_frags with XA_FLAGS_LOCK_BH.
Date: Sun,  6 Dec 2026 09:30:46 +0900	[thread overview]
Message-ID: <20261206003057.947812-1-kuniyu@google.com> (raw)

tcp_xa_pool_refill() calls __xa_alloc() with GFP_KERNEL under
xa_lock_bh(&sk->sk_user_frags), and the same applies to
__xa_cmpxchg() in tcp_xa_pool_commit_locked().

When __xa_alloc() or __xa_cmpxchg() reaches __xas_nomem(),
gfpflags_allow_blocking() returns true.

Then, the lock is released with xas_unlock_type(), and memory is
allocated with kmem_cache_alloc_lru(), which may sleep.

However, sk->sk_user_frags is not initialised with XA_FLAGS_LOCK_BH,
so xas_unlock_type() does not enable BH, resulting in the splat
below. [0]

Let's initialise sk->sk_user_frags with XA_FLAGS_LOCK_BH.

[0]:
BUG: sleeping function called from invalid context at include/linux/sched/mm.h:322
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 9368, name: ncdevmem
preempt_count: 200, expected: 0
CPU: 194 UID: 0 PID: 9368 Comm: ncdevmem Tainted: G S                  7.4.0-rc5-00307-ge9d78fc6741a #1 PREEMPTLAZY
Tainted: [S]=CPU_OUT_OF_SPEC
Hardware name: Google, BIOS 0.20260724.3-6 09/11/2026
Call Trace:
 <TASK>
 dump_stack_lvl (lib/dump_stack.c:120)
 __might_resched (kernel/sched/core.c:9250)
 kmem_cache_alloc_lru_noprof (include/linux/sched/mm.h:322 mm/slub.c:4673 mm/slub.c:5011 mm/slub.c:5066)
 __xas_nomem (lib/xarray.c:341)
 __xa_alloc (lib/xarray.c:2013)
 tcp_recvmsg_locked (net/ipv4/tcp.c:2496)
 tcp_recvmsg (net/ipv4/tcp.c:2957)
 sock_recvmsg (net/socket.c:1154)
 ____sys_recvmsg (net/socket.c:2933)
 ___sys_recvmsg (net/socket.c:2978)
 __x64_sys_recvmsg (net/socket.c:3011)
 do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:89)
 entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
RIP: 0033:0x473802
Code: 18 41 8b 93 08 03 00 00 59 5e 48 83 f8 fc 75 1a 83 e2 39 83 fa 08 75 12 e8 1b ff ff ff 0f 1f 00 49 89 ca 48 8b 44 24 20 0f 05 <48> 83 c4 18 c3 66 0f 1f 84 00 00 00 00 00 48 83 ec 10 ff 74 24 18
RSP: 002b:00007ffe52c85930 EFLAGS: 00000202 ORIG_RAX: 000000000000002f
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 0000000000473802
RDX: 0000000002000000 RSI: 00007ffe52c85a50 RDI: 0000000000000008
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000000
R13: 00007f6f13cde010 R14: 0000000000000007 R15: 00000000004d9480
 </TASK>

Fixes: 8f0b3cc9a4c1 ("tcp: RX path for devmem TCP")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
Found by LLM
---
 net/ipv4/tcp.c           | 2 +-
 net/ipv4/tcp_minisocks.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 80de376a9d2e..0754e31a545d 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -476,7 +476,7 @@ void tcp_init_sock(struct sock *sk)
 
 	set_bit(SOCK_SUPPORT_ZC, &sk->sk_socket->flags);
 	sk_sockets_allocated_inc(sk);
-	xa_init_flags(&sk->sk_user_frags, XA_FLAGS_ALLOC1);
+	xa_init_flags(&sk->sk_user_frags, XA_FLAGS_ALLOC1 | XA_FLAGS_LOCK_BH);
 }
 
 static void tcp_tx_timestamp(struct sock *sk, struct sockcm_cookie *sockc)
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 934012cdac27..6dc8b924d5e9 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -665,7 +665,7 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 
 	__TCP_INC_STATS(sock_net(sk), TCP_MIB_PASSIVEOPENS);
 
-	xa_init_flags(&newsk->sk_user_frags, XA_FLAGS_ALLOC1);
+	xa_init_flags(&newsk->sk_user_frags, XA_FLAGS_ALLOC1 | XA_FLAGS_LOCK_BH);
 
 	return newsk;
 }
-- 
2.56.1.915.g69d5ec7298-goog


                 reply	other threads:[~2026-12-06  0:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261206003057.947812-1-kuniyu@google.com \
    --to=kuniyu@google.com \
    --cc=almasrymina@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /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