FAILED: patch "[PATCH] espintcp: use sk_msg_free_partial to fix partial send" failed to apply to 6.1-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 007800408002d871f5699bdb944f985896730b8f
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072137-hatred-autograph-0bbe@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 007800408002d871f5699bdb944f985896730b8f Mon Sep 17 00:00:00 2001
From: Sabrina Dubroca <[email protected]>
Date: Fri, 12 Jun 2026 16:11:39 +0200
Subject: [PATCH] espintcp: use sk_msg_free_partial to fix partial send
sk_msg_free_partial() ensures consistency of the skmsg at every iteration, without having to manually handle uncharges and offsets. This simplifies the code, and fixes some bugs in skmsg accounting when we don't send the full contents.
net/xfrm/espintcp.c +7 -27
@@ -212,43 +212,23 @@ static int espintcp_sendskmsg_locked(struct sock *sk,struct sk_msg *skmsg = &emsg->skmsg;bool more = flags &MSG_MORE ;struct scatterlist *sg; -int done =0 ;int ret; - sg = &skmsg->sg.data[skmsg->sg.start];do {struct bio_vec bvec; -size_t size = sg->length - emsg->offset; -int offset = sg->offset + emsg->offset; -struct page *p; - - emsg->offset =0 ; + sg = &skmsg->sg.data[skmsg->sg.start];if (sg_is_last (sg) && !more) msghdr.msg_flags &= ~MSG_MORE ; - p =sg_page (sg); -retry: -bvec_set_page (&bvec, p, size, offset); -iov_iter_bvec (&msghdr.msg_iter,ITER_SOURCE , &bvec,1 , size); - ret =tcp_sendmsg_locked (sk, &msghdr, size); -if (ret <0 ) { - emsg->offset = offset - sg->offset; - skmsg->sg.start += done; +bvec_set_page (&bvec,sg_page (sg), sg->length, sg->offset); +iov_iter_bvec (&msghdr.msg_iter,ITER_SOURCE , &bvec,1 , sg->length); + ret =tcp_sendmsg_locked (sk, &msghdr, sg->length); +if (ret <0 )return ret; - } -if (ret != size) { - offset += ret; - size -= ret; - goto retry; - } - - done++; -put_page (p); -sk_mem_uncharge (sk, sg->length); - sg =sg_next (sg); - }while (sg); +sk_msg_free_partial (sk, skmsg, ret); + }while (skmsg->sg.size);memset (emsg,0 ,sizeof (*emsg));
Sasha Levin
maintainerPATCH 1/5 tcp_bpf: Inline do_tcp_sendpages as it's now a wrapper around tcp_sendmsg
From: David Howells <[email protected]>
[ Upstream commit ebf2e8860eea66e2c4764316b80c6a5ee5f336ee ]
do_tcp_sendpages() is now just a small wrapper around tcp_sendmsg_locked(), so inline it. This is part of replacing ->sendpage() with a call to sendmsg() with MSG_SPLICE_PAGES set.
Stable-dep-of: 007800408002 ("espintcp: use sk_msg_free_partial to fix partial send")
--- net/ipv4/tcp_bpf.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
net/ipv4/tcp_bpf.c +12 -8
@@ -92,11 +92,13 @@ static int tcp_bpf_push(struct sock *sk, struct sk_msg *msg, u32 apply_bytes, {bool apply = apply_bytes;struct scatterlist *sge; +struct msghdr msghdr = { .msg_flags = flags |MSG_SPLICE_PAGES , };struct page *page;int size, ret =0 ;u32 off;while (1 ) { +struct bio_vec bvec;bool has_tx_ulp; sge =sk_msg_elem (msg, msg->sg.start);
@@ -108,16 +110,18 @@ static int tcp_bpf_push(struct sock *sk, struct sk_msg *msg, u32 apply_bytes,tcp_rate_check_app_limited (sk); retry: has_tx_ulp =tls_sw_has_ctx_tx (sk); -if (has_tx_ulp) { - flags |=MSG_SENDPAGE_NOPOLICY ; - ret =kernel_sendpage_locked (sk, - page, off, size, flags); - }else { - ret =do_tcp_sendpages (sk, page, off, size, flags); - } +if (has_tx_ulp) + msghdr.msg_flags |=MSG_SENDPAGE_NOPOLICY ; +if (flags &MSG_SENDPAGE_NOTLAST ) + msghdr.msg_flags |=MSG_MORE ; + +bvec_set_page (&bvec, page, size, off); +iov_iter_bvec (&msghdr.msg_iter,ITER_SOURCE , &bvec,1 , size); + ret =tcp_sendmsg_locked (sk, &msghdr, size);if (ret <=0 )return ret; +if (apply) apply_bytes -= ret; msg->sg.size -= ret;
@@ -499,7 +503,7 @@ static int tcp_bpf_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)long timeo;int flags; -/* Don't let internal do_tcp_sendpages() flags through */ +/* Don't let internal sendpage flags through */ flags = (msg->msg_flags & ~MSG_SENDPAGE_DECRYPTED ); flags |=MSG_NO_SHARED_FRAGS ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/5 espintcp: Inline do_tcp_sendpages()
From: David Howells <[email protected]>
[ Upstream commit 7f8816ab4bae9dd42c5720fdad4b102532d4e43a ]
do_tcp_sendpages() is now just a small wrapper around tcp_sendmsg_locked(), so inline it, allowing do_tcp_sendpages() to be removed. This is part of replacing ->sendpage() with a call to sendmsg() with MSG_SPLICE_PAGES set.
Stable-dep-of: 007800408002 ("espintcp: use sk_msg_free_partial to fix partial send")
--- net/xfrm/espintcp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/xfrm/espintcp.c +7 -3
@@ -206,14 +206,16 @@ static int espintcp_sendskb_locked(struct sock *sk, struct espintcp_msg *emsg,static int espintcp_sendskmsg_locked (struct sock *sk,struct espintcp_msg *emsg,int flags) { +struct msghdr msghdr = { .msg_flags = flags |MSG_SPLICE_PAGES , };struct sk_msg *skmsg = &emsg->skmsg;struct scatterlist *sg;int done =0 ;int ret; - flags |=MSG_SENDPAGE_NOTLAST ; + msghdr.msg_flags |=MSG_SENDPAGE_NOTLAST ; sg = &skmsg->sg.data[skmsg->sg.start]; do { + struct bio_vec bvec; size_t size = sg->length - emsg->offset; int offset = sg->offset + emsg->offset; struct page *p;
@@ -221,11 +223,13 @@ static int espintcp_sendskmsg_locked(struct sock *sk, emsg->offset =0 ;if (sg_is_last (sg)) - flags &= ~MSG_SENDPAGE_NOTLAST ; + msghdr.msg_flags &= ~MSG_SENDPAGE_NOTLAST ; p =sg_page (sg); retry: - ret =do_tcp_sendpages (sk, p, offset, size, flags); +bvec_set_page (&bvec, p, size, offset); +iov_iter_bvec (&msghdr.msg_iter,ITER_SOURCE , &bvec,1 , size); + ret =tcp_sendmsg_locked (sk, &msghdr, size);if (ret <0 ) { emsg->offset = offset - sg->offset; skmsg->sg.start += done;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/5 siw: Inline do_tcp_sendpages()
In reply to Sasha LevinFrom: David Howells <[email protected]>
[ Upstream commit c2ff29e99a764769eb2ce3a1a5585013633ee9a6 ]
do_tcp_sendpages() is now just a small wrapper around tcp_sendmsg_locked(), so inline it, allowing do_tcp_sendpages() to be removed. This is part of replacing ->sendpage() with a call to sendmsg() with MSG_SPLICE_PAGES set.
Stable-dep-of: 007800408002 ("espintcp: use sk_msg_free_partial to fix partial send")
--- drivers/infiniband/sw/siw/siw_qp_tx.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/infiniband/sw/siw/siw_qp_tx.c +12 -5
@@ -313,7 +313,7 @@ static int siw_tx_ctrl(struct siw_iwarp_tx *c_tx, struct socket *s, }/* -* 0copy TCP transmit interface: Use do_tcp_sendpages. +* 0copy TCP transmit interface: Use MSG_SPLICE_PAGES. * * Using sendpage to push page by page appears to be less efficient * than using sendmsg, even if data are copied.
@@ -324,20 +324,27 @@ static int siw_tx_ctrl(struct siw_iwarp_tx *c_tx, struct socket *s,static int siw_tcp_sendpages (struct socket *s,struct page **page,int offset,size_t size) { +struct bio_vec bvec; +struct msghdr msg = { + .msg_flags = (MSG_MORE |MSG_DONTWAIT |MSG_SENDPAGE_NOTLAST | +MSG_SPLICE_PAGES ), + };struct sock *sk = s->sk; -int i =0 , rv =0 , sent =0 , - flags =MSG_MORE |MSG_DONTWAIT |MSG_SENDPAGE_NOTLAST ; +int i =0 , rv =0 , sent =0 ;while (size) {size_t bytes =min_t (size_t,PAGE_SIZE - offset, size);if (size + offset <=PAGE_SIZE ) - flags =MSG_MORE |MSG_DONTWAIT ; + msg.msg_flags &= ~MSG_SENDPAGE_NOTLAST ;tcp_rate_check_app_limited (sk); +bvec_set_page (&bvec, page[i], bytes, offset); +iov_iter_bvec (&msg.msg_iter,ITER_SOURCE , &bvec,1 , size); + try_page_again:lock_sock (sk); - rv =do_tcp_sendpages (sk, page[i], offset, bytes, flags); + rv =tcp_sendmsg_locked (sk, &msg, size);release_sock (sk);if (rv >0 ) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/5 tcp_bpf, smc, tls, espintcp, siw: Reduce MSG_SENDPAGE_NOTLAST usage
In reply to Sasha LevinFrom: David Howells <[email protected]>
[ Upstream commit f8dd95b29d7ef08c19ec9720564acf72243ddcf6 ]
As MSG_SENDPAGE_NOTLAST is being phased out along with sendpage(), don't use it further in than the sendpage methods, but rather translate it to MSG_MORE and use that instead.
Stable-dep-of: 007800408002 ("espintcp: use sk_msg_free_partial to fix partial send")
--- drivers/infiniband/sw/siw/siw_qp_tx.c | 5 ++--- net/ipv4/tcp_bpf.c | 5 +++-- net/smc/smc_tx.c | 6 ++++-- net/tls/tls_device.c | 4 ++-- net/xfrm/espintcp.c | 10 ++++++---- 5 files changed, 17 insertions(+), 13 deletions(-)
drivers/infiniband/sw/siw/siw_qp_tx.c +2 -3
@@ -326,8 +326,7 @@ static int siw_tcp_sendpages(struct socket *s, struct page **page, int offset, {struct bio_vec bvec;struct msghdr msg = { - .msg_flags = (MSG_MORE |MSG_DONTWAIT |MSG_SENDPAGE_NOTLAST | -MSG_SPLICE_PAGES ), + .msg_flags = (MSG_MORE |MSG_DONTWAIT |MSG_SPLICE_PAGES ), };struct sock *sk = s->sk;int i =0 , rv =0 , sent =0 ;
@@ -336,7 +335,7 @@ static int siw_tcp_sendpages(struct socket *s, struct page **page, int offset,size_t bytes =min_t (size_t,PAGE_SIZE - offset, size);if (size + offset <=PAGE_SIZE ) - msg.msg_flags &= ~MSG_SENDPAGE_NOTLAST ; + msg.msg_flags &= ~MSG_MORE ;tcp_rate_check_app_limited (sk);bvec_set_page (&bvec, page[i], bytes, offset);
net/ipv4/tcp_bpf.c +3 -2
@@ -90,9 +90,9 @@ static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock,static int tcp_bpf_push (struct sock *sk,struct sk_msg *msg,u32 apply_bytes,int flags,bool uncharge) { +struct msghdr msghdr = {};bool apply = apply_bytes;struct scatterlist *sge; -struct msghdr msghdr = { .msg_flags = flags |MSG_SPLICE_PAGES , };struct page *page;int size, ret =0 ;u32 off;
@@ -109,11 +109,12 @@ static int tcp_bpf_push(struct sock *sk, struct sk_msg *msg, u32 apply_bytes,tcp_rate_check_app_limited (sk); retry: + msghdr.msg_flags = flags |MSG_SPLICE_PAGES ; has_tx_ulp =tls_sw_has_ctx_tx (sk);if (has_tx_ulp) msghdr.msg_flags |=MSG_SENDPAGE_NOPOLICY ; -if (flags &MSG_SENDPAGE_NOTLAST ) +if (size < sge->length && msg->sg.start != msg->sg.end) msghdr.msg_flags |=MSG_MORE ;bvec_set_page (&bvec, page, size, off);
net/smc/smc_tx.c +4 -2
@@ -168,8 +168,7 @@ static bool smc_tx_should_cork(struct smc_sock *smc, struct msghdr *msg)* should known how/when to uncork it. */ if ((msg->msg_flags &MSG_MORE || -smc_tx_is_corked (smc) || - msg->msg_flags &MSG_SENDPAGE_NOTLAST ) && +smc_tx_is_corked (smc)) &&atomic_read (&conn->sndbuf_space))return true;
@@ -306,6 +305,9 @@ int smc_tx_sendpage(struct smc_sock *smc, struct page *page, int offset,struct kvec iov;int rc; +if (flags &MSG_SENDPAGE_NOTLAST ) + msg.msg_flags |=MSG_MORE ; + iov.iov_base = kaddr + offset; iov.iov_len = size;iov_iter_kvec (&msg.msg_iter,ITER_SOURCE , &iov,1 , size);
net/tls/tls_device.c +2 -2
@@ -457,7 +457,7 @@ static int tls_push_data(struct sock *sk,return -sk->sk_err; flags |=MSG_SENDPAGE_DECRYPTED ; - tls_push_record_flags = flags |MSG_SENDPAGE_NOTLAST ; + tls_push_record_flags = flags |MSG_MORE ; timeo =sock_sndtimeo (sk, flags &MSG_DONTWAIT );if (tls_is_partially_sent_record (tls_ctx)) {
@@ -526,7 +526,7 @@ static int tls_push_data(struct sock *sk,if (!size) { last_record: tls_push_record_flags = flags; -if (flags & (MSG_SENDPAGE_NOTLAST |MSG_MORE )) { +if (flags &MSG_MORE ) { more = true;break ; }
net/xfrm/espintcp.c +6 -4
@@ -206,13 +206,15 @@ static int espintcp_sendskb_locked(struct sock *sk, struct espintcp_msg *emsg,static int espintcp_sendskmsg_locked (struct sock *sk,struct espintcp_msg *emsg,int flags) { -struct msghdr msghdr = { .msg_flags = flags |MSG_SPLICE_PAGES , }; +struct msghdr msghdr = { + .msg_flags = flags |MSG_SPLICE_PAGES |MSG_MORE , + };struct sk_msg *skmsg = &emsg->skmsg; +bool more = flags &MSG_MORE ;struct scatterlist *sg;int done =0 ;int ret; - msghdr.msg_flags |=MSG_SENDPAGE_NOTLAST ; sg = &skmsg->sg.data[skmsg->sg.start]; do { struct bio_vec bvec;
@@ -222,8 +224,8 @@ static int espintcp_sendskmsg_locked(struct sock *sk, emsg->offset =0 ; -if (sg_is_last (sg)) - msghdr.msg_flags &= ~MSG_SENDPAGE_NOTLAST ; +if (sg_is_last (sg) && !more) + msghdr.msg_flags &= ~MSG_MORE ; p =sg_page (sg); retry:
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 5/5 espintcp: use sk_msg_free_partial to fix partial send
In reply to Sasha LevinFrom: Sabrina Dubroca <[email protected]>
[ Upstream commit 007800408002d871f5699bdb944f985896730b8f ]
sk_msg_free_partial() ensures consistency of the skmsg at every iteration, without having to manually handle uncharges and offsets. This simplifies the code, and fixes some bugs in skmsg accounting when we don't send the full contents.
--- net/xfrm/espintcp.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-)
net/xfrm/espintcp.c +7 -27
@@ -212,43 +212,23 @@ static int espintcp_sendskmsg_locked(struct sock *sk,struct sk_msg *skmsg = &emsg->skmsg;bool more = flags &MSG_MORE ;struct scatterlist *sg; -int done =0 ;int ret; - sg = &skmsg->sg.data[skmsg->sg.start];do {struct bio_vec bvec; -size_t size = sg->length - emsg->offset; -int offset = sg->offset + emsg->offset; -struct page *p; - - emsg->offset =0 ; + sg = &skmsg->sg.data[skmsg->sg.start];if (sg_is_last (sg) && !more) msghdr.msg_flags &= ~MSG_MORE ; - p =sg_page (sg); -retry: -bvec_set_page (&bvec, p, size, offset); -iov_iter_bvec (&msghdr.msg_iter,ITER_SOURCE , &bvec,1 , size); - ret =tcp_sendmsg_locked (sk, &msghdr, size); -if (ret <0 ) { - emsg->offset = offset - sg->offset; - skmsg->sg.start += done; +bvec_set_page (&bvec,sg_page (sg), sg->length, sg->offset); +iov_iter_bvec (&msghdr.msg_iter,ITER_SOURCE , &bvec,1 , sg->length); + ret =tcp_sendmsg_locked (sk, &msghdr, sg->length); +if (ret <0 )return ret; - } - -if (ret != size) { - offset += ret; - size -= ret; - goto retry; - } - done++; -put_page (p); -sk_mem_uncharge (sk, sg->length); - sg =sg_next (sg); - }while (sg); +sk_msg_free_partial (sk, skmsg, ret); + }while (skmsg->sg.size);memset (emsg,0 ,sizeof (*emsg));
Signature · 1 line
2.53.0