page-alloc: fix initialization of cross-node regions
PATCH 1/1 page-alloc: fix initialization of cross-node regions
Quite obviously to determine the split condition successive pages' attributes need to be evaluated, not always those of the initial page.
---
Part of the problem was already introduced in 24a53060bd37 ("xen/heap:
Split init_heap_pages() in two"), but there it was still benign.
xen/common/page_alloc.c +2 -2
@@ -1885,11 +1885,11 @@ static void init_heap_pages(* range to cross zones. */ #ifdef CONFIG_SEPARATE_XENHEAP -if ( zone !=page_to_zone (pg) ) +if ( zone !=page_to_zone (pg + contig_pages) )break ;#endif -if ( nid != (phys_to_nid (page_to_maddr (pg))) ) +if ( nid != (phys_to_nid (page_to_maddr (pg + contig_pages))) )break ; }
Hi Jan,
(Sorry for the formatting)
Quoted 10 lines · On Mon, 25 Jul 2022, 14:10 Jan Beulich, <[email protected]> wrote:
Quite obviously to determine the split condition successive pages' attributes need to be evaluated, not always those of the initial page.
Fixes 72b02bc75b47 ("xen/heap: pass order to free_heap_pages() in heapinit")
Signed-off-by Jan Beulich <[email protected]>---
Part of the problem was already introduced in24a53060bd37("xen/heap:
Splitinit_heap_pages()in two"), but there it was still benign.
Is this because range will never cross numa node? How about the fake NUMA node?
Quoted 6 lines
xen/common/page_alloc.c +0
-0@@ -1885,11 +1885,11 @@ static void init_heap_pages(* range to cross zones. */ #ifdef CONFIG_SEPARATE_XENHEAP
xen/common/page_alloc.c static void init_heap_pages( · line 1895
Quoted 10 lines
xen/common/page_alloc.c +2
-2-if ( zone !=page_to_zone (pg) ) +if ( zone !=page_to_zone (pg + contig_pages) )break ;#endif -if ( nid != (phys_to_nid (page_to_maddr (pg))) ) +if ( nid != (phys_to_nid (page_to_maddr (pg + contig_pages))) )break ; }
Hmmm I am not sure why I didn't spot this issue during my testing. It looks like this was introduced in v2, sorry for that.
Cheets,
Quoted 1 line
Quoted 1 line · Julien Grall
(Sorry for the formatting)
No issues seen.
Quoted 13 lines · On Mon, 25 Jul 2022, 14:10 Jan Beulich, <[email protected]> wrote:
Quoted 11 lines
Quite obviously to determine the split condition successive pages' attributes need to be evaluated, not always those of the initial page.
Fixes 72b02bc75b47 ("xen/heap: pass order to free_heap_pages() in heapinit")
Signed-off-by Jan Beulich <[email protected]>---
Part of the problem was already introduced in24a53060bd37("xen/heap:
Splitinit_heap_pages()in two"), but there it was still benign.
Quoted 2 lines
Is this because range will never cross numa node? How about the fake NUMA node?
No (afaict), because pages were still freed one by one (and hence node boundaries still wouldn't end up in the middle of a buddy).
Quoted 20 lines
Quoted 6 lines
xen/common/page_alloc.c +0
-0@@ -1885,11 +1885,11 @@ static void init_heap_pages(* range to cross zones. */ #ifdef CONFIG_SEPARATE_XENHEAP xen/common/page_alloc.c static void init_heap_pages( · line 1895
Quoted 10 lines
xen/common/page_alloc.c +2
-2-if ( zone !=page_to_zone (pg) ) +if ( zone !=page_to_zone (pg + contig_pages) )break ;#endif -if ( nid != (phys_to_nid (page_to_maddr (pg))) ) +if ( nid != (phys_to_nid (page_to_maddr (pg + contig_pages))) )break ; }Hmmm I am not sure why I didn't spot this issue during my testing. It looks like this was introduced in v2, sorry for that.
Quoted 1 line
Reviewed-by Julien Grall <[email protected]>
Thanks.
Jan
Hi Jan,
Quoted 4 lines · Jan Beulich
Quoted 1 line · Julien Grall
(Sorry for the formatting)
No issues seen.
Good to know. I sent it from my phone and the gmail app used to mangle e-mails.
Quoted 14 lines
Quoted 14 lines · On Mon, 25 Jul 2022, 14:10 Jan Beulich, <[email protected]> wrote:
Quoted 11 lines
Quite obviously to determine the split condition successive pages' attributes need to be evaluated, not always those of the initial page.
Fixes 72b02bc75b47 ("xen/heap: pass order to free_heap_pages() in heapinit")
Signed-off-by Jan Beulich <[email protected]>---
Part of the problem was already introduced in24a53060bd37("xen/heap:
Splitinit_heap_pages()in two"), but there it was still benign.
Quoted 5 lines
Quoted 2 lines
Is this because range will never cross numa node? How about the fake NUMA node?
No (afaict), because pages were still freed one by one (and hence node boundaries still wouldn't end up in the middle of a buddy).
So I agree that free_heap_pages() would be called with one page at the time. However, I think _init_heap_pages() would end up to be called with the full range.
So we would initialize the first node but not the others (if the range spans over multiple ones). Therefore, I think free_heap_pages() could dereference a NULL pointer.
Anyway, I would not expect anyone to only backport the patch to split _init_heap_pages() and... in any case you already committed it (which is fine given this is a major regression).
Cheers,
Signature · 1 line
Julien Grall
Quoted 8 lines · Jan Beulich
Quite obviously to determine the split condition successive pages' attributes need to be evaluated, not always those of the initial page.
Fixes 72b02bc75b47 ("xen/heap: pass order to free_heap_pages() in heap init")Signed-off-by Jan Beulich <[email protected]>---
Part of the problem was already introduced in24a53060bd37("xen/heap:
Splitinit_heap_pages()in two"), but there it was still benign.
This also fixes the crash that XenRT found on loads of hardware, which looks something like:
(XEN) NUMA: Allocated memnodemap from 105bc81000 - 105bc92000 (XEN) NUMA: Using 8 for the hash shift.
(XEN) Early fatal page fault at e008:ffff82d04022ae1e (cr2=00000000000000b8, ec=0002)
(XEN) ----[ Xen-4.17.0 x86_64 debug=y Not tainted ]---- (XEN) CPU: 0
(XEN) RIP: e008:[<ffff82d04022ae1e>] common/page_alloc.c#free_heap_pages+0x2dd/0x850
...
(XEN) Xen call trace:
(XEN) [<ffff82d04022ae1e>] R common/page_alloc.c#free_heap_pages+0x2dd/0x850 (XEN) [<ffff82d04022dd64>] F common/page_alloc.c#init_heap_pages+0x55f/0x720 (XEN) [<ffff82d040415234>] F end_boot_allocator+0x187/0x1e7 (XEN) [<ffff82d040452337>] F __start_xen+0x1a06/0x2779 (XEN) [<ffff82d040204344>] F __high_start+0x94/0xa0
Debugging shows that it's always a block which crosses node 0 and 1, where avail[1] has yet to be initialised.
What I'm confused by is how this manages to manifest broken swiotlb issues without Xen crashing.
~Andrew
Quoted 31 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich
Quite obviously to determine the split condition successive pages' attributes need to be evaluated, not always those of the initial page.
Fixes 72b02bc75b47 ("xen/heap: pass order to free_heap_pages() in heap init")Signed-off-by Jan Beulich <[email protected]>---
Part of the problem was already introduced in24a53060bd37("xen/heap:
Splitinit_heap_pages()in two"), but there it was still benign.This also fixes the crash that XenRT found on loads of hardware, which looks something like:
(XEN) NUMA: Allocated memnodemap from
105bc81000-105bc92000(XEN) NUMA: Using 8 for the hash shift.
(XEN) Early fatal page fault at e008:ffff82d04022ae1e (cr2=00000000000000b8, ec=0002)
(XEN) ----[ Xen-4.17.0 x86_64 debug=y Not tainted ]---- (XEN) CPU: 0
(XEN) RIP: e008:[<ffff82d04022ae1e>] common/page_alloc.c#free_heap_pages+0x2dd/0x850
...
(XEN) Xen call trace:
(XEN) [<ffff82d04022ae1e>] R common/page_alloc.c#free_heap_pages+0x2dd/0x850 (XEN) [<ffff82d04022dd64>] F common/page_alloc.c#init_heap_pages+0x55f/0x720 (XEN) [<ffff82d040415234>] Fend_boot_allocator+0x187/0x1e7(XEN) [<ffff82d040452337>] F__start_xen+0x1a06/0x2779(XEN) [<ffff82d040204344>] F__high_start+0x94/0xa0
Quoted 5 lines
Debugging shows that it's always a block which crosses node 0 and 1, where avail[1] has yet to be initialised.
What I'm confused by is how this manages to manifest broken swiotlb issues without Xen crashing.
I didn't debug this in detail since I had managed to spot the issue by staring at the offending patch, but from the observations some of node 1's memory was actually accounted to node 0 (incl off-by- 65535 node_need_scrub[] values for both nodes), so I would guess avail[1] simply wasn't accessed before being set up in my case.
Jan