]> git.ipfire.org Git - thirdparty/linux.git/commit
RISC-V: KVM: Reuse KVM_CAP_VM_GPA_BITS to select HGATP.MODE
authorFangyu Yu <fangyu.yu@linux.alibaba.com>
Fri, 3 Apr 2026 15:30:18 +0000 (23:30 +0800)
committerAnup Patel <anup@brainfault.org>
Sat, 4 Apr 2026 08:18:21 +0000 (13:48 +0530)
commit7263b4fdb0b240e67e3ebd802e0df761d35a7fdf
treec80034f5d424a4c489803de700d5d0fecb76afde
parentec92248431be7ad08742e0d1dff5109cec5ef905
RISC-V: KVM: Reuse KVM_CAP_VM_GPA_BITS to select HGATP.MODE

Reuse KVM_CAP_VM_GPA_BITS to advertise and select the effective
G-stage GPA width for a VM.

KVM_CHECK_EXTENSION(KVM_CAP_VM_GPA_BITS) returns the effective GPA
bits for a VM, KVM_ENABLE_CAP(KVM_CAP_VM_GPA_BITS) allows userspace
to downsize the effective GPA width by selecting a smaller G-stage
page table format:
  - gpa_bits <= 41 selects Sv39x4 (pgd_levels=3)
  - gpa_bits <= 50 selects Sv48x4 (pgd_levels=4)
  - gpa_bits <= 59 selects Sv57x4 (pgd_levels=5)

Reject the request with -EINVAL for unsupported values and with -EBUSY
if vCPUs have been created or any memslot is populated.

Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Reviewed-by: Andrew Jones <andrew.jones@oss.qualcomm.com>
Reviewed-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260403153019.9916-4-fangyu.yu@linux.alibaba.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/kvm/vm.c