KVM: nVMX: Add support for activity state HLT
PATCH 1/1 KVM: nVMX: Add support for activity state HLT
We can easily emulate the HLT activity state for L1: If it decides that L2 shall be halted on entry, just invoke the normal emulation of halt after switching to L2. We do not depend on specific host features to provide this, so we can expose the capability unconditionally.
---
Jailhouse would like to use this. Experimental code works fine so far, both on patched KVM and real HW.
arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/vmx.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)
arch/x86/include/asm/vmx.h +1 -0
@@ -100,6 +100,7 @@#define VMX_MISC_PREEMPTION_TIMER_RATE_MASK 0x0000001f#define VMX_MISC_SAVE_EFER_LMA 0x00000020 +#define VMX_MISC_ACTIVITY_HLT 0x00000040/* VMCS Encodings */ enum vmcs_field {
arch/x86/kvm/vmx.c +6 -1
@@ -2279,6 +2279,7 @@ static __init void nested_vmx_setup_ctls_msrs(void)rdmsr (MSR_IA32_VMX_MISC , nested_vmx_misc_low, nested_vmx_misc_high); nested_vmx_misc_low &=VMX_MISC_PREEMPTION_TIMER_RATE_MASK |VMX_MISC_SAVE_EFER_LMA ; + nested_vmx_misc_low |=VMX_MISC_ACTIVITY_HLT ; nested_vmx_misc_high =0 ; }
@@ -7882,7 +7883,8 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)return 1 ; } -if (vmcs12->guest_activity_state !=GUEST_ACTIVITY_ACTIVE ) { +if (vmcs12->guest_activity_state !=GUEST_ACTIVITY_ACTIVE && + vmcs12->guest_activity_state !=GUEST_ACTIVITY_HLT ) {nested_vmx_failValid (vcpu,VMXERR_ENTRY_INVALID_CONTROL_FIELD );return 1 ; }
@@ -8011,6 +8013,9 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)prepare_vmcs02 (vcpu, vmcs12); +if (vmcs12->guest_activity_state ==GUEST_ACTIVITY_HLT ) +return kvm_emulate_halt (vcpu); +/* * Note no nested_vmx_succeed or nested_vmx_fail here. At this point * we are no longer running L1, and VMLAUNCH/VMRESUME has not yet
Signature · 1 line
1.8.1.1.298.ge7eed54
Paolo Bonzini
maintainerIl 04/12/2013 08:58, Jan Kiszka ha scritto:
Quoted 10 lines
We can easily emulate the HLT activity state for L1: If it decides that L2 shall be halted on entry, just invoke the normal emulation of halt after switching to L2. We do not depend on specific host features to provide this, so we can expose the capability unconditionally.
Signed-off-by Jan Kiszka <[email protected]>---
Jailhouse would like to use this. Experimental code works fine so far, both on patched KVM and real HW.
Nice. :)
Do you have a testcase for kvm-unit-tests?
Paolo
Quoted 49 lines
arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/vmx.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)arch/x86/include/asm/vmx.h +1
-0@@ -100,6 +100,7 @@#define VMX_MISC_PREEMPTION_TIMER_RATE_MASK 0x0000001f#define VMX_MISC_SAVE_EFER_LMA 0x00000020 +#define VMX_MISC_ACTIVITY_HLT 0x00000040/* VMCS Encodings */ enum vmcs_field {arch/x86/kvm/vmx.c +6
-1@@ -2279,6 +2279,7 @@ static __init void nested_vmx_setup_ctls_msrs(void)rdmsr (MSR_IA32_VMX_MISC , nested_vmx_misc_low, nested_vmx_misc_high); nested_vmx_misc_low &=VMX_MISC_PREEMPTION_TIMER_RATE_MASK |VMX_MISC_SAVE_EFER_LMA ; + nested_vmx_misc_low |=VMX_MISC_ACTIVITY_HLT ; nested_vmx_misc_high =0 ; }@@ -7882,7 +7883,8 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)return 1 ; } -if (vmcs12->guest_activity_state !=GUEST_ACTIVITY_ACTIVE ) { +if (vmcs12->guest_activity_state !=GUEST_ACTIVITY_ACTIVE && + vmcs12->guest_activity_state !=GUEST_ACTIVITY_HLT ) {nested_vmx_failValid (vcpu,VMXERR_ENTRY_INVALID_CONTROL_FIELD );return 1 ; }@@ -8011,6 +8013,9 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)prepare_vmcs02 (vcpu, vmcs12); +if (vmcs12->guest_activity_state ==GUEST_ACTIVITY_HLT ) +return kvm_emulate_halt (vcpu); +/* * Note no nested_vmx_succeed or nested_vmx_fail here. At this point * we are no longer running L1, and VMLAUNCH/VMRESUME has not yet
Quoted 9 lines · Paolo Bonzini
Il 04/12/2013 08:58, Jan Kiszka ha scritto:
Quoted 8 lines
We can easily emulate the HLT activity state for L1: If it decides that L2 shall be halted on entry, just invoke the normal emulation of halt after switching to L2. We do not depend on specific host features to provide this, so we can expose the capability unconditionally.
Signed-off-by Jan Kiszka <[email protected]>---
Quoted 6 lines
Quoted 2 lines
Jailhouse would like to use this. Experimental code works fine so far, both on patched KVM and real HW.
Nice. :)
Do you have a testcase for kvm-unit-tests?
Not yet. Maybe I will find a little time these days.
Jan
Quoted 53 lines
Paolo
Quoted 49 lines
arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/vmx.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)arch/x86/include/asm/vmx.h +1
-0@@ -100,6 +100,7 @@#define VMX_MISC_PREEMPTION_TIMER_RATE_MASK 0x0000001f#define VMX_MISC_SAVE_EFER_LMA 0x00000020 +#define VMX_MISC_ACTIVITY_HLT 0x00000040/* VMCS Encodings */ enum vmcs_field {arch/x86/kvm/vmx.c +6
-1@@ -2279,6 +2279,7 @@ static __init void nested_vmx_setup_ctls_msrs(void)rdmsr (MSR_IA32_VMX_MISC , nested_vmx_misc_low, nested_vmx_misc_high); nested_vmx_misc_low &=VMX_MISC_PREEMPTION_TIMER_RATE_MASK |VMX_MISC_SAVE_EFER_LMA ; + nested_vmx_misc_low |=VMX_MISC_ACTIVITY_HLT ; nested_vmx_misc_high =0 ; }@@ -7882,7 +7883,8 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)return 1 ; } -if (vmcs12->guest_activity_state !=GUEST_ACTIVITY_ACTIVE ) { +if (vmcs12->guest_activity_state !=GUEST_ACTIVITY_ACTIVE && + vmcs12->guest_activity_state !=GUEST_ACTIVITY_HLT ) {nested_vmx_failValid (vcpu,VMXERR_ENTRY_INVALID_CONTROL_FIELD );return 1 ; }@@ -8011,6 +8013,9 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)prepare_vmcs02 (vcpu, vmcs12); +if (vmcs12->guest_activity_state ==GUEST_ACTIVITY_HLT ) +return kvm_emulate_halt (vcpu); +/* * Note no nested_vmx_succeed or nested_vmx_fail here. At this point * we are no longer running L1, and VMLAUNCH/VMRESUME has not yet
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 10 lines · Jan Kiszka
Quoted 9 lines · Paolo Bonzini
Il 04/12/2013 08:58, Jan Kiszka ha scritto:
Quoted 8 lines
We can easily emulate the HLT activity state for L1: If it decides that L2 shall be halted on entry, just invoke the normal emulation of halt after switching to L2. We do not depend on specific host features to provide this, so we can expose the capability unconditionally.
Signed-off-by Jan Kiszka <[email protected]>---
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Jailhouse would like to use this. Experimental code works fine so far, both on patched KVM and real HW.
Nice. :)
Do you have a testcase for kvm-unit-tests?
Not yet. Maybe I will find a little time these days.
Test are still ongoing, but it seems there are problems remaining with halting in L2 in general, i.e. with unintercepted hlt. I'm currently applying this to get beyond some hangups, but I'm still experiencing some delayed IRQ delivery to L2:
arch/x86/kvm/vmx.c +3 -2
@@ -4684,6 +4684,7 @@ static int vmx_interrupt_allowed(struct kvm_vcpu *vcpu) vmcs12->vm_exit_reason =EXIT_REASON_EXTERNAL_INTERRUPT ; vmcs12->vm_exit_intr_info =0 ; +kvm_make_request (KVM_REQ_UNHALT , vcpu);/* * fall through to normal code, but now in L1, not L2 */
@@ -8057,8 +8058,6 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)enter_guest_mode (vcpu); - vmx->nested.nested_run_pending =1 ; - vmx->nested.vmcs01_tsc_offset =vmcs_read64 (TSC_OFFSET ); cpu =get_cpu ();
@@ -8077,6 +8076,8 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)if (vmcs12->guest_activity_state ==GUEST_ACTIVITY_HLT )return kvm_emulate_halt (vcpu); + vmx->nested.nested_run_pending =1 ; +/* * Note no nested_vmx_succeed or nested_vmx_fail here. At this point * we are no longer running L1, and VMLAUNCH/VMRESUME has not yet
Jan