Skip to contentSkip to conversation

GenieZone hypervisor drivers

PATCH Superseded Yi-De Wu 8 participants 39 messages Apr 28, 2023 – Jun 26, 2023

Subsystems (5)

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Yi-De Wu

author
#0 lore raw

v2 cover GenieZone hypervisor drivers

This series is based on linux-next, tag: next-20230427.

Changes in v2:
- Refactor: move to drivers/virt/geniezone
- Refactor: decouple arch-dependent and arch-independent
- Check pending signal before entering guest context
- Fix reviewer's comments

Yi-De Wu (7):
docs: geniezone: Introduce GenieZone hypervisor
dt-bindings: hypervisor: Add MediaTek GenieZone hypervisor
virt: geniezone: Introduce 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

 .../hypervisor/mediatek,geniezone-hyp.yaml    |  31 +
 Documentation/virt/geniezone/introduction.rst |  34 ++
 MAINTAINERS                                   |  13 +
 arch/arm64/Kbuild                             |   1 +
 arch/arm64/geniezone/Makefile                 |   9 +
 arch/arm64/geniezone/gzvm_arch.c              | 280 +++++++++
 arch/arm64/geniezone/gzvm_arch.h              |  92 +++
 arch/arm64/geniezone/gzvm_irqchip.c           | 108 ++++
 arch/arm64/include/uapi/asm/gzvm_arch.h       |  47 ++
 drivers/virt/Kconfig                          |   2 +
 drivers/virt/geniezone/Kconfig                |  17 +
 drivers/virt/geniezone/Makefile               |  12 +
 drivers/virt/geniezone/gzvm_ioeventfd.c       | 263 +++++++++
 drivers/virt/geniezone/gzvm_irqfd.c           | 536 ++++++++++++++++++
 drivers/virt/geniezone/gzvm_main.c            | 151 +++++
 drivers/virt/geniezone/gzvm_vcpu.c            | 260 +++++++++
 drivers/virt/geniezone/gzvm_vm.c              | 447 +++++++++++++++
 include/linux/gzvm_drv.h                      | 154 +++++
 include/uapi/asm-generic/gzvm_arch.h          |  10 +
 include/uapi/linux/gzvm.h                     | 274 +++++++++
 20 files changed, 2741 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hypervisor/mediatek,
 geniezone-hyp.yaml
 create mode 100644 Documentation/virt/geniezone/introduction.rst
 create mode 100644 arch/arm64/geniezone/Makefile
 create mode 100644 arch/arm64/geniezone/gzvm_arch.c
 create mode 100644 arch/arm64/geniezone/gzvm_arch.h
 create mode 100644 arch/arm64/geniezone/gzvm_irqchip.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_ioeventfd.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
author
#1 lore raw

PATCH v2 1/7 docs: geniezone: Introduce GenieZone hypervisor

From: "Yingshiuan Pan" <[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 | 34 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++++
 2 files changed, 40 insertions(+)
 create mode 100644 Documentation/virt/geniezone/introduction.rst
Documentation/virt/geniezone/introduction.rst new file +34 -0
new file mode 100644
index 000000000000..1fffd6cbb4db
@@ -0,0 +1,34 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+======================
+GenieZone Introduction
+======================
+
+
+Overview
+========
+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.
+
+To enable guest VMs running, a driver (gzvm) is provided for VMM (virtual
+machine monitor) to operate. Currently, the gzvm driver supports only crosvm.
+
+
+Supported Architecture
+======================
+GenieZone now only supports MediaTek arm64 SoC.
+
+
+Platform Virtualization
+=======================
+We leverages arm64's timer virtualization and gic virtualization for timer and
+interrupts controller.
+
+
+Device Virtualizaton
+====================
+We adopts VMM's virtio devices emulations by passing io trap to VMM, and virtio
+is a well-known and widely used virtual device implementation.
+
MAINTAINERS +6 -0
index 4b8971cba764..db8915114b86 100644
@@ -8694,6 +8694,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
#2 lore raw

Re: [PATCH v2 1/7] docs: geniezone: Introduce GenieZone hypervisor

Hi!

Documentation/virt/geniezone/introduction.rst line 27

Quoted 12 lines

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.

+++ b/Documentation/virt/geniezone/introduction.rst

Documentation/virt/geniezone/introduction.rst new file +4 -0
@@ -0,0 +1,34 @@
 
+Platform Virtualization
+=======================
+We leverages arm64's timer virtualization and gic virtualization for timer and
+interrupts controller.

'interrupt'.

Quoted 4 lines
Documentation/virt/geniezone/introduction.rst new file +3 -0
+Device Virtualizaton
+====================
+We adopts VMM's virtio devices emulations by passing io trap to

VMM, and virtio

'adopt', 'device emulation'

Documentation/virt/geniezone/introduction.rst line 34

Quoted 2 lines
Documentation/virt/geniezone/introduction.rst new file +2 -0
+is a well-known and widely used virtual device implementation.
+

Plus, I'd expect documentation to be more detailed or have pointer where
to learn more.

BR, Pavel

#3 lore raw

Re: [PATCH v2 1/7] docs: geniezone: Introduce GenieZone hypervisor

Quoted 6 lines · Pavel Machek

External email : Please do not click links or open attachments until you have verified the sender or the content.

Hi!

Quoted 17 lines
Quoted 12 lines

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.
+++ b/Documentation/virt/geniezone/introduction.rst

Documentation/virt/geniezone/introduction.rst new file +3 -0
@@ -0,0 +1,34 @@
+Platform Virtualization
+=======================
+We leverages arm64's timer virtualization and gic virtualization
Quoted 2 lines

for timer and
+interrupts controller.

'interrupt'.

Noted.

Quoted 7 lines
Quoted 4 lines
Documentation/virt/geniezone/introduction.rst new file +3 -0
+Device Virtualizaton
+====================
+We adopts VMM's virtio devices emulations by passing io trap to

VMM, and virtio

'adopt', 'device emulation'

Noted.

Quoted 10 lines

Documentation/virt/geniezone/introduction.rst line 34

Quoted 2 lines
Documentation/virt/geniezone/introduction.rst new file +2 -0
+is a well-known and widely used virtual device implementation.
+

Plus, I'd expect documentation to be more detailed or have pointer where
to learn more.

BR, Pavel

--

Sure, we tend to enumerate the high-level features of GenieZone and the design considerations of each module on the next version of our documentation.

author
#4 lore raw

PATCH v2 2/7 dt-bindings: hypervisor: Add MediaTek GenieZone hypervisor

In reply to Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Add documentation for GenieZone(gzvm) node. This node informs gzvm driver to start probing if geniezone hypervisor is available and able to do virtual machine operations.

---
 .../hypervisor/mediatek,geniezone-hyp.yaml    | 31 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hypervisor/mediatek,geniezone-hyp.yaml
Documentation/devicetree/bindings/hypervisor/mediatek,geniezone-hyp.yaml new file +31 -0
new file mode 100644
index 000000000000..9dc0831cf175
@@ -0,0 +1,31 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hypervisor/mediatek,gzvm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek GenieZone hypervisor
+
+maintainers:
+  - Yingshiuan Pan <[email protected]>
+
+description:
+  This interface is designed for integrating GenieZone hypervisor into Android
+  Virtualization Framework(AVF) along with Crosvm as a VMM.
+  It acts like a wrapper for every hypercalls to GenieZone hypervisor in
+  order to control guest VM lifecycles and virtual interrupt injections.
+
+properties:
+  compatible:
+    const: mediatek,geniezone-hyp
+
+required:
+  - compatible
+
+additionalProperties: false
+
+examples:
+  - |
+    hypervisor {
+        compatible = "mediatek,geniezone-hyp";
+    };
MAINTAINERS +1 -0
index db8915114b86..1e911d1d9741 100644
@@ -8698,6 +8698,7 @@ GENIEZONE HYPERVISOR DRIVER
 M:	Yingshiuan Pan <[email protected]>
 M:	Ze-Yu Wang <[email protected]>
 M:	Yi-De Wu <[email protected]>
+F:	Documentation/devicetree/bindings/hypervisor/mediatek,geniezone-hyp.yaml
 F:	Documentation/virt/geniezone/
 
 GENWQE (IBM Generic Workqueue Card)
Signature · 1 line
2.18.0
maintainer
#5 lore raw

Re: [PATCH v2 2/7] dt-bindings: hypervisor: Add MediaTek GenieZone hypervisor

Quoted 6 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Add documentation for GenieZone(gzvm) node. This node informs gzvm driver to start probing if geniezone hypervisor is available and able to do virtual machine operations.

Quoted 8 lines
---
 .../hypervisor/mediatek,geniezone-hyp.yaml    | 31 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hypervisor/mediatek,geniezone-hyp.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
./Documentation/devicetree/bindings/hypervisor/mediatek,geniezone-hyp.yaml: $id: relative path/filename doesn't match actual path or filename
expected: http://devicetree.org/schemas/hypervisor/mediatek,geniezone-hyp.yaml#

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

#6 lore raw

Re: [PATCH v2 2/7] dt-bindings: hypervisor: Add MediaTek GenieZone hypervisor

Quoted 50 lines · Rob Herring

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 8 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Add documentation for GenieZone(gzvm) node. This node informs gzvm driver to start probing if geniezone hypervisor is available and able to do virtual machine operations.

Quoted 9 lines
---
 .../hypervisor/mediatek,geniezone-hyp.yaml    | 31
+++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 32 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/hypervisor/mediatek,geniezone- hyp.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
./Documentation/devicetree/bindings/hypervisor/mediatek,geniezone- hyp.yaml: $id: relative path/filename doesn't match actual path or filename
expected:
https://urldefense.com/v3/__http://devicetree.org/schemas/hypervisor/mediatek,geniezone-hyp.yaml*__;Iw!!CTRNKA9wMg0ARbw!joIOXbICM7UGvy3XBEJvfzSKO7s61efB87_NX5cqpUqpu5ot5cuzw50A8-8ledZT9_7ifsB2sKzxSD0$

doc reference errors (make refcheckdocs):

See
https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

Quoted 9 lines

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.

Noted, we've run the yaml check and we are going to re-submit the latest version in v3.

#7 lore raw

Re: [PATCH v2 2/7] dt-bindings: hypervisor: Add MediaTek GenieZone hypervisor

Quoted 63 lines · Yi-De Wu (吳一德)
Quoted 49 lines · Rob Herring

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 8 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Add documentation for GenieZone(gzvm) node. This node informs gzvm driver to start probing if geniezone hypervisor is available and able to do virtual machine operations.

Quoted 9 lines
---
 .../hypervisor/mediatek,geniezone-hyp.yaml    | 31
+++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 32 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/hypervisor/mediatek,geniezone- hyp.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
./Documentation/devicetree/bindings/hypervisor/mediatek,geniezone- hyp.yaml: $id: relative path/filename doesn't match actual path or filename
expected:
https://urldefense.com/v3/__http://devicetree.org/schemas/hypervisor/mediatek,geniezone-hyp.yaml*__;Iw!!CTRNKA9wMg0ARbw!joIOXbICM7UGvy3XBEJvfzSKO7s61efB87_NX5cqpUqpu5ot5cuzw50A8-8ledZT9_7ifsB2sKzxSD0$

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

Quoted 9 lines

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.

Noted, we've run the yaml check and we are going to re-submit the latest version in v3.

Quoted 12 lines

************* MEDIATEK Confidentiality Notice ******************** The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!

Do you want us to reply w/ such a big confidentiality notice?

#8 lore raw

Re: [PATCH v2 2/7] dt-bindings: hypervisor: Add MediaTek GenieZone hypervisor

Quoted 4 lines · Trilok Soni

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 43 lines
Quoted 42 lines · Yi-De Wu (吳一德)
Quoted 41 lines · Rob Herring

External email : Please do not click links or open attachments until
you have verified the sender or the content.

Quoted 16 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Add documentation for GenieZone(gzvm) node. This node informs gzvm
driver to start probing if geniezone hypervisor is available and
able to do virtual machine operations.

---
 .../hypervisor/mediatek,geniezone-hyp.yaml    | 31
+++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 32 insertions(+)
 create mode 100644
Quoted 4 lines

Documentation/devicetree/bindings/hypervisor/mediatek,geniezone -
hyp.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
./Documentation/devicetree/bindings/hypervisor/mediatek,geniezone -
hyp.yaml: $id: relative path/filename doesn't match actual path or
filename
expected:

https://urldefense.com/v3/__http://devicetree.org/schemas/hypervisor/mediatek,geniezone-hyp.yaml*__;Iw!!CTRNKA9wMg0ARbw!joIOXbICM7UGvy3XBEJvfzSKO7s61efB87_NX5cqpUqpu5ot5cuzw50A8-8ledZT9_7ifsB2sKzxSD0$

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

doc reference errors (make refcheckdocs):

See

https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

Quoted 48 lines
Quoted 39 lines
Quoted 14 lines

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up
to
date:

pip3 install dtschema --upgrade

Quoted 9 lines

Please check and re-submit after running the above command yourself.
Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your
schema.

Noted, we've run the yaml check and we are going to re-submit the latest version in v3.

************* MEDIATEK Confidentiality Notice ******************** The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise
exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination,
distribution, printing, retaining or copying of this e-mail (including its
attachments) by unintended recipient(s) is strictly prohibited and may
be unlawful. If you are not an intended recipient of this e-mail,

Quoted 8 lines

or believe
that you have received this e-mail in error, please notify the sender
immediately (by replying to this e-mail), delete any and all copies of
this e-mail (including any attachments) from your system, and do not
disclose the content of this e-mail to any other person. Thank you!

Quoted 2 lines

Do you want us to reply w/ such a big confidentiality notice?

My apology to this mistake, our mail server wasn't configured properly. We've added all related mailing list to our disclaimer-free bypassing list to prevent such issues from happening again.

maintainer
#9 lore raw

Re: [PATCH v2 2/7] dt-bindings: hypervisor: Add MediaTek GenieZone hypervisor

In reply to Yi-De Wu
Quoted 5 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Add documentation for GenieZone(gzvm) node. This node informs gzvm driver to start probing if geniezone hypervisor is available and able to do virtual machine operations.

Why can't the driver just try and do virtual machine operations to see if the hypervisor is there? IOW, make your software interfaces discoverable. DT is for non-discoverable hardware.

Rob

#10 lore raw

Re: [PATCH v2 2/7] dt-bindings: hypervisor: Add MediaTek GenieZone hypervisor

Quoted 11 lines · Rob Herring

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 5 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Add documentation for GenieZone(gzvm) node. This node informs gzvm driver to start probing if geniezone hypervisor is available and able to do virtual machine operations.

Quoted 6 lines

Why can't the driver just try and do virtual machine operations to see
if the hypervisor is there? IOW, make your software interfaces discoverable. DT is for non-discoverable hardware.

Rob

Can do, our hypervisor is discoverable through invoking probing hypercall, and we use the device tree to prevent unnecessary module loading on all systems.

#11 lore raw

Re: [PATCH v2 2/7] dt-bindings: hypervisor: Add MediaTek GenieZone hypervisor

Quoted 17 lines · Yi-De Wu (吳一德)
Quoted 16 lines · Rob Herring

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 5 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Add documentation for GenieZone(gzvm) node. This node informs gzvm driver to start probing if geniezone hypervisor is available and able to do virtual machine operations.

Why can't the driver just try and do virtual machine operations to see
if the hypervisor is there? IOW, make your software interfaces discoverable. DT is for non-discoverable hardware.

Quoted 5 lines
Quoted 1 line

Rob

Can do, our hypervisor is discoverable through invoking probing hypercall, and we use the device tree to prevent unnecessary module loading on all systems.

Please do not wait until immediately prior to submitting version N+1 before replying to any of the comments on version N.
This creates a confusing scenario, where some review comments may be missed due to parallel discussion.

Thanks,
Conor.

#12 lore raw

Re: [PATCH v2 2/7] dt-bindings: hypervisor: Add MediaTek GenieZone hypervisor

Quoted 28 lines · Conor Dooley
Quoted 21 lines · Yi-De Wu (吳一德)
Quoted 20 lines · Rob Herring

External email : Please do not click links or open attachments until
you have verified the sender or the content.

Quoted 7 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Add documentation for GenieZone(gzvm) node. This node informs gzvm
driver to start probing if geniezone hypervisor is available and
able to do virtual machine operations.

Why can't the driver just try and do virtual machine operations to
see
if the hypervisor is there? IOW, make your software interfaces discoverable. DT is for non-discoverable hardware.

Quoted 5 lines
Quoted 1 line

Rob

Can do, our hypervisor is discoverable through invoking probing hypercall, and we use the device tree to prevent unnecessary module loading on all systems.

Quoted 8 lines

Please do not wait until immediately prior to submitting version N+1 before replying to any of the comments on version N.
This creates a confusing scenario, where some review comments may be missed due to parallel discussion.

Thanks,
Conor.

Noted, we would stop updating newer version until there's some consensus to do so.

#13 lore raw

Re: [PATCH v2 2/7] dt-bindings: hypervisor: Add MediaTek GenieZone hypervisor

In reply to Yi-De Wu (吳一德)
Quoted 19 lines · Yi-De Wu
Quoted 18 lines · Rob Herring

External email : Please do not click links or open attachments until
you have verified the sender or the content.

Quoted 6 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Add documentation for GenieZone(gzvm) node. This node informs gzvm
driver to start probing if geniezone hypervisor is available and able to do virtual machine operations.

Why can't the driver just try and do virtual machine operations to see
if the hypervisor is there? IOW, make your software interfaces discoverable. DT is for non-discoverable hardware.

Quoted 5 lines
Quoted 1 line

Rob

Can do, our hypervisor is discoverable through invoking probing hypercall, and we use the device tree to prevent unnecessary module loading on all systems.

hi Rob,

We'd like to continue with the argument whether to use dt here. As per our previous discussion, we knew that dt is for non-discoverable hardware. However, probing on all devices could possibly raise the worries about polluting other users with redundant system overhead in our v4 patches[1].

Are there any concerns from your side if we were to take the dt back in v5 patches and keep it as simple as possible just to initialize our hypervisor exclusively? Something similar to what we proposed before[2].

Reference:
[1]
https://lore.kernel.org/lkml/[email protected]/
[2]
https://android-review.googlesource.com/c/kernel/common/+/2447547/1..2/drivers/virt/geniezone/gzvm_main.c#b112

Regards,
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#14 lore raw

PATCH v2 3/7 virt: geniezone: Introduce GenieZone hypervisor support

In reply to 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.

---
 MAINTAINERS                             |   6 +
 arch/arm64/Kbuild                       |   1 +
 arch/arm64/geniezone/Makefile           |   9 +
 arch/arm64/geniezone/gzvm_arch.c        | 189 +++++++++++++
 arch/arm64/geniezone/gzvm_arch.h        |  50 ++++
 arch/arm64/include/uapi/asm/gzvm_arch.h |  18 ++
 drivers/virt/Kconfig                    |   2 +
 drivers/virt/geniezone/Kconfig          |  17 ++
 drivers/virt/geniezone/Makefile         |  10 +
 drivers/virt/geniezone/gzvm_main.c      | 146 ++++++++++
 drivers/virt/geniezone/gzvm_vm.c        | 336 ++++++++++++++++++++++++
 include/linux/gzvm_drv.h                |  98 +++++++
 include/uapi/asm-generic/gzvm_arch.h    |  10 +
 include/uapi/linux/gzvm.h               |  99 +++++++
 14 files changed, 991 insertions(+)
 create mode 100644 arch/arm64/geniezone/Makefile
 create mode 100644 arch/arm64/geniezone/gzvm_arch.c
 create mode 100644 arch/arm64/geniezone/gzvm_arch.h
 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
index 1e911d1d9741..09a8ccf77b01 100644
@@ -8700,6 +8700,12 @@ M:	Ze-Yu Wang <[email protected]>
 M:	Yi-De Wu <[email protected]>
 F:	Documentation/devicetree/bindings/hypervisor/mediatek,geniezone-hyp.yaml
 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
index 5bfbf7d79c99..0c3cca572919 100644
@@ -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
new file mode 100644
index 000000000000..5720c076d73c
@@ -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 += gzvm_arch.o
+
+obj-$(CONFIG_MTK_GZVM) += gzvm.o
arch/arm64/geniezone/gzvm_arch.c new file +189 -0

189 lines not on this page · raw message

arch/arm64/geniezone/gzvm_arch.h new file +50 -0

50 lines not on this page · raw message

arch/arm64/include/uapi/asm/gzvm_arch.h new file +18 -0
new file mode 100644
index 000000000000..e7927f3dcb11
@@ -0,0 +1,18 @@
+/* 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
+
+#endif /* __GZVM_ARCH_H__ */
drivers/virt/Kconfig +2 -0
index f79ab13a5c28..9bbf0bdf672c 100644
@@ -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 +17 -0
new file mode 100644
index 000000000000..6fad3c30f8d9
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config MTK_GZVM
+	tristate "GenieZone Hypervisor driver for guest VM operation"
+	depends on ARM64
+	depends on KVM
+	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
new file mode 100644
index 000000000000..066efddc0b9c
@@ -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 +146 -0

146 lines not on this page · raw message

drivers/virt/geniezone/gzvm_vm.c new file +336 -0

336 lines not on this page · raw message

include/linux/gzvm_drv.h new file +98 -0

98 lines not on this page · raw message

include/uapi/asm-generic/gzvm_arch.h new file +10 -0
new file mode 100644
index 000000000000..c4cc12716c91
@@ -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 +99 -0

99 lines not on this page · raw message

Signature · 1 line
2.18.0
#15 lore raw

Re: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support

kernel test robot noticed the following build errors:

Hi Yi-De,

kernel test robot noticed the following build errors:

[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on robh/for-next arnd-asm-generic/master linus/master v6.3 next-20230427] [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/20230428-183738
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
patch link:    https://lore.kernel.org/r/20230428103622.18291-4-yi-de.wu%40mediatek.com
patch subject: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support
config: x86_64-randconfig-a004 (https://download.01.org/0day-ci/archive/20230429/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/0e3f05a6e4547eb309032d047115a47d8f59641d
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Yi-De-Wu/docs-geniezone-Introduce-GenieZone-hypervisor/20230428-183738
        git checkout 0e3f05a6e4547eb309032d047115a47d8f59641d
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 olddefconfig
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> usr/include/linux/gzvm.h:15: included file 'asm-x86/gzvm_arch.h' is not exported
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#16 lore raw

Re: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support

In reply to Yi-De Wu
kernel test robot noticed the following build errors:

Hi Yi-De,

kernel test robot noticed the following build errors:

[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on robh/for-next arnd-asm-generic/master linus/master v6.3 next-20230427] [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/20230428-183738
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
patch link:    https://lore.kernel.org/r/20230428103622.18291-4-yi-de.wu%40mediatek.com
patch subject: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support
config: x86_64-randconfig-a016 (https://download.01.org/0day-ci/archive/20230429/[email protected]/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/0e3f05a6e4547eb309032d047115a47d8f59641d
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yi-De-Wu/docs-geniezone-Introduce-GenieZone-hypervisor/20230428-183738 git checkout 0e3f05a6e4547eb309032d047115a47d8f59641d
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> usr/include/linux/gzvm.h:15: included file 'asm-x86/gzvm_arch.h' is not exported
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#17 lore raw

Re: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support

In reply to Yi-De Wu
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 robh/for-next arnd-asm-generic/master linus/master v6.3 next-20230428] [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/20230428-183738
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
patch link:    https://lore.kernel.org/r/20230428103622.18291-4-yi-de.wu%40mediatek.com
patch subject: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support
config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20230429/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 12.1.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/0e3f05a6e4547eb309032d047115a47d8f59641d
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yi-De-Wu/docs-geniezone-Introduce-GenieZone-hypervisor/20230428-183738
git checkout 0e3f05a6e4547eb309032d047115a47d8f59641d
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/geniezone/ drivers/virt/geniezone/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> arch/arm64/geniezone/gzvm_arch.c:112:5: warning: no previous prototype for 'gzvm_vm_arch_enable_cap' [-Wmissing-prototypes]

112 | int gzvm_vm_arch_enable_cap(struct gzvm *gzvm, struct gzvm_enable_cap *cap,
| ^~~~~~~~~~~~~~~~~~~~~~~
--
arch/arm64/geniezone/gzvm_arch.c:24: warning: Function parameter or member 'a0' not described in 'gzvm_hypcall_wrapper' arch/arm64/geniezone/gzvm_arch.c:24: warning: Function parameter or member 'a1' not described in 'gzvm_hypcall_wrapper' arch/arm64/geniezone/gzvm_arch.c:24: warning: Function parameter or member 'a2' not described in 'gzvm_hypcall_wrapper' arch/arm64/geniezone/gzvm_arch.c:24: warning: Function parameter or member 'a3' not described in 'gzvm_hypcall_wrapper' arch/arm64/geniezone/gzvm_arch.c:24: warning: Function parameter or member 'a4' not described in 'gzvm_hypcall_wrapper' arch/arm64/geniezone/gzvm_arch.c:24: warning: Function parameter or member 'a5' not described in 'gzvm_hypcall_wrapper' arch/arm64/geniezone/gzvm_arch.c:24: warning: Function parameter or member 'a6' not described in 'gzvm_hypcall_wrapper' arch/arm64/geniezone/gzvm_arch.c:24: warning: Function parameter or member 'a7' not described in 'gzvm_hypcall_wrapper' arch/arm64/geniezone/gzvm_arch.c:24: warning: Function parameter or member 'res' not described in 'gzvm_hypcall_wrapper'

>> arch/arm64/geniezone/gzvm_arch.c:24: warning: expecting prototype for geniezone_hypercall_wrapper(). Prototype was for gzvm_hypcall_wrapper() instead

arch/arm64/geniezone/gzvm_arch.c:133: warning: Function parameter or member 'gzvm' not described in 'gzvm_vm_ioctl_get_pvmfw_size' arch/arm64/geniezone/gzvm_arch.c:133: warning: Function parameter or member 'cap' not described in 'gzvm_vm_ioctl_get_pvmfw_size' arch/arm64/geniezone/gzvm_arch.c:133: warning: Function parameter or member 'argp' not described in 'gzvm_vm_ioctl_get_pvmfw_size' arch/arm64/geniezone/gzvm_arch.c:155: warning: Function parameter or member 'gzvm' not described in 'gzvm_vm_ioctl_cap_pvm' arch/arm64/geniezone/gzvm_arch.c:155: warning: Function parameter or member 'cap' not described in 'gzvm_vm_ioctl_cap_pvm' arch/arm64/geniezone/gzvm_arch.c:155: warning: Function parameter or member 'argp' not described in 'gzvm_vm_ioctl_cap_pvm'

vim +/gzvm_vm_arch_enable_cap +112 arch/arm64/geniezone/gzvm_arch.c

    13	
    14	/**
    15	 * geniezone_hypercall_wrapper()
    16	 *
    17	 * Return: The wrapper helps caller to convert geniezone errno to Linux errno.
    18	 */
    19	static int gzvm_hypcall_wrapper(unsigned long a0, unsigned long a1,
    20					unsigned long a2, unsigned long a3,
    21					unsigned long a4, unsigned long a5,
    22					unsigned long a6, unsigned long a7,
    23					struct arm_smccc_res *res)
  > 24	{
    25		arm_smccc_hvc(a0, a1, a2, a3, a4, a5, a6, a7, res);
    26		return gz_err_to_errno(res->a0);
    27	}
    28	
    29	int gzvm_arch_probe(void)
    30	{
    31		struct arm_smccc_res res;
    32	
    33		arm_smccc_hvc(MT_HVC_GZVM_PROBE, 0, 0, 0, 0, 0, 0, 0, &res);
    34		if (res.a0 == 0)
    35			return 0;
    36	
    37		return -ENXIO;
    38	}
    39	
    40	int gzvm_arch_set_memregion(gzvm_id_t vm_id, size_t buf_size,
    41				    phys_addr_t region)
    42	{
    43		struct arm_smccc_res res;
    44	
    45		return gzvm_hypcall_wrapper(MT_HVC_GZVM_SET_MEMREGION, vm_id,
    46					    buf_size, region, 0, 0, 0, 0, &res);
    47	}
    48	
    49	static int gzvm_cap_arm_vm_ipa_size(void __user *argp)
    50	{
    51		__u64 value = CONFIG_ARM64_PA_BITS;
    52	
    53		if (copy_to_user(argp, &value, sizeof(__u64)))
    54			return -EFAULT;
    55	
    56		return 0;
    57	}
    58	
    59	int gzvm_arch_check_extension(struct gzvm *gzvm, __u64 cap, void __user *argp)
    60	{
    61		int ret = -EOPNOTSUPP;
    62	
    63		switch (cap) {
    64		case GZVM_CAP_ARM_PROTECTED_VM: {
    65			__u64 success = 1;
    66	
    67			if (copy_to_user(argp, &success, sizeof(__u64)))
    68				return -EFAULT;
    69			ret = 0;
    70			break;
    71		}
    72		case GZVM_CAP_ARM_VM_IPA_SIZE: {
    73			ret = gzvm_cap_arm_vm_ipa_size(argp);
    74			break;
    75		}
    76		default:
    77			ret = -EOPNOTSUPP;
    78		}
    79	
    80		return ret;
    81	}
    82	
    83	/**
    84	 * gzvm_arch_create_vm()
    85	 *
    86	 * Return:
    87	 * * positive value	- VM ID
    88	 * * -ENOMEM		- Memory not enough for storing VM data
    89	 */
    90	int gzvm_arch_create_vm(void)
    91	{
    92		struct arm_smccc_res res;
    93		int ret;
    94	
    95		ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_CREATE_VM, 0, 0, 0, 0, 0, 0, 0,
    96					   &res);
    97	
    98		if (ret == 0)
    99			return res.a1;
   100		else
   101			return ret;
   102	}
   103	
   104	int gzvm_arch_destroy_vm(gzvm_id_t vm_id)
   105	{
   106		struct arm_smccc_res res;
   107	
   108		return gzvm_hypcall_wrapper(MT_HVC_GZVM_DESTROY_VM, vm_id, 0, 0, 0, 0,
   109					    0, 0, &res);
   110	}
   111	
 > 112	int gzvm_vm_arch_enable_cap(struct gzvm *gzvm, struct gzvm_enable_cap *cap,
   113				    struct arm_smccc_res *res)
   114	{
   115		return gzvm_hypcall_wrapper(MT_HVC_GZVM_ENABLE_CAP, gzvm->vm_id,
   116					   cap->cap, cap->args[0], cap->args[1],
   117					   cap->args[2], cap->args[3], cap->args[4],
   118					   res);

119 }
120

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#18 lore raw

Re: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support

In reply to Yi-De Wu
Quoted 387 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.

---
 MAINTAINERS                             |   6 +
 arch/arm64/Kbuild                       |   1 +
 arch/arm64/geniezone/Makefile           |   9 +
 arch/arm64/geniezone/gzvm_arch.c        | 189 +++++++++++++
 arch/arm64/geniezone/gzvm_arch.h        |  50 ++++
 arch/arm64/include/uapi/asm/gzvm_arch.h |  18 ++
 drivers/virt/Kconfig                    |   2 +
 drivers/virt/geniezone/Kconfig          |  17 ++
 drivers/virt/geniezone/Makefile         |  10 +
 drivers/virt/geniezone/gzvm_main.c      | 146 ++++++++++
 drivers/virt/geniezone/gzvm_vm.c        | 336 ++++++++++++++++++++++++
 include/linux/gzvm_drv.h                |  98 +++++++
 include/uapi/asm-generic/gzvm_arch.h    |  10 +
 include/uapi/linux/gzvm.h               |  99 +++++++
 14 files changed, 991 insertions(+)
 create mode 100644 arch/arm64/geniezone/Makefile
 create mode 100644 arch/arm64/geniezone/gzvm_arch.c
 create mode 100644 arch/arm64/geniezone/gzvm_arch.h
 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 +0 -0
index 1e911d1d9741..09a8ccf77b01 100644
@@ -8700,6 +8700,12 @@ M:	Ze-Yu Wang <[email protected]>
 M:	Yi-De Wu <[email protected]>
 

F: Documentation/devicetree/bindings/hypervisor/mediatek,geniezone-hyp.yaml
F: Documentation/virt/geniezone/

MAINTAINERS +6 -0
+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
index 5bfbf7d79c99..0c3cca572919 100644
@@ -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 +3 -0
new file mode 100644
index 000000000000..5720c076d73c
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Main Makefile for gzvm, this one includes 

drivers/virt/geniezone/Makefile

arch/arm64/geniezone/Makefile new file +6 -0
+#
+include $(srctree)/drivers/virt/geniezone/Makefile
+
+gzvm-y += gzvm_arch.o
+
+obj-$(CONFIG_MTK_GZVM) += gzvm.o
arch/arm64/geniezone/gzvm_arch.c new file +17 -0
new file mode 100644
index 000000000000..2fc76f7d440f
@@ -0,0 +1,189 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#include <linux/arm-smccc.h>
+#include <linux/err.h>
+#include <linux/uaccess.h>
+
+#include <linux/gzvm.h>
+#include <linux/gzvm_drv.h>
+#include "gzvm_arch.h"
+
+/**
+ * geniezone_hypercall_wrapper()
+ *
+ * Return: The wrapper helps caller to convert geniezone errno to 

Linux errno.
+ */

arch/arm64/geniezone/gzvm_arch.c new file +41 -0
+static int gzvm_hypcall_wrapper(unsigned long a0, unsigned long a1,
+				unsigned long a2, unsigned long a3,
+				unsigned long a4, unsigned long a5,
+				unsigned long a6, unsigned long a7,
+				struct arm_smccc_res *res)
+{
+	arm_smccc_hvc(a0, a1, a2, a3, a4, a5, a6, a7, res);
+	return gz_err_to_errno(res->a0);
+}
+
+int gzvm_arch_probe(void)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_hvc(MT_HVC_GZVM_PROBE, 0, 0, 0, 0, 0, 0, 0, &res);
+	if (res.a0 == 0)
+		return 0;
+
+	return -ENXIO;
+}
+
+int gzvm_arch_set_memregion(gzvm_id_t vm_id, size_t buf_size,
+			    phys_addr_t region)
+{
+	struct arm_smccc_res res;
+
+	return gzvm_hypcall_wrapper(MT_HVC_GZVM_SET_MEMREGION, vm_id,
+				    buf_size, region, 0, 0, 0, 0, &res);
+}
+
+static int gzvm_cap_arm_vm_ipa_size(void __user *argp)
+{
+	__u64 value = CONFIG_ARM64_PA_BITS;
+
+	if (copy_to_user(argp, &value, sizeof(__u64)))
+		return -EFAULT;
+
+	return 0;
+}
+
+int gzvm_arch_check_extension(struct gzvm *gzvm, __u64 cap, void 

__user *argp)

arch/arm64/geniezone/gzvm_arch.c new file +36 -0
+{
+	int ret = -EOPNOTSUPP;
+
+	switch (cap) {
+	case GZVM_CAP_ARM_PROTECTED_VM: {
+		__u64 success = 1;
+
+		if (copy_to_user(argp, &success, sizeof(__u64)))
+			return -EFAULT;
+		ret = 0;
+		break;
+	}
+	case GZVM_CAP_ARM_VM_IPA_SIZE: {
+		ret = gzvm_cap_arm_vm_ipa_size(argp);
+		break;
+	}
+	default:
+		ret = -EOPNOTSUPP;
+	}
+
+	return ret;
+}
+
+/**
+ * gzvm_arch_create_vm()
+ *
+ * Return:
+ * * positive value	- VM ID
+ * * -ENOMEM		- Memory not enough for storing VM data
+ */
+int gzvm_arch_create_vm(void)
+{
+	struct arm_smccc_res res;
+	int ret;
+
+	ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_CREATE_VM, 0, 0, 0, 0, 0, 0, 

0,

arch/arm64/geniezone/gzvm_arch.c new file +13 -0
+				   &res);
+
+	if (ret == 0)
+		return res.a1;
+	else
+		return ret;
+}
+
+int gzvm_arch_destroy_vm(gzvm_id_t vm_id)
+{
+	struct arm_smccc_res res;
+
+	return gzvm_hypcall_wrapper(MT_HVC_GZVM_DESTROY_VM, vm_id, 0, 0, 0, 

0,

arch/arm64/geniezone/gzvm_arch.c new file +4 -0
+				    0, 0, &res);
+}
+
+int gzvm_vm_arch_enable_cap(struct gzvm *gzvm, struct gzvm_enable_cap 

*cap,

arch/arm64/geniezone/gzvm_arch.c new file +10 -0
+			    struct arm_smccc_res *res)
+{
+	return gzvm_hypcall_wrapper(MT_HVC_GZVM_ENABLE_CAP, gzvm->vm_id,
+				   cap->cap, cap->args[0], cap->args[1],
+				   cap->args[2], cap->args[3], cap->args[4],
+				   res);
+}
+
+/**
+ * gzvm_vm_ioctl_get_pvmfw_size() - Get pvmfw size from hypervisor, 

return
+ * in x1, and return to userspace in args.
+ *
+ * Return:
+ * * 0 - Succeed
+ * * -EINVAL - Hypervisor return invalid results
+ * * -EFAULT - Fail to copy back to userspace buffer
+ */

arch/arm64/geniezone/gzvm_arch.c new file +18 -0
+static int gzvm_vm_ioctl_get_pvmfw_size(struct gzvm *gzvm,
+					struct gzvm_enable_cap *cap,
+					void __user *argp)
+{
+	struct arm_smccc_res res = {0};
+
+	if (gzvm_vm_arch_enable_cap(gzvm, cap, &res) != 0)
+		return -EINVAL;
+
+	cap->args[1] = res.a1;
+	if (copy_to_user(argp, cap, sizeof(*cap)))
+		return -EFAULT;
+
+	return 0;
+}
+
+/**
+ * gzvm_vm_ioctl_cap_pvm() - Proceed GZVM_CAP_ARM_PROTECTED_VM's 

subcommands
+ *
+ * Return:
+ * * 0 - Succeed
+ * * -EINVAL - Invalid subcommand or arguments
+ */
+static int gzvm_vm_ioctl_cap_pvm(struct gzvm *gzvm, struct gzvm_enable_cap *cap,

arch/arm64/geniezone/gzvm_arch.c new file +21 -0
+				 void __user *argp)
+{
+	int ret = -EINVAL;
+	struct arm_smccc_res res = {0};
+
+	switch (cap->args[0]) {
+	case GZVM_CAP_ARM_PVM_SET_PVMFW_IPA:
+		ret = gzvm_vm_arch_enable_cap(gzvm, cap, &res);
+		break;
+	case GZVM_CAP_ARM_PVM_GET_PVMFW_SIZE:
+		ret = gzvm_vm_ioctl_get_pvmfw_size(gzvm, cap, argp);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	return ret;
+}
+
+int gzvm_vm_ioctl_arch_enable_cap(struct gzvm *gzvm, struct

gzvm_enable_cap *cap,

arch/arm64/geniezone/gzvm_arch.c new file +15 -0
+				  void __user *argp)
+{
+	int ret = -EINVAL;
+
+	switch (cap->cap) {
+	case GZVM_CAP_ARM_PROTECTED_VM:
+		ret = gzvm_vm_ioctl_cap_pvm(gzvm, cap, argp);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	return ret;
+}
arch/arm64/geniezone/gzvm_arch.h new file +39 -0
new file mode 100644
index 000000000000..dd0b7b5f7c65
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#ifndef __GZ_ARCH_H__
+#define __GZ_ARCH_H__
+
+#include <linux/arm-smccc.h>
+
+enum {
+	GZVM_FUNC_CREATE_VM = 0,
+	GZVM_FUNC_DESTROY_VM,
+	GZVM_FUNC_CREATE_VCPU,
+	GZVM_FUNC_DESTROY_VCPU,
+	GZVM_FUNC_SET_MEMREGION,
+	GZVM_FUNC_RUN,
+	GZVM_FUNC_GET_REGS,
+	GZVM_FUNC_SET_REGS,
+	GZVM_FUNC_GET_ONE_REG,
+	GZVM_FUNC_SET_ONE_REG,
+	GZVM_FUNC_IRQ_LINE,
+	GZVM_FUNC_CREATE_DEVICE,
+	GZVM_FUNC_PROBE,
+	GZVM_FUNC_ENABLE_CAP,
+	NR_GZVM_FUNC
+};
+
+#define SMC_ENTITY_MTK			59
+#define GZVM_FUNCID_START		(0x1000)
+#define GZVM_HCALL_ID(func)						\
+	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32,	\
+			   SMC_ENTITY_MTK, (GZVM_FUNCID_START + (func)))
+
+#define MT_HVC_GZVM_CREATE_VM		GZVM_HCALL_ID(GZVM_FUNC_CREATE_VM)
+#define MT_HVC_GZVM_DESTROY_VM		GZVM_HCALL_ID(GZVM_FUNC_DESTROY_VM)
+#define MT_HVC_GZVM_CREATE_VCPU		GZVM_HCALL_ID(GZVM_FUNC_CREATE_VCPU)
+#define MT_HVC_GZVM_DESTROY_VCPU	GZVM_HCALL_ID(GZVM_FUNC_DESTROY_VCPU)
+#define 

MT_HVC_GZVM_SET_MEMREGION GZVM_HCALL_ID(GZVM_FUNC_SET_MEMREGION)

arch/arm64/geniezone/gzvm_arch.h new file +7 -0
+#define MT_HVC_GZVM_RUN			GZVM_HCALL_ID(GZVM_FUNC_RUN)
+#define MT_HVC_GZVM_GET_REGS		GZVM_HCALL_ID(GZVM_FUNC_GET_REGS)
+#define MT_HVC_GZVM_SET_REGS		GZVM_HCALL_ID(GZVM_FUNC_SET_REGS)
+#define MT_HVC_GZVM_GET_ONE_REG		GZVM_HCALL_ID(GZVM_FUNC_GET_ONE_REG)
+#define MT_HVC_GZVM_SET_ONE_REG		GZVM_HCALL_ID(GZVM_FUNC_SET_ONE_REG)
+#define MT_HVC_GZVM_IRQ_LINE		GZVM_HCALL_ID(GZVM_FUNC_IRQ_LINE)
+#define 

MT_HVC_GZVM_CREATE_DEVICE GZVM_HCALL_ID(GZVM_FUNC_CREATE_DEVICE)

arch/arm64/geniezone/gzvm_arch.h new file +4 -0
+#define MT_HVC_GZVM_PROBE		GZVM_HCALL_ID(GZVM_FUNC_PROBE)
+#define MT_HVC_GZVM_ENABLE_CAP		GZVM_HCALL_ID(GZVM_FUNC_ENABLE_CAP)
+
+#endif /* __GZVM_ARCH_H__ */
arch/arm64/include/uapi/asm/gzvm_arch.h new file +18 -0
new file mode 100644
index 000000000000..e7927f3dcb11
@@ -0,0 +1,18 @@
+/* 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
+
+#endif /* __GZVM_ARCH_H__ */
drivers/virt/Kconfig +2 -0
index f79ab13a5c28..9bbf0bdf672c 100644
@@ -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 +0 -0
new file mode 100644
index 000000000000..6fad3c30f8d9

drivers/virt/geniezone/Kconfig line 6

Quoted 6 lines
drivers/virt/geniezone/Kconfig new file +6 -0
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config MTK_GZVM
+	tristate "GenieZone Hypervisor driver for guest VM operation"
+	depends on ARM64
+	depends on KVM

NAK.

Either this is KVM, and this code serves no purpose, or it is a standalone hypervisor, and it *cannot* have a dependency on KVM.

[...]

Quoted 20 lines
drivers/virt/geniezone/Kconfig new file +2 -0
+/**
+ * gzvm_gfn_to_pfn_memslot() - Translate gfn (guest ipa) to pfn (host 

pa),
+ * result is in @pfn
+ *
+ * Leverage KVM's gfn_to_pfn_memslot(). Because gfn_to_pfn_memslot() needs
+ * kvm_memory_slot as parameter, this function populates necessary fileds
+ * for calling gfn_to_pfn_memslot().
+ *
+ * Return:
+ * * 0 - Succeed
+ * * -EFAULT - Failed to convert
+ */
+static int gzvm_gfn_to_pfn_memslot(struct gzvm_memslot *memslot, u64 gfn, u64 *pfn)

drivers/virt/geniezone/Kconfig new file +3 -0
+{
+	hfn_t __pfn;
+	struct kvm_memory_slot kvm_slot = {0};

drivers/virt/geniezone/Kconfig

Quoted 10 lines
drivers/virt/geniezone/Kconfig new file +10 -0
+
+	kvm_slot.base_gfn = memslot->base_gfn;
+	kvm_slot.npages = memslot->npages;
+	kvm_slot.dirty_bitmap = NULL;
+	kvm_slot.userspace_addr = memslot->userspace_addr;
+	kvm_slot.flags = memslot->flags;
+	kvm_slot.id = memslot->slot_id;
+	kvm_slot.as_id = 0;
+
+	__pfn = gfn_to_pfn_memslot(&kvm_slot, gfn);

Again, I absolutely oppose this horror. This is internal to KVM, and we want to be able to change this without having to mess with your own code that we cannot test anyway.

What if we start using the extra fields that you don't populate as they mean nothing to you? Or add a backpointer to the kvm structure to do fancy accounting?

You have your own hypervisor, that's well and good. Since your main argument is that it is supposed to be standalone, make it *really* standalone and don't use KVM as a prop.

Thanks,

        M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#19 lore raw

Re: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support

Hi Marc,

Quoted 38 lines

[...]

Quoted 20 lines

+/**
+ * gzvm_gfn_to_pfn_memslot() - Translate gfn (guest ipa) to pfn (host pa),
+ *                   result is in @pfn
+ *
+ * Leverage KVM's gfn_to_pfn_memslot(). Because gfn_to_pfn_memslot() needs
+ * kvm_memory_slot as parameter, this function populates necessary fileds
+ * for calling gfn_to_pfn_memslot().
+ *
+ * Return:
+ * * 0            - Succeed
+ * * -EFAULT        - Failed to convert
+ */
+static int gzvm_gfn_to_pfn_memslot(struct gzvm_memslot *memslot, u64 gfn, u64 *pfn)

drivers/virt/geniezone/gzvm_vm.c new file +3 -0
+{
+    hfn_t __pfn;
+    struct kvm_memory_slot kvm_slot = {0};

drivers/virt/geniezone/gzvm_vm.c line 43

Quoted 10 lines
drivers/virt/geniezone/gzvm_vm.c new file +10 -0
+
+    kvm_slot.base_gfn = memslot->base_gfn;
+    kvm_slot.npages = memslot->npages;
+    kvm_slot.dirty_bitmap = NULL;
+    kvm_slot.userspace_addr = memslot->userspace_addr;
+    kvm_slot.flags = memslot->flags;
+    kvm_slot.id = memslot->slot_id;
+    kvm_slot.as_id = 0;
+
+    __pfn = gfn_to_pfn_memslot(&kvm_slot, gfn);

Again, I absolutely oppose this horror. This is internal to KVM, and we want to be able to change this without having to mess with your own code that we cannot test anyway.

Quoted 7 lines

What if we start using the extra fields that you don't populate as they mean nothing to you? Or add a backpointer to the kvm structure to do fancy accounting?

You have your own hypervisor, that's well and good. Since your main argument is that it is supposed to be standalone, make it *really* standalone and don't use KVM as a prop.

Agreed, same comments were made earlier too. I would prefer that GenieZone have its own identify rather than sharing the APIs/data-structures here.

---Trilok Soni

#20 lore raw

Re: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support

Quoted 57 lines · Trilok Soni

External email : Please do not click links or open attachments until you have verified the sender or the content.

Hi Marc,

Quoted 42 lines

[...]

Quoted 24 lines

+/**
+ * gzvm_gfn_to_pfn_memslot() - Translate gfn (guest ipa) to pfn (host
pa),
+ * result is in @pfn
+ *
+ * Leverage KVM's gfn_to_pfn_memslot(). Because gfn_to_pfn_memslot()
needs
+ * kvm_memory_slot as parameter, this function populates necessary
fileds
+ * for calling gfn_to_pfn_memslot().
+ *
+ * Return:
+ * * 0 - Succeed
+ * * -EFAULT - Failed to convert
+ */
+static int gzvm_gfn_to_pfn_memslot(struct gzvm_memslot *memslot, u64
gfn, u64 *pfn)

drivers/virt/geniezone/gzvm_vm.c new file +3 -0
+{
+    hfn_t __pfn;
+    struct kvm_memory_slot kvm_slot = {0};

drivers/virt/geniezone/gzvm_vm.c line 43

Quoted 10 lines
drivers/virt/geniezone/gzvm_vm.c new file +10 -0
+
+    kvm_slot.base_gfn = memslot->base_gfn;
+    kvm_slot.npages = memslot->npages;
+    kvm_slot.dirty_bitmap = NULL;
+    kvm_slot.userspace_addr = memslot->userspace_addr;
+    kvm_slot.flags = memslot->flags;
+    kvm_slot.id = memslot->slot_id;
+    kvm_slot.as_id = 0;
+
+    __pfn = gfn_to_pfn_memslot(&kvm_slot, gfn);

Again, I absolutely oppose this horror. This is internal to KVM, and we want to be able to change this without having to mess with your own code that we cannot test anyway.

Quoted 7 lines

What if we start using the extra fields that you don't populate as they mean nothing to you? Or add a backpointer to the kvm structure to do fancy accounting?

You have your own hypervisor, that's well and good. Since your main argument is that it is supposed to be standalone, make it *really* standalone and don't use KVM as a prop.

Quoted 5 lines

Agreed, same comments were made earlier too. I would prefer that GenieZone have its own identify rather than sharing the APIs/data-structures here.

---Trilok Soni

Same with previous discussion, we'd like to copy or rename the related part from KVM and keep the maintainance at our own if it's ok.

#21 lore raw

Re: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support

In reply to Marc Zyngier
Quoted 441 lines · Marc Zyngier

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 427 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.

---
 MAINTAINERS                             |   6 +
 arch/arm64/Kbuild                       |   1 +
 arch/arm64/geniezone/Makefile           |   9 +
 arch/arm64/geniezone/gzvm_arch.c        | 189 +++++++++++++
 arch/arm64/geniezone/gzvm_arch.h        |  50 ++++
 arch/arm64/include/uapi/asm/gzvm_arch.h |  18 ++
 drivers/virt/Kconfig                    |   2 +
 drivers/virt/geniezone/Kconfig          |  17 ++
 drivers/virt/geniezone/Makefile         |  10 +
 drivers/virt/geniezone/gzvm_main.c      | 146 ++++++++++
 drivers/virt/geniezone/gzvm_vm.c        | 336
++++++++++++++++++++++++
 include/linux/gzvm_drv.h                |  98 +++++++
 include/uapi/asm-generic/gzvm_arch.h    |  10 +
 include/uapi/linux/gzvm.h               |  99 +++++++
 14 files changed, 991 insertions(+)
 create mode 100644 arch/arm64/geniezone/Makefile
 create mode 100644 arch/arm64/geniezone/gzvm_arch.c
 create mode 100644 arch/arm64/geniezone/gzvm_arch.h
 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 +0 -0
index 1e911d1d9741..09a8ccf77b01 100644
@@ -8700,6 +8700,12 @@ M:     Ze-Yu Wang <[email protected]>
 M:   Yi-De Wu <[email protected]>
 

F: Documentation/devicetree/bindings/hypervisor/mediatek,geniezo
ne-hyp.yaml
F: Documentation/virt/geniezone/

MAINTAINERS +6 -0
+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
index 5bfbf7d79c99..0c3cca572919 100644
@@ -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 +3 -0
new file mode 100644
index 000000000000..5720c076d73c
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Main Makefile for gzvm, this one includes

drivers/virt/geniezone/Makefile

arch/arm64/geniezone/Makefile new file +6 -0
+#
+include $(srctree)/drivers/virt/geniezone/Makefile
+
+gzvm-y += gzvm_arch.o
+
+obj-$(CONFIG_MTK_GZVM) += gzvm.o
arch/arm64/geniezone/gzvm_arch.c new file +17 -0
new file mode 100644
index 000000000000..2fc76f7d440f
@@ -0,0 +1,189 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#include <linux/arm-smccc.h>
+#include <linux/err.h>
+#include <linux/uaccess.h>
+
+#include <linux/gzvm.h>
+#include <linux/gzvm_drv.h>
+#include "gzvm_arch.h"
+
+/**
+ * geniezone_hypercall_wrapper()
+ *
+ * Return: The wrapper helps caller to convert geniezone errno to

Linux errno.
+ */
+static int gzvm_hypcall_wrapper(unsigned long a0, unsigned long a1,

arch/arm64/geniezone/gzvm_arch.c new file +27 -0
+                             unsigned long a2, unsigned long a3,
+                             unsigned long a4, unsigned long a5,
+                             unsigned long a6, unsigned long a7,
+                             struct arm_smccc_res *res)
+{
+     arm_smccc_hvc(a0, a1, a2, a3, a4, a5, a6, a7, res);
+     return gz_err_to_errno(res->a0);
+}
+
+int gzvm_arch_probe(void)
+{
+     struct arm_smccc_res res;
+
+     arm_smccc_hvc(MT_HVC_GZVM_PROBE, 0, 0, 0, 0, 0, 0, 0, &res);
+     if (res.a0 == 0)
+             return 0;
+
+     return -ENXIO;
+}
+
+int gzvm_arch_set_memregion(gzvm_id_t vm_id, size_t buf_size,
+                         phys_addr_t region)
+{
+     struct arm_smccc_res res;
+
+     return gzvm_hypcall_wrapper(MT_HVC_GZVM_SET_MEMREGION, vm_id,
+                                 buf_size, region, 0, 0, 0, 0,

&res);

arch/arm64/geniezone/gzvm_arch.c new file +13 -0
+}
+
+static int gzvm_cap_arm_vm_ipa_size(void __user *argp)
+{
+     __u64 value = CONFIG_ARM64_PA_BITS;
+
+     if (copy_to_user(argp, &value, sizeof(__u64)))
+             return -EFAULT;
+
+     return 0;
+}
+
+int gzvm_arch_check_extension(struct gzvm *gzvm, __u64 cap, void

__user *argp)

arch/arm64/geniezone/gzvm_arch.c new file +36 -0
+{
+     int ret = -EOPNOTSUPP;
+
+     switch (cap) {
+     case GZVM_CAP_ARM_PROTECTED_VM: {
+             __u64 success = 1;
+
+             if (copy_to_user(argp, &success, sizeof(__u64)))
+                     return -EFAULT;
+             ret = 0;
+             break;
+     }
+     case GZVM_CAP_ARM_VM_IPA_SIZE: {
+             ret = gzvm_cap_arm_vm_ipa_size(argp);
+             break;
+     }
+     default:
+             ret = -EOPNOTSUPP;
+     }
+
+     return ret;
+}
+
+/**
+ * gzvm_arch_create_vm()
+ *
+ * Return:
+ * * positive value  - VM ID
+ * * -ENOMEM         - Memory not enough for storing VM data
+ */
+int gzvm_arch_create_vm(void)
+{
+     struct arm_smccc_res res;
+     int ret;
+
+     ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_CREATE_VM, 0, 0, 0, 0,

0, 0,
0,

arch/arm64/geniezone/gzvm_arch.c new file +13 -0
+                                &res);
+
+     if (ret == 0)
+             return res.a1;
+     else
+             return ret;
+}
+
+int gzvm_arch_destroy_vm(gzvm_id_t vm_id)
+{
+     struct arm_smccc_res res;
+
+     return gzvm_hypcall_wrapper(MT_HVC_GZVM_DESTROY_VM, vm_id, 0,

0, 0,
0,

arch/arm64/geniezone/gzvm_arch.c new file +4 -0
+                                 0, 0, &res);
+}
+
+int gzvm_vm_arch_enable_cap(struct gzvm *gzvm, struct

gzvm_enable_cap
*cap,

arch/arm64/geniezone/gzvm_arch.c new file +3 -0
+                         struct arm_smccc_res *res)
+{
+     return gzvm_hypcall_wrapper(MT_HVC_GZVM_ENABLE_CAP, gzvm-
Quoted 1 line

vm_id,

+ cap->cap, cap->args[0], cap-

Quoted 1 line

args[1],

+ cap->args[2], cap->args[3], cap-

Quoted 1 line

args[4],

arch/arm64/geniezone/gzvm_arch.c new file +5 -0
+                                res);
+}
+
+/**
+ * gzvm_vm_ioctl_get_pvmfw_size() - Get pvmfw size from

hypervisor,
return
+ * in x1, and return to userspace in
args.
+ *
+ * Return:
+ * * 0 - Succeed
+ * * -EINVAL - Hypervisor return invalid results
+ * * -EFAULT - Fail to copy back to userspace buffer
+ */

arch/arm64/geniezone/gzvm_arch.c new file +18 -0
+static int gzvm_vm_ioctl_get_pvmfw_size(struct gzvm *gzvm,
+                                     struct gzvm_enable_cap *cap,
+                                     void __user *argp)
+{
+     struct arm_smccc_res res = {0};
+
+     if (gzvm_vm_arch_enable_cap(gzvm, cap, &res) != 0)
+             return -EINVAL;
+
+     cap->args[1] = res.a1;
+     if (copy_to_user(argp, cap, sizeof(*cap)))
+             return -EFAULT;
+
+     return 0;
+}
+
+/**
+ * gzvm_vm_ioctl_cap_pvm() - Proceed GZVM_CAP_ARM_PROTECTED_VM's

subcommands
+ *
+ * Return:
+ * * 0 - Succeed
+ * * -EINVAL - Invalid subcommand or arguments
+ */
+static int gzvm_vm_ioctl_cap_pvm(struct gzvm *gzvm, struct gzvm_enable_cap *cap,

arch/arm64/geniezone/gzvm_arch.c new file +21 -0
+                              void __user *argp)
+{
+     int ret = -EINVAL;
+     struct arm_smccc_res res = {0};
+
+     switch (cap->args[0]) {
+     case GZVM_CAP_ARM_PVM_SET_PVMFW_IPA:
+             ret = gzvm_vm_arch_enable_cap(gzvm, cap, &res);
+             break;
+     case GZVM_CAP_ARM_PVM_GET_PVMFW_SIZE:
+             ret = gzvm_vm_ioctl_get_pvmfw_size(gzvm, cap, argp);
+             break;
+     default:
+             ret = -EINVAL;
+             break;
+     }
+
+     return ret;
+}
+
+int gzvm_vm_ioctl_arch_enable_cap(struct gzvm *gzvm, struct

gzvm_enable_cap *cap,

arch/arm64/geniezone/gzvm_arch.c new file +15 -0
+                               void __user *argp)
+{
+     int ret = -EINVAL;
+
+     switch (cap->cap) {
+     case GZVM_CAP_ARM_PROTECTED_VM:
+             ret = gzvm_vm_ioctl_cap_pvm(gzvm, cap, argp);
+             break;
+     default:
+             ret = -EINVAL;
+             break;
+     }
+
+     return ret;
+}
arch/arm64/geniezone/gzvm_arch.h new file +31 -0
new file mode 100644
index 000000000000..dd0b7b5f7c65
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#ifndef __GZ_ARCH_H__
+#define __GZ_ARCH_H__
+
+#include <linux/arm-smccc.h>
+
+enum {
+     GZVM_FUNC_CREATE_VM = 0,
+     GZVM_FUNC_DESTROY_VM,
+     GZVM_FUNC_CREATE_VCPU,
+     GZVM_FUNC_DESTROY_VCPU,
+     GZVM_FUNC_SET_MEMREGION,
+     GZVM_FUNC_RUN,
+     GZVM_FUNC_GET_REGS,
+     GZVM_FUNC_SET_REGS,
+     GZVM_FUNC_GET_ONE_REG,
+     GZVM_FUNC_SET_ONE_REG,
+     GZVM_FUNC_IRQ_LINE,
+     GZVM_FUNC_CREATE_DEVICE,
+     GZVM_FUNC_PROBE,
+     GZVM_FUNC_ENABLE_CAP,
+     NR_GZVM_FUNC
+};
+
+#define SMC_ENTITY_MTK                       59
+#define GZVM_FUNCID_START            (0x1000)
+#define

GZVM_HCALL_ID(func) \
+ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,
ARM_SMCCC_SMC_32, \
+ SMC_ENTITY_MTK, (GZVM_FUNCID_START +
(func)))

arch/arm64/geniezone/gzvm_arch.h new file +2 -0
+
+#define

MT_HVC_GZVM_CREATE_VM GZVM_HCALL_ID(GZVM_FUNC_CREATE
_VM)
+#define
MT_HVC_GZVM_DESTROY_VM GZVM_HCALL_ID(GZVM_FUNC_DESTRO
Y_VM)
+#define
MT_HVC_GZVM_CREATE_VCPU GZVM_HCALL_ID(GZVM_FUNC_CREATE
_VCPU)
+#define
MT_HVC_GZVM_DESTROY_VCPU GZVM_HCALL_ID(GZVM_FUNC_DESTROY_VCPU)
+#define
MT_HVC_GZVM_SET_MEMREGION GZVM_HCALL_ID(GZVM_FUNC_SET_MEMREGION
)
+#define
MT_HVC_GZVM_RUN GZVM_HCALL_ID(GZVM_FUNC_RUN)
+#define
MT_HVC_GZVM_GET_REGS GZVM_HCALL_ID(GZVM_FUNC_GET_REGS)
+#define
MT_HVC_GZVM_SET_REGS GZVM_HCALL_ID(GZVM_FUNC_SET_REGS)
+#define
MT_HVC_GZVM_GET_ONE_REG GZVM_HCALL_ID(GZVM_FUNC_GET_ON
E_REG)
+#define
MT_HVC_GZVM_SET_ONE_REG GZVM_HCALL_ID(GZVM_FUNC_SET_ON
E_REG)
+#define
MT_HVC_GZVM_IRQ_LINE GZVM_HCALL_ID(GZVM_FUNC_IRQ_LINE)
+#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)

arch/arm64/geniezone/gzvm_arch.h new file +2 -0
+
+#endif /* __GZVM_ARCH_H__ */
arch/arm64/include/uapi/asm/gzvm_arch.h new file +18 -0
new file mode 100644
index 000000000000..e7927f3dcb11
@@ -0,0 +1,18 @@
+/* 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
+
+#endif /* __GZVM_ARCH_H__ */
drivers/virt/Kconfig +2 -0
index f79ab13a5c28..9bbf0bdf672c 100644
@@ -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 +0 -0
new file mode 100644
index 000000000000..6fad3c30f8d9

drivers/virt/geniezone/Kconfig line 6

Quoted 6 lines
drivers/virt/geniezone/Kconfig new file +6 -0
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config MTK_GZVM
+     tristate "GenieZone Hypervisor driver for guest VM operation"
+     depends on ARM64
+     depends on KVM

NAK.

Quoted 6 lines

Either this is KVM, and this code serves no purpose, or it is a standalone
hypervisor, and it *cannot* have a dependency on KVM.

[...]

In order to be self-contained and avoid dependency like with KVM, may we leverage KVM's symbol, macro e.g. VGIC_NR_SGIS, VGIC_NR_PRIVATE_IRQS...etc, and copy or rename the related part to */geniezone/?

Quoted 46 lines
Quoted 23 lines
drivers/virt/geniezone/Kconfig new file +2 -0
+/**
+ * gzvm_gfn_to_pfn_memslot() - Translate gfn (guest ipa) to pfn

(host
pa),
+ * result is in @pfn
+ *
+ * Leverage KVM's gfn_to_pfn_memslot(). Because gfn_to_pfn_memslot()
needs
+ * kvm_memory_slot as parameter, this function populates necessary fileds
+ * for calling gfn_to_pfn_memslot().
+ *
+ * Return:
+ * * 0 - Succeed
+ * * -EFAULT - Failed to convert
+ */
+static int gzvm_gfn_to_pfn_memslot(struct gzvm_memslot *memslot, u64
gfn, u64 *pfn)

drivers/virt/geniezone/Kconfig new file +3 -0
+{
+     hfn_t __pfn;
+     struct kvm_memory_slot kvm_slot = {0};

drivers/virt/geniezone/Kconfig

Quoted 10 lines
drivers/virt/geniezone/Kconfig new file +10 -0
+
+     kvm_slot.base_gfn = memslot->base_gfn;
+     kvm_slot.npages = memslot->npages;
+     kvm_slot.dirty_bitmap = NULL;
+     kvm_slot.userspace_addr = memslot->userspace_addr;
+     kvm_slot.flags = memslot->flags;
+     kvm_slot.id = memslot->slot_id;
+     kvm_slot.as_id = 0;
+
+     __pfn = gfn_to_pfn_memslot(&kvm_slot, gfn);

Again, I absolutely oppose this horror. This is internal to KVM, and we want to be able to change this without having to mess with your own code that we cannot test anyway.

What if we start using the extra fields that you don't populate as they mean nothing to you? Or add a backpointer to the kvm structure to do fancy accounting?

You have your own hypervisor, that's well and good. Since your main argument is that it is supposed to be standalone, make it *really* standalone and don't use KVM as a prop.

Quoted 5 lines

Thanks,

         M.

--
Jazz is not dead. It just smells funny...

Same with previous discussion, we'd like to copy or rename the related part from KVM and keep the maintainance at our own if it's ok.

#22 lore raw

Re: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support

Quoted 20 lines · Yi-De Wu (吳一德)
Quoted 18 lines · Marc Zyngier

External email : Please do not click links or open attachments until you have verified the sender or the content.

drivers/virt/geniezone/Kconfig line 6

Quoted 6 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

drivers/virt/geniezone/Kconfig new file +4 -0
+config MTK_GZVM
+     tristate "GenieZone Hypervisor driver for guest VM operation"
+     depends on ARM64
+     depends on KVM

NAK.

Either this is KVM, and this code serves no purpose, or it is a standalone
hypervisor, and it *cannot* have a dependency on KVM.

Quoted 7 lines
Quoted 2 lines

[...]

In order to be self-contained and avoid dependency like with KVM, may we leverage KVM's symbol, macro e.g. VGIC_NR_SGIS, VGIC_NR_PRIVATE_IRQS...etc, and copy or rename the related part to */geniezone/?

Again, these are architected constants. You can have your own. You can already consider any use of a KVM structure or symbol as a bug.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#23 lore raw

Re: [PATCH v2 3/7] virt: geniezone: Introduce GenieZone hypervisor support

Quoted 37 lines · Marc Zyngier

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 22 lines · Yi-De Wu (吳一德)
Quoted 20 lines · Marc Zyngier

External email : Please do not click links or open attachments until
you have verified the sender or the content.

drivers/virt/geniezone/Kconfig line 6

Quoted 7 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

(quoted diff) +2 -0
+config MTK_GZVM
+     tristate "GenieZone Hypervisor driver for guest VM

operation"

drivers/virt/geniezone/Kconfig new file +2 -0
+     depends on ARM64
+     depends on KVM

NAK.

Either this is KVM, and this code serves no purpose, or it is a standalone
hypervisor, and it *cannot* have a dependency on KVM.

Quoted 8 lines
Quoted 2 lines

[...]

In order to be self-contained and avoid dependency like with KVM, may
we leverage KVM's symbol, macro e.g. VGIC_NR_SGIS, VGIC_NR_PRIVATE_IRQS...etc, and copy or rename the related part to */geniezone/?

Quoted 8 lines

Again, these are architected constants. You can have your own. You can
already consider any use of a KVM structure or symbol as a bug.

        M.

--
Without deviation from the norm, progress is not possible.

Noted, we've received clear messages and agreed the current usage on KVM's data structure and function prototype should be treated as bugs. We would provide our own implementation on v4 to solve this issue.

author
#24 lore raw

PATCH v2 4/7 virt: geniezone: Add vcpu support

In reply to Yi-De Wu

From: "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/gzvm_arch.c        |  72 ++++++++
 arch/arm64/geniezone/gzvm_arch.h        |  24 +++
 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        |  48 ++---
 include/linux/gzvm_drv.h                |  26 ++-
 include/uapi/linux/gzvm.h               | 130 +++++++++++--
 8 files changed, 519 insertions(+), 47 deletions(-)
 create mode 100644 drivers/virt/geniezone/gzvm_vcpu.c
arch/arm64/geniezone/gzvm_arch.c +72 -0
index 2fc76f7d440f..3c91f3f1ae50 100644
@@ -187,3 +187,75 @@ int gzvm_vm_ioctl_arch_enable_cap(struct gzvm *gzvm, struct gzvm_enable_cap *cap
 
 	return ret;
 }
+
+int gzvm_arch_vcpu_update_one_reg(struct gzvm_vcpu *vcpu, __u64 reg_id,
+				  bool is_write, __u64 *data)
+{
+	struct arm_smccc_res res;
+	unsigned long a1;
+	int ret;
+
+	/* reg id follows KVM's encoding */
+	switch (reg_id & GZVM_REG_ARM_COPROC_MASK) {
+	case GZVM_REG_ARM_CORE:
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	a1 = assemble_vm_vcpu_tuple(vcpu->gzvm->vm_id, vcpu->vcpuid);
+	if (!is_write) {
+		ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_GET_ONE_REG,
+					   a1, reg_id, 0, 0, 0, 0, 0, &res);
+		if (ret == 0)
+			*data = res.a1;
+	} else {
+		ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_SET_ONE_REG,
+					   a1, reg_id, *data, 0, 0, 0, 0, &res);
+	}
+
+	return ret;
+}
+
+int gzvm_arch_vcpu_run(struct gzvm_vcpu *vcpu, __u64 *exit_reason)
+{
+	struct arm_smccc_res res;
+	unsigned long a1;
+	int ret;
+
+	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);
+	*exit_reason = res.a1;
+	return ret;
+}
+
+int gzvm_arch_destroy_vcpu(gzvm_id_t vm_id, int vcpuid)
+{
+	struct arm_smccc_res res;
+	unsigned long a1;
+
+	a1 = assemble_vm_vcpu_tuple(vm_id, vcpuid);
+	gzvm_hypcall_wrapper(MT_HVC_GZVM_DESTROY_VCPU, a1, 0, 0, 0, 0, 0, 0,
+			     &res);
+
+	return 0;
+}
+
+/**
+ * gzvm_arch_create_vcpu() - Call smc to gz hypervisor to create vcpu
+ * @run: Virtual address of vcpu->run
+ */
+int gzvm_arch_create_vcpu(gzvm_id_t vm_id, int vcpuid, void *run)
+{
+	struct arm_smccc_res res;
+	unsigned long a1, a2;
+	int ret;
+
+	a1 = assemble_vm_vcpu_tuple(vm_id, vcpuid);
+	a2 = (__u64)virt_to_phys(run);
+	ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_CREATE_VCPU, a1, a2, 0, 0, 0, 0,
+				   0, &res);
+
+	return ret;
+}
arch/arm64/geniezone/gzvm_arch.h +24 -0
index dd0b7b5f7c65..ecc24ff4e244 100644
@@ -47,4 +47,28 @@ 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)
 
+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_H__ */
arch/arm64/include/uapi/asm/gzvm_arch.h +29 -0
index e7927f3dcb11..3e66087f635f 100644
@@ -15,4 +15,33 @@
 #define GZVM_CAP_ARM_PVM_SET_PVMFW_IPA		0
 #define GZVM_CAP_ARM_PVM_GET_PVMFW_SIZE		1
 
+/*
+ * 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
index 066efddc0b9c..8ebf2db0c970 100644
@@ -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 +24 -24

114 lines not on this page · raw message

include/linux/gzvm_drv.h +20 -6
index f2cfbf87c113..5736ddf97741 100644
@@ -26,18 +26,15 @@
 #define ERR_NOT_IMPLEMENTED     (-27)
 #define ERR_FAULT               (-40)
 
-static inline gzvm_id_t get_vmid_from_tuple(unsigned int tuple)
-{
-	return (gzvm_id_t)(tuple >> 16);
-}
-
-/**
+/*
  * The following data structures are for data transferring between driver and
  * hypervisor, and they're aligned with hypervisor definitions
  */
 #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 */
@@ -65,7 +62,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];
@@ -82,6 +88,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,
@@ -92,6 +100,12 @@ int gzvm_arch_destroy_vm(gzvm_id_t vm_id);
 int gzvm_vm_ioctl_arch_enable_cap(struct gzvm *gzvm,
 				  struct gzvm_enable_cap *cap,
 				  void __user *argp);
+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 platform_device *gzvm_debug_dev;
 
include/uapi/linux/gzvm.h +114 -16

172 lines not on this page · raw message

Signature · 1 line
2.18.0
#25 lore raw

Re: [PATCH v2 4/7] virt: geniezone: Add vcpu support

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 robh/for-next arnd-asm-generic/master linus/master v6.3 next-20230428] [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/20230428-183738
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
patch link:    https://lore.kernel.org/r/20230428103622.18291-5-yi-de.wu%40mediatek.com
patch subject: [PATCH v2 4/7] virt: geniezone: Add vcpu support
config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20230429/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 12.1.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/d4ced06ba2f149b099e9bf745a0e451c43e9d823
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yi-De-Wu/docs-geniezone-Introduce-GenieZone-hypervisor/20230428-183738 git checkout d4ced06ba2f149b099e9bf745a0e451c43e9d823
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> arch/arm64/geniezone/../../../drivers/virt/geniezone/gzvm_vcpu.c:145:6: warning: no previous prototype for 'gzvm_destroy_vcpu' [-Wmissing-prototypes]

145 | void gzvm_destroy_vcpu(struct gzvm_vcpu *vcpu)
| ^~~~~~~~~~~~~~~~~

vim +/gzvm_destroy_vcpu +145 arch/arm64/geniezone/../../../drivers/virt/geniezone/gzvm_vcpu.c

143
144 /* caller must hold the vm lock */

 > 145	void gzvm_destroy_vcpu(struct gzvm_vcpu *vcpu)

146 {
147 if (!vcpu)
148 return;
149
150 gzvm_arch_destroy_vcpu(vcpu->gzvm->vm_id, vcpu->vcpuid);
151 /* clean guest's data */
152 memset(vcpu->run, 0, GZVM_VCPU_RUN_MAP_SIZE);
153 free_pages_exact(vcpu->run, GZVM_VCPU_RUN_MAP_SIZE);
154 kfree(vcpu);
155 }
156

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
author
#26 lore raw

PATCH v2 5/7 virt: geniezone: Add irqchip support for virtual interrupt injection

In reply to Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Enable GenieZone to handle virtual interrupt injection request.

---
 arch/arm64/geniezone/Makefile       |  2 +-
 arch/arm64/geniezone/gzvm_arch.c    | 24 ++++++--
 arch/arm64/geniezone/gzvm_arch.h    | 11 ++++
 arch/arm64/geniezone/gzvm_irqchip.c | 88 +++++++++++++++++++++++++++++
 drivers/virt/geniezone/gzvm_vm.c    | 75 ++++++++++++++++++++++++
 include/linux/gzvm_drv.h            |  4 ++
 include/uapi/linux/gzvm.h           | 38 ++++++++++++-
 7 files changed, 235 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm64/geniezone/gzvm_irqchip.c
arch/arm64/geniezone/Makefile +1 -1
index 5720c076d73c..82af1ed870bc 100644
@@ -4,6 +4,6 @@
 #
 include $(srctree)/drivers/virt/geniezone/Makefile
 
-gzvm-y += gzvm_arch.o
+gzvm-y += gzvm_arch.o gzvm_irqchip.o
 
 obj-$(CONFIG_MTK_GZVM) += gzvm.o
arch/arm64/geniezone/gzvm_arch.c +19 -5
index 3c91f3f1ae50..16ab5d4fd5b8 100644
@@ -16,11 +16,10 @@
  *
  * Return: The wrapper helps caller to convert geniezone errno to Linux errno.
  */
-static int gzvm_hypcall_wrapper(unsigned long a0, unsigned long a1,
-				unsigned long a2, unsigned long a3,
-				unsigned long a4, unsigned long a5,
-				unsigned long a6, unsigned long a7,
-				struct arm_smccc_res *res)
+int gzvm_hypcall_wrapper(unsigned long a0, unsigned long a1, unsigned long a2,
+			 unsigned long a3, unsigned long a4, unsigned long a5,
+			 unsigned long a6, unsigned long a7,
+			 struct arm_smccc_res *res)
 {
 	arm_smccc_hvc(a0, a1, a2, a3, a4, a5, a6, a7, res);
 	return gz_err_to_errno(res->a0);
@@ -259,3 +258,18 @@ int gzvm_arch_create_vcpu(gzvm_id_t vm_id, int vcpuid, void *run)
 
 	return ret;
 }
+
+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/geniezone/gzvm_arch.h +11 -0
index ecc24ff4e244..205bd0901333 100644
@@ -71,4 +71,15 @@ disassemble_vm_vcpu_tuple(unsigned int tuple, gzvm_id_t *vmid,
 	*vcpuid = get_vcpuid_from_tuple(tuple);
 }
 
+int gzvm_hypcall_wrapper(unsigned long a0, unsigned long a1, unsigned long a2,
+			 unsigned long a3, unsigned long a4, unsigned long a5,
+			 unsigned long a6, unsigned long a7,
+			 struct arm_smccc_res *res);
+
+void gzvm_sync_vgic_state(struct gzvm_vcpu *vcpu);
+int gzvm_vgic_inject_irq(struct gzvm *gzvm, unsigned int vcpu_idx, u32 irq_type,
+			 u32 irq, bool level);
+int gzvm_vgic_inject_spi(struct gzvm *gzvm, unsigned int vcpu_idx,
+			 u32 spi_irq, bool level);
+
 #endif /* __GZVM_ARCH_H__ */
arch/arm64/geniezone/gzvm_irqchip.c new file +88 -0

88 lines not on this page · raw message

drivers/virt/geniezone/gzvm_vm.c +75 -0

87 lines not on this page · raw message

include/linux/gzvm_drv.h +4 -0
index 5736ddf97741..1e7c81597e9a 100644
@@ -107,6 +107,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 platform_device *gzvm_debug_dev;
 
 #endif /* __GZVM_DRV_H__ */
include/uapi/linux/gzvm.h +37 -1
index 6462961299eb..2f56a53efb27 100644
@@ -87,7 +87,43 @@ struct gzvm_userspace_memory_region {
 #define GZVM_IRQ_CPU_IRQ		0
 #define GZVM_IRQ_CPU_FIQ		1
 
-/* ioctls for vcpu fds */
+struct gzvm_irq_level {
+	union {
+		__u32 irq;
+		__s32 status;
+	};
+	__u32 level;
+};
+
+#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,
+};
+
+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.
+	 */
+	__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
+ */
 #define GZVM_RUN                   _IO(GZVM_IOC_MAGIC,   0x80)
 
 /* VM exit reason */
Signature · 1 line
2.18.0
#27 lore raw

Re: [PATCH v2 5/7] virt: geniezone: Add irqchip support for virtual interrupt injection

Quoted 16 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Enable GenieZone to handle virtual interrupt injection request.

---
 arch/arm64/geniezone/Makefile       |  2 +-
 arch/arm64/geniezone/gzvm_arch.c    | 24 ++++++--
 arch/arm64/geniezone/gzvm_arch.h    | 11 ++++
 arch/arm64/geniezone/gzvm_irqchip.c | 88 +++++++++++++++++++++++++++++
 drivers/virt/geniezone/gzvm_vm.c    | 75 ++++++++++++++++++++++++
 include/linux/gzvm_drv.h            |  4 ++
 include/uapi/linux/gzvm.h           | 38 ++++++++++++-
 7 files changed, 235 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm64/geniezone/gzvm_irqchip.c

[...]

arch/arm64/geniezone/gzvm_irqchip.c line 7

Quoted 9 lines

+++ b/arch/arm64/geniezone/gzvm_irqchip.c

arch/arm64/geniezone/gzvm_irqchip.c new file +7 -0
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#include <linux/irqchip/arm-gic-v3.h>
+#include <kvm/arm_vgic.h>

NAK.

There is no way you can rely on anything from KVM in your own hypervisor code.

Quoted 21 lines
arch/arm64/geniezone/gzvm_irqchip.c new file +10 -0
+
+#include <linux/gzvm.h>
+#include <linux/gzvm_drv.h>
+#include "gzvm_arch.h"
+
+/**
+ * gzvm_sync_vgic_state() - Check all LRs synced from gz hypervisor
+ *
+ * Traverse all LRs, see if any EOIed vint, notify_acked_irq if any.
+ * GZ does not fold/unfold everytime KVM_RUN, so we have to traverse 

all saved
+ * LRs. It will not takes much more time comparing to fold/unfold everytime
+ * GZVM_RUN, because there are only few LRs.
+ */

arch/arm64/geniezone/gzvm_irqchip.c new file +6 -0
+void gzvm_sync_vgic_state(struct gzvm_vcpu *vcpu)
+{
+}
+
+/* is_irq_valid() - Check the irq number and irq_type are matched */
+static bool is_irq_valid(u32 irq, u32 irq_type)

arch/arm64/geniezone/gzvm_irqchip.c line 36

Quoted 10 lines
arch/arm64/geniezone/gzvm_irqchip.c new file +10 -0
+{
+	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 >= VGIC_NR_SGIS && irq < VGIC_NR_PRIVATE_IRQS))

What happens if I redefine all these macros tomorrow? None of this code should rely on anything that is *INTERNAL* to KVM.

        M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#28 lore raw

Re: [PATCH v2 5/7] virt: geniezone: Add irqchip support for virtual interrupt injection

Quoted 37 lines · Marc Zyngier

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 17 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Enable GenieZone to handle virtual interrupt injection request.

---
 arch/arm64/geniezone/Makefile       |  2 +-
 arch/arm64/geniezone/gzvm_arch.c    | 24 ++++++--
 arch/arm64/geniezone/gzvm_arch.h    | 11 ++++
 arch/arm64/geniezone/gzvm_irqchip.c | 88
+++++++++++++++++++++++++++++
 drivers/virt/geniezone/gzvm_vm.c    | 75 ++++++++++++++++++++++++
 include/linux/gzvm_drv.h            |  4 ++
 include/uapi/linux/gzvm.h           | 38 ++++++++++++-
 7 files changed, 235 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm64/geniezone/gzvm_irqchip.c

[...]

arch/arm64/geniezone/gzvm_irqchip.c line 7

Quoted 9 lines

+++ b/arch/arm64/geniezone/gzvm_irqchip.c

arch/arm64/geniezone/gzvm_irqchip.c new file +7 -0
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#include <linux/irqchip/arm-gic-v3.h>
+#include <kvm/arm_vgic.h>

NAK.

Quoted 3 lines

There is no way you can rely on anything from KVM in your own hypervisor code.

Same with previous discussion, we'd like to copy or rename the related part from KVM and keep the maintainance at our own if it's ok.

Quoted 43 lines
Quoted 35 lines
arch/arm64/geniezone/gzvm_irqchip.c new file +7 -0
+
+#include <linux/gzvm.h>
+#include <linux/gzvm_drv.h>
+#include "gzvm_arch.h"
+
+/**
+ * gzvm_sync_vgic_state() - Check all LRs synced from gz

hypervisor
+ *
+ * Traverse all LRs, see if any EOIed vint, notify_acked_irq if any.
+ * GZ does not fold/unfold everytime KVM_RUN, so we have to traverse
all saved
+ * LRs. It will not takes much more time comparing to fold/unfold everytime
+ * GZVM_RUN, because there are only few LRs.
+ */

arch/arm64/geniezone/gzvm_irqchip.c new file +5 -0
+void gzvm_sync_vgic_state(struct gzvm_vcpu *vcpu)
+{
+}
+
+/* is_irq_valid() - Check the irq number and irq_type are matched

*/

arch/arm64/geniezone/gzvm_irqchip.c new file +11 -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 >= VGIC_NR_SGIS && irq <
Quoted 1 line

VGIC_NR_PRIVATE_IRQS))

What happens if I redefine all these macros tomorrow? None of this code should rely on anything that is *INTERNAL* to KVM.

         M.

--
Jazz is not dead. It just smells funny...

#29 lore raw

Re: [PATCH v2 5/7] virt: geniezone: Add irqchip support for virtual interrupt injection

Quoted 39 lines · Yi-De Wu (吳一德)
Quoted 37 lines · Marc Zyngier

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 17 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Enable GenieZone to handle virtual interrupt injection request.

---
 arch/arm64/geniezone/Makefile       |  2 +-
 arch/arm64/geniezone/gzvm_arch.c    | 24 ++++++--
 arch/arm64/geniezone/gzvm_arch.h    | 11 ++++
 arch/arm64/geniezone/gzvm_irqchip.c | 88
+++++++++++++++++++++++++++++
 drivers/virt/geniezone/gzvm_vm.c    | 75 ++++++++++++++++++++++++
 include/linux/gzvm_drv.h            |  4 ++
 include/uapi/linux/gzvm.h           | 38 ++++++++++++-
 7 files changed, 235 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm64/geniezone/gzvm_irqchip.c

[...]

arch/arm64/geniezone/gzvm_irqchip.c line 7

Quoted 9 lines

+++ b/arch/arm64/geniezone/gzvm_irqchip.c

arch/arm64/geniezone/gzvm_irqchip.c new file +7 -0
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#include <linux/irqchip/arm-gic-v3.h>
+#include <kvm/arm_vgic.h>

NAK.

Quoted 6 lines
Quoted 3 lines

There is no way you can rely on anything from KVM in your own hypervisor code.

Same with previous discussion, we'd like to copy or rename the related part from KVM and keep the maintainance at our own if it's ok.

Why do you need *ANY* of the KVM stuff? Please fully enumerate these dependencies and why you have them.

Directly using KVM stuff for something completely unrelated is not OK, and will never be.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#30 lore raw

Re: [PATCH v2 5/7] virt: geniezone: Add irqchip support for virtual interrupt injection

Quoted 58 lines · Marc Zyngier

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 41 lines · Yi-De Wu (吳一德)
Quoted 39 lines · Marc Zyngier

External email : Please do not click links or open attachments until
you have verified the sender or the content.

Quoted 18 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Enable GenieZone to handle virtual interrupt injection request.

---
 arch/arm64/geniezone/Makefile       |  2 +-
 arch/arm64/geniezone/gzvm_arch.c    | 24 ++++++--
 arch/arm64/geniezone/gzvm_arch.h    | 11 ++++
 arch/arm64/geniezone/gzvm_irqchip.c | 88
+++++++++++++++++++++++++++++
 drivers/virt/geniezone/gzvm_vm.c    | 75
++++++++++++++++++++++++
 include/linux/gzvm_drv.h            |  4 ++
 include/uapi/linux/gzvm.h           | 38 ++++++++++++-
 7 files changed, 235 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm64/geniezone/gzvm_irqchip.c

[...]

arch/arm64/geniezone/gzvm_irqchip.c line 7

Quoted 9 lines

+++ b/arch/arm64/geniezone/gzvm_irqchip.c

arch/arm64/geniezone/gzvm_irqchip.c new file +7 -0
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#include <linux/irqchip/arm-gic-v3.h>
+#include <kvm/arm_vgic.h>

NAK.

Quoted 7 lines
Quoted 3 lines

There is no way you can rely on anything from KVM in your own hypervisor code.

Same with previous discussion, we'd like to copy or rename the related
part from KVM and keep the maintainance at our own if it's ok.

Why do you need *ANY* of the KVM stuff? Please fully enumerate these dependencies and why you have them.

Quoted 8 lines

Directly using KVM stuff for something completely unrelated is not OK,
and will never be.

        M.

--
Without deviation from the norm, progress is not possible.

The particular part we'd like to leverage from KVM are as followed
1. gfn_to_pfn_memslot to convert guest physical address(or intermediate physical address) to physical address
2. get ARM's number of interrupt of different types e.g. number of SGI, number of PPI...etc

#31 lore raw

Re: [PATCH v2 5/7] virt: geniezone: Add irqchip support for virtual interrupt injection

Quoted 64 lines · Yi-De Wu (吳一德)
Quoted 62 lines · Marc Zyngier

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 41 lines · Yi-De Wu (吳一德)
Quoted 39 lines · Marc Zyngier

External email : Please do not click links or open attachments until
you have verified the sender or the content.

Quoted 18 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Enable GenieZone to handle virtual interrupt injection request.

---
 arch/arm64/geniezone/Makefile       |  2 +-
 arch/arm64/geniezone/gzvm_arch.c    | 24 ++++++--
 arch/arm64/geniezone/gzvm_arch.h    | 11 ++++
 arch/arm64/geniezone/gzvm_irqchip.c | 88
+++++++++++++++++++++++++++++
 drivers/virt/geniezone/gzvm_vm.c    | 75
++++++++++++++++++++++++
 include/linux/gzvm_drv.h            |  4 ++
 include/uapi/linux/gzvm.h           | 38 ++++++++++++-
 7 files changed, 235 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm64/geniezone/gzvm_irqchip.c

[...]

arch/arm64/geniezone/gzvm_irqchip.c line 7

Quoted 9 lines

+++ b/arch/arm64/geniezone/gzvm_irqchip.c

arch/arm64/geniezone/gzvm_irqchip.c new file +7 -0
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#include <linux/irqchip/arm-gic-v3.h>
+#include <kvm/arm_vgic.h>

NAK.

Quoted 7 lines
Quoted 3 lines

There is no way you can rely on anything from KVM in your own hypervisor code.

Same with previous discussion, we'd like to copy or rename the related
part from KVM and keep the maintainance at our own if it's ok.

Why do you need *ANY* of the KVM stuff? Please fully enumerate these dependencies and why you have them.

Directly using KVM stuff for something completely unrelated is not OK,
and will never be.

Quoted 8 lines
Quoted 4 lines
        M.

--
Without deviation from the norm, progress is not possible.

The particular part we'd like to leverage from KVM are as followed
1. gfn_to_pfn_memslot to convert guest physical address(or intermediate physical address) to physical address

What is a memslot in your hypervisor? How does it relate to KVM's? What about the use of struct kvm?

I'm sorry, but your use of *internal* structures and API would make it impossible for us to make any further change without potentially affecting your hypervisor. Which is closed source and untestable.

To sum it up, I'm strongly opposed to any use of these data structures. If you can spot some commonalities, expose them as a 0-cost abstraction. But don't use them as is your code.

Quoted 2 lines

2. get ARM's number of interrupt of different types e.g. number of SGI, number of PPI...etc

These are architectural constants, and you can define your own. That will cost you nothing but a handful of #define, and keep the two subsystem independent.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#32 lore raw

Re: [PATCH v2 5/7] virt: geniezone: Add irqchip support for virtual interrupt injection

Quoted 100 lines · Marc Zyngier

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 69 lines · Yi-De Wu (吳一德)
Quoted 67 lines · Marc Zyngier

External email : Please do not click links or open attachments until
you have verified the sender or the content.

Quoted 43 lines · Yi-De Wu (吳一德)
Quoted 41 lines · Marc Zyngier

External email : Please do not click links or open attachments
until
you have verified the sender or the content.

Quoted 19 lines · Yi-De Wu

From: "Yingshiuan Pan" <[email protected]>

Enable GenieZone to handle virtual interrupt injection request.

---
 arch/arm64/geniezone/Makefile       |  2 +-
 arch/arm64/geniezone/gzvm_arch.c    | 24 ++++++--
 arch/arm64/geniezone/gzvm_arch.h    | 11 ++++
 arch/arm64/geniezone/gzvm_irqchip.c | 88
+++++++++++++++++++++++++++++
 drivers/virt/geniezone/gzvm_vm.c    | 75
++++++++++++++++++++++++
 include/linux/gzvm_drv.h            |  4 ++
 include/uapi/linux/gzvm.h           | 38 ++++++++++++-
 7 files changed, 235 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm64/geniezone/gzvm_irqchip.c

[...]

arch/arm64/geniezone/gzvm_irqchip.c line 7

Quoted 9 lines

+++ b/arch/arm64/geniezone/gzvm_irqchip.c

arch/arm64/geniezone/gzvm_irqchip.c new file +7 -0
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#include <linux/irqchip/arm-gic-v3.h>
+#include <kvm/arm_vgic.h>

NAK.

Quoted 7 lines
Quoted 3 lines

There is no way you can rely on anything from KVM in your own hypervisor code.

Same with previous discussion, we'd like to copy or rename the related
part from KVM and keep the maintainance at our own if it's ok.

Why do you need *ANY* of the KVM stuff? Please fully enumerate these
dependencies and why you have them.

Directly using KVM stuff for something completely unrelated is not
OK,
and will never be.

Quoted 8 lines
Quoted 4 lines
        M.

--
Without deviation from the norm, progress is not possible.

The particular part we'd like to leverage from KVM are as followed
1. gfn_to_pfn_memslot to convert guest physical address(or intermediate physical address) to physical address

What is a memslot in your hypervisor? How does it relate to KVM's? What about the use of struct kvm?

I'm sorry, but your use of *internal* structures and API would make it
impossible for us to make any further change without potentially affecting your hypervisor. Which is closed source and untestable.

To sum it up, I'm strongly opposed to any use of these data structures. If you can spot some commonalities, expose them as a 0-cost abstraction. But don't use them as is your code.

Quoted 3 lines

2. get ARM's number of interrupt of different types e.g. number of SGI,
number of PPI...etc

Quoted 8 lines

These are architectural constants, and you can define your own. That will cost you nothing but a handful of #define, and keep the two subsystem independent.

        M.

--
Without deviation from the norm, progress is not possible.

As per discussion, we would define our own constants here and keep the subsystem indepedent.

author
#33 lore raw

PATCH v2 6/7 virt: geniezone: Add irqfd support

In reply to Yi-De Wu

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.

---
 arch/arm64/geniezone/gzvm_arch.c    |   5 +
 arch/arm64/geniezone/gzvm_arch.h    |   7 +
 arch/arm64/geniezone/gzvm_irqchip.c |  22 +-
 drivers/virt/geniezone/Makefile     |   2 +-
 drivers/virt/geniezone/gzvm_irqfd.c | 536 ++++++++++++++++++++++++++++
 drivers/virt/geniezone/gzvm_main.c  |   5 +
 drivers/virt/geniezone/gzvm_vcpu.c  |   1 +
 drivers/virt/geniezone/gzvm_vm.c    |  19 +
 include/linux/gzvm_drv.h            |  27 ++
 include/uapi/linux/gzvm.h           |  20 +-
 10 files changed, 641 insertions(+), 3 deletions(-)
 create mode 100644 drivers/virt/geniezone/gzvm_irqfd.c
arch/arm64/geniezone/gzvm_arch.c +5 -0
index 16ab5d4fd5b8..19ac7c1a4743 100644
@@ -273,3 +273,8 @@ int gzvm_arch_inject_irq(struct gzvm *gzvm, unsigned int vcpu_idx, u32 irq_type,
 	/* default use spi */
 	return gzvm_vgic_inject_spi(gzvm, vcpu_idx, irq, level);
 }
+
+void gzvm_sync_hwstate(struct gzvm_vcpu *vcpu)
+{
+	gzvm_sync_vgic_state(vcpu);
+}
arch/arm64/geniezone/gzvm_arch.h +7 -0
index 205bd0901333..e8d7c82efb50 100644
@@ -47,6 +47,8 @@ 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 GIC_V3_NR_LRS			16
+
 static inline gzvm_id_t get_vmid_from_tuple(unsigned int tuple)
 {
 	return (gzvm_id_t)(tuple >> 16);
@@ -57,6 +59,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)
 {
arch/arm64/geniezone/gzvm_irqchip.c +21 -1
index c46bd34fee1b..1887cbb58fc6 100644
@@ -10,8 +10,15 @@
 #include <linux/gzvm_drv.h>
 #include "gzvm_arch.h"
 
+static bool lr_signals_eoi(uint64_t lr_val)
+{
+	return !(lr_val & ICH_LR_STATE) && (lr_val & ICH_LR_EOI) &&
+		 !(lr_val & ICH_LR_HW);
+}
+
 /**
- * gzvm_sync_vgic_state() - Check all LRs synced from gz hypervisor
+ * gzvm_sync_vgic_state() - Check all LRs synced from gz hypervisor.
+ * @vcpu: Pointer to gzvm_vcpu.
  *
  * Traverse all LRs, see if any EOIed vint, notify_acked_irq if any.
  * GZ does not fold/unfold everytime KVM_RUN, so we have to traverse all saved
@@ -20,6 +27,19 @@
  */
 void gzvm_sync_vgic_state(struct gzvm_vcpu *vcpu)
 {
+	int i;
+
+	for (i = 0; i < vcpu->hwstate->nr_lrs; i++) {
+		u32 vintid;
+		u64 lr_val = vcpu->hwstate->lr[i];
+		/* 0 means unused */
+		if (!lr_val)
+			continue;
+
+		vintid = lr_val & ICH_LR_VIRTUAL_ID_MASK;
+		if (lr_signals_eoi(lr_val))
+			gzvm_notify_acked_irq(vcpu->gzvm, vintid - VGIC_NR_PRIVATE_IRQS);
+	}
 }
 
 /* is_irq_valid() - Check the irq number and irq_type are matched */
drivers/virt/geniezone/Makefile +1 -1
index 8ebf2db0c970..8517549e7dfb 100644
@@ -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_irqfd.o
 
drivers/virt/geniezone/gzvm_irqfd.c new file +536 -0

536 lines not on this page · raw message

drivers/virt/geniezone/gzvm_main.c +5 -0
index e3fe3ad9ffce..121816a09c8e 100644
@@ -113,11 +113,16 @@ static int gzvm_drv_probe(struct platform_device *pdev)
 		return ret;
 	gzvm_debug_dev = pdev;
 
+	ret = gzvm_drv_irqfd_init();
+	if (ret)
+		return ret;
+
 	return 0;
 }
 
 static int gzvm_drv_remove(struct platform_device *pdev)
 {
+	gzvm_drv_irqfd_exit();
 	destroy_all_vm();
 	misc_deregister(&gzvm_dev);
 	return 0;
drivers/virt/geniezone/gzvm_vcpu.c +1 -0
index 65b1a2372b30..faee2ee64639 100644
@@ -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 +19 -0
index a5444541b745..eb34d7ba94a2 100644
@@ -295,6 +295,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;
 
@@ -319,6 +328,8 @@ 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);
 
 	gzvm_destroy_vcpus(gzvm);
@@ -365,6 +376,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->dev,
+			"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
index 1e7c81597e9a..a54a7915c514 100644
@@ -10,6 +10,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
@@ -25,6 +26,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
@@ -68,6 +71,7 @@ struct gzvm_vcpu {
 	/* lock of vcpu*/
 	struct mutex lock;
 	struct gzvm_vcpu_run *run;
+	struct gzvm_vcpu_hwstate *hwstate;
 };
 
 struct gzvm {
@@ -77,8 +81,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);
@@ -111,6 +130,14 @@ 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);
 
+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 platform_device *gzvm_debug_dev;
 
 #endif /* __GZVM_DRV_H__ */
include/uapi/linux/gzvm.h +19 -1
index 2f56a53efb27..b878b25ff963 100644
@@ -230,4 +230,22 @@ struct gzvm_one_reg {
 
 #define GZVM_REG_GENERIC	   0x0000000000000000ULL
 
-#endif /* __GZVM_H__ */
+#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
author
#34 lore raw

PATCH v2 7/7 virt: geniezone: Add ioeventfd support

In reply to Yi-De Wu

From: "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         |   3 +-
 drivers/virt/geniezone/gzvm_ioeventfd.c | 263 ++++++++++++++++++++++++
 drivers/virt/geniezone/gzvm_vcpu.c      |  29 ++-
 drivers/virt/geniezone/gzvm_vm.c        |  17 ++
 include/linux/gzvm_drv.h                |  11 +
 include/uapi/linux/gzvm.h               |  23 +++
 6 files changed, 343 insertions(+), 3 deletions(-)
 create mode 100644 drivers/virt/geniezone/gzvm_ioeventfd.c
drivers/virt/geniezone/Makefile +2 -1
index 8517549e7dfb..b1ecdd235a4e 100644
@@ -7,5 +7,6 @@
 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_irqfd.o
+	  $(GZVM_DIR)/gzvm_vcpu.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 +27 -2
index faee2ee64639..cd5f5735ec3b 100644
@@ -49,10 +49,34 @@ 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
- * @argp: pointer to struct gzvm_vcpu_run in userspace
+ * @argp: Pointer to struct gzvm_vcpu_run in userspace
  */
 static long gzvm_vcpu_run(struct gzvm_vcpu *vcpu, void * __user argp)
 {
@@ -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
index eb34d7ba94a2..6d31c25cec6b 100644
@@ -304,6 +304,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;
 
@@ -384,6 +393,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->dev,
+			"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
index a54a7915c514..3c9f617d6bf1 100644
@@ -6,6 +6,7 @@
 #ifndef __GZVM_DRV_H__
 #define __GZVM_DRV_H__
 
+#include <linux/eventfd.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
@@ -91,6 +92,8 @@ struct gzvm {
 		struct mutex      resampler_lock;
 	} irqfds;
 
+	struct list_head ioevents;
+
 	struct list_head vm_list;
 	gzvm_id_t vm_id;
 
@@ -140,4 +143,12 @@ void gzvm_sync_hwstate(struct gzvm_vcpu *vcpu);
 
 extern struct platform_device *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
index b878b25ff963..02adb0305f70 100644
@@ -248,4 +248,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 · 1 line
2.18.0
#35 lore raw
In reply to Yi-De Wu
Quoted 8 lines · Yi-De Wu

This series is based on linux-next, tag: next-20230427.

Changes in v2:
- Refactor: move to drivers/virt/geniezone
- Refactor: decouple arch-dependent and arch-independent
- Check pending signal before entering guest context
- Fix reviewer's comments

Please explain what is Geniezone, where we can find it, what's the plan for open-sourcing it etc.

That's what cover letter is for.

Best regards,
Krzysztof

#36 lore raw
Quoted 14 lines · Krzysztof Kozlowski

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 8 lines · Yi-De Wu

This series is based on linux-next, tag: next-20230427.

Changes in v2:
- Refactor: move to drivers/virt/geniezone
- Refactor: decouple arch-dependent and arch-independent
- Check pending signal before entering guest context
- Fix reviewer's comments

Quoted 9 lines

Please explain what is Geniezone, where we can find it, what's the plan
for open-sourcing it etc.

That's what cover letter is for.

Best regards,
Krzysztof

The introdution of GenieZone in cover letter in v1 was missing in v2. We've brought it back in v3, and would keep it updated in the future.

#37 lore raw
In reply to Yi-De Wu
Quoted 7 lines · Yi-De Wu

This series is based on linux-next, tag: next-20230427.

Changes in v2:
- Refactor: move to drivers/virt/geniezone
- Refactor: decouple arch-dependent and arch-independent
- Check pending signal before entering guest context
- Fix reviewer's comments

You need to be specific about what you changed.

Best regards,
Krzysztof

#38 lore raw
Quoted 13 lines · Krzysztof Kozlowski

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 7 lines · Yi-De Wu

This series is based on linux-next, tag: next-20230427.

Changes in v2:
- Refactor: move to drivers/virt/geniezone
- Refactor: decouple arch-dependent and arch-independent
- Check pending signal before entering guest context
- Fix reviewer's comments

Quoted 5 lines

You need to be specific about what you changed.

Best regards,
Krzysztof

Noted, we would specify more clearly on the code change in the changelog.