[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241113031727.2815628-6-maobibo@loongson.cn>
Date: Wed, 13 Nov 2024 11:17:27 +0800
From: Bibo Mao <maobibo@...ngson.cn>
To: Tianrui Zhao <zhaotianrui@...ngson.cn>,
Huacai Chen <chenhuacai@...nel.org>
Cc: WANG Xuerui <kernel@...0n.name>,
kvm@...r.kernel.org,
loongarch@...ts.linux.dev,
linux-kernel@...r.kernel.org
Subject: [RFC 5/5] LoongArch: KVM: Enable separate vmid feature
With CSR GTLBC shortname for Guest TLB Control Register, separate vmid
feature will be enabled if bit 14 CSR_GTLBC_USEVMID is set. Enable
this feature if cpu_has_guestid is true when KVM module is loaded.
Signed-off-by: Bibo Mao <maobibo@...ngson.cn>
---
arch/loongarch/include/asm/loongarch.h | 2 ++
arch/loongarch/kvm/main.c | 4 +++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/loongarch/include/asm/loongarch.h b/arch/loongarch/include/asm/loongarch.h
index 64ad277e096e..5fee5db3bea0 100644
--- a/arch/loongarch/include/asm/loongarch.h
+++ b/arch/loongarch/include/asm/loongarch.h
@@ -326,6 +326,8 @@
#define CSR_GTLBC_TGID_WIDTH 8
#define CSR_GTLBC_TGID_SHIFT_END (CSR_GTLBC_TGID_SHIFT + CSR_GTLBC_TGID_WIDTH - 1)
#define CSR_GTLBC_TGID (_ULCAST_(0xff) << CSR_GTLBC_TGID_SHIFT)
+#define CSR_GTLBC_USEVMID_SHIFT 14
+#define CSR_GTLBC_USEVMID (_ULCAST_(0x1) << CSR_GTLBC_USEVMID_SHIFT)
#define CSR_GTLBC_TOTI_SHIFT 13
#define CSR_GTLBC_TOTI (_ULCAST_(0x1) << CSR_GTLBC_TOTI_SHIFT)
#define CSR_GTLBC_USETGID_SHIFT 12
diff --git a/arch/loongarch/kvm/main.c b/arch/loongarch/kvm/main.c
index f89d1df885d7..50c977d8b414 100644
--- a/arch/loongarch/kvm/main.c
+++ b/arch/loongarch/kvm/main.c
@@ -336,7 +336,7 @@ int kvm_arch_enable_virtualization_cpu(void)
write_csr_gcfg(0);
write_csr_gstat(0);
write_csr_gintc(0);
- clear_csr_gtlbc(CSR_GTLBC_USETGID | CSR_GTLBC_TOTI);
+ clear_csr_gtlbc(CSR_GTLBC_USETGID | CSR_GTLBC_TOTI | CSR_GTLBC_USEVMID);
/*
* Enable virtualization features granting guest direct control of
@@ -359,6 +359,8 @@ int kvm_arch_enable_virtualization_cpu(void)
/* Enable using TGID */
set_csr_gtlbc(CSR_GTLBC_USETGID);
+ if (cpu_has_guestid)
+ set_csr_gtlbc(CSR_GTLBC_USEVMID);
kvm_debug("GCFG:%lx GSTAT:%lx GINTC:%lx GTLBC:%lx",
read_csr_gcfg(), read_csr_gstat(), read_csr_gintc(), read_csr_gtlbc());
--
2.39.3
Powered by blists - more mailing lists