Skip to content

Commit

Permalink
powerpc/book3s64/kuap: Move KUAP related function outside radix
Browse files Browse the repository at this point in the history
The next set of patches adds support for kuap with hash translation.
In preparation for that rename/move kuap related functions to
non radix names.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201127044424.40686-6-aneesh.kumar@linux.ibm.com
  • Loading branch information
Aneesh Kumar K.V authored and Michael Ellerman committed Dec 3, 2020
1 parent 39df17b commit 3b47b75
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_POWERPC_BOOK3S_64_KUP_RADIX_H
#define _ASM_POWERPC_BOOK3S_64_KUP_RADIX_H
#ifndef _ASM_POWERPC_BOOK3S_64_KUP_H
#define _ASM_POWERPC_BOOK3S_64_KUP_H

#include <linux/const.h>
#include <asm/reg.h>
Expand Down Expand Up @@ -202,4 +202,4 @@ static inline void restore_user_access(unsigned long flags)
}
#endif /* __ASSEMBLY__ */

#endif /* _ASM_POWERPC_BOOK3S_64_KUP_RADIX_H */
#endif /* _ASM_POWERPC_BOOK3S_64_KUP_H */
4 changes: 3 additions & 1 deletion arch/powerpc/include/asm/kup.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#define KUAP_CURRENT (KUAP_CURRENT_READ | KUAP_CURRENT_WRITE)

#ifdef CONFIG_PPC_BOOK3S_64
#include <asm/book3s/64/kup-radix.h>
#include <asm/book3s/64/kup.h>
#endif

#ifdef CONFIG_PPC_8xx
#include <asm/nohash/32/kup-8xx.h>
#endif

#ifdef CONFIG_PPC_BOOK3S_32
#include <asm/book3s/32/kup.h>
#endif
Expand Down
22 changes: 22 additions & 0 deletions arch/powerpc/mm/book3s64/pkeys.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
#include <asm/mmu_context.h>
#include <asm/mmu.h>
#include <asm/setup.h>
#include <asm/smp.h>

#include <linux/pkeys.h>
#include <linux/of_fdt.h>


int num_pkey; /* Max number of pkeys supported */
/*
* Keys marked in the reservation list cannot be allocated by userspace
Expand Down Expand Up @@ -226,6 +229,25 @@ void __init pkey_early_init_devtree(void)
return;
}

#ifdef CONFIG_PPC_KUAP
void __init setup_kuap(bool disabled)
{
if (disabled || !early_radix_enabled())
return;

if (smp_processor_id() == boot_cpuid) {
pr_info("Activating Kernel Userspace Access Prevention\n");
cur_cpu_spec->mmu_features |= MMU_FTR_RADIX_KUAP;
}

/*
* Set the default kernel AMR values on all cpus.
*/
mtspr(SPRN_AMR, AMR_KUAP_BLOCKED);
isync();
}
#endif

static inline u64 read_amr(void)
{
return mfspr(SPRN_AMR);
Expand Down
19 changes: 0 additions & 19 deletions arch/powerpc/mm/book3s64/radix_pgtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,25 +609,6 @@ void setup_kuep(bool disabled)
}
#endif

#ifdef CONFIG_PPC_KUAP
void setup_kuap(bool disabled)
{
if (disabled || !early_radix_enabled())
return;

if (smp_processor_id() == boot_cpuid) {
pr_info("Activating Kernel Userspace Access Prevention\n");
cur_cpu_spec->mmu_features |= MMU_FTR_RADIX_KUAP;
}

/*
* Set the default kernel AMR values on all cpus.
*/
mtspr(SPRN_AMR, AMR_KUAP_BLOCKED);
isync();
}
#endif

void __init radix__early_init_mmu(void)
{
unsigned long lpcr;
Expand Down

0 comments on commit 3b47b75

Please sign in to comment.