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

[PATCH] vVMX: Cleanup partial vCPU initialization


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • Date: Fri, 24 Oct 2025 17:20:54 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • 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=6uUQTuet8fHMJ2w3FZTZuj/+41PlPOzUESjZXEwkEDA=; b=JuQgJwHboDcHXHZyT56hbHOwz6zCX2HkI/CRykevQdIZzpMVHChBPRn5kAJ0TgVyoU4Bn9fyJq0jMVVkMTfnP66yE6ZzEe5x3ul3uE1G1NbJSz0x75ru7xo4k2jNSnt1TRFWmw9+P3pA90CVEpoaVNgmDY8+GB0NF3VfUyH2l1kXXjNoWTTyrPbOfyMkD3pLW9ODWHmGhwja/vz8223fTTT2YagCwvPQAYvkFDZviGXbuUvIVDlGkBMy9dcj2uncCxFPP9UhrqnfTjidBiTskAD/n9Zc2DJdriQA0ohFkpRgyrPVxrMByenCVSSNJhhM2OVXE5IhHbIZzXp3hzD+Nw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=N5Z+a/GvLsGYtSEf70jhHJ39g11C/XMxbI0APvaz7Xr7bzEyAIB2thAyOKy9qfXnv1FPGbmYLJtsREYai7sT46mjPpvmUy2bfjCD/CzACj6QcBAup1WmnoNMm/oIO/vCTLDpiWsDyJj6/BXG4uqmuIGUWrLQwd8+Bd4mLRmn3OGAlSTcoWOMUcYuPZSQnayvcto/BDJfoKe+bL5s26jemgih6d3lzK08s1JzVozoLigVB1lVA081ju5S+W+6AayblY1EEew3tEaEhN+Cl+6DGNfiXh3NN4BKnHS01CFl0ZSOl3V5lKwOJ7GHVgTK2LRdRZwSce1erZipyxrS8t/IJA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Fri, 24 Oct 2025 16:21:27 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

If nested vCPU initialization fails, cleanup the allocated memory since
it is no longer handled by the caller.

Fixes: c47984aabead ("nvmx: implement support for MSR bitmaps")
Fixes: f5bdb4aaa165 ("x86/hvm: Obsolete the use of HVM_PARAM_NESTEDHVM")
Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
---
 xen/arch/x86/hvm/vmx/vvmx.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c
index e4f3a5fe4c71..cf9aecb4c3e4 100644
--- a/xen/arch/x86/hvm/vmx/vvmx.c
+++ b/xen/arch/x86/hvm/vmx/vvmx.c
@@ -53,6 +53,13 @@ void nvmx_cpu_dead(unsigned int cpu)
     XFREE(per_cpu(vvmcs_buf, cpu));
 }
 
+static void vcpu_relinquish_resources(struct vcpu *v)
+{
+    struct nestedvmx *nvmx = &vcpu_2_nvmx(v);
+
+    FREE_XENHEAP_PAGE(nvmx->msr_merged);
+}
+
 int cf_check nvmx_vcpu_initialise(struct vcpu *v)
 {
     struct domain *d = v->domain;
@@ -89,7 +96,7 @@ int cf_check nvmx_vcpu_initialise(struct vcpu *v)
         if ( !vmread_bitmap )
         {
             gdprintk(XENLOG_ERR, "nest: allocation for vmread bitmap 
failed\n");
-            return -ENOMEM;
+            goto err;
         }
         v->arch.hvm.vmx.vmread_bitmap = vmread_bitmap;
 
@@ -99,7 +106,7 @@ int cf_check nvmx_vcpu_initialise(struct vcpu *v)
         if ( !vmwrite_bitmap )
         {
             gdprintk(XENLOG_ERR, "nest: allocation for vmwrite bitmap 
failed\n");
-            return -ENOMEM;
+            goto err;
         }
         v->arch.hvm.vmx.vmwrite_bitmap = vmwrite_bitmap;
 
@@ -124,7 +131,7 @@ int cf_check nvmx_vcpu_initialise(struct vcpu *v)
     {
         nvmx->msr_merged = alloc_xenheap_page();
         if ( !nvmx->msr_merged )
-            return -ENOMEM;
+            goto err;
     }
 
     nvmx->ept.enabled = 0;
@@ -139,6 +146,11 @@ int cf_check nvmx_vcpu_initialise(struct vcpu *v)
     nvmx->msrbitmap = NULL;
     INIT_LIST_HEAD(&nvmx->launched_list);
     return 0;
+
+ err:
+    nvmx_vcpu_destroy(v);
+    vcpu_relinquish_resources(v);
+    return -ENOMEM;
 }
  
 void cf_check nvmx_vcpu_destroy(struct vcpu *v)
@@ -183,13 +195,6 @@ void cf_check nvmx_vcpu_destroy(struct vcpu *v)
     }
 }
 
-static void vcpu_relinquish_resources(struct vcpu *v)
-{
-    struct nestedvmx *nvmx = &vcpu_2_nvmx(v);
-
-    FREE_XENHEAP_PAGE(nvmx->msr_merged);
-}
-
 void cf_check nvmx_domain_relinquish_resources(struct domain *d)
 {
     struct vcpu *v;
-- 
2.51.0




 


Rackspace

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