RISC-V: KVM: Add VM capability to allow userspace get GPA bits
authorAnup Patel <anup.patel@wdc.com>
Fri, 26 Nov 2021 11:35:51 +0000 (17:05 +0530)
committerAnup Patel <anup@brainfault.org>
Thu, 6 Jan 2022 09:46:58 +0000 (15:16 +0530)
The number of GPA bits supported for a RISC-V Guest/VM is based on the
MMU mode used by the G-stage translation. The KVM RISC-V will detect and
use the best possible MMU mode for the G-stage in kvm_arch_init().

We add a generic VM capability KVM_CAP_VM_GPA_BITS which can be used by
the KVM userspace to get the number of GPA (guest physical address) bits
supported for a Guest/VM.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-and-tested-by: Atish Patra <atishp@rivosinc.com>
arch/riscv/include/asm/kvm_host.h
arch/riscv/kvm/mmu.c
arch/riscv/kvm/vm.c
include/uapi/linux/kvm.h

index 52e19888ce433e53ea780ac1e2c474b1a1025d08..99ef6a1206177a2f52313d2b5a126e559d60121f 100644 (file)
@@ -218,6 +218,7 @@ void kvm_riscv_stage2_free_pgd(struct kvm *kvm);
 void kvm_riscv_stage2_update_hgatp(struct kvm_vcpu *vcpu);
 void kvm_riscv_stage2_mode_detect(void);
 unsigned long kvm_riscv_stage2_mode(void);
+int kvm_riscv_stage2_gpa_bits(void);
 
 void kvm_riscv_stage2_vmid_detect(void);
 unsigned long kvm_riscv_stage2_vmid_bits(void);
index 5f2736c2e773eb898cdd2892cc82e23b33cb0e4b..9af67dbdc66af7ce351df1146987cf0e1187216b 100644 (file)
@@ -769,3 +769,8 @@ unsigned long kvm_riscv_stage2_mode(void)
 {
        return stage2_mode >> HGATP_MODE_SHIFT;
 }
+
+int kvm_riscv_stage2_gpa_bits(void)
+{
+       return stage2_gpa_bits;
+}
index 7619691d89530babeba749e8a3b5af463d2f8424..c768f75279ef6ff92ab02dcc0cd82713c02acce2 100644 (file)
@@ -74,6 +74,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
        case KVM_CAP_NR_MEMSLOTS:
                r = KVM_USER_MEM_SLOTS;
                break;
+       case KVM_CAP_VM_GPA_BITS:
+               r = kvm_riscv_stage2_gpa_bits();
+               break;
        default:
                r = 0;
                break;
index 1daa45268de266ce9b71fbe6470a362cb4d482f6..469f05d69c8d1df8046fff5f39bfaf55a30f7cec 100644 (file)
@@ -1131,6 +1131,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_EXIT_ON_EMULATION_FAILURE 204
 #define KVM_CAP_ARM_MTE 205
 #define KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM 206
+#define KVM_CAP_VM_GPA_BITS 207
 
 #ifdef KVM_CAP_IRQ_ROUTING