[PATCH 2/2] powerpc/strict_rwx: fixup region splitting
Balbir Singh
bsingharora at gmail.com
Wed Sep 27 19:51:11 AEST 2017
We were aggressive with splitting regions and missed the case
when _stext and __init_begin completely overlap addr and addr+mapping.
This patch fixes that case and allows us to keep the largest possible
mapping through the overlap. The patch also simplies the check
into a function
Fixes: 7614ff3 ("powerpc/mm/radix: Implement STRICT_RWX/mark_rodata_ro() for Radix")
Signed-off-by: Balbir Singh <bsingharora at gmail.com>
---
arch/powerpc/mm/pgtable-radix.c | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c
index c2a2b46..ea0da3b 100644
--- a/arch/powerpc/mm/pgtable-radix.c
+++ b/arch/powerpc/mm/pgtable-radix.c
@@ -210,17 +210,36 @@ static inline void __meminit print_mapping(unsigned long start,
pr_info("Mapped 0x%016lx-0x%016lx with %s pages\n", start, end, buf);
}
+static inline int __meminit
+should_split_mapping_size(unsigned long addr, unsigned long mapping_size)
+{
+#ifdef CONFIG_STRICT_KERNEL_RWX
+ /*
+ * If addr, addr+mapping overlap the text region and
+ * _stext and __init_begin end up lying between
+ * addr, addr+mapping split the mapping size down
+ * further
+ */
+ if ((addr < __pa_symbol(__init_begin)) &&
+ (addr + mapping_size) > __pa_symbol(_stext)) {
+
+ if (((addr + mapping_size) <= __pa_symbol(__init_begin)) &&
+ (addr >= __pa_symbol(_stext)))
+ return 0;
+
+ return 1;
+ }
+#endif
+ return 0;
+}
+
+
static int __meminit create_physical_mapping(unsigned long start,
unsigned long end)
{
unsigned long vaddr, addr, mapping_size = 0;
pgprot_t prot;
unsigned long max_mapping_size;
-#ifdef CONFIG_STRICT_KERNEL_RWX
- int split_text_mapping = 1;
-#else
- int split_text_mapping = 0;
-#endif
start = _ALIGN_UP(start, PAGE_SIZE);
for (addr = start; addr < end; addr += mapping_size) {
@@ -242,16 +261,14 @@ static int __meminit create_physical_mapping(unsigned long start,
else
mapping_size = PAGE_SIZE;
- if (split_text_mapping && (mapping_size == PUD_SIZE) &&
- (addr <= __pa_symbol(__init_begin)) &&
- (addr + mapping_size) >= __pa_symbol(_stext)) {
+ if ((mapping_size == PUD_SIZE) &&
+ should_split_mapping_size(addr, mapping_size)) {
max_mapping_size = PMD_SIZE;
goto retry;
}
- if (split_text_mapping && (mapping_size == PMD_SIZE) &&
- (addr <= __pa_symbol(__init_begin)) &&
- (addr + mapping_size) >= __pa_symbol(_stext))
+ if ((mapping_size == PMD_SIZE) &&
+ should_split_mapping_size(addr, mapping_size))
mapping_size = PAGE_SIZE;
if (mapping_size != previous_size) {
--
2.9.5
More information about the Linuxppc-dev
mailing list