From patchwork Wed Sep 20 11:58:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13392582 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 2DDDFCE79D4 for ; Wed, 20 Sep 2023 12:02:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB9506B014B; Wed, 20 Sep 2023 08:02:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B69956B014C; Wed, 20 Sep 2023 08:02:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A399E6B014D; Wed, 20 Sep 2023 08:02:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 90F1C6B014B for ; Wed, 20 Sep 2023 08:02:30 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 34469A1160 for ; Wed, 20 Sep 2023 12:02:30 +0000 (UTC) X-FDA: 81256838460.22.DCECC60 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf10.hostedemail.com (Postfix) with ESMTP id 1BD1CC0024 for ; Wed, 20 Sep 2023 12:02:25 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf10.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695211347; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HtyQut5Ox5O25x5oa4M9ImK9wI6N4z503fUlerZ/CWA=; b=DW6zlDSlXWbeeY+QSSUSH6+YEp4he7ZiKbkNG7kn5tOzso8EhzQs2y6PvUNpGnhVFnMJNV U+jOoRr7tpgheiPyv8o445X1VKDiA8jtHQRfs+12tp907CrR7vg85FX7qLy42E0S1fa/pb Scx9+UoHJHPY2890Kmjw0msCAs1mpqo= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf10.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695211347; a=rsa-sha256; cv=none; b=pAYuBmcREfXeEZ/3cMe27D5TqKcSFhaSfnR26R6p7x8tWHaP3WX/gMMbgv3dN/Pk0/daNj etJmoZNDNdbc97XajB0kuuhRVPVzhej42MjVmVh90ne2t3zHhK0m36GfbgZDVBnScbabGI qz1yZu7+7gPOlJqzCgPFVTXY8PRtnXM= Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RrHBb4W4LzVl3n; Wed, 20 Sep 2023 19:59:19 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 20 Sep 2023 20:02:17 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Lorenzo Bianconi , Alexander Duyck , Liang Chen , Alexander Lobakin , Guillaume Tucker , Matthew Wilcox , Linux-MM , Jesper Dangaard Brouer , Ilias Apalodimas , Eric Dumazet Subject: [PATCH net-next v9 1/6] page_pool: frag API support for 32-bit arch with 64-bit DMA Date: Wed, 20 Sep 2023 19:58:50 +0800 Message-ID: <20230920115855.27631-2-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230920115855.27631-1-linyunsheng@huawei.com> References: <20230920115855.27631-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1BD1CC0024 X-Stat-Signature: aqa6hn7ygyd91ha1pff81g8nxc6atpna X-Rspam-User: X-HE-Tag: 1695211345-748296 X-HE-Meta: U2FsdGVkX18EYqoD6nD47Mz7lodxFJWLKEakn85FgoczTAVJcx3HxMFHx271cZ5t51ZFNX15Qv2HT06ugUh0Z2kVWBAVfczetENw0MPWE62aJlnMhIMgYnN7O7xn24EKNZto7wsUef1zlR3TbdOoWVQQuRyiQhtoBASc9Ur5h2YfYcQytEQyppyy60CKvkaNU6cw0tZ/eyGbk64Vs+l9eYtzbdbL1/aybODk2Rq3JyHNvApYoqdLYGw3SmWiubni1x8RK1VSfxWTRIHcxl7BY15FkshQJw3GFtXQuEdoDuYMEUKGxHehqLrmFXqhjskxNVbhwF/m2PgowtQpT7bWWSJEMYmNfyif8aCHTuCvIivvJpctaTy4w+DSwtQAfKiQ/O4TYWkP5x7qIEPueIprrs2CHj0248LnFeiT/o/36a7uxHs3YY1xowU6Mgs6Y4mai6VNOxBRKCLmOG0U14Oc0rrrRZJNxgA/tWpT1Jz1GpHsyvIKXomkBUZxIjJ2ljYVwQk1Za1dOX/Kv3VRSyklV1KYhYyR0XL8HEzDtAB99LHm3k5Q4DN4TazV1wBF/AL/zPN+Y8CQne8S/aajKY0bU/Zmej3yRjH+g3XaJBAkShWFmD3upfJWDFcD13ZqtcaG2+PB2k5rynkU1m0NtAiwJLtRu4jpbg654SjX3HgpuHwnu2o0X0d1sAnr0ctaaeOV3nGmxUnOQJww650Bz5hh7DokLnWKUQxI9PPG/zrNip0TJJtDf8K3TiL33RtWHRrE2V0dzH09pGTp/C5DNBmNJj5x03D11GkkqfWLftPhUoP7RtXLvMNff9GiPNcx/OW2BS4XmpDIqY1RK1jFeDH3Q1GGaWoOG50g7faLLQuGHxzBEZwijU0v4qA003dCB99uF2YCs3NiutvWHlwLl+JGhSD/E14yS8AMSTPWg6GwCGYmHFr8ADDq+9Hs53jY0IxgH5VR/CvKkphBGDujO/Z 3o62LQ89 Wj9Z/8kyRRAniT9Mz4paPUjxktwqi5zZtZogEPzHUD32bEuyULnaucW9VLGu446gsZFTS1qA088F9KtjckRHA45Wz7YLgRnTdvTQN5R+VV8SHo9B5G+UpDA69EFcKG2FdJIszxmEIrlnvhfpIjyCm4sDqTHdUx7RNGI2JPMBxdhFm4gqZW/YcJNU6rZ1bXE/b1npuOXegSFCDp4Acww8Oz281emuh5l99qJSpk7IY9i3iYh+3OTW8V5shAfO6cKcflwY3L57TPjtTYiAQm/GApLNQ/SY3imhK4DwTsSWuvRNjlyrrrR5IRCUALse136Me81VY4/P6htSBsap92NOQn3OZ6esTSmDz9F+eiM0h6/LJ8Fhrgtl52OKeMUgj1gR64ktAdw3emq9bY4Yaae+QHkt7EW8Jare1XD3ENpd1lmICtClny+q4tGKSw/GdepEoOZXuz0vmkxHwhD1lPI3fUV5vFXXHpFJTFpb4IhxrLzYqPT35pZbLB2HS6ZGTsvNVeQFCU7RmePqD0Uf0tI72/TV6EBwC8xWZRQtCOPFxgTGYZm4= 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: Currently page_pool_alloc_frag() is not supported in 32-bit arch with 64-bit DMA because of the overlap issue between pp_frag_count and dma_addr_upper in 'struct page' for those arches, which seems to be quite common, see [1], which means driver may need to handle it when using frag API. It is assumed that the combination of the above arch with an address space >16TB does not exist, as all those arches have 64b equivalent, it seems logical to use the 64b version for a system with a large address space. It is also assumed that dma address is page aligned when we are dma mapping a page aligned buffer, see [2]. That means we're storing 12 bits of 0 at the lower end for a dma address, we can reuse those bits for the above arches to support 32b+12b, which is 16TB of memory. If we make a wrong assumption, a warning is emitted so that user can report to us. 1. https://lore.kernel.org/all/20211117075652.58299-1-linyunsheng@huawei.com/ 2. https://lore.kernel.org/all/20230818145145.4b357c89@kernel.org/ Signed-off-by: Jakub Kicinski Signed-off-by: Yunsheng Lin CC: Lorenzo Bianconi CC: Alexander Duyck CC: Liang Chen CC: Alexander Lobakin CC: Guillaume Tucker CC: Matthew Wilcox CC: Linux-MM --- include/linux/mm_types.h | 13 +------------ include/net/page_pool/helpers.h | 20 ++++++++++++++------ net/core/page_pool.c | 14 +++++++++----- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 36c5b43999e6..74b49c4c7a52 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -125,18 +125,7 @@ struct page { struct page_pool *pp; unsigned long _pp_mapping_pad; unsigned long dma_addr; - union { - /** - * dma_addr_upper: might require a 64-bit - * value on 32-bit architectures. - */ - unsigned long dma_addr_upper; - /** - * For frag page support, not supported in - * 32-bit architectures with 64-bit DMA. - */ - atomic_long_t pp_frag_count; - }; + atomic_long_t pp_frag_count; }; struct { /* Tail pages of compound page */ unsigned long compound_head; /* Bit zero is set */ diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index 94231533a369..8e1c85de4995 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -197,7 +197,7 @@ static inline void page_pool_recycle_direct(struct page_pool *pool, page_pool_put_full_page(pool, page, true); } -#define PAGE_POOL_DMA_USE_PP_FRAG_COUNT \ +#define PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA \ (sizeof(dma_addr_t) > sizeof(unsigned long)) /** @@ -211,17 +211,25 @@ static inline dma_addr_t page_pool_get_dma_addr(struct page *page) { dma_addr_t ret = page->dma_addr; - if (PAGE_POOL_DMA_USE_PP_FRAG_COUNT) - ret |= (dma_addr_t)page->dma_addr_upper << 16 << 16; + if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA) + ret <<= PAGE_SHIFT; return ret; } -static inline void page_pool_set_dma_addr(struct page *page, dma_addr_t addr) +static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr) { + if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA) { + page->dma_addr = addr >> PAGE_SHIFT; + + /* We assume page alignment to shave off bottom bits, + * if this "compression" doesn't work we need to drop. + */ + return addr != (dma_addr_t)page->dma_addr << PAGE_SHIFT; + } + page->dma_addr = addr; - if (PAGE_POOL_DMA_USE_PP_FRAG_COUNT) - page->dma_addr_upper = upper_32_bits(addr); + return false; } static inline bool page_pool_put(struct page_pool *pool) diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 77cb75e63aca..8a9868ea5067 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -211,10 +211,6 @@ static int page_pool_init(struct page_pool *pool, */ } - if (PAGE_POOL_DMA_USE_PP_FRAG_COUNT && - pool->p.flags & PP_FLAG_PAGE_FRAG) - return -EINVAL; - #ifdef CONFIG_PAGE_POOL_STATS pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats); if (!pool->recycle_stats) @@ -359,12 +355,20 @@ static bool page_pool_dma_map(struct page_pool *pool, struct page *page) if (dma_mapping_error(pool->p.dev, dma)) return false; - page_pool_set_dma_addr(page, dma); + if (page_pool_set_dma_addr(page, dma)) + goto unmap_failed; if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV) page_pool_dma_sync_for_device(pool, page, pool->p.max_len); return true; + +unmap_failed: + WARN_ON_ONCE("unexpected DMA address, please report to netdev@"); + dma_unmap_page_attrs(pool->p.dev, dma, + PAGE_SIZE << pool->p.order, pool->p.dma_dir, + DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING); + return false; } static void page_pool_set_pp_info(struct page_pool *pool,