Skip to content

Added Interrupt controller emulation for loongarch kvm

Xianglai Li kvm lkml loongarch 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest11 patches 1 replyIn review
  2. v2 RFC posting 2/25 patches 6 repliesSuperseded
  3. v311 patches 1 replySuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v2 posting 1/210 patches1 replySuperseded
v1 RFC4 patches1 replySuperseded

Changes in v4 from the cover letter

1.Fix some macro definition names and some formatting errors
2.Combine the IPI two device address Spaces into one address device space
3.Optimize the function kvm_vm_ioctl_irq_line implementation, directly call the public function kvm_set_irq for interrupt distribution 4.Optimize the description of the commit log
5.Deleting an interface trace_kvm_iocsr

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11LoongArch: KVM: Add iocsr and mmio bus simulation in kernelarch/loongarch/kvm/exit.c include/linux/kvm_host.h+56 -250 replies
2/11LoongArch: KVM: Add IPI device supportarch/loongarch/include/asm/kvm_host.h arch/loongarch/include/asm/kvm_ipi.h arch/loongarch/kvm/Makefile +4 more+163 -20 replies
3/11LoongArch: KVM: Add IPI read and write functionarch/loongarch/include/asm/kvm_host.h arch/loongarch/include/asm/kvm_ipi.h arch/loongarch/kvm/intc/ipi.c+285 -20 replies
4/11LoongArch: KVM: Add IPI user mode read and write functionarch/loongarch/include/uapi/asm/kvm.h arch/loongarch/kvm/intc/ipi.c+90 -20 replies
5/11LoongArch: KVM: Add EIOINTC device supportarch/loongarch/include/asm/kvm_eiointc.h arch/loongarch/include/asm/kvm_host.h arch/loongarch/kvm/Makefile +3 more+234 -10 replies
6/11LoongArch: KVM: Add EIOINTC read and write functionsarch/loongarch/include/asm/kvm_eiointc.h arch/loongarch/include/asm/kvm_host.h arch/loongarch/kvm/intc/eiointc.c+788 -50 replies
7/11LoongArch: KVM: Add EIOINTC user mode read and write functionsarch/loongarch/include/uapi/asm/kvm.h arch/loongarch/kvm/intc/eiointc.c+188 -20 replies
8/11LoongArch: KVM: Add PCHPIC device supportarch/loongarch/include/asm/kvm_host.h arch/loongarch/include/asm/kvm_pch_pic.h arch/loongarch/kvm/Makefile +3 more+130 -00 replies
9/11LoongArch: KVM: Add PCHPIC read and write functionsarch/loongarch/include/asm/kvm_host.h arch/loongarch/include/asm/kvm_pch_pic.h arch/loongarch/include/uapi/asm/kvm.h +2 more+336 -20 replies
10/11LoongArch: KVM: Add PCHPIC user mode read and write functionsarch/loongarch/include/uapi/asm/kvm.h arch/loongarch/kvm/intc/pch_pic.c+128 -20 replies
11/11LoongArch: KVM: Add irqfd supportarch/loongarch/include/asm/kvm_host.h arch/loongarch/kvm/Kconfig arch/loongarch/kvm/Makefile +3 more+139 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH V4 00/11] Added Interrupt controller emulation for loongarch kvm

Before this, the interrupt controller simulation has been completed in the user mode program. In order to reduce the loss caused by frequent switching of the virtual machine monitor from kernel mode to user mode when the guest accesses the interrupt controller, we add the interrupt controller simulation in kvm.

The following is a virtual machine simulation diagram of interrupted connections:

  +-----+    +---------+     +-------+
  | IPI |--> | CPUINTC | <-- | Timer |
  +-----+    +---------+     +-------+
                 ^
                 |
           +---------+
           | EIOINTC |
           +---------+
            ^       ^
            |       |
     +---------+ +---------+
     | PCH-PIC | | PCH-MSI |
     +---------+ +---------+
       ^      ^          ^
       |      |          |
+--------+ +---------+ +---------+
| UARTs  | | Devices | | Devices |
+--------+ +---------+ +---------+

In this series of patches, we mainly realized the simulation of IPI EIOINTC PCH-PIC interrupt controller.

The simulation of IPI EIOINTC PCH-PIC interrupt controller mainly completes the creation simulation of the interrupt controller, the register address space read and write simulation, and the interface with user mode to obtain and set the interrupt controller state for the preservation,
recovery and migration of virtual machines.

IPI simulation implementation reference:
https://github.com/loongson/LoongArch-Documentation/tree/main/docs/Loongson-3A5000-usermanual-EN/inter-processor-interrupts-and-communication

EIOINTC simulation implementation reference:
https://github.com/loongson/LoongArch-Documentation/tree/main/docs/Loongson-3A5000-usermanual-EN/io-interrupts/extended-io-interrupts

PCH-PIC simulation implementation reference:
https://github.com/loongson/LoongArch-Documentation/blob/main/docs/Loongson-7A1000-usermanual-EN/interrupt-controller.adoc

For PCH-MSI, we used irqfd mechanism to send the interrupt signal generated by user state to kernel state and then to EIOINTC without maintaining PCH-MSI state in kernel state.

You can easily get the code from the link below:
the kernel:
https://github.com/lixianglai/linux
the branch is: interrupt-v4

the qemu:
https://github.com/lixianglai/qemu
the branch is: interrupt-v3

Please note that the code above is regularly updated based on community reviews.

change log:
V3->V4:
1.Fix some macro definition names and some formatting errors
2.Combine the IPI two device address Spaces into one address device space
3.Optimize the function kvm_vm_ioctl_irq_line implementation, directly call the public function kvm_set_irq for interrupt distribution 4.Optimize the description of the commit log
5.Deleting an interface trace_kvm_iocsr

V2->V3:
1.Modify the macro definition name:
KVM_DEV_TYPE_LA_* -> KVM_DEV_TYPE_LOONGARCH_*
2.Change the short name for "Extended I/O Interrupt Controller" from EXTIOI to EIOINTC Rename file extioi.c to eiointc.c
Rename file extioi.h to eiointc.h

V1->V2:
1.Remove redundant blank lines according to community comments 2.Remove simplified redundant code
3.Adds 16 bits of read/write interface to the eiointc iocsr address space 4.Optimize user - and kernel-mode data access interfaces: Access fixed length data each time to prevent memory overruns
5.Added virtual eiointc, where interrupts can be routed to cpus other than cpu 4

Cc Bibo Mao <[email protected]>
Cc Huacai Chen <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Tianrui Zhao <[email protected]>
Cc WANG Xuerui <[email protected]>
Cc Xianglai li <[email protected]>

Xianglai Li (11):
LoongArch: KVM: Add iocsr and mmio bus simulation in kernel
LoongArch: KVM: Add IPI device support
LoongArch: KVM: Add IPI read and write function
LoongArch: KVM: Add IPI user mode read and write function
LoongArch: KVM: Add EIOINTC device support
LoongArch: KVM: Add EIOINTC read and write functions
LoongArch: KVM: Add EIOINTC user mode read and write functions
LoongArch: KVM: Add PCHPIC device support
LoongArch: KVM: Add PCHPIC read and write functions
LoongArch: KVM: Add PCHPIC user mode read and write functions
LoongArch: KVM: Add irqfd support

 arch/loongarch/include/asm/kvm_eiointc.h |  122 +++
 arch/loongarch/include/asm/kvm_host.h    |   18 +-
 arch/loongarch/include/asm/kvm_ipi.h     |   46 +
 arch/loongarch/include/asm/kvm_pch_pic.h |   61 ++
 arch/loongarch/include/uapi/asm/kvm.h    |   19 +
 arch/loongarch/kvm/Kconfig               |    5 +-
 arch/loongarch/kvm/Makefile              |    4 +
 arch/loongarch/kvm/exit.c                |   80 +-
 arch/loongarch/kvm/intc/eiointc.c        | 1055 ++++++++++++++++++++++
 arch/loongarch/kvm/intc/ipi.c            |  468 ++++++++++
 arch/loongarch/kvm/intc/pch_pic.c        |  523 +++++++++++
 arch/loongarch/kvm/irqfd.c               |   97 ++
 arch/loongarch/kvm/main.c                |   19 +-
 arch/loongarch/kvm/vcpu.c                |    3 +
 arch/loongarch/kvm/vm.c                  |   22 +
 include/linux/kvm_host.h                 |    1 +
 include/uapi/linux/kvm.h                 |    8 +
 17 files changed, 2522 insertions(+), 29 deletions(-)
 create mode 100644 arch/loongarch/include/asm/kvm_eiointc.h
 create mode 100644 arch/loongarch/include/asm/kvm_ipi.h
 create mode 100644 arch/loongarch/include/asm/kvm_pch_pic.h
 create mode 100644 arch/loongarch/kvm/intc/eiointc.c
 create mode 100644 arch/loongarch/kvm/intc/ipi.c
 create mode 100644 arch/loongarch/kvm/intc/pch_pic.c
 create mode 100644 arch/loongarch/kvm/irqfd.c

base-commit: 906bd684e4b1e517dd424a354744c5b0aebef8af

Signature · 1 line
2.39.1