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

Re: [PATCH V2] xen/dom0less: Calculate guest DTB size based on MAX_VIRT_CPUS


  • To: Oleksandr Tyshchenko <Oleksandr_Tyshchenko@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • Date: Wed, 3 Dec 2025 22:15:04 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.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=NOFmLvdYGGyIfQP9eMobra+CovqHFu5AZXo6eqWj3uA=; b=fOaAR3kCCRqVlfScEJXmCYfPY3DPEpcRKmOIi9ptddKNvwS3z6M1FHZEt3V8bdIOjpst3p2/sQScagQTgCeYhkiqu9ahnMCE9YTYgP93chodszZNqh7PM0R1ec0tS3RkudBdHjK6w8BzQrEvZJNZ133zpaylvU1sVVCWGYp8fDG2rh5ZWaWF4VVz/ZsVWkYJKjSV/9F7WRCU1L55tvmvb7zwUXI+LJ1uusldGriCZEgJfad1ZIqg3N1iYLBQljrSjwTCaqw6aL18M1IUkEP9NEAYxsD/1VzV9L7t2YnqA5fXSq/mqa02oKA4f50lE890AObWCFa2724OziECNYDpDw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AmKDLmfGANVk+Fu9re2VY6n7uA7uL7RzfvrnQjCSIgJB1sXpqdlHgSpqjDya7O0OmvrDmzRN1JcG76Y8IzyT0pOU3D1z2vDnijRF4A5L2dtxUz1OdEqRRqyW6E/JQliOF5TQcT4cK578cZznkT5dOFZLjcN1KqV+brwAuvewEKTSUdMMg7UVbw5QzzPljT33+BUFPUXcY3USfu9aCqEUxeD2Cp1+UWmjhHvq0AgKfkUOUoujfOvVxEFa9Bh4yI02jQqLfRQEo2TnWfjL9yrOTjJoX0BTnQiYew3Ef3rej48tTqDdzoT2wzkiwER7OdkfR5W5PMYg0bbz25KWo2Jvtg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Wed, 03 Dec 2025 20:15:29 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>



On 03.12.25 20:58, Oleksandr Tyshchenko wrote:
Creating a dom0less guest with a high vCPU count (e.g., >32) fails
because the fixed 4KiB device tree buffer (DOMU_DTB_SIZE) overflows
during creation.

The FDT nodes for each vCPU are the primary consumer of space,
and the previous fixed-size buffer was insufficient.

This patch replaces the fixed size with a formula that calculates
the required buffer size based on a fixed baseline plus a scalable
portion for each potential vCPU up to the MAX_VIRT_CPUS limit.

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>
---
V1: 
https://patchew.org/Xen/20251202193246.3357821-1-oleksandr._5Ftyshchenko@xxxxxxxx/

   V2:
    - update commit subj/desc
    - use a formula that accounts MAX_VIRT_CPUS
    - add BUILD_BUG_ON
---
---
  xen/common/device-tree/dom0less-build.c | 16 +++++++++++++---
  1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/xen/common/device-tree/dom0less-build.c 
b/xen/common/device-tree/dom0less-build.c
index 3f5b987ed8..38a5830813 100644
--- a/xen/common/device-tree/dom0less-build.c
+++ b/xen/common/device-tree/dom0less-build.c
@@ -461,15 +461,25 @@ static int __init domain_handle_dtb_boot_module(struct 
domain *d,
/*
   * The max size for DT is 2MB. However, the generated DT is small (not 
including
- * domU passthrough DT nodes whose size we account separately), 4KB are enough
- * for now, but we might have to increase it in the future.
+ * domU passthrough DT nodes whose size we account separately). The size is
+ * calculated from a fixed baseline plus a scalable portion for each potential
+ * vCPU node up to the system limit (MAX_VIRT_CPUS), as the vCPU nodes are
+ * the primary consumer of space.
+ *
+ * The baseline of 2KiB is a safe buffer for all non-vCPU FDT content.
+ * Empirical testing with the maximum number of other device tree nodes shows
+ * a final compacted base size of ~1.5KiB. The 128 bytes per vCPU is derived
+ * from a worst-case analysis of the FDT construction-time size for a single
+ * vCPU node.
   */
-#define DOMU_DTB_SIZE 4096
+#define DOMU_DTB_SIZE (2048 + (MAX_VIRT_CPUS * 128))
  static int __init prepare_dtb_domU(struct domain *d, struct kernel_info 
*kinfo)
  {
      int addrcells, sizecells;
      int ret, fdt_size = DOMU_DTB_SIZE;
+ BUILD_BUG_ON(DOMU_DTB_SIZE > SZ_2M);
+
      kinfo->phandle_intc = GUEST_PHANDLE_GIC;
#ifdef CONFIG_GRANT_TABLE

Reviewed-by: Grygorii Strashko <grygorii_strashko@xxxxxxxx>

--
Best regards,
-grygorii




 


Rackspace

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