summaryrefslogtreecommitdiff
path: root/arch/powerpc/platforms/book3s
diff options
context:
space:
mode:
authorHaren Myneni <haren@linux.ibm.com>2021-06-17 23:31:43 +0300
committerMichael Ellerman <mpe@ellerman.id.au>2021-06-20 14:58:56 +0300
commit3856aa542d90ed79cd5ed4cfd828b1fb04017131 (patch)
tree12568cf37fd354fcff057329ffa7d4a88680e025 /arch/powerpc/platforms/book3s
parent1a0d0d5ed5e3cd9e3fc1ad4459f1db2f3618fce0 (diff)
downloadlinux-3856aa542d90ed79cd5ed4cfd828b1fb04017131.tar.xz
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/platforms/book3s')
-rw-r--r--arch/powerpc/platforms/book3s/vas-api.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/book3s/vas-api.c b/arch/powerpc/platforms/book3s/vas-api.c
index ad566464b55b..4ce82500f4c5 100644
--- a/arch/powerpc/platforms/book3s/vas-api.c
+++ b/arch/powerpc/platforms/book3s/vas-api.c
@@ -55,6 +55,45 @@ static char *coproc_devnode(struct device *dev, umode_t *mode)
return kasprintf(GFP_KERNEL, "crypto/%s", dev_name(dev));
}
+/*
+ * Take reference to pid and mm
+ */
+int get_vas_user_win_ref(struct vas_user_win_ref *task_ref)
+{
+ /*
+ * Window opened by a child thread may not be closed when
+ * it exits. So take reference to its pid and release it
+ * when the window is free by parent thread.
+ * Acquire a reference to the task's pid to make sure
+ * pid will not be re-used - needed only for multithread
+ * applications.
+ */
+ task_ref->pid = get_task_pid(current, PIDTYPE_PID);
+ /*
+ * Acquire a reference to the task's mm.
+ */
+ task_ref->mm = get_task_mm(current);
+ if (!task_ref->mm) {
+ put_pid(task_ref->pid);
+ pr_err("VAS: pid(%d): mm_struct is not found\n",
+ current->pid);
+ return -EPERM;
+ }
+
+ mmgrab(task_ref->mm);
+ mmput(task_ref->mm);
+ /*
+ * Process closes window during exit. In the case of
+ * multithread application, the child thread can open
+ * window and can exit without closing it. So takes tgid
+ * reference until window closed to make sure tgid is not
+ * reused.
+ */
+ task_ref->tgid = find_get_pid(task_tgid_vnr(current));
+
+ return 0;
+}
+
static int coproc_open(struct inode *inode, struct file *fp)
{
struct coproc_instance *cp_inst;