Netdev List
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Simon Horman <horms@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kiryl Shutsemau <kas@kernel.org>,
	Song Liu <songliubraving@fb.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Rik van Riel <riel@surriel.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Neal Cardwell <ncardwell@google.com>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Pedro Falcato <pfalcato@suse.de>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, stable@vger.kernel.org
Subject: Re: [PATCH net 4/4] net: skbuff: limit folio refcount when splicing from sockets
Date: Thu, 26 Nov 2026 15:44:19 +0100	[thread overview]
Message-ID: <832f42a7-1d44-4138-a7f5-7cead4a28e57@kernel.org> (raw)
In-Reply-To: <14059088-7992-4d89-ac6c-1e6d1f61b3c8@redhat.com>

On 11/26/26 15:18, Paolo Abeni wrote:
> On 11/18/26 09:32, David Hildenbrand (Arm) wrote:
>> @@ -3299,14 +3311,14 @@ int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset,
>>   		.ops = &default_pipe_buf_ops,
>>   		.spd_release = sock_spd_release,
>>   	};
>> -	int ret = 0;
>> +	int ret;
>>   
>> -	__skb_splice_bits(skb, pipe, &offset, &tlen, &spd, sk);
>> +	ret = __skb_splice_bits(skb, pipe, &offset, &tlen, &spd, sk);
>>   
>>   	if (spd.nr_pages)
>> -		ret = splice_to_pipe(pipe, &spd);
>> -
>> -	return ret;
>> +		return splice_to_pipe(pipe, &spd);
>> +	/* Returning 0 would make callers report EOF. */
>> +	return ret < 0 ? ret : 0;
> 

Thanks for having a look.

> AFAICS the above introduces a change of behavior:
> caller with tlen==0 get 1 as return value, while they
> used to get EOF. I think the return code from
> `__skb_splice_bits` should be ignored, when not negative.

I think you are right.

> 
> I think the churn here could be reduced re-using the `len`
> ptr argument to store the error code; something alike the
> (completely untested) following:
> 
> ---
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 85d5caa08887..9fd5116f33f3 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -3177,6 +3177,10 @@ static bool spd_fill_page(struct splice_pipe_desc *spd, struct page *page,
>                  spd->partial[spd->nr_pages - 1].len += *len;
>                  return false;
>          }
> +       if (!try_get_page(page)) {
> +               *len = -EFAULT;
> +               return true;
> +       }
>          get_page(page);

Double get, easily fixed.

>          spd->pages[spd->nr_pages] = page;
>          spd->partial[spd->nr_pages].len = *len;
> @@ -3299,6 +3303,8 @@ int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset,
>          int ret = 0;
> 
>          __skb_splice_bits(skb, pipe, &offset, &tlen, &spd, sk);
> +       if (tlen < 0)
> +               return tlen;
> 
>          if (spd.nr_pages)
>                  ret = splice_to_pipe(pipe, &spd);
> ---
> 
> which is arguably ugly but IMHO no more than the tristate
> return value in the current version.

That doesn't work. "len" you write in the function is not tlen ...

__splice_segment() passes &flen.

Further all these lengths are unsigned int, not signed :/

Also, I think we have to respect spd.nr_pages.

If we want it minimal, a separate error pointer might be the easiest way to fix it. Still
ugly, but I tried to get it clean above and there is no way around some churn I'm afraid.


diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index c937d74eed6ac..f471bea7fb26e 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3166,7 +3166,7 @@ static bool spd_can_coalesce(const struct splice_pipe_desc *spd,
  */
 static bool spd_fill_page(struct splice_pipe_desc *spd, struct page *page,
 			  unsigned int *len, unsigned int offset, bool linear,
-			  struct sock *sk)
+			  struct sock *sk, int *err)
 {
 	if (unlikely(spd->nr_pages == MAX_SKB_FRAGS))
 		return true;
@@ -3180,7 +3180,10 @@ static bool spd_fill_page(struct splice_pipe_desc *spd, struct page *page,
 		spd->partial[spd->nr_pages - 1].len += *len;
 		return false;
 	}
-	get_page(page);
+	if (!try_get_page(page)) {
+		*err = -EFAULT;
+		return true;
+	}
 	spd->pages[spd->nr_pages] = page;
 	spd->partial[spd->nr_pages].len = *len;
 	spd->partial[spd->nr_pages].offset = offset;
@@ -3193,7 +3196,7 @@ static bool __splice_segment(struct page *page, unsigned int poff,
 			     unsigned int plen, unsigned int *off,
 			     unsigned int *len,
 			     struct splice_pipe_desc *spd, bool linear,
-			     struct sock *sk)
+			     struct sock *sk, int *err)
 {
 	if (!*len)
 		return true;
@@ -3212,7 +3215,7 @@ static bool __splice_segment(struct page *page, unsigned int poff,
 	do {
 		unsigned int flen = min(*len, plen);
 
-		if (spd_fill_page(spd, page, &flen, poff, linear, sk))
+		if (spd_fill_page(spd, page, &flen, poff, linear, sk, err))
 			return true;
 		poff += flen;
 		plen -= flen;
@@ -3230,7 +3233,8 @@ static bool __splice_segment(struct page *page, unsigned int poff,
  */
 static bool __skb_splice_bits(struct sk_buff *skb, struct pipe_inode_info *pipe,
 			      unsigned int *offset, unsigned int *len,
-			      struct splice_pipe_desc *spd, struct sock *sk)
+			      struct splice_pipe_desc *spd, struct sock *sk,
+			      int *err)
 {
 	struct sk_buff *iter;
 	int seg;
@@ -3245,7 +3249,7 @@ static bool __skb_splice_bits(struct sk_buff *skb, struct pipe_inode_info *pipe,
 			     skb_headlen(skb),
 			     offset, len, spd,
 			     skb_head_is_locked(skb),
-			     sk))
+			     sk, err))
 		return true;
 
 	/*
@@ -3262,7 +3266,7 @@ static bool __skb_splice_bits(struct sk_buff *skb, struct pipe_inode_info *pipe,
 
 		if (__splice_segment(skb_frag_page(f),
 				     skb_frag_off(f), skb_frag_size(f),
-				     offset, len, spd, false, sk))
+				     offset, len, spd, false, sk, err))
 			return true;
 	}
 
@@ -3272,10 +3276,10 @@ static bool __skb_splice_bits(struct sk_buff *skb, struct pipe_inode_info *pipe,
 			continue;
 		}
 		/* __skb_splice_bits() only fails if the output has no room
-		 * left, so no point in going over the frag_list for the error
-		 * case.
+		 * left or on error, so no point in going over the frag_list
+		 * for the error case.
 		 */
-		if (__skb_splice_bits(iter, pipe, offset, len, spd, sk))
+		if (__skb_splice_bits(iter, pipe, offset, len, spd, sk, err))
 			return true;
 	}
 
@@ -3299,9 +3303,11 @@ int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset,
 		.ops = &default_pipe_buf_ops,
 		.spd_release = sock_spd_release,
 	};
-	int ret = 0;
+	int ret = 0, err = 0;
 
-	__skb_splice_bits(skb, pipe, &offset, &tlen, &spd, sk);
+	__skb_splice_bits(skb, pipe, &offset, &tlen, &spd, sk, &err);
+	if (err && !spd.nr_pages)
+		return err;
 
 	if (spd.nr_pages)
 		ret = splice_to_pipe(pipe, &spd);
-- 
2.56.1

-- 
Cheers,

David

  reply	other threads:[~2026-11-26 14:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  8:32 [PATCH net 0/4] net: skbuff: limit pagecache folio refcount David Hildenbrand (Arm)
2026-11-18  8:32 ` [PATCH net 1/4] net: skbuff: limit folio refcount when copying skb frag references David Hildenbrand (Arm)
2026-11-19 13:53   ` David Hildenbrand (Arm)
2026-11-20 16:21   ` Stanislav Fomichev
2026-11-20 21:01     ` David Hildenbrand (Arm)
2026-11-22  9:19   ` netdev-bot+sashiko
2026-11-22 12:58     ` David Hildenbrand (Arm)
2026-11-22 18:43       ` David Hildenbrand (Arm)
2026-11-18  8:32 ` [PATCH net 2/4] net: skbuff: limit folio refcount when rearranging skb frags David Hildenbrand (Arm)
2026-11-22  9:19   ` netdev-bot+sashiko
2026-11-22 12:48     ` David Hildenbrand (Arm)
2026-11-18  8:32 ` [PATCH net 3/4] net: skbuff: limit folio refcount when splicing pages into skbs David Hildenbrand (Arm)
2026-11-22  9:19   ` netdev-bot+sashiko
2026-11-22 13:05     ` David Hildenbrand (Arm)
2026-11-18  8:32 ` [PATCH net 4/4] net: skbuff: limit folio refcount when splicing from sockets David Hildenbrand (Arm)
2026-11-22  9:19   ` netdev-bot+sashiko
2026-11-22 13:09     ` David Hildenbrand (Arm)
2026-11-26 14:18   ` Paolo Abeni
2026-11-26 14:44     ` David Hildenbrand (Arm) [this message]
2026-11-26 16:10       ` Paolo Abeni
2026-11-26 16:12         ` David Hildenbrand (Arm)
2026-11-26 16:31           ` Paolo Abeni

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=832f42a7-1d44-4138-a7f5-7cead4a28e57@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=horms@kernel.org \
    --cc=kas@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pfalcato@suse.de \
    --cc=riel@surriel.com \
    --cc=songliubraving@fb.com \
    --cc=stable@vger.kernel.org \
    --cc=willy@infradead.org \
    /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