Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp942604lql; Tue, 12 Mar 2024 02:44:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUj9CKk6CN6BX4qcoyuq8sONwt3UpPLsmjLRjGxN+ycljvoUrV7TDB8TlBQ8YLeeFQDjb17PktAjB0hYVxDDNjixxmGwem+rxnUht48dA== X-Google-Smtp-Source: AGHT+IE3at2ecswnMDylcBffVKxoCcGJysNfeahr2PpweGHXtMm4/0B1pJPXAP+OdiQQDN4tcu7S X-Received: by 2002:a17:907:d049:b0:a43:f587:d427 with SMTP id vb9-20020a170907d04900b00a43f587d427mr6779476ejc.34.1710236660783; Tue, 12 Mar 2024 02:44:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710236660; cv=pass; d=google.com; s=arc-20160816; b=r+/CcnyniY3Oyka6ej12e2Os5ck2t7yRBCibwqevKxhqXwChMdWv0+fUBQ6PuQAWuF KCFsrKRLr36F2IHfTi5b91gvVszoMHfBRtChjCnlWtKpnRQFFDKGUvpmp4sLV/OKScZ8 MSuI7wc1lWz4sDjaepnxD5nZNx8IbURHr3+TuJmnfcg5NBDqUe5EylVBZZiSdtuTJC+8 s4xid/tkuBI4ibM+kLDTM58W0tuWmcA3vqroqV8s1ZOIl1QNYj9h9XNfKLD7Qk3FUmop CP2G3nGa9UXVIlcnNLXaiehtDB8cRd8B0l7/ni1RtClBSho0F/WOEW50Z0Jpgp7JlECN /x0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9QtTxRX/inj0OtKTHCIe6FPb0V6jffrKP/nT087XKzU=; fh=LBs5Yi2wt5QjYfFvb91udzVHY2FuAkjH1HCuP+JRzvg=; b=I4GPHbwu6qHyfQ+eysvavS+9D5xxT7PBcwRME9/N5b3S9BSYXwdgc/y+stceTYoVWT TSpDvfWGB8xCcE5Qiou57tO0maFvKevZzSQX2Pzl2RngtXB006gAaEwJJDDIj3POTDST dyUezBo2ssTOIZPvsE6MwYwrIdRrXUqi2iSY2isu2UvgU8yC+fA9wpzGjL75VSA6Rkap ytE/7ZXylgeE2KlnY342XN5MmE/dKmmZaQSNL2u/n3ZKfVPiXTOpG9cEAa2Z0c36cfsZ Gm46Ic+S1AzZ4NbbAT3wJ6OwDerts9NDocf1y72wZ3EVOav96aDQwFUFsT8Gv+vpyfSF Bh1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=KETwIXC0; arc=pass (i=1 spf=pass spfdomain=ionos.com dkim=pass dkdomain=ionos.com dmarc=pass fromdomain=ionos.com); spf=pass (google.com: domain of linux-kernel+bounces-100046-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100046-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gb37-20020a170907962500b00a464a2fc2fcsi169594ejc.905.2024.03.12.02.44.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 02:44:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100046-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=KETwIXC0; arc=pass (i=1 spf=pass spfdomain=ionos.com dkim=pass dkdomain=ionos.com dmarc=pass fromdomain=ionos.com); spf=pass (google.com: domain of linux-kernel+bounces-100046-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100046-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 599561F21118 for ; Tue, 12 Mar 2024 09:44:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEAB87AE4E; Tue, 12 Mar 2024 09:41:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="KETwIXC0" Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF13A7A136 for ; Tue, 12 Mar 2024 09:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710236518; cv=none; b=Gbqfwv39S+FwwZ49FEPvUlBdDOCx9aP4Ushem0fwSazSn+Dzcb0EV8vKYho2JzY8Y9IJIp3KJ0eMMSBAYTP3lIn/KNs6huewB9R6cr7VWbXggzdHwjWcDe04vubOAnqKuYjQ6WuTguc1tp0pTAl1HKmVWvgaMG74j/erfOl3aw4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710236518; c=relaxed/simple; bh=7TBD917famya0UMoNWGhR2gZVEy1ZqrdJunlSs1U06E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jPWzPsdaPSs7GJtlPdYl+NbHgrALKxQVJuofFRFKOd6IBADyQJkchuolCUinrlQxPO3FghDAy0+phygwtVE9ba/iHDzyW4oFD5pA0asv//p+pDwSR+qnDGJKm5JOydk9NzUJPlyEvZsKS2GLIUgrh3iSrT4AoxzgYNmfS9C4D1g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ionos.com; spf=pass smtp.mailfrom=ionos.com; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b=KETwIXC0; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ionos.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ionos.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a4644bde1d4so56084366b.3 for ; Tue, 12 Mar 2024 02:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1710236515; x=1710841315; darn=vger.kernel.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=9QtTxRX/inj0OtKTHCIe6FPb0V6jffrKP/nT087XKzU=; b=KETwIXC015fXkXmZSPZ43QFrlXLllMBqEECIlYcAF8xMBAB46MCBpDMLhAVY0j9YZf 1CrVf4VWdEBX6PYCiUkluM2UAXzXq5KNtfZQ81Q7YI2+r0PCZG9gmzmyPS3UdMZBeieW by69KdZgaLMKovdQrRSg9sMXWnJ/BCZJx+ajSh/0nDdr6IN1pXlxJS0TiMqS/CGffb42 Ogfyig8Gf61GOejz3VRSpsMO58ff+EX+F3eaiTIabXx0eP+7XyW0mhgA6UkFTX9sgvpF 2h5mdHS8yHMoyQ11hkOcOpJOXsWvkXyokSnhPIof03CzyjbnOnR6x0+l1H8+aX9w6xFP THWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710236515; x=1710841315; 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=9QtTxRX/inj0OtKTHCIe6FPb0V6jffrKP/nT087XKzU=; b=cX3x1lrJ+IFZtZIcfC/zFWoKnjyrHFvDN+p8eJSzdktJjFZU8lEVxFuLKoWOvNFRTx aXBF7W8iigGB9DF1UdXe5hQB8Je865/5g6FSlpD6Za5wa/JA9hixKTqlemWsEWHK/PVa WyS7ewBucTeGIkDHkgKljkcwRIBZ6hgssyKXo107FghMlAEE/61XYXJV4D1UtQYNwb5v acoqNMSHT2H+92MreJKmF/XY5ujRfEpyCuXuIDrRi0p/MgyoW3/H7PRuBXO49LujAy5T P40hYfOAmNOLeBpPm0lPXN8+Z+H2tqAhRp0grr9fwiJHYPbnsLVZ9ye2SqEvJc1vX0dD bOFg== X-Forwarded-Encrypted: i=1; AJvYcCUkFcw3hX4aoYVdCcsimagACi9un5bPPcqCBYuv3T5iXKDmjEySJzB9tN7PMQKGHtzptmpng8v1mZCmCaYy8VVn9Va3feHRVoOMaJ8S X-Gm-Message-State: AOJu0Yyrt36XmPvMHlTD1ew2dWCBamvL85cdyh/sjwCBfQCPJxXYPTq1 u2FNHykXxcQ4P94vdUi5NW+HFHXgBgCOKFj8SzWs2ROnhYI3kqzlMst/oYT4wmw= X-Received: by 2002:a17:906:234a:b0:a45:cdb2:b6db with SMTP id m10-20020a170906234a00b00a45cdb2b6dbmr5768531eja.46.1710236515272; Tue, 12 Mar 2024 02:41:55 -0700 (PDT) Received: from raven.blarg.de (p200300dc6f010900023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f01:900:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id jw22-20020a170906e95600b00a4623030893sm2091961ejb.126.2024.03.12.02.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 02:41:54 -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, Max Kellermann Subject: [PATCH v4 06/15] linux/mm.h: move page_address() and others to mm/page_address.h Date: Tue, 12 Mar 2024 10:41:24 +0100 Message-Id: <20240312094133.2084996-7-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240312094133.2084996-1-max.kellermann@ionos.com> References: <20240312094133.2084996-1-max.kellermann@ionos.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 79c1f924d4b5..713cedc03b88 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 @@ -104,10 +104,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 @@ -211,14 +207,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) @@ -2137,44 +2125,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); /* @@ -2237,10 +2187,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 */ -- 2.39.2