linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] RISC-V: KVM: Write hgatp register with valid mode bits
@ 2025-08-18  5:42 fangyu.yu
  2025-08-18  6:17 ` Guo Ren
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: fangyu.yu @ 2025-08-18  5:42 UTC (permalink / raw)
  To: anup, atish.patra, paul.walmsley, palmer, aou, alex
  Cc: guoren, guoren, kvm, kvm-riscv, linux-riscv, linux-kernel,
	Fangyu Yu

From: Fangyu Yu <fangyu.yu@linux.alibaba.com>

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.

Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>

---
Changes in v2:
- Fixed build error since kvm_riscv_gstage_mode() has been modified.
---
 arch/riscv/kvm/vmid.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kvm/vmid.c b/arch/riscv/kvm/vmid.c
index 3b426c800480..5f33625f4070 100644
--- a/arch/riscv/kvm/vmid.c
+++ b/arch/riscv/kvm/vmid.c
@@ -14,6 +14,7 @@
 #include <linux/smp.h>
 #include <linux/kvm_host.h>
 #include <asm/csr.h>
+#include <asm/kvm_mmu.h>
 #include <asm/kvm_tlb.h>
 #include <asm/kvm_vmid.h>
 
@@ -28,7 +29,7 @@ void __init kvm_riscv_gstage_vmid_detect(void)
 
 	/* Figure-out number of VMID bits in HW */
 	old = csr_read(CSR_HGATP);
-	csr_write(CSR_HGATP, old | HGATP_VMID);
+	csr_write(CSR_HGATP, (kvm_riscv_gstage_mode << HGATP_MODE_SHIFT) | HGATP_VMID);
 	vmid_bits = csr_read(CSR_HGATP);
 	vmid_bits = (vmid_bits & HGATP_VMID) >> HGATP_VMID_SHIFT;
 	vmid_bits = fls_long(vmid_bits);
-- 
2.49.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-08-21  4:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18  5:42 [PATCH V2] RISC-V: KVM: Write hgatp register with valid mode bits fangyu.yu
2025-08-18  6:17 ` Guo Ren
2025-08-18  7:45   ` Guo Ren
2025-08-19  6:44     ` [PATCH] RISC-V KVM: Remove unnecessary HGATP csr_read guoren
2025-08-21  3:17     ` [PATCH V4 0/3] Fixup & optimize hgatp mode & vmid detect functions guoren
2025-08-21  3:17       ` [PATCH V4 1/3] RISC-V: KVM: Write hgatp register with valid mode bits guoren
2025-08-21  3:17       ` [PATCH V4 2/3] RISC-V: KVM: Remove unnecessary HGATP csr_read guoren
2025-08-21  3:17       ` [PATCH V4 3/3] RISC-V: KVM: Prevent HGATP_MODE_BARE passed guoren
2025-08-18  7:10 ` [PATCH V2] RISC-V: KVM: Write hgatp register with valid mode bits Troy Mitchell
2025-08-19  3:47 ` Nutty.Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).