From patchwork Sat Dec 23 02:55:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 182894 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1462538dyi; Fri, 22 Dec 2023 19:08:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgGDCYBvQS9KMaGHb7FUnPjgkvdezXG8h7eUlXjeje9osuxH3c57lqzXN0YwuVnjC3w5QQ X-Received: by 2002:a17:90b:268a:b0:28c:1017:fbda with SMTP id pl10-20020a17090b268a00b0028c1017fbdamr1868988pjb.0.1703300919182; Fri, 22 Dec 2023 19:08:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703300919; cv=none; d=google.com; s=arc-20160816; b=CXMeXmdKCQDFz1v3e+alStiuV0ZKXH2frMtxnZcfix4gKoH2Hc4HMQkAdaZt+FHvqK q6hCUp+ytx7eH+pWuqjdXhZCqIqUJOZk50cAfUHEuWzIsgWTod/H1XYTK9G9XVSNkjka u8XM7DDj+k5otNeUExqEskudhplRFeakZUF0w8Y6kUcovy5/PuGj9foC9bj7jq0tTV2S ENHlYkUvuysJTF3C4QuWd0Xaczrt9e/uXVDLo8FxPZARsu22ZRFtwe+jy4qcwcUbTX0k Fi2Z1w75y61aLxB/fu6+t7FCyf5XsiIXBACUDemC3I3Rkfr2wKidwie/Z3U2v6oW9UM2 sIeQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10242-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b4-20020a633404000000b005cdf95ddf8dsi1719976pga.271.2023.12.22.19.08.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 19:08:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10242-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10242-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4E0BAB244D3 for ; Sat, 23 Dec 2023 03:07:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F7FA3A287; Sat, 23 Dec 2023 02:59:50 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786040464415898944 X-GMAIL-MSGID: 1786040464415898944 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)