Skip to content

Commit f73531f

Browse files
Anshuman Khandualwilldeacon
authored andcommitted
arm64/cpufeature: Drop open encodings while extracting parange
Currently there are multiple instances of parange feature width mask open encodings while fetching it's value. Even the width mask value (0x7) itself is not accurate. It should be (0xf) per ID_AA64MMFR0_EL1.PARange[3:0] as in ARM ARM (0487F.a). Replace them with cpuid_feature_extract_unsigned_field() which can extract given standard feature (4 bits width i.e 0xf mask) field. Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: James Morse <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Anshuman Khandual <[email protected]> Acked-by: Marc Zyngier <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent c73433f commit f73531f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

arch/arm64/kernel/cpufeature.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,8 @@ static void verify_hyp_capabilities(void)
23372337
}
23382338

23392339
/* Verify IPA range */
2340-
parange = mmfr0 & 0x7;
2340+
parange = cpuid_feature_extract_unsigned_field(mmfr0,
2341+
ID_AA64MMFR0_PARANGE_SHIFT);
23412342
ipa_max = id_aa64mmfr0_parange_to_phys_shift(parange);
23422343
if (ipa_max < get_kvm_ipa_limit()) {
23432344
pr_crit("CPU%d: IPA range mismatch\n", smp_processor_id());

arch/arm64/kvm/reset.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,11 @@ u32 get_kvm_ipa_limit(void)
340340
void kvm_set_ipa_limit(void)
341341
{
342342
unsigned int ipa_max, pa_max, va_max, parange;
343+
u64 mmfr0;
343344

344-
parange = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1) & 0x7;
345+
mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
346+
parange = cpuid_feature_extract_unsigned_field(mmfr0,
347+
ID_AA64MMFR0_PARANGE_SHIFT);
345348
pa_max = id_aa64mmfr0_parange_to_phys_shift(parange);
346349

347350
/* Clamp the IPA limit to the PA size supported by the kernel */
@@ -387,7 +390,7 @@ void kvm_set_ipa_limit(void)
387390
*/
388391
int kvm_arm_setup_stage2(struct kvm *kvm, unsigned long type)
389392
{
390-
u64 vtcr = VTCR_EL2_FLAGS;
393+
u64 vtcr = VTCR_EL2_FLAGS, mmfr0;
391394
u32 parange, phys_shift;
392395
u8 lvls;
393396

@@ -403,7 +406,9 @@ int kvm_arm_setup_stage2(struct kvm *kvm, unsigned long type)
403406
phys_shift = KVM_PHYS_SHIFT;
404407
}
405408

406-
parange = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1) & 7;
409+
mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
410+
parange = cpuid_feature_extract_unsigned_field(mmfr0,
411+
ID_AA64MMFR0_PARANGE_SHIFT);
407412
if (parange > ID_AA64MMFR0_PARANGE_MAX)
408413
parange = ID_AA64MMFR0_PARANGE_MAX;
409414
vtcr |= parange << VTCR_EL2_PS_SHIFT;

0 commit comments

Comments
 (0)