Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6100033rdb; Thu, 14 Dec 2023 08:16:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/TY5Jn/y4+4ENQlyz5pcbDQ0O0qqVYZNZnm0AgCheJtoAa6Wi2HtgmW29PCHn9N79XfNA X-Received: by 2002:a17:903:2282:b0:1d3:39fd:9043 with SMTP id b2-20020a170903228200b001d339fd9043mr2705738plh.13.1702570619626; Thu, 14 Dec 2023 08:16:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702570619; cv=none; d=google.com; s=arc-20160816; b=piR5/r7jMRTGbaKDKgRLB619/x05gcN0GiPB06lbiV7+L2c4++4GGjVUmr+mR6PvMn PzWp1LO3vpKkGrIcTk+vtSHxw1uMbK28PyILOLsn2+oNaih/FUWD6XJfHes4boTyPjdh uYkhMXsaETZEd/wtTHFjxthKD7B5v4HQi+sZw/QL7cHm70z1d2vpu7/7D6tzbwsB0LP0 tC+yAdiGGWqaVgcCGPGV6OUsG6iL+IbgC0AMocg6sJ9Qtul85rtodHEzKtPK6QQ7R+2t 2fAaKdxgLh4AfySw39aixkODsoH3TCsMYhOky7Yp217ZYm3fNg/cLuZ2A96mSXmszaOS lIiw== 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=5J92rhUx9O4NC2HtcY1UYg+cIOivjlNLhe292Pbv634=; fh=mICuJ9AXYR1QndEhb7gyIK4qNKddtfEEk2Hpw4BMBSM=; b=NAA8y7BYusZvR4OhvLCgVpPKlzi1gVpYpI5KB5g5UdTZf2zLXSNDsOIm7La49Yj6Qe o2Yc4YIZKAA/dN2eIxVm7qNknn2s/88QqVdKS+HJkWWQbePUpRJICRP4RkBOvCN0E9Jw LVrnoRl4STs/atmtdlnweY3gUgryRLaEwp6pmRrF2GvUUbbQsmBUPpyGwOFUqtDLxzgZ OjcOBhvYDtS5gfk3EXBlDgGjY2pTmtpb/rWGPx8tWBEGEKRXebj5yU33eEgSJdBhfkl4 7UIZDjUdvPlYdBz4Au+t5xh4MJgoVb1lYyEA7wmMcuoMx4H9S2Wo/QUQlYLmNyhPAG19 ZpUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Lxt6IJID; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id ix19-20020a170902f81300b001d3656c64b2si1475867plb.155.2023.12.14.08.16.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 08:16:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Lxt6IJID; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 7EC978183EEC; Thu, 14 Dec 2023 08:16:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443504AbjLNQQm (ORCPT + 99 others); Thu, 14 Dec 2023 11:16:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbjLNQQl (ORCPT ); Thu, 14 Dec 2023 11:16:41 -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 D908910E; Thu, 14 Dec 2023 08:16:46 -0800 (PST) Received: by mail-ej1-x642.google.com with SMTP id a640c23a62f3a-a22fb5f71d9so160488666b.0; Thu, 14 Dec 2023 08:16:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702570605; x=1703175405; 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=5J92rhUx9O4NC2HtcY1UYg+cIOivjlNLhe292Pbv634=; b=Lxt6IJIDMJIEp8j3cRC2+e6T9lNqC5gC35omrlh1rZIM23wUvb0Ak/3X6H21mkbua3 Sy49mb0MvrzyqQ5HW4vnr3HG0MPd71NM9MPUBxeTBu/nwarciLqkZu8v1VD41/3P7eme fTOXcSI1hnV9CUXt/DFnmx26TMwmtMO0wpzKPrOEHebRn4OQDaLO1VxN+UgK/65+8Rb+ uCZFzgvxjXZyqQtePbbR10Yvdcq6WuWI3bJ8W9I+mW+TWsIxsPYiwvFMS0nSaIjoUlTm zWOWgSEyQU0yCgu224KCEu7AUkaFnP3xdDG3uXEKQCvIS14FlK2LkhAuh48gJPOK4j76 DEOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702570605; x=1703175405; 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=5J92rhUx9O4NC2HtcY1UYg+cIOivjlNLhe292Pbv634=; b=U0AUsWY/v75NdWoYiVl7P4unRtNgq4ssQvOmscn/JNlD8gjL2xPnrcwDmlMd5CC+Xh n27NAXFihERq66NR3Gv2fCJBROmfsh3vffA/tHv8N8XIy7iLpq4RgEDysiMxMbFSCiyB rHd9tNm05R5OltVv6i0SboOXrCvzFHD78Tw23nuJ3ZUqR7nby9zSoF467UKkZkrHOm9g znQbrghK9X009XtQsWfcUotqCYkkrD82Hl9jZqux5l40QO92o07zPLbetCQqEChQTj0f sHMs2+IZXlFMbW5UvuIzDp5vx3qd5rHihILytyEsSbsbkJ0QPEawP41fVkjTEPaTn//n BysA== X-Gm-Message-State: AOJu0YwkAv+3XvwhJJzsua7La+Lkhh3cd9avUyjM4Z7GxNC+UaPpr0XU Guwa6yX1E09YbUHNId8yf2+fzefiypYX3ePZJgUiHcsIVq8= X-Received: by 2002:a17:907:2e02:b0:a23:f55:8825 with SMTP id ig2-20020a1709072e0200b00a230f558825mr1101594ejc.37.1702570605252; Thu, 14 Dec 2023 08:16:45 -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:16:08 +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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 14 Dec 2023 08:16:56 -0800 (PST) On Thu, 14 Dec 2023 at 17:08, Kumar Kartikeya Dwivedi wr= ote: > > 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 b= y > > > > BPF_PROG_TYPE_XDP. I would simply register the generic_kfunc_set fo= r > > > > 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_m= eta, > > > > > but I can run the exceptions selftests just fine with the same bz= Image. > > > > > 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 sendin= g > > > > 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= to > > > > 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 i= n 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_experimen= tal.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/se= lftests/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(va= lue), ___i++) > > > > Ah, yes, that's a typo. Eyal is right, it should be ___i. Additionally, I would modify the macro to do ___j =3D !!(cond).