[PATCH v4 04/12] KVM: arm64: Add ARM64_HAS_LPA2 CPU capability

Marc Zyngier maz at kernel.org
Mon Nov 13 04:16:01 PST 2023


On Mon, 13 Nov 2023 11:57:45 +0000,
Ryan Roberts <ryan.roberts at arm.com> wrote:
> 
> >> +{
> >> +#if defined(CONFIG_ARM64_4K_PAGES) || defined(CONFIG_ARM64_16K_PAGES)
> >> +	unsigned int tgran;
> >> +
> >> +	tgran = cpuid_feature_extract_unsigned_field(mmfr0,
> >> +						ID_AA64MMFR0_EL1_TGRAN_SHIFT);
> >> +	return tgran == ID_AA64MMFR0_EL1_TGRAN_LPA2;
> >> +#else
> >> +	return false;
> >> +#endif
> > 
> > Writing this using IS_ENABLED() would be slightly more pleasing to my
> > tired eyes... ;-)
> 
> Unfortunately this doesn't work because ID_AA64MMFR0_EL1_TGRAN_LPA2 is only
> defined for 4K and 16K configs (there is no field ofr 64K). So proposing to do
> it this way instead. Please shout if you have a better idea:
> 
> #if defined(CONFIG_ARM64_4K_PAGES) || defined(CONFIG_ARM64_16K_PAGES)
> static bool has_lpa2_at_stage1(u64 mmfr0)
> {
> 	unsigned int tgran;
> 
> 	tgran = cpuid_feature_extract_unsigned_field(mmfr0,
> 					ID_AA64MMFR0_EL1_TGRAN_SHIFT);
> 	return tgran == ID_AA64MMFR0_EL1_TGRAN_LPA2;
> }
> 
> static bool has_lpa2_at_stage2(u64 mmfr0)
> {
> 	unsigned int tgran;
> 
> 	tgran = cpuid_feature_extract_unsigned_field(mmfr0,
> 					ID_AA64MMFR0_EL1_TGRAN_2_SHIFT);
> 	return tgran == ID_AA64MMFR0_EL1_TGRAN_2_SUPPORTED_LPA2;
> }
> 
> static bool has_lpa2(const struct arm64_cpu_capabilities *entry, int scope)
> {
> 	u64 mmfr0;
> 
> 	mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
> 	return has_lpa2_at_stage1(mmfr0) && has_lpa2_at_stage2(mmfr0);
> }
> #else
> static bool has_lpa2(const struct arm64_cpu_capabilities *entry, int scope)
> {
> 	return false;
> }
> #endif

Ah, fair enough. This looks marginally better anyway.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list