[PATCH 1/2] x86: Make hvm_enabled a constant unless both PV and HVM are both compiled

Alejandro Vallejo posted 2 patches 1 month, 4 weeks ago
[PATCH 1/2] x86: Make hvm_enabled a constant unless both PV and HVM are both compiled
Posted by Alejandro Vallejo 1 month, 4 weeks ago
PV-shim already has hvm_enabled optimised to false, but there's no
reason HVM-only builds can't benefit from the same optimisation as long
as we add a boot-time panic in case HVM support is missed. Many branches
go away, some in the potentially hot switch_cr3_cr4.

HVM-only:
  add/remove: 0/1 grow/shrink: 1/9 up/down: 1/-162 (-161)
  Function                                     old     new   delta
  arch_do_physinfo                              79      80      +1
  hvm_enabled                                    1       -      -1
  symbols_offsets                            30732   30728      -4
  symbols_names                             108029  108022      -7
  symbols_sorted_offsets                     60656   60648      -8
  flush_area_local                             571     562      -9
  switch_cr3_cr4                               311     300     -11
  init_xen_cap_info                             62      43     -19
  arch_sanitise_domain_config                  885     863     -22
  init_guest_cpu_policies                     1270    1247     -23
  hvm_domain_initialise                       1127    1069     -58
  Total: Before=3797004, After=3796843, chg -0.00%

With hvm_enabled const-ified, it's fine to take hvm_flush_guest_tlbs()
outside the CONFIG_HVM ifdef and remove the stub. They compile to the
same code after DCE.

Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
---
 xen/arch/x86/hvm/hvm.c             |  9 +++++++++
 xen/arch/x86/include/asm/hvm/hvm.h | 30 +++++++++++++++---------------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 4d37a93c57..da56944e74 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -72,7 +72,9 @@
 
 #include <compat/hvm/hvm_op.h>
 
+#ifdef CONFIG_PV
 bool __read_mostly hvm_enabled;
+#endif /* CONFIG_PV */
 
 #ifdef DBG_LEVEL_0
 unsigned int opt_hvm_debug_level __read_mostly;
@@ -173,9 +175,16 @@ static int __init cf_check hvm_enable(void)
         svm_fill_funcs();
 
     if ( fns == NULL )
+    {
+        if ( !IS_ENABLED(CONFIG_PV) )
+            panic("HVM support not detected and PV compiled-out\n");
+
         return 0;
+    }
 
+#ifdef CONFIG_PV
     hvm_enabled = 1;
+#endif /* CONFIG_PV */
 
     printk("HVM: %s enabled\n", fns->name);
     if ( !hap_supported(&hvm_funcs) )
diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h
index 7d9774df59..dc609bf4cb 100644
--- a/xen/arch/x86/include/asm/hvm/hvm.h
+++ b/xen/arch/x86/include/asm/hvm/hvm.h
@@ -261,7 +261,11 @@ struct hvm_function_table {
 };
 
 extern struct hvm_function_table hvm_funcs;
+#if defined(CONFIG_PV) && defined(CONFIG_HVM)
 extern bool hvm_enabled;
+#else
+#define hvm_enabled IS_ENABLED(CONFIG_HVM)
+#endif
 extern int8_t hvm_port80_allowed;
 
 extern const struct hvm_function_table *start_svm(void);
@@ -399,6 +403,17 @@ static inline bool using_svm(void)
 #define hvm_is_in_uc_mode(d) \
     (using_vmx() && (d)->arch.hvm.vmx.in_uc_mode)
 
+/*
+ * Called to ensure than all guest-specific mappings in a tagged TLB are
+ * flushed; does *not* flush Xen's TLB entries, and on processors without a
+ * tagged TLB it will be a noop.
+ */
+static inline void hvm_flush_guest_tlbs(void)
+{
+    if ( hvm_enabled )
+        hvm_asid_flush_core();
+}
+
 #ifdef CONFIG_HVM
 
 #define hvm_get_guest_tsc(v) hvm_get_guest_tsc_fixed(v, 0)
@@ -498,17 +513,6 @@ static inline void hvm_set_tsc_offset(struct vcpu *v, uint64_t offset)
     alternative_vcall(hvm_funcs.set_tsc_offset, v, offset);
 }
 
-/*
- * Called to ensure than all guest-specific mappings in a tagged TLB are 
- * flushed; does *not* flush Xen's TLB entries, and on processors without a 
- * tagged TLB it will be a noop.
- */
-static inline void hvm_flush_guest_tlbs(void)
-{
-    if ( hvm_enabled )
-        hvm_asid_flush_core();
-}
-
 static inline unsigned int
 hvm_get_cpl(struct vcpu *v)
 {
@@ -854,8 +858,6 @@ static inline void hvm_sync_pir_to_irr(struct vcpu *v)
 
 #else  /* CONFIG_HVM */
 
-#define hvm_enabled false
-
 /*
  * List of inline functions above, of which only declarations are
  * needed because DCE will kick in.
@@ -902,8 +904,6 @@ static inline int hvm_cpu_up(void)
 
 static inline void hvm_cpu_down(void) {}
 
-static inline void hvm_flush_guest_tlbs(void) {}
-
 static inline void hvm_invlpg(const struct vcpu *v, unsigned long linear)
 {
     ASSERT_UNREACHABLE();
-- 
2.43.0
Re: [PATCH 1/2] x86: Make hvm_enabled a constant unless both PV and HVM are both compiled
Posted by Roger Pau Monné 1 month, 4 weeks ago
On Fri, Feb 13, 2026 at 02:37:29PM +0100, Alejandro Vallejo wrote:
> PV-shim already has hvm_enabled optimised to false, but there's no
> reason HVM-only builds can't benefit from the same optimisation as long
> as we add a boot-time panic in case HVM support is missed. Many branches
> go away, some in the potentially hot switch_cr3_cr4.
> 
> HVM-only:
>   add/remove: 0/1 grow/shrink: 1/9 up/down: 1/-162 (-161)
>   Function                                     old     new   delta
>   arch_do_physinfo                              79      80      +1
>   hvm_enabled                                    1       -      -1
>   symbols_offsets                            30732   30728      -4
>   symbols_names                             108029  108022      -7
>   symbols_sorted_offsets                     60656   60648      -8
>   flush_area_local                             571     562      -9
>   switch_cr3_cr4                               311     300     -11
>   init_xen_cap_info                             62      43     -19
>   arch_sanitise_domain_config                  885     863     -22
>   init_guest_cpu_policies                     1270    1247     -23
>   hvm_domain_initialise                       1127    1069     -58
>   Total: Before=3797004, After=3796843, chg -0.00%
> 
> With hvm_enabled const-ified, it's fine to take hvm_flush_guest_tlbs()
> outside the CONFIG_HVM ifdef and remove the stub. They compile to the
> same code after DCE.
> 
> Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
> ---
>  xen/arch/x86/hvm/hvm.c             |  9 +++++++++
>  xen/arch/x86/include/asm/hvm/hvm.h | 30 +++++++++++++++---------------
>  2 files changed, 24 insertions(+), 15 deletions(-)
> 
> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> index 4d37a93c57..da56944e74 100644
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -72,7 +72,9 @@
>  
>  #include <compat/hvm/hvm_op.h>
>  
> +#ifdef CONFIG_PV
>  bool __read_mostly hvm_enabled;

__ro_after_init?

> +#endif /* CONFIG_PV */
>  
>  #ifdef DBG_LEVEL_0
>  unsigned int opt_hvm_debug_level __read_mostly;
> @@ -173,9 +175,16 @@ static int __init cf_check hvm_enable(void)
>          svm_fill_funcs();
>  
>      if ( fns == NULL )
> +    {
> +        if ( !IS_ENABLED(CONFIG_PV) )
> +            panic("HVM support not detected and PV compiled-out\n");
> +
>          return 0;
> +    }
>  
> +#ifdef CONFIG_PV

CONFIG_HVM I think?

>      hvm_enabled = 1;

= true;

> +#endif /* CONFIG_PV */
>  
>      printk("HVM: %s enabled\n", fns->name);
>      if ( !hap_supported(&hvm_funcs) )
> diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h
> index 7d9774df59..dc609bf4cb 100644
> --- a/xen/arch/x86/include/asm/hvm/hvm.h
> +++ b/xen/arch/x86/include/asm/hvm/hvm.h
> @@ -261,7 +261,11 @@ struct hvm_function_table {
>  };
>  
>  extern struct hvm_function_table hvm_funcs;
> +#if defined(CONFIG_PV) && defined(CONFIG_HVM)
>  extern bool hvm_enabled;
> +#else
> +#define hvm_enabled IS_ENABLED(CONFIG_HVM)
> +#endif
>  extern int8_t hvm_port80_allowed;
>  
>  extern const struct hvm_function_table *start_svm(void);
> @@ -399,6 +403,17 @@ static inline bool using_svm(void)
>  #define hvm_is_in_uc_mode(d) \
>      (using_vmx() && (d)->arch.hvm.vmx.in_uc_mode)
>  
> +/*
> + * Called to ensure than all guest-specific mappings in a tagged TLB are
> + * flushed; does *not* flush Xen's TLB entries, and on processors without a
> + * tagged TLB it will be a noop.
> + */
> +static inline void hvm_flush_guest_tlbs(void)
> +{
> +    if ( hvm_enabled )
> +        hvm_asid_flush_core();
> +}
> +
>  #ifdef CONFIG_HVM
>  
>  #define hvm_get_guest_tsc(v) hvm_get_guest_tsc_fixed(v, 0)
> @@ -498,17 +513,6 @@ static inline void hvm_set_tsc_offset(struct vcpu *v, uint64_t offset)
>      alternative_vcall(hvm_funcs.set_tsc_offset, v, offset);
>  }
>  
> -/*
> - * Called to ensure than all guest-specific mappings in a tagged TLB are 
> - * flushed; does *not* flush Xen's TLB entries, and on processors without a 
> - * tagged TLB it will be a noop.
> - */
> -static inline void hvm_flush_guest_tlbs(void)
> -{
> -    if ( hvm_enabled )
> -        hvm_asid_flush_core();
> -}

Is there any specific reason you only pick hvm_flush_guest_tlbs().
Given what you do with hvm_enabled you could probably generalize all
the dummy helpers in the !CONFIG_HVM section now?

Thanks, Roger.
Re: [PATCH 1/2] x86: Make hvm_enabled a constant unless both PV and HVM are both compiled
Posted by Alejandro Vallejo 1 month, 4 weeks ago
On Fri Feb 13, 2026 at 3:26 PM CET, Roger Pau Monné wrote:
> On Fri, Feb 13, 2026 at 02:37:29PM +0100, Alejandro Vallejo wrote:
>> PV-shim already has hvm_enabled optimised to false, but there's no
>> reason HVM-only builds can't benefit from the same optimisation as long
>> as we add a boot-time panic in case HVM support is missed. Many branches
>> go away, some in the potentially hot switch_cr3_cr4.
>> 
>> HVM-only:
>>   add/remove: 0/1 grow/shrink: 1/9 up/down: 1/-162 (-161)
>>   Function                                     old     new   delta
>>   arch_do_physinfo                              79      80      +1
>>   hvm_enabled                                    1       -      -1
>>   symbols_offsets                            30732   30728      -4
>>   symbols_names                             108029  108022      -7
>>   symbols_sorted_offsets                     60656   60648      -8
>>   flush_area_local                             571     562      -9
>>   switch_cr3_cr4                               311     300     -11
>>   init_xen_cap_info                             62      43     -19
>>   arch_sanitise_domain_config                  885     863     -22
>>   init_guest_cpu_policies                     1270    1247     -23
>>   hvm_domain_initialise                       1127    1069     -58
>>   Total: Before=3797004, After=3796843, chg -0.00%
>> 
>> With hvm_enabled const-ified, it's fine to take hvm_flush_guest_tlbs()
>> outside the CONFIG_HVM ifdef and remove the stub. They compile to the
>> same code after DCE.
>> 
>> Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
>> ---
>>  xen/arch/x86/hvm/hvm.c             |  9 +++++++++
>>  xen/arch/x86/include/asm/hvm/hvm.h | 30 +++++++++++++++---------------
>>  2 files changed, 24 insertions(+), 15 deletions(-)
>> 
>> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
>> index 4d37a93c57..da56944e74 100644
>> --- a/xen/arch/x86/hvm/hvm.c
>> +++ b/xen/arch/x86/hvm/hvm.c
>> @@ -72,7 +72,9 @@
>>  
>>  #include <compat/hvm/hvm_op.h>
>>  
>> +#ifdef CONFIG_PV
>>  bool __read_mostly hvm_enabled;
>
> __ro_after_init?

Yeah, seems to have been missing originally

>
>> +#endif /* CONFIG_PV */
>>  
>>  #ifdef DBG_LEVEL_0
>>  unsigned int opt_hvm_debug_level __read_mostly;
>> @@ -173,9 +175,16 @@ static int __init cf_check hvm_enable(void)
>>          svm_fill_funcs();
>>  
>>      if ( fns == NULL )
>> +    {
>> +        if ( !IS_ENABLED(CONFIG_PV) )
>> +            panic("HVM support not detected and PV compiled-out\n");
>> +
>>          return 0;
>> +    }
>>  
>> +#ifdef CONFIG_PV
>
> CONFIG_HVM I think?

No. CONFIG_HVM always holds here, what we want to remove is hvm_enabled being
present when CONFIG_PV is _also_ present.

>
>>      hvm_enabled = 1;
>
> = true;

True enough.

>
>> +#endif /* CONFIG_PV */
>>  
>>      printk("HVM: %s enabled\n", fns->name);
>>      if ( !hap_supported(&hvm_funcs) )
>> diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h
>> index 7d9774df59..dc609bf4cb 100644
>> --- a/xen/arch/x86/include/asm/hvm/hvm.h
>> +++ b/xen/arch/x86/include/asm/hvm/hvm.h
>> @@ -261,7 +261,11 @@ struct hvm_function_table {
>>  };
>>  
>>  extern struct hvm_function_table hvm_funcs;
>> +#if defined(CONFIG_PV) && defined(CONFIG_HVM)
>>  extern bool hvm_enabled;
>> +#else
>> +#define hvm_enabled IS_ENABLED(CONFIG_HVM)
>> +#endif
>>  extern int8_t hvm_port80_allowed;
>>  
>>  extern const struct hvm_function_table *start_svm(void);
>> @@ -399,6 +403,17 @@ static inline bool using_svm(void)
>>  #define hvm_is_in_uc_mode(d) \
>>      (using_vmx() && (d)->arch.hvm.vmx.in_uc_mode)
>>  
>> +/*
>> + * Called to ensure than all guest-specific mappings in a tagged TLB are
>> + * flushed; does *not* flush Xen's TLB entries, and on processors without a
>> + * tagged TLB it will be a noop.
>> + */
>> +static inline void hvm_flush_guest_tlbs(void)
>> +{
>> +    if ( hvm_enabled )
>> +        hvm_asid_flush_core();
>> +}
>> +
>>  #ifdef CONFIG_HVM
>>  
>>  #define hvm_get_guest_tsc(v) hvm_get_guest_tsc_fixed(v, 0)
>> @@ -498,17 +513,6 @@ static inline void hvm_set_tsc_offset(struct vcpu *v, uint64_t offset)
>>      alternative_vcall(hvm_funcs.set_tsc_offset, v, offset);
>>  }
>>  
>> -/*
>> - * Called to ensure than all guest-specific mappings in a tagged TLB are 
>> - * flushed; does *not* flush Xen's TLB entries, and on processors without a 
>> - * tagged TLB it will be a noop.
>> - */
>> -static inline void hvm_flush_guest_tlbs(void)
>> -{
>> -    if ( hvm_enabled )
>> -        hvm_asid_flush_core();
>> -}
>
> Is there any specific reason you only pick hvm_flush_guest_tlbs().

I didn't try to remove more. That one was the only one with hvm_enabled in the
static inline so it seems easy to pick apart.

I just tried compiling and I require very few additions to make the build
compile without stubs. I'll send another version with the adjustments needed.

Cheers,
Alejandro
Re: [PATCH 1/2] x86: Make hvm_enabled a constant unless both PV and HVM are both compiled
Posted by Roger Pau Monné 1 month, 4 weeks ago
On Fri, Feb 13, 2026 at 06:04:33PM +0100, Alejandro Vallejo wrote:
> On Fri Feb 13, 2026 at 3:26 PM CET, Roger Pau Monné wrote:
> > On Fri, Feb 13, 2026 at 02:37:29PM +0100, Alejandro Vallejo wrote:
> >> PV-shim already has hvm_enabled optimised to false, but there's no
> >> reason HVM-only builds can't benefit from the same optimisation as long
> >> as we add a boot-time panic in case HVM support is missed. Many branches
> >> go away, some in the potentially hot switch_cr3_cr4.
> >> 
> >> HVM-only:
> >>   add/remove: 0/1 grow/shrink: 1/9 up/down: 1/-162 (-161)
> >>   Function                                     old     new   delta
> >>   arch_do_physinfo                              79      80      +1
> >>   hvm_enabled                                    1       -      -1
> >>   symbols_offsets                            30732   30728      -4
> >>   symbols_names                             108029  108022      -7
> >>   symbols_sorted_offsets                     60656   60648      -8
> >>   flush_area_local                             571     562      -9
> >>   switch_cr3_cr4                               311     300     -11
> >>   init_xen_cap_info                             62      43     -19
> >>   arch_sanitise_domain_config                  885     863     -22
> >>   init_guest_cpu_policies                     1270    1247     -23
> >>   hvm_domain_initialise                       1127    1069     -58
> >>   Total: Before=3797004, After=3796843, chg -0.00%
> >> 
> >> With hvm_enabled const-ified, it's fine to take hvm_flush_guest_tlbs()
> >> outside the CONFIG_HVM ifdef and remove the stub. They compile to the
> >> same code after DCE.
> >> 
> >> Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
> >> ---
> >>  xen/arch/x86/hvm/hvm.c             |  9 +++++++++
> >>  xen/arch/x86/include/asm/hvm/hvm.h | 30 +++++++++++++++---------------
> >>  2 files changed, 24 insertions(+), 15 deletions(-)
> >> 
> >> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> >> index 4d37a93c57..da56944e74 100644
> >> --- a/xen/arch/x86/hvm/hvm.c
> >> +++ b/xen/arch/x86/hvm/hvm.c
> >> @@ -72,7 +72,9 @@
> >>  
> >>  #include <compat/hvm/hvm_op.h>
> >>  
> >> +#ifdef CONFIG_PV
> >>  bool __read_mostly hvm_enabled;
> >
> > __ro_after_init?
> 
> Yeah, seems to have been missing originally

I bet __ro_after_init wasn't available when this was introduced.

> >
> >> +#endif /* CONFIG_PV */
> >>  
> >>  #ifdef DBG_LEVEL_0
> >>  unsigned int opt_hvm_debug_level __read_mostly;
> >> @@ -173,9 +175,16 @@ static int __init cf_check hvm_enable(void)
> >>          svm_fill_funcs();
> >>  
> >>      if ( fns == NULL )
> >> +    {
> >> +        if ( !IS_ENABLED(CONFIG_PV) )
> >> +            panic("HVM support not detected and PV compiled-out\n");
> >> +
> >>          return 0;
> >> +    }
> >>  
> >> +#ifdef CONFIG_PV
> >
> > CONFIG_HVM I think?
> 
> No. CONFIG_HVM always holds here, what we want to remove is hvm_enabled being
> present when CONFIG_PV is _also_ present.

Yeah, Andrew already noticed that.

> >
> >>      hvm_enabled = 1;
> >
> > = true;
> 
> True enough.
> 
> >
> >> +#endif /* CONFIG_PV */
> >>  
> >>      printk("HVM: %s enabled\n", fns->name);
> >>      if ( !hap_supported(&hvm_funcs) )
> >> diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h
> >> index 7d9774df59..dc609bf4cb 100644
> >> --- a/xen/arch/x86/include/asm/hvm/hvm.h
> >> +++ b/xen/arch/x86/include/asm/hvm/hvm.h
> >> @@ -261,7 +261,11 @@ struct hvm_function_table {
> >>  };
> >>  
> >>  extern struct hvm_function_table hvm_funcs;
> >> +#if defined(CONFIG_PV) && defined(CONFIG_HVM)
> >>  extern bool hvm_enabled;
> >> +#else
> >> +#define hvm_enabled IS_ENABLED(CONFIG_HVM)
> >> +#endif
> >>  extern int8_t hvm_port80_allowed;
> >>  
> >>  extern const struct hvm_function_table *start_svm(void);
> >> @@ -399,6 +403,17 @@ static inline bool using_svm(void)
> >>  #define hvm_is_in_uc_mode(d) \
> >>      (using_vmx() && (d)->arch.hvm.vmx.in_uc_mode)
> >>  
> >> +/*
> >> + * Called to ensure than all guest-specific mappings in a tagged TLB are
> >> + * flushed; does *not* flush Xen's TLB entries, and on processors without a
> >> + * tagged TLB it will be a noop.
> >> + */
> >> +static inline void hvm_flush_guest_tlbs(void)
> >> +{
> >> +    if ( hvm_enabled )
> >> +        hvm_asid_flush_core();
> >> +}
> >> +
> >>  #ifdef CONFIG_HVM
> >>  
> >>  #define hvm_get_guest_tsc(v) hvm_get_guest_tsc_fixed(v, 0)
> >> @@ -498,17 +513,6 @@ static inline void hvm_set_tsc_offset(struct vcpu *v, uint64_t offset)
> >>      alternative_vcall(hvm_funcs.set_tsc_offset, v, offset);
> >>  }
> >>  
> >> -/*
> >> - * Called to ensure than all guest-specific mappings in a tagged TLB are 
> >> - * flushed; does *not* flush Xen's TLB entries, and on processors without a 
> >> - * tagged TLB it will be a noop.
> >> - */
> >> -static inline void hvm_flush_guest_tlbs(void)
> >> -{
> >> -    if ( hvm_enabled )
> >> -        hvm_asid_flush_core();
> >> -}
> >
> > Is there any specific reason you only pick hvm_flush_guest_tlbs().
> 
> I didn't try to remove more. That one was the only one with hvm_enabled in the
> static inline so it seems easy to pick apart.

Oh, I see.  That one already had the hvm_enabled condition in it's
non-stub version.

> I just tried compiling and I require very few additions to make the build
> compile without stubs. I'll send another version with the adjustments needed.

OK, I think if we could unify them that would make the header smaller
and easier to read.

Thanks, Roger.

Re: [PATCH 1/2] x86: Make hvm_enabled a constant unless both PV and HVM are both compiled
Posted by Andrew Cooper 1 month, 4 weeks ago
On 13/02/2026 2:26 pm, Roger Pau Monné wrote:
> On Fri, Feb 13, 2026 at 02:37:29PM +0100, Alejandro Vallejo wrote:
>> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
>> index 4d37a93c57..da56944e74 100644
>> --- a/xen/arch/x86/hvm/hvm.c
>> +++ b/xen/arch/x86/hvm/hvm.c
>> @@ -173,9 +175,16 @@ static int __init cf_check hvm_enable(void)
>>          svm_fill_funcs();
>>  
>>      if ( fns == NULL )
>> +    {
>> +        if ( !IS_ENABLED(CONFIG_PV) )
>> +            panic("HVM support not detected and PV compiled-out\n");

As with Rogers feedback on the next patch, this wording isn't ideal. 
How about:

"HVM support required but not available\n".

This is reachable for people who use cpuid=no-vmx,no-svm but they get to
keep all the pieces and the documentation already has a general warning
about this kind of stuff.

>> +
>>          return 0;
>> +    }
>>  
>> +#ifdef CONFIG_PV
> CONFIG_HVM I think?

No - CONFIG_PV is correct here, because we're inside an HVM-only file. 
It's the only case where this variable exists for real.

~Andrew

Re: [PATCH 1/2] x86: Make hvm_enabled a constant unless both PV and HVM are both compiled
Posted by Roger Pau Monné 1 month, 4 weeks ago
On Fri, Feb 13, 2026 at 04:01:25PM +0000, Andrew Cooper wrote:
> On 13/02/2026 2:26 pm, Roger Pau Monné wrote:
> > On Fri, Feb 13, 2026 at 02:37:29PM +0100, Alejandro Vallejo wrote:
> >> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> >> index 4d37a93c57..da56944e74 100644
> >> --- a/xen/arch/x86/hvm/hvm.c
> >> +++ b/xen/arch/x86/hvm/hvm.c
> >> @@ -173,9 +175,16 @@ static int __init cf_check hvm_enable(void)
> >>          svm_fill_funcs();
> >>  
> >>      if ( fns == NULL )
> >> +    {
> >> +        if ( !IS_ENABLED(CONFIG_PV) )
> >> +            panic("HVM support not detected and PV compiled-out\n");
> 
> As with Rogers feedback on the next patch, this wording isn't ideal. 
> How about:
> 
> "HVM support required but not available\n".
> 
> This is reachable for people who use cpuid=no-vmx,no-svm but they get to
> keep all the pieces and the documentation already has a general warning
> about this kind of stuff.

Hm, yes, I forgot to comment on this one.

> 
> >> +
> >>          return 0;
> >> +    }
> >>  
> >> +#ifdef CONFIG_PV
> > CONFIG_HVM I think?
> 
> No - CONFIG_PV is correct here, because we're inside an HVM-only file. 
> It's the only case where this variable exists for real.

Oh, I see.  Yes, those are the right guards, otherwise the variable is
hardcoded to IS_ENABLED(CONFIG_HVM).  Sorry, my bad.  It's a bit ugly
to have to do it with such ifdefs, but right now I don't see a better
way.

Thanks, Roger.