Skip to content

Commit 92e3da3

Browse files
Ram Paimpe
authored andcommitted
powerpc: initial pkey plumbing
Basic plumbing to initialize the pkey system. Nothing is enabled yet. A later patch will enable it once all the infrastructure is in place. Signed-off-by: Ram Pai <[email protected]> [mpe: Rework copyrights to use SPDX tags] Signed-off-by: Michael Ellerman <[email protected]>
1 parent b1db551 commit 92e3da3

File tree

6 files changed

+98
-0
lines changed

6 files changed

+98
-0
lines changed

arch/powerpc/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,21 @@ config SECCOMP
867867

868868
If unsure, say Y. Only embedded should say N here.
869869

870+
config PPC_MEM_KEYS
871+
prompt "PowerPC Memory Protection Keys"
872+
def_bool y
873+
depends on PPC_BOOK3S_64
874+
select ARCH_USES_HIGH_VMA_FLAGS
875+
select ARCH_HAS_PKEYS
876+
help
877+
Memory Protection Keys provides a mechanism for enforcing
878+
page-based protections, but without requiring modification of the
879+
page tables when an application changes protection domains.
880+
881+
For details, see Documentation/vm/protection-keys.txt
882+
883+
If unsure, say y.
884+
870885
endmenu
871886

872887
config ISA_DMA_API

arch/powerpc/include/asm/mmu_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,6 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
192192
/* by default, allow everything */
193193
return true;
194194
}
195+
195196
#endif /* __KERNEL__ */
196197
#endif /* __ASM_POWERPC_MMU_CONTEXT_H */

arch/powerpc/include/asm/pkeys.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ */
2+
/*
3+
* PowerPC Memory Protection Keys management
4+
*
5+
* Copyright 2017, Ram Pai, IBM Corporation.
6+
*/
7+
8+
#ifndef _ASM_POWERPC_KEYS_H
9+
#define _ASM_POWERPC_KEYS_H
10+
11+
#include <linux/jump_label.h>
12+
13+
DECLARE_STATIC_KEY_TRUE(pkey_disabled);
14+
#define ARCH_VM_PKEY_FLAGS 0
15+
16+
static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey)
17+
{
18+
return false;
19+
}
20+
21+
static inline int mm_pkey_alloc(struct mm_struct *mm)
22+
{
23+
return -1;
24+
}
25+
26+
static inline int mm_pkey_free(struct mm_struct *mm, int pkey)
27+
{
28+
return -EINVAL;
29+
}
30+
31+
/*
32+
* Try to dedicate one of the protection keys to be used as an
33+
* execute-only protection key.
34+
*/
35+
static inline int execute_only_pkey(struct mm_struct *mm)
36+
{
37+
return 0;
38+
}
39+
40+
static inline int arch_override_mprotect_pkey(struct vm_area_struct *vma,
41+
int prot, int pkey)
42+
{
43+
return 0;
44+
}
45+
46+
static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
47+
unsigned long init_val)
48+
{
49+
return 0;
50+
}
51+
#endif /*_ASM_POWERPC_KEYS_H */

arch/powerpc/mm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.o
4444
obj-$(CONFIG_SPAPR_TCE_IOMMU) += mmu_context_iommu.o
4545
obj-$(CONFIG_PPC_PTDUMP) += dump_linuxpagetables.o
4646
obj-$(CONFIG_PPC_HTDUMP) += dump_hashpagetable.o
47+
obj-$(CONFIG_PPC_MEM_KEYS) += pkeys.o

arch/powerpc/mm/hash_utils_64.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/memblock.h>
3737
#include <linux/context_tracking.h>
3838
#include <linux/libfdt.h>
39+
#include <linux/pkeys.h>
3940

4041
#include <asm/debugfs.h>
4142
#include <asm/processor.h>

arch/powerpc/mm/pkeys.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* PowerPC Memory Protection Keys management
4+
*
5+
* Copyright 2017, Ram Pai, IBM Corporation.
6+
*/
7+
8+
#include <linux/pkeys.h>
9+
10+
DEFINE_STATIC_KEY_TRUE(pkey_disabled);
11+
bool pkey_execute_disable_supported;
12+
13+
int pkey_initialize(void)
14+
{
15+
/*
16+
* Disable the pkey system till everything is in place. A subsequent
17+
* patch will enable it.
18+
*/
19+
static_branch_enable(&pkey_disabled);
20+
21+
/*
22+
* Disable execute_disable support for now. A subsequent patch will
23+
* enable it.
24+
*/
25+
pkey_execute_disable_supported = false;
26+
return 0;
27+
}
28+
29+
arch_initcall(pkey_initialize);

0 commit comments

Comments
 (0)