[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230214025648.1898508-24-zhaotianrui@loongson.cn>
Date: Tue, 14 Feb 2023 10:56:47 +0800
From: Tianrui Zhao <zhaotianrui@...ngson.cn>
To: Paolo Bonzini <pbonzini@...hat.com>
Cc: Huacai Chen <chenhuacai@...nel.org>,
WANG Xuerui <kernel@...0n.name>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
loongarch@...ts.linux.dev, linux-kernel@...r.kernel.org,
kvm@...r.kernel.org, Jens Axboe <axboe@...nel.dk>,
Mark Brown <broonie@...nel.org>,
Alex Deucher <alexander.deucher@....com>
Subject: [PATCH v1 23/24] 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 | 53 +++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/arch/loongarch/kernel/cpu-probe.c b/arch/loongarch/kernel/cpu-probe.c
index 3a3fce2d7..9c3483d9a 100644
--- a/arch/loongarch/kernel/cpu-probe.c
+++ b/arch/loongarch/kernel/cpu-probe.c
@@ -176,6 +176,57 @@ 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, gprcfg1;
+
+ 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.ases |= LOONGARCH_CPU_LSX;
+ c->guest.ases_dyn |= LOONGARCH_CPU_LSX;
+ gprcfg1 = read_gcsr_prcfg1();
+ c->guest.kscratch_mask = GENMASK((gprcfg1 & CSR_CONF1_KSNUM) - 1, 0);
+
+ 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
@@ -289,6 +340,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.31.1
Powered by blists - more mailing lists