[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAFULd4Zc4-nPLSEeUbOh_A1O9VyC8arHVy=Y4Gg-d_Rjhon1Ow@mail.gmail.com>
Date: Thu, 6 Nov 2025 19:29:31 +0100
From: Uros Bizjak <ubizjak@...il.com>
To: Sean Christopherson <seanjc@...gle.com>
Cc: kvm@...r.kernel.org, x86@...nel.org, linux-kernel@...r.kernel.org,
Paolo Bonzini <pbonzini@...hat.com>, Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...nel.org>,
Borislav Petkov <bp@...en8.de>, Dave Hansen <dave.hansen@...ux.intel.com>,
"H. Peter Anvin" <hpa@...or.com>
Subject: Re: [PATCH] KVM: VMX: Micro-optimize SPEC_CTRL handling in __vmx_vcpu_run()
On Thu, Nov 6, 2025 at 2:12 AM Sean Christopherson <seanjc@...gle.com> wrote:
> > VMX patch is at [1]. SVM patch is a bit more involved, because new
> > 32-bit code needs to clobber one additional register. The SVM patch is
> > attached to this message, but while I compile tested it, I have no
> > means of testing it with runtime tests. Can you please put it through
> > your torture tests?
[...]
> > -
> > /* Now restore the host value of the MSR if different from the guest's. */
> > - movl PER_CPU_VAR(x86_spec_ctrl_current), %eax
> > - cmp SVM_spec_ctrl(%_ASM_DI), %eax
> > + mov SVM_spec_ctrl(%rdi), %rdx
> > + cmp PER_CPU_VAR(x86_spec_ctrl_current), %rdx
> > je 901b
> > - xor %edx, %edx
> > + movl %edx, %eax
> > + shr $32, %rdx
> > +#else
> > + mov %eax, SVM_spec_ctrl(%edi)
> > + mov %edx, SVM_spec_ctrl + 4(%edi)
> > +998:
> > + /* Now restore the host value of the MSR if different from the guest's. */
> > + mov SVM_spec_ctrl(%edi), %eax
> > + mov PER_CPU_VAR(x86_spec_ctrl_current), %esi
> > + xor %eax, %esi
> > + mov SVM_spec_ctrl + 4(%edi), %edx
> > + mov PER_CPU_VAR(x86_spec_ctrl_current + 4), %edi
> > + xor %edx, %edi
> > + or %edi, %esi
> > + je 901b
>
> This particular flow is backwards, in that it loads the guest value into EDX:EAX
> instead of the host values.
Yeah, sorry about that, I was really not sure which value is where.
Please just swap
SVM_spec_ctrl(%edi) with PER_CPU_VAR(x86_spec_ctrl_current)
references (and their offseted variants) in the above code, and it
will result in the correct and optimal code.
Thanks,
Uros.
Powered by blists - more mailing lists