summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPengpeng Hou <hppiscas@163.com>2026-09-20 21:09:55 +0800
committerAnup Patel <anup@brainfault.org>2026-11-16 18:06:13 +0530
commitea4302d313014da5ea988f03ee7b88e29e161dcf (patch)
tree662237a0e6465b24b87e7d7fe3015ea656d0243f
parentd33cad95d2e4996105e68f6ccb65bdce7ad1d636 (diff)
RISC-V: KVM: Disallow GPA-width changes after AIA init
KVM_ENABLE_CAP(KVM_CAP_VM_GPA_BITS) allows userspace to reduce the stage-2 GPA width while a VM has no vCPUs or memory slots. AIA initialization can complete with an APLIC and no vCPUs or memory slots. The APLIC MMIO device has then been registered, but the existing checks still allow userspace to shrink the GPA width below its address. Reject GPA-width changes after AIA initialization. Both paths hold kvm->lock, serializing the width change with AIA initialization. The issue was found by our static-analysis tool. Fixes: 7263b4fdb0b2 ("RISC-V: KVM: Reuse KVM_CAP_VM_GPA_BITS to select HGATP.MODE") Reviewed-by: Anup Patel <anup@brainfault.org> Assisted-by: gpt 5 Signed-off-by: Pengpeng Hou <hppiscas@163.com> Reviewed-by: Nutty Liu <nutty.liu@hotmail.com> Link: https://lore.kernel.org/r/fbe7337f6989994ad4dbc4dc03a67e8ebfa61f8d.1789872556.git.hppiscas@163.com Signed-off-by: Anup Patel <anup@brainfault.org>
-rw-r--r--arch/riscv/kvm/vm.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c
index 58500a19b33b..17598d487e83 100644
--- a/arch/riscv/kvm/vm.c
+++ b/arch/riscv/kvm/vm.c
@@ -251,7 +251,8 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap)
mutex_lock(&kvm->lock);
mutex_lock(&kvm->slots_lock);
- if (kvm->created_vcpus || !kvm_are_all_memslots_empty(kvm))
+ if (kvm->created_vcpus || !kvm_are_all_memslots_empty(kvm) ||
+ kvm_riscv_aia_initialized(kvm))
r = -EBUSY;
else
kvm->arch.pgd_levels = new_levels;