All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Peter Xu <peterx@redhat.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
	Wanpeng Li <kernellwp@gmail.com>,
	Krish Sadhukhan <krish.sadhukhan@oracle.com>
Subject: Re: [PATCH v2 1/3] KVM: X86: Trace vcpu_id for vmexit
Date: Thu, 5 Sep 2019 08:56:54 -0700	[thread overview]
Message-ID: <20190905155654.GA29019@linux.intel.com> (raw)
In-Reply-To: <20190905021515.GD31707@xz-x1>

On Thu, Sep 05, 2019 at 10:15:15AM +0800, Peter Xu wrote:
> On Wed, Sep 04, 2019 at 10:26:58AM -0700, Sean Christopherson wrote:
> > On Thu, Aug 15, 2019 at 06:34:56PM +0800, Peter Xu wrote:
> > > Tracing the ID helps to pair vmenters and vmexits for guests with
> > > multiple vCPUs.
> > > 
> > > Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> > > Signed-off-by: Peter Xu <peterx@redhat.com>
> > > ---
> > >  arch/x86/kvm/trace.h | 5 ++++-
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
> > > index b5c831e79094..c682f3f7f998 100644
> > > --- a/arch/x86/kvm/trace.h
> > > +++ b/arch/x86/kvm/trace.h
> > > @@ -232,17 +232,20 @@ TRACE_EVENT(kvm_exit,
> > >  		__field(	u32,	        isa             )
> > >  		__field(	u64,	        info1           )
> > >  		__field(	u64,	        info2           )
> > > +		__field(	int,	        vcpu_id         )
> > 
> > It doesn't actually affect anything, but vcpu_id is stored and printed as
> > an 'unsigned int' everywhere else in the trace code.  Stylistically I like
> > that approach even though struct kvm_vcpu holds it as a signed int.
> 
> True.  I can switch to unsigned int to get aligned with the rest if
> there's other comment to address.  Though from codebase-wise I would
> even prefer signed because it gives us a chance to set an invalid vcpu
> id (-1) where necessary, or notice something severly wrong when <-1.

I agree that a signed int makes sense for flows like kvm_get_vcpu_by_id(),
where the incoming id isn't sanitized.  But for struct kvm_vcpu, a negative 
vcpu_id is simply impossible, e.g. vcpu_id is set to a postive (and capped)
value as part of the core vcpu initialization and is never changed.  I
prefer storing an unsigned val in the tracing as it communicates that
vcpu_id is always valid.  I suspect struct kvm_vcpu uses a signed int
purely to avoid having to constantly cast it to an int.

> After all it should far cover our usage (IIUC max vcpu id should be
> 512 cross archs).

  reply	other threads:[~2019-09-05 15:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-15 10:34 [PATCH v2 0/3] KVM: X86: Some tracepoint enhancements Peter Xu
2019-08-15 10:34 ` [PATCH v2 1/3] KVM: X86: Trace vcpu_id for vmexit Peter Xu
2019-09-04 17:26   ` Sean Christopherson
2019-09-05  2:15     ` Peter Xu
2019-09-05 15:56       ` Sean Christopherson [this message]
2019-08-15 10:34 ` [PATCH v2 2/3] KVM: X86: Remove tailing newline for tracepoints Peter Xu
2019-09-04 17:27   ` Sean Christopherson
2019-08-15 10:34 ` [PATCH v2 3/3] KVM: X86: Tune PLE Window tracepoint Peter Xu
2019-09-04 17:32   ` Sean Christopherson
2019-09-05  2:25     ` Peter Xu

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=20190905155654.GA29019@linux.intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=kernellwp@gmail.com \
    --cc=krish.sadhukhan@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.