From patchwork Mon Oct 7 06:28:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13824142 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 AEFFBCFB440 for ; Mon, 7 Oct 2024 06:30:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46DD26B010B; Mon, 7 Oct 2024 02:30:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F7486B010C; Mon, 7 Oct 2024 02:30:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2711D6B010D; Mon, 7 Oct 2024 02:30:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 04CFB6B010B for ; Mon, 7 Oct 2024 02:30:43 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AB04B140A77 for ; Mon, 7 Oct 2024 06:30:43 +0000 (UTC) X-FDA: 82645832766.29.9A602DA Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id E834618000D for ; Mon, 7 Oct 2024 06:30:41 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=t5NZOr0r; spf=pass (imf06.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728282574; 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=3M5tZmZR587g2tYwNpnjlAQqKJk5qTehs9EZKmH7WvU=; b=FBdCDXK9lSXrmXZoN3BmpTHlu7CYi0vgqnQANC9+y7PcnfasAPgp8mlGseP01hbt64zMZM N8GSRXi659ORocASNUdiqz8tSGVjS0huxTpuN0kwMbnX/IHb3aUuEq159Kd1/zc4ku6OFP 1AuIuleUJiQWXpRYYmmAf/d7d0tIG+A= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=t5NZOr0r; spf=pass (imf06.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728282574; a=rsa-sha256; cv=none; b=BkjacP2ovDc6aiXXs58p3laHJhKh3FMbt4qg3Wz2AA6DpRsJQfr3N9vfh4kkVS2AUnFVjp 6ZCWFgLBIRMxzCJWqq6vzUMcVjspvQkI2+zORyvAJn2N40KJZkq6s6NtQ6sVqlN1hwpCn5 UBwxR5JbdVVNtGTzui14Jw4iRsdqvnw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id DB0FA5C004D; Mon, 7 Oct 2024 06:30:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9D1EC4CEC7; Mon, 7 Oct 2024 06:30:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728282640; bh=wNNekRGAbZryYx39DSPhNWVfD+rXqj7AYYB/EQ4dkrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t5NZOr0r+MDPPbXGYRdga5lmfK4ACI5iUhFae2QKUPlVVPSY6vfta0uCYsjQAsMnw BfgIe7WB1uPxSKyBoiQsUh2UjsbNnYe8+4jXZO/sF+t3Njd7bAjWngf0gZz3P0BHWU 0I5QGuRGsjvvcQpZKz73XkGRrZt7IYal3+qtG0pe1j5vent2TJWtBtEkNHryQPx1lR bX3sxw7tPO6YTjySBX7aI2GH4qLQ1UUCmm+mC7W14pTtGyu0S01J5d7H4iOvw3Clwe j7ijmmCQCH9z1EMT3k8MNebCpKk8OsGRV0ON9qfRA1O0ccYghTrJ7qqoPJkFksAxEU vVrd/p7JdkH2g== From: Mike Rapoport To: Andrew Morton Cc: Andreas Larsson , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Borislav Petkov , Brian Cain , Catalin Marinas , Christoph Hellwig , Christophe Leroy , Dave Hansen , Dinh Nguyen , Geert Uytterhoeven , Guo Ren , Helge Deller , Huacai Chen , Ingo Molnar , Johannes Berg , John Paul Adrian Glaubitz , Kent Overstreet , "Liam R. Howlett" , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Matt Turner , Max Filippov , Michael Ellerman , Michal Simek , Mike Rapoport , Oleg Nesterov , Palmer Dabbelt , Peter Zijlstra , Richard Weinberger , Russell King , Song Liu , Stafford Horne , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Uladzislau Rezki , Vineet Gupta , Will Deacon , bpf@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-sh@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-trace-kernel@vger.kernel.org, linux-um@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v4 5/8] arch: introduce set_direct_map_valid_noflush() Date: Mon, 7 Oct 2024 09:28:55 +0300 Message-ID: <20241007062858.44248-6-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241007062858.44248-1-rppt@kernel.org> References: <20241007062858.44248-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: E834618000D X-Stat-Signature: fwmjpzbrc4fasinikw8xfk1myrbxua8o X-HE-Tag: 1728282641-517315 X-HE-Meta: U2FsdGVkX1/8PSQFX9Sbi6ShpiWQCxFBL4RAYIZmtBEWnBHQikPF06GkV+kw8NRbJD5Ttt0iD8PWG5rjGEsECLIJhN5vA1L9yuFy+zkY0lm0RXYca/pqoBBwvc8dai3DcCGQ4XBYtwfbQiBKFyP75Ncf/FOy1jcLGcRVSYOaOcSrF/de0KXK2ivAJjPZcso+/RIn+aeIla4f6ztlrQjvYOn6XK2pmTYdTrY+FOus9gKvSfuRe5v+TceePq34+hj6i5zXGSeFelEbF62Ce62RyTbm7FCCuzpj2cone+M7bleUxlEyGUgu4guAfyImlUTM8wqkMSPW0rVsV3cuMB98Og/94LnH7pm6UD+weeMoWdtvGGPolMZRoEm+IqoJmsB68tfDa4GyZycBJZcGPmW89u7XVfOwX2Dp+2XvgquDer0hLzVf3W8RrioHEmMKsAJvW1Va/ExofDuqQ724B8AFU/DwQsaE8Am9QVvahyjDHp3l6Jo31tFSljQai0ZbBOZleNth/HlYPuM/ZsGfP8Ey5s3J+kxKMi2A7rRESHjPap+g+DV5+Ss938m0V5qjt+9PF+qBLgym+5LjjAB4z2IdapOp5YV5Up0PGZKUw37LbXQw51V1lFboSXYOsPVeaKdflKq51B7YwR0G3uW06coldbXBY8QhKeSuowO+0Aies4wvu86jP4spYqwXIMwPWQ/8j9lkMj5wyQhMoxWn3oZrApzVWckva4UfIeZ+8TBMsYTTJqCDehNIqw3/lz2waPwv/a1pSBiWJLu4tynTSuvtiMeUyvLsqF5XZjRQFM+CkYzm5BgZGfMx5SbmBPVgagCtTxGb5QGWjDys9vu/VGVUBGy28VcPqPioIIgV46v/NT6BXo+J/D8lJMTlE7l8E4rv5JTJNV4n0L8rjGmB5hawgItEQmr3z6eehwConsfDYuJ9q2snTO+vTX7+R6B8deYWIFK2fDhnPqppnTJXP9s m03K+tz/ wewihHaEOupnAb4iBkwMHnks1ftWF/71IrM4BfVz+hGclDGcaTnyF6q11t+3IF+il/sKFxuDSdbilVPhSOzuCMjWAG31cxeop0BVw97jDY1sPopuU4OmtzVP/yuXpzZ93d1GY0esGnoyUn14fqz0bloNn3gC9qcGRBoCIztyiPOT/tKxMqYJ967bOvxvQxSQ+uX6YWzPWLWaiR3xJb3D1jv4xgapBN7A1anb5CQOYVsxfQ/74bZ1p2nvaNvoVoRfBS9aFzHf2fh2ZvMUyCLc8xhzOPgePDyaovCbT 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: From: "Mike Rapoport (Microsoft)" Add an API that will allow updates of the direct/linear map for a set of physically contiguous pages. It will be used in the following patches. Signed-off-by: Mike Rapoport (Microsoft) --- arch/arm64/include/asm/set_memory.h | 1 + arch/arm64/mm/pageattr.c | 10 ++++++++++ arch/loongarch/include/asm/set_memory.h | 1 + arch/loongarch/mm/pageattr.c | 21 +++++++++++++++++++++ arch/riscv/include/asm/set_memory.h | 1 + arch/riscv/mm/pageattr.c | 15 +++++++++++++++ arch/s390/include/asm/set_memory.h | 1 + arch/s390/mm/pageattr.c | 11 +++++++++++ arch/x86/include/asm/set_memory.h | 1 + arch/x86/mm/pat/set_memory.c | 8 ++++++++ include/linux/set_memory.h | 6 ++++++ 11 files changed, 76 insertions(+) diff --git a/arch/arm64/include/asm/set_memory.h b/arch/arm64/include/asm/set_memory.h index 917761feeffd..98088c043606 100644 --- a/arch/arm64/include/asm/set_memory.h +++ b/arch/arm64/include/asm/set_memory.h @@ -13,6 +13,7 @@ int set_memory_valid(unsigned long addr, int numpages, int enable); int set_direct_map_invalid_noflush(struct page *page); int set_direct_map_default_noflush(struct page *page); +int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid); bool kernel_page_present(struct page *page); #endif /* _ASM_ARM64_SET_MEMORY_H */ diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c index 0e270a1c51e6..01225900293a 100644 --- a/arch/arm64/mm/pageattr.c +++ b/arch/arm64/mm/pageattr.c @@ -192,6 +192,16 @@ int set_direct_map_default_noflush(struct page *page) PAGE_SIZE, change_page_range, &data); } +int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid) +{ + unsigned long addr = (unsigned long)page_address(page); + + if (!can_set_direct_map()) + return 0; + + return set_memory_valid(addr, nr, valid); +} + #ifdef CONFIG_DEBUG_PAGEALLOC void __kernel_map_pages(struct page *page, int numpages, int enable) { diff --git a/arch/loongarch/include/asm/set_memory.h b/arch/loongarch/include/asm/set_memory.h index d70505b6676c..55dfaefd02c8 100644 --- a/arch/loongarch/include/asm/set_memory.h +++ b/arch/loongarch/include/asm/set_memory.h @@ -17,5 +17,6 @@ int set_memory_rw(unsigned long addr, int numpages); bool kernel_page_present(struct page *page); int set_direct_map_default_noflush(struct page *page); int set_direct_map_invalid_noflush(struct page *page); +int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid); #endif /* _ASM_LOONGARCH_SET_MEMORY_H */ diff --git a/arch/loongarch/mm/pageattr.c b/arch/loongarch/mm/pageattr.c index ffd8d76021d4..f14b40c968b4 100644 --- a/arch/loongarch/mm/pageattr.c +++ b/arch/loongarch/mm/pageattr.c @@ -216,3 +216,24 @@ int set_direct_map_invalid_noflush(struct page *page) return __set_memory(addr, 1, __pgprot(0), __pgprot(_PAGE_PRESENT | _PAGE_VALID)); } + +int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid) +{ + unsigned long addr = (unsigned long)page_address(page); + pgprot_t set, clear; + + return __set_memory((unsigned long)page_address(page), nr, set, clear); + + if (addr < vm_map_base) + return 0; + + if (valid) { + set = PAGE_KERNEL; + clear = __pgprot(0); + } else { + set = __pgprot(0); + clear = __pgprot(_PAGE_PRESENT | _PAGE_VALID); + } + + return __set_memory(addr, 1, set, clear); +} diff --git a/arch/riscv/include/asm/set_memory.h b/arch/riscv/include/asm/set_memory.h index ab92fc84e1fc..ea263d3683ef 100644 --- a/arch/riscv/include/asm/set_memory.h +++ b/arch/riscv/include/asm/set_memory.h @@ -42,6 +42,7 @@ static inline int set_kernel_memory(char *startp, char *endp, int set_direct_map_invalid_noflush(struct page *page); int set_direct_map_default_noflush(struct page *page); +int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid); bool kernel_page_present(struct page *page); #endif /* __ASSEMBLY__ */ diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c index 271d01a5ba4d..d815448758a1 100644 --- a/arch/riscv/mm/pageattr.c +++ b/arch/riscv/mm/pageattr.c @@ -386,6 +386,21 @@ int set_direct_map_default_noflush(struct page *page) PAGE_KERNEL, __pgprot(_PAGE_EXEC)); } +int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid) +{ + pgprot_t set, clear; + + if (valid) { + set = PAGE_KERNEL; + clear = __pgprot(_PAGE_EXEC); + } else { + set = __pgprot(0); + clear = __pgprot(_PAGE_PRESENT); + } + + return __set_memory((unsigned long)page_address(page), nr, set, clear); +} + #ifdef CONFIG_DEBUG_PAGEALLOC static int debug_pagealloc_set_page(pte_t *pte, unsigned long addr, void *data) { diff --git a/arch/s390/include/asm/set_memory.h b/arch/s390/include/asm/set_memory.h index 06fbabe2f66c..240bcfbdcdce 100644 --- a/arch/s390/include/asm/set_memory.h +++ b/arch/s390/include/asm/set_memory.h @@ -62,5 +62,6 @@ __SET_MEMORY_FUNC(set_memory_4k, SET_MEMORY_4K) int set_direct_map_invalid_noflush(struct page *page); int set_direct_map_default_noflush(struct page *page); +int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid); #endif diff --git a/arch/s390/mm/pageattr.c b/arch/s390/mm/pageattr.c index 5f805ad42d4c..4c7ee74aa130 100644 --- a/arch/s390/mm/pageattr.c +++ b/arch/s390/mm/pageattr.c @@ -406,6 +406,17 @@ int set_direct_map_default_noflush(struct page *page) return __set_memory((unsigned long)page_to_virt(page), 1, SET_MEMORY_DEF); } +int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid) +{ + unsigned long flags; + + if (valid) + flags = SET_MEMORY_DEF; + else + flags = SET_MEMORY_INV; + + return __set_memory((unsigned long)page_to_virt(page), nr, flags); +} #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE) static void ipte_range(pte_t *pte, unsigned long address, int nr) diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_memory.h index 4b2abce2e3e7..cc62ef70ccc0 100644 --- a/arch/x86/include/asm/set_memory.h +++ b/arch/x86/include/asm/set_memory.h @@ -89,6 +89,7 @@ int set_pages_rw(struct page *page, int numpages); int set_direct_map_invalid_noflush(struct page *page); int set_direct_map_default_noflush(struct page *page); +int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid); bool kernel_page_present(struct page *page); extern int kernel_set_to_readonly; diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 44f7b2ea6a07..069e421c2247 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2444,6 +2444,14 @@ int set_direct_map_default_noflush(struct page *page) return __set_pages_p(page, 1); } +int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid) +{ + if (valid) + return __set_pages_p(page, nr); + + return __set_pages_np(page, nr); +} + #ifdef CONFIG_DEBUG_PAGEALLOC void __kernel_map_pages(struct page *page, int numpages, int enable) { diff --git a/include/linux/set_memory.h b/include/linux/set_memory.h index e7aec20fb44f..3030d9245f5a 100644 --- a/include/linux/set_memory.h +++ b/include/linux/set_memory.h @@ -34,6 +34,12 @@ static inline int set_direct_map_default_noflush(struct page *page) return 0; } +static inline int set_direct_map_valid_noflush(struct page *page, + unsigned nr, bool valid) +{ + return 0; +} + static inline bool kernel_page_present(struct page *page) { return true;