Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6183857rdb; Thu, 14 Dec 2023 10:23:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1OJYWozfzfqUxCQg9SHR1UUXuGjYaleLYaC2sSZ18NNXPHV/pls1lE78tBhBGLEoAhDyB X-Received: by 2002:a05:6a20:5525:b0:187:6dd3:946c with SMTP id ko37-20020a056a20552500b001876dd3946cmr5488508pzb.61.1702578205323; Thu, 14 Dec 2023 10:23:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702578205; cv=none; d=google.com; s=arc-20160816; b=odKZGqGQK4+sqqc3OO2/Nz2G3UsFvQp2BZRcaZM/FZ8jID0CMbyPSTIXAl+/x+vvyN b156se8OiR/C2Z1u9AGNVGmmKqg7MiwKTQlJSyaSq1Op+CXIPhqzJv5tyPl4DJaJ22xT SIxFjiK/CiDLnB3KVqWbjvVUKdHpjY24ShiC9s+Hiy4SlrOn/yVqzP0HgSs6e8lXdSj5 faTvKm0mKTazL/GLbeTnrIvUlf3Ei8PcyFUEy04ncdW/wYN3JSb7eSeR0vM/TMblJ7A8 aFO6qzCFhbchy2AFaqSwtRDmNs0NZJ+6y4Rx7A1S+cZWLKyowCmTqrJM3VNyOpZTMNAS y66A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature:dkim-signature; bh=jO8QFkyxT8UnwR2dcix1epeyX1NgYymqMvBUkD8jyH4=; fh=vECZytdXh6a3Ju9hRW8JL+heHRk4yVgE6Mm6okRFTOM=; b=1JOeEOAaBE2vGVO9EMS453LGmFzd/KzYGjw9rdLKJKhHOQn/g5ZPA8YHkgUd5LPD3P 0+B2zjZZOPJKYxdY1Sztpfpox5el9ZHUaSqFJaXSsSrqxESO/zHJuX+sGQWcmrJ8wTl1 k0GAtGoX0eEV8DHXiVbUdmcUYEyytkBFD7hkBJS2BXuBovD82WNk8Q8Li5xi7phcFuod Ht0PomcuTUATwbLlWru0h0maDI0Q8qIYjQkX7wqzqoDuBK9JRGvdAk/hCzLG4qT75CaW r6y9Scr8jkvThp8Kn8OiSzg95qmJYXqF4dexViHfI3ihG6BWGJYcbAW3yW2QKC7bl/yd se8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=LqG+BjVV; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Bpbf0Ttm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id br15-20020a17090b0f0f00b0028b1abb0afasi646173pjb.100.2023.12.14.10.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 10:23:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=LqG+BjVV; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Bpbf0Ttm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 48BEA8705E9F; Thu, 14 Dec 2023 10:23:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230513AbjLNSXH (ORCPT + 99 others); Thu, 14 Dec 2023 13:23:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbjLNSXF (ORCPT ); Thu, 14 Dec 2023 13:23:05 -0500 Received: from wnew3-smtp.messagingengine.com (wnew3-smtp.messagingengine.com [64.147.123.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9923310A; Thu, 14 Dec 2023 10:23:11 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.west.internal (Postfix) with ESMTP id 022982B000CF; Thu, 14 Dec 2023 13:23:06 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 14 Dec 2023 13:23:09 -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=1702578186; x=1702585386; bh=jO8QFkyxT8UnwR2dcix1epeyX1NgYymqMvBUkD8jyH4=; b= LqG+BjVVn4Z890upuU+L9WS2St9a3ZnojxXfbpRBnK7O9s2AS1bMbGNSKHeOT/1w SoCPQ+MBULtS7Es1+sV64ePILKocDVHsHh+rHbHd/2SpuFK9O3OLyRJMFKDWvgXM v7lAPyYZ1l96d6ljhskKAmvwnt8kLfo6etclrSfWLi+dtnBbVeCFjTS6+pvNNDWD ym391Yw+8+XG5bNc4vvQT5Rz/8mZ/iF3vlRrv/U14SshKjU/3UFHOQo6+3zLPXzA rDdlBXQTNg5Nx/z5fB+XqvNGGW/ZDsTZwvhH3/wHRfq2KpRcNichLdVp9e+EDQYL 9cKCRRhJxfYQDGmZWpJHLA== 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=1702578186; x= 1702585386; bh=jO8QFkyxT8UnwR2dcix1epeyX1NgYymqMvBUkD8jyH4=; b=B pbf0Ttm/qZDdaZfK8by5DZs02Zn4xHoqby1dDmnF+SD1Fe9pC5JjQ0/gez6wgo/i fqqFihaMwY4HGlE6PyatQ9TPk4JzYHPtKJu4bjTMbL4XGMUM8yNHn7SQUmZAfRyY 4DH/spKE2Ddh+5J29by+fhiVIitOzsBS4Q9dZUbVF2dm+WgYFaANjQnYBTxBXj6d EHvzAHb93C05ysNj/vymwaEfXmvXBrSqhR/MYkTeaIKMET1r8+sgUXvCXFdo0q7G YppJqaaz/gk1RDvoCk3h2ex7u0ZLOrMQmE0PxpQ5Pkte5LWXvKphKobRFAg5rd16 58ww+AcHucbFNQsitTeKg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudelledguddutdcutefuodetggdotefrod 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 13:23:03 -0500 (EST) Date: Thu, 14 Dec 2023 11:23:02 -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: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 14 Dec 2023 10:23:22 -0800 (PST) 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.