Re: [RFC PATCH v1 10/15] KVM: VMX: Use WRMSRNS or its immediate form when available

From: H. Peter Anvin
Date: Fri Apr 11 2025 - 16:52:35 EST


On April 11, 2025 9:18:08 AM PDT, Xin Li <xin@xxxxxxxxx> wrote:
>On 4/10/2025 4:24 PM, Sean Christopherson wrote:
>>> +/*
>>> + * Write EAX to MSR_IA32_SPEC_CTRL.
>>> + *
>>> + * Choose the best WRMSR instruction based on availability.
>>> + *
>>> + * Replace with 'wrmsrns' and 'wrmsrns %rax, $MSR_IA32_SPEC_CTRL' once binutils support them.
>>> + */
>>> +.macro WRITE_EAX_TO_MSR_IA32_SPEC_CTRL
>>> + ALTERNATIVE_2 __stringify(mov $MSR_IA32_SPEC_CTRL, %ecx; \
>>> + xor %edx, %edx; \
>>> + mov %edi, %eax; \
>>> + ds wrmsr), \
>>> + __stringify(mov $MSR_IA32_SPEC_CTRL, %ecx; \
>>> + xor %edx, %edx; \
>>> + mov %edi, %eax; \
>>> + ASM_WRMSRNS), \
>>> + X86_FEATURE_WRMSRNS, \
>>> + __stringify(xor %_ASM_AX, %_ASM_AX; \
>>> + mov %edi, %eax; \
>>> + ASM_WRMSRNS_RAX; .long MSR_IA32_SPEC_CTRL), \
>>> + X86_FEATURE_MSR_IMM
>>> +.endm
>> This is quite hideous. I have no objection to optimizing __vmx_vcpu_run(), but
>> I would much prefer that a macro like this live in generic code, and that it be
>> generic. It should be easy enough to provide an assembly friendly equivalent to
>> __native_wrmsr_constant().
>
>Will do.

This should be coming anyway, right?