diff mbox series

[bpf] skmsg: schedule psock work if the cached skb exists on the psock

Message ID 20220907071311.60534-1-liujian56@huawei.com (mailing list archive)
State Accepted
Commit bec217197b412d74168c6a42fc0f76d0cc9cad00
Delegated to: BPF
Headers show
Series [bpf] skmsg: schedule psock work if the cached skb exists on the psock | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 5 this patch: 5
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 30 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-PR success PR summary
bpf/vmtest-bpf-VM_Test-4 success Logs for llvm-toolchain
bpf/vmtest-bpf-VM_Test-5 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-2 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-3 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-1 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-7 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-8 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-16 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-13 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-14 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-10 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-11 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-6 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-VM_Test-15 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-9 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for test_progs_no_alu32 on s390x with gcc

Commit Message

Liu Jian Sept. 7, 2022, 7:13 a.m. UTC
In sk_psock_backlog function, for ingress direction skb, if no new data
packet arrives after the skb is cached, the cached skb does not have a
chance to be added to the receive queue of psock. As a result, the cached
skb cannot be received by the upper-layer application.

Fix this by reschedule the psock work to dispose the cached skb in
sk_msg_recvmsg function.

Fixes: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: Liu Jian <liujian56@huawei.com>
---
 net/core/skmsg.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

John Fastabend Sept. 22, 2022, 6:19 p.m. UTC | #1
Liu Jian wrote:
> In sk_psock_backlog function, for ingress direction skb, if no new data
> packet arrives after the skb is cached, the cached skb does not have a
> chance to be added to the receive queue of psock. As a result, the cached
> skb cannot be received by the upper-layer application.
> 
> Fix this by reschedule the psock work to dispose the cached skb in
> sk_msg_recvmsg function.
> 
> Fixes: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface")
> Signed-off-by: Liu Jian <liujian56@huawei.com>
> ---

Yep thanks. We have another fix coming for a similar case with ENOMEM
through backlog. I'll post here before end of week.

Acked-by: John Fastabend <john.fastabend@gmail.com>

>  net/core/skmsg.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/net/core/skmsg.c b/net/core/skmsg.c
> index 188f8558d27d..ca70525621c7 100644
> --- a/net/core/skmsg.c
> +++ b/net/core/skmsg.c
> @@ -434,8 +434,10 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
>  			if (copied + copy > len)
>  				copy = len - copied;
>  			copy = copy_page_to_iter(page, sge->offset, copy, iter);
> -			if (!copy)
> -				return copied ? copied : -EFAULT;
> +			if (!copy) {
> +				copied = copied ? copied : -EFAULT;
> +				goto out;
> +			}
>  
>  			copied += copy;
>  			if (likely(!peek)) {
> @@ -455,7 +457,7 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
>  				 * didn't copy the entire length lets just break.
>  				 */
>  				if (copy != sge->length)
> -					return copied;
> +					goto out;
>  				sk_msg_iter_var_next(i);
>  			}
>  
> @@ -477,7 +479,9 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
>  		}
>  		msg_rx = sk_psock_peek_msg(psock);
>  	}
> -
> +out:
> +	if (psock->work_state.skb && copied > 0)
> +		schedule_work(&psock->work);
>  	return copied;
>  }
>  EXPORT_SYMBOL_GPL(sk_msg_recvmsg);
> -- 
> 2.17.1
>
patchwork-bot+netdevbpf@kernel.org Sept. 26, 2022, 4 p.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Wed, 7 Sep 2022 15:13:11 +0800 you wrote:
> In sk_psock_backlog function, for ingress direction skb, if no new data
> packet arrives after the skb is cached, the cached skb does not have a
> chance to be added to the receive queue of psock. As a result, the cached
> skb cannot be received by the upper-layer application.
> 
> Fix this by reschedule the psock work to dispose the cached skb in
> sk_msg_recvmsg function.
> 
> [...]

Here is the summary with links:
  - [bpf] skmsg: schedule psock work if the cached skb exists on the psock
    https://git.kernel.org/bpf/bpf-next/c/bec217197b41

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index 188f8558d27d..ca70525621c7 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -434,8 +434,10 @@  int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
 			if (copied + copy > len)
 				copy = len - copied;
 			copy = copy_page_to_iter(page, sge->offset, copy, iter);
-			if (!copy)
-				return copied ? copied : -EFAULT;
+			if (!copy) {
+				copied = copied ? copied : -EFAULT;
+				goto out;
+			}
 
 			copied += copy;
 			if (likely(!peek)) {
@@ -455,7 +457,7 @@  int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
 				 * didn't copy the entire length lets just break.
 				 */
 				if (copy != sge->length)
-					return copied;
+					goto out;
 				sk_msg_iter_var_next(i);
 			}
 
@@ -477,7 +479,9 @@  int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
 		}
 		msg_rx = sk_psock_peek_msg(psock);
 	}
-
+out:
+	if (psock->work_state.skb && copied > 0)
+		schedule_work(&psock->work);
 	return copied;
 }
 EXPORT_SYMBOL_GPL(sk_msg_recvmsg);