powerpc/32s: Create C version of kuap save/restore/check helpers
In preparation of porting PPC32 to C syscall entry/exit, create C version of kuap_save_and_lock() and kuap_user_restore() and kuap_kernel_restore() and kuap_assert_locked() and kuap_get_and_assert_locked() on book3s/32. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/2be8fb729da4a0f9863b25e1b9d547174fcd5056.1615552867.git.christophe.leroy@csgroup.eu
This commit is contained in:
parent
ad2d234477
commit
21eb58ae4f
|
@ -72,6 +72,51 @@ static inline void kuap_update_sr(u32 sr, u32 addr, u32 end)
|
|||
isync(); /* Context sync required after mtsr() */
|
||||
}
|
||||
|
||||
static inline void kuap_save_and_lock(struct pt_regs *regs)
|
||||
{
|
||||
unsigned long kuap = current->thread.kuap;
|
||||
u32 addr = kuap & 0xf0000000;
|
||||
u32 end = kuap << 28;
|
||||
|
||||
regs->kuap = kuap;
|
||||
if (unlikely(!kuap))
|
||||
return;
|
||||
|
||||
current->thread.kuap = 0;
|
||||
kuap_update_sr(mfsr(addr) | SR_KS, addr, end); /* Set Ks */
|
||||
}
|
||||
|
||||
static inline void kuap_user_restore(struct pt_regs *regs)
|
||||
{
|
||||
}
|
||||
|
||||
static inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap)
|
||||
{
|
||||
u32 addr = regs->kuap & 0xf0000000;
|
||||
u32 end = regs->kuap << 28;
|
||||
|
||||
current->thread.kuap = regs->kuap;
|
||||
|
||||
if (unlikely(regs->kuap == kuap))
|
||||
return;
|
||||
|
||||
kuap_update_sr(mfsr(addr) & ~SR_KS, addr, end); /* Clear Ks */
|
||||
}
|
||||
|
||||
static inline unsigned long kuap_get_and_assert_locked(void)
|
||||
{
|
||||
unsigned long kuap = current->thread.kuap;
|
||||
|
||||
WARN_ON_ONCE(IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && kuap != 0);
|
||||
|
||||
return kuap;
|
||||
}
|
||||
|
||||
static inline void kuap_assert_locked(void)
|
||||
{
|
||||
kuap_get_and_assert_locked();
|
||||
}
|
||||
|
||||
static __always_inline void allow_user_access(void __user *to, const void __user *from,
|
||||
u32 size, unsigned long dir)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue