Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2679113rdb; Fri, 8 Dec 2023 16:08:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVv5y2btp6vkBJZdZF7kQjk3b9GRKIJHp8wbrwqKS/H8ipFBqke8202NWoABtQt68yZRyP X-Received: by 2002:a05:6871:297:b0:1fb:75a:de68 with SMTP id i23-20020a056871029700b001fb075ade68mr1117391oae.86.1702080499718; Fri, 08 Dec 2023 16:08:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702080499; cv=none; d=google.com; s=arc-20160816; b=pYdTsZ7Kptwx3wVzgPVOwPi86NvVb15Uwk6JtDUqfYLYNVQAGZOwVKR0x6A7jHvlfw rtgRUTD/LUsIlQji4eXaxWfeNBJ2IK2sRLMVfNCXdJ6DLRXB/hIUCOWUoIg1V2nsi92d WIYuliXr92kTRoKCDdtbfNezCqkJzB+wIfsd2sHawoWYYBwcdf94J71rulWlSdB4jd3Z fmBNw2JAIbx8eESQ/x1vXQnoaZCXGz3B47MX1ICoBgapogeyDARo/Znt79IxFV2f8rCh PN0gFvNa/+8jdmX4Qq5L626Rrkctz8yWj2FCMxesNjQrnw/QUfOOsOd2oJAArpqhdkYb T9Gw== 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=m98dLHyPwI+eg2Ijq83uqu7OvTQevvvXu+0DP05ozNs=; fh=/RQuIw2XQsJeWS/ve+opfL4EnlOZGBstpPMFSVXd12A=; b=RLx5AlFRftHJdp1Brc6u3U0sFL0x/SmFZiI+yekuUm6/ETjAqUGRtNzhZ7dd3wr+el PrWAPdXOotRivOcsR58Lgq1ffBhm1TsUBYHQqABS8AEwu+W02OgGwywodcKfGG57cIJl QsPKYR4OjSa76gC3vk/fSzbqy4OdnJxzNwVipco/y51moa8UbL5C/DV7Cd+tGdA6fotB hhyp5UtBLO4laPWeu3f6uiXhwU6F4iEKbCoxiPLt1UGD+E4pEJuZ80YCAH649vySDK+a BCOEQsAQpo42umWoTg2bw43qu8SRvVqZoLHpCHiFB2UnpfaT6tn2opHN85ZgGPpv2RvF tJmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=ddIGLF7A; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=d+xGH14f; 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 z20-20020a656654000000b005bddb417affsi2124316pgv.291.2023.12.08.16.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 16:08:19 -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=ddIGLF7A; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=d+xGH14f; 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 D334E804C67B; Fri, 8 Dec 2023 16:08:16 -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 S1574829AbjLIAHy (ORCPT + 99 others); Fri, 8 Dec 2023 19:07:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229525AbjLIAHv (ORCPT ); Fri, 8 Dec 2023 19:07:51 -0500 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A956AC; Fri, 8 Dec 2023 16:07:57 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 4FC5932005C1; Fri, 8 Dec 2023 19:07:55 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 08 Dec 2023 19:07:57 -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:sender:subject:subject:to:to; s=fm3; t= 1702080474; x=1702166874; bh=m98dLHyPwI+eg2Ijq83uqu7OvTQevvvXu+0 DP05ozNs=; b=ddIGLF7AaNmnEW79+jOnw5EwvTm7427Hej6wBRLVNLEogCxE9VX UrV3H2uUT0G3am/S/ednqVUmumgqCMkdusoE+QDqR5zrM3sW957QzdTrS2TD9YrP 3EwDukzy8EpVk7k2UxT7Uw3dPqLSu7o8faCYm02ID+EA680i4yWaEvv8J3DRAoXP yhh5tRLTXe22KdksfC7joSItsRjRkDt2Nvkk/SjqfijaWigBjYNyENSU5ugz8ZKS 9iwSdPj99tffOo61rhbxbfWnVP7u+oerMGNg2eSsVSX4Y0Pu0UT99A1UrPRYc7lg rvYrYx+LzkFjDs8/yXxKUEghGxpcMKe5dNA== 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:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1702080474; x=1702166874; bh=m98dLHyPwI+eg2Ijq83uqu7OvTQevvvXu+0 DP05ozNs=; b=d+xGH14fpAprU6BJ8STzBEuYXe0FQYuOl2+Q4Er8JyEW2egvFFe NNq2u3/smCxnE6TPc4JV+hVINPaAOYAY9Mgx2F92go0rE9DdxuqZ4xadtRbl99LV 7BiAooaVU7dCarvRnLSSGEmEKmg1bgWOHkLJEBbr5IvYsKvOHpgR97O1or1u3vfv FBp7rdkbo0WxL6ogCqn66Sjsgza4S9ggSuhJESpAP1XrxP65LEbaVuAKBok8c9X1 9BWO4Q1ZyLA/EV8AUvEADXkOr2Vz17gAtXCwMCFvyqX1nJaFqdt5Sulmbj47Nh5s SGxyeSITeplQ6QbbGYL9JA8BuMjuhvfk7Qg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudekjedgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdlfeehmdenucfjughrpeffhffvvefukfhfgggtugfgjgestheksfdt tddtjeenucfhrhhomhepffgrnhhivghlucgiuhcuoegugihusegugihuuhhurdighiiiqe enucggtffrrghtthgvrhhnpedtgfeuueeukeeikefgieeukeffleetkeekkeeggeffvedt vdejueehueeuleefteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 8 Dec 2023 19:07:53 -0500 (EST) Date: Fri, 8 Dec 2023 17:07:51 -0700 From: Daniel Xu To: Eyal Birger Cc: ast@kernel.org, daniel@iogearbox.net, davem@davemloft.net, Herbert Xu , steffen.klassert@secunet.com, pabeni@redhat.com, hawk@kernel.org, john.fastabend@gmail.com, kuba@kernel.org, edumazet@google.com, antony.antony@secunet.com, alexei.starovoitov@gmail.com, yonghong.song@linux.dev, eddyz87@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, devel@linux-ipsec.org Subject: Re: [PATCH bpf-next v4 02/10] bpf: xfrm: Add bpf_xdp_get_xfrm_state() kfunc 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]); Fri, 08 Dec 2023 16:08:17 -0800 (PST) On Thu, Dec 07, 2023 at 01:21:11PM -0800, Eyal Birger wrote: > On Mon, Dec 4, 2023 at 12:57 PM Daniel Xu wrote: > > > > This commit adds an unstable kfunc helper to access internal xfrm_state > > associated with an SA. This is intended to be used for the upcoming > > IPsec pcpu work to assign special pcpu SAs to a particular CPU. In other > > words: for custom software RSS. > > > > That being said, the function that this kfunc wraps is fairly generic > > and used for a lot of xfrm tasks. I'm sure people will find uses > > elsewhere over time. > > > > Co-developed-by: Antony Antony > > Signed-off-by: Antony Antony > > Signed-off-by: Daniel Xu > > --- > > include/net/xfrm.h | 9 ++++ > > net/xfrm/xfrm_bpf.c | 102 +++++++++++++++++++++++++++++++++++++++++ > > net/xfrm/xfrm_policy.c | 2 + > > 3 files changed, 113 insertions(+) > > > > diff --git a/include/net/xfrm.h b/include/net/xfrm.h > > index c9bb0f892f55..1d107241b901 100644 > > --- a/include/net/xfrm.h > > +++ b/include/net/xfrm.h > > @@ -2190,4 +2190,13 @@ static inline int register_xfrm_interface_bpf(void) > > > > #endif > > > > +#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF) > > +int register_xfrm_state_bpf(void); > > +#else > > +static inline int register_xfrm_state_bpf(void) > > +{ > > + return 0; > > +} > > +#endif > > + > > #endif /* _NET_XFRM_H */ > > diff --git a/net/xfrm/xfrm_bpf.c b/net/xfrm/xfrm_bpf.c > > index 3d3018b87f96..3d6cac7345ca 100644 > > --- a/net/xfrm/xfrm_bpf.c > > +++ b/net/xfrm/xfrm_bpf.c > > @@ -6,9 +6,11 @@ > > */ > > > > #include > > +#include > > #include > > > > #include > > +#include > > #include > > > > #if IS_BUILTIN(CONFIG_XFRM_INTERFACE) || \ > > @@ -112,3 +114,103 @@ int __init register_xfrm_interface_bpf(void) > > } > > > > #endif /* xfrm interface */ > > + > > +/* bpf_xfrm_state_opts - Options for XFRM state lookup helpers > > + * > > + * Members: > > + * @error - Out parameter, set for any errors encountered > > + * Values: > > + * -EINVAL - netns_id is less than -1 > > + * -EINVAL - opts__sz isn't BPF_XFRM_STATE_OPTS_SZ > > + * -ENONET - No network namespace found for netns_id > > + * @netns_id - Specify the network namespace for lookup > > + * Values: > > + * BPF_F_CURRENT_NETNS (-1) > > + * Use namespace associated with ctx > > + * [0, S32_MAX] > > + * Network Namespace ID > > + * @mark - XFRM mark to match on > > + * @daddr - Destination address to match on > > + * @spi - Security parameter index to match on > > + * @proto - L3 protocol to match on > > + * @family - L3 protocol family to match on > > + */ > > +struct bpf_xfrm_state_opts { > > + s32 error; > > + s32 netns_id; > > + u32 mark; > > + xfrm_address_t daddr; > > + __be32 spi; > > + u8 proto; > > + u16 family; > > +}; > > + > > +enum { > > + BPF_XFRM_STATE_OPTS_SZ = sizeof(struct bpf_xfrm_state_opts), > > +}; > > + > > +__bpf_kfunc_start_defs(); > > + > > +/* bpf_xdp_get_xfrm_state - Get XFRM state > > + * > > + * Parameters: > > + * @ctx - Pointer to ctx (xdp_md) in XDP program > > + * Cannot be NULL > > + * @opts - Options for lookup (documented above) > > + * Cannot be NULL > > + * @opts__sz - Length of the bpf_xfrm_state_opts structure > > + * Must be BPF_XFRM_STATE_OPTS_SZ > > + */ > > +__bpf_kfunc struct xfrm_state * > > +bpf_xdp_get_xfrm_state(struct xdp_md *ctx, struct bpf_xfrm_state_opts *opts, u32 opts__sz) > > +{ > > + struct xdp_buff *xdp = (struct xdp_buff *)ctx; > > + struct net *net = dev_net(xdp->rxq->dev); > > + struct xfrm_state *x; > > + > > + if (!opts || opts__sz < sizeof(opts->error)) > > + return NULL; > > + > > + if (opts__sz != BPF_XFRM_STATE_OPTS_SZ) { > > + opts->error = -EINVAL; > > + return NULL; > > + } > > + > > + if (unlikely(opts->netns_id < BPF_F_CURRENT_NETNS)) { > > + opts->error = -EINVAL; > > + return NULL; > > + } > > + > > + if (opts->netns_id >= 0) { > > + net = get_net_ns_by_id(net, opts->netns_id); > > + if (unlikely(!net)) { > > + opts->error = -ENONET; > > + return NULL; > > + } > > + } > > + > > + x = xfrm_state_lookup(net, opts->mark, &opts->daddr, opts->spi, > > + opts->proto, opts->family); > > + > > + if (opts->netns_id >= 0) > > + put_net(net); > > Maybe opts->error should be set to something like -ENOENT if x == NULL? Originally I opted not to do that b/c xfrm_state_lookup() chooses not to do anything like that (eg PTR_ERR()). But I don't mind adding it - I think it's reasonable either way. [..] Thanks, Daniel