From patchwork Thu Apr 18 11:36:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 13634540 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 94086C4345F for ; Thu, 18 Apr 2024 11:37:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2276F6B00A5; Thu, 18 Apr 2024 07:37:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D6A06B00A7; Thu, 18 Apr 2024 07:37:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0782F6B00A8; Thu, 18 Apr 2024 07:37:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D984E6B00A5 for ; Thu, 18 Apr 2024 07:37:03 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9A99516119D for ; Thu, 18 Apr 2024 11:37:03 +0000 (UTC) X-FDA: 82022451126.28.0F8F1E2 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by imf25.hostedemail.com (Postfix) with ESMTP id 7B28EA001C for ; Thu, 18 Apr 2024 11:37:01 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=DtyCqZki; spf=pass (imf25.hostedemail.com: domain of aleksander.lobakin@intel.com designates 192.198.163.11 as permitted sender) smtp.mailfrom=aleksander.lobakin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713440221; 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=IkXtCBgDKuWeqz2XLV2JMEvllUs/Yd/rxEuHoPJy8faDO+HUrMvuFmf6mX3FkNs1o6orT2 WEx8sv8S4YWoT4Leak0MsTNevkJaNMqtmg+SKU/ZTAL4+SO6TXkENFur/NLi7b9TJRwzVr l7DCvtOdSFyIz+2USuyLgk7RHe5l+F8= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=DtyCqZki; spf=pass (imf25.hostedemail.com: domain of aleksander.lobakin@intel.com designates 192.198.163.11 as permitted sender) smtp.mailfrom=aleksander.lobakin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713440221; a=rsa-sha256; cv=none; b=TmssFNPRoDUvhrB5lbjnn6ubwRn9yOE6RkHak9shJP2dPpyw/QhaGW7ip+PqMjGVmw4I96 Y1eIb1NsAdkrNCxjxyD3yUJAy8FDmwZh9WygCdM1Ef4wCn5qNcJhRmh5KMjAmhserDDq80 5Cx9pqVH7aWkqOsSbFzNBdZrk7SlS8E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713440221; x=1744976221; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OhUqtf35fdgCEyiIWVQHl/adPq6y26tJ1DJr2rp+7fQ=; b=DtyCqZki4N2mfsrLOR80iko2QDBcSN1uE1ah2kllTy4kzdQ9UZjK1tBO 4B9UquFLDW3jGHg5PZu0S3guP9/F5RwvEzsgJTDXZ6uRf9FXANGWjsEjV ddwshXo7gg3kDN7Kj+fSB1xYLN2rF1XP4Pq9uU1b+huWlUWHWQviExuCy Z/vrFMgPR2vHUwrXazbwTscG2h3MrcppZpvcDuIrV3UIRQpmDUxlLEpfC 8Q7t3W6voPzN6O3ecKr+iGXxkOifQNyWQm/2273q220rhSpmVbXIPvacW J5K4jXbvRsgqsPUWAQNlzkfpxVsF99mA8Lsyp8tRMYDA7BARrlpTE4Hxs w==; X-CSE-ConnectionGUID: +5WVPCzyQZem12E0YglteA== X-CSE-MsgGUID: DFpfYzuSTgyCCaKuw57Ffg== X-IronPort-AV: E=McAfee;i="6600,9927,11047"; a="19587792" X-IronPort-AV: E=Sophos;i="6.07,212,1708416000"; d="scan'208";a="19587792" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2024 04:37:01 -0700 X-CSE-ConnectionGUID: nnD24O+AS8Ou8XYPzWCoNw== X-CSE-MsgGUID: i7kHYavwRdepzRSa2rF85g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,212,1708416000"; d="scan'208";a="27586122" Received: from newjersey.igk.intel.com ([10.102.20.203]) by fmviesa004.fm.intel.com with ESMTP; 18 Apr 2024 04:36:57 -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 , Przemek Kitszel , 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 v10 06/10] page_pool: add DMA-sync-for-CPU inline helper Date: Thu, 18 Apr 2024 13:36:12 +0200 Message-ID: <20240418113616.1108566-7-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240418113616.1108566-1-aleksander.lobakin@intel.com> References: <20240418113616.1108566-1-aleksander.lobakin@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7B28EA001C X-Stat-Signature: p6hx6bz4uzrb5fto4wh8qab4eari9obd X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1713440221-4898 X-HE-Meta: U2FsdGVkX19BxMvoq7qRfRWhqd6tdXkTre23fMzbRLk4RPy/UxZ09Bu0Gswda4yUKCw8t0T9gTr1rMBFgzp6vfo+ZfJbXkKnTKsREVP78arOCiA5TAaI9Iq7393YdSAHkGTF8y3uaDquXUg+oPfy1yivX/g5C2yMkjYmAcYBRjbbJolCiy+/lYNohoQ7INPVjIHThUfi5mtFXTEgjxaETX5wgBAPgyii03KBWSjBJlvZpdHuma5OosxK8nVx13RIuECdAmAOV0bl5mzkFhZks7zDRCE2GGli9fou8C0z0l8+I3/9yyLdE5IrfNUJF4pmT8gfgShdZb5rHx30PsaCKgMysA8OhMhuf5koS/1G3UjNcAkzAuqp1NABuKsjQgyZYaD9YrfSc2o1BlqJgeYqQ/os7i6BS9SFL6sflUDWAaYVdwu1pPUSzx2SuCJuoAAIk4iossdaXZD7wx2QztFW9vWWtOOok8clCjKBNujULKG8oaAzx7jSJXFfVpNLu9mb1mDyW/q6i4reLh9wDU/6NHCcpVdCRbZtsI2jRMdEd2zRWH2giW+UZX7G85p3AL6aaKZHABZ4UEllv8rRe+LZJ0wFSIhaRiKPMvkXyNSMgSAwP8r+ipfkvJ43GbhyoALWRkpto0aWHfMwfVbP3BVc7pZvph4WkaCpzGwqtupYP0RibVzDKZoLxMhAksZLlBpMpuJlUHzpo92g1SUSVzD7LpvWItaFerlsw1mAFwOp//Vbcd/ewkWn3vXKxj8ebLiaIsDhWxcZsEnBp7Lo/oH90q4t53dqJaOFpHgBpvU2GEMceqSJXPY71rE3Ht8PHSTP3+K68cPI35UNVL1IqO9YHHU8r8H7u9RpqSfofqutwHqyrYYKf3zoJOm8+yTZQdPPTfZJ6rD+4+dD7JDouJSCAq3RTj6uT1G906SJK+2hXTaGRdsvtMj7ZRtFQofKu+ceG9BjA1ruLOjJmSQzp6a zz9He6zT yXNaOb76gqp6662EnMhZPNzABmoe0W4StYWzxqfiUw53gctiB+hogErn0118aY2uvEGbRj/XiuRXbi4M0LiATeSjb3XHEIoAdwcsv311gPeSocVwtoTsNfl8H7Whs5/mcg0bogBnhdLUTUnwdQDpc4Fq6aSZbZbgV4qDbZUBts8j+m0VP4PL/ztLywtG/R3UESp6o1JrILycPdoNVnpjGZNUUQHnrjKUtV6UM+aEXDxCPR/9sbV7ufZaFWg== 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 Reviewed-by: Ilias Apalodimas --- 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);