Skip to content

Commit 2b351e3

Browse files
fangyu0809avpatel
authored andcommitted
RISC-V: KVM: Write hgatp register with valid mode bits
According to the RISC-V Privileged Architecture Spec, when MODE=Bare is selected,software must write zero to the remaining fields of hgatp. We have detected the valid mode supported by the HW before, So using a valid mode to detect how many vmid bits are supported. Fixes: fd7bb4a ("RISC-V: KVM: Implement VMID allocator") Reviewed-by: Nutty Liu <nutty.liu@hotmail.com> Reviewed-by: Troy Mitchell <troy.mitchell@linux.spacemit.com> Reviewed-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org> Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com> Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org> Link: https://lore.kernel.org/r/20250821142542.2472079-2-guoren@kernel.org Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent dbe3d1d commit 2b351e3

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

arch/riscv/kvm/vmid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/smp.h>
1515
#include <linux/kvm_host.h>
1616
#include <asm/csr.h>
17+
#include <asm/kvm_mmu.h>
1718
#include <asm/kvm_tlb.h>
1819
#include <asm/kvm_vmid.h>
1920

@@ -28,7 +29,7 @@ void __init kvm_riscv_gstage_vmid_detect(void)
2829

2930
/* Figure-out number of VMID bits in HW */
3031
old = csr_read(CSR_HGATP);
31-
csr_write(CSR_HGATP, old | HGATP_VMID);
32+
csr_write(CSR_HGATP, (kvm_riscv_gstage_mode << HGATP_MODE_SHIFT) | HGATP_VMID);
3233
vmid_bits = csr_read(CSR_HGATP);
3334
vmid_bits = (vmid_bits & HGATP_VMID) >> HGATP_VMID_SHIFT;
3435
vmid_bits = fls_long(vmid_bits);

0 commit comments

Comments
 (0)