diff mbox

KVM: nVMX: Add support for activity state HLT

Message ID 529EE0BE.4050501@siemens.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Kiszka Dec. 4, 2013, 7:58 a.m. UTC
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 <jan.kiszka@siemens.com>
---

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(-)

Comments

Paolo Bonzini Dec. 5, 2013, 9:52 a.m. UTC | #1
Il 04/12/2013 08:58, Jan Kiszka ha scritto:
> 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 <jan.kiszka@siemens.com>
> ---
> 
> 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

>  arch/x86/include/asm/vmx.h | 1 +
>  arch/x86/kvm/vmx.c         | 7 ++++++-
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
> index 966502d..2067264 100644
> --- a/arch/x86/include/asm/vmx.h
> +++ b/arch/x86/include/asm/vmx.h
> @@ -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 {
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index b2fe1c2..00faf1f 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -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
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jan Kiszka Dec. 6, 2013, 12:49 p.m. UTC | #2
On 2013-12-05 10:52, Paolo Bonzini wrote:
> Il 04/12/2013 08:58, Jan Kiszka ha scritto:
>> 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 <jan.kiszka@siemens.com>
>> ---
>>
>> 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

> 
> Paolo
> 
>>  arch/x86/include/asm/vmx.h | 1 +
>>  arch/x86/kvm/vmx.c         | 7 ++++++-
>>  2 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
>> index 966502d..2067264 100644
>> --- a/arch/x86/include/asm/vmx.h
>> +++ b/arch/x86/include/asm/vmx.h
>> @@ -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 {
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index b2fe1c2..00faf1f 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -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
>>
>
diff mbox

Patch

diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index 966502d..2067264 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -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 {
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index b2fe1c2..00faf1f 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -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