GenieZone hypervisor drivers
Subsystems (4)
v4 cover GenieZone hypervisor drivers
This series is based on linux-next, tag: next-20230608.
GenieZone hypervisor(gzvm) is a type-1 hypervisor that supports various virtual machine types and provides security features such as TEE-like scenarios and secure boot. It can create guest VMs for security use cases and has virtualization capabilities for both platform and interrupt. Although the hypervisor can be booted independently, it requires the assistance of GenieZone hypervisor kernel driver(gzvm-ko) to leverage the ability of Linux kernel for vCPU scheduling, memory management, inter-VM communication and virtio backend support.
Changes in v4:
- Add macro to set VM as protected without triggering pvmfw in AVF.
- Add support to pass dtb config to hypervisor.
- Add support for virtual timer.
- Add UAPI to pass memory region metadata to hypervisor.
- Define our own macros for ARM's interrupt number
- Elaborate more on GenieZone hyperivsor in documentation
- Fix coding style.
- Implement our own module for coverting ipa to pa
- Modify the way of initializing device from dt to a more discoverable way
- Move refactoring changes into indepedent patches.
Changes in v3:
https://lore.kernel.org/all/[email protected]/
- Refactor: separate arch/arm64/geniezone/gzvm_arch.c into vm.c/vcpu.c/vgic.c
- Remove redundant functions
- Fix reviewer's comments
Changes in v2:
https://lore.kernel.org/all/[email protected]/
- Refactor: move to drivers/virt/geniezone
- Refactor: decouple arch-dependent and arch-independent
- Check pending signal before entering guest context
- Fix reviewer's comments
Initial Commit in v1:
https://lore.kernel.org/all/[email protected]/
Yi-De Wu (9):
docs: geniezone: Introduce GenieZone hypervisor
virt: geniezone: Add GenieZone hypervisor support
virt: geniezone: Add vcpu support
virt: geniezone: Add irqchip support for virtual interrupt injection
virt: geniezone: Add irqfd support
virt: geniezone: Add ioeventfd support
virt: geniezone: Add memory region support
virt: geniezone: Add dtb config support
virt: geniezone: Add virtual timer support
Documentation/virt/geniezone/introduction.rst | 79 +++ MAINTAINERS | 12 + arch/arm64/Kbuild | 1 + arch/arm64/geniezone/Makefile | 9 + arch/arm64/geniezone/gzvm_arch_common.h | 101 ++++ arch/arm64/geniezone/vcpu.c | 124 ++++ arch/arm64/geniezone/vgic.c | 89 +++ arch/arm64/geniezone/vm.c | 218 +++++++ arch/arm64/include/uapi/asm/gzvm_arch.h | 53 ++ drivers/virt/Kconfig | 2 + drivers/virt/geniezone/Kconfig | 16 + drivers/virt/geniezone/Makefile | 11 + drivers/virt/geniezone/gzvm_common.h | 12 + drivers/virt/geniezone/gzvm_ioeventfd.c | 263 +++++++++ drivers/virt/geniezone/gzvm_irqchip.c | 13 + drivers/virt/geniezone/gzvm_irqfd.c | 537 ++++++++++++++++++ drivers/virt/geniezone/gzvm_main.c | 142 +++++ drivers/virt/geniezone/gzvm_vcpu.c | 294 ++++++++++ drivers/virt/geniezone/gzvm_vm.c | 526 +++++++++++++++++ include/linux/gzvm_drv.h | 168 ++++++ include/uapi/asm-generic/Kbuild | 1 + include/uapi/asm-generic/gzvm_arch.h | 10 + include/uapi/linux/gzvm.h | 280 +++++++++ 23 files changed, 2961 insertions(+) create mode 100644 Documentation/virt/geniezone/introduction.rst create mode 100644 arch/arm64/geniezone/Makefile create mode 100644 arch/arm64/geniezone/gzvm_arch_common.h create mode 100644 arch/arm64/geniezone/vcpu.c create mode 100644 arch/arm64/geniezone/vgic.c create mode 100644 arch/arm64/geniezone/vm.c create mode 100644 arch/arm64/include/uapi/asm/gzvm_arch.h create mode 100644 drivers/virt/geniezone/Kconfig create mode 100644 drivers/virt/geniezone/Makefile create mode 100644 drivers/virt/geniezone/gzvm_common.h create mode 100644 drivers/virt/geniezone/gzvm_ioeventfd.c create mode 100644 drivers/virt/geniezone/gzvm_irqchip.c create mode 100644 drivers/virt/geniezone/gzvm_irqfd.c create mode 100644 drivers/virt/geniezone/gzvm_main.c create mode 100644 drivers/virt/geniezone/gzvm_vcpu.c create mode 100644 drivers/virt/geniezone/gzvm_vm.c create mode 100644 include/linux/gzvm_drv.h create mode 100644 include/uapi/asm-generic/gzvm_arch.h create mode 100644 include/uapi/linux/gzvm.h
Signature · 1 line
2.18.0
PATCH v4 1/9 docs: geniezone: Introduce GenieZone hypervisor
From: "Yi-De Wu" <[email protected]>
GenieZone is MediaTek proprietary hypervisor solution, and it is running in EL2 stand alone as a type-I hypervisor. It is a pure EL2 implementation which implies it does not rely any specific host VM, and this behavior improves GenieZone's security as it limits its interface.
--- Documentation/virt/geniezone/introduction.rst | 79 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 85 insertions(+) create mode 100644 Documentation/virt/geniezone/introduction.rst
Documentation/virt/geniezone/introduction.rst new file +79 -0
@@ -0,0 +1,79 @@ +.. SPDX-License-Identifier: GPL-2.0 + +====================== +GenieZone Introduction +====================== + +Overview +======== + +GenieZone hypervisor(gzvm) is a type-1 hypervisor that supports various virtual +machine types and provides security features such as TEE-like scenarios and +secure boot. It can create guest VMs for security use cases and has +virtualization capabilities for both platform and interrupt. Although the +hypervisor can be booted independently, it requires the assistance of GenieZone +hypervisor kernel driver(gzvm-ko) to leverage the ability of Linux kernel for +vCPU scheduling, memory management, inter-VM communication and virtio backend +support. + +Supported Architecture +====================== + +GenieZone now only supports MediaTek ARM64 SoC. + +Features +======== + +- vCPU Management +VM manager aims to provide vCPUs on the basis of time sharing on physical CPUs. +It requires Linux kernel in host VM for vCPU scheduling and VM power management. + +- Memory Management +Direct use of physical memory from VMs is forbidden and designed to be dictated +to the privilege models managed by GenieZone hypervisor for security reason. +With the help of gzvm-ko, the hypervisor would be able to manipulate memory as +objects. + +- Virtual Platform +We manage to emulate a virtual mobile platform for guest OS running on guest +VM. The platform supports various architecture-defined devices, such as +virtual virtual arch timer, GIC, MMIO, PSCI, and exception watching...etc. + +- Inter-VM Communication +Communication among guest VMs was provided mainly on RPC. More communication +mechanisms were to be provided in the future based on VirtIO-vsock. + +- Device Virtualization +The solution is provided using the well-known VirtIO. The gzvm-ko would +redirect MMIO traps back to VMM where the virtual devices are mostly emulated. +Ioeventfd is implemented using eventfd for signaling host VM that some IO +events in guest VMs need to be processed. + +- Interrupt virtualization +All Interrupts during some guest VMs running would be handled by GenieZone +hypervisor with the help of gzvm-ko, both virtual and physical ones. In case +there's no guest VM running out there, physical interrupts would be handled by +host VM directly for performance reason. Irqfd is also implemented using +eventfd for accepting vIRQ requests in gzvm-ko. + +Platform architecture component +=============================== + +- vm +The vm component is responsible for setting up the capability and memory +management for the protected VMs. The capability is mainly about the lifecycle +control and boot context initialization. And the memory management is highly +integrated with ARM 2-stage translation tables to convert VA to IPA to PA under +proper security measures required by protected VMs. + +- vcpu +The vcpu component is the core of virtualizing aarch64 physical CPU runnable, +and it controls the vCPU lifecycle including creating, running and destroying. +With self-defined exit handler, the vm component would be able to act +accordingly before terminated. + +- vgic +The vgic component exposes control interfaces to Linux kernel via irqchip, and +we intend to support all SPI, PPI, and SGI. When it comes to virtual +interrupts, the GenieZone hypervisor would write to list registers and trigger +vIRQ injection in guest VMs via GIC.
MAINTAINERS +6 -0
@@ -8745,6 +8745,12 @@ F: include/vdso/ F: kernel/time/vsyscall.c F: lib/vdso/ +GENIEZONE HYPERVISOR DRIVER +M: Yingshiuan Pan <[email protected]> +M: Ze-Yu Wang <[email protected]> +M: Yi-De Wu <[email protected]> +F: Documentation/virt/geniezone/ + GENWQE (IBM Generic Workqueue Card) M: Frank Haverkamp <[email protected]> S: Supported
Signature · 1 line
2.18.0
kernel test robot
build botRe: [PATCH v4 1/9] docs: geniezone: Introduce GenieZone hypervisor
kernel test robot noticed the following build warnings:
Hi Yi-De,
kernel test robot noticed the following build warnings:
[auto build test WARNING on arm64/for-next/core]
[also build test WARNING on arnd-asm-generic/master lwn/docs-next linus/master v6.4-rc6 next-20230615] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yi-De-Wu/docs-geniezone-Introduce-GenieZone-hypervisor/20230609-165552 base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core patch link: https://lore.kernel.org/r/20230609085214.31071-2-yi-de.wu%40mediatek.com patch subject: [PATCH v4 1/9] docs: geniezone: Introduce GenieZone hypervisor
reproduce:
git remote add arm64 https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
git fetch arm64 for-next/core
git checkout arm64/for-next/core
b4 shazam https://lore.kernel.org/r/[email protected]
make menuconfig
# enable CONFIG_COMPILE_TEST, CONFIG_WARN_MISSING_DOCUMENTS, CONFIG_WARN_ABI_ERRORS make htmldocs
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> Documentation/virt/geniezone/introduction.rst:28: WARNING: Bullet list ends without a blank line; unexpected unindent. >> Documentation/virt/geniezone/introduction.rst: WARNING: document isn't included in any toctree
vim +28 Documentation/virt/geniezone/introduction.rst
26
27 - vCPU Management
> 28 VM manager aims to provide vCPUs on the basis of time sharing on physical CPUs.
29 It requires Linux kernel in host VM for vCPU scheduling and VM power management.
30
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v4 2/9 virt: geniezone: Add GenieZone hypervisor support
In reply to Yi-De WuFrom: "Yingshiuan Pan" <[email protected]>
GenieZone is MediaTek hypervisor solution, and it is running in EL2 stand alone as a type-I hypervisor. This patch exports a set of ioctl interfaces for userspace VMM (e.g., crosvm) to operate guest VMs lifecycle (creation and destroy) on GenieZone.
--- MAINTAINERS | 6 + arch/arm64/Kbuild | 1 + arch/arm64/geniezone/Makefile | 9 + arch/arm64/geniezone/gzvm_arch_common.h | 70 +++++ arch/arm64/geniezone/vm.c | 201 ++++++++++++ arch/arm64/include/uapi/asm/gzvm_arch.h | 20 ++ drivers/virt/Kconfig | 2 + drivers/virt/geniezone/Kconfig | 16 + drivers/virt/geniezone/Makefile | 10 + drivers/virt/geniezone/gzvm_main.c | 141 +++++++++ drivers/virt/geniezone/gzvm_vm.c | 390 ++++++++++++++++++++++++ include/linux/gzvm_drv.h | 95 ++++++ include/uapi/asm-generic/Kbuild | 1 + include/uapi/asm-generic/gzvm_arch.h | 10 + include/uapi/linux/gzvm.h | 73 +++++ 15 files changed, 1045 insertions(+) create mode 100644 arch/arm64/geniezone/Makefile create mode 100644 arch/arm64/geniezone/gzvm_arch_common.h create mode 100644 arch/arm64/geniezone/vm.c create mode 100644 arch/arm64/include/uapi/asm/gzvm_arch.h create mode 100644 drivers/virt/geniezone/Kconfig create mode 100644 drivers/virt/geniezone/Makefile create mode 100644 drivers/virt/geniezone/gzvm_main.c create mode 100644 drivers/virt/geniezone/gzvm_vm.c create mode 100644 include/linux/gzvm_drv.h create mode 100644 include/uapi/asm-generic/gzvm_arch.h create mode 100644 include/uapi/linux/gzvm.h
MAINTAINERS +6 -0
@@ -8750,6 +8750,12 @@ M: Yingshiuan Pan <[email protected]> M: Ze-Yu Wang <[email protected]> M: Yi-De Wu <[email protected]> F: Documentation/virt/geniezone/ +F: arch/arm64/geniezone/ +F: arch/arm64/include/uapi/asm/gzvm_arch.h +F: drivers/virt/geniezone/ +F: include/linux/gzvm_drv.h +F include/uapi/asm-generic/gzvm_arch.h +F: include/uapi/linux/gzvm.h GENWQE (IBM Generic Workqueue Card) M: Frank Haverkamp <[email protected]>
arch/arm64/Kbuild +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_KVM) += kvm/ obj-$(CONFIG_XEN) += xen/ obj-$(subst m,y,$(CONFIG_HYPERV)) += hyperv/ obj-$(CONFIG_CRYPTO) += crypto/ +obj-$(CONFIG_MTK_GZVM) += geniezone/ # for cleaning subdir- += boot
arch/arm64/geniezone/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Main Makefile for gzvm, this one includes drivers/virt/geniezone/Makefile +# +include $(srctree)/drivers/virt/geniezone/Makefile + +gzvm-y += vm.o + +obj-$(CONFIG_MTK_GZVM) += gzvm.o
arch/arm64/geniezone/gzvm_arch_common.h new file +70 -0
70 lines not on this page · raw message
arch/arm64/geniezone/vm.c new file +201 -0
201 lines not on this page · raw message
arch/arm64/include/uapi/asm/gzvm_arch.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (c) 2023 MediaTek Inc. +*/ + +#ifndef __GZVM_ARCH_H__ +#define __GZVM_ARCH_H__ + +#include <linux/types.h> + +#define GZVM_CAP_ARM_VM_IPA_SIZE 165 +#define GZVM_CAP_ARM_PROTECTED_VM 0xffbadab1 + +/* sub-commands put in args[0] for GZVM_CAP_ARM_PROTECTED_VM */ +#define GZVM_CAP_ARM_PVM_SET_PVMFW_IPA 0 +#define GZVM_CAP_ARM_PVM_GET_PVMFW_SIZE 1 +/* GZVM_CAP_ARM_PVM_SET_PROTECTED_VM only sets protected but not load pvmfw */ +#define GZVM_CAP_ARM_PVM_SET_PROTECTED_VM 2 + +#endif /* __GZVM_ARCH_H__ */
drivers/virt/Kconfig +2 -0
@@ -54,4 +54,6 @@ source "drivers/virt/coco/sev-guest/Kconfig" source "drivers/virt/coco/tdx-guest/Kconfig" +source "drivers/virt/geniezone/Kconfig" + endif
drivers/virt/geniezone/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config MTK_GZVM + tristate "GenieZone Hypervisor driver for guest VM operation" + depends on ARM64 + help + This driver, gzvm, enables to run guest VMs on MTK GenieZone + hypervisor. It exports kvm-like interfaces for VMM (e.g., crosvm) in + order to operate guest VMs on GenieZone hypervisor. + + GenieZone hypervisor now only supports MediaTek SoC and arm64 + architecture. + + Select M if you want it be built as a module (gzvm.ko). + + If unsure, say N.
drivers/virt/geniezone/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for GenieZone driver, this file should be include in arch's +# to avoid two ko being generated. +# + +GZVM_DIR ?= ../../../drivers/virt/geniezone + +gzvm-y := $(GZVM_DIR)/gzvm_main.o $(GZVM_DIR)/gzvm_vm.o +
drivers/virt/geniezone/gzvm_main.c new file +141 -0
141 lines not on this page · raw message
drivers/virt/geniezone/gzvm_vm.c new file +390 -0
390 lines not on this page · raw message
include/linux/gzvm_drv.h new file +95 -0
95 lines not on this page · raw message
include/uapi/asm-generic/Kbuild +1 -0
@@ -34,3 +34,4 @@ mandatory-y += termbits.h mandatory-y += termios.h mandatory-y += types.h mandatory-y += unistd.h +mandatory-y += gzvm_arch.h
include/uapi/asm-generic/gzvm_arch.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (c) 2023 MediaTek Inc. +*/ + +#ifndef __ASM_GENERIC_GZVM_ARCH_H +#define __ASM_GENERIC_GZVM_ARCH_H +/* geniezone only supports aarch64 platform for now */ + +#endif /* __ASM_GENERIC_GZVM_ARCH_H */
include/uapi/linux/gzvm.h new file +73 -0
73 lines not on this page · raw message
Signature · 7 lines
2.18.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v4 2/9] virt: geniezone: Add GenieZone hypervisor support
Quoted 6 lines · Yi-De Wu
From: "Yingshiuan Pan" <[email protected]>
GenieZone is MediaTek hypervisor solution, and it is running in EL2 stand alone as a type-I hypervisor. This patch exports a set of ioctl interfaces for userspace VMM (e.g., crosvm) to operate guest VMs lifecycle (creation and destroy) on GenieZone.
...
Quoted 17 lines
drivers/virt/geniezone/gzvm_main.c new file +17
-0+static int gzvm_drv_probe (void ) +{ +int ret; + +if (gzvm_arch_probe () !=0 ) { +pr_err ("Not found available conduit\n" ); +return -ENODEV ; + } + + ret =misc_register (&gzvm_dev); +if (ret) +return ret; + gzvm_debug_dev = &gzvm_dev; + +return 0 ; +} +
drivers/virt/geniezone/gzvm_main.c line 128
Quoted 10 lines
drivers/virt/geniezone/gzvm_main.c new file +10
-0+static int gzvm_drv_remove (void ) +{ +destroy_all_vm (); +misc_deregister (&gzvm_dev); +return 0 ; +} + +static int gzvm_dev_init (void ) +{ +return gzvm_drv_probe ();
So for every system and architecture you want to: probe, run some SMC and then print error that it is not othe system you wanted.
I don't think this is what we want. You basically pollute all of other users just to have your hypervisor guest additions...
Best regards,
Krzysztof
Re: [PATCH v4 2/9] virt: geniezone: Add GenieZone hypervisor support
Quoted 45 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 4 lines · Yi-De Wu
From: "Yingshiuan Pan" <[email protected]>
GenieZone is MediaTek hypervisor solution, and it is running in EL2 stand alone as a type-I hypervisor. This patch exports a set of
ioctl
Quoted 2 lines
interfaces for userspace VMM (e.g., crosvm) to operate guest VMs lifecycle (creation and destroy) on GenieZone.
...
Quoted 17 lines
drivers/virt/geniezone/gzvm_main.c new file +17
-0+static int gzvm_drv_probe (void ) +{ +int ret; + +if (gzvm_arch_probe () !=0 ) { +pr_err ("Not found available conduit\n" ); +return -ENODEV ; +} + +ret =misc_register (&gzvm_dev); +if (ret) +return ret; +gzvm_debug_dev = &gzvm_dev; + +return 0 ; +} +drivers/virt/geniezone/gzvm_main.c line 128
Quoted 10 lines
drivers/virt/geniezone/gzvm_main.c new file +10
-0+static int gzvm_drv_remove (void ) +{ +destroy_all_vm (); +misc_deregister (&gzvm_dev); +return 0 ; +} + +static int gzvm_dev_init (void ) +{ +return gzvm_drv_probe ();So for every system and architecture you want to: probe, run some SMC and then print error that it is not othe system you wanted.
Quoted 7 lines
I don't think this is what we want. You basically pollute all of other
users just to have your hypervisor guest additions...Best regards,
Krzysztof
hi Krzysztof,
After some back-and-forth discussion[1][2][3][4][5], we'd like to bring bakc all the attension of related issues in this thread.
We're going to restore the dt solution on our next version, which means we would maintain a simple dt for discovering the hypervisor node and probe for the status of the device when needed.
The reasons are listed below for the record.
- Although dt is for hardware, it's difficult to discover a specific hypervisor without probing on all subsystem and thus pollute all of other users[4] as a consequence.
- The GenieZone hypervisor could be considered as a vendor model to assist platform virtualization whose implementation is independent from Linuxism.
Please let us if there're any other concerns.
Reference
[1]
https://android-review.googlesource.com/c/kernel/common/+/2447547/comment/495502f3_bb52344b/
[2]
https://lore.kernel.org/all/[email protected]/
[3]
https://lore.kernel.org/all/[email protected]/
[4]
https://lore.kernel.org/lkml/[email protected]/
[5]
https://lore.kernel.org/all/[email protected]/
Regards,
Quoted 1 line
Re: [PATCH v4 2/9] virt: geniezone: Add GenieZone hypervisor support
Quoted 55 lines · Yi-De Wu (吳一德)
Quoted 45 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 4 lines · Yi-De Wu
From: "Yingshiuan Pan" <[email protected]>
GenieZone is MediaTek hypervisor solution, and it is running in EL2 stand alone as a type-I hypervisor. This patch exports a set of
ioctl
Quoted 2 lines
interfaces for userspace VMM (e.g., crosvm) to operate guest VMs lifecycle (creation and destroy) on GenieZone.
...
Quoted 17 lines
drivers/virt/geniezone/gzvm_main.c new file +17
-0+static int gzvm_drv_probe (void ) +{ +int ret; + +if (gzvm_arch_probe () !=0 ) { +pr_err ("Not found available conduit\n" ); +return -ENODEV ; +} + +ret =misc_register (&gzvm_dev); +if (ret) +return ret; +gzvm_debug_dev = &gzvm_dev; + +return 0 ; +} +drivers/virt/geniezone/gzvm_main.c line 128
Quoted 10 lines
drivers/virt/geniezone/gzvm_main.c new file +10
-0+static int gzvm_drv_remove (void ) +{ +destroy_all_vm (); +misc_deregister (&gzvm_dev); +return 0 ; +} + +static int gzvm_dev_init (void ) +{ +return gzvm_drv_probe ();So for every system and architecture you want to: probe, run some SMC and then print error that it is not othe system you wanted.
Quoted 7 lines
I don't think this is what we want. You basically pollute all of other
users just to have your hypervisor guest additions...Best regards,
Krzysztof
Quoted 8 lines
hi Krzysztof,
After some back-and-forth discussion[1][2][3][4][5], we'd like to bring bakc all the attension of related issues in this thread.
We're going to restore the dt solution on our next version, which means we would maintain a simple dt for discovering the hypervisor node and probe for the status of the device when needed.
.. see the comment below.
Quoted 5 lines
The reasons are listed below for the record.
- Although dt is for hardware, it's difficult to discover a specific hypervisor without probing on all subsystem and thus pollute all of other users[4] as a consequence.
I don't understand. Patches will help here to understand what exactly you are referring here.
Quoted 3 lines
- The GenieZone hypervisor could be considered as a vendor model to assist platform virtualization whose implementation is independent from Linuxism.
Then why we are adding this hypervisor support in Linux?
Quoted 7 lines
Please let us if there're any other concerns.
Reference
[1]
https://android-review.googlesource.com/c/kernel/common/+/2447547/comment/495502f3_bb52344b/
Why we look at the ACK patches here on the LKML? Please submit them here if you would like to discuss and review?
---Trilok Soni
PATCH v4 3/9 virt: geniezone: Add vcpu support
In reply to Yi-De WuFrom: "Yingshiuan Pan" <[email protected]>
VMM use this interface to create vcpu instance which is a fd, and this fd will be for any vcpu operations, such as setting vcpu registers and accepts the most important ioctl GZVM_VCPU_RUN which requests GenieZone hypervisor to do context switch to execute VM's vcpu context.
--- arch/arm64/geniezone/Makefile | 2 +- arch/arm64/geniezone/gzvm_arch_common.h | 19 ++ arch/arm64/geniezone/vcpu.c | 84 +++++++++ arch/arm64/include/uapi/asm/gzvm_arch.h | 29 +++ drivers/virt/geniezone/Makefile | 3 +- drivers/virt/geniezone/gzvm_vcpu.c | 234 ++++++++++++++++++++++++ drivers/virt/geniezone/gzvm_vm.c | 5 + include/linux/gzvm_drv.h | 19 ++ include/uapi/linux/gzvm.h | 101 ++++++++++ 9 files changed, 494 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/geniezone/vcpu.c create mode 100644 drivers/virt/geniezone/gzvm_vcpu.c
arch/arm64/geniezone/Makefile +1 -1
@@ -4,6 +4,6 @@ # include $(srctree)/drivers/virt/geniezone/Makefile -gzvm-y += vm.o +gzvm-y += vm.o vcpu.o obj-$(CONFIG_MTK_GZVM) += gzvm.o
arch/arm64/geniezone/gzvm_arch_common.h +19 -0
@@ -67,4 +67,23 @@ static inline gzvm_id_t get_vmid_from_tuple(unsigned int tuple) return (gzvm_id_t)(tuple >> 16); } +static inline gzvm_vcpu_id_t get_vcpuid_from_tuple (unsigned int tuple) +{ +return (gzvm_vcpu_id_t)(tuple &0xffff ); +} + +static inline unsigned int +assemble_vm_vcpu_tuple (gzvm_id_t vmid,gzvm_vcpu_id_t vcpuid) +{ +return ((unsigned int )vmid <<16 | vcpuid); +} + +static inline void +disassemble_vm_vcpu_tuple (unsigned int tuple,gzvm_id_t *vmid, +gzvm_vcpu_id_t *vcpuid) +{ + *vmid =get_vmid_from_tuple (tuple); + *vcpuid =get_vcpuid_from_tuple (tuple); +} +#endif /* __GZVM_ARCH_COMMON_H__ */
arch/arm64/geniezone/vcpu.c new file +84 -0
84 lines not on this page · raw message
arch/arm64/include/uapi/asm/gzvm_arch.h +29 -0
@@ -17,4 +17,33 @@/* GZVM_CAP_ARM_PVM_SET_PROTECTED_VM only sets protected but not load pvmfw */ #define GZVM_CAP_ARM_PVM_SET_PROTECTED_VM 2 +/** +* Architecture specific registers are to be defined in arch headers and +* ORed with the arch identifier. +*/ +#define GZVM_REG_ARM 0x4000000000000000ULL +#define GZVM_REG_ARM64 0x6000000000000000ULL + +#define GZVM_REG_SIZE_SHIFT 52 +#define GZVM_REG_SIZE_MASK 0x00f0000000000000ULL +#define GZVM_REG_SIZE_U8 0x0000000000000000ULL +#define GZVM_REG_SIZE_U16 0x0010000000000000ULL +#define GZVM_REG_SIZE_U32 0x0020000000000000ULL +#define GZVM_REG_SIZE_U64 0x0030000000000000ULL +#define GZVM_REG_SIZE_U128 0x0040000000000000ULL +#define GZVM_REG_SIZE_U256 0x0050000000000000ULL +#define GZVM_REG_SIZE_U512 0x0060000000000000ULL +#define GZVM_REG_SIZE_U1024 0x0070000000000000ULL +#define GZVM_REG_SIZE_U2048 0x0080000000000000ULL + +#define GZVM_REG_ARCH_MASK 0xff00000000000000ULL + +/* If you need to interpret the index values, here is the key: */ +#define GZVM_REG_ARM_COPROC_MASK 0x000000000FFF0000 +#define GZVM_REG_ARM_COPROC_SHIFT 16 + +/* Normal registers are mapped as coprocessor 16. */ +#define GZVM_REG_ARM_CORE (0x0010 << GZVM_REG_ARM_COPROC_SHIFT) +#define GZVM_REG_ARM_CORE_REG (name) (offsetof(struct gzvm_regs, name) / sizeof(__u32)) +#endif /* __GZVM_ARCH_H__ */
drivers/virt/geniezone/Makefile +2 -1
@@ -6,5 +6,6 @@ GZVM_DIR ?= ../../../drivers/virt/geniezone -gzvm-y := $(GZVM_DIR)/gzvm_main.o $(GZVM_DIR)/gzvm_vm.o +gzvm-y := $(GZVM_DIR)/gzvm_main.o $(GZVM_DIR)/gzvm_vm.o \ + $(GZVM_DIR)/gzvm_vcpu.o
drivers/virt/geniezone/gzvm_vcpu.c new file +234 -0
234 lines not on this page · raw message
drivers/virt/geniezone/gzvm_vm.c +5 -0
@@ -270,6 +270,10 @@ static long gzvm_vm_ioctl(struct file *filp, unsigned int ioctl, ret =gzvm_dev_ioctl_check_extension (gzvm, arg);break ; } +case GZVM_CREATE_VCPU : { + ret =gzvm_vm_ioctl_create_vcpu (gzvm, arg); +break ; + }case GZVM_SET_USER_MEMORY_REGION : {struct gzvm_userspace_memory_region userspace_mem;
@@ -304,6 +308,7 @@ static void gzvm_destroy_vm(struct gzvm *gzvm)mutex_lock (&gzvm->lock); +gzvm_destroy_vcpus (gzvm);gzvm_arch_destroy_vm (gzvm->vm_id);mutex_lock (&gzvm_list_lock);
include/linux/gzvm_drv.h +19 -0
@@ -34,6 +34,8 @@#define GZVM_MAX_VCPUS 8#define GZVM_MAX_MEM_REGION 10 +#define GZVM_VCPU_RUN_MAP_SIZE (PAGE_SIZE * 2) +/* struct mem_region_addr_range - Identical to ffa memory constituent */ struct mem_region_addr_range {/* the base IPA of the constituent memory region, aligned to 4 kiB */
@@ -61,7 +63,16 @@ struct gzvm_memslot {u32 slot_id; }; +struct gzvm_vcpu { +struct gzvm *gzvm; +int vcpuid; +/* lock of vcpu*/ +struct mutex lock; +struct gzvm_vcpu_run *run; +}; +struct gzvm { +struct gzvm_vcpu *vcpus[GZVM_MAX_VCPUS ];/* userspace tied to this vm */ struct mm_struct *mm;struct gzvm_memslot memslot[GZVM_MAX_MEM_REGION ];
@@ -78,6 +89,8 @@ int gz_err_to_errno(unsigned long err);void destroy_all_vm (void ); +void gzvm_destroy_vcpus (struct gzvm *gzvm); +/* arch-dependant functions */ int gzvm_arch_probe (void ); int gzvm_arch_set_memregion(gzvm_id_t vm_id, size_t buf_size,
@@ -89,6 +102,12 @@ int gzvm_vm_ioctl_arch_enable_cap(struct gzvm *gzvm,struct gzvm_enable_cap *cap, void __user *argp);u64 hva_to_pa_arch (u64 hva); +int gzvm_vm_ioctl_create_vcpu (struct gzvm *gzvm,u32 cpuid); +int gzvm_arch_vcpu_update_one_reg (struct gzvm_vcpu *vcpu,__u64 reg_id, +bool is_write,__u64 *data); +int gzvm_arch_create_vcpu (gzvm_id_t vm_id,int vcpuid,void *run); +int gzvm_arch_vcpu_run (struct gzvm_vcpu *vcpu,__u64 *exit_reason); +int gzvm_arch_destroy_vcpu (gzvm_id_t vm_id,int vcpuid);extern struct miscdevice *gzvm_debug_dev;
include/uapi/linux/gzvm.h +101 -0
117 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v4 4/9 virt: geniezone: Add irqchip support for virtual interrupt injection
In reply to Yi-De WuFrom: "Yingshiuan Pan" <[email protected]>
Enable GenieZone to handle virtual interrupt injection request.
--- arch/arm64/geniezone/Makefile | 2 +- arch/arm64/geniezone/vgic.c | 89 +++++++++++++++++++++++++ arch/arm64/include/uapi/asm/gzvm_arch.h | 4 ++ drivers/virt/geniezone/Makefile | 2 +- drivers/virt/geniezone/gzvm_common.h | 12 ++++ drivers/virt/geniezone/gzvm_irqchip.c | 13 ++++ drivers/virt/geniezone/gzvm_vm.c | 77 +++++++++++++++++++++ include/linux/gzvm_drv.h | 4 ++ include/uapi/linux/gzvm.h | 53 +++++++++++++++ 9 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/geniezone/vgic.c create mode 100644 drivers/virt/geniezone/gzvm_common.h create mode 100644 drivers/virt/geniezone/gzvm_irqchip.c
arch/arm64/geniezone/Makefile +1 -1
@@ -4,6 +4,6 @@ # include $(srctree)/drivers/virt/geniezone/Makefile -gzvm-y += vm.o vcpu.o +gzvm-y += vm.o vcpu.o vgic.o obj-$(CONFIG_MTK_GZVM) += gzvm.o
arch/arm64/geniezone/vgic.c new file +89 -0
89 lines not on this page · raw message
arch/arm64/include/uapi/asm/gzvm_arch.h +4 -0
@@ -46,4 +46,8 @@#define GZVM_REG_ARM_CORE (0x0010 << GZVM_REG_ARM_COPROC_SHIFT)#define GZVM_REG_ARM_CORE_REG (name) (offsetof(struct gzvm_regs, name) / sizeof(__u32)) +#define GZVM_VGIC_NR_SGIS 16 +#define GZVM_VGIC_NR_PPIS 16 +#define GZVM_VGIC_NR_PRIVATE_IRQS (GZVM_VGIC_NR_SGIS + GZVM_VGIC_NR_PPIS) +#endif /* __GZVM_ARCH_H__ */
drivers/virt/geniezone/Makefile +1 -1
@@ -7,5 +7,5 @@ GZVM_DIR ?= ../../../drivers/virt/geniezone gzvm-y := $(GZVM_DIR)/gzvm_main.o $(GZVM_DIR)/gzvm_vm.o \ - $(GZVM_DIR)/gzvm_vcpu.o + $(GZVM_DIR)/gzvm_vcpu.o $(GZVM_DIR)/gzvm_irqchip.o
drivers/virt/geniezone/gzvm_common.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2023 MediaTek Inc. +*/ + +#ifndef __GZ_COMMON_H__ +#define __GZ_COMMON_H__ + +int gzvm_irqchip_inject_irq (struct gzvm *gzvm,unsigned int vcpu_idx, +u32 irq_type,u32 irq,bool level); + +#endif /* __GZVM_COMMON_H__ */
drivers/virt/geniezone/gzvm_irqchip.c new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2023 MediaTek Inc. +*/ + +#include <linux/gzvm_drv.h> +#include "gzvm_common.h" + +int gzvm_irqchip_inject_irq (struct gzvm *gzvm,unsigned int vcpu_idx, +u32 irq_type,u32 irq,bool level) +{ +return gzvm_arch_inject_irq (gzvm, vcpu_idx, irq_type, irq, level); +}
drivers/virt/geniezone/gzvm_vm.c +77 -0
95 lines not on this page · raw message
include/linux/gzvm_drv.h +4 -0
@@ -109,6 +109,10 @@ int gzvm_arch_create_vcpu(gzvm_id_t vm_id, int vcpuid, void *run);int gzvm_arch_vcpu_run (struct gzvm_vcpu *vcpu,__u64 *exit_reason);int gzvm_arch_destroy_vcpu (gzvm_id_t vm_id,int vcpuid); +int gzvm_arch_create_device (gzvm_id_t vm_id,struct gzvm_create_device *gzvm_dev); +int gzvm_arch_inject_irq (struct gzvm *gzvm,unsigned int vcpu_idx,u32 irq_type, +u32 irq,bool level); +extern struct miscdevice *gzvm_debug_dev;#endif /* __GZVM_DRV_H__ */
include/uapi/linux/gzvm.h +53 -0
59 lines not on this page · raw message
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [PATCH v4 4/9] virt: geniezone: Add irqchip support for virtual interrupt injection
Il 09/06/23 10:52, Yi-De Wu ha scritto:
Quoted 41 lines
From: "Yingshiuan Pan" <[email protected]>
Enable GenieZone to handle virtual interrupt injection request.
Signed-off-by Yingshiuan Pan <[email protected]>Signed-off-by Liju Chen <[email protected]>Signed-off-by Yi-De Wu <[email protected]>--- arch/arm64/geniezone/Makefile | 2 +- arch/arm64/geniezone/vgic.c | 89 +++++++++++++++++++++++++ arch/arm64/include/uapi/asm/gzvm_arch.h | 4 ++ drivers/virt/geniezone/Makefile | 2 +- drivers/virt/geniezone/gzvm_common.h | 12 ++++ drivers/virt/geniezone/gzvm_irqchip.c | 13 ++++ drivers/virt/geniezone/gzvm_vm.c | 77 +++++++++++++++++++++ include/linux/gzvm_drv.h | 4 ++ include/uapi/linux/gzvm.h | 53 +++++++++++++++ 9 files changed, 254 insertions(+), 2 deletions(-)create mode 100644
arch/arm64/geniezone/vgic.ccreate mode 100644drivers/virt/geniezone/gzvm_common.hcreate mode 100644drivers/virt/geniezone/gzvm_irqchip.carch/arm64/geniezone/Makefile +1
-1@@ -4,6 +4,6 @@ # include $(srctree)/drivers/virt/geniezone/Makefile -gzvm-y += vm.o vcpu.o +gzvm-y += vm.o vcpu.o vgic.o obj-$(CONFIG_MTK_GZVM) += gzvm.oarch/arm64/geniezone/vgic.c new file +1
-0@@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0
arch/arm64/geniezone/vgic.c line 11
Quoted 10 lines
arch/arm64/geniezone/vgic.c new file +10
-0+/* +* Copyright (c) 2023 MediaTek Inc. +*/ + +#include <linux/irqchip/arm-gic-v3.h> +#include <linux/gzvm.h> +#include <linux/gzvm_drv.h> +#include "gzvm_arch_common.h" + +/* is_irq_valid() - Check the irq number and irq_type are matched */
/**
* is_irq_valid() - Check if the IRQ number and type are matched
* @irq: interrupt number
* @irq_type: interrupt type
*/
Quoted 152 lines
arch/arm64/geniezone/vgic.c new file +78
-0+static bool is_irq_valid (u32 irq,u32 irq_type) +{ +switch (irq_type) { +case GZVM_IRQ_TYPE_CPU : +/* 0 ~ 15: SGI */ +if (likely (irq <=GZVM_IRQ_CPU_FIQ )) +return true; +break ; +case GZVM_IRQ_TYPE_PPI : +/* 16 ~ 31: PPI */ +if (likely (irq >=GZVM_VGIC_NR_SGIS && irq <GZVM_VGIC_NR_PRIVATE_IRQS )) +return true; +break ; +case GZVM_IRQ_TYPE_SPI : +/* 32 ~ : SPT */ +if (likely (irq >=GZVM_VGIC_NR_PRIVATE_IRQS )) +return true; +break ; +default : +return false; + } +return false; +} + +/** +* gzvm_vgic_inject_irq() - Inject virtual interrupt to a VM +* @vcpu_idx: vcpu index, only valid if PPI +* @irq: irq number +* @level: 1 if true else 0 +*/ +static int gzvm_vgic_inject_irq (struct gzvm *gzvm,unsigned int vcpu_idx,u32 irq_type, +u32 irq,bool level) +{ +unsigned long a1 =assemble_vm_vcpu_tuple (gzvm->vm_id, vcpu_idx); +struct arm_smccc_res res; + +if (!unlikely (is_irq_valid (irq, irq_type))) +return -EINVAL ; + +gzvm_hypcall_wrapper (MT_HVC_GZVM_IRQ_LINE , a1, irq, level, +0 ,0 ,0 ,0 , &res); +if (res.a0) { +pr_err ("Failed to set IRQ level (%d) to irq#%u on vcpu %d with ret=%d\n" , + level, irq, vcpu_idx, (int )res.a0); +return -EFAULT ; + } + +return 0 ; +} + +/** +* gzvm_vgic_inject_spi() - Inject virtual spi interrupt +* +* @spi_irq: This is spi interrupt number (starts from 0 instead of 32) +* +* Return 0 if succeed else other negative values indicating each errors +*/ +static int gzvm_vgic_inject_spi (struct gzvm *gzvm,unsigned int vcpu_idx, +u32 spi_irq,bool level) +{ +return gzvm_vgic_inject_irq (gzvm,0 ,GZVM_IRQ_TYPE_SPI , + spi_irq +GZVM_VGIC_NR_PRIVATE_IRQS , level); +} + +int gzvm_arch_create_device (gzvm_id_t vm_id,struct gzvm_create_device *gzvm_dev) +{ +struct arm_smccc_res res; + +return gzvm_hypcall_wrapper (MT_HVC_GZVM_CREATE_DEVICE , vm_id, +virt_to_phys (gzvm_dev),0 ,0 ,0 ,0 ,0 , &res); +} + +int gzvm_arch_inject_irq (struct gzvm *gzvm,unsigned int vcpu_idx,u32 irq_type, +u32 irq,bool level) +{ +/* default use spi */ +return gzvm_vgic_inject_spi (gzvm, vcpu_idx, irq, level); +}arch/arm64/include/uapi/asm/gzvm_arch.h +4
-0@@ -46,4 +46,8 @@#define GZVM_REG_ARM_CORE (0x0010 << GZVM_REG_ARM_COPROC_SHIFT)#define GZVM_REG_ARM_CORE_REG (name) (offsetof(struct gzvm_regs, name) / sizeof(__u32)) +#define GZVM_VGIC_NR_SGIS 16 +#define GZVM_VGIC_NR_PPIS 16 +#define GZVM_VGIC_NR_PRIVATE_IRQS (GZVM_VGIC_NR_SGIS + GZVM_VGIC_NR_PPIS) +#endif /* __GZVM_ARCH_H__ */ drivers/virt/geniezone/Makefile +1
-1@@ -7,5 +7,5 @@ GZVM_DIR ?= ../../../drivers/virt/geniezone gzvm-y := $(GZVM_DIR)/gzvm_main.o $(GZVM_DIR)/gzvm_vm.o \ - $(GZVM_DIR)/gzvm_vcpu.o + $(GZVM_DIR)/gzvm_vcpu.o $(GZVM_DIR)/gzvm_irqchip.odrivers/virt/geniezone/gzvm_common.h new file +12
-0@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2023 MediaTek Inc. +*/ + +#ifndef __GZ_COMMON_H__ +#define __GZ_COMMON_H__ + +int gzvm_irqchip_inject_irq (struct gzvm *gzvm,unsigned int vcpu_idx, +u32 irq_type,u32 irq,bool level); + +#endif /* __GZVM_COMMON_H__ */ drivers/virt/geniezone/gzvm_irqchip.c new file +13
-0@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2023 MediaTek Inc. +*/ + +#include <linux/gzvm_drv.h> +#include "gzvm_common.h" + +int gzvm_irqchip_inject_irq (struct gzvm *gzvm,unsigned int vcpu_idx, +u32 irq_type,u32 irq,bool level) +{ +return gzvm_arch_inject_irq (gzvm, vcpu_idx, irq_type, irq, level); +}drivers/virt/geniezone/gzvm_vm.c +1
-0@@ -12,6 +12,7 @@#include <linux/platform_device.h> #include <linux/slab.h> #include <linux/gzvm_drv.h> +#include "gzvm_common.h" static DEFINE_MUTEX (gzvm_list_lock);static LIST_HEAD (gzvm_list);
drivers/virt/geniezone/gzvm_vm.c gzvm_vm_ioctl_set_memory_region(struct gzvm *gzvm, · line 258
Quoted 8 lines
drivers/virt/geniezone/gzvm_vm.c +5
-0@@ -250,6 +251,68 @@ gzvm_vm_ioctl_set_memory_region(struct gzvm *gzvm,return register_memslot_addr_range (gzvm, memslot); } +static int gzvm_vm_ioctl_irq_line (struct gzvm *gzvm, +struct gzvm_irq_level *irq_level) +{ +u32 irq = irq_level->irq; +unsigned int irq_type, vcpu_idx, irq_num;
Is there any reason why you're not using fixed size types here?
drivers/virt/geniezone/gzvm_vm.c gzvm_vm_ioctl_set_memory_region(struct gzvm *gzvm, · line 262
Quoted 4 lines
drivers/virt/geniezone/gzvm_vm.c +4
-0+bool level = irq_level->level; + + irq_type = (irq >>GZVM_IRQ_TYPE_SHIFT ) &GZVM_IRQ_TYPE_MASK ; + vcpu_idx = (irq >>GZVM_IRQ_VCPU_SHIFT ) &GZVM_IRQ_VCPU_MASK ;
Why aren't you using bitfield macros here?
#define GZVM_IRQ_LINE_TYPE GENMASK(27, 24)
#define ..........
irq_type = FIELD_GET(GZVM_IRQ_LINE_TYPE, irq);vcpu_idx = FIELD_GET(GZVM_IRQ_LINE_VCPU, irq);vcpu2_idx = FIELD_GET(GZVM_IRQ_LINE_VCPU, irq) * (GZVM_IRQ_VCPU_MASK + 1); irq_num = FIELD_GET(GZVM_IRQ_LINE_NUM, irq);
return gzvm_irqchip_inject_irq(gzvm, vcpu_idx + vcpu2_idx, irq_type, irq_num,
level);
Quoted 126 lines
drivers/virt/geniezone/gzvm_vm.c +67
-0+ vcpu_idx += ((irq >>GZVM_IRQ_VCPU2_SHIFT ) &GZVM_IRQ_VCPU2_MASK ) * + (GZVM_IRQ_VCPU_MASK +1 ); + irq_num = (irq >>GZVM_IRQ_NUM_SHIFT ) &GZVM_IRQ_NUM_MASK ; + +return gzvm_irqchip_inject_irq (gzvm, vcpu_idx, irq_type, irq_num, + level); +} + +static int gzvm_vm_ioctl_create_device (struct gzvm *gzvm,void __user *argp) +{ +struct gzvm_create_device *gzvm_dev; +void *dev_data =NULL ; +int ret; + + gzvm_dev = (struct gzvm_create_device *)alloc_pages_exact (PAGE_SIZE , +GFP_KERNEL ); +if (!gzvm_dev) +return -ENOMEM ; +if (copy_from_user (gzvm_dev, argp,sizeof (*gzvm_dev))) { + ret = -EFAULT ; + goto err_free_dev; + } + +if (gzvm_dev->attr_addr !=0 && gzvm_dev->attr_size !=0 ) { +size_t attr_size = gzvm_dev->attr_size; +void __user *attr_addr = (void __user *)gzvm_dev->attr_addr; + +/* Size of device specific data should not be over a page. */ +if (attr_size >PAGE_SIZE ) +return -EINVAL ; + + dev_data =alloc_pages_exact (attr_size,GFP_KERNEL ); +if (!dev_data) { + ret = -ENOMEM ; + goto err_free_dev; + } + +if (copy_from_user (dev_data, attr_addr, attr_size)) { + ret = -EFAULT ; + goto err_free_dev_data; + } + gzvm_dev->attr_addr =virt_to_phys (dev_data); + } + + ret =gzvm_arch_create_device (gzvm->vm_id, gzvm_dev); +err_free_dev_data: +if (dev_data) +free_pages_exact (dev_data,0 ); +err_free_dev: +free_pages_exact (gzvm_dev,0 ); +return ret; +} +static int gzvm_vm_ioctl_enable_cap (struct gzvm *gzvm,struct gzvm_enable_cap *cap,void __user *argp)@@ -284,6 +347,20 @@ static long gzvm_vm_ioctl(struct file *filp, unsigned int ioctl, ret =gzvm_vm_ioctl_set_memory_region (gzvm, &userspace_mem);break ; } +case GZVM_IRQ_LINE : { +struct gzvm_irq_level irq_event; + + ret = -EFAULT ; +if (copy_from_user (&irq_event, argp,sizeof (irq_event))) + goto out; + + ret =gzvm_vm_ioctl_irq_line (gzvm, &irq_event); +break ; + } +case GZVM_CREATE_DEVICE : { + ret =gzvm_vm_ioctl_create_device (gzvm, argp); +break ; + }case GZVM_ENABLE_CAP : {struct gzvm_enable_cap cap;include/linux/gzvm_drv.h +4
-0@@ -109,6 +109,10 @@ int gzvm_arch_create_vcpu(gzvm_id_t vm_id, int vcpuid, void *run);int gzvm_arch_vcpu_run (struct gzvm_vcpu *vcpu,__u64 *exit_reason);int gzvm_arch_destroy_vcpu (gzvm_id_t vm_id,int vcpuid); +int gzvm_arch_create_device (gzvm_id_t vm_id,struct gzvm_create_device *gzvm_dev); +int gzvm_arch_inject_irq (struct gzvm *gzvm,unsigned int vcpu_idx,u32 irq_type, +u32 irq,bool level); +extern struct miscdevice *gzvm_debug_dev;#endif /* __GZVM_DRV_H__ */ include/uapi/linux/gzvm.h +26
-0@@ -61,6 +61,59 @@ struct gzvm_userspace_memory_region {#define GZVM_SET_USER_MEMORY_REGION _IOW(GZVM_IOC_MAGIC, 0x46, \ struct gzvm_userspace_memory_region) +/* for GZVM_IRQ_LINE, irq field index values */ +#define GZVM_IRQ_VCPU2_SHIFT 28 +#define GZVM_IRQ_VCPU2_MASK 0xf +#define GZVM_IRQ_TYPE_SHIFT 24 +#define GZVM_IRQ_TYPE_MASK 0xf +#define GZVM_IRQ_VCPU_SHIFT 16 +#define GZVM_IRQ_VCPU_MASK 0xff +#define GZVM_IRQ_NUM_SHIFT 0 +#define GZVM_IRQ_NUM_MASK 0xffff + +/* irq_type field */ +#define GZVM_IRQ_TYPE_CPU 0 +#define GZVM_IRQ_TYPE_SPI 1 +#define GZVM_IRQ_TYPE_PPI 2 + +/* out-of-kernel GIC cpu interrupt injection irq_number field */ +#define GZVM_IRQ_CPU_IRQ 0 +#define GZVM_IRQ_CPU_FIQ 1 + +struct gzvm_irq_level { +union { +__u32 irq; +__s32 status; + }; +__u32 level; +};
include/uapi/linux/gzvm.h struct gzvm_userspace_memory_region { · line 99
Quoted 10 lines
include/uapi/linux/gzvm.h +10
-0+ +#define GZVM_IRQ_LINE _IOW(GZVM_IOC_MAGIC, 0x61, \ + struct gzvm_irq_level) + +enum gzvm_device_type { +GZVM_DEV_TYPE_ARM_VGIC_V3_DIST , +GZVM_DEV_TYPE_ARM_VGIC_V3_REDIST , +GZVM_DEV_TYPE_MAX , +}; +
Please use kerneldoc.
Quoted 10 lines
include/uapi/linux/gzvm.h +10
-0+struct gzvm_create_device { +__u32 dev_type;/* device type */ +__u32 id;/* out: device id */ +__u64 flags;/* device specific flags */ +__u64 dev_addr;/* device ipa address in VM's view */ +__u64 dev_reg_size;/* device register range size */ +/* +* If user -> kernel, this is user virtual address of device specific +* attributes (if needed). If kernel->hypervisor, this is ipa. +*/
include/uapi/linux/gzvm.h struct gzvm_userspace_memory_region { · line 119
Quoted 10 lines
include/uapi/linux/gzvm.h +7
-0+__u64 attr_addr; +__u64 attr_size;/* size of device specific attributes */ +}; + +#define GZVM_CREATE_DEVICE _IOWR(GZVM_IOC_MAGIC, 0xe0, \ + struct gzvm_create_device) +/** * ioctls for vcpu fds */
Regards,
Angelo
PATCH v4 5/9 virt: geniezone: Add irqfd support
In reply to Yi-De WuFrom: "Yingshiuan Pan" <[email protected]>
irqfd enables other threads than vcpu threads to inject virtual interrupt through irqfd asynchronously rather through ioctl interface. This interface is necessary for VMM which creates separated thread for IO handling or uses vhost devices.
--- arch/arm64/geniezone/gzvm_arch_common.h | 6 + drivers/virt/geniezone/Makefile | 4 +- drivers/virt/geniezone/gzvm_irqfd.c | 537 ++++++++++++++++++++++++ drivers/virt/geniezone/gzvm_main.c | 3 +- drivers/virt/geniezone/gzvm_vcpu.c | 1 + drivers/virt/geniezone/gzvm_vm.c | 18 + include/linux/gzvm_drv.h | 27 ++ include/uapi/linux/gzvm.h | 18 + 8 files changed, 611 insertions(+), 3 deletions(-) create mode 100644 drivers/virt/geniezone/gzvm_irqfd.c
arch/arm64/geniezone/gzvm_arch_common.h +6 -0
@@ -46,6 +46,7 @@ enum {#define MT_HVC_GZVM_CREATE_DEVICE GZVM_HCALL_ID(GZVM_FUNC_CREATE_DEVICE)#define MT_HVC_GZVM_PROBE GZVM_HCALL_ID(GZVM_FUNC_PROBE)#define MT_HVC_GZVM_ENABLE_CAP GZVM_HCALL_ID(GZVM_FUNC_ENABLE_CAP) +#define GIC_V3_NR_LRS 16/** * gzvm_hypercall_wrapper()
@@ -72,6 +73,11 @@ static inline gzvm_vcpu_id_t get_vcpuid_from_tuple(unsigned int tuple)return (gzvm_vcpu_id_t)(tuple &0xffff ); } +struct gzvm_vcpu_hwstate { +__u32 nr_lrs; +__u64 lr[GIC_V3_NR_LRS ]; +}; +static inline unsigned int assemble_vm_vcpu_tuple (gzvm_id_t vmid,gzvm_vcpu_id_t vcpuid) {
drivers/virt/geniezone/Makefile +2 -2
@@ -7,5 +7,5 @@ GZVM_DIR ?= ../../../drivers/virt/geniezone gzvm-y := $(GZVM_DIR)/gzvm_main.o $(GZVM_DIR)/gzvm_vm.o \ - $(GZVM_DIR)/gzvm_vcpu.o $(GZVM_DIR)/gzvm_irqchip.o - + $(GZVM_DIR)/gzvm_vcpu.o $(GZVM_DIR)/gzvm_irqchip.o \ + $(GZVM_DIR)/gzvm_irqfd.o
drivers/virt/geniezone/gzvm_irqfd.c new file +537 -0
537 lines not on this page · raw message
drivers/virt/geniezone/gzvm_main.c +2 -1
@@ -113,11 +113,12 @@ static int gzvm_drv_probe(void)return ret; gzvm_debug_dev = &gzvm_dev; -return 0 ; +return gzvm_drv_irqfd_init (); }static int gzvm_drv_remove (void ) { +gzvm_drv_irqfd_exit ();destroy_all_vm ();misc_deregister (&gzvm_dev);return 0 ;
drivers/virt/geniezone/gzvm_vcpu.c +1 -0
@@ -211,6 +211,7 @@ int gzvm_vm_ioctl_create_vcpu(struct gzvm *gzvm, u32 cpuid) ret = -ENOMEM ; goto free_vcpu; } + vcpu->hwstate = (void *)vcpu->run +PAGE_SIZE ; vcpu->vcpuid = cpuid; vcpu->gzvm = gzvm;mutex_init (&vcpu->lock);
drivers/virt/geniezone/gzvm_vm.c +18 -0
@@ -361,6 +361,15 @@ static long gzvm_vm_ioctl(struct file *filp, unsigned int ioctl, ret =gzvm_vm_ioctl_create_device (gzvm, argp);break ; } +case GZVM_IRQFD : { +struct gzvm_irqfd data; + + ret = -EFAULT ; +if (copy_from_user (&data, argp,sizeof (data))) + goto out; + ret =gzvm_irqfd (gzvm, &data); +break ; + }case GZVM_ENABLE_CAP : {struct gzvm_enable_cap cap;
@@ -385,6 +394,7 @@ static void gzvm_destroy_vm(struct gzvm *gzvm)mutex_lock (&gzvm->lock); +gzvm_vm_irqfd_release (gzvm);gzvm_destroy_vcpus (gzvm);gzvm_arch_destroy_vm (gzvm->vm_id);
@@ -430,6 +440,14 @@ static struct gzvm *gzvm_create_vm(unsigned long vm_type) gzvm->mm = current->mm;mutex_init (&gzvm->lock); + ret =gzvm_vm_irqfd_init (gzvm); +if (ret) { +dev_err (gzvm_debug_dev->this_device, +"Failed to initialize irqfd\n" ); +kfree (gzvm); +return ERR_PTR (ret); + } +mutex_lock (&gzvm_list_lock);list_add (&gzvm->vm_list, &gzvm_list);mutex_unlock (&gzvm_list_lock);
include/linux/gzvm_drv.h +27 -0
@@ -11,6 +11,7 @@#include <linux/mutex.h> #include <linux/platform_device.h> #include <linux/gzvm.h> +#include <linux/srcu.h> #define MODULE_NAME "gzvm"#define GZVM_VCPU_MMAP_SIZE PAGE_SIZE
@@ -26,6 +27,8 @@#define ERR_NOT_SUPPORTED (-24)#define ERR_NOT_IMPLEMENTED (-27)#define ERR_FAULT (-40) +#define GZVM_USERSPACE_IRQ_SOURCE_ID 0 +#define GZVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID 1/** * The following data structures are for data transferring between driver and
@@ -69,6 +72,7 @@ struct gzvm_vcpu {/* lock of vcpu*/ struct mutex lock;struct gzvm_vcpu_run *run; +struct gzvm_vcpu_hwstate *hwstate; };struct gzvm {
@@ -78,8 +82,23 @@ struct gzvm {struct gzvm_memslot memslot[GZVM_MAX_MEM_REGION ];/* lock for list_add*/ struct mutex lock; + +struct { +/* lock for irqfds list operation */ +spinlock_t lock; +struct list_head items; +struct list_head resampler_list; +/* lock for irqfds resampler */ +struct mutex resampler_lock; + } irqfds; +struct list_head vm_list;gzvm_id_t vm_id; + +struct hlist_head irq_ack_notifier_list; +struct srcu_struct irq_srcu; +/* lock for irq injection */ +struct mutex irq_lock; };long gzvm_dev_ioctl_check_extension (struct gzvm *gzvm,unsigned long args);
@@ -113,6 +132,14 @@ int gzvm_arch_create_device(gzvm_id_t vm_id, struct gzvm_create_device *gzvm_devint gzvm_arch_inject_irq (struct gzvm *gzvm,unsigned int vcpu_idx,u32 irq_type,u32 irq,bool level); +void gzvm_notify_acked_irq (struct gzvm *gzvm,unsigned int gsi); +int gzvm_irqfd (struct gzvm *gzvm,struct gzvm_irqfd *args); +int gzvm_drv_irqfd_init (void ); +void gzvm_drv_irqfd_exit (void ); +int gzvm_vm_irqfd_init (struct gzvm *gzvm); +void gzvm_vm_irqfd_release (struct gzvm *gzvm); +void gzvm_sync_hwstate (struct gzvm_vcpu *vcpu); +extern struct miscdevice *gzvm_debug_dev;#endif /* __GZVM_DRV_H__ */
include/uapi/linux/gzvm.h +18 -0
@@ -224,4 +224,22 @@ struct gzvm_one_reg {#define GZVM_REG_GENERIC 0x0000000000000000ULL +#define GZVM_IRQFD_FLAG_DEASSIGN (1 << 0) +/** +* GZVM_IRQFD_FLAG_RESAMPLE indicates resamplefd is valid and specifies +* the irqfd to operate in resampling mode for level triggered interrupt +* emulation. +*/ +#define GZVM_IRQFD_FLAG_RESAMPLE (1 << 1) + +struct gzvm_irqfd { +__u32 fd; +__u32 gsi; +__u32 flags; +__u32 resamplefd; +__u8 pad[16 ]; +}; + +#define GZVM_IRQFD _IOW(GZVM_IOC_MAGIC, 0x76, struct gzvm_irqfd) +#endif /* __GZVM_H__ */
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [PATCH v4 5/9] virt: geniezone: Add irqfd support
Il 09/06/23 10:52, Yi-De Wu ha scritto:
Quoted 35 lines
From: "Yingshiuan Pan" <[email protected]>
irqfd enables other threads than vcpu threads to inject virtual interrupt through irqfd asynchronously rather through ioctl interface. This interface is necessary for VMM which creates separated thread for IO handling or uses vhost devices.
Signed-off-by Yingshiuan Pan <[email protected]>Signed-off-by Liju Chen <[email protected]>Signed-off-by Yi-De Wu <[email protected]>--- arch/arm64/geniezone/gzvm_arch_common.h | 6 + drivers/virt/geniezone/Makefile | 4 +- drivers/virt/geniezone/gzvm_irqfd.c | 537 ++++++++++++++++++++++++ drivers/virt/geniezone/gzvm_main.c | 3 +- drivers/virt/geniezone/gzvm_vcpu.c | 1 + drivers/virt/geniezone/gzvm_vm.c | 18 + include/linux/gzvm_drv.h | 27 ++ include/uapi/linux/gzvm.h | 18 + 8 files changed, 611 insertions(+), 3 deletions(-)create mode 100644
drivers/virt/geniezone/gzvm_irqfd.carch/arm64/geniezone/gzvm_arch_common.h +1
-0@@ -46,6 +46,7 @@ enum {#define MT_HVC_GZVM_CREATE_DEVICE GZVM_HCALL_ID(GZVM_FUNC_CREATE_DEVICE)#define MT_HVC_GZVM_PROBE GZVM_HCALL_ID(GZVM_FUNC_PROBE)#define MT_HVC_GZVM_ENABLE_CAP GZVM_HCALL_ID(GZVM_FUNC_ENABLE_CAP) +#define GIC_V3_NR_LRS 16/** * gzvm_hypercall_wrapper()
arch/arm64/geniezone/gzvm_arch_common.h static inline gzvm_vcpu_id_t get_vcpuid_from_tuple(unsigned int tuple) · line 76
Quoted 4 lines
arch/arm64/geniezone/gzvm_arch_common.h +1
-0@@ -72,6 +73,11 @@ static inline gzvm_vcpu_id_t get_vcpuid_from_tuple(unsigned int tuple)return (gzvm_vcpu_id_t)(tuple &0xffff ); } +struct gzvm_vcpu_hwstate {
No documentation?
Quoted 35 lines
arch/arm64/geniezone/gzvm_arch_common.h +4
-0+__u32 nr_lrs; +__u64 lr[GIC_V3_NR_LRS ]; +}; +static inline unsigned int assemble_vm_vcpu_tuple (gzvm_id_t vmid,gzvm_vcpu_id_t vcpuid) {drivers/virt/geniezone/Makefile +2
-2@@ -7,5 +7,5 @@ GZVM_DIR ?= ../../../drivers/virt/geniezone gzvm-y := $(GZVM_DIR)/gzvm_main.o $(GZVM_DIR)/gzvm_vm.o \ - $(GZVM_DIR)/gzvm_vcpu.o $(GZVM_DIR)/gzvm_irqchip.o - + $(GZVM_DIR)/gzvm_vcpu.o $(GZVM_DIR)/gzvm_irqchip.o \ + $(GZVM_DIR)/gzvm_irqfd.odrivers/virt/geniezone/gzvm_irqfd.c new file +10
-0@@ -0,0 +1,537 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2023 MediaTek Inc. +*/ + +#include <linux/eventfd.h> +#include <linux/syscalls.h> +#include <linux/gzvm_drv.h> +#include "gzvm_common.h" +
drivers/virt/geniezone/gzvm_irqfd.c line 20
Quoted 10 lines
drivers/virt/geniezone/gzvm_irqfd.c new file +10
-0+struct gzvm_irq_ack_notifier { +struct hlist_node link; +unsigned int gsi; +void (*irq_acked)(struct gzvm_irq_ack_notifier *ian); +}; + +/** +* struct gzvm_kernel_irqfd_resampler - irqfd resampler descriptor. +* @gzvm: Poiner to gzvm. +* @list_head list: List of resampling struct _irqfd objects sharing this gsi.
This is just @list
drivers/virt/geniezone/gzvm_irqfd.c line 23
Quoted 3 lines
drivers/virt/geniezone/gzvm_irqfd.c new file +3
-0+* RCU list modified under gzvm->irqfds.resampler_lock. +* @notifier: gzvm irq ack notifier. +* @list_head link: Entry in list of gzvm->irqfd.resampler_list.
and this is @link.
Quoted 19 lines
drivers/virt/geniezone/gzvm_irqfd.c new file +19
-0+* Use for sharing esamplers among irqfds on the same gsi. +* Accessed and modified under gzvm->irqfds.resampler_lock. +* +* Resampling irqfds are a special variety of irqfds used to emulate +* level triggered interrupts. The interrupt is asserted on eventfd +* trigger. On acknowledgment through the irq ack notifier, the +* interrupt is de-asserted and userspace is notified through the +* resamplefd. All resamplers on the same gsi are de-asserted +* together, so we don't need to track the state of each individual +* user. We can also therefore share the same irq source ID. +*/ +struct gzvm_kernel_irqfd_resampler { +struct gzvm *gzvm; + +struct list_head list; +struct gzvm_irq_ack_notifier notifier; + +struct list_head link; +};
drivers/virt/geniezone/gzvm_irqfd.c line 52
Quoted 10 lines
drivers/virt/geniezone/gzvm_irqfd.c new file +10
-0+ +/** +* struct gzvm_kernel_irqfd: gzvm kernel irqfd descriptor. +* @gzvm: Pointer to gzvm. +* @wait: Wait queue entry. +* @gsi: Used for level IRQ fast-path. +* @resampler: The resampler used by this irqfd (resampler-only). +* @resamplefd: Eventfd notified on resample (resampler-only). +* @resampler_link: Entry in list of irqfds for a resampler (resampler-only). +* @eventfd: Used for setup/shutdown.
You're not documenting list, pt, shutdown: that will trigger a kerneldoc warning. Please fix.
Quoted 18 lines
drivers/virt/geniezone/gzvm_irqfd.c new file +18
-0+*/ +struct gzvm_kernel_irqfd { +struct gzvm *gzvm; +wait_queue_entry_t wait; + +int gsi; + +struct gzvm_kernel_irqfd_resampler *resampler; + +struct eventfd_ctx *resamplefd; + +struct list_head resampler_link; + +struct eventfd_ctx *eventfd; +struct list_head list; +poll_table pt; +struct work_struct shutdown; +};
..snip..
drivers/virt/geniezone/gzvm_main.c static int gzvm_drv_probe(void) · line 116
Quoted 10 lines
drivers/virt/geniezone/gzvm_main.c +1
-1@@ -113,11 +113,12 @@ static int gzvm_drv_probe(void)return ret; gzvm_debug_dev = &gzvm_dev; -return 0 ; +return gzvm_drv_irqfd_init ();
ret = gzvm_drv_irqfd_init();
if (ret)
return ret;
return 0;
Quoted 25 lines
drivers/virt/geniezone/gzvm_main.c +1
-0}static int gzvm_drv_remove (void ) { +gzvm_drv_irqfd_exit ();destroy_all_vm ();misc_deregister (&gzvm_dev);return 0 ;drivers/virt/geniezone/gzvm_vcpu.c +1
-0@@ -211,6 +211,7 @@ int gzvm_vm_ioctl_create_vcpu(struct gzvm *gzvm, u32 cpuid) ret = -ENOMEM ; goto free_vcpu; } + vcpu->hwstate = (void *)vcpu->run +PAGE_SIZE ; vcpu->vcpuid = cpuid; vcpu->gzvm = gzvm;mutex_init (&vcpu->lock);drivers/virt/geniezone/gzvm_vm.c +0
-0
drivers/virt/geniezone/gzvm_vm.c static long gzvm_vm_ioctl(struct file *filp, unsigned int ioctl, · line 368
Quoted 8 lines
drivers/virt/geniezone/gzvm_vm.c +5
-0@@ -361,6 +361,15 @@ static long gzvm_vm_ioctl(struct file *filp, unsigned int ioctl, ret =gzvm_vm_ioctl_create_device (gzvm, argp);break ; } +case GZVM_IRQFD : { +struct gzvm_irqfd data; + + ret = -EFAULT ; +if (copy_from_user (&data, argp,sizeof (data)))
if (copy_from_user...) {
ret = -EFAULT;
goto out;
}Quoted 103 lines
drivers/virt/geniezone/gzvm_vm.c +13
-0+ goto out; + ret =gzvm_irqfd (gzvm, &data); +break ; + }case GZVM_ENABLE_CAP : {struct gzvm_enable_cap cap;@@ -385,6 +394,7 @@ static void gzvm_destroy_vm(struct gzvm *gzvm)mutex_lock (&gzvm->lock); +gzvm_vm_irqfd_release (gzvm);gzvm_destroy_vcpus (gzvm);gzvm_arch_destroy_vm (gzvm->vm_id);@@ -430,6 +440,14 @@ static struct gzvm *gzvm_create_vm(unsigned long vm_type) gzvm->mm = current->mm;mutex_init (&gzvm->lock); + ret =gzvm_vm_irqfd_init (gzvm); +if (ret) { +dev_err (gzvm_debug_dev->this_device, +"Failed to initialize irqfd\n" ); +kfree (gzvm); +return ERR_PTR (ret); + } +mutex_lock (&gzvm_list_lock);list_add (&gzvm->vm_list, &gzvm_list);mutex_unlock (&gzvm_list_lock);include/linux/gzvm_drv.h +27
-0@@ -11,6 +11,7 @@#include <linux/mutex.h> #include <linux/platform_device.h> #include <linux/gzvm.h> +#include <linux/srcu.h> #define MODULE_NAME "gzvm"#define GZVM_VCPU_MMAP_SIZE PAGE_SIZE@@ -26,6 +27,8 @@#define ERR_NOT_SUPPORTED (-24)#define ERR_NOT_IMPLEMENTED (-27)#define ERR_FAULT (-40) +#define GZVM_USERSPACE_IRQ_SOURCE_ID 0 +#define GZVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID 1/** * The following data structures are for data transferring between driver and @@ -69,6 +72,7 @@ struct gzvm_vcpu {/* lock of vcpu*/ struct mutex lock;struct gzvm_vcpu_run *run; +struct gzvm_vcpu_hwstate *hwstate; };struct gzvm {@@ -78,8 +82,23 @@ struct gzvm {struct gzvm_memslot memslot[GZVM_MAX_MEM_REGION ];/* lock for list_add*/ struct mutex lock; + +struct { +/* lock for irqfds list operation */ +spinlock_t lock; +struct list_head items; +struct list_head resampler_list; +/* lock for irqfds resampler */ +struct mutex resampler_lock; + } irqfds; +struct list_head vm_list;gzvm_id_t vm_id; + +struct hlist_head irq_ack_notifier_list; +struct srcu_struct irq_srcu; +/* lock for irq injection */ +struct mutex irq_lock; };long gzvm_dev_ioctl_check_extension (struct gzvm *gzvm,unsigned long args);@@ -113,6 +132,14 @@ int gzvm_arch_create_device(gzvm_id_t vm_id, struct gzvm_create_device *gzvm_devint gzvm_arch_inject_irq (struct gzvm *gzvm,unsigned int vcpu_idx,u32 irq_type,u32 irq,bool level); +void gzvm_notify_acked_irq (struct gzvm *gzvm,unsigned int gsi); +int gzvm_irqfd (struct gzvm *gzvm,struct gzvm_irqfd *args); +int gzvm_drv_irqfd_init (void ); +void gzvm_drv_irqfd_exit (void ); +int gzvm_vm_irqfd_init (struct gzvm *gzvm); +void gzvm_vm_irqfd_release (struct gzvm *gzvm); +void gzvm_sync_hwstate (struct gzvm_vcpu *vcpu); +extern struct miscdevice *gzvm_debug_dev;#endif /* __GZVM_DRV_H__ */ include/uapi/linux/gzvm.h +0
-0
include/uapi/linux/gzvm.h struct gzvm_one_reg { · line 227
Quoted 4 lines
include/uapi/linux/gzvm.h +1
-0@@ -224,4 +224,22 @@ struct gzvm_one_reg {#define GZVM_REG_GENERIC 0x0000000000000000ULL +#define GZVM_IRQFD_FLAG_DEASSIGN (1 << 0)
This is BIT(0)
include/uapi/linux/gzvm.h struct gzvm_one_reg { · line 233
Quoted 6 lines
include/uapi/linux/gzvm.h +6
-0+/** +* GZVM_IRQFD_FLAG_RESAMPLE indicates resamplefd is valid and specifies +* the irqfd to operate in resampling mode for level triggered interrupt +* emulation. +*/ +#define GZVM_IRQFD_FLAG_RESAMPLE (1 << 1)
...and this is BIT(1).
include/uapi/linux/gzvm.h struct gzvm_one_reg { · line 235
Quoted 2 lines
include/uapi/linux/gzvm.h +2
-0+ +struct gzvm_irqfd {
...no documentation?
include/uapi/linux/gzvm.h struct gzvm_one_reg { · line 245
Quoted 10 lines
include/uapi/linux/gzvm.h +9
-0+__u32 fd; +__u32 gsi; +__u32 flags; +__u32 resamplefd; + __u8 pad[16]; +}; + +#define GZVM_IRQFD _IOW(GZVM_IOC_MAGIC, 0x76, struct gzvm_irqfd) +#endif /* __GZVM_H__ */
Regards,
Angelo
A message that is not in the archive (sent off-list or not yet received): [email protected]
Arnd Bergmann
maintainerRe: [PATCH v4 5/9] virt: geniezone: Add irqfd support
Quoted 3 lines · Yi-De Wu (吳一德)
Quoted 3 lines
..snip..
drivers/virt/geniezone/gzvm_main.c > index 230970cb0953..e62c046d76b3 100644 > --- a/drivers/virt/geniezone/gzvm_main.c > +++ b/drivers/virt/geniezone/gzvm_main.c > @@ -113,11 +113,12 @@ static int gzvm_drv_probe(void) > return ret; > gzvm_debug_dev = &gzvm_dev; > > -return 0; > +return gzvm_drv_irqfd_init();
Quoted 1 line
drivers/virt/geniezone/gzvm_main.c > index 230970cb0953..e62c046d76b3 100644 > --- a/drivers/virt/geniezone/gzvm_main.c > +++ b/drivers/virt/geniezone/gzvm_main.c > @@ -113,11 +113,12 @@ static int gzvm_drv_probe(void) > return ret; > gzvm_debug_dev = &gzvm_dev; > > -return 0; > +return gzvm_drv_irqfd_init(); renamed from drivers/virt/geniezone/gzvm_main.c +0
-0ret =
gzvm_drv_irqfd_init(); if (ret) return ret;
Something went wrong with the quoting up here, please make sure to use plaintext email instead of html.
Quoted 9 lines
Quoted 1 line
return 0;
We're wondering the pros and cons for this coding style.
Could you kindly give us some hint for possibly we could miss it somewhere.Some other suggestion had been made by AOSP reviewer on the very line mentioned. As a consequence, we'd like to dig in the rationale behind such debate.
https://android-review.googlesource.com/c/kernel/common/+/2574178/comment/f23bbd52_e3b14396/
I think most developers prefer the shorter form here, and I've seen cleanup patches actually changing the longer version to that.
Arnd
Arnd Bergmann
maintainerRe: [PATCH v4 5/9] virt: geniezone: Add irqfd support
In reply to Yi-De Wuarch/arm64/geniezone/gzvm_arch_common.h static inline gzvm_vcpu_id_t · line 80
Quoted 12 lines · Yi-De Wu
/**
*gzvm_hypercall_wrapper()arch/arm64/geniezone/gzvm_arch_common.h +4
-0@@ -72,6 +73,11 @@ static inline gzvm_vcpu_id_t get_vcpuid_from_tuple(unsigned int tuple) return (gzvm_vcpu_id_t)(tuple & 0xffff); } +struct gzvm_vcpu_hwstate { +__u32 nr_lrs; +__u64 lr[GIC_V3_NR_LRS ]; +};
This is not a good definition for a hardware data structure, as there is architecture specific implicit padding between the two members.
Better add an explicit '__u32 __pad;' in the middle to make it clear what the actual layout is and make it portable.
If this is an interface to the hypervisor, it should probably also use explicit endianess, using __le32 and __le64 instead of __u32 and __u64, along with the corresponding accessors.
Arnd
PATCH v4 6/9 virt: geniezone: Add ioeventfd support
In reply to Yi-De WuFrom: "Yingshiuan Pan" <[email protected]>
Ioeventfd leverages eventfd to provide asynchronous notification mechanism for VMM. VMM can register a mmio address and bind with an eventfd. Once a mmio trap occurs on this registered region, its corresponding eventfd will be notified.
--- drivers/virt/geniezone/Makefile | 2 +- drivers/virt/geniezone/gzvm_ioeventfd.c | 263 ++++++++++++++++++++++++ drivers/virt/geniezone/gzvm_vcpu.c | 27 ++- drivers/virt/geniezone/gzvm_vm.c | 17 ++ include/linux/gzvm_drv.h | 11 + include/uapi/linux/gzvm.h | 23 +++ 6 files changed, 341 insertions(+), 2 deletions(-) create mode 100644 drivers/virt/geniezone/gzvm_ioeventfd.c
drivers/virt/geniezone/Makefile +1 -1
@@ -8,4 +8,4 @@ GZVM_DIR ?= ../../../drivers/virt/geniezone gzvm-y := $(GZVM_DIR)/gzvm_main.o $(GZVM_DIR)/gzvm_vm.o \ $(GZVM_DIR)/gzvm_vcpu.o $(GZVM_DIR)/gzvm_irqchip.o \ - $(GZVM_DIR)/gzvm_irqfd.o + $(GZVM_DIR)/gzvm_irqfd.o $(GZVM_DIR)/gzvm_ioeventfd.o
drivers/virt/geniezone/gzvm_ioeventfd.c new file +263 -0
263 lines not on this page · raw message
drivers/virt/geniezone/gzvm_vcpu.c +26 -1
@@ -49,6 +49,30 @@ static long gzvm_vcpu_update_one_reg(struct gzvm_vcpu *vcpu, void * __user argp,return 0 ; } +/** +* gzvm_vcpu_handle_mmio() - Handle mmio in kernel space. +* @vcpu: Pointer to vcpu. +* +* Return: +* * true - This mmio exit has been processed. +* * false - This mmio exit has not been processed, require userspace. +*/ +static bool gzvm_vcpu_handle_mmio (struct gzvm_vcpu *vcpu) +{ +__u64 addr; +__u32 len; +const void *val_ptr; + +/* So far, we don't have in-kernel mmio read handler */ +if (!vcpu->run->mmio.is_write) +return false; + addr = vcpu->run->mmio.phys_addr; + len = vcpu->run->mmio.size; + val_ptr = &vcpu->run->mmio.data; + +return gzvm_ioevent_write (vcpu, addr, len, val_ptr); +} +/** * gzvm_vcpu_run() - Handle vcpu run ioctl, entry point to guest and exit * point from guest
@@ -70,7 +94,8 @@ static long gzvm_vcpu_run(struct gzvm_vcpu *vcpu, void * __user argp)switch (exit_reason) {case GZVM_EXIT_MMIO : - need_userspace = true; +if (!gzvm_vcpu_handle_mmio (vcpu)) + need_userspace = true;break ;/** * it's geniezone's responsibility to fill corresponding data
drivers/virt/geniezone/gzvm_vm.c +17 -0
@@ -370,6 +370,15 @@ static long gzvm_vm_ioctl(struct file *filp, unsigned int ioctl, ret =gzvm_irqfd (gzvm, &data);break ; } +case GZVM_IOEVENTFD : { +struct gzvm_ioeventfd data; + + ret = -EFAULT ; +if (copy_from_user (&data, argp,sizeof (data))) + goto out; + ret =gzvm_ioeventfd (gzvm, &data); +break ; + }case GZVM_ENABLE_CAP : {struct gzvm_enable_cap cap;
@@ -448,6 +457,14 @@ static struct gzvm *gzvm_create_vm(unsigned long vm_type)return ERR_PTR (ret); } + ret =gzvm_init_ioeventfd (gzvm); +if (ret) { +dev_err (gzvm_debug_dev->this_device, +"Failed to initialize ioeventfd\n" ); +kfree (gzvm); +return ERR_PTR (ret); + } +mutex_lock (&gzvm_list_lock);list_add (&gzvm->vm_list, &gzvm_list);mutex_unlock (&gzvm_list_lock);
include/linux/gzvm_drv.h +11 -0
@@ -6,6 +6,7 @@#ifndef __GZVM_DRV_H__#define __GZVM_DRV_H__ +#include <linux/eventfd.h> #include <linux/list.h> #include <linux/miscdevice.h> #include <linux/mutex.h>
@@ -92,6 +93,8 @@ struct gzvm {struct mutex resampler_lock; } irqfds; +struct list_head ioevents; +struct list_head vm_list;gzvm_id_t vm_id;
@@ -142,4 +145,12 @@ void gzvm_sync_hwstate(struct gzvm_vcpu *vcpu);extern struct miscdevice *gzvm_debug_dev; +int gzvm_init_ioeventfd (struct gzvm *gzvm); +int gzvm_ioeventfd (struct gzvm *gzvm,struct gzvm_ioeventfd *args); +bool gzvm_ioevent_write (struct gzvm_vcpu *vcpu,__u64 addr,int len, +const void *val); +void eventfd_ctx_do_read (struct eventfd_ctx *ctx,__u64 *cnt); +struct vm_area_struct *vma_lookup (struct mm_struct *mm,unsigned long addr); +void add_wait_queue_priority (struct wait_queue_head *wq_head,struct wait_queue_entry *wq_entry); +#endif /* __GZVM_DRV_H__ */
include/uapi/linux/gzvm.h +23 -0
@@ -242,4 +242,27 @@ struct gzvm_irqfd {#define GZVM_IRQFD _IOW(GZVM_IOC_MAGIC, 0x76, struct gzvm_irqfd) +enum { + gzvm_ioeventfd_flag_nr_datamatch, + gzvm_ioeventfd_flag_nr_pio, + gzvm_ioeventfd_flag_nr_deassign, + gzvm_ioeventfd_flag_nr_max, +}; + +#define GZVM_IOEVENTFD_FLAG_DATAMATCH (1 << gzvm_ioeventfd_flag_nr_datamatch) +#define GZVM_IOEVENTFD_FLAG_PIO (1 << gzvm_ioeventfd_flag_nr_pio) +#define GZVM_IOEVENTFD_FLAG_DEASSIGN (1 << gzvm_ioeventfd_flag_nr_deassign) +#define GZVM_IOEVENTFD_VALID_FLAG_MASK ((1 << gzvm_ioeventfd_flag_nr_max) - 1) + +struct gzvm_ioeventfd { +__u64 datamatch; +__u64 addr;/* legal pio/mmio address */ +__u32 len;/* 1, 2, 4, or 8 bytes; or 0 to ignore length */ +__s32 fd; +__u32 flags; +__u8 pad[36 ]; +}; + +#define GZVM_IOEVENTFD _IOW(GZVM_IOC_MAGIC, 0x79, struct gzvm_ioeventfd) +#endif /* __GZVM_H__ */
Signature · 7 lines
2.18.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v4 7/9 virt: geniezone: Add memory region support
In reply to Yi-De WuFrom: "Jerry Wang" <[email protected]>
Hypervisor might need to know the precise purpose of each memory region, so that it can provide specific memory protection. We add a new uapi to pass address and size of a memory region and its purpose.
--- arch/arm64/geniezone/gzvm_arch_common.h | 2 ++ arch/arm64/geniezone/vm.c | 9 +++++++++ drivers/virt/geniezone/gzvm_vm.c | 1 + include/linux/gzvm_drv.h | 2 ++ 4 files changed, 14 insertions(+)
arch/arm64/geniezone/gzvm_arch_common.h +2 -0
@@ -23,6 +23,7 @@ enum {GZVM_FUNC_CREATE_DEVICE ,GZVM_FUNC_PROBE ,GZVM_FUNC_ENABLE_CAP , +GZVM_FUNC_MEMREGION_PURPOSE , NR_GZVM_FUNC };
@@ -46,6 +47,7 @@ enum {#define MT_HVC_GZVM_CREATE_DEVICE GZVM_HCALL_ID(GZVM_FUNC_CREATE_DEVICE)#define MT_HVC_GZVM_PROBE GZVM_HCALL_ID(GZVM_FUNC_PROBE)#define MT_HVC_GZVM_ENABLE_CAP GZVM_HCALL_ID(GZVM_FUNC_ENABLE_CAP) +#define MT_HVC_GZVM_MEMREGION_PURPOSE GZVM_HCALL_ID(GZVM_FUNC_MEMREGION_PURPOSE)#define GIC_V3_NR_LRS 16/**
arch/arm64/geniezone/vm.c +9 -0
@@ -97,6 +97,15 @@ int gzvm_arch_destroy_vm(gzvm_id_t vm_id) 0, 0, &res); } +int gzvm_arch_memregion_purpose (struct gzvm *gzvm,struct gzvm_userspace_memory_region *mem) +{ +struct arm_smccc_res res; + +return gzvm_hypcall_wrapper (MT_HVC_GZVM_MEMREGION_PURPOSE , gzvm->vm_id, + mem->guest_phys_addr, mem->memory_size, + mem->flags,0 ,0 ,0 , &res); +} +static int gzvm_vm_arch_enable_cap (struct gzvm *gzvm,struct gzvm_enable_cap *cap,struct arm_smccc_res *res) {
drivers/virt/geniezone/gzvm_vm.c +1 -0
@@ -248,6 +248,7 @@ gzvm_vm_ioctl_set_memory_region(struct gzvm *gzvm, memslot->vma = vma; memslot->flags = mem->flags; memslot->slot_id = mem->slot; +gzvm_arch_memregion_purpose (gzvm, mem);return register_memslot_addr_range (gzvm, memslot); }
include/linux/gzvm_drv.h +2 -0
@@ -145,6 +145,8 @@ void gzvm_sync_hwstate(struct gzvm_vcpu *vcpu);extern struct miscdevice *gzvm_debug_dev; +int gzvm_arch_memregion_purpose (struct gzvm *gzvm,struct gzvm_userspace_memory_region *mem); +int gzvm_init_ioeventfd (struct gzvm *gzvm);int gzvm_ioeventfd (struct gzvm *gzvm,struct gzvm_ioeventfd *args); bool gzvm_ioevent_write(struct gzvm_vcpu *vcpu, __u64 addr, int len,
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [PATCH v4 7/9] virt: geniezone: Add memory region support
Il 09/06/23 10:52, Yi-De Wu ha scritto:
Quoted 61 lines
From: "Jerry Wang" <[email protected]>
Hypervisor might need to know the precise purpose of each memory region, so that it can provide specific memory protection. We add a new uapi to pass address and size of a memory region and its purpose.
Signed-off-by Jerry Wang <[email protected]>Signed-off-by Liju-clr Chen <[email protected]>Signed-off-by Yi-De Wu <[email protected]>--- arch/arm64/geniezone/gzvm_arch_common.h | 2 ++ arch/arm64/geniezone/vm.c | 9 +++++++++ drivers/virt/geniezone/gzvm_vm.c | 1 + include/linux/gzvm_drv.h | 2 ++ 4 files changed, 14 insertions(+)arch/arm64/geniezone/gzvm_arch_common.h +2
-0@@ -23,6 +23,7 @@ enum {GZVM_FUNC_CREATE_DEVICE ,GZVM_FUNC_PROBE ,GZVM_FUNC_ENABLE_CAP , +GZVM_FUNC_MEMREGION_PURPOSE , NR_GZVM_FUNC };@@ -46,6 +47,7 @@ enum {#define MT_HVC_GZVM_CREATE_DEVICE GZVM_HCALL_ID(GZVM_FUNC_CREATE_DEVICE)#define MT_HVC_GZVM_PROBE GZVM_HCALL_ID(GZVM_FUNC_PROBE)#define MT_HVC_GZVM_ENABLE_CAP GZVM_HCALL_ID(GZVM_FUNC_ENABLE_CAP) +#define MT_HVC_GZVM_MEMREGION_PURPOSE GZVM_HCALL_ID(GZVM_FUNC_MEMREGION_PURPOSE)#define GIC_V3_NR_LRS 16/** arch/arm64/geniezone/vm.c +9
-0@@ -97,6 +97,15 @@ int gzvm_arch_destroy_vm(gzvm_id_t vm_id) 0, 0, &res); } +int gzvm_arch_memregion_purpose (struct gzvm *gzvm,struct gzvm_userspace_memory_region *mem) +{ +struct arm_smccc_res res; + +return gzvm_hypcall_wrapper (MT_HVC_GZVM_MEMREGION_PURPOSE , gzvm->vm_id, + mem->guest_phys_addr, mem->memory_size, + mem->flags,0 ,0 ,0 , &res); +} +static int gzvm_vm_arch_enable_cap (struct gzvm *gzvm,struct gzvm_enable_cap *cap,struct arm_smccc_res *res) {drivers/virt/geniezone/gzvm_vm.c +0
-0
drivers/virt/geniezone/gzvm_vm.c gzvm_vm_ioctl_set_memory_region(struct gzvm *gzvm, · line 251
Quoted 4 lines
drivers/virt/geniezone/gzvm_vm.c +1
-0@@ -248,6 +248,7 @@ gzvm_vm_ioctl_set_memory_region(struct gzvm *gzvm, memslot->vma = vma; memslot->flags = mem->flags; memslot->slot_id = mem->slot; +gzvm_arch_memregion_purpose (gzvm, mem);
ret = gzvm_arch_memregion_purpose(...)
if (ret)
......
drivers/virt/geniezone/gzvm_vm.c gzvm_vm_ioctl_set_memory_region(struct gzvm *gzvm, · line 254
Quoted 3 lines
drivers/virt/geniezone/gzvm_vm.c +0
-0return register_memslot_addr_range (gzvm, memslot); }
Regards,
Angelo
PATCH v4 8/9 virt: geniezone: Add dtb config support
In reply to Yi-De WuFrom: "Jerry Wang" <[email protected]>
Hypervisor might need to know the accurate address and size of dtb passed from userspace. And then hypervisor would parse the dtb and get vm information.
--- arch/arm64/geniezone/gzvm_arch_common.h | 2 ++ arch/arm64/geniezone/vm.c | 8 ++++++++ drivers/virt/geniezone/gzvm_vm.c | 8 ++++++++ include/linux/gzvm_drv.h | 1 + include/uapi/linux/gzvm.h | 10 ++++++++++ 5 files changed, 29 insertions(+)
arch/arm64/geniezone/gzvm_arch_common.h +2 -0
@@ -24,6 +24,7 @@ enum {GZVM_FUNC_PROBE ,GZVM_FUNC_ENABLE_CAP ,GZVM_FUNC_MEMREGION_PURPOSE , +GZVM_FUNC_SET_DTB_CONFIG , NR_GZVM_FUNC };
@@ -48,6 +49,7 @@ enum {#define MT_HVC_GZVM_PROBE GZVM_HCALL_ID(GZVM_FUNC_PROBE)#define MT_HVC_GZVM_ENABLE_CAP GZVM_HCALL_ID(GZVM_FUNC_ENABLE_CAP)#define MT_HVC_GZVM_MEMREGION_PURPOSE GZVM_HCALL_ID(GZVM_FUNC_MEMREGION_PURPOSE) +#define MT_HVC_GZVM_SET_DTB_CONFIG GZVM_HCALL_ID(GZVM_FUNC_SET_DTB_CONFIG)#define GIC_V3_NR_LRS 16/**
arch/arm64/geniezone/vm.c +8 -0
@@ -106,6 +106,14 @@ int gzvm_arch_memregion_purpose(struct gzvm *gzvm, struct gzvm_userspace_memory_ mem->flags, 0, 0, 0, &res); } +int gzvm_arch_set_dtb_config (struct gzvm *gzvm,struct gzvm_dtb_config *cfg) +{ +struct arm_smccc_res res; + +return gzvm_hypcall_wrapper (MT_HVC_GZVM_SET_DTB_CONFIG , gzvm->vm_id, cfg->dtb_addr, + cfg->dtb_size,0 ,0 ,0 ,0 , &res); +} +static int gzvm_vm_arch_enable_cap (struct gzvm *gzvm,struct gzvm_enable_cap *cap,struct arm_smccc_res *res) {
drivers/virt/geniezone/gzvm_vm.c +8 -0
@@ -390,6 +390,14 @@ static long gzvm_vm_ioctl(struct file *filp, unsigned int ioctl, ret =gzvm_vm_ioctl_enable_cap (gzvm, &cap, argp);break ; } +case GZVM_SET_DTB_CONFIG : { +struct gzvm_dtb_config cfg; + +if (copy_from_user (&cfg, argp,sizeof (cfg))) + goto out; + ret =gzvm_arch_set_dtb_config (gzvm, &cfg); +break ; + }default : ret = -ENOTTY ; }
include/linux/gzvm_drv.h +1 -0
@@ -146,6 +146,7 @@ void gzvm_sync_hwstate(struct gzvm_vcpu *vcpu);extern struct miscdevice *gzvm_debug_dev;int gzvm_arch_memregion_purpose (struct gzvm *gzvm,struct gzvm_userspace_memory_region *mem); +int gzvm_arch_set_dtb_config (struct gzvm *gzvm,struct gzvm_dtb_config *args);int gzvm_init_ioeventfd (struct gzvm *gzvm);int gzvm_ioeventfd (struct gzvm *gzvm,struct gzvm_ioeventfd *args);
include/uapi/linux/gzvm.h +10 -0
@@ -265,4 +265,14 @@ struct gzvm_ioeventfd {#define GZVM_IOEVENTFD _IOW(GZVM_IOC_MAGIC, 0x79, struct gzvm_ioeventfd) +struct gzvm_dtb_config { +/* dtb address set by VMM (guset memory) */ +__u64 dtb_addr; +/* dtb size */ +__u64 dtb_size; +}; + +#define GZVM_SET_DTB_CONFIG _IOW(GZVM_IOC_MAGIC, 0xff, \ + struct gzvm_dtb_config) +#endif /* __GZVM_H__ */
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [PATCH v4 8/9] virt: geniezone: Add dtb config support
Il 09/06/23 10:52, Yi-De Wu ha scritto:
Quoted 92 lines
From: "Jerry Wang" <[email protected]>
Hypervisor might need to know the accurate address and size of dtb passed from userspace. And then hypervisor would parse the dtb and get vm information.
Signed-off-by Jerry Wang <[email protected]>Signed-off-by Liju-clr Chen <[email protected]>Signed-off-by Yi-De Wu <[email protected]>--- arch/arm64/geniezone/gzvm_arch_common.h | 2 ++ arch/arm64/geniezone/vm.c | 8 ++++++++ drivers/virt/geniezone/gzvm_vm.c | 8 ++++++++ include/linux/gzvm_drv.h | 1 + include/uapi/linux/gzvm.h | 10 ++++++++++ 5 files changed, 29 insertions(+)arch/arm64/geniezone/gzvm_arch_common.h +2
-0@@ -24,6 +24,7 @@ enum {GZVM_FUNC_PROBE ,GZVM_FUNC_ENABLE_CAP ,GZVM_FUNC_MEMREGION_PURPOSE , +GZVM_FUNC_SET_DTB_CONFIG , NR_GZVM_FUNC };@@ -48,6 +49,7 @@ enum {#define MT_HVC_GZVM_PROBE GZVM_HCALL_ID(GZVM_FUNC_PROBE)#define MT_HVC_GZVM_ENABLE_CAP GZVM_HCALL_ID(GZVM_FUNC_ENABLE_CAP)#define MT_HVC_GZVM_MEMREGION_PURPOSE GZVM_HCALL_ID(GZVM_FUNC_MEMREGION_PURPOSE) +#define MT_HVC_GZVM_SET_DTB_CONFIG GZVM_HCALL_ID(GZVM_FUNC_SET_DTB_CONFIG)#define GIC_V3_NR_LRS 16/** arch/arm64/geniezone/vm.c +8
-0@@ -106,6 +106,14 @@ int gzvm_arch_memregion_purpose(struct gzvm *gzvm, struct gzvm_userspace_memory_ mem->flags, 0, 0, 0, &res); } +int gzvm_arch_set_dtb_config (struct gzvm *gzvm,struct gzvm_dtb_config *cfg) +{ +struct arm_smccc_res res; + +return gzvm_hypcall_wrapper (MT_HVC_GZVM_SET_DTB_CONFIG , gzvm->vm_id, cfg->dtb_addr, + cfg->dtb_size,0 ,0 ,0 ,0 , &res); +} +static int gzvm_vm_arch_enable_cap (struct gzvm *gzvm,struct gzvm_enable_cap *cap,struct arm_smccc_res *res) {drivers/virt/geniezone/gzvm_vm.c +8
-0@@ -390,6 +390,14 @@ static long gzvm_vm_ioctl(struct file *filp, unsigned int ioctl, ret =gzvm_vm_ioctl_enable_cap (gzvm, &cap, argp);break ; } +case GZVM_SET_DTB_CONFIG : { +struct gzvm_dtb_config cfg; + +if (copy_from_user (&cfg, argp,sizeof (cfg))) + goto out; + ret =gzvm_arch_set_dtb_config (gzvm, &cfg); +break ; + }default : ret = -ENOTTY ; }include/linux/gzvm_drv.h +1
-0@@ -146,6 +146,7 @@ void gzvm_sync_hwstate(struct gzvm_vcpu *vcpu);extern struct miscdevice *gzvm_debug_dev;int gzvm_arch_memregion_purpose (struct gzvm *gzvm,struct gzvm_userspace_memory_region *mem); +int gzvm_arch_set_dtb_config (struct gzvm *gzvm,struct gzvm_dtb_config *args);int gzvm_init_ioeventfd (struct gzvm *gzvm);int gzvm_ioeventfd (struct gzvm *gzvm,struct gzvm_ioeventfd *args);include/uapi/linux/gzvm.h +0
-0
include/uapi/linux/gzvm.h struct gzvm_ioeventfd { · line 268
Quoted 4 lines
include/uapi/linux/gzvm.h +1
-0@@ -265,4 +265,14 @@ struct gzvm_ioeventfd {#define GZVM_IOEVENTFD _IOW(GZVM_IOC_MAGIC, 0x79, struct gzvm_ioeventfd) +struct gzvm_dtb_config {
kerneldoc please.
Quoted 10 lines
include/uapi/linux/gzvm.h +9
-0+/* dtb address set by VMM (guset memory) */ +__u64 dtb_addr; +/* dtb size */ + __u64 dtb_size; +}; + +#define GZVM_SET_DTB_CONFIG _IOW(GZVM_IOC_MAGIC, 0xff, \ + struct gzvm_dtb_config) +#endif /* __GZVM_H__ */
PATCH v4 9/9 virt: geniezone: Add virtual timer support
In reply to Yi-De WuFrom: "Willix Yeh" <[email protected]>
Implement vtimer migration handler.
- Using hrtimer for guest vtimer migration
- Identify migrate flag to do register hrtimer
--- arch/arm64/geniezone/gzvm_arch_common.h | 2 ++ arch/arm64/geniezone/vcpu.c | 40 +++++++++++++++++++++++++ drivers/virt/geniezone/gzvm_vcpu.c | 34 +++++++++++++++++++++ drivers/virt/geniezone/gzvm_vm.c | 10 +++++++ include/linux/gzvm_drv.h | 9 ++++++ include/uapi/linux/gzvm.h | 2 ++ 6 files changed, 97 insertions(+)
arch/arm64/geniezone/gzvm_arch_common.h +2 -0
@@ -80,6 +80,8 @@ static inline gzvm_vcpu_id_t get_vcpuid_from_tuple(unsigned int tuple)struct gzvm_vcpu_hwstate {__u32 nr_lrs;__u64 lr[GIC_V3_NR_LRS ]; +__u64 vtimer_delay; +__u32 vtimer_migrate; }; static inline unsigned int
arch/arm64/geniezone/vcpu.c +40 -0
@@ -4,6 +4,7 @@*/ #include <linux/arm-smccc.h> +#include <linux/clocksource.h> #include <linux/err.h> #include <linux/uaccess.h>
@@ -40,15 +41,54 @@ int gzvm_arch_vcpu_update_one_reg(struct gzvm_vcpu *vcpu, __u64 reg_id,return ret; } +static void clear_migrate_state (struct gzvm_vcpu *vcpu) +{ + vcpu->hwstate->vtimer_migrate =0 ; + vcpu->hwstate->vtimer_delay =0 ; +} + +static u64 gzvm_mtimer_delay_time (u64 delay) +{ +u64 ns; + + ns =clocksource_cyc2ns (delay, timecycle.mult, timecycle.shift); + +return ns; +} + +static void gzvm_mtimer_release (struct gzvm_vcpu *vcpu) +{ +hrtimer_cancel (&vcpu->gzvm_mtimer); + +clear_migrate_state (vcpu); +} + +static void gzvm_mtimer_catch (struct hrtimer *hrt,u64 delay) +{ +u64 ns; + + ns =gzvm_mtimer_delay_time (delay); +hrtimer_start (hrt,ktime_add_ns (ktime_get (), ns),HRTIMER_MODE_ABS_HARD ); +} +int gzvm_arch_vcpu_run (struct gzvm_vcpu *vcpu,__u64 *exit_reason) {struct arm_smccc_res res;unsigned long a1;int ret; +/* hrtimer cancel and clear migrate state */ +if (vcpu->hwstate->vtimer_migrate) +gzvm_mtimer_release (vcpu); + a1 =assemble_vm_vcpu_tuple (vcpu->gzvm->vm_id, vcpu->vcpuid); ret =gzvm_hypcall_wrapper (MT_HVC_GZVM_RUN , a1,0 ,0 ,0 ,0 ,0 ,0 , &res); + +/* hrtimer register if migration needed */ +if (vcpu->hwstate->vtimer_migrate) +gzvm_mtimer_catch (&vcpu->gzvm_mtimer, vcpu->hwstate->vtimer_delay); + *exit_reason = res.a1;return ret; }
drivers/virt/geniezone/gzvm_vcpu.c +34 -0
@@ -5,12 +5,14 @@#include <asm/sysreg.h> #include <linux/anon_inodes.h> +#include <linux/clocksource.h> #include <linux/device.h> #include <linux/file.h> #include <linux/mm.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/gzvm_drv.h> +#include "gzvm_common.h" /* maximum size needed for holding an integer */ #define ITOA_MAX_LEN 12
@@ -73,6 +75,33 @@ static bool gzvm_vcpu_handle_mmio(struct gzvm_vcpu *vcpu)return gzvm_ioevent_write (vcpu, addr, len, val_ptr); } +static void mtimer_irq_forward (struct gzvm_vcpu *vcpu) +{ +struct gzvm *gzvm; +unsigned int irq_num, irq_type, vcpu_idx; + + gzvm = vcpu->gzvm; + + irq_num = (GZVM_VTIMER_IRQ >>GZVM_IRQ_NUM_SHIFT ) &GZVM_IRQ_NUM_MASK ; + irq_type = (GZVM_VTIMER_IRQ >>GZVM_IRQ_TYPE_SHIFT ) &GZVM_IRQ_TYPE_MASK ; + vcpu_idx = (GZVM_VTIMER_IRQ >>GZVM_IRQ_VCPU_SHIFT ) &GZVM_IRQ_VCPU_MASK ; + vcpu_idx += ((GZVM_VTIMER_IRQ >>GZVM_IRQ_VCPU2_SHIFT ) &GZVM_IRQ_VCPU2_MASK ) * + (GZVM_IRQ_VCPU_MASK +1 ); + +gzvm_irqchip_inject_irq (gzvm, vcpu_idx, irq_type, irq_num,1 ); +} + +static enum hrtimer_restart gzvm_mtimer_expire (struct hrtimer *hrt) +{ +struct gzvm_vcpu *vcpu; + + vcpu = container_of(hrt, struct gzvm_vcpu, gzvm_mtimer); + +mtimer_irq_forward (vcpu); + +return HRTIMER_NORESTART ; +} +/** * gzvm_vcpu_run() - Handle vcpu run ioctl, entry point to guest and exit * point from guest
@@ -172,6 +201,7 @@ static void gzvm_destroy_vcpu(struct gzvm_vcpu *vcpu)if (!vcpu)return ; +hrtimer_cancel (&vcpu->gzvm_mtimer);gzvm_arch_destroy_vcpu (vcpu->gzvm->vm_id, vcpu->vcpuid);/* clean guest's data */ memset (vcpu->run,0 ,GZVM_VCPU_RUN_MAP_SIZE );
@@ -241,6 +271,10 @@ int gzvm_vm_ioctl_create_vcpu(struct gzvm *gzvm, u32 cpuid) vcpu->gzvm = gzvm;mutex_init (&vcpu->lock); +/* gzvm_mtimer init based on hrtimer */ +hrtimer_init (&vcpu->gzvm_mtimer,CLOCK_MONOTONIC ,HRTIMER_MODE_ABS_HARD ); + vcpu->gzvm_mtimer.function = gzvm_mtimer_expire; + ret =gzvm_arch_create_vcpu (gzvm->vm_id, vcpu->vcpuid, vcpu->run);if (ret <0 ) goto free_vcpu_run;
drivers/virt/geniezone/gzvm_vm.c +10 -0
@@ -4,6 +4,7 @@*/ #include <linux/anon_inodes.h> +#include <linux/clocksource.h> #include <linux/file.h> #include <linux/kdev_t.h> #include <linux/miscdevice.h>
@@ -17,6 +18,8 @@static DEFINE_MUTEX (gzvm_list_lock);static LIST_HEAD (gzvm_list); +struct timecycle timecycle; +/** * hva_to_pa_fast() - converts hva to pa in generic fast way *
@@ -474,6 +477,13 @@ static struct gzvm *gzvm_create_vm(unsigned long vm_type)return ERR_PTR (ret); } +/* timecycle init mult shift */ +clocks_calc_mult_shift (&timecycle.mult, + &timecycle.shift, +arch_timer_get_cntfrq (), +NSEC_PER_SEC , +10 ); +mutex_lock (&gzvm_list_lock);list_add (&gzvm->vm_list, &gzvm_list);mutex_unlock (&gzvm_list_lock);
include/linux/gzvm_drv.h +9 -0
@@ -6,6 +6,7 @@#ifndef __GZVM_DRV_H__#define __GZVM_DRV_H__ +#include <asm/arch_timer.h> #include <linux/eventfd.h> #include <linux/list.h> #include <linux/miscdevice.h>
@@ -40,6 +41,13 @@#define GZVM_VCPU_RUN_MAP_SIZE (PAGE_SIZE * 2) +struct timecycle { +u32 mult; +u32 shift; +}; + +extern struct timecycle timecycle; +/* struct mem_region_addr_range - Identical to ffa memory constituent */ struct mem_region_addr_range {/* the base IPA of the constituent memory region, aligned to 4 kiB */
@@ -74,6 +82,7 @@ struct gzvm_vcpu {struct mutex lock;struct gzvm_vcpu_run *run;struct gzvm_vcpu_hwstate *hwstate; +struct hrtimer gzvm_mtimer; };struct gzvm {
include/uapi/linux/gzvm.h +2 -0
@@ -61,6 +61,8 @@ struct gzvm_userspace_memory_region {#define GZVM_SET_USER_MEMORY_REGION _IOW(GZVM_IOC_MAGIC, 0x46, \ struct gzvm_userspace_memory_region) +#define GZVM_VTIMER_IRQ 27 +/* for GZVM_IRQ_LINE, irq field index values */ #define GZVM_IRQ_VCPU2_SHIFT 28#define GZVM_IRQ_VCPU2_MASK 0xf
Signature · 1 line
2.18.0