RISC-V KVM in-kernel AIA irqchip
Subsystems (3)
v3 cover RISC-V KVM in-kernel AIA irqchip
This series adds in-kernel AIA irqchip to KVM RISC-V which trap-n-emulate IMSIC and APLIC MSI-mode for Guest. The APLIC MSI-mode trap-n-emulate is optional so KVM user space can emulate APLIC entirely in user space.
The use of IMSIC HW guest files to accelerate IMSIC virtualization will be done as separate series since this depends on AIA irqchip drivers to be upstreamed. This series has no dependency on the AIA irqchip drivers.
There is also a KVM AIA irq-bypass (or device MSI virtualization) series under development which depends on this series and upcoming IOMMU driver series.
These patches (or this series) can also be found in the riscv_kvm_aia_irqchip_v3 branch at: https://github.com/avpatel/linux.git
Changes since v2:
- Added KVM_CAP_IRQCHIP in PATCH5
- Fix check for KVM_DEV_RISCV_AIA_CONFIG_IDS write in PATCH6
- Fix APLIC_IRQ_STATE_ENPEND usage in PATCH7
Changes since v1:
- Rebased on Linux-6.4-rc6
- Addressed Atish's comment in PATCH6
- Added comments in arch/riscv/include/uapi/asm/kvm.h about APLIC and IMSIC device attribute type
Anup Patel (10):
RISC-V: KVM: Implement guest external interrupt line management
RISC-V: KVM: Add IMSIC related defines
RISC-V: KVM: Add APLIC related defines
RISC-V: KVM: Set kvm_riscv_aia_nr_hgei to zero
RISC-V: KVM: Skeletal in-kernel AIA irqchip support
RISC-V: KVM: Implement device interface for AIA irqchip
RISC-V: KVM: Add in-kernel emulation of AIA APLIC
RISC-V: KVM: Expose APLIC registers as attributes of AIA irqchip
RISC-V: KVM: Add in-kernel virtualization of AIA IMSIC
RISC-V: KVM: Expose IMSIC registers as attributes of AIA irqchip
arch/riscv/include/asm/kvm_aia.h | 107 ++- arch/riscv/include/asm/kvm_aia_aplic.h | 58 ++ arch/riscv/include/asm/kvm_aia_imsic.h | 38 + arch/riscv/include/asm/kvm_host.h | 4 + arch/riscv/include/uapi/asm/kvm.h | 72 ++ arch/riscv/kvm/Kconfig | 4 + arch/riscv/kvm/Makefile | 3 + arch/riscv/kvm/aia.c | 274 +++++- arch/riscv/kvm/aia_aplic.c | 619 ++++++++++++++ arch/riscv/kvm/aia_device.c | 673 +++++++++++++++ arch/riscv/kvm/aia_imsic.c | 1083 ++++++++++++++++++++++++ arch/riscv/kvm/main.c | 3 +- arch/riscv/kvm/vcpu.c | 2 + arch/riscv/kvm/vm.c | 118 +++ include/uapi/linux/kvm.h | 2 + 15 files changed, 3027 insertions(+), 33 deletions(-) create mode 100644 arch/riscv/include/asm/kvm_aia_aplic.h create mode 100644 arch/riscv/include/asm/kvm_aia_imsic.h create mode 100644 arch/riscv/kvm/aia_aplic.c create mode 100644 arch/riscv/kvm/aia_device.c create mode 100644 arch/riscv/kvm/aia_imsic.c
Signature · 1 line
2.34.1
PATCH v3 1/10 RISC-V: KVM: Implement guest external interrupt line management
The RISC-V host will have one guest external interrupt line for each VS-level IMSICs associated with a HART. The guest external interrupt lines are per-HART resources and hypervisor can use HGEIE, HGEIP, and HIE CSRs to manage these guest external interrupt lines.
--- arch/riscv/include/asm/kvm_aia.h | 10 ++ arch/riscv/kvm/aia.c | 244 +++++++++++++++++++++++++++++++ arch/riscv/kvm/main.c | 3 +- arch/riscv/kvm/vcpu.c | 2 + 4 files changed, 258 insertions(+), 1 deletion(-)
arch/riscv/include/asm/kvm_aia.h +10 -0
@@ -44,10 +44,15 @@ struct kvm_vcpu_aia {#define irqchip_in_kernel (k) ((k)->arch.aia.in_kernel) +extern unsigned int kvm_riscv_aia_nr_hgei;DECLARE_STATIC_KEY_FALSE (kvm_riscv_aia_available);#define kvm_riscv_aia_available () \ static_branch_unlikely(&kvm_riscv_aia_available) +static inline void kvm_riscv_vcpu_aia_imsic_release (struct kvm_vcpu *vcpu) +{ +} +#define KVM_RISCV_AIA_IMSIC_TOPEI (ISELECT_MASK + 1) static inline int kvm_riscv_vcpu_aia_imsic_rmw(struct kvm_vcpu *vcpu, unsigned long isel,
@@ -119,6 +124,11 @@ static inline void kvm_riscv_aia_destroy_vm(struct kvm *kvm) { } +int kvm_riscv_aia_alloc_hgei (int cpu,struct kvm_vcpu *owner, +void __iomem **hgei_va,phys_addr_t *hgei_pa); +void kvm_riscv_aia_free_hgei (int cpu,int hgei); +void kvm_riscv_aia_wakeon_hgei (struct kvm_vcpu *owner,bool enable); +void kvm_riscv_aia_enable (void );void kvm_riscv_aia_disable (void );int kvm_riscv_aia_init (void );
arch/riscv/kvm/aia.c +244 -0
298 lines not on this page · raw message
arch/riscv/kvm/main.c +2 -1
@@ -116,7 +116,8 @@ static int __init riscv_kvm_init(void)kvm_info ("VMID %ld bits available\n" ,kvm_riscv_gstage_vmid_bits ());if (kvm_riscv_aia_available ()) -kvm_info ("AIA available\n" ); +kvm_info ("AIA available with %d guest external interrupts\n" , + kvm_riscv_aia_nr_hgei); rc =kvm_init (sizeof (struct kvm_vcpu ),0 ,THIS_MODULE );if (rc) {
arch/riscv/kvm/vcpu.c +2 -0
@@ -250,10 +250,12 @@ int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)void kvm_arch_vcpu_blocking (struct kvm_vcpu *vcpu) { +kvm_riscv_aia_wakeon_hgei (vcpu, true); }void kvm_arch_vcpu_unblocking (struct kvm_vcpu *vcpu) { +kvm_riscv_aia_wakeon_hgei (vcpu, false); }int kvm_arch_vcpu_runnable (struct kvm_vcpu *vcpu)
Signature · 1 line
2.34.1
PATCH v3 2/10 RISC-V: KVM: Add IMSIC related defines
In reply to Anup PatelWe add IMSIC related defines in a separate header so that different parts of KVM code can share it. Once AIA drivers are merged will have a common IMSIC header shared by both KVM and IRQCHIP driver.
--- arch/riscv/include/asm/kvm_aia_imsic.h | 38 ++++++++++++++++++++++++++ arch/riscv/kvm/aia.c | 3 +- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 arch/riscv/include/asm/kvm_aia_imsic.h
arch/riscv/include/asm/kvm_aia_imsic.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2021 Western Digital Corporation or its affiliates. +* Copyright (C) 2022 Ventana Micro Systems Inc. +*/ +#ifndef __KVM_RISCV_AIA_IMSIC_H +#define __KVM_RISCV_AIA_IMSIC_H + +#include <linux/types.h> +#include <asm/csr.h> + +#define IMSIC_MMIO_PAGE_SHIFT 12 +#define IMSIC_MMIO_PAGE_SZ (1UL << IMSIC_MMIO_PAGE_SHIFT) +#define IMSIC_MMIO_PAGE_LE 0x00 +#define IMSIC_MMIO_PAGE_BE 0x04 + +#define IMSIC_MIN_ID 63 +#define IMSIC_MAX_ID 2048 + +#define IMSIC_EIDELIVERY 0x70 + +#define IMSIC_EITHRESHOLD 0x72 + +#define IMSIC_EIP0 0x80 +#define IMSIC_EIP63 0xbf +#define IMSIC_EIPx_BITS 32 + +#define IMSIC_EIE0 0xc0 +#define IMSIC_EIE63 0xff +#define IMSIC_EIEx_BITS 32 + +#define IMSIC_FIRST IMSIC_EIDELIVERY +#define IMSIC_LAST IMSIC_EIE63 + +#define IMSIC_MMIO_SETIPNUM_LE 0x00 +#define IMSIC_MMIO_SETIPNUM_BE 0x04 + +#endif
arch/riscv/kvm/aia.c +1 -2
@@ -15,6 +15,7 @@#include <linux/percpu.h> #include <linux/spinlock.h> #include <asm/hwcap.h> +#include <asm/kvm_aia_imsic.h> struct aia_hgei_control {raw_spinlock_t lock;
@@ -364,8 +365,6 @@ static int aia_rmw_iprio(struct kvm_vcpu *vcpu, unsigned int isel,return KVM_INSN_CONTINUE_NEXT_SEPC ; } -#define IMSIC_FIRST 0x70 -#define IMSIC_LAST 0xffint kvm_riscv_vcpu_aia_rmw_ireg (struct kvm_vcpu *vcpu,unsigned int csr_num,unsigned long *val,unsigned long new_val,unsigned long wr_mask)
Signature · 1 line
2.34.1
PATCH v3 3/10 RISC-V: KVM: Add APLIC related defines
In reply to Anup PatelWe add APLIC related defines in a separate header so that different parts of KVM code can share it. Once AIA drivers are merged will have a common APLIC header shared by both KVM and IRQCHIP driver.
--- arch/riscv/include/asm/kvm_aia_aplic.h | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 arch/riscv/include/asm/kvm_aia_aplic.h
arch/riscv/include/asm/kvm_aia_aplic.h new file +58 -0
@@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2021 Western Digital Corporation or its affiliates. +* Copyright (C) 2022 Ventana Micro Systems Inc. +*/ +#ifndef __KVM_RISCV_AIA_IMSIC_H +#define __KVM_RISCV_AIA_IMSIC_H + +#include <linux/bitops.h> + +#define APLIC_MAX_IDC BIT(14) +#define APLIC_MAX_SOURCE 1024 + +#define APLIC_DOMAINCFG 0x0000 +#define APLIC_DOMAINCFG_RDONLY 0x80000000 +#define APLIC_DOMAINCFG_IE BIT(8) +#define APLIC_DOMAINCFG_DM BIT(2) +#define APLIC_DOMAINCFG_BE BIT(0) + +#define APLIC_SOURCECFG_BASE 0x0004 +#define APLIC_SOURCECFG_D BIT(10) +#define APLIC_SOURCECFG_CHILDIDX_MASK 0x000003ff +#define APLIC_SOURCECFG_SM_MASK 0x00000007 +#define APLIC_SOURCECFG_SM_INACTIVE 0x0 +#define APLIC_SOURCECFG_SM_DETACH 0x1 +#define APLIC_SOURCECFG_SM_EDGE_RISE 0x4 +#define APLIC_SOURCECFG_SM_EDGE_FALL 0x5 +#define APLIC_SOURCECFG_SM_LEVEL_HIGH 0x6 +#define APLIC_SOURCECFG_SM_LEVEL_LOW 0x7 + +#define APLIC_IRQBITS_PER_REG 32 + +#define APLIC_SETIP_BASE 0x1c00 +#define APLIC_SETIPNUM 0x1cdc + +#define APLIC_CLRIP_BASE 0x1d00 +#define APLIC_CLRIPNUM 0x1ddc + +#define APLIC_SETIE_BASE 0x1e00 +#define APLIC_SETIENUM 0x1edc + +#define APLIC_CLRIE_BASE 0x1f00 +#define APLIC_CLRIENUM 0x1fdc + +#define APLIC_SETIPNUM_LE 0x2000 +#define APLIC_SETIPNUM_BE 0x2004 + +#define APLIC_GENMSI 0x3000 + +#define APLIC_TARGET_BASE 0x3004 +#define APLIC_TARGET_HART_IDX_SHIFT 18 +#define APLIC_TARGET_HART_IDX_MASK 0x3fff +#define APLIC_TARGET_GUEST_IDX_SHIFT 12 +#define APLIC_TARGET_GUEST_IDX_MASK 0x3f +#define APLIC_TARGET_IPRIO_MASK 0xff +#define APLIC_TARGET_EIID_MASK 0x7ff + +#endif
Signature · 1 line
2.34.1
PATCH v3 4/10 RISC-V: KVM: Set kvm_riscv_aia_nr_hgei to zero
In reply to Anup PatelWe hard-code the kvm_riscv_aia_nr_hgei to zero until IMSIC HW guest file support is added in KVM RISC-V.
--- arch/riscv/kvm/aia.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arch/riscv/kvm/aia.c +9 -1
@@ -408,7 +408,7 @@ int kvm_riscv_aia_alloc_hgei(int cpu, struct kvm_vcpu *owner,raw_spin_unlock_irqrestore (&hgctrl->lock, flags); -/* TODO: To be updated later by AIA in-kernel irqchip support */ +/* TODO: To be updated later by AIA IMSIC HW guest file support */ if (hgei_va) *hgei_va =NULL ;if (hgei_pa)
@@ -610,6 +610,14 @@ int kvm_riscv_aia_init(void)if (kvm_riscv_aia_nr_hgei) kvm_riscv_aia_nr_hgei--; +/* +* Number of usable HGEI lines should be minimum of per-HART +* IMSIC guest files and number of bits in HGEIE +* +* TODO: To be updated later by AIA IMSIC HW guest file support +*/ + kvm_riscv_aia_nr_hgei =0 ; +/* Initialize guest external interrupt line management */ rc =aia_hgei_init ();if (rc)
Signature · 1 line
2.34.1
PATCH v3 5/10 RISC-V: KVM: Skeletal in-kernel AIA irqchip support
In reply to Anup PatelTo incrementally implement in-kernel AIA irqchip support, we first add minimal skeletal support which only compiles but does not provide any functionality.
--- arch/riscv/include/asm/kvm_aia.h | 20 +++++ arch/riscv/include/asm/kvm_host.h | 4 + arch/riscv/include/uapi/asm/kvm.h | 4 + arch/riscv/kvm/Kconfig | 4 + arch/riscv/kvm/aia.c | 8 ++ arch/riscv/kvm/vm.c | 118 ++++++++++++++++++++++++++++++ 6 files changed, 158 insertions(+)
arch/riscv/include/asm/kvm_aia.h +20 -0
@@ -45,6 +45,7 @@ struct kvm_vcpu_aia {#define irqchip_in_kernel (k) ((k)->arch.aia.in_kernel)extern unsigned int kvm_riscv_aia_nr_hgei; +extern unsigned int kvm_riscv_aia_max_ids;DECLARE_STATIC_KEY_FALSE (kvm_riscv_aia_available);#define kvm_riscv_aia_available () \ static_branch_unlikely(&kvm_riscv_aia_available)
@@ -116,6 +117,25 @@ static inline void kvm_riscv_vcpu_aia_deinit(struct kvm_vcpu *vcpu) { } +static inline int kvm_riscv_aia_inject_msi_by_id (struct kvm *kvm, +u32 hart_index, +u32 guest_index,u32 iid) +{ +return 0 ; +} + +static inline int kvm_riscv_aia_inject_msi (struct kvm *kvm, +struct kvm_msi *msi) +{ +return 0 ; +} + +static inline int kvm_riscv_aia_inject_irq (struct kvm *kvm, +unsigned int irq,bool level) +{ +return 0 ; +} +static inline void kvm_riscv_aia_init_vm (struct kvm *kvm) { }
arch/riscv/include/asm/kvm_host.h +4 -0
@@ -27,6 +27,8 @@#define KVM_VCPU_MAX_FEATURES 0 +#define KVM_IRQCHIP_NUM_PINS 1024 +#define KVM_REQ_SLEEP \ KVM_ARCH_REQ_FLAGS(0, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)#define KVM_REQ_VCPU_RESET KVM_ARCH_REQ(1)
@@ -318,6 +320,8 @@ int kvm_riscv_gstage_vmid_init(struct kvm *kvm);bool kvm_riscv_gstage_vmid_ver_changed (struct kvm_vmid *vmid);void kvm_riscv_gstage_vmid_update (struct kvm_vcpu *vcpu); +int kvm_riscv_setup_default_irq_routing (struct kvm *kvm,u32 lines); +void __kvm_riscv_unpriv_trap (void ); unsigned long kvm_riscv_vcpu_unpriv_read(struct kvm_vcpu *vcpu,
arch/riscv/include/uapi/asm/kvm.h +4 -0
@@ -15,6 +15,7 @@#include <asm/bitsperlong.h> #include <asm/ptrace.h> +#define __KVM_HAVE_IRQ_LINE#define __KVM_HAVE_READONLY_MEM#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
@@ -203,6 +204,9 @@ enum KVM_RISCV_SBI_EXT_ID {#define KVM_REG_RISCV_SBI_MULTI_REG_LAST \ KVM_REG_RISCV_SBI_MULTI_REG(KVM_RISCV_SBI_EXT_MAX - 1) +/* One single KVM irqchip, ie. the AIA */ +#define KVM_NR_IRQCHIPS 1 +#endif #endif /* __LINUX_KVM_RISCV_H */
arch/riscv/kvm/Kconfig +4 -0
@@ -21,6 +21,10 @@ config KVM tristate "Kernel-based Virtual Machine (KVM) support (EXPERIMENTAL)" depends on RISCV_SBI && MMU select HAVE_KVM_EVENTFD + select HAVE_KVM_IRQCHIP + select HAVE_KVM_IRQFD + select HAVE_KVM_IRQ_ROUTING + select HAVE_KVM_MSI select HAVE_KVM_VCPU_ASYNC_IOCTL select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_GENERIC_HARDWARE_ENABLING
arch/riscv/kvm/aia.c +8 -0
@@ -26,6 +26,7 @@ static DEFINE_PER_CPU(struct aia_hgei_control, aia_hgei);static int hgei_parent_irq;unsigned int kvm_riscv_aia_nr_hgei; +unsigned int kvm_riscv_aia_max_ids;DEFINE_STATIC_KEY_FALSE (kvm_riscv_aia_available);static int aia_find_hgei (struct kvm_vcpu *owner)
@@ -618,6 +619,13 @@ int kvm_riscv_aia_init(void)*/ kvm_riscv_aia_nr_hgei =0 ; +/* +* Find number of guest MSI IDs +* +* TODO: To be updated later by AIA IMSIC HW guest file support +*/ + kvm_riscv_aia_max_ids =IMSIC_MAX_ID ; +/* Initialize guest external interrupt line management */ rc =aia_hgei_init ();if (rc)
arch/riscv/kvm/vm.c +118 -0
129 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 6/10 RISC-V: KVM: Implement device interface for AIA irqchip
In reply to Anup PatelWe implement KVM device interface for in-kernel AIA irqchip so that user-space can use KVM device ioctls to create, configure, and destroy in-kernel AIA irqchip.
--- arch/riscv/include/asm/kvm_aia.h | 132 +++++-- arch/riscv/include/uapi/asm/kvm.h | 45 +++ arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/aia.c | 11 + arch/riscv/kvm/aia_device.c | 623 ++++++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 2 + 6 files changed, 772 insertions(+), 42 deletions(-) create mode 100644 arch/riscv/kvm/aia_device.c
arch/riscv/include/asm/kvm_aia.h +90 -42
@@ -20,6 +20,33 @@ struct kvm_aia {/* In-kernel irqchip initialized */ bool initialized; + +/* Virtualization mode (Emulation, HW Accelerated, or Auto) */ +u32 mode; + +/* Number of MSIs */ +u32 nr_ids; + +/* Number of wired IRQs */ +u32 nr_sources; + +/* Number of group bits in IMSIC address */ +u32 nr_group_bits; + +/* Position of group bits in IMSIC address */ +u32 nr_group_shift; + +/* Number of hart bits in IMSIC address */ +u32 nr_hart_bits; + +/* Number of guest bits in IMSIC address */ +u32 nr_guest_bits; + +/* Guest physical address of APLIC */ +gpa_t aplic_addr; + +/* Internal state of APLIC */ +void *aplic_state; };struct kvm_vcpu_aia_csr {
@@ -38,8 +65,19 @@ struct kvm_vcpu_aia {/* CPU AIA CSR context upon Guest VCPU reset */ struct kvm_vcpu_aia_csr guest_reset_csr; + +/* Guest physical address of IMSIC for this VCPU */ +gpa_t imsic_addr; + +/* HART index of IMSIC extacted from guest physical address */ +u32 hart_index; + +/* Internal state of IMSIC for this VCPU */ +void *imsic_state; }; +#define KVM_RISCV_AIA_UNDEF_ADDR (-1) +#define kvm_riscv_aia_initialized (k) ((k)->arch.aia.initialized)#define irqchip_in_kernel (k) ((k)->arch.aia.in_kernel)
@@ -50,10 +88,17 @@ DECLARE_STATIC_KEY_FALSE(kvm_riscv_aia_available);#define kvm_riscv_aia_available () \ static_branch_unlikely(&kvm_riscv_aia_available) +extern struct kvm_device_ops kvm_riscv_aia_device_ops; +static inline void kvm_riscv_vcpu_aia_imsic_release (struct kvm_vcpu *vcpu) { } +static inline int kvm_riscv_vcpu_aia_imsic_update (struct kvm_vcpu *vcpu) +{ +return 1 ; +} +#define KVM_RISCV_AIA_IMSIC_TOPEI (ISELECT_MASK + 1) static inline int kvm_riscv_vcpu_aia_imsic_rmw(struct kvm_vcpu *vcpu, unsigned long isel,
@@ -64,6 +109,41 @@ static inline int kvm_riscv_vcpu_aia_imsic_rmw(struct kvm_vcpu *vcpu,return 0 ; } +static inline void kvm_riscv_vcpu_aia_imsic_reset (struct kvm_vcpu *vcpu) +{ +} + +static inline int kvm_riscv_vcpu_aia_imsic_inject (struct kvm_vcpu *vcpu, +u32 guest_index,u32 offset, +u32 iid) +{ +return 0 ; +} + +static inline int kvm_riscv_vcpu_aia_imsic_init (struct kvm_vcpu *vcpu) +{ +return 0 ; +} + +static inline void kvm_riscv_vcpu_aia_imsic_cleanup (struct kvm_vcpu *vcpu) +{ +} + +static inline int kvm_riscv_aia_aplic_inject (struct kvm *kvm, +u32 source,bool level) +{ +return 0 ; +} + +static inline int kvm_riscv_aia_aplic_init (struct kvm *kvm) +{ +return 0 ; +} + +static inline void kvm_riscv_aia_aplic_cleanup (struct kvm *kvm) +{ +} +#ifdef CONFIG_32BIT void kvm_riscv_vcpu_aia_flush_interrupts (struct kvm_vcpu *vcpu);void kvm_riscv_vcpu_aia_sync_interrupts (struct kvm_vcpu *vcpu);
@@ -99,50 +179,18 @@ int kvm_riscv_vcpu_aia_rmw_ireg(struct kvm_vcpu *vcpu, unsigned int csr_num, { .base = CSR_SIREG, .count = 1, .func = kvm_riscv_vcpu_aia_rmw_ireg }, \ { .base = CSR_STOPEI, .count = 1, .func = kvm_riscv_vcpu_aia_rmw_topei }, -static inline int kvm_riscv_vcpu_aia_update(struct kvm_vcpu *vcpu) -{ -return 1 ; -} - -static inline void kvm_riscv_vcpu_aia_reset (struct kvm_vcpu *vcpu) -{ -} - -static inline int kvm_riscv_vcpu_aia_init (struct kvm_vcpu *vcpu) -{ -return 0 ; -} - -static inline void kvm_riscv_vcpu_aia_deinit (struct kvm_vcpu *vcpu) -{ -} - -static inline int kvm_riscv_aia_inject_msi_by_id (struct kvm *kvm, -u32 hart_index, -u32 guest_index,u32 iid) -{ -return 0 ; -} - -static inline int kvm_riscv_aia_inject_msi (struct kvm *kvm, -struct kvm_msi *msi) -{ -return 0 ; -} +int kvm_riscv_vcpu_aia_update(struct kvm_vcpu *vcpu); +void kvm_riscv_vcpu_aia_reset (struct kvm_vcpu *vcpu); +int kvm_riscv_vcpu_aia_init (struct kvm_vcpu *vcpu); +void kvm_riscv_vcpu_aia_deinit (struct kvm_vcpu *vcpu); -static inline int kvm_riscv_aia_inject_irq (struct kvm *kvm, -unsigned int irq,bool level) -{ -return 0 ; -} +int kvm_riscv_aia_inject_msi_by_id (struct kvm *kvm,u32 hart_index, +u32 guest_index,u32 iid); +int kvm_riscv_aia_inject_msi (struct kvm *kvm,struct kvm_msi *msi); +int kvm_riscv_aia_inject_irq (struct kvm *kvm,unsigned int irq,bool level); -static inline void kvm_riscv_aia_init_vm (struct kvm *kvm) -{ -} - -static inline void kvm_riscv_aia_destroy_vm (struct kvm *kvm) -{ -} +void kvm_riscv_aia_init_vm (struct kvm *kvm); +void kvm_riscv_aia_destroy_vm (struct kvm *kvm);int kvm_riscv_aia_alloc_hgei (int cpu,struct kvm_vcpu *owner,void __iomem **hgei_va,phys_addr_t *hgei_pa);
arch/riscv/include/uapi/asm/kvm.h +45 -0
51 lines not on this page · raw message
arch/riscv/kvm/Makefile +1 -0
@@ -27,3 +27,4 @@ kvm-y += vcpu_sbi_hsm.o kvm-y += vcpu_timer.o kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_pmu.o vcpu_sbi_pmu.o kvm-y += aia.o +kvm-y += aia_device.o
arch/riscv/kvm/aia.c +11 -0
@@ -631,6 +631,14 @@ int kvm_riscv_aia_init(void)if (rc)return rc; +/* Register device operations */ + rc =kvm_register_device_ops (&kvm_riscv_aia_device_ops, +KVM_DEV_TYPE_RISCV_AIA ); +if (rc) { +aia_hgei_exit (); +return rc; + } +/* Enable KVM AIA support */ static_branch_enable (&kvm_riscv_aia_available);
@@ -642,6 +650,9 @@ void kvm_riscv_aia_exit(void)if (!kvm_riscv_aia_available ())return ; +/* Unregister device operations */ +kvm_unregister_device_ops (KVM_DEV_TYPE_RISCV_AIA ); +/* Cleanup the HGEI state */ aia_hgei_exit (); }
arch/riscv/kvm/aia_device.c new file +623 -0
623 lines not on this page · raw message
include/uapi/linux/kvm.h +2 -0
@@ -1442,6 +1442,8 @@ enum kvm_device_type {#define KVM_DEV_TYPE_XIVE KVM_DEV_TYPE_XIVE KVM_DEV_TYPE_ARM_PV_TIME,#define KVM_DEV_TYPE_ARM_PV_TIME KVM_DEV_TYPE_ARM_PV_TIME + KVM_DEV_TYPE_RISCV_AIA, +#define KVM_DEV_TYPE_RISCV_AIA KVM_DEV_TYPE_RISCV_AIA KVM_DEV_TYPE_MAX, };
Signature · 1 line
2.34.1
PATCH v3 7/10 RISC-V: KVM: Add in-kernel emulation of AIA APLIC
In reply to Anup PatelThere is no virtualization support in AIA APLIC so we add in-kernel emulation of AIA APLIC which only supports MSI-mode (i.e. wired interrupts forwarded to AIA IMSIC as MSIs).
--- arch/riscv/include/asm/kvm_aia.h | 17 +- arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/aia_aplic.c | 576 +++++++++++++++++++++++++++++++ 3 files changed, 580 insertions(+), 14 deletions(-) create mode 100644 arch/riscv/kvm/aia_aplic.c
arch/riscv/include/asm/kvm_aia.h +3 -14
@@ -129,20 +129,9 @@ static inline void kvm_riscv_vcpu_aia_imsic_cleanup(struct kvm_vcpu *vcpu) { } -static inline int kvm_riscv_aia_aplic_inject (struct kvm *kvm, -u32 source,bool level) -{ -return 0 ; -} - -static inline int kvm_riscv_aia_aplic_init (struct kvm *kvm) -{ -return 0 ; -} - -static inline void kvm_riscv_aia_aplic_cleanup (struct kvm *kvm) -{ -} +int kvm_riscv_aia_aplic_inject (struct kvm *kvm,u32 source,bool level); +int kvm_riscv_aia_aplic_init (struct kvm *kvm); +void kvm_riscv_aia_aplic_cleanup (struct kvm *kvm);#ifdef CONFIG_32BIT void kvm_riscv_vcpu_aia_flush_interrupts (struct kvm_vcpu *vcpu);
arch/riscv/kvm/Makefile +1 -0
@@ -28,3 +28,4 @@ kvm-y += vcpu_timer.o kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_pmu.o vcpu_sbi_pmu.o kvm-y += aia.o kvm-y += aia_device.o +kvm-y += aia_aplic.o
arch/riscv/kvm/aia_aplic.c new file +576 -0
576 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v3 07/10] RISC-V: KVM: Add in-kernel emulation of AIA APLIC
Quoted 633 lines · On Thu, Jun 15, 2023 at 12:34?AM Anup Patel <[email protected]> wrote:
There is no virtualization support in AIA APLIC so we add in-kernel emulation of AIA APLIC which only supports MSI-mode (i.e. wired interrupts forwarded to AIA IMSIC as MSIs).
Signed-off-by Anup Patel <[email protected]>--- arch/riscv/include/asm/kvm_aia.h | 17 +- arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/aia_aplic.c | 576 +++++++++++++++++++++++++++++++ 3 files changed, 580 insertions(+), 14 deletions(-) create mode 100644 arch/riscv/kvm/aia_aplic.carch/riscv/include/asm/kvm_aia.h +3
-14@@ -129,20 +129,9 @@ static inline void kvm_riscv_vcpu_aia_imsic_cleanup(struct kvm_vcpu *vcpu) { } -static inline int kvm_riscv_aia_aplic_inject (struct kvm *kvm, -u32 source,bool level) -{ -return 0 ; -} - -static inline int kvm_riscv_aia_aplic_init (struct kvm *kvm) -{ -return 0 ; -} - -static inline void kvm_riscv_aia_aplic_cleanup (struct kvm *kvm) -{ -} +int kvm_riscv_aia_aplic_inject (struct kvm *kvm,u32 source,bool level); +int kvm_riscv_aia_aplic_init (struct kvm *kvm); +void kvm_riscv_aia_aplic_cleanup (struct kvm *kvm);#ifdef CONFIG_32BIT void kvm_riscv_vcpu_aia_flush_interrupts (struct kvm_vcpu *vcpu);arch/riscv/kvm/Makefile +1
-0@@ -28,3 +28,4 @@ kvm-y += vcpu_timer.o kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_pmu.o vcpu_sbi_pmu.o kvm-y += aia.o kvm-y += aia_device.o +kvm-y += aia_aplic.oarch/riscv/kvm/aia_aplic.c new file +576
-1@@ -0,0 +1,576 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2021 Western Digital Corporation or its affiliates. +* Copyright (C) 2022 Ventana Micro Systems Inc. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#include <linux/kvm_host.h> +#include <linux/math.h> +#include <linux/spinlock.h> +#include <linux/swab.h> +#include <kvm/iodev.h> +#include <asm/kvm_aia_aplic.h> + +struct aplic_irq { +raw_spinlock_t lock; +u32 sourcecfg; +u32 state; +#define APLIC_IRQ_STATE_PENDING BIT(0) +#define APLIC_IRQ_STATE_ENABLED BIT(1) +#define APLIC_IRQ_STATE_ENPEND (APLIC_IRQ_STATE_PENDING | \ + APLIC_IRQ_STATE_ENABLED) +#define APLIC_IRQ_STATE_INPUT BIT(8) +u32 target; +}; + +struct aplic { +struct kvm_io_device iodev; + +u32 domaincfg; +u32 genmsi; + +u32 nr_irqs; +u32 nr_words; +struct aplic_irq *irqs; +}; + +static u32 aplic_read_sourcecfg (struct aplic *aplic,u32 irq) +{ +u32 ret; +unsigned long flags; +struct aplic_irq *irqd; + +if (!irq || aplic->nr_irqs <= irq) +return 0 ; + irqd = &aplic->irqs[irq]; + +raw_spin_lock_irqsave (&irqd->lock, flags); + ret = irqd->sourcecfg; +raw_spin_unlock_irqrestore (&irqd->lock, flags); + +return ret; +} + +static void aplic_write_sourcecfg (struct aplic *aplic,u32 irq,u32 val) +{ +unsigned long flags; +struct aplic_irq *irqd; + +if (!irq || aplic->nr_irqs <= irq) +return ; + irqd = &aplic->irqs[irq]; + +if (val &APLIC_SOURCECFG_D ) + val =0 ; +else + val &=APLIC_SOURCECFG_SM_MASK ; + +raw_spin_lock_irqsave (&irqd->lock, flags); + irqd->sourcecfg = val; +raw_spin_unlock_irqrestore (&irqd->lock, flags); +} + +static u32 aplic_read_target (struct aplic *aplic,u32 irq) +{ +u32 ret; +unsigned long flags; +struct aplic_irq *irqd; + +if (!irq || aplic->nr_irqs <= irq) +return 0 ; + irqd = &aplic->irqs[irq]; + +raw_spin_lock_irqsave (&irqd->lock, flags); + ret = irqd->target; +raw_spin_unlock_irqrestore (&irqd->lock, flags); + +return ret; +} + +static void aplic_write_target (struct aplic *aplic,u32 irq,u32 val) +{ +unsigned long flags; +struct aplic_irq *irqd; + +if (!irq || aplic->nr_irqs <= irq) +return ; + irqd = &aplic->irqs[irq]; + + val &=APLIC_TARGET_EIID_MASK | + (APLIC_TARGET_HART_IDX_MASK <<APLIC_TARGET_HART_IDX_SHIFT ) | + (APLIC_TARGET_GUEST_IDX_MASK <<APLIC_TARGET_GUEST_IDX_SHIFT ); + +raw_spin_lock_irqsave (&irqd->lock, flags); + irqd->target = val; +raw_spin_unlock_irqrestore (&irqd->lock, flags); +} + +static bool aplic_read_pending (struct aplic *aplic,u32 irq) +{ +bool ret; +unsigned long flags; +struct aplic_irq *irqd; + +if (!irq || aplic->nr_irqs <= irq) +return false; + irqd = &aplic->irqs[irq]; + +raw_spin_lock_irqsave (&irqd->lock, flags); + ret = (irqd->state &APLIC_IRQ_STATE_PENDING ) ? true : false; +raw_spin_unlock_irqrestore (&irqd->lock, flags); + +return ret; +} + +static void aplic_write_pending (struct aplic *aplic,u32 irq,bool pending) +{ +unsigned long flags, sm; +struct aplic_irq *irqd; + +if (!irq || aplic->nr_irqs <= irq) +return ; + irqd = &aplic->irqs[irq]; + +raw_spin_lock_irqsave (&irqd->lock, flags); + + sm = irqd->sourcecfg &APLIC_SOURCECFG_SM_MASK ; +if (!pending && + ((sm ==APLIC_SOURCECFG_SM_LEVEL_HIGH ) || + (sm ==APLIC_SOURCECFG_SM_LEVEL_LOW ))) + goto skip_write_pending; + +if (pending) + irqd->state |=APLIC_IRQ_STATE_PENDING ; +else + irqd->state &= ~APLIC_IRQ_STATE_PENDING ; + +skip_write_pending: +raw_spin_unlock_irqrestore (&irqd->lock, flags); +} + +static bool aplic_read_enabled (struct aplic *aplic,u32 irq) +{ +bool ret; +unsigned long flags; +struct aplic_irq *irqd; + +if (!irq || aplic->nr_irqs <= irq) +return false; + irqd = &aplic->irqs[irq]; + +raw_spin_lock_irqsave (&irqd->lock, flags); + ret = (irqd->state &APLIC_IRQ_STATE_ENABLED ) ? true : false; +raw_spin_unlock_irqrestore (&irqd->lock, flags); + +return ret; +} + +static void aplic_write_enabled (struct aplic *aplic,u32 irq,bool enabled) +{ +unsigned long flags; +struct aplic_irq *irqd; + +if (!irq || aplic->nr_irqs <= irq) +return ; + irqd = &aplic->irqs[irq]; + +raw_spin_lock_irqsave (&irqd->lock, flags); +if (enabled) + irqd->state |=APLIC_IRQ_STATE_ENABLED ; +else + irqd->state &= ~APLIC_IRQ_STATE_ENABLED ; +raw_spin_unlock_irqrestore (&irqd->lock, flags); +} + +static bool aplic_read_input (struct aplic *aplic,u32 irq) +{ +bool ret; +unsigned long flags; +struct aplic_irq *irqd; + +if (!irq || aplic->nr_irqs <= irq) +return false; + irqd = &aplic->irqs[irq]; + +raw_spin_lock_irqsave (&irqd->lock, flags); + ret = (irqd->state &APLIC_IRQ_STATE_INPUT ) ? true : false; +raw_spin_unlock_irqrestore (&irqd->lock, flags); + +return ret; +} + +static void aplic_inject_msi (struct kvm *kvm,u32 irq,u32 target) +{ +u32 hart_idx, guest_idx, eiid; + + hart_idx = target >>APLIC_TARGET_HART_IDX_SHIFT ; + hart_idx &=APLIC_TARGET_HART_IDX_MASK ; + guest_idx = target >>APLIC_TARGET_GUEST_IDX_SHIFT ; + guest_idx &=APLIC_TARGET_GUEST_IDX_MASK ; + eiid = target &APLIC_TARGET_EIID_MASK ; +kvm_riscv_aia_inject_msi_by_id (kvm, hart_idx, guest_idx, eiid); +} + +static void aplic_update_irq_range (struct kvm *kvm,u32 first,u32 last) +{ +bool inject; +u32 irq, target; +unsigned long flags; +struct aplic_irq *irqd; +struct aplic *aplic = kvm->arch.aia.aplic_state; + +if (!(aplic->domaincfg &APLIC_DOMAINCFG_IE )) +return ; + +for (irq = first; irq <= last; irq++) { +if (!irq || aplic->nr_irqs <= irq) +continue ; + irqd = &aplic->irqs[irq]; + +raw_spin_lock_irqsave (&irqd->lock, flags); + + inject = false; + target = irqd->target; +if ((irqd->state &APLIC_IRQ_STATE_ENPEND ) == +APLIC_IRQ_STATE_ENPEND ) { + irqd->state &= ~APLIC_IRQ_STATE_PENDING ; + inject = true; + } + +raw_spin_unlock_irqrestore (&irqd->lock, flags); + +if (inject) +aplic_inject_msi (kvm, irq, target); + } +} + +int kvm_riscv_aia_aplic_inject (struct kvm *kvm,u32 source,bool level) +{ +u32 target; +bool inject = false, ie; +unsigned long flags; +struct aplic_irq *irqd; +struct aplic *aplic = kvm->arch.aia.aplic_state; + +if (!aplic || !source || (aplic->nr_irqs <= source)) +return -ENODEV ; + irqd = &aplic->irqs[source]; + ie = (aplic->domaincfg &APLIC_DOMAINCFG_IE ) ? true : false; + +raw_spin_lock_irqsave (&irqd->lock, flags); + +if (irqd->sourcecfg &APLIC_SOURCECFG_D ) + goto skip_unlock; + +switch (irqd->sourcecfg &APLIC_SOURCECFG_SM_MASK ) { +case APLIC_SOURCECFG_SM_EDGE_RISE : +if (level && !(irqd->state &APLIC_IRQ_STATE_INPUT ) && + !(irqd->state &APLIC_IRQ_STATE_PENDING )) + irqd->state |=APLIC_IRQ_STATE_PENDING ; +break ; +case APLIC_SOURCECFG_SM_EDGE_FALL : +if (!level && (irqd->state &APLIC_IRQ_STATE_INPUT ) && + !(irqd->state &APLIC_IRQ_STATE_PENDING )) + irqd->state |=APLIC_IRQ_STATE_PENDING ; +break ; +case APLIC_SOURCECFG_SM_LEVEL_HIGH : +if (level && !(irqd->state &APLIC_IRQ_STATE_PENDING )) + irqd->state |=APLIC_IRQ_STATE_PENDING ; +break ; +case APLIC_SOURCECFG_SM_LEVEL_LOW : +if (!level && !(irqd->state &APLIC_IRQ_STATE_PENDING )) + irqd->state |=APLIC_IRQ_STATE_PENDING ; +break ; + } + +if (level) + irqd->state |=APLIC_IRQ_STATE_INPUT ; +else + irqd->state &= ~APLIC_IRQ_STATE_INPUT ; + + target = irqd->target; +if (ie && ((irqd->state &APLIC_IRQ_STATE_ENPEND ) == +APLIC_IRQ_STATE_ENPEND )) { + irqd->state &= ~APLIC_IRQ_STATE_PENDING ; + inject = true; + } + +skip_unlock: +raw_spin_unlock_irqrestore (&irqd->lock, flags); + +if (inject) +aplic_inject_msi (kvm, source, target); + +return 0 ; +} + +static u32 aplic_read_input_word (struct aplic *aplic,u32 word) +{ +u32 i, ret =0 ; + +for (i =0 ; i <32 ; i++) + ret |=aplic_read_input (aplic, word *32 + i) ?BIT (i) :0 ; + +return ret; +} + +static u32 aplic_read_pending_word (struct aplic *aplic,u32 word) +{ +u32 i, ret =0 ; + +for (i =0 ; i <32 ; i++) + ret |=aplic_read_pending (aplic, word *32 + i) ?BIT (i) :0 ; + +return ret; +} + +static void aplic_write_pending_word (struct aplic *aplic,u32 word, +u32 val,bool pending) +{ +u32 i; + +for (i =0 ; i <32 ; i++) { +if (val &BIT (i)) +aplic_write_pending (aplic, word *32 + i, pending); + } +} + +static u32 aplic_read_enabled_word (struct aplic *aplic,u32 word) +{ +u32 i, ret =0 ; + +for (i =0 ; i <32 ; i++) + ret |=aplic_read_enabled (aplic, word *32 + i) ?BIT (i) :0 ; + +return ret; +} + +static void aplic_write_enabled_word (struct aplic *aplic,u32 word, +u32 val,bool enabled) +{ +u32 i; + +for (i =0 ; i <32 ; i++) { +if (val &BIT (i)) +aplic_write_enabled (aplic, word *32 + i, enabled); + } +} + +static int aplic_mmio_read_offset (struct kvm *kvm,gpa_t off,u32 *val32) +{ +u32 i; +struct aplic *aplic = kvm->arch.aia.aplic_state; + +if ((off &0x3 ) !=0 ) +return -EOPNOTSUPP ; + +if (off ==APLIC_DOMAINCFG ) { + *val32 =APLIC_DOMAINCFG_RDONLY | + aplic->domaincfg |APLIC_DOMAINCFG_DM ; + }else if ((off >=APLIC_SOURCECFG_BASE ) && + (off < (APLIC_SOURCECFG_BASE + (aplic->nr_irqs -1 ) *4 ))) { + i = ((off -APLIC_SOURCECFG_BASE ) >>2 ) +1 ; + *val32 =aplic_read_sourcecfg (aplic, i); + }else if ((off >=APLIC_SETIP_BASE ) && + (off < (APLIC_SETIP_BASE + aplic->nr_words *4 ))) { + i = (off -APLIC_SETIP_BASE ) >>2 ; + *val32 =aplic_read_pending_word (aplic, i); + }else if (off ==APLIC_SETIPNUM ) { + *val32 =0 ; + }else if ((off >=APLIC_CLRIP_BASE ) && + (off < (APLIC_CLRIP_BASE + aplic->nr_words *4 ))) { + i = (off -APLIC_CLRIP_BASE ) >>2 ; + *val32 =aplic_read_input_word (aplic, i); + }else if (off ==APLIC_CLRIPNUM ) { + *val32 =0 ; + }else if ((off >=APLIC_SETIE_BASE ) && + (off < (APLIC_SETIE_BASE + aplic->nr_words *4 ))) { + i = (off -APLIC_SETIE_BASE ) >>2 ; + *val32 =aplic_read_enabled_word (aplic, i); + }else if (off ==APLIC_SETIENUM ) { + *val32 =0 ; + }else if ((off >=APLIC_CLRIE_BASE ) && + (off < (APLIC_CLRIE_BASE + aplic->nr_words *4 ))) { + *val32 =0 ; + }else if (off ==APLIC_CLRIENUM ) { + *val32 =0 ; + }else if (off ==APLIC_SETIPNUM_LE ) { + *val32 =0 ; + }else if (off ==APLIC_SETIPNUM_BE ) { + *val32 =0 ; + }else if (off ==APLIC_GENMSI ) { + *val32 = aplic->genmsi; + }else if ((off >=APLIC_TARGET_BASE ) && + (off < (APLIC_TARGET_BASE + (aplic->nr_irqs -1 ) *4 ))) { + i = ((off -APLIC_TARGET_BASE ) >>2 ) +1 ; + *val32 =aplic_read_target (aplic, i); + }else +return -ENODEV ; + +return 0 ; +} + +static int aplic_mmio_read (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +if (len !=4 ) +return -EOPNOTSUPP ; + +return aplic_mmio_read_offset (vcpu->kvm, + addr - vcpu->kvm->arch.aia.aplic_addr, + val); +} + +static int aplic_mmio_write_offset (struct kvm *kvm,gpa_t off,u32 val32) +{ +u32 i; +struct aplic *aplic = kvm->arch.aia.aplic_state; + +if ((off &0x3 ) !=0 ) +return -EOPNOTSUPP ; + +if (off ==APLIC_DOMAINCFG ) { +/* Only IE bit writeable */ + aplic->domaincfg = val32 &APLIC_DOMAINCFG_IE ; + }else if ((off >=APLIC_SOURCECFG_BASE ) && + (off < (APLIC_SOURCECFG_BASE + (aplic->nr_irqs -1 ) *4 ))) { + i = ((off -APLIC_SOURCECFG_BASE ) >>2 ) +1 ; +aplic_write_sourcecfg (aplic, i, val32); + }else if ((off >=APLIC_SETIP_BASE ) && + (off < (APLIC_SETIP_BASE + aplic->nr_words *4 ))) { + i = (off -APLIC_SETIP_BASE ) >>2 ; +aplic_write_pending_word (aplic, i, val32, true); + }else if (off ==APLIC_SETIPNUM ) { +aplic_write_pending (aplic, val32, true); + }else if ((off >=APLIC_CLRIP_BASE ) && + (off < (APLIC_CLRIP_BASE + aplic->nr_words *4 ))) { + i = (off -APLIC_CLRIP_BASE ) >>2 ; +aplic_write_pending_word (aplic, i, val32, false); + }else if (off ==APLIC_CLRIPNUM ) { +aplic_write_pending (aplic, val32, false); + }else if ((off >=APLIC_SETIE_BASE ) && + (off < (APLIC_SETIE_BASE + aplic->nr_words *4 ))) { + i = (off -APLIC_SETIE_BASE ) >>2 ; +aplic_write_enabled_word (aplic, i, val32, true); + }else if (off ==APLIC_SETIENUM ) { +aplic_write_enabled (aplic, val32, true); + }else if ((off >=APLIC_CLRIE_BASE ) && + (off < (APLIC_CLRIE_BASE + aplic->nr_words *4 ))) { + i = (off -APLIC_CLRIE_BASE ) >>2 ; +aplic_write_enabled_word (aplic, i, val32, false); + }else if (off ==APLIC_CLRIENUM ) { +aplic_write_enabled (aplic, val32, false); + }else if (off ==APLIC_SETIPNUM_LE ) { +aplic_write_pending (aplic, val32, true); + }else if (off ==APLIC_SETIPNUM_BE ) { +aplic_write_pending (aplic,__swab32 (val32), true); + }else if (off ==APLIC_GENMSI ) { + aplic->genmsi = val32 & ~(APLIC_TARGET_GUEST_IDX_MASK << +APLIC_TARGET_GUEST_IDX_SHIFT ); +kvm_riscv_aia_inject_msi_by_id (kvm, + val32 >>APLIC_TARGET_HART_IDX_SHIFT ,0 , + val32 &APLIC_TARGET_EIID_MASK ); + }else if ((off >=APLIC_TARGET_BASE ) && + (off < (APLIC_TARGET_BASE + (aplic->nr_irqs -1 ) *4 ))) { + i = ((off -APLIC_TARGET_BASE ) >>2 ) +1 ; +aplic_write_target (aplic, i, val32); + }else +return -ENODEV ; + +aplic_update_irq_range (kvm,1 , aplic->nr_irqs -1 ); + +return 0 ; +} + +static int aplic_mmio_write (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +if (len !=4 ) +return -EOPNOTSUPP ; + +return aplic_mmio_write_offset (vcpu->kvm, + addr - vcpu->kvm->arch.aia.aplic_addr, + *((const u32 *)val)); +} + +static struct kvm_io_device_ops aplic_iodoev_ops = { + .read = aplic_mmio_read, + .write = aplic_mmio_write, +}; + +int kvm_riscv_aia_aplic_init (struct kvm *kvm) +{ +int i, ret =0 ; +struct aplic *aplic; + +/* Do nothing if we have zero sources */ +if (!kvm->arch.aia.nr_sources) +return 0 ; + +/* Allocate APLIC global state */ + aplic =kzalloc (sizeof (*aplic),GFP_KERNEL ); +if (!aplic) +return -ENOMEM ; + kvm->arch.aia.aplic_state = aplic; + +/* Setup APLIC IRQs */ + aplic->nr_irqs = kvm->arch.aia.nr_sources +1 ; + aplic->nr_words =DIV_ROUND_UP (aplic->nr_irqs,32 ); + aplic->irqs =kcalloc (aplic->nr_irqs, +sizeof (*aplic->irqs),GFP_KERNEL ); +if (!aplic->irqs) { + ret = -ENOMEM ; + goto fail_free_aplic; + } +for (i =0 ; i < aplic->nr_irqs; i++) +raw_spin_lock_init (&aplic->irqs[i].lock); + +/* Setup IO device */ +kvm_iodevice_init (&aplic->iodev, &aplic_iodoev_ops); +mutex_lock (&kvm->slots_lock); + ret =kvm_io_bus_register_dev (kvm,KVM_MMIO_BUS , + kvm->arch.aia.aplic_addr, +KVM_DEV_RISCV_APLIC_SIZE , + &aplic->iodev); +mutex_unlock (&kvm->slots_lock); +if (ret) + goto fail_free_aplic_irqs; + +/* Setup default IRQ routing */ + ret =kvm_riscv_setup_default_irq_routing (kvm, aplic->nr_irqs); +if (ret) + goto fail_unreg_iodev; + +return 0 ; + +fail_unreg_iodev: +mutex_lock (&kvm->slots_lock); +kvm_io_bus_unregister_dev (kvm,KVM_MMIO_BUS , &aplic->iodev); +mutex_unlock (&kvm->slots_lock); +fail_free_aplic_irqs: +kfree (aplic->irqs); +fail_free_aplic: + kvm->arch.aia.aplic_state =NULL ; +kfree (aplic); +return ret; +} + +void kvm_riscv_aia_aplic_cleanup (struct kvm *kvm) +{ +struct aplic *aplic = kvm->arch.aia.aplic_state; + +if (!aplic) +return ; + +mutex_lock (&kvm->slots_lock); +kvm_io_bus_unregister_dev (kvm,KVM_MMIO_BUS , &aplic->iodev); +mutex_unlock (&kvm->slots_lock); + +kfree (aplic->irqs); + + kvm->arch.aia.aplic_state =NULL ; +kfree (aplic); +} --
Quoted 2 lines
2.34.1
Signature · 2 lines
Regards, Atish
PATCH v3 8/10 RISC-V: KVM: Expose APLIC registers as attributes of AIA irqchip
In reply to Anup PatelWe expose APLIC registers as KVM device attributes of the in-kernel AIA irqchip device. This will allow KVM user-space to save/restore APLIC state using KVM device ioctls().
--- arch/riscv/include/asm/kvm_aia.h | 3 +++ arch/riscv/include/uapi/asm/kvm.h | 6 +++++ arch/riscv/kvm/aia_aplic.c | 43 +++++++++++++++++++++++++++++++ arch/riscv/kvm/aia_device.c | 25 ++++++++++++++++++ 4 files changed, 77 insertions(+)
arch/riscv/include/asm/kvm_aia.h +3 -0
@@ -129,6 +129,9 @@ static inline void kvm_riscv_vcpu_aia_imsic_cleanup(struct kvm_vcpu *vcpu) { } +int kvm_riscv_aia_aplic_set_attr (struct kvm *kvm,unsigned long type,u32 v); +int kvm_riscv_aia_aplic_get_attr (struct kvm *kvm,unsigned long type,u32 *v); +int kvm_riscv_aia_aplic_has_attr (struct kvm *kvm,unsigned long type);int kvm_riscv_aia_aplic_inject (struct kvm *kvm,u32 source,bool level);int kvm_riscv_aia_aplic_init (struct kvm *kvm);void kvm_riscv_aia_aplic_cleanup (struct kvm *kvm);
arch/riscv/include/uapi/asm/kvm.h +6 -0
@@ -249,6 +249,12 @@ enum KVM_RISCV_SBI_EXT_ID {#define KVM_DEV_RISCV_AIA_GRP_CTRL 2#define KVM_DEV_RISCV_AIA_CTRL_INIT 0 +/* +* The device attribute type contains the memory mapped offset of the +* APLIC register (range 0x0000-0x3FFF) and it must be 4-byte aligned. +*/ +#define KVM_DEV_RISCV_AIA_GRP_APLIC 3 +/* One single KVM irqchip, ie. the AIA */ #define KVM_NR_IRQCHIPS 1
arch/riscv/kvm/aia_aplic.c +43 -0
49 lines not on this page · raw message
arch/riscv/kvm/aia_device.c +25 -0
@@ -365,6 +365,15 @@ static int aia_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)break ; } +break ; +case KVM_DEV_RISCV_AIA_GRP_APLIC : +if (copy_from_user (&nr, uaddr,sizeof (nr))) +return -EFAULT ; + +mutex_lock (&dev->kvm->lock); + r =kvm_riscv_aia_aplic_set_attr (dev->kvm, type, nr); +mutex_unlock (&dev->kvm->lock); +break ; }
@@ -412,6 +421,20 @@ static int aia_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr)if (copy_to_user (uaddr, &addr,sizeof (addr)))return -EFAULT ; +break ; +case KVM_DEV_RISCV_AIA_GRP_APLIC : +if (copy_from_user (&nr, uaddr,sizeof (nr))) +return -EFAULT ; + +mutex_lock (&dev->kvm->lock); + r =kvm_riscv_aia_aplic_get_attr (dev->kvm, type, &nr); +mutex_unlock (&dev->kvm->lock); +if (r) +return r; + +if (copy_to_user (uaddr, &nr,sizeof (nr))) +return -EFAULT ; +break ; }
@@ -448,6 +471,8 @@ static int aia_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr)return 0 ; }break ; +case KVM_DEV_RISCV_AIA_GRP_APLIC : +return kvm_riscv_aia_aplic_has_attr (dev->kvm, attr->attr); }return -ENXIO ;
Signature · 1 line
2.34.1
Re: [PATCH v3 08/10] RISC-V: KVM: Expose APLIC registers as attributes of AIA irqchip
Quoted 149 lines · On Thu, Jun 15, 2023 at 12:34?AM Anup Patel <[email protected]> wrote:
We expose APLIC registers as KVM device attributes of the in-kernel AIA irqchip device. This will allow KVM user-space to save/restore APLIC state using KVM device
ioctls().Signed-off-by Anup Patel <[email protected]>--- arch/riscv/include/asm/kvm_aia.h | 3 +++ arch/riscv/include/uapi/asm/kvm.h | 6 +++++ arch/riscv/kvm/aia_aplic.c | 43 +++++++++++++++++++++++++++++++ arch/riscv/kvm/aia_device.c | 25 ++++++++++++++++++ 4 files changed, 77 insertions(+)arch/riscv/include/asm/kvm_aia.h +3
-0@@ -129,6 +129,9 @@ static inline void kvm_riscv_vcpu_aia_imsic_cleanup(struct kvm_vcpu *vcpu) { } +int kvm_riscv_aia_aplic_set_attr (struct kvm *kvm,unsigned long type,u32 v); +int kvm_riscv_aia_aplic_get_attr (struct kvm *kvm,unsigned long type,u32 *v); +int kvm_riscv_aia_aplic_has_attr (struct kvm *kvm,unsigned long type);int kvm_riscv_aia_aplic_inject (struct kvm *kvm,u32 source,bool level);int kvm_riscv_aia_aplic_init (struct kvm *kvm);void kvm_riscv_aia_aplic_cleanup (struct kvm *kvm);arch/riscv/include/uapi/asm/kvm.h +6
-0@@ -249,6 +249,12 @@ enum KVM_RISCV_SBI_EXT_ID {#define KVM_DEV_RISCV_AIA_GRP_CTRL 2#define KVM_DEV_RISCV_AIA_CTRL_INIT 0 +/* +* The device attribute type contains the memory mapped offset of the +* APLIC register (range 0x0000-0x3FFF) and it must be 4-byte aligned. +*/ +#define KVM_DEV_RISCV_AIA_GRP_APLIC 3 +/* One single KVM irqchip, ie. the AIA */ #define KVM_NR_IRQCHIPS 1arch/riscv/kvm/aia_aplic.c +43
-0@@ -501,6 +501,49 @@ static struct kvm_io_device_ops aplic_iodoev_ops = { .write = aplic_mmio_write, }; +int kvm_riscv_aia_aplic_set_attr (struct kvm *kvm,unsigned long type,u32 v) +{ +int rc; + +if (!kvm->arch.aia.aplic_state) +return -ENODEV ; + + rc =aplic_mmio_write_offset (kvm, type, v); +if (rc) +return rc; + +return 0 ; +} + +int kvm_riscv_aia_aplic_get_attr (struct kvm *kvm,unsigned long type,u32 *v) +{ +int rc; + +if (!kvm->arch.aia.aplic_state) +return -ENODEV ; + + rc =aplic_mmio_read_offset (kvm, type, v); +if (rc) +return rc; + +return 0 ; +} + +int kvm_riscv_aia_aplic_has_attr (struct kvm *kvm,unsigned long type) +{ +int rc; +u32 val; + +if (!kvm->arch.aia.aplic_state) +return -ENODEV ; + + rc =aplic_mmio_read_offset (kvm, type, &val); +if (rc) +return rc; + +return 0 ; +} +int kvm_riscv_aia_aplic_init (struct kvm *kvm) {int i, ret =0 ;arch/riscv/kvm/aia_device.c +25
-1@@ -365,6 +365,15 @@ static int aia_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)break ; } +break ; +case KVM_DEV_RISCV_AIA_GRP_APLIC : +if (copy_from_user (&nr, uaddr,sizeof (nr))) +return -EFAULT ; + +mutex_lock (&dev->kvm->lock); + r =kvm_riscv_aia_aplic_set_attr (dev->kvm, type, nr); +mutex_unlock (&dev->kvm->lock); +break ; }@@ -412,6 +421,20 @@ static int aia_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr)if (copy_to_user (uaddr, &addr,sizeof (addr)))return -EFAULT ; +break ; +case KVM_DEV_RISCV_AIA_GRP_APLIC : +if (copy_from_user (&nr, uaddr,sizeof (nr))) +return -EFAULT ; + +mutex_lock (&dev->kvm->lock); + r =kvm_riscv_aia_aplic_get_attr (dev->kvm, type, &nr); +mutex_unlock (&dev->kvm->lock); +if (r) +return r; + +if (copy_to_user (uaddr, &nr,sizeof (nr))) +return -EFAULT ; +break ; }@@ -448,6 +471,8 @@ static int aia_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr)return 0 ; }break ; +case KVM_DEV_RISCV_AIA_GRP_APLIC : +return kvm_riscv_aia_aplic_has_attr (dev->kvm, attr->attr); }return -ENXIO ; --
Quoted 2 lines
2.34.1
Signature · 2 lines
Regards, Atish
PATCH v3 9/10 RISC-V: KVM: Add in-kernel virtualization of AIA IMSIC
In reply to Anup PatelWe can have AIA IMSIC support for both HS-level and VS-level but the VS-level IMSICs are optional. We use the VS-level IMSICs for Guest/VM whenever available otherwise we fallback to software emulation of AIA IMSIC.
This patch adds in-kernel virtualization of AIA IMSIC.
--- arch/riscv/include/asm/kvm_aia.h | 46 +- arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/aia_imsic.c | 913 +++++++++++++++++++++++++++++++ 3 files changed, 924 insertions(+), 36 deletions(-) create mode 100644 arch/riscv/kvm/aia_imsic.c
arch/riscv/include/asm/kvm_aia.h +10 -36
@@ -90,44 +90,18 @@ DECLARE_STATIC_KEY_FALSE(kvm_riscv_aia_available);extern struct kvm_device_ops kvm_riscv_aia_device_ops; -static inline void kvm_riscv_vcpu_aia_imsic_release (struct kvm_vcpu *vcpu) -{ -} - -static inline int kvm_riscv_vcpu_aia_imsic_update (struct kvm_vcpu *vcpu) -{ -return 1 ; -} +void kvm_riscv_vcpu_aia_imsic_release (struct kvm_vcpu *vcpu); +int kvm_riscv_vcpu_aia_imsic_update (struct kvm_vcpu *vcpu);#define KVM_RISCV_AIA_IMSIC_TOPEI (ISELECT_MASK + 1) -static inline int kvm_riscv_vcpu_aia_imsic_rmw (struct kvm_vcpu *vcpu, -unsigned long isel, -unsigned long *val, -unsigned long new_val, -unsigned long wr_mask) -{ -return 0 ; -} - -static inline void kvm_riscv_vcpu_aia_imsic_reset (struct kvm_vcpu *vcpu) -{ -} - -static inline int kvm_riscv_vcpu_aia_imsic_inject (struct kvm_vcpu *vcpu, -u32 guest_index,u32 offset, -u32 iid) -{ -return 0 ; -} - -static inline int kvm_riscv_vcpu_aia_imsic_init (struct kvm_vcpu *vcpu) -{ -return 0 ; -} - -static inline void kvm_riscv_vcpu_aia_imsic_cleanup (struct kvm_vcpu *vcpu) -{ -} +int kvm_riscv_vcpu_aia_imsic_rmw (struct kvm_vcpu *vcpu,unsigned long isel, +unsigned long *val,unsigned long new_val, +unsigned long wr_mask); +void kvm_riscv_vcpu_aia_imsic_reset (struct kvm_vcpu *vcpu); +int kvm_riscv_vcpu_aia_imsic_inject (struct kvm_vcpu *vcpu, +u32 guest_index,u32 offset,u32 iid); +int kvm_riscv_vcpu_aia_imsic_init (struct kvm_vcpu *vcpu); +void kvm_riscv_vcpu_aia_imsic_cleanup (struct kvm_vcpu *vcpu);int kvm_riscv_aia_aplic_set_attr (struct kvm *kvm,unsigned long type,u32 v);int kvm_riscv_aia_aplic_get_attr (struct kvm *kvm,unsigned long type,u32 *v);
arch/riscv/kvm/Makefile +1 -0
@@ -29,3 +29,4 @@ kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_pmu.o vcpu_sbi_pmu.o kvm-y += aia.o kvm-y += aia_device.o kvm-y += aia_aplic.o +kvm-y += aia_imsic.o
arch/riscv/kvm/aia_imsic.c new file +913 -0
913 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 10/10 RISC-V: KVM: Expose IMSIC registers as attributes of AIA irqchip
In reply to Anup PatelWe expose IMSIC registers as KVM device attributes of the in-kernel AIA irqchip device. This will allow KVM user-space to save/restore IMISC state of each VCPU using KVM device ioctls().
--- arch/riscv/include/asm/kvm_aia.h | 3 + arch/riscv/include/uapi/asm/kvm.h | 17 +++ arch/riscv/kvm/aia_device.c | 29 ++++- arch/riscv/kvm/aia_imsic.c | 170 ++++++++++++++++++++++++++++++ 4 files changed, 217 insertions(+), 2 deletions(-)
arch/riscv/include/asm/kvm_aia.h +3 -0
@@ -97,6 +97,9 @@ int kvm_riscv_vcpu_aia_imsic_update(struct kvm_vcpu *vcpu);int kvm_riscv_vcpu_aia_imsic_rmw (struct kvm_vcpu *vcpu,unsigned long isel,unsigned long *val,unsigned long new_val,unsigned long wr_mask); +int kvm_riscv_aia_imsic_rw_attr (struct kvm *kvm,unsigned long type, +bool write,unsigned long *val); +int kvm_riscv_aia_imsic_has_attr (struct kvm *kvm,unsigned long type);void kvm_riscv_vcpu_aia_imsic_reset (struct kvm_vcpu *vcpu);int kvm_riscv_vcpu_aia_imsic_inject (struct kvm_vcpu *vcpu,u32 guest_index,u32 offset,u32 iid);
arch/riscv/include/uapi/asm/kvm.h +17 -0
@@ -255,6 +255,23 @@ enum KVM_RISCV_SBI_EXT_ID {*/ #define KVM_DEV_RISCV_AIA_GRP_APLIC 3 +/* +* The lower 12-bits of the device attribute type contains the iselect +* value of the IMSIC register (range 0x70-0xFF) whereas the higher order +* bits contains the VCPU id. +*/ +#define KVM_DEV_RISCV_AIA_GRP_IMSIC 4 +#define KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS 12 +#define KVM_DEV_RISCV_AIA_IMSIC_ISEL_MASK \ + ((1U << KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS) - 1) +#define KVM_DEV_RISCV_AIA_IMSIC_MKATTR (__vcpu, __isel) \ + (((__vcpu) << KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS) | \ + ((__isel) & KVM_DEV_RISCV_AIA_IMSIC_ISEL_MASK)) +#define KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL (__attr) \ + ((__attr) & KVM_DEV_RISCV_AIA_IMSIC_ISEL_MASK) +#define KVM_DEV_RISCV_AIA_IMSIC_GET_VCPU (__attr) \ + ((__attr) >> KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS) +/* One single KVM irqchip, ie. the AIA */ #define KVM_NR_IRQCHIPS 1
arch/riscv/kvm/aia_device.c +27 -2
@@ -327,7 +327,7 @@ static int aia_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)u32 nr;u64 addr;int nr_vcpus, r = -ENXIO ; -unsigned long type = (unsigned long )attr->attr; +unsigned long v, type = (unsigned long )attr->attr;void __user *uaddr = (void __user *)(long )attr->addr;switch (attr->group) {
@@ -374,6 +374,15 @@ static int aia_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr) r =kvm_riscv_aia_aplic_set_attr (dev->kvm, type, nr);mutex_unlock (&dev->kvm->lock); +break ; +case KVM_DEV_RISCV_AIA_GRP_IMSIC : +if (copy_from_user (&v, uaddr,sizeof (v))) +return -EFAULT ; + +mutex_lock (&dev->kvm->lock); + r =kvm_riscv_aia_imsic_rw_attr (dev->kvm, type, true, &v); +mutex_unlock (&dev->kvm->lock); +break ; }
@@ -386,7 +395,7 @@ static int aia_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr)u64 addr;int nr_vcpus, r = -ENXIO ;void __user *uaddr = (void __user *)(long )attr->addr; -unsigned long type = (unsigned long )attr->attr; +unsigned long v, type = (unsigned long )attr->attr;switch (attr->group) {case KVM_DEV_RISCV_AIA_GRP_CONFIG :
@@ -435,6 +444,20 @@ static int aia_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr)if (copy_to_user (uaddr, &nr,sizeof (nr)))return -EFAULT ; +break ; +case KVM_DEV_RISCV_AIA_GRP_IMSIC : +if (copy_from_user (&v, uaddr,sizeof (v))) +return -EFAULT ; + +mutex_lock (&dev->kvm->lock); + r =kvm_riscv_aia_imsic_rw_attr (dev->kvm, type, false, &v); +mutex_unlock (&dev->kvm->lock); +if (r) +return r; + +if (copy_to_user (uaddr, &v,sizeof (v))) +return -EFAULT ; +break ; }
@@ -473,6 +496,8 @@ static int aia_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr)break ;case KVM_DEV_RISCV_AIA_GRP_APLIC :return kvm_riscv_aia_aplic_has_attr (dev->kvm, attr->attr); +case KVM_DEV_RISCV_AIA_GRP_IMSIC : +return kvm_riscv_aia_imsic_has_attr (dev->kvm, attr->attr); }return -ENXIO ;
arch/riscv/kvm/aia_imsic.c +170 -0
188 lines not on this page · raw message
Signature · 1 line
2.34.1
Anup Patel
maintainerQuoted 27 lines · On Thu, Jun 15, 2023 at 1:04?PM Anup Patel <[email protected]> wrote:
This series adds in-kernel AIA irqchip to KVM RISC-V which trap-n-emulate IMSIC and APLIC MSI-mode for Guest. The APLIC MSI-mode trap-n-emulate is optional so KVM user space can emulate APLIC entirely in user space.
The use of IMSIC HW guest files to accelerate IMSIC virtualization will be done as separate series since this depends on AIA irqchip drivers to be upstreamed. This series has no dependency on the AIA irqchip drivers.
There is also a KVM AIA irq-bypass (or device MSI virtualization) series under development which depends on this series and upcoming IOMMU driver series.
These patches (or this series) can also be found in the
riscv_kvm_aia_irqchip_v3branch at: https://github.com/avpatel/linux.gitChanges since v2:
- AddedKVM_CAP_IRQCHIPin PATCH5
- Fix check forKVM_DEV_RISCV_AIA_CONFIG_IDSwrite in PATCH6
- FixAPLIC_IRQ_STATE_ENPENDusage in PATCH7Changes since v1:
- Rebased on Linux-6.4-rc6
- Addressed Atish's comment in PATCH6
- Added comments inarch/riscv/include/uapi/asm/kvm.habout APLIC and IMSIC device attribute type
Quoted 11 lines
Anup Patel (10):
RISC-V: KVM: Implement guest external interrupt line management
RISC-V: KVM: Add IMSIC related defines
RISC-V: KVM: Add APLIC related defines
RISC-V: KVM: Setkvm_riscv_aia_nr_hgeito zero
RISC-V: KVM: Skeletal in-kernel AIA irqchip support
RISC-V: KVM: Implement device interface for AIA irqchip
RISC-V: KVM: Add in-kernel emulation of AIA APLIC
RISC-V: KVM: Expose APLIC registers as attributes of AIA irqchip
RISC-V: KVM: Add in-kernel virtualization of AIA IMSIC
RISC-V: KVM: Expose IMSIC registers as attributes of AIA irqchip
Queued this series for 6.5
Regards,
Anup
Quoted 31 lines
arch/riscv/include/asm/kvm_aia.h | 107 ++- arch/riscv/include/asm/kvm_aia_aplic.h | 58 ++ arch/riscv/include/asm/kvm_aia_imsic.h | 38 + arch/riscv/include/asm/kvm_host.h | 4 + arch/riscv/include/uapi/asm/kvm.h | 72 ++ arch/riscv/kvm/Kconfig | 4 + arch/riscv/kvm/Makefile | 3 + arch/riscv/kvm/aia.c | 274 +++++- arch/riscv/kvm/aia_aplic.c | 619 ++++++++++++++ arch/riscv/kvm/aia_device.c | 673 +++++++++++++++ arch/riscv/kvm/aia_imsic.c | 1083 ++++++++++++++++++++++++ arch/riscv/kvm/main.c | 3 +- arch/riscv/kvm/vcpu.c | 2 + arch/riscv/kvm/vm.c | 118 +++ include/uapi/linux/kvm.h | 2 + 15 files changed, 3027 insertions(+), 33 deletions(-) create mode 100644 arch/riscv/include/asm/kvm_aia_aplic.h create mode 100644 arch/riscv/include/asm/kvm_aia_imsic.h create mode 100644 arch/riscv/kvm/aia_aplic.c create mode 100644 arch/riscv/kvm/aia_device.c create mode 100644 arch/riscv/kvm/aia_imsic.c--
2.34.1--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv