Skip to content

Commit 52532c6

Browse files
bibo-maogregkh
authored andcommitted
LoongArch: KVM: Fix GPA size issue about VM
commit 6bdbb73 upstream. Physical address space is 48 bit on Loongson-3A5000 physical machine, however it is 47 bit for VM on Loongson-3A5000 system. Size of physical address space of VM is the same with the size of virtual user space (a half) of physical machine. Variable cpu_vabits represents user address space, kernel address space is not included (user space and kernel space are both a half of total). Here cpu_vabits, rather than cpu_vabits - 1, is to represent the size of guest physical address space. Also there is strict checking about page fault GPA address, inject error if it is larger than maximum GPA address of VM. Cc: stable@vger.kernel.org Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3700cd7 commit 52532c6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

arch/loongarch/kvm/exit.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,12 @@ static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write)
624624
struct kvm_run *run = vcpu->run;
625625
unsigned long badv = vcpu->arch.badv;
626626

627+
/* Inject ADE exception if exceed max GPA size */
628+
if (unlikely(badv >= vcpu->kvm->arch.gpa_size)) {
629+
kvm_queue_exception(vcpu, EXCCODE_ADE, EXSUBCODE_ADEM);
630+
return RESUME_GUEST;
631+
}
632+
627633
ret = kvm_handle_mm_fault(vcpu, badv, write);
628634
if (ret) {
629635
/* Treat as MMIO */

arch/loongarch/kvm/vm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
4646
if (kvm_pvtime_supported())
4747
kvm->arch.pv_features |= BIT(KVM_FEATURE_STEAL_TIME);
4848

49-
kvm->arch.gpa_size = BIT(cpu_vabits - 1);
49+
/*
50+
* cpu_vabits means user address space only (a half of total).
51+
* GPA size of VM is the same with the size of user address space.
52+
*/
53+
kvm->arch.gpa_size = BIT(cpu_vabits);
5054
kvm->arch.root_level = CONFIG_PGTABLE_LEVELS - 1;
5155
kvm->arch.invalid_ptes[0] = 0;
5256
kvm->arch.invalid_ptes[1] = (unsigned long)invalid_pte_table;

0 commit comments

Comments
 (0)