powerpc/vas: Don't set uses_vas for kernel windows

"Linux Kernel Mailing List" <[email protected]> Wed, 14 Feb 2018 18:19:52 +0000 (UTC)
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/b00b62898631b756c3e123542bbb0487aa343dd9
Commit:     b00b62898631b756c3e123542bbb0487aa343dd9
Parent:     c9dccf1d074a67d36c510845f663980d69e3409b
Refname:    refs/heads/master
Author:     Nicholas Piggin <[email protected]>
AuthorDate: Thu Feb 8 19:18:38 2018 +1000
Committer:  Michael Ellerman <[email protected]>
CommitDate: Tue Feb 13 22:37:46 2018 +1100

    powerpc/vas: Don't set uses_vas for kernel windows
    
    cp_abort is only required for user windows, because kernel context
    must not be preempted between a copy/paste pair.
    
    Without this patch, the init task gets used_vas set when it runs the
    nx842_powernv_init initcall, which opens windows for kernel usage.
    
    used_vas is then never cleared anywhere, so it gets propagated into
    all other tasks. It's a property of the address space, so it should
    really be cleared when a new mm is created (or in dup_mmap if the
    mmaps are marked as VM_DONTCOPY). For now we seem to have no such
    driver, so leave that for another patch.
    
    Fixes: 6c8e6bb2a52d ("powerpc/vas: Add support for user receive window")
    Cc: [email protected] # v4.15+
    Signed-off-by: Nicholas Piggin <[email protected]>
    Reviewed-by: Sukadev Bhattiprolu <[email protected]>
    Signed-off-by: Michael Ellerman <[email protected]>
---
 arch/powerpc/platforms/powernv/vas-window.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c
index 2b3eb01ab110..b7c53a51c31b 100644
--- a/arch/powerpc/platforms/powernv/vas-window.c
+++ b/arch/powerpc/platforms/powernv/vas-window.c
@@ -1063,16 +1063,16 @@ struct vas_window *vas_tx_win_open(int vasid, enum vas_cop_type cop,
 			rc = PTR_ERR(txwin->paste_kaddr);
 			goto free_window;
 		}
+	} else {
+		/*
+		 * A user mapping must ensure that context switch issues
+		 * CP_ABORT for this thread.
+		 */
+		rc = set_thread_uses_vas();
+		if (rc)
+			goto free_window;
 	}
 
-	/*
-	 * Now that we have a send window, ensure context switch issues
-	 * CP_ABORT for this thread.
-	 */
-	rc = -EINVAL;
-	if (set_thread_uses_vas() < 0)
-		goto free_window;