From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CBE83054D8 for ; Sun, 15 Feb 2026 20:44:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771188244; cv=none; b=ljO729lih80T+06vdoWviNCHbC0QRKpOmjVUneKyt3n8O4Q4h33xo55vzG39s/pKP8EDYk8NriCKmlUueokE/8ogyu3jGdoyyRVPbWW3ni4EsyhRS1hLo6sg91cgvW+PiVw2v5ul9ZqpTQ+FAC7EU0gwRvEtySs4jz9WxL4+XYQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771188244; c=relaxed/simple; bh=MkAF6NrOoDIjmjTurHR5Pb6sxyEpSSoVIdDhEBK0kcA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nrZJxHSYlT7tVkKiHeFjZWntznk3z7OuxRPFeoQ0szLcq4c5JTWHkmGgqdebhQAZ4GAZq2KGEBjmQ4xLZuEg/zTBA7icNg9u8d1am1aEr36ZgzAlRwowz+nJc9lh1yLuPlaq7NqpYXi1VC77Jw41OHE70p7s/uSuGMoaZfexzjc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OIwa8ccY; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OIwa8ccY" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3562bdba6f7so11962559a91.2 for ; Sun, 15 Feb 2026 12:44:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771188242; x=1771793042; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/BT5YOjf9XtzKKAlrK8bU47/cOZRZChjPVpJTvbg7E4=; b=OIwa8ccYDiV8LLp/sslakXCmy4rDoLLysoxqMzyZTJgFrPGhKgon9NXR8hdkQq/HVB zlKabaefdQSsv7Kz1vs84r1HBtueIAhkhBCyo8n/vzueUQyUBxHgQ80Kr5w+FTLqbYFe oCrY2Ow77mnwl001WuJywoturXSh68PpSRh1Pz2rC81c/Hr4fLoTAnI5tJnRDy+wNHqP da4QbexO+dLOAIsxttZWCv9/ubnTGsvheqdx0e0V3F7C/fybsXO6NK9uxLLFG7T2rsQh ki8M5zuJ6TGN653qamu40HWW0R5DOzUY+X3NVLKVI4Sm9cJXVvHIQ2a3jJHG6JqNbdzE Fp4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771188242; x=1771793042; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/BT5YOjf9XtzKKAlrK8bU47/cOZRZChjPVpJTvbg7E4=; b=c/Wum0z5z7dxhWaJgXLBTtHkpMy1/qwcHLaABZ5T8xOUYPu8GhuWh/tgs1Vpyir8H5 VVxJeRA7QPq5XjpjOJdT3aVx/bEJXzfMij0dYS9GTgy70iLZZ3Dgch/Ax2GRExDN2Wb9 eR1rXgE5ltIkI2F6GDnk5uM2IzBRpW+MRPE8yNdQGxWawZfDl52Hnbj8hbFDWrCvQQaq M+B/fSgSKM9NsJfAb7nZNswViDqZW9kGTiliv9WXQpxmpyYwmroK9w4P16abg3vosfJ/ fTNgtdR/Rx+BPavP5y06DYTQHxIPuPf9ivlfTZ5ibe2ztq0fVtbI5ZMgmIFF9/ZpJM1l NY7g== X-Forwarded-Encrypted: i=1; AJvYcCV+oLpLOFLvVSvzZ+UXANkkaiWShtW8DQZkSqE8Zkx2DXkpMgtdZjjaEBGBX6duTm1TGv7GJfE=@vger.kernel.org X-Gm-Message-State: AOJu0YwHKikWgbc8d+qSMyzFjURiZcgal4im5aphovD4b9VMOfKUB3TY vxiWLYqTIttkU6DGtYYoCTdJGsEijx5xj8TNhIJteg0+U4Fk+bhVOAlxkR8W/uonOyRWTx6vXjr hNdAZRw== X-Received: from pjbei12.prod.google.com ([2002:a17:90a:e54c:b0:340:bd8e:458f]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5345:b0:354:a57c:65ec with SMTP id 98e67ed59e1d1-356a7a43faemr9852892a91.20.1771188242392; Sun, 15 Feb 2026 12:44:02 -0800 (PST) Date: Sun, 15 Feb 2026 20:41:39 +0000 In-Reply-To: <20260215204353.3645744-1-kuniyu@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260215204353.3645744-1-kuniyu@google.com> X-Mailer: git-send-email 2.53.0.310.g728cabbaf7-goog Message-ID: <20260215204353.3645744-5-kuniyu@google.com> Subject: [PATCH v1 bpf/net 4/6] sockmap: Pass gfp_t flag to sk_psock_skb_ingress(). From: Kuniyuki Iwashima To: John Fastabend , Jakub Sitnicki Cc: Willem de Bruijn , Cong Wang , Kuniyuki Iwashima , Kuniyuki Iwashima , bpf@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" SOCKMAP memory accounting for UDP is broken for two reasons: 1. sk->sk_forward_alloc must be changed under spin_lock_bh(&sk->sk_receive_queue.lock) 2. sk_psock_skb_ingress_self() should not be used for UDP since UDP may reclaim sk->sk_forward_alloc partially before passing skb to sockmap, resulting in a negative sk->sk_forward_alloc This is a prep commit to consolidate sk_psock_skb_ingress_self() and centralise the fix to sk_psock_skb_ingress(). Let's pass gfp_t flag to sk_psock_skb_ingress() and inline sk_psock_create_ingress_msg(). Note that now alloc_sk_msg() is called first. Signed-off-by: Kuniyuki Iwashima --- net/core/skmsg.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index 3d7eb2f4ac98..57845b0d8a71 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -529,18 +529,6 @@ static struct sk_msg *alloc_sk_msg(gfp_t gfp) return msg; } -static struct sk_msg *sk_psock_create_ingress_msg(struct sock *sk, - struct sk_buff *skb) -{ - if (atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf) - return NULL; - - if (!sk_rmem_schedule(sk, skb, skb->truesize)) - return NULL; - - return alloc_sk_msg(GFP_KERNEL); -} - static int sk_psock_skb_ingress_enqueue(struct sk_buff *skb, u32 off, u32 len, struct sk_psock *psock, @@ -588,11 +576,11 @@ static int sk_psock_skb_ingress_self(struct sk_psock *psock, struct sk_buff *skb u32 off, u32 len, bool take_ref); static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb, - u32 off, u32 len) + u32 off, u32 len, gfp_t gfp_flags) { struct sock *sk = psock->sk; struct sk_msg *msg; - int err; + int err = -EAGAIN; /* If we are receiving on the same sock skb->sk is already assigned, * skip memory accounting and owner transition seeing it already set @@ -600,9 +588,16 @@ static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb, */ if (unlikely(skb->sk == sk)) return sk_psock_skb_ingress_self(psock, skb, off, len, true); - msg = sk_psock_create_ingress_msg(sk, skb); + + msg = alloc_sk_msg(gfp_flags); if (!msg) - return -EAGAIN; + goto out; + + if (atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf) + goto free; + + if (!sk_rmem_schedule(sk, skb, skb->truesize)) + goto free; /* This will transition ownership of the data from the socket where * the BPF program was run initiating the redirect to the socket @@ -613,8 +608,12 @@ static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb, skb_set_owner_r(skb, sk); err = sk_psock_skb_ingress_enqueue(skb, off, len, psock, sk, msg, true); if (err < 0) - kfree(msg); + goto free; +out: return err; +free: + kfree(msg); + goto out; } /* Puts an skb on the ingress queue of the socket already assigned to the @@ -652,7 +651,7 @@ static int sk_psock_handle_skb(struct sk_psock *psock, struct sk_buff *skb, return skb_send_sock(psock->sk, skb, off, len); } - return sk_psock_skb_ingress(psock, skb, off, len); + return sk_psock_skb_ingress(psock, skb, off, len, GFP_KERNEL); } static void sk_psock_skb_state(struct sk_psock *psock, -- 2.53.0.310.g728cabbaf7-goog