From patchwork Wed Oct 30 13:49:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Roy X-Patchwork-Id: 13856548 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 58113D5CCB0 for ; Wed, 30 Oct 2024 13:50:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD2FD6B0098; Wed, 30 Oct 2024 09:50:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5BB56B0099; Wed, 30 Oct 2024 09:50:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAEFA6B009B; Wed, 30 Oct 2024 09:50:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 897EC6B0098 for ; Wed, 30 Oct 2024 09:50:08 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 391761C5FBC for ; Wed, 30 Oct 2024 13:50:08 +0000 (UTC) X-FDA: 82730400732.17.D5C9ECA Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by imf11.hostedemail.com (Postfix) with ESMTP id 7E4F540021 for ; Wed, 30 Oct 2024 13:49:34 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=amazon.co.uk header.s=amazon201209 header.b=MJtRUPEo; dmarc=pass (policy=quarantine) header.from=amazon.co.uk; spf=pass (imf11.hostedemail.com: domain of "prvs=02621381b=roypat@amazon.co.uk" designates 207.171.190.10 as permitted sender) smtp.mailfrom="prvs=02621381b=roypat@amazon.co.uk" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730296088; a=rsa-sha256; cv=none; b=dVKb5aoXiFyerFw/PBHHZ7YxPWrvtO/aEC9zb1cMLQS8STGuUW9h5p1c4ntTnoWFItdZVV alvMnbUZJrooVpLQ9K4PhRigc0ZOOPwPWoutguLmo+bERrAgq4CF5AU0oD7iRHHYr4edsY w6gy48Dxl77s+xQERA9uKRyK6h64fB8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=amazon.co.uk header.s=amazon201209 header.b=MJtRUPEo; dmarc=pass (policy=quarantine) header.from=amazon.co.uk; spf=pass (imf11.hostedemail.com: domain of "prvs=02621381b=roypat@amazon.co.uk" designates 207.171.190.10 as permitted sender) smtp.mailfrom="prvs=02621381b=roypat@amazon.co.uk" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730296088; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=blYJo1yNoaziWCkfOsSivyw3bncyOYuZYYL2mpgphk8=; b=ihZqT+IEQQK2r3XGhyxaFXDGXzzdh8SYkA0WLxFFxUS88q2PAGNwXBSvygHRjb+eL1oZ9M vVLWALqL2fl4JpijcnkvlrL3eFErnKXqPY+qJa8Yuq/gdfLevcaU1iYwkBhW7W5JDTzpGP 8Sqipw1NU6i1ceL4NUCaMd5qVcH+IBs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazon201209; t=1730296207; x=1761832207; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=blYJo1yNoaziWCkfOsSivyw3bncyOYuZYYL2mpgphk8=; b=MJtRUPEo47mJkkNHPu+PWo3q3C/vRvAB5DL1+yelLuZUhVs9VL3CH8IS 99jRkUWMtwY1pSxVFD0vwvpkdMJy9w9jewKyDYW3DKb8cV8Kqv1CiIQo3 ehUSCavPeZ3edMwW/Z3bslG8Nq67nw330abDejoAjBToMmh316PvTO+Vn A=; X-IronPort-AV: E=Sophos;i="6.11,245,1725321600"; d="scan'208";a="381122622" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2024 13:49:59 +0000 Received: from EX19MTAEUA001.ant.amazon.com [10.0.17.79:33275] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.20.52:2525] with esmtp (Farcaster) id c77b8478-8ab2-4663-a8a5-9c2518ad8ef5; Wed, 30 Oct 2024 13:49:56 +0000 (UTC) X-Farcaster-Flow-ID: c77b8478-8ab2-4663-a8a5-9c2518ad8ef5 Received: from EX19D030EUB004.ant.amazon.com (10.252.61.33) by EX19MTAEUA001.ant.amazon.com (10.252.50.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 30 Oct 2024 13:49:49 +0000 Received: from EX19MTAUEA002.ant.amazon.com (10.252.134.9) by EX19D030EUB004.ant.amazon.com (10.252.61.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 30 Oct 2024 13:49:48 +0000 Received: from email-imr-corp-prod-pdx-all-2c-8a67eb17.us-west-2.amazon.com (10.43.8.2) by mail-relay.amazon.com (10.252.134.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34 via Frontend Transport; Wed, 30 Oct 2024 13:49:48 +0000 Received: from ua2d7e1a6107c5b.home (dev-dsk-roypat-1c-dbe2a224.eu-west-1.amazon.com [172.19.88.180]) by email-imr-corp-prod-pdx-all-2c-8a67eb17.us-west-2.amazon.com (Postfix) with ESMTPS id EC34C4032D; Wed, 30 Oct 2024 13:49:37 +0000 (UTC) From: Patrick Roy To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Patrick Roy Subject: [RFC PATCH v3 1/6] arch: introduce set_direct_map_valid_noflush() Date: Wed, 30 Oct 2024 13:49:05 +0000 Message-ID: <20241030134912.515725-2-roypat@amazon.co.uk> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030134912.515725-1-roypat@amazon.co.uk> References: <20241030134912.515725-1-roypat@amazon.co.uk> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7E4F540021 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: mf4hzu3udp97hiw1fuuwk7shddpzcrmg X-HE-Tag: 1730296174-489159 X-HE-Meta: U2FsdGVkX1+CgGrU4o5gFJDE5p8VlohtWbuIhBCp14iUoqZUqu1/WhDcuSDUbIy9qGKDu4u7HnRHCl16JYCxn5w73tiTN/mOhIPdagRDI5lZCgutuy76Bb4ukesNJw+zjctti02/cRmxJnX0EmObsOeluoKheEEjTl5Mmk7NbFh3B0L8HIHoRDinALGohSR13GDRW8ddWjrtXRgXFkeIWeJBdYAA92gIUSdhxmG/D8vGbg0dB8mM1gWuiwZYk8xCUsqL9cbYB9VSkC1z1+NGhlS7qhorPvuay1dSaM4KUfNfn/nnBQ2htjDy2m00z4zrteKpEwTmIeWezulXlhULR7Dy15cHQS3Vpn3QAH3aNBwTO+nlEimIcI3AX5hu9PknY95MQthiNOPdZV+BcqatKordp5M1oL+TFL0nevw7hJaJjwm22F5o49JngNe55BDTifQpqXUiDP5juiKmhUu8K7UKvR2KnMbSH9/S2cUCY9OdsmP1C7j6gRMS4zIvfLJvjJd0WI3D0Oga2fF+vHPkhpD2aGIICAeaZSA8/anrPkFBj4fsHTjyzSag4q+Ww7DSfXsgRZGIwt3/jvy9DaZ+wsj8DICACwsTwXPGpKmtHjCLQCMRkNSHj2HHS4v2eaatPbrk4XDrCgwh0QCWFyqsgM2B+np5ZbfWGjc5c5MeZ8vyeChApIiYxRlbHXAGWT/tgbWThkb8eHh6CyzDpWcrVUxs10tiJK+0hlvFmKGtKA+QexWpbDe6EOJgjgITLYzUUIubF107VibNmZ4+6lnMhr8E7JujuGyuoPtXjLmpJCQrX8KO+MJR31QBY1z2u5Q85cUVsruz088Tl1VzKNgDcO7YkRzdCRLMuU6hiyL+b/t2g7jTdH3EC9vYi0n5X5oN0KEqPIwqWXX27fDIzmR9rAbWaC8H2CfLXhNSBLsRFb1xtND8CyzkaKAhlPiOPdfVRZsCZM6cv48fd7kWRDg DwoSDMMJ U7DN3QjdJEGVWfvgggTe2M95webJ8okuc13VCKUSau/f+MeXCsxOUGElCtejklWFURLB5cR4i9HiU22JlkKSbKtmnj96wBC2Ja8EmR33ir6QV5NTK2aUMW7WjHt63XTiJr5NkPN7rzpONEv8loYToeervr2r4yiD6Aqgmd9mpoy5e4bM9wWgKLFbg+GNKNZ9NW/RBzeHJ2XXVkw+eWQ+BUNM9cYf6xCB+2fqShXIMB5HPifNvhoCV82WLyHMm0HtaLzrc6QMsWCYeIMqaiqX1I1xW6IABAtl6hRFZ7YKOQoNQKb6FobRlc/Y2KaoasSSr6qoLfDLDHPlKU/1xcoF7wH222kAU3FXcM34yR8uSatAr1QSDPhwVjJqFomB0Dalr4njfN/xAucizQy4Y1ZMeaOj4VQvwuFLMtW812VAa9jt9oajVH+Mnq5hNXUUGishh07Um38vsJ+oxiTI8O/aJlIL3gg== 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)" 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) Signed-off-by: Patrick Roy --- 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(+) base-commit: 5cb1659f412041e4780f2e8ee49b2e03728a2ba6 diff --git a/arch/arm64/include/asm/set_memory.h b/arch/arm64/include/asm/set_memory.h index 917761feeffdd..98088c043606a 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 0e270a1c51e64..01225900293ac 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 d70505b6676cb..55dfaefd02c8a 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 ffd8d76021d47..f14b40c968b48 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 ab92fc84e1fc9..ea263d3683ef6 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 271d01a5ba4da..d815448758a19 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 06fbabe2f66c9..240bcfbdcdcec 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 5f805ad42d4c3..4c7ee74aa130d 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 4b2abce2e3e7d..cc62ef70ccc0a 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 44f7b2ea6a073..069e421c22474 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 e7aec20fb44f1..3030d9245f5ac 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;