xen: Check if the range is valid in init_domheap_pages
PATCH v2 1/1 xen: Check if the range is valid in init_domheap_pages
On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in the device tree.
In this case, when xen decides to free unused memory, dt_unreserved_regions will call init_domheap_pages with the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.
---
Changes in v2:
- Change commit title
- Move the check in init_domheap_pages
--- xen/common/page_alloc.c | 3 +++ 1 file changed, 3 insertions(+)
xen/common/page_alloc.c +3 -0
@@ -1429,6 +1429,9 @@ void init_domheap_pages(paddr_t ps, paddr_t pe) smfn =round_pgup (ps) >>PAGE_SHIFT ; emfn =round_pgdown (pe) >>PAGE_SHIFT ; +if ( smfn <= emfn ) +return ; +init_heap_pages (mfn_to_page (smfn), emfn - smfn); }
Signature · 1 line
1.8.3.1
Quoted 24 lines · Julien Grall
On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in the device tree.
In this case, when xen decides to free unused memory,dt_unreserved_regionswill callinit_domheap_pageswith the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.Signed-off-by Julien Grall <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>---
Changes in v2:
- Change commit title
- Move the check ininit_domheap_pages--- xen/common/page_alloc.c | 3 +++ 1 file changed, 3 insertions(+)xen/common/page_alloc.c +0
-0
xen/common/page_alloc.c void init_domheap_pages(paddr_t ps, paddr_t pe) · line 1432
Quoted 4 lines
xen/common/page_alloc.c +1
-0@@ -1429,6 +1429,9 @@ void init_domheap_pages(paddr_t ps, paddr_t pe) smfn =round_pgup (ps) >>PAGE_SHIFT ; emfn =round_pgdown (pe) >>PAGE_SHIFT ; +if ( smfn <= emfn )
You've got this backwards I think.
Quoted 5 lines
xen/common/page_alloc.c +2
-0+return ; +init_heap_pages (mfn_to_page (smfn), emfn - smfn); }
Quoted 28 lines · Ian Campbell
Quoted 27 lines · Julien Grall
On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in the device tree.
In this case, when xen decides to free unused memory,dt_unreserved_regionswill callinit_domheap_pageswith the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.Signed-off-by Julien Grall <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>---
Changes in v2:
- Change commit title
- Move the check ininit_domheap_pages--- xen/common/page_alloc.c | 3 +++ 1 file changed, 3 insertions(+)xen/common/page_alloc.c +0
-0@@ -1429,6 +1429,9 @@ void init_domheap_pages(paddr_t ps, paddr_t pe) smfn =round_pgup (ps) >>PAGE_SHIFT ; emfn =round_pgdown (pe) >>PAGE_SHIFT ;
Quoted 3 lines
xen/common/page_alloc.c void init_domheap_pages(paddr_t ps, paddr_t pe) · line 1432
Quoted 1 line
xen/common/page_alloc.c +1
-0+if ( smfn <= emfn )You've got this backwards I think.
Oh right, I will fix it in the next version.
Quoted 8 lines
Quoted 6 lines
xen/common/page_alloc.c +2
-0+return ; +init_heap_pages (mfn_to_page (smfn), emfn - smfn); }
Signature · 1 line
Julien Grall
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Julien Grall
On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in the device tree.
In this case, when xen decides to free unused memory,dt_unreserved_regionswill callinit_domheap_pageswith the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.
The change is simple enough, so I don't really mind it going in, but I wonder ...
Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>---
Changes in v2:
- Change commit title
- Move the check ininit_domheap_pages
... who and why suggested to move it here. After all, I'm considering it an error to call the function with non-page-aligned addresses and/ or end < start (I take it that page-aligned, but start == end is not a problem without your change).
Jan
Quoted 20 lines
xen/common/page_alloc.c +3
-0@@ -1429,6 +1429,9 @@ void init_domheap_pages(paddr_t ps, paddr_t pe) smfn =round_pgup (ps) >>PAGE_SHIFT ; emfn =round_pgdown (pe) >>PAGE_SHIFT ; +if ( smfn <= emfn ) +return ; +init_heap_pages (mfn_to_page (smfn), emfn - smfn); }Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 20 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Julien Grall
On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in the device tree.
In this case, when xen decides to free unused memory,dt_unreserved_regionswill callinit_domheap_pageswith the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.The change is simple enough, so I don't really mind it going in, but I wonder ...
Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>---
Changes in v2:
- Change commit title
- Move the check ininit_domheap_pages
Quoted 4 lines
... who and why suggested to move it here. After all, I'm considering it an error to call the function with non-page-aligned addresses and/ or end < start (I take it that page-aligned, but start == end is not a problem without your change).
if ps == pe, then emfn == (smfn - 1). This will result to the number of pages of -1.
There is a similar check in init_xenheap_pages, it doesn't seem harmfull to let it here.
Signature · 1 line
Julien Grall
Quoted 24 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Quoted 20 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Julien Grall
On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in the device tree.
In this case, when xen decides to free unused memory,dt_unreserved_regionswill callinit_domheap_pageswith the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.The change is simple enough, so I don't really mind it going in, but I wonder ...
Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>---
Changes in v2:
- Change commit title
- Move the check ininit_domheap_pages
Quoted 7 lines
Quoted 4 lines
... who and why suggested to move it here. After all, I'm considering it an error to call the function with non-page-aligned addresses and/ or end < start (I take it that page-aligned, but start == end is not a problem without your change).
if ps == pe, then emfn == (smfn - 1). This will result to the number of pages of -1.
I'm not following: If ps == pe and they're page aligned, then
smfn = round_pgup(ps) >> PAGE_SHIFT;
emfn = round_pgdown(pe) >> PAGE_SHIFT;produces smfn == emfn. So as said earlier - emfn = smfn - 1 requires the input to either be not page aligned, or pe < ps, both of which look invalid to me.
Quoted 2 lines
There is a similar check in
init_xenheap_pages, it doesn't seem harmfull to let it here.
In the CONFIG_SEPARATE_XENHEAP case, yes. And it's there for a good reason - that code doesn't tolerate ps == pe (and if I'm not mistaken would break even on specific ps < pe cases).
Jan
Quoted 41 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Quoted 20 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Julien Grall
On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in the device tree.
In this case, when xen decides to free unused memory,dt_unreserved_regionswill callinit_domheap_pageswith the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.The change is simple enough, so I don't really mind it going in, but I wonder ...
Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>---
Changes in v2:
- Change commit title
- Move the check ininit_domheap_pagesQuoted 7 lines
Quoted 4 lines
... who and why suggested to move it here. After all, I'm considering it an error to call the function with non-page-aligned addresses and/ or end < start (I take it that page-aligned, but start == end is not a problem without your change).
if ps == pe, then emfn == (smfn - 1). This will result to the number of pages of -1.
I'm not following: If ps == pe and they're page aligned, then
smfn = round_pgup(ps) >> PAGE_SHIFT; emfn = round_pgdown(pe) >> PAGE_SHIFT;produces smfn == emfn. So as said earlier - emfn = smfn - 1 requires the input to either be not page aligned, or pe < ps, both of which look invalid to me.
Quoted 6 lines
Quoted 2 lines
There is a similar check in
init_xenheap_pages, it doesn't seem harmfull to let it here.In the
CONFIG_SEPARATE_XENHEAPcase, yes. And it's there for a good reason - that code doesn't tolerate ps == pe (and if I'm not mistaken would break even on specific ps < pe cases).
init_xenheap_pages doesn't tolerate it, so it checks for it instead of pushing the burden onto the caller.
Julien is adding the same check to init_domheap_pages which also doesn't tolerate it, but here you are arguing that it should be up to the caller to not pass invalid parameters.
This could be fixed in the caller, but it seems cleaner to do it in the core to me, since there are plenty of case where you are munging around with addresses and catching all the corners where that munging ends up makes end<=start makes that code uglier.
Ian.
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Julien Grall
There is a similar check in
init_xenheap_pages, it doesn't seem harmfull to let it here.In the
CONFIG_SEPARATE_XENHEAPcase, yes. And it's there for a good reason - that code doesn't tolerate ps == pe (and if I'm not mistaken would break even on specific ps < pe cases).
Quoted 6 lines
init_xenheap_pagesdoesn't tolerate it, so it checks for it instead of pushing the burden onto the caller.Julien is adding the same check to
init_domheap_pageswhich also doesn't tolerate it, but here you are arguing that it should be up to the caller to not pass invalid parameters.
Not exactly: init_xenheap_pages() wants to _shrink_ the area (under certain conditions), and hence needs to check even for the valid (from a calling perspective) case of ps == pe.
Quoted 4 lines
This could be fixed in the caller, but it seems cleaner to do it in the core to me, since there are plenty of case where you are munging around with addresses and catching all the corners where that munging ends up makes end<=start makes that code uglier.
And again, I'm not fundamentally opposed to the patch (and it's anyway Keir who'll need to judge on whether to take it), I'm just trying to point out that there must be something wrong with how the function is being called (and that if it was called with proper arguments, the issue would have shown up in the first place).
Jan
Quoted 5 lines · Jan Beulich
I'm just
trying to point out that there must be something wrong with how the function is being called (and that if it was called with proper arguments, the issue would have shown up in the first place).
I don't think any one has disputed that the inputs are invalid or that the caller could be changed instead.
I think it is better to make this function more liberal in what it accepts (by rejecting certain invalid constructs) than to add complexity to all the callers.
Ian.
Quoted 10 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · Julien Grall
I'm not following: If ps == pe and they're page aligned, then
smfn = round_pgup(ps) >> PAGE_SHIFT; emfn = round_pgdown(pe) >> PAGE_SHIFT;produces smfn == emfn. So as said earlier - emfn = smfn - 1 requires the input to either be not page aligned, or pe < ps, both of which look invalid to me.
Right, my fault I didn't pay attention that ps and pe is non-aligned, with the same value. That will result to my previous assertion.
In any case, init_domheap_pages seems to be able to handle non-aligned address. Otherwise round_pg{up,down} is not necessary.
Signature · 1 line
Julien Grall
Quoted 15 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Julien Grall
On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in the device tree.
In this case, when xen decides to free unused memory,dt_unreserved_regionswill callinit_domheap_pageswith the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.The change is simple enough, so I don't really mind it going in, but I wonder ...
Quoted 4 lines
Signed-off-by Julien Grall <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>
Quoted 6 lines
Quoted 4 lines
---
Changes in v2:
- Change commit title
- Move the check ininit_domheap_pages... who and why suggested to move it here.
Me in response to "xen/arm: Don't call init_domheap_page with an empty range".
Quoted 4 lines
After all, I'm considering
it an error to call the function with non-page-aligned addresses and/ or end < start (I take it that page-aligned, but start == end is not a problem without your change).
Since init_xenheap_page does the right thing it seemed reasonable to me to make domheap do the same.
Ian,