Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: fd7bb4a251df ("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>

authored by

Fangyu Yu and committed by
Anup Patel
2b351e3d dbe3d1d1

+2 -1
+2 -1
arch/riscv/kvm/vmid.c
··· 14 14 #include <linux/smp.h> 15 15 #include <linux/kvm_host.h> 16 16 #include <asm/csr.h> 17 + #include <asm/kvm_mmu.h> 17 18 #include <asm/kvm_tlb.h> 18 19 #include <asm/kvm_vmid.h> 19 20 ··· 29 28 30 29 /* Figure-out number of VMID bits in HW */ 31 30 old = csr_read(CSR_HGATP); 32 - csr_write(CSR_HGATP, old | HGATP_VMID); 31 + csr_write(CSR_HGATP, (kvm_riscv_gstage_mode << HGATP_MODE_SHIFT) | HGATP_VMID); 33 32 vmid_bits = csr_read(CSR_HGATP); 34 33 vmid_bits = (vmid_bits & HGATP_VMID) >> HGATP_VMID_SHIFT; 35 34 vmid_bits = fls_long(vmid_bits);