mbox series

[[PATCH,V2,00/10] Added Interrupt controller emulation for loongarch kvm

Message ID 20240823093404.204450-1-lixianglai@loongson.cn (mailing list archive)
Headers show
Series Added Interrupt controller emulation for loongarch kvm | expand

Message

lixianglai Aug. 23, 2024, 9:33 a.m. UTC
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 EXTIOI PCH-PIC interrupt controller.

The simulation of IPI EXTIOI 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

EXTIOI 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 EXTIOI 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

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

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

change log:
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 extioi 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 extioi, where interrupts can be routed to cpus other than cpu 4

Cc: Bibo Mao <maobibo@loongson.cn> 
Cc: Huacai Chen <chenhuacai@kernel.org> 
Cc: kvm@vger.kernel.org 
Cc: loongarch@lists.linux.dev 
Cc: Paolo Bonzini <pbonzini@redhat.com> 
Cc: Tianrui Zhao <zhaotianrui@loongson.cn> 
Cc: WANG Xuerui <kernel@xen0n.name> 
Cc: Xianglai li <lixianglai@loongson.cn> 

Xianglai Li (10):
  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 EXTIOI device support
  LoongArch: KVM: Add EXTIOI 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_extioi.h  |  122 +++
 arch/loongarch/include/asm/kvm_host.h    |   30 +
 arch/loongarch/include/asm/kvm_ipi.h     |   52 ++
 arch/loongarch/include/asm/kvm_pch_pic.h |   61 ++
 arch/loongarch/include/uapi/asm/kvm.h    |   19 +
 arch/loongarch/kvm/Kconfig               |    3 +
 arch/loongarch/kvm/Makefile              |    4 +
 arch/loongarch/kvm/exit.c                |   86 +-
 arch/loongarch/kvm/intc/extioi.c         | 1056 ++++++++++++++++++++++
 arch/loongarch/kvm/intc/ipi.c            |  510 +++++++++++
 arch/loongarch/kvm/intc/pch_pic.c        |  521 +++++++++++
 arch/loongarch/kvm/irqfd.c               |   87 ++
 arch/loongarch/kvm/main.c                |   18 +-
 arch/loongarch/kvm/vcpu.c                |    3 +
 arch/loongarch/kvm/vm.c                  |   53 +-
 include/linux/kvm_host.h                 |    1 +
 include/trace/events/kvm.h               |   35 +
 include/uapi/linux/kvm.h                 |    8 +
 18 files changed, 2641 insertions(+), 28 deletions(-)
 create mode 100644 arch/loongarch/include/asm/kvm_extioi.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/extioi.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: 872cf28b8df9c5c3a1e71a88ee750df7c2513971

Comments

Huacai Chen Sept. 7, 2024, 7:56 a.m. UTC | #1
Hi, Xianglai,

This series is good as a whole, just some naming issues.
1, In the current kernel the short name of "Extended I/O Interrupt
Controller" is eiointc, so please change related prefix from extioi_
to eiointc.

And for

  KVM_DEV_TYPE_LA_IOAPIC,
  KVM_DEV_TYPE_LA_IPI,
  KVM_DEV_TYPE_LA_EXTIOI,

Please use

  KVM_DEV_TYPE_LOONGARCH_IPI,
  KVM_DEV_TYPE_LOONGARCH_EXTIOI,
  KVM_DEV_TYPE_LOONGARCH_PCHPIC,

instead.

Huacai

On Fri, Aug 23, 2024 at 5:51 PM Xianglai Li <lixianglai@loongson.cn> wrote:
>
> 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 EXTIOI PCH-PIC interrupt controller.
>
> The simulation of IPI EXTIOI 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
>
> EXTIOI 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 EXTIOI 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
>
> the qemu:
> https://github.com/lixianglai/qemu
> the branch is: interrupt
>
> Please note that the code above is regularly updated based on community
> reviews.
>
> change log:
> 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 extioi 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 extioi, where interrupts can be routed to cpus other than cpu 4
>
> Cc: Bibo Mao <maobibo@loongson.cn>
> Cc: Huacai Chen <chenhuacai@kernel.org>
> Cc: kvm@vger.kernel.org
> Cc: loongarch@lists.linux.dev
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Tianrui Zhao <zhaotianrui@loongson.cn>
> Cc: WANG Xuerui <kernel@xen0n.name>
> Cc: Xianglai li <lixianglai@loongson.cn>
>
> Xianglai Li (10):
>   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 EXTIOI device support
>   LoongArch: KVM: Add EXTIOI 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_extioi.h  |  122 +++
>  arch/loongarch/include/asm/kvm_host.h    |   30 +
>  arch/loongarch/include/asm/kvm_ipi.h     |   52 ++
>  arch/loongarch/include/asm/kvm_pch_pic.h |   61 ++
>  arch/loongarch/include/uapi/asm/kvm.h    |   19 +
>  arch/loongarch/kvm/Kconfig               |    3 +
>  arch/loongarch/kvm/Makefile              |    4 +
>  arch/loongarch/kvm/exit.c                |   86 +-
>  arch/loongarch/kvm/intc/extioi.c         | 1056 ++++++++++++++++++++++
>  arch/loongarch/kvm/intc/ipi.c            |  510 +++++++++++
>  arch/loongarch/kvm/intc/pch_pic.c        |  521 +++++++++++
>  arch/loongarch/kvm/irqfd.c               |   87 ++
>  arch/loongarch/kvm/main.c                |   18 +-
>  arch/loongarch/kvm/vcpu.c                |    3 +
>  arch/loongarch/kvm/vm.c                  |   53 +-
>  include/linux/kvm_host.h                 |    1 +
>  include/trace/events/kvm.h               |   35 +
>  include/uapi/linux/kvm.h                 |    8 +
>  18 files changed, 2641 insertions(+), 28 deletions(-)
>  create mode 100644 arch/loongarch/include/asm/kvm_extioi.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/extioi.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: 872cf28b8df9c5c3a1e71a88ee750df7c2513971
> --
> 2.39.1
>