diff mbox series

[RFC,v2,63/69] KVM: VMX: Move .get_interrupt_shadow() implementation to common VMX code

Message ID 11a3389da6184785b238b0d5a7f60279aa0a93b1.1625186503.git.isaku.yamahata@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM: X86: TDX support | expand

Commit Message

Isaku Yamahata July 2, 2021, 10:05 p.m. UTC
From: Sean Christopherson <sean.j.christopherson@intel.com>

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
 arch/x86/kvm/vmx/common.h | 14 ++++++++++++++
 arch/x86/kvm/vmx/vmx.c    | 10 +---------
 2 files changed, 15 insertions(+), 9 deletions(-)

Comments

Paolo Bonzini July 6, 2021, 2:17 p.m. UTC | #1
On 03/07/21 00:05, isaku.yamahata@intel.com wrote:
> From: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
> ---
>   arch/x86/kvm/vmx/common.h | 14 ++++++++++++++
>   arch/x86/kvm/vmx/vmx.c    | 10 +---------
>   2 files changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx/common.h b/arch/x86/kvm/vmx/common.h
> index 755aaec85199..817ff3e74933 100644
> --- a/arch/x86/kvm/vmx/common.h
> +++ b/arch/x86/kvm/vmx/common.h
> @@ -120,6 +120,20 @@ static inline int __vmx_handle_ept_violation(struct kvm_vcpu *vcpu, gpa_t gpa,
>   	return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0);
>   }
>   
> +static inline u32 __vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu)
> +{
> +	u32 interruptibility;
> +	int ret = 0;
> +
> +	interruptibility = vmread32(vcpu, GUEST_INTERRUPTIBILITY_INFO);
> +	if (interruptibility & GUEST_INTR_STATE_STI)
> +		ret |= KVM_X86_SHADOW_INT_STI;
> +	if (interruptibility & GUEST_INTR_STATE_MOV_SS)
> +		ret |= KVM_X86_SHADOW_INT_MOV_SS;
> +
> +	return ret;
> +}
> +
>   static inline u32 vmx_encode_ar_bytes(struct kvm_segment *var)
>   {
>   	u32 ar;
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index d69d4dc7c071..d31cace67907 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -1467,15 +1467,7 @@ void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
>   
>   u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu)
>   {
> -	u32 interruptibility = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO);
> -	int ret = 0;
> -
> -	if (interruptibility & GUEST_INTR_STATE_STI)
> -		ret |= KVM_X86_SHADOW_INT_STI;
> -	if (interruptibility & GUEST_INTR_STATE_MOV_SS)
> -		ret |= KVM_X86_SHADOW_INT_MOV_SS;
> -
> -	return ret;
> +	return __vmx_get_interrupt_shadow(vcpu);
>   }
>   
>   void vmx_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
> 

Is there any reason to add the __ version, since at this point 
kvm_x86_ops is already pointing to vt_get_interrupt_shadow?

Paolo
Sean Christopherson July 13, 2021, 8:45 p.m. UTC | #2
On Tue, Jul 06, 2021, Paolo Bonzini wrote:
> On 03/07/21 00:05, isaku.yamahata@intel.com wrote:
> > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> > index d69d4dc7c071..d31cace67907 100644
> > --- a/arch/x86/kvm/vmx/vmx.c
> > +++ b/arch/x86/kvm/vmx/vmx.c
> > @@ -1467,15 +1467,7 @@ void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
> >   u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu)
> >   {
> > -	u32 interruptibility = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO);
> > -	int ret = 0;
> > -
> > -	if (interruptibility & GUEST_INTR_STATE_STI)
> > -		ret |= KVM_X86_SHADOW_INT_STI;
> > -	if (interruptibility & GUEST_INTR_STATE_MOV_SS)
> > -		ret |= KVM_X86_SHADOW_INT_MOV_SS;
> > -
> > -	return ret;
> > +	return __vmx_get_interrupt_shadow(vcpu);
> >   }
> >   void vmx_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
> > 
> 
> Is there any reason to add the __ version, since at this point kvm_x86_ops
> is already pointing to vt_get_interrupt_shadow?

Yeah, no idea what I was thinking, the whole thing can be moved as is, just need
to delete the prototype in vmx.h.
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx/common.h b/arch/x86/kvm/vmx/common.h
index 755aaec85199..817ff3e74933 100644
--- a/arch/x86/kvm/vmx/common.h
+++ b/arch/x86/kvm/vmx/common.h
@@ -120,6 +120,20 @@  static inline int __vmx_handle_ept_violation(struct kvm_vcpu *vcpu, gpa_t gpa,
 	return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0);
 }
 
+static inline u32 __vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu)
+{
+	u32 interruptibility;
+	int ret = 0;
+
+	interruptibility = vmread32(vcpu, GUEST_INTERRUPTIBILITY_INFO);
+	if (interruptibility & GUEST_INTR_STATE_STI)
+		ret |= KVM_X86_SHADOW_INT_STI;
+	if (interruptibility & GUEST_INTR_STATE_MOV_SS)
+		ret |= KVM_X86_SHADOW_INT_MOV_SS;
+
+	return ret;
+}
+
 static inline u32 vmx_encode_ar_bytes(struct kvm_segment *var)
 {
 	u32 ar;
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index d69d4dc7c071..d31cace67907 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -1467,15 +1467,7 @@  void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
 
 u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu)
 {
-	u32 interruptibility = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO);
-	int ret = 0;
-
-	if (interruptibility & GUEST_INTR_STATE_STI)
-		ret |= KVM_X86_SHADOW_INT_STI;
-	if (interruptibility & GUEST_INTR_STATE_MOV_SS)
-		ret |= KVM_X86_SHADOW_INT_MOV_SS;
-
-	return ret;
+	return __vmx_get_interrupt_shadow(vcpu);
 }
 
 void vmx_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)