Skip to content

Commit

Permalink
arm64: Make the PHYS_MASK_SHIFT dynamic
Browse files Browse the repository at this point in the history
Make the PHYS_MASK_SHIFT dynamic for Realms. This is only is required
for masking the PFN from a pte entry. Elsewhere, we could still use the
PA bits configured by the kernel. So, this patch:

 -> renames PHYS_MASK_SHIFT -> MAX_PHYS_SHIFT as supported by the kernel
 -> Makes PHYS_MASK_SHIFT -> Dynamic value of the (I)PA bit width
 -> For a realm: reduces phys_mask_shift if the RMM reports a smaller
    configured size for the guest.

Co-developed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Steven Price <steven.price@arm.com>
  • Loading branch information
Steven Price authored and intel-lab-lkp committed Jan 28, 2023
1 parent a1da93a commit 31ee93a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion arch/arm64/include/asm/kvm_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
* bits in PAR are res0.
*/
#define PAR_TO_HPFAR(par) \
(((par) & GENMASK_ULL(52 - 1, 12)) >> 8)
(((par) & GENMASK_ULL(MAX_PHYS_MASK_SHIFT - 1, 12)) >> 8)

#define ECN(x) { ESR_ELx_EC_##x, #x }

Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/include/asm/pgtable-hwdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@
/*
* Highest possible physical address supported.
*/
#define PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS)
#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1)
#define MAX_PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS)
#define MAX_PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1)

#define TTBR_CNP_BIT (UL(1) << 0)

Expand Down
5 changes: 5 additions & 0 deletions arch/arm64/include/asm/pgtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
#include <linux/sched.h>
#include <linux/page_table_check.h>

extern unsigned int phys_mask_shift;

#define PHYS_MASK_SHIFT (phys_mask_shift)
#define PHYS_MASK ((1UL << PHYS_MASK_SHIFT) - 1)

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
#define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE

Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/kernel/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ SYM_FUNC_START_LOCAL(create_idmap)
#error "Mismatch between VA_BITS and page size/number of translation levels"
#endif
#else
#define IDMAP_PGD_ORDER (PHYS_MASK_SHIFT - PGDIR_SHIFT)
#define IDMAP_PGD_ORDER (MAX_PHYS_MASK_SHIFT - PGDIR_SHIFT)
#define EXTRA_SHIFT
/*
* If VA_BITS == 48, we don't have to configure an additional
Expand Down
5 changes: 5 additions & 0 deletions arch/arm64/kernel/rsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct realm_config __attribute((aligned(PAGE_SIZE))) config;
unsigned long prot_ns_shared;
EXPORT_SYMBOL(prot_ns_shared);

unsigned int phys_mask_shift = CONFIG_ARM64_PA_BITS;

DEFINE_STATIC_KEY_FALSE_RO(rsi_present);

static bool rsi_version_matches(void)
Expand Down Expand Up @@ -54,5 +56,8 @@ void __init arm64_rsi_init(void)
return;
prot_ns_shared = BIT(config.ipa_bits - 1);

if (config.ipa_bits - 1 < phys_mask_shift)
phys_mask_shift = config.ipa_bits - 1;

static_branch_enable(&rsi_present);
}

0 comments on commit 31ee93a

Please sign in to comment.