ANDROID: KVM: arm64: Calculate traps for all vcpus at hyp vm creation
In non-protected mode, vcpu traps are calculated for each vcpu the first time it's run. Protected mode creates the hyp view of the vm and all its vcpus when the first vcpu is run. At that point in time, the remaining vcpus might not have calculated their trap values. To fix this problem, calculate vcpu traps for _all_ vcpus before creating and initializing the hyp view. Bug: 394097954 Bug: 357781595 Signed-off-by: Fuad Tabba <tabba@google.com> Change-Id: I9fdccd035aa2d95775704b8e3dcbd6f549ae3c4c
This commit is contained in:
@@ -1347,6 +1347,7 @@ int __init populate_nv_trap_config(void);
|
||||
bool lock_all_vcpus(struct kvm *kvm);
|
||||
void unlock_all_vcpus(struct kvm *kvm);
|
||||
|
||||
void __kvm_calculate_traps(struct kvm_vcpu *vcpu);
|
||||
void kvm_calculate_traps(struct kvm_vcpu *vcpu);
|
||||
|
||||
/* MMIO helpers */
|
||||
|
||||
@@ -857,7 +857,8 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)
|
||||
* This needs to happen after any restriction has been applied
|
||||
* to the feature set.
|
||||
*/
|
||||
kvm_calculate_traps(vcpu);
|
||||
if (!is_protected_kvm_enabled())
|
||||
kvm_calculate_traps(vcpu);
|
||||
|
||||
ret = kvm_timer_enable(vcpu);
|
||||
if (ret)
|
||||
|
||||
@@ -449,6 +449,7 @@ static int __pkvm_create_hyp_vm(struct kvm *host_kvm)
|
||||
|
||||
/* Donate memory for the vcpus at hyp and initialize it. */
|
||||
kvm_for_each_vcpu(idx, host_vcpu, host_kvm) {
|
||||
__kvm_calculate_traps(host_vcpu);
|
||||
ret = __pkvm_create_hyp_vcpu(host_kvm, host_vcpu, idx);
|
||||
if (ret)
|
||||
goto destroy_vm;
|
||||
|
||||
@@ -4615,11 +4615,10 @@ static void vcpu_set_hcr(struct kvm_vcpu *vcpu)
|
||||
vcpu->arch.hcr_el2 |= HCR_TTLBOS;
|
||||
}
|
||||
|
||||
void kvm_calculate_traps(struct kvm_vcpu *vcpu)
|
||||
void __kvm_calculate_traps(struct kvm_vcpu *vcpu)
|
||||
{
|
||||
struct kvm *kvm = vcpu->kvm;
|
||||
|
||||
mutex_lock(&kvm->arch.config_lock);
|
||||
vcpu_set_hcr(vcpu);
|
||||
vcpu_set_ich_hcr(vcpu);
|
||||
|
||||
@@ -4643,7 +4642,7 @@ void kvm_calculate_traps(struct kvm_vcpu *vcpu)
|
||||
}
|
||||
|
||||
if (test_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags))
|
||||
goto out;
|
||||
return;
|
||||
|
||||
kvm->arch.fgu[HFGxTR_GROUP] = (HFGxTR_EL2_nAMAIR2_EL1 |
|
||||
HFGxTR_EL2_nMAIR2_EL1 |
|
||||
@@ -4698,7 +4697,14 @@ void kvm_calculate_traps(struct kvm_vcpu *vcpu)
|
||||
HAFGRTR_EL2_RES1);
|
||||
|
||||
set_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags);
|
||||
out:
|
||||
}
|
||||
|
||||
void kvm_calculate_traps(struct kvm_vcpu *vcpu)
|
||||
{
|
||||
struct kvm *kvm = vcpu->kvm;
|
||||
|
||||
mutex_lock(&kvm->arch.config_lock);
|
||||
__kvm_calculate_traps(vcpu);
|
||||
mutex_unlock(&kvm->arch.config_lock);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user