Memory region overlap check in device tree
v3 cover Memory region overlap check in device tree
As we are having more and more types of memory region defined in the device tree, it is necessary to add the overlap check of these memory regions in Xen, because such check will help user to identify the misconfiguration in the device tree at the early stage of boot time.
The first patch introduces the basic memory overlap check mechanism, and does the memory check for memory regions in bootinfo.reserved_mem. Following patches extend the overlap check to include bootmodules and EfiACPIReclaimMemory.
v2 -> v3:
1. Use "[start, end]" format in printk error message.
2. Change the return type of helper functions to bool.
3. Use 'start' and 'size' in helper functions to describe a region.
v1 -> v2:
- Split original overlap_check() to meminfo_overlap_check() and bootmodules_overlap_check().
- Rework commit message.
Henry Wang (3):
xen/arm: Add memory overlap check for bootinfo.reserved_mem xen/arm: Extend the memory overlap check to include bootmodules xen/arm: Extend the memory overlap check to include
EfiACPIReclaimMemory
xen/arch/arm/bootfdt.c | 13 +++-- xen/arch/arm/efi/efi-boot.h | 10 +++- xen/arch/arm/include/asm/setup.h | 2 + xen/arch/arm/setup.c | 82 ++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 9 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/3 xen/arm: Add memory overlap check for bootinfo.reserved_mem
As we are having more and more types of static region, and all of these static regions are defined in bootinfo.reserved_mem, it is necessary to add the overlap check of reserved memory regions in Xen, because such check will help user to identify the misconfiguration in the device tree at the early stage of boot time.
Currently we have 3 types of static region, namely
(1) static memory
(2) static heap
(3) static shared memory
(1) and (2) are parsed by the function device_tree_get_meminfo() and
(3) is parsed using its own logic. All of parsed information of these types will be stored in struct meminfo.
Therefore, to unify the overlap checking logic for all of these types, this commit firstly introduces a helper meminfo_overlap_check() and a function check_reserved_regions_overlap() to check if an input physical address range is overlapping with the existing memory regions defined in bootinfo. After that, use check_reserved_regions_overlap() in device_tree_get_meminfo() to do the overlap check of (1) and (2) and replace the original overlap check of (3) with check_reserved_regions_overlap().
---
v2 -> v3:
1. Use "[start, end]" format in printk error message.
2. Change the return type of helper functions to bool.
3. Use 'start' and 'size' in helper functions to describe a region. v1 -> v2:
1. Split original overlap_check() to meminfo_overlap_check().
2. Rework commit message.
--- xen/arch/arm/bootfdt.c | 13 +++++----- xen/arch/arm/include/asm/setup.h | 2 ++ xen/arch/arm/setup.c | 41 ++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-)
xen/arch/arm/bootfdt.c +6 -7
@@ -88,6 +88,9 @@ static int __init device_tree_get_meminfo(const void *fdt, int node,for ( i =0 ; i < banks && mem->nr_banks <NR_MEM_BANKS ; i++ ) {device_tree_get_reg (&cell, address_cells, size_cells, &start, &size); +if ( mem == &bootinfo.reserved_mem && +check_reserved_regions_overlap (start, size) ) +return -EINVAL ;/* Some DT may describe empty bank, ignore them */ if ( !size )continue ;
@@ -482,7 +485,9 @@ static int __init process_shm_node(const void *fdt, int node,return -EINVAL ; } -if ( (end <= mem->bank[i].start) || (paddr >= bank_end) ) +if (check_reserved_regions_overlap (paddr, size) ) +return -EINVAL ; +else {if (strcmp (shm_id, mem->bank[i].shm_id) !=0 )continue ;
@@ -493,12 +498,6 @@ static int __init process_shm_node(const void *fdt, int node,return -EINVAL ; } } -else - { -printk ("fdt: shared memory region overlap with an existing entry %#" PRIpaddr" - %#" PRIpaddr"\n" , - mem->bank[i].start, bank_end); -return -EINVAL ; - } } }
xen/arch/arm/include/asm/setup.h +2 -0
@@ -143,6 +143,8 @@ void fw_unreserved_regions(paddr_t s, paddr_t e,size_t boot_fdt_info (const void *fdt,paddr_t paddr);const char *boot_fdt_cmdline (const void *fdt); +bool check_reserved_regions_overlap (paddr_t region_start,paddr_t region_size); +struct bootmodule *add_boot_module (bootmodule_kind kind,paddr_t start,paddr_t size,bool domU);struct bootmodule *boot_module_find_by_kind (bootmodule_kind kind);
xen/arch/arm/setup.c +41 -0
54 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 1/3] xen/arm: Add memory overlap check for bootinfo.reserved_mem
Quoted 24 lines · Henry Wang
As we are having more and more types of static region, and all of these static regions are defined in bootinfo.reserved_mem, it is necessary to add the overlap check of reserved memory regions in Xen, because such check will help user to identify the misconfiguration in the device tree at the early stage of boot time.
Currently we have 3 types of static region, namely
(1) static memory
(2) static heap
(3) static shared memory(1) and (2) are parsed by the function
device_tree_get_meminfo()and
(3) is parsed using its own logic. All of parsed information of these types will be stored instruct meminfo.Therefore, to unify the overlap checking logic for all of these types, this commit firstly introduces a helper
meminfo_overlap_check()and a functioncheck_reserved_regions_overlap()to check if an input physical address range is overlapping with the existing memory regions defined in bootinfo. After that, usecheck_reserved_regions_overlap()indevice_tree_get_meminfo()to do the overlap check of (1) and (2) and replace the original overlap check of (3) withcheck_reserved_regions_overlap().
Quoted 1 line
Signed-off-by Henry Wang <[email protected]>
Quoted 29 lines
---
v2 -> v3:
1. Use "[start, end]" format in printk error message.
2. Change the return type of helper functions to bool.
3. Use 'start' and 'size' in helper functions to describe a region. v1 -> v2:
1. Split originaloverlap_check()tomeminfo_overlap_check().
2. Rework commit message.--- xen/arch/arm/bootfdt.c | 13 +++++----- xen/arch/arm/include/asm/setup.h | 2 ++ xen/arch/arm/setup.c | 41 ++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-)xen/arch/arm/bootfdt.c +3
-0@@ -88,6 +88,9 @@ static int __init device_tree_get_meminfo(const void *fdt, int node,for ( i =0 ; i < banks && mem->nr_banks <NR_MEM_BANKS ; i++ ) {device_tree_get_reg (&cell, address_cells, size_cells, &start, &size); +if ( mem == &bootinfo.reserved_mem && +check_reserved_regions_overlap (start, size) ) +return -EINVAL ;/* Some DT may describe empty bank, ignore them */ if ( !size )continue ;
xen/arch/arm/bootfdt.c static int __init process_shm_node(const void *fdt, int node, · line 486
Quoted 2 lines
xen/arch/arm/bootfdt.c +0
-0@@ -482,7 +485,9 @@ static int __init process_shm_node(const void *fdt, int node,return -EINVAL ; }
~
Quoted 96 lines
xen/arch/arm/bootfdt.c +3
-7-if ( (end <= mem->bank[i].start) || (paddr >= bank_end) ) +if (check_reserved_regions_overlap (paddr, size) ) +return -EINVAL ; +else {if (strcmp (shm_id, mem->bank[i].shm_id) !=0 )continue ;@@ -493,12 +498,6 @@ static int __init process_shm_node(const void *fdt, int node,return -EINVAL ; } } -else - { -printk ("fdt: shared memory region overlap with an existing entry %#" PRIpaddr" - %#" PRIpaddr"\n" , - mem->bank[i].start, bank_end); -return -EINVAL ; - } } }xen/arch/arm/include/asm/setup.h +2
-0@@ -143,6 +143,8 @@ void fw_unreserved_regions(paddr_t s, paddr_t e,size_t boot_fdt_info (const void *fdt,paddr_t paddr);const char *boot_fdt_cmdline (const void *fdt); +bool check_reserved_regions_overlap (paddr_t region_start,paddr_t region_size); +struct bootmodule *add_boot_module (bootmodule_kind kind,paddr_t start,paddr_t size,bool domU);struct bootmodule *boot_module_find_by_kind (bootmodule_kind kind);xen/arch/arm/setup.c +41
-0@@ -261,6 +261,32 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e,cb (s, e); } +static bool __init meminfo_overlap_check (struct meminfo *meminfo, +paddr_t region_start, +paddr_t region_size) +{ +paddr_t bank_start =INVALID_PADDR , bank_end =0 ; +paddr_t region_end = region_start + region_size; +unsigned int i, bank_num = meminfo->nr_banks; + +for ( i =0 ; i < bank_num; i++ ) + { + bank_start = meminfo->bank[i].start; + bank_end = bank_start + meminfo->bank[i].size; + +if ( region_end <= bank_start || region_start >= bank_end ) +continue ; +else + { +printk ("Region: [%#" PRIpaddr", %#" PRIpaddr"] overlapping with bank[%u]: [%#" PRIpaddr", %#" PRIpaddr"]\n" , + region_start, region_end, i, bank_start, bank_end); +return true; + } + } + +return false; +} +void __init fw_unreserved_regions (paddr_t s,paddr_t e,void (*cb)(paddr_t ,paddr_t ),unsigned int first)@@ -271,7 +297,22 @@ void __init fw_unreserved_regions(paddr_t s, paddr_t e,cb (s, e); } +/* +* Given an input physical address range, check if this range is overlapping +* with the existing reserved memory regions defined in bootinfo. +* Return true if the input physical address range is overlapping with any +* existing reserved memory regions, otherwise false. +*/ +bool __init check_reserved_regions_overlap (paddr_t region_start, +paddr_t region_size) +{ +/* Check if input region is overlapping with bootinfo.reserved_mem banks */ +if (meminfo_overlap_check (&bootinfo.reserved_mem, + region_start, region_size) ) +return true; +return false; +} struct bootmodule __init *add_boot_module(bootmodule_kind kind, paddr_t start, paddr_t size,Signature · 1 line
2.25.1
Re: [PATCH v3 1/3] xen/arm: Add memory overlap check for bootinfo.reserved_mem
In reply to Henry WangHi Henry,
Quoted 18 lines · Henry Wang
xen/arch/arm/include/asm/setup.h +2
-0@@ -143,6 +143,8 @@ void fw_unreserved_regions(paddr_t s, paddr_t e,size_t boot_fdt_info (const void *fdt,paddr_t paddr);const char *boot_fdt_cmdline (const void *fdt); +bool check_reserved_regions_overlap (paddr_t region_start,paddr_t region_size); +struct bootmodule *add_boot_module (bootmodule_kind kind,paddr_t start,paddr_t size,bool domU);struct bootmodule *boot_module_find_by_kind (bootmodule_kind kind);xen/arch/arm/setup.c +0
-0
xen/arch/arm/setup.c static void __init dt_unreserved_regions(paddr_t s, paddr_t e, · line 266
Quoted 6 lines
xen/arch/arm/setup.c +3
-0@@ -261,6 +261,32 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e,cb (s, e); } +static bool __init meminfo_overlap_check (struct meminfo *meminfo, +paddr_t region_start, +paddr_t region_size)
So the interface looks nicer but now...
xen/arch/arm/setup.c static void __init dt_unreserved_regions(paddr_t s, paddr_t e, · line 277
Quoted 11 lines
xen/arch/arm/setup.c +11
-0+{ +paddr_t bank_start =INVALID_PADDR , bank_end =0 ; +paddr_t region_end = region_start + region_size; +unsigned int i, bank_num = meminfo->nr_banks; + +for ( i =0 ; i < bank_num; i++ ) + { + bank_start = meminfo->bank[i].start; + bank_end = bank_start + meminfo->bank[i].size; + +if ( region_end <= bank_start || region_start >= bank_end )
... it clearly shows how this check would be wrong when either the bank or the region is at the end of the address space. You may say it doesn't overlap when it could (e.g. when region_end < region_start).
That said, unless we rework 'bank', we would not properly solve the problem. But that's likely a bigger piece of work and not something I would request.
So for now, I would suggest to add a comment. Stefano, what do you think?
xen/arch/arm/setup.c static void __init dt_unreserved_regions(paddr_t s, paddr_t e, · line 281
Quoted 4 lines
xen/arch/arm/setup.c +4
-0+continue ; + else + { + printk("Region: [%#"PRIpaddr", %#"PRIpaddr"] overlapping with bank[%u]: [%#"PRIpaddr", %#"PRIpaddr"]\n",
']' usually mean inclusive. But here, 'end' is exclusive. So you want '['.
This could be fixed on commit.
BTW, the same comments applies for the second patch.
Quoted 24 lines
xen/arch/arm/setup.c +17
-0+ region_start, region_end, i, bank_start, bank_end); +return true; + } + } + +return false; +} +void __init fw_unreserved_regions (paddr_t s,paddr_t e,void (*cb)(paddr_t ,paddr_t ),unsigned int first)@@ -271,7 +297,22 @@ void __init fw_unreserved_regions(paddr_t s, paddr_t e,cb (s, e); } +/* +* Given an input physical address range, check if this range is overlapping +* with the existing reserved memory regions defined in bootinfo. +* Return true if the input physical address range is overlapping with any +* existing reserved memory regions, otherwise false. +*/ +bool __init check_reserved_regions_overlap (paddr_t region_start, +paddr_t region_size) +{
xen/arch/arm/setup.c void __init fw_unreserved_regions(paddr_t s, paddr_t e, · line 318
Quoted 10 lines
xen/arch/arm/setup.c +6
-0+/* Check if input region is overlapping with bootinfo.reserved_mem banks */ +if (meminfo_overlap_check (&bootinfo.reserved_mem, + region_start, region_size) ) +return true; +return false; +} struct bootmodule __init *add_boot_module(bootmodule_kind kind, paddr_t start, paddr_t size,
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH v3 1/3] xen/arm: Add memory overlap check for bootinfo.reserved_mem
Hi Julien,
Quoted 7 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Subject: Re: [PATCH v3 1/3] xen/arm: Add memory overlap check for bootinfo.reserved_memHi Henry,
Quoted 15 lines
xen/arch/arm/setup.c static void __init dt_unreserved_regions(paddr_t s, paddr_t e, · line 277
Quoted 11 lines
xen/arch/arm/setup.c +11
-0+{ +paddr_t bank_start =INVALID_PADDR , bank_end =0 ; +paddr_t region_end = region_start + region_size; +unsigned int i, bank_num = meminfo->nr_banks; + +for ( i =0 ; i < bank_num; i++ ) + { + bank_start = meminfo->bank[i].start; + bank_end = bank_start + meminfo->bank[i].size; + +if ( region_end <= bank_start || region_start >= bank_end )... it clearly shows how this check would be wrong when either the bank or the region is at the end of the address space. You may say it doesn't overlap when it could (e.g. when
region_end<region_start).
Here do you mean if the region is at the end of the addr space, "region_start + region_end" will overflow and cause region_end < region_start? If so...
Quoted 6 lines
That said, unless we rework 'bank', we would not properly solve the problem. But that's likely a bigger piece of work and not something I would request.
So for now, I would suggest to add a comment. Stefano, what do you think?
...I am not really sure if simply adding a comment here would help, because when the overflow happens, we are already doomed because of the messed-up device tree.
Would adding a BUG_ON(region_end < region_start) make sense to you?
Quoted 8 lines
xen/arch/arm/setup.c static void __init dt_unreserved_regions(paddr_t s, paddr_t e,
Quoted 5 lines
xen/arch/arm/setup.c +4
-0+continue ; + else + { + printk("Region: [%#"PRIpaddr", %#"PRIpaddr"] overlapping withbank[%u]: [%#"PRIpaddr", %#"PRIpaddr"]\n",
']' usually mean inclusive. But here, 'end' is exclusive. So you want '['.
Oh, now I understand the misunderstanding in our communication in v1:
I didn't know '[' means exclusive because I was educated to use ')' [1] so I thought you meant inclusive. Sorry for this.
To keep consistency, may I use ')' here? Because I think this is the current way in the code base, for example see:xen/include/xen/numa.h L99: [*start, *end) xen/drivers/passthrough/amd/iommu_acpi.c L177: overlap [%lx,%lx)
Quoted 4 lines
This could be fixed on commit.
BTW, the same comments applies for the second patch.
I will fix this patch and #2 in v4.
[1] https://en.wikipedia.org/wiki/Interval_(mathematics)#Including_or_excluding_endpoints
Kind regards,
Henry
Quoted 5 lines
Cheers,
--
Julien Grall
Re: [PATCH v3 1/3] xen/arm: Add memory overlap check for bootinfo.reserved_mem
Quoted 25 lines · Henry Wang
Hi Julien,
Quoted 7 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Subject: Re: [PATCH v3 1/3] xen/arm: Add memory overlap check for bootinfo.reserved_memHi Henry,
Quoted 15 lines
xen/arch/arm/setup.c static void __init dt_unreserved_regions(paddr_t s, paddr_t e, · line 277
Quoted 11 lines
xen/arch/arm/setup.c +11
-0+{ +paddr_t bank_start =INVALID_PADDR , bank_end =0 ; +paddr_t region_end = region_start + region_size; +unsigned int i, bank_num = meminfo->nr_banks; + +for ( i =0 ; i < bank_num; i++ ) + { + bank_start = meminfo->bank[i].start; + bank_end = bank_start + meminfo->bank[i].size; + +if ( region_end <= bank_start || region_start >= bank_end )... it clearly shows how this check would be wrong when either the bank or the region is at the end of the address space. You may say it doesn't overlap when it could (e.g. when
region_end<region_start).
Quoted 3 lines
Here do you mean if the region is at the end of the addr space, "
region_start+region_end" will overflow and causeregion_end<region_start? If so...
Yes.
Quoted 11 lines
Quoted 7 lines
That said, unless we rework 'bank', we would not properly solve the problem. But that's likely a bigger piece of work and not something I would request.
So for now, I would suggest to add a comment. Stefano, what do you think?
...I am not really sure if simply adding a comment here would help, because when the overflow happens, we are already doomed because of the messed-up device tree.
Not necessarily. This could happen if the region is right at the top of the address (e.g. finishing at 2^64 - 1). As the 'end' is exclusive, then it would be equal to 0.
I think this is less likely for arm64, but this could happen for 32-bit Arm as we will allow the admin to reduce paddr_t from 64-bit to 32-bit.
Quoted 2 lines
Would adding a
BUG_ON(region_end < region_start)make sense to you?
No for the reason I stated above.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/arm/setup.c +4
-0+continue ; + else + { + printk("Region: [%#"PRIpaddr", %#"PRIpaddr"] overlapping with
Quoted 7 lines
Quoted 3 lines
bank[%u]: [%#"PRIpaddr", %#"PRIpaddr"]\n",
']' usually mean inclusive. But here, 'end' is exclusive. So you want '['.
Oh, now I understand the misunderstanding in our communication in v1:
I didn't know '[' means exclusive because I was educated to use ')' [1] so I thought you meant inclusive. Sorry for this.
No worries. That might be only me using [ and ) interchangeably :).
Quoted 5 lines
To keep consistency, may I use ')' here? Because I think this is the current way in the code base, for example see:
xen/include/xen/numa.hL99: [*start, *end)xen/drivers/passthrough/amd/iommu_acpi.cL177: overlap [%lx,%lx)
I am fine with that.
Quoted 3 lines
Quoted 1 line
BTW, the same comments applies for the second patch.
I will fix this patch and #2 in v4.
I am happy to deal with it on commit if you want.
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH v3 1/3] xen/arm: Add memory overlap check for bootinfo.reserved_mem
Hi Julien,
Quoted 7 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Subject: Re: [PATCH v3 1/3] xen/arm: Add memory overlap check for bootinfo.reserved_memQuoted 1 line
I will fix this patch and #2 in v4.
I am happy to deal with it on commit if you want.
Including adding the comment for both patches? This would be wonderful and very nice of you to do that. But if your time is limited I am also more than happy to respin the patch (probably even with Stefano's Reviewed-by tag if he is ok with it) to reduce your burden. That said, if I need to respin the patch, it would be good to get some hints about the wording of the comments to avoid another v+1 just because of my inaccurate wording :) Thanks very much!
Kind regards,
Henry
Quoted 5 lines
Cheers,
--
Julien Grall
Re: [PATCH v3 1/3] xen/arm: Add memory overlap check for bootinfo.reserved_mem
Quoted 8 lines · Henry Wang
Hi Julien,
Quoted 6 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Subject: Re: [PATCH v3 1/3] xen/arm: Add memory overlap check for bootinfo.reserved_memQuoted 1 line
I will fix this patch and #2 in v4.
Quoted 8 lines
Quoted 1 line
I am happy to deal with it on commit if you want.
Including adding the comment for both patches? This would be wonderful and very nice of you to do that. But if your time is limited I am also more than happy to respin the patch (probably even with Stefano's Reviewed-by tag if he is ok with it) to reduce your burden. That said, if I need to respin the patch, it would be good to get some hints about the wording of the comments to avoid another v+1 just because of my inaccurate wording :)
Good idea. My suggestion would be:
TODO: '*_end' could be 0 if the bank/region is at the end of the physical address space. This is for now not handled as it requires more rework.
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 2/3 xen/arm: Extend the memory overlap check to include bootmodules
In reply to Henry WangSimilarly as the static regions defined in bootinfo.reserved_mem, the bootmodule regions defined in bootinfo.modules should also not be overlapping with memory regions in either bootinfo.reserved_mem or bootinfo.modules.
Therefore, this commit introduces a helper bootmodules_overlap_check() and uses this helper to extend the check in function check_reserved_regions_overlap() so that memory regions in bootinfo.modules are included. Use check_reserved_regions_overlap() in add_boot_module() to return early if any error occurs.
---
v2 -> v3:
1. Use "[start, end]" format in printk error message.
2. Change the return type of helper functions to bool.
3. Use 'start' and 'size' in helper functions to describe a region. v1 -> v2:
1. Split original overlap_check() to bootmodules_overlap_check().
2. Rework commit message.
--- xen/arch/arm/setup.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
xen/arch/arm/setup.c +35 -0
@@ -287,6 +287,32 @@ static bool __init meminfo_overlap_check(struct meminfo *meminfo,return false; } +static bool __init bootmodules_overlap_check (struct bootmodules *bootmodules, +paddr_t region_start, +paddr_t region_size) +{ +paddr_t mod_start =INVALID_PADDR , mod_end =0 ; +paddr_t region_end = region_start + region_size; +unsigned int i, mod_num = bootmodules->nr_mods; + +for ( i =0 ; i < mod_num; i++ ) + { + mod_start = bootmodules->module[i].start; + mod_end = mod_start + bootmodules->module[i].size; + +if ( region_end <= mod_start || region_start >= mod_end ) +continue ; +else + { +printk ("Region: [%#" PRIpaddr", %#" PRIpaddr"] overlapping with mod[%u]: [%#" PRIpaddr", %#" PRIpaddr"]\n" , + region_start, region_end, i, mod_start, mod_end); +return true; + } + } + +return false; +} +void __init fw_unreserved_regions (paddr_t s,paddr_t e,void (*cb)(paddr_t ,paddr_t ),unsigned int first)
@@ -311,6 +337,11 @@ bool __init check_reserved_regions_overlap(paddr_t region_start, region_start, region_size) )return true; +/* Check if input region is overlapping with bootmodules */ +if (bootmodules_overlap_check (&bootinfo.modules, + region_start, region_size) ) +return true; +return false; }
@@ -328,6 +359,10 @@ struct bootmodule __init *add_boot_module(bootmodule_kind kind, boot_module_kind_as_string(kind), start, start + size);return NULL ; } + +if (check_reserved_regions_overlap (start, size) ) +return NULL ; +for ( i =0 ; i < mods->nr_mods ; i++ ) { mod = &mods->module[i];
Signature · 1 line
2.25.1
Re: [PATCH v3 2/3] xen/arm: Extend the memory overlap check to include bootmodules
Quoted 5 lines · Henry Wang
Similarly as the static regions defined in bootinfo.reserved_mem, the bootmodule regions defined in bootinfo.modules should also not be overlapping with memory regions in either bootinfo.reserved_mem or bootinfo.modules.
Quoted 7 lines
Therefore, this commit introduces a helper
bootmodules_overlap_check()and uses this helper to extend the check in functioncheck_reserved_regions_overlap()so that memory regions in bootinfo.modules are included. Usecheck_reserved_regions_overlap()inadd_boot_module()to return early if any error occurs.Signed-off-by Henry Wang <[email protected]>
Quoted 75 lines
---
v2 -> v3:
1. Use "[start, end]" format in printk error message.
2. Change the return type of helper functions to bool.
3. Use 'start' and 'size' in helper functions to describe a region. v1 -> v2:
1. Split originaloverlap_check()tobootmodules_overlap_check().
2. Rework commit message.--- xen/arch/arm/setup.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)xen/arch/arm/setup.c +35
-0@@ -287,6 +287,32 @@ static bool __init meminfo_overlap_check(struct meminfo *meminfo,return false; } +static bool __init bootmodules_overlap_check (struct bootmodules *bootmodules, +paddr_t region_start, +paddr_t region_size) +{ +paddr_t mod_start =INVALID_PADDR , mod_end =0 ; +paddr_t region_end = region_start + region_size; +unsigned int i, mod_num = bootmodules->nr_mods; + +for ( i =0 ; i < mod_num; i++ ) + { + mod_start = bootmodules->module[i].start; + mod_end = mod_start + bootmodules->module[i].size; + +if ( region_end <= mod_start || region_start >= mod_end ) +continue ; +else + { +printk ("Region: [%#" PRIpaddr", %#" PRIpaddr"] overlapping with mod[%u]: [%#" PRIpaddr", %#" PRIpaddr"]\n" , + region_start, region_end, i, mod_start, mod_end); +return true; + } + } + +return false; +} +void __init fw_unreserved_regions (paddr_t s,paddr_t e,void (*cb)(paddr_t ,paddr_t ),unsigned int first)@@ -311,6 +337,11 @@ bool __init check_reserved_regions_overlap(paddr_t region_start, region_start, region_size) )return true; +/* Check if input region is overlapping with bootmodules */ +if (bootmodules_overlap_check (&bootinfo.modules, + region_start, region_size) ) +return true; +return false; }@@ -328,6 +359,10 @@ struct bootmodule __init *add_boot_module(bootmodule_kind kind, boot_module_kind_as_string(kind), start, start + size);return NULL ; } + +if (check_reserved_regions_overlap (start, size) ) +return NULL ; +for ( i =0 ; i < mods->nr_mods ; i++ ) { mod = &mods->module[i];Signature · 1 line
2.25.1
PATCH v3 3/3 xen/arm: Extend the memory overlap check to include EfiACPIReclaimMemory
In reply to Henry WangSimilarly as the static regions and boot modules, memory regions with EfiACPIReclaimMemory type (defined in bootinfo.acpi if CONFIG_ACPI is enabled) should also not be overlapping with memory regions in bootinfo.reserved_mem and bootinfo.modules.
Therefore, this commit reuses the meminfo_overlap_check() to further extends the check in function check_reserved_regions_overlap() so that memory regions in bootinfo.acpi are included. If any error occurs in the extended check_reserved_regions_overlap(), the meminfo_add_bank() defined in efi-boot.h will return early.
---
v2 -> v3:
1. Rebase on top of patch #1 and #2.
2. Add Stefano's Reviewed-by tag.
v1 -> v2:
1. Rebase on top of patch #1 and #2.
--- xen/arch/arm/efi/efi-boot.h | 10 ++++++++-- xen/arch/arm/setup.c | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
xen/arch/arm/efi/efi-boot.h +8 -2
@@ -161,13 +161,19 @@ static bool __init meminfo_add_bank(struct meminfo *mem, EFI_MEMORY_DESCRIPTOR *desc) {struct membank *bank; +paddr_t start = desc->PhysicalStart; +paddr_t size = desc->NumberOfPages *EFI_PAGE_SIZE ;if ( mem->nr_banks >=NR_MEM_BANKS )return false; +#ifdef CONFIG_ACPI +if (check_reserved_regions_overlap (start, size) ) +return false; +#endif bank = &mem->bank[mem->nr_banks]; - bank->start = desc->PhysicalStart; - bank->size = desc->NumberOfPages *EFI_PAGE_SIZE ; + bank->start = start; + bank->size = size; mem->nr_banks++;
xen/arch/arm/setup.c +6 -0
@@ -342,6 +342,12 @@ bool __init check_reserved_regions_overlap(paddr_t region_start, region_start, region_size) )return true; +#ifdef CONFIG_ACPI +/* Check if input region is overlapping with ACPI EfiACPIReclaimMemory */ +if (meminfo_overlap_check (&bootinfo.acpi, region_start, region_size) ) +return true; +#endif +return false; }
Signature · 1 line
2.25.1