Skip to contentSkip to conversation

x86/hvm: revise "cpu_has_vmx" usage for !CONFIG_INTEL_VMX case

PATCH In review Grygorii Strashko 3 participants 6 messages Sep 24, 2025 – Nov 13, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: revise "cpu_has_vmx" usage for !CONFIG_INTEL_VMX case

From: Grygorii Strashko <[email protected]>

Since commit b99227347230 ("x86: Fix AMD_SVM and INTEL_VMX dependency") the HVM Intel VT-x support can be disabled, but it still keeps VMX code partially built-in. Particularly in HVM code there are two places:

1) hvm/dom0_build.c
dom0_construct_pvh()->pvh_populate_p2m()

    ...
    if ( cpu_has_vmx && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
    {
        ...
        [unreachable for !cpu_has_vmx case]
        rc = pvh_setup_vmx_realmode_helpers(d);

pvh_setup_vmx_realmode_helpers() allocates memory and configures
HVM_PARAM_VM86_TSS_SIZED
HVM_PARAM_IDENT_PT

2) hvm/hvm.c
hvm_set_param()

    ...
    case HVM_PARAM_IDENT_PT:

        if ( !paging_mode_hap(d) || !cpu_has_vmx )
        {
            d->arch.hvm.params[index] = value;
            break;
        }
        [unreachable for !cpu_has_vmx case]
        ...

Hence HVM_PARAM_IDENT_PT/HVM_PARAM_VM86_TSS_SIZED are used only by VMX code above code become unreachable in !cpu_has_vmx case and can be optimazed when !CONFIG_INTEL_VMX.

Replace "cpu_has_vmx" with using_vmx() to account !CONFIG_INTEL_VMX and allow compiler DCE to optimize code.

---
add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-604 (-604)
Function old new delta

hvm_set_param                               1602    1473    -129
dom0_construct_pvh                          4438    3963    -475

Total: Before=3567191, After=3566587, chg -0.02%

 xen/arch/x86/hvm/dom0_build.c | 2 +-
 xen/arch/x86/hvm/hvm.c        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/dom0_build.c +1 -1
index 5551f9044836..5ac2cf8394d8 100644
@@ -473,7 +473,7 @@ static int __init pvh_populate_p2m(struct domain *d)
         }
     }
 
-    if ( cpu_has_vmx && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
+    if ( using_vmx() && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
     {
         /*
          * Since Dom0 cannot be migrated, we will only setup the
xen/arch/x86/hvm/hvm.c +1 -1
index 95a80369b9b8..70331aeec9a0 100644
@@ -4302,7 +4302,7 @@ static int hvm_set_param(struct domain *d, uint32_t index, uint64_t value)
          * Only actually required for VT-x lacking unrestricted_guest
          * capabilities.  Short circuit the pause if possible.
          */
-        if ( !paging_mode_hap(d) || !cpu_has_vmx )
+        if ( !paging_mode_hap(d) || !using_vmx() )
         {
             d->arch.hvm.params[index] = value;
             break;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 21 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Since commit b99227347230 ("x86: Fix AMD_SVM and INTEL_VMX dependency") the HVM Intel VT-x support can be disabled, but it still keeps VMX code partially built-in. Particularly in HVM code there are two places:

1) hvm/dom0_build.c
dom0_construct_pvh()->pvh_populate_p2m()

    ...
    if ( cpu_has_vmx && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
    {
        ...
        [unreachable for !cpu_has_vmx case]
        rc = pvh_setup_vmx_realmode_helpers(d);

pvh_setup_vmx_realmode_helpers() allocates memory and configures
HVM_PARAM_VM86_TSS_SIZED
HVM_PARAM_IDENT_PT

2) hvm/hvm.c
hvm_set_param()

Quoted 10 lines
    ...
    case HVM_PARAM_IDENT_PT:

        if ( !paging_mode_hap(d) || !cpu_has_vmx )
        {
            d->arch.hvm.params[index] = value;
            break;
        }
        [unreachable for !cpu_has_vmx case]
        ...

nit: These (1) and (2) are rather large for a commit message. I wouldn't mind if they went away and the rest of the commit message was adjusted to make it a bit leaner.

Either way, with or without this change...

Quoted 9 lines

Hence HVM_PARAM_IDENT_PT/HVM_PARAM_VM86_TSS_SIZED are used only by VMX code above code become unreachable in !cpu_has_vmx case and can be optimazed when !CONFIG_INTEL_VMX.

Replace "cpu_has_vmx" with using_vmx() to account !CONFIG_INTEL_VMX and allow compiler DCE to optimize code.

... Reviewed-by: Alejandro Vallejo <[email protected]>

Cheers,
Alejandro

Reviewed-by on v1 1/1
#2 lore raw
In reply to Grygorii Strashko
Quoted 32 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Since commit b99227347230 ("x86: Fix AMD_SVM and INTEL_VMX dependency") the HVM Intel VT-x support can be disabled, but it still keeps VMX code partially built-in. Particularly in HVM code there are two places:

1) hvm/dom0_build.c
dom0_construct_pvh()->pvh_populate_p2m()

    ...
    if ( cpu_has_vmx && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
    {
        ...
        [unreachable for !cpu_has_vmx case]
        rc = pvh_setup_vmx_realmode_helpers(d);

pvh_setup_vmx_realmode_helpers() allocates memory and configures
HVM_PARAM_VM86_TSS_SIZED
HVM_PARAM_IDENT_PT

2) hvm/hvm.c
hvm_set_param()

    ...
    case HVM_PARAM_IDENT_PT:

        if ( !paging_mode_hap(d) || !cpu_has_vmx )
        {
            d->arch.hvm.params[index] = value;
            break;
        }
        [unreachable for !cpu_has_vmx case]
        ...
Quoted 8 lines

Hence HVM_PARAM_IDENT_PT/HVM_PARAM_VM86_TSS_SIZED are used only by VMX code above code become unreachable in !cpu_has_vmx case and can be optimazed when !CONFIG_INTEL_VMX.

Replace "cpu_has_vmx" with using_vmx() to account !CONFIG_INTEL_VMX and allow compiler DCE to optimize code.

#3 lore raw
In reply to Grygorii Strashko

Hi

Could it be merged if no other comments, please?

Quoted 77 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Since commit b99227347230 ("x86: Fix AMD_SVM and INTEL_VMX dependency") the HVM Intel VT-x support can be disabled, but it still keeps VMX code partially built-in. Particularly in HVM code there are two places:

1) hvm/dom0_build.c
dom0_construct_pvh()->pvh_populate_p2m()

     ...
     if ( cpu_has_vmx && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
     {
         ...
         [unreachable for !cpu_has_vmx case]
         rc = pvh_setup_vmx_realmode_helpers(d);

pvh_setup_vmx_realmode_helpers() allocates memory and configures
HVM_PARAM_VM86_TSS_SIZED
HVM_PARAM_IDENT_PT

2) hvm/hvm.c
hvm_set_param()

     ...
     case HVM_PARAM_IDENT_PT:

         if ( !paging_mode_hap(d) || !cpu_has_vmx )
         {
             d->arch.hvm.params[index] = value;
             break;
         }
         [unreachable for !cpu_has_vmx case]
         ...

Hence HVM_PARAM_IDENT_PT/HVM_PARAM_VM86_TSS_SIZED are used only by VMX code above code become unreachable in !cpu_has_vmx case and can be optimazed when !CONFIG_INTEL_VMX.

Replace "cpu_has_vmx" with using_vmx() to account !CONFIG_INTEL_VMX and allow compiler DCE to optimize code.

---
add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-604 (-604)
Function old new delta

hvm_set_param                               1602    1473    -129
dom0_construct_pvh                          4438    3963    -475

Total: Before=3567191, After=3566587, chg -0.02%

  xen/arch/x86/hvm/dom0_build.c | 2 +-
  xen/arch/x86/hvm/hvm.c        | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/dom0_build.c +1 -1
index 5551f9044836..5ac2cf8394d8 100644
@@ -473,7 +473,7 @@ static int __init pvh_populate_p2m(struct domain *d)
          }
      }
 
-    if ( cpu_has_vmx && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
+    if ( using_vmx() && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
      {
          /*
           * Since Dom0 cannot be migrated, we will only setup the
xen/arch/x86/hvm/hvm.c +1 -1
index 95a80369b9b8..70331aeec9a0 100644
@@ -4302,7 +4302,7 @@ static int hvm_set_param(struct domain *d, uint32_t index, uint64_t value)
           * Only actually required for VT-x lacking unrestricted_guest
           * capabilities.  Short circuit the pause if possible.
           */
-        if ( !paging_mode_hap(d) || !cpu_has_vmx )
+        if ( !paging_mode_hap(d) || !using_vmx() )
          {
              d->arch.hvm.params[index] = value;
              break;
Signature · 2 lines
Best regards,
-grygorii
#4 lore raw
Quoted 1 line · Grygorii Strashko

Could it be merged if no other comments, please?

It's on my list of things to put in. However, since you ask: You do realize that all your recent postings were while the tree was frozen? That's okay-ish, but when preparing a release people would preferably focus on the release, not on what is to come afterwards. This change of yours, like quite a few from others, will need to wait until the tree is fully open again. It having been progressed to the point where it can in principle go in was already a courtesy, considering the timing.

Jan

Quoted 79 lines · Grygorii Strashko
Quoted 77 lines

From: Grygorii Strashko <[email protected]>

Since commit b99227347230 ("x86: Fix AMD_SVM and INTEL_VMX dependency") the HVM Intel VT-x support can be disabled, but it still keeps VMX code partially built-in. Particularly in HVM code there are two places:

1) hvm/dom0_build.c
dom0_construct_pvh()->pvh_populate_p2m()

     ...
     if ( cpu_has_vmx && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
     {
         ...
         [unreachable for !cpu_has_vmx case]
         rc = pvh_setup_vmx_realmode_helpers(d);

pvh_setup_vmx_realmode_helpers() allocates memory and configures
HVM_PARAM_VM86_TSS_SIZED
HVM_PARAM_IDENT_PT

2) hvm/hvm.c
hvm_set_param()

     ...
     case HVM_PARAM_IDENT_PT:

         if ( !paging_mode_hap(d) || !cpu_has_vmx )
         {
             d->arch.hvm.params[index] = value;
             break;
         }
         [unreachable for !cpu_has_vmx case]
         ...

Hence HVM_PARAM_IDENT_PT/HVM_PARAM_VM86_TSS_SIZED are used only by VMX code above code become unreachable in !cpu_has_vmx case and can be optimazed when !CONFIG_INTEL_VMX.

Replace "cpu_has_vmx" with using_vmx() to account !CONFIG_INTEL_VMX and allow compiler DCE to optimize code.

---
add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-604 (-604)
Function old new delta

hvm_set_param                               1602    1473    -129
dom0_construct_pvh                          4438    3963    -475

Total: Before=3567191, After=3566587, chg -0.02%

  xen/arch/x86/hvm/dom0_build.c | 2 +-
  xen/arch/x86/hvm/hvm.c        | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/dom0_build.c +1 -1
index 5551f9044836..5ac2cf8394d8 100644
@@ -473,7 +473,7 @@ static int __init pvh_populate_p2m(struct domain *d)
          }
      }
 
-    if ( cpu_has_vmx && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
+    if ( using_vmx() && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
      {
          /*
           * Since Dom0 cannot be migrated, we will only setup the
xen/arch/x86/hvm/hvm.c +1 -1
index 95a80369b9b8..70331aeec9a0 100644
@@ -4302,7 +4302,7 @@ static int hvm_set_param(struct domain *d, uint32_t index, uint64_t value)
           * Only actually required for VT-x lacking unrestricted_guest
           * capabilities.  Short circuit the pause if possible.
           */
-        if ( !paging_mode_hap(d) || !cpu_has_vmx )
+        if ( !paging_mode_hap(d) || !using_vmx() )
          {
              d->arch.hvm.params[index] = value;
              break;
#5 lore raw

Hi Jan,

Quoted 11 lines · Jan Beulich
Quoted 1 line · Grygorii Strashko

Could it be merged if no other comments, please?

It's on my list of things to put in. However, since you ask: You do realize that all your recent postings were while the tree was frozen? That's okay-ish, but when preparing a release people would preferably focus on the release, not on what is to come afterwards. This change of yours, like quite a few from others, will need to wait until the tree is fully open again. It having been progressed to the point where it can in principle go in was already a courtesy, considering the timing.

I'm very sorry for disturbing you and being annoying in this regards.

Quoted 81 lines
Quoted 80 lines · Grygorii Strashko
Quoted 77 lines

From: Grygorii Strashko <[email protected]>

Since commit b99227347230 ("x86: Fix AMD_SVM and INTEL_VMX dependency") the HVM Intel VT-x support can be disabled, but it still keeps VMX code partially built-in. Particularly in HVM code there are two places:

1) hvm/dom0_build.c
dom0_construct_pvh()->pvh_populate_p2m()

      ...
      if ( cpu_has_vmx && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
      {
          ...
          [unreachable for !cpu_has_vmx case]
          rc = pvh_setup_vmx_realmode_helpers(d);

pvh_setup_vmx_realmode_helpers() allocates memory and configures
HVM_PARAM_VM86_TSS_SIZED
HVM_PARAM_IDENT_PT

2) hvm/hvm.c
hvm_set_param()

      ...
      case HVM_PARAM_IDENT_PT:

          if ( !paging_mode_hap(d) || !cpu_has_vmx )
          {
              d->arch.hvm.params[index] = value;
              break;
          }
          [unreachable for !cpu_has_vmx case]
          ...

Hence HVM_PARAM_IDENT_PT/HVM_PARAM_VM86_TSS_SIZED are used only by VMX code above code become unreachable in !cpu_has_vmx case and can be optimazed when !CONFIG_INTEL_VMX.

Replace "cpu_has_vmx" with using_vmx() to account !CONFIG_INTEL_VMX and allow compiler DCE to optimize code.

---
add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-604 (-604)
Function old new delta

hvm_set_param                               1602    1473    -129
dom0_construct_pvh                          4438    3963    -475

Total: Before=3567191, After=3566587, chg -0.02%

   xen/arch/x86/hvm/dom0_build.c | 2 +-
   xen/arch/x86/hvm/hvm.c        | 2 +-
   2 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/dom0_build.c +1 -1
index 5551f9044836..5ac2cf8394d8 100644
@@ -473,7 +473,7 @@ static int __init pvh_populate_p2m(struct domain *d)
           }
       }
 
-    if ( cpu_has_vmx && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
+    if ( using_vmx() && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
       {
           /*
            * Since Dom0 cannot be migrated, we will only setup the
xen/arch/x86/hvm/hvm.c +1 -1
index 95a80369b9b8..70331aeec9a0 100644
@@ -4302,7 +4302,7 @@ static int hvm_set_param(struct domain *d, uint32_t index, uint64_t value)
            * Only actually required for VT-x lacking unrestricted_guest
            * capabilities.  Short circuit the pause if possible.
            */
-        if ( !paging_mode_hap(d) || !cpu_has_vmx )
+        if ( !paging_mode_hap(d) || !using_vmx() )
           {
               d->arch.hvm.params[index] = value;
               break;
Signature · 2 lines
Best regards,
-grygorii