All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls
@ 2017-02-15 14:44 Paolo Bonzini
  2017-02-16 16:24 ` Radim Krčmář
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Paolo Bonzini @ 2017-02-15 14:44 UTC (permalink / raw)
  To: linux-kernel, kvm

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/vmx.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index bca60665d55d..0e0b5d09597e 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -5459,26 +5459,20 @@ static bool nested_exit_on_nmi(struct kvm_vcpu *vcpu)
 
 static void enable_irq_window(struct kvm_vcpu *vcpu)
 {
-	u32 cpu_based_vm_exec_control;
-
-	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
-	cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_INTR_PENDING;
-	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
+	vmcs_set_bits(CPU_BASED_VM_EXEC_CONTROL,
+		      CPU_BASED_VIRTUAL_INTR_PENDING);
 }
 
 static void enable_nmi_window(struct kvm_vcpu *vcpu)
 {
-	u32 cpu_based_vm_exec_control;
-
 	if (!cpu_has_virtual_nmis() ||
 	    vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & GUEST_INTR_STATE_STI) {
 		enable_irq_window(vcpu);
 		return;
 	}
 
-	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
-	cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_NMI_PENDING;
-	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
+	vmcs_set_bits(CPU_BASED_VM_EXEC_CONTROL,
+		      CPU_BASED_VIRTUAL_NMI_PENDING);
 }
 
 static void vmx_inject_irq(struct kvm_vcpu *vcpu)
@@ -6137,12 +6131,8 @@ static int handle_tpr_below_threshold(struct kvm_vcpu *vcpu)
 
 static int handle_interrupt_window(struct kvm_vcpu *vcpu)
 {
-	u32 cpu_based_vm_exec_control;
-
-	/* clear pending irq */
-	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
-	cpu_based_vm_exec_control &= ~CPU_BASED_VIRTUAL_INTR_PENDING;
-	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
+	vmcs_clear_bits(CPU_BASED_VM_EXEC_CONTROL,
+			CPU_BASED_VIRTUAL_INTR_PENDING);
 
 	kvm_make_request(KVM_REQ_EVENT, vcpu);
 
@@ -6408,12 +6398,8 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu)
 
 static int handle_nmi_window(struct kvm_vcpu *vcpu)
 {
-	u32 cpu_based_vm_exec_control;
-
-	/* clear pending NMI */
-	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
-	cpu_based_vm_exec_control &= ~CPU_BASED_VIRTUAL_NMI_PENDING;
-	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
+	vmcs_clear_bits(CPU_BASED_VM_EXEC_CONTROL,
+			CPU_BASED_VIRTUAL_NMI_PENDING);
 	++vcpu->stat.nmi_window_exits;
 	kvm_make_request(KVM_REQ_EVENT, vcpu);
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls
  2017-02-15 14:44 [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls Paolo Bonzini
@ 2017-02-16 16:24 ` Radim Krčmář
  2017-02-16 19:22 ` David Hildenbrand
  2017-02-17  0:04 ` Bandan Das
  2 siblings, 0 replies; 6+ messages in thread
From: Radim Krčmář @ 2017-02-16 16:24 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm

2017-02-15 15:44+0100, Paolo Bonzini:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Radim Krčmář <rkrcmar@redhat.com>

> ---
>  arch/x86/kvm/vmx.c | 30 ++++++++----------------------
>  1 file changed, 8 insertions(+), 22 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index bca60665d55d..0e0b5d09597e 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -5459,26 +5459,20 @@ static bool nested_exit_on_nmi(struct kvm_vcpu *vcpu)
>  
>  static void enable_irq_window(struct kvm_vcpu *vcpu)
>  {
> -	u32 cpu_based_vm_exec_control;
> -
> -	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
> -	cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_INTR_PENDING;
> -	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
> +	vmcs_set_bits(CPU_BASED_VM_EXEC_CONTROL,
> +		      CPU_BASED_VIRTUAL_INTR_PENDING);
>  }
>  
>  static void enable_nmi_window(struct kvm_vcpu *vcpu)
>  {
> -	u32 cpu_based_vm_exec_control;
> -
>  	if (!cpu_has_virtual_nmis() ||
>  	    vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & GUEST_INTR_STATE_STI) {
>  		enable_irq_window(vcpu);
>  		return;
>  	}
>  
> -	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
> -	cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_NMI_PENDING;
> -	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
> +	vmcs_set_bits(CPU_BASED_VM_EXEC_CONTROL,
> +		      CPU_BASED_VIRTUAL_NMI_PENDING);
>  }
>  
>  static void vmx_inject_irq(struct kvm_vcpu *vcpu)
> @@ -6137,12 +6131,8 @@ static int handle_tpr_below_threshold(struct kvm_vcpu *vcpu)
>  
>  static int handle_interrupt_window(struct kvm_vcpu *vcpu)
>  {
> -	u32 cpu_based_vm_exec_control;
> -
> -	/* clear pending irq */
> -	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
> -	cpu_based_vm_exec_control &= ~CPU_BASED_VIRTUAL_INTR_PENDING;
> -	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
> +	vmcs_clear_bits(CPU_BASED_VM_EXEC_CONTROL,
> +			CPU_BASED_VIRTUAL_INTR_PENDING);
>  
>  	kvm_make_request(KVM_REQ_EVENT, vcpu);
>  
> @@ -6408,12 +6398,8 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu)
>  
>  static int handle_nmi_window(struct kvm_vcpu *vcpu)
>  {
> -	u32 cpu_based_vm_exec_control;
> -
> -	/* clear pending NMI */
> -	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
> -	cpu_based_vm_exec_control &= ~CPU_BASED_VIRTUAL_NMI_PENDING;
> -	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
> +	vmcs_clear_bits(CPU_BASED_VM_EXEC_CONTROL,
> +			CPU_BASED_VIRTUAL_NMI_PENDING);
>  	++vcpu->stat.nmi_window_exits;
>  	kvm_make_request(KVM_REQ_EVENT, vcpu);
>  
> -- 
> 1.8.3.1
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls
  2017-02-15 14:44 [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls Paolo Bonzini
  2017-02-16 16:24 ` Radim Krčmář
@ 2017-02-16 19:22 ` David Hildenbrand
  2017-02-17  0:04 ` Bandan Das
  2 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand @ 2017-02-16 19:22 UTC (permalink / raw)
  To: Paolo Bonzini, linux-kernel, kvm

Am 15.02.2017 um 15:44 schrieb Paolo Bonzini:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/vmx.c | 30 ++++++++----------------------
>  1 file changed, 8 insertions(+), 22 deletions(-)
> 

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls
  2017-02-15 14:44 [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls Paolo Bonzini
  2017-02-16 16:24 ` Radim Krčmář
  2017-02-16 19:22 ` David Hildenbrand
@ 2017-02-17  0:04 ` Bandan Das
  2017-02-17  8:41   ` Paolo Bonzini
  2 siblings, 1 reply; 6+ messages in thread
From: Bandan Das @ 2017-02-17  0:04 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm

Paolo Bonzini <pbonzini@redhat.com> writes:

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---

I took a quick look and found these two potential
consumers of these set/clear wrappers.

vmcs_set_secondary_exec_control()
vmx_set_virtual_x2apic_mode()

Since this has been reviewed already, 
we can just have them later in a follow up
(unless you left them out intentionally).

Bandan

>  arch/x86/kvm/vmx.c | 30 ++++++++----------------------
>  1 file changed, 8 insertions(+), 22 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index bca60665d55d..0e0b5d09597e 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -5459,26 +5459,20 @@ static bool nested_exit_on_nmi(struct kvm_vcpu *vcpu)
>  
>  static void enable_irq_window(struct kvm_vcpu *vcpu)
>  {
> -	u32 cpu_based_vm_exec_control;
> -
> -	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
> -	cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_INTR_PENDING;
> -	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
> +	vmcs_set_bits(CPU_BASED_VM_EXEC_CONTROL,
> +		      CPU_BASED_VIRTUAL_INTR_PENDING);
>  }
>  
>  static void enable_nmi_window(struct kvm_vcpu *vcpu)
>  {
> -	u32 cpu_based_vm_exec_control;
> -
>  	if (!cpu_has_virtual_nmis() ||
>  	    vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & GUEST_INTR_STATE_STI) {
>  		enable_irq_window(vcpu);
>  		return;
>  	}
>  
> -	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
> -	cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_NMI_PENDING;
> -	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
> +	vmcs_set_bits(CPU_BASED_VM_EXEC_CONTROL,
> +		      CPU_BASED_VIRTUAL_NMI_PENDING);
>  }
>  
>  static void vmx_inject_irq(struct kvm_vcpu *vcpu)
> @@ -6137,12 +6131,8 @@ static int handle_tpr_below_threshold(struct kvm_vcpu *vcpu)
>  
>  static int handle_interrupt_window(struct kvm_vcpu *vcpu)
>  {
> -	u32 cpu_based_vm_exec_control;
> -
> -	/* clear pending irq */
> -	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
> -	cpu_based_vm_exec_control &= ~CPU_BASED_VIRTUAL_INTR_PENDING;
> -	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
> +	vmcs_clear_bits(CPU_BASED_VM_EXEC_CONTROL,
> +			CPU_BASED_VIRTUAL_INTR_PENDING);
>  
>  	kvm_make_request(KVM_REQ_EVENT, vcpu);
>  
> @@ -6408,12 +6398,8 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu)
>  
>  static int handle_nmi_window(struct kvm_vcpu *vcpu)
>  {
> -	u32 cpu_based_vm_exec_control;
> -
> -	/* clear pending NMI */
> -	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
> -	cpu_based_vm_exec_control &= ~CPU_BASED_VIRTUAL_NMI_PENDING;
> -	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
> +	vmcs_clear_bits(CPU_BASED_VM_EXEC_CONTROL,
> +			CPU_BASED_VIRTUAL_NMI_PENDING);
>  	++vcpu->stat.nmi_window_exits;
>  	kvm_make_request(KVM_REQ_EVENT, vcpu);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls
  2017-02-17  0:04 ` Bandan Das
@ 2017-02-17  8:41   ` Paolo Bonzini
  2017-02-17 17:22     ` Bandan Das
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2017-02-17  8:41 UTC (permalink / raw)
  To: Bandan Das; +Cc: linux-kernel, kvm



----- Original Message -----
> From: "Bandan Das" <bsd@redhat.com>
> To: "Paolo Bonzini" <pbonzini@redhat.com>
> Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
> Sent: Friday, February 17, 2017 1:04:14 AM
> Subject: Re: [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls
> 
> Paolo Bonzini <pbonzini@redhat.com> writes:
> 
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > ---
> 
> I took a quick look and found these two potential
> consumers of these set/clear wrappers.
> 
> vmcs_set_secondary_exec_control()
> vmx_set_virtual_x2apic_mode()
> 
> Since this has been reviewed already,
> we can just have them later in a follow up
> (unless you left them out intentionally).

Both of these can both set and clear bits, so they could be the
consumer of a new function

void vmcs_write_bits(u16 field, u32 value, u32 mask)

but I don't see much benefit in introducing it; the cognitive
load is higher than vmcs_{set,clear}_bits.

Paolo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls
  2017-02-17  8:41   ` Paolo Bonzini
@ 2017-02-17 17:22     ` Bandan Das
  0 siblings, 0 replies; 6+ messages in thread
From: Bandan Das @ 2017-02-17 17:22 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm

Paolo Bonzini <pbonzini@redhat.com> writes:

> ----- Original Message -----
>> From: "Bandan Das" <bsd@redhat.com>
>> To: "Paolo Bonzini" <pbonzini@redhat.com>
>> Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
>> Sent: Friday, February 17, 2017 1:04:14 AM
>> Subject: Re: [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls
>> 
>> Paolo Bonzini <pbonzini@redhat.com> writes:
>> 
>> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> > ---
>> 
>> I took a quick look and found these two potential
>> consumers of these set/clear wrappers.
>> 
>> vmcs_set_secondary_exec_control()
>> vmx_set_virtual_x2apic_mode()
>> 
>> Since this has been reviewed already,
>> we can just have them later in a follow up
>> (unless you left them out intentionally).
>
> Both of these can both set and clear bits, so they could be the
> consumer of a new function
>
> void vmcs_write_bits(u16 field, u32 value, u32 mask)
>
> but I don't see much benefit in introducing it; the cognitive
> load is higher than vmcs_{set,clear}_bits.

Yes, agreed. Thanks!

> Paolo

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-02-17 17:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-15 14:44 [PATCH] KVM: VMX: use vmcs_set/clear_bits for CPU-based execution controls Paolo Bonzini
2017-02-16 16:24 ` Radim Krčmář
2017-02-16 19:22 ` David Hildenbrand
2017-02-17  0:04 ` Bandan Das
2017-02-17  8:41   ` Paolo Bonzini
2017-02-17 17:22     ` Bandan Das

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.