[PATCH 2/2] RISC-V: KVM: Disallow GPA-width changes after AIA init

Anup Patel anup at brainfault.org
Fri Sep 11 00:24:26 PDT 2026


On Wed, Aug 12, 2026 at 11:09 AM Pengpeng Hou <pengpeng at iscas.ac.cn> wrote:
>
> 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 still complete with an APLIC and no vCPUs or
> memory slots.  In that state, the APLIC MMIO device has already been
> registered, but the existing checks allow userspace to shrink the GPA
> width below its address.
>
> Reject GPA-width changes after AIA initialization.  Both paths hold
> kvm->lock, so the check also closes the race between final AIA address
> validation and publication.
>
> Fixes: 7263b4fdb0b2 ("RISC-V: KVM: Reuse KVM_CAP_VM_GPA_BITS to select HGATP.MODE")
> Signed-off-by: Pengpeng Hou <pengpeng at iscas.ac.cn>

LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

Thanks,
Anup


> ---
>  arch/riscv/kvm/vm.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c
> index a9f083feeb76..66edfaa86243 100644
> --- a/arch/riscv/kvm/vm.c
> +++ b/arch/riscv/kvm/vm.c
> @@ -250,7 +250,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;
> --
> 2.50.1 (Apple Git-155)
>



More information about the linux-riscv mailing list