[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XEN][PATCH 1/2] x86: hvm: vmx: fix runtime vmx presence check for !CONFIG_INTEL_VMX case


  • To: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 25 Sep 2025 07:58:44 +0200
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew@xxxxxxx>
  • Delivery-date: Thu, 25 Sep 2025 05:58:44 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 24.09.2025 13:23, Alejandro Vallejo wrote:
> On Tue Sep 16, 2025 at 7:14 PM CEST, Andrew Cooper wrote:
>> On 16/09/2025 9:57 am, Grygorii Strashko wrote:
>>> Hi Jan,
>>>
>>> On 16.09.25 17:34, Jan Beulich wrote:
>>>> On 16.09.2025 12:32, Grygorii Strashko wrote:
>>>>> From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
>>>>>
>>>>> Since commit b99227347230 ("x86: Fix AMD_SVM and INTEL_VMX
>>>>> dependency") the
>>>>> HVM Intel VT-x support can be gracefully disabled, but it still
>>>>> keeps VMX
>>>>> code partially built-in, because HVM code uses mix of:
>>>>>
>>>>>   - "cpu_has_vmx" macro, which doesn't account for CONFIG_INTEL_VMX cfg
>>>>>   - "using_vmx()" function, which accounts for CONFIG_INTEL_VMX cfg
>>>>>
>>>>> for runtime VMX availability checking. As result compiler DCE can't
>>>>> remove
>>>>> all, unreachable VMX code.
>>>>>
>>>>> Fix it by sticking to "cpu_has_vmx" macro usage only which is
>>>>> updated to
>>>>> account CONFIG_INTEL_VMX cfg.
>>>>>
>>>>> Signed-off-by: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
>>>>> ---
>>>>> Hi
>>>>>
>>>>> It could be good to have it in 4.21, so vmx/svm disabling
>>>>> option will be in complete state within 4.21 version.
>>>>
>>>> Imo this isn't release critical and has come too late. It's of course
>>>> Oleksii's call in the end.
>>>>
>>>>> --- a/xen/arch/x86/include/asm/cpufeature.h
>>>>> +++ b/xen/arch/x86/include/asm/cpufeature.h
>>>>> @@ -136,7 +136,8 @@ static inline bool boot_cpu_has(unsigned int feat)
>>>>>   #define cpu_has_sse3            boot_cpu_has(X86_FEATURE_SSE3)
>>>>>   #define cpu_has_pclmulqdq       boot_cpu_has(X86_FEATURE_PCLMULQDQ)
>>>>>   #define cpu_has_monitor         boot_cpu_has(X86_FEATURE_MONITOR)
>>>>> -#define cpu_has_vmx             boot_cpu_has(X86_FEATURE_VMX)
>>>>> +#define cpu_has_vmx             (IS_ENABLED(CONFIG_INTEL_VMX) && \
>>>>> +                                 boot_cpu_has(X86_FEATURE_VMX))
>>>>
>>>> I'm pretty sure using_vmx() was introduced precisely to avoid the use of
>>>> IS_ENABLED() here. What is completely missing from the description is a
>>>> discussion of the effect of this change on pre-existing uses of the
>>>> macro. ISTR there being at least one instance which would break with
>>>> that change. And no, I'm not looking forward to digging that out again,
>>>> when I already did at the time the using_vmx() was suggested and then
>>>> implemented. (I can't exclude it was the SVM counterpart; we want to
>>>> keep both in sync in any event, imo.)
> 
> Apologies if this has already been discussed, but I didn't participate in 
> prior
> discussions. Targeted lookups in lore are not shedding a lot of light either.
> 
>>>
>>> Thank you for your comments and sorry for not digging into the history of
>>> the related patches.
>>>
>>> All, please ignore these patches as existing places. where
>>> cpu_has_vmx/smv
>>> are still used, need to be revised one by one.
>>>
>>
>> Off the top of my head, fixups to MSR_FEATURE_CONTROL, and AMD SKINIT
>> need cpu_has_vmx/svm not guarded by Kconfig like this.
>>
>> ~Andrew
> 
> What do you mean? AFAICS SKINIT is guarded by cpu_has_skinit, not cpu_has_svm.
> 
> And MSR_IA32_FEATURE_CONTROL tweaking seems self-contained in xen/hvm/vmx/ 
> which
> is compiled out when !CONFIG_INTEL_VMX.
> 
> For the hypothetical case in which we might want to know the real HW value
> we can go look at the raw policy, as in "raw_cpu_policy.basic.vmx" or
> "raw_cpu_policy.extd.svm". Or what's mentioned in passing here.
> 
> https://lore.kernel.org/xen-devel/a881c6a6-2c36-4e5c-8336-21cd0e14b873@xxxxxxxx/
> 
> Forcing the common case to use a helper and leaving the rare case in the
> shorthand macro seems like a bad idea. This ought to follow what cpu_has_nx
> already does.
> 
> Is there a specific code instance in which having IS_ENABLED() in the
> cpu_has_{svm,vmx} macros would cause issues today? While there are some 
> dubious
> choices of svm vs vmx with or without negation, they all seem to resolve
> to correct code, with less codegen after IS_ENABLED() ends up in all the
> conditionals.
> 
> IOW: I have seen fear of incorrectness, but not proof of it. Now, obviously 
> the
> burden of proof rests on the submitter, indeed, but I'd like to know where we
> stand in terms of what that proof would look like.

Such a proof could be a statement clarifying that all use sites were audited. If
then a reviewer found an issue with that, it would get interesting (as 
[possibly]
in: it being questionable whether an audit was actually done; what I mean to say
here is that it's not a matter of merely stating that an audit was [supposedly]
done).

Jan

> A naive grep shows not many
> sites to check.
> 
>   $git grep cpu_has_svm | grep -v cpu_has_svm_ | wc -l
>   6
> 
>   $git grep cpu_has_vmx | grep -v cpu_has_vmx_ | wc -l
>   11
> 
> cpu_has_X_Y would be off when cpu_has_X is off, but those shouldn't matter for
> this discussion.
> 
> Am I missing something here?
> 
> Cheers,
> Alejandro




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.