From patchwork Fri Oct 13 06:48:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13420188 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 EF675CDB47E for ; Fri, 13 Oct 2023 06:48:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3558F8D015D; Fri, 13 Oct 2023 02:48:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DE638D0015; Fri, 13 Oct 2023 02:48:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A57B8D015D; Fri, 13 Oct 2023 02:48:10 -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 06E4E8D0015 for ; Fri, 13 Oct 2023 02:48:10 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BF98E4015A for ; Fri, 13 Oct 2023 06:48:09 +0000 (UTC) X-FDA: 81339508698.16.90F9073 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf06.hostedemail.com (Postfix) with ESMTP id 3BEB1180018 for ; Fri, 13 Oct 2023 06:48:05 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697179687; a=rsa-sha256; cv=none; b=gml3HObK4l3oR9IyPWb22DoO6guAuKh9A3TyDD2Od4WpaaQTg+ffTDwJ+ltGvd6twjTxHf iDjECVq1BhqFgZCZkMsyB6yQIiRsuXjEKDYPjqSJ5o8SsvqcxD/EtlBmSiTPhATyqrperV Iw/Sa1EyaVlgoh6+lkA2Pw4G2iZ+HVY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697179687; 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=zVA7elN/2O4Fscb3Hd0qUhvQabTGrv5/OgZx4nAAiOA=; b=TdXgmSZBHjcN2hoPetkuN05qqAovni1K+cz6CGMOZROPn8ilvclbcKZ2sxwGZGyZ6GqoZ7 n6CTb1AarrTPQjcAYu/TPzCywG03KwOBZIu7xyLHstFXg7p+XPnYFF/S+cqPonbdprSuJt BkS4qwGnxMbWouv12xJysa5GpU88m3M= Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4S6H5L64DqzvPxv; Fri, 13 Oct 2023 14:43:18 +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; Fri, 13 Oct 2023 14:47:57 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Lobakin , Lorenzo Bianconi , Alexander Duyck , Liang Chen , Guillaume Tucker , Matthew Wilcox , Linux-MM , Jesper Dangaard Brouer , Ilias Apalodimas , Eric Dumazet Subject: [PATCH net-next v11 1/6] page_pool: fragment API support for 32-bit arch with 64-bit DMA Date: Fri, 13 Oct 2023 14:48:21 +0800 Message-ID: <20231013064827.61135-2-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231013064827.61135-1-linyunsheng@huawei.com> References: <20231013064827.61135-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3BEB1180018 X-Stat-Signature: kuuh7hy943atw1wt3cqfh4qr7u9gy1g4 X-HE-Tag: 1697179685-232714 X-HE-Meta: U2FsdGVkX1/hl/TmXuCkGfp/xoYZeBTRjKYoEILWl+g29Ce00JqvtHTpbghPSSSDX4APBL/Ao8yz8Us0YRCbf8T8lxsa1xJNbzxQe8VwmqV2TdjyGUkcMv42TsOShbmmW8cGAfcU/+xludpZ8AH334OtsTuCTiHl2Hx2NvXUK/4FrWTiwB26jGTrNeCFfp6h40vpJ7dR9JVRCMwAUkNQ8B1XVa8Nhetnva0CBEt9yPmk10Y592Rq1qPJlc4vFMd/0RGuKN7evncl0NqW1Ond/h5Z8AeBOlAR7p0AWFq5b0nlcL3ZBro6CYB2wG+RxUPSwtIFAbiTT0SD7mKwCdcl1vJ+f8ddYBrcu/eIcgc5GtM3rYlr5iKNTrSsDLgH7MjmTiiQTDQvG+UtPaFyA1XawDpYM3ck3AUH4JqZV6hhqdkOKtHfh1K7V4SHKT6CBb0x3FSVvJMqZxtTNAIgd3tqHrjN521Rp13PvijftuOaascqXO7SdoC3EJ96KYrks94s9JollyfgjZlh8BIi9XciogsKDUfRCZHePgB2eiFmcTH6AtiDv6MVG28ledUXrPxMnpDwyRWJ6aLH7NJ2REHhPzRvVoXJTPe6NYVECpxrzCOtL9taZE9a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edence: 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 fragment 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/ Tested-by: Alexander Lobakin 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 Acked-by: Ilias Apalodimas Acked-by: Ilias Apalodimas --- 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 8e7751464ff5..8f64adf86f5b 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,