[RFC,net-next,15/34] page_pool: add inline helper to sync VA for device (for XDP_TX)
Message ID | 20231223025554.2316836-16-aleksander.lobakin@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-10231-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1460971dyi; Fri, 22 Dec 2023 19:03:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4DTK1IieT8F664mWttje464WHKW8jHeD/ttPlDGCDdrTaYXWXuLX2r1lvI+/nF8iB6NIx X-Received: by 2002:a05:6870:e409:b0:1fa:f541:5297 with SMTP id n9-20020a056870e40900b001faf5415297mr2808578oag.42.1703300635969; Fri, 22 Dec 2023 19:03:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703300635; cv=none; d=google.com; s=arc-20160816; b=gtWDj+CxWQAneTy/wfvvK6UjChcKlFv/2N8MWLD4COluCAftOU4fTAZMm0fFpdV/I1 wEqCCc1kOY55QmlVTrAj4oZPZncNMNXY6HVXiBApNgwldQCSlnOR31tSyWitTA6leRhB 8SihwvQjW/oM22C9WcjFrkt3AelHmnrCpHG5jCTmdzcQ2buiP3SILlFdpQZAePB9iwPX dOcWMkLlUmfmgrzw39HcvJZI4XzqOko6ATY5rLrOcN+DmwwCCowj2aCew+IFWno4g5Do bBLH8+tCtxgxJM3H0g0Ctp/4a31hCWsCxSve3DqIm587o4p2prYNxx5uGoyScNdFZ7Dp TlGQ== 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=VsDFzbr61ZrYN/+9EjwxZW6bB9G6JrBPgfTPVtL7cSg=; fh=J3H3jkZRTdH/CD0R7uXO8r43FYFiJ1FqB2ouoqeBxmQ=; b=Ji9YkiFCrAYkO4wNfHaDp+4t/5cNdkm5zy4bZtsbmFpVCGNF6LhXfptq4LYLoa+DWP C+Zbz2jqel1FLreAgtPGtXG5FOBaF2hW3jXJ0p6AKqcVInrwDZvnorWXREluAmp3Xz7/ sNwCRFaPkrcpEYjjsmU9tVR3w3eQZ32kQhv21YnV1Inbv+WUriDcPVpylj+KCYSnisOb WxPnN35S2q75JfZRM7LtH10FvNovlYK9AJlNDbfFOU9P12g47eGFCPNPLbZApazEFOY3 4sTMPhxlRw66Il9Nyps8ukH8cYb1WlMg2lmzy+vc6MIqlUPlDjsAxE3jLvsDbxGImQxi DWGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l9Ycgs0d; spf=pass (google.com: domain of linux-kernel+bounces-10231-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10231-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. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e2-20020a656782000000b005cdff2eb998si1003116pgr.744.2023.12.22.19.03.55 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 19:03:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10231-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l9Ycgs0d; spf=pass (google.com: domain of linux-kernel+bounces-10231-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10231-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 B4905B210E1 for <ouuuleilei@gmail.com>; Sat, 23 Dec 2023 03:03:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05FEA28383; Sat, 23 Dec 2023 02:59:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="l9Ycgs0d" 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 1B52D2577B; Sat, 23 Dec 2023 02:59:02 +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=1703300342; x=1734836342; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jcsuGPpFSGcZ4sgNc0Vw/DW519NNgEvMXndn/cJUseI=; b=l9Ycgs0dFb0PGHHQJXMR1NS5+blXTfGC0esupwQa5nDbovJ6mM8NxeUs 4Wc9ZXTQpH3TeoUnFlsXRJnP1RCMsFkrgJhpyNZhZld6nJ82CJYEPlZwo k/MQmPZeuvX8HXOdbWCiDvH9kfKMLtdmlzj6/ZI+uCz3cgdWGIRXpH1Je BBw5NwbFp52YI0nHG9oCiS6ItuZi0TJfzLzz0Gs67XiB1RFAG6e3Yvtw2 5wyIIUumQW8XCx/wAdLazdfHop+YVopUuYzLg7+IiBR6EGnnsMn/t85H3 Ze8MTX2AorSP++zuc9ovymJNrQX+02dFU68mB0HKwXddnfYaxlsn0RW/z Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="386610891" X-IronPort-AV: E=Sophos;i="6.04,298,1695711600"; d="scan'208";a="386610891" 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:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,298,1695711600"; d="scan'208";a="25537505" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa001.jf.intel.com with ESMTP; 22 Dec 2023 18:58:58 -0800 From: Alexander Lobakin <aleksander.lobakin@intel.com> To: "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: Alexander Lobakin <aleksander.lobakin@intel.com>, Maciej Fijalkowski <maciej.fijalkowski@intel.com>, Michal Kubiak <michal.kubiak@intel.com>, Larysa Zaremba <larysa.zaremba@intel.com>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Willem de Bruijn <willemdebruijn.kernel@gmail.com>, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC net-next 15/34] page_pool: add inline helper to sync VA for device (for XDP_TX) Date: Sat, 23 Dec 2023 03:55:35 +0100 Message-ID: <20231223025554.2316836-16-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: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786040167830277511 X-GMAIL-MSGID: 1786040167830277511 |
Series |
Christmas 3-serie XDP for idpf (+generic stuff)
|
|
Commit Message
Alexander Lobakin
Dec. 23, 2023, 2:55 a.m. UTC
Drivers using Page Pool for Rx buffers do the same pattern on XDP_TX:
syncing-DMA-for-device and obtaining DMA address for &xdp_buff they
are sending.
Add a helper for that to be able to do that in one call in the drivers.
I explicitly added `bool compound` argument and set it to false by
default: only a few drivers, if any, uses high-order pages with Page
Pool, so losing cycles on compound_head() looks suboptimal. Drivers
can always call the underscored version if needed (for example, pass
pool->p.order as the last argument -- will always work).
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
---
include/net/page_pool/helpers.h | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index 873631c79ab1..99dc825b03a5 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -397,6 +397,38 @@ static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr) return false; } +static inline dma_addr_t __page_pool_dma_sync_va_for_device(const void *va, + u32 dma_sync_size, + bool compound) +{ + const struct page_pool *pool; + const struct page *page; + dma_addr_t addr; + u32 offset; + + if (unlikely(compound)) { + page = virt_to_head_page(va); + offset = va - page_address(page); + } else { + page = virt_to_page(va); + offset = offset_in_page(va); + } + + addr = page_pool_get_dma_addr(page) + offset; + pool = page->pp; + + dma_sync_single_for_device(pool->p.dev, addr, dma_sync_size, + page_pool_get_dma_dir(pool)); + + return addr; +} + +static inline dma_addr_t page_pool_dma_sync_va_for_device(const void *va, + u32 dma_sync_size) +{ + return __page_pool_dma_sync_va_for_device(va, dma_sync_size, false); +} + /** * page_pool_dma_sync_for_cpu - sync Rx page for CPU after it's written by HW * @pool: &page_pool the @page belongs to