Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1186561rdb; Fri, 22 Dec 2023 19:07:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7LvFr+mV8rsfHbnmLxIjx/VrZ7CQWZvEa3UOHYHlwHAaIzHsHC3tp8x9HhRBn2q8Ghv5M X-Received: by 2002:a37:de0d:0:b0:781:193c:9a83 with SMTP id h13-20020a37de0d000000b00781193c9a83mr4222006qkj.72.1703300843647; Fri, 22 Dec 2023 19:07:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703300843; cv=none; d=google.com; s=arc-20160816; b=WMNTwXzGW6/biheTybzEUmiNL0/BxtfTbCoeCBJVetCQo//zA7IqRoCa/mWlVshbPK VsMpJQ/+OHeKo6s6L5sHMUwJVBIOTaabhwuv36aHvI272BXSeQDqECAp0x3ICyUq6ngO xzjvJUqBkx2H9ESrVE4ICpFn4FIb1dvqxPYLY54axx2ZyREe+3Ml1FoWGj/yOiuf71O2 KndrJdfpYN5V9PJwXlTO3jy32RMcqpTwXzaap5XxuUSHY6XYP8M7a339vh2r75I6xRET 5Ekt9Bpwtf25lWzCz7UxF9Qn3AztTS+jrL0a9h4nxyydEyvnx2m4heT716KCnzF7B9/o UQVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=++L6ZZtpr4puZy1tQOJ2aj7LMQFCrbne9P5iC7Fqox0=; fh=J3H3jkZRTdH/CD0R7uXO8r43FYFiJ1FqB2ouoqeBxmQ=; b=N/2s+bPS9+nEuHyt1vQwr1BNW6DLQG52DjkCKJ/605ZUhLfHbTk5ny4/mReBNsr8wQ 0qPqM3NnuQWHz5G7gniKjJtAwk9HonArF38iZQxcZ9+0JrnKRqb4GFpWtpnDF+ekda+P y4DpkgBv02GG0y7/18vwlPa0l8WqTR70wxwMoSPHaxroEsCCp3b+S8btQkkI+iZdsnmj BuAHdbu1jTISyVmEYKJB38wK2gR98LYtpuLh4/20nAoN3a6smKkWXsWsDMV+N93G746Y sSKpM/wqohFwwI70L19C3djbhbUQo/gguMdiFIV9F0xaO0F15NDeFZeCQECjouqKDAkV 9uGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dxWSx7yi; spf=pass (google.com: domain of linux-kernel+bounces-10242-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10242-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g6-20020ac85806000000b004278ae7591csi5813315qtg.592.2023.12.22.19.07.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 19:07:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10242-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dxWSx7yi; spf=pass (google.com: domain of linux-kernel+bounces-10242-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10242-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5D7181C22B44 for ; Sat, 23 Dec 2023 03:07:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 76D74CA58; Sat, 23 Dec 2023 02:59:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dxWSx7yi" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) (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 6535839FD9; Sat, 23 Dec 2023 02:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703300386; x=1734836386; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yxZYHXhn633FddOUdDcraFQxZakRgJVpB7yodhsBcbU=; b=dxWSx7yi1SeULGUBhFjT876DsNvVTOtyQQ0dAZrFGCzV8CIySEA+W1+v wHMA+yazUMdCFC4jxyMK9IdGbwyCzXglg3xQvNr6U5icLLTvlJoCV56Zm ncLvEAegztKXObmFAdup6YWfp/B+CkwxPX+w624azzvf6/Ez09rXEXjmH 2n1vUumI9Y4lledZ8vRdvlCsZGMKnTemvArEt4prEjzBlY50DvbbnVBgH 2J88DeMpAXXZK59Uk2jpMM85TjWuQsY/2x7SR7tFY6bC4VoeJd4GVLQzq EzOb3Iol/4GAX93zQ8uxpcVN5Idxt+9DWwSgJ0eLHSqi228iTld6Hn9EK Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="386611043" X-IronPort-AV: E=Sophos;i="6.04,298,1695711600"; d="scan'208";a="386611043" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 18:59:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,298,1695711600"; d="scan'208";a="25537644" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa001.jf.intel.com with ESMTP; 22 Dec 2023 18:59:42 -0800 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Maciej Fijalkowski , Michal Kubiak , Larysa Zaremba , Alexei Starovoitov , Daniel Borkmann , Willem de Bruijn , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC net-next 26/34] xdp: add generic XSk xdp_buff -> skb conversion Date: Sat, 23 Dec 2023 03:55:46 +0100 Message-ID: <20231223025554.2316836-27-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231223025554.2316836-1-aleksander.lobakin@intel.com> References: <20231223025554.2316836-1-aleksander.lobakin@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Same as with converting &xdp_buff to skb on Rx, the code which allocates a new skb and copies the XSk frame there is identical across the drivers, so make it generic. Note that this time skb_record_rx_queue() is called unconditionally, as it's not intended to call this function with a non-registered RxQ info. Signed-off-by: Alexander Lobakin --- include/net/xdp.h | 11 ++++++++++- net/core/xdp.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/include/net/xdp.h b/include/net/xdp.h index 66854b755b58..23ada4bb0e69 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -273,7 +273,16 @@ void xdp_warn(const char *msg, const char *func, const int line); struct sk_buff *__xdp_build_skb_from_buff(struct sk_buff *skb, const struct xdp_buff *xdp); -#define xdp_build_skb_from_buff(xdp) __xdp_build_skb_from_buff(NULL, xdp) +struct sk_buff *xdp_build_skb_from_zc(struct napi_struct *napi, + struct xdp_buff *xdp); + +static inline struct sk_buff *xdp_build_skb_from_buff(struct xdp_buff *xdp) +{ + if (xdp->rxq->mem.type == MEM_TYPE_XSK_BUFF_POOL) + return xdp_build_skb_from_zc(NULL, xdp); + + return __xdp_build_skb_from_buff(NULL, xdp); +} struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp); struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf, diff --git a/net/core/xdp.c b/net/core/xdp.c index 8ef1d735a7eb..2bdb1fb8a9b8 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -21,6 +21,8 @@ #include #include +#include "dev.h" + #define REG_STATE_NEW 0x0 #define REG_STATE_REGISTERED 0x1 #define REG_STATE_UNREGISTERED 0x2 @@ -647,6 +649,45 @@ struct sk_buff *__xdp_build_skb_from_buff(struct sk_buff *skb, } EXPORT_SYMBOL_GPL(__xdp_build_skb_from_buff); +struct sk_buff *xdp_build_skb_from_zc(struct napi_struct *napi, + struct xdp_buff *xdp) +{ + const struct xdp_rxq_info *rxq = xdp->rxq; + u32 totalsize, metasize; + struct sk_buff *skb; + + if (!napi) { + napi = napi_by_id(rxq->napi_id); + if (unlikely(!napi)) + return NULL; + } + + totalsize = xdp->data_end - xdp->data_meta; + + skb = __napi_alloc_skb(napi, totalsize, GFP_ATOMIC | __GFP_NOWARN); + if (unlikely(!skb)) + return NULL; + + net_prefetch(xdp->data_meta); + + memcpy(__skb_put(skb, totalsize), xdp->data_meta, + ALIGN(totalsize, sizeof(long))); + + metasize = xdp->data - xdp->data_meta; + if (metasize) { + skb_metadata_set(skb, metasize); + __skb_pull(skb, metasize); + } + + skb_record_rx_queue(skb, rxq->queue_index); + skb->protocol = eth_type_trans(skb, rxq->dev); + + xsk_buff_free(xdp); + + return skb; +} +EXPORT_SYMBOL_GPL(xdp_build_skb_from_zc); + struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf, struct sk_buff *skb, struct net_device *dev) -- 2.43.0