From patchwork Mon Feb 22 09:09:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jithu Joseph X-Patchwork-Id: 1443004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dkbtn4rhfz9sCD for ; Mon, 22 Feb 2021 20:08:01 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 2D72F60590; Mon, 22 Feb 2021 09:08:00 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KyXJfkaFtJgh; Mon, 22 Feb 2021 09:07:59 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id EACA2605DD; Mon, 22 Feb 2021 09:07:58 +0000 (UTC) X-Original-To: intel-wired-lan@osuosl.org Delivered-To: intel-wired-lan@osuosl.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 4FC601BF38E for ; Mon, 22 Feb 2021 09:07:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 3DB7083829 for ; Mon, 22 Feb 2021 09:07:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EvstzqccITKx for ; Mon, 22 Feb 2021 09:07:57 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by smtp1.osuosl.org (Postfix) with ESMTPS id 31A188380E for ; Mon, 22 Feb 2021 09:07:57 +0000 (UTC) IronPort-SDR: Lae7qudW90LveCgxHPCtLJbqXtwGK98fDVG+0q7GwCbAwB6+n/TBfFTprfeC0xvUwml6Efgp5S cxGGYY76Kegg== X-IronPort-AV: E=McAfee;i="6000,8403,9902"; a="245808727" X-IronPort-AV: E=Sophos;i="5.81,196,1610438400"; d="scan'208";a="245808727" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2021 01:07:56 -0800 IronPort-SDR: YxU3QQxTOjsdOv//61+J0yJWDl62z04ZUFrEB4Qvg19SpBF+YjPDI5k/lG1+hmPWCkP1PyVTKV BqOWGBNr90AQ== X-IronPort-AV: E=Sophos;i="5.81,196,1610438400"; d="scan'208";a="441321431" Received: from coffy.sc.intel.com ([10.3.79.166]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2021 01:07:48 -0800 From: Jithu Joseph To: intel-wired-lan@osuosl.org Date: Mon, 22 Feb 2021 01:09:29 -0800 Message-Id: <20210222090936.6768-3-jithu.joseph@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210222090936.6768-1-jithu.joseph@intel.com> References: <20210222090936.6768-1-jithu.joseph@intel.com> Subject: [Intel-wired-lan] [PATCH v4 2/9] igc: Refactor __igc_xdp_run_prog() X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andre Guedes MIME-Version: 1.0 Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" From: Andre Guedes Refactor __igc_xdp_run_prog() helper from igc_xdp_run_prog(), preparing the code for AF_XDP zero-copy support which is added by upcoming patches. The existing igc_xdp_run_prog() caters to regular XDP rx path which has to verify if bpf_prog is not NULL. Zero-copy path assumes that bpf_prog is not NULL and hence this check is not required. Therefore it makes sense to refactor the common code into a helper function, to avoid code duplication. Signed-off-by: Andre Guedes Signed-off-by: Vedang Patel Signed-off-by: Jithu Joseph Reviewed-by: Maciej Fijalkowski --- drivers/net/ethernet/intel/igc/igc_main.c | 56 +++++++++++------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index a659e6f24886..d9d60c6c6726 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -2021,38 +2021,22 @@ static int igc_xdp_xmit_back(struct igc_adapter *adapter, struct xdp_buff *xdp) return res; } -static struct sk_buff *igc_xdp_run_prog(struct igc_adapter *adapter, - struct xdp_buff *xdp) +/* This function assumes rcu_read_lock() is held by the caller. */ +static int __igc_xdp_run_prog(struct igc_adapter *adapter, + struct bpf_prog *prog, + struct xdp_buff *xdp) { - struct bpf_prog *prog; - int res; - u32 act; - - rcu_read_lock(); - - prog = READ_ONCE(adapter->xdp_prog); - if (!prog) { - res = IGC_XDP_PASS; - goto unlock; - } + u32 act = bpf_prog_run_xdp(prog, xdp); - act = bpf_prog_run_xdp(prog, xdp); switch (act) { case XDP_PASS: - res = IGC_XDP_PASS; - break; + return IGC_XDP_PASS; case XDP_TX: - if (igc_xdp_xmit_back(adapter, xdp) < 0) - res = IGC_XDP_CONSUMED; - else - res = IGC_XDP_TX; - break; + return igc_xdp_xmit_back(adapter, xdp) < 0 ? + IGC_XDP_CONSUMED : IGC_XDP_TX; case XDP_REDIRECT: - if (xdp_do_redirect(adapter->netdev, xdp, prog) < 0) - res = IGC_XDP_CONSUMED; - else - res = IGC_XDP_REDIRECT; - break; + return xdp_do_redirect(adapter->netdev, xdp, prog) < 0 ? + IGC_XDP_CONSUMED : IGC_XDP_REDIRECT; default: bpf_warn_invalid_xdp_action(act); fallthrough; @@ -2060,9 +2044,25 @@ static struct sk_buff *igc_xdp_run_prog(struct igc_adapter *adapter, trace_xdp_exception(adapter->netdev, prog, act); fallthrough; case XDP_DROP: - res = IGC_XDP_CONSUMED; - break; + return IGC_XDP_CONSUMED; } +} + +static struct sk_buff *igc_xdp_run_prog(struct igc_adapter *adapter, + struct xdp_buff *xdp) +{ + struct bpf_prog *prog; + int res; + + rcu_read_lock(); + + prog = READ_ONCE(adapter->xdp_prog); + if (!prog) { + res = IGC_XDP_PASS; + goto unlock; + } + + res = __igc_xdp_run_prog(adapter, prog, xdp); unlock: rcu_read_unlock();