* [PATCH V2] arm64/mm: Fix __enable_mmu() for new TGRAN range values
@ 2021-03-10 5:53 Anshuman Khandual
2021-03-10 11:39 ` Will Deacon
2022-08-26 12:00 ` Anders Roxell
0 siblings, 2 replies; 5+ messages in thread
From: Anshuman Khandual @ 2021-03-10 5:53 UTC (permalink / raw)
To: linux-arm-kernel
Cc: James Morse, Catalin Marinas, Will Deacon, Marc Zyngier,
Suzuki K Poulose, Ard Biesheuvel, Mark Rutland, kvmarm,
linux-efi, linux-kernel, Anshuman Khandual
From: James Morse <james.morse@arm.com>
As per ARM ARM DDI 0487G.a, when FEAT_LPA2 is implemented, ID_AA64MMFR0_EL1
might contain a range of values to describe supported translation granules
(4K and 16K pages sizes in particular) instead of just enabled or disabled
values. This changes __enable_mmu() function to handle complete acceptable
range of values (depending on whether the field is signed or unsigned) now
represented with ID_AA64MMFR0_TGRAN_SUPPORTED_[MIN..MAX] pair. While here,
also fix similar situations in EFI stub and KVM as well.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Marc Zyngier <maz@kernel.org>
Cc: James Morse <james.morse@arm.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: kvmarm@lists.cs.columbia.edu
Cc: linux-efi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Acked-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
Changes in V2:
- Changes back to switch construct in kvm_set_ipa_limit() per Marc
Changes in V1:
https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=442817
arch/arm64/include/asm/sysreg.h | 20 ++++++++++++++------
arch/arm64/kernel/head.S | 6 ++++--
arch/arm64/kvm/reset.c | 10 ++++++----
drivers/firmware/efi/libstub/arm64-stub.c | 2 +-
4 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index dfd4edb..d4a5fca9 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -796,6 +796,11 @@
#define ID_AA64MMFR0_PARANGE_48 0x5
#define ID_AA64MMFR0_PARANGE_52 0x6
+#define ID_AA64MMFR0_TGRAN_2_SUPPORTED_DEFAULT 0x0
+#define ID_AA64MMFR0_TGRAN_2_SUPPORTED_NONE 0x1
+#define ID_AA64MMFR0_TGRAN_2_SUPPORTED_MIN 0x2
+#define ID_AA64MMFR0_TGRAN_2_SUPPORTED_MAX 0x7
+
#ifdef CONFIG_ARM64_PA_BITS_52
#define ID_AA64MMFR0_PARANGE_MAX ID_AA64MMFR0_PARANGE_52
#else
@@ -961,14 +966,17 @@
#define ID_PFR1_PROGMOD_SHIFT 0
#if defined(CONFIG_ARM64_4K_PAGES)
-#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN4_SHIFT
-#define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN4_SUPPORTED
+#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN4_SHIFT
+#define ID_AA64MMFR0_TGRAN_SUPPORTED_MIN ID_AA64MMFR0_TGRAN4_SUPPORTED
+#define ID_AA64MMFR0_TGRAN_SUPPORTED_MAX 0x7
#elif defined(CONFIG_ARM64_16K_PAGES)
-#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN16_SHIFT
-#define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN16_SUPPORTED
+#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN16_SHIFT
+#define ID_AA64MMFR0_TGRAN_SUPPORTED_MIN ID_AA64MMFR0_TGRAN16_SUPPORTED
+#define ID_AA64MMFR0_TGRAN_SUPPORTED_MAX 0xF
#elif defined(CONFIG_ARM64_64K_PAGES)
-#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN64_SHIFT
-#define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN64_SUPPORTED
+#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN64_SHIFT
+#define ID_AA64MMFR0_TGRAN_SUPPORTED_MIN ID_AA64MMFR0_TGRAN64_SUPPORTED
+#define ID_AA64MMFR0_TGRAN_SUPPORTED_MAX 0x7
#endif
#define MVFR2_FPMISC_SHIFT 4
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 66b0e0b..8b469f1 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -655,8 +655,10 @@ SYM_FUNC_END(__secondary_too_slow)
SYM_FUNC_START(__enable_mmu)
mrs x2, ID_AA64MMFR0_EL1
ubfx x2, x2, #ID_AA64MMFR0_TGRAN_SHIFT, 4
- cmp x2, #ID_AA64MMFR0_TGRAN_SUPPORTED
- b.ne __no_granule_support
+ cmp x2, #ID_AA64MMFR0_TGRAN_SUPPORTED_MIN
+ b.lt __no_granule_support
+ cmp x2, #ID_AA64MMFR0_TGRAN_SUPPORTED_MAX
+ b.gt __no_granule_support
update_early_cpu_boot_status 0, x2, x3
adrp x2, idmap_pg_dir
phys_to_ttbr x1, x1
diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index 47f3f03..e81c7ec 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -311,16 +311,18 @@ int kvm_set_ipa_limit(void)
}
switch (cpuid_feature_extract_unsigned_field(mmfr0, tgran_2)) {
- default:
- case 1:
+ case ID_AA64MMFR0_TGRAN_2_SUPPORTED_NONE:
kvm_err("PAGE_SIZE not supported at Stage-2, giving up\n");
return -EINVAL;
- case 0:
+ case ID_AA64MMFR0_TGRAN_2_SUPPORTED_DEFAULT:
kvm_debug("PAGE_SIZE supported at Stage-2 (default)\n");
break;
- case 2:
+ case ID_AA64MMFR0_TGRAN_2_SUPPORTED_MIN ... ID_AA64MMFR0_TGRAN_2_SUPPORTED_MAX:
kvm_debug("PAGE_SIZE supported at Stage-2 (advertised)\n");
break;
+ default:
+ kvm_err("Unsupported value for TGRAN_2, giving up\n");
+ return -EINVAL;
}
kvm_ipa_limit = id_aa64mmfr0_parange_to_phys_shift(parange);
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index b69d631..7bf0a7a 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -24,7 +24,7 @@ efi_status_t check_platform_features(void)
return EFI_SUCCESS;
tg = (read_cpuid(ID_AA64MMFR0_EL1) >> ID_AA64MMFR0_TGRAN_SHIFT) & 0xf;
- if (tg != ID_AA64MMFR0_TGRAN_SUPPORTED) {
+ if (tg < ID_AA64MMFR0_TGRAN_SUPPORTED_MIN || tg > ID_AA64MMFR0_TGRAN_SUPPORTED_MAX) {
if (IS_ENABLED(CONFIG_ARM64_64K_PAGES))
efi_err("This 64 KB granular kernel is not supported by your CPU\n");
else
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH V2] arm64/mm: Fix __enable_mmu() for new TGRAN range values
2021-03-10 5:53 [PATCH V2] arm64/mm: Fix __enable_mmu() for new TGRAN range values Anshuman Khandual
@ 2021-03-10 11:39 ` Will Deacon
2022-08-26 12:00 ` Anders Roxell
1 sibling, 0 replies; 5+ messages in thread
From: Will Deacon @ 2021-03-10 11:39 UTC (permalink / raw)
To: Anshuman Khandual, linux-arm-kernel
Cc: catalin.marinas, kernel-team, Will Deacon, kvmarm, linux-efi,
linux-kernel, Marc Zyngier
On Wed, 10 Mar 2021 11:23:10 +0530, Anshuman Khandual wrote:
> As per ARM ARM DDI 0487G.a, when FEAT_LPA2 is implemented, ID_AA64MMFR0_EL1
> might contain a range of values to describe supported translation granules
> (4K and 16K pages sizes in particular) instead of just enabled or disabled
> values. This changes __enable_mmu() function to handle complete acceptable
> range of values (depending on whether the field is signed or unsigned) now
> represented with ID_AA64MMFR0_TGRAN_SUPPORTED_[MIN..MAX] pair. While here,
> also fix similar situations in EFI stub and KVM as well.
Applied to arm64 (for-next/fixes), thanks!
[1/1] arm64/mm: Fix __enable_mmu() for new TGRAN range values
https://git.kernel.org/arm64/c/26f55386f964
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V2] arm64/mm: Fix __enable_mmu() for new TGRAN range values
2021-03-10 5:53 [PATCH V2] arm64/mm: Fix __enable_mmu() for new TGRAN range values Anshuman Khandual
2021-03-10 11:39 ` Will Deacon
@ 2022-08-26 12:00 ` Anders Roxell
2022-10-28 2:18 ` Zenghui Yu
1 sibling, 1 reply; 5+ messages in thread
From: Anders Roxell @ 2022-08-26 12:00 UTC (permalink / raw)
To: Anshuman Khandual
Cc: linux-arm-kernel, James Morse, Catalin Marinas, Will Deacon,
Marc Zyngier, Suzuki K Poulose, Ard Biesheuvel, Mark Rutland,
kvmarm, linux-efi, linux-kernel, alex.bennee, arnd
On 2021-03-10 11:23, Anshuman Khandual wrote:
> From: James Morse <james.morse@arm.com>
>
> As per ARM ARM DDI 0487G.a, when FEAT_LPA2 is implemented, ID_AA64MMFR0_EL1
> might contain a range of values to describe supported translation granules
> (4K and 16K pages sizes in particular) instead of just enabled or disabled
> values. This changes __enable_mmu() function to handle complete acceptable
> range of values (depending on whether the field is signed or unsigned) now
> represented with ID_AA64MMFR0_TGRAN_SUPPORTED_[MIN..MAX] pair. While here,
> also fix similar situations in EFI stub and KVM as well.
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: James Morse <james.morse@arm.com>
> Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: kvmarm@lists.cs.columbia.edu
> Cc: linux-efi@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Acked-by: Marc Zyngier <maz@kernel.org>
> Signed-off-by: James Morse <james.morse@arm.com>
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Hi,
When building an arm64 defconfig kernel from stable/linux-5.10.y and
booting that in QEMU (version: 1:7.0+dfsg-2~bpo11+2) with '-cpu max' the
kernel doesn't boot. I don't get any output. The kernel boots fine if I
change to '-cpu cortex-a72'.
If I cherry-pick this patch to stable/linux-5.10.y I'm able too boot the
kernel with '-cpu max'.
However, I'm not comfortable to backport this patch to older kernels
since there are a lot of conflicts.
Can someone help out to do the packport?
Cheers,
Anders
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V2] arm64/mm: Fix __enable_mmu() for new TGRAN range values
2022-08-26 12:00 ` Anders Roxell
@ 2022-10-28 2:18 ` Zenghui Yu
2022-10-28 20:35 ` Catalin Marinas
0 siblings, 1 reply; 5+ messages in thread
From: Zenghui Yu @ 2022-10-28 2:18 UTC (permalink / raw)
To: Anders Roxell
Cc: Anshuman Khandual, linux-arm-kernel, James Morse,
Catalin Marinas, Will Deacon, Marc Zyngier, Suzuki K Poulose,
Ard Biesheuvel, Mark Rutland, kvmarm, linux-efi, linux-kernel,
alex.bennee, arnd
On 2022/8/26 20:00, Anders Roxell wrote:
> On 2021-03-10 11:23, Anshuman Khandual wrote:
>> From: James Morse <james.morse@arm.com>
>>
>> As per ARM ARM DDI 0487G.a, when FEAT_LPA2 is implemented, ID_AA64MMFR0_EL1
>> might contain a range of values to describe supported translation granules
>> (4K and 16K pages sizes in particular) instead of just enabled or disabled
>> values. This changes __enable_mmu() function to handle complete acceptable
>> range of values (depending on whether the field is signed or unsigned) now
>> represented with ID_AA64MMFR0_TGRAN_SUPPORTED_[MIN..MAX] pair. While here,
>> also fix similar situations in EFI stub and KVM as well.
>>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will@kernel.org>
>> Cc: Marc Zyngier <maz@kernel.org>
>> Cc: James Morse <james.morse@arm.com>
>> Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
>> Cc: Ard Biesheuvel <ardb@kernel.org>
>> Cc: Mark Rutland <mark.rutland@arm.com>
>> Cc: linux-arm-kernel@lists.infradead.org
>> Cc: kvmarm@lists.cs.columbia.edu
>> Cc: linux-efi@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> Acked-by: Marc Zyngier <maz@kernel.org>
>> Signed-off-by: James Morse <james.morse@arm.com>
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>
> Hi,
>
> When building an arm64 defconfig kernel from stable/linux-5.10.y and
> booting that in QEMU (version: 1:7.0+dfsg-2~bpo11+2) with '-cpu max' the
> kernel doesn't boot. I don't get any output. The kernel boots fine if I
> change to '-cpu cortex-a72'.
>
> If I cherry-pick this patch to stable/linux-5.10.y I'm able too boot the
> kernel with '-cpu max'.
You can workaround the kernel boot failure by specifying
'-cpu max,lpa2=off' [*] in the QEMU command line.
> However, I'm not comfortable to backport this patch to older kernels
> since there are a lot of conflicts.
> Can someone help out to do the packport?
Upstream commit 26f55386f964 ("arm64/mm: Fix __enable_mmu() for new
TGRAN range values") can still be applied cleanly on top of
linux-5.10.y. I can send it to <stable@vger.kernel.org> if maintainers
are okay with the stable-5.10 backport.
[*] https://gitlab.com/qemu-project/qemu/-/commit/69b2265d5fe8
Zenghui
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V2] arm64/mm: Fix __enable_mmu() for new TGRAN range values
2022-10-28 2:18 ` Zenghui Yu
@ 2022-10-28 20:35 ` Catalin Marinas
0 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2022-10-28 20:35 UTC (permalink / raw)
To: Zenghui Yu
Cc: Anders Roxell, Anshuman Khandual, linux-arm-kernel, James Morse,
Will Deacon, Marc Zyngier, Suzuki K Poulose, Ard Biesheuvel,
Mark Rutland, kvmarm, linux-efi, linux-kernel, alex.bennee, arnd
On Fri, Oct 28, 2022 at 10:18:41AM +0800, Zenghui Yu wrote:
> On 2022/8/26 20:00, Anders Roxell wrote:
> > On 2021-03-10 11:23, Anshuman Khandual wrote:
> > > From: James Morse <james.morse@arm.com>
> > >
> > > As per ARM ARM DDI 0487G.a, when FEAT_LPA2 is implemented, ID_AA64MMFR0_EL1
> > > might contain a range of values to describe supported translation granules
> > > (4K and 16K pages sizes in particular) instead of just enabled or disabled
> > > values. This changes __enable_mmu() function to handle complete acceptable
> > > range of values (depending on whether the field is signed or unsigned) now
> > > represented with ID_AA64MMFR0_TGRAN_SUPPORTED_[MIN..MAX] pair. While here,
> > > also fix similar situations in EFI stub and KVM as well.
> > >
> > > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > > Cc: Will Deacon <will@kernel.org>
> > > Cc: Marc Zyngier <maz@kernel.org>
> > > Cc: James Morse <james.morse@arm.com>
> > > Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
> > > Cc: Ard Biesheuvel <ardb@kernel.org>
> > > Cc: Mark Rutland <mark.rutland@arm.com>
> > > Cc: linux-arm-kernel@lists.infradead.org
> > > Cc: kvmarm@lists.cs.columbia.edu
> > > Cc: linux-efi@vger.kernel.org
> > > Cc: linux-kernel@vger.kernel.org
> > > Acked-by: Marc Zyngier <maz@kernel.org>
> > > Signed-off-by: James Morse <james.morse@arm.com>
> > > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> >
> > When building an arm64 defconfig kernel from stable/linux-5.10.y and
> > booting that in QEMU (version: 1:7.0+dfsg-2~bpo11+2) with '-cpu max' the
> > kernel doesn't boot. I don't get any output. The kernel boots fine if I
> > change to '-cpu cortex-a72'.
> >
> > If I cherry-pick this patch to stable/linux-5.10.y I'm able too boot the
> > kernel with '-cpu max'.
>
> You can workaround the kernel boot failure by specifying
> '-cpu max,lpa2=off' [*] in the QEMU command line.
>
> > However, I'm not comfortable to backport this patch to older kernels
> > since there are a lot of conflicts.
> > Can someone help out to do the packport?
>
> Upstream commit 26f55386f964 ("arm64/mm: Fix __enable_mmu() for new
> TGRAN range values") can still be applied cleanly on top of
> linux-5.10.y. I can send it to <stable@vger.kernel.org> if maintainers
> are okay with the stable-5.10 backport.
If you have a backport, please send it (and cc the original
author/reviewers just to double-check that the backport is correct).
Thanks.
--
Catalin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-10-28 20:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10 5:53 [PATCH V2] arm64/mm: Fix __enable_mmu() for new TGRAN range values Anshuman Khandual
2021-03-10 11:39 ` Will Deacon
2022-08-26 12:00 ` Anders Roxell
2022-10-28 2:18 ` Zenghui Yu
2022-10-28 20:35 ` Catalin Marinas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).