From patchwork Thu Feb 22 11:50:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 13567166 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 3BB0DC48BEB for ; Thu, 22 Feb 2024 11:51:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41A1E6B007B; Thu, 22 Feb 2024 06:51:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A3456B007E; Thu, 22 Feb 2024 06:51:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F5056B0080; Thu, 22 Feb 2024 06:51:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 03DDD6B007B for ; Thu, 22 Feb 2024 06:51:10 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D8EBB80D88 for ; Thu, 22 Feb 2024 11:51:09 +0000 (UTC) X-FDA: 81819273858.07.53C7E09 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf09.hostedemail.com (Postfix) with ESMTP id 18F6D140005 for ; Thu, 22 Feb 2024 11:51:07 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=c0HDr1Ar; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf09.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.128.53 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=1708602668; 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=TYSYlSdUn/dXTjpoW2eB+NQW7lqG+bTDZOpmc2h8jwc=; b=60x0pE43kDQbiOZiODy/guNj0zG1iWaESphzsScgP7hCCBO1qnlnb0glGXShr7MlbAfltF 3B2tRjmBYrPx7TVqQyDbr8IlEX/VhVLwyuzwqir6OxinSCtxMVQR/UvyAkunluxWCJNG5Y qwO8DpoaWnFKoWiDPkn9F0/PiMmpJP8= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=c0HDr1Ar; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf09.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708602668; a=rsa-sha256; cv=none; b=dfsaQOXl4k4anxoX0AEynLQH24XVhPGsR72zuxxjGGvtQbdScRs0v/8lhvOKIE9gMuEW5R mel2UqesyqSZfnAnOpYQau2Omc6uzHh1Q6vOANHij+sa4g3P7swhj8+jurf5Rmp7SviYm3 S5/k/XDUdPl2J/8wD56yaXJ6KyM3pZQ= Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-41273f53c71so13504325e9.1 for ; Thu, 22 Feb 2024 03:51:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1708602667; x=1709207467; 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=TYSYlSdUn/dXTjpoW2eB+NQW7lqG+bTDZOpmc2h8jwc=; b=c0HDr1ArOoqFhtM7ccSDPPvo4Trl2Oz02cqfXsWw/fjgs5Yd0/rYbZeAPkmliQG4do xOUNkWZl7DTeXdOhWEf7XaQxQuVZPzusraAFa3v9F3xqxqxlU9QtMq87SLSWJsMlp8tk tZCEZMeftpt7v65O2fg9GUEQu1V7ylsNARiJ0Giwtp+OVg9pK2KowXNVHNHZyKmc1AvC N/jQf/dXHOUU3/rjVaCjgFlbEcA5g6pPo5dtKZ0RgIJNCZZxWzunC/0OOCvwNweORidU FXeBR4foY64T2Nu/TM0AQPQnEwVrdNOBsrn5yxsbdH2ckEPExoPhlgUgMbhfH7KdTY76 h8DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708602667; x=1709207467; 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=TYSYlSdUn/dXTjpoW2eB+NQW7lqG+bTDZOpmc2h8jwc=; b=V56ScqewiLuIQ8KYvkYsZ0ry1dC0QCAvZAlTx4ok8vrLgofIqnrtRGkwsaof35GRej NJAM6QjS3arGPN6G9iUpxFqnW0bOZQv/EdLLE5w38JoJgRcyzqiZBWIzCKIOSwGrh6qT KvD8IIonh3gtZfvnIlCxr0wnKA2FDqSoliURCztAUYm4SpUq9jQ059Hh9TQJi7m+zKJh uzIC96jUtgllnStAzEM8yFfNLfD1H3ibYENEVtmLSOS7mezRrIgdYP38WsZGcR8Nawg1 G5Z0/qX1Q28s/nhmhOXZnc03M4K8MkTDLVbuleNAvsqC/SqrWkZkZGiSd/E+zDpfBbJZ gu1Q== X-Forwarded-Encrypted: i=1; AJvYcCXsSWDFOVi7h9rgZnVSzFhPalA/pP+oPtDEULx26weKeD5YCIuAfs6o1H8nBKIomFLFJgcM5A9CEKHH6ItwbcYbwNI= X-Gm-Message-State: AOJu0Yw/BF/f2LcJ2D4pcrVgajyPy2EZPUBB3wqLaJB43VRhveTEPHlg hWXiTez6qObgbk/AZNzaSPmhZibTM+ZgvsNAwmbLtCaVEJxjUJ12W8t9aoTA7UfL747R0Ru/Uda D X-Google-Smtp-Source: AGHT+IFW5wFv4Nr2vL4lmZv1xSYSknW8VzR0FHgUnlq32KXpNWXRidmFH8ltDuIb+OCkhQa5lrc0ng== X-Received: by 2002:a05:600c:3c8a:b0:411:9508:e237 with SMTP id bg10-20020a05600c3c8a00b004119508e237mr17669840wmb.19.1708602666816; Thu, 22 Feb 2024 03:51:06 -0800 (PST) Received: from raven.intern.cm-ag (p200300dc6f010900023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f01:900:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id co18-20020a0560000a1200b0033d4c3b0beesm15044920wrb.19.2024.02.22.03.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:51:06 -0800 (PST) From: Max Kellermann To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: willy@infradead.org, Max Kellermann Subject: [PATCH v2 05/14] linux/mm.h: move page_address() and others to mm/page_address.h Date: Thu, 22 Feb 2024 12:50:46 +0100 Message-Id: <20240222115055.1172877-6-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240222115055.1172877-1-max.kellermann@ionos.com> References: <20240222115055.1172877-1-max.kellermann@ionos.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 18F6D140005 X-Stat-Signature: ki3enwz5bgzyztanf97roiq7bp3ue88m X-HE-Tag: 1708602667-349414 X-HE-Meta: U2FsdGVkX19Jymq6I2VkvV0QhlZeyh0ypevGunNhbOAJPzh7JpFJfU9zIjhjH7MTuIKpLvKvDEtaAHIWEYnz0dVMjuMgDYZzKY0U9CGpuESw48PNEO9g2HM69EPDqlLR0sVlaWvIc33WCHnNH8D2HUgVetOY25/lxUuX5snFjHB9XwC0kbacJXW1t7OZ2WuniMnr393V9+crLhiSthXW1FDkG4ivf72AwygU6oOpnUntknitq4GY5HpG4hhhm+QmUpuC5sWtMtt/gpofdD1AAJskG/7oz6ADWlkBGEq5l+4JcJBR22BKiSa+2165lR49lyEWxXG+wA8rc7COiyTZwdxSyeUcFB6yNxr8UqTSfqR2bZsLdBxfyngSeQNkYEEhBGxr+l5BTpD4btD1TstRSuYOS/M7lcLw8jzrWJ17Us3r17b3AuhTFAo92lbAOj0KtoOXWfAwb32hdsl1iCtigKmF/cXTJiGohL8jZS4oWHRaauVux/DPPfHCme8UNmLTAlsK9zcKT3VxFKB537db9qcy6izIhkQSsoORCZKM/OvfOg4LHskKK+q++Zh1S7ArlkWdAMFdbaQhR7xuzUbqvP3I3fMdb5D4RKkPrWmSVoHFy4kbEWNPHO8cBBsZklt3UyyCsXypUsUGrejs+X032MsQHSMHQHyZsBJsin1BBgyOPD9nUNc4qGlbuR455F9S9sDMFRSkGAUTMLm0Z+wELkKRXW3IFkWurKq7EGDnOOMacht7V4l5caM1wIrw4le9d41wLiizR7IOG7nHt6U5FLkGItEPLdtPJixWpxBrvYeZM5ZvWUGL7szxL42xTJCWtYwoYIvTQ2XVAbLMjVG41dLKFMiIZm/85DGg0ZHk4cWxb/HpbZlqtIDDeuzUIt7STiXM2IB/8wr4T2m8gpSHOv0CrHdfyBWwNN21Q+8jNNWt+08SI6L0rT7lYwJ1M5C/3PgvFmbOwJ+ZOa+omPb Qaenpw8U sm3adGYWNuktCbRI864cxukXbyhCo4DGS9G3LeNe0kWw3ZqX2XANkhCTkf1Igs8Di6u3dknkbXHMTEYZEmuD4o4stOpfEbR7FkUc+Zjcgytlaj2zFAMCPVEUxmonohP96ZEGt5+vwrfoCqCwtgaSOv09aVVfdY24JtGl3 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 7c3d2bd69818..57c091e7579e 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) @@ -2122,44 +2110,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); /* @@ -2222,10 +2172,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 */