diff options
author | Haren Myneni <haren@linux.ibm.com> | 2021-06-17 13:31:43 -0700 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2021-06-20 21:58:56 +1000 |
commit | 3856aa542d90ed79cd5ed4cfd828b1fb04017131 (patch) | |
tree | 12568cf37fd354fcff057329ffa7d4a88680e025 /arch/powerpc/include/asm/vas.h | |
parent | 1a0d0d5ed5e3cd9e3fc1ad4459f1db2f3618fce0 (diff) | |
download | linux-3856aa542d90ed79cd5ed4cfd828b1fb04017131.tar.gz |
powerpc/vas: Create take/drop pid and mm reference functions
Take pid and mm references when each window opens and drops during
close. This functionality is needed for powerNV and pseries. So
this patch defines the existing code as functions in common book3s
platform vas-api.c
Signed-off-by: Haren Myneni <haren@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/2fa40df962250a737c804e58202924717b39e381.camel@linux.ibm.com
Diffstat (limited to 'arch/powerpc/include/asm/vas.h')
-rw-r--r-- | arch/powerpc/include/asm/vas.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h index 163a8bb85d02..71cff6d6bf3a 100644 --- a/arch/powerpc/include/asm/vas.h +++ b/arch/powerpc/include/asm/vas.h @@ -5,6 +5,9 @@ #ifndef _ASM_POWERPC_VAS_H #define _ASM_POWERPC_VAS_H +#include <linux/sched/mm.h> +#include <linux/mmu_context.h> +#include <asm/icswx.h> #include <uapi/asm/vas-api.h> struct vas_window; @@ -50,6 +53,17 @@ enum vas_cop_type { }; /* + * User space VAS windows are opened by tasks and take references + * to pid and mm until windows are closed. + * Stores pid, mm, and tgid for each window. + */ +struct vas_user_win_ref { + struct pid *pid; /* PID of owner */ + struct pid *tgid; /* Thread group ID of owner */ + struct mm_struct *mm; /* Linux process mm_struct */ +}; + +/* * User space window operations used for powernv and powerVM */ struct vas_user_win_ops { @@ -59,6 +73,31 @@ struct vas_user_win_ops { int (*close_win)(struct vas_window *); }; +static inline void put_vas_user_win_ref(struct vas_user_win_ref *ref) +{ + /* Drop references to pid, tgid, and mm */ + put_pid(ref->pid); + put_pid(ref->tgid); + if (ref->mm) + mmdrop(ref->mm); +} + +static inline void vas_user_win_add_mm_context(struct vas_user_win_ref *ref) +{ + mm_context_add_vas_window(ref->mm); + /* + * Even a process that has no foreign real address mapping can + * use an unpaired COPY instruction (to no real effect). Issue + * CP_ABORT to clear any pending COPY and prevent a covert + * channel. + * + * __switch_to() will issue CP_ABORT on future context switches + * if process / thread has any open VAS window (Use + * current->mm->context.vas_windows). + */ + asm volatile(PPC_CP_ABORT); +} + /* * Receive window attributes specified by the (in-kernel) owner of window. */ @@ -190,4 +229,5 @@ int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, const struct vas_user_win_ops *vops); void vas_unregister_coproc_api(void); +int get_vas_user_win_ref(struct vas_user_win_ref *task_ref); #endif /* __ASM_POWERPC_VAS_H */ |