From patchwork Thu Feb 15 14:55:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 13558585 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 B4698C48BC4 for ; Thu, 15 Feb 2024 14:56:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3AD028D0025; Thu, 15 Feb 2024 09:56:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3347C8D0022; Thu, 15 Feb 2024 09:56:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04E3C8D0025; Thu, 15 Feb 2024 09:56:19 -0500 (EST) 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 E17758D0022 for ; Thu, 15 Feb 2024 09:56:19 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B504112111E for ; Thu, 15 Feb 2024 14:56:19 +0000 (UTC) X-FDA: 81794338878.18.126A414 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf09.hostedemail.com (Postfix) with ESMTP id B3B84140038 for ; Thu, 15 Feb 2024 14:56:17 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b="cE/SfAQT"; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf09.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708008977; 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=f2uzIED0RGgrcDO6EVVxl3NNU/jaMuJjJACfUgXp0rs=; b=czA+CrxY9zrS8SIsYcd0dwsV9QGseTClTL/BfdFS6Tehy8ZLhWNNJK2ZWGi6RG7KPQ5hDw 1/PSfQLEjoM7/q9W46iuxGrkRPibERVYK08kfrR9NWR0QkeC3V2gwuHfoj37+93gUF07W3 DjIA0Ep9eQeClBeAKZ7GOMLBDlS5O28= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b="cE/SfAQT"; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf09.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708008977; a=rsa-sha256; cv=none; b=25YHPrDuNMNyhtIIgszDIHJ2JC0IiAsCxxtpz7Y+do9tQw8Ea/48bcmCjl6LzIwXvREQpw j1BKfzstPC7fGrTmQ8zsFAcAfV4DW2wtBnQXeP7k4Sk0UlMsyl7uA3tLhCtPsF7P3WND7l jFAoOGf/hHSDMBP1L4tdLd96ScSwntw= Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a29c4bbb2f4so124901266b.1 for ; Thu, 15 Feb 2024 06:56:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1708008976; x=1708613776; 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=f2uzIED0RGgrcDO6EVVxl3NNU/jaMuJjJACfUgXp0rs=; b=cE/SfAQT5+AtdH0LMg7hWC2LuqEjiLkpsj8pWVJzAmVuvfVY3TBhgK6QIGQE4vHLnK 8wF6lwzdarVW9rWExcfj8dOENqD1c5sgT7In60gY70jUSljwTn8MULQlf7OpG7d2A2pM 3p0OrdAg8HskAX3biGoBRW9QOFSXWEuAl+hnLYZimX+5LlkD9mZWR6Pz9kCRkkhhS/xm xt+SWVEIzV65PuWvr6mMiNFa6A8prZcb6/VGG0A1N25XdbSndSKGvUHgDjkFtzwlmbsh Z6x+PpWiiHyKGsmEpJYQASfIX4E3VfWVvbuh23UkOJx1s1NTv4mYDtLzcbbLW8VFwA8d 5bTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708008976; x=1708613776; 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=f2uzIED0RGgrcDO6EVVxl3NNU/jaMuJjJACfUgXp0rs=; b=TOlpfDK8W9t/O4XaknEq+/6IK+cEB1Ltx98cV+OpRD95TIXOHt5tbrdE0GhwYj81x5 beuK0J5U6259GE3a8VvCRkSfSNBXsh2cGSYSApaSkPqhL4IBMiXzICwLVmmWudDDuUb4 RqqgOsGXcBpH64dC3QOGbpvQ0x3qxEuNjPc0sjCGZOacg12cMfFZo0Npd642jIX8vjMy i8dYp3yC66FVTuE7WxKZzERfJau2z/l7+OOI9QLbQO+rtKIDgPRpm9CSk/OPhQkyMF+e mrnWtRT4MBP0+UC91mUhFUVnjzwEwlwxrcvY7VSnpAawWOq9Sm3lB1R4eyjEIU/l0ipA tMdw== X-Forwarded-Encrypted: i=1; AJvYcCUP+NDaej0rSoRGntpzu1zpzk+ncZNpM0J7FY7y5G0yJj7JVQMkctyGD/4Q7j0hbjtVjwAxuM68lQoGS2Gjh3f1I3s= X-Gm-Message-State: AOJu0Yxiv7bdIQhnKhOio6YiwVIbRQk3fePlGK7gALwcH5Y8EVWMt4u3 SK8PBsDLEAhEwfizPOGxqRMDuPfBLaYWHMx636I9D0UXO3XEHGXZdojEJqyM25k= X-Google-Smtp-Source: AGHT+IEogiGpBqeDYKaXFqCb508Hw08QFq2QQBDux+q+ITm+88gc/oYv7hnWpDwgdVDup9PJgOOyvw== X-Received: by 2002:a17:906:4894:b0:a3d:bbea:da41 with SMTP id v20-20020a170906489400b00a3dbbeada41mr67225ejq.12.1708008976461; Thu, 15 Feb 2024 06:56:16 -0800 (PST) Received: from raven.intern.cm-ag (p200300dc6f267100023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f26:7100:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id s18-20020a170906169200b00a3d1897ab68sm631175ejd.113.2024.02.15.06.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 06:56:15 -0800 (PST) From: Max Kellermann To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Max Kellermann Subject: [PATCH v1 05/14] linux/mm.h: move page_address() and others to mm/page_address.h Date: Thu, 15 Feb 2024 15:55:53 +0100 Message-Id: <20240215145602.1371274-6-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215145602.1371274-1-max.kellermann@ionos.com> References: <20240215145602.1371274-1-max.kellermann@ionos.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: B3B84140038 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ra7cbpxyfaxwd4secfdbripuzxyuhdba X-HE-Tag: 1708008977-258577 X-HE-Meta: U2FsdGVkX1/h/LXpi3Cxjwo9Y5SeKv723ICgsMMwlyN9eRIBDIxEyzrDGYO9YZ8i6ogjA3sp9kGBMrfGzZ3bdQWJw8ED1pEvbII9vkVuEUuVdC1w8KnPgiqiGNxC1n16CxANMR06Wftbh+2wtO2MvdufVbx83ZNik4TKISvnD9m9yol62f0dr8c4P/tulGlBH5LWu/vhj3Hi/iHSZ0r7CDbfF/YF7TS019omZtCqxoWpe+9bLoKvOaPMbMvYsEp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Lhb+HvSMaFiq5MQGgMJdltPdOOXsB8S+Lb1sp5YbfMR1kpd8PdBZbUzyyV/F4WyA0rTGkuI= 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 in 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 84a49178b94a..2cc39916cf04 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 @@ -103,10 +103,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 @@ -210,14 +206,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) @@ -2117,44 +2105,6 @@ static inline int arch_make_folio_accessible(struct folio *folio) */ #include -static __always_inline void *lowmem_page_address(const struct page *page) -{ - return page_to_virt(page); -} - -#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 - -#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); -} - extern pgoff_t __page_file_index(struct page *page); /* @@ -2217,10 +2167,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..e1aaacc5003f --- /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 + +static __always_inline void *lowmem_page_address(const struct page *page) +{ + return page_to_virt(page); +} + +#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 + +#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 */