Skip to content

Commit 7af0c25

Browse files
akihikodakioupton
authored andcommitted
KVM: arm64: Normalize cache configuration
Before this change, the cache configuration of the physical CPU was exposed to vcpus. This is problematic because the cache configuration a vcpu sees varies when it migrates between vcpus with different cache configurations. Fabricate cache configuration from the sanitized value, which holds the CTR_EL0 value the userspace sees regardless of which physical CPU it resides on. CLIDR_EL1 and CCSIDR_EL1 are now writable from the userspace so that the VMM can restore the values saved with the old kernel. Suggested-by: Marc Zyngier <[email protected]> Signed-off-by: Akihiko Odaki <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Oliver: Squash Marc's fix for CCSIDR_EL1.LineSize when set from userspace ] Signed-off-by: Oliver Upton <[email protected]>
1 parent bf48040 commit 7af0c25

File tree

4 files changed

+176
-96
lines changed

4 files changed

+176
-96
lines changed

Diff for: arch/arm64/include/asm/cache.h

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#define CLIDR_CTYPE(clidr, level) \
2323
(((clidr) & CLIDR_CTYPE_MASK(level)) >> CLIDR_CTYPE_SHIFT(level))
2424

25+
/* Ttypen, bits [2(n - 1) + 34 : 2(n - 1) + 33], for n = 1 to 7 */
26+
#define CLIDR_TTYPE_SHIFT(level) (2 * ((level) - 1) + CLIDR_EL1_Ttypen_SHIFT)
27+
2528
/*
2629
* Memory returned by kmalloc() may be used for DMA, so we must make
2730
* sure that all such allocations are cache aligned. Otherwise,

Diff for: arch/arm64/include/asm/kvm_host.h

+4
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ struct kvm_vcpu_fault_info {
252252
enum vcpu_sysreg {
253253
__INVALID_SYSREG__, /* 0 is reserved as an invalid value */
254254
MPIDR_EL1, /* MultiProcessor Affinity Register */
255+
CLIDR_EL1, /* Cache Level ID Register */
255256
CSSELR_EL1, /* Cache Size Selection Register */
256257
SCTLR_EL1, /* System Control Register */
257258
ACTLR_EL1, /* Auxiliary Control Register */
@@ -501,6 +502,9 @@ struct kvm_vcpu_arch {
501502
u64 last_steal;
502503
gpa_t base;
503504
} steal;
505+
506+
/* Per-vcpu CCSIDR override or NULL */
507+
u32 *ccsidr;
504508
};
505509

506510
/*

Diff for: arch/arm64/kvm/reset.c

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ void kvm_arm_vcpu_destroy(struct kvm_vcpu *vcpu)
157157
if (sve_state)
158158
kvm_unshare_hyp(sve_state, sve_state + vcpu_sve_state_size(vcpu));
159159
kfree(sve_state);
160+
kfree(vcpu->arch.ccsidr);
160161
}
161162

162163
static void kvm_vcpu_reset_sve(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)