[PATCH] static-memory: Fix incorrect tot_size calculation

Michal Orzel posted 1 patch 4 days, 3 hours ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20260204124235.134773-1-michal.orzel@amd.com
xen/common/device-tree/static-memory.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] static-memory: Fix incorrect tot_size calculation
Posted by Michal Orzel 4 days, 3 hours ago
When a physical memory bank spans multiple guest RAM banks, the variable
psize is modified inside the allocation loop, but the modified value
(instead of the original bank size) is added to tot_size. This causes an
incorrect total size calculation leading to false panic. Move the
tot_size calculation right after acquire_static_memory_bank().

Fixes: 487975df53b5 ("xen/arm: introduce allocate_static_memory")
Signed-off-by: Michal Orzel <michal.orzel@amd.com>
---
 xen/common/device-tree/static-memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/common/device-tree/static-memory.c b/xen/common/device-tree/static-memory.c
index 0774d0680604..ffbc12aa24df 100644
--- a/xen/common/device-tree/static-memory.c
+++ b/xen/common/device-tree/static-memory.c
@@ -118,6 +118,8 @@ void __init allocate_static_memory(struct domain *d, struct kernel_info *kinfo,
         if ( mfn_eq(smfn, INVALID_MFN) )
             goto fail;
 
+        tot_size += psize;
+
         printk(XENLOG_INFO "%pd: STATIC BANK[%u] %#"PRIpaddr"-%#"PRIpaddr"\n",
                d, bank, pbase, pbase + psize);
 
@@ -158,8 +160,6 @@ void __init allocate_static_memory(struct domain *d, struct kernel_info *kinfo,
                 mem->bank[gbank].start = rambase[gbank];
             }
         }
-
-        tot_size += psize;
     }
 
     mem->nr_banks = ++gbank;
-- 
2.43.0
Re: [PATCH] static-memory: Fix incorrect tot_size calculation
Posted by Bertrand Marquis 4 days, 2 hours ago
Hi Michal,


> On 4 Feb 2026, at 13:42, Michal Orzel <michal.orzel@amd.com> wrote:
> 
> When a physical memory bank spans multiple guest RAM banks, the variable
> psize is modified inside the allocation loop, but the modified value
> (instead of the original bank size) is added to tot_size. This causes an
> incorrect total size calculation leading to false panic. Move the
> tot_size calculation right after acquire_static_memory_bank().

Looks good to me.

> 
> Fixes: 487975df53b5 ("xen/arm: introduce allocate_static_memory")
> Signed-off-by: Michal Orzel <michal.orzel@amd.com>

Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>

Cheers
Bertrand

> ---
> xen/common/device-tree/static-memory.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/common/device-tree/static-memory.c b/xen/common/device-tree/static-memory.c
> index 0774d0680604..ffbc12aa24df 100644
> --- a/xen/common/device-tree/static-memory.c
> +++ b/xen/common/device-tree/static-memory.c
> @@ -118,6 +118,8 @@ void __init allocate_static_memory(struct domain *d, struct kernel_info *kinfo,
>         if ( mfn_eq(smfn, INVALID_MFN) )
>             goto fail;
> 
> +        tot_size += psize;
> +
>         printk(XENLOG_INFO "%pd: STATIC BANK[%u] %#"PRIpaddr"-%#"PRIpaddr"\n",
>                d, bank, pbase, pbase + psize);
> 
> @@ -158,8 +160,6 @@ void __init allocate_static_memory(struct domain *d, struct kernel_info *kinfo,
>                 mem->bank[gbank].start = rambase[gbank];
>             }
>         }
> -
> -        tot_size += psize;
>     }
> 
>     mem->nr_banks = ++gbank;
> -- 
> 2.43.0
>