static-memory: Fix incorrect tot_size calculation
PATCH 1/1 static-memory: Fix incorrect tot_size calculation
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().
--- xen/common/device-tree/static-memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/common/device-tree/static-memory.c +2 -2
@@ -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;
Signature · 1 line
2.43.0
Hi Michal,
Quoted 7 lines · Michal Orzel
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 thetot_sizecalculation right afteracquire_static_memory_bank().
Looks good to me.
Quoted 3 lines
Fixes 487975df53b5 ("xen/arm: introduce allocate_static_memory")Signed-off-by Michal Orzel <[email protected]>
Cheers
Bertrand
Quoted 29 lines
---
xen/common/device-tree/static-memory.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)xen/common/device-tree/static-memory.c +2
-2@@ -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;Signature · 1 line
2.43.0