From patchwork Thu Apr 4 15:43:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 13618015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D310CD1284 for ; Thu, 4 Apr 2024 15:46:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCC0B6B009B; Thu, 4 Apr 2024 11:46:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C7A3E6B009C; Thu, 4 Apr 2024 11:46:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF49E6B009D; Thu, 4 Apr 2024 11:46:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 882F76B009B for ; Thu, 4 Apr 2024 11:46:13 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 55F0A1C0DD9 for ; Thu, 4 Apr 2024 15:46:13 +0000 (UTC) X-FDA: 81972275826.14.43FEB06 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by imf24.hostedemail.com (Postfix) with ESMTP id 31B9618002C for ; Thu, 4 Apr 2024 15:46:11 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=E+8LdYcP; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of aleksander.lobakin@intel.com designates 192.198.163.12 as permitted sender) smtp.mailfrom=aleksander.lobakin@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712245571; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cP32Q3dEgPXhmR3/rYVgH7UWTRGTR3MvWVNydA/XXaI=; b=zso0p525caoqo19c6EuUQtW64o9ktMeuCiy4LVaxnQJcPZ29+KMDLtvopaSdl8X1cfDrzY F5uP0dYBji1eADjtgOptZsg7sdrPWUK9/UrBhsj3ROduBYCkPLzJyk2vTpaTPHJxVK5FpZ Z05vkVT0pS63dwrrDkNqi8QSuI6I1a4= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=E+8LdYcP; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of aleksander.lobakin@intel.com designates 192.198.163.12 as permitted sender) smtp.mailfrom=aleksander.lobakin@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712245571; a=rsa-sha256; cv=none; b=Au2F/a6f1kKOay6hB3MZQIfxeeZbLl4lS5S9Q5QKbsNt+p1NIRl20GG2D3CZh7CMnHT6XM 3yVoQ+CumhRihJyD6ONDin+osDiRuNgdLSubAs3kaaaei81Gr9m9gW7EM50/BHjbIU15sA Px9mVjQ4qc8pS7Zmuyx6DtzvuvWGdP8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712245571; x=1743781571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OhUqtf35fdgCEyiIWVQHl/adPq6y26tJ1DJr2rp+7fQ=; b=E+8LdYcPmg19eD/MkabWsuyv0ScEbxJi/1ifLJgD/AZWYw3f6GTOuwx3 5CY3Bpe1Urg7PwWYTHhq+D77BmRIPBGAal79j/0s8RyWSwFokGhaMIc8Q iLSifU4L9kCtGxqVKSC0WfeZaa91osDefesFtkBnz6I6Uf34y7WLDSg+7 ig533OD7EKqdx6TT6qQSUDy+FWlkmqHBdsqaa8T6V8Q7ZjcmO6qwQri7I C1lAUdKO1S72pnIhRtrXTXLYNLtF5bChANlveELx4PpaWpzU5G0q9u8ba Io/6OBm2SlM/nHIpEmV6hKvPXMH9AOQg9F5vnHEoQMuL+SP57XsqjshMG A==; X-CSE-ConnectionGUID: oulPZGMCSj6W33Kimek9ng== X-CSE-MsgGUID: NGW9Qq0tReabJyZxd6M+VA== X-IronPort-AV: E=McAfee;i="6600,9927,11034"; a="11312231" X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="11312231" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2024 08:46:11 -0700 X-CSE-ConnectionGUID: gL68NynBRQKuBxaQ9iDDNQ== X-CSE-MsgGUID: WllCqo++T3K8lvL91O/gXQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="23288103" Received: from newjersey.igk.intel.com ([10.102.20.203]) by fmviesa005.fm.intel.com with ESMTP; 04 Apr 2024 08:46:07 -0700 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Alexander Duyck , Yunsheng Lin , Jesper Dangaard Brouer , Ilias Apalodimas , Christoph Lameter , Vlastimil Babka , Andrew Morton , nex.sw.ncis.osdt.itp.upstreaming@intel.com, netdev@vger.kernel.org, intel-wired-lan@lists.osuosl.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v9 6/9] page_pool: add DMA-sync-for-CPU inline helper Date: Thu, 4 Apr 2024 17:43:59 +0200 Message-ID: <20240404154402.3581254-7-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404154402.3581254-1-aleksander.lobakin@intel.com> References: <20240404154402.3581254-1-aleksander.lobakin@intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 31B9618002C X-Stat-Signature: ffysnhpn6ha73n38k3nygsbjmu5zdo5c X-Rspam-User: X-HE-Tag: 1712245571-145275 X-HE-Meta: U2FsdGVkX19xrCU1oNIfKYPKx3H1KFpKG+ztjy+JZB3wBp7WRH4N4gjy8C53hP1py9F180H2/rrJ85fUKZrgOa3pY2WnReutHxgdQRVinJ/HGzdE+ki8ezBtWh7OVZfyUB6LqM26vUas23Uob1zhSG6IPl0MabqIVnaKEl8711z4t7TKFDoDsS9ZAf55c3Q6MqK83Hsk81jt+XROnJM/xrxJMqB+Gfvm/5dv8vaSdPhbUi5drVaznXCe0E7369l9Vm0GJ7gf09C8YbsX90ArqzoNumiZqzm2dOuHydAVRkulRSKD+7pREKMdIs4hUFHlANlHCtrm9qoqi53zvKZyMJXXdlGNvFBmRYlDnhwUlSe12Tyi8T4XFDbqRgBsG9zZlmExjGzasZWkiWJ4xehp+lGLHd3JjzMffwFf5+gASkq+P7p49O43PaZ8bXuQrKNBGxuzx10a8JMoXYGcDgI+MlikTZxTWGJoPLZDLM8N6lImZzy6o9dZv/3UoHYcPHXFdXcrgxdBSMXbAYYwRxQFd6UdR6n/aMfhn5LbZk0v6d8/nkz1u4pScffnRYoK1YgsXNUyuDfhXT5+I5ACVIaRf/eE4Bl6KEaoSYxavm/1idRLU9o3uSk+1reTU6964YXyUl2YZcAkb6w6yXIdwByNjYxBt+c1IBi47Lg8hDxmtegB/F86N9sCcrxvuPvrs3ig63CuP0pIO4Bo0feXP13giaD0zi81A74cmBCg6ND9tyjgc+p90JKYoux45OzgO+rTC6EXXpucQKyTYm1YjmI/WuPHgPjOdhy2r69o5AWYJpgVd2NjLScz/wZxO/sUcdO8jfsjnjnrMYlEC+MkC5KfEOTlRoLTXKZWmzoHX0zKtBL45igW7uIyTO5e6uOnZ/VhqqWz+RqNN6NFRz4u4A2/RBQTtbU1x6L/mjw4hbavogIzH2HtG9EvNRH+qUQMiIDE9v5+gKfuIjCFULppNqt gLOhIvTf dsJ4WeuAnPkn5L2O1VwRp7l3kWgox8MHnzm3siSBe/3BcGR4jC5dtqzgwTtO6c9gIViO1nEERTh6RXwxfH9pGTRreTrStxtDZFNXYm25CH2VPlYcwB1RHVZq8jIWWUjtgG432PW+jwJYqQ0F5MrIkixfoxmzSostZh74TAIvoXSYRLKT4vrSdcc2AtDJHoaLt1g9Hyoz/vVZovW8QTJwle51YWX2ql+JXr+1A8FsgLznNrebHMJUxXSUDQQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Each driver is responsible for syncing buffers written by HW for CPU before accessing them. Almost each PP-enabled driver uses the same pattern, which could be shorthanded into a static inline to make driver code a little bit more compact. Introduce a simple helper which performs DMA synchronization for the size passed from the driver. It can be used even when the pool doesn't manage DMA-syncs-for-device, just make sure the page has a correct DMA address set via page_pool_set_dma_addr(). Signed-off-by: Alexander Lobakin --- include/net/page_pool/helpers.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index c7bb06750e85..873631c79ab1 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -52,6 +52,8 @@ #ifndef _NET_PAGE_POOL_HELPERS_H #define _NET_PAGE_POOL_HELPERS_H +#include + #include #ifdef CONFIG_PAGE_POOL_STATS @@ -395,6 +397,28 @@ static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr) return 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 + * @page: page to sync + * @offset: offset from page start to "hard" start if using PP frags + * @dma_sync_size: size of the data written to the page + * + * Can be used as a shorthand to sync Rx pages before accessing them in the + * driver. Caller must ensure the pool was created with ``PP_FLAG_DMA_MAP``. + * Note that this version performs DMA sync unconditionally, even if the + * associated PP doesn't perform sync-for-device. + */ +static inline void page_pool_dma_sync_for_cpu(const struct page_pool *pool, + const struct page *page, + u32 offset, u32 dma_sync_size) +{ + dma_sync_single_range_for_cpu(pool->p.dev, + page_pool_get_dma_addr(page), + offset + pool->p.offset, dma_sync_size, + page_pool_get_dma_dir(pool)); +} + static inline bool page_pool_put(struct page_pool *pool) { return refcount_dec_and_test(&pool->user_cnt);