Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp47677rdh; Mon, 18 Dec 2023 11:07:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEutO9vSYh1i80xsGq3t0rVTWUiNe6aA9TiGApVY1xU3oqL2sozcufc/TnE8FBzYNFB808r X-Received: by 2002:a05:6a00:810:b0:6ce:2732:27e with SMTP id m16-20020a056a00081000b006ce2732027emr9852224pfk.45.1702926422381; Mon, 18 Dec 2023 11:07:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702926422; cv=none; d=google.com; s=arc-20160816; b=wIqzG2e2XSCDtN1wpCMC1AnPjfUNUWIeYRI6b2uyC/UT6jlUxDUQOcGjo03uWGXFHL Z2QO2+AGjY9iZdzwwAh94PEyii11ltC69lH6zfSkFq80NaX59i9wAJW75LsdPbA+bfO7 V70ZQadYQTa4y8pA+1hLIqC+Jitdn8Yzkk9ap+AEbJ7tSSoJVEDLAabPl3pDBQCt3r9s Is4QL4jUgof0oKPbcCdwoHKtS5p+Hk2lr/pawh9sctofcAu63bLbpbFb9huKdLlMOxsW yw1PDRpBTb2U3bmw9SdPywqNO+/jUwLQxJINa5Sr8ETHZMxoSiALWeotzwliFujzU8fb H9eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FQJIpeeRpjjjHg2ytY/l24PwlpYXuMK7YLuClzEI/kk=; fh=U0t+ZY+jo+J1zjdh5z2waJB2uW0lU7nPptatOtTtJpI=; b=yRVvi2+tRe+qEGV0JTT4tuz7jV4UAHDfPMjsSRA2bKnD+xn+mE8bq9f+wKG27zoplK k4iTvKLG3Jzavzbi2A3GPJdAqSU3lDMHKr1ZGDAO4QhsN7JBgMn0crfr4y50EC+HcTOY 47PKRMQfGSZMVMlrHleuICwICn31Xecx8yZaBEi1tTbyqt8jKuAnxiR3D2SDZyXOP+2b 4VUuXnV0ZknRFhQWgmoSrUPEZgZcEfu0cyKYJZSy/AOVFKP4AS5wEaif/o6irRXiEV2B tPyAmgDUkGzh8y72g/k2lA0Kg6zZMMpswsh4EmaiXhE/TJcBo4bPxVLjk3WVACC8i7is t3ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r5YqmWcH; spf=pass (google.com: domain of linux-kernel+bounces-4274-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4274-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b20-20020a056a000a9400b006ce9e6cbdf5si18109413pfl.351.2023.12.18.11.07.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 11:07:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4274-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r5YqmWcH; spf=pass (google.com: domain of linux-kernel+bounces-4274-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4274-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 47D69B22504 for ; Mon, 18 Dec 2023 19:07:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C355771450; Mon, 18 Dec 2023 19:06:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r5YqmWcH" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E7D0B53BF; Mon, 18 Dec 2023 19:06:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2AB9C433CA; Mon, 18 Dec 2023 19:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702926406; bh=Oj7Gm/7pBuv1oprC+a4gyIhGSXnfXjSzl+Q2UzH9PfU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=r5YqmWcHA0EErYG+wdUrVMo+G3NRUlAHHAaq8OYyMC+0aX3HzBieTQD+saJYkuXz8 8tVeyb80ImB6jhtI/nCc/Z9kQn/N2mRN7e1vDE5LoljMmYoR69+vqAXN1l42F15tJv a8k2+RplvA3gsK98gcp0wfob+x0GP2P5SzBFh9Z+IYLdNg9RRtq2wmqwaOSQBPQXr0 6aWyqySgDEBIot96WJUo8TFNS+PW1e7qTruMg+rlru7oGH0qU8CsY51PH95b3w4QJA md8wKk/oWSDg770HWrBq6f79Fd0ArFWxcevlh1fKJbMVseMl2yto9fneZ6aWJD194T SIuvC5hdmrtMA== Date: Mon, 18 Dec 2023 19:06:40 +0000 From: Simon Horman To: "D. Wythe" Cc: pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, coreteam@netfilter.org, netfilter-devel@vger.kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org Subject: Re: [RFC nf-next v2 1/2] netfilter: bpf: support prog update Message-ID: <20231218190640.GJ6288@kernel.org> References: <1702873101-77522-1-git-send-email-alibuda@linux.alibaba.com> <1702873101-77522-2-git-send-email-alibuda@linux.alibaba.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <1702873101-77522-2-git-send-email-alibuda@linux.alibaba.com> On Mon, Dec 18, 2023 at 12:18:20PM +0800, D. Wythe wrote: > From: "D. Wythe" > > To support the prog update, we need to ensure that the prog seen > within the hook is always valid. Considering that hooks are always > protected by rcu_read_lock(), which provide us the ability to > access the prog under rcu. > > Signed-off-by: D. Wythe ... > @@ -26,8 +17,20 @@ struct bpf_nf_link { > struct net *net; > u32 dead; > const struct nf_defrag_hook *defrag_hook; > + struct rcu_head head; > }; > > +static unsigned int nf_hook_run_bpf(void *bpf_link, struct sk_buff *skb, > + const struct nf_hook_state *s) > +{ > + const struct bpf_nf_link *nf_link = bpf_link; > + struct bpf_nf_ctx ctx = { > + .state = s, > + .skb = skb, > + }; > + return bpf_prog_run(rcu_dereference(nf_link->link.prog), &ctx); Hi, AFAICT nf_link->link.prog isn't annotated as __rcu, so perhaps rcu_dereference() is not correct here? In any case, sparse seems a bit unhappy: .../nf_bpf_link.c:31:29: error: incompatible types in comparison expression (different address spaces): .../nf_bpf_link.c:31:29: struct bpf_prog [noderef] __rcu * .../nf_bpf_link.c:31:29: struct bpf_prog * > +} > + > #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) || IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) > static const struct nf_defrag_hook * > get_proto_defrag_hook(struct bpf_nf_link *link, ...