Skip to content

Commit

Permalink
powerpc/fsl_booke: Update of TLBCAMs after init
Browse files Browse the repository at this point in the history
After init, set readonly memory as ROX and set readwrite
memory as RWX, if STRICT_KERNEL_RWX is enabled.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/66bef0b9c273e1121706883f3cf5ad0a053d863f.1634292136.git.christophe.leroy@csgroup.eu
  • Loading branch information
Christophe Leroy authored and Michael Ellerman committed Oct 22, 2021
1 parent 0b2859a commit d597004
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion arch/powerpc/mm/mmu_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static inline phys_addr_t v_block_mapped(unsigned long va) { return 0; }
static inline unsigned long p_block_mapped(phys_addr_t pa) { return 0; }
#endif

#if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx)
#if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx) || defined(CONFIG_PPC_FSL_BOOK3E)
void mmu_mark_initmem_nx(void);
void mmu_mark_rodata_ro(void);
#else
Expand Down
32 changes: 28 additions & 4 deletions arch/powerpc/mm/nohash/fsl_book3e.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static unsigned long map_mem_in_cams_addr(phys_addr_t phys, unsigned long virt,
/* Calculate CAM values */
for (i = 0; boundary && i < max_cam_idx; i++) {
unsigned long cam_sz;
pgprot_t prot = PAGE_KERNEL_X;
pgprot_t prot = init ? PAGE_KERNEL_X : PAGE_KERNEL_ROX;

cam_sz = calc_cam_sz(boundary, virt, phys);
if (!dryrun)
Expand All @@ -194,7 +194,7 @@ static unsigned long map_mem_in_cams_addr(phys_addr_t phys, unsigned long virt,
}
for (ram -= amount_mapped; ram && i < max_cam_idx; i++) {
unsigned long cam_sz;
pgprot_t prot = PAGE_KERNEL_X;
pgprot_t prot = init ? PAGE_KERNEL_X : PAGE_KERNEL;

cam_sz = calc_cam_sz(ram, virt, phys);
if (!dryrun)
Expand All @@ -209,8 +209,13 @@ static unsigned long map_mem_in_cams_addr(phys_addr_t phys, unsigned long virt,
if (dryrun)
return amount_mapped;

loadcam_multi(0, i, max_cam_idx);
tlbcam_index = i;
if (init) {
loadcam_multi(0, i, max_cam_idx);
tlbcam_index = i;
} else {
loadcam_multi(0, i, 0);
WARN_ON(i > tlbcam_index);
}

#ifdef CONFIG_PPC64
get_paca()->tcd.esel_next = i;
Expand Down Expand Up @@ -279,6 +284,25 @@ void __init adjust_total_lowmem(void)
memblock_set_current_limit(memstart_addr + __max_low_memory);
}

#ifdef CONFIG_STRICT_KERNEL_RWX
void mmu_mark_rodata_ro(void)
{
/* Everything is done in mmu_mark_initmem_nx() */
}
#endif

void mmu_mark_initmem_nx(void)
{
unsigned long remapped;

if (!strict_kernel_rwx_enabled())
return;

remapped = map_mem_in_cams(__max_low_memory, CONFIG_LOWMEM_CAM_NUM, false, false);

WARN_ON(__max_low_memory != remapped);
}

void setup_initial_memory_limit(phys_addr_t first_memblock_base,
phys_addr_t first_memblock_size)
{
Expand Down

0 comments on commit d597004

Please sign in to comment.