diff mbox series

[v2,03/13] KVM: x86: Move emulation-only helpers to emulate.c

Message ID 20200218232953.5724-4-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86: Allow userspace to disable the emulator | expand

Commit Message

Sean Christopherson Feb. 18, 2020, 11:29 p.m. UTC
Move ctxt_virt_addr_bits() and emul_is_noncanonical_address() from x86.h
to emulate.c.  This eliminates all references to struct x86_emulate_ctxt
from x86.h, and sets the stage for a future patch to stop including
kvm_emulate.h in asm/kvm_host.h.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/emulate.c | 11 +++++++++++
 arch/x86/kvm/x86.h     | 11 -----------
 2 files changed, 11 insertions(+), 11 deletions(-)

Comments

Vitaly Kuznetsov Feb. 26, 2020, 3:23 p.m. UTC | #1
Sean Christopherson <sean.j.christopherson@intel.com> writes:

> Move ctxt_virt_addr_bits() and emul_is_noncanonical_address() from x86.h
> to emulate.c.  This eliminates all references to struct x86_emulate_ctxt
> from x86.h, and sets the stage for a future patch to stop including
> kvm_emulate.h in asm/kvm_host.h.
>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>  arch/x86/kvm/emulate.c | 11 +++++++++++
>  arch/x86/kvm/x86.h     | 11 -----------
>  2 files changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index ddbc61984227..1e394cb190ce 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -673,6 +673,17 @@ static void set_segment_selector(struct x86_emulate_ctxt *ctxt, u16 selector,
>  	ctxt->ops->set_segment(ctxt, selector, &desc, base3, seg);
>  }
>  
> +static inline u8 ctxt_virt_addr_bits(struct x86_emulate_ctxt *ctxt)
> +{
> +	return (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_LA57) ? 57 : 48;
> +}
> +
> +static inline bool emul_is_noncanonical_address(u64 la,
> +						struct x86_emulate_ctxt *ctxt)
> +{
> +	return get_canonical(la, ctxt_virt_addr_bits(ctxt)) != la;
> +}
> +
>  /*
>   * x86 defines three classes of vector instructions: explicitly
>   * aligned, explicitly unaligned, and the rest, which change behaviour
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 3624665acee4..8409842a25d9 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -149,11 +149,6 @@ static inline u8 vcpu_virt_addr_bits(struct kvm_vcpu *vcpu)
>  	return kvm_read_cr4_bits(vcpu, X86_CR4_LA57) ? 57 : 48;
>  }
>  
> -static inline u8 ctxt_virt_addr_bits(struct x86_emulate_ctxt *ctxt)
> -{
> -	return (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_LA57) ? 57 : 48;
> -}
> -
>  static inline u64 get_canonical(u64 la, u8 vaddr_bits)
>  {
>  	return ((int64_t)la << (64 - vaddr_bits)) >> (64 - vaddr_bits);
> @@ -164,12 +159,6 @@ static inline bool is_noncanonical_address(u64 la, struct kvm_vcpu *vcpu)
>  	return get_canonical(la, vcpu_virt_addr_bits(vcpu)) != la;
>  }
>  
> -static inline bool emul_is_noncanonical_address(u64 la,
> -						struct x86_emulate_ctxt *ctxt)
> -{
> -	return get_canonical(la, ctxt_virt_addr_bits(ctxt)) != la;
> -}
> -
>  static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu,
>  					gva_t gva, gfn_t gfn, unsigned access)
>  {

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
diff mbox series

Patch

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index ddbc61984227..1e394cb190ce 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -673,6 +673,17 @@  static void set_segment_selector(struct x86_emulate_ctxt *ctxt, u16 selector,
 	ctxt->ops->set_segment(ctxt, selector, &desc, base3, seg);
 }
 
+static inline u8 ctxt_virt_addr_bits(struct x86_emulate_ctxt *ctxt)
+{
+	return (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_LA57) ? 57 : 48;
+}
+
+static inline bool emul_is_noncanonical_address(u64 la,
+						struct x86_emulate_ctxt *ctxt)
+{
+	return get_canonical(la, ctxt_virt_addr_bits(ctxt)) != la;
+}
+
 /*
  * x86 defines three classes of vector instructions: explicitly
  * aligned, explicitly unaligned, and the rest, which change behaviour
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 3624665acee4..8409842a25d9 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -149,11 +149,6 @@  static inline u8 vcpu_virt_addr_bits(struct kvm_vcpu *vcpu)
 	return kvm_read_cr4_bits(vcpu, X86_CR4_LA57) ? 57 : 48;
 }
 
-static inline u8 ctxt_virt_addr_bits(struct x86_emulate_ctxt *ctxt)
-{
-	return (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_LA57) ? 57 : 48;
-}
-
 static inline u64 get_canonical(u64 la, u8 vaddr_bits)
 {
 	return ((int64_t)la << (64 - vaddr_bits)) >> (64 - vaddr_bits);
@@ -164,12 +159,6 @@  static inline bool is_noncanonical_address(u64 la, struct kvm_vcpu *vcpu)
 	return get_canonical(la, vcpu_virt_addr_bits(vcpu)) != la;
 }
 
-static inline bool emul_is_noncanonical_address(u64 la,
-						struct x86_emulate_ctxt *ctxt)
-{
-	return get_canonical(la, ctxt_virt_addr_bits(ctxt)) != la;
-}
-
 static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu,
 					gva_t gva, gfn_t gfn, unsigned access)
 {