Skip to content

Commit 3b5c082

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Work out supported block level at compile time
Work out the minimum page table level where KVM supports block mappings at compile time. While at it, rewrite the comment around supported block mappings to directly describe what KVM supports instead of phrasing in terms of what it does not. Signed-off-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b302ca5 commit 3b5c082

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

arch/arm64/include/asm/kvm_pgtable.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313

1414
#define KVM_PGTABLE_MAX_LEVELS 4U
1515

16+
/*
17+
* The largest supported block sizes for KVM (no 52-bit PA support):
18+
* - 4K (level 1): 1GB
19+
* - 16K (level 2): 32MB
20+
* - 64K (level 2): 512MB
21+
*/
22+
#ifdef CONFIG_ARM64_4K_PAGES
23+
#define KVM_PGTABLE_MIN_BLOCK_LEVEL 1U
24+
#else
25+
#define KVM_PGTABLE_MIN_BLOCK_LEVEL 2U
26+
#endif
27+
1628
static inline u64 kvm_get_parange(u64 mmfr0)
1729
{
1830
u64 parange = cpuid_feature_extract_unsigned_field(mmfr0,
@@ -58,11 +70,7 @@ static inline u64 kvm_granule_size(u32 level)
5870

5971
static inline bool kvm_level_supports_block_mapping(u32 level)
6072
{
61-
/*
62-
* Reject invalid block mappings and don't bother with 4TB mappings for
63-
* 52-bit PAs.
64-
*/
65-
return !(level == 0 || (PAGE_SIZE != SZ_4K && level == 1));
73+
return level >= KVM_PGTABLE_MIN_BLOCK_LEVEL;
6674
}
6775

6876
/**

0 commit comments

Comments
 (0)