Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/x86/x86 Change the effect of SVS on the TLB. Keep C...
details: https://anonhg.NetBSD.org/src/rev/2894310fdecb
branches: trunk
changeset: 999276:2894310fdecb
user: maxv <maxv%NetBSD.org@localhost>
date: Mon May 27 18:36:37 2019 +0000
description:
Change the effect of SVS on the TLB. Keep CR4_PGE set when SVS is enabled,
but don't use PTE_G on the kernel PTEs in general.
Add PTE_G on only a few pages, that are already leaked to userland and do
not contain secrets.
This slightly improves syscall performance.
diffstat:
sys/arch/x86/x86/cpu.c | 7 ++-----
sys/arch/x86/x86/pmap.c | 11 ++++++++---
sys/arch/x86/x86/svs.c | 33 ++++++++++++++++++++++-----------
3 files changed, 32 insertions(+), 19 deletions(-)
diffs (157 lines):
diff -r caccd133bc09 -r 2894310fdecb sys/arch/x86/x86/cpu.c
--- a/sys/arch/x86/x86/cpu.c Mon May 27 17:32:36 2019 +0000
+++ b/sys/arch/x86/x86/cpu.c Mon May 27 18:36:37 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.169 2019/05/27 17:32:36 maxv Exp $ */
+/* $NetBSD: cpu.c,v 1.170 2019/05/27 18:36:37 maxv Exp $ */
/*
* Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.169 2019/05/27 17:32:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.170 2019/05/27 18:36:37 maxv Exp $");
#include "opt_ddb.h"
#include "opt_mpbios.h" /* for MPDEBUG */
@@ -586,9 +586,6 @@
/* If global TLB caching is supported, enable it */
if (cpu_feature[0] & CPUID_PGE)
-#ifdef SVS
- if (!svs_enabled)
-#endif
cr4 |= CR4_PGE;
/*
diff -r caccd133bc09 -r 2894310fdecb sys/arch/x86/x86/pmap.c
--- a/sys/arch/x86/x86/pmap.c Mon May 27 17:32:36 2019 +0000
+++ b/sys/arch/x86/x86/pmap.c Mon May 27 18:36:37 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.332 2019/05/27 17:32:36 maxv Exp $ */
+/* $NetBSD: pmap.c,v 1.333 2019/05/27 18:36:37 maxv Exp $ */
/*
* Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.332 2019/05/27 17:32:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.333 2019/05/27 18:36:37 maxv Exp $");
#include "opt_user_ldt.h"
#include "opt_lockdebug.h"
@@ -1117,12 +1117,17 @@
#if !defined(XENPV)
/*
* Begin to enable global TLB entries if they are supported: add PTE_G
- * attribute to already mapped kernel pages.
+ * attribute to already mapped kernel pages. Do that only if SVS is
+ * disabled.
*
* The G bit has no effect until the CR4_PGE bit is set in CR4, which
* happens later in cpu_init().
*/
+#ifdef SVS
+ if (!svs_enabled && (cpu_feature[0] & CPUID_PGE)) {
+#else
if (cpu_feature[0] & CPUID_PGE) {
+#endif
pmap_pg_g = PTE_G;
pmap_remap_global();
}
diff -r caccd133bc09 -r 2894310fdecb sys/arch/x86/x86/svs.c
--- a/sys/arch/x86/x86/svs.c Mon May 27 17:32:36 2019 +0000
+++ b/sys/arch/x86/x86/svs.c Mon May 27 18:36:37 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: svs.c,v 1.27 2019/05/27 17:32:36 maxv Exp $ */
+/* $NetBSD: svs.c,v 1.28 2019/05/27 18:36:37 maxv Exp $ */
/*
* Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svs.c,v 1.27 2019/05/27 17:32:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svs.c,v 1.28 2019/05/27 18:36:37 maxv Exp $");
#include "opt_svs.h"
@@ -268,7 +268,7 @@
}
static void
-svs_page_add(struct cpu_info *ci, vaddr_t va)
+svs_page_add(struct cpu_info *ci, vaddr_t va, bool global)
{
pd_entry_t *srcpde, *dstpde, pde;
size_t idx, pidx;
@@ -289,9 +289,10 @@
panic("%s: L2 page not mapped", __func__);
}
if (srcpde[idx] & PTE_PS) {
+ KASSERT(!global);
pa = srcpde[idx] & PTE_2MFRAME;
pa += (paddr_t)(va % NBPD_L2);
- pde = (srcpde[idx] & ~(PTE_G|PTE_PS|PTE_2MFRAME)) | pa;
+ pde = (srcpde[idx] & ~(PTE_PS|PTE_2MFRAME)) | pa;
if (pmap_valid_entry(dstpde[pidx])) {
panic("%s: L1 page already mapped", __func__);
@@ -311,7 +312,17 @@
if (pmap_valid_entry(dstpde[pidx])) {
panic("%s: L1 page already mapped", __func__);
}
- dstpde[pidx] = srcpde[idx] & ~(PTE_G);
+ dstpde[pidx] = srcpde[idx];
+
+ /*
+ * If we want a global translation, mark both the src and dst with
+ * PTE_G.
+ */
+ if (global) {
+ srcpde[idx] |= PTE_G;
+ dstpde[pidx] |= PTE_G;
+ tlbflushg();
+ }
}
static void
@@ -394,14 +405,14 @@
}
static void
-svs_range_add(struct cpu_info *ci, vaddr_t va, size_t size)
+svs_range_add(struct cpu_info *ci, vaddr_t va, size_t size, bool global)
{
size_t i, n;
KASSERT(size % PAGE_SIZE == 0);
n = size / PAGE_SIZE;
for (i = 0; i < n; i++) {
- svs_page_add(ci, va + i * PAGE_SIZE);
+ svs_page_add(ci, va + i * PAGE_SIZE, global);
}
}
@@ -434,12 +445,12 @@
mutex_init(&ci->ci_svs_mtx, MUTEX_DEFAULT, IPL_VM);
- svs_page_add(ci, (vaddr_t)&pcpuarea->idt);
- svs_page_add(ci, (vaddr_t)&pcpuarea->ldt);
+ svs_page_add(ci, (vaddr_t)&pcpuarea->idt, true);
+ svs_page_add(ci, (vaddr_t)&pcpuarea->ldt, true);
svs_range_add(ci, (vaddr_t)&pcpuarea->ent[cid],
- offsetof(struct pcpu_entry, rsp0));
+ offsetof(struct pcpu_entry, rsp0), true);
svs_range_add(ci, (vaddr_t)&__text_user_start,
- (vaddr_t)&__text_user_end - (vaddr_t)&__text_user_start);
+ (vaddr_t)&__text_user_end - (vaddr_t)&__text_user_start, false);
svs_rsp0_init(ci);
svs_utls_init(ci);
Home |
Main Index |
Thread Index |
Old Index