linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Haren Myneni <haren@linux.vnet.ibm.com>
To: linuxppc-dev@lists.ozlabs.org, mpe@ellerman.id.au
Cc: sukadev@linux.vnet.ibm.com
Subject: [RFC PATCH 09/13] powerpc/vas: Add and use tgid in vas_window to close window
Date: Fri, 18 Oct 2019 22:59:06 -0700	[thread overview]
Message-ID: <1571464746.24387.35.camel@hbabu-laptop> (raw)


In multi-thread applications, child can open a window but release FD
will not be called upon its exit. NX Send window will be closed with
release function. Parent thread will be closing it later upon its exit.

The parent can also send NX requests with this window and NX can
generate page faults. After kernel handles the page fault, send
signal to process by using PID if CRB is invalid. So parent thread
will not receive signal since its PID is different from the one saved
in vas_window.

So use tgid in case if the task which has the same pid as in window
is not running and sends signal to the parent.

Signed-off-by: Haren Myneni <haren@us.ibm.com>
---
 arch/powerpc/platforms/powernv/vas-fault.c  | 14 ++++++++++++--
 arch/powerpc/platforms/powernv/vas-window.c |  6 +++++-
 arch/powerpc/platforms/powernv/vas.h        |  6 ++++++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/vas-fault.c b/arch/powerpc/platforms/powernv/vas-fault.c
index 1ce85b5..98100c7 100644
--- a/arch/powerpc/platforms/powernv/vas-fault.c
+++ b/arch/powerpc/platforms/powernv/vas-fault.c
@@ -109,12 +109,14 @@ static void notify_process(pid_t pid, u64 fault_addr)
  * Remaining settings in the CSB are based on wait_for_csb() of
  * NX-GZIP.
 */
-static void update_csb(int pid, struct coprocessor_request_block *crb)
+static void update_csb(struct vas_window *window,
+			struct coprocessor_request_block *crb)
 {
 	int rc;
 	void __user *csb_addr;
 	struct task_struct *tsk;
 	struct coprocessor_status_block csb;
+	pid_t pid = vas_window_pid(window);
 
 	if (fault_in_csb(crb))
 		goto notify;
@@ -137,6 +139,14 @@ static void update_csb(int pid, struct coprocessor_request_block *crb)
 
 	rcu_read_lock();
 	tsk = find_task_by_vpid(pid);
+
+	/*
+	 * Thread may not exists, but does not close FD (means send window)
+	 * upon exit. Expects parent (tgid) to use and close the window.
+	 */
+	if (!tsk && window->user_win)
+		tsk = find_task_by_vpid(vas_window_tgid(window));
+
 	if (!tsk) {
 		/*
 		 * vas_win_close() waits for any pending CRBs and pending
@@ -270,7 +280,7 @@ static void process_fault_crbs(struct vas_instance *vinst)
 			return;
 		}
 
-		update_csb(vas_window_pid(window), crb);
+		update_csb(window, crb);
 	} while (true);
 }
 
diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c
index 77871c1..2946dd6 100644
--- a/arch/powerpc/platforms/powernv/vas-window.c
+++ b/arch/powerpc/platforms/powernv/vas-window.c
@@ -886,8 +886,10 @@ struct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop,
 	rxwin->user_win = rxattr->user_win;
 	rxwin->cop = cop;
 	rxwin->wcreds_max = rxattr->wcreds_max ?: VAS_WCREDS_DEFAULT;
-	if (rxattr->user_win)
+	if (rxattr->user_win) {
 		rxwin->pid = task_pid_vnr(current);
+		rxwin->tgid = task_tgid_vnr(current);
+	}
 
 	init_winctx_for_rxwin(rxwin, rxattr, &winctx);
 	init_winctx_regs(rxwin, &winctx);
@@ -1033,6 +1035,8 @@ struct vas_window *vas_tx_win_open(int vasid, enum vas_cop_type cop,
 	txwin->pid = attr->pid;
 	txwin->user_win = attr->user_win;
 	txwin->wcreds_max = attr->wcreds_max ?: VAS_WCREDS_DEFAULT;
+	if (attr->user_win)
+		txwin->tgid = task_tgid_vnr(current);
 
 	init_winctx_for_txwin(txwin, attr, &winctx);
 
diff --git a/arch/powerpc/platforms/powernv/vas.h b/arch/powerpc/platforms/powernv/vas.h
index be1aefa..1812c59 100644
--- a/arch/powerpc/platforms/powernv/vas.h
+++ b/arch/powerpc/platforms/powernv/vas.h
@@ -344,6 +344,7 @@ struct vas_window {
 	void *hvwc_map;		/* HV window context */
 	void *uwc_map;		/* OS/User window context */
 	pid_t pid;		/* Linux process id of owner */
+	pid_t tgid;		/* Thread group ID of owner */
 	int wcreds_max;		/* Window credits */
 
 	char *dbgname;
@@ -429,6 +430,11 @@ static inline int vas_window_pid(struct vas_window *window)
 	return window->pid;
 }
 
+static inline int vas_window_tgid(struct vas_window *window)
+{
+	return window->tgid;
+}
+
 static inline void vas_log_write(struct vas_window *win, char *name,
 			void *regptr, u64 val)
 {
-- 
1.8.3.1




                 reply	other threads:[~2019-10-19  6:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1571464746.24387.35.camel@hbabu-laptop \
    --to=haren@linux.vnet.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=sukadev@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).