@@ -1311,6 +1311,60 @@ static void __init kmap_init(void)
#endif
}
+struct custom_map {
+ unsigned long start;
+ unsigned long end;
+ unsigned int type;
+};
+
+struct custom_map __initdata custom_maps[] = {
+ {
+ .start = _stext,
+ .end = __start_rodata,
+ .type = MT_MEMORY_RX,
+ },
+ {
+ .start = __start_rodata,
+ .end = __init_begin,
+ .type = MT_MEMORY_R
+ },
+ {
+ .start = __init_begin,
+ .end = __arch_info_begin,
+ .type = MT_MEMORY_RX,
+ }
+};
+
+static void __init map_custom_regions(void)
+{
+#ifdef CONFIG_STRICT_MEMORY_RWX
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(custom_maps); i++) {
+ struct map_desc map;
+ unsigned long addr;
+
+ if (!IS_ALIGNED(custom_maps[i].start, PMD_SIZE) ||
+ !IS_ALIGNED(custom_maps[i].end, PMD_SIZE)) {
+ pr_err("BUG: section %x-%x not aligned to %x\n",
+ custom_maps[i].start, custom_maps[i].end,
+ PMD_SIZE);
+ continue;
+ }
+
+ for (addr = custom_maps[i].start;
+ addr < custom_maps[i].end; addr += PMD_SIZE)
+ pmd_clear(pmd_off_k(addr));
+
+ map.virtual = custom_maps[i].start;
+ map.pfn = __phys_to_pfn(__virt_to_phys(custom_maps[i].start));
+ map.length = custom_maps[i].end - custom_maps[i].start;
+ map.type = custom_maps[i].type;
+ create_mapping(&map);
+ }
+#endif
+}
+
static void __init map_lowmem(void)
{
struct memblock_region *reg;
@@ -1329,10 +1383,11 @@ static void __init map_lowmem(void)
map.pfn = __phys_to_pfn(start);
map.virtual = __phys_to_virt(start);
map.length = end - start;
- map.type = MT_MEMORY;
+ map.type = MT_MEMORY_RW;
create_mapping(&map);
}
+ map_custom_regions();
}
/*