The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: netdev-bot+sashiko@kernel.org
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, akpm@linux-foundation.org,
	kas@kernel.org, songliubraving@fb.com, hannes@cmpxchg.org,
	riel@surriel.com, willy@infradead.org, ncardwell@google.com,
	kuniyu@google.com, pfalcato@suse.de, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	stable@vger.kernel.org
Subject: Re: [PATCH net 3/4] net: skbuff: limit folio refcount when splicing pages into skbs
Date: Sun, 22 Nov 2026 14:05:22 +0100	[thread overview]
Message-ID: <8e4ac3be-8d0e-4846-9577-6c968ceab776@kernel.org> (raw)
In-Reply-To: <179533917877.3135.7884614269284288545@kernel.org>

[...]

> 
> [Severity: High]
> Does this cover all of the in-kernel MSG_SPLICE_PAGES users that the commit
> message is aimed at? Both kTLS sendmsg paths handle MSG_SPLICE_PAGES without
> ever calling skb_append_pagefrags(). They still take an unchecked reference
> on every spliced page.
> 
> For software kTLS the path is
> tls_sw_sendmsg_locked()->tls_sw_sendmsg_splice()->sk_msg_page_add():

I had the following as part of the -mm submission [1] linked in the cover that
carried these things:

"
Net paths that take page refs that I don't touch because the references
are either bounded or the paths are not relevant in practice:

 - skb_split(): can add one reference per split, but each split
   allocates a new skb that is charged to the socket, and the references
   go away once the data was acked. Reworking that to be able to fail
   requires more plumbing.
 - IP-TFS reassembly: needs one new inner skb per additional reference.
 - io_uring zerocopy send (managed frag references): each zerocopy piece
   is charged at least 4 KiB of TCP memory, so not relevant in practice.
 - kTLS software splicing: only transfers references from the pipe, so
   not a problem.
 - AF_XDP zerocopy TX, nfsd splice reads, sockmap / sk_msg, espintcp:
   bounded, or require privileges / special setups, so not a problem in
   practice.
 - Driver-specific paths (e.g., kTLS device offload): require special
   hardware, didn't look into these.
 - page_pool and net_iov frags: not pagecache pages, so not a problem.
"

I think I tried getting it reproduced with kTLS, but due to lack of HW I was
only able to test the software path.

The hw path can be tackled separately, if that is really a problem (again, no HW
to test).

[1]
https://lore.kernel.org/linux-mm/20261112-refcount_overflow_stable-v4-0-ad3deef0bd23@kernel.org/


> 
> include/linux/skmsg.h:sk_msg_page_add() {
>     ...
> 	get_page(page);
> 	sge = sk_msg_elem(msg, msg->sg.end);
> 	sg_set_page(sge, page, len, offset);
>     ...
> }
> 
> The only check in tls_sw_sendmsg_splice() is this one, and it does not look
> at the refcount limit:
> 
> 		if (WARN_ON_ONCE(!sendpage_ok(page))) {
> 
> For device offload kTLS the path is tls_push_data()->tls_append_frag():
> 
> net/tls/tls_device.c:tls_append_frag() {
>     ...
> 		++record->num_frags;
> 		get_page(pfrag->page);
>     ...
> }
> 
> These references stay in offload_ctx->records_list until
> tls_tcp_clean_acked() runs, so they last until the peer ACKs.
> 
> The sunrpc example from the commit message appears to take this route.
> svc_tcp_sendmsg() sets MSG_SPLICE_PAGES and calls sock_sendmsg(). On
> XPT_TLS_SESSION transports, set up by
> svc_tcp_handshake()->tls_server_hello_x509(), that socket is a kTLS socket.
> So nfsd pagecache pages would reach sk_msg_page_add() or tls_append_frag()
> and never skb_append_pagefrags().
> 
> No later patch in the series touches net/tls/ or include/linux/skmsg.h,
> including "net: skbuff: limit folio refcount when splicing from sockets".
> 
> Should the spliced-page references in sk_msg_page_add() and
> tls_append_frag() also go through try_get_page()?
> 
> [Severity: Medium]
> Can this new -EFAULT cause nfsd connections to be torn down over and over?
> 
> nfsd threads are kthreads, and folio_ref_count_over_limit_slowpath()
> refuses them at FOLIO_REF_COUNT_LIMIT, with no admin headroom:
> 
> 	/* Background threads must not consume admin reserves. */
> 	if (current->flags & PF_KTHREAD)
> 		goto over_limit;
> 
> On the read side the limit is checked only once, when
> filemap_splice_read()->splice_folio_into_pipe() calls folio_get_checked().
> After that, nfsd_splice_actor()->svc_rqst_replace_page() takes an unchecked
> get_page() for rq_respages, and the pipe reference is dropped. With this
> patch, sending the reply needs a second, checked reference per page here.
> 
> Let k be roughly the number of pages from the folio in the reply. Suppose a
> local user holds the folio refcount between FOLIO_REF_COUNT_LIMIT - k and
> FOLIO_REF_COUNT_LIMIT. The read stage succeeds and fills the refcount up to
> the limit. The send then fails:
> 
> skb_append_pagefrags()
>   try_get_page() fails, returns -EFAULT
> skb_splice_from_iter()
>   iov_iter_revert(), returns -EFAULT or a short count
> tcp_sendmsg_locked()
>   returns a short count
> svc_tcp_sendto()
> 	if (sent < 0 || sent != (xdr->len + sizeof(marker)))
> 		goto out_close;
>     ...
> 	svc_xprt_deferred_close(xprt);
> 
> This closes the connection together with every other RPC in flight on it.
> The client reconnects and retransmits the same READ. Nothing clears the
> condition, so the cycle repeats for as long as the refcount stays in that
> window.
> 
> Mappings are checked against the same limit. An unprivileged user can
> therefore put the count in that window by mapping until refused and then
> unmapping a few pages.
> 
> Before this patch the send succeeded. At or above FOLIO_REF_COUNT_LIMIT, the
> pipe-stage check makes nfsd return an NFS read error rather than close the
> connection.
> 
> The commit message says:
> 
>     The only caller, skb_splice_from_iter(), handles that.
> 
> For sunrpc, though, the error ends in connection teardown, and nothing falls
> back to copying the data into frags. Would a copy fallback be better here,
> or is the teardown intended?

I don't think so. If someone pushed a folio refcount to its limit we should just
fail instead of trying to keep it somehow working slower. (Linus had the same
thought about failing splice instead of falling back to a copy)

-- 
Cheers,

David

  reply	other threads:[~2026-11-22 13:05 UTC|newest]

Thread overview: 16+ 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-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) [this message]
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)

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=8e4ac3be-8d0e-4846-9577-6c968ceab776@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-bot+sashiko@kernel.org \
    --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