Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1727917

[PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host

From Dongjiu Geng <gengdongjiu@huawei.com>
Newsgroups linux.kernel
Subject [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host
Date 2017-09-07 07:40 +0200
Message-ID <umXHH-3QW-3@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


In VHE mode, host kernel runs in the EL2 and can enable
'User Access Override' when fs==KERNEL_DS so that it can
access kernel memory. However, PSTATE.UAO is set to 0 on
an exception taken from EL1 to EL2. Thus when VHE is used
and exception taken from a guest UAO will be disabled and
host will use the incorrect PSTATE.UAO. So check and reset
the PSTATE.UAO when switching to host.

Move the reset PSTATE.PAN on entry to EL2 together with
PSTATE.UAO reset.

Signed-off-by: Dongjiu Geng <gengdongjiu@huawei.com>
Signed-off-by: Haibin Zhang <zhanghaibin7@huawei.com>
Tested-by: Dongjiu Geng <gengdongjiu@huawei.com>
---
 arch/arm64/kvm/hyp/entry.S  |  2 --
 arch/arm64/kvm/hyp/switch.c | 12 ++++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S
index 12ee62d..7662ef5 100644
--- a/arch/arm64/kvm/hyp/entry.S
+++ b/arch/arm64/kvm/hyp/entry.S
@@ -96,8 +96,6 @@ ENTRY(__guest_exit)
 
 	add	x1, x1, #VCPU_CONTEXT
 
-	ALTERNATIVE(nop, SET_PSTATE_PAN(1), ARM64_HAS_PAN, CONFIG_ARM64_PAN)
-
 	// Store the guest regs x2 and x3
 	stp	x2, x3,   [x1, #CPU_XREG_OFFSET(2)]
 
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
index a733461..715b3941 100644
--- a/arch/arm64/kvm/hyp/switch.c
+++ b/arch/arm64/kvm/hyp/switch.c
@@ -22,6 +22,7 @@
 #include <asm/kvm_emulate.h>
 #include <asm/kvm_hyp.h>
 #include <asm/fpsimd.h>
+#include <asm/exec.h>
 
 static bool __hyp_text __fpsimd_enabled_nvhe(void)
 {
@@ -399,6 +400,17 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
 
 	__sysreg_restore_host_state(host_ctxt);
 
+	if (has_vhe()) {
+		/*
+		 * PSTATE was not saved over guest enter/exit, re-enable
+		 * any detecte features that might not have been set
+		 * correctly.
+		 */
+		uao_thread_switch(current);
+		asm(ALTERNATIVE("nop", SET_PSTATE_PAN(1),
+			ARM64_HAS_PAN, CONFIG_ARM64_PAN));
+	}
+
 	if (fp_enabled) {
 		__fpsimd_save_state(&guest_ctxt->gp_regs.fp_regs);
 		__fpsimd_restore_state(&host_ctxt->gp_regs.fp_regs);
-- 
1.8.3.1

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host Dongjiu Geng <gengdongjiu@huawei.com> - 2017-09-07 07:40 +0200
  Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host James Morse <james.morse@arm.com> - 2017-09-07 11:30 +0200
    Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host gengdongjiu <gengdongjiu@huawei.com> - 2017-09-07 12:10 +0200
      Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host Marc Zyngier <marc.zyngier@arm.com> - 2017-09-07 12:20 +0200
        Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host gengdongjiu <gengdongjiu@huawei.com> - 2017-09-07 14:00 +0200
          Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host Marc Zyngier <marc.zyngier@arm.com> - 2017-09-07 14:10 +0200

csiph-web