Skip to contentSkip to conversation

x86/domain: Fix struct domain memory corruption when building PV guests

PATCH In review Andrew Cooper 2 participants 3 messages Aug 22, 2022 – Aug 23, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/domain: Fix struct domain memory corruption when building PV guests

arch_domain_create() can't blindly write into d->arch.hvm union. Move the logic into hvm_domain_initialise(), which involves passing config down.

Fixes 2ce11ce249a3 ("x86/HVM: allow per-domain usage of hardware virtualized APIC")

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jane Malalane <[email protected]>

This does not fix XenServer's wall of red from testing, but I have at least figured out what's going on. There's a piece of plain RAM in place of a working LAPIC MMIO mapping (accelerated or otherwise), which causes HVMLoader to spin in a tight loop waiting for CPU 1 to come up after failing to send an INIT-SIPI-SIPI.

Sadly the fix is not as straightforward as I'd hoped, and needs more testing.

---
 xen/arch/x86/domain.c              | 8 +-------
 xen/arch/x86/hvm/hvm.c             | 9 ++++++++-
 xen/arch/x86/include/asm/hvm/hvm.h | 3 ++-
 3 files changed, 11 insertions(+), 9 deletions(-)
xen/arch/x86/domain.c +1 -7
index 15e7e772012e..41e1e3f27272 100644
@@ -853,7 +853,7 @@ int arch_domain_create(struct domain *d,
 
     if ( is_hvm_domain(d) )
     {
-        if ( (rc = hvm_domain_initialise(d)) != 0 )
+        if ( (rc = hvm_domain_initialise(d, config)) != 0 )
             goto fail;
     }
     else if ( is_pv_domain(d) )
@@ -885,12 +885,6 @@ int arch_domain_create(struct domain *d,
 
     d->arch.msr_relaxed = config->arch.misc_flags & XEN_X86_MSR_RELAXED;
 
-    d->arch.hvm.assisted_xapic =
-        config->arch.misc_flags & XEN_X86_ASSISTED_XAPIC;
-
-    d->arch.hvm.assisted_x2apic =
-        config->arch.misc_flags & XEN_X86_ASSISTED_X2APIC;
-
     spec_ctrl_init_domain(d);
 
     return 0;
xen/arch/x86/hvm/hvm.c +8 -1
index 6b5d585ed4cc..ae8267852013 100644
@@ -576,7 +576,8 @@ static int cf_check hvm_print_line(
     return X86EMUL_OKAY;
 }
 
-int hvm_domain_initialise(struct domain *d)
+int hvm_domain_initialise(struct domain *d,
+                          struct xen_domctl_createdomain *config)
 {
     unsigned int nr_gsis;
     int rc;
@@ -597,6 +598,12 @@ int hvm_domain_initialise(struct domain *d)
     INIT_LIST_HEAD(&d->arch.hvm.mmcfg_regions);
     INIT_LIST_HEAD(&d->arch.hvm.msix_tables);
 
+    d->arch.hvm.assisted_xapic =
+        config->arch.misc_flags & XEN_X86_ASSISTED_XAPIC;
+
+    d->arch.hvm.assisted_x2apic =
+        config->arch.misc_flags & XEN_X86_ASSISTED_X2APIC;
+
     rc = create_perdomain_mapping(d, PERDOMAIN_VIRT_START, 0, NULL, NULL);
     if ( rc )
         goto fail;
xen/arch/x86/include/asm/hvm/hvm.h +2 -1
index 03096f31effa..55a53d9cac8f 100644
@@ -259,7 +259,8 @@ extern s8 hvm_port80_allowed;
 extern const struct hvm_function_table *start_svm(void);
 extern const struct hvm_function_table *start_vmx(void);
 
-int hvm_domain_initialise(struct domain *d);
+int hvm_domain_initialise(struct domain *d,
+                          struct xen_domctl_createdomain *config);
 void hvm_domain_relinquish_resources(struct domain *d);
 void hvm_domain_destroy(struct domain *d);
 
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Andrew Cooper

arch_domain_create() can't blindly write into d->arch.hvm union. Move the logic into hvm_domain_initialise(), which involves passing config down.

Fixes 2ce11ce249a3 ("x86/HVM: allow per-domain usage of hardware virtualized APIC")

preferably with a small adjustment (see below).

Quoted 5 lines

This does not fix XenServer's wall of red from testing, but I have at least figured out what's going on. There's a piece of plain RAM in place of a working LAPIC MMIO mapping (accelerated or otherwise), which causes HVMLoader to spin in a tight loop waiting for CPU 1 to come up after failing to send an INIT-SIPI-SIPI.

Where's that page of plain RAM coming from? And do you meanwhile understand why XenServer testing is exposing the issue while osstest isn't?

xen/arch/x86/hvm/hvm.c static int cf_check hvm_print_line( · line 580

Quoted 9 lines
xen/arch/x86/hvm/hvm.c +2 -1
@@ -576,7 +576,8 @@ static int cf_check hvm_print_line(
     return X86EMUL_OKAY;
 }
 
-int hvm_domain_initialise(struct domain *d)
+int hvm_domain_initialise(struct domain *d,
+                          struct xen_domctl_createdomain *config)

May I ask for const to be added here? Unless you anticipate the function might legitimately modify the config data?

Jan

#2 lore raw
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Andrew Cooper

arch_domain_create() can't blindly write into d->arch.hvm union. Move the logic into hvm_domain_initialise(), which involves passing config down.

Fixes 2ce11ce249a3 ("x86/HVM: allow per-domain usage of hardware virtualized APIC")

Thanks.

Quoted 8 lines
Quoted 5 lines

This does not fix XenServer's wall of red from testing, but I have at least figured out what's going on. There's a piece of plain RAM in place of a working LAPIC MMIO mapping (accelerated or otherwise), which causes HVMLoader to spin in a tight loop waiting for CPU 1 to come up after failing to send an INIT-SIPI-SIPI.

Where's that page of plain RAM coming from? And do you meanwhile understand why XenServer testing is exposing the issue while osstest isn't?

The sink page is allocated and inserted into the P2M based on hardware capabilities, and the VMCS is (not) configured using the new settings.

APIC-V is still fully disabled in XenServer because there are still interrupts lost on migration which take out Windows.  Jane's work was the very start of being able to test APIC acceleration rationally, and ultimately find a fix.

~Andrew