Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/nvmm/x86 Optimize:
details: https://anonhg.NetBSD.org/src/rev/e08e8d0f3e71
branches: trunk
changeset: 838302:e08e8d0f3e71
user: maxv <maxv%NetBSD.org@localhost>
date: Thu Jan 10 06:58:36 2019 +0000
description:
Optimize:
* Don't save/restore the host CR2, we don't care because we're not in a
#PF context (and preemption switches already handle CR2 safely).
* Don't save/restore the host FS and GS, just reset them to zero after
VMRUN. Note: DS and ES must be reset _before_ VMRUN, but that doesn't
apply to FS and GS.
* Handle FSBASE and KGSBASE outside of the VCPU loop, to avoid the cost
of saving/restoring them when there's no reason to leave the loop.
diffstat:
sys/dev/nvmm/x86/nvmm_x86_svm.c | 19 ++++++++-----------
sys/dev/nvmm/x86/nvmm_x86_svmfunc.S | 34 ++++++++--------------------------
2 files changed, 16 insertions(+), 37 deletions(-)
diffs (131 lines):
diff -r 0bca7ee03841 -r e08e8d0f3e71 sys/dev/nvmm/x86/nvmm_x86_svm.c
--- a/sys/dev/nvmm/x86/nvmm_x86_svm.c Thu Jan 10 06:31:04 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_svm.c Thu Jan 10 06:58:36 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvmm_x86_svm.c,v 1.13 2019/01/08 14:43:18 maxv Exp $ */
+/* $NetBSD: nvmm_x86_svm.c,v 1.14 2019/01/10 06:58:36 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.13 2019/01/08 14:43:18 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.14 2019/01/10 06:58:36 maxv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -521,7 +521,8 @@
uint64_t lstar;
uint64_t cstar;
uint64_t sfmask;
- uint64_t cr2;
+ uint64_t fsbase;
+ uint64_t kernelgsbase;
bool ts_set;
struct xsave_header hfpu __aligned(16);
@@ -1151,14 +1152,12 @@
{
struct svm_cpudata *cpudata = vcpu->cpudata;
- /* Save the fixed Host MSRs. */
cpudata->star = rdmsr(MSR_STAR);
cpudata->lstar = rdmsr(MSR_LSTAR);
cpudata->cstar = rdmsr(MSR_CSTAR);
cpudata->sfmask = rdmsr(MSR_SFMASK);
-
- /* Save the Host CR2. */
- cpudata->cr2 = rcr2();
+ cpudata->fsbase = rdmsr(MSR_FSBASE);
+ cpudata->kernelgsbase = rdmsr(MSR_KERNELGSBASE);
}
static void
@@ -1166,14 +1165,12 @@
{
struct svm_cpudata *cpudata = vcpu->cpudata;
- /* Restore the fixed Host MSRs. */
wrmsr(MSR_STAR, cpudata->star);
wrmsr(MSR_LSTAR, cpudata->lstar);
wrmsr(MSR_CSTAR, cpudata->cstar);
wrmsr(MSR_SFMASK, cpudata->sfmask);
-
- /* Restore the Host CR2. */
- lcr2(cpudata->cr2);
+ wrmsr(MSR_FSBASE, cpudata->fsbase);
+ wrmsr(MSR_KERNELGSBASE, cpudata->kernelgsbase);
}
static int
diff -r 0bca7ee03841 -r e08e8d0f3e71 sys/dev/nvmm/x86/nvmm_x86_svmfunc.S
--- a/sys/dev/nvmm/x86/nvmm_x86_svmfunc.S Thu Jan 10 06:31:04 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_svmfunc.S Thu Jan 10 06:58:36 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvmm_x86_svmfunc.S,v 1.1 2018/11/07 07:43:08 maxv Exp $ */
+/* $NetBSD: nvmm_x86_svmfunc.S,v 1.2 2019/01/10 06:58:36 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -73,14 +73,6 @@
movq $msr,%rcx ;\
wrmsr
-#define HOST_SAVE_SEGREG(sreg) \
- movw sreg,%ax ;\
- pushw %ax
-
-#define HOST_RESTORE_SEGREG(sreg)\
- popw %ax ;\
- movw %ax,sreg
-
#define HOST_SAVE_TR \
strw %ax ;\
pushw %ax
@@ -150,22 +142,13 @@
/* Save the Host TR. */
HOST_SAVE_TR
- /* Save the variable Host MSRs. */
- HOST_SAVE_MSR(MSR_KERNELGSBASE)
+ /* Save the Host GSBASE. */
HOST_SAVE_MSR(MSR_GSBASE)
- HOST_SAVE_MSR(MSR_FSBASE)
- /* Reset the Host Segregs. */
+ /* Reset DS and ES. */
movq $GSEL(GUDATA_SEL, SEL_UPL),%rax
movw %ax,%ds
movw %ax,%es
- xorq %rax,%rax
- movw %ax,%fs
- movw %ax,%gs
-
- /* Save some Host Segregs. */
- HOST_SAVE_SEGREG(%fs)
- HOST_SAVE_SEGREG(%gs)
/* Save the Host LDT. */
HOST_SAVE_LDT
@@ -195,14 +178,13 @@
/* Restore the Host LDT. */
HOST_RESTORE_LDT
- /* Restore the Host Segregs. */
- HOST_RESTORE_SEGREG(%gs)
- HOST_RESTORE_SEGREG(%fs)
+ /* Reset FS and GS. */
+ xorq %rax,%rax
+ movw %ax,%fs
+ movw %ax,%gs
- /* Restore the variable Host MSRs. */
- HOST_RESTORE_MSR(MSR_FSBASE)
+ /* Restore the Host GSBASE. */
HOST_RESTORE_MSR(MSR_GSBASE)
- HOST_RESTORE_MSR(MSR_KERNELGSBASE)
/* Restore the Host TR. */
HOST_RESTORE_TR
Home |
Main Index |
Thread Index |
Old Index