Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1464599lqj; Tue, 4 Jun 2024 02:19:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU8dhQ2STkoSCXiW3z/SO89xrRA6UBZTPlcJDNn29LaVhjOldzBKGmIa5GzY1e42ns5e917jreOXzcq2n40iCnXJoiMU2xo2gdN5EGNmg== X-Google-Smtp-Source: AGHT+IHFv2+O0ouxX8A+tmTAIosva7Qhi3AnwTxYxq/Nlbw1QZ2tuOkbf5ynRly6d6f2VRo2E+FA X-Received: by 2002:a17:906:6a81:b0:a68:a2fc:55f3 with SMTP id a640c23a62f3a-a68a2fc56e9mr713326766b.44.1717492763581; Tue, 04 Jun 2024 02:19:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717492763; cv=pass; d=google.com; s=arc-20160816; b=hEEQ4hSaQ8dBN/sLTkI8wlkUyOWtLgJwUlTzMZx99nwNhm2IGKql2x8ttHPSvzJzM9 3eqjZILXP1Epb2SqP4NLmR0UY7LOvkf+DeyY4+XanPcX5R6r+SjRjVP7z0y6buIMY62Q EVfJYqIFEcWYy4N5RaIdy4XdlxnaZ8saGepltlOkyD7LqjvH/BAUIqDBHj1bEvv44twN tcJy61YgjM6M15OLAkMveIMlCr0Dp+tFrzkpcwvIM7irWpT0U5zVzqj6M16BuZMwkNcA 5decBilnLU07tA3csoLhXVFi+oXFb4MTEWknHOUL+Du9y+H7zlPNw2qwsjmWU7/o7orq 5oKA== 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=oVxAKKIuGzczdMzzJCnaqt6bk9QQZalHnDhl7auSlGA=; fh=BbiYdDB/2N6Q2U36/qIKAGc1eWYz9N6/GKgvWGP83Xk=; b=Ww8CTm+UnqKISleyEhE1j92TE+1NtSmhEuduuOHyQEI0YEj7lkbTtvs9tAxrGKMC6i KS3SGIcdd12baqcCoqzLo/dQfEPP6Uye63ARUfseeVigkc/uOqZm6yAFvGoJF2YegvBJ 8ka4V4IYbYO4oWq7q41IFZuV2DG2gsTHcwtQeJogj2TvFFTxTU9GzpdmYNCjZegNud3w soLG4k9allEEjWXM2vCRgdySj7gc+xkIjoywvjvQZ7IkgeGb1cjOnDvm4Ohv16Ev+pZN wPh7diTrzahovhhJvp0aOgzDTK1JwQnsiGbnsCS9X+rVP3oKuDQ/Cmr4gRSxV7P34ZWw lJrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=blYZpVz4; 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-200316-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200316-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 a640c23a62f3a-a68bfb2472bsi317924566b.689.2024.06.04.02.19.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 02:19:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200316-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=blYZpVz4; 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-200316-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200316-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 52E6B1F21BE5 for ; Tue, 4 Jun 2024 09:10:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C70D61448EA; Tue, 4 Jun 2024 09:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="blYZpVz4" Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 97B561442EF for ; Tue, 4 Jun 2024 09:09:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717492157; cv=none; b=oBb1b6FC6Sl1xJPJrVGZY8Nc7zeLO43zIxgfLwP3B5rfWbGBdK2BXCEhubSELbRCPqxMxs4IlSMzkScTJWB670qnCM8ImuCv2LQvHkkj6mEZKsUFjr0W2yCMm85JJgFDz798fZJL9uEzvlaQWmZNHXiO2LByakmX4CtTOjPbDco= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717492157; c=relaxed/simple; bh=rkUGvj+ij6RicIA5EFzODwQ7Ora3dIw64eYqggjnLq4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qq6xNuCRzSbAXiLikj8A53iIMD7OVJ4HcOBrU0CMxxgzVwu++7TDmu20uI3zITaGTuIGWqMVNADgNUa25NzbraU+bs8zT/o8YsIgFfiY/rkvYdr0EMP2zyMjwHbHZrSu6Dd94k5jvQ7/XqNWT0zHo5T0ncgNRQnHLHSKaIr7xqM= 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=blYZpVz4; arc=none smtp.client-ip=209.85.218.53 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-f53.google.com with SMTP id a640c23a62f3a-a68f10171bdso264743566b.0 for ; Tue, 04 Jun 2024 02:09:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1717492154; x=1718096954; 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=oVxAKKIuGzczdMzzJCnaqt6bk9QQZalHnDhl7auSlGA=; b=blYZpVz49Qr7+sw4ovvi/0Dh9nCrkFMyfR9XE4+H+tihCd96m/5cQZ0PId8Y8K7Whb krClDfagcHsDARdCAcIKVWgwN5i9q1YgDWVmt/iVxcfD78rQcxv3HGmeyUhqi1W2s65q br66KT4Q8ggMpBIV2BSEe2qf0frehvMm8SBdwhCHg3/vBe92PqNJKt3aIQvUa9qombQ/ tST3NkQSbiMjG/CO1VWTjrUiAf2TNUogeoHHpmJ7D0rHtlyDPYbjcDQNiZHYZxHuIWC7 J2vzTaK0920z1nBCrZSyANIXfTo2i5wWwkgviyyDzQjp7cgBuvLb3Zi6USasYPCzZ8Um Qs/A== 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=D2jxoMGYaQuiWZ2m4F2QCKkn2jvG8r83u41qc3kd/4srE0I2k6EznqAfTlz6ztJqgt jzymUgMQBeM+0lH3GiXL940c+J4TZHDTj1THiWSBeOd1+Pm2SzL7gx7lsqAFj8bKu0o4 WGc30kozAwYA0iVgC5lezLlHjw6dkViFI5dT1hsi+iczltX9pA92OJJGiPs/gSXlx1D7 N9RqqPoxElIlSYV0lNAj3ClggkqcyVYumwJYeMOuc+Pa4aXUQDpQ4aSKlhTv5hZ0OC7u CqSVhtp9iszwRsVRoomrV+K5aZnBUZuNLlUBsPa9NlI5F2Sdv7gJ2O37XapiZwSniZYn pt3g== X-Forwarded-Encrypted: i=1; AJvYcCWlpk8W88qoeezSu1W1jwz3ZO79yq3d0Mj8m0ajcl47Gw+l9P3eRroSCmUXgJoGyepgLEGq3YbDiCmuLCh+V7IlbcWjMoNvnnuFWLSc X-Gm-Message-State: AOJu0YzQDqAzrrCCey1ie0Qw0fCujnCi3JG8KVNKV+2t3poWX+JztmLr VQL7VhT07NYY3sTDTI2iA3V4eFqLiq3f1XoJ+yTknS8wdkD4wAcEHuK8CBSZR7I= 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> 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 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 */ -- 2.39.2