[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230530015223.147755-29-zhaotianrui@loongson.cn>
Date: Tue, 30 May 2023 09:52:20 +0800
From: Tianrui Zhao <zhaotianrui@...ngson.cn>
To: linux-kernel@...r.kernel.org, kvm@...r.kernel.org
Cc: Paolo Bonzini <pbonzini@...hat.com>,
Huacai Chen <chenhuacai@...nel.org>,
WANG Xuerui <kernel@...0n.name>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
loongarch@...ts.linux.dev, Jens Axboe <axboe@...nel.dk>,
Mark Brown <broonie@...nel.org>,
Alex Deucher <alexander.deucher@....com>,
Oliver Upton <oliver.upton@...ux.dev>, maobibo@...ngson.cn,
Xi Ruoyao <xry111@...111.site>, zhaotianrui@...ngson.cn
Subject: [PATCH v12 28/31] LoongArch: KVM: Implement probe virtualization when LoongArch cpu init
Implement probe virtualization when LoongArch cpu init, including guest
gid info, guest fpu info, etc.
Signed-off-by: Tianrui Zhao <zhaotianrui@...ngson.cn>
---
arch/loongarch/kernel/cpu-probe.c | 51 +++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/arch/loongarch/kernel/cpu-probe.c b/arch/loongarch/kernel/cpu-probe.c
index 5adf0f736c6d..d6f7e7cbb2ed 100644
--- a/arch/loongarch/kernel/cpu-probe.c
+++ b/arch/loongarch/kernel/cpu-probe.c
@@ -181,6 +181,55 @@ static void cpu_probe_common(struct cpuinfo_loongarch *c)
}
}
+static inline void cpu_probe_guestinfo(struct cpuinfo_loongarch *c)
+{
+ unsigned long guestinfo;
+
+ guestinfo = read_csr_gstat();
+ if (guestinfo & CSR_GSTAT_GIDBIT) {
+ c->options |= LOONGARCH_CPU_GUESTID;
+ write_csr_gstat(0);
+ }
+}
+
+static inline void cpu_probe_lvz(struct cpuinfo_loongarch *c)
+{
+ unsigned long gcfg;
+
+ cpu_probe_guestinfo(c);
+
+ c->guest.options |= LOONGARCH_CPU_FPU;
+ c->guest.options_dyn |= LOONGARCH_CPU_FPU;
+ c->guest.options_dyn |= LOONGARCH_CPU_PMP;
+
+ c->guest.options |= LOONGARCH_CPU_LSX;
+ c->guest.options_dyn |= LOONGARCH_CPU_LSX;
+
+ gcfg = read_csr_gcfg();
+ if (gcfg & CSR_GCFG_MATP_GUEST)
+ c->guest_cfg |= BIT(0);
+ if (gcfg & CSR_GCFG_MATP_ROOT)
+ c->guest_cfg |= BIT(1);
+ if (gcfg & CSR_GCFG_MATP_NEST)
+ c->guest_cfg |= BIT(2);
+ if (gcfg & CSR_GCFG_SITP)
+ c->guest_cfg |= BIT(6);
+ if (gcfg & CSR_GCFG_TITP)
+ c->guest_cfg |= BIT(8);
+ if (gcfg & CSR_GCFG_TOEP)
+ c->guest_cfg |= BIT(10);
+ if (gcfg & CSR_GCFG_TOPP)
+ c->guest_cfg |= BIT(12);
+ if (gcfg & CSR_GCFG_TORUP)
+ c->guest_cfg |= BIT(14);
+ if (gcfg & CSR_GCFG_GCIP_ALL)
+ c->guest_cfg |= BIT(16);
+ if (gcfg & CSR_GCFG_GCIP_HIT)
+ c->guest_cfg |= BIT(17);
+ if (gcfg & CSR_GCFG_GCIP_SECURE)
+ c->guest_cfg |= BIT(18);
+}
+
#define MAX_NAME_LEN 32
#define VENDOR_OFFSET 0
#define CPUNAME_OFFSET 9
@@ -294,6 +343,8 @@ void cpu_probe(void)
if (cpu == 0)
__ua_limit = ~((1ull << cpu_vabits) - 1);
#endif
+ if (cpu_has_lvz)
+ cpu_probe_lvz(c);
cpu_report();
}
--
2.39.1
Powered by blists - more mailing lists