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

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


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
  • Date: Fri, 13 Feb 2026 14:37:29 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.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=OfExmNOBgyzV/W769nG2O1sMuHbppnbUF9pYKKsd9Bo=; b=laFjq7VPZRpck3q47GM9cPx9kfKw+R0qtkcGemVGFkTqXVOHypkUfyqSGBkhJgzS5MqFrF7cD7Q7Pi2Yx73y/nSzIu3R/CEQshgj9+EIgSwu60LOz5R1G+l9MOyKlruQS4hEadjr6SSv9iBvniicSZNpmXsKr9D1BuvBkIeW2yXC0MZChnGahHDvDe08wyEIoNNZnvOjlSgQeW9m1Abuc/QjqV6kY6dtPs28OW3I2Y8A8nAZDodNxbRNGsBmwZ9Z5AUDpHSxWyL7soSaXL+QMKVoUgQo/2/b4cV2Ftjez9qJvUOx5YHgiX+n4getAPo5tetFcCmFfd4iYeF66gG4+g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WhVkPyDXl7Z8VCbJjEt+oxoKIBCMT/ozco1rnnNTbQvAkFmFqVvOlw/8n6Bm2reZ6um6ZxLX5rgNxl8zvtwz2e5B32tgOwQwO4VXgz3eqn2IshZbRebgF2tYinB9nHhkjMv+fvT368/NlaiBjTpQTkpIC1bdRHEfAKnLy2GfPBzW+zyOL2R17Lv32Qylbr2ivhU+KrCfKg16SF7tSbFp2N2e/ikq/YhbRNkjRxmYtNePn/vh1FIYMBGqDgMaosyvXTDKX0neFHwRTGmyIdtZ0iO5qMWJqiHBqR7i+21oQU2L7f3vFGlUL6fEo2V/SqHUp9B4pl82YW7rhHTRito//g==
  • Cc: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Fri, 13 Feb 2026 13:38:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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@xxxxxxx>
---
 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




 


Rackspace

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