Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp285236rdb; Thu, 22 Feb 2024 03:52:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUDaQaxI3s97vZmz4C+r+oqoCPmDiz13kMpQEHYodwvO4yX89Ncn2e5Vnt+//OvfZjjYiJGE8TYoRZ354RWCI4phOOCnOj9MS/dY/Y8dQ== X-Google-Smtp-Source: AGHT+IG3GLjrxqXVFuC+BJ0eBAXAtVVTdqffOr0BX6Ua/CWAqqj8IWzxuDgAhUIVnW/SLVcCwn8J X-Received: by 2002:a05:6a20:9596:b0:1a0:6c04:4bba with SMTP id iu22-20020a056a20959600b001a06c044bbamr22083616pzb.11.1708602744045; Thu, 22 Feb 2024 03:52:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708602744; cv=pass; d=google.com; s=arc-20160816; b=SQCdWCb9xlekiY+WkB3W6WdU6zXOdaeHkaSuKaxUyj/a76sC9pE14PxGEETrSdTmpB Wo33Ab7q6T2zzDicf/3qZjAYHLMR4mFD3Tccak8LJCUINyCrmFlggqEnZsOMDTBUPWe1 6LVUi73Td2zNKi3ZF4gdqwWczw2aqEO8ShAf662f6u4OYdqSZOPQc7hKJfhYloXRj6RA U26Pt2gr5RxSf895T0yGGDi2MQvHgLDyhXccPi8D7Q/FiEVcMLYATBgqQHX6JQ6y3nUm ZPv/bftNl+X8cwKYNAMOi8QWngozg0s0okP44AuMEP7swL2C9ZGbwUQUGupM8uw06p0P hw9g== 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=TYSYlSdUn/dXTjpoW2eB+NQW7lqG+bTDZOpmc2h8jwc=; fh=qJ/p4J+HsKIoErDVqhEILECNHE0//9BYOVtHOJtR4CI=; b=Xq1M4l75OTNqAyPPECg+E0JFF0nOPTe+yPmxEGQLXpO59i4JjnwxdimBBbc07kzpXV OOk12YDpFFEM5CseyIpC0uz7JOj2ErdfzFFwVAvWDUi5qjasQNeyqi3QuOCo2JjEGDzY 2oIODALaRPKKqbhHDygTgTheXvnO7RmEDaT7LwxdJQxIni0L/de1bHAAc3/8TDreARFh AYrohUOQ9rxFLohZLYfltstPac8K0+f8OylcM4sJZHHIUaEAgWStdVPGBqeNdP848Y0d vWKhqW1StbuIpBQdj08zrUPPhY6v1N0csqPQIFbVymhqd6XgyC3R5fo2w+d1mcFklxoO mHJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=g0eIL8rQ; 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-76453-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76453-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g69-20020a636b48000000b005cd6507bb84si9779040pgc.183.2024.02.22.03.52.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:52:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76453-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=g0eIL8rQ; 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-76453-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76453-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 69B9328269E for ; Thu, 22 Feb 2024 11:52:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E81D94CE04; Thu, 22 Feb 2024 11:51:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="g0eIL8rQ" Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 5C29D47774 for ; Thu, 22 Feb 2024 11:51:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708602670; cv=none; b=meVl2YocZ+AGnHhg2VzJ5dwmrGvKWg/fXvxmpSV+088Kx2Hi+q/8FVRv9738AF9IuIoW5DmU2c0I2i5dR8XZEsqBSDlTTgmwZ3cWBizEWOESnPfEs37e1aOdBFkIz1R14oO4DvJtTkktz3ufCGPTez54Iu4OD3bdaaUdcdUkswQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708602670; c=relaxed/simple; bh=q8kKn6ZoIx/6RjLM+3qIn9pYs3Fc/OtpL0DtI2Q7y9Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kh44g4dpeC6ny2khfvW3p9g54DJW/NuCpcaeeC4t2iG7wcGv3T4UHNflcNkdjCi5acqxEtpd8x8oWCncXnASr4eyc94YWh8lVxwWv2uN+pSXA4zQY/JBw9JLWaB/cxqQIEjASJFpqH4FGv3hQmssoEvgu1Txh+rrK67etpkA4ZY= 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=g0eIL8rQ; arc=none smtp.client-ip=209.85.128.50 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-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4128d15a4e4so1586095e9.3 for ; Thu, 22 Feb 2024 03:51:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1708602667; x=1709207467; 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=TYSYlSdUn/dXTjpoW2eB+NQW7lqG+bTDZOpmc2h8jwc=; b=g0eIL8rQ2fH0h/GmuUP3dWN5UpXI1266O9mRsn0dXTc6dELpx0UcW5e2PrJ6t2aUKL muVEnyfQpnbF+/9whRcVjKbqO8kQebv7o1tS1YTYa8L8MqPb9tS8Snw5/bFgQ8dIHmjI U4KfdJsn3S+/nyYcrl0MF7sZykYllQrIBlLrRop2BIEvw7iBiMnSh9JrFyynvTe5nFgk RCTWSCEMcvXUXDutjMoaoQL5J/Ai0OUCCGjiyEyq1ywaShnOnPamyi02tM7ltpHyRUMG JJHQid6Sj/4Uzrg4Q6NWZCsXTLQmap0gOs3fiP6ncOqg95hjFmp0KXqg+qrJ2qylAF54 yBSQ== 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=Opf25ie2KRFVnvi/tZBocsmW1zRPr43QzzLaSGG1m9FhBlbQIiznMhXJNkIwU6ftSs 49x1ZftDH1l7zm5bbgXzkQy6L2EM3aiW7Rk8PanxrKF1HMAN2fBoIBDt5klhRPQLQedS eu2bnNK/AX1aRIjwdigslsyfLUOIV//UD+liqn8ASgw7dHVZUsSp/zR4u3X3aS7qY5UA l08f6+yH9aLUU7xd3EJv8m7ihtzCeXWNMMya9wvPdN3s3QG6QbNFAdRg9MNjmBSnEu+L nN8wmFZrXnNKUIvGrnun/dZn6bthJxa5hqjZuXW1htNzU/IYYwswSJEom3JdqWidQRgK mMxw== X-Forwarded-Encrypted: i=1; AJvYcCV6b3dbTCxqcW4G5I3GgLhlhleRWtnsxQxJM+zsoZdP3u20R9KDB2qzTWOC3gDNn1KFkFfUjKfDfkrJlWLYqV1ahfX91o21yEPOX4Jq X-Gm-Message-State: AOJu0Yxg4IrwBVRNkvqKvE7XDAzqeJiyRnV0c+B8/AZLcrKKupX0WiTC dt4hMVQraJzDYxIyuHhzhRjP9n929iVkeBm8UkadM6AU0NHuV9oDjGQWPCKipBM= 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> 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 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 */ -- 2.39.2