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: 201515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp454025dyb; Thu, 15 Feb 2024 06:58:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXc389CZpZRpKcAuw1NIM4AEcfqoIEnZvcL2Taru7ZG9VHnSn7mlxuqnbPZQmH7/7Dp62yK5/MdpNZ4aY5j7GA/dDx6VQ== X-Google-Smtp-Source: AGHT+IF/guxgLnFnc4VT7xdYPV/P2VKTiSbPF96LWi8NQD2fld6JzKULqMXKI6lgcs0zXRxEcCtO X-Received: by 2002:a17:906:ecea:b0:a36:fc15:c6d2 with SMTP id qt10-20020a170906ecea00b00a36fc15c6d2mr1495088ejb.5.1708009103617; Thu, 15 Feb 2024 06:58:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708009103; cv=pass; d=google.com; s=arc-20160816; b=y2cXFDvb5HOfqgSnd6xFeNXT2Ab3gioSjhS79aZKeps2ddSw2InwWPuNsqIpTIwbtX 2+dE/3MErSm5tssTcN1DAkafK36pmUojr+Sowu5cf5iNoiG+L1fYrRY0t1Kbt0k3JWHl ZrMrjltUmZQrSPbLr7li3F/lzJ8ni+VVuuRXdU2py8i6SNn0yMHFmCP2ALF+W2j2vGku PMrCsrAGcz3Fhf3CvtX79zHvL3XjtaWOVryiD+uTCl9XyNlBnku0ev983T2lfzTU8M2B hHzXoYYDk24vl6fi9K6cdL3XXd91AgyMYAuICk4mr77OIuGaY2fsRckK4E94i7fXJ55S beeQ== 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=f2uzIED0RGgrcDO6EVVxl3NNU/jaMuJjJACfUgXp0rs=; fh=AfpZl/TKrvVCIWU3wgBeppF286cYG/5Cn/gWAUseLQA=; b=cHDf06k3Dm+UxZJC/B7e9nzvQXy0j7oB3IfDm67pzOpdZCvBNNaMTklah2Y64egMdW aYgYVdjd5KJ3/xdwWjpCiV1xBXMR421iCJbhvnHbIYcXzDG+E/O69MNuRGcst+ay9f3e 9EOjhXKwsYBtOyboRd9RD39ohFr9yDvs37m9ruunxQABCFf/Uaic1EmwrG3FObhcpa/+ aPmuI9exLXiuWoIc1g0MgAkKcv311xN6AcFh/xVeR0IlaIGxhDp7TGeD5q5zyAQPQVI5 TeE12szegTG0vuCfaWkbYDpWR0NV4HmSoI0Jj9YfB5JMYsylxdX1N4hZFp7OhmsCCeC/ Y7rQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=TTCNhKuU; 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-67116-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67116-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e18-20020a170906045200b00a3d9e6c2a03si512540eja.229.2024.02.15.06.58.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 06:58:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67116-ouuuleilei=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=TTCNhKuU; 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-67116-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67116-ouuuleilei=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 12FA21F213C7 for ; Thu, 15 Feb 2024 14:58:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8846B134720; Thu, 15 Feb 2024 14:56:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="TTCNhKuU" Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 3B51B132C3E for ; Thu, 15 Feb 2024 14:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708008980; cv=none; b=HLSYA9hKPzqyafh6sZ1QA2LMyHjYT93XdT/leNM4NOjxxT7Aa1fCNK90b7rXsBrBgqX7R519G4pSzYDmhQ5QzhfKMcTXqPhyztqCu36rcKRMlh70IIy8nUCkDdBEWqiQnKd3AzzLkZ/Fq4GmCSRzPaLufUoPpGfKrQv2wzm6GKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708008980; c=relaxed/simple; bh=0uXYMYmV0wyNfz0Ocw3x17eNVG1QKmSQ8m1yDzP5ZNQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ILeGR8hihQ53olWtQsMh0QsE6DVIQW95h/hzI2G6VQgL/48qo7b2LCdiZMqx8Gby2Rll7MZSK85XYuyOxmnQJ35ksv/rD4jVEyO5YrtoIMcSYcBVzMWhy9ZIobeuWXYwrF8vbz5V3f48UcqzX3kzl/A+kSZ/q/IrMsmHjstZkFE= 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=TTCNhKuU; arc=none smtp.client-ip=209.85.218.44 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-f44.google.com with SMTP id a640c23a62f3a-a36126ee41eso131434366b.2 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=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=f2uzIED0RGgrcDO6EVVxl3NNU/jaMuJjJACfUgXp0rs=; b=TTCNhKuUQ1fkUvNebk7MVlAME5WV2aZhqGzzKw35BnzGGHDm30+w86cXjWCgiuiSXC Ovb12GN32NNjyYBMhRBsau6Vb87rcNtlWwtakKdjAp+DSLpl5XLb6BRME/wTiyUE9gAM r22axQD62xIqpFG0R1kTohREBL8xahLlO/clkUzh3aJamMq24P1Jyj+TtrNy6vLQ7b0M sIy2QZSwf1sxxNX93yvbH1burJUn0fDJEe9EES8nEuVemS3AthDZjq0kKi0xSgXHzy3H 9Lz9jpaD2AwbL2IpIYStLLiLQjj4e3alYQAxwWCCT8KJyKyzeMlu9OLwTP/mwKOv3olw Qz0g== 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=KORUGzH6CX3s5M2DS6E5ReDpbYBAPiX/sExpQEgqQtcq7OsU5ZtDTUaesdFwo8c/cI Kcfhy9zzv2wtBjIRKwV0vOUrdR9WuSq/jzOUjmrZQflSyWLsEenhFF2UiGfp3rWgT8lr buolQvZj3T4IIRQtuc4BktgqpMPrkD56l3F5pt7wJ4Bg4b4L3AUigBkgPDjlmYssYIf3 ICWDS5HietWimNxxF1NU/4gcudbxhMcQnKkPVYGQ9xSBCp0Cv+ihQRfdJxEVfZjoFFYf znzrgv3bynD5sIha5end9YCvNB71f3TqGIHRcIBQ7gAkp+3mrQ2CMjCqvLBThxTv3nfL nYYQ== X-Forwarded-Encrypted: i=1; AJvYcCUY96Rh8XhcEPlG+7bIkLRT2zk4dOREv00MrdW5DpnCLy7cOHu4XQegaa8+NLYOi/A4j58qocPuPl2HPvuuCteQMWt0U7qmRSkNnFJv X-Gm-Message-State: AOJu0YxdaQk/oUOh46WRQG3AiQEr/AQLN8gmx42OUiJkAssISaDJVwKL MgpDQ6xvU4a2i0lMTclq75rRC8quNj8lns1sUaZAAFDDvc7dGTQOiWzgy5pU3Xo= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790977353921257095 X-GMAIL-MSGID: 1790977353921257095 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 */