xen/arm: Creating base for future PDX changes
cover xen/arm: Creating base for future PDX changes
Two small patches laying a base for future PDX changes. See discussion here:
https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2507031103360.605088@ubuntu-linux-20-04-desktop/T/#m157f07f957bdad3d807ff53d05e75688a8ae6837
Michal Orzel (2):
xen/arm64: Panic if direct map is too small
xen/arm: Skip loops in init_pdx() when no PDX compression is used
xen/arch/arm/arm32/mmu/mm.c | 1 - xen/arch/arm/arm64/mmu/mm.c | 4 +++- xen/arch/arm/setup.c | 10 ++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 xen/arm64: Panic if direct map is too small
Harden the code by panicing if direct map is too small for current memory
layout taking into account possible PDX compression. Otherwise the assert
is observed:
Assertion '(mfn_to_pdx(maddr_to_mfn(ma)) - directmap_base_pdx) < (DIRECTMAP_SIZE >> PAGE_SHIFT)' failed at ./arch/arm/include/asm/mmu/mm.h:72
At the moment, we don't set max_pdx denoting maximum usable PDX which should be based on max_page. Consolidate setting of max_page and max_pdx in init_pdx() for both arm32 and arm64. max_pdx will be used in the future to set up frametable mappings respecting the PDX grouping.
---
A similar check for frametable will be introduced with other changes to frametable setting in the future.
--- xen/arch/arm/arm32/mmu/mm.c | 1 - xen/arch/arm/arm64/mmu/mm.c | 4 +++- xen/arch/arm/setup.c | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-)
xen/arch/arm/arm32/mmu/mm.c +0 -1
@@ -190,7 +190,6 @@ void __init setup_mm(void)/* Frame table covers all of RAM region, including holes */ setup_frametable_mappings (ram_start, ram_end); - max_page =PFN_DOWN (ram_end);/* * The allocators may need to use map_domain_page() (such as for
xen/arch/arm/arm64/mmu/mm.c +3 -1
@@ -224,6 +224,9 @@ static void __init setup_directmap_mappings(unsigned long base_mfn,*/ directmap_virt_start =DIRECTMAP_VIRT_START + (base_mfn - mfn_gb) *PAGE_SIZE ; + +if ( (max_pdx - directmap_base_pdx) > (DIRECTMAP_SIZE >>PAGE_SHIFT ) ) +panic ("Direct map is too small\n" ); }if ( base_mfn <mfn_x (directmap_mfn_start) )
@@ -278,7 +281,6 @@ void __init setup_mm(void) directmap_mfn_end =maddr_to_mfn (ram_end);setup_frametable_mappings (ram_start, ram_end); - max_page =PFN_DOWN (ram_end);init_staticmem_pages ();init_sharedmem_pages ();
xen/arch/arm/setup.c +5 -1
@@ -254,7 +254,7 @@ static void __init relocate_fdt(const void **dtb_vaddr, size_t dtb_size)void __init init_pdx (void ) {const struct membanks *mem =bootinfo_get_mem (); -paddr_t bank_start, bank_size, bank_end; +paddr_t bank_start, bank_size, bank_end, ram_end =0 ;/* * Arm does not have any restrictions on the bits to compress. Pass 0 to
@@ -290,10 +290,14 @@ void __init init_pdx(void) bank_start = mem->bank[bank].start; bank_size = mem->bank[bank].size; bank_end = bank_start + bank_size; + ram_end =max (ram_end, bank_end);set_pdx_range (paddr_to_pfn (bank_start),paddr_to_pfn (bank_end)); } + + max_page =PFN_DOWN (ram_end); + max_pdx =pfn_to_pdx (max_page -1 ) +1 ; }size_t __read_mostly dcache_line_bytes;
Signature · 1 line
2.25.1
Re: [PATCH 1/2] xen/arm64: Panic if direct map is too small
Quoted 1 line · Michal Orzel
Harden the code by panicing if direct map is too small for current memory
NIT: s/panicing/panicking
Quoted 10 lines
layout taking into account possible PDX compression. Otherwise the assert
is observed:
Assertion '(mfn_to_pdx(maddr_to_mfn(ma)) -directmap_base_pdx) < (DIRECTMAP_SIZE>>PAGE_SHIFT)' failed at./arch/arm/include/asm/mmu/mm.h:72At the moment, we don't set
max_pdxdenoting maximum usable PDX which should be based onmax_page. Consolidate setting ofmax_pageandmax_pdxininit_pdx()for both arm32 and arm64.max_pdxwill be used in the future to set up frametable mappings respecting the PDX grouping.Signed-off-by Michal Orzel <[email protected]>
LGTM! Tested (compilation) via both Arm AArch32 and AArch64 builds.
Many thanks,
Hari
Re: [PATCH 1/2] xen/arm64: Panic if direct map is too small
In reply to Michal OrzelQuoted 11 lines · Michal Orzel
Harden the code by panicing if direct map is too small for current memory
layout taking into account possible PDX compression. Otherwise the assert
is observed:
Assertion '(mfn_to_pdx(maddr_to_mfn(ma)) -directmap_base_pdx) < (DIRECTMAP_SIZE>>PAGE_SHIFT)' failed at./arch/arm/include/asm/mmu/mm.h:72At the moment, we don't set
max_pdxdenoting maximum usable PDX which should be based onmax_page. Consolidate setting ofmax_pageandmax_pdxininit_pdx()for both arm32 and arm64.max_pdxwill be used in the future to set up frametable mappings respecting the PDX grouping.Signed-off-by Michal Orzel <[email protected]>
PATCH 2/2 xen/arm: Skip loops in init_pdx() when no PDX compression is used
In reply to Michal OrzelWhen CONFIG_PDX_COMPRESSION=n, pdx_init_mask(), pdx_region_mask() and pfn_pdx_hole_setup() are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.
--- xen/arch/arm/setup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/arm/setup.c +3 -1
@@ -255,7 +255,9 @@ void __init init_pdx(void) {const struct membanks *mem =bootinfo_get_mem ();paddr_t bank_start, bank_size, bank_end, ram_end =0 ; +int bank; +#ifdef CONFIG_PDX_COMPRESSION /* * Arm does not have any restrictions on the bits to compress. Pass 0 to * let the common code further restrict the mask.
@@ -264,7 +266,6 @@ void __init init_pdx(void)* update this function too. */ uint64_t mask =pdx_init_mask (0x0 ); -int bank;for ( bank =0 ; bank < mem->nr_banks; bank++ ) {
@@ -284,6 +285,7 @@ void __init init_pdx(void) }pfn_pdx_hole_setup (mask >>PAGE_SHIFT ); +#endif for ( bank =0 ; bank < mem->nr_banks; bank++ ) {
Signature · 1 line
2.25.1
Re: [PATCH 2/2] xen/arm: Skip loops in init_pdx() when no PDX compression is used
Hi Michal,
Quoted 15 lines · Michal Orzel
When
CONFIG_PDX_COMPRESSION=n,pdx_init_mask(),pdx_region_mask()andpfn_pdx_hole_setup()are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.Signed-off-by Michal Orzel <[email protected]>--- xen/arch/arm/setup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen/arch/arm/setup.c +0
-0
xen/arch/arm/setup.c void __init init_pdx(void) · line 258
Quoted 4 lines
xen/arch/arm/setup.c +1
-0@@ -255,7 +255,9 @@ void __init init_pdx(void) {const struct membanks *mem =bootinfo_get_mem ();paddr_t bank_start, bank_size, bank_end, ram_end =0 ; +int bank;
Minor/question: Would we potentially prefer to move the declaration of the loop counter bank variables to each for loop? As the variable is not used outside of the loops and is always initialized to 0, this seems perhaps better from a variable scope perspective?
Quoted 14 lines
xen/arch/arm/setup.c +1
-1+#ifdef CONFIG_PDX_COMPRESSION /* * Arm does not have any restrictions on the bits to compress. Pass 0 to * let the common code further restrict the mask. @@ -264,7 +266,6 @@ void __init init_pdx(void)* update this function too. */ uint64_t mask =pdx_init_mask (0x0 ); -int bank;for ( bank =0 ; bank < mem->nr_banks; bank++ ) {
xen/arch/arm/setup.c void __init init_pdx(void) · line 291
Quoted 7 lines
xen/arch/arm/setup.c +1
-0@@ -284,6 +285,7 @@ void __init init_pdx(void) }pfn_pdx_hole_setup (mask >>PAGE_SHIFT ); +#endif for ( bank =0 ; bank < mem->nr_banks; bank++ ) {
Otherwise, LGTM! Tested (compilation) via both Arm AArch32 and AArch64 builds.
Many thanks,
Hari
Re: [PATCH 2/2] xen/arm: Skip loops in init_pdx() when no PDX compression is used
Quoted 12 lines · Hari Limaye
Hi Michal,
Quoted 10 lines · Michal Orzel
When
CONFIG_PDX_COMPRESSION=n,pdx_init_mask(),pdx_region_mask()andpfn_pdx_hole_setup()are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.Signed-off-by Michal Orzel <[email protected]>--- xen/arch/arm/setup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 14 lines
xen/arch/arm/setup.c void __init init_pdx(void) · line 258
Quoted 9 lines
xen/arch/arm/setup.c +1
-0@@ -255,7 +255,9 @@ void __init init_pdx(void) {const struct membanks *mem =bootinfo_get_mem ();paddr_t bank_start, bank_size, bank_end, ram_end =0 ; +int bank;Minor/question: Would we potentially prefer to move the declaration of the loop counter
bankvariables to each for loop? As the variable is not used outside of the loops and is always initialized to 0, this seems perhaps better from a variable scope perspective?
Maybe it does but it was too minor for me to be willing to incorporate it in this patch whose goal was not to reduce the variable scope (I think adding such change would not fit the purpose of the patch).
Quoted 20 lines
Quoted 20 lines
xen/arch/arm/setup.c +2
-1+#ifdef CONFIG_PDX_COMPRESSION /* * Arm does not have any restrictions on the bits to compress. Pass 0 to * let the common code further restrict the mask. @@ -264,7 +266,6 @@ void __init init_pdx(void)* update this function too. */ uint64_t mask =pdx_init_mask (0x0 ); -int bank;for ( bank =0 ; bank < mem->nr_banks; bank++ ) {@@ -284,6 +285,7 @@ void __init init_pdx(void) }pfn_pdx_hole_setup (mask >>PAGE_SHIFT ); +#endif
Quoted 7 lines
xen/arch/arm/setup.c void __init init_pdx(void) · line 291
Quoted 2 lines
xen/arch/arm/setup.c +0
-0for ( bank =0 ; bank < mem->nr_banks; bank++ ) {Otherwise, LGTM! Tested (compilation) via both Arm AArch32 and AArch64 builds.
Many thanks,
Hari
Thanks.
~Michal
Re: [PATCH 2/2] xen/arm: Skip loops in init_pdx() when no PDX compression is used
In reply to Michal OrzelApologies for noise, my previous message was missing the intended tags:
Quoted 6 lines · Michal Orzel
When
CONFIG_PDX_COMPRESSION=n,pdx_init_mask(),pdx_region_mask()andpfn_pdx_hole_setup()are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.Signed-off-by Michal Orzel <[email protected]>---
Cheers,
Hari
Re: [PATCH 2/2] xen/arm: Skip loops in init_pdx() when no PDX compression is used
In reply to Michal OrzelQuoted 5 lines · Michal Orzel
When
CONFIG_PDX_COMPRESSION=n,pdx_init_mask(),pdx_region_mask()andpfn_pdx_hole_setup()are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.Signed-off-by Michal Orzel <[email protected]>
Quoted 37 lines
--- xen/arch/arm/setup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen/arch/arm/setup.c +3
-1@@ -255,7 +255,9 @@ void __init init_pdx(void) {const struct membanks *mem =bootinfo_get_mem ();paddr_t bank_start, bank_size, bank_end, ram_end =0 ; +int bank; +#ifdef CONFIG_PDX_COMPRESSION /* * Arm does not have any restrictions on the bits to compress. Pass 0 to * let the common code further restrict the mask. @@ -264,7 +266,6 @@ void __init init_pdx(void)* update this function too. */ uint64_t mask =pdx_init_mask (0x0 ); -int bank;for ( bank =0 ; bank < mem->nr_banks; bank++ ) {@@ -284,6 +285,7 @@ void __init init_pdx(void) }pfn_pdx_hole_setup (mask >>PAGE_SHIFT ); +#endif for ( bank =0 ; bank < mem->nr_banks; bank++ ) {Signature · 1 line
2.25.1
Re: [PATCH 2/2] xen/arm: Skip loops in init_pdx() when no PDX compression is used
In reply to Michal OrzelHi Michal,
Quoted 3 lines · Michal Orzel
When
CONFIG_PDX_COMPRESSION=n,pdx_init_mask(),pdx_region_mask()andpfn_pdx_hole_setup()are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.
I saw this was already committed. But I have a question. Wouldn't the compiler be able to optimize and remove the loops? Asking because we are trying to limit the number of #ifdef in the code hence why we have stubs.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 2/2] xen/arm: Skip loops in init_pdx() when no PDX compression is used
Quoted 10 lines · Julien Grall
Hi Michal,
Quoted 3 lines · Michal Orzel
When
CONFIG_PDX_COMPRESSION=n,pdx_init_mask(),pdx_region_mask()andpfn_pdx_hole_setup()are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.I saw this was already committed. But I have a question. Wouldn't the compiler be able to optimize and remove the loops? Asking because we are trying to limit the number of #ifdef in the code hence why we have stubs.
Before submitting a patch I did disassembled init_pdx() with and without my patch and in the latter case the compiler did not optimize out the loops.
~Michal
Re: [PATCH 2/2] xen/arm: Skip loops in init_pdx() when no PDX compression is used
Hi Michal,
Quoted 10 lines · Michal
Quoted 7 lines · Julien Grall
Hi Michal,
Quoted 3 lines · Michal Orzel
When
CONFIG_PDX_COMPRESSION=n,pdx_init_mask(),pdx_region_mask()andpfn_pdx_hole_setup()are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.
Quoted 5 lines
Quoted 3 lines
I saw this was already committed. But I have a question. Wouldn't the compiler be able to optimize and remove the loops? Asking because we are trying to limit the number of #ifdef in the code hence why we have stubs.
Before submitting a patch I did disassembled
init_pdx()with and without my patch and in the latter case the compiler did not optimize out the loops.
One more question. Was this in debug or non-debug build?
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 2/2] xen/arm: Skip loops in init_pdx() when no PDX compression is used
Quoted 13 lines · Julien Grall
Hi Michal,
Quoted 10 lines · Michal
Quoted 7 lines · Julien Grall
Hi Michal,
Quoted 3 lines · Michal Orzel
When
CONFIG_PDX_COMPRESSION=n,pdx_init_mask(),pdx_region_mask()andpfn_pdx_hole_setup()are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I saw this was already committed. But I have a question. Wouldn't the compiler be able to optimize and remove the loops? Asking because we are trying to limit the number of #ifdef in the code hence why we have stubs.
Before submitting a patch I did disassembled
init_pdx()with and without my patch and in the latter case the compiler did not optimize out the loops.One more question. Was this in debug or non-debug build?
It was in debug build.
~Michal
Re: [PATCH 2/2] xen/arm: Skip loops in init_pdx() when no PDX compression is used
Hi Michal,
Quoted 16 lines · Michal
Quoted 13 lines · Julien Grall
Hi Michal,
Quoted 10 lines · Michal
Quoted 7 lines · Julien Grall
Hi Michal,
Quoted 3 lines · Michal Orzel
When
CONFIG_PDX_COMPRESSION=n,pdx_init_mask(),pdx_region_mask()andpfn_pdx_hole_setup()are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I saw this was already committed. But I have a question. Wouldn't the compiler be able to optimize and remove the loops? Asking because we are trying to limit the number of #ifdef in the code hence why we have stubs.
Before submitting a patch I did disassembled
init_pdx()with and without my patch and in the latter case the compiler did not optimize out the loops.One more question. Was this in debug or non-debug build?
It was in debug build.
Ok. I would be interested to know if this change in non-debug build because we have quite a few places in Xen relying on code elimination.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 2/2] xen/arm: Skip loops in init_pdx() when no PDX compression is used
Quoted 22 lines · Julien Grall
Hi Michal,
Quoted 19 lines · Michal
Quoted 16 lines · Julien Grall
Hi Michal,
Quoted 13 lines · Michal
Quoted 10 lines · Julien Grall
Hi Michal,
Quoted 3 lines · Michal Orzel
When
CONFIG_PDX_COMPRESSION=n,pdx_init_mask(),pdx_region_mask()andpfn_pdx_hole_setup()are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.I saw this was already committed. But I have a question. Wouldn't the compiler be able to optimize and remove the loops? Asking because we are trying to limit the number of #ifdef in the code hence why we have stubs.
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Before submitting a patch I did disassembled
init_pdx()with and without my patch and in the latter case the compiler did not optimize out the loops.One more question. Was this in debug or non-debug build?
It was in debug build.
Ok. I would be interested to know if this change in non-debug build because we have quite a few places in Xen relying on code elimination.
I did a test and with -O2 (non-debug), the loops are removed as oppose to -O1 (debug). That said, -fdce is part of -O1, so it's difficult to say what option made impact here.
~Michal
Re: [PATCH 2/2] xen/arm: Skip loops in init_pdx() when no PDX compression is used
Hi Michal,
Quoted 28 lines · Michal
Quoted 25 lines · Julien Grall
Hi Michal,
Quoted 22 lines · Michal
Quoted 19 lines · Julien Grall
Hi Michal,
Quoted 15 lines · Michal
Quoted 10 lines · Julien Grall
Hi Michal,
Quoted 3 lines · Michal Orzel
When
CONFIG_PDX_COMPRESSION=n,pdx_init_mask(),pdx_region_mask()andpfn_pdx_hole_setup()are just stubs doing nothing. It does not make sense to keep the two loops iterating over all the memory banks.I saw this was already committed. But I have a question. Wouldn't the compiler be able to optimize and remove the loops? Asking because we are trying to limit the number of #ifdef in the code hence why we have stubs.
Before submitting a patch I did disassembled
init_pdx()with and without my patch and in the latter case the compiler did not optimize out the loops.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
One more question. Was this in debug or non-debug build?
It was in debug build.
Ok. I would be interested to know if this change in non-debug build because we have quite a few places in Xen relying on code elimination.
I did a test and with -O2 (non-debug), the loops are removed as oppose to -O1 (debug). That said, -fdce is part of -O1, so it's difficult to say what option made impact here.
Ok. If the compiler is able to remove the code in non-debug build, then I think we should avoid using #ifdef. This is matching the policy we have for the rest of the code base.
IIRC, the idea was to be able to catch compile error in advance (we had some cases where we forgot to update code within the #ifdef).
Cheers,
Signature · 1 line
Julien Grall