Skip to contentSkip to conversation

Check allocations when starting HVM domains

PATCH New Charles Coffing 1 participant 1 message May 18, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Check allocations when starting HVM domains

Several page allocations, done in the hypervisor when starting an HVM domain, are not checked. This can cause the physical machine to crash when starting the HVM domain during low-memory conditions.

One patch is against xen-3.0-testing; the other is for xen-unstable.

Kudos to Charles Arnold for catching the problem with shadow_direct_map_init.

Thanks.

xen/arch/x86/hvm/hvm.c +5 -1
Index: xen-3.0-testing/xen/arch/x86/hvm/hvm.c
===================================================================
@@ -189,7 +189,11 @@ void hvm_setup_platform(struct domain* d
     if ( !hvm_guest(current) || (current->vcpu_id != 0) )
         return;
 
-    shadow_direct_map_init(d);
+    if ( shadow_direct_map_init(d) == 0 )
+    {
+        printk("Can not allocate shadow direct map for HVM domain.\n");
+        domain_crash_synchronous();
+    }
 
     hvm_map_io_shared_page(d);
     hvm_get_info(d);
xen/arch/x86/hvm/svm/svm.c +3 -1
Index: xen-3.0-testing/xen/arch/x86/hvm/svm/svm.c
===================================================================
@@ -451,6 +451,9 @@ int start_svm(void)
     
     if (!(test_bit(X86_FEATURE_SVME, &boot_cpu_data.x86_capability)))
         return 0;
+    host_save_area[ cpu ] = alloc_host_save_area();
+    if (! host_save_area[ cpu ])
+        return 0;
     
     rdmsr(MSR_EFER, eax, edx);
     eax |= EFER_SVME;
@@ -459,7 +462,6 @@ int start_svm(void)
     printk("AMD SVM Extension is enabled for cpu %d.\n", cpu );
 
     /* Initialize the HSA for this core */
-    host_save_area[ cpu ] = alloc_host_save_area();
     phys_hsa = (u64) virt_to_maddr( host_save_area[ cpu ] ); 
     phys_hsa_lo = (u32) phys_hsa;
     phys_hsa_hi = (u32) (phys_hsa >> 32);    
xen/arch/x86/hvm/svm/vmcb.c +10 -7
Index: xen-3.0-testing/xen/arch/x86/hvm/svm/vmcb.c
===================================================================
@@ -143,18 +143,21 @@ static int construct_vmcb_controls(struc
 
     /* The following is for I/O and MSR permision map */
     iopm = alloc_xenheap_pages(get_order_from_bytes(IOPM_SIZE));
-
-    ASSERT(iopm);
-    memset(iopm, 0xff, IOPM_SIZE);
-    clear_bit(PC_DEBUG_PORT, iopm);
+    if (iopm)
+    {
+        memset(iopm, 0xff, IOPM_SIZE);
+        clear_bit(PC_DEBUG_PORT, iopm);
+    }
     msrpm = alloc_xenheap_pages(get_order_from_bytes(MSRPM_SIZE));
-
-    ASSERT(msrpm);
-    memset(msrpm, 0xff, MSRPM_SIZE);
+    if (msrpm)
+        memset(msrpm, 0xff, MSRPM_SIZE);
 
     arch_svm->iopm = iopm;
     arch_svm->msrpm = msrpm;
 
+    if (! iopm || ! msrpm)
+        return 1;
+
     vmcb->iopm_base_pa = (u64) virt_to_maddr(iopm);
     vmcb->msrpm_base_pa = (u64) virt_to_maddr(msrpm);
 
xen/arch/x86/hvm/hvm.c +5 -1
diff -ru a/xen/arch/x86/hvm/hvm.c xen-unstable.hg/xen/arch/x86/hvm/hvm.c
@@ -189,7 +189,11 @@
     if ( !hvm_guest(current) || (current->vcpu_id != 0) )
         return;
 
-    shadow_direct_map_init(d);
+    if ( shadow_direct_map_init(d) == 0 )
+    {
+        printk("Can not allocate shadow direct map for HVM domain.\n");
+        domain_crash_synchronous();
+    }
 
     hvm_map_io_shared_page(d);
     hvm_get_info(d);
xen/arch/x86/hvm/svm/svm.c +3 -1
diff -ru a/xen/arch/x86/hvm/svm/svm.c xen-unstable.hg/xen/arch/x86/hvm/svm/svm.c
@@ -458,6 +458,9 @@
     
     if (!(test_bit(X86_FEATURE_SVME, &boot_cpu_data.x86_capability)))
         return 0;
+    svm_globals[cpu].hsa = alloc_host_save_area();
+    if (! svm_globals[cpu].hsa)
+        return 0;
     
     rdmsr(MSR_EFER, eax, edx);
     eax |= EFER_SVME;
@@ -466,7 +469,6 @@
     printk("AMD SVM Extension is enabled for cpu %d.\n", cpu );
 
     /* Initialize the HSA for this core */
-    svm_globals[cpu].hsa = alloc_host_save_area();
     phys_hsa = (u64) virt_to_maddr( svm_globals[cpu].hsa ); 
     phys_hsa_lo = (u32) phys_hsa;
     phys_hsa_hi = (u32) (phys_hsa >> 32);    
xen/arch/x86/hvm/svm/vmcb.c +10 -7
diff -ru a/xen/arch/x86/hvm/svm/vmcb.c xen-unstable.hg/xen/arch/x86/hvm/svm/vmcb.c
@@ -139,18 +139,21 @@
 
     /* The following is for I/O and MSR permision map */
     iopm = alloc_xenheap_pages(get_order_from_bytes(IOPM_SIZE));
-
-    ASSERT(iopm);
-    memset(iopm, 0xff, IOPM_SIZE);
-    clear_bit(PC_DEBUG_PORT, iopm);
+    if (iopm)
+    {
+        memset(iopm, 0xff, IOPM_SIZE);
+        clear_bit(PC_DEBUG_PORT, iopm);
+    }
     msrpm = alloc_xenheap_pages(get_order_from_bytes(MSRPM_SIZE));
-
-    ASSERT(msrpm);
-    memset(msrpm, 0xff, MSRPM_SIZE);
+    if (msrpm)
+        memset(msrpm, 0xff, MSRPM_SIZE);
 
     arch_svm->iopm = iopm;
     arch_svm->msrpm = msrpm;
 
+    if (! iopm || ! msrpm)
+        return 1;
+
     vmcb->iopm_base_pa = (u64) virt_to_maddr(iopm);
     vmcb->msrpm_base_pa = (u64) virt_to_maddr(msrpm);
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel