From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
mikey@neuling.org, hbabu@us.ibm.com, nicholas.piggin@gmail.com,
linuxppc-dev@ozlabs.org, <linux-kernel@vger.kernel.org>
Subject: [PATCH v3 14/18] powerpc: Define set_thread_uses_vas()
Date: Tue, 7 Nov 2017 18:23:54 -0800 [thread overview]
Message-ID: <1510107838-15181-15-git-send-email-sukadev@linux.vnet.ibm.com> (raw)
In-Reply-To: <1510107838-15181-1-git-send-email-sukadev@linux.vnet.ibm.com>
A CP_ABORT instruction is required in processes that have mapped a VAS
"paste address" with the intention of using COPY/PASTE instructions.
But since CP_ABORT is expensive, we want to restrict it to only processes
that use/intend to use COPY/PASTE.
Define an interface, set_thread_uses_vas(), that VAS can use to indicate
that the current process opened a send window. During context switch,
issue CP_ABORT only for processes that have the flag set.
Thanks for input from Nick Piggin, Michael Ellerman.
Cc: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
---
Changelog[v3]:
- [Nick Piggin] Rename interface to set_thread_uses_vas(), tweak
comment and move the CP_ABORT from callers into the interface.
---
arch/powerpc/include/asm/processor.h | 2 ++
arch/powerpc/include/asm/switch_to.h | 2 ++
arch/powerpc/kernel/process.c | 41 +++++++++++++++++++++++++++---------
3 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h
index 58cc212..bdab3b74 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -341,7 +341,9 @@ struct thread_struct {
unsigned long sier;
unsigned long mmcr2;
unsigned mmcr0;
+
unsigned used_ebb;
+ unsigned int used_vas;
#endif
};
diff --git a/arch/powerpc/include/asm/switch_to.h b/arch/powerpc/include/asm/switch_to.h
index ad2d762..c3ca42c 100644
--- a/arch/powerpc/include/asm/switch_to.h
+++ b/arch/powerpc/include/asm/switch_to.h
@@ -92,6 +92,8 @@ static inline void clear_task_ebb(struct task_struct *t)
#endif
}
+extern int set_thread_uses_vas(void);
+
extern int set_thread_tidr(struct task_struct *t);
extern void clear_thread_tidr(struct task_struct *t);
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index d861fcd..395ca80 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1234,17 +1234,17 @@ struct task_struct *__switch_to(struct task_struct *prev,
* The copy-paste buffer can only store into foreign real
* addresses, so unprivileged processes can not see the
* data or use it in any way unless they have foreign real
- * mappings. We don't have a VAS driver that allocates those
- * yet, so no cpabort is required.
+ * mappings. If the new process has the foreign real address
+ * mappings, we must issue a cp_abort to clear any state and
+ * prevent snooping, corruption or a covert channel.
+ *
+ * DD1 allows paste into normal system memory so we do an
+ * unpaired copy, rather than cp_abort, to clear the buffer,
+ * since cp_abort is quite expensive.
*/
- if (cpu_has_feature(CPU_FTR_POWER9_DD1)) {
- /*
- * DD1 allows paste into normal system memory, so we
- * do an unpaired copy here to clear the buffer and
- * prevent a covert channel being set up.
- *
- * cpabort is not used because it is quite expensive.
- */
+ if (new_thread->used_vas) {
+ asm volatile(PPC_CP_ABORT);
+ } else if (cpu_has_feature(CPU_FTR_POWER9_DD1)) {
asm volatile(PPC_COPY(%0, %1)
: : "r"(dummy_copy_buffer), "r"(0));
}
@@ -1445,6 +1445,27 @@ void flush_thread(void)
#endif /* CONFIG_HAVE_HW_BREAKPOINT */
}
+int set_thread_uses_vas(void)
+{
+#ifdef CONFIG_PPC_BOOK3S_64
+ if (!cpu_has_feature(CPU_FTR_ARCH_300))
+ return -EINVAL;
+
+ current->thread.used_vas = 1;
+
+ /*
+ * 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.
+ */
+ asm volatile(PPC_CP_ABORT);
+
+#endif /* CONFIG_PPC_BOOK3S_64 */
+ return 0;
+}
+
#ifdef CONFIG_PPC64
static DEFINE_SPINLOCK(vas_thread_id_lock);
static DEFINE_IDA(vas_thread_ida);
--
2.7.4
next prev parent reply other threads:[~2017-11-08 2:24 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-08 2:23 [PATCH v3 00/18] powerpc/vas: Add support for FTW Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 01/18] powerpc/vas: init missing fields from [rt]xattr Sukadev Bhattiprolu
2017-11-14 11:12 ` [v3,01/18] " Michael Ellerman
2017-11-08 2:23 ` [PATCH v3 02/18] powerpc/vas: Validate window credits Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 03/18] powerpc/vas: Cleanup some debug code Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 04/18] powerpc/vas: Drop poll_window_cast_out() Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 05/18] powerpc/vas: Use helper to unpin/close window Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 06/18] powerpc/vas: Reduce polling interval for busy state Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 07/18] powerpc/vas: Save configured window credits Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 08/18] powerpc/vas: poll for return of " Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 09/18] powerpc/vas: Create cpu to vas id mapping Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 10/18] powerpc/vas, nx-842: Define and use chip_to_vas_id() Sukadev Bhattiprolu
2017-11-20 17:57 ` Josh Boyer
2017-11-22 11:56 ` Michael Ellerman
2017-11-08 2:23 ` [PATCH v3 11/18] powerpc/vas: Export HVWC to debugfs Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 12/18] powerpc: have copy depend on CONFIG_BOOK3S_64 Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 13/18] powerpc: Add support for setting SPRN_TIDR Sukadev Bhattiprolu
2017-11-09 11:53 ` Michael Ellerman
2017-11-08 2:23 ` Sukadev Bhattiprolu [this message]
2017-11-08 2:23 ` [PATCH v3 15/18] powerpc: Emulate paste instruction Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 16/18] powerpc/vas: Define vas_win_paste_addr() Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 17/18] powerpc/vas: Define vas_win_id() Sukadev Bhattiprolu
2017-11-08 2:23 ` [PATCH v3 18/18] powerpc/vas: Add support for user receive window Sukadev Bhattiprolu
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=1510107838-15181-15-git-send-email-sukadev@linux.vnet.ibm.com \
--to=sukadev@linux.vnet.ibm.com \
--cc=benh@kernel.crashing.org \
--cc=hbabu@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=mikey@neuling.org \
--cc=mpe@ellerman.id.au \
--cc=nicholas.piggin@gmail.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).