Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2742279pxb; Tue, 13 Apr 2021 09:06:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzt/EqFN2K3PsRnuTw2EmZ8UUQ2tOXupXZtWkuy1nwXMyYy4SxbbsW3zi+96hjEX69CBJ6H X-Received: by 2002:a17:906:3c1b:: with SMTP id h27mr18733058ejg.182.1618330018412; Tue, 13 Apr 2021 09:06:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618330018; cv=none; d=google.com; s=arc-20160816; b=qXP+MT3LVZE/F82Dyh4r4JuxUO5kR5A1aNG1C0O/9EVbQsqviFMLiptisZsoNmHT+b 0lg9UVp8FgUfPXB1qO6fSvnTfkPuNDdBdg99tYQnnsFUfFuwGXFPTk6mmG03oVKe5Xcw its087DMRj0S+ArOMDZNZ8exHJWBW3dj3zvC0u6IUtDDAtpyJZwItGKFJPEjpLJ6mypw KwNfJ7h9Zfkb8DA7TRsBzoH63XnWmIknkl4ksYlac0dEJBhGOnnfjirmj6JDzIr79dSJ GPJ0S51cZEg/R/wUJOldM6LN37qujy/Ji1b9B81pR5k+WlHYS/daWd2KRyUGtOO4x90p liHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=aJME64vi6vashiw71EUO4x514amznXm9bLQASfY4lkE=; b=ERjsfimbIBzRicWNeHk+BzxZHKXjC8PMFNuB86sfPjCqpr5v8g8kS4jqbk6KVNXAZT Iqvy4l4wCLdStY54p5p4dJ69ZF9QZM2k1E4DDDqqIRXXkEQ9iNY+R6Wa2NdoITvOtxUg 2PmvjokPSjGNggZwWPoSeie+dQ+nCOviOfQfiOIaznk7ErjDN/uKK2DgXGaJDdZm6VCg ZVAnVI7er8HGP3YX4RqJnsAbcUSNoPcD0pUcX3941n7uh5kxYKB/zS3hG02OxPmxXyiJ 0TP4oHeIzqrNl5U45s3COLI+zHrYZP/O9eCrRWq9WoG0hmsEhWpG7/FYNzNDHFuuStmd Lmsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nd11si10272685ejc.470.2021.04.13.09.06.32; Tue, 13 Apr 2021 09:06:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343620AbhDMJdG (ORCPT + 99 others); Tue, 13 Apr 2021 05:33:06 -0400 Received: from mga05.intel.com ([192.55.52.43]:17206 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343553AbhDMJdB (ORCPT ); Tue, 13 Apr 2021 05:33:01 -0400 IronPort-SDR: IUT2i0chsDoQjlAa/oDRLECKbrgMaiRsDNnUB+l6gcwvKG1yoLE3eBnKyryCj1aheUvAnb7nDb JBQizONQWglg== X-IronPort-AV: E=McAfee;i="6200,9189,9952"; a="279681262" X-IronPort-AV: E=Sophos;i="5.82,219,1613462400"; d="scan'208";a="279681262" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2021 02:32:41 -0700 IronPort-SDR: /d4kk3xEeYhVjKG9EI0x4bPz/abpWv5I8UQjIAXFp58MaJkYFp6qLnFC4uj5h/cBD6i1BhYotO HMrh5eCfaAIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,219,1613462400"; d="scan'208";a="424178214" Received: from glass.png.intel.com ([10.158.65.59]) by orsmga008.jf.intel.com with ESMTP; 13 Apr 2021 02:32:35 -0700 From: Ong Boon Leong To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S . Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend Cc: alexandre.torgue@foss.st.com, Maxime Coquelin , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Ong Boon Leong Subject: [PATCH net-next v2 5/7] net: stmmac: Refactor __stmmac_xdp_run_prog for XDP ZC Date: Tue, 13 Apr 2021 17:36:24 +0800 Message-Id: <20210413093626.3447-6-boon.leong.ong@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210413093626.3447-1-boon.leong.ong@intel.com> References: <20210413093626.3447-1-boon.leong.ong@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prepare stmmac_xdp_run_prog() for AF_XDP zero-copy support which will be added by upcoming patches by splitting out the XDP verdict processing into __stmmac_xdp_run_prog() and it callable for XDP ZC path which does not need to verify bpf_prog is not NULL. The stmmac_xdp_run_prog() is used for regular XDP Rx path which requires bpf_prog to be verified. Signed-off-by: Ong Boon Leong --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 0804674e628e..329a3abbac76 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -4408,20 +4408,13 @@ static int stmmac_xdp_xmit_back(struct stmmac_priv *priv, return res; } -static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv, - struct xdp_buff *xdp) +/* This function assumes rcu_read_lock() is held by the caller. */ +static int __stmmac_xdp_run_prog(struct stmmac_priv *priv, + struct bpf_prog *prog, + struct xdp_buff *xdp) { - struct bpf_prog *prog; - int res; u32 act; - - rcu_read_lock(); - - prog = READ_ONCE(priv->xdp_prog); - if (!prog) { - res = STMMAC_XDP_PASS; - goto unlock; - } + int res; act = bpf_prog_run_xdp(prog, xdp); switch (act) { @@ -4448,6 +4441,24 @@ static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv, break; } + return res; +} + +static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv, + struct xdp_buff *xdp) +{ + struct bpf_prog *prog; + int res; + + rcu_read_lock(); + + prog = READ_ONCE(priv->xdp_prog); + if (!prog) { + res = STMMAC_XDP_PASS; + goto unlock; + } + + res = __stmmac_xdp_run_prog(priv, prog, xdp); unlock: rcu_read_unlock(); return ERR_PTR(-res); -- 2.25.1