diff mbox series

[2/2,Bionic] KVM: x86: SVM: Set EMULTYPE_NO_REEXECUTE for RSM emulation

Message ID 20190829170658.16739-2-rafaeldtinoco@ubuntu.com
State New
Headers show
Series None | expand

Commit Message

Rafael David Tinoco Aug. 29, 2019, 5:06 p.m. UTC
From: Sean Christopherson <sean.j.christopherson@intel.com>

BugLink: https://bugs.launchpad.net/bugs/1834522

Re-execution after an emulation decode failure is only intended to
handle a case where two or vCPUs race to write a shadowed page, i.e.
we should never re-execute an instruction as part of RSM emulation.

Add a new helper, kvm_emulate_instruction_from_buffer(), to support
emulating from a pre-defined buffer.  This eliminates the last direct
call to x86_emulate_instruction() outside of kvm_mmu_page_fault(),
which means x86_emulate_instruction() can be unexported in a future
patch.

Fixes: 7607b7174405 ("KVM: SVM: install RSM intercept")
Cc: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: stable@vger.kernel.org
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
(cherry-picked from 35be0aded76b54a24dc8aa678a71bca22273e8d8)
Signed-off-by: Rafael David Tinoco <rafaeldtinoco@ubuntu.com>

---
 arch/x86/include/asm/kvm_host.h | 7 +++++++
 arch/x86/kvm/svm.c              | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

Comments

Thadeu Lima de Souza Cascardo Aug. 30, 2019, 11:34 a.m. UTC | #1
On Thu, Aug 29, 2019 at 02:06:58PM -0300, Rafael David Tinoco wrote:
> From: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1834522
> 
> Re-execution after an emulation decode failure is only intended to
> handle a case where two or vCPUs race to write a shadowed page, i.e.
> we should never re-execute an instruction as part of RSM emulation.
> 
> Add a new helper, kvm_emulate_instruction_from_buffer(), to support
> emulating from a pre-defined buffer.  This eliminates the last direct
> call to x86_emulate_instruction() outside of kvm_mmu_page_fault(),
> which means x86_emulate_instruction() can be unexported in a future
> patch.
> 
> Fixes: 7607b7174405 ("KVM: SVM: install RSM intercept")
> Cc: Brijesh Singh <brijesh.singh@amd.com>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
> (cherry-picked from 35be0aded76b54a24dc8aa678a71bca22273e8d8)
> Signed-off-by: Rafael David Tinoco <rafaeldtinoco@ubuntu.com>

Acking just in case the ACK for patch 1 is missed as an ACK for patch 2 as
well.

Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>

> 
> ---
>  arch/x86/include/asm/kvm_host.h | 7 +++++++
>  arch/x86/kvm/svm.c              | 4 ++--
>  2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index c2bb7da8e5b4..836426e6fd9b 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1189,6 +1189,13 @@ static inline int emulate_instruction(struct kvm_vcpu *vcpu,
>  			emulation_type | EMULTYPE_NO_REEXECUTE, NULL, 0);
>  }
>  
> +static inline int kvm_emulate_instruction_from_buffer(struct kvm_vcpu *vcpu,
> +						      void *insn, int insn_len)
> +{
> +	return x86_emulate_instruction(vcpu, 0, EMULTYPE_NO_REEXECUTE,
> +				       insn, insn_len);
> +}
> +
>  void kvm_enable_efer_bits(u64);
>  bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
>  int kvm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr);
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 538ca5446cfd..235e5181e1a0 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -3446,8 +3446,8 @@ static int emulate_on_interception(struct vcpu_svm *svm)
>  
>  static int rsm_interception(struct vcpu_svm *svm)
>  {
> -	return x86_emulate_instruction(&svm->vcpu, 0, 0,
> -				       rsm_ins_bytes, 2) == EMULATE_DONE;
> +	return kvm_emulate_instruction_from_buffer(&svm->vcpu,
> +					rsm_ins_bytes, 2) == EMULATE_DONE;
>  }
>  
>  static int rdpmc_interception(struct vcpu_svm *svm)
> -- 
> 2.17.1
> 
> 
> -- 
> kernel-team mailing list
> kernel-team@lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team
Khalid Elmously Sept. 3, 2019, 5:30 a.m. UTC | #2
On 2019-08-29 14:06:58 , Rafael David Tinoco wrote:
> From: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1834522
> 
> Re-execution after an emulation decode failure is only intended to
> handle a case where two or vCPUs race to write a shadowed page, i.e.
> we should never re-execute an instruction as part of RSM emulation.
> 
> Add a new helper, kvm_emulate_instruction_from_buffer(), to support
> emulating from a pre-defined buffer.  This eliminates the last direct
> call to x86_emulate_instruction() outside of kvm_mmu_page_fault(),
> which means x86_emulate_instruction() can be unexported in a future
> patch.
> 
> Fixes: 7607b7174405 ("KVM: SVM: install RSM intercept")
> Cc: Brijesh Singh <brijesh.singh@amd.com>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
> (cherry-picked from 35be0aded76b54a24dc8aa678a71bca22273e8d8)
> Signed-off-by: Rafael David Tinoco <rafaeldtinoco@ubuntu.com>
> 
> ---
>  arch/x86/include/asm/kvm_host.h | 7 +++++++
>  arch/x86/kvm/svm.c              | 4 ++--
>  2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index c2bb7da8e5b4..836426e6fd9b 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1189,6 +1189,13 @@ static inline int emulate_instruction(struct kvm_vcpu *vcpu,
>  			emulation_type | EMULTYPE_NO_REEXECUTE, NULL, 0);
>  }
>  
> +static inline int kvm_emulate_instruction_from_buffer(struct kvm_vcpu *vcpu,
> +						      void *insn, int insn_len)
> +{
> +	return x86_emulate_instruction(vcpu, 0, EMULTYPE_NO_REEXECUTE,
> +				       insn, insn_len);
> +}
> +
>  void kvm_enable_efer_bits(u64);
>  bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
>  int kvm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr);
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 538ca5446cfd..235e5181e1a0 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -3446,8 +3446,8 @@ static int emulate_on_interception(struct vcpu_svm *svm)
>  
>  static int rsm_interception(struct vcpu_svm *svm)
>  {
> -	return x86_emulate_instruction(&svm->vcpu, 0, 0,
> -				       rsm_ins_bytes, 2) == EMULATE_DONE;
> +	return kvm_emulate_instruction_from_buffer(&svm->vcpu,
> +					rsm_ins_bytes, 2) == EMULATE_DONE;
>  }
>  
>  static int rdpmc_interception(struct vcpu_svm *svm)
> -- 
> 2.17.1
> 
> 
> -- 
> kernel-team mailing list
> kernel-team@lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team
diff mbox series

Patch

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index c2bb7da8e5b4..836426e6fd9b 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1189,6 +1189,13 @@  static inline int emulate_instruction(struct kvm_vcpu *vcpu,
 			emulation_type | EMULTYPE_NO_REEXECUTE, NULL, 0);
 }
 
+static inline int kvm_emulate_instruction_from_buffer(struct kvm_vcpu *vcpu,
+						      void *insn, int insn_len)
+{
+	return x86_emulate_instruction(vcpu, 0, EMULTYPE_NO_REEXECUTE,
+				       insn, insn_len);
+}
+
 void kvm_enable_efer_bits(u64);
 bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
 int kvm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr);
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 538ca5446cfd..235e5181e1a0 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -3446,8 +3446,8 @@  static int emulate_on_interception(struct vcpu_svm *svm)
 
 static int rsm_interception(struct vcpu_svm *svm)
 {
-	return x86_emulate_instruction(&svm->vcpu, 0, 0,
-				       rsm_ins_bytes, 2) == EMULATE_DONE;
+	return kvm_emulate_instruction_from_buffer(&svm->vcpu,
+					rsm_ins_bytes, 2) == EMULATE_DONE;
 }
 
 static int rdpmc_interception(struct vcpu_svm *svm)