Commit 57452d76 authored by Cong Wang's avatar Cong Wang Committed by Daniel Borkmann

skmsg: Get rid of skb_clone()

With ->read_skb() now we have an entire skb dequeued from
receive queue, now we just need to grab an addtional refcnt
before passing its ownership to recv actors.

And we should not touch them any more, particularly for
skb->sk. Fortunately, skb->sk is already set for most of
the protocols except UDP where skb->sk has been stolen,
so we have to fix it up for UDP case.
Signed-off-by: default avatarCong Wang <cong.wang@bytedance.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20220615162014.89193-4-xiyou.wangcong@gmail.com
parent 965b57b4
...@@ -1167,10 +1167,7 @@ static int sk_psock_verdict_recv(struct sock *sk, struct sk_buff *skb) ...@@ -1167,10 +1167,7 @@ static int sk_psock_verdict_recv(struct sock *sk, struct sk_buff *skb)
int ret = __SK_DROP; int ret = __SK_DROP;
int len = skb->len; int len = skb->len;
/* clone here so sk_eat_skb() in tcp_read_sock does not drop our data */ skb_get(skb);
skb = skb_clone(skb, GFP_ATOMIC);
if (!skb)
return 0;
rcu_read_lock(); rcu_read_lock();
psock = sk_psock(sk); psock = sk_psock(sk);
...@@ -1183,12 +1180,10 @@ static int sk_psock_verdict_recv(struct sock *sk, struct sk_buff *skb) ...@@ -1183,12 +1180,10 @@ static int sk_psock_verdict_recv(struct sock *sk, struct sk_buff *skb)
if (!prog) if (!prog)
prog = READ_ONCE(psock->progs.skb_verdict); prog = READ_ONCE(psock->progs.skb_verdict);
if (likely(prog)) { if (likely(prog)) {
skb->sk = sk;
skb_dst_drop(skb); skb_dst_drop(skb);
skb_bpf_redirect_clear(skb); skb_bpf_redirect_clear(skb);
ret = bpf_prog_run_pin_on_cpu(prog, skb); ret = bpf_prog_run_pin_on_cpu(prog, skb);
ret = sk_psock_map_verd(ret, skb_bpf_redirect_fetch(skb)); ret = sk_psock_map_verd(ret, skb_bpf_redirect_fetch(skb));
skb->sk = NULL;
} }
if (sk_psock_verdict_apply(psock, skb, ret) < 0) if (sk_psock_verdict_apply(psock, skb, ret) < 0)
len = 0; len = 0;
......
...@@ -1819,6 +1819,7 @@ int udp_read_skb(struct sock *sk, skb_read_actor_t recv_actor) ...@@ -1819,6 +1819,7 @@ int udp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
continue; continue;
} }
WARN_ON(!skb_set_owner_sk_safe(skb, sk));
used = recv_actor(sk, skb); used = recv_actor(sk, skb);
if (used <= 0) { if (used <= 0) {
if (!copied) if (!copied)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment