Re: [PATCH v2 07/10] KVM: X86: Move write_l1_tsc_offset() logic to common code and rename it
From: Sean Christopherson
Date: Wed May 19 2021 - 11:49:21 EST
On Wed, May 19, 2021, Stamatis, Ilias wrote:
> On Wed, 2021-05-19 at 00:05 +0000, Sean Christopherson wrote:
> > On Wed, May 12, 2021, Ilias Stamatis wrote:
> > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > > index 1db6cfc2079f..f3ba1be4d5b9 100644
> > > --- a/arch/x86/kvm/x86.c
> > > +++ b/arch/x86/kvm/x86.c
> > > @@ -2377,8 +2377,23 @@ EXPORT_SYMBOL_GPL(kvm_set_02_tsc_multiplier);
> > >
> > > static void kvm_vcpu_write_tsc_offset(struct kvm_vcpu *vcpu, u64 offset)
> > > {
> > > + trace_kvm_write_tsc_offset(vcpu->vcpu_id,
> > > + vcpu->arch.l1_tsc_offset,
> > > + offset);
> > > +
> > > vcpu->arch.l1_tsc_offset = offset;
> > > - vcpu->arch.tsc_offset = static_call(kvm_x86_write_l1_tsc_offset)(vcpu, offset);
> > > + vcpu->arch.tsc_offset = offset;
> > > +
> > > + if (is_guest_mode(vcpu)) {
> >
> > Unnecessary curly braces.
>
> Really? We are supposed to have a 6-lines body without brackets? I'm not
> opposing, I'm just surprised that that's the coding standard.
Comments don't (technically) count. I usually avoid the ambiguity by putting
the comment above the if statement. That also helps with indentation, e.g.
/*
* This is a comment.
*/
if (is_guest_mode(vcpu))
kvm_set_02_tsc_offset(vcpu);
> > > + /*
> > > + * We're here if L1 chose not to trap WRMSR to TSC and
> > > + * according to the spec this should set L1's TSC (as opposed
> > > + * to setting L1's offset for L2).
> > > + */
> >
> > While we're shuffling code, can we improve this comment? It works for the WRMSR
> > case, but makes no sense in the context of host TSC adjustments. It's not at all
> > clear to me that it's even correct or relevant in those cases.
> >
>
> Do you suggest removing it completely or how do you want it to be? I don't
> mind deleting it.
Heh, I'd happily write the comment, except I have no idea what the logic is in
the non-WRMSR case. I do think we need a comment, IMO none of paths that lead
to changing the TSC offset while L2 is active are obvious.