From: Huangzhaoyang <huangzhaoyang@gmail.com>
To: Ard Biesheuvel <ardb@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Nicholas Piggin <npiggin@gmail.com>,
Mike Rapoport <rppt@kernel.org>,
Pavel Tatashin <pasha.tatashin@soleen.com>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
Jonathan Marek <jonathan@marek.ca>,
Zhaoyang Huang <zhaoyang.huang@unisoc.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH] mm: introduce alloc hook to apply PTE_CONT
Date: Tue, 23 Nov 2021 17:12:40 +0800 [thread overview]
Message-ID: <1637658760-5813-1-git-send-email-huangzhaoyang@gmail.com> (raw)
From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
Since there is no PTE_CONT when rodata_full in ARM64, introducing a
hook function to apply PTE_CONT on the proper page blocks.
Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
arch/arm64/include/asm/page.h | 5 +++++
arch/arm64/mm/pageattr.c | 45 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/arch/arm64/include/asm/page.h b/arch/arm64/include/asm/page.h
index f98c91b..53cdd09 100644
--- a/arch/arm64/include/asm/page.h
+++ b/arch/arm64/include/asm/page.h
@@ -46,6 +46,11 @@ struct page *alloc_zeroed_user_highpage_movable(struct vm_area_struct *vma,
#include <asm/memory.h>
+#define HAVE_ARCH_ALLOC_PAGE
+#define HAVE_ARCH_FREE_PAGE
+
+extern void arch_alloc_page(struct page *page, int order);
+extern void arch_free_page(struct page *page, int order);
#endif /* !__ASSEMBLY__ */
#define VM_DATA_DEFAULT_FLAGS (VM_DATA_FLAGS_TSK_EXEC | VM_MTE_ALLOWED)
diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
index a3bacd7..815a06d 100644
--- a/arch/arm64/mm/pageattr.c
+++ b/arch/arm64/mm/pageattr.c
@@ -239,3 +239,48 @@ bool kernel_page_present(struct page *page)
ptep = pte_offset_kernel(pmdp, addr);
return pte_valid(READ_ONCE(*ptep));
}
+
+void arch_alloc_page(struct page *page, int order)
+{
+ unsigned long addr;
+ unsigned long cont_pte_low_bound;
+
+ if (!rodata_full)
+ return;
+
+ addr = (u64)page_address(page);
+ if ((order >= 4) && (addr & ~CONT_PTE_MASK) == 0) {
+ order -= 4;
+ do {
+ cont_pte_low_bound = addr & CONT_PTE_MASK;
+ __change_memory_common(cont_pte_low_bound,
+ (~CONT_PTE_MASK + 1), __pgprot(PTE_CONT), __pgprot(0));
+ addr = (u64)page_address(page);
+ page += 4;
+ order--;
+ }while (order >= 0);
+ }
+}
+
+void arch_free_page(struct page *page, int order)
+{
+ unsigned long addr;
+ unsigned long cont_pte_low_bound;
+
+ if (!rodata_full)
+ return;
+
+ addr = (u64)page_address(page);
+ if ((order >= 4) && (addr & ~CONT_PTE_MASK) == 0) {
+ order -= 4;
+ do {
+ cont_pte_low_bound = addr & CONT_PTE_MASK;
+ __change_memory_common(cont_pte_low_bound,
+ (~CONT_PTE_MASK + 1), __pgprot(0), __pgprot(PTE_CONT));
+ addr = (u64)page_address(page);
+ page += 4;
+ order--;
+ }while (order >= 0);
+ }
+}
+
--
1.9.1
next reply other threads:[~2021-11-23 9:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-23 9:12 Huangzhaoyang [this message]
2021-11-23 9:57 ` Ard Biesheuvel
2021-11-24 8:08 ` Zhaoyang Huang
2021-11-24 9:23 ` Ard Biesheuvel
2021-11-24 12:00 ` Zhaoyang Huang
2021-11-24 13:54 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1637658760-5813-1-git-send-email-huangzhaoyang@gmail.com \
--to=huangzhaoyang@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=christophe.leroy@csgroup.eu \
--cc=jonathan@marek.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=npiggin@gmail.com \
--cc=pasha.tatashin@soleen.com \
--cc=rppt@kernel.org \
--cc=will@kernel.org \
--cc=zhaoyang.huang@unisoc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox