Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit afb91f5

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Ensure that SME controls are disabled in protected mode
KVM (and pKVM) do not support SME guests. Therefore KVM ensures that the host's SME state is flushed and that SME controls for enabling access to ZA storage and for streaming are disabled. pKVM needs to protect against a buggy/malicious host. Ensure that it wouldn't run a guest when protected mode is enabled should any of the SME controls be enabled. Signed-off-by: Fuad Tabba <tabba@google.com> Link: https://lore.kernel.org/r/20240603122852.3923848-10-tabba@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent a69283a commit afb91f5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

arch/arm64/kvm/fpsimd.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
9090
fpsimd_save_and_flush_cpu_state();
9191
}
9292
}
93+
94+
/*
95+
* If normal guests gain SME support, maintain this behavior for pKVM
96+
* guests, which don't support SME.
97+
*/
98+
WARN_ON(is_protected_kvm_enabled() && system_supports_sme() &&
99+
read_sysreg_s(SYS_SVCR));
93100
}
94101

95102
/*

arch/arm64/kvm/hyp/nvhe/hyp-main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ static void handle___kvm_vcpu_run(struct kvm_cpu_context *host_ctxt)
140140
struct pkvm_hyp_vcpu *hyp_vcpu;
141141
struct kvm *host_kvm;
142142

143+
/*
144+
* KVM (and pKVM) doesn't support SME guests for now, and
145+
* ensures that SME features aren't enabled in pstate when
146+
* loading a vcpu. Therefore, if SME features enabled the host
147+
* is misbehaving.
148+
*/
149+
if (unlikely(system_supports_sme() && read_sysreg_s(SYS_SVCR))) {
150+
ret = -EINVAL;
151+
goto out;
152+
}
153+
143154
host_kvm = kern_hyp_va(host_vcpu->kvm);
144155
hyp_vcpu = pkvm_load_hyp_vcpu(host_kvm->arch.pkvm.handle,
145156
host_vcpu->vcpu_idx);

0 commit comments

Comments
 (0)