Skip to content

Commit 0685f21

Browse files
Ram Paimpe
authored andcommitted
powerpc: cleanup AMR, IAMR when a key is allocated or freed
Cleanup the bits corresponding to a key in the AMR, and IAMR register, when the key is newly allocated/activated or is freed. We dont want some residual bits cause the hardware enforce unintended behavior when the key is activated or freed. Reviewed-by: Thiago Jung Bauermann <[email protected]> Signed-off-by: Ram Pai <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 4d70b69 commit 0685f21

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

arch/powerpc/include/asm/pkeys.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey)
5858
__mm_pkey_is_allocated(mm, pkey));
5959
}
6060

61+
extern void __arch_activate_pkey(int pkey);
62+
extern void __arch_deactivate_pkey(int pkey);
6163
/*
6264
* Returns a positive, 5-bit key on success, or -1 on failure.
6365
* Relies on the mmap_sem to protect against concurrency in mm_pkey_alloc() and
@@ -85,6 +87,12 @@ static inline int mm_pkey_alloc(struct mm_struct *mm)
8587

8688
ret = ffz((u32)mm_pkey_allocation_map(mm));
8789
__mm_pkey_allocated(mm, ret);
90+
91+
/*
92+
* Enable the key in the hardware
93+
*/
94+
if (ret > 0)
95+
__arch_activate_pkey(ret);
8896
return ret;
8997
}
9098

@@ -96,6 +104,10 @@ static inline int mm_pkey_free(struct mm_struct *mm, int pkey)
96104
if (!mm_pkey_is_allocated(mm, pkey))
97105
return -EINVAL;
98106

107+
/*
108+
* Disable the key in the hardware
109+
*/
110+
__arch_deactivate_pkey(pkey);
99111
__mm_pkey_free(mm, pkey);
100112

101113
return 0;

0 commit comments

Comments
 (0)