[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: Andrew Cooper <andrew@xxxxxxx>, Grygorii Strashko <grygorii_strashko@xxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>
  • From: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
  • Date: Wed, 24 Sep 2025 13:23:53 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=xen.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TJ1tSyabFMHOybYVns4qVp3jMn68goaH320dG5GL//I=; b=CTV9UcAaD5nd4O9Z/XwvxmnI+xsmsT66BB75L/bDbv9AoTzN5h7/muCRGq4gGEG7uaSinN2mPLjwJbrPDX9abNKYyrMHyaOmDLPPwqIJhI8t8RQHVceTZlIrWeNz8C3+ejB6FMAX45j9Lu6O7QlhVrxzchrmXp78uIY770PmpcDZuqnPwZLkBc2E0pSrOq5oF6dTHd1p4RJ+qpJZDlCtWTfzwnVbMiQ0uKT0Gc7eLJU/k3S+7/eqo2tZ597FAgVjHU5H8C5Wjl3oRIhOWuOM/OAsDXKbjAevfqGgkhHaazxopChOVUqO8GWm9ba0xhjvPpnZbJDPH7C/X+V9bZjFkA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JRMkRlVBYZX35HXUseKZopbzGYhXj2Z1lq8LQEXqyhJi2+tANNDe3Efxlau37Tuk9+lrNuyp63x7asTmSFue6KOA/Hrtn8TdlT74z5A5XsuVywwi55oY7mbvEE5z4nXMPouJCDSRJWCLay+derZF4bCwIVcGW2jnK7rm+9dsAZZ50co2qCPGfd5AcylLL02G4rdmCVi1VZM/bsIot4yiunQGtCMs4OcQl2M1aGWAsTlQbo46OXiD5IZ5PU03A0XXyMhc4pvoDrFzk1HtlI0bzxW/I3+7JlvCaz8OsaoK1+7Fg030o18d2dyhYD7KbmRJkieJzNh6/BtQ0xFLwYJgeg==
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 24 Sep 2025 11:24:10 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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. 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®.