Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6248483rdb; Thu, 14 Dec 2023 12:25:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5BOn6zm4PIPZlA5J5Dl8yOCErmsqruH9cLAQxMVF3CkTtOhgEaVNGEbq9DmVJnVnkJ6qK X-Received: by 2002:a05:6a20:65b0:b0:190:6d:1c5a with SMTP id p48-20020a056a2065b000b00190006d1c5amr10124163pzh.56.1702585514569; Thu, 14 Dec 2023 12:25:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702585514; cv=none; d=google.com; s=arc-20160816; b=sWzRdTvVRV4fctbxaF+CSKC/Y5IrMmUlVJy7RgPdUXWeWbQcj4WEbZkAqAlob5//wk FykNhvIblZB1B+vxqApyEMLgZg/yWxbm+oP6B/kr6A4BcZS7FcG52Di/gQJJsWPeGCvR esGqSSPbpng9ETYL4XCv69g+V7orALzpkfyXjhes23T9WHiIBJEvqqbWPB7felUgdjal 1+0OIi/rSF/0NeIF8SodLEJ50R3uxJVwhyj+zDIXB0RBvEVSxBYDNdSIaDVlQugPFiZ7 ffQanP/x2ASM+sLcThCBPHtH3t6iBQB5tKydp8VhN8brRuSXKPftqUEeKYus5c3FLaKB 1mCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=+t4pVgVSi2R2QRypiJjLIGqmBMSDOZdJg7dHN9HfN3g=; fh=vECZytdXh6a3Ju9hRW8JL+heHRk4yVgE6Mm6okRFTOM=; b=taHIst646jxSYqveBs3a7uJzLw07AZz96GUyli/cJCyRIUgkW6aFiKIAgTqYhoYgae 7mBe55ZwzTYFJ76EJKDyHR6aCPA7D3/Zj4Ctmo1vfUYtbIP0hyNnKDba3qmnCXPbMvxS u4Sif6pdeU9Oxo7tfkWaU3umTYHyYGVET3CzYLZpO8lItRjX5SlBzMBX8urrZHK+csY7 x1HdkzKrFBpeIvKxqhNxYdY9/weH8Z8/tMTwPH85xhFKu81PrxSVgGOKye5kqc/wfAuT 8KwEHu2wZMO4y+Um9Jub6czGauNOSj0MDWBjviQbQKLdzOfSXC08HpcXeS5wYwCumVwG v3Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=XssIEsre; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=n7nuOxai; spf=pass (google.com: domain of linux-kernel+bounces-64-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y190-20020a6364c7000000b005c60319034bsi11741931pgb.481.2023.12.14.12.25.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:25:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=XssIEsre; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=n7nuOxai; spf=pass (google.com: domain of linux-kernel+bounces-64-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 350212835B1 for ; Thu, 14 Dec 2023 20:25:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC1A76A34C; Thu, 14 Dec 2023 20:25:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="XssIEsre"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="n7nuOxai" X-Original-To: linux-kernel@vger.kernel.org Received: from wnew4-smtp.messagingengine.com (wnew4-smtp.messagingengine.com [64.147.123.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 821AC675CD; Thu, 14 Dec 2023 20:24:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id 346A72B007D8; Thu, 14 Dec 2023 15:24:56 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 14 Dec 2023 15:24:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1702585495; x=1702592695; bh=+t4pVgVSi2R2QRypiJjLIGqmBMSDOZdJg7dHN9HfN3g=; b= XssIEsreV4K1heTY+91HoJX52cZPmrrpOYEqSO83jF/mx/4N9g6qLaN67bxVdlrM gbQLIWXkwxqDkExCf8o5OMz2J8aWyy3eOgm1UZAbT3sEUzWeIg63AmOvo1mD+Ef8 YaraA/fKVPL8YZWtMa3YKKNttWkdo6wQ7aXGywwsf7iOpRyH7G9U+PPe5vvu6GHq irs0SMewZVr0KKLtdNWRV4ZGRD7QdMLFXE+Ih3ziDTtiJW+RaByNl4dKIcV8DRkF rt77Mf8rw/d4C0CYFA1x/ugMUTFQoJJcv+AwFFJyP5dy8MUL/Wp1wvxPwkP9jTlK cmq89oQMUShG6CPmvnovEw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1702585495; x= 1702592695; bh=+t4pVgVSi2R2QRypiJjLIGqmBMSDOZdJg7dHN9HfN3g=; b=n 7nuOxaiJegwukTTbdEOHgVrsaojYuvEbAZGMkrWLg+wxWGYwt2jmpak/zFoaI8Ei Q9lqu2AD6MNZictbUqPH+/xqEex2VCRCAdbn7vbdeOwdo7Fl1VzXi932RL0xSw/L xfa0lSqusL8YeIxoJ59m8H7fkOjd2gF4bHd+syamQJxseVcjrVbCANtuRLUBx1yR tRDqKMyZg0APRmKHsmDleWuV0JbfVq2XsgYJGzLJlEZpuQqvF1AV9SZYkBR2Vd2W PWnLCQUIHPOEVCkLIEjHCbMXEsSpc/c3ZaTso/55ETAE7/HG7ZfKiq9ii49VIZi0 ejkPVVzP93VFmU0MJviig== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudelledgudefhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enfghrlhcuvffnffculdefhedmnecujfgurhepfffhvfevuffkfhggtggugfgjsehtkefs tddttdejnecuhfhrohhmpeffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihii eqnecuggftrfgrthhtvghrnheptdfgueeuueekieekgfeiueekffelteekkeekgeegffev tddvjeeuheeuueelfeetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Dec 2023 15:24:53 -0500 (EST) Date: Thu, 14 Dec 2023 13:24:51 -0700 From: Daniel Xu To: Kumar Kartikeya Dwivedi Cc: Eyal Birger , 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 Subject: Re: [PATCH bpf-next v5 9/9] bpf: xfrm: Add selftest for bpf_xdp_get_xfrm_state() Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Dec 14, 2023 at 11:23:02AM -0700, Daniel Xu wrote: > On Thu, Dec 14, 2023 at 05:16:08PM +0100, Kumar Kartikeya Dwivedi wrote: > > On Thu, 14 Dec 2023 at 17:08, Kumar Kartikeya Dwivedi wrote: > > > > > > On Thu, 14 Dec 2023 at 00:49, Eyal Birger wrote: > > > > > > > > On Wed, Dec 13, 2023 at 3:15 PM 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 = AF_INET; > > > > > > > > > > > > > > x = bpf_xdp_get_xfrm_state(xdp, &opts, sizeof(opts)); > > > > > > > - if (!x || opts.error) > > > > > > > + if (!x) > > > > > > > goto out; > > > > > > > + bpf_assert_with(opts.error == 0, XDP_PASS); > > > > > > > > > > > > > > if (!x->replay_esn) > > > > > > > goto out; > > > > > > > > > > > > > > results in: > > > > > > > > > > > > > > 57: (b7) r1 = 2 ; R1_w=2 refs=5 > > > > > > > 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_meta, > > > > > > > but I can run the exceptions selftests just fine with the same bzImage. > > > > > > > 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 = 0, ___j = (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 == 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 == 0, XDP_PASS) { > > > > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > > /home/dxu/dev/linux/tools/testing/selftests/bpf/bpf_experimental.h:295:38: note: expanded from macro 'bpf_assert_with_if' > > > > > for (int ___i = 0, ___j = (cond); !(___j) && !___j; bpf_throw(value), ___i++) > > > > > ^~~~ ~~~~ > > > > > 1 error generated. > > > > > make: *** [Makefile:618: /home/dxu/dev/linux/tools/testing/selftests/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 = 0, ___j = (cond); !(___j) && !___i; bpf_throw(value), ___i++) > > > > > > > > > > Ah, yes, that's a typo. Eyal is right, it should be ___i. > > > > Additionally, I would modify the macro to do ___j = !!(cond). > > Makes sense. Will send out v6 with these fixes today. > Looks like only x86 supports exceptions (looking at bpf_jit_supports_exceptions()). This causes selftests in this patchset to fail on !x86, which is unfortunate. We probably want to be running these tests on all the major archs, so I will drop the assertion patches from this patchset. But since they're generally useful and I've already written the selftests for it, I could put them up in another patchset? Or maybe not cuz you're gonna fix it later anyways. WDYT? Thanks, Daniel