public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Haiwei Li <lihaiwei.kernel@gmail.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: pbonzini@redhat.com, sean.j.christopherson@intel.com,
	vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com,
	joro@8bytes.org, Haiwei Li <lihaiwei@tencent.com>
Subject: Re: [PATCH v2] KVM: x86: Add tracepoint for dr_write/dr_read
Date: Fri, 6 Nov 2020 08:31:54 +0800	[thread overview]
Message-ID: <eb80c1e1-152c-0bad-562d-ff07ed9685ea@gmail.com> (raw)
In-Reply-To: <20201009032130.6774-1-lihaiwei.kernel@gmail.com>

Kindly ping. :)

On 20/10/9 11:21, lihaiwei.kernel@gmail.com wrote:
> From: Haiwei Li <lihaiwei@tencent.com>
> 
> When vmexit occurs caused by accessing dr, there is no tracepoint to track
> this action. Add tracepoint for this on x86 kvm.
> 
> Signed-off-by: Haiwei Li <lihaiwei@tencent.com>
> ---
> v1 -> v2:
>   * Improve the changelog
> 
>   arch/x86/kvm/svm/svm.c |  2 ++
>   arch/x86/kvm/trace.h   | 27 +++++++++++++++++++++++++++
>   arch/x86/kvm/vmx/vmx.c | 10 ++++++++--
>   arch/x86/kvm/x86.c     |  1 +
>   4 files changed, 38 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 4f401fc6a05d..52c69551aea4 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -2423,12 +2423,14 @@ static int dr_interception(struct vcpu_svm *svm)
>   		if (!kvm_require_dr(&svm->vcpu, dr - 16))
>   			return 1;
>   		val = kvm_register_read(&svm->vcpu, reg);
> +		trace_kvm_dr_write(dr - 16, val);
>   		kvm_set_dr(&svm->vcpu, dr - 16, val);
>   	} else {
>   		if (!kvm_require_dr(&svm->vcpu, dr))
>   			return 1;
>   		kvm_get_dr(&svm->vcpu, dr, &val);
>   		kvm_register_write(&svm->vcpu, reg, val);
> +		trace_kvm_dr_read(dr, val);
>   	}
>   
>   	return kvm_skip_emulated_instruction(&svm->vcpu);
> diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
> index aef960f90f26..b3bf54405862 100644
> --- a/arch/x86/kvm/trace.h
> +++ b/arch/x86/kvm/trace.h
> @@ -405,6 +405,33 @@ TRACE_EVENT(kvm_cr,
>   #define trace_kvm_cr_read(cr, val)		trace_kvm_cr(0, cr, val)
>   #define trace_kvm_cr_write(cr, val)		trace_kvm_cr(1, cr, val)
>   
> +/*
> + * Tracepoint for guest DR access.
> + */
> +TRACE_EVENT(kvm_dr,
> +	TP_PROTO(unsigned int rw, unsigned int dr, unsigned long val),
> +	TP_ARGS(rw, dr, val),
> +
> +	TP_STRUCT__entry(
> +		__field(	unsigned int,	rw		)
> +		__field(	unsigned int,	dr		)
> +		__field(	unsigned long,	val		)
> +	),
> +
> +	TP_fast_assign(
> +		__entry->rw		= rw;
> +		__entry->dr		= dr;
> +		__entry->val		= val;
> +	),
> +
> +	TP_printk("dr_%s %x = 0x%lx",
> +		  __entry->rw ? "write" : "read",
> +		  __entry->dr, __entry->val)
> +);
> +
> +#define trace_kvm_dr_read(dr, val)		trace_kvm_dr(0, dr, val)
> +#define trace_kvm_dr_write(dr, val)		trace_kvm_dr(1, dr, val)
> +
>   TRACE_EVENT(kvm_pic_set_irq,
>   	    TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
>   	    TP_ARGS(chip, pin, elcr, imr, coalesced),
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 4551a7e80ebc..f78fd297d51e 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -5091,10 +5091,16 @@ static int handle_dr(struct kvm_vcpu *vcpu)
>   
>   		if (kvm_get_dr(vcpu, dr, &val))
>   			return 1;
> +		trace_kvm_dr_read(dr, val);
>   		kvm_register_write(vcpu, reg, val);
> -	} else
> -		if (kvm_set_dr(vcpu, dr, kvm_register_readl(vcpu, reg)))
> +	} else {
> +		unsigned long val;
> +
> +		val = kvm_register_readl(vcpu, reg);
> +		trace_kvm_dr_write(dr, val);
> +		if (kvm_set_dr(vcpu, dr, val))
>   			return 1;
> +	}
>   
>   	return kvm_skip_emulated_instruction(vcpu);
>   }
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index c4015a43cc8a..68cb7b331324 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -11153,6 +11153,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_inj_virq);
>   EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_page_fault);
>   EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_msr);
>   EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_cr);
> +EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_dr);
>   EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_nested_vmrun);
>   EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_nested_vmexit);
>   EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_nested_vmexit_inject);
> 

      parent reply	other threads:[~2020-11-06  0:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-09  3:21 [PATCH v2] KVM: x86: Add tracepoint for dr_write/dr_read lihaiwei.kernel
2020-10-22  0:43 ` Haiwei Li
2020-11-06  0:31 ` Haiwei Li [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb80c1e1-152c-0bad-562d-ff07ed9685ea@gmail.com \
    --to=lihaiwei.kernel@gmail.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=lihaiwei@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox