mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-09 22:50:41 +00:00
33436335e9
- Fix wrong usage of PGDIR_SIZE to check page sizes - Fix privilege mode setting in kvm_riscv_vcpu_trap_redirect() - Redirect illegal instruction traps to guest - SBI PMU support for guest -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEZdn75s5e6LHDQ+f/rUjsVaLHLAcFAmPifFIACgkQrUjsVaLH LAcEyxAAinMBaBhiPmwWZQvcCzh/UFmJo8BQCwAPuwoc/a4ZGAR7ylzd0oJilP8M wSgX6Ad8XF+CEW2VpxW9nwyi41N25ep1Lrf8vOaWy9L9QNUo0t15WrCIbXT2p399 HrK9fz7HHKKIMsJy+rYb9EepdmMf55xtr1Y/EjyvhoDQbrEMlKsAODYz/SUoriQG Tn3cCYBzLdvzDzu0xXM9v+nsetWXdajK/v4je+mE3NQceXhePAO4oVWP4IpnoROd ZQm3evvVdf0WtKG9curxwMB7jjBqDBFrcLYl0qHGa7pi2o5PzVM7esgaV47KwetH IgA/Mrf1IfzpgM7VYDDax5wUHlKj63KisqU0J8rU3PUloQXaWqv7+ho51t9GzZ/i 9x4uyO/evVntgyTw6HCbqmQJDgEtJiG1ydrR/ydBMYHLnh7LPY2UpKgcqmirtbkK 1/DYDp84vikQ5VW1hc8IACdoBShh9Moh4xsEStzkTrIeHcZCjtORXUh8UIPZ0Mu2 7Mnkktu9I55SLwA3rwH/EYT1ISrOV1G+q3wfqgeLpn8YUWwCIiqWQ5Ur0/WSMJse uJ3HedZDzj9T4n4khX+mKEYh6joAafQZag+4TID2lRSwd0S/mpeC22hYrViMdDmq yhE+JNin/sz4AVaHNzGwfqk2NC2RFl9aRn2X0xTwyBubif9pKMQ= =spUL -----END PGP SIGNATURE----- Merge tag 'kvm-riscv-6.3-1' of https://github.com/kvm-riscv/linux into HEAD KVM/riscv changes for 6.3 - Fix wrong usage of PGDIR_SIZE to check page sizes - Fix privilege mode setting in kvm_riscv_vcpu_trap_redirect() - Redirect illegal instruction traps to guest - SBI PMU support for guest
118 lines
2.6 KiB
C
118 lines
2.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (C) 2019 Western Digital Corporation or its affiliates.
|
|
*
|
|
* Authors:
|
|
* Anup Patel <anup.patel@wdc.com>
|
|
*/
|
|
|
|
#include <linux/errno.h>
|
|
#include <linux/err.h>
|
|
#include <linux/module.h>
|
|
#include <linux/kvm_host.h>
|
|
#include <asm/csr.h>
|
|
#include <asm/hwcap.h>
|
|
#include <asm/sbi.h>
|
|
|
|
long kvm_arch_dev_ioctl(struct file *filp,
|
|
unsigned int ioctl, unsigned long arg)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
int kvm_arch_hardware_enable(void)
|
|
{
|
|
unsigned long hideleg, hedeleg;
|
|
|
|
hedeleg = 0;
|
|
hedeleg |= (1UL << EXC_INST_MISALIGNED);
|
|
hedeleg |= (1UL << EXC_BREAKPOINT);
|
|
hedeleg |= (1UL << EXC_SYSCALL);
|
|
hedeleg |= (1UL << EXC_INST_PAGE_FAULT);
|
|
hedeleg |= (1UL << EXC_LOAD_PAGE_FAULT);
|
|
hedeleg |= (1UL << EXC_STORE_PAGE_FAULT);
|
|
csr_write(CSR_HEDELEG, hedeleg);
|
|
|
|
hideleg = 0;
|
|
hideleg |= (1UL << IRQ_VS_SOFT);
|
|
hideleg |= (1UL << IRQ_VS_TIMER);
|
|
hideleg |= (1UL << IRQ_VS_EXT);
|
|
csr_write(CSR_HIDELEG, hideleg);
|
|
|
|
/* VS should access only the time counter directly. Everything else should trap */
|
|
csr_write(CSR_HCOUNTEREN, 0x02);
|
|
|
|
csr_write(CSR_HVIP, 0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void kvm_arch_hardware_disable(void)
|
|
{
|
|
/*
|
|
* After clearing the hideleg CSR, the host kernel will receive
|
|
* spurious interrupts if hvip CSR has pending interrupts and the
|
|
* corresponding enable bits in vsie CSR are asserted. To avoid it,
|
|
* hvip CSR and vsie CSR must be cleared before clearing hideleg CSR.
|
|
*/
|
|
csr_write(CSR_VSIE, 0);
|
|
csr_write(CSR_HVIP, 0);
|
|
csr_write(CSR_HEDELEG, 0);
|
|
csr_write(CSR_HIDELEG, 0);
|
|
}
|
|
|
|
static int __init riscv_kvm_init(void)
|
|
{
|
|
const char *str;
|
|
|
|
if (!riscv_isa_extension_available(NULL, h)) {
|
|
kvm_info("hypervisor extension not available\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
if (sbi_spec_is_0_1()) {
|
|
kvm_info("require SBI v0.2 or higher\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
if (sbi_probe_extension(SBI_EXT_RFENCE) <= 0) {
|
|
kvm_info("require SBI RFENCE extension\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
kvm_riscv_gstage_mode_detect();
|
|
|
|
kvm_riscv_gstage_vmid_detect();
|
|
|
|
kvm_info("hypervisor extension available\n");
|
|
|
|
switch (kvm_riscv_gstage_mode()) {
|
|
case HGATP_MODE_SV32X4:
|
|
str = "Sv32x4";
|
|
break;
|
|
case HGATP_MODE_SV39X4:
|
|
str = "Sv39x4";
|
|
break;
|
|
case HGATP_MODE_SV48X4:
|
|
str = "Sv48x4";
|
|
break;
|
|
case HGATP_MODE_SV57X4:
|
|
str = "Sv57x4";
|
|
break;
|
|
default:
|
|
return -ENODEV;
|
|
}
|
|
kvm_info("using %s G-stage page table format\n", str);
|
|
|
|
kvm_info("VMID %ld bits available\n", kvm_riscv_gstage_vmid_bits());
|
|
|
|
return kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
|
|
}
|
|
module_init(riscv_kvm_init);
|
|
|
|
static void __exit riscv_kvm_exit(void)
|
|
{
|
|
kvm_exit();
|
|
}
|
|
module_exit(riscv_kvm_exit);
|