Skip to content

Commit 9a48c59

Browse files
author
Marc Zyngier
committed
Merge branch kvm-arm64/misc-6.4 into kvmarm-master/fixes
* kvm-arm64/misc-6.4: : . : Minor changes for 6.4: : : - Make better use of the bitmap API (bitmap_zero, bitmap_zalloc...) : : - FP/SVE/SME documentation update, in the hope that this field : becomes clearer... : : - Add workaround for the usual Apple SEIS brokenness : : - Random comment fixes : . KVM: arm64: vgic: Add Apple M2 PRO/MAX cpus to the list of broken SEIS implementations KVM: arm64: Clarify host SME state management KVM: arm64: Restructure check for SVE support in FP trap handler KVM: arm64: Document check for TIF_FOREIGN_FPSTATE KVM: arm64: Fix repeated words in comments KVM: arm64: Use the bitmap API to allocate bitmaps KVM: arm64: Slightly optimize flush_context() Signed-off-by: Marc Zyngier <maz@kernel.org>
2 parents ac9a786 + e910baa commit 9a48c59

File tree

6 files changed

+43
-16
lines changed

6 files changed

+43
-16
lines changed

arch/arm64/include/asm/cputype.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@
126126
#define APPLE_CPU_PART_M1_FIRESTORM_MAX 0x029
127127
#define APPLE_CPU_PART_M2_BLIZZARD 0x032
128128
#define APPLE_CPU_PART_M2_AVALANCHE 0x033
129+
#define APPLE_CPU_PART_M2_BLIZZARD_PRO 0x034
130+
#define APPLE_CPU_PART_M2_AVALANCHE_PRO 0x035
131+
#define APPLE_CPU_PART_M2_BLIZZARD_MAX 0x038
132+
#define APPLE_CPU_PART_M2_AVALANCHE_MAX 0x039
129133

130134
#define AMPERE_CPU_PART_AMPERE1 0xAC3
131135

@@ -181,6 +185,10 @@
181185
#define MIDR_APPLE_M1_FIRESTORM_MAX MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M1_FIRESTORM_MAX)
182186
#define MIDR_APPLE_M2_BLIZZARD MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_BLIZZARD)
183187
#define MIDR_APPLE_M2_AVALANCHE MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_AVALANCHE)
188+
#define MIDR_APPLE_M2_BLIZZARD_PRO MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_BLIZZARD_PRO)
189+
#define MIDR_APPLE_M2_AVALANCHE_PRO MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_AVALANCHE_PRO)
190+
#define MIDR_APPLE_M2_BLIZZARD_MAX MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_BLIZZARD_MAX)
191+
#define MIDR_APPLE_M2_AVALANCHE_MAX MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_AVALANCHE_MAX)
184192
#define MIDR_AMPERE1 MIDR_CPU_MODEL(ARM_CPU_IMP_AMPERE, AMPERE_CPU_PART_AMPERE1)
185193

186194
/* Fujitsu Erratum 010001 affects A64FX 1.0 and 1.1, (v0r0 and v1r0) */

arch/arm64/kvm/fpsimd.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,34 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
8181

8282
fpsimd_kvm_prepare();
8383

84+
/*
85+
* We will check TIF_FOREIGN_FPSTATE just before entering the
86+
* guest in kvm_arch_vcpu_ctxflush_fp() and override this to
87+
* FP_STATE_FREE if the flag set.
88+
*/
8489
vcpu->arch.fp_state = FP_STATE_HOST_OWNED;
8590

8691
vcpu_clear_flag(vcpu, HOST_SVE_ENABLED);
8792
if (read_sysreg(cpacr_el1) & CPACR_EL1_ZEN_EL0EN)
8893
vcpu_set_flag(vcpu, HOST_SVE_ENABLED);
8994

90-
/*
91-
* We don't currently support SME guests but if we leave
92-
* things in streaming mode then when the guest starts running
93-
* FPSIMD or SVE code it may generate SME traps so as a
94-
* special case if we are in streaming mode we force the host
95-
* state to be saved now and exit streaming mode so that we
96-
* don't have to handle any SME traps for valid guest
97-
* operations. Do this for ZA as well for now for simplicity.
98-
*/
9995
if (system_supports_sme()) {
10096
vcpu_clear_flag(vcpu, HOST_SME_ENABLED);
10197
if (read_sysreg(cpacr_el1) & CPACR_EL1_SMEN_EL0EN)
10298
vcpu_set_flag(vcpu, HOST_SME_ENABLED);
10399

100+
/*
101+
* If PSTATE.SM is enabled then save any pending FP
102+
* state and disable PSTATE.SM. If we leave PSTATE.SM
103+
* enabled and the guest does not enable SME via
104+
* CPACR_EL1.SMEN then operations that should be valid
105+
* may generate SME traps from EL1 to EL1 which we
106+
* can't intercept and which would confuse the guest.
107+
*
108+
* Do the same for PSTATE.ZA in the case where there
109+
* is state in the registers which has not already
110+
* been saved, this is very unlikely to happen.
111+
*/
104112
if (read_sysreg_s(SYS_SVCR) & (SVCR_SM_MASK | SVCR_ZA_MASK)) {
105113
vcpu->arch.fp_state = FP_STATE_FREE;
106114
fpsimd_save_and_flush_cpu_state();

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,17 @@ static bool kvm_hyp_handle_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code)
177177
sve_guest = vcpu_has_sve(vcpu);
178178
esr_ec = kvm_vcpu_trap_get_class(vcpu);
179179

180-
/* Don't handle SVE traps for non-SVE vcpus here: */
181-
if (!sve_guest && esr_ec != ESR_ELx_EC_FP_ASIMD)
180+
/* Only handle traps the vCPU can support here: */
181+
switch (esr_ec) {
182+
case ESR_ELx_EC_FP_ASIMD:
183+
break;
184+
case ESR_ELx_EC_SVE:
185+
if (!sve_guest)
186+
return false;
187+
break;
188+
default:
182189
return false;
190+
}
183191

184192
/* Valid trap. Switch the context: */
185193

arch/arm64/kvm/inject_fault.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void kvm_inject_size_fault(struct kvm_vcpu *vcpu)
204204
* Size Fault at level 0, as if exceeding PARange.
205205
*
206206
* Non-LPAE guests will only get the external abort, as there
207-
* is no way to to describe the ASF.
207+
* is no way to describe the ASF.
208208
*/
209209
if (vcpu_el1_is_32bit(vcpu) &&
210210
!(vcpu_read_sys_reg(vcpu, TCR_EL1) & TTBCR_EAE))

arch/arm64/kvm/vgic/vgic-v3.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,10 @@ static const struct midr_range broken_seis[] = {
616616
MIDR_ALL_VERSIONS(MIDR_APPLE_M1_FIRESTORM_MAX),
617617
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_BLIZZARD),
618618
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_AVALANCHE),
619+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_BLIZZARD_PRO),
620+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_AVALANCHE_PRO),
621+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_BLIZZARD_MAX),
622+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_AVALANCHE_MAX),
619623
{},
620624
};
621625

arch/arm64/kvm/vmid.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void flush_context(void)
4747
int cpu;
4848
u64 vmid;
4949

50-
bitmap_clear(vmid_map, 0, NUM_USER_VMIDS);
50+
bitmap_zero(vmid_map, NUM_USER_VMIDS);
5151

5252
for_each_possible_cpu(cpu) {
5353
vmid = atomic64_xchg_relaxed(&per_cpu(active_vmids, cpu), 0);
@@ -182,8 +182,7 @@ int __init kvm_arm_vmid_alloc_init(void)
182182
*/
183183
WARN_ON(NUM_USER_VMIDS - 1 <= num_possible_cpus());
184184
atomic64_set(&vmid_generation, VMID_FIRST_VERSION);
185-
vmid_map = kcalloc(BITS_TO_LONGS(NUM_USER_VMIDS),
186-
sizeof(*vmid_map), GFP_KERNEL);
185+
vmid_map = bitmap_zalloc(NUM_USER_VMIDS, GFP_KERNEL);
187186
if (!vmid_map)
188187
return -ENOMEM;
189188

@@ -192,5 +191,5 @@ int __init kvm_arm_vmid_alloc_init(void)
192191

193192
void __init kvm_arm_vmid_alloc_free(void)
194193
{
195-
kfree(vmid_map);
194+
bitmap_free(vmid_map);
196195
}

0 commit comments

Comments
 (0)