Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp151112lqp; Thu, 4 Apr 2024 09:14:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVv3XdxyTth59ybPKA8ucoAafqDkdF8O64xCVVH1UMbZielLS04sYvPdUC8/50SvDdJFiPwyF2iSOhyDkY1sjbzS4TfrbDP43FATLxtnA== X-Google-Smtp-Source: AGHT+IFB8jzk9svamGBvDVfb2V+UmDR8v37hbKZNbNr3wrrfy0W0lpd9/spJpbOCPftx83LB4GJR X-Received: by 2002:a05:6a21:78a8:b0:1a5:6abb:7503 with SMTP id bf40-20020a056a2178a800b001a56abb7503mr271314pzc.49.1712247265772; Thu, 04 Apr 2024 09:14:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712247265; cv=pass; d=google.com; s=arc-20160816; b=YepMIkfl36F7m0SlzE6RzzYZnjVQVeovXQ1x/jiASpSreYaHovkqWkh1oDa+f7abTu +yX1FE20IJscwWJ5JpSS0u0aBLqKY6ptcJ6QlpkEqijf6FKTRmqMgvtXDImKRgePqve2 +4uel8jr7SKvp/4fqRgs6//fh4+gfXZpsAnRPtxDl4SgIdjM4KApOtIOPAIg2a5atyku 1aR7OoejYH9s3ckAbfSqwaT+IE/4Y0TMlv+mwJapM2hhdI9M7+aAW1HvXdKMNwHXKeiY mXhoH2fNesAJXPvSBy+K6UuRm3l2hHscx8Z7UQ9fzUUGxZH5MWZ8qWia2H2B/lBGvFz6 9C0A== ARC-Message-Signature: i=2; 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=cP32Q3dEgPXhmR3/rYVgH7UWTRGTR3MvWVNydA/XXaI=; fh=B5gvjxB31ljWn9/oP8q8GGKyJ7/RnV7iry/PFi28Ayg=; b=Di8mFEp6HzhuGFFE0Ma3RiZ68dv/1WrC+L7dtCr16nfURPMG7uQo/BhPzWhNPr48ah lXR0kXrCjwt7PhM+QPZQPkp031jyzspnhkGGq/qJoFwV/osZ++RXiBP9sG77cdo1IYTw rp33UG743UbFcWzC8Qz0JHxA98wtZC4U/M3vLK6ncsIcU7iLMAhEOn1XvzLX7m1L9JT/ gjhCqfcC+WoA2cb1aGV1jgqm/vPoWBgRXuKeHnDj65IgG5ftMY4Fpi4Goh1L909DBKNP X6Lr9iYUWSm4W+nZF4H5JZe1XKys1ATWtl35e3N22SJbkou4j2krtMGhMsb3W0G6oymj kE8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=E+8LdYcP; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-131760-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131760-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p29-20020a637f5d000000b005dc12a99c6esi14979148pgn.355.2024.04.04.09.14.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 09:14:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131760-linux.lists.archive=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=E+8LdYcP; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-131760-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131760-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D27FCB29455 for ; Thu, 4 Apr 2024 15:49:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 780E813441E; Thu, 4 Apr 2024 15:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="E+8LdYcP" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 06FE81339AB; Thu, 4 Apr 2024 15:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712245572; cv=none; b=mGCHJZpVdZtMAmOH3LZUn79A2fdLjSYmuK6FY1VVhwcIGt+7rnc0q1mV9kwOIzoWtjQFlkSMBaxmhTuM6X0ur8n1mCEz0VTuBU2u3b0SA9YYhHyrB9fnGJkg1EUXJ0IvfCN/XhaPkuLQ2a2zQ6eiIwzS2wUhXYZTDvIdLCrz7fc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712245572; c=relaxed/simple; bh=OhUqtf35fdgCEyiIWVQHl/adPq6y26tJ1DJr2rp+7fQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gSIxtOIlMhw8cUqefqiVngSvyqi+xO5OLjp4yTn5Lchq8qscwgQhiDC1/EdNLL7QmfCFa0H7WhOAFsvEnshLpFpzvV3N9FIiqzQq4pbKyRV3/P242ZKPZGSbRIfi5tgipyjIy6PBkXelQUsiJRdXyaKGhXSOXA8NSoTT92+myS4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=E+8LdYcP; arc=none smtp.client-ip=192.198.163.12 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=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: VW9K3WsTTeWa1eaoxicF+Q== X-CSE-MsgGUID: NYP/HhyTTCCLurac+BEymQ== X-IronPort-AV: E=McAfee;i="6600,9927,11034"; a="11312225" X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="11312225" 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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); -- 2.44.0