Skip to content

Commit 0d0df3c

Browse files
zhaotianrui-loongsonchenhuacai
authored andcommitted
LoongArch: KVM: Implement kvm hardware enable, disable interface
Implement kvm hardware enable, disable interface, setting the guest config register to enable virtualization features when called the interface. Reviewed-by: Bibo Mao <[email protected]> Tested-by: Huacai Chen <[email protected]> Signed-off-by: Tianrui Zhao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 2bd6ac6 commit 0d0df3c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

arch/loongarch/kvm/main.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,68 @@ void kvm_check_vpid(struct kvm_vcpu *vcpu)
249249
change_csr_gstat(vpid_mask << CSR_GSTAT_GID_SHIFT, vpid);
250250
}
251251

252+
void kvm_init_vmcs(struct kvm *kvm)
253+
{
254+
kvm->arch.vmcs = vmcs;
255+
}
256+
257+
long kvm_arch_dev_ioctl(struct file *filp,
258+
unsigned int ioctl, unsigned long arg)
259+
{
260+
return -ENOIOCTLCMD;
261+
}
262+
263+
int kvm_arch_hardware_enable(void)
264+
{
265+
unsigned long env, gcfg = 0;
266+
267+
env = read_csr_gcfg();
268+
269+
/* First init gcfg, gstat, gintc, gtlbc. All guest use the same config */
270+
write_csr_gcfg(0);
271+
write_csr_gstat(0);
272+
write_csr_gintc(0);
273+
clear_csr_gtlbc(CSR_GTLBC_USETGID | CSR_GTLBC_TOTI);
274+
275+
/*
276+
* Enable virtualization features granting guest direct control of
277+
* certain features:
278+
* GCI=2: Trap on init or unimplement cache instruction.
279+
* TORU=0: Trap on Root Unimplement.
280+
* CACTRL=1: Root control cache.
281+
* TOP=0: Trap on Previlege.
282+
* TOE=0: Trap on Exception.
283+
* TIT=0: Trap on Timer.
284+
*/
285+
if (env & CSR_GCFG_GCIP_ALL)
286+
gcfg |= CSR_GCFG_GCI_SECURE;
287+
if (env & CSR_GCFG_MATC_ROOT)
288+
gcfg |= CSR_GCFG_MATC_ROOT;
289+
290+
gcfg |= CSR_GCFG_TIT;
291+
write_csr_gcfg(gcfg);
292+
293+
kvm_flush_tlb_all();
294+
295+
/* Enable using TGID */
296+
set_csr_gtlbc(CSR_GTLBC_USETGID);
297+
kvm_debug("GCFG:%lx GSTAT:%lx GINTC:%lx GTLBC:%lx",
298+
read_csr_gcfg(), read_csr_gstat(), read_csr_gintc(), read_csr_gtlbc());
299+
300+
return 0;
301+
}
302+
303+
void kvm_arch_hardware_disable(void)
304+
{
305+
write_csr_gcfg(0);
306+
write_csr_gstat(0);
307+
write_csr_gintc(0);
308+
clear_csr_gtlbc(CSR_GTLBC_USETGID | CSR_GTLBC_TOTI);
309+
310+
/* Flush any remaining guest TLB entries */
311+
kvm_flush_tlb_all();
312+
}
313+
252314
static int kvm_loongarch_env_init(void)
253315
{
254316
int cpu, order;

0 commit comments

Comments
 (0)