History

RISC-V: KVM: Add VM capability to allow userspace get GPA bits

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.

Anup Patel committed 4 years ago

Commit a457fd51 parent ef8949a4 files · +10 −0Browse files

Unified · Split

4 files
  1. arch/riscv/include/asm/kvm_host.h +1 −0
  2. arch/riscv/kvm/mmu.c +5 −0
  3. arch/riscv/kvm/vm.c +3 −0
  4. include/uapi/linux/kvm.h +1 −0
arch/riscv/include/asm/kvm_host.h+1−0
@@ -218,6 +218,7 @@ void kvm_riscv_stage2_free_pgd(struct kvm *kvm); · 217 unmodified lines
218218 void kvm_riscv_stage2_update_hgatp(struct kvm_vcpu *vcpu);
219219 void kvm_riscv_stage2_mode_detect(void);
220220 unsigned long kvm_riscv_stage2_mode(void);
221+int kvm_riscv_stage2_gpa_bits(void);
221222
222223 void kvm_riscv_stage2_vmid_detect(void);
223224 unsigned long kvm_riscv_stage2_vmid_bits(void);
arch/riscv/kvm/mmu.c+5−0
@@ -769,3 +769,8 @@ unsigned long kvm_riscv_stage2_mode(void) · 768 unmodified lines
769769 {
770770 return stage2_mode >> HGATP_MODE_SHIFT;
771771 }
772+
773+int kvm_riscv_stage2_gpa_bits(void)
774+{
775+ return stage2_gpa_bits;
776+}
arch/riscv/kvm/vm.c+3−0
@@ -74,6 +74,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · 73 unmodified lines
7474 case KVM_CAP_NR_MEMSLOTS:
7575 r = KVM_USER_MEM_SLOTS;
7676 break;
77+ case KVM_CAP_VM_GPA_BITS:
78+ r = kvm_riscv_stage2_gpa_bits();
79+ break;
7780 default:
7881 r = 0;
7982 break;
include/uapi/linux/kvm.h+1−0
@@ -1131,6 +1131,7 @@ struct kvm_ppc_resize_hpt { · 1130 unmodified lines
11311131 #define KVM_CAP_EXIT_ON_EMULATION_FAILURE 204
11321132 #define KVM_CAP_ARM_MTE 205
11331133 #define KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM 206
1134+#define KVM_CAP_VM_GPA_BITS 207
11341135
11351136 #ifdef KVM_CAP_IRQ_ROUTING
11361137