From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mail.toke.dk (Postfix) with ESMTPS id C7C36982EDD for ; Tue, 28 Jun 2022 21:49:57 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KEMEc59O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656445798; x=1687981798; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ufgJOb+TezFSxWKDyYwF8u0ehQj1wQzhK8T9FWSr3eU=; b=KEMEc59OvzPVAILvcDdEFbfMRnY73Eh9NKBP8YhpDbeubTYqiDk4d3Bf TgTctyULt0oeRkUthoNNL+E2tjsVOPtunff8eX3cjHMuiR+Y4KHydiZ8l 9ZZt3BIEsvUdMN83qW8Ze4A9g71HzI+AzBR/kGHRaQLyR3dj/+He+ZEEw gUXYcSkVXGMHbPXDF9DVy2q9H97lE59R2nkSEzk3e9tbz1KlP/IouedjF V47mg3qP1lQYd+IvQME6UCJhZH6z2RYJOAzKjPhW6uZwxLPm7xYz7dsrL xnDV8jvU62sa0dMiTGpN1MRriweThrKcGyg+JmDXV91rgfVIBN4jsetFe g==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="281869688" X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="281869688" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 12:49:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="617303166" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga008.jf.intel.com with ESMTP; 28 Jun 2022 12:49:50 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 25SJmr9f022013; Tue, 28 Jun 2022 20:49:48 +0100 From: Alexander Lobakin To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Date: Tue, 28 Jun 2022 21:48:01 +0200 Message-Id: <20220628194812.1453059-42-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628194812.1453059-1-alexandr.lobakin@intel.com> References: <20220628194812.1453059-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: HMSTYP33W4U2VWMNOHW45A7NIQ2DP3A7 X-Message-ID-Hash: HMSTYP33W4U2VWMNOHW45A7NIQ2DP3A7 X-MailFrom: alexandr.lobakin@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alexander Lobakin , Larysa Zaremba , Michal Swiatkowski , Jesper Dangaard Brouer , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , Toke Hoiland-Jorgensen , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesse Brandeburg , John Fastabend , Yajun Deng , Willem de Bruijn , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.5 Precedence: list Subject: [xdp-hints] [PATCH RFC bpf-next 41/52] net, xdp: replace net_device::xdp_prog pointer with &xdp_attachment_info List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: To have access and store not only BPF prog pointer, but also auxiliary params on Generic (skb) XDP path, replace it with an &xdp_attachment_info struct and use xdp_attachment_setup_rcu() (since Generic XDP code RCU-protects the pointer already). This slightly changes the struct &net_device cacheline layout, but nothing performance-critical. Signed-off-by: Alexander Lobakin --- include/linux/netdevice.h | 7 +++---- net/bpf/dev.c | 11 ++++------- net/core/dev.c | 4 +++- net/core/rtnetlink.c | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 60df42b3f116..1c033c164257 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2168,7 +2168,7 @@ struct net_device { unsigned int num_rx_queues; unsigned int real_num_rx_queues; - struct bpf_prog __rcu *xdp_prog; + struct xdp_attachment_info xdp_info; unsigned long gro_flush_timeout; int napi_defer_hard_irqs; #define GRO_LEGACY_MAX_SIZE 65536u @@ -2343,9 +2343,8 @@ struct net_device { static inline bool netif_elide_gro(const struct net_device *dev) { - if (!(dev->features & NETIF_F_GRO) || dev->xdp_prog) - return true; - return false; + return !(dev->features & NETIF_F_GRO) || + rcu_access_pointer(dev->xdp_info.prog_rcu); } #define NETDEV_ALIGN 32 diff --git a/net/bpf/dev.c b/net/bpf/dev.c index 82948d0536c8..cc43f73929f3 100644 --- a/net/bpf/dev.c +++ b/net/bpf/dev.c @@ -242,19 +242,16 @@ static void dev_disable_gro_hw(struct net_device *dev) static int generic_xdp_install(struct net_device *dev, struct netdev_bpf *xdp) { - struct bpf_prog *old = rtnl_dereference(dev->xdp_prog); - struct bpf_prog *new = xdp->prog; + bool old = !!rtnl_dereference(dev->xdp_info.prog_rcu); int ret = 0; switch (xdp->command) { case XDP_SETUP_PROG: - rcu_assign_pointer(dev->xdp_prog, new); - if (old) - bpf_prog_put(old); + xdp_attachment_setup_rcu(&dev->xdp_info, xdp); - if (old && !new) { + if (old && !xdp->prog) { static_branch_dec(&generic_xdp_needed_key); - } else if (new && !old) { + } else if (xdp->prog && !old) { static_branch_inc(&generic_xdp_needed_key); dev_disable_lro(dev); dev_disable_gro_hw(dev); diff --git a/net/core/dev.c b/net/core/dev.c index 62bf6ee00741..e57ae87d619e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5055,10 +5055,12 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, __this_cpu_inc(softnet_data.processed); if (static_branch_unlikely(&generic_xdp_needed_key)) { + struct bpf_prog *prog; int ret2; migrate_disable(); - ret2 = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog), skb); + prog = rcu_dereference(skb->dev->xdp_info.prog_rcu); + ret2 = do_xdp_generic(prog, skb); migrate_enable(); if (ret2 != XDP_PASS) { diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 500420d5017c..72f696b12df2 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1451,7 +1451,7 @@ static u32 rtnl_xdp_prog_skb(struct net_device *dev) ASSERT_RTNL(); - generic_xdp_prog = rtnl_dereference(dev->xdp_prog); + generic_xdp_prog = rtnl_dereference(dev->xdp_info.prog_rcu); if (!generic_xdp_prog) return 0; return generic_xdp_prog->aux->id; -- 2.36.1