From: Martin KaFai Lau <martin.lau@linux.dev>
To: Yan Zhai <yan@cloudflare.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>, Song Liu <song@kernel.org>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Mykola Lysenko <mykolal@fb.com>, Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
linux-kselftest@vger.kernel.org, kernel-team@cloudflare.com,
Jordan Griege <jgriege@cloudflare.com>,
Markus Elfring <Markus.Elfring@web.de>,
Jakub Sitnicki <jakub@cloudflare.com>
Subject: Re: [PATCH v4 bpf 1/2] bpf: fix skb_do_redirect return values
Date: Mon, 31 Jul 2023 15:11:27 -0700 [thread overview]
Message-ID: <2f285967-6cc0-c492-6a79-edc233c1368e@linux.dev> (raw)
In-Reply-To: <CAO3-Pbon7tCdChnK9kZ4992C-AFPvE5gTDWre6dQT9npEMxS2Q@mail.gmail.com>
On 7/31/23 2:35 PM, Yan Zhai wrote:
> On Fri, Jul 28, 2023 at 5:02 PM Martin KaFai Lau <martin.lau@linux.dev> wrote:
>>
>> On 7/25/23 6:08 PM, Yan Zhai wrote:
>>> skb_do_redirect returns various of values: error code (negative),
>>> 0 (success), and some positive status code, e.g. NET_XMIT_CN,
>>> NET_RX_DROP. Commit 3a0af8fd61f9 ("bpf: BPF for lightweight tunnel
>>> infrastructure") didn't check the return code correctly, so positive
>>> values are propagated back along call chain:
>>>
>>> ip_finish_output2
>>> -> bpf_xmit
>>> -> run_lwt_bpf
>>> -> skb_do_redirect
>>
>> From looking at skb_do_redirect, the skb_do_redirect should have consumed the
>> skb except for the -EAGAIN return value. afaik, -EAGAIN could only happen by
>> using the bpf_redirect_peer helper. lwt does not have the bpf_redirect_peer
>> helper available, so there is no -EAGAIN case in lwt. iow, skb_do_redirect
>> should have always consumed the skb in lwt. or did I miss something?
>>
>> If that is the case, it feels like the fix should be in run_lwt_bpf() and the
>> "if (ret == 0)" test in run_lwt_bpf() is unnecessary?
>>
>> ret = skb_do_redirect(skb);
>> if (ret == 0)
>> ret = BPF_REDIRECT;
>>
>>
> Just fixing skb redirect return code won't be sufficient. I realized
> there are other return paths that need to be treated, e.g. bpf reroute
> path also directly returns dev_queue_xmit status. I plan to check for
> LWTUNNEL_XMIT_CONTINUE (and change it to a value that does not
> conflict with NET_RX_DROP and NET_XMIT_DROP) in the next revision. On
> the other hand, the return value of NETDEV_TX_BUSY is another hassle.
I suspect we are talking about different things or I am still missing something.
I was thinking skb_do_redirect() should have always consumed the skb and
bpf_xmit should always return LWTUNNEL_XMIT_DONE also (instead of
LWTUNNEL_XMIT_CONTINUE described in the this patch commit message). It is what
sch_handle_egress() is doing also. Could you explain how is it different from
the skb_do_redirect usage in sch_handle_egress() or you are suggesting the
current sch_handle_egress() has the issue too also?
> As Dan suggested, packets might not have been freed when this is
> returned from drivers. The caller of dev_queue_xmit might need to free
> skb when this happens.
>
> Yan
next prev parent reply other threads:[~2023-07-31 22:11 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-26 1:07 [PATCH v4 bpf 0/2] bpf: return proper error codes for lwt redirect Yan Zhai
2023-07-26 1:08 ` [PATCH v4 bpf 1/2] bpf: fix skb_do_redirect return values Yan Zhai
2023-07-26 7:42 ` Markus Elfring
2023-07-26 11:48 ` Markus Elfring
2023-07-26 12:25 ` Jakub Sitnicki
2023-07-26 13:39 ` Dan Carpenter
2023-07-26 14:14 ` Yan Zhai
2023-07-26 15:01 ` Dan Carpenter
2023-07-26 16:10 ` Yan Zhai
2023-07-26 16:53 ` Dan Carpenter
2023-07-31 14:26 ` Dan Carpenter
2023-08-01 22:18 ` Yan Zhai
2023-07-28 22:02 ` Martin KaFai Lau
2023-07-31 21:35 ` Yan Zhai
2023-07-31 22:11 ` Martin KaFai Lau [this message]
2023-07-31 23:01 ` Yan Zhai
2023-07-31 23:52 ` Martin KaFai Lau
2023-07-26 1:09 ` [PATCH v4 bpf 2/2] bpf: selftests: add lwt redirect regression test cases Yan Zhai
2023-07-26 8:10 ` Markus Elfring
[not found] ` <CAO3-PbraNcfQnqHUG_992vssuA795RxtexYsMdEo=k9zp-XHog@mail.gmail.com>
2023-07-26 10:30 ` Yan Zhai
2023-07-26 13:22 ` Dan Carpenter
2023-07-26 11:04 ` [v4 " Markus Elfring
2023-07-26 12:26 ` [PATCH v4 " Jakub Sitnicki
2023-07-28 22:47 ` Martin KaFai Lau
2023-07-31 9:48 ` Jakub Sitnicki
2023-07-31 18:46 ` Alexei Starovoitov
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=2f285967-6cc0-c492-6a79-edc233c1368e@linux.dev \
--to=martin.lau@linux.dev \
--cc=Markus.Elfring@web.de \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=jakub@cloudflare.com \
--cc=jgriege@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@cloudflare.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mykolal@fb.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yan@cloudflare.com \
--cc=yhs@fb.com \
/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;
as well as URLs for NNTP newsgroup(s).