From patchwork Tue Jun 4 09:08:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 13684918 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 4E2E5C25B78 for ; Tue, 4 Jun 2024 09:09:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0A0F6B009A; Tue, 4 Jun 2024 05:09:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A42AD6B009C; Tue, 4 Jun 2024 05:09:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E3AE6B009F; Tue, 4 Jun 2024 05:09:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 69F5B6B009A for ; Tue, 4 Jun 2024 05:09:17 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 359021A0950 for ; Tue, 4 Jun 2024 09:09:17 +0000 (UTC) X-FDA: 82192632354.09.0144857 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf05.hostedemail.com (Postfix) with ESMTP id 496AA100015 for ; Tue, 4 Jun 2024 09:09:15 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=Gsq0yzUh; spf=pass (imf05.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com; dmarc=pass (policy=quarantine) header.from=ionos.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717492155; a=rsa-sha256; cv=none; b=G6Ulwac/wyoJ3ZHZo3oaFrCzxirQxzflakIoZ+ysA/t7+dIqSjPq9qekunexpGRl4X9Tyc veEEYprF2jv5hOS4IvPYhBr1sAueDJhi1glpw5989JtweC/CL2PHYRlRI3ATPRq27lN+sw 1hzaHAtVdS+Ou4XF//apxdrroKSxOKg= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=Gsq0yzUh; spf=pass (imf05.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com; dmarc=pass (policy=quarantine) header.from=ionos.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717492155; 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=oVxAKKIuGzczdMzzJCnaqt6bk9QQZalHnDhl7auSlGA=; b=sTpP5mQVpA9DYDF7MHyH6+eTbgF0nahS1Xtiqz806JbYndtS1xWvTf6Ah9pxPUAy235gn5 Cgw4qXt102YHsBJ0nHtZvwDXFu/YE+ebYfSbDaVNP5lnOx2oEvIlXsqtehfwK5VQwl/498 PMdto2wFm4RpzP46nEBY0sDqxVXFv6k= Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a691bbb7031so218663566b.1 for ; Tue, 04 Jun 2024 02:09:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1717492154; x=1718096954; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oVxAKKIuGzczdMzzJCnaqt6bk9QQZalHnDhl7auSlGA=; b=Gsq0yzUheH43yuwbDVk6S7EWVaR0hi7q2EUKAUdwttJFFnhGpmMJHLegHApWjZIheY WFs0yT46rT5zV0tXybM6vc51Dy4Qkl9MA+CwHaGVsH0hacUeEEAGeflnQM8vzogLiFlh ZuFCGxwTRD1yZ7I1l96hzOEk7rtiKU2PQdH629cGj1hTPBqKJEUPyssErWk5ye27oDUT xdxCrOGb5qV6M9AZ0kskLRccHuUMCI0BZxVcJ+indCm+IMbb33GHw+dUt5H5IY0xPWV6 9VwoM5K9P17HpwWTrzQ+OFhqyOdOfWDghWnOQsQ2qWH7Tv9UCMcUVVDqjc+2w3NXkyQe re3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717492154; x=1718096954; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oVxAKKIuGzczdMzzJCnaqt6bk9QQZalHnDhl7auSlGA=; b=UgGb8BJ/ga3yH54w7gz8HLnSsW/EwfrluUogT4w5fc9y5OI9IDv4JTuAKAKXQeZRAv bmUcx4GoCYied2eCzeielIUgSTiqk865jbBgRV0OR9TSXH7XiFpwQG7g/oMw1fLS+qBu sRSw2fy69RaEAwsr7VitW2eUjR+XRPP0c/cax38lGMdG/GP7PVsJ3jxWwAX6cX5tJgPk TUb+Ft445fPLKNXj9Q8d6rQuWIfKOzpuzO5OTxSo53G3rUPvp7+2t8y3GyFGsBQJVvaL jNK2bBkpR5K9UriKOilZl/k6kDxveK8jwE19WfZ6dp30cxwzSFmrNUHHHsztAvYn4NOX u+zA== X-Forwarded-Encrypted: i=1; AJvYcCWjn+Le52pGrVFREpuhB4XA/rT9ZXNuAFjXzSAmhpP06yFpyB/2WxJ6976g4bpqyyUfasyL+GqJEefU06MK4BRWoDc= X-Gm-Message-State: AOJu0Yx6ae/tUBgOaJux+oq2vxBYgLO47jRM+RimEo2HGJJgiViE/N75 hGWfeubUGhh/lC/cYCndXijNbd2tHzwolCKaAiGivJrW/Jsq0vfyuoTq2WwteAo= X-Google-Smtp-Source: AGHT+IGOgen2Jx0g/YQ6+0A61e2VmACILINzoPWZHBtfeJO66xBbBL4F3Gr+Gh7gEwW1i0zrX6OeUg== X-Received: by 2002:a17:906:c94d:b0:a67:aa2b:1028 with SMTP id a640c23a62f3a-a681fc5cbccmr901709666b.8.1717492153798; Tue, 04 Jun 2024 02:09:13 -0700 (PDT) Received: from raven.blarg.de (p200300dc6f4f9200023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f4f:9200:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a68fa49e66fsm328376766b.129.2024.06.04.02.09.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 02:09:13 -0700 (PDT) From: Max Kellermann To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: willy@infradead.org, sfr@canb.auug.org.au, david@redhat.com, Max Kellermann Subject: [PATCH v6 06/15] linux/mm.h: move page_address() and others to mm/page_address.h Date: Tue, 4 Jun 2024 11:08:36 +0200 Message-Id: <20240604090845.2182265-7-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240604090845.2182265-1-max.kellermann@ionos.com> References: <20240604090845.2182265-1-max.kellermann@ionos.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 496AA100015 X-Stat-Signature: csyi983hmxwafzjdqf7wdo4rp8fky3oc X-HE-Tag: 1717492155-948409 X-HE-Meta: U2FsdGVkX1+RclLaSxo4jYgDOhy0BoAKWNI0Rs3cFGEAugU54c/lOSVRV13FCmZUXkueC//bKklcroKAkRGyptiuas3z2W9MhETF67Rl79snz2k3MLMw1cJWUWKL0x2mUniLdVD1u79cTz2JFJqAqBFdmeQuNX9y5Yx1NJ94JN5gfHJDTwZbgko5CXd9U2fHu6QJj3NV1uvE/Ozzu3E0wZhZEgQ6MbUsVDxMSiCyCpvRAxkN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Gb75WUmFj8FXqGBdAH8vLgpLKVlFBaxLqO0bP0Vb4bdtqQdnarA7YKT6P3WCT5XYplLhUCNALRtSn3F9xLiwIvCEoYLeUhcN7grmknMh140= 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: Prepare to reduce dependencies on linux/mm.h. page_address() is used by the following popular headers: - linux/bio.h - linux/bvec.h - linux/highmem.h - linux/scatterlist.h - linux/skbuff.h Moving it to a separate lean header will allow us to avoid the dependency on linux/mm.h. Signed-off-by: Max Kellermann --- include/linux/mm.h | 56 +------------------------- include/linux/mm/page_address.h | 71 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 55 deletions(-) create mode 100644 include/linux/mm/page_address.h diff --git a/include/linux/mm.h b/include/linux/mm.h index c9a3f1c0ae07..014db2b39c16 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2,7 +2,7 @@ #ifndef _LINUX_MM_H #define _LINUX_MM_H -#include +#include #include #include #include @@ -105,10 +105,6 @@ extern int mmap_rnd_compat_bits __read_mostly; #define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0)) #endif -#ifndef page_to_virt -#define page_to_virt(x) __va(PFN_PHYS(page_to_pfn(x))) -#endif - #ifndef lm_alias #define lm_alias(x) __va(__pa_symbol(x)) #endif @@ -212,14 +208,6 @@ int overcommit_kbytes_handler(struct ctl_table *, int, void *, size_t *, int overcommit_policy_handler(struct ctl_table *, int, void *, size_t *, loff_t *); -#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) -#define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n)) -#define folio_page_idx(folio, p) (page_to_pfn(p) - folio_pfn(folio)) -#else -#define nth_page(page,n) ((page) + (n)) -#define folio_page_idx(folio, p) ((p) - &(folio)->page) -#endif - /* to align the pointer to the (next) page boundary */ #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) @@ -2174,44 +2162,6 @@ static inline int arch_make_folio_accessible(struct folio *folio) */ #include -#if defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL) -#define HASHED_PAGE_VIRTUAL -#endif - -#if defined(WANT_PAGE_VIRTUAL) -static inline void *page_address(const struct page *page) -{ - return page->virtual; -} -static inline void set_page_address(struct page *page, void *address) -{ - page->virtual = address; -} -#define page_address_init() do { } while(0) -#endif - -#if defined(HASHED_PAGE_VIRTUAL) -void *page_address(const struct page *page); -void set_page_address(struct page *page, void *virtual); -void page_address_init(void); -#endif - -static __always_inline void *lowmem_page_address(const struct page *page) -{ - return page_to_virt(page); -} - -#if !defined(HASHED_PAGE_VIRTUAL) && !defined(WANT_PAGE_VIRTUAL) -#define page_address(page) lowmem_page_address(page) -#define set_page_address(page, address) do { } while(0) -#define page_address_init() do { } while(0) -#endif - -static inline void *folio_address(const struct folio *folio) -{ - return page_address(&folio->page); -} - /* * Return true only if the page has been allocated with * ALLOC_NO_WATERMARKS and the low watermark was not @@ -2261,10 +2211,6 @@ static inline void clear_page_pfmemalloc(struct page *page) */ extern void pagefault_out_of_memory(void); -#define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK) -#define offset_in_thp(page, p) ((unsigned long)(p) & (thp_size(page) - 1)) -#define offset_in_folio(folio, p) ((unsigned long)(p) & (folio_size(folio) - 1)) - /* * Parameter block passed down to zap_pte_range in exceptional cases. */ diff --git a/include/linux/mm/page_address.h b/include/linux/mm/page_address.h new file mode 100644 index 000000000000..630fc4e2be95 --- /dev/null +++ b/include/linux/mm/page_address.h @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_MM_PAGE_ADDRESS_H +#define _LINUX_MM_PAGE_ADDRESS_H + +#include // for struct page +#include // needed by the page_to_virt() macro on some architectures (e.g. arm64) +#include // for PAGE_MASK, page_to_virt() + +#if defined(CONFIG_FLATMEM) +#include // for memmap (used by __pfn_to_page()) +#elif defined(CONFIG_SPARSEMEM_VMEMMAP) +#include // for vmemmap (used by __pfn_to_page()) +#elif defined(CONFIG_SPARSEMEM) +#include // for page_to_section() (used by __page_to_pfn()) +#endif + +#ifndef page_to_virt +#define page_to_virt(x) __va(PFN_PHYS(page_to_pfn(x))) +#endif + +#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) +#define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n)) +#define folio_page_idx(folio, p) (page_to_pfn(p) - folio_pfn(folio)) +#else +#define nth_page(page,n) ((page) + (n)) +#define folio_page_idx(folio, p) ((p) - &(folio)->page) +#endif + +#if defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL) +#define HASHED_PAGE_VIRTUAL +#endif + +#if defined(WANT_PAGE_VIRTUAL) +static inline void *page_address(const struct page *page) +{ + return page->virtual; +} +static inline void set_page_address(struct page *page, void *address) +{ + page->virtual = address; +} +#define page_address_init() do { } while(0) +#endif + +#if defined(HASHED_PAGE_VIRTUAL) +void *page_address(const struct page *page); +void set_page_address(struct page *page, void *virtual); +void page_address_init(void); +#endif + +static __always_inline void *lowmem_page_address(const struct page *page) +{ + return page_to_virt(page); +} + +#if !defined(HASHED_PAGE_VIRTUAL) && !defined(WANT_PAGE_VIRTUAL) +#define page_address(page) lowmem_page_address(page) +#define set_page_address(page, address) do { } while(0) +#define page_address_init() do { } while(0) +#endif + +static inline void *folio_address(const struct folio *folio) +{ + return page_address(&folio->page); +} + +#define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK) +#define offset_in_thp(page, p) ((unsigned long)(p) & (thp_size(page) - 1)) +#define offset_in_folio(folio, p) ((unsigned long)(p) & (folio_size(folio) - 1)) + +#endif /* _LINUX_MM_PAGE_ADDRESS_H */