xen/arm: Frametable hardening and config.h cleanup
v2 cover xen/arm: Frametable hardening and config.h cleanup
The first patch fixes a bug due to incorrect DIRECTMAP_SIZE calculation.
The second patch removes unused macro FRAMETABLE_VIRT_END.
The third patch hardens the setup_frametable_mappings by adding a sanity check for the size of struct page_info and calling panic if the calculate size of the frametable exceeds the limit.
Sent together for ease of merging.
Michal Orzel (3):
xen/arm64: Fix incorrect DIRECTMAP_SIZE calculation xen/arm32: Remove unused macro FRAMETABLE_VIRT_END xen/arm: Harden setup_frametable_mappings
xen/arch/arm/include/asm/config.h | 7 +++---- xen/arch/arm/include/asm/mm.h | 11 +++++++++++ xen/arch/arm/mm.c | 6 ++++++ 3 files changed, 20 insertions(+), 4 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/3 xen/arm64: Fix incorrect DIRECTMAP_SIZE calculation
The direct mapped area occupies L0 slots from 256 to 265 included (i.e. 10 slots), resulting in 5TB (512GB * 10) of virtual address space. However, due to incorrect slot subtraction (we take 9 slots into account) we set DIRECTMAP_SIZE to 4.5TB instead. Fix it.
Note that we only support up to 2TB of physical memory so this is a latent issue.
---
Changes in v2:
- update commit msg making it clear that this is a latent issue
--- xen/arch/arm/include/asm/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/include/asm/config.h +1 -1
@@ -157,7 +157,7 @@#define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table))#define DIRECTMAP_VIRT_START SLOT0(256) -#define DIRECTMAP_SIZE (SLOT0_ENTRY_SIZE * (265-256)) +#define DIRECTMAP_SIZE (SLOT0_ENTRY_SIZE * (266 - 256))#define DIRECTMAP_VIRT_END (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE - 1)#define XENHEAP_VIRT_START directmap_virt_start
Signature · 1 line
2.25.1
Re: [PATCH v2 1/3] xen/arm64: Fix incorrect DIRECTMAP_SIZE calculation
Hi Michal,
Quoted 10 lines · Michal Orzel
The direct mapped area occupies L0 slots from 256 to 265 included (i.e. 10 slots), resulting in 5TB (512GB * 10) of virtual address space. However, due to incorrect slot subtraction (we take 9 slots into account) we set
DIRECTMAP_SIZEto 4.5TB instead. Fix it.Note that we only support up to 2TB of physical memory so this is a latent issue.
Fixes 5263507b1b4a ("xen: arm: Use a direct mapping of RAM on arm64")Signed-off-by Michal Orzel <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v2 2/3 xen/arm32: Remove unused macro FRAMETABLE_VIRT_END
In reply to Michal OrzelThis macro is unused and the corresponding one for arm64 has already been removed as part of the commit 6dc9a1fe982f ("xen/arm: Remove most of the *_VIRT_END defines").
---
Changes in v2:
- move a change to a separate patch
--- xen/arch/arm/include/asm/config.h | 1 - 1 file changed, 1 deletion(-)
xen/arch/arm/include/asm/config.h +0 -1
@@ -127,7 +127,6 @@#define FRAMETABLE_VIRT_START _AT(vaddr_t,0x02000000)#define FRAMETABLE_SIZE MB(128-32)#define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table)) -#define FRAMETABLE_VIRT_END (FRAMETABLE_VIRT_START + FRAMETABLE_SIZE - 1)#define VMAP_VIRT_START _AT(vaddr_t,0x10000000)#define VMAP_VIRT_SIZE _AT(vaddr_t, GB(1) - MB(256))
Signature · 1 line
2.25.1
Re: [PATCH v2 2/3] xen/arm32: Remove unused macro FRAMETABLE_VIRT_END
Hi Michal,
Quoted 5 lines · Michal Orzel
This macro is unused and the corresponding one for arm64 has already been removed as part of the commit
6dc9a1fe982f("xen/arm: Remove most of the*_VIRT_ENDdefines").Signed-off-by Michal Orzel <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v2 3/3 xen/arm: Harden setup_frametable_mappings
In reply to Michal OrzelThe amount of supported physical memory depends on the frametable size and the number of struct page_info entries that can fit into it. Define a macro PAGE_INFO_SIZE to store the current size of the struct page_info (i.e. 56B for arm64 and 32B for arm32) and add a sanity check in setup_frametable_mappings to be notified whenever the size of the structure changes. Also call a panic if the calculated frametable_size exceeds the limit defined by FRAMETABLE_SIZE macro.
Update the comments regarding the frametable in asm/config.h.
---
Changes in v2:
- refactor panic message
- move removal of FRAMETABLE_VIRT_END to a separate patch
--- xen/arch/arm/include/asm/config.h | 4 ++-- xen/arch/arm/include/asm/mm.h | 11 +++++++++++ xen/arch/arm/mm.c | 6 ++++++ 3 files changed, 19 insertions(+), 2 deletions(-)
xen/arch/arm/include/asm/config.h +2 -2
@@ -82,7 +82,7 @@* ARM32 layout: * 0 - 12M <COMMON> * -* 32M - 128M Frametable: 24 bytes per page for 16GB of RAM +* 32M - 128M Frametable: 32 bytes per page for 12GB of RAM * 256M - 1G VMAP: ioremap and early_ioremap use this virtual address * space *
@@ -95,7 +95,7 @@* * 1G - 2G VMAP: ioremap and early_ioremap * -* 32G - 64G Frametable: 24 bytes per page for 5.3TB of RAM +* 32G - 64G Frametable: 56 bytes per page for 2TB of RAM * * 0x0000008000000000 - 0x00007fffffffffff (127.5TB, L0 slots [1..255]) * Unused
xen/arch/arm/include/asm/mm.h +11 -0
@@ -26,6 +26,17 @@*/ #define PFN_ORDER (_pfn) ((_pfn)->v.free.order) +/* +* The size of struct page_info impacts the number of entries that can fit +* into the frametable area and thus it affects the amount of physical memory +* we claim to support. Define PAGE_INFO_SIZE to be used for sanity checking. +*/ +#ifdef CONFIG_ARM_64 +#define PAGE_INFO_SIZE 56 +#else +#define PAGE_INFO_SIZE 32 +#endif +struct page_info {/* Each frame can be threaded onto a doubly-linked list. */
xen/arch/arm/mm.c +6 -0
@@ -676,6 +676,12 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe)const unsigned long mapping_size = frametable_size <MB (32 ) ?MB (2 ) :MB (32 );int rc; +BUILD_BUG_ON (sizeof (struct page_info ) !=PAGE_INFO_SIZE ); + +if ( frametable_size >FRAMETABLE_SIZE ) +panic ("The frametable cannot cover the physical region %#" PRIpaddr" - %#" PRIpaddr"\n" , + ps, pe); + frametable_base_pdx =mfn_to_pdx (maddr_to_mfn (ps));/* Round up to 2M or 32M boundary, as appropriate. */ frametable_size =ROUNDUP (frametable_size, mapping_size);
Signature · 1 line
2.25.1
Re: [PATCH v2 3/3] xen/arm: Harden setup_frametable_mappings
Hi Michal,
Quoted 11 lines · Michal Orzel
The amount of supported physical memory depends on the frametable size and the number of struct
page_infoentries that can fit into it. Define a macroPAGE_INFO_SIZEto store the current size of the structpage_info(i.e. 56B for arm64 and 32B for arm32) and add a sanity check insetup_frametable_mappingsto be notified whenever the size of the structure changes. Also call a panic if the calculatedframetable_sizeexceeds the limit defined byFRAMETABLE_SIZEmacro.Update the comments regarding the frametable in
asm/config.h.Signed-off-by Michal Orzel <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
Hi,
Quoted 8 lines · Michal Orzel
The first patch fixes a bug due to incorrect
DIRECTMAP_SIZEcalculation.The second patch removes unused macro
FRAMETABLE_VIRT_END.The third patch hardens the
setup_frametable_mappingsby adding a sanity check for the size of structpage_infoand calling panic if the calculate size of the frametable exceeds the limit.
Quoted 6 lines
Sent together for ease of merging.
Michal Orzel (3):
xen/arm64: Fix incorrectDIRECTMAP_SIZEcalculation xen/arm32: Remove unused macroFRAMETABLE_VIRT_ENDxen/arm: Hardensetup_frametable_mappings
I have committed the series.
Cheers,
Signature · 1 line
Julien Grall