Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5046229rwb; Mon, 31 Jul 2023 17:24:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlFGOPkffV9CPWBzqiAuoygcFhyN9TolvZ9EVdWWh9eA28lR25f4SItsDzuJ6/84wdUI31C4 X-Received: by 2002:a05:6808:bd1:b0:3a7:470a:e702 with SMTP id o17-20020a0568080bd100b003a7470ae702mr1613721oik.16.1690849498976; Mon, 31 Jul 2023 17:24:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690849498; cv=none; d=google.com; s=arc-20160816; b=eUqfVXwLrFpBBkBa/4QwXSdP2O2Bh1a62T4sE12LhkL21F0i/M4u2DfS4rv/U4vJ7O fdYIcAScxFZlsWSgUNiInw66lop21FoVvNLREmq8bHFIIkRaG0/y3OtVRxLeZlk9rf13 lbRDUrwGWloPQ/l+4taLKeJjsVLtnLEHuw5Zw5tPy5i0VYXdBpc9A6NykfchgFziLygY bfgkSH5Wxt7NkDyLCKckhBVkFsvIc3LSOgGeI710itGPpEmhPJll9ikkmaabIGamkNmF GaZZXR+tUIJLAe4QqCWFB1C/NZjE2jvtLro+z9pmr76pyKhU+M3MkXW8BDPzHfVQrQVl GbWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:mime-version:date :dkim-signature:message-id; bh=xeaSvsYEmBCskRg+zXZEB8g7ybgRHrMcw1QMHD9iWQU=; fh=Y9oS8IEtZ89Fm0x8bg3UBmK/eL30cPuOlM1f8vIZueo=; b=zmamqBmpHgHt8kdVDVWC7noojBQp8uuQiX4f64WzoYzdPzCSk1tkHIFQ4Z4unCmFyW HMoGV+gabrpJuF6yALX3hKasJTbJ5hbS/W0erKhSzsHgbaVqABZO/lqcIFDTQx4eyjty +ks9CySQY+DuUClYGo+Uw5/Baq24jVloHp5gUmqCTUzKaxPl2gFGikRLlzrbSqJak8/i L8MyqlNufBeU820HUveczygktO6w0BP5QV4nesDgKx2kORBP4DsydkMJlpAi54rJrhER WYEQeImnMcQjfxKc0PV+e+Ufa48ewVtMM3zcBz5PJojyMXwOHHVH+4mPZ+x1qBwKcK2o JUPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=gK5DS9Fx; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qe6-20020a17090b4f8600b00267b910cb37si8298710pjb.52.2023.07.31.17.24.47; Mon, 31 Jul 2023 17:24:58 -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=@linux.dev header.s=key1 header.b=gK5DS9Fx; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231802AbjGaWLo (ORCPT + 99 others); Mon, 31 Jul 2023 18:11:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbjGaWLn (ORCPT ); Mon, 31 Jul 2023 18:11:43 -0400 Received: from out-88.mta0.migadu.com (out-88.mta0.migadu.com [IPv6:2001:41d0:1004:224b::58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A05911997 for ; Mon, 31 Jul 2023 15:11:38 -0700 (PDT) Message-ID: <2f285967-6cc0-c492-6a79-edc233c1368e@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1690841496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xeaSvsYEmBCskRg+zXZEB8g7ybgRHrMcw1QMHD9iWQU=; b=gK5DS9Fx2+hSI7gjnc8FtEEQbSogDfp/j111F6w2/hWCyTZBR/aCcytDVq3X3mWU9hoMe6 42zEZTj2zEIkkhioOiSoP+xmAyngv31miQzdtMhmqSmLk0Ty3coELK32xt11Lhq8R7xdEd MZDqtW5LJb1/bvGZ5N+RNI36ctNAY8Q= Date: Mon, 31 Jul 2023 15:11:27 -0700 MIME-Version: 1.0 Subject: Re: [PATCH v4 bpf 1/2] bpf: fix skb_do_redirect return values Content-Language: en-US To: Yan Zhai 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 References: <266ab56e-ae83-7ddc-618e-3af228df81bd@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 7/31/23 2:35 PM, Yan Zhai wrote: > On Fri, Jul 28, 2023 at 5:02 PM 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 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