Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6094080rdb; Thu, 14 Dec 2023 08:09:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhbrZUhwUMeNh23LbcBdeUkaSyBh8rmTtI7q/PfeG6zkQg1Lai1nwblsCeZ6DUOtW0+0DE X-Received: by 2002:a17:903:1207:b0:1d0:c0d3:5c1 with SMTP id l7-20020a170903120700b001d0c0d305c1mr5767706plh.102.1702570168650; Thu, 14 Dec 2023 08:09:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702570168; cv=none; d=google.com; s=arc-20160816; b=kjnenJgnoWuS00LwH6a5wetirvRxXA2KCrV7OlcilUTYOtpUeXhZYvyUGXKjZ4P65y GEx8D5KPmvIB+uohyW9Eod5Uwbg9qMubKgist0Eyu9CtgsJVdUYbB1uCnIMb5BVExeaR jHxWG6VdbcSR3Rx3GRjRe9+zeh/DqKh03QWykzcRIPB1owUXqNepN64+zR7ANVMadOZw ReTgyqlx44wGceUQl173YtgLs2bnfVLqvn4RE3esk+68YeghqBLVkLLY3zr0BW+To9tq wnWTqkeWe/gxOPoaY1mICsWGogaX20eC9DZDLdI/2V1ypxUEL7o0VCqHXa/YVzX7fndw s0Bg== 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=irrGSo/jXwM5O23C0Oho2ggjcoMi5gY8zL2PFLKo9UM=; fh=mICuJ9AXYR1QndEhb7gyIK4qNKddtfEEk2Hpw4BMBSM=; b=vLqNHbt7FhRABAtFIZtBMSG6AQW1JeWLywYgS/nG21dmYhUf0+h5B0JgJdBez22n3c n+n7+W1FE1yAbuvrndFBSgC2VybCl1VmZU5F50UgL4+xMLldcmJJGySt8Xq17cAuTvV8 Yoz7TthY2ZiMpWCkZUNq+ZBNDE9Btby9VJRMRyzqFQFX1JbuYAHYf79qiJLKa+7VyR1c wkIHavKtsE7awOpTtW//ecUlPAOnn6o2o7okfJaZgqlvV/Nbt4W8rEz0k1hFzP300yVi XRO2xQQO2z4v4Zo2bNgdOmuXxacdItYx9hwQc8mOuz7ddFlte50MXj/XBK2ONSJF6meR SC3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GoV+v3N7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id t7-20020a170902bc4700b001d0ba4101e0si1232546plz.381.2023.12.14.08.09.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 08:09:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GoV+v3N7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 40BF8801CE82; Thu, 14 Dec 2023 08:09:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443555AbjLNQJK (ORCPT + 99 others); Thu, 14 Dec 2023 11:09:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229599AbjLNQJJ (ORCPT ); Thu, 14 Dec 2023 11:09:09 -0500 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 323C911A; Thu, 14 Dec 2023 08:09:15 -0800 (PST) Received: by mail-ej1-x642.google.com with SMTP id a640c23a62f3a-a22ed5f0440so432018966b.1; Thu, 14 Dec 2023 08:09:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702570153; x=1703174953; darn=vger.kernel.org; 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=irrGSo/jXwM5O23C0Oho2ggjcoMi5gY8zL2PFLKo9UM=; b=GoV+v3N7S8oYd+BUHRx/upiZGCx7B7MeiXfKpNNtiqkTaT+DSIu2hdmOtGfFVjlUj/ 7hUobDR2nGCvm6upMNWLodK5QgYTQ3FEk6mWkxsz4Qrn43M00zOiOuDEraoCwMXNfoWS HwVc2w7mZZZ/pZFxEoViHxgBQI+d6OHzQybQjB8YWcHRY90wAFm17CuLB+k/1JkUoPqm 2+J5RBkq5KlKe1jp8xRJsFbPXuX7JAc9DveIOFBzfqDH/pmCyAvhri8GT2QKlTI5pUgQ vMDUA4tUjbsYfbE/AjfamSjOWbnaiX/tMbEuddI6OB4LC4uP5+/1ErsLbFMJnbw0Rcn2 CQZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702570153; x=1703174953; 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=irrGSo/jXwM5O23C0Oho2ggjcoMi5gY8zL2PFLKo9UM=; b=RJEoR90WNJzMkuQEJn6611jhuDAlR2TZfcXczjYijaZT6NuOc8VJJ4xCY5UcJSOM/3 6wVY8MpN09jY1xMq+I5GWMfBEriCzW4fXvEtEq7s3yzeCi2KFypFy1F3oH2TNzRAv8La NdoHYqZcWbHvzqlurEq5SrrlgG+7At5tmh9L7aea0r2R7jnuipVBCr/DdZ4dOPXGB/yZ VJi8xS+nxNTmzvjTqcLvU9QZxRRVZbGY7AbXTIvp/wwqBkq98KrW5Db52sosaMPzlwRQ jtRz1Ti+YJxvh4pRJi7TxTgufx9rAl4qVX39lvLvz7N3buvARpsFevmi51DIngSSL1Dy 1PhQ== X-Gm-Message-State: AOJu0Yy3scacbMTFTAfjk8c6MHRcYpAclSnmHypuMKReZZ9doeQZVxyH jLiNRCvpeRXUIwVsl8Vr0TiHicarkEYx3vf56bg= X-Received: by 2002:a17:906:1708:b0:a19:a19b:4238 with SMTP id c8-20020a170906170800b00a19a19b4238mr3098200eje.163.1702570153479; Thu, 14 Dec 2023 08:09:13 -0800 (PST) MIME-Version: 1.0 References: <8ec1b885d2e13fcd20944cce9edc0340d993d044.1702325874.git.dxu@dxuuu.xyz> <7yjkfhrwdphtcljq3odv4jc6lucd32wcg277hfsf4ve2jbo7hp@vuqzwbq5nxjw> In-Reply-To: From: Kumar Kartikeya Dwivedi Date: Thu, 14 Dec 2023 17:08:36 +0100 Message-ID: Subject: Re: [PATCH bpf-next v5 9/9] bpf: xfrm: Add selftest for bpf_xdp_get_xfrm_state() To: Eyal Birger Cc: Daniel Xu , daniel@iogearbox.net, davem@davemloft.net, shuah@kernel.org, ast@kernel.org, john.fastabend@gmail.com, kuba@kernel.org, andrii@kernel.org, hawk@kernel.org, steffen.klassert@secunet.com, antony.antony@secunet.com, alexei.starovoitov@gmail.com, yonghong.song@linux.dev, eddyz87@gmail.com, mykolal@fb.com, martin.lau@linux.dev, song@kernel.org, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, devel@linux-ipsec.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 14 Dec 2023 08:09:25 -0800 (PST) On Thu, 14 Dec 2023 at 00:49, Eyal Birger wrote: > > On Wed, Dec 13, 2023 at 3:15=E2=80=AFPM Daniel Xu wrote: > > > > [...] > > > > > > > > diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b= /tools/testing/selftests/bpf/progs/test_tunnel_kern.c > > > > index c0dd38616562..f00dba85ac5d 100644 > > > > --- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c > > > > +++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c > > > > @@ -8,8 +8,9 @@ > > > > */ > > > > #include "vmlinux.h" > > > > #include > > > > -#include > > > > #include > > > > +#include > > > > +#include "bpf_experimental.h" > > > > #include "bpf_kfuncs.h" > > > > #include "bpf_tracing_net.h" > > > > > > > > @@ -988,8 +989,9 @@ int xfrm_get_state_xdp(struct xdp_md *xdp) > > > > opts.family =3D AF_INET; > > > > > > > > x =3D bpf_xdp_get_xfrm_state(xdp, &opts, sizeof(opts)); > > > > - if (!x || opts.error) > > > > + if (!x) > > > > goto out; > > > > + bpf_assert_with(opts.error =3D=3D 0, XDP_PASS); > > > > > > > > if (!x->replay_esn) > > > > goto out; > > > > > > > > results in: > > > > > > > > 57: (b7) r1 =3D 2 ; R1_w=3D2 refs=3D5 > > > > 58: (85) call bpf_throw#115436 > > > > calling kernel function bpf_throw is not allowed > > > > > > > > > > I think this might be because bpf_throw is not registered for use by > > > BPF_PROG_TYPE_XDP. I would simply register the generic_kfunc_set for > > > this program type as well, since it's already done for TC. > > > > Ah yeah, that was it. > > > > > > > > > It looks like the above error comes from verifier.c:fetch_kfunc_met= a, > > > > but I can run the exceptions selftests just fine with the same bzIm= age. > > > > So I'm thinking it's not a kfunc registration or BTF issue. > > > > > > > > Maybe it's cuz I'm holding onto KFUNC_ACQUIRE'd `x`? Not sure. > > > > > > > > > > Yes, even once you enable this, this will fail for now. I am sending > > > out a series later this week that enables bpf_throw with acquired > > > references, but until then may I suggest the following: > > > > > > #define bpf_assert_if(cond) for (int ___i =3D 0, ___j =3D (cond); !(_= __j) \ > > > && !___j; bpf_throw(), ___i++) > > > > > > This will allow you to insert some cleanup code with an assertion. > > > Then in my series, I will convert this temporary bpf_assert_if back t= o > > > the normal bpf_assert. > > > > > > It would look like: > > > bpf_assert_if(opts.error =3D=3D 0) { > > > // Execute if assertion failed > > > bpf_xdp_xfrm_state_release(x); > > > } > > > > > > Likewise for bpf_assert_with_if, you get the idea. > > > > I gave it a try and I'm getting this compile error: > > > > progs/test_tunnel_kern.c:996:2: error: variable '___j' used in = loop condition not modified in loop body [-Werror,-Wfor-loop-analysis] > > bpf_assert_with_if(opts.error =3D=3D 0, XDP_PASS) { > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > /home/dxu/dev/linux/tools/testing/selftests/bpf/bpf_experimenta= l.h:295:38: note: expanded from macro 'bpf_assert_with_if' > > for (int ___i =3D 0, ___j =3D (cond); !(___j) && !___j;= bpf_throw(value), ___i++) > > ^~~~ ~~~~ > > 1 error generated. > > make: *** [Makefile:618: /home/dxu/dev/linux/tools/testing/self= tests/bpf/test_tunnel_kern.bpf.o] Error 1 > > > > Seems like the compiler is being clever. > > It looks like ___j is used twice - maybe it was meant to be ___i? i.e.: > > for (int ___i =3D 0, ___j =3D (cond); !(___j) && !___i; bpf_throw(valu= e), ___i++) > Ah, yes, that's a typo. Eyal is right, it should be ___i.