AIA initialization sets up per-vCPU IMSIC state by iterating over all online vCPUs. Creating another vCPU afterwards leaves it without initialized IMSIC state, but KVM currently permits that sequence. Reject KVM_CREATE_VCPU once AIA initialization succeeds. Both paths are serialized by kvm->lock, so checking the initialized state from kvm_arch_vcpu_precreate() freezes the vCPU set used by AIA. Fixes: 89d01306e34d ("RISC-V: KVM: Implement device interface for AIA irqchip") Signed-off-by: Andrew Jones --- arch/riscv/kvm/vcpu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index e062ca19f9d8..ccf2def834f1 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -138,6 +138,9 @@ static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu, bool kvm_sbi_reset) int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) { + if (kvm_riscv_aia_initialized(kvm)) + return -EBUSY; + return 0; } -- 2.43.0