xen/dom0less: Calculate guest DTB size based on MAX_VIRT_CPUS
PATCH v2 1/1 xen/dom0less: Calculate guest DTB size based on MAX_VIRT_CPUS
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.
---
V1: https://patchew.org/Xen/[email protected]/
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(-)
xen/common/device-tree/dom0less-build.c +13 -3
@@ -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
Signature · 1 line
2.34.1
Quoted 47 lines · Oleksandr Tyshchenko
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_CPUSlimit.Signed-off-by Oleksandr Tyshchenko <[email protected]>---
V1: https://patchew.org/Xen/[email protected]/V2:
- update commit subj/desc
- use a formula that accountsMAX_VIRT_CPUS
- addBUILD_BUG_ON
------ xen/common/device-tree/dom0less-build.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)xen/common/device-tree/dom0less-build.c +11
-3@@ -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))
xen/common/device-tree/dom0less-build.c static int __init domain_handle_dtb_boot_module(struct domain *d, · line 485
Quoted 10 lines
xen/common/device-tree/dom0less-build.c +2
-0static 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
Signature · 2 lines
Best regards, -grygorii
Hi,
Quoted 30 lines · Oleksandr Tyshchenko
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_CPUSlimit.Signed-off-by Oleksandr Tyshchenko <[email protected]>---
V1: https://patchew.org/Xen/[email protected]/V2:
- update commit subj/desc
- use a formula that accountsMAX_VIRT_CPUS
- addBUILD_BUG_ON
------ xen/common/device-tree/dom0less-build.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)xen/common/device-tree/dom0less-build.c +0
-0@@ -461,15 +461,25 @@ static int __init domain_handle_dtb_boot_module(struct domain *d,
xen/common/device-tree/dom0less-build.c static int __init domain_handle_dtb_boot_module(struct domain *d, · line 469
Quoted 10 lines
xen/common/device-tree/dom0less-build.c +6
-2/* * 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.
What if the use decides to pass a DTB fragment? How do we know this will fit in the 2KiB?
xen/common/device-tree/dom0less-build.c static int __init domain_handle_dtb_boot_module(struct domain *d, · line 473
Quoted 4 lines
xen/common/device-tree/dom0less-build.c +4
-0+* 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.
For in-code documentation, this is ok to just provide some numbers. But this needs a bit more details in the commit message with the exact tests you did. This would be helpful if we ever need to change the size (for instance we could have extra emulated devices or we need another property per CPU).
xen/common/device-tree/dom0less-build.c static int __init domain_handle_dtb_boot_module(struct domain *d, · line 475
Quoted 3 lines
xen/common/device-tree/dom0less-build.c +1
-1*/ -#define DOMU_DTB_SIZE 4096 +#define DOMU_DTB_SIZE (2048 + (MAX_VIRT_CPUS * 128))
On Arm32, MAX_VIRT_CPUS is 8. This means the new DOMU_DTB_SIZE is going to be smaller than 4096. Why is it ok?
xen/common/device-tree/dom0less-build.c static int __init domain_handle_dtb_boot_module(struct domain *d, · line 485
Quoted 10 lines
xen/common/device-tree/dom0less-build.c +2
-0static 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
Cheers,
Signature · 1 line
Julien Grall
Quoted 1 line · Julien Grall
Hi,
Hello Julien
Quoted 45 lines · Oleksandr Tyshchenko
Quoted 43 lines
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_CPUSlimit.Signed-off-by Oleksandr Tyshchenko <[email protected]>---
V1: https://eur01.safelinks.protection.outlook.com/?
url=https%3A%2F%2Fpatchew.org%2FXen%2F20251202193246.3357821-1- oleksandr._5Ftyshchenko%40epam.com%2F&data=05%7C02%7COleksandr_Tyshchenko%40epam.com%7C57bf7711ac4747de3d2f08de32b069ce%7Cb41b72d04e9f4c268a69f949f367c91d%7C1%7C0%7C639003930443970639%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=u6pp39%2FVto2vU7Hp5aXl46VF4zDvD8C79Xp09bbowS4%3D&reserved=0V2:
- update commit subj/desc
- use a formula that accountsMAX_VIRT_CPUS
- addBUILD_BUG_ON
---
---
xen/common/device-tree/dom0less-build.c| 16 +++++++++++++---1 file changed, 13 insertions(+), 3 deletions(-)xen/common/ renamed from xen/common/device-tree/dom0less-build.c +0
-0
device-tree/dom0less-build.c
index3f5b987ed8..38a5830813100644xen/common/device-tree/dom0less-build.c +0
-0@@ -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
Quoted 8 lines
Quoted 5 lines
+ * 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.What if the use decides to pass a DTB fragment? How do we know this will fit in the 2KiB?
If a partial device tree is provided then it will be accounted separately. There is a code, non-visible is the context, so I think, we are good here.
/* Account for domU passthrough DT size */
if ( kinfo->dtb )
fdt_size += kinfo->dtb->size;Quoted 9 lines
Quoted 8 lines
+ * 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.
Quoted 5 lines
For in-code documentation, this is ok to just provide some numbers. But this needs a bit more details in the commit message with the exact tests you did. This would be helpful if we ever need to change the size (for instance we could have extra emulated devices or we need another property per CPU).
ok, I will add my testing details into the commit description.
Quoted 7 lines
xen/common/device-tree/dom0less-build.c
Quoted 4 lines
*/
xen/common/device-tree/dom0less-build.c +1
-1-#define DOMU_DTB_SIZE 4096 +#define DOMU_DTB_SIZE (2048 + (MAX_VIRT_CPUS * 128))On Arm32,
MAX_VIRT_CPUSis 8. This means the newDOMU_DTB_SIZEis going to be smaller than 4096. Why is it ok?
You are correct to question the impact on Arm32, where MAX_VIRT_CPUS is smaller, leading to a calculated buffer size of 3072 bytes, which is less than the original 4096 bytes.
Unfortunately, I have no possibility to test on Arm32. But, I do not see much difference between Arm64 and Arm32 in the context of DomU device tree generation by looking into the code.
I simulated this exact environment on my Arm64 setup to validate that the new size remains sufficient. To do this, I temporarily switched MAX_VIRT_CPUS to 8 and ran tests with 1 and 8 vCPUs.
(quoted diff) +0 -0
b/xen/common/device-tree/dom0less-build.c
index 38a5830813..0c64b9dfb7 100644
xen/common/device-tree/dom0less-build.c +0 -0
@@ -472,7 +472,7 @@ static int __init
domain_handle_dtb_boot_module(struct domain *d,
* from a worst-case analysis of the FDT construction-time size for a
single
* vCPU node.
*/
-#define DOMU_DTB_SIZE (2048 + (MAX_VIRT_CPUS * 128)) +#define DOMU_DTB_SIZE (2048 + (8 * 128))
static int __init prepare_dtb_domU(struct domain *d, structkernel_info *kinfo)
{
int addrcells, sizecells;
@@ -577,6 +577,9 @@ static int __init prepare_dtb_domU(struct domain *d,
struct kernel_info *kinfo)
if ( ret < 0 )
goto err;+ printk("Final compacted FDT size is: %d bytes\n",fdt_totalsize(kinfo->fdt));
+ printk("Predefined FDT size is: %d bytes\n", DOMU_DTB_SIZE);
+
return 0;
err:(END)
cpus=1
(XEN) Final compacted FDT size is: 1586 bytes
(XEN) Predefined FDT size is: 3072 bytes
cpus=8
(XEN) Final compacted FDT size is: 2370 bytes
(XEN) Predefined FDT size is: 3072 bytes
Also, if I understand the code correctly, on Arm32 the "enable-method = "psci" is not added to the generated device tree, so Arm32's vCPU node would require less space.
if ( is_64bit_domain(d) )
{
res = fdt_property_string(fdt, "enable-method", "psci");
if ( res )
return res;
}Quoted 13 lines
Quoted 10 lines
static int
__initprepare_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; #ifdefCONFIG_GRANT_TABLECheers,
Hi Oleksandr,
Quoted 9 lines
Quoted 8 lines
Review
Quoted 5 lines
*/(quoted diff) +1
-1-#define DOMU_DTB_SIZE 4096 +#define DOMU_DTB_SIZE (2048 + (MAX_VIRT_CPUS * 128))On Arm32,
MAX_VIRT_CPUSis 8. This means the newDOMU_DTB_SIZEis going to be smaller than 4096. Why is it ok?
Quoted 7 lines
You are correct to question the impact on Arm32, where
MAX_VIRT_CPUSis smaller, leading to a calculated buffer size of 3072 bytes, which is less than the original 4096 bytes.Unfortunately, I have no possibility to test on Arm32. But, I do not see much difference between Arm64 and Arm32 in the context of DomU device tree generation by looking into the code.
Let me know what kind of test you need, we have some arm32 setup here (not HW, virtual platforms).
Cheers,
Luca
Quoted 3 lines · Luca Fancellu
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
Hi Oleksandr,
Hello Luca
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
Review
Quoted 6 lines
*/(quoted diff) +1
-1-#define DOMU_DTB_SIZE 4096 +#define DOMU_DTB_SIZE (2048 + (MAX_VIRT_CPUS * 128))On Arm32,
MAX_VIRT_CPUSis 8. This means the newDOMU_DTB_SIZEis going to be smaller than 4096. Why is it ok?You are correct to question the impact on Arm32, where
MAX_VIRT_CPUSis smaller, leading to a calculated buffer size of 3072 bytes, which is less than the original 4096 bytes.
Quoted 5 lines
Quoted 3 lines
Unfortunately, I have no possibility to test on Arm32. But, I do not see much difference between Arm64 and Arm32 in the context of DomU device tree generation by looking into the code.
Let me know what kind of test you need, we have some arm32 setup here (not HW, virtual platforms).
Thank you very much for offering to test this on Arm32 platforms.
The primary goal of the test is to confirm that the new, calculated DTB buffer size of 3072 bytes is sufficient for a worst-case Arm32 dom0less guest. The expected result is that Xen boots successfully, and the regular dom0less guest is created without any panics.
The ideal test configuration would be a dom0less guest with the following configuration:
- The vCPU count set to the maximum for Arm32, which is 8, the vCPU nodes should ideally contain "clock-frequency" property.
- Any other features that add nodes to the guest device tree enabled (e.g., hypervisor, reserved-memory, pl011 nodes are present, etc), to create the largest possible "base" FDT size.
The test would involve applying the current patch, and the diff below:
(quoted diff) +0 -0
b/xen/common/device-tree/dom0less-build.c
index 38a5830813..e95f42d1e1 100644
xen/common/device-tree/dom0less-build.c +0 -0
@@ -577,6 +577,9 @@ static int __init prepare_dtb_domU(struct domain *d,
struct kernel_info *kinfo)
if ( ret < 0 )
goto err;+ printk("Final compacted FDT size is: %d bytes\n",fdt_totalsize(kinfo->fdt));
+ printk("Predefined FDT size is: %d bytes\n", DOMU_DTB_SIZE);
+
return 0;
err:Please let me know what you get. Thanks again.
Quoted 4 lines
Cheers,
Luca
Harry Ramsey
Tested-byQuoted 33 lines · Oleksandr Tyshchenko
Thank you very much for offering to test this on Arm32 platforms.
The primary goal of the test is to confirm that the new, calculated DTB buffer size of 3072 bytes is sufficient for a worst-case Arm32 dom0less guest. The expected result is that Xen boots successfully, and the regular dom0less guest is created without any panics.
The ideal test configuration would be a dom0less guest with the following configuration:
- The vCPU count set to the maximum for Arm32, which is 8, the vCPU nodes should ideally contain "clock-frequency" property.
- Any other features that add nodes to the guest device tree enabled (e.g., hypervisor, reserved-memory, pl011 nodes are present, etc), to create the largest possible "base" FDT size.The test would involve applying the current patch, and the diff below:
xen/common/device-tree/dom0less-build.c +3
-0@@ -577,6 +577,9 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)if ( ret <0 ) goto err; +printk ("Final compacted FDT size is: %d bytes\n" ,fdt_totalsize (kinfo->fdt)); +printk ("Predefined FDT size is: %d bytes\n" ,DOMU_DTB_SIZE ); +return 0 ;
Quoted 4 lines
err:
Please let me know what you get. Thanks again.
I have tested this and can confirm it boots into Linux with an 8-core setup. Here are the values I got:
(XEN) Final compacted FDT size is: 1127 bytes
(XEN) Predefined FDT size is: 3072 bytes
Thanks,
Harry Ramsey
On 16.12.25 17:00, Harry Ramsey wrote:
Hello Harry
Quoted 40 lines
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
Quoted 36 lines · Oleksandr Tyshchenko
Thank you very much for offering to test this on Arm32 platforms.
The primary goal of the test is to confirm that the new, calculated DTB buffer size of 3072 bytes is sufficient for a worst-case Arm32 dom0less guest. The expected result is that Xen boots successfully, and the regular dom0less guest is created without any panics.
The ideal test configuration would be a dom0less guest with the following configuration:
- The vCPU count set to the maximum for Arm32, which is 8, the vCPU nodes should ideally contain "clock-frequency" property.
- Any other features that add nodes to the guest device tree enabled (e.g., hypervisor, reserved-memory, pl011 nodes are present, etc), to create the largest possible "base" FDT size.The test would involve applying the current patch, and the diff below:
xen/common/device-tree/dom0less-build.c +3
-0@@ -577,6 +577,9 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) if ( ret < 0 ) goto err; + printk("Final compacted FDT size is: %d bytes\n",fdt_totalsize (kinfo->fdt)); + printk("Predefined FDT size is: %d bytes\n", DOMU_DTB_SIZE); + return 0;err:
Quoted 8 lines
Quoted 1 line
Please let me know what you get. Thanks again.
I have tested this and can confirm it boots into Linux with an 8-core setup. Here are the values I got:
(XEN) Final compacted FDT size is: 1127 bytes
(XEN) Predefined FDT size is: 3072 bytesTested-by Harry Ramsey <[email protected]>
Thank you very much for testing on the Arm32 platform and confirming that the proposed size is sufficient!
Quoted 3 lines
Thanks,
Harry Ramsey
Quoted 61 lines · Oleksandr Tyshchenko
Quoted 1 line · Julien Grall
Hi,
Hello Julien
Quoted 45 lines · Oleksandr Tyshchenko
Quoted 43 lines
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_CPUSlimit.Signed-off-by Oleksandr Tyshchenko <[email protected]>---
V1: https://eur01.safelinks.protection.outlook.com/?
url=https%3A%2F%2Fpatchew.org%2FXen%2F20251202193246.3357821-1- oleksandr._5Ftyshchenko%40epam.com%2F&data=05%7C02%7COleksandr_Tyshchenko%40epam.com%7C57bf7711ac4747de3d2f08de32b069ce%7Cb41b72d04e9f4c268a69f949f367c91d%7C1%7C0%7C639003930443970639%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=u6pp39%2FVto2vU7Hp5aXl46VF4zDvD8C79Xp09bbowS4%3D&reserved=0V2:
- update commit subj/desc
- use a formula that accountsMAX_VIRT_CPUS
- addBUILD_BUG_ON
------ xen/common/device-tree/dom0less-build.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)xen/common/ renamed from xen/common/device-tree/dom0less-build.c +0
-0
device-tree/dom0less-build.c
index3f5b987ed8..38a5830813100644xen/common/device-tree/dom0less-build.c +0
-0@@ -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 potentialQuoted 8 lines
Quoted 5 lines
+ * 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.What if the use decides to pass a DTB fragment? How do we know this will fit in the 2KiB?
Quoted 3 lines
If a partial device tree is provided then it will be accounted separately. There is a code, non-visible is the context, so I think, we are good here.
Ah yes! I missed that code. Sorry for the noise.
Quoted 31 lines
Quoted 11 lines
Quoted 10 lines
+ * 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.Quoted 5 lines
For in-code documentation, this is ok to just provide some numbers. But this needs a bit more details in the commit message with the exact tests you did. This would be helpful if we ever need to change the size (for instance we could have extra emulated devices or we need another property per CPU).
ok, I will add my testing details into the commit description.
Quoted 7 lines
xen/common/device-tree/dom0less-build.c
Quoted 4 lines
*/
xen/common/device-tree/dom0less-build.c +1
-1-#define DOMU_DTB_SIZE 4096 +#define DOMU_DTB_SIZE (2048 + (MAX_VIRT_CPUS * 128))On Arm32,
MAX_VIRT_CPUSis 8. This means the newDOMU_DTB_SIZEis going to be smaller than 4096. Why is it ok?You are correct to question the impact on Arm32, where
MAX_VIRT_CPUSis smaller, leading to a calculated buffer size of 3072 bytes, which is less than the original 4096 bytes.
Quoted 7 lines
Unfortunately, I have no possibility to test on Arm32. But, I do not see much difference between Arm64 and Arm32 in the context of DomU device tree generation by looking into the code.
I simulated this exact environment on my Arm64 setup to validate that the new size remains sufficient. To do this, I temporarily switched
MAX_VIRT_CPUSto 8 and ran tests with 1 and 8 vCPUs.
Thanks for doing that! I also see Luca is going to help. If he also confirms the size is good then can you mention the change for Arm 32-bit?
Cheers,
Signature · 1 line
Julien Grall
On 04.12.25 16:21, Julien Grall wrote:
Hello Julien
Quoted 105 lines · Oleksandr Tyshchenko
Quoted 61 lines · Julien Grall
Quoted 1 line
Hi,
Hello Julien
Quoted 45 lines · Oleksandr Tyshchenko
Quoted 43 lines
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_CPUSlimit.Signed-off-by Oleksandr Tyshchenko <[email protected]>---
V1: https://eur01.safelinks.protection.outlook.com/?
url=https%3A%2F%2Fpatchew.org%2FXen%2F20251202193246.3357821-1- oleksandr._5Ftyshchenko%40epam.com%2F&data=05%7C02%7COleksandr_Tyshchenko%40epam.com%7C57bf7711ac4747de3d2f08de32b069ce%7Cb41b72d04e9f4c268a69f949f367c91d%7C1%7C0%7C639003930443970639%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=u6pp39%2FVto2vU7Hp5aXl46VF4zDvD8C79Xp09bbowS4%3D&reserved=0V2:
- update commit subj/desc
- use a formula that accountsMAX_VIRT_CPUS
- addBUILD_BUG_ON
---
---
xen/common/device-tree/dom0less-build.c| 16 +++++++++++++---1 file changed, 13 insertions(+), 3 deletions(-)xen/common/ renamed from xen/common/device-tree/dom0less-build.c +0
-0
device-tree/dom0less-build.c
index3f5b987ed8..38a5830813100644xen/common/device-tree/dom0less-build.c +0
-0@@ -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 potentialQuoted 8 lines
Quoted 5 lines
+ * 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.What if the use decides to pass a DTB fragment? How do we know this will fit in the 2KiB?
Quoted 3 lines
If a partial device tree is provided then it will be accounted separately. There is a code, non-visible is the context, so I think, we are good here.
Ah yes! I missed that code. Sorry for the noise.
Quoted 35 lines
Quoted 11 lines
Quoted 10 lines
+ * 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.Quoted 5 lines
For in-code documentation, this is ok to just provide some numbers. But this needs a bit more details in the commit message with the exact tests you did. This would be helpful if we ever need to change the size (for instance we could have extra emulated devices or we need another property per CPU).
ok, I will add my testing details into the commit description.
Quoted 7 lines
xen/common/device-tree/dom0less-build.c
Quoted 4 lines
*/
xen/common/device-tree/dom0less-build.c +1
-1-#define DOMU_DTB_SIZE 4096 +#define DOMU_DTB_SIZE (2048 + (MAX_VIRT_CPUS * 128))On Arm32,
MAX_VIRT_CPUSis 8. This means the newDOMU_DTB_SIZEis going to be smaller than 4096. Why is it ok?You are correct to question the impact on Arm32, where
MAX_VIRT_CPUSis smaller, leading to a calculated buffer size of 3072 bytes, which is less than the original 4096 bytes.Unfortunately, I have no possibility to test on Arm32. But, I do not see much difference between Arm64 and Arm32 in the context of DomU device tree generation by looking into the code.
Quoted 6 lines
Quoted 3 lines
I simulated this exact environment on my Arm64 setup to validate that the new size remains sufficient. To do this, I temporarily switched
MAX_VIRT_CPUSto 8 and ran tests with 1 and 8 vCPUs.Thanks for doing that! I also see Luca is going to help. If he also confirms the size is good then can you mention the change for Arm 32-bit?
Yes, sure
Quoted 3 lines
Cheers,
Hello Oleksandr,
Quoted 47 lines · Oleksandr Tyshchenko
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_CPUSlimit.Signed-off-by Oleksandr Tyshchenko <[email protected]>---
V1: https://patchew.org/Xen/[email protected]/V2:
- update commit subj/desc
- use a formula that accountsMAX_VIRT_CPUS
- addBUILD_BUG_ON
------ xen/common/device-tree/dom0less-build.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)xen/common/device-tree/dom0less-build.c +11
-3@@ -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))
xen/common/device-tree/dom0less-build.c static int __init domain_handle_dtb_boot_module(struct domain *d, · line 485
Quoted 10 lines
xen/common/device-tree/dom0less-build.c +2
-0static 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
LGTM:
Thanks!
~ Oleksii