Skip to content

Commit 54f89b3

Browse files
Cong Wangborkmann
authored andcommitted
tcp_bpf: Charge receive socket buffer in bpf_tcp_ingress()
When bpf_tcp_ingress() is called, the skmsg is being redirected to the ingress of the destination socket. Therefore, we should charge its receive socket buffer, instead of sending socket buffer. Because sk_rmem_schedule() tests pfmemalloc of skb, we need to introduce a wrapper and call it for skmsg. Fixes: 604326b ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: Cong Wang <cong.wang@bytedance.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20241210012039.1669389-2-zijianzhang@bytedance.com
1 parent 716f2bc commit 54f89b3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

include/net/sock.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,15 +1527,21 @@ static inline bool sk_wmem_schedule(struct sock *sk, int size)
15271527
}
15281528

15291529
static inline bool
1530-
sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
1530+
__sk_rmem_schedule(struct sock *sk, int size, bool pfmemalloc)
15311531
{
15321532
int delta;
15331533

15341534
if (!sk_has_account(sk))
15351535
return true;
15361536
delta = size - sk->sk_forward_alloc;
15371537
return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) ||
1538-
skb_pfmemalloc(skb);
1538+
pfmemalloc;
1539+
}
1540+
1541+
static inline bool
1542+
sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
1543+
{
1544+
return __sk_rmem_schedule(sk, size, skb_pfmemalloc(skb));
15391545
}
15401546

15411547
static inline int sk_unused_reserved_mem(const struct sock *sk)

net/ipv4/tcp_bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock,
4949
sge = sk_msg_elem(msg, i);
5050
size = (apply && apply_bytes < sge->length) ?
5151
apply_bytes : sge->length;
52-
if (!sk_wmem_schedule(sk, size)) {
52+
if (!__sk_rmem_schedule(sk, size, false)) {
5353
if (!copied)
5454
ret = -ENOMEM;
5555
break;

0 commit comments

Comments
 (0)