kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: X86: Use kvm_get_linear_rip() in single-step and #DB/#BP interception
@ 2021-05-26  6:38 Yuan Yao
  2021-05-26 14:52 ` Sean Christopherson
  2021-05-27 13:08 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Yuan Yao @ 2021-05-26  6:38 UTC (permalink / raw)
  To: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel, kvm
  Cc: Yuan Yao

From: Yuan Yao <yuan.yao@intel.com>

The kvm_get_linear_rip() handles x86/long mode cases well and has
better readability, __kvm_set_rflags() also use the paired
fucntion kvm_is_linear_rip() to check the vcpu->arch.singlestep_rip
set in kvm_arch_vcpu_ioctl_set_guest_debug(), so change the
"CS.BASE + RIP" code in kvm_arch_vcpu_ioctl_set_guest_debug() and
handle_exception_nmi() to this one.

Signed-off-by: Yuan Yao <yuan.yao@intel.com>

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 4bceb5ca3a89..0db05cfbe434 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -4843,7 +4843,7 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
 	struct kvm_run *kvm_run = vcpu->run;
 	u32 intr_info, ex_no, error_code;
-	unsigned long cr2, rip, dr6;
+	unsigned long cr2, dr6;
 	u32 vect_info;
 
 	vect_info = vmx->idt_vectoring_info;
@@ -4933,8 +4933,7 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
 		vmx->vcpu.arch.event_exit_inst_len =
 			vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
 		kvm_run->exit_reason = KVM_EXIT_DEBUG;
-		rip = kvm_rip_read(vcpu);
-		kvm_run->debug.arch.pc = vmcs_readl(GUEST_CS_BASE) + rip;
+		kvm_run->debug.arch.pc = kvm_get_linear_rip(vcpu);
 		kvm_run->debug.arch.exception = ex_no;
 		break;
 	case AC_VECTOR:
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 9b6bca616929..5cac5d883710 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10115,8 +10115,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 	kvm_update_dr7(vcpu);
 
 	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
-		vcpu->arch.singlestep_rip = kvm_rip_read(vcpu) +
-			get_segment_base(vcpu, VCPU_SREG_CS);
+		vcpu->arch.singlestep_rip = kvm_get_linear_rip(vcpu);
 
 	/*
 	 * Trigger an rflags update that will inject or remove the trace
-- 
2.17.1


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

* Re: [PATCH] KVM: X86: Use kvm_get_linear_rip() in single-step and #DB/#BP interception
  2021-05-26  6:38 [PATCH] KVM: X86: Use kvm_get_linear_rip() in single-step and #DB/#BP interception Yuan Yao
@ 2021-05-26 14:52 ` Sean Christopherson
  2021-05-27  0:49   ` Yuan Yao
  2021-05-27 13:08 ` Paolo Bonzini
  1 sibling, 1 reply; 4+ messages in thread
From: Sean Christopherson @ 2021-05-26 14:52 UTC (permalink / raw)
  To: Yuan Yao
  Cc: Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, Yuan Yao

On Wed, May 26, 2021, Yuan Yao wrote:
> From: Yuan Yao <yuan.yao@intel.com>
> 
> The kvm_get_linear_rip() handles x86/long mode cases well and has
> better readability, __kvm_set_rflags() also use the paired
> fucntion kvm_is_linear_rip() to check the vcpu->arch.singlestep_rip
  ^^^^^^^^
  function

Please run checkpatch before submitting in the future, it will catch some of
these misspellings.

> set in kvm_arch_vcpu_ioctl_set_guest_debug(), so change the
> "CS.BASE + RIP" code in kvm_arch_vcpu_ioctl_set_guest_debug() and
> handle_exception_nmi() to this one.
> 
> Signed-off-by: Yuan Yao <yuan.yao@intel.com>

Reviewed-by: Sean Christopherson <seanjc@google.com>

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

* Re: [PATCH] KVM: X86: Use kvm_get_linear_rip() in single-step and #DB/#BP interception
  2021-05-26 14:52 ` Sean Christopherson
@ 2021-05-27  0:49   ` Yuan Yao
  0 siblings, 0 replies; 4+ messages in thread
From: Yuan Yao @ 2021-05-27  0:49 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, Yuan Yao

On Wed, May 26, 2021 at 02:52:33PM +0000, Sean Christopherson wrote:
> On Wed, May 26, 2021, Yuan Yao wrote:
> > From: Yuan Yao <yuan.yao@intel.com>
> > 
> > The kvm_get_linear_rip() handles x86/long mode cases well and has
> > better readability, __kvm_set_rflags() also use the paired
> > fucntion kvm_is_linear_rip() to check the vcpu->arch.singlestep_rip
>   ^^^^^^^^
>   function
> 
> Please run checkpatch before submitting in the future, it will catch some of
> these misspellings.

Sorry for this mistake, I will take care next time.

> 
> > set in kvm_arch_vcpu_ioctl_set_guest_debug(), so change the
> > "CS.BASE + RIP" code in kvm_arch_vcpu_ioctl_set_guest_debug() and
> > handle_exception_nmi() to this one.
> > 
> > Signed-off-by: Yuan Yao <yuan.yao@intel.com>
> 
> Reviewed-by: Sean Christopherson <seanjc@google.com>

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

* Re: [PATCH] KVM: X86: Use kvm_get_linear_rip() in single-step and #DB/#BP interception
  2021-05-26  6:38 [PATCH] KVM: X86: Use kvm_get_linear_rip() in single-step and #DB/#BP interception Yuan Yao
  2021-05-26 14:52 ` Sean Christopherson
@ 2021-05-27 13:08 ` Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2021-05-27 13:08 UTC (permalink / raw)
  To: Yuan Yao, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel, kvm
  Cc: Yuan Yao

On 26/05/21 08:38, Yuan Yao wrote:
> From: Yuan Yao <yuan.yao@intel.com>
> 
> The kvm_get_linear_rip() handles x86/long mode cases well and has
> better readability, __kvm_set_rflags() also use the paired
> fucntion kvm_is_linear_rip() to check the vcpu->arch.singlestep_rip
> set in kvm_arch_vcpu_ioctl_set_guest_debug(), so change the
> "CS.BASE + RIP" code in kvm_arch_vcpu_ioctl_set_guest_debug() and
> handle_exception_nmi() to this one.
> 
> Signed-off-by: Yuan Yao <yuan.yao@intel.com>
> 
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 4bceb5ca3a89..0db05cfbe434 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -4843,7 +4843,7 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
>   	struct vcpu_vmx *vmx = to_vmx(vcpu);
>   	struct kvm_run *kvm_run = vcpu->run;
>   	u32 intr_info, ex_no, error_code;
> -	unsigned long cr2, rip, dr6;
> +	unsigned long cr2, dr6;
>   	u32 vect_info;
>   
>   	vect_info = vmx->idt_vectoring_info;
> @@ -4933,8 +4933,7 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
>   		vmx->vcpu.arch.event_exit_inst_len =
>   			vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
>   		kvm_run->exit_reason = KVM_EXIT_DEBUG;
> -		rip = kvm_rip_read(vcpu);
> -		kvm_run->debug.arch.pc = vmcs_readl(GUEST_CS_BASE) + rip;
> +		kvm_run->debug.arch.pc = kvm_get_linear_rip(vcpu);
>   		kvm_run->debug.arch.exception = ex_no;
>   		break;
>   	case AC_VECTOR:
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 9b6bca616929..5cac5d883710 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -10115,8 +10115,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
>   	kvm_update_dr7(vcpu);
>   
>   	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
> -		vcpu->arch.singlestep_rip = kvm_rip_read(vcpu) +
> -			get_segment_base(vcpu, VCPU_SREG_CS);
> +		vcpu->arch.singlestep_rip = kvm_get_linear_rip(vcpu);
>   
>   	/*
>   	 * Trigger an rflags update that will inject or remove the trace
> 

Queued, thanks.

Paolo


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

end of thread, other threads:[~2021-05-27 13:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-26  6:38 [PATCH] KVM: X86: Use kvm_get_linear_rip() in single-step and #DB/#BP interception Yuan Yao
2021-05-26 14:52 ` Sean Christopherson
2021-05-27  0:49   ` Yuan Yao
2021-05-27 13:08 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).