xen/arm: add warning if memory modules overlap
PATCH 1/1 xen/arm: add warning if memory modules overlap
It's possible for a misconfigured device tree to cause Xen to crash when there are overlapping addresses in the memory modules. Add a warning when printing the addresses to let the user know there's a possible issue when DEBUG is enabled.
---
sample output:
...
(XEN) MODULE[0]: 0000000001400000 - 000000000153b8f1 Xen
(XEN) MODULE[1]: 00000000076d2000 - 00000000076dc080 Device Tree
(XEN) MODULE[2]: 00000000076df000 - 0000000007fff364 Ramdisk
(XEN) MODULE[3]: 0000000000080000 - 0000000003180000 Kernel
(XEN) RESVD[0]: 00000000076d2000 - 00000000076dc000
(XEN) RESVD[1]: 00000000076df000 - 0000000007fff364
(XEN)
(XEN) WARNING: modules Xen and Kernel overlap
(XEN)
(XEN) Command line: console=dtuart dtuart=serial0 dom0_mem=1G bootscrub=0 maxcpus=1 timer_slop=0
...
xen/arch/arm/bootfdt.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
xen/arch/arm/bootfdt.c +17 -0
@@ -387,6 +387,23 @@ static void __init early_print_info(void) mem_resv->bank[j].start + mem_resv->bank[j].size - 1); }printk ("\n" ); + +#ifndef NDEBUG +/* +* Assuming all combinations are checked, only the starting address +* has to be checked if it's in another memory module's range. +*/ +for ( i =0 ; i < mods->nr_mods; i++ ) +for ( j =0 ; j < mods->nr_mods; j++ ) +if ( (i != j) && + (mods->module[i].start >= mods->module[j].start) && + (mods->module[i].start < + mods->module[j].start + mods->module[j].size) ) +printk ("WARNING: modules %-12s and %-12s overlap\n" , +boot_module_kind_as_string (mods->module[i].kind), +boot_module_kind_as_string (mods->module[j].kind)); +#endif +for ( i =0 ; i < cmds->nr_mods; i++ ) printk("CMDLINE[%"PRIpaddr"]:%s %s\n", cmds->cmdline[i].start, cmds->cmdline[i].dt_name,
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Brian,
Thank you for the patch.
Quoted 37 lines · Brian Woods
It's possible for a misconfigured device tree to cause Xen to crash when there are overlapping addresses in the memory modules. Add a warning when printing the addresses to let the user know there's a possible issue when DEBUG is enabled.
Signed-off-by Brian Woods <[email protected]>---
sample output:
...
(XEN) MODULE[0]: 0000000001400000 -000000000153b8f1Xen
(XEN) MODULE[1]:00000000076d2000-00000000076dc080Device Tree
(XEN) MODULE[2]:00000000076df000-0000000007fff364Ramdisk
(XEN) MODULE[3]: 0000000000080000 - 0000000003180000 Kernel
(XEN) RESVD[0]:00000000076d2000-00000000076dc000
(XEN) RESVD[1]:00000000076df000-0000000007fff364
(XEN)
(XEN) WARNING: modules Xen and Kernel overlap
(XEN)
(XEN) Command line: console=dtuart dtuart=serial0 dom0_mem=1G bootscrub=0 maxcpus=1 timer_slop=0
...xen/arch/arm/bootfdt.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)xen/arch/arm/bootfdt.c +5
-0@@ -387,6 +387,23 @@ static void __init early_print_info(void) mem_resv->bank[j].start + mem_resv->bank[j].size - 1); }printk ("\n" ); + +#ifndef NDEBUG +/* +* Assuming all combinations are checked, only the starting address +* has to be checked if it's in another memory module's range.
xen/arch/arm/bootfdt.c static void __init early_print_info(void) · line 404
Quoted 10 lines
xen/arch/arm/bootfdt.c +10
-0+*/ +for ( i =0 ; i < mods->nr_mods; i++ ) +for ( j =0 ; j < mods->nr_mods; j++ ) +if ( (i != j) && + (mods->module[i].start >= mods->module[j].start) && + (mods->module[i].start < + mods->module[j].start + mods->module[j].size) ) +printk ("WARNING: modules %-12s and %-12s overlap\n" , +boot_module_kind_as_string (mods->module[i].kind), +boot_module_kind_as_string (mods->module[j].kind));
I am not entirely happy with the double for-loop here.
As we already go through all the modules in add_boot_module(). Could you look whether this check could be part of it?
This should also allow to have this check for non-debug build as well.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 55 lines · Julien Grall
Hi Brian,
Thank you for the patch.
Quoted 37 lines · Brian Woods
It's possible for a misconfigured device tree to cause Xen to crash when there are overlapping addresses in the memory modules. Add a warning when printing the addresses to let the user know there's a possible issue when DEBUG is enabled.
Signed-off-by Brian Woods <[email protected]>---
sample output:
...
(XEN) MODULE[0]: 0000000001400000 -000000000153b8f1Xen
(XEN) MODULE[1]:00000000076d2000-00000000076dc080Device Tree
(XEN) MODULE[2]:00000000076df000-0000000007fff364Ramdisk
(XEN) MODULE[3]: 0000000000080000 - 0000000003180000 Kernel
(XEN) RESVD[0]:00000000076d2000-00000000076dc000
(XEN) RESVD[1]:00000000076df000-0000000007fff364
(XEN)
(XEN) WARNING: modules Xen and Kernel overlap
(XEN)
(XEN) Command line: console=dtuart dtuart=serial0 dom0_mem=1G bootscrub=0 maxcpus=1 timer_slop=0
...xen/arch/arm/bootfdt.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)xen/arch/arm/bootfdt.c +5
-0@@ -387,6 +387,23 @@ static void __init early_print_info(void) mem_resv->bank[j].start + mem_resv->bank[j].size - 1); }printk ("\n" ); + +#ifndef NDEBUG +/* +* Assuming all combinations are checked, only the starting address +* has to be checked if it's in another memory module's range. xen/arch/arm/bootfdt.c static void __init early_print_info(void) · line 404
Quoted 10 lines
xen/arch/arm/bootfdt.c +10
-0+*/ +for ( i =0 ; i < mods->nr_mods; i++ ) +for ( j =0 ; j < mods->nr_mods; j++ ) +if ( (i != j) && + (mods->module[i].start >= mods->module[j].start) && + (mods->module[i].start < + mods->module[j].start + mods->module[j].size) ) +printk ("WARNING: modules %-12s and %-12s overlap\n" , +boot_module_kind_as_string (mods->module[i].kind), +boot_module_kind_as_string (mods->module[j].kind));I am not entirely happy with the double for-loop here.
Quoted 9 lines
As we already go through all the modules in
add_boot_module(). Could you look whether this check could be part of it?This should also allow to have this check for non-debug build as well.
Cheers,
Signature · 1 line
Julien Grall
To make sure the module is going to get added, you'd need to do the check after the for loop. This means there's going to be multiple for loops just spread over the course of adding the boot modules rather than one place.
I had this before but decided against it but after changing it to both starts rather than the stand and end (ends look much uglier), it looks cleaner.
for ( i = 0 ; i < mods->nr_mods-1; i++ )
for ( j = i+1 ; j < mods->nr_mods; j++ )
if ( ((mods->module[i].start >= mods->module[j].start) &&
(mods->module[i].start <=
mods->module[j].start + mods->module[j].size)) ||
((mods->module[j].start >= mods->module[i].start) &&
(mods->module[j].start <=
mods->module[i].start + mods->module[i].size)) )
printk("WARNING: modules %-12s and %-12s overlap\n",
boot_module_kind_as_string(mods->module[i].kind),
boot_module_kind_as_string(mods->module[j].kind));That's also a possibility.
I just don't see a way around it, computationally. You can split where the loops are executed but in the end the same amount of checks/total iterations have to be run.
I was talking to someone and he suggested you could just check Xen at early boot and then check other modules later.
Signature · 6 lines
Brian Woods _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi,
Quoted 59 lines · Brian Woods
Quoted 58 lines · Julien Grall
Hi Brian,
Thank you for the patch.
Quoted 37 lines · Brian Woods
It's possible for a misconfigured device tree to cause Xen to crash when there are overlapping addresses in the memory modules. Add a warning when printing the addresses to let the user know there's a possible issue when DEBUG is enabled.
Signed-off-by Brian Woods <[email protected]>---
sample output:
...
(XEN) MODULE[0]: 0000000001400000 -000000000153b8f1Xen
(XEN) MODULE[1]:00000000076d2000-00000000076dc080Device Tree
(XEN) MODULE[2]:00000000076df000-0000000007fff364Ramdisk
(XEN) MODULE[3]: 0000000000080000 - 0000000003180000 Kernel
(XEN) RESVD[0]:00000000076d2000-00000000076dc000
(XEN) RESVD[1]:00000000076df000-0000000007fff364
(XEN)
(XEN) WARNING: modules Xen and Kernel overlap
(XEN)
(XEN) Command line: console=dtuart dtuart=serial0 dom0_mem=1G bootscrub=0 maxcpus=1 timer_slop=0
...xen/arch/arm/bootfdt.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)xen/arch/arm/bootfdt.c +5
-0@@ -387,6 +387,23 @@ static void __init early_print_info(void) mem_resv->bank[j].start + mem_resv->bank[j].size - 1); }printk ("\n" ); + +#ifndef NDEBUG +/* +* Assuming all combinations are checked, only the starting address +* has to be checked if it's in another memory module's range. xen/arch/arm/bootfdt.c static void __init early_print_info(void) · line 404
Quoted 10 lines
xen/arch/arm/bootfdt.c +10
-0+*/ +for ( i =0 ; i < mods->nr_mods; i++ ) +for ( j =0 ; j < mods->nr_mods; j++ ) +if ( (i != j) && + (mods->module[i].start >= mods->module[j].start) && + (mods->module[i].start < + mods->module[j].start + mods->module[j].size) ) +printk ("WARNING: modules %-12s and %-12s overlap\n" , +boot_module_kind_as_string (mods->module[i].kind), +boot_module_kind_as_string (mods->module[j].kind));I am not entirely happy with the double for-loop here.
As we already go through all the modules in
add_boot_module(). Could you look whether this check could be part of it?
Quoted 6 lines
Quoted 6 lines
This should also allow to have this check for non-debug build as well.
Cheers,
Signature · 1 line
Julien Grall
Please at least remove the signature in the e-mail you reply to. The best would be to trim the e-mail and answer right below the specific paragraph.
Quoted 5 lines
To make sure the module is going to get added, you'd need to do the check after the for loop. This means there's going to be multiple for loops just spread over the course of adding the boot modules rather than one place.
I don't think you need to do the check after the loop. The only way to go out of the loop in add_boot_module() is when i reached mods->nr_mods.
Quoted 17 lines
I had this before but decided against it but after changing it to both starts rather than the stand and end (ends look much uglier), it looks cleaner.
for ( i = 0 ; i < mods->nr_mods-1; i++ ) for ( j = i+1 ; j < mods->nr_mods; j++ ) if ( ((mods->module[i].start >= mods->module[j].start) && (mods->module[i].start <= mods->module[j].start + mods->module[j].size)) || ((mods->module[j].start >= mods->module[i].start) && (mods->module[j].start <= mods->module[i].start + mods->module[i].size)) ) printk("WARNING: modules %-12s and %-12s overlap\n", boot_module_kind_as_string(mods->module[i].kind), boot_module_kind_as_string(mods->module[j].kind));
Quoted 8 lines
That's also a possibility.
I just don't see a way around it, computationally. You can split where the loops are executed but in the end the same amount of checks/total iterations have to be run.
I was talking to someone and he suggested you could just check Xen at early boot and then check other modules later.
What's wrong with:
xen/arch/arm/setup.c +4 -0
@@ -254,6 +254,10 @@ struct bootmodule __init *add_boot_module(bootmodule_kind kind, mod->domU = false;return mod; } + +if ((mod->start >= start) && + (mod->start < (start + size))) +printk ("WARNING: modules...\n" ); } mod = &mods->module[mods->nr_mods++];
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Julien Grall
Hi,
Please at least remove the signature in the e-mail you reply to. The best would be to trim the e-mail and answer right below the specific paragraph.
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
To make sure the module is going to get added, you'd need to do the check after the for loop. This means there's going to be multiple for loops just spread over the course of adding the boot modules rather than one place.
I don't think you need to do the check after the loop. The only way to go out of the loop in
add_boot_module()is when i reachedmods->nr_mods.
See below.
Quoted 45 lines
Quoted 17 lines
I had this before but decided against it but after changing it to both starts rather than the stand and end (ends look much uglier), it looks cleaner.
for ( i = 0 ; i < mods->nr_mods-1; i++ ) for ( j = i+1 ; j < mods->nr_mods; j++ ) if ( ((mods->module[i].start >= mods->module[j].start) && (mods->module[i].start <= mods->module[j].start + mods->module[j].size)) || ((mods->module[j].start >= mods->module[i].start) && (mods->module[j].start <= mods->module[i].start + mods->module[i].size)) ) printk("WARNING: modules %-12s and %-12s overlap\n", boot_module_kind_as_string(mods->module[i].kind), boot_module_kind_as_string(mods->module[j].kind));Quoted 8 lines
That's also a possibility.
I just don't see a way around it, computationally. You can split where the loops are executed but in the end the same amount of checks/total iterations have to be run.
I was talking to someone and he suggested you could just check Xen at early boot and then check other modules later.
What's wrong with:
xen/arch/arm/setup.c +4
-0@@ -254,6 +254,10 @@ struct bootmodule __init *add_boot_module(bootmodule_kind kind, mod->domU = false;return mod; } + +if ((mod->start >= start) && + (mod->start < (start + size))) +printk ("WARNING: modules...\n" ); }mod = &mods->module[mods->nr_mods++];
Quoted 4 lines
Cheers,
Signature · 1 line
Julien Grall
For that, you'd need to either check the start and end of the added module or the start of both. So something like:
if ( ((mod->start >= start) && (mod->start < (start + size))) ||
((start >= mod->start) && (start < (mod->start + mod->size))) )
printk("WARNING: ...");If you don't you run the risk of having a module overlap but not at the start of the added module (unless there's a guaranteed order). You're still running all of the checks from what I can tell, just not in nested for loop so. Plus I'm not sure how many times add_boot_module gets run and the "mod->kind == kind .." if statement gets run and is true. If the above is true, wouldn't that cause extra checks for the for loop iterations before it was true?
Brian
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi,
Quoted 8 lines · Brian Woods
On Fri, Oct 11, 2019 at 05:58:35PM +0100, Julien Grall wrote:
For that, you'd need to either check the start and end of the added module or the start of both. So something like:if ( ((
mod->start>= start) && (mod->start< (start + size))) ||((start >= mod->start) && (start < (mod->start + mod->size))) ) printk("WARNING: ...");
Quoted 7 lines
If you don't you run the risk of having a module overlap but not at the start of the added module (unless there's a guaranteed order). You're still running all of the checks from what I can tell, just not in nested for loop so. Plus I'm not sure how many times
add_boot_modulegets run and the "mod->kind== kind .." if statement gets run and is true. If the above is true, wouldn't that cause extra checks for the for loop iterations before it was true?
For non-dom0less case, we are talking about 4 modules max (Xen, Kernel, Initramfs, flask policy). Modules cannot be the shared here.
For dom0less, you are unlikely to have that many domains started from Xen. So the number of modules will still be limited (even more if you share it).
This code is also only called at boot where there are bigger time consuming part (such as domheap initialization). So I would be surprised if you see any improvement (other than a couple of cycles) in boot time here.
Therefore, I would favor a readable solution over a micro-optimized solution here.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 19 lines · Julien Grall
Hi,
Quoted 8 lines · Brian Woods
On Fri, Oct 11, 2019 at 05:58:35PM +0100, Julien Grall wrote:
For that, you'd need to either check the start and end of the added module or the start of both. So something like:if ( ((
mod->start>= start) && (mod->start< (start + size))) ||((start >= mod->start) && (start < (mod->start + mod->size))) ) printk("WARNING: ...");Quoted 7 lines
If you don't you run the risk of having a module overlap but not at the start of the added module (unless there's a guaranteed order). You're still running all of the checks from what I can tell, just not in nested for loop so. Plus I'm not sure how many times
add_boot_modulegets run and the "mod->kind== kind .." if statement gets run and is true. If the above is true, wouldn't that cause extra checks for the for loop iterations before it was true?
Quoted 5 lines
For non-dom0less case, we are talking about 4 modules max (Xen, Kernel, Initramfs, flask policy). Modules cannot be the shared here.
For dom0less, you are unlikely to have that many domains started from Xen. So the number of modules will still be limited (even more if you share it).
Not arguing that. With the second loop (checking two start addresses) it's only n(n-1)/2 iterations. Even if you had 12 memory modules, it's only 66 iterations. In the large scheme of things, that isn't THAT many.
Quoted 6 lines
This code is also only called at boot where there are bigger time consuming part (such as domheap initialization). So I would be surprised if you see any improvement (other than a couple of cycles) in boot time here.
Therefore, I would favor a readable solution over a micro-optimized solution here.
Which is why I wanted to put it where it was in the patch. Where the user would see the warning after the information about the memory modules were printed (and fair early).
Either way, take your pick of location and if it's only debug or not and I can write it up and test it.
Brian
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi,
Sorry for the late answer.
Quoted 11 lines · Brian Woods
Quoted 6 lines · Julien Grall
This code is also only called at boot where there are bigger time consuming part (such as domheap initialization). So I would be surprised if you see any improvement (other than a couple of cycles) in boot time here.
Therefore, I would favor a readable solution over a micro-optimized solution here.
Which is why I wanted to put it where it was in the patch. Where the user would see the warning after the information about the memory modules were printed (and fair early).
I had a think about it, dumping the modules informations before is useful if you know that you have one module max per kind. So you avoid to print the modules address/size in the warning.
However, it is possible to have multiple kernel module (as long as they don't have the same start address), you could end up with the following message:
"WARNING: modules Kernel and Kernel overlap"
To make the message more meaningful, we would need to print the modules address/size. Therefore, I don't view that it is important to check overlapping in early_print_info(). In this case I would favor any code that don't add a double for loop.
While thinking about this case, it made me realize that we only check the start address to consider a match. This means if the size is different, then it will be ignored. I think we ought to throw at least warning for this case as well.
Would you mind to have a look?
Quoted 3 lines
Either way, take your pick of location and if it's only debug or not and I can write it up and test it.
I would still prefer in add_boot_module(). See why above.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 17 lines · Julien Grall
Hi,
Sorry for the late answer.
Quoted 3 lines · Brian Woods
Which is why I wanted to put it where it was in the patch. Where the user would see the warning after the information about the memory modules were printed (and fair early).
I had a think about it, dumping the modules informations before is useful if you know that you have one module max per kind. So you avoid to print the modules address/size in the warning.
However, it is possible to have multiple kernel module (as long as they don't have the same start address), you could end up with the following message:
Quoted 6 lines
"WARNING: modules Kernel and Kernel overlap"
To make the message more meaningful, we would need to print the modules address/size. Therefore, I don't view that it is important to check overlapping in
early_print_info(). In this case I would favor any code that don't add a double for loop.
Well, adding that information would be easy enough and cheap. It would make it multiline prinktk though:
WARNING: memory modules over lap:
start_addr-end_addr: modulename
start_addr-end_addr: modulename
If we're not doing that though, would it make sense to have a initdata bool that checks it in add_boot_module() and then prints a simple warning that there's a memory module overlap in early_print_info()? That way there's no nested for loop and it gets printed where all the addresses get printed (so you can actually figure out where the overlap is).
Quoted 6 lines
While thinking about this case, it made me realize that we only check the start address to consider a match. This means if the size is different, then it will be ignored. I think we ought to throw at least warning for this case as well.
Would you mind to have a look?
When you say starting address, do you mean like in the orginal patch? If so, there's no functional change in checking the starts of n on m and m on n then checking the start and end of n on m.
Quoted 5 lines
Quoted 3 lines
Either way, take your pick of location and if it's only debug or not and I can write it up and test it.
I would still prefer in
add_boot_module(). See why above.
I wrote I suggested above and tested it so that'll be sent out soon.
Brian
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 1/1 xen/arm: add warning if memory modules overlap
In reply to Brian WoodsIt's possible for a misconfigured device tree to cause Xen to crash when there are overlapping addresses in the memory modules. Add a warning when printing the addresses to let the user know there's a possible issue.
---
v1 -> v2
- removed nested loop and placed check in add_boot_module()
Sample output:
...
(XEN) MODULE[0]: 0000000001400000 - 0000000001542121 Xen
(XEN) MODULE[1]: 0000000003846000 - 0000000003850080 Device Tree
(XEN) MODULE[2]: 0000000003853000 - 0000000007fff676 Ramdisk
(XEN) MODULE[3]: 0000000000080000 - 0000000003180000 Kernel
(XEN) RESVD[0]: 0000000003846000 - 0000000003850000
(XEN) RESVD[1]: 0000000003853000 - 0000000007fff676
(XEN)
(XEN) WARNING: overlap detected in the memory module addresses
(XEN)
(XEN) Command line: console=dtuart dtuart=serial0 dom0_mem=1G bootscrub=0 maxcpus=1 timer_slop=0
...
xen/arch/arm/bootfdt.c | 4 ++++ xen/arch/arm/setup.c | 6 ++++++ xen/include/asm-arm/setup.h | 1 + 3 files changed, 11 insertions(+)
xen/arch/arm/bootfdt.c +4 -0
@@ -387,6 +387,10 @@ static void __init early_print_info(void) mem_resv->bank[j].start + mem_resv->bank[j].size - 1); }printk ("\n" ); + +if ( mem_module_overlap ) +printk ("WARNING: overlap detected in the memory module addresses.\n" ); +for ( i =0 ; i < cmds->nr_mods; i++ ) printk("CMDLINE[%"PRIpaddr"]:%s %s\n", cmds->cmdline[i].start, cmds->cmdline[i].dt_name,
xen/arch/arm/setup.c +6 -0
@@ -69,6 +69,8 @@ integer_param("xenheap_megabytes", opt_xenheap_megabytes);domid_t __read_mostly max_init_domid; +bool __initdata mem_module_overlap; +static __used void init_done (void ) {/* Must be done past setting system_state. */
@@ -254,6 +256,10 @@ struct bootmodule __init *add_boot_module(bootmodule_kind kind, mod->domU = false;return mod; } + +if ( ((mod->start >= start) && (mod->start < start + size)) || + ((start >= mod->start) && (start < mod->start + mod->size)) ) + mem_module_overlap = true; } mod = &mods->module[mods->nr_mods++];
xen/include/asm-arm/setup.h +1 -0
@@ -122,6 +122,7 @@ void device_tree_get_reg(const __be32 **cell, u32 address_cells,u32 device_tree_get_u32 (const void *fdt,int node,const char *prop_name,u32 dflt); +extern bool mem_module_overlap;#endif /* * Local variables:
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi,
Quoted 25 lines · Brian Woods
Quoted 17 lines · Julien Grall
Hi,
Sorry for the late answer.
Quoted 3 lines · Brian Woods
Which is why I wanted to put it where it was in the patch. Where the user would see the warning after the information about the memory modules were printed (and fair early).
I had a think about it, dumping the modules informations before is useful if you know that you have one module max per kind. So you avoid to print the modules address/size in the warning.
However, it is possible to have multiple kernel module (as long as they don't have the same start address), you could end up with the following message:
Quoted 6 lines
"WARNING: modules Kernel and Kernel overlap"
To make the message more meaningful, we would need to print the modules address/size. Therefore, I don't view that it is important to check overlapping in
early_print_info(). In this case I would favor any code that don't add a double for loop.
Quoted 5 lines
Well, adding that information would be easy enough and cheap. It would make it multiline prinktk though:
WARNING: memory modules over lap:
start_addr-end_addr: modulename
start_addr-end_addr: modulename
Why do you need a multiline? A single 80-charaters should really be sufficient.
Quoted 7 lines
If we're not doing that though, would it make sense to have a initdata bool that checks it in
add_boot_module()and then prints a simple warning that there's a memory module overlap inearly_print_info()? That way there's no nested for loop and it gets printed where all the addresses get printed (so you can actually figure out where the overlap is).
Please no. There are no need to add a bool just for the sake of getting all the print together.
The more that if you print all the information as I suggested above, you don't need to have it printed by early_print_info().
To be honest, I really don't think this is Xen job to check that you specify your modules correctly. There are other way to screw up your device-tree anyway (like overlap in memory banks or reserved region...).
The modules overlap can really only happen if you try to have your DT pre-generated and don't bother to use the bootloader (U-boot/Grub) script to generate your DT/modules.
Quoted 11 lines
Quoted 7 lines
While thinking about this case, it made me realize that we only check the start address to consider a match. This means if the size is different, then it will be ignored. I think we ought to throw at least warning for this case as well.
Would you mind to have a look?
When you say starting address, do you mean like in the orginal patch? If so, there's no functional change in checking the starts of n on m and m on n then checking the start and end of n on m.
No. I meant that you could have a device-tree describing two modules starting at the same address, but with a different size.
See the check in add_boot_module() to see if a module already exist of the same kind.
Cheers,
Signature · 5 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi,
Quoted 35 lines · Brian Woods
It's possible for a misconfigured device tree to cause Xen to crash when there are overlapping addresses in the memory modules. Add a warning when printing the addresses to let the user know there's a possible issue.
Signed-off-by Brian Woods <[email protected]>---
v1 -> v2
- removed nested loop and placed check inadd_boot_module()Sample output:
...
(XEN) MODULE[0]: 0000000001400000 - 0000000001542121 Xen
(XEN) MODULE[1]: 0000000003846000 - 0000000003850080 Device Tree
(XEN) MODULE[2]: 0000000003853000 -0000000007fff676Ramdisk
(XEN) MODULE[3]: 0000000000080000 - 0000000003180000 Kernel
(XEN) RESVD[0]: 0000000003846000 - 0000000003850000
(XEN) RESVD[1]: 0000000003853000 -0000000007fff676
(XEN)
(XEN) WARNING: overlap detected in the memory module addresses
(XEN)
(XEN) Command line: console=dtuart dtuart=serial0 dom0_mem=1G bootscrub=0 maxcpus=1 timer_slop=0
...xen/arch/arm/bootfdt.c | 4 ++++ xen/arch/arm/setup.c | 6 ++++++ xen/include/asm-arm/setup.h | 1 + 3 files changed, 11 insertions(+)xen/arch/arm/bootfdt.c +0
-0
xen/arch/arm/bootfdt.c static void __init early_print_info(void) · line 392
Quoted 6 lines
xen/arch/arm/bootfdt.c +3
-0@@ -387,6 +387,10 @@ static void __init early_print_info(void) mem_resv->bank[j].start + mem_resv->bank[j].size - 1); }printk ("\n" ); + +if ( mem_module_overlap ) +printk ("WARNING: overlap detected in the memory module addresses.\n" );
As a user such message would likely put me off. You tell me there are an overlap, but you don't provide more information even if you likely have the information in place. However...
Quoted 18 lines
xen/arch/arm/bootfdt.c +1
-0+for ( i =0 ; i < cmds->nr_mods; i++ ) printk("CMDLINE[%"PRIpaddr"]:%s %s\n", cmds->cmdline[i].start, cmds->cmdline[i].dt_name,xen/arch/arm/setup.c +2
-0@@ -69,6 +69,8 @@ integer_param("xenheap_megabytes", opt_xenheap_megabytes);domid_t __read_mostly max_init_domid; +bool __initdata mem_module_overlap; +static __used void init_done (void ) {/* Must be done past setting system_state. */
xen/arch/arm/setup.c struct bootmodule __init *add_boot_module(bootmodule_kind kind, · line 262
Quoted 7 lines
xen/arch/arm/setup.c +4
-0@@ -254,6 +256,10 @@ struct bootmodule __init *add_boot_module(bootmodule_kind kind, mod->domU = false;return mod; } + +if ( ((mod->start >= start) && (mod->start < start + size)) || + ((start >= mod->start) && (start < mod->start + mod->size)) ) + mem_module_overlap = true;
... What's wrong with just dumping the information here directly?
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 33 lines · Julien Grall
Hi,
Quoted 30 lines · Brian Woods
It's possible for a misconfigured device tree to cause Xen to crash when there are overlapping addresses in the memory modules. Add a warning when printing the addresses to let the user know there's a possible issue.
Signed-off-by Brian Woods <[email protected]>---
v1 -> v2
- removed nested loop and placed check inadd_boot_module()Sample output:
...
(XEN) MODULE[0]: 0000000001400000 - 0000000001542121 Xen
(XEN) MODULE[1]: 0000000003846000 - 0000000003850080 Device Tree
(XEN) MODULE[2]: 0000000003853000 -0000000007fff676Ramdisk
(XEN) MODULE[3]: 0000000000080000 - 0000000003180000 Kernel
(XEN) RESVD[0]: 0000000003846000 - 0000000003850000
(XEN) RESVD[1]: 0000000003853000 -0000000007fff676
(XEN)
(XEN) WARNING: overlap detected in the memory module addresses
(XEN)
(XEN) Command line: console=dtuart dtuart=serial0 dom0_mem=1G bootscrub=0 maxcpus=1 timer_slop=0
...xen/arch/arm/bootfdt.c | 4 ++++ xen/arch/arm/setup.c | 6 ++++++ xen/include/asm-arm/setup.h | 1 + 3 files changed, 11 insertions(+)
Quoted 15 lines
xen/arch/arm/bootfdt.c static void __init early_print_info(void) · line 392
Quoted 11 lines
xen/arch/arm/bootfdt.c +3
-0@@ -387,6 +387,10 @@ static void __init early_print_info(void) mem_resv->bank[j].start + mem_resv->bank[j].size - 1); }printk ("\n" ); + +if ( mem_module_overlap ) +printk ("WARNING: overlap detected in the memory module addresses.\n" );As a user such message would likely put me off. You tell me there are an overlap, but you don't provide more information even if you likely have the information in place. However...
Well, I suppose the message could be changed to something like:
"WARNING: overlap detected in the above memory module addresses." or something to more directly guide the users to the section. Maybe move the 'printk("\n");' after the warning so it's grouped tighter with the module information.
Quoted 12 lines
Quoted 12 lines
xen/arch/arm/bootfdt.c +1
-0+for ( i =0 ; i < cmds->nr_mods; i++ ) printk("CMDLINE[%"PRIpaddr"]:%s %s\n", cmds->cmdline[i].start, cmds->cmdline[i].dt_name,xen/arch/arm/setup.c +0
-0@@ -69,6 +69,8 @@ integer_param("xenheap_megabytes", opt_xenheap_megabytes);domid_t __read_mostly max_init_domid;
Quoted 15 lines
xen/arch/arm/setup.c struct bootmodule __init *add_boot_module(bootmodule_kind kind, · line 262
Quoted 13 lines
xen/arch/arm/setup.c +6
-0+bool __initdata mem_module_overlap; +static __used void init_done (void ) {/* Must be done past setting system_state. */ @@ -254,6 +256,10 @@ struct bootmodule __init *add_boot_module(bootmodule_kind kind, mod->domU = false;return mod; } + +if ( ((mod->start >= start) && (mod->start < start + size)) || + ((start >= mod->start) && (start < mod->start + mod->size)) ) + mem_module_overlap = true;... What's wrong with just dumping the information here directly?
IMO, it is better to have all the information printed in one spot. There is less to go through and easier to find out what is happening. There is also the fact that we do not have to print things twice (2 sets of names, starting addresses and ending addresses per overlap) when it is going to be printed in the near future anyway. The cost of this is just one initdata bool, which while I am not thrilled about, does not seem that expensive (compared to a nested loop or printing out at least (16*2 + 12) * 2 characters per overlap(at least on Arm64)).
I do think the message could use some polish, but this approach makes the most sense to me.
Brian
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 51 lines · Brian Woods
Quoted 33 lines · Julien Grall
Hi,
Quoted 30 lines · Brian Woods
It's possible for a misconfigured device tree to cause Xen to crash when there are overlapping addresses in the memory modules. Add a warning when printing the addresses to let the user know there's a possible issue.
Signed-off-by Brian Woods <[email protected]>---
v1 -> v2
- removed nested loop and placed check inadd_boot_module()Sample output:
...
(XEN) MODULE[0]: 0000000001400000 - 0000000001542121 Xen
(XEN) MODULE[1]: 0000000003846000 - 0000000003850080 Device Tree
(XEN) MODULE[2]: 0000000003853000 -0000000007fff676Ramdisk
(XEN) MODULE[3]: 0000000000080000 - 0000000003180000 Kernel
(XEN) RESVD[0]: 0000000003846000 - 0000000003850000
(XEN) RESVD[1]: 0000000003853000 -0000000007fff676
(XEN)
(XEN) WARNING: overlap detected in the memory module addresses
(XEN)
(XEN) Command line: console=dtuart dtuart=serial0 dom0_mem=1G bootscrub=0 maxcpus=1 timer_slop=0
...xen/arch/arm/bootfdt.c | 4 ++++ xen/arch/arm/setup.c | 6 ++++++ xen/include/asm-arm/setup.h | 1 + 3 files changed, 11 insertions(+)Quoted 15 lines
xen/arch/arm/bootfdt.c static void __init early_print_info(void) · line 392
Quoted 11 lines
xen/arch/arm/bootfdt.c +3
-0@@ -387,6 +387,10 @@ static void __init early_print_info(void) mem_resv->bank[j].start + mem_resv->bank[j].size - 1); }printk ("\n" ); + +if ( mem_module_overlap ) +printk ("WARNING: overlap detected in the memory module addresses.\n" );As a user such message would likely put me off. You tell me there are an overlap, but you don't provide more information even if you likely have the information in place. However...
Quoted 5 lines
Well, I suppose the message could be changed to something like:
"WARNING: overlap detected in the above memory module addresses." or something to more directly guide the users to the section. Maybe move the 'printk("\n");' after the warning so it's grouped tighter with the module information.
My point stands even for this sort of message. You know the exact overlap, so why would you hide it from the users?
Quoted 29 lines
Quoted 13 lines
Quoted 13 lines
xen/arch/arm/bootfdt.c +1
-0+for ( i =0 ; i < cmds->nr_mods; i++ ) printk("CMDLINE[%"PRIpaddr"]:%s %s\n", cmds->cmdline[i].start, cmds->cmdline[i].dt_name,xen/arch/arm/setup.c +0
-0@@ -69,6 +69,8 @@ integer_param("xenheap_megabytes", opt_xenheap_megabytes);domid_t __read_mostly max_init_domid;Quoted 15 lines
xen/arch/arm/setup.c struct bootmodule __init *add_boot_module(bootmodule_kind kind, · line 262
Quoted 13 lines
xen/arch/arm/setup.c +6
-0+bool __initdata mem_module_overlap; +static __used void init_done (void ) {/* Must be done past setting system_state. */ @@ -254,6 +256,10 @@ struct bootmodule __init *add_boot_module(bootmodule_kind kind, mod->domU = false;return mod; } + +if ( ((mod->start >= start) && (mod->start < start + size)) || + ((start >= mod->start) && (start < mod->start + mod->size)) ) + mem_module_overlap = true;... What's wrong with just dumping the information here directly?
Quoted 8 lines
IMO, it is better to have all the information printed in one spot. There is less to go through and easier to find out what is happening. There is also the fact that we do not have to print things twice (2 sets of names, starting addresses and ending addresses per overlap) when it is going to be printed in the near future anyway. The cost of this is just one initdata bool, which while I am not thrilled about, does not seem that expensive (compared to a nested loop or printing out at least (16*2 + 12) * 2 characters per overlap(at least on Arm64)).
Again, this is boot code and not a path that is going to be called hundreds of time. So performance is the last thing I care in this patch.
If we try to help the users by telling them there is an overlap between modules, then we should do it properly and tell them the exact overlap. Otherwise this is nearly as pointless as a crash later on in the boot process.
I also don't want a double for loop or any additional global variable when it can be done by simply adding a check in add_boot_module().
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines · Julien Grall
Quoted 8 lines · Brian Woods
Quoted 5 lines · Julien Grall
Hi,
As a user such message would likely put me off. You tell me there are an overlap, but you don't provide more information even if you likely have the information in place. However...
Quoted 8 lines
Quoted 5 lines
Well, I suppose the message could be changed to something like:
"WARNING: overlap detected in the above memory module addresses." or something to more directly guide the users to the section. Maybe move the 'printk("\n");' after the warning so it's grouped tighter with the module information.My point stands even for this sort of message. You know the exact overlap, so why would you hide it from the users?
We're not hiding it. You're not cluttering up the log with the same data multiple times. See below.
Quoted 16 lines
Quoted 11 lines
Quoted 2 lines
... What's wrong with just dumping the information here directly?
IMO, it is better to have all the information printed in one spot. There is less to go through and easier to find out what is happening. There is also the fact that we do not have to print things twice (2 sets of names, starting addresses and ending addresses per overlap) when it is going to be printed in the near future anyway. The cost of this is just one initdata bool, which while I am not thrilled about, does not seem that expensive (compared to a nested loop or printing out at least (16*2 + 12) * 2 characters per overlap(at least on Arm64)).
Again, this is boot code and not a path that is going to be called hundreds of time. So performance is the last thing I care in this patch.
Quoted 7 lines
If we try to help the users by telling them there is an overlap between modules, then we should do it properly and tell them the exact overlap. Otherwise this is nearly as pointless as a crash later on in the boot process.
I also don't want a double for loop or any additional global variable when it can be done by simply adding a check in
add_boot_module().
This isn't about performance (other than the nested for), this is about providing a relatively clean and sane log to read. It's not that difficult to go through the addresses and see conflicts. This also keeps it all in one part of the log and shorter without losing information. Shorter and well structured logs (without losing info) makes it easier to read. Making logs easier to read helps everyone.
Showing the addresses and module name itself will take 2 lines assuming you stay within 80 chars. (16*2 + 12) * 2 = 88, that's without spaces, '0x's or any sort of message explaining what's actually going wrong. The module names and addresses will be printed out anyway in the near future, so why not group them together?
The purpose of the warning is to tell the user something is wrong, both messages do that and provide the information to determine what's wrong.
Brian
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Brian,
Quoted 16 lines · Brian Woods
Quoted 15 lines · Julien Grall
Quoted 13 lines · Brian Woods
Quoted 5 lines · Julien Grall
Hi,
As a user such message would likely put me off. You tell me there are an overlap, but you don't provide more information even if you likely have the information in place. However...
Well, I suppose the message could be changed to something like:
"WARNING: overlap detected in the above memory module addresses." or something to more directly guide the users to the section. Maybe move the 'printk("\n");' after the warning so it's grouped tighter with the module information.
Quoted 5 lines
Quoted 2 lines
My point stands even for this sort of message. You know the exact overlap, so why would you hide it from the users?
We're not hiding it. You're not cluttering up the log with the same data multiple times. See below.
While the values are the same, the data is printed in a different way to help the users.
Quoted 32 lines
Quoted 17 lines
Quoted 4 lines
Quoted 3 lines
... What's wrong with just dumping the information here directly?
Quoted 8 lines
IMO, it is better to have all the information printed in one spot. There is less to go through and easier to find out what is happening. There is also the fact that we do not have to print things twice (2 sets of names, starting addresses and ending addresses per overlap) when it is going to be printed in the near future anyway. The cost of this is just one initdata bool, which while I am not thrilled about, does not seem that expensive (compared to a nested loop or printing out at least (16*2 + 12) * 2 characters per overlap(at least on Arm64)).
Again, this is boot code and not a path that is going to be called hundreds of time. So performance is the last thing I care in this patch.
Quoted 7 lines
If we try to help the users by telling them there is an overlap between modules, then we should do it properly and tell them the exact overlap. Otherwise this is nearly as pointless as a crash later on in the boot process.
I also don't want a double for loop or any additional global variable when it can be done by simply adding a check in
add_boot_module().This isn't about performance (other than the nested for), this is about providing a relatively clean and sane log to read. It's not that difficult to go through the addresses and see conflicts. This also keeps it all in one part of the log and shorter without losing information. Shorter and well structured logs (without losing info) makes it easier to read. Making logs easier to read helps everyone.
Quoted 5 lines
Showing the addresses and module name itself will take 2 lines assuming you stay within 80 chars. (16*2 + 12) * 2 = 88, that's without spaces, '0x's or any sort of message explaining what's actually going wrong. The module names and addresses will be printed out anyway in the near future, so why not group them together?
Here again you argue about the performance and smaller message... This is a warning (so not printed in the normal course) and Xen is likely to break afterwards. So what you want here is a big fat warning and not a small one and easy to miss.
Quoted 3 lines
The purpose of the warning is to tell the user something is wrong, both messages do that and provide the information to determine what's wrong
We both can probably figure out with more or less some effort. If you have 2-3 modules that's fine. But if you have 10, then it is becoming more complex. My time is quite valuable and therefore I want the hypervisor to help me find.
To make an analogy, would you like if your compiler tells you "There is a bug in file X" but does not tell you the exact line? I personally wouldn't, even if the file is fairly small.
So while I am happy to se a way to check the modules, I dislike this approach. So:
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel