Skip to content

Commit 99e3f63

Browse files
James MorseKexyBiscuit
authored andcommitted
BACKPORT: OPENEULER: KVM: arm64: Fix missing traps of guest accesses to the MPAM registers
maillist inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8T2RT Reference: https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/log/?h=mpam/snapshot/v6.7-rc2 --------------------------- commit 011e5f5 ("arm64/cpufeature: Add remaining feature bits in ID_AA64PFR0 register") exposed the MPAM field of AA64PFR0_EL1 to guests, but didn't add trap handling. If you are unlucky, this results in an MPAM aware guest being delivered an undef during boot. The host prints: | kvm [97]: Unsupported guest sys_reg access at: ffff800080024c64 [00000005] | { Op0( 3), Op1( 0), CRn(10), CRm( 5), Op2( 0), func_read }, Which results in: | Internal error: Oops - Undefined instruction: 0000000002000000 [#1] PREEMPT SMP | Modules linked in: | CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.6.0-rc7-00559-gd89c186d50b2 #14616 | Hardware name: linux,dummy-virt (DT) | pstate: 00000005 (nzcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) | pc : test_has_mpam+0x18/0x30 | lr : test_has_mpam+0x10/0x30 | sp : ffff80008000bd90 ... | Call trace: | test_has_mpam+0x18/0x30 | update_cpu_capabilities+0x7c/0x11c | setup_cpu_features+0x14/0xd8 | smp_cpus_done+0x24/0xb8 | smp_init+0x7c/0x8c | kernel_init_freeable+0xf8/0x280 | kernel_init+0x24/0x1e0 | ret_from_fork+0x10/0x20 | Code: 910003fd 97ffffde 72001c0 5400008 (d538a500) | ---[ end trace 0000000000000000 ]--- | Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b | ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]--- Add the support to enable the traps, and handle the three guest accessible registers as RAZ/WI. This allows guests to keep the invariant id-register value, while advertising that MPAM isn't really supported. With MPAM v1.0 we can trap the MPAMIDR_EL1 register only if ARM64_HAS_MPAM_HCR, with v1.1 an additional MPAM2_EL2.TIDR bit traps MPAMIDR_EL1 on platforms that don't have MPAMHCR_EL2. Enable one of these if either is supported. If neither is supported, the guest can discover that the CPU has MPAM support, and how many PARTID etc the host has ... but it can't influence anything, so its harmless. Full support for the feature would only expose MPAM to the guest if a psuedo-device has been created to describe the virt->phys partid mapping the VMM expects. This will depend on ARM64_HAS_MPAM_HCR. Fixes: 011e5f5 ("arm64/cpufeature: Add remaining feature bits in ID_AA64PFR0 register") CC: Anshuman Khandual <[email protected]> Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/ Signed-off-by: James Morse <[email protected]> Signed-off-by: Zeng Heng <[email protected]> Link: https://gitee.com/openeuler/kernel/commit/c55eb641d53ac3d0a7ab9f1d1fae8a6460fc4f98 [Kexy: Dropped changes in arch/arm64/include/asm/kvm_arm.h, arch/arm64/kernel/image-vars.h, arch/arm64/kvm/hyp/include/hyp/switch.h, and arch/arm64/kvm/sys_regs.c] Signed-off-by: Kexy Biscuit <[email protected]>
1 parent e1a395c commit 99e3f63

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/arm64/include/asm/mpam.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@
5151
DECLARE_STATIC_KEY_FALSE(arm64_mpam_has_hcr);
5252

5353
/* check whether all CPUs have MPAM support */
54-
static inline bool mpam_cpus_have_feature(void)
54+
static __always_inline bool mpam_cpus_have_feature(void)
5555
{
5656
if (IS_ENABLED(CONFIG_ARM64_MPAM))
5757
return cpus_have_final_cap(ARM64_MPAM);
5858
return false;
5959
}
6060

6161
/* check whether all CPUs have MPAM virtualisation support */
62-
static inline bool mpam_cpus_have_mpam_hcr(void)
62+
static __always_inline bool mpam_cpus_have_mpam_hcr(void)
6363
{
6464
if (IS_ENABLED(CONFIG_ARM64_MPAM))
6565
return static_branch_unlikely(&arm64_mpam_has_hcr);

0 commit comments

Comments
 (0)