Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4996672rwb; Mon, 31 Jul 2023 16:21:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlHuLFwc4TboCKRV2jYrRNO4v64YsSI35LAm/u771KXAlMQl5sJAtk9rBTD2mH7NYY6C6WJz X-Received: by 2002:a05:6808:1485:b0:3a7:4802:c50 with SMTP id e5-20020a056808148500b003a748020c50mr1218903oiw.10.1690845692726; Mon, 31 Jul 2023 16:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690845692; cv=none; d=google.com; s=arc-20160816; b=VA8FFheW4lgBZ/3tQp5FNu183uKFOFJ87ijSqHVMFGO50uMsPSrnsPaf4y7TH+WOsm pCLCakUUbBfCxreQc4mjBBX8Y9liwQOzHRT2w7z5dExod/zKLit1Aw8cuh2VFGgRAf1e CeC5kuqpOQge5bRJ29Cdol6KBfhY0lwXU3yhNyq4aYIkdKkcv4ZfZyQtYARtqbwKPFXi pVltWjl8Ss2WlfT2O2KxOYoL7XLPsLF4V/QLPR+6lWHZy36RUfR4jv5qXQ9cY6YttrGQ WB0Bz+jyVNE5tlfKgEdjxH+fgtWsVzMcQ8Sq9Zd/I7jBuReFLMSFOCo458dc0blFRiI5 +Wbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=OoQ6AMqbH7T3p3Yr5Pye74Q6WCQZL+lK6DdYCEXr40o=; fh=GO0IyLN1GTX2QAA2ka6TV70Ize3sdrnke/p7wPLdrcE=; b=ZfbMZqQ8wH/YmI1B0ceRznP5cvfMh5LiWZgx5AHbSUo45XIkIJDx7tJbXm7n4Spizh z2nHdTmtCK+4nnisQGi2CEW8hUBFbM7CXbPTgWs3dGhfAgVC8JDDiWozhDZQ8dXOaIPq gB4RVBNasu5G7O/ZglE2NadIpSto2UjLIlnjCNqSOLgrOoQ5hA7fB6Lw6rAMeSJredeR 2/ZFgmzet8738b4GbvW1BhyYt/4X6kHNd6sxxWfzjSd1Oq+HYWlQMZOIK0ziDtLfKaiZ 9TT5Uc5a9TUuixVBke30zZ65DqIqjx2WCe7SO7R1nJQh3LGPyH8yflVec0ObtxbfCaR5 ua0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=YDtNwl2g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cx2-20020a17090afd8200b00263d0beafafsi5428064pjb.181.2023.07.31.16.21.20; Mon, 31 Jul 2023 16:21:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=YDtNwl2g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230153AbjGaVf6 (ORCPT + 99 others); Mon, 31 Jul 2023 17:35:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230089AbjGaVfp (ORCPT ); Mon, 31 Jul 2023 17:35:45 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BDB4126 for ; Mon, 31 Jul 2023 14:35:17 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5221cf2bb8cso7304232a12.1 for ; Mon, 31 Jul 2023 14:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; t=1690839313; x=1691444113; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OoQ6AMqbH7T3p3Yr5Pye74Q6WCQZL+lK6DdYCEXr40o=; b=YDtNwl2gvEdzUtsqGkrJjlUralI+dGLNS813sAQedgc5FSaOYZgvtEZA5Z6tcC5UzI mAbX/ZGY5EoRq2jjO8qgvt2qAHUGcfWv5FM3ponM9TkB2ywUB90eka8w3BAjewqY0rnv qprjOTgYL1vA4ZCIVQBHw0ksn9cr7Ls/qYsFA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690839313; x=1691444113; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OoQ6AMqbH7T3p3Yr5Pye74Q6WCQZL+lK6DdYCEXr40o=; b=RMgUxq5QxxKt6hl2/ta/YVD7T1nXZUmXoNvaYiIGI7CB5Rq/8FVOvV4PQvkTrYwx8P HUKl1h1PRmcH8IrxvVOvliFQihwEdFnv4a5gugl18eLn3oxPOJKhaKc8fmt53j1io7IW B1cF28D5Yv6h+L5WcUo+LHyaJOIrMc/4Pw2Ur+teqwdgjYkLTGvRqfBT2wgcdyuLA6Os c1ei7HXAW8SPbGOSp4FKSBmFbm0Y1ryv8ipaf1wSbxZ8BPnZbXvLtDeqcXqHVjy4tp6+ GGX0BxS+TDrl0F67MuXXCrV/kSrw0q/59fpO16kQMdOHxfOq5LsPS3eAvDqhaWG61r8I UNEA== X-Gm-Message-State: ABy/qLY4qqRWZRuyQ3mKj192um5xI+aB/asUCsn2+kK4BaiRzoVg8Oxv ITSndCxPz4KFnIFlL3MM/FgElZNeBv0WwNrrGflUZg== X-Received: by 2002:aa7:d311:0:b0:522:4dd0:de6e with SMTP id p17-20020aa7d311000000b005224dd0de6emr825060edq.8.1690839312703; Mon, 31 Jul 2023 14:35:12 -0700 (PDT) MIME-Version: 1.0 References: <266ab56e-ae83-7ddc-618e-3af228df81bd@linux.dev> In-Reply-To: <266ab56e-ae83-7ddc-618e-3af228df81bd@linux.dev> From: Yan Zhai Date: Mon, 31 Jul 2023 16:35:01 -0500 Message-ID: Subject: Re: [PATCH v4 bpf 1/2] bpf: fix skb_do_redirect return values To: Martin KaFai Lau Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Mykola Lysenko , Shuah Khan , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@cloudflare.com, Jordan Griege , Markus Elfring , Jakub Sitnicki Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 28, 2023 at 5:02=E2=80=AFPM Martin KaFai Lau 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 consume= d 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_pe= er > helper available, so there is no -EAGAIN case in lwt. iow, skb_do_redirec= t > 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 =3D=3D 0)" test in run_lwt_bpf() is unnecessary? > > ret =3D skb_do_redirect(skb); > if (ret =3D=3D 0) > ret =3D 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. 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