Support SDEI Virtualization
v4 cover Support SDEI Virtualization
This series intends to virtualize Software Delegated Exception Interface (SDEI), which is defined by DEN0054A. It allows the hypervisor to deliver NMI-alike event to guest and it's needed by asynchronous page fault to deliver page-not-present notification from hypervisor to guest. The code and the required qemu changes can be found from:
https://developer.arm.com/documentation/den0054/latest
https://github.com/gwshan/linux ("kvm/arm64_sdei")
https://github.com/gwshan/qemu ("kvm/arm64_sdei")
The SDEI event is identified by a 32-bits number. Bits[31:24] are used to indicate the SDEI event properties while bits[23:0] are identifying the unique number. The implementation takes bits[23:22] to indicate the owner of the SDEI event. For example, those SDEI events owned by KVM should have these two bits set to 0b01. Besides, the implementation supports SDEI events owned by KVM only.
The design is pretty straightforward and the implementation is just following the SDEI specification, to support the defined SMCCC intefaces, except the IRQ binding stuff. There are several data structures introduced. Some of the objects have to be migrated by VMM. So their definitions are split up for VMM to include the corresponding states for migration.
struct kvm_sdei_kvm
Associated with VM and used to track the KVM exposed SDEI events and those registered by guest.
struct kvm_sdei_vcpu
Associated with vCPU and used to track SDEI event delivery. The preempted context is saved prior to the delivery and restored after that.
struct kvm_sdei_event
SDEI events exposed by KVM so that guest can register and enable.
struct kvm_sdei_kvm_event
SDEI events that have been registered by guest.
struct kvm_sdei_vcpu_event
SDEI events that have been queued to specific vCPU for delivery.
The series is organized as below:
PATCH[01] Introduces template for smccc_get_argx()
PATCH[02] Introduces the data structures and infrastructure
PATCH[03-14] Supports various SDEI related hypercalls
PATCH[15] Supports SDEI event notification
PATCH[16-17] Introduces ioctl command for migration PATCH[18-19] Supports SDEI event injection and cancellation
PATCH[20] Exports SDEI capability
PATCH[21] Adds self-test case for SDEI virtualization
Testing
=======
There are additional patches in the following repositories to create procfs entries, allowing inject SDEI event and test driver in the guest to handle the SDEI event. Besides, the additional QEMU changes are needed so that guest can detect the SDEI service through ACPI table.
https://github.com/gwshan/linux ("kvm/arm64_sdei") https://github.com/gwshan/qemu ("kvm/arm64_sdei")
The SDEI event is received and handled in the guest after it's injected through the procfs entries from host side.
host# /home/gavin/sandbox/qemu.main/build/qemu-system-aarch64 \
-accel kvm -machine virt,gic-version=host \
-cpu host -smp 8,sockets=2,cores=4,threads=1 -m 1024M \
: \
-kernel /home/gavin/sandbox/linux.guest/arch/arm64/boot/Image \
-initrd /home/gavin/sandbox/images/rootfs.cpio.xz \
-append 'earlycon=pl011,mmio,0x9000000'
host# echo > /proc/kvm/kvm-10842/vcpu-0
guest# =========== SDEI Event (CPU#0) ===========
num=0x40400000, arg=0xdabfdabf
SP: 0xffff800011613e90 PC: 0x0 pState: 0x0
Regs:
000000000002ac4 ffff00001ff947a0 0000000000002ac2 ffff00001ff976c0
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 ffff80001121a000
ffff8000116199e0 ffff800011619ad8 ffff80001122d8b8 ffff800011619afc
0000000000000000 0000000000000000 ffff800011622140 ffff800011150108
00000000582c0018 ffff800011613e90 ffff800010bd0248
Query context:
x[00]: 0000000000002ac4 errno: 0
x[01]: ffff00001ff947a0 errno: 0
:
x[18]: ffff800010bd01d8 errno: 0
x[19]: fffffffffffffffe errno: -22
x[20]: fffffffffffffffe errno: -22
:
x[30]: fffffffffffffffe errno: -22
host# echo > /proc/kvm/kvm-10842/vcpu-7
guest# =========== SDEI Event (CPU#7) ===========
num=0x40400000, arg=0xdabfdabf
SP: 0xffff800011b73f20 PC: 0x0 pState: 0x0
Regs:
00000000000010d0 ffff00003fde07a0 00000000000010ce 7fffffff1999999a
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 ffff80001121a000
ffff8000116199e0 ffff800011619ad8 ffff80001122d8b8 ffff800011619afc
0000000000000000 0000000000000000 ffff000020032ac0 0000000000000000
0000000000000000 ffff800011b73f20 ffff800010bd0248
Query context:
x[00]: 00000000000010d0 errno: 0
x[01]: ffff00003fde07a0 errno: 0
:
x[18]: ffff800010bd01d8 errno: 0
x[19]: fffffffffffffffe errno: -22
:
x[30]: fffffffffffffffe errno: -22Changelog
=========
v4:
* Rebased to v5.14.rc5 (Gavin)
v3:
* Rebased to v5.13.rc1 (Gavin)
* Use linux data types in kvm_sdei.h (Gavin)
v2:
* Rebased to v5.11.rc6 (Gavin) * Dropped changes related to SDEI client driver (Gavin) * Removed support for passthrou SDEI events (Gavin) * Redesigned data structures (Gavin)
* Implementation is almost rewritten as the data structures
are totally changed (Gavin)
* Added ioctl commands to support migration (Gavin)
Gavin Shan (21):
KVM: arm64: Introduce template for inline functions
KVM: arm64: Add SDEI virtualization infrastructure
KVM: arm64: Support SDEI_VERSION hypercall
KVM: arm64: Support SDEI_EVENT_REGISTER hypercall
KVM: arm64: Support SDEI_EVENT_{ENABLE, DISABLE} hypercall
KVM: arm64: Support SDEI_EVENT_CONTEXT hypercall
KVM: arm64: Support SDEI_EVENT_UNREGISTER hypercall
KVM: arm64: Support SDEI_EVENT_STATUS hypercall
KVM: arm64: Support SDEI_EVENT_GET_INFO hypercall
KVM: arm64: Support SDEI_EVENT_ROUTING_SET hypercall
KVM: arm64: Support SDEI_PE_{MASK, UNMASK} hypercall
KVM: arm64: Support SDEI_{PRIVATE, SHARED}_RESET hypercall
KVM: arm64: Impment SDEI event delivery
KVM: arm64: Support SDEI_EVENT_{COMPLETE, COMPLETE_AND_RESUME}
hypercall
KVM: arm64: Support SDEI event notifier
KVM: arm64: Support SDEI ioctl commands on VM
KVM: arm64: Support SDEI ioctl commands on vCPU
KVM: arm64: Support SDEI event injection
KVM: arm64: Support SDEI event cancellation
KVM: arm64: Export SDEI capability
KVM: selftests: Add SDEI test case
arch/arm64/include/asm/kvm_emulate.h | 1 + arch/arm64/include/asm/kvm_host.h | 8 + arch/arm64/include/asm/kvm_sdei.h | 136 ++ arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/include/uapi/asm/kvm_sdei.h | 86 ++ arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/arm.c | 19 + arch/arm64/kvm/hyp/exception.c | 7 + arch/arm64/kvm/hypercalls.c | 18 + arch/arm64/kvm/inject_fault.c | 27 + arch/arm64/kvm/sdei.c | 1519 ++++++++++++++++++++ include/kvm/arm_hypercalls.h | 34 +- include/uapi/linux/kvm.h | 4 + tools/testing/selftests/kvm/Makefile | 1 + tools/testing/selftests/kvm/aarch64/sdei.c | 171 +++ 15 files changed, 2014 insertions(+), 20 deletions(-) create mode 100644 arch/arm64/include/asm/kvm_sdei.h create mode 100644 arch/arm64/include/uapi/asm/kvm_sdei.h create mode 100644 arch/arm64/kvm/sdei.c create mode 100644 tools/testing/selftests/kvm/aarch64/sdei.c
Signature · 1 line
2.23.0
PATCH v4 1/21 KVM: arm64: Introduce template for inline functions
The inline functions used to get the SMCCC parameters have same layout. It means these functions can be presented by a template, to make the code simplified. Besides, this adds more similar inline functions like smccc_get_arg{4,5,6,7,8}() to visit more SMCCC arguments, which are needed by SDEI virtualization support.
--- include/kvm/arm_hypercalls.h | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)
include/kvm/arm_hypercalls.h +15 -19
@@ -6,27 +6,21 @@#include <asm/kvm_emulate.h> -int kvm_hvc_call_handler (struct kvm_vcpu *vcpu); - -static inline u32 smccc_get_function (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,0 ); +#define SMCCC_DECLARE_GET_FUNC (type, name, reg) \ +static inline type smccc_get_##name(struct kvm_vcpu *vcpu) \ +{ \ + return vcpu_get_reg(vcpu, reg); \ } -static inline unsigned long smccc_get_arg1 (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,1 ); -} - -static inline unsigned long smccc_get_arg2 (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,2 ); -} - -static inline unsigned long smccc_get_arg3 (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,3 ); -} +SMCCC_DECLARE_GET_FUNC(u32, function, 0) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg1, 1) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg2, 2) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg3, 3) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg4, 4) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg5, 5) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg6, 6) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg7, 7) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg8, 8) static inline void smccc_set_retval(struct kvm_vcpu *vcpu, unsigned long a0,
@@ -40,4 +34,6 @@ static inline void smccc_set_retval(struct kvm_vcpu *vcpu, vcpu_set_reg(vcpu, 3, a3); } +int kvm_hvc_call_handler (struct kvm_vcpu *vcpu); +#endif
Signature · 1 line
2.23.0
Re: [PATCH v4 01/21] KVM: arm64: Introduce template for inline functions
Hi Gavin,
Quoted 43 lines · Gavin Shan
The inline functions used to get the SMCCC parameters have same layout. It means these functions can be presented by a template, to make the code simplified. Besides, this adds more similar inline functions like smccc_get_arg{4,5,6,7,8}() to visit more SMCCC arguments, which are needed by SDEI virtualization support.
Signed-off-by Gavin Shan <[email protected]>--- include/kvm/arm_hypercalls.h | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)include/kvm/arm_hypercalls.h +4
-18@@ -6,27 +6,21 @@#include <asm/kvm_emulate.h> -int kvm_hvc_call_handler (struct kvm_vcpu *vcpu); - -static inline u32 smccc_get_function (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,0 ); +#define SMCCC_DECLARE_GET_FUNC (type, name, reg) \ +static inline type smccc_get_##name(struct kvm_vcpu *vcpu) \ +{ \ + return vcpu_get_reg(vcpu, reg); \ } -static inline unsigned long smccc_get_arg1 (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,1 ); -} - -static inline unsigned long smccc_get_arg2 (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,2 ); -} - -static inline unsigned long smccc_get_arg3 (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,3 );
include/kvm/arm_hypercalls.h line 23
Quoted 10 lines
include/kvm/arm_hypercalls.h +9
-1-} +SMCCC_DECLARE_GET_FUNC(u32, function, 0) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg1, 1) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg2, 2) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg3, 3) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg4, 4) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg5, 5) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg6, 6) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg7, 7) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg8, 8)
I think I would keep smccc_get_function() and add macros to get the 64-bit args. SMCCC_DECLARE_GET_FUNC is an odd macro name for a function fetching an arg. I would suggest:
Quoted 9 lines
include/kvm/arm_hypercalls.h +4
-0+#define SMCCC_DECLARE_GET_ARG (reg) \ +static inline unsigned long smccc_get_arg##reg(struct kvm_vcpu *vcpu) \ +{ \ + return vcpu_get_reg(vcpu, reg); \ } static inline void smccc_set_retval(struct kvm_vcpu *vcpu, unsigned long a0,
include/kvm/arm_hypercalls.h static inline void smccc_set_retval(struct kvm_vcpu *vcpu, · line 38
Quoted 5 lines
include/kvm/arm_hypercalls.h +2
-0@@ -40,4 +34,6 @@ static inline void smccc_set_retval(struct kvm_vcpu *vcpu,vcpu_set_reg (vcpu,3 , a3); } +int kvm_hvc_call_handler (struct kvm_vcpu *vcpu); +
spurious change?
include/kvm/arm_hypercalls.h static inline void smccc_set_retval(struct kvm_vcpu *vcpu, · line 39
Quoted 2 lines
include/kvm/arm_hypercalls.h +0
-0#endif
Thanks
Eric
Re: [PATCH v4 01/21] KVM: arm64: Introduce template for inline functions
Hi Eric,
Quoted 49 lines · Eric Auger
Quoted 48 lines · Gavin Shan
The inline functions used to get the SMCCC parameters have same layout. It means these functions can be presented by a template, to make the code simplified. Besides, this adds more similar inline functions like smccc_get_arg{4,5,6,7,8}() to visit more SMCCC arguments, which are needed by SDEI virtualization support.
Signed-off-by Gavin Shan <[email protected]>--- include/kvm/arm_hypercalls.h | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)include/kvm/arm_hypercalls.h +8
-19@@ -6,27 +6,21 @@#include <asm/kvm_emulate.h> -int kvm_hvc_call_handler (struct kvm_vcpu *vcpu); - -static inline u32 smccc_get_function (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,0 ); +#define SMCCC_DECLARE_GET_FUNC (type, name, reg) \ +static inline type smccc_get_##name(struct kvm_vcpu *vcpu) \ +{ \ + return vcpu_get_reg(vcpu, reg); \ } -static inline unsigned long smccc_get_arg1 (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,1 ); -} - -static inline unsigned long smccc_get_arg2 (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,2 ); -} - -static inline unsigned long smccc_get_arg3 (struct kvm_vcpu *vcpu) -{ -return vcpu_get_reg (vcpu,3 ); -} +SMCCC_DECLARE_GET_FUNC(u32, function, 0) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg1, 1) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg2, 2) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg3, 3)
Quoted 9 lines
include/kvm/arm_hypercalls.h line 23
Quoted 5 lines
include/kvm/arm_hypercalls.h +5
-0+SMCCC_DECLARE_GET_FUNC(unsigned long, arg4, 4) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg5, 5) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg6, 6) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg7, 7) +SMCCC_DECLARE_GET_FUNC(unsigned long, arg8, 8)I think I would keep
smccc_get_function()and add macros to get the 64-bit args.SMCCC_DECLARE_GET_FUNCis an odd macro name for a function fetching an arg. I would suggest:
I agree. The code will be changed accordingly in next respin.
Quoted 12 lines
Quoted 12 lines
include/kvm/arm_hypercalls.h +4
-0+#define SMCCC_DECLARE_GET_ARG (reg) \ +static inline unsigned long smccc_get_arg##reg(struct kvm_vcpu *vcpu) \ +{ \ + return vcpu_get_reg(vcpu, reg); \ } static inline void smccc_set_retval(struct kvm_vcpu *vcpu, unsigned long a0,@@ -40,4 +34,6 @@ static inline void smccc_set_retval(struct kvm_vcpu *vcpu,vcpu_set_reg (vcpu,3 , a3); }
Quoted 3 lines
include/kvm/arm_hypercalls.h static inline void smccc_set_retval(struct kvm_vcpu *vcpu, · line 38
Quoted 2 lines
include/kvm/arm_hypercalls.h +2
-0+int kvm_hvc_call_handler (struct kvm_vcpu *vcpu); +spurious change?
I thought the inline function would come before the exposed ones. However, I don't think it's necessary. I will drop the changes in next respin.
Quoted 2 lines
include/kvm/arm_hypercalls.h static inline void smccc_set_retval(struct kvm_vcpu *vcpu, · line 39
Quoted 2 lines
include/kvm/arm_hypercalls.h +0
-0#endif
Thanks,
Gavin
PATCH v4 2/21 KVM: arm64: Add SDEI virtualization infrastructure
In reply to Gavin ShanSoftware Delegated Exception Interface (SDEI) provides a mechanism for registering and servicing system events. Those system events are high priority events, which must be serviced immediately. It's going to be used by Asynchronous Page Fault (APF) to deliver notification from KVM to guest. It's noted that SDEI is defined by ARM DEN0054A specification.
This introduces SDEI virtualization infrastructure where the SDEI events are registered and manuplated by the guest through hypercall. The SDEI event is delivered to one specific vCPU by KVM once it's raised. This introduces data structures to represent the needed objects to implement the feature, which is highlighted as below. As those objects could be migrated between VMs, these data structures are partially exported to user space.
* kvm_sdei_event
SDEI events are exported from KVM so that guest is able to register and manuplate.
* kvm_sdei_kvm_event
SDEI event that has been registered by guest.
* kvm_sdei_kvm_vcpu
SDEI event that has been delivered to the target vCPU.
* kvm_sdei_kvm
Place holder of exported and registered SDEI events.
* kvm_sdei_vcpu
Auxiliary object to save the preempted context during SDEI event delivery.
The error is returned for all SDEI hypercalls for now. They will be implemented by the subsequent patches.
--- arch/arm64/include/asm/kvm_host.h | 6 + arch/arm64/include/asm/kvm_sdei.h | 118 +++++++++++++++ arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/include/uapi/asm/kvm_sdei.h | 60 ++++++++ arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/arm.c | 7 + arch/arm64/kvm/hypercalls.c | 18 +++ arch/arm64/kvm/sdei.c | 198 +++++++++++++++++++++++++ 8 files changed, 409 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/include/asm/kvm_sdei.h create mode 100644 arch/arm64/include/uapi/asm/kvm_sdei.h create mode 100644 arch/arm64/kvm/sdei.c
arch/arm64/include/asm/kvm_host.h +6 -0
@@ -113,6 +113,9 @@ struct kvm_arch {/* Interrupt controller */ struct vgic_dist vgic; +/* SDEI support */ +struct kvm_sdei_kvm *sdei; +/* Mandated version of PSCI */ u32 psci_version;
@@ -339,6 +342,9 @@ struct kvm_vcpu_arch {* here. */ +/* SDEI support */ +struct kvm_sdei_vcpu *sdei; +/* * Guest registers we preserve during guest debugging. *
arch/arm64/include/asm/kvm_sdei.h new file +118 -0
118 lines not on this page · raw message
arch/arm64/include/uapi/asm/kvm.h +1 -0
@@ -36,6 +36,7 @@#include <linux/types.h> #include <asm/ptrace.h> #include <asm/sve_context.h> +#include <asm/kvm_sdei.h> #define __KVM_HAVE_GUEST_DEBUG#define __KVM_HAVE_IRQ_LINE
arch/arm64/include/uapi/asm/kvm_sdei.h new file +60 -0
60 lines not on this page · raw message
arch/arm64/kvm/Makefile +1 -1
@@ -16,7 +16,7 @@ kvm-y := $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o \ inject_fault.o va_layout.o handle_exit.o \ guest.o debug.o reset.o sys_regs.o \ vgic-sys-reg-v3.o fpsimd.o pmu.o \ - arch_timer.o trng.o\ + arch_timer.o trng.o sdei.o \ vgic/vgic.o vgic/vgic-init.o \ vgic/vgic-irqfd.o vgic/vgic-v2.o \ vgic/vgic-v3.o vgic/vgic-v4.o \
arch/arm64/kvm/arm.c +7 -0
@@ -150,6 +150,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)kvm_vgic_early_init (kvm); +kvm_sdei_init_vm (kvm); +/* The maximum number of VCPUs is limited by the host's GIC model */ kvm->arch.max_vcpus =kvm_arm_default_max_vcpus ();
@@ -179,6 +181,8 @@ void kvm_arch_destroy_vm(struct kvm *kvm)kvm_vgic_destroy (kvm); +kvm_sdei_destroy_vm (kvm); +for (i =0 ; i <KVM_MAX_VCPUS ; ++i) {if (kvm->vcpus[i]) {kvm_vcpu_destroy (kvm->vcpus[i]);
@@ -333,6 +337,8 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)kvm_arm_pvtime_vcpu_init (&vcpu->arch); +kvm_sdei_create_vcpu (vcpu); + vcpu->arch.hw_mmu = &vcpu->kvm->arch.mmu; err =kvm_vgic_vcpu_init (vcpu);
@@ -354,6 +360,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)kvm_mmu_free_memory_cache (&vcpu->arch.mmu_page_cache);kvm_timer_vcpu_terminate (vcpu);kvm_pmu_vcpu_destroy (vcpu); +kvm_sdei_destroy_vcpu (vcpu);kvm_arm_vcpu_destroy (vcpu); }
arch/arm64/kvm/hypercalls.c +18 -0
@@ -139,6 +139,24 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)case ARM_SMCCC_TRNG_RND32 :case ARM_SMCCC_TRNG_RND64 :return kvm_trng_call (vcpu); +case SDEI_1_0_FN_SDEI_VERSION : +case SDEI_1_0_FN_SDEI_EVENT_REGISTER : +case SDEI_1_0_FN_SDEI_EVENT_ENABLE : +case SDEI_1_0_FN_SDEI_EVENT_DISABLE : +case SDEI_1_0_FN_SDEI_EVENT_CONTEXT : +case SDEI_1_0_FN_SDEI_EVENT_COMPLETE : +case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME : +case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER : +case SDEI_1_0_FN_SDEI_EVENT_STATUS : +case SDEI_1_0_FN_SDEI_EVENT_GET_INFO : +case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET : +case SDEI_1_0_FN_SDEI_PE_MASK : +case SDEI_1_0_FN_SDEI_PE_UNMASK : +case SDEI_1_0_FN_SDEI_INTERRUPT_BIND : +case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE : +case SDEI_1_0_FN_SDEI_PRIVATE_RESET : +case SDEI_1_0_FN_SDEI_SHARED_RESET : +return kvm_sdei_hypercall (vcpu);default :return kvm_psci_call (vcpu); }
arch/arm64/kvm/sdei.c new file +198 -0
198 lines not on this page · raw message
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 02/21] KVM: arm64: Add SDEI virtualization infrastructure
Hi Gavin,
Quoted 8 lines · Gavin Shan
Software Delegated Exception Interface (SDEI) provides a mechanism for registering and servicing system events. Those system events are high priority events, which must be serviced immediately. It's going to be used by Asynchronous Page Fault (APF) to deliver notification from KVM to guest. It's noted that SDEI is defined by ARM DEN0054A specification.
This introduces SDEI virtualization infrastructure where the SDEI events are registered and manuplated by the guest through hypercall. The SDEI
manipulated
Quoted 9 lines
event is delivered to one specific vCPU by KVM once it's raised. This introduces data structures to represent the needed objects to implement the feature, which is highlighted as below. As those objects could be migrated between VMs, these data structures are partially exported to user space.
*
kvm_sdei_event
SDEI events are exported from KVM so that guest is able to register and manuplate.
manipulate
Quoted 2 lines
*
kvm_sdei_kvm_event
SDEI event that has been registered by guest.
I would recomment to revisit the names. Why kvm event? Why not registered_event instead that actually would tell what it its. also you have kvm twice in the struct name.
Quoted 1 line
*
kvm_sdei_kvm_vcpu
Didn't you mean kvm_sdei_vcpu_event instead?
Quoted 30 lines
SDEI event that has been delivered to the target vCPU.
*kvm_sdei_kvm
Place holder of exported and registered SDEI events.
*kvm_sdei_vcpu
Auxiliary object to save the preempted context during SDEI event delivery.The error is returned for all SDEI hypercalls for now. They will be implemented by the subsequent patches.
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_host.h | 6 + arch/arm64/include/asm/kvm_sdei.h | 118 +++++++++++++++ arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/include/uapi/asm/kvm_sdei.h | 60 ++++++++ arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/arm.c | 7 + arch/arm64/kvm/hypercalls.c | 18 +++ arch/arm64/kvm/sdei.c | 198 +++++++++++++++++++++++++ 8 files changed, 409 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/include/asm/kvm_sdei.h create mode 100644 arch/arm64/include/uapi/asm/kvm_sdei.h create mode 100644 arch/arm64/kvm/sdei.carch/arm64/include/asm/kvm_host.h +0
-0
arch/arm64/include/asm/kvm_host.h struct kvm_arch { · line 116
Quoted 4 lines
arch/arm64/include/asm/kvm_host.h +1
-0@@ -113,6 +113,9 @@ struct kvm_arch {/* Interrupt controller */ struct vgic_dist vgic; +/* SDEI support */
does not bring much. Why not reusing the commit msg explanation? Here and below.
Quoted 37 lines
arch/arm64/include/asm/kvm_host.h +4
-0+struct kvm_sdei_kvm *sdei; +/* Mandated version of PSCI */ u32 psci_version;@@ -339,6 +342,9 @@ struct kvm_vcpu_arch {* here. */ +/* SDEI support */ + struct kvm_sdei_vcpu *sdei;> +/* * Guest registers we preserve during guest debugging. * arch/arm64/include/asm/kvm_sdei.h new file +17
-0@@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Definitions of various KVM SDEI events. +* +* Copyright (C) 2021 Red Hat, Inc. +* +* Author(s): Gavin Shan <[email protected]> +*/ + +#ifndef __ARM64_KVM_SDEI_H__ +#define __ARM64_KVM_SDEI_H__ + +#include <uapi/linux/arm_sdei.h>> +#include <uapi/asm/kvm_sdei.h> +#include <linux/bitmap.h> +#include <linux/list.h> +#include <linux/spinlock.h> +
arch/arm64/include/asm/kvm_sdei.h line 27
Quoted 10 lines
arch/arm64/include/asm/kvm_sdei.h new file +10
-0+struct kvm_sdei_event { +struct kvm_sdei_event_state state; +struct kvm *kvm; +struct list_head link; +}; + +struct kvm_sdei_kvm_event { +struct kvm_sdei_kvm_event_state state; +struct kvm_sdei_event *kse; +struct kvm *kvm;
can't you reuse the kvm handle in state?
Quoted 9 lines
arch/arm64/include/asm/kvm_sdei.h new file +9
-0+struct list_head link; +}; + +struct kvm_sdei_vcpu_event { +struct kvm_sdei_vcpu_event_state state; +struct kvm_sdei_kvm_event *kske; +struct kvm_vcpu *vcpu; +struct list_head link; +};
arch/arm64/include/asm/kvm_sdei.h line 47
Quoted 10 lines
arch/arm64/include/asm/kvm_sdei.h new file +10
-0+ +struct kvm_sdei_kvm { +spinlock_t lock; +struct list_head events;/* kvm_sdei_event */ +struct list_head kvm_events;/* kvm_sdei_kvm_event */ +}; + +struct kvm_sdei_vcpu { +spinlock_t lock; +struct kvm_sdei_vcpu_state state;
could you explain the fields below?
arch/arm64/include/asm/kvm_sdei.h line 60
Quoted 13 lines
arch/arm64/include/asm/kvm_sdei.h new file +13
-0+struct kvm_sdei_vcpu_event *critical_event; +struct kvm_sdei_vcpu_event *normal_event; +struct list_head critical_events; +struct list_head normal_events; +}; + +/* +* According to SDEI specification (v1.0), the event number spans 32-bits +* and the lower 24-bits are used as the (real) event number. I don't +* think we can use that much SDEI numbers in one system. So we reserve +* two bits from the 24-bits real event number, to indicate its types: +* physical event and virtual event. One reserved bit is enough for now, +* but two bits are reserved for possible extension in future.
I think this assumption is worth to be mentionned in the commit msg.
arch/arm64/include/asm/kvm_sdei.h line 61
Quoted 2 lines
arch/arm64/include/asm/kvm_sdei.h new file +2
-0+* +* The physical events are owned by underly firmware while the virtual
underly?
arch/arm64/include/asm/kvm_sdei.h line 70
Quoted 8 lines
arch/arm64/include/asm/kvm_sdei.h new file +8
-0+* events are used by VMM and KVM. +*/ +#define KVM_SDEI_EV_NUM_TYPE_SHIFT 22 +#define KVM_SDEI_EV_NUM_TYPE_MASK 3 +#define KVM_SDEI_EV_NUM_TYPE_PHYS 0 +#define KVM_SDEI_EV_NUM_TYPE_VIRT 1 + +static inline bool kvm_sdei_is_valid_event_num (unsigned long num)
the name of the function does does not really describe what it does. It actually checks the sdei is a virtual one. suggest kvm_sdei_is_virtual?
arch/arm64/include/asm/kvm_sdei.h line 77
Quoted 7 lines
arch/arm64/include/asm/kvm_sdei.h new file +7
-0+{ +unsigned long type; + +if (num >>32 ) +return false; + + type = (num >>KVM_SDEI_EV_NUM_TYPE_SHIFT ) &KVM_SDEI_EV_NUM_TYPE_MASK ;
I think the the mask generally is applied before shifting. See include/linux/irqchip/arm-gic-v3.h
Quoted 5 lines
arch/arm64/include/asm/kvm_sdei.h new file +5
-0+if (type !=KVM_SDEI_EV_NUM_TYPE_VIRT ) +return false; + +return true; +}
arch/arm64/include/asm/kvm_sdei.h line 92
Quoted 10 lines
arch/arm64/include/asm/kvm_sdei.h new file +10
-0+ +/* Accessors for the registration or enablement states of KVM event */ +#define KVM_SDEI_FLAG_FUNC (field) \ +static inline bool kvm_sdei_is_##field(struct kvm_sdei_kvm_event *kske, \ + unsigned int index) \ +{ \ + return !!test_bit(index, (void *)(kske->state.field)); \ +} \ + \ +static inline bool kvm_sdei_empty_##field(struct kvm_sdei_kvm_event *kske) \
nit: s/empty/none ?
Quoted 52 lines
arch/arm64/include/asm/kvm_sdei.h new file +26
-0+{ \ +return bitmap_empty ((void *)(kske->state.field), \ +KVM_SDEI_MAX_VCPUS ); \ +} \ +static inline void kvm_sdei_set_##field(struct kvm_sdei_kvm_event *kske, \ + unsigned int index) \ +{ \ + set_bit(index, (void *)(kske->state.field)); \ +} \ +static inline void kvm_sdei_clear_##field(struct kvm_sdei_kvm_event *kske, \ + unsigned int index) \ +{ \ + clear_bit(index, (void *)(kske->state.field)); \ +} + +KVM_SDEI_FLAG_FUNC(registered) +KVM_SDEI_FLAG_FUNC(enabled) + +/* APIs */ +void kvm_sdei_init_vm(struct kvm *kvm); +void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu); +int kvm_sdei_hypercall(struct kvm_vcpu *vcpu); +void kvm_sdei_destroy_vcpu(struct kvm_vcpu *vcpu); +void kvm_sdei_destroy_vm(struct kvm *kvm); + +#endif /* __ARM64_KVM_SDEI_H__ */ arch/arm64/include/uapi/asm/kvm.h +1
-0@@ -36,6 +36,7 @@#include <linux/types.h> #include <asm/ptrace.h> #include <asm/sve_context.h> +#include <asm/kvm_sdei.h> #define __KVM_HAVE_GUEST_DEBUG#define __KVM_HAVE_IRQ_LINEarch/arm64/include/uapi/asm/kvm_sdei.h new file +8
-0@@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Definitions of various KVM SDEI event states. +* +* Copyright (C) 2021 Red Hat, Inc. +* +* Author(s): Gavin Shan <[email protected]> +*/
arch/arm64/include/uapi/asm/kvm_sdei.h line 18
Quoted 10 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +10
-0+ +#ifndef _UAPI__ASM_KVM_SDEI_H +#define _UAPI__ASM_KVM_SDEI_H + +#ifndef __ASSEMBLY__ +#include <linux/types.h> + +#define KVM_SDEI_MAX_VCPUS 512 +#define KVM_SDEI_INVALID_NUM 0 +#define KVM_SDEI_DEFAULT_NUM 0x40400000
The motivation behind introducing such uapi should be clearer (besides just telling this aims at migrating). To me atm, this justification does not make possible to understand if those structs are well suited. You should document the migration process I think.
I would remove _state suffix in all of them.
arch/arm64/include/uapi/asm/kvm_sdei.h line 20
Quoted 2 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +2
-0+ +struct kvm_sdei_event_state {
This is not really a state because it cannot be changed by the guest, right? I would remove _state and just call it kvm_sdei_event
arch/arm64/include/uapi/asm/kvm_sdei.h line 25
Quoted 5 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +5
-0+__u64 num; + +__u8 type; +__u8 signaled; +__u8 priority;
you need some padding to be 64-bit aligned. See in generic or aarch64 kvm.h for instance.
arch/arm64/include/uapi/asm/kvm_sdei.h line 28
Quoted 3 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +3
-0+}; + +struct kvm_sdei_kvm_event_state {
I would rename into kvm_sdei_registered_event or smth alike
arch/arm64/include/uapi/asm/kvm_sdei.h line 29
Quoted 1 line
arch/arm64/include/uapi/asm/kvm_sdei.h new file +1
-0+__u64 num;
how does this num differ from the event state one?
arch/arm64/include/uapi/asm/kvm_sdei.h line 32
Quoted 3 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +3
-0+__u32 refcount; + +__u8 route_mode;
padding also here. See for instance
https://lore.kernel.org/kvm/[email protected]/T/#m7bac2ff2b28a68f8d2196ec452afd3e46682760d
Maybe put the the route_mode field and refcount at the end and add one byte of padding?
Why can't we have a single sdei_event uapi representation where route mode defaults to unset and refcount defaults to 0 when not registered?
arch/arm64/include/uapi/asm/kvm_sdei.h line 35
Quoted 3 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +3
-0+__u64 route_affinity; +__u64 entries[KVM_SDEI_MAX_VCPUS ]; +__u64 params[KVM_SDEI_MAX_VCPUS ];
I would rename entries into ep_address and params into ep_arg.
arch/arm64/include/uapi/asm/kvm_sdei.h line 36
Quoted 1 line
arch/arm64/include/uapi/asm/kvm_sdei.h new file +1
-0+__u64 registered[KVM_SDEI_MAX_VCPUS /64 ];
maybe add a comment along with KVM_SDEI_MAX_VCPUS that it must be a multiple of 64 (or a build check)
arch/arm64/include/uapi/asm/kvm_sdei.h line 37
Quoted 1 line
arch/arm64/include/uapi/asm/kvm_sdei.h new file +1
-0+__u64 enabled[KVM_SDEI_MAX_VCPUS /64 ];
Also you may clarify what this gets used for a shared event. I guess this only makes sense for a private event which can be registered by several EPs?
arch/arm64/include/uapi/asm/kvm_sdei.h line 42
Quoted 5 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +5
-0+}; + +struct kvm_sdei_vcpu_event_state { +__u64 num; +__u32 refcount;
how does it differ from num and refcount of the registered event? padding++
arch/arm64/include/uapi/asm/kvm_sdei.h line 52
Quoted 10 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +10
-0+}; + +struct kvm_sdei_vcpu_regs { +__u64 regs[18 ]; +__u64 pc; +__u64 pstate; +}; + +struct kvm_sdei_vcpu_state { +__u8 masked;
padding++
Quoted 106 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +7
-0+__u64 critical_num; +__u64 normal_num; +struct kvm_sdei_vcpu_regs critical_regs; +struct kvm_sdei_vcpu_regs normal_regs; +};> + +#endif /* !__ASSEMBLY__ */ +#endif /* _UAPI__ASM_KVM_SDEI_H */ arch/arm64/kvm/Makefile +1
-1@@ -16,7 +16,7 @@ kvm-y := $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o \ inject_fault.o va_layout.o handle_exit.o \ guest.o debug.o reset.o sys_regs.o \ vgic-sys-reg-v3.o fpsimd.o pmu.o \ - arch_timer.o trng.o\ + arch_timer.o trng.o sdei.o \ vgic/vgic.o vgic/vgic-init.o \ vgic/vgic-irqfd.o vgic/vgic-v2.o \ vgic/vgic-v3.o vgic/vgic-v4.o \arch/arm64/kvm/arm.c +7
-0@@ -150,6 +150,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)kvm_vgic_early_init (kvm); +kvm_sdei_init_vm (kvm); +/* The maximum number of VCPUs is limited by the host's GIC model */ kvm->arch.max_vcpus =kvm_arm_default_max_vcpus ();@@ -179,6 +181,8 @@ void kvm_arch_destroy_vm(struct kvm *kvm)kvm_vgic_destroy (kvm); +kvm_sdei_destroy_vm (kvm); +for (i =0 ; i <KVM_MAX_VCPUS ; ++i) {if (kvm->vcpus[i]) {kvm_vcpu_destroy (kvm->vcpus[i]);@@ -333,6 +337,8 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)kvm_arm_pvtime_vcpu_init (&vcpu->arch); +kvm_sdei_create_vcpu (vcpu); + vcpu->arch.hw_mmu = &vcpu->kvm->arch.mmu; err =kvm_vgic_vcpu_init (vcpu);@@ -354,6 +360,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)kvm_mmu_free_memory_cache (&vcpu->arch.mmu_page_cache);kvm_timer_vcpu_terminate (vcpu);kvm_pmu_vcpu_destroy (vcpu); +kvm_sdei_destroy_vcpu (vcpu);kvm_arm_vcpu_destroy (vcpu); }arch/arm64/kvm/hypercalls.c +18
-0@@ -139,6 +139,24 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)case ARM_SMCCC_TRNG_RND32 :case ARM_SMCCC_TRNG_RND64 :return kvm_trng_call (vcpu); +case SDEI_1_0_FN_SDEI_VERSION : +case SDEI_1_0_FN_SDEI_EVENT_REGISTER : +case SDEI_1_0_FN_SDEI_EVENT_ENABLE : +case SDEI_1_0_FN_SDEI_EVENT_DISABLE : +case SDEI_1_0_FN_SDEI_EVENT_CONTEXT : +case SDEI_1_0_FN_SDEI_EVENT_COMPLETE : +case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME : +case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER : +case SDEI_1_0_FN_SDEI_EVENT_STATUS : +case SDEI_1_0_FN_SDEI_EVENT_GET_INFO : +case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET : +case SDEI_1_0_FN_SDEI_PE_MASK : +case SDEI_1_0_FN_SDEI_PE_UNMASK : +case SDEI_1_0_FN_SDEI_INTERRUPT_BIND : +case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE : +case SDEI_1_0_FN_SDEI_PRIVATE_RESET : +case SDEI_1_0_FN_SDEI_SHARED_RESET : +return kvm_sdei_hypercall (vcpu);default :return kvm_psci_call (vcpu); }arch/arm64/kvm/sdei.c new file +12
-0@@ -0,0 +1,198 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* SDEI virtualization support. +* +* Copyright (C) 2021 Red Hat, Inc. +* +* Author(s): Gavin Shan <[email protected]> +*/ + +#include <linux/kernel.h> +#include <linux/kvm_host.h> +#include <linux/spinlock.h>
arch/arm64/kvm/sdei.c line 22
Quoted 10 lines
arch/arm64/kvm/sdei.c new file +10
-0+#include <linux/slab.h> +#include <kvm/arm_hypercalls.h> + +static struct kvm_sdei_event_state defined_kse[] = { + {KVM_SDEI_DEFAULT_NUM , +SDEI_EVENT_TYPE_PRIVATE , +1 , +SDEI_EVENT_PRIORITY_CRITICAL + }, +};
I understand from the above we currently only support a single static (~ platform) SDEI event with num = KVM_SDEI_DEFAULT_NUM. We do not support bound events. You may add a comment here and maybe in the commit msg. I would rename the variable into exported_events.
Quoted 15 lines
arch/arm64/kvm/sdei.c new file +15
-0+ +static void kvm_sdei_remove_events (struct kvm *kvm) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse, *tmp; + +list_for_each_entry_safe (kse, tmp, &ksdei->events, link) { +list_del (&kse->link); +kfree (kse); + } +} + +static void kvm_sdei_remove_kvm_events (struct kvm *kvm, +unsigned int mask, +bool force)
arch/arm64/kvm/sdei.c line 47
Quoted 10 lines
arch/arm64/kvm/sdei.c new file +10
-0+{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse; +struct kvm_sdei_kvm_event *kske, *tmp; + +list_for_each_entry_safe (kske, tmp, &ksdei->kvm_events, link) { + kse = kske->kse; + +if (!((1 << kse->state.type) & mask)) +continue ;
don't you need to hold a lock before looping? What if sbdy concurrently changes the state fields, especially the refcount below?
arch/arm64/kvm/sdei.c line 50
Quoted 3 lines
arch/arm64/kvm/sdei.c new file +3
-0+ +if (!force && kske->state.refcount) +continue ;
Usually the refcount is used to control the lifetime of the object. The 'force' flag looks wrong in that context. Shouldn't you make sure all users have released their refcounts and on the last decrement, delete the object?
Quoted 46 lines
arch/arm64/kvm/sdei.c new file +46
-0+ +list_del (&kske->link); +kfree (kske); + } +} + +static void kvm_sdei_remove_vcpu_events (struct kvm_vcpu *vcpu) +{ +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_vcpu_event *ksve, *tmp; + +list_for_each_entry_safe (ksve, tmp, &vsdei->critical_events, link) { +list_del (&ksve->link); +kfree (ksve); + } + +list_for_each_entry_safe (ksve, tmp, &vsdei->normal_events, link) { +list_del (&ksve->link); +kfree (ksve); + } +} + +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) +{ +u32 func =smccc_get_function (vcpu); +bool has_result = true; +unsigned long ret; + +switch (func) { +case SDEI_1_0_FN_SDEI_VERSION : +case SDEI_1_0_FN_SDEI_EVENT_REGISTER : +case SDEI_1_0_FN_SDEI_EVENT_ENABLE : +case SDEI_1_0_FN_SDEI_EVENT_DISABLE : +case SDEI_1_0_FN_SDEI_EVENT_CONTEXT : +case SDEI_1_0_FN_SDEI_EVENT_COMPLETE : +case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME : +case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER : +case SDEI_1_0_FN_SDEI_EVENT_STATUS : +case SDEI_1_0_FN_SDEI_EVENT_GET_INFO : +case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET : +case SDEI_1_0_FN_SDEI_PE_MASK : +case SDEI_1_0_FN_SDEI_PE_UNMASK : +case SDEI_1_0_FN_SDEI_INTERRUPT_BIND : +case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE : +case SDEI_1_0_FN_SDEI_PRIVATE_RESET : +case SDEI_1_0_FN_SDEI_SHARED_RESET :
arch/arm64/kvm/sdei.c line 106
Quoted 10 lines
arch/arm64/kvm/sdei.c new file +10
-0+default : + ret =SDEI_NOT_SUPPORTED ; + } + +/* +* We don't have return value for COMPLETE or COMPLETE_AND_RESUME +* hypercalls. Otherwise, the restored context will be corrupted. +*/ +if (has_result) +smccc_set_retval (vcpu, ret,0 ,0 ,0 );
If I understand the above comment, COMPLETE and COMPLETE_AND_RESUME should have has_result set to false whereas in that case they will return NOT_SUPPORTED. Is that OK for the context restore?
Quoted 11 lines
arch/arm64/kvm/sdei.c new file +11
-0+ +return 1 ; +} + +void kvm_sdei_init_vm (struct kvm *kvm) +{ +struct kvm_sdei_kvm *ksdei; +struct kvm_sdei_event *kse; +int i; + + ksdei =kzalloc (sizeof (*ksdei),GFP_KERNEL );
arch/arm64/kvm/sdei.c line 127
Quoted 10 lines
arch/arm64/kvm/sdei.c new file +10
-0+if (!ksdei) +return ; + +spin_lock_init (&ksdei->lock); +INIT_LIST_HEAD (&ksdei->events); +INIT_LIST_HEAD (&ksdei->kvm_events); + +/* +* Populate the defined KVM SDEI events. The whole functionality +* will be disabled on any errors.
You should definitively revise your naming conventions. this brings confusion inbetween exported events and registered events. Why not simply adopt the spec terminology?
arch/arm64/kvm/sdei.c line 135
Quoted 8 lines
arch/arm64/kvm/sdei.c new file +8
-0+*/ +for (i =0 ; i <ARRAY_SIZE (defined_kse); i++) { + kse =kzalloc (sizeof (*kse),GFP_KERNEL ); +if (!kse) { +kvm_sdei_remove_events (kvm); +kfree (ksdei); +return ; + }
Add a comment saying that despite we currently support a single static event we prepare for binding support by building a list of exposed events?
Or maybe simplify the implementation at this stage of the development assuming a single platform event is supported?
Quoted 53 lines
arch/arm64/kvm/sdei.c new file +52
-0+ + kse->kvm = kvm; + kse->state = defined_kse[i]; +list_add_tail (&kse->link, &ksdei->events); + } + + kvm->arch.sdei = ksdei; +} + +void kvm_sdei_create_vcpu (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_vcpu *vsdei; + +if (!kvm->arch.sdei) +return ; + + vsdei =kzalloc (sizeof (*vsdei),GFP_KERNEL ); +if (!vsdei) +return ; + +spin_lock_init (&vsdei->lock); + vsdei->state.masked =1 ; + vsdei->state.critical_num =KVM_SDEI_INVALID_NUM ; + vsdei->state.normal_num =KVM_SDEI_INVALID_NUM ; + vsdei->critical_event =NULL ; + vsdei->normal_event =NULL ; +INIT_LIST_HEAD (&vsdei->critical_events); +INIT_LIST_HEAD (&vsdei->normal_events); + + vcpu->arch.sdei = vsdei; +} + +void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu) +{ +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + +if (vsdei) { +spin_lock (&vsdei->lock); +kvm_sdei_remove_vcpu_events (vcpu); +spin_unlock (&vsdei->lock); + +kfree (vsdei); + vcpu->arch.sdei =NULL ; + } +} + +void kvm_sdei_destroy_vm (struct kvm *kvm) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +unsigned int mask = (1 <<SDEI_EVENT_TYPE_PRIVATE ) | + (1 <<SDEI_EVENT_TYPE_SHARED );
arch/arm64/kvm/sdei.c line 198
Quoted 10 lines
arch/arm64/kvm/sdei.c new file +10
-0+ +if (ksdei) { +spin_lock (&ksdei->lock); + kvm_sdei_remove_kvm_events(kvm, mask, true);> + kvm_sdei_remove_events(kvm); +spin_unlock (&ksdei->lock); + +kfree (ksdei); + kvm->arch.sdei =NULL ; + } +}
Thanks
Eric
Re: [PATCH v4 02/21] KVM: arm64: Add SDEI virtualization infrastructure
Hi Eric,
Quoted 10 lines · Eric Auger
Quoted 8 lines · Gavin Shan
Software Delegated Exception Interface (SDEI) provides a mechanism for registering and servicing system events. Those system events are high priority events, which must be serviced immediately. It's going to be used by Asynchronous Page Fault (APF) to deliver notification from KVM to guest. It's noted that SDEI is defined by ARM DEN0054A specification.
This introduces SDEI virtualization infrastructure where the SDEI events are registered and manuplated by the guest through hypercall. The SDEI
manipulated
Thanks, It will be corrected in next respin.
Quoted 10 lines
Quoted 9 lines
event is delivered to one specific vCPU by KVM once it's raised. This introduces data structures to represent the needed objects to implement the feature, which is highlighted as below. As those objects could be migrated between VMs, these data structures are partially exported to user space.
*
kvm_sdei_event
SDEI events are exported from KVM so that guest is able to register and manuplate.manipulate
Thanks, It will be fixed in next respin. I'm uncertain how the wrong spelling are still existing even though I had spelling check with "scripts/checkpatch.pl --codespell".
Quoted 5 lines
Quoted 2 lines
*
kvm_sdei_kvm_event
SDEI event that has been registered by guest.I would recomment to revisit the names. Why kvm event? Why not
registered_eventinstead that actually would tell what it its. also you have kvm twice in the struct name.
Yep, I think I need reconsider the struct names. The primary reason why I had the names are keeping the struct names short enough while being easy to be identified: "kvm_sdei" is the prefix. How about to have the following struct names?
kvm_sdei_event events exported from KVM to userspace
kvm_sdei_kevent events registered (associated) to KVM
kvm_sdei_vevent events associated with vCPU
kvm_sdei_vcpu vCPU context for event deliveryQuoted 2 lines
Quoted 1 line
*
kvm_sdei_kvm_vcpuDidn't you mean
kvm_sdei_vcpu_eventinstead?
Yeah, you're correct. I was supposed to explain kvm_sdei_vcpu_event here.
Quoted 33 lines
Quoted 33 lines
SDEI event that has been delivered to the target vCPU.
*kvm_sdei_kvm
Place holder of exported and registered SDEI events.
*kvm_sdei_vcpu
Auxiliary object to save the preempted context during SDEI event delivery.The error is returned for all SDEI hypercalls for now. They will be implemented by the subsequent patches.
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_host.h | 6 + arch/arm64/include/asm/kvm_sdei.h | 118 +++++++++++++++ arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/include/uapi/asm/kvm_sdei.h | 60 ++++++++ arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/arm.c | 7 + arch/arm64/kvm/hypercalls.c | 18 +++ arch/arm64/kvm/sdei.c | 198 +++++++++++++++++++++++++ 8 files changed, 409 insertions(+), 1 deletion(-)create mode 100644
arch/arm64/include/asm/kvm_sdei.hcreate mode 100644arch/arm64/include/uapi/asm/kvm_sdei.hcreate mode 100644arch/arm64/kvm/sdei.carch/arm64/include/asm/kvm_host.h +0
-0@@ -113,6 +113,9 @@ struct kvm_arch {/* Interrupt controller */ struct vgic_dist vgic;
Quoted 3 lines
arch/arm64/include/asm/kvm_host.h struct kvm_arch { · line 116
Quoted 1 line
arch/arm64/include/asm/kvm_host.h +1
-0+/* SDEI support */ does not bring much. Why not reusing the commit msg explanation? Here and below.
I would drop the comment in next respin because I want to avoid too much comments to be embedded into "struct kvm_arch". The struct is already huge in terms of number of fields.
Quoted 40 lines
Quoted 40 lines
arch/arm64/include/asm/kvm_host.h +4
-0+struct kvm_sdei_kvm *sdei; +/* Mandated version of PSCI */ u32 psci_version;@@ -339,6 +342,9 @@ struct kvm_vcpu_arch {* here. */ +/* SDEI support */ + struct kvm_sdei_vcpu *sdei;> +/* * Guest registers we preserve during guest debugging. * arch/arm64/include/asm/kvm_sdei.h new file +20
-0@@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Definitions of various KVM SDEI events. +* +* Copyright (C) 2021 Red Hat, Inc. +* +* Author(s): Gavin Shan <[email protected]> +*/ + +#ifndef __ARM64_KVM_SDEI_H__ +#define __ARM64_KVM_SDEI_H__ + +#include <uapi/linux/arm_sdei.h>> +#include <uapi/asm/kvm_sdei.h> +#include <linux/bitmap.h> +#include <linux/list.h> +#include <linux/spinlock.h> + +struct kvm_sdei_event { + struct kvm_sdei_event_state state; + struct kvm *kvm;
Quoted 8 lines
arch/arm64/include/asm/kvm_sdei.h line 28
Quoted 7 lines
arch/arm64/include/asm/kvm_sdei.h new file +7
-0+struct list_head link; +}; + +struct kvm_sdei_kvm_event { +struct kvm_sdei_kvm_event_state state; +struct kvm_sdei_event *kse; +struct kvm *kvm;can't you reuse the kvm handle in state?
Nope, there is no kvm handle in @state.
Quoted 12 lines
Quoted 12 lines
arch/arm64/include/asm/kvm_sdei.h new file +12
-0+struct list_head link; +}; + +struct kvm_sdei_vcpu_event { +struct kvm_sdei_vcpu_event_state state; +struct kvm_sdei_kvm_event *kske; +struct kvm_vcpu *vcpu; +struct list_head link; +}; + +struct kvm_sdei_kvm { +spinlock_t lock;
Quoted 8 lines
arch/arm64/include/asm/kvm_sdei.h line 47
Quoted 7 lines
arch/arm64/include/asm/kvm_sdei.h new file +7
-0+struct list_head events;/* kvm_sdei_event */ +struct list_head kvm_events;/* kvm_sdei_kvm_event */ +}; + +struct kvm_sdei_vcpu { +spinlock_t lock; +struct kvm_sdei_vcpu_state state;could you explain the fields below?
As defined by the specification, each SDEI event is given priority: critical or normal priority. The priority affects how the SDEI event is delivered. The critical event can preempt the normal one, but the reverse thing can't be done.
Quoted 6 lines
Quoted 6 lines
arch/arm64/include/asm/kvm_sdei.h new file +6
-0+struct kvm_sdei_vcpu_event *critical_event; +struct kvm_sdei_vcpu_event *normal_event; +struct list_head critical_events; +struct list_head normal_events; +}; +
Quoted 8 lines
arch/arm64/include/asm/kvm_sdei.h line 60
Quoted 7 lines
arch/arm64/include/asm/kvm_sdei.h new file +7
-0+/* +* According to SDEI specification (v1.0), the event number spans 32-bits +* and the lower 24-bits are used as the (real) event number. I don't +* think we can use that much SDEI numbers in one system. So we reserve +* two bits from the 24-bits real event number, to indicate its types: +* physical event and virtual event. One reserved bit is enough for now, +* but two bits are reserved for possible extension in future. I think this assumption is worth to be mentionned in the commit msg.
Sure, I will explain it in the commit log in next respin.
Quoted 3 lines
arch/arm64/include/asm/kvm_sdei.h line 61
Quoted 2 lines
arch/arm64/include/asm/kvm_sdei.h new file +2
-0+* +* The physical events are owned by underly firmware while the virtual underly?
s/underly firmware/firmware in next respin.
Quoted 10 lines
arch/arm64/include/asm/kvm_sdei.h line 70
Quoted 8 lines
arch/arm64/include/asm/kvm_sdei.h new file +8
-0+* events are used by VMM and KVM. +*/ +#define KVM_SDEI_EV_NUM_TYPE_SHIFT 22 +#define KVM_SDEI_EV_NUM_TYPE_MASK 3 +#define KVM_SDEI_EV_NUM_TYPE_PHYS 0 +#define KVM_SDEI_EV_NUM_TYPE_VIRT 1 + +static inline bool kvm_sdei_is_valid_event_num (unsigned long num)the name of the function does does not really describe what it does. It actually checks the sdei is a virtual one. suggest
kvm_sdei_is_virtual?
The header file is only used by KVM where the virtual SDEI event is the only concern. However, kvm_sdei_is_virtual() is a better name.
Quoted 9 lines
arch/arm64/include/asm/kvm_sdei.h line 77
Quoted 7 lines
arch/arm64/include/asm/kvm_sdei.h new file +7
-0+{ +unsigned long type; + +if (num >>32 ) +return false; + + type = (num >>KVM_SDEI_EV_NUM_TYPE_SHIFT ) &KVM_SDEI_EV_NUM_TYPE_MASK ;I think the the mask generally is applied before shifting. See
include/linux/irqchip/arm-gic-v3.h
Ok, I will adopt the style in next respin.
Quoted 8 lines
Quoted 8 lines
arch/arm64/include/asm/kvm_sdei.h new file +8
-0+if (type !=KVM_SDEI_EV_NUM_TYPE_VIRT ) +return false; + +return true; +} + +/* Accessors for the registration or enablement states of KVM event */ +#define KVM_SDEI_FLAG_FUNC (field) \
Quoted 8 lines
arch/arm64/include/asm/kvm_sdei.h line 92
Quoted 7 lines
arch/arm64/include/asm/kvm_sdei.h new file +7
-0+static inline bool kvm_sdei_is_##field(struct kvm_sdei_kvm_event *kske, \ + unsigned int index) \ +{ \ + return !!test_bit(index, (void *)(kske->state.field)); \ +} \ + \ +static inline bool kvm_sdei_empty_##field(struct kvm_sdei_kvm_event *kske) \nit: s/empty/none ?
"empty" is sticky to bitmap_empty(), but "none" here looks better :)
Quoted 68 lines
Quoted 52 lines
arch/arm64/include/asm/kvm_sdei.h new file +26
-0+{ \ +return bitmap_empty ((void *)(kske->state.field), \ +KVM_SDEI_MAX_VCPUS ); \ +} \ +static inline void kvm_sdei_set_##field(struct kvm_sdei_kvm_event *kske, \ + unsigned int index) \ +{ \ + set_bit(index, (void *)(kske->state.field)); \ +} \ +static inline void kvm_sdei_clear_##field(struct kvm_sdei_kvm_event *kske, \ + unsigned int index) \ +{ \ + clear_bit(index, (void *)(kske->state.field)); \ +} + +KVM_SDEI_FLAG_FUNC(registered) +KVM_SDEI_FLAG_FUNC(enabled) + +/* APIs */ +void kvm_sdei_init_vm(struct kvm *kvm); +void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu); +int kvm_sdei_hypercall(struct kvm_vcpu *vcpu); +void kvm_sdei_destroy_vcpu(struct kvm_vcpu *vcpu); +void kvm_sdei_destroy_vm(struct kvm *kvm); + +#endif /* __ARM64_KVM_SDEI_H__ */ arch/arm64/include/uapi/asm/kvm.h +1
-0@@ -36,6 +36,7 @@#include <linux/types.h> #include <asm/ptrace.h> #include <asm/sve_context.h> +#include <asm/kvm_sdei.h> #define __KVM_HAVE_GUEST_DEBUG#define __KVM_HAVE_IRQ_LINEarch/arm64/include/uapi/asm/kvm_sdei.h new file +8
-0@@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Definitions of various KVM SDEI event states. +* +* Copyright (C) 2021 Red Hat, Inc. +* +* Author(s): Gavin Shan <[email protected]> +*/ arch/arm64/include/uapi/asm/kvm_sdei.h line 18
Quoted 10 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +10
-0+ +#ifndef _UAPI__ASM_KVM_SDEI_H +#define _UAPI__ASM_KVM_SDEI_H + +#ifndef __ASSEMBLY__ +#include <linux/types.h> + +#define KVM_SDEI_MAX_VCPUS 512 +#define KVM_SDEI_INVALID_NUM 0 +#define KVM_SDEI_DEFAULT_NUM 0x40400000The motivation behind introducing such uapi should be clearer (besides just telling this aims at migrating). To me atm, this justification does not make possible to understand if those structs are well suited. You should document the migration process I think.
Quoted 1 line
I would remove
_statesuffix in all of them.
I think so. I will add document "Documentation/virt/kvm/arm/sdei.rst" to explain the design and the corresponding data structs for migration. However, I would keep "state" suffix because I used this field as indicator for data structs to be migrated. However, the structs should be named accordingly since they're embedded to their parent structs:
kvm_sdei_event_state
kvm_sdei_kevent_state
kvm_sdei_vevent_state
kvm_sdei_vcpu_state
Quoted 4 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 20
Quoted 2 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +2
-0+ +struct kvm_sdei_event_state {This is not really a state because it cannot be changed by the guest, right? I would remove
_stateand just call itkvm_sdei_event
The name kvm_sdei_event will be conflicting with same struct, defined in include/asm/kvm_sdei.h. Lets keep "_state" as I explained. I use the suffix as indicator to structs which need migration even though they're not changeable.
Quoted 7 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 25
Quoted 5 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +5
-0+__u64 num; + +__u8 type; +__u8 signaled; +__u8 priority;you need some padding to be 64-bit aligned. See in generic or aarch64
kvm.hfor instance.
Sure.
Quoted 4 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 28
Quoted 3 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +3
-0+}; + +struct kvm_sdei_kvm_event_state {I would rename into
kvm_sdei_registered_eventor smth alike
As above, it will be conflicting with its parent struct, defined in include/asm/kvm_sdei.h
Quoted 2 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 29
Quoted 1 line
arch/arm64/include/uapi/asm/kvm_sdei.h new file +1
-0+__u64 num;how does this num differ from the event state one?
@num is same thing to that in kvm_sdei_event_state. It's used as
index to retrieve corresponding kvm_sdei_event_state. One kvm_sdei_event_state instance can be dereferenced by kvm_sdei_kvm_event_state and kvm_sdei_kvm_vcpu_event_state. It's why we don't embed kvm_sdei_event_state in them, to avoid duplicated traffic in migration.
Quoted 6 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 32
Quoted 3 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +3
-0+__u32 refcount; + +__u8 route_mode;padding also here. See for instance
https://lore.kernel.org/kvm/[email protected]/T/#m7bac2ff2b28a68f8d2196ec452afd3e46682760d
Quoted 6 lines
Maybe put the the
route_modefield and refcount at the end and add one byte of padding?Why can't we have a single
sdei_eventuapi representation where route mode defaults to unset and refcount defaults to 0 when not registered?
Ok. I will fix the padding and alignment in next respin. The @route_affinity can be changed on request from the guest. The @refcount helps to prevent the event from being unregistered if it's still dereferenced by kvm_sdei_vcpu_event_state.
Quoted 4 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 35
Quoted 3 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +3
-0+__u64 route_affinity; +__u64 entries[KVM_SDEI_MAX_VCPUS ]; +__u64 params[KVM_SDEI_MAX_VCPUS ];I would rename entries into
ep_addressand params intoep_arg.
Ok, but what does "ep" means? I barely guess it's "entry point". I'm not sure if you're talking about "PE" here.
Quoted 4 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 36
Quoted 1 line
arch/arm64/include/uapi/asm/kvm_sdei.h new file +1
-0+__u64 registered[KVM_SDEI_MAX_VCPUS /64 ];maybe add a comment along with
KVM_SDEI_MAX_VCPUSthat it must be a multiple of 64 (or a build check)
Sure.
Quoted 4 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 37
Quoted 1 line
arch/arm64/include/uapi/asm/kvm_sdei.h new file +1
-0+__u64 enabled[KVM_SDEI_MAX_VCPUS /64 ];Also you may clarify what this gets used for a shared event. I guess this only makes sense for a private event which can be registered by several EPs?
Nope, they're used by both shared and private events. For shared event, the bit#0 is used to indicate the state, while the individual bit is used for the private event. Yes, the private event can be registered and enabled separately on multiple PEs.
Quoted 7 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 42
Quoted 5 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +5
-0+}; + +struct kvm_sdei_vcpu_event_state { +__u64 num; +__u32 refcount;how does it differ from num and refcount of the registered event? padding++
About @num and @refcount, please refer to the above explanation. Yes, I will fix padding in next respin.
Quoted 11 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 52
Quoted 10 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +10
-0+}; + +struct kvm_sdei_vcpu_regs { +__u64 regs[18 ]; +__u64 pc; +__u64 pstate; +}; + +struct kvm_sdei_vcpu_state { +__u8 masked;padding++
Ok.
Quoted 112 lines
Quoted 112 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +7
-0+__u64 critical_num; +__u64 normal_num; +struct kvm_sdei_vcpu_regs critical_regs; +struct kvm_sdei_vcpu_regs normal_regs; +};> + +#endif /* !__ASSEMBLY__ */ +#endif /* _UAPI__ASM_KVM_SDEI_H */ arch/arm64/kvm/Makefile +1
-1@@ -16,7 +16,7 @@ kvm-y := $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o \ inject_fault.o va_layout.o handle_exit.o \ guest.o debug.o reset.o sys_regs.o \ vgic-sys-reg-v3.o fpsimd.o pmu.o \ - arch_timer.o trng.o\ + arch_timer.o trng.o sdei.o \ vgic/vgic.o vgic/vgic-init.o \ vgic/vgic-irqfd.o vgic/vgic-v2.o \ vgic/vgic-v3.o vgic/vgic-v4.o \arch/arm64/kvm/arm.c +7
-0@@ -150,6 +150,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)kvm_vgic_early_init (kvm); +kvm_sdei_init_vm (kvm); +/* The maximum number of VCPUs is limited by the host's GIC model */ kvm->arch.max_vcpus =kvm_arm_default_max_vcpus ();@@ -179,6 +181,8 @@ void kvm_arch_destroy_vm(struct kvm *kvm)kvm_vgic_destroy (kvm); +kvm_sdei_destroy_vm (kvm); +for (i =0 ; i <KVM_MAX_VCPUS ; ++i) {if (kvm->vcpus[i]) {kvm_vcpu_destroy (kvm->vcpus[i]);@@ -333,6 +337,8 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)kvm_arm_pvtime_vcpu_init (&vcpu->arch); +kvm_sdei_create_vcpu (vcpu); + vcpu->arch.hw_mmu = &vcpu->kvm->arch.mmu; err =kvm_vgic_vcpu_init (vcpu);@@ -354,6 +360,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)kvm_mmu_free_memory_cache (&vcpu->arch.mmu_page_cache);kvm_timer_vcpu_terminate (vcpu);kvm_pmu_vcpu_destroy (vcpu); +kvm_sdei_destroy_vcpu (vcpu);kvm_arm_vcpu_destroy (vcpu); }arch/arm64/kvm/hypercalls.c +18
-0@@ -139,6 +139,24 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)case ARM_SMCCC_TRNG_RND32 :case ARM_SMCCC_TRNG_RND64 :return kvm_trng_call (vcpu); +case SDEI_1_0_FN_SDEI_VERSION : +case SDEI_1_0_FN_SDEI_EVENT_REGISTER : +case SDEI_1_0_FN_SDEI_EVENT_ENABLE : +case SDEI_1_0_FN_SDEI_EVENT_DISABLE : +case SDEI_1_0_FN_SDEI_EVENT_CONTEXT : +case SDEI_1_0_FN_SDEI_EVENT_COMPLETE : +case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME : +case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER : +case SDEI_1_0_FN_SDEI_EVENT_STATUS : +case SDEI_1_0_FN_SDEI_EVENT_GET_INFO : +case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET : +case SDEI_1_0_FN_SDEI_PE_MASK : +case SDEI_1_0_FN_SDEI_PE_UNMASK : +case SDEI_1_0_FN_SDEI_INTERRUPT_BIND : +case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE : +case SDEI_1_0_FN_SDEI_PRIVATE_RESET : +case SDEI_1_0_FN_SDEI_SHARED_RESET : +return kvm_sdei_hypercall (vcpu);default :return kvm_psci_call (vcpu); }arch/arm64/kvm/sdei.c new file +18
-0@@ -0,0 +1,198 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* SDEI virtualization support. +* +* Copyright (C) 2021 Red Hat, Inc. +* +* Author(s): Gavin Shan <[email protected]> +*/ + +#include <linux/kernel.h> +#include <linux/kvm_host.h> +#include <linux/spinlock.h> +#include <linux/slab.h> +#include <kvm/arm_hypercalls.h> + +static struct kvm_sdei_event_state defined_kse[] = { + {KVM_SDEI_DEFAULT_NUM , +SDEI_EVENT_TYPE_PRIVATE ,
Quoted 8 lines
arch/arm64/kvm/sdei.c line 22
Quoted 4 lines
arch/arm64/kvm/sdei.c new file +4
-0+ 1, +SDEI_EVENT_PRIORITY_CRITICAL + }, +};I understand from the above we currently only support a single static (~ platform) SDEI event with num =
KVM_SDEI_DEFAULT_NUM. We do not support bound events. You may add a comment here and maybe in the commit msg. I would rename the variable intoexported_events.
Yeah, we may enhance it to allow userspace to add more in future, but not now. Ok, I will rename it to @exported_events.
Quoted 19 lines
Quoted 19 lines
arch/arm64/kvm/sdei.c new file +19
-0+ +static void kvm_sdei_remove_events (struct kvm *kvm) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse, *tmp; + +list_for_each_entry_safe (kse, tmp, &ksdei->events, link) { +list_del (&kse->link); +kfree (kse); + } +} + +static void kvm_sdei_remove_kvm_events (struct kvm *kvm, +unsigned int mask, +bool force) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse; +struct kvm_sdei_kvm_event *kske, *tmp;
Quoted 8 lines
arch/arm64/kvm/sdei.c line 47
Quoted 6 lines
arch/arm64/kvm/sdei.c new file +6
-0+ +list_for_each_entry_safe (kske, tmp, &ksdei->kvm_events, link) { + kse = kske->kse; + +if (!((1 << kse->state.type) & mask)) +continue ;don't you need to hold a lock before looping? What if sbdy concurrently changes the state fields, especially the refcount below?
Yes, the caller holds @kvm->sdei_lock.
Quoted 7 lines
arch/arm64/kvm/sdei.c line 50
Quoted 3 lines
arch/arm64/kvm/sdei.c new file +3
-0+ +if (!force && kske->state.refcount) +continue ;Usually the refcount is used to control the lifetime of the object. The 'force' flag looks wrong in that context. Shouldn't you make sure all users have released their refcounts and on the last decrement, delete the object?
@force is used for exceptional case. For example, the KVM process is killed before the event reference count gets chance to be dropped.
Quoted 51 lines
Quoted 51 lines
arch/arm64/kvm/sdei.c new file +51
-0+ +list_del (&kske->link); +kfree (kske); + } +} + +static void kvm_sdei_remove_vcpu_events (struct kvm_vcpu *vcpu) +{ +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_vcpu_event *ksve, *tmp; + +list_for_each_entry_safe (ksve, tmp, &vsdei->critical_events, link) { +list_del (&ksve->link); +kfree (ksve); + } + +list_for_each_entry_safe (ksve, tmp, &vsdei->normal_events, link) { +list_del (&ksve->link); +kfree (ksve); + } +} + +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) +{ +u32 func =smccc_get_function (vcpu); +bool has_result = true; +unsigned long ret; + +switch (func) { +case SDEI_1_0_FN_SDEI_VERSION : +case SDEI_1_0_FN_SDEI_EVENT_REGISTER : +case SDEI_1_0_FN_SDEI_EVENT_ENABLE : +case SDEI_1_0_FN_SDEI_EVENT_DISABLE : +case SDEI_1_0_FN_SDEI_EVENT_CONTEXT : +case SDEI_1_0_FN_SDEI_EVENT_COMPLETE : +case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME : +case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER : +case SDEI_1_0_FN_SDEI_EVENT_STATUS : +case SDEI_1_0_FN_SDEI_EVENT_GET_INFO : +case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET : +case SDEI_1_0_FN_SDEI_PE_MASK : +case SDEI_1_0_FN_SDEI_PE_UNMASK : +case SDEI_1_0_FN_SDEI_INTERRUPT_BIND : +case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE : +case SDEI_1_0_FN_SDEI_PRIVATE_RESET : +case SDEI_1_0_FN_SDEI_SHARED_RESET : +default : + ret =SDEI_NOT_SUPPORTED ; + } + +/*
Quoted 8 lines
arch/arm64/kvm/sdei.c line 106
Quoted 5 lines
arch/arm64/kvm/sdei.c new file +5
-0+* We don't have return value for COMPLETE or COMPLETE_AND_RESUME +* hypercalls. Otherwise, the restored context will be corrupted. +*/ +if (has_result) +smccc_set_retval (vcpu, ret,0 ,0 ,0 );If I understand the above comment, COMPLETE and
COMPLETE_AND_RESUMEshould havehas_resultset to false whereas in that case they will returnNOT_SUPPORTED. Is that OK for the context restore?
Nice catch! @has_result needs to be false for COMPLETE and COMPLETE_AND_RESUME.
Quoted 16 lines
Quoted 16 lines
arch/arm64/kvm/sdei.c new file +16
-0+ +return 1 ; +} + +void kvm_sdei_init_vm (struct kvm *kvm) +{ +struct kvm_sdei_kvm *ksdei; +struct kvm_sdei_event *kse; +int i; + + ksdei =kzalloc (sizeof (*ksdei),GFP_KERNEL ); +if (!ksdei) +return ; + +spin_lock_init (&ksdei->lock); +INIT_LIST_HEAD (&ksdei->events);
Quoted 8 lines
arch/arm64/kvm/sdei.c line 127
Quoted 5 lines
arch/arm64/kvm/sdei.c new file +5
-0+INIT_LIST_HEAD (&ksdei->kvm_events); + +/* +* Populate the defined KVM SDEI events. The whole functionality +* will be disabled on any errors. You should definitively revise your naming conventions. this brings confusion inbetween exported events and registered events. Why not simply adopt the spec terminology?
Yeah, I think so, but I think "defined KVM SDEI events" is following the specification because the SDEI event is defined by the firmware as the specification says. We're emulating firmware in KVM here.
Quoted 11 lines
arch/arm64/kvm/sdei.c line 135
Quoted 8 lines
arch/arm64/kvm/sdei.c new file +8
-0+*/ +for (i =0 ; i <ARRAY_SIZE (defined_kse); i++) { + kse =kzalloc (sizeof (*kse),GFP_KERNEL ); +if (!kse) { +kvm_sdei_remove_events (kvm); +kfree (ksdei); +return ; + }Add a comment saying that despite we currently support a single static event we prepare for binding support by building a list of exposed events?
Quoted 2 lines
Or maybe simplify the implementation at this stage of the development assuming a single platform event is supported?
I will add comment as you suggested in next respin. Note that another entry will be added to the defined event array when Async PF is involved.
Quoted 55 lines
Quoted 55 lines
arch/arm64/kvm/sdei.c new file +55
-0+ + kse->kvm = kvm; + kse->state = defined_kse[i]; +list_add_tail (&kse->link, &ksdei->events); + } + + kvm->arch.sdei = ksdei; +} + +void kvm_sdei_create_vcpu (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_vcpu *vsdei; + +if (!kvm->arch.sdei) +return ; + + vsdei =kzalloc (sizeof (*vsdei),GFP_KERNEL ); +if (!vsdei) +return ; + +spin_lock_init (&vsdei->lock); + vsdei->state.masked =1 ; + vsdei->state.critical_num =KVM_SDEI_INVALID_NUM ; + vsdei->state.normal_num =KVM_SDEI_INVALID_NUM ; + vsdei->critical_event =NULL ; + vsdei->normal_event =NULL ; +INIT_LIST_HEAD (&vsdei->critical_events); +INIT_LIST_HEAD (&vsdei->normal_events); + + vcpu->arch.sdei = vsdei; +} + +void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu) +{ +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + +if (vsdei) { +spin_lock (&vsdei->lock); +kvm_sdei_remove_vcpu_events (vcpu); +spin_unlock (&vsdei->lock); + +kfree (vsdei); + vcpu->arch.sdei =NULL ; + } +} + +void kvm_sdei_destroy_vm (struct kvm *kvm) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +unsigned int mask = (1 <<SDEI_EVENT_TYPE_PRIVATE ) | + (1 <<SDEI_EVENT_TYPE_SHARED ); + +if (ksdei) { +spin_lock (&ksdei->lock);
Quoted 8 lines
arch/arm64/kvm/sdei.c line 198
Quoted 8 lines
arch/arm64/kvm/sdei.c new file +7
-0+ kvm_sdei_remove_kvm_events(kvm, mask, true);> + kvm_sdei_remove_events(kvm); +spin_unlock (&ksdei->lock); + +kfree (ksdei); + kvm->arch.sdei =NULL ; + } +}
Thanks,
Gavin
Re: [PATCH v4 02/21] KVM: arm64: Add SDEI virtualization infrastructure
Hi Gavin,
Quoted 26 lines · Gavin Shan
Hi Eric,
Quoted 10 lines · Eric Auger
Quoted 8 lines · Gavin Shan
Software Delegated Exception Interface (SDEI) provides a mechanism for registering and servicing system events. Those system events are high priority events, which must be serviced immediately. It's going to be used by Asynchronous Page Fault (APF) to deliver notification from KVM to guest. It's noted that SDEI is defined by ARM DEN0054A specification.
This introduces SDEI virtualization infrastructure where the SDEI events are registered and manuplated by the guest through hypercall. The SDEI
manipulated
Thanks, It will be corrected in next respin.
Quoted 10 lines
Quoted 10 lines
event is delivered to one specific vCPU by KVM once it's raised. This introduces data structures to represent the needed objects to implement the feature, which is highlighted as below. As those objects could be migrated between VMs, these data structures are partially exported to user space.
*
kvm_sdei_event
SDEI events are exported from KVM so that guest is able to register
and manuplate.
Quoted 5 lines
Quoted 1 line
manipulate
Thanks, It will be fixed in next respin. I'm uncertain how the wrong spelling are still existing even though I had spelling check with "
scripts/checkpatch.pl--codespell".
I don't know. I am not used to it :(
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
*
kvm_sdei_kvm_event
SDEI event that has been registered by guest.I would recomment to revisit the names. Why kvm event? Why not
registered_eventinstead that actually would tell what it its. also you have kvm twice in the struct name.Yep, I think I need reconsider the struct names. The primary reason why I had the names are keeping the struct names short enough while being easy to be identified: "
kvm_sdei" is the prefix. How about to have the following struct names?
also kvm_sdei_kvm looks awkward to me. since it is arch specific, couldn't you name kvm_sdei_arch?
Quoted 3 lines
kvm_sdei_event events exported from KVM to userspace kvm_sdei_kevent events registered (associated) to KVM
I still don't find kevent self explanatory. and even confusing because it makes me think of events exposed by kvm.
To me there are exposed events and registered events and I think it would be simpler to stick to this terminology. I would rather rename kevent into registered_event.
Quoted 1 line
kvm_sdei_vevent events associated with vCPU
s/vevent/vcpu_event otherwise sounds like virtual event
Quoted 44 lines
kvm_sdei_vcpu vCPU context for event delivery
Quoted 2 lines
Quoted 1 line
*
kvm_sdei_kvm_vcpuDidn't you mean
kvm_sdei_vcpu_eventinstead?Yeah, you're correct. I was supposed to explain
kvm_sdei_vcpu_eventhere.Quoted 25 lines
Quoted 25 lines
SDEI event that has been delivered to the target vCPU.
*kvm_sdei_kvm
Place holder of exported and registered SDEI events.
*kvm_sdei_vcpu
Auxiliary object to save the preempted context during SDEI event delivery.The error is returned for all SDEI hypercalls for now. They will be implemented by the subsequent patches.
Signed-off-by Gavin Shan <[email protected]>---
arch/arm64/include/asm/kvm_host.h | 6 + arch/arm64/include/asm/kvm_sdei.h | 118 +++++++++++++++ arch/arm64/include/uapi/asm/kvm.h | 1 +
arch/arm64/include/uapi/asm/kvm_sdei.h| 60 ++++++++ arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/arm.c | 7 + arch/arm64/kvm/hypercalls.c | 18 +++ arch/arm64/kvm/sdei.c | 198 +++++++++++++++++++++++++8 files changed, 409 insertions(+), 1 deletion(-)create mode 100644
arch/arm64/include/asm/kvm_sdei.hcreate mode 100644arch/arm64/include/uapi/asm/kvm_sdei.hcreate mode 100644arch/arm64/kvm/sdei.cQuoted 11 lines
Quoted 9 lines
arch/arm64/include/asm/kvm_host.h +0
-0@@ -113,6 +113,9 @@ struct kvm_arch { /* Interrupt controller */ struct vgic_dist vgic;+ /* SDEI support */
does not bring much. Why not reusing the commit msg explanation? Here and below.
Quoted 3 lines
I would drop the comment in next respin because I want to avoid too much comments to be embedded into "struct
kvm_arch". The struct is already huge in terms of number of fields.
Yep I would drop it too.
Quoted 48 lines
Quoted 39 lines
Quoted 39 lines
+ struct
kvm_sdei_kvm*sdei;
+
/* Mandated version of PSCI */
u32psci_version;
@@ -339,6 +342,9 @@ structkvm_vcpu_arch{
* here.
*/
+ /* SDEI support */
+ structkvm_sdei_vcpu*sdei;> +
/*
* Guest registers we preserve during guest debugging. *arch/arm64/include/asm/kvm_sdei.h new file +19
-0@@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Definitions of various KVM SDEI events. +* +* Copyright (C) 2021 Red Hat, Inc. +* +* Author(s): Gavin Shan <[email protected]> +*/ + +#ifndef __ARM64_KVM_SDEI_H__ +#define __ARM64_KVM_SDEI_H__ + +#include <uapi/linux/arm_sdei.h>> +#include <uapi/asm/kvm_sdei.h> +#include <linux/bitmap.h> +#include <linux/list.h> +#include <linux/spinlock.h> + +struct kvm_sdei_event { + struct kvm_sdei_event_state state;Quoted 8 lines
arch/arm64/include/asm/kvm_sdei.h line 28
Quoted 7 lines
arch/arm64/include/asm/kvm_sdei.h new file +7
-0+ struct kvm *kvm; + struct list_head link;>>> +}; + +struct kvm_sdei_kvm_event { + struct kvm_sdei_kvm_event_state state; + struct kvm_sdei_event *kse; + struct kvm *kvm;can't you reuse the kvm handle in state?
Quoted 1 line
Nope, there is no kvm handle in @state.
right mixed names sorry
Quoted 193 lines
Quoted 13 lines
Quoted 13 lines
arch/arm64/include/asm/kvm_sdei.h new file +12
-0+ struct list_head link; +}; + +struct kvm_sdei_vcpu_event { + struct kvm_sdei_vcpu_event_state state; + struct kvm_sdei_kvm_event *kske; + struct kvm_vcpu *vcpu; + struct list_head link; +}; + +struct kvm_sdei_kvm { + spinlock_t lock;Quoted 8 lines
arch/arm64/include/asm/kvm_sdei.h line 47
Quoted 7 lines
arch/arm64/include/asm/kvm_sdei.h new file +7
-0+ struct list_head events; /* kvm_sdei_event */ + struct list_head kvm_events; /* kvm_sdei_kvm_event */ +}; + +struct kvm_sdei_vcpu { + spinlock_t lock; + struct kvm_sdei_vcpu_state state;could you explain the fields below?
As defined by the specification, each SDEI event is given priority:
critical
or normal priority. The priority affects how the SDEI event is delivered. The critical event can preempt the normal one, but the reverse thing can't be done.Quoted 8 lines
Quoted 8 lines
arch/arm64/include/asm/kvm_sdei.h new file +8
-0+ struct kvm_sdei_vcpu_event *critical_event; + struct kvm_sdei_vcpu_event *normal_event; + struct list_head critical_events; + struct list_head normal_events; +}; + +/* +* According to SDEI specification (v1.0), the event number spans Quoted 8 lines
Quoted 7 lines
32-bits
+ * and the lower 24-bits are used as the (real) event number. I don't
+ * think we can use that much SDEI numbers in one system. So we reserve
+ * two bits from the 24-bits real event number, to indicate its types:
+ * physical event and virtual event. One reserved bit is enough for now,
+ * but two bits are reserved for possible extension in future.I think this assumption is worth to be mentionned in the commit msg.
Sure, I will explain it in the commit log in next respin.
Quoted 3 lines
Quoted 2 lines
+ *
+ * The physical events are owned by underly firmware while the virtualunderly?
s/underly
firmware/firmwarein next respin.Quoted 10 lines
arch/arm64/include/asm/kvm_sdei.h line 70
Quoted 8 lines
+ * events are used by VMM and KVM.
+ */arch/arm64/include/asm/kvm_sdei.h new file +6
-0+#define KVM_SDEI_EV_NUM_TYPE_SHIFT 22 +#define KVM_SDEI_EV_NUM_TYPE_MASK 3 +#define KVM_SDEI_EV_NUM_TYPE_PHYS 0 +#define KVM_SDEI_EV_NUM_TYPE_VIRT 1 + +static inline bool kvm_sdei_is_valid_event_num (unsigned long num)the name of the function does does not really describe what it does. It actually checks the sdei is a virtual one. suggest
kvm_sdei_is_virtual?The header file is only used by KVM where the virtual SDEI event is the only concern. However,
kvm_sdei_is_virtual()is a better name.Quoted 10 lines
Quoted 8 lines
arch/arm64/include/asm/kvm_sdei.h new file +7
-0+{ + unsigned long type; + + if (num >> 32) + return false; + + type = (num >> KVM_SDEI_EV_NUM_TYPE_SHIFT) &
KVM_SDEI_EV_NUM_TYPE_MASK;I think the the mask generally is applied before shifting. See
include/linux/irqchip/arm-gic-v3.hOk, I will adopt the style in next respin.
Quoted 10 lines
Quoted 10 lines
+ if (type !=
KVM_SDEI_EV_NUM_TYPE_VIRT)
+ return false;arch/arm64/include/asm/kvm_sdei.h new file +7
-0+ + return true; +} + +/* Accessors for the registration or enablement states of KVM event */ +#define KVM_SDEI_FLAG_FUNC (field) \ +static inline bool kvm_sdei_is_##field(struct kvm_sdei_kvm_event*kske, \
Quoted 8 lines
Quoted 7 lines
+ unsigned int index) \
arch/arm64/include/asm/kvm_sdei.h new file +5
-0+{ \ + return !!test_bit(index, (void *)(kske->state.field)); \ +} \ + \ +static inline bool kvm_sdei_empty_##field(struct kvm_sdei_kvm_event*kske) \
nit: s/empty/none ?
"empty" is sticky to
bitmap_empty(), but "none" here looks better :)Quoted 71 lines
Quoted 55 lines
arch/arm64/include/asm/kvm_sdei.h new file +5
-0+{ \ + return bitmap_empty((void *)(kske->state.field), \ + KVM_SDEI_MAX_VCPUS); \ +} \ +static inline void kvm_sdei_set_##field(struct kvm_sdei_kvm_event*kske, \
+ unsigned int index) \arch/arm64/include/asm/kvm_sdei.h new file +4
-0+{ \ + set_bit(index, (void *)(kske->state.field)); \ +} \ +static inline void kvm_sdei_clear_##field(struct kvm_sdei_kvm_event*kske, \
+ unsigned int index) \arch/arm64/include/asm/kvm_sdei.h new file +15
-0+{ \ + clear_bit(index, (void *)(kske->state.field)); \ +} + +KVM_SDEI_FLAG_FUNC(registered) +KVM_SDEI_FLAG_FUNC(enabled) + +/* APIs */ +void kvm_sdei_init_vm(struct kvm *kvm); +void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu); +int kvm_sdei_hypercall(struct kvm_vcpu *vcpu); +void kvm_sdei_destroy_vcpu(struct kvm_vcpu *vcpu); +void kvm_sdei_destroy_vm(struct kvm *kvm); + +#endif /* __ARM64_KVM_SDEI_H__ */ arch/arm64/include/uapi/asm/kvm.h +1
-0@@ -36,6 +36,7 @@ #include <linux/types.h> #include <asm/ptrace.h> #include <asm/sve_context.h> +#include <asm/kvm_sdei.h> #define __KVM_HAVE_GUEST_DEBUG #define __KVM_HAVE_IRQ_LINEarch/arm64/include/uapi/asm/kvm_sdei.h new file +8
-0@@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Definitions of various KVM SDEI event states. +* +* Copyright (C) 2021 Red Hat, Inc. +* +* Author(s): Gavin Shan <[email protected]> +*/ arch/arm64/include/uapi/asm/kvm_sdei.h line 18
Quoted 10 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +10
-0+ +#ifndef _UAPI__ASM_KVM_SDEI_H +#define _UAPI__ASM_KVM_SDEI_H + +#ifndef __ASSEMBLY__ +#include <linux/types.h> + +#define KVM_SDEI_MAX_VCPUS 512 +#define KVM_SDEI_INVALID_NUM 0 +#define KVM_SDEI_DEFAULT_NUM 0x40400000The motivation behind introducing such uapi should be clearer (besides just telling this aims at migrating). To me atm, this justification does not make possible to understand if those structs are well suited. You should document the migration process I think.
Quoted 1 line
I would remove
_statesuffix in all of them.I think so. I will add document "
Documentation/virt/kvm/arm/sdei.rst" to explain the design and the corresponding data structs for migration. However,
I would keep "state" suffix because I used this field as indicator for data structs to be migrated. However, the structs should be named accordingly
since they're embedded to their parent structs:
kvm_sdei_event_state
kvm_sdei_kevent_state
kvm_sdei_vevent_state
kvm_sdei_vcpu_stateQuoted 4 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 20
Quoted 2 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +2
-0+ +struct kvm_sdei_event_state {This is not really a state because it cannot be changed by the guest, right? I would remove
_stateand just call itkvm_sdei_event
Quoted 4 lines
The name
kvm_sdei_eventwill be conflicting with same struct, defined ininclude/asm/kvm_sdei.h. Lets keep "_state" as I explained. I use the suffix as indicator to structs which need migration even though they're not changeable.
ok
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +5
-0+ __u64 num; + + __u8 type; + __u8 signaled; + __u8 priority;
Quoted 9 lines
Quoted 2 lines
you need some padding to be 64-bit aligned. See in generic or aarch64
kvm.hfor instance.Sure.
Quoted 4 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 28
Quoted 3 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +3
-0+}; + +struct kvm_sdei_kvm_event_state {I would rename into
kvm_sdei_registered_eventor smth alike
anyway the doc explaining the migration process will help here.
Quoted 36 lines
As above, it will be conflicting with its parent struct, defined in
include/asm/kvm_sdei.hQuoted 2 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 29
Quoted 1 line
arch/arm64/include/uapi/asm/kvm_sdei.h new file +1
-0+ __u64 num;how does this num differ from the event state one?
@num is same thing to that in
kvm_sdei_event_state. It's used as index to retrieve correspondingkvm_sdei_event_state. Onekvm_sdei_event_state
instance can be dereferenced bykvm_sdei_kvm_event_stateandkvm_sdei_kvm_vcpu_event_state.
It's why we don't embedkvm_sdei_event_statein them, to avoid duplicated traffic in migration.Quoted 7 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 32
Quoted 3 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +3
-0+ __u32 refcount; + + __u8 route_mode;padding also here. See for instance
https://lore.kernel.org/kvm/[email protected]/T/#m7bac2ff2b28a68f8d2196ec452afd3e46682760dQuoted 6 lines
Maybe put the the
route_modefield and refcount at the end and add one byte of padding?Why can't we have a single
sdei_eventuapi representation where route mode defaults to unset and refcount defaults to 0 when not registered?Ok. I will fix the padding and alignment in next respin. The @route_affinity
can be changed on request from the guest. The @refcount helps to prevent the
event from being unregistered if it's still dereferenced bykvm_sdei_vcpu_event_state.
Quoted 7 lines
Quoted 4 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 35
Quoted 3 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +3
-0+ __u64 route_affinity; + __u64 entries[KVM_SDEI_MAX_VCPUS]; + __u64 params[KVM_SDEI_MAX_VCPUS];I would rename entries into
ep_addressand params intoep_arg.Ok, but what does "ep" means? I barely guess it's "entry point". I'm not sure if you're talking about "PE" here.
ep = entry point
Quoted 194 lines
Quoted 5 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 36
Quoted 2 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +1
-0+ __u64 registered[KVM_SDEI_MAX_VCPUS/64];maybe add a comment along with
KVM_SDEI_MAX_VCPUSthat it must be a multiple of 64 (or a build check)Sure.
Quoted 4 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 37
Quoted 1 line
arch/arm64/include/uapi/asm/kvm_sdei.h new file +1
-0+ __u64 enabled[KVM_SDEI_MAX_VCPUS/64];Also you may clarify what this gets used for a shared event. I guess this only makes sense for a private event which can be registered by several EPs?
Nope, they're used by both shared and private events. For shared event, the bit#0 is used to indicate the state, while the individual bit is used for the private eventYes, the private event can be registered and enabled separately on multiple PEs.
Quoted 7 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 42
Quoted 5 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +5
-0+}; + +struct kvm_sdei_vcpu_event_state { + __u64 num; + __u32 refcount;how does it differ from num and refcount of the registered event? padding++
About @num and @refcount, please refer to the above explanation. Yes, I will fix padding in next respin.
Quoted 11 lines
arch/arm64/include/uapi/asm/kvm_sdei.h line 52
Quoted 10 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +10
-0+}; + +struct kvm_sdei_vcpu_regs { + __u64 regs[18]; + __u64 pc; + __u64 pstate; +}; + +struct kvm_sdei_vcpu_state { + __u8 masked;padding++
Ok.
Quoted 106 lines
Quoted 106 lines
arch/arm64/include/uapi/asm/kvm_sdei.h new file +7
-0+ __u64 critical_num; + __u64 normal_num; + struct kvm_sdei_vcpu_regs critical_regs; + struct kvm_sdei_vcpu_regs normal_regs; +};> + +#endif /* !__ASSEMBLY__ */ +#endif /* _UAPI__ASM_KVM_SDEI_H */ arch/arm64/kvm/Makefile +1
-1@@ -16,7 +16,7 @@ kvm-y := $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o \ inject_fault.o va_layout.o handle_exit.o \ guest.o debug.o reset.o sys_regs.o \ vgic-sys-reg-v3.o fpsimd.o pmu.o \ - arch_timer.o trng.o\ + arch_timer.o trng.o sdei.o \ vgic/vgic.o vgic/vgic-init.o \ vgic/vgic-irqfd.o vgic/vgic-v2.o \
vgic/vgic-v3.ovgic/vgic-v4.o\arch/arm64/kvm/arm.c +1
-0@@ -150,6 +150,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) kvm_vgic_early_init(kvm); + kvm_sdei_init_vm(kvm); + /* The maximum number of VCPUs is limited by the host's GICmodel */
kvm->arch.max_vcpus=kvm_arm_default_max_vcpus(); @@ -179,6 +181,8 @@ voidkvm_arch_destroy_vm(struct kvm *kvm)kvm_vgic_destroy(kvm);
+kvm_sdei_destroy_vm(kvm);
+
for (i = 0; i <KVM_MAX_VCPUS; ++i) {
if (kvm->vcpus[i]) {kvm_vcpu_destroy(kvm->vcpus[i]);arch/arm64/kvm/arm.c +2
-0@@ -333,6 +337,8 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) kvm_arm_pvtime_vcpu_init(&vcpu->arch); + kvm_sdei_create_vcpu(vcpu); + vcpu->arch.hw_mmu = &vcpu->kvm->arch.mmu; err = kvm_vgic_vcpu_init(vcpu);@@ -354,6 +360,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) kvm_mmu_free_memory_cache(&vcpu->arch.mmu_page_cache); kvm_timer_vcpu_terminate(vcpu); kvm_pmu_vcpu_destroy(vcpu); + kvm_sdei_destroy_vcpu(vcpu); kvm_arm_vcpu_destroy(vcpu); }arch/arm64/kvm/hypercalls.c +0
-0@@ -139,6 +139,24 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)case
ARM_SMCCC_TRNG_RND32:
caseARM_SMCCC_TRNG_RND64:
returnkvm_trng_call(vcpu);
+ caseSDEI_1_0_FN_SDEI_VERSION:
+ caseSDEI_1_0_FN_SDEI_EVENT_REGISTER:
+ caseSDEI_1_0_FN_SDEI_EVENT_ENABLE:
+ caseSDEI_1_0_FN_SDEI_EVENT_DISABLE:
+ caseSDEI_1_0_FN_SDEI_EVENT_CONTEXT:
+ caseSDEI_1_0_FN_SDEI_EVENT_COMPLETE:
+ caseSDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME:
+ caseSDEI_1_0_FN_SDEI_EVENT_UNREGISTER:
+ caseSDEI_1_0_FN_SDEI_EVENT_STATUS:
+ caseSDEI_1_0_FN_SDEI_EVENT_GET_INFO:
+ caseSDEI_1_0_FN_SDEI_EVENT_ROUTING_SET:
+ caseSDEI_1_0_FN_SDEI_PE_MASK:
+ caseSDEI_1_0_FN_SDEI_PE_UNMASK:
+ caseSDEI_1_0_FN_SDEI_INTERRUPT_BIND:
+ caseSDEI_1_0_FN_SDEI_INTERRUPT_RELEASE:
+ caseSDEI_1_0_FN_SDEI_PRIVATE_RESET:
+ caseSDEI_1_0_FN_SDEI_SHARED_RESET:
+ returnkvm_sdei_hypercall(vcpu); default:
returnkvm_psci_call(vcpu);
}arch/arm64/kvm/sdei.c new file +18
-0@@ -0,0 +1,198 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* SDEI virtualization support. +* +* Copyright (C) 2021 Red Hat, Inc. +* +* Author(s): Gavin Shan <[email protected]> +*/ + +#include <linux/kernel.h> +#include <linux/kvm_host.h> +#include <linux/spinlock.h> +#include <linux/slab.h> +#include <kvm/arm_hypercalls.h> + +static struct kvm_sdei_event_state defined_kse[] = { + { KVM_SDEI_DEFAULT_NUM, + SDEI_EVENT_TYPE_PRIVATE,Quoted 8 lines
arch/arm64/kvm/sdei.c line 22
Quoted 4 lines
arch/arm64/kvm/sdei.c new file +4
-0+ 1, + SDEI_EVENT_PRIORITY_CRITICAL + }, +};I understand from the above we currently only support a single static (~ platform) SDEI event with num =
KVM_SDEI_DEFAULT_NUM. We do not support bound events. You may add a comment here and maybe in the commit msg. I would rename the variable intoexported_events.Yeah, we may enhance it to allow userspace to add more in future, but not now. Ok, I will rename it to @exported_events.
Quoted 19 lines
Quoted 19 lines
arch/arm64/kvm/sdei.c new file +19
-0+ +static void kvm_sdei_remove_events (struct kvm *kvm) +{ + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_event *kse, *tmp; + + list_for_each_entry_safe(kse, tmp, &ksdei->events, link) { + list_del(&kse->link); + kfree(kse); + } +} + +static void kvm_sdei_remove_kvm_events (struct kvm *kvm, + unsigned int mask, + bool force) +{ + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_event *kse; + struct kvm_sdei_kvm_event *kske, *tmp;Quoted 8 lines
arch/arm64/kvm/sdei.c line 47
Quoted 6 lines
arch/arm64/kvm/sdei.c new file +6
-0+ + list_for_each_entry_safe(kske, tmp, &ksdei->kvm_events, link) { + kse = kske->kse; + + if (!((1 << kse->state.type) & mask)) + continue;don't you need to hold a lock before looping? What if sbdy concurrently changes the state fields, especially the refcount below?
Yes, the caller holds @kvm->sdei_lock.
Quoted 3 lines
Quoted 3 lines
arch/arm64/kvm/sdei.c new file +3
-0+ + if (!force && kske->state.refcount) + continue;
Quoted 7 lines
Quoted 4 lines
Usually the refcount is used to control the lifetime of the object. The 'force' flag looks wrong in that context. Shouldn't you make sure all users have released their refcounts and on the last decrement, delete the object?
@force is used for exceptional case. For example, the KVM process is killed before the event reference count gets chance to be dropped.
hum not totally convinced here but let's see your next version ;-)
Quoted 171 lines
Quoted 53 lines
Quoted 53 lines
arch/arm64/kvm/sdei.c new file +12
-0+ + list_del(&kske->link); + kfree(kske); + } +} + +static void kvm_sdei_remove_vcpu_events (struct kvm_vcpu *vcpu) +{ + struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + struct kvm_sdei_vcpu_event *ksve, *tmp; + + list_for_each_entry_safe(ksve, tmp, &vsdei->critical_events,link) {
+list_del(&ksve->link);
+ kfree(ksve);
+ }arch/arm64/kvm/sdei.c new file +36
-0+ + list_for_each_entry_safe(ksve, tmp, &vsdei->normal_events, link) { + list_del(&ksve->link); + kfree(ksve); + } +} + +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) +{ + u32 func = smccc_get_function(vcpu); + bool has_result = true; + unsigned long ret; + + switch (func) { + case SDEI_1_0_FN_SDEI_VERSION: + case SDEI_1_0_FN_SDEI_EVENT_REGISTER: + case SDEI_1_0_FN_SDEI_EVENT_ENABLE: + case SDEI_1_0_FN_SDEI_EVENT_DISABLE: + case SDEI_1_0_FN_SDEI_EVENT_CONTEXT: + case SDEI_1_0_FN_SDEI_EVENT_COMPLETE: + case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME: + case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER: + case SDEI_1_0_FN_SDEI_EVENT_STATUS: + case SDEI_1_0_FN_SDEI_EVENT_GET_INFO: + case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET: + case SDEI_1_0_FN_SDEI_PE_MASK: + case SDEI_1_0_FN_SDEI_PE_UNMASK: + case SDEI_1_0_FN_SDEI_INTERRUPT_BIND: + case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE: + case SDEI_1_0_FN_SDEI_PRIVATE_RESET: + case SDEI_1_0_FN_SDEI_SHARED_RESET: + default: + ret = SDEI_NOT_SUPPORTED; + } + + /*Quoted 8 lines
Quoted 5 lines
+ * We don't have return value for COMPLETE or
COMPLETE_AND_RESUME+ * hypercalls. Otherwise, the restored context will be corrupted. + */
+ if (has_result)
+smccc_set_retval(vcpu, ret, 0, 0, 0);If I understand the above comment, COMPLETE and
COMPLETE_AND_RESUMEshould havehas_resultset to false whereas in that case they will returnNOT_SUPPORTED. Is that OK for the context restore?Nice catch! @has_result needs to be false for COMPLETE and
COMPLETE_AND_RESUME.Quoted 16 lines
Quoted 16 lines
arch/arm64/kvm/sdei.c new file +16
-0+ + return 1; +} + +void kvm_sdei_init_vm (struct kvm *kvm) +{ + struct kvm_sdei_kvm *ksdei; + struct kvm_sdei_event *kse; + int i; + + ksdei = kzalloc(sizeof(*ksdei), GFP_KERNEL); + if (!ksdei) + return; + + spin_lock_init(&ksdei->lock); + INIT_LIST_HEAD(&ksdei->events);Quoted 8 lines
Quoted 5 lines
+
INIT_LIST_HEAD(&ksdei->kvm_events);
+
+ /*
+ * Populate the defined KVM SDEI events. The whole functionality + * will be disabled on any errors.You should definitively revise your naming conventions. this brings confusion inbetween exported events and registered events. Why not simply adopt the spec terminology?
Yeah, I think so, but I think "defined KVM SDEI events" is following the specification because the SDEI event is defined by the firmware as the specification says. We're emulating firmware in KVM here.
Quoted 8 lines
Quoted 8 lines
+ */
+ for (i = 0; i <ARRAY_SIZE(defined_kse); i++) { + kse =kzalloc(sizeof(*kse), GFP_KERNEL); + if (!kse) {
+kvm_sdei_remove_events(kvm);
+ kfree(ksdei);
+ return;
+ }Quoted 6 lines
Add a comment saying that despite we currently support a single static event we prepare for binding support by building a list of exposed events?
Or maybe simplify the implementation at this stage of the development assuming a single platform event is supported?
I will add comment as you suggested in next respin. Note that another entry will be added to the defined event array when Async PF is involved.
Quoted 59 lines
Quoted 59 lines
arch/arm64/kvm/sdei.c new file +56
-0+ + kse->kvm = kvm; + kse->state = defined_kse[i]; + list_add_tail(&kse->link, &ksdei->events); + } + + kvm->arch.sdei = ksdei; +} + +void kvm_sdei_create_vcpu (struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + struct kvm_sdei_vcpu *vsdei; + + if (!kvm->arch.sdei) + return; + + vsdei = kzalloc(sizeof(*vsdei), GFP_KERNEL); + if (!vsdei) + return; + + spin_lock_init(&vsdei->lock); + vsdei->state.masked = 1; + vsdei->state.critical_num = KVM_SDEI_INVALID_NUM; + vsdei->state.normal_num = KVM_SDEI_INVALID_NUM; + vsdei->critical_event = NULL; + vsdei->normal_event = NULL; + INIT_LIST_HEAD(&vsdei->critical_events); + INIT_LIST_HEAD(&vsdei->normal_events); + + vcpu->arch.sdei = vsdei; +} + +void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu) +{ + struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + + if (vsdei) { + spin_lock(&vsdei->lock); + kvm_sdei_remove_vcpu_events(vcpu); + spin_unlock(&vsdei->lock); + + kfree(vsdei); + vcpu->arch.sdei = NULL; + } +} + +void kvm_sdei_destroy_vm (struct kvm *kvm) +{ + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + unsigned int mask = (1 << SDEI_EVENT_TYPE_PRIVATE) | + (1 << SDEI_EVENT_TYPE_SHARED); + + if (ksdei) { + spin_lock(&ksdei->lock); + kvm_sdei_remove_kvm_events(kvm, mask, true);> +
kvm_sdei_remove_events(kvm);
+spin_unlock(&ksdei->lock);
+
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
+ kfree(ksdei);
+kvm->arch.sdei= NULL;
+ }
+}Thanks,
Gavin
Thanks
Eric
Re: [PATCH v4 02/21] KVM: arm64: Add SDEI virtualization infrastructure
In reply to Gavin Shanarch/arm64/kvm/arm.c int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) · line 156
Quoted 12 lines · Gavin Shan
arch/arm64/kvm/arm.c +2
-0@@ -150,6 +150,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)kvm_vgic_early_init (kvm); +kvm_sdei_init_vm (kvm); +/* The maximum number of VCPUs is limited by the host's GIC model */ kvm->arch.max_vcpus =kvm_arm_default_max_vcpus ();
Hi, Is it possible to let user space to choose whether enabling SEDI or not rather than enable it by default?
Re: [PATCH v4 02/21] KVM: arm64: Add SDEI virtualization infrastructure
Hi Shannon,
Quoted 13 lines · Shannon Zhao
arch/arm64/kvm/arm.c int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) · line 154
Quoted 10 lines · Gavin Shan
arch/arm64/kvm/arm.c +2
-0@@ -150,6 +150,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) kvm_vgic_early_init(kvm); + kvm_sdei_init_vm(kvm); + /* The maximum number of VCPUs is limited by the host's GIC model */ kvm->arch.max_vcpus = kvm_arm_default_max_vcpus();Hi, Is it possible to let user space to choose whether enabling SEDI or not rather than enable it by default?
It's possible, but what's the benefit to do so. I think about it for a while and I don't think it's not necessary, at least for now. First of all, the SDEI event is injected from individual modules in userspace (QEMU) or host kernel (Async PF). If we really want the function to be disabled, the individual modules can accept parameter, used to indicate the SDEI event injection is allowed or not. In this case, SDEI is enabled by default, but the individual modules can choose not to use it :)
Thanks,
Gavin
PATCH v4 3/21 KVM: arm64: Support SDEI_VERSION hypercall
In reply to Gavin ShanThis supports SDEI_VERSION hypercall by returning v1.0.0 simply when the functionality is supported on the VM and vCPU.
--- arch/arm64/kvm/sdei.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
arch/arm64/kvm/sdei.c +18 -0
@@ -70,6 +70,22 @@ static void kvm_sdei_remove_vcpu_events(struct kvm_vcpu *vcpu) } } +static unsigned long kvm_sdei_hypercall_version (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +unsigned long ret =SDEI_NOT_SUPPORTED ; + +if (!(ksdei && vsdei)) +return ret; + +/* v1.0.0 */ + ret = (1UL <<SDEI_VERSION_MAJOR_SHIFT ); + +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
@@ -78,6 +94,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)switch (func) {case SDEI_1_0_FN_SDEI_VERSION : + ret =kvm_sdei_hypercall_version (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_REGISTER :case SDEI_1_0_FN_SDEI_EVENT_ENABLE :case SDEI_1_0_FN_SDEI_EVENT_DISABLE :
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 03/21] KVM: arm64: Support SDEI_VERSION hypercall
Hi Gavin
Quoted 1 line · Gavin Shan
This supports
SDEI_VERSIONhypercall by returning v1.0.0 simply
s/This supports/Add Support. I think this is the prefered way to start the commit msg. Here and elsewhere.
Quoted 1 line
when the functionality is supported on the VM and vCPU.
Can you explain when the functionality isn't supported on either. From the infra patch I have the impression that an allocation failure is the sole cause of lack of support?
Quoted 11 lines
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)arch/arm64/kvm/sdei.c +0
-0
arch/arm64/kvm/sdei.c static void kvm_sdei_remove_vcpu_events(struct kvm_vcpu *vcpu) · line 78
Quoted 9 lines
arch/arm64/kvm/sdei.c +6
-0@@ -70,6 +70,22 @@ static void kvm_sdei_remove_vcpu_events(struct kvm_vcpu *vcpu) } } +static unsigned long kvm_sdei_hypercall_version (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +unsigned long ret =SDEI_NOT_SUPPORTED ;
nit: I would remove ret local variable
Quoted 15 lines
arch/arm64/kvm/sdei.c +10
-0+ +if (!(ksdei && vsdei)) +return ret; + +/* v1.0.0 */ + ret = (1UL <<SDEI_VERSION_MAJOR_SHIFT ); + +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 101
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0@@ -78,6 +94,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)switch (func) {case SDEI_1_0_FN_SDEI_VERSION : + ret =kvm_sdei_hypercall_version (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_REGISTER :case SDEI_1_0_FN_SDEI_EVENT_ENABLE :case SDEI_1_0_FN_SDEI_EVENT_DISABLE :
Eric
Re: [PATCH v4 03/21] KVM: arm64: Support SDEI_VERSION hypercall
Hi Eric,
Quoted 4 lines · Eric Auger
Quoted 1 line · Gavin Shan
This supports
SDEI_VERSIONhypercall by returning v1.0.0 simplys/This supports/Add Support. I think this is the prefered way to start the commit msg. Here and elsewhere.
Ok.
Quoted 4 lines
Quoted 1 line
when the functionality is supported on the VM and vCPU.
Can you explain when the functionality isn't supported on either. From the infra patch I have the impression that an allocation failure is the sole cause of lack of support?
Yes, it's the only reason that SDEI isn't supported. I will mention this in the commit log in next respin.
Quoted 14 lines
Quoted 14 lines
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)arch/arm64/kvm/sdei.c +0
-0@@ -70,6 +70,22 @@ static void kvm_sdei_remove_vcpu_events(struct kvm_vcpu *vcpu) } }
Quoted 7 lines
arch/arm64/kvm/sdei.c static void kvm_sdei_remove_vcpu_events(struct kvm_vcpu *vcpu) · line 78
Quoted 6 lines
arch/arm64/kvm/sdei.c +6
-0+static unsigned long kvm_sdei_hypercall_version (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +unsigned long ret =SDEI_NOT_SUPPORTED ;nit: I would remove ret local variable
Ok.
Quoted 15 lines
Quoted 15 lines
arch/arm64/kvm/sdei.c +10
-0+ +if (!(ksdei && vsdei)) +return ret; + +/* v1.0.0 */ + ret = (1UL <<SDEI_VERSION_MAJOR_SHIFT ); + +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -78,6 +94,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 101
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0switch (func) {case SDEI_1_0_FN_SDEI_VERSION : + ret =kvm_sdei_hypercall_version (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_REGISTER :case SDEI_1_0_FN_SDEI_EVENT_ENABLE :case SDEI_1_0_FN_SDEI_EVENT_DISABLE :
Thanks,
Gavin
PATCH v4 4/21 KVM: arm64: Support SDEI_EVENT_REGISTER hypercall
In reply to Gavin ShanThis supports SDEI_EVENT_REGISTER hypercall, which is used by guest to register SDEI events. The SDEI event won't be raised to the guest or specific vCPU until it's registered and enabled explicitly.
Only those events that have been exported by KVM can be registered. After the event is registered successfully, the KVM SDEI event (object) is created or updated because the same KVM SDEI event is shared by multiple vCPUs if it's a private event.
--- arch/arm64/kvm/sdei.c | 122 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+)
arch/arm64/kvm/sdei.c +122 -0
@@ -21,6 +21,20 @@ static struct kvm_sdei_event_state defined_kse[] = { }, }; +static struct kvm_sdei_event *kvm_sdei_find_event (struct kvm *kvm, +unsigned long num) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse; + +list_for_each_entry (kse, &ksdei->events, link) { +if (kse->state.num == num) +return kse; + } + +return NULL ; +} +static void kvm_sdei_remove_events (struct kvm *kvm) {struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;
@@ -32,6 +46,20 @@ static void kvm_sdei_remove_events(struct kvm *kvm) } } +static struct kvm_sdei_kvm_event *kvm_sdei_find_kvm_event (struct kvm *kvm, +unsigned long num) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_kvm_event *kske; + +list_for_each_entry (kske, &ksdei->kvm_events, link) { +if (kske->state.num == num) +return kske; + } + +return NULL ; +} +static void kvm_sdei_remove_kvm_events (struct kvm *kvm,unsigned int mask,bool force)
@@ -86,6 +114,98 @@ static unsigned long kvm_sdei_hypercall_version(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_register (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +unsigned long event_entry =smccc_get_arg2 (vcpu); +unsigned long event_param =smccc_get_arg3 (vcpu); +unsigned long route_mode =smccc_get_arg4 (vcpu); +unsigned long route_affinity =smccc_get_arg5 (vcpu); +int index = vcpu->vcpu_idx; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +if (!(route_mode ==SDEI_EVENT_REGISTER_RM_ANY || + route_mode ==SDEI_EVENT_REGISTER_RM_PE )) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* +* The KVM event could have been created if it's a private event. +* We needn't create a KVM event in this case. +*/ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (kske) { + kse = kske->kse; + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; + +if (kvm_sdei_is_registered (kske, index)) { + ret =SDEI_DENIED ; + goto unlock; + } + + kske->state.route_mode = route_mode; + kske->state.route_affinity = route_affinity; + kske->state.entries[index] = event_entry; + kske->state.params[index] = event_param; +kvm_sdei_set_registered (kske, index); + goto unlock; + } + +/* Check if the event number has been registered */ + kse =kvm_sdei_find_event (kvm, event_num); +if (!kse) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } + +/* Create KVM event */ + kske =kzalloc (sizeof (*kske),GFP_KERNEL ); +if (!kske) { + ret =SDEI_OUT_OF_RESOURCE ; + goto unlock; + } + +/* Initialize KVM event state */ + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; + kske->state.num = event_num; + kske->state.refcount =0 ; + kske->state.route_mode = route_affinity; + kske->state.route_affinity = route_affinity; + kske->state.entries[index] = event_entry; + kske->state.params[index] = event_param; +kvm_sdei_set_registered (kske, index); + +/* Initialize KVM event */ + kske->kse = kse; + kske->kvm = kvm; +list_add_tail (&kske->link, &ksdei->kvm_events); + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
@@ -97,6 +217,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_version (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_REGISTER : + ret =kvm_sdei_hypercall_register (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_ENABLE :case SDEI_1_0_FN_SDEI_EVENT_DISABLE :case SDEI_1_0_FN_SDEI_EVENT_CONTEXT :
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 04/21] KVM: arm64: Support SDEI_EVENT_REGISTER hypercall
Hi Gavin,
Quoted 7 lines · Gavin Shan
This supports
SDEI_EVENT_REGISTERhypercall, which is used by guest to register SDEI events. The SDEI event won't be raised to the guest or specific vCPU until it's registered and enabled explicitly.Only those events that have been exported by KVM can be registered. After the event is registered successfully, the KVM SDEI event (object) is created or updated because the same KVM SDEI event is shared by
revisit the terminology (KVM SDEI event). The same SDEI registered event object is shared by multiple vCPUs if it is a private event.
Quoted 11 lines
multiple vCPUs if it's a private event.>
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 122 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+)arch/arm64/kvm/sdei.c +0
-0
arch/arm64/kvm/sdei.c static struct kvm_sdei_event_state defined_kse[] = { · line 28
Quoted 8 lines
arch/arm64/kvm/sdei.c +5
-0@@ -21,6 +21,20 @@ static struct kvm_sdei_event_state defined_kse[] = { }, }; +static struct kvm_sdei_event *kvm_sdei_find_event (struct kvm *kvm, +unsigned long num) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse;
the 'k' prefix everywhere for your local variable is unneeded.
Quoted 13 lines
arch/arm64/kvm/sdei.c +9
-0+ +list_for_each_entry (kse, &ksdei->events, link) { +if (kse->state.num == num) +return kse; + } + +return NULL ; +} +static void kvm_sdei_remove_events (struct kvm *kvm) {struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;
arch/arm64/kvm/sdei.c static void kvm_sdei_remove_events(struct kvm *kvm) · line 55
Quoted 10 lines
arch/arm64/kvm/sdei.c +7
-0@@ -32,6 +46,20 @@ static void kvm_sdei_remove_events(struct kvm *kvm) } } +static struct kvm_sdei_kvm_event *kvm_sdei_find_kvm_event (struct kvm *kvm, +unsigned long num) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_kvm_event *kske; + + list_for_each_entry(kske, &ksdei->kvm_events, link) {> + if (kske->state.num == num)
I still don't get the diff between the num of an SDEI event vs the num of a so-called SDEI kvm event. Event numbers are either static or dynamically created using bind ops which you do not support. But to me this is a property of the root exposed SDEI event and not a property of the registered event. Please could you clarify?
Quoted 38 lines
arch/arm64/kvm/sdei.c +31
-0+return kske; + } + +return NULL ; +} +static void kvm_sdei_remove_kvm_events (struct kvm *kvm,unsigned int mask,bool force)@@ -86,6 +114,98 @@ static unsigned long kvm_sdei_hypercall_version(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_register (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +unsigned long event_entry =smccc_get_arg2 (vcpu); +unsigned long event_param =smccc_get_arg3 (vcpu); +unsigned long route_mode =smccc_get_arg4 (vcpu); +unsigned long route_affinity =smccc_get_arg5 (vcpu); +int index = vcpu->vcpu_idx; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + }
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_version(struct kvm_vcpu *vcpu) · line 151
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ +if (!(route_mode ==SDEI_EVENT_REGISTER_RM_ANY || + route_mode ==SDEI_EVENT_REGISTER_RM_PE )) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* +* The KVM event could have been created if it's a private event. +* We needn't create a KVM event in this case.
s/create a KVM event/to create another KVM event instance
Quoted 13 lines
arch/arm64/kvm/sdei.c +13
-0+*/ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (kske) { + kse = kske->kse; + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; + +if (kvm_sdei_is_registered (kske, index)) { + ret =SDEI_DENIED ; + goto unlock; + } +
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_version(struct kvm_vcpu *vcpu) · line 174
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ kske->state.route_mode = route_mode; + kske->state.route_affinity = route_affinity; + kske->state.entries[index] = event_entry; + kske->state.params[index] = event_param; +kvm_sdei_set_registered (kske, index); + goto unlock; + } + +/* Check if the event number has been registered */ + kse =kvm_sdei_find_event (kvm, event_num);
I don't get the comment. find_event looks up for exposed events and not registered events, right? So maybe this is the first thing to check, ie. the num matches one exposed event.
Quoted 39 lines
arch/arm64/kvm/sdei.c +34
-0+if (!kse) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } + +/* Create KVM event */ + kske =kzalloc (sizeof (*kske),GFP_KERNEL ); +if (!kske) { + ret =SDEI_OUT_OF_RESOURCE ; + goto unlock; + } + +/* Initialize KVM event state */ + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; + kske->state.num = event_num; + kske->state.refcount =0 ; + kske->state.route_mode = route_affinity; + kske->state.route_affinity = route_affinity; + kske->state.entries[index] = event_entry; + kske->state.params[index] = event_param; +kvm_sdei_set_registered (kske, index); + +/* Initialize KVM event */ + kske->kse = kse; + kske->kvm = kvm; +list_add_tail (&kske->link, &ksdei->kvm_events); + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 224
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0@@ -97,6 +217,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_version (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_REGISTER : + ret =kvm_sdei_hypercall_register (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_ENABLE :case SDEI_1_0_FN_SDEI_EVENT_DISABLE :case SDEI_1_0_FN_SDEI_EVENT_CONTEXT :
Thanks
Eric
Re: [PATCH v4 04/21] KVM: arm64: Support SDEI_EVENT_REGISTER hypercall
Hi Eric,
Quoted 10 lines · Eric Auger
Quoted 7 lines · Gavin Shan
This supports
SDEI_EVENT_REGISTERhypercall, which is used by guest to register SDEI events. The SDEI event won't be raised to the guest or specific vCPU until it's registered and enabled explicitly.Only those events that have been exported by KVM can be registered. After the event is registered successfully, the KVM SDEI event (object) is created or updated because the same KVM SDEI event is shared by
revisit the terminology (KVM SDEI event). The same SDEI registered event object is shared by multiple vCPUs if it is a private event.
Yep, I will correct the commit log in next respin.
Quoted 14 lines
Quoted 14 lines
multiple vCPUs if it's a private event.>
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 122 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+)arch/arm64/kvm/sdei.c +0
-0@@ -21,6 +21,20 @@ static struct kvm_sdei_event_state defined_kse[] = { }, };
Quoted 6 lines
arch/arm64/kvm/sdei.c static struct kvm_sdei_event_state defined_kse[] = { · line 28
Quoted 5 lines
arch/arm64/kvm/sdei.c +5
-0+static struct kvm_sdei_event *kvm_sdei_find_event (struct kvm *kvm, +unsigned long num) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse;the 'k' prefix everywhere for your local variable is unneeded.
ok.
Quoted 16 lines
Quoted 16 lines
arch/arm64/kvm/sdei.c +9
-0+ +list_for_each_entry (kse, &ksdei->events, link) { +if (kse->state.num == num) +return kse; + } + +return NULL ; +} +static void kvm_sdei_remove_events (struct kvm *kvm) {struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;@@ -32,6 +46,20 @@ static void kvm_sdei_remove_events(struct kvm *kvm) } }
Quoted 12 lines
arch/arm64/kvm/sdei.c static void kvm_sdei_remove_events(struct kvm *kvm)
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+static struct kvm_sdei_kvm_event *kvm_sdei_find_kvm_event (struct kvm *kvm, +unsigned long num) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_kvm_event *kske; + + list_for_each_entry(kske, &ksdei->kvm_events, link) {> + if (kske->state.num == num)I still don't get the diff between the num of an SDEI event vs the num of a so-called SDEI kvm event. Event numbers are either static or dynamically created using bind ops which you do not support. But to me this is a property of the root exposed SDEI event and not a property of the registered event. Please could you clarify?
Your understanding is correct. The SDEI events are defined staticly apart from the binding one, which we don't support for now. As the information (properties) of one specific SDEI event is scattered and associated with different objects, like KVM/vCPU/context. The SDEI event (@num) is the key to associate these scattered information (properties).
Quoted 41 lines
Quoted 41 lines
arch/arm64/kvm/sdei.c +34
-0+return kske; + } + +return NULL ; +} +static void kvm_sdei_remove_kvm_events (struct kvm *kvm,unsigned int mask,bool force)@@ -86,6 +114,98 @@ static unsigned long kvm_sdei_hypercall_version(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_register (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +unsigned long event_entry =smccc_get_arg2 (vcpu); +unsigned long event_param =smccc_get_arg3 (vcpu); +unsigned long route_mode =smccc_get_arg4 (vcpu); +unsigned long route_affinity =smccc_get_arg5 (vcpu); +int index = vcpu->vcpu_idx; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +if (!(route_mode ==SDEI_EVENT_REGISTER_RM_ANY || + route_mode ==SDEI_EVENT_REGISTER_RM_PE )) {
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_version(struct kvm_vcpu *vcpu) · line 151
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* +* The KVM event could have been created if it's a private event. +* We needn't create a KVM event in this case. s/create a KVM event/to create another KVM event instance
Ok.
Quoted 18 lines
Quoted 18 lines
arch/arm64/kvm/sdei.c +18
-0+*/ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (kske) { + kse = kske->kse; + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; + +if (kvm_sdei_is_registered (kske, index)) { + ret =SDEI_DENIED ; + goto unlock; + } + + kske->state.route_mode = route_mode; + kske->state.route_affinity = route_affinity; + kske->state.entries[index] = event_entry; + kske->state.params[index] = event_param; +kvm_sdei_set_registered (kske, index);
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_version(struct kvm_vcpu *vcpu) · line 174
Quoted 5 lines
arch/arm64/kvm/sdei.c +5
-0+ goto unlock; + } + +/* Check if the event number has been registered */ + kse =kvm_sdei_find_event (kvm, event_num);I don't get the comment.
find_eventlooks up for exposed events and not registered events, right? So maybe this is the first thing to check, ie. the num matches one exposed event.
This should be corrected to:
/* Check if the event has been defined or exposed */
Quoted 39 lines
Quoted 39 lines
arch/arm64/kvm/sdei.c +34
-0+if (!kse) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } + +/* Create KVM event */ + kske =kzalloc (sizeof (*kske),GFP_KERNEL ); +if (!kske) { + ret =SDEI_OUT_OF_RESOURCE ; + goto unlock; + } + +/* Initialize KVM event state */ + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; + kske->state.num = event_num; + kske->state.refcount =0 ; + kske->state.route_mode = route_affinity; + kske->state.route_affinity = route_affinity; + kske->state.entries[index] = event_entry; + kske->state.params[index] = event_param; +kvm_sdei_set_registered (kske, index); + +/* Initialize KVM event */ + kske->kse = kse; + kske->kvm = kvm; +list_add_tail (&kske->link, &ksdei->kvm_events); + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -97,6 +217,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_version (vcpu);
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 224
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0break ;case SDEI_1_0_FN_SDEI_EVENT_REGISTER : + ret =kvm_sdei_hypercall_register (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_ENABLE :case SDEI_1_0_FN_SDEI_EVENT_DISABLE :case SDEI_1_0_FN_SDEI_EVENT_CONTEXT :
Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 5/21 KVM: arm64: Support SDEI_EVENT_{ENABLE, DISABLE} hypercall
In reply to Gavin ShanThis supports SDEI_EVENT_{ENABLE, DISABLE} hypercall. After SDEI event is registered by guest, it won't be delivered to the guest until it's enabled. On the other hand, the SDEI event won't be raised to the guest or specific vCPU if it's has been disabled on the guest or specific vCPU.
--- arch/arm64/kvm/sdei.c | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
arch/arm64/kvm/sdei.c +68 -0
@@ -206,6 +206,70 @@ static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_enable (struct kvm_vcpu *vcpu, +bool enable) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +int index =0 ; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* Check if the KVM event exists */ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } + +/* Check if there is pending events */ +if (kske->state.refcount) { + ret =SDEI_PENDING ; + goto unlock; + } + +/* Check if it has been registered */ + kse = kske->kse; + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; +if (!kvm_sdei_is_registered (kske, index)) { + ret =SDEI_DENIED ; + goto unlock; + } + +/* Verify its enablement state */ +if (enable ==kvm_sdei_is_enabled (kske, index)) { + ret =SDEI_DENIED ; + goto unlock; + } + +/* Update enablement state */ +if (enable) +kvm_sdei_set_enabled (kske, index); +else +kvm_sdei_clear_enabled (kske, index); + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
@@ -220,7 +284,11 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_register (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_ENABLE : + ret =kvm_sdei_hypercall_enable (vcpu, true); +break ;case SDEI_1_0_FN_SDEI_EVENT_DISABLE : + ret =kvm_sdei_hypercall_enable (vcpu, false); +break ;case SDEI_1_0_FN_SDEI_EVENT_CONTEXT :case SDEI_1_0_FN_SDEI_EVENT_COMPLETE :case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME :
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 05/21] KVM: arm64: Support SDEI_EVENT_{ENABLE, DISABLE} hypercall
Hi Gavin,
Quoted 28 lines · Gavin Shan
This supports SDEI_EVENT_{ENABLE, DISABLE} hypercall. After SDEI event is registered by guest, it won't be delivered to the guest until it's enabled. On the other hand, the SDEI event won't be raised to the guest or specific vCPU if it's has been disabled on the guest or specific vCPU.
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)arch/arm64/kvm/sdei.c +9
-0@@ -206,6 +206,70 @@ static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_enable (struct kvm_vcpu *vcpu, +bool enable) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu);
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 227
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+int index =0 ; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) {
I would rename into is_exposed_event_num()
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 236
Quoted 9 lines
arch/arm64/kvm/sdei.c +9
-0+ ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* Check if the KVM event exists */ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =SDEI_INVALID_PARAMETERS ;
should be DENIED according to the spec, ie. nobody registered that event?
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 240
Quoted 4 lines
arch/arm64/kvm/sdei.c +4
-0+ goto unlock; + } + +/* Check if there is pending events */
does that match the "handler-unregister-pending state" case mentionned in the spec?
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 242
Quoted 2 lines
arch/arm64/kvm/sdei.c +2
-0+if (kske->state.refcount) { + ret =SDEI_PENDING ;
? not documented in my A spec? DENIED?
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 246
Quoted 4 lines
arch/arm64/kvm/sdei.c +4
-0+ goto unlock; + } + +/* Check if it has been registered */
isn't duplicate of /* Check if the KVM event exists */ ?
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 256
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ kse = kske->kse; + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; +if (!kvm_sdei_is_registered (kske, index)) { + ret =SDEI_DENIED ; + goto unlock; + } + +/* Verify its enablement state */ +if (enable ==kvm_sdei_is_enabled (kske, index)) {
spec says:
Enabling/disabled an event, which is already enabled/disabled, is permitted and has no effect. I guess ret should be OK.
Quoted 22 lines
arch/arm64/kvm/sdei.c +16
-0+ ret =SDEI_DENIED ; + goto unlock; + } + +/* Update enablement state */ +if (enable) +kvm_sdei_set_enabled (kske, index); +else +kvm_sdei_clear_enabled (kske, index); + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -220,7 +284,11 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_register (vcpu);
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 294
Quoted 10 lines
arch/arm64/kvm/sdei.c +4
-0break ;case SDEI_1_0_FN_SDEI_EVENT_ENABLE : + ret =kvm_sdei_hypercall_enable (vcpu, true); +break ;case SDEI_1_0_FN_SDEI_EVENT_DISABLE : + ret =kvm_sdei_hypercall_enable (vcpu, false); +break ;case SDEI_1_0_FN_SDEI_EVENT_CONTEXT :case SDEI_1_0_FN_SDEI_EVENT_COMPLETE :case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME :
Eric
Re: [PATCH v4 05/21] KVM: arm64: Support SDEI_EVENT_{ENABLE, DISABLE} hypercall
Hi Eric,
Quoted 32 lines · Eric Auger
Quoted 31 lines · Gavin Shan
This supports SDEI_EVENT_{ENABLE, DISABLE} hypercall. After SDEI event is registered by guest, it won't be delivered to the guest until it's enabled. On the other hand, the SDEI event won't be raised to the guest or specific vCPU if it's has been disabled on the guest or specific vCPU.
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)arch/arm64/kvm/sdei.c +12
-0@@ -206,6 +206,70 @@ static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_enable (struct kvm_vcpu *vcpu, +bool enable) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +int index =0 ; +unsigned long ret =SDEI_SUCCESS ; +
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 227
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) {I would rename into
is_exposed_event_num()
kvm_sdei_is_virtual() has been recommended by you when you reviewed the following patch. I think kvm_sdei_is_virtual() is good enough :)
[PATCH v4 02/21] KVM: arm64: Add SDEI virtualization infrastructure
Quoted 10 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 236
Quoted 9 lines
arch/arm64/kvm/sdei.c +9
-0+ ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* Check if the KVM event exists */ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =SDEI_INVALID_PARAMETERS ;should be DENIED according to the spec, ie. nobody registered that event?
Ok.
Quoted 9 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 240
Quoted 4 lines
arch/arm64/kvm/sdei.c +4
-0+ goto unlock; + } + +/* Check if there is pending events */ does that match the "handler-unregister-pending state" case mentionned in the spec?
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 242
Quoted 2 lines
arch/arm64/kvm/sdei.c +2
-0+if (kske->state.refcount) { + ret =SDEI_PENDING ;? not documented in my A spec? DENIED?
Yep, It should be DENIED.
Quoted 5 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 246
Quoted 4 lines
arch/arm64/kvm/sdei.c +4
-0+ goto unlock; + } + +/* Check if it has been registered */ isn't duplicate of /* Check if the KVM event exists */ ?
It's not duplicate check, but the comment here seems misleading. I will correct this to:
/* Check if it has been defined or exposed */
Quoted 5 lines
Quoted 5 lines
arch/arm64/kvm/sdei.c +5
-0+ kse = kske->kse; + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; +if (!kvm_sdei_is_registered (kske, index)) { + ret =SDEI_DENIED ;
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 256
Quoted 5 lines
arch/arm64/kvm/sdei.c +5
-0+ goto unlock; + } + +/* Verify its enablement state */ +if (enable ==kvm_sdei_is_enabled (kske, index)) {spec says:
Enabling/disabled an event, which is already enabled/disabled, is permitted and has no effect. I guess ret should be OK.
yep, it should be ok.
Quoted 24 lines
Quoted 24 lines
arch/arm64/kvm/sdei.c +17
-0+ ret =SDEI_DENIED ; + goto unlock; + } + +/* Update enablement state */ +if (enable) +kvm_sdei_set_enabled (kske, index); +else +kvm_sdei_clear_enabled (kske, index); + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -220,7 +284,11 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_register (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_ENABLE : + ret =kvm_sdei_hypercall_enable (vcpu, true);
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 294
Quoted 8 lines
arch/arm64/kvm/sdei.c +3
-0+break ;case SDEI_1_0_FN_SDEI_EVENT_DISABLE : + ret =kvm_sdei_hypercall_enable (vcpu, false); +break ;case SDEI_1_0_FN_SDEI_EVENT_CONTEXT :case SDEI_1_0_FN_SDEI_EVENT_COMPLETE :case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME :
Thanks,
Gavin
Re: [PATCH v4 05/21] KVM: arm64: Support SDEI_EVENT_{ENABLE, DISABLE} hypercall
Hi Gavin,
Quoted 44 lines · Gavin Shan
Hi Eric,
Quoted 32 lines · Eric Auger
Quoted 31 lines · Gavin Shan
This supports SDEI_EVENT_{ENABLE, DISABLE} hypercall. After SDEI event is registered by guest, it won't be delivered to the guest until it's enabled. On the other hand, the SDEI event won't be raised to the guest or specific vCPU if it's has been disabled on the guest or specific vCPU.
Signed-off-by Gavin Shan <[email protected]>---
arch/arm64/kvm/sdei.c| 68 +++++++++++++++++++++++++++++++++++++++++++1 file changed, 68 insertions(+)arch/arm64/kvm/sdei.c +11
-0@@ -206,6 +206,70 @@ static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) return ret; } +static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, + bool enable) +{ + struct kvm *kvm = vcpu->kvm; + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + struct kvm_sdei_event *kse = NULL; + struct kvm_sdei_kvm_event *kske = NULL; + unsigned long event_num = smccc_get_arg1(vcpu); + int index = 0; + unsigned long ret = SDEI_SUCCESS; +Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 227
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + } + + if (!kvm_sdei_is_valid_event_num(event_num)) {I would rename into
is_exposed_event_num()
Quoted 3 lines
kvm_sdei_is_virtual()has been recommended by you when you reviewed the following
patch. I thinkkvm_sdei_is_virtual()is good enough :)
argh, is_virtual() then :)
Eric
Quoted 82 lines
[PATCH v4 02/21] KVM: arm64: Add SDEI virtualization infrastructure
Quoted 10 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 236
Quoted 9 lines
arch/arm64/kvm/sdei.c +9
-0+ ret = SDEI_INVALID_PARAMETERS; + goto out; + } + + /* Check if the KVM event exists */ + spin_lock(&ksdei->lock); + kske = kvm_sdei_find_kvm_event(kvm, event_num); + if (!kske) { + ret = SDEI_INVALID_PARAMETERS;should be DENIED according to the spec, ie. nobody registered that event?
Ok.
Quoted 9 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 240
Quoted 4 lines
arch/arm64/kvm/sdei.c +4
-0+ goto unlock; + } + + /* Check if there is pending events */does that match the "handler-unregister-pending state" case mentionned in the spec?
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 242
Quoted 2 lines
arch/arm64/kvm/sdei.c +2
-0+ if (kske->state.refcount) { + ret = SDEI_PENDING;? not documented in my A spec? DENIED?
Yep, It should be DENIED.
Quoted 5 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 246
Quoted 4 lines
arch/arm64/kvm/sdei.c +4
-0+ goto unlock; + } + + /* Check if it has been registered */isn't duplicate of /* Check if the KVM event exists */ ?
It's not duplicate check, but the comment here seems misleading. I will correct this to:
/* Check if it has been defined or exposed */
Quoted 10 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_register(struct kvm_vcpu *vcpu) · line 256
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ kse = kske->kse; + index = (kse->state.type == SDEI_EVENT_TYPE_PRIVATE) ? + vcpu->vcpu_idx : 0; + if (!kvm_sdei_is_registered(kske, index)) { + ret = SDEI_DENIED; + goto unlock; + } + + /* Verify its enablement state */ + if (enable == kvm_sdei_is_enabled(kske, index)) {Quoted 3 lines
spec says:
Enabling/disabled an event, which is already enabled/disabled, is permitted and has no effect. I guess ret should be OK.yep, it should be ok.
Quoted 27 lines
Quoted 27 lines
arch/arm64/kvm/sdei.c +16
-0+ ret = SDEI_DENIED; + goto unlock; + } + + /* Update enablement state */ + if (enable) + kvm_sdei_set_enabled(kske, index); + else + kvm_sdei_clear_enabled(kske, index); + +unlock: + spin_unlock(&ksdei->lock); +out: + return ret; +} + int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) {u32 func =
smccc_get_function(vcpu);arch/arm64/kvm/sdei.c +0
-0@@ -220,7 +284,11 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret = kvm_sdei_hypercall_register(vcpu); break;case
SDEI_1_0_FN_SDEI_EVENT_ENABLE:
+ ret =kvm_sdei_hypercall_enable(vcpu, true); + break;
caseSDEI_1_0_FN_SDEI_EVENT_DISABLE:
+ ret =kvm_sdei_hypercall_enable(vcpu, false);
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
+ break;
caseSDEI_1_0_FN_SDEI_EVENT_CONTEXT:
caseSDEI_1_0_FN_SDEI_EVENT_COMPLETE:
caseSDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME:Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 6/21 KVM: arm64: Support SDEI_EVENT_CONTEXT hypercall
In reply to Gavin ShanThis supports SDEI_EVENT_CONTEXT hypercall. It's used by the guest to retrieved the original registers (R0 - R17) in its SDEI event handler. Those registers can be corrupted during the SDEI event delivery.
--- arch/arm64/kvm/sdei.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
arch/arm64/kvm/sdei.c +40 -0
@@ -270,6 +270,44 @@ static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu,return ret; } +static unsigned long kvm_sdei_hypercall_context (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_vcpu_regs *regs; +unsigned long index =smccc_get_arg1 (vcpu); +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (index >ARRAY_SIZE (vsdei->state.critical_regs.regs)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* Check if the pending event exists */ +spin_lock (&vsdei->lock); +if (!(vsdei->critical_event || vsdei->normal_event)) { + ret =SDEI_DENIED ; + goto unlock; + } + +/* Fetch the requested register */ + regs = vsdei->critical_event ? &vsdei->state.critical_regs : + &vsdei->state.normal_regs; + ret = regs->regs[index]; + +unlock: +spin_unlock (&vsdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
@@ -290,6 +328,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_enable (vcpu, false);break ;case SDEI_1_0_FN_SDEI_EVENT_CONTEXT : + ret =kvm_sdei_hypercall_context (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_COMPLETE :case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME :case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER :
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 06/21] KVM: arm64: Support SDEI_EVENT_CONTEXT hypercall
Hi Gavin,
Quoted 15 lines · Gavin Shan
This supports
SDEI_EVENT_CONTEXThypercall. It's used by the guest to retrieved the original registers (R0 - R17) in its SDEI event handler. Those registers can be corrupted during the SDEI event delivery.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)arch/arm64/kvm/sdei.c +0
-0
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, · line 279
Quoted 10 lines
arch/arm64/kvm/sdei.c +7
-0@@ -270,6 +270,44 @@ static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu,return ret; } +static unsigned long kvm_sdei_hypercall_context (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_vcpu_regs *regs; +unsigned long index =smccc_get_arg1 (vcpu);
s/index/param_id to match the spec?
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, · line 291
Quoted 12 lines
arch/arm64/kvm/sdei.c +12
-0+unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (index >ARRAY_SIZE (vsdei->state.critical_regs.regs)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + }
I would move the above after regs = and use regs there (although the regs ARRAY_SIZE of both is identifical)
Quoted 24 lines
arch/arm64/kvm/sdei.c +19
-0+ +/* Check if the pending event exists */ +spin_lock (&vsdei->lock); +if (!(vsdei->critical_event || vsdei->normal_event)) { + ret =SDEI_DENIED ; + goto unlock; + } + +/* Fetch the requested register */ + regs = vsdei->critical_event ? &vsdei->state.critical_regs : + &vsdei->state.normal_regs; + ret = regs->regs[index]; + +unlock: +spin_unlock (&vsdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 335
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0@@ -290,6 +328,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_enable (vcpu, false);break ;case SDEI_1_0_FN_SDEI_EVENT_CONTEXT : + ret =kvm_sdei_hypercall_context (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_COMPLETE :case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME :case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER :
Eric
Re: [PATCH v4 06/21] KVM: arm64: Support SDEI_EVENT_CONTEXT hypercall
Hi Eric,
Quoted 19 lines · Eric Auger
Quoted 18 lines · Gavin Shan
This supports
SDEI_EVENT_CONTEXThypercall. It's used by the guest to retrieved the original registers (R0 - R17) in its SDEI event handler. Those registers can be corrupted during the SDEI event delivery.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)arch/arm64/kvm/sdei.c +0
-0@@ -270,6 +270,44 @@ static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu,return ret; }
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, · line 279
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+static unsigned long kvm_sdei_hypercall_context (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_vcpu_regs *regs; +unsigned long index =smccc_get_arg1 (vcpu);s/index/param_id to match the spec?
Sure, but "reg_id" seems better here. As the parameter indicates the GPR index to be fetched on request of the guest kernel.
Quoted 6 lines
Quoted 6 lines
arch/arm64/kvm/sdei.c +6
-0+unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out;
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, · line 291
Quoted 6 lines
arch/arm64/kvm/sdei.c +6
-0+ } + +if (index >ARRAY_SIZE (vsdei->state.critical_regs.regs)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + }I would move the above after regs = and use regs there (although the regs
ARRAY_SIZEof both is identifical)
Ok.
Quoted 24 lines
Quoted 24 lines
arch/arm64/kvm/sdei.c +19
-0+ +/* Check if the pending event exists */ +spin_lock (&vsdei->lock); +if (!(vsdei->critical_event || vsdei->normal_event)) { + ret =SDEI_DENIED ; + goto unlock; + } + +/* Fetch the requested register */ + regs = vsdei->critical_event ? &vsdei->state.critical_regs : + &vsdei->state.normal_regs; + ret = regs->regs[index]; + +unlock: +spin_unlock (&vsdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -290,6 +328,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_enable (vcpu, false);
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 335
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0break ;case SDEI_1_0_FN_SDEI_EVENT_CONTEXT : + ret =kvm_sdei_hypercall_context (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_COMPLETE :case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME :case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER :
Thanks,
Gavin
Re: [PATCH v4 06/21] KVM: arm64: Support SDEI_EVENT_CONTEXT hypercall
Hi Gavin,
Quoted 32 lines · Gavin Shan
Hi Eric,
Quoted 20 lines · Eric Auger
Quoted 19 lines · Gavin Shan
This supports
SDEI_EVENT_CONTEXThypercall. It's used by the guest to retrieved the original registers (R0 - R17) in its SDEI event handler. Those registers can be corrupted during the SDEI event delivery.Signed-off-by Gavin Shan <[email protected]>---
arch/arm64/kvm/sdei.c| 40 ++++++++++++++++++++++++++++++++++++++++1 file changed, 40 insertions(+)arch/arm64/kvm/sdei.c +0
-0@@ -270,6 +270,44 @@ static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, return ret; }+static unsigned long kvm_sdei_hypercall_context(struct
kvm_vcpuQuoted 8 lines
Quoted 7 lines
*vcpu)
+{
+ struct kvm *kvm =vcpu->kvm;
+ structkvm_sdei_kvm*ksdei =kvm->arch.sdei; + structkvm_sdei_vcpu*vsdei =vcpu->arch.sdei; + structkvm_sdei_vcpu_regs*regs;
+ unsigned long index =smccc_get_arg1(vcpu);s/index/param_id to match the spec?
Quoted 3 lines
Sure, but "
reg_id" seems better here. As the parameter indicates the GPR index
to be fetched on request of the guest kernel.
fine with me.
Quoted 45 lines
Quoted 15 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, · line 291
Quoted 13 lines
+ unsigned long ret =
SDEI_SUCCESS;arch/arm64/kvm/sdei.c +11
-0+ + /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + } + + if (index > ARRAY_SIZE(vsdei->state.critical_regs.regs)) { + ret = SDEI_INVALID_PARAMETERS; + goto out; + }I would move the above after regs = and use regs there (although the regs
ARRAY_SIZEof both is identifical)Ok.
Quoted 27 lines
Quoted 27 lines
arch/arm64/kvm/sdei.c +19
-0+ + /* Check if the pending event exists */ + spin_lock(&vsdei->lock); + if (!(vsdei->critical_event || vsdei->normal_event)) { + ret = SDEI_DENIED; + goto unlock; + } + + /* Fetch the requested register */ + regs = vsdei->critical_event ? &vsdei->state.critical_regs : + &vsdei->state.normal_regs; + ret = regs->regs[index]; + +unlock: + spin_unlock(&vsdei->lock); +out: + return ret; +} +int
kvm_sdei_hypercall(struct kvm_vcpu *vcpu)
{
u32 func =smccc_get_function(vcpu);arch/arm64/kvm/sdei.c +0
-0@@ -290,6 +328,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret = kvm_sdei_hypercall_enable(vcpu, false); break;case
SDEI_1_0_FN_SDEI_EVENT_CONTEXT:
+ ret =kvm_sdei_hypercall_context(vcpu);
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
+ break;
caseSDEI_1_0_FN_SDEI_EVENT_COMPLETE:
caseSDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME:
caseSDEI_1_0_FN_SDEI_EVENT_UNREGISTER:Thanks,
Gavin
Eric
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 06/21] KVM: arm64: Support SDEI_EVENT_CONTEXT hypercall
In reply to Gavin ShanQuoted 4 lines · Gavin Shan
arch/arm64/kvm/sdei.c +4
-0+static unsigned long kvm_sdei_hypercall_context (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, · line 286
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_vcpu_regs *regs; +unsigned long index =smccc_get_arg1 (vcpu); +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + }
Maybe we could move these common sanity check codes to kvm_sdei_hypercall to save some lines.
Thanks,
Shannon
Re: [PATCH v4 06/21] KVM: arm64: Support SDEI_EVENT_CONTEXT hypercall
Hi Shannon,
Quoted 17 lines · Shannon Zhao
Quoted 4 lines · Gavin Shan
arch/arm64/kvm/sdei.c +4
-0+static unsigned long kvm_sdei_hypercall_context (struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, · line 286
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + struct kvm_sdei_vcpu_regs *regs; + unsigned long index = smccc_get_arg1(vcpu); + unsigned long ret = SDEI_SUCCESS; + + /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + }Maybe we could move these common sanity check codes to
kvm_sdei_hypercallto save some lines.
Not all hypercalls need this check. For example, COMPLETE/COMPLETE_RESUME/CONTEXT don't have SDEI event number as the argument. If we really want move this check into function kvm_sdei_hypercall(), we would have code like below. Too much duplicated snippets will be seen. I don't think it's better than what we have if I fully understand your comments.
switch (...) {
case REGISTER:
if (!(ksdei && vsdei)) {
ret = SDEI_NOT_SUPPORTED;
break;
}
ret = kvm_sdei_hypercall_register(vcpu);
break;
case UNREGISTER:
if (!(ksdei && vsdei)) {
ret = SDEI_NOT_SUPPORTED;
break;
}
ret = kvm_sdei_hypercall_unregister(vcpu);
break;
case CONTEXT:
ret = kvm_sdei_hypercall_context(vcpu);
break;
:
}Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 06/21] KVM: arm64: Support SDEI_EVENT_CONTEXT hypercall
Hi Shannon,
Quoted 19 lines · Gavin Shan
Quoted 17 lines · Shannon Zhao
Quoted 4 lines · Gavin Shan
arch/arm64/kvm/sdei.c +4
-0+static unsigned long kvm_sdei_hypercall_context (struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, · line 286
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + struct kvm_sdei_vcpu_regs *regs; + unsigned long index = smccc_get_arg1(vcpu); + unsigned long ret = SDEI_SUCCESS; + + /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + }Maybe we could move these common sanity check codes to
kvm_sdei_hypercallto save some lines.
Quoted 5 lines
Not all hypercalls need this check. For example, COMPLETE/COMPLETE_RESUME/CONTEXT don't have SDEI event number as the argument. If we really want move this check into function
kvm_sdei_hypercall(), we would have code like below. Too much duplicated snippets will be seen. I don't think it's better than what we have if I fully understand your comments.
oops... sorry. Please ignore my previous reply. I thought you talk about the check on the SDEI event number wrongly. Yes, you're correct that the check should be moved to kvm_sdei_hypercall().
Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 06/21] KVM: arm64: Support SDEI_EVENT_CONTEXT hypercall
Hi Gavin,
Quoted 33 lines · Gavin Shan
Hi Shannon,
Quoted 20 lines · Gavin Shan
Quoted 18 lines · Shannon Zhao
Quoted 4 lines · Gavin Shan
arch/arm64/kvm/sdei.c +4
-0+static unsigned long kvm_sdei_hypercall_context (struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, · line 286
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + struct kvm_sdei_vcpu_regs *regs; + unsigned long index = smccc_get_arg1(vcpu); + unsigned long ret = SDEI_SUCCESS; + + /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + }Maybe we could move these common sanity check codes to
kvm_sdei_hypercallto save some lines.Quoted 9 lines
Not all hypercalls need this check. For example, COMPLETE/COMPLETE_RESUME/CONTEXT don't
have SDEI event number as the argument. If we really want move this check into functionkvm_sdei_hypercall(), we would have code like below. Too much duplicated snippets will
be seen. I don't think it's better than what we have if I fully understand your comments.
Quoted 3 lines
oops... sorry. Please ignore my previous reply. I thought you talk about the check on the SDEI event number wrongly. Yes, you're correct that the check should be moved to
kvm_sdei_hypercall().
even better than my previous proposal then
Eric
Quoted 8 lines
Thanks,
Gavin_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 06/21] KVM: arm64: Support SDEI_EVENT_CONTEXT hypercall
In reply to Gavin ShanHi Gavin,
Quoted 31 lines · Gavin Shan
Hi Shannon,
Quoted 18 lines · Shannon Zhao
Quoted 4 lines · Gavin Shan
arch/arm64/kvm/sdei.c +4
-0+static unsigned long kvm_sdei_hypercall_context (struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_enable(struct kvm_vcpu *vcpu, · line 286
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + struct kvm_sdei_vcpu_regs *regs; + unsigned long index = smccc_get_arg1(vcpu); + unsigned long ret = SDEI_SUCCESS; + + /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + }Maybe we could move these common sanity check codes to
kvm_sdei_hypercallto save some lines.Not all hypercalls need this check. For example, COMPLETE/COMPLETE_RESUME/CONTEXT don't
have SDEI event number as the argument. If we really want move this check into functionkvm_sdei_hypercall(), we would have code like below. Too much duplicated snippets will
be seen. I don't think it's better than what we have if I fully understand your comments.
Quoted 6 lines
switch (...) {
case REGISTER:
if (!(ksdei && vsdei)) {
ret =SDEI_NOT_SUPPORTED;
break;
}
at least you can use an inline function taking the vcpu as param?
Thanks
Eric
Quoted 17 lines
ret =
kvm_sdei_hypercall_register(vcpu); break;
case UNREGISTER:
if (!(ksdei && vsdei)) {
ret =SDEI_NOT_SUPPORTED; break;
}ret =
kvm_sdei_hypercall_unregister(vcpu); break;
case CONTEXT:
ret =kvm_sdei_hypercall_context(vcpu); break;
:
}
Quoted 7 lines
Thanks,
Gavin_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 7/21 KVM: arm64: Support SDEI_EVENT_UNREGISTER hypercall
In reply to Gavin ShanThis supports SDEI_EVENT_UNREGISTER hypercall. It's used by the guest to unregister SDEI event. The SDEI event won't be raised to the guest or specific vCPU after it's unregistered successfully. It's notable the SDEI event is disabled automatically on the guest or specific vCPU once it's unregistered successfully.
--- arch/arm64/kvm/sdei.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
arch/arm64/kvm/sdei.c +61 -0
@@ -308,6 +308,65 @@ static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_unregister (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +int index =0 ; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* Check if the KVM event exists */ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } + +/* Check if there is pending events */ +if (kske->state.refcount) { + ret =SDEI_PENDING ; + goto unlock; + } + +/* Check if it has been registered */ + kse = kske->kse; + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; +if (!kvm_sdei_is_registered (kske, index)) { + ret =SDEI_DENIED ; + goto unlock; + } + +/* The event is disabled when it's unregistered */ +kvm_sdei_clear_enabled (kske, index); +kvm_sdei_clear_registered (kske, index); +if (kvm_sdei_empty_registered (kske)) { +list_del (&kske->link); +kfree (kske); + } + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
@@ -333,6 +392,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)case SDEI_1_0_FN_SDEI_EVENT_COMPLETE :case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME :case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER : + ret =kvm_sdei_hypercall_unregister (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_STATUS :case SDEI_1_0_FN_SDEI_EVENT_GET_INFO :case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET :
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 07/21] KVM: arm64: Support SDEI_EVENT_UNREGISTER hypercall
Quoted 42 lines · Gavin Shan
This supports
SDEI_EVENT_UNREGISTERhypercall. It's used by the guest to unregister SDEI event. The SDEI event won't be raised to the guest or specific vCPU after it's unregistered successfully. It's notable the SDEI event is disabled automatically on the guest or specific vCPU once it's unregistered successfully.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)arch/arm64/kvm/sdei.c +23
-0@@ -308,6 +308,65 @@ static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_unregister (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +int index =0 ; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* Check if the KVM event exists */
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 343
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } + +/* Check if there is pending events */ +if (kske->state.refcount) { + ret =SDEI_PENDING ;
don't you want to record the fact the unregistration is outstanding to perform subsequent actions? Otherwise nothing will hapen when the current executing handlers complete?
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 350
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ goto unlock; + } + +/* Check if it has been registered */ + kse = kske->kse; + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ;
you could have an inline for the above as this is executed in many functions. even including the code below.
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 359
Quoted 9 lines
arch/arm64/kvm/sdei.c +9
-0+if (!kvm_sdei_is_registered (kske, index)) { + ret =SDEI_DENIED ; + goto unlock; + } + +/* The event is disabled when it's unregistered */ +kvm_sdei_clear_enabled (kske, index); +kvm_sdei_clear_registered (kske, index); +if (kvm_sdei_empty_registered (kske)) {
a refcount mechanism would be cleaner I think.
Quoted 23 lines
arch/arm64/kvm/sdei.c +12
-0+list_del (&kske->link); +kfree (kske); + } + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -333,6 +392,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)case SDEI_1_0_FN_SDEI_EVENT_COMPLETE :case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME :case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER : + ret =kvm_sdei_hypercall_unregister (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_STATUS :case SDEI_1_0_FN_SDEI_EVENT_GET_INFO :case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET :
Re: [PATCH v4 07/21] KVM: arm64: Support SDEI_EVENT_UNREGISTER hypercall
Hi Eric,
Quoted 48 lines · Eric Auger
Quoted 47 lines · Gavin Shan
This supports
SDEI_EVENT_UNREGISTERhypercall. It's used by the guest to unregister SDEI event. The SDEI event won't be raised to the guest or specific vCPU after it's unregistered successfully. It's notable the SDEI event is disabled automatically on the guest or specific vCPU once it's unregistered successfully.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)arch/arm64/kvm/sdei.c +28
-0@@ -308,6 +308,65 @@ static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_unregister (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +int index =0 ; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* Check if the KVM event exists */ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock;
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 343
Quoted 5 lines
arch/arm64/kvm/sdei.c +5
-0+ } + +/* Check if there is pending events */ +if (kske->state.refcount) { + ret =SDEI_PENDING ;don't you want to record the fact the unregistration is outstanding to perform subsequent actions? Otherwise nothing will hapen when the current executing handlers complete?
It's not necessary. The guest should retry in this case.
Quoted 9 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 350
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ goto unlock; + } + +/* Check if it has been registered */ + kse = kske->kse; + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ;you could have an inline for the above as this is executed in many functions. even including the code below.
Ok, it's a good idea.
Quoted 10 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 359
Quoted 9 lines
arch/arm64/kvm/sdei.c +9
-0+if (!kvm_sdei_is_registered (kske, index)) { + ret =SDEI_DENIED ; + goto unlock; + } + +/* The event is disabled when it's unregistered */ +kvm_sdei_clear_enabled (kske, index); +kvm_sdei_clear_registered (kske, index); +if (kvm_sdei_empty_registered (kske)) {a refcount mechanism would be cleaner I think.
A refcount isn't working well. We need a mapping here because the private SDEI event can be enabled/registered on multiple vCPUs. We need to know the exact vCPUs where the private SDEI event is enabled/registered.
Quoted 15 lines
Quoted 15 lines
arch/arm64/kvm/sdei.c +10
-0+list_del (&kske->link); +kfree (kske); + } + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -333,6 +392,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)case SDEI_1_0_FN_SDEI_EVENT_COMPLETE :
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 399
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME :case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER : + ret =kvm_sdei_hypercall_unregister (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_STATUS :case SDEI_1_0_FN_SDEI_EVENT_GET_INFO :case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET :
Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 07/21] KVM: arm64: Support SDEI_EVENT_UNREGISTER hypercall
Hi Gavin,
Quoted 60 lines · Gavin Shan
Hi Eric,
Quoted 49 lines · Eric Auger
Quoted 48 lines · Gavin Shan
This supports
SDEI_EVENT_UNREGISTERhypercall. It's used by the guest to unregister SDEI event. The SDEI event won't be raised to the guest or specific vCPU after it's unregistered successfully. It's notable the SDEI event is disabled automatically on the guest or specific vCPU once it's unregistered successfully.Signed-off-by Gavin Shan <[email protected]>---
arch/arm64/kvm/sdei.c| 61 +++++++++++++++++++++++++++++++++++++++++++1 file changed, 61 insertions(+)arch/arm64/kvm/sdei.c +0
-0@@ -308,6 +308,65 @@ static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) return ret; }+static unsigned long
kvm_sdei_hypercall_unregister(struct kvm_vcpu *vcpu)arch/arm64/kvm/sdei.c +27
-0+{ + struct kvm *kvm = vcpu->kvm; + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + struct kvm_sdei_event *kse = NULL; + struct kvm_sdei_kvm_event *kske = NULL; + unsigned long event_num = smccc_get_arg1(vcpu); + int index = 0; + unsigned long ret = SDEI_SUCCESS; + + /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + } + + if (!kvm_sdei_is_valid_event_num(event_num)) { + ret = SDEI_INVALID_PARAMETERS; + goto out; + } + + /* Check if the KVM event exists */ + spin_lock(&ksdei->lock); + kske = kvm_sdei_find_kvm_event(kvm, event_num); + if (!kske) { + ret = SDEI_INVALID_PARAMETERS; + goto unlock;Quoted 8 lines
Quoted 5 lines
+ }
+
+ /* Check if there is pending events */
+ if (kske->state.refcount) {
+ ret =SDEI_PENDING;don't you want to record the fact the unregistration is outstanding to perform subsequent actions? Otherwise nothing will hapen when the current executing handlers complete?>
Quoted 1 line
It's not necessary. The guest should retry in this case.
I do not understand that from the spec:
6.7 Unregistering an event says
With the PENDING status, the unregister request will be queued until the event is completed using SDEI_EVENT_COMPLETE .
Also there is state called "Handler-unregister-pending"
But well I would need to dig further into the spec again :)
Quoted 22 lines
Quoted 10 lines
Quoted 8 lines
+ goto unlock;
+ }
+
+ /* Check if it has been registered */
+ kse =kske->kse;
+ index = (kse->state.type==SDEI_EVENT_TYPE_PRIVATE) ? +vcpu->vcpu_idx: 0;you could have an inline for the above as this is executed in many functions. even including the code below.
Ok, it's a good idea.
Quoted 9 lines
Quoted 9 lines
+ if (!kvm_sdei_is_registered(kske, index)) { + ret =
SDEI_DENIED;
+ goto unlock;
+ }
+
+ /* The event is disabled when it's unregistered */ +kvm_sdei_clear_enabled(kske, index);
+kvm_sdei_clear_registered(kske, index);
+ if (kvm_sdei_empty_registered(kske)) {
Quoted 5 lines
Quoted 1 line
a refcount mechanism would be cleaner I think.
A refcount isn't working well. We need a mapping here because the private SDEI event can be enabled/registered on multiple vCPUs. We need to know the exact vCPUs where the private SDEI event is enabled/registered.
I don't get why you can't increment/decrement the ref count each time the event is registered/unregistered by a given vcpu to manage its life cycle? Does not mean you don't need the bitmap to know the actual mapping.
Thanks
Eric
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
+
list_del(&kske->link);
+ kfree(kske);
+ }arch/arm64/kvm/sdei.c +7
-0+ +unlock: + spin_unlock(&ksdei->lock); +out: + return ret; +} +int
kvm_sdei_hypercall(struct kvm_vcpu *vcpu)
{
u32 func =smccc_get_function(vcpu);arch/arm64/kvm/sdei.c +0
-0@@ -333,6 +392,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)case
SDEI_1_0_FN_SDEI_EVENT_COMPLETE:
caseSDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME:
caseSDEI_1_0_FN_SDEI_EVENT_UNREGISTER:
+ ret =kvm_sdei_hypercall_unregister(vcpu);
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
+ break;
caseSDEI_1_0_FN_SDEI_EVENT_STATUS:
caseSDEI_1_0_FN_SDEI_EVENT_GET_INFO:
caseSDEI_1_0_FN_SDEI_EVENT_ROUTING_SET:Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 8/21 KVM: arm64: Support SDEI_EVENT_STATUS hypercall
In reply to Gavin ShanThis supports SDEI_EVENT_STATUS hypercall. It's used by the guest to retrieve a bitmap to indicate the SDEI event states, including registration, enablement and delivery state.
--- arch/arm64/kvm/sdei.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
arch/arm64/kvm/sdei.c +50 -0
@@ -367,6 +367,54 @@ static unsigned long kvm_sdei_hypercall_unregister(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_status (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +int index =0 ; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* +* Check if the KVM event exists. None of the flags +* will be set if it doesn't exist. +*/ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =0 ; + goto unlock; + } + + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; +if (kvm_sdei_is_registered (kske, index)) + ret |= (1UL <<SDEI_EVENT_STATUS_REGISTERED ); +if (kvm_sdei_is_enabled (kske, index)) + ret |= (1UL <<SDEI_EVENT_STATUS_ENABLED ); +if (kske->state.refcount) + ret |= (1UL <<SDEI_EVENT_STATUS_RUNNING ); + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
@@ -395,6 +443,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_unregister (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_STATUS : + ret =kvm_sdei_hypercall_status (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_GET_INFO :case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET :case SDEI_1_0_FN_SDEI_PE_MASK :
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 08/21] KVM: arm64: Support SDEI_EVENT_STATUS hypercall
Quoted 28 lines · Gavin Shan
This supports
SDEI_EVENT_STATUShypercall. It's used by the guest to retrieve a bitmap to indicate the SDEI event states, including registration, enablement and delivery state.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)arch/arm64/kvm/sdei.c +11
-0@@ -367,6 +367,54 @@ static unsigned long kvm_sdei_hypercall_unregister(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_status (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +int index =0 ; +unsigned long ret =SDEI_SUCCESS ; +
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_unregister(struct kvm_vcpu *vcpu) · line 390
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + }
if we were to support bound events, I do not know if a given even num can disapper inbetween that check and the rest of the code, in which case a lock would be needed?
Quoted 32 lines
arch/arm64/kvm/sdei.c +27
-0+ +/* +* Check if the KVM event exists. None of the flags +* will be set if it doesn't exist. +*/ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =0 ; + goto unlock; + } + + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; +if (kvm_sdei_is_registered (kske, index)) + ret |= (1UL <<SDEI_EVENT_STATUS_REGISTERED ); +if (kvm_sdei_is_enabled (kske, index)) + ret |= (1UL <<SDEI_EVENT_STATUS_ENABLED ); +if (kske->state.refcount) + ret |= (1UL <<SDEI_EVENT_STATUS_RUNNING ); + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 450
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0@@ -395,6 +443,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_unregister (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_STATUS : + ret =kvm_sdei_hypercall_status (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_GET_INFO :case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET :case SDEI_1_0_FN_SDEI_PE_MASK :
Thanks
Eric
Re: [PATCH v4 08/21] KVM: arm64: Support SDEI_EVENT_STATUS hypercall
Hi Eric,
Quoted 34 lines · Eric Auger
Quoted 33 lines · Gavin Shan
This supports
SDEI_EVENT_STATUShypercall. It's used by the guest to retrieve a bitmap to indicate the SDEI event states, including registration, enablement and delivery state.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)arch/arm64/kvm/sdei.c +16
-0@@ -367,6 +367,54 @@ static unsigned long kvm_sdei_hypercall_unregister(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_status (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +int index =0 ; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + }
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_unregister(struct kvm_vcpu *vcpu) · line 390
Quoted 5 lines
arch/arm64/kvm/sdei.c +5
-0+ +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + }if we were to support bound events, I do not know if a given even num can disapper inbetween that check and the rest of the code, in which case a lock would be needed?
For the bound events, it's possbile. However, @ksdei->lock can be reused in that cause. Anyway, it's something for future :)
Quoted 32 lines
Quoted 32 lines
arch/arm64/kvm/sdei.c +27
-0+ +/* +* Check if the KVM event exists. None of the flags +* will be set if it doesn't exist. +*/ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =0 ; + goto unlock; + } + + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; +if (kvm_sdei_is_registered (kske, index)) + ret |= (1UL <<SDEI_EVENT_STATUS_REGISTERED ); +if (kvm_sdei_is_enabled (kske, index)) + ret |= (1UL <<SDEI_EVENT_STATUS_ENABLED ); +if (kske->state.refcount) + ret |= (1UL <<SDEI_EVENT_STATUS_RUNNING ); + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -395,6 +443,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_unregister (vcpu);
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 450
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0break ;case SDEI_1_0_FN_SDEI_EVENT_STATUS : + ret =kvm_sdei_hypercall_status (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_GET_INFO :case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET :case SDEI_1_0_FN_SDEI_PE_MASK :
Thanks,
Gavin
PATCH v4 9/21 KVM: arm64: Support SDEI_EVENT_GET_INFO hypercall
In reply to Gavin ShanThis supports SDEI_EVENT_GET_INFO hypercall. It's used by the guest to retrieve various information about the supported (exported) events, including type, signaled, route mode and affinity for the shared events.
--- arch/arm64/kvm/sdei.c | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)
arch/arm64/kvm/sdei.c +76 -0
@@ -415,6 +415,80 @@ static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_info (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +unsigned long event_info =smccc_get_arg2 (vcpu); +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* +* Check if the KVM event exists. The event might have been +* registered, we need fetch the information from the registered +* event in that case. +*/ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); + kse = kske ? kske->kse :NULL ; +if (!kse) { + kse =kvm_sdei_find_event (kvm, event_num); +if (!kse) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } + } + +/* Retrieve the requested information */ +switch (event_info) { +case SDEI_EVENT_INFO_EV_TYPE : + ret = kse->state.type; +break ; +case SDEI_EVENT_INFO_EV_SIGNALED : + ret = kse->state.signaled; +break ; +case SDEI_EVENT_INFO_EV_PRIORITY : + ret = kse->state.priority; +break ; +case SDEI_EVENT_INFO_EV_ROUTING_MODE : +case SDEI_EVENT_INFO_EV_ROUTING_AFF : +if (kse->state.type !=SDEI_EVENT_TYPE_SHARED ) { + ret =SDEI_INVALID_PARAMETERS ; +break ; + } + +if (event_info ==SDEI_EVENT_INFO_EV_ROUTING_MODE ) { + ret = kske ? kske->state.route_mode : +SDEI_EVENT_REGISTER_RM_ANY ; + }else { + ret = kske ? kske->state.route_affinity :0 ; + } + +break ; +default : + ret =SDEI_INVALID_PARAMETERS ; + } + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
@@ -446,6 +520,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_status (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_GET_INFO : + ret =kvm_sdei_hypercall_info (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET :case SDEI_1_0_FN_SDEI_PE_MASK :case SDEI_1_0_FN_SDEI_PE_UNMASK :
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 09/21] KVM: arm64: Support SDEI_EVENT_GET_INFO hypercall
Hi Gavin,
Quoted 33 lines · Gavin Shan
This supports
SDEI_EVENT_GET_INFOhypercall. It's used by the guest to retrieve various information about the supported (exported) events, including type, signaled, route mode and affinity for the shared events.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)arch/arm64/kvm/sdei.c +15
-0@@ -415,6 +415,80 @@ static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_info (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +unsigned long event_info =smccc_get_arg2 (vcpu); +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out;
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) · line 442
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* +* Check if the KVM event exists. The event might have been +* registered, we need fetch the information from the registered
s/fetch/to fetch
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) · line 451
Quoted 9 lines
arch/arm64/kvm/sdei.c +9
-0+* event in that case. +*/ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); + kse = kske ? kske->kse :NULL ; +if (!kse) { + kse =kvm_sdei_find_event (kvm, event_num); +if (!kse) { + ret =SDEI_INVALID_PARAMETERS ;
this should have already be covered by !kvm_sdei_is_valid_event_num I think (although this latter only checks the since static event num with KVM owner mask)
Quoted 15 lines
arch/arm64/kvm/sdei.c +15
-0+ goto unlock; + } + } + +/* Retrieve the requested information */ +switch (event_info) { +case SDEI_EVENT_INFO_EV_TYPE : + ret = kse->state.type; +break ; +case SDEI_EVENT_INFO_EV_SIGNALED : + ret = kse->state.signaled; +break ; +case SDEI_EVENT_INFO_EV_PRIORITY : + ret = kse->state.priority; +break ;
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) · line 476
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+case SDEI_EVENT_INFO_EV_ROUTING_MODE : +case SDEI_EVENT_INFO_EV_ROUTING_AFF : +if (kse->state.type !=SDEI_EVENT_TYPE_SHARED ) { + ret =SDEI_INVALID_PARAMETERS ; +break ; + } + +if (event_info ==SDEI_EVENT_INFO_EV_ROUTING_MODE ) { + ret = kske ? kske->state.route_mode : +SDEI_EVENT_REGISTER_RM_ANY ;
no, if event is not registered (!kske) DENIED should be returned
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) · line 477
Quoted 1 line
arch/arm64/kvm/sdei.c +1
-0+ }else {
same here
Quoted 19 lines
arch/arm64/kvm/sdei.c +14
-0+ ret = kske ? kske->state.route_affinity :0 ; + } + +break ; +default : + ret =SDEI_INVALID_PARAMETERS ; + } + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 527
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0@@ -446,6 +520,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_status (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_GET_INFO : + ret =kvm_sdei_hypercall_info (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET :case SDEI_1_0_FN_SDEI_PE_MASK :case SDEI_1_0_FN_SDEI_PE_UNMASK :
Eric
Re: [PATCH v4 09/21] KVM: arm64: Support SDEI_EVENT_GET_INFO hypercall
Hi Eric,
Quoted 37 lines · Eric Auger
Quoted 36 lines · Gavin Shan
This supports
SDEI_EVENT_GET_INFOhypercall. It's used by the guest to retrieve various information about the supported (exported) events, including type, signaled, route mode and affinity for the shared events.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)arch/arm64/kvm/sdei.c +18
-0@@ -415,6 +415,80 @@ static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_info (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +unsigned long event_info =smccc_get_arg2 (vcpu); +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) {
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) · line 442
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* +* Check if the KVM event exists. The event might have been +* registered, we need fetch the information from the registered s/fetch/to fetch
Ack.
Quoted 4 lines
Quoted 4 lines
arch/arm64/kvm/sdei.c +4
-0+* event in that case. +*/ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num);
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) · line 451
Quoted 5 lines
arch/arm64/kvm/sdei.c +5
-0+ kse = kske ? kske->kse :NULL ; +if (!kse) { + kse =kvm_sdei_find_event (kvm, event_num); +if (!kse) { + ret =SDEI_INVALID_PARAMETERS ;this should have already be covered by !kvm_sdei_is_valid_event_num I think (although this latter only checks the since static event num with KVM owner mask)
Nope. Strictly speaking, kvm_sdei_find_event() covers the check carried by !kvm_sdei_is_valid_event_num(). All the defined (exposed) events should have virtual event number :)
Quoted 18 lines
Quoted 18 lines
arch/arm64/kvm/sdei.c +18
-0+ goto unlock; + } + } + +/* Retrieve the requested information */ +switch (event_info) { +case SDEI_EVENT_INFO_EV_TYPE : + ret = kse->state.type; +break ; +case SDEI_EVENT_INFO_EV_SIGNALED : + ret = kse->state.signaled; +break ; +case SDEI_EVENT_INFO_EV_PRIORITY : + ret = kse->state.priority; +break ; +case SDEI_EVENT_INFO_EV_ROUTING_MODE : +case SDEI_EVENT_INFO_EV_ROUTING_AFF : +if (kse->state.type !=SDEI_EVENT_TYPE_SHARED ) {
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) · line 476
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ ret =SDEI_INVALID_PARAMETERS ; +break ; + } + +if (event_info ==SDEI_EVENT_INFO_EV_ROUTING_MODE ) { + ret = kske ? kske->state.route_mode : +SDEI_EVENT_REGISTER_RM_ANY ;no, if event is not registered (!kske) DENIED should be returned
I don't think so. According to the specification, there is no DENIED return value for STATUS hypercall. Either INVALID_PARAMETERS or NOT_SUPPORTED should be returned from this hypercall :)
Quoted 21 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) · line 477
Quoted 1 line
arch/arm64/kvm/sdei.c +1
-0+ }else {same here
Quoted 19 lines
arch/arm64/kvm/sdei.c +14
-0+ ret = kske ? kske->state.route_affinity :0 ; + } + +break ; +default : + ret =SDEI_INVALID_PARAMETERS ; + } + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -446,6 +520,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_status (vcpu);
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 527
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0break ;case SDEI_1_0_FN_SDEI_EVENT_GET_INFO : + ret =kvm_sdei_hypercall_info (vcpu); +break ;case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET :case SDEI_1_0_FN_SDEI_PE_MASK :case SDEI_1_0_FN_SDEI_PE_UNMASK :
Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 09/21] KVM: arm64: Support SDEI_EVENT_GET_INFO hypercall
Hi Gavin,
Quoted 60 lines · Gavin Shan
Hi Eric,
Quoted 37 lines · Eric Auger
Quoted 36 lines · Gavin Shan
This supports
SDEI_EVENT_GET_INFOhypercall. It's used by the guest to retrieve various information about the supported (exported) events, including type, signaled, route mode and affinity for the shared events.Signed-off-by Gavin Shan <[email protected]>---
arch/arm64/kvm/sdei.c| 76 +++++++++++++++++++++++++++++++++++++++++++1 file changed, 76 insertions(+)arch/arm64/kvm/sdei.c +17
-0@@ -415,6 +415,80 @@ static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) return ret; } +static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + struct kvm_sdei_event *kse = NULL; + struct kvm_sdei_kvm_event *kske = NULL; + unsigned long event_num = smccc_get_arg1(vcpu); + unsigned long event_info = smccc_get_arg2(vcpu); + unsigned long ret = SDEI_SUCCESS; + + /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + } + + if (!kvm_sdei_is_valid_event_num(event_num)) {Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) · line 442
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ ret = SDEI_INVALID_PARAMETERS; + goto out; + } + + /* +* Check if the KVM event exists. The event might have been +* registered, we need fetch the information from the registered s/fetch/to fetch
Ack.
Quoted 9 lines
Quoted 9 lines
arch/arm64/kvm/sdei.c +9
-0+* event in that case. +*/ + spin_lock(&ksdei->lock); + kske = kvm_sdei_find_kvm_event(kvm, event_num); + kse = kske ? kske->kse : NULL; + if (!kse) { + kse = kvm_sdei_find_event(kvm, event_num); + if (!kse) { + ret = SDEI_INVALID_PARAMETERS;
Quoted 7 lines
Quoted 3 lines
this should have already be covered by !kvm_sdei_is_valid_event_num I think (although this latter only checks the since static event num with KVM owner mask)
Nope. Strictly speaking,
kvm_sdei_find_event()covers the check carried by !kvm_sdei_is_valid_event_num(). All the defined (exposed) events should have virtual event number :)
you're right
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
arch/arm64/kvm/sdei.c +18
-0+ goto unlock; + } + } + + /* Retrieve the requested information */ + switch (event_info) { + case SDEI_EVENT_INFO_EV_TYPE: + ret = kse->state.type; + break; + case SDEI_EVENT_INFO_EV_SIGNALED: + ret = kse->state.signaled; + break; + case SDEI_EVENT_INFO_EV_PRIORITY: + ret = kse->state.priority; + break; + case SDEI_EVENT_INFO_EV_ROUTING_MODE: + case SDEI_EVENT_INFO_EV_ROUTING_AFF: + if (kse->state.type != SDEI_EVENT_TYPE_SHARED) {Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) · line 476
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ ret = SDEI_INVALID_PARAMETERS; + break; + } + + if (event_info == SDEI_EVENT_INFO_EV_ROUTING_MODE) { + ret = kske ? kske->state.route_mode : + SDEI_EVENT_REGISTER_RM_ANY;no, if event is not registered (!kske) DENIED should be returned
Quoted 4 lines
I don't think so. According to the specification, there is no DENIED return value for STATUS hypercall. Either
INVALID_PARAMETERSorNOT_SUPPORTED
should be returned from this hypercall :)
Look at table 5.1.10.2 Parameter a,d Return Values. DENIED is returned in some cases
Eric
Quoted 34 lines
Quoted 22 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_status(struct kvm_vcpu *vcpu) · line 477
Quoted 2 lines
arch/arm64/kvm/sdei.c +1
-0+ } else {same here
Quoted 19 lines
arch/arm64/kvm/sdei.c +14
-0+ ret = kske ? kske->state.route_affinity : 0; + } + + break; + default: + ret = SDEI_INVALID_PARAMETERS; + } + +unlock: + spin_unlock(&ksdei->lock); +out: + return ret; +} + int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) {u32 func =
smccc_get_function(vcpu);arch/arm64/kvm/sdei.c +0
-0@@ -446,6 +520,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret = kvm_sdei_hypercall_status(vcpu);Quoted 8 lines
Quoted 8 lines
arch/arm64/kvm/sdei.c +0
-0break;case
SDEI_1_0_FN_SDEI_EVENT_GET_INFO:
+ ret =kvm_sdei_hypercall_info(vcpu);
+ break;
caseSDEI_1_0_FN_SDEI_EVENT_ROUTING_SET:
caseSDEI_1_0_FN_SDEI_PE_MASK:
caseSDEI_1_0_FN_SDEI_PE_UNMASK:Thanks,
Gavin
PATCH v4 10/21 KVM: arm64: Support SDEI_EVENT_ROUTING_SET hypercall
In reply to Gavin ShanThis supports SDEI_EVENT_ROUTING_SET hypercall. It's used by the guest to set route mode and affinity for the registered KVM event. It's only valid for the shared events. It's not allowed to do so when the corresponding event has been raised to the guest.
--- arch/arm64/kvm/sdei.c | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
arch/arm64/kvm/sdei.c +64 -0
@@ -489,6 +489,68 @@ static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_route (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +unsigned long route_mode =smccc_get_arg2 (vcpu); +unsigned long route_affinity =smccc_get_arg3 (vcpu); +int index =0 ; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +if (!(route_mode ==SDEI_EVENT_REGISTER_RM_ANY || + route_mode ==SDEI_EVENT_REGISTER_RM_PE )) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +/* Check if the KVM event has been registered */ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } + +/* Validate KVM event state */ + kse = kske->kse; +if (kse->state.type !=SDEI_EVENT_TYPE_SHARED ) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } + +if (!kvm_sdei_is_registered (kske, index) || +kvm_sdei_is_enabled (kske, index) || + kske->state.refcount) { + ret =SDEI_DENIED ; + goto unlock; + } + +/* Update state */ + kske->state.route_mode = route_mode; + kske->state.route_affinity = route_affinity; + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
@@ -523,6 +585,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_info (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET : + ret =kvm_sdei_hypercall_route (vcpu); +break ;case SDEI_1_0_FN_SDEI_PE_MASK :case SDEI_1_0_FN_SDEI_PE_UNMASK :case SDEI_1_0_FN_SDEI_INTERRUPT_BIND :
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 10/21] KVM: arm64: Support SDEI_EVENT_ROUTING_SET hypercall
Hi Gavin,
Quoted 37 lines · Gavin Shan
This supports
SDEI_EVENT_ROUTING_SEThypercall. It's used by the guest to set route mode and affinity for the registered KVM event. It's only valid for the shared events. It's not allowed to do so when the corresponding event has been raised to the guest.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)arch/arm64/kvm/sdei.c +19
-0@@ -489,6 +489,68 @@ static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_route (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +unsigned long route_mode =smccc_get_arg2 (vcpu); +unsigned long route_affinity =smccc_get_arg3 (vcpu); +int index =0 ; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } +
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu) · line 520
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } + +if (!(route_mode ==SDEI_EVENT_REGISTER_RM_ANY || + route_mode ==SDEI_EVENT_REGISTER_RM_PE )) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + }
Some sanity checking on the affinity arg could be made as well according to 5.1.2 affinity desc. The fn shall return INVALID_PARAMETER in case of invalid affinity.
Quoted 6 lines
arch/arm64/kvm/sdei.c +6
-0+ +/* Check if the KVM event has been registered */ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =SDEI_INVALID_PARAMETERS ;
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu) · line 536
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ goto unlock; + } + +/* Validate KVM event state */ + kse = kske->kse; +if (kse->state.type !=SDEI_EVENT_TYPE_SHARED ) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } +
Event handler is in a state other than: handler-registered.
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu) · line 539
Quoted 3 lines
arch/arm64/kvm/sdei.c +3
-0+if (!kvm_sdei_is_registered (kske, index) || +kvm_sdei_is_enabled (kske, index) || + kske->state.refcount) {
I am not sure about the refcount role here. Does it make sure the state is != handler-enabled and running or handler-unregister-pending?
I think we would gain in readibility if we had a helper to check whether we are in those states?
Quoted 19 lines
arch/arm64/kvm/sdei.c +14
-0+ ret =SDEI_DENIED ; + goto unlock; + } + +/* Update state */ + kske->state.route_mode = route_mode; + kske->state.route_affinity = route_affinity; + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 592
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0@@ -523,6 +585,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_info (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET : + ret =kvm_sdei_hypercall_route (vcpu); +break ;case SDEI_1_0_FN_SDEI_PE_MASK :case SDEI_1_0_FN_SDEI_PE_UNMASK :case SDEI_1_0_FN_SDEI_INTERRUPT_BIND :
Eric
Re: [PATCH v4 10/21] KVM: arm64: Support SDEI_EVENT_ROUTING_SET hypercall
Hi Eric,
Quoted 43 lines · Eric Auger
Quoted 42 lines · Gavin Shan
This supports
SDEI_EVENT_ROUTING_SEThypercall. It's used by the guest to set route mode and affinity for the registered KVM event. It's only valid for the shared events. It's not allowed to do so when the corresponding event has been raised to the guest.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)arch/arm64/kvm/sdei.c +24
-0@@ -489,6 +489,68 @@ static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_route (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +unsigned long event_num =smccc_get_arg1 (vcpu); +unsigned long route_mode =smccc_get_arg2 (vcpu); +unsigned long route_affinity =smccc_get_arg3 (vcpu); +int index =0 ; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (event_num)) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + } +
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu) · line 520
Quoted 5 lines
arch/arm64/kvm/sdei.c +5
-0+if (!(route_mode ==SDEI_EVENT_REGISTER_RM_ANY || + route_mode ==SDEI_EVENT_REGISTER_RM_PE )) { + ret =SDEI_INVALID_PARAMETERS ; + goto out; + }Some sanity checking on the affinity arg could be made as well according to 5.1.2 affinity desc. The fn shall return
INVALID_PARAMETERin case of invalid affinity.
Yep, you're right. I didn't figure out it. I may put a comment here. For now, the SDEI client driver in the guest kernel doesn't attempt to change the routing mode.
/* FIXME: The affinity should be verified */
Quoted 9 lines
Quoted 9 lines
arch/arm64/kvm/sdei.c +9
-0+ +/* Check if the KVM event has been registered */ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, event_num); +if (!kske) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } +
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu) · line 536
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+/* Validate KVM event state */ + kse = kske->kse; +if (kse->state.type !=SDEI_EVENT_TYPE_SHARED ) { + ret =SDEI_INVALID_PARAMETERS ; + goto unlock; + } +Event handler is in a state other than: handler-registered.
They're equivalent as the handler is provided as a parameter when the event is registered.
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu) · line 539
Quoted 3 lines
arch/arm64/kvm/sdei.c +3
-0+if (!kvm_sdei_is_registered (kske, index) || +kvm_sdei_is_enabled (kske, index) || + kske->state.refcount) {I am not sure about the refcount role here. Does it make sure the state is != handler-enabled and running or handler-unregister-pending?
I think we would gain in readibility if we had a helper to check whether we are in those states?
@refcount here indicates pending SDEI event for delivery. In this case, chaning its routing mode is disallowed.
Quoted 19 lines
Quoted 19 lines
arch/arm64/kvm/sdei.c +14
-0+ ret =SDEI_DENIED ; + goto unlock; + } + +/* Update state */ + kske->state.route_mode = route_mode; + kske->state.route_affinity = route_affinity; + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -523,6 +585,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_info (vcpu);
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 592
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0break ;case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET : + ret =kvm_sdei_hypercall_route (vcpu); +break ;case SDEI_1_0_FN_SDEI_PE_MASK :case SDEI_1_0_FN_SDEI_PE_UNMASK :case SDEI_1_0_FN_SDEI_INTERRUPT_BIND :
Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 10/21] KVM: arm64: Support SDEI_EVENT_ROUTING_SET hypercall
Hi Gavin,
Quoted 85 lines · Gavin Shan
Hi Eric,
Quoted 43 lines · Eric Auger
Quoted 42 lines · Gavin Shan
This supports
SDEI_EVENT_ROUTING_SEThypercall. It's used by the guest to set route mode and affinity for the registered KVM event. It's only valid for the shared events. It's not allowed to do so when the corresponding event has been raised to the guest.Signed-off-by Gavin Shan <[email protected]>---
arch/arm64/kvm/sdei.c| 64 +++++++++++++++++++++++++++++++++++++++++++1 file changed, 64 insertions(+)arch/arm64/kvm/sdei.c +23
-0@@ -489,6 +489,68 @@ static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu) return ret; } +static unsigned long kvm_sdei_hypercall_route(struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + struct kvm_sdei_event *kse = NULL; + struct kvm_sdei_kvm_event *kske = NULL; + unsigned long event_num = smccc_get_arg1(vcpu); + unsigned long route_mode = smccc_get_arg2(vcpu); + unsigned long route_affinity = smccc_get_arg3(vcpu); + int index = 0; + unsigned long ret = SDEI_SUCCESS; + + /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + } + + if (!kvm_sdei_is_valid_event_num(event_num)) { + ret = SDEI_INVALID_PARAMETERS; + goto out; + } +Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu) · line 520
Quoted 5 lines
arch/arm64/kvm/sdei.c +5
-0+ if (!(route_mode == SDEI_EVENT_REGISTER_RM_ANY || + route_mode == SDEI_EVENT_REGISTER_RM_PE)) { + ret = SDEI_INVALID_PARAMETERS; + goto out; + }Some sanity checking on the affinity arg could be made as well according to 5.1.2 affinity desc. The fn shall return
INVALID_PARAMETERin case of invalid affinity.Yep, you're right. I didn't figure out it. I may put a comment here. For now, the SDEI client driver in the guest kernel doesn't attempt to change the routing mode.
/* FIXME: The affinity should be verified */
Quoted 9 lines
Quoted 9 lines
arch/arm64/kvm/sdei.c +9
-0+ + /* Check if the KVM event has been registered */ + spin_lock(&ksdei->lock); + kske = kvm_sdei_find_kvm_event(kvm, event_num); + if (!kske) { + ret = SDEI_INVALID_PARAMETERS; + goto unlock; + } +Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_info(struct kvm_vcpu *vcpu) · line 536
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ /* Validate KVM event state */ + kse = kske->kse; + if (kse->state.type != SDEI_EVENT_TYPE_SHARED) { + ret = SDEI_INVALID_PARAMETERS; + goto unlock; + } +Event handler is in a state other than: handler-registered.
They're equivalent as the handler is provided as a parameter when the event is registered.
Quoted 3 lines
Quoted 3 lines
arch/arm64/kvm/sdei.c +3
-0+ if (!kvm_sdei_is_registered(kske, index) || + kvm_sdei_is_enabled(kske, index) || + kske->state.refcount) {
Quoted 8 lines
Quoted 5 lines
I am not sure about the refcount role here. Does it make sure the state is != handler-enabled and running or handler-unregister-pending?
I think we would gain in readibility if we had a helper to check whether we are in those states?
@refcount here indicates pending SDEI event for delivery. In this case, chaning its routing mode is disallowed.
OK. I guess you will document the refcount role somewhere.
Thanks
Eric
Quoted 32 lines
Quoted 20 lines
Quoted 20 lines
arch/arm64/kvm/sdei.c +14
-0+ ret = SDEI_DENIED; + goto unlock; + } + + /* Update state */ + kske->state.route_mode = route_mode; + kske->state.route_affinity = route_affinity; + +unlock: + spin_unlock(&ksdei->lock); +out: + return ret; +} + int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) {u32 func =
smccc_get_function(vcpu);arch/arm64/kvm/sdei.c +0
-0@@ -523,6 +585,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret = kvm_sdei_hypercall_info(vcpu);Quoted 8 lines
Quoted 8 lines
arch/arm64/kvm/sdei.c +0
-0break;case
SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET:
+ ret =kvm_sdei_hypercall_route(vcpu);
+ break;
caseSDEI_1_0_FN_SDEI_PE_MASK:
caseSDEI_1_0_FN_SDEI_PE_UNMASK:
caseSDEI_1_0_FN_SDEI_INTERRUPT_BIND:Thanks,
Gavin
PATCH v4 11/21 KVM: arm64: Support SDEI_PE_{MASK, UNMASK} hypercall
In reply to Gavin ShanThis supports SDEI_PE_{MASK, UNMASK} hypercall. They are used by the guest to stop the specific vCPU from receiving SDEI events.
--- arch/arm64/kvm/sdei.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
arch/arm64/kvm/sdei.c +35 -0
@@ -551,6 +551,37 @@ static unsigned long kvm_sdei_hypercall_route(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_mask (struct kvm_vcpu *vcpu, +bool mask) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +spin_lock (&vsdei->lock); + +/* Check the state */ +if (mask == vsdei->state.masked) { + ret =SDEI_DENIED ; + goto unlock; + } + +/* Update the state */ + vsdei->state.masked = mask ?1 :0 ; + +unlock: +spin_unlock (&vsdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
@@ -588,7 +619,11 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_route (vcpu);break ;case SDEI_1_0_FN_SDEI_PE_MASK : + ret =kvm_sdei_hypercall_mask (vcpu, true); +break ;case SDEI_1_0_FN_SDEI_PE_UNMASK : + ret =kvm_sdei_hypercall_mask (vcpu, false); +break ;case SDEI_1_0_FN_SDEI_INTERRUPT_BIND :case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE :case SDEI_1_0_FN_SDEI_PRIVATE_RESET :
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 11/21] KVM: arm64: Support SDEI_PE_{MASK, UNMASK} hypercall
Hi Gavin,
Quoted 25 lines · Gavin Shan
This supports SDEI_PE_{MASK, UNMASK} hypercall. They are used by the guest to stop the specific vCPU from receiving SDEI events.
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)arch/arm64/kvm/sdei.c +9
-0@@ -551,6 +551,37 @@ static unsigned long kvm_sdei_hypercall_route(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_mask (struct kvm_vcpu *vcpu, +bool mask) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_route(struct kvm_vcpu *vcpu) · line 572
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +spin_lock (&vsdei->lock); + +/* Check the state */ +if (mask == vsdei->state.masked) { + ret =SDEI_DENIED ;
are you sure? I don't this error documented in 5.1.12?
Besides the spec says:
"
This call can be invoked by the client to mask the PE, whether or not the PE is already masked."
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_route(struct kvm_vcpu *vcpu) · line 582
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ goto unlock; + } + +/* Update the state */ + vsdei->state.masked = mask ?1 :0 ; + +unlock: +spin_unlock (&vsdei->lock); +out: +return ret;
In case of success the returned value is SUCESS for UNMASK but not for MASK (see table in 5.1.12).
By the way I have just noticed there is a more recent of the spec than the A:
ARM_DEN0054C
You should update the cover letter and [PATCH v4 02/21] KVM: arm64: Add SDEI virtualization infrastructure commit msg
Quoted 8 lines
arch/arm64/kvm/sdei.c +2
-0+} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -588,7 +619,11 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_route (vcpu);
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 629
Quoted 10 lines
arch/arm64/kvm/sdei.c +4
-0break ;case SDEI_1_0_FN_SDEI_PE_MASK : + ret =kvm_sdei_hypercall_mask (vcpu, true); +break ;case SDEI_1_0_FN_SDEI_PE_UNMASK : + ret =kvm_sdei_hypercall_mask (vcpu, false); +break ;case SDEI_1_0_FN_SDEI_INTERRUPT_BIND :case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE :case SDEI_1_0_FN_SDEI_PRIVATE_RESET :
Eric
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 11/21] KVM: arm64: Support SDEI_PE_{MASK, UNMASK} hypercall
Hi Eric,
Quoted 38 lines · Eric Auger
Quoted 25 lines · Gavin Shan
This supports SDEI_PE_{MASK, UNMASK} hypercall. They are used by the guest to stop the specific vCPU from receiving SDEI events.
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)arch/arm64/kvm/sdei.c +9
-0@@ -551,6 +551,37 @@ static unsigned long kvm_sdei_hypercall_route(struct kvm_vcpu *vcpu)return ret; } +static unsigned long kvm_sdei_hypercall_mask (struct kvm_vcpu *vcpu, +bool mask) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_route(struct kvm_vcpu *vcpu) · line 572
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +spin_lock (&vsdei->lock); + +/* Check the state */ +if (mask == vsdei->state.masked) { + ret =SDEI_DENIED ;are you sure? I don't this error documented in 5.1.12?
Quoted 4 lines
Besides the spec says:
"
This call can be invoked by the client to mask the PE, whether or not the PE is already masked."
Yep, I think this check can safely dropped.
Quoted 13 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_route(struct kvm_vcpu *vcpu) · line 582
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ goto unlock; + } + +/* Update the state */ + vsdei->state.masked = mask ?1 :0 ; + +unlock: +spin_unlock (&vsdei->lock); +out: +return ret;In case of success the returned value is SUCESS for UNMASK but not for MASK (see table in 5.1.12).
Quoted 8 lines
By the way I have just noticed there is a more recent of the spec than the A:
ARM_DEN0054CYou should update the cover letter and [PATCH v4 02/21] KVM: arm64: Add SDEI virtualization infrastructure commit msg
Thanks, Eric. You've looked into newer version of spec. I will update the code and link to the spec accordingly :)
Quoted 11 lines
Quoted 11 lines
arch/arm64/kvm/sdei.c +3
-0+} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -588,7 +619,11 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_route (vcpu);break ;case SDEI_1_0_FN_SDEI_PE_MASK : + ret =kvm_sdei_hypercall_mask (vcpu, true);
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 629
Quoted 8 lines
arch/arm64/kvm/sdei.c +3
-0+break ;case SDEI_1_0_FN_SDEI_PE_UNMASK : + ret =kvm_sdei_hypercall_mask (vcpu, false); +break ;case SDEI_1_0_FN_SDEI_INTERRUPT_BIND :case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE :case SDEI_1_0_FN_SDEI_PRIVATE_RESET :
Thanks,
Gavin
PATCH v4 12/21 KVM: arm64: Support SDEI_{PRIVATE, SHARED}_RESET hypercall
In reply to Gavin ShanThis supports SDEI_{PRIVATE, SHARED}_RESET. They are used by the guest to purge the private or shared SDEI events, which are registered previously.
--- arch/arm64/kvm/sdei.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
arch/arm64/kvm/sdei.c +29 -0
@@ -582,6 +582,29 @@ static unsigned long kvm_sdei_hypercall_mask(struct kvm_vcpu *vcpu,return ret; } +static unsigned long kvm_sdei_hypercall_reset (struct kvm_vcpu *vcpu, +bool private) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +unsigned int mask = private ? (1 <<SDEI_EVENT_TYPE_PRIVATE ) : + (1 <<SDEI_EVENT_TYPE_SHARED ); +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +spin_lock (&ksdei->lock); +kvm_sdei_remove_kvm_events (kvm, mask, false); +spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);
@@ -626,8 +649,14 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)break ;case SDEI_1_0_FN_SDEI_INTERRUPT_BIND :case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE : + ret =SDEI_NOT_SUPPORTED ; +break ;case SDEI_1_0_FN_SDEI_PRIVATE_RESET : + ret =kvm_sdei_hypercall_reset (vcpu, true); +break ;case SDEI_1_0_FN_SDEI_SHARED_RESET : + ret =kvm_sdei_hypercall_reset (vcpu, false); +break ;default : ret =SDEI_NOT_SUPPORTED ; }
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 12/21] KVM: arm64: Support SDEI_{PRIVATE, SHARED}_RESET hypercall
Quoted 2 lines · Gavin Shan
This supports SDEI_{PRIVATE, SHARED}_RESET. They are used by the guest to purge the private or shared SDEI events, which are registered
to reset all private SDEI event registrations of the calling PE (resp. PRIVATE or SHARED)
Quoted 23 lines
previously.
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)arch/arm64/kvm/sdei.c +8
-0@@ -582,6 +582,29 @@ static unsigned long kvm_sdei_hypercall_mask(struct kvm_vcpu *vcpu,return ret; } +static unsigned long kvm_sdei_hypercall_reset (struct kvm_vcpu *vcpu, +bool private) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +unsigned int mask = private ? (1 <<SDEI_EVENT_TYPE_PRIVATE ) : + (1 <<SDEI_EVENT_TYPE_SHARED );
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_mask(struct kvm_vcpu *vcpu, · line 602
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +spin_lock (&ksdei->lock); +kvm_sdei_remove_kvm_events (kvm, mask, false);
With kvm_sdei_remove_kvm_events() implementation, why do you make sure that events which have a running handler get unregistered once the handler completes? I just see the refcount check that prevents the "KVM event object" from being removed.
Quoted 14 lines
arch/arm64/kvm/sdei.c +6
-0+spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -626,8 +649,14 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)break ;case SDEI_1_0_FN_SDEI_INTERRUPT_BIND :case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE : + ret =SDEI_NOT_SUPPORTED ;
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 662
Quoted 10 lines
arch/arm64/kvm/sdei.c +5
-0+break ;case SDEI_1_0_FN_SDEI_PRIVATE_RESET : + ret =kvm_sdei_hypercall_reset (vcpu, true); +break ;case SDEI_1_0_FN_SDEI_SHARED_RESET : + ret =kvm_sdei_hypercall_reset (vcpu, false); +break ;default : ret =SDEI_NOT_SUPPORTED ; }
Eric
Re: [PATCH v4 12/21] KVM: arm64: Support SDEI_{PRIVATE, SHARED}_RESET hypercall
Hi Eric,
Quoted 5 lines · Eric Auger
Quoted 2 lines · Gavin Shan
This supports SDEI_{PRIVATE, SHARED}_RESET. They are used by the guest to purge the private or shared SDEI events, which are registered
to reset all private SDEI event registrations of the calling PE (resp. PRIVATE or SHARED)
Ok.
Quoted 29 lines
Quoted 29 lines
previously.
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/sdei.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)arch/arm64/kvm/sdei.c +14
-0@@ -582,6 +582,29 @@ static unsigned long kvm_sdei_hypercall_mask(struct kvm_vcpu *vcpu,return ret; } +static unsigned long kvm_sdei_hypercall_reset (struct kvm_vcpu *vcpu, +bool private) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +unsigned int mask = private ? (1 <<SDEI_EVENT_TYPE_PRIVATE ) : + (1 <<SDEI_EVENT_TYPE_SHARED ); +unsigned long ret =SDEI_SUCCESS ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out;
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_mask(struct kvm_vcpu *vcpu, · line 602
Quoted 4 lines
arch/arm64/kvm/sdei.c +4
-0+ } + +spin_lock (&ksdei->lock); +kvm_sdei_remove_kvm_events (kvm, mask, false);With
kvm_sdei_remove_kvm_events()implementation, why do you make sure that events which have a running handler get unregistered once the handler completes? I just see the refcount check that prevents the "KVM event object" from being removed.
Good point. I think here we need enhancement to cancel the pending events prior to destroying them. I will think about it :)
Quoted 16 lines
Quoted 16 lines
arch/arm64/kvm/sdei.c +8
-0+spin_unlock (&ksdei->lock); +out: +return ret; +} +int kvm_sdei_hypercall (struct kvm_vcpu *vcpu) {u32 func =smccc_get_function (vcpu);@@ -626,8 +649,14 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)break ;case SDEI_1_0_FN_SDEI_INTERRUPT_BIND :case SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE : + ret =SDEI_NOT_SUPPORTED ; +break ;case SDEI_1_0_FN_SDEI_PRIVATE_RESET : + ret =kvm_sdei_hypercall_reset (vcpu, true);
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 662
Quoted 8 lines
arch/arm64/kvm/sdei.c +3
-0+break ;case SDEI_1_0_FN_SDEI_SHARED_RESET : + ret =kvm_sdei_hypercall_reset (vcpu, false); +break ;default : ret =SDEI_NOT_SUPPORTED ; }
Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 13/21 KVM: arm64: Impment SDEI event delivery
In reply to Gavin ShanThis implement kvm_sdei_deliver() to support SDEI event delivery. The function is called when the request (KVM_REQ_SDEI) is raised. The following rules are taken according to the SDEI specification:
* x0 - x17 are saved. All of them are cleared except the following registered:
x0: number SDEI event to be delivered
x1: parameter associated with the SDEI event
x2: PC of the interrupted context
x3: PState of the interrupted context
* PC is set to the handler of the SDEI event, which was provided during its registration. PState is modified accordingly.
* SDEI event with critical priority can preempt those with normal priority.
--- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/include/asm/kvm_sdei.h | 1 + arch/arm64/kvm/arm.c | 3 ++ arch/arm64/kvm/sdei.c | 84 +++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+)
arch/arm64/include/asm/kvm_host.h +1 -0
@@ -47,6 +47,7 @@#define KVM_REQ_RECORD_STEAL KVM_ARCH_REQ(3)#define KVM_REQ_RELOAD_GICv4 KVM_ARCH_REQ(4)#define KVM_REQ_RELOAD_PMU KVM_ARCH_REQ(5) +#define KVM_REQ_SDEI KVM_ARCH_REQ(6)#define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \ KVM_DIRTY_LOG_INITIALLY_SET)
arch/arm64/include/asm/kvm_sdei.h +1 -0
@@ -112,6 +112,7 @@ KVM_SDEI_FLAG_FUNC(enabled)void kvm_sdei_init_vm (struct kvm *kvm);void kvm_sdei_create_vcpu (struct kvm_vcpu *vcpu);int kvm_sdei_hypercall (struct kvm_vcpu *vcpu); +void kvm_sdei_deliver (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vm (struct kvm *kvm);
arch/arm64/kvm/arm.c +3 -0
@@ -689,6 +689,9 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu)if (kvm_check_request (KVM_REQ_VCPU_RESET , vcpu))kvm_reset_vcpu (vcpu); +if (kvm_check_request (KVM_REQ_SDEI , vcpu)) +kvm_sdei_deliver (vcpu); +/* * Clear IRQ_PENDING requests that were made to guarantee * that a VCPU sees new virtual interrupts.
arch/arm64/kvm/sdei.c +84 -0
90 lines not on this page · raw message
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 13/21] KVM: arm64: Impment SDEI event delivery
s/Impment/Implement in the commit title
Quoted 6 lines · Gavin Shan
This implement
kvm_sdei_deliver()to support SDEI event delivery. The function is called when the request (KVM_REQ_SDEI) is raised. The following rules are taken according to the SDEI specification:* x0 - x17 are saved. All of them are cleared except the following registered:
s/registered/registers
Quoted 1 line
x0: number SDEI event to be delivered
s/number SDEI event/SDEI event number
Quoted 1 line
x1: parameter associated with the SDEI event
user arg?
Quoted 70 lines
x2: PC of the interrupted context
x3: PState of the interrupted context* PC is set to the handler of the SDEI event, which was provided during its registration. PState is modified accordingly.
* SDEI event with critical priority can preempt those with normal priority.
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/include/asm/kvm_sdei.h | 1 + arch/arm64/kvm/arm.c | 3 ++ arch/arm64/kvm/sdei.c | 84 +++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+)arch/arm64/include/asm/kvm_host.h +1
-0@@ -47,6 +47,7 @@#define KVM_REQ_RECORD_STEAL KVM_ARCH_REQ(3)#define KVM_REQ_RELOAD_GICv4 KVM_ARCH_REQ(4)#define KVM_REQ_RELOAD_PMU KVM_ARCH_REQ(5) +#define KVM_REQ_SDEI KVM_ARCH_REQ(6)#define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \ KVM_DIRTY_LOG_INITIALLY_SET)arch/arm64/include/asm/kvm_sdei.h +1
-0@@ -112,6 +112,7 @@ KVM_SDEI_FLAG_FUNC(enabled)void kvm_sdei_init_vm (struct kvm *kvm);void kvm_sdei_create_vcpu (struct kvm_vcpu *vcpu);int kvm_sdei_hypercall (struct kvm_vcpu *vcpu); +void kvm_sdei_deliver (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vm (struct kvm *kvm);arch/arm64/kvm/arm.c +3
-0@@ -689,6 +689,9 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu)if (kvm_check_request (KVM_REQ_VCPU_RESET , vcpu))kvm_reset_vcpu (vcpu); +if (kvm_check_request (KVM_REQ_SDEI , vcpu)) +kvm_sdei_deliver (vcpu); +/* * Clear IRQ_PENDING requests that were made to guarantee * that a VCPU sees new virtual interrupts. arch/arm64/kvm/sdei.c +7
-0@@ -671,6 +671,90 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)return 1 ; } +void kvm_sdei_deliver (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ;
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 690
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+struct kvm_sdei_vcpu_event *ksve =NULL ; +struct kvm_sdei_vcpu_regs *regs =NULL ; +unsigned long pstate; +int index =0 ; + +/* Sanity check */ +if (!(ksdei && vsdei)) +return ; + +/* The critical event can't be preempted */
move the comment after the spin_lock
Quoted 5 lines
arch/arm64/kvm/sdei.c +5
-0+spin_lock (&vsdei->lock); +if (vsdei->critical_event) + goto unlock; + +/*
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 705
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+* The normal event can be preempted by the critical event. +* However, the normal event can't be preempted by another +* normal event. +*/ + ksve =list_first_entry_or_null (&vsdei->critical_events, + struct kvm_sdei_vcpu_event, link); +if (!ksve && !vsdei->normal_event) { + ksve =list_first_entry_or_null (&vsdei->normal_events, + struct kvm_sdei_vcpu_event, link); + }
At this stage of the review the struct kvm_sdei_vcpu_event lifecycle is not known.
From the dispatcher pseudocode I understand you check
((IsCriticalEvent(E) and !CriticalEventRunning(P, C)) || (!IsCriticalEvent(E) and !EventRunning(P, C)))
but I can't check you take care of
IsEnabled(E) andIsEventTarget(E, P)
IsUnmasked(P)
Either you should shash with 18/21 or at least you should add comments.
Quoted 46 lines
arch/arm64/kvm/sdei.c +45
-0+ +if (!ksve) + goto unlock; + + kske = ksve->kske; + kse = kske->kse; +if (kse->state.priority ==SDEI_EVENT_PRIORITY_CRITICAL ) { + vsdei->critical_event = ksve; + vsdei->state.critical_num = ksve->state.num; + regs = &vsdei->state.critical_regs; + }else { + vsdei->normal_event = ksve; + vsdei->state.normal_num = ksve->state.num; + regs = &vsdei->state.normal_regs; + } + +/* Save registers: x0 -> x17, PC, PState */ +for (index =0 ; index <ARRAY_SIZE (regs->regs); index++) + regs->regs[index] =vcpu_get_reg (vcpu, index); + + regs->pc = *vcpu_pc (vcpu); + regs->pstate = *vcpu_cpsr (vcpu); + +/* +* Inject SDEI event: x0 -> x3, PC, PState. We needn't take lock +* for the KVM event as it can't be destroyed because of its +* reference count. +*/ +for (index =0 ; index <ARRAY_SIZE (regs->regs); index++) +vcpu_set_reg (vcpu, index,0 ); + + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; +vcpu_set_reg (vcpu,0 , kske->state.num); +vcpu_set_reg (vcpu,1 , kske->state.params[index]); +vcpu_set_reg (vcpu,2 , regs->pc); +vcpu_set_reg (vcpu,3 , regs->pstate); + + pstate = regs->pstate; + pstate |= (PSR_D_BIT |PSR_A_BIT |PSR_I_BIT |PSR_F_BIT ); + pstate &= ~PSR_MODE_MASK ; + pstate |= PSR_MODE_EL1h; + pstate &= ~PSR_MODE32_BIT ; + +vcpu_write_sys_reg (vcpu, regs->pstate,SPSR_EL1 );
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 760
Quoted 10 lines
arch/arm64/kvm/sdei.c +7
-0+ *vcpu_cpsr (vcpu) = pstate; + *vcpu_pc (vcpu) = kske->state.entries[index]; + +unlock: +spin_unlock (&vsdei->lock); +} +void kvm_sdei_init_vm (struct kvm *kvm) {struct kvm_sdei_kvm *ksdei;
Eric
Re: [PATCH v4 13/21] KVM: arm64: Impment SDEI event delivery
Hi Eric,
Quoted 7 lines · Eric Auger
s/Impment/Implement in the commit title
Quoted 4 lines · Gavin Shan
This implement
kvm_sdei_deliver()to support SDEI event delivery. The function is called when the request (KVM_REQ_SDEI) is raised. The following rules are taken according to the SDEI specification:
Quoted 7 lines
Quoted 2 lines
* x0 - x17 are saved. All of them are cleared except the following registered:
s/registered/registers
Quoted 1 line
x0: number SDEI event to be delivered
s/number SDEI event/SDEI event number
Quoted 1 line
x1: parameter associated with the SDEI event
user arg?
The commit log will be improved in next respin.
Quoted 73 lines
Quoted 73 lines
x2: PC of the interrupted context
x3: PState of the interrupted context* PC is set to the handler of the SDEI event, which was provided during its registration. PState is modified accordingly.
* SDEI event with critical priority can preempt those with normal priority.
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/include/asm/kvm_sdei.h | 1 + arch/arm64/kvm/arm.c | 3 ++ arch/arm64/kvm/sdei.c | 84 +++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+)arch/arm64/include/asm/kvm_host.h +1
-0@@ -47,6 +47,7 @@#define KVM_REQ_RECORD_STEAL KVM_ARCH_REQ(3)#define KVM_REQ_RELOAD_GICv4 KVM_ARCH_REQ(4)#define KVM_REQ_RELOAD_PMU KVM_ARCH_REQ(5) +#define KVM_REQ_SDEI KVM_ARCH_REQ(6)#define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \ KVM_DIRTY_LOG_INITIALLY_SET)arch/arm64/include/asm/kvm_sdei.h +1
-0@@ -112,6 +112,7 @@ KVM_SDEI_FLAG_FUNC(enabled)void kvm_sdei_init_vm (struct kvm *kvm);void kvm_sdei_create_vcpu (struct kvm_vcpu *vcpu);int kvm_sdei_hypercall (struct kvm_vcpu *vcpu); +void kvm_sdei_deliver (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vm (struct kvm *kvm);arch/arm64/kvm/arm.c +3
-0@@ -689,6 +689,9 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu)if (kvm_check_request (KVM_REQ_VCPU_RESET , vcpu))kvm_reset_vcpu (vcpu); +if (kvm_check_request (KVM_REQ_SDEI , vcpu)) +kvm_sdei_deliver (vcpu); +/* * Clear IRQ_PENDING requests that were made to guarantee * that a VCPU sees new virtual interrupts. arch/arm64/kvm/sdei.c +10
-0@@ -671,6 +671,90 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)return 1 ; } +void kvm_sdei_deliver (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +struct kvm_sdei_vcpu_event *ksve =NULL ; +struct kvm_sdei_vcpu_regs *regs =NULL ; +unsigned long pstate;
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 690
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+int index =0 ; + +/* Sanity check */ +if (!(ksdei && vsdei)) +return ; + +/* The critical event can't be preempted */ move the comment after the
spin_lock
Ok.
Quoted 9 lines
Quoted 9 lines
arch/arm64/kvm/sdei.c +9
-0+spin_lock (&vsdei->lock); +if (vsdei->critical_event) + goto unlock; + +/* +* The normal event can be preempted by the critical event. +* However, the normal event can't be preempted by another +* normal event. +*/
Quoted 9 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 705
Quoted 6 lines
arch/arm64/kvm/sdei.c +6
-0+ ksve =list_first_entry_or_null (&vsdei->critical_events, + struct kvm_sdei_vcpu_event, link); +if (!ksve && !vsdei->normal_event) { + ksve =list_first_entry_or_null (&vsdei->normal_events, + struct kvm_sdei_vcpu_event, link); + }At this stage of the review the struct
kvm_sdei_vcpu_eventlifecycle is not known.
The object (kvm_sdei_vcpu_event) is queued to the target vCPU for dispatch. The multiple and same SDEI events can be queued to one target vCPU. In this case, the objecct is reused.
Quoted 11 lines
Quoted 1 line
From the dispatcher pseudocode I understand you check
((IsCriticalEvent(E) and !CriticalEventRunning(P, C)) || (!IsCriticalEvent(E) and !EventRunning(P, C)))
but I can't check you take care of
IsEnabled(E) andIsEventTarget(E, P)
IsUnmasked(P)Either you should shash with 18/21 or at least you should add comments.
The additional conditions are checked when the event is injected in PATCH[v4 18/21]. I think it's good idead to squash them.
Quoted 48 lines
Quoted 48 lines
arch/arm64/kvm/sdei.c +48
-0+ +if (!ksve) + goto unlock; + + kske = ksve->kske; + kse = kske->kse; +if (kse->state.priority ==SDEI_EVENT_PRIORITY_CRITICAL ) { + vsdei->critical_event = ksve; + vsdei->state.critical_num = ksve->state.num; + regs = &vsdei->state.critical_regs; + }else { + vsdei->normal_event = ksve; + vsdei->state.normal_num = ksve->state.num; + regs = &vsdei->state.normal_regs; + } + +/* Save registers: x0 -> x17, PC, PState */ +for (index =0 ; index <ARRAY_SIZE (regs->regs); index++) + regs->regs[index] =vcpu_get_reg (vcpu, index); + + regs->pc = *vcpu_pc (vcpu); + regs->pstate = *vcpu_cpsr (vcpu); + +/* +* Inject SDEI event: x0 -> x3, PC, PState. We needn't take lock +* for the KVM event as it can't be destroyed because of its +* reference count. +*/ +for (index =0 ; index <ARRAY_SIZE (regs->regs); index++) +vcpu_set_reg (vcpu, index,0 ); + + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; +vcpu_set_reg (vcpu,0 , kske->state.num); +vcpu_set_reg (vcpu,1 , kske->state.params[index]); +vcpu_set_reg (vcpu,2 , regs->pc); +vcpu_set_reg (vcpu,3 , regs->pstate); + + pstate = regs->pstate; + pstate |= (PSR_D_BIT |PSR_A_BIT |PSR_I_BIT |PSR_F_BIT ); + pstate &= ~PSR_MODE_MASK ; + pstate |= PSR_MODE_EL1h; + pstate &= ~PSR_MODE32_BIT ; + +vcpu_write_sys_reg (vcpu, regs->pstate,SPSR_EL1 ); + *vcpu_cpsr (vcpu) = pstate; + *vcpu_pc (vcpu) = kske->state.entries[index]; +
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 760
Quoted 8 lines
arch/arm64/kvm/sdei.c +4
-0+unlock: +spin_unlock (&vsdei->lock); +} +void kvm_sdei_init_vm (struct kvm *kvm) {struct kvm_sdei_kvm *ksdei;
Thanks,
Gavin
PATCH v4 14/21 KVM: arm64: Support SDEI_EVENT_{COMPLETE, COMPLETE_AND_RESUME} hypercall
In reply to Gavin ShanThis supports SDEI_EVENT_{COMPLETE, COMPLETE_AND_RESUME} hypercall. They are used by the guest to notify the completion of the SDEI event in the handler. The registers are changed according to the SDEI specification as below:
* x0 - x17, PC and PState are restored to what values we had in the interrupted context.
* If it's SDEI_EVENT_COMPLETE_AND_RESUME hypercall, IRQ exception is injected.
--- arch/arm64/include/asm/kvm_emulate.h | 1 + arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/hyp/exception.c | 7 +++ arch/arm64/kvm/inject_fault.c | 27 ++++++++++ arch/arm64/kvm/sdei.c | 75 ++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+)
arch/arm64/include/asm/kvm_emulate.h +1 -0
@@ -37,6 +37,7 @@ bool kvm_condition_valid32(const struct kvm_vcpu *vcpu);void kvm_skip_instr32 (struct kvm_vcpu *vcpu);void kvm_inject_undefined (struct kvm_vcpu *vcpu); +void kvm_inject_irq (struct kvm_vcpu *vcpu);void kvm_inject_vabt (struct kvm_vcpu *vcpu);void kvm_inject_dabt (struct kvm_vcpu *vcpu,unsigned long addr);void kvm_inject_pabt (struct kvm_vcpu *vcpu,unsigned long addr);
arch/arm64/include/asm/kvm_host.h +1 -0
@@ -437,6 +437,7 @@ struct kvm_vcpu_arch {#define KVM_ARM64_EXCEPT_AA32_UND (0 << 9)#define KVM_ARM64_EXCEPT_AA32_IABT (1 << 9)#define KVM_ARM64_EXCEPT_AA32_DABT (2 << 9) +#define KVM_ARM64_EXCEPT_AA32_IRQ (3 << 9)/* For AArch64: */ #define KVM_ARM64_EXCEPT_AA64_ELx_SYNC (0 << 9)#define KVM_ARM64_EXCEPT_AA64_ELx_IRQ (1 << 9)
arch/arm64/kvm/hyp/exception.c +7 -0
@@ -310,6 +310,9 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu)case KVM_ARM64_EXCEPT_AA32_DABT :enter_exception32 (vcpu,PSR_AA32_MODE_ABT ,16 );break ; +case KVM_ARM64_EXCEPT_AA32_IRQ : +enter_exception32 (vcpu,PSR_AA32_MODE_IRQ ,4 ); +break ;default :/* Err... */ break ;
@@ -320,6 +323,10 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu) KVM_ARM64_EXCEPT_AA64_EL1):enter_exception64 (vcpu, PSR_MODE_EL1h, except_type_sync);break ; +case (KVM_ARM64_EXCEPT_AA64_ELx_IRQ | +KVM_ARM64_EXCEPT_AA64_EL1 ): +enter_exception64 (vcpu, PSR_MODE_EL1h, except_type_irq); +break ;default :/* * Only EL1_SYNC makes sense so far, EL2_{SYNC,IRQ}
arch/arm64/kvm/inject_fault.c +27 -0
@@ -66,6 +66,13 @@ static void inject_undef64(struct kvm_vcpu *vcpu)vcpu_write_sys_reg (vcpu, esr,ESR_EL1 ); } +static void inject_irq64 (struct kvm_vcpu *vcpu) +{ + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1 | + KVM_ARM64_EXCEPT_AA64_ELx_IRQ | +KVM_ARM64_PENDING_EXCEPTION ); +} +#define DFSR_FSC_EXTABT_LPAE 0x10#define DFSR_FSC_EXTABT_nLPAE 0x08#define DFSR_LPAE BIT(9)
@@ -77,6 +84,12 @@ static void inject_undef32(struct kvm_vcpu *vcpu) KVM_ARM64_PENDING_EXCEPTION); } +static void inject_irq32 (struct kvm_vcpu *vcpu) +{ + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA32_IRQ | +KVM_ARM64_PENDING_EXCEPTION ); +} +/* * Modelled after TakeDataAbortException() and TakePrefetchAbortException * pseudocode.
@@ -160,6 +173,20 @@ void kvm_inject_undefined(struct kvm_vcpu *vcpu)inject_undef64 (vcpu); } +/** +* kvm_inject_irq - inject an IRQ into the guest +* +* It is assumed that this code is called from the VCPU thread and that the +* VCPU therefore is not currently executing guest code. +*/ +void kvm_inject_irq (struct kvm_vcpu *vcpu) +{ +if (vcpu_el1_is_32bit (vcpu)) +inject_irq32 (vcpu); +else +inject_irq64 (vcpu); +} +void kvm_set_sei_esr (struct kvm_vcpu *vcpu,u64 esr) {vcpu_set_vsesr (vcpu, esr & ESR_ELx_ISS_MASK);
arch/arm64/kvm/sdei.c +75 -0
88 lines not on this page · raw message
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 14/21] KVM: arm64: Support SDEI_EVENT_{COMPLETE, COMPLETE_AND_RESUME} hypercall
Hi Gavin,
Quoted 129 lines · Gavin Shan
This supports SDEI_EVENT_{COMPLETE,
COMPLETE_AND_RESUME} hypercall. They are used by the guest to notify the completion of the SDEI event in the handler. The registers are changed according to the SDEI specification as below:* x0 - x17, PC and PState are restored to what values we had in the interrupted context.
* If it's
SDEI_EVENT_COMPLETE_AND_RESUMEhypercall, IRQ exception is injected.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_emulate.h | 1 + arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/hyp/exception.c | 7 +++ arch/arm64/kvm/inject_fault.c | 27 ++++++++++ arch/arm64/kvm/sdei.c | 75 ++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+)arch/arm64/include/asm/kvm_emulate.h +1
-0@@ -37,6 +37,7 @@ bool kvm_condition_valid32(const struct kvm_vcpu *vcpu);void kvm_skip_instr32 (struct kvm_vcpu *vcpu);void kvm_inject_undefined (struct kvm_vcpu *vcpu); +void kvm_inject_irq (struct kvm_vcpu *vcpu);void kvm_inject_vabt (struct kvm_vcpu *vcpu);void kvm_inject_dabt (struct kvm_vcpu *vcpu,unsigned long addr);void kvm_inject_pabt (struct kvm_vcpu *vcpu,unsigned long addr);arch/arm64/include/asm/kvm_host.h +1
-0@@ -437,6 +437,7 @@ struct kvm_vcpu_arch {#define KVM_ARM64_EXCEPT_AA32_UND (0 << 9)#define KVM_ARM64_EXCEPT_AA32_IABT (1 << 9)#define KVM_ARM64_EXCEPT_AA32_DABT (2 << 9) +#define KVM_ARM64_EXCEPT_AA32_IRQ (3 << 9)/* For AArch64: */ #define KVM_ARM64_EXCEPT_AA64_ELx_SYNC (0 << 9)#define KVM_ARM64_EXCEPT_AA64_ELx_IRQ (1 << 9)arch/arm64/kvm/hyp/exception.c +7
-0@@ -310,6 +310,9 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu)case KVM_ARM64_EXCEPT_AA32_DABT :enter_exception32 (vcpu,PSR_AA32_MODE_ABT ,16 );break ; +case KVM_ARM64_EXCEPT_AA32_IRQ : +enter_exception32 (vcpu,PSR_AA32_MODE_IRQ ,4 ); +break ;default :/* Err... */ break ;@@ -320,6 +323,10 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu) KVM_ARM64_EXCEPT_AA64_EL1):enter_exception64 (vcpu, PSR_MODE_EL1h, except_type_sync);break ; +case (KVM_ARM64_EXCEPT_AA64_ELx_IRQ | +KVM_ARM64_EXCEPT_AA64_EL1 ): +enter_exception64 (vcpu, PSR_MODE_EL1h, except_type_irq); +break ;default :/* * Only EL1_SYNC makes sense so far, EL2_{SYNC,IRQ} arch/arm64/kvm/inject_fault.c +27
-0@@ -66,6 +66,13 @@ static void inject_undef64(struct kvm_vcpu *vcpu)vcpu_write_sys_reg (vcpu, esr,ESR_EL1 ); } +static void inject_irq64 (struct kvm_vcpu *vcpu) +{ + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1 | + KVM_ARM64_EXCEPT_AA64_ELx_IRQ | +KVM_ARM64_PENDING_EXCEPTION ); +} +#define DFSR_FSC_EXTABT_LPAE 0x10#define DFSR_FSC_EXTABT_nLPAE 0x08#define DFSR_LPAE BIT(9)@@ -77,6 +84,12 @@ static void inject_undef32(struct kvm_vcpu *vcpu) KVM_ARM64_PENDING_EXCEPTION); } +static void inject_irq32 (struct kvm_vcpu *vcpu) +{ + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA32_IRQ | +KVM_ARM64_PENDING_EXCEPTION ); +} +/* * Modelled after TakeDataAbortException() and TakePrefetchAbortException * pseudocode. @@ -160,6 +173,20 @@ void kvm_inject_undefined(struct kvm_vcpu *vcpu)inject_undef64 (vcpu); } +/** +* kvm_inject_irq - inject an IRQ into the guest +* +* It is assumed that this code is called from the VCPU thread and that the +* VCPU therefore is not currently executing guest code. +*/ +void kvm_inject_irq (struct kvm_vcpu *vcpu) +{ +if (vcpu_el1_is_32bit (vcpu)) +inject_irq32 (vcpu); +else +inject_irq64 (vcpu); +} +void kvm_set_sei_esr (struct kvm_vcpu *vcpu,u64 esr) {vcpu_set_vsesr (vcpu, esr & ESR_ELx_ISS_MASK);arch/arm64/kvm/sdei.c +0
-0@@ -308,6 +308,75 @@ static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu)return ret; }
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 320
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+static unsigned long kvm_sdei_hypercall_complete (struct kvm_vcpu *vcpu, +bool resume) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_kvm_event *kske =NULL ; +struct kvm_sdei_vcpu_event *ksve =NULL ; +struct kvm_sdei_vcpu_regs *regs; +unsigned long ret =SDEI_SUCCESS ;
for the RESUME you never seem to read resume_addr arg? How does it work? I don't get the irq injection path. Please could you explain?
Quoted 33 lines
arch/arm64/kvm/sdei.c +33
-0+int index; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +spin_lock (&vsdei->lock); +if (vsdei->critical_event) { + ksve = vsdei->critical_event; + regs = &vsdei->state.critical_regs; + vsdei->critical_event =NULL ; + vsdei->state.critical_num =KVM_SDEI_INVALID_NUM ; + }else if (vsdei->normal_event) { + ksve = vsdei->normal_event; + regs = &vsdei->state.normal_regs; + vsdei->normal_event =NULL ; + vsdei->state.normal_num =KVM_SDEI_INVALID_NUM ; + }else { + ret =SDEI_DENIED ; + goto unlock; + } + +/* Restore registers: x0 -> x17, PC, PState */ +for (index =0 ; index <ARRAY_SIZE (regs->regs); index++) +vcpu_set_reg (vcpu, index, regs->regs[index]); + + *vcpu_cpsr (vcpu) = regs->pstate; + *vcpu_pc (vcpu) = regs->pc; + +/* Inject interrupt if needed */ +if (resume)
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 363
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+kvm_inject_irq (vcpu); + +/* +* Update state. We needn't take lock in order to update the KVM +* event state as it's not destroyed because of the reference +* count. +*/ + kske = ksve->kske; + ksve->state.refcount--; + kske->state.refcount--;
why double --?
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 364
Quoted 1 line
arch/arm64/kvm/sdei.c +1
-0+if (!ksve->state.refcount) {
why not using a struct kref directly?
Quoted 23 lines
arch/arm64/kvm/sdei.c +15
-0+list_del (&ksve->link); +kfree (ksve); + } + +/* Make another request if there is pending event */ +if (!(list_empty (&vsdei->critical_events) && +list_empty (&vsdei->normal_events))) +kvm_make_request (KVM_REQ_SDEI , vcpu); + +unlock: +spin_unlock (&vsdei->lock); +out: +return ret; +} +static unsigned long kvm_sdei_hypercall_unregister (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;@@ -628,7 +697,13 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_context (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_COMPLETE :
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 709
Quoted 10 lines
arch/arm64/kvm/sdei.c +6
-0+ has_result = false; + ret =kvm_sdei_hypercall_complete (vcpu, false); +break ;case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME : + has_result = false; + ret =kvm_sdei_hypercall_complete (vcpu, true); +break ;case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER : ret =kvm_sdei_hypercall_unregister (vcpu);break ;
Eric
Re: [PATCH v4 14/21] KVM: arm64: Support SDEI_EVENT_{COMPLETE, COMPLETE_AND_RESUME} hypercall
Hi Eric,
Quoted 130 lines · Eric Auger
Quoted 129 lines · Gavin Shan
This supports SDEI_EVENT_{COMPLETE,
COMPLETE_AND_RESUME} hypercall. They are used by the guest to notify the completion of the SDEI event in the handler. The registers are changed according to the SDEI specification as below:* x0 - x17, PC and PState are restored to what values we had in the interrupted context.
* If it's
SDEI_EVENT_COMPLETE_AND_RESUMEhypercall, IRQ exception is injected.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_emulate.h | 1 + arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/hyp/exception.c | 7 +++ arch/arm64/kvm/inject_fault.c | 27 ++++++++++ arch/arm64/kvm/sdei.c | 75 ++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+)arch/arm64/include/asm/kvm_emulate.h +1
-0@@ -37,6 +37,7 @@ bool kvm_condition_valid32(const struct kvm_vcpu *vcpu);void kvm_skip_instr32 (struct kvm_vcpu *vcpu);void kvm_inject_undefined (struct kvm_vcpu *vcpu); +void kvm_inject_irq (struct kvm_vcpu *vcpu);void kvm_inject_vabt (struct kvm_vcpu *vcpu);void kvm_inject_dabt (struct kvm_vcpu *vcpu,unsigned long addr);void kvm_inject_pabt (struct kvm_vcpu *vcpu,unsigned long addr);arch/arm64/include/asm/kvm_host.h +1
-0@@ -437,6 +437,7 @@ struct kvm_vcpu_arch {#define KVM_ARM64_EXCEPT_AA32_UND (0 << 9)#define KVM_ARM64_EXCEPT_AA32_IABT (1 << 9)#define KVM_ARM64_EXCEPT_AA32_DABT (2 << 9) +#define KVM_ARM64_EXCEPT_AA32_IRQ (3 << 9)/* For AArch64: */ #define KVM_ARM64_EXCEPT_AA64_ELx_SYNC (0 << 9)#define KVM_ARM64_EXCEPT_AA64_ELx_IRQ (1 << 9)arch/arm64/kvm/hyp/exception.c +7
-0@@ -310,6 +310,9 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu)case KVM_ARM64_EXCEPT_AA32_DABT :enter_exception32 (vcpu,PSR_AA32_MODE_ABT ,16 );break ; +case KVM_ARM64_EXCEPT_AA32_IRQ : +enter_exception32 (vcpu,PSR_AA32_MODE_IRQ ,4 ); +break ;default :/* Err... */ break ;@@ -320,6 +323,10 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu) KVM_ARM64_EXCEPT_AA64_EL1):enter_exception64 (vcpu, PSR_MODE_EL1h, except_type_sync);break ; +case (KVM_ARM64_EXCEPT_AA64_ELx_IRQ | +KVM_ARM64_EXCEPT_AA64_EL1 ): +enter_exception64 (vcpu, PSR_MODE_EL1h, except_type_irq); +break ;default :/* * Only EL1_SYNC makes sense so far, EL2_{SYNC,IRQ} arch/arm64/kvm/inject_fault.c +27
-0@@ -66,6 +66,13 @@ static void inject_undef64(struct kvm_vcpu *vcpu)vcpu_write_sys_reg (vcpu, esr,ESR_EL1 ); } +static void inject_irq64 (struct kvm_vcpu *vcpu) +{ + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1 | + KVM_ARM64_EXCEPT_AA64_ELx_IRQ | +KVM_ARM64_PENDING_EXCEPTION ); +} +#define DFSR_FSC_EXTABT_LPAE 0x10#define DFSR_FSC_EXTABT_nLPAE 0x08#define DFSR_LPAE BIT(9)@@ -77,6 +84,12 @@ static void inject_undef32(struct kvm_vcpu *vcpu) KVM_ARM64_PENDING_EXCEPTION); } +static void inject_irq32 (struct kvm_vcpu *vcpu) +{ + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA32_IRQ | +KVM_ARM64_PENDING_EXCEPTION ); +} +/* * Modelled after TakeDataAbortException() and TakePrefetchAbortException * pseudocode. @@ -160,6 +173,20 @@ void kvm_inject_undefined(struct kvm_vcpu *vcpu)inject_undef64 (vcpu); } +/** +* kvm_inject_irq - inject an IRQ into the guest +* +* It is assumed that this code is called from the VCPU thread and that the +* VCPU therefore is not currently executing guest code. +*/ +void kvm_inject_irq (struct kvm_vcpu *vcpu) +{ +if (vcpu_el1_is_32bit (vcpu)) +inject_irq32 (vcpu); +else +inject_irq64 (vcpu); +} +void kvm_set_sei_esr (struct kvm_vcpu *vcpu,u64 esr) {vcpu_set_vsesr (vcpu, esr & ESR_ELx_ISS_MASK);arch/arm64/kvm/sdei.c +0
-0@@ -308,6 +308,75 @@ static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu)return ret; }
Quoted 12 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 320
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+static unsigned long kvm_sdei_hypercall_complete (struct kvm_vcpu *vcpu, +bool resume) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_kvm_event *kske =NULL ; +struct kvm_sdei_vcpu_event *ksve =NULL ; +struct kvm_sdei_vcpu_regs *regs; +unsigned long ret =SDEI_SUCCESS ;for the RESUME you never seem to read
resume_addrarg? How does it work? I don't get the irq injection path. Please could you explain?
The guest kernel uses COMPLETE and COMPLETE_AND_RESUME hypercalls to notify the SDEI event has been acknoledged by it. The difference between them is COMPLETE_AND_RESUME fires the pending interrupts, but COMPLETE doesn't.
Quoted 36 lines
Quoted 36 lines
arch/arm64/kvm/sdei.c +36
-0+int index; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret =SDEI_NOT_SUPPORTED ; + goto out; + } + +spin_lock (&vsdei->lock); +if (vsdei->critical_event) { + ksve = vsdei->critical_event; + regs = &vsdei->state.critical_regs; + vsdei->critical_event =NULL ; + vsdei->state.critical_num =KVM_SDEI_INVALID_NUM ; + }else if (vsdei->normal_event) { + ksve = vsdei->normal_event; + regs = &vsdei->state.normal_regs; + vsdei->normal_event =NULL ; + vsdei->state.normal_num =KVM_SDEI_INVALID_NUM ; + }else { + ret =SDEI_DENIED ; + goto unlock; + } + +/* Restore registers: x0 -> x17, PC, PState */ +for (index =0 ; index <ARRAY_SIZE (regs->regs); index++) +vcpu_set_reg (vcpu, index, regs->regs[index]); + + *vcpu_cpsr (vcpu) = regs->pstate; + *vcpu_pc (vcpu) = regs->pc; + +/* Inject interrupt if needed */ +if (resume) +kvm_inject_irq (vcpu); + +/*
Quoted 8 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 363
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+* Update state. We needn't take lock in order to update the KVM +* event state as it's not destroyed because of the reference +* count. +*/ + kske = ksve->kske; + ksve->state.refcount--; + kske->state.refcount--;why double --?
On each SDEI event is queued for delivery, both reference count are increased. I guess it's a bit confusing. I will change in next revision:
ksve->state.refcount: Increased on each SDEI event is queued for delivered kske->state.refcount: Increased on each @ksve is created
Quoted 2 lines
arch/arm64/kvm/sdei.c static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) · line 364
Quoted 1 line
arch/arm64/kvm/sdei.c +1
-0+if (!ksve->state.refcount) {why not using a struct kref directly?
The reason is kref isn't friendly to userspace. This field (@refcount) needs to be migrated :)
Quoted 25 lines
Quoted 25 lines
arch/arm64/kvm/sdei.c +18
-0+list_del (&ksve->link); +kfree (ksve); + } + +/* Make another request if there is pending event */ +if (!(list_empty (&vsdei->critical_events) && +list_empty (&vsdei->normal_events))) +kvm_make_request (KVM_REQ_SDEI , vcpu); + +unlock: +spin_unlock (&vsdei->lock); +out: +return ret; +} +static unsigned long kvm_sdei_hypercall_unregister (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;@@ -628,7 +697,13 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret =kvm_sdei_hypercall_context (vcpu);break ;case SDEI_1_0_FN_SDEI_EVENT_COMPLETE : + has_result = false; + ret =kvm_sdei_hypercall_complete (vcpu, false); +break ;
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) · line 709
Quoted 8 lines
arch/arm64/kvm/sdei.c +3
-0case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME : + has_result = false; + ret =kvm_sdei_hypercall_complete (vcpu, true); +break ;case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER : ret =kvm_sdei_hypercall_unregister (vcpu);break ;
Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 14/21] KVM: arm64: Support SDEI_EVENT_{COMPLETE, COMPLETE_AND_RESUME} hypercall
Hi Gavin,
Quoted 152 lines · Gavin Shan
Hi Eric,
Quoted 140 lines · Eric Auger
Quoted 139 lines · Gavin Shan
This supports SDEI_EVENT_{COMPLETE,
COMPLETE_AND_RESUME} hypercall. They are used by the guest to notify the completion of the SDEI event in the handler. The registers are changed according to the SDEI specification as below:* x0 - x17, PC and PState are restored to what values we had in the interrupted context.
* If it's
SDEI_EVENT_COMPLETE_AND_RESUMEhypercall, IRQ exception is injected.Signed-off-by Gavin Shan <[email protected]>---
arch/arm64/include/asm/kvm_emulate.h| 1 + arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/hyp/exception.c | 7 +++ arch/arm64/kvm/inject_fault.c | 27 ++++++++++ arch/arm64/kvm/sdei.c | 75 ++++++++++++++++++++++++++++5 files changed, 111 insertions(+)arch/arm64/include/asm/kvm_emulate.h +1
-0@@ -37,6 +37,7 @@ bool kvm_condition_valid32(const struct kvm_vcpu *vcpu); void kvm_skip_instr32(struct kvm_vcpu *vcpu); void kvm_inject_undefined(struct kvm_vcpu *vcpu); +void kvm_inject_irq (struct kvm_vcpu *vcpu); void kvm_inject_vabt(struct kvm_vcpu *vcpu); void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr); void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);arch/arm64/include/asm/kvm_host.h +1
-0@@ -437,6 +437,7 @@ struct kvm_vcpu_arch { #define KVM_ARM64_EXCEPT_AA32_UND (0 << 9) #define KVM_ARM64_EXCEPT_AA32_IABT (1 << 9) #define KVM_ARM64_EXCEPT_AA32_DABT (2 << 9) +#define KVM_ARM64_EXCEPT_AA32_IRQ (3 << 9) /* For AArch64: */ #define KVM_ARM64_EXCEPT_AA64_ELx_SYNC (0 << 9) #define KVM_ARM64_EXCEPT_AA64_ELx_IRQ (1 << 9)arch/arm64/kvm/hyp/exception.c +0
-0@@ -310,6 +310,9 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu)case
KVM_ARM64_EXCEPT_AA32_DABT:
enter_exception32(vcpu, PSR_AA32_MODE_ABT, 16); break;
+ caseKVM_ARM64_EXCEPT_AA32_IRQ:
+enter_exception32(vcpu, PSR_AA32_MODE_IRQ, 4); + break;
default:
/* Err... */
break;arch/arm64/kvm/hyp/exception.c +0
-0@@ -320,6 +323,10 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu)
KVM_ARM64_EXCEPT_AA64_EL1):
enter_exception64(vcpu, PSR_MODE_EL1h, except_type_sync); break;
+ case (KVM_ARM64_EXCEPT_AA64_ELx_IRQ|
+KVM_ARM64_EXCEPT_AA64_EL1):
+enter_exception64(vcpu, PSR_MODE_EL1h, except_type_irq); + break;
default:
/*
* OnlyEL1_SYNCmakes sense so far, EL2_{SYNC,IRQ}arch/arm64/kvm/inject_fault.c +11
-0@@ -66,6 +66,13 @@ static void inject_undef64(struct kvm_vcpu *vcpu) vcpu_write_sys_reg(vcpu, esr, ESR_EL1); } +static void inject_irq64(struct kvm_vcpu *vcpu) +{ + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1 | + KVM_ARM64_EXCEPT_AA64_ELx_IRQ | + KVM_ARM64_PENDING_EXCEPTION); +} + #define DFSR_FSC_EXTABT_LPAE 0x10 #define DFSR_FSC_EXTABT_nLPAE 0x08 #define DFSR_LPAE BIT(9)@@ -77,6 +84,12 @@ static void inject_undef32(struct kvm_vcpu *vcpu) KVM_ARM64_PENDING_EXCEPTION); } +static void inject_irq32(struct kvm_vcpu *vcpu) +{ + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA32_IRQ | + KVM_ARM64_PENDING_EXCEPTION); +} + /** Modelled after TakeDataAbortException() and TakePrefetchAbortException
* pseudocode.arch/arm64/kvm/inject_fault.c +0
-0@@ -160,6 +173,20 @@ void kvm_inject_undefined(struct kvm_vcpu *vcpu) inject_undef64(vcpu); }+/**
+ *kvm_inject_irq- inject an IRQ into the guest
+ *
+ * It is assumed that this code is called from the VCPU thread and that the
+ * VCPU therefore is not currently executing guest code.
+ */arch/arm64/kvm/inject_fault.c +8
-0+void kvm_inject_irq (struct kvm_vcpu *vcpu) +{ + if (vcpu_el1_is_32bit(vcpu)) + inject_irq32(vcpu); + else + inject_irq64(vcpu); +} +void
kvm_set_sei_esr(struct kvm_vcpu *vcpu, u64 esr){
vcpu_set_vsesr(vcpu, esr & ESR_ELx_ISS_MASK);arch/arm64/kvm/sdei.c +0
-0@@ -308,6 +308,75 @@ static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) return ret; }+static unsigned long kvm_sdei_hypercall_complete(struct
kvm_vcpu*vcpu,
+ bool resume)
+{
+ struct kvm *kvm =vcpu->kvm;Quoted 8 lines
Quoted 6 lines
+ struct
kvm_sdei_kvm*ksdei =kvm->arch.sdei; + structkvm_sdei_vcpu*vsdei =vcpu->arch.sdei; + structkvm_sdei_kvm_event*kske = NULL; + structkvm_sdei_vcpu_event*ksve = NULL; + structkvm_sdei_vcpu_regs*regs;
+ unsigned long ret =SDEI_SUCCESS;for the RESUME you never seem to read
resume_addrarg? How does it work? I don't get the irq injection path. Please could you explain?
Quoted 5 lines
The guest kernel uses COMPLETE and
COMPLETE_AND_RESUMEhypercalls to notify the
SDEI event has been acknoledged by it. The difference between them isCOMPLETE_AND_RESUME
fires the pending interrupts, but COMPLETE doesn't.
so resume_addr never is used, right?
Quoted 54 lines
Quoted 37 lines
Quoted 37 lines
+ int index;
arch/arm64/kvm/sdei.c +35
-0+ + /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + } + + spin_lock(&vsdei->lock); + if (vsdei->critical_event) { + ksve = vsdei->critical_event; + regs = &vsdei->state.critical_regs; + vsdei->critical_event = NULL; + vsdei->state.critical_num = KVM_SDEI_INVALID_NUM; + } else if (vsdei->normal_event) { + ksve = vsdei->normal_event; + regs = &vsdei->state.normal_regs; + vsdei->normal_event = NULL; + vsdei->state.normal_num = KVM_SDEI_INVALID_NUM; + } else { + ret = SDEI_DENIED; + goto unlock; + } + + /* Restore registers: x0 -> x17, PC, PState */ + for (index = 0; index < ARRAY_SIZE(regs->regs); index++) + vcpu_set_reg(vcpu, index, regs->regs[index]); + + *vcpu_cpsr(vcpu) = regs->pstate; + *vcpu_pc(vcpu) = regs->pc; + + /* Inject interrupt if needed */ + if (resume) + kvm_inject_irq(vcpu); + + /*Quoted 8 lines
Quoted 7 lines
+ * Update state. We needn't take lock in order to update the KVM + * event state as it's not destroyed because of the reference + * count.
+ */
+ kske =ksve->kske;
+ ksve->state.refcount--;
+ kske->state.refcount--;why double --?
On each SDEI event is queued for delivery, both reference count are increased. I guess
it's a bit confusing. I will change in next revision:
ksve->state.refcount: Increased on each SDEI event is queued for deliveredkske->state.refcount: Increased on each @ksve is created
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
+ if (!ksve->state.refcount) {
why not using a struct kref directly?
The reason is kref isn't friendly to userspace. This field (@refcount) needs to be
migrated :)
I will see with next version migration doc
Thanks
Eric
Quoted 39 lines
Quoted 27 lines
Quoted 27 lines
+
list_del(&ksve->link);
+ kfree(ksve);
+ }arch/arm64/kvm/sdei.c +12
-0+ + /* Make another request if there is pending event */ + if (!(list_empty(&vsdei->critical_events) && + list_empty(&vsdei->normal_events))) + kvm_make_request(KVM_REQ_SDEI, vcpu); + +unlock: + spin_unlock(&vsdei->lock); +out: + return ret; +} +static unsigned long
kvm_sdei_hypercall_unregister(struct kvm_vcpu *vcpu)
{
struct kvm *kvm =vcpu->kvm;arch/arm64/kvm/sdei.c +0
-0@@ -628,7 +697,13 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret = kvm_sdei_hypercall_context(vcpu); break;case
SDEI_1_0_FN_SDEI_EVENT_COMPLETE:
+has_result= false;
+ ret =kvm_sdei_hypercall_complete(vcpu, false); + break;Quoted 8 lines
Quoted 8 lines
case
SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME:
+has_result= false;
+ ret =kvm_sdei_hypercall_complete(vcpu, true); + break;
caseSDEI_1_0_FN_SDEI_EVENT_UNREGISTER:
ret =kvm_sdei_hypercall_unregister(vcpu); break;Thanks,
Gavin
Re: [PATCH v4 14/21] KVM: arm64: Support SDEI_EVENT_{COMPLETE, COMPLETE_AND_RESUME} hypercall
In reply to Gavin ShanHi Gavin,
Quoted 204 lines · Gavin Shan
Hi Eric,
Quoted 140 lines · Eric Auger
Quoted 139 lines · Gavin Shan
This supports SDEI_EVENT_{COMPLETE,
COMPLETE_AND_RESUME} hypercall. They are used by the guest to notify the completion of the SDEI event in the handler. The registers are changed according to the SDEI specification as below:* x0 - x17, PC and PState are restored to what values we had in the interrupted context.
* If it's
SDEI_EVENT_COMPLETE_AND_RESUMEhypercall, IRQ exception is injected.Signed-off-by Gavin Shan <[email protected]>---
arch/arm64/include/asm/kvm_emulate.h| 1 + arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/hyp/exception.c | 7 +++ arch/arm64/kvm/inject_fault.c | 27 ++++++++++ arch/arm64/kvm/sdei.c | 75 ++++++++++++++++++++++++++++5 files changed, 111 insertions(+)arch/arm64/include/asm/kvm_emulate.h +1
-0@@ -37,6 +37,7 @@ bool kvm_condition_valid32(const struct kvm_vcpu *vcpu); void kvm_skip_instr32(struct kvm_vcpu *vcpu); void kvm_inject_undefined(struct kvm_vcpu *vcpu); +void kvm_inject_irq (struct kvm_vcpu *vcpu); void kvm_inject_vabt(struct kvm_vcpu *vcpu); void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr); void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);arch/arm64/include/asm/kvm_host.h +1
-0@@ -437,6 +437,7 @@ struct kvm_vcpu_arch { #define KVM_ARM64_EXCEPT_AA32_UND (0 << 9) #define KVM_ARM64_EXCEPT_AA32_IABT (1 << 9) #define KVM_ARM64_EXCEPT_AA32_DABT (2 << 9) +#define KVM_ARM64_EXCEPT_AA32_IRQ (3 << 9) /* For AArch64: */ #define KVM_ARM64_EXCEPT_AA64_ELx_SYNC (0 << 9) #define KVM_ARM64_EXCEPT_AA64_ELx_IRQ (1 << 9)arch/arm64/kvm/hyp/exception.c +0
-0@@ -310,6 +310,9 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu)case
KVM_ARM64_EXCEPT_AA32_DABT:
enter_exception32(vcpu, PSR_AA32_MODE_ABT, 16); break;
+ caseKVM_ARM64_EXCEPT_AA32_IRQ:
+enter_exception32(vcpu, PSR_AA32_MODE_IRQ, 4); + break;
default:
/* Err... */
break;arch/arm64/kvm/hyp/exception.c +0
-0@@ -320,6 +323,10 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu)
KVM_ARM64_EXCEPT_AA64_EL1):
enter_exception64(vcpu, PSR_MODE_EL1h, except_type_sync); break;
+ case (KVM_ARM64_EXCEPT_AA64_ELx_IRQ|
+KVM_ARM64_EXCEPT_AA64_EL1):
+enter_exception64(vcpu, PSR_MODE_EL1h, except_type_irq); + break;
default:
/*
* OnlyEL1_SYNCmakes sense so far, EL2_{SYNC,IRQ}arch/arm64/kvm/inject_fault.c +11
-0@@ -66,6 +66,13 @@ static void inject_undef64(struct kvm_vcpu *vcpu) vcpu_write_sys_reg(vcpu, esr, ESR_EL1); } +static void inject_irq64(struct kvm_vcpu *vcpu) +{ + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1 | + KVM_ARM64_EXCEPT_AA64_ELx_IRQ | + KVM_ARM64_PENDING_EXCEPTION); +} + #define DFSR_FSC_EXTABT_LPAE 0x10 #define DFSR_FSC_EXTABT_nLPAE 0x08 #define DFSR_LPAE BIT(9)@@ -77,6 +84,12 @@ static void inject_undef32(struct kvm_vcpu *vcpu) KVM_ARM64_PENDING_EXCEPTION); } +static void inject_irq32(struct kvm_vcpu *vcpu) +{ + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA32_IRQ | + KVM_ARM64_PENDING_EXCEPTION); +} + /** Modelled after TakeDataAbortException() and TakePrefetchAbortException
* pseudocode.arch/arm64/kvm/inject_fault.c +0
-0@@ -160,6 +173,20 @@ void kvm_inject_undefined(struct kvm_vcpu *vcpu) inject_undef64(vcpu); }+/**
+ *kvm_inject_irq- inject an IRQ into the guest
+ *
+ * It is assumed that this code is called from the VCPU thread and that the
+ * VCPU therefore is not currently executing guest code.
+ */arch/arm64/kvm/inject_fault.c +8
-0+void kvm_inject_irq (struct kvm_vcpu *vcpu) +{ + if (vcpu_el1_is_32bit(vcpu)) + inject_irq32(vcpu); + else + inject_irq64(vcpu); +} +void
kvm_set_sei_esr(struct kvm_vcpu *vcpu, u64 esr){
vcpu_set_vsesr(vcpu, esr & ESR_ELx_ISS_MASK);arch/arm64/kvm/sdei.c +0
-0@@ -308,6 +308,75 @@ static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) return ret; }+static unsigned long kvm_sdei_hypercall_complete(struct
kvm_vcpu*vcpu,
+ bool resume)
+{
+ struct kvm *kvm =vcpu->kvm;Quoted 8 lines
Quoted 6 lines
+ struct
kvm_sdei_kvm*ksdei =kvm->arch.sdei; + structkvm_sdei_vcpu*vsdei =vcpu->arch.sdei; + structkvm_sdei_kvm_event*kske = NULL; + structkvm_sdei_vcpu_event*ksve = NULL; + structkvm_sdei_vcpu_regs*regs;
+ unsigned long ret =SDEI_SUCCESS;for the RESUME you never seem to read
resume_addrarg? How does it work? I don't get the irq injection path. Please could you explain?The guest kernel uses COMPLETE and
COMPLETE_AND_RESUMEhypercalls to notify the
SDEI event has been acknoledged by it. The difference between them isCOMPLETE_AND_RESUME
fires the pending interrupts, but COMPLETE doesn't.Quoted 36 lines
Quoted 36 lines
+ int index;
arch/arm64/kvm/sdei.c +35
-0+ + /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + } + + spin_lock(&vsdei->lock); + if (vsdei->critical_event) { + ksve = vsdei->critical_event; + regs = &vsdei->state.critical_regs; + vsdei->critical_event = NULL; + vsdei->state.critical_num = KVM_SDEI_INVALID_NUM; + } else if (vsdei->normal_event) { + ksve = vsdei->normal_event; + regs = &vsdei->state.normal_regs; + vsdei->normal_event = NULL; + vsdei->state.normal_num = KVM_SDEI_INVALID_NUM; + } else { + ret = SDEI_DENIED; + goto unlock; + } + + /* Restore registers: x0 -> x17, PC, PState */ + for (index = 0; index < ARRAY_SIZE(regs->regs); index++) + vcpu_set_reg(vcpu, index, regs->regs[index]); + + *vcpu_cpsr(vcpu) = regs->pstate; + *vcpu_pc(vcpu) = regs->pc; + + /* Inject interrupt if needed */ + if (resume) + kvm_inject_irq(vcpu); + + /*Quoted 8 lines
Quoted 7 lines
+ * Update state. We needn't take lock in order to update the KVM + * event state as it's not destroyed because of the reference + * count.
+ */
+ kske =ksve->kske;
+ ksve->state.refcount--;
+ kske->state.refcount--;why double --?
Quoted 6 lines
On each SDEI event is queued for delivery, both reference count are increased. I guess
it's a bit confusing. I will change in next revision:
ksve->state.refcount: Increased on each SDEI event is queued for deliveredkske->state.refcount: Increased on each @ksve is created
Well generally this kind of stuff is frown upon.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
+ if (!ksve->state.refcount) {
why not using a struct kref directly?
The reason is kref isn't friendly to userspace. This field (@refcount) needs to be
migrated :)
waiting for the mig documentation to further comment.
Thanks
Eric
Quoted 39 lines
Quoted 27 lines
Quoted 27 lines
+
list_del(&ksve->link);
+ kfree(ksve);
+ }arch/arm64/kvm/sdei.c +12
-0+ + /* Make another request if there is pending event */ + if (!(list_empty(&vsdei->critical_events) && + list_empty(&vsdei->normal_events))) + kvm_make_request(KVM_REQ_SDEI, vcpu); + +unlock: + spin_unlock(&vsdei->lock); +out: + return ret; +} +static unsigned long
kvm_sdei_hypercall_unregister(struct kvm_vcpu *vcpu)
{
struct kvm *kvm =vcpu->kvm;arch/arm64/kvm/sdei.c +0
-0@@ -628,7 +697,13 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret = kvm_sdei_hypercall_context(vcpu); break;case
SDEI_1_0_FN_SDEI_EVENT_COMPLETE:
+has_result= false;
+ ret =kvm_sdei_hypercall_complete(vcpu, false); + break;Quoted 8 lines
Quoted 8 lines
case
SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME:
+has_result= false;
+ ret =kvm_sdei_hypercall_complete(vcpu, true); + break;
caseSDEI_1_0_FN_SDEI_EVENT_UNREGISTER:
ret =kvm_sdei_hypercall_unregister(vcpu); break;Thanks,
Gavin
PATCH v4 15/21 KVM: arm64: Support SDEI event notifier
In reply to Gavin ShanThe owner of the SDEI event, like asynchronous page fault, need know the state of injected SDEI event. This supports SDEI event state updating by introducing notifier mechanism. It's notable the notifier (handler) should be capable of migration.
--- arch/arm64/include/asm/kvm_sdei.h | 12 +++++++ arch/arm64/include/uapi/asm/kvm_sdei.h | 1 + arch/arm64/kvm/sdei.c | 45 +++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-)
arch/arm64/include/asm/kvm_sdei.h +12 -0
@@ -16,6 +16,16 @@#include <linux/list.h> #include <linux/spinlock.h> +struct kvm_vcpu ; + +typedef void (*kvm_sdei_notifier )(struct kvm_vcpu *vcpu, +unsigned long num, +unsigned int state); +enum { +KVM_SDEI_NOTIFY_DELIVERED , +KVM_SDEI_NOTIFY_COMPLETED , +}; +struct kvm_sdei_event {struct kvm_sdei_event_state state;struct kvm *kvm;
@@ -112,6 +122,8 @@ KVM_SDEI_FLAG_FUNC(enabled)void kvm_sdei_init_vm (struct kvm *kvm);void kvm_sdei_create_vcpu (struct kvm_vcpu *vcpu);int kvm_sdei_hypercall (struct kvm_vcpu *vcpu); +int kvm_sdei_register_notifier (struct kvm *kvm,unsigned long num, +kvm_sdei_notifier notifier);void kvm_sdei_deliver (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vm (struct kvm *kvm);
arch/arm64/include/uapi/asm/kvm_sdei.h +1 -0
@@ -23,6 +23,7 @@ struct kvm_sdei_event_state {__u8 type;__u8 signaled;__u8 priority; +__u64 notifier; };struct kvm_sdei_kvm_event_state {
arch/arm64/kvm/sdei.c +44 -1
84 lines not on this page · raw message
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 15/21] KVM: arm64: Support SDEI event notifier
Hi Gavin,
Quoted 1 line · Gavin Shan
The owner of the SDEI event, like asynchronous page fault, need
owner is not a terminology used in the SDEI spec
Quoted 1 line
know the state of injected SDEI event. This supports SDEI event
s/need know the state of injected/to know the state of the injected
Quoted 1 line
state updating by introducing notifier mechanism. It's notable
a notifier mechanism
Quoted 1 line
the notifier (handler) should be capable of migration.
I don't understand the last sentence
Quoted 43 lines
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_sdei.h | 12 +++++++ arch/arm64/include/uapi/asm/kvm_sdei.h | 1 + arch/arm64/kvm/sdei.c | 45 +++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-)arch/arm64/include/asm/kvm_sdei.h +12
-0@@ -16,6 +16,16 @@#include <linux/list.h> #include <linux/spinlock.h> +struct kvm_vcpu ; + +typedef void (*kvm_sdei_notifier )(struct kvm_vcpu *vcpu, +unsigned long num, +unsigned int state); +enum { +KVM_SDEI_NOTIFY_DELIVERED , +KVM_SDEI_NOTIFY_COMPLETED , +}; +struct kvm_sdei_event {struct kvm_sdei_event_state state;struct kvm *kvm;@@ -112,6 +122,8 @@ KVM_SDEI_FLAG_FUNC(enabled)void kvm_sdei_init_vm (struct kvm *kvm);void kvm_sdei_create_vcpu (struct kvm_vcpu *vcpu);int kvm_sdei_hypercall (struct kvm_vcpu *vcpu); +int kvm_sdei_register_notifier (struct kvm *kvm,unsigned long num, +kvm_sdei_notifier notifier);void kvm_sdei_deliver (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vm (struct kvm *kvm);arch/arm64/include/uapi/asm/kvm_sdei.h +0
-0
arch/arm64/include/uapi/asm/kvm_sdei.h struct kvm_sdei_event_state { · line 26
Quoted 4 lines
arch/arm64/include/uapi/asm/kvm_sdei.h +1
-0@@ -23,6 +23,7 @@ struct kvm_sdei_event_state {__u8 type;__u8 signaled;__u8 priority; +__u64 notifier;
why is the notifier attached to the exposed event and not to the registered or even vcpu event? This needs to be motivated.
Also as commented earlier I really think we first need to agree on the uapi and get a consensus on it as it must be right on the 1st shot. In that prospect maybe introduce a patch dedicated to the uapi and document it properly, including the way the end user is supposed to use it.
Another way to proceed would be to not support migration at the moment, mature the API and then introduce migration support later. Would it make sense? For instance, in the past in-kernel ITS emulation was first introduced without migration support.
Thanks
Eric
Quoted 98 lines
arch/arm64/include/uapi/asm/kvm_sdei.h +0
-0};struct kvm_sdei_kvm_event_state {arch/arm64/kvm/sdei.c +44
-1@@ -314,9 +314,11 @@ static unsigned long kvm_sdei_hypercall_complete(struct kvm_vcpu *vcpu,struct kvm *kvm = vcpu->kvm;struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ;struct kvm_sdei_kvm_event *kske =NULL ;struct kvm_sdei_vcpu_event *ksve =NULL ;struct kvm_sdei_vcpu_regs *regs; +kvm_sdei_notifier notifier;unsigned long ret =SDEI_SUCCESS ;int index;@@ -349,6 +351,13 @@ static unsigned long kvm_sdei_hypercall_complete(struct kvm_vcpu *vcpu, *vcpu_cpsr (vcpu) = regs->pstate; *vcpu_pc (vcpu) = regs->pc; +/* Notifier */ + kske = ksve->kske; + kse = kske->kse; + notifier = (kvm_sdei_notifier)(kse->state.notifier); +if (notifier) +notifier (vcpu, kse->state.num,KVM_SDEI_NOTIFY_COMPLETED ); +/* Inject interrupt if needed */ if (resume)kvm_inject_irq (vcpu);@@ -358,7 +367,6 @@ static unsigned long kvm_sdei_hypercall_complete(struct kvm_vcpu *vcpu,* event state as it's not destroyed because of the reference * count. */ - kske = ksve->kske; ksve->state.refcount--; kske->state.refcount--;if (!ksve->state.refcount) {@@ -746,6 +754,35 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)return 1 ; } +int kvm_sdei_register_notifier (struct kvm *kvm, +unsigned long num, +kvm_sdei_notifier notifier) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +int ret =0 ; + +if (!ksdei) { + ret = -EPERM ; + goto out; + } + +spin_lock (&ksdei->lock); + + kse =kvm_sdei_find_event (kvm, num); +if (!kse) { + ret = -EINVAL ; + goto unlock; + } + + kse->state.notifier = (unsigned long )notifier; + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +void kvm_sdei_deliver (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;@@ -755,6 +792,7 @@ void kvm_sdei_deliver(struct kvm_vcpu *vcpu)struct kvm_sdei_kvm_event *kske =NULL ;struct kvm_sdei_vcpu_event *ksve =NULL ;struct kvm_sdei_vcpu_regs *regs =NULL ; +kvm_sdei_notifier notifier;unsigned long pstate;int index =0 ;@@ -826,6 +864,11 @@ void kvm_sdei_deliver(struct kvm_vcpu *vcpu) *vcpu_cpsr (vcpu) = pstate; *vcpu_pc (vcpu) = kske->state.entries[index]; +/* Notifier */ + notifier = (kvm_sdei_notifier)(kse->state.notifier); +if (notifier) +notifier (vcpu, kse->state.num,KVM_SDEI_NOTIFY_DELIVERED ); + unlock:spin_unlock (&vsdei->lock); }
Re: [PATCH v4 15/21] KVM: arm64: Support SDEI event notifier
Hi Eric,
Quoted 9 lines · Eric Auger
Quoted 1 line · Gavin Shan
The owner of the SDEI event, like asynchronous page fault, need
owner is not a terminology used in the SDEI spec
Quoted 1 line
know the state of injected SDEI event. This supports SDEI event
s/need know the state of injected/to know the state of the injected
Quoted 1 line
state updating by introducing notifier mechanism. It's notable
a notifier mechanism
Quoted 1 line
the notifier (handler) should be capable of migration.
I don't understand the last sentence
Thanks, Eric. The commit log will be improved accordingly in next revision.
Quoted 55 lines
Quoted 43 lines
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_sdei.h | 12 +++++++ arch/arm64/include/uapi/asm/kvm_sdei.h | 1 + arch/arm64/kvm/sdei.c | 45 +++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-)arch/arm64/include/asm/kvm_sdei.h +12
-0@@ -16,6 +16,16 @@#include <linux/list.h> #include <linux/spinlock.h> +struct kvm_vcpu ; + +typedef void (*kvm_sdei_notifier )(struct kvm_vcpu *vcpu, +unsigned long num, +unsigned int state); +enum { +KVM_SDEI_NOTIFY_DELIVERED , +KVM_SDEI_NOTIFY_COMPLETED , +}; +struct kvm_sdei_event {struct kvm_sdei_event_state state;struct kvm *kvm;@@ -112,6 +122,8 @@ KVM_SDEI_FLAG_FUNC(enabled)void kvm_sdei_init_vm (struct kvm *kvm);void kvm_sdei_create_vcpu (struct kvm_vcpu *vcpu);int kvm_sdei_hypercall (struct kvm_vcpu *vcpu); +int kvm_sdei_register_notifier (struct kvm *kvm,unsigned long num, +kvm_sdei_notifier notifier);void kvm_sdei_deliver (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vm (struct kvm *kvm);arch/arm64/include/uapi/asm/kvm_sdei.h +0
-0arch/arm64/include/uapi/asm/kvm_sdei.h struct kvm_sdei_event_state { · line 26
Quoted 4 lines
arch/arm64/include/uapi/asm/kvm_sdei.h +1
-0@@ -23,6 +23,7 @@ struct kvm_sdei_event_state {__u8 type;__u8 signaled;__u8 priority; +__u64 notifier;why is the notifier attached to the exposed event and not to the registered or even vcpu event? This needs to be motivated.
Also as commented earlier I really think we first need to agree on the uapi and get a consensus on it as it must be right on the 1st shot. In that prospect maybe introduce a patch dedicated to the uapi and document it properly, including the way the end user is supposed to use it.
Quoted 5 lines
Another way to proceed would be to not support migration at the moment, mature the API and then introduce migration support later. Would it make sense? For instance, in the past in-kernel ITS emulation was first introduced without migration support.
You're correct that @notifier needs to be migrated. I perfer to drop the migration support at first, and then add the support when the APIs become mature. However, the only user of SDEI would be Async PF, which is used in migration scenario. So I will think about how to reorgnize the code and have separate patch for the UAPI stuff, including the document.
Quoted 89 lines
Quoted 89 lines
arch/arm64/include/uapi/asm/kvm_sdei.h +0
-0};struct kvm_sdei_kvm_event_state {arch/arm64/kvm/sdei.c +39
-1@@ -314,9 +314,11 @@ static unsigned long kvm_sdei_hypercall_complete(struct kvm_vcpu *vcpu,struct kvm *kvm = vcpu->kvm;struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ;struct kvm_sdei_kvm_event *kske =NULL ;struct kvm_sdei_vcpu_event *ksve =NULL ;struct kvm_sdei_vcpu_regs *regs; +kvm_sdei_notifier notifier;unsigned long ret =SDEI_SUCCESS ;int index;@@ -349,6 +351,13 @@ static unsigned long kvm_sdei_hypercall_complete(struct kvm_vcpu *vcpu, *vcpu_cpsr (vcpu) = regs->pstate; *vcpu_pc (vcpu) = regs->pc; +/* Notifier */ + kske = ksve->kske; + kse = kske->kse; + notifier = (kvm_sdei_notifier)(kse->state.notifier); +if (notifier) +notifier (vcpu, kse->state.num,KVM_SDEI_NOTIFY_COMPLETED ); +/* Inject interrupt if needed */ if (resume)kvm_inject_irq (vcpu);@@ -358,7 +367,6 @@ static unsigned long kvm_sdei_hypercall_complete(struct kvm_vcpu *vcpu,* event state as it's not destroyed because of the reference * count. */ - kske = ksve->kske; ksve->state.refcount--; kske->state.refcount--;if (!ksve->state.refcount) {@@ -746,6 +754,35 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)return 1 ; } +int kvm_sdei_register_notifier (struct kvm *kvm, +unsigned long num, +kvm_sdei_notifier notifier) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +int ret =0 ; + +if (!ksdei) { + ret = -EPERM ; + goto out; + } + +spin_lock (&ksdei->lock); + + kse =kvm_sdei_find_event (kvm, num); +if (!kse) { + ret = -EINVAL ; + goto unlock; + } + + kse->state.notifier = (unsigned long )notifier; + +unlock: +spin_unlock (&ksdei->lock); +out: +return ret; +} +void kvm_sdei_deliver (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;@@ -755,6 +792,7 @@ void kvm_sdei_deliver(struct kvm_vcpu *vcpu)struct kvm_sdei_kvm_event *kske =NULL ;struct kvm_sdei_vcpu_event *ksve =NULL ;struct kvm_sdei_vcpu_regs *regs =NULL ; +kvm_sdei_notifier notifier;unsigned long pstate;int index =0 ;@@ -826,6 +864,11 @@ void kvm_sdei_deliver(struct kvm_vcpu *vcpu) *vcpu_cpsr (vcpu) = pstate; *vcpu_pc (vcpu) = kske->state.entries[index];
Quoted 10 lines
arch/arm64/kvm/sdei.c void kvm_sdei_deliver(struct kvm_vcpu *vcpu) · line 874
Quoted 9 lines
arch/arm64/kvm/sdei.c +5
-0+/* Notifier */ + notifier = (kvm_sdei_notifier)(kse->state.notifier); +if (notifier) +notifier (vcpu, kse->state.num,KVM_SDEI_NOTIFY_DELIVERED ); + unlock:spin_unlock (&vsdei->lock); }
Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 16/21 KVM: arm64: Support SDEI ioctl commands on VM
In reply to Gavin ShanThis supports ioctl commands on VM to manage the various objects. It's primarily used by VMM to accomplish live migration. The ioctl commands introduced by this are highlighted as blow:
* KVM_SDEI_CMD_GET_VERSION
Retrieve the version of current implementation
* KVM_SDEI_CMD_SET_EVENT
Add event to be exported from KVM so that guest can register against it afterwards
* KVM_SDEI_CMD_GET_KEVENT_COUNT
Retrieve number of registered SDEI events
* KVM_SDEI_CMD_GET_KEVENT
Retrieve the state of the registered SDEI event
* KVM_SDEI_CMD_SET_KEVENT
Populate the registered SDEI event
--- arch/arm64/include/asm/kvm_sdei.h | 1 + arch/arm64/include/uapi/asm/kvm_sdei.h | 17 +++ arch/arm64/kvm/arm.c | 3 + arch/arm64/kvm/sdei.c | 171 +++++++++++++++++++++++++ include/uapi/linux/kvm.h | 3 + 5 files changed, 195 insertions(+)
arch/arm64/include/asm/kvm_sdei.h +1 -0
@@ -125,6 +125,7 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu);int kvm_sdei_register_notifier (struct kvm *kvm,unsigned long num,kvm_sdei_notifier notifier);void kvm_sdei_deliver (struct kvm_vcpu *vcpu); +long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg);void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vm (struct kvm *kvm);
arch/arm64/include/uapi/asm/kvm_sdei.h +17 -0
@@ -57,5 +57,22 @@ struct kvm_sdei_vcpu_state {struct kvm_sdei_vcpu_regs normal_regs; }; +#define KVM_SDEI_CMD_GET_VERSION 0 +#define KVM_SDEI_CMD_SET_EVENT 1 +#define KVM_SDEI_CMD_GET_KEVENT_COUNT 2 +#define KVM_SDEI_CMD_GET_KEVENT 3 +#define KVM_SDEI_CMD_SET_KEVENT 4 + +struct kvm_sdei_cmd { +__u32 cmd; +union { +__u32 version; +__u32 count; +__u64 num; +struct kvm_sdei_event_state kse_state; +struct kvm_sdei_kvm_event_state kske_state; + }; +}; +#endif /* !__ASSEMBLY__ */ #endif /* _UAPI__ASM_KVM_SDEI_H */
arch/arm64/kvm/arm.c +3 -0
@@ -1389,6 +1389,9 @@ long kvm_arch_vm_ioctl(struct file *filp,return -EFAULT ;return kvm_vm_ioctl_mte_copy_tags (kvm, ©_tags); } +case KVM_ARM_SDEI_COMMAND : { +return kvm_sdei_vm_ioctl (kvm, arg); + }default :return -EINVAL ; }
arch/arm64/kvm/sdei.c +171 -0
177 lines not on this page · raw message
include/uapi/linux/kvm.h +3 -0
@@ -1679,6 +1679,9 @@ struct kvm_xen_vcpu_attr {#define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA 0x4#define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST 0x5 +/* Available with KVM_CAP_ARM_SDEI */ +#define KVM_ARM_SDEI_COMMAND _IOWR(KVMIO, 0xce, struct kvm_sdei_cmd) +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 16/21] KVM: arm64: Support SDEI ioctl commands on VM
Quoted 3 lines · Gavin Shan
This supports ioctl commands on VM to manage the various objects. It's primarily used by VMM to accomplish live migration. The ioctl commands introduced by this are highlighted as blow:
below
Quoted 3 lines
*
KVM_SDEI_CMD_GET_VERSION
Retrieve the version of current implementation
which implementation, SDEI?
Quoted 9 lines
*
KVM_SDEI_CMD_SET_EVENT
Add event to be exported from KVM so that guest can register against it afterwards
*KVM_SDEI_CMD_GET_KEVENT_COUNT
Retrieve number of registered SDEI events
*KVM_SDEI_CMD_GET_KEVENT
Retrieve the state of the registered SDEI event
*KVM_SDEI_CMD_SET_KEVENT
Populate the registered SDEI event
I think we really miss the full picture of what you want to achieve with those IOCTLs or at least I fail to get it. Please document the UAPI separately including the structs and IOCTLs.
Quoted 85 lines
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_sdei.h | 1 + arch/arm64/include/uapi/asm/kvm_sdei.h | 17 +++ arch/arm64/kvm/arm.c | 3 + arch/arm64/kvm/sdei.c | 171 +++++++++++++++++++++++++ include/uapi/linux/kvm.h | 3 + 5 files changed, 195 insertions(+)arch/arm64/include/asm/kvm_sdei.h +1
-0@@ -125,6 +125,7 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu);int kvm_sdei_register_notifier (struct kvm *kvm,unsigned long num,kvm_sdei_notifier notifier);void kvm_sdei_deliver (struct kvm_vcpu *vcpu); +long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg);void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vm (struct kvm *kvm);arch/arm64/include/uapi/asm/kvm_sdei.h +17
-0@@ -57,5 +57,22 @@ struct kvm_sdei_vcpu_state {struct kvm_sdei_vcpu_regs normal_regs; }; +#define KVM_SDEI_CMD_GET_VERSION 0 +#define KVM_SDEI_CMD_SET_EVENT 1 +#define KVM_SDEI_CMD_GET_KEVENT_COUNT 2 +#define KVM_SDEI_CMD_GET_KEVENT 3 +#define KVM_SDEI_CMD_SET_KEVENT 4 + +struct kvm_sdei_cmd { +__u32 cmd; +union { +__u32 version; +__u32 count; +__u64 num; +struct kvm_sdei_event_state kse_state; +struct kvm_sdei_kvm_event_state kske_state; + }; +}; +#endif /* !__ASSEMBLY__ */ #endif /* _UAPI__ASM_KVM_SDEI_H */ arch/arm64/kvm/arm.c +3
-0@@ -1389,6 +1389,9 @@ long kvm_arch_vm_ioctl(struct file *filp,return -EFAULT ;return kvm_vm_ioctl_mte_copy_tags (kvm, ©_tags); } +case KVM_ARM_SDEI_COMMAND : { +return kvm_sdei_vm_ioctl (kvm, arg); + }default :return -EINVAL ; }arch/arm64/kvm/sdei.c +14
-0@@ -931,6 +931,177 @@ void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) vcpu->arch.sdei = vsdei; } +static long kvm_sdei_set_event (struct kvm *kvm, +struct kvm_sdei_event_state *kse_state) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse =NULL ; + +if (!kvm_sdei_is_valid_event_num (kse_state->num)) +return -EINVAL ; + +if (!(kse_state->type ==SDEI_EVENT_TYPE_SHARED || + kse_state->type ==SDEI_EVENT_TYPE_PRIVATE )) +return -EINVAL ; + + if (!(kse_state->priority == SDEI_EVENT_PRIORITY_NORMAL ||
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 957
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ kse_state->priority == SDEI_EVENT_PRIORITY_CRITICAL)) +return -EINVAL ; + + kse =kvm_sdei_find_event (kvm, kse_state->num); +if (kse) +return -EEXIST ; + + kse =kzalloc (sizeof (*kse),GFP_KERNEL ); +if (!kse) +return -ENOMEM ;
userspace can exhaust the mem since there is no limit. There must be a max.
Quoted 21 lines
arch/arm64/kvm/sdei.c +21
-0+ + kse->state = *kse_state; + kse->kvm = kvm; +list_add_tail (&kse->link, &ksdei->events); + +return 0 ; +} + +static long kvm_sdei_get_kevent_count (struct kvm *kvm,int *count) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_kvm_event *kske =NULL ; +int total =0 ; + +list_for_each_entry (kske, &ksdei->kvm_events, link) { + total++; + } + + *count = total; +return 0 ; +}
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 988
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ +static long kvm_sdei_get_kevent (struct kvm *kvm, +struct kvm_sdei_kvm_event_state *kske_state) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_kvm_event *kske =NULL ; + +/* +* The first entry is fetched if the event number is invalid. +* Otherwise, the next entry is fetched.
why don't we return an error? What is the point returning the next entry?
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 996
Quoted 8 lines
arch/arm64/kvm/sdei.c +8
-0+*/ +if (!kvm_sdei_is_valid_event_num (kske_state->num)) { + kske =list_first_entry_or_null (&ksdei->kvm_events, + struct kvm_sdei_kvm_event, link); + }else { + kske =kvm_sdei_find_kvm_event (kvm, kske_state->num); +if (kske && !list_is_last (&kske->link, &ksdei->kvm_events)) + kske =list_next_entry (kske, link);
Sorry I don't get why we return the next one?
Quoted 28 lines
arch/arm64/kvm/sdei.c +28
-0+else + kske =NULL ; + } + +if (!kske) +return -ENOENT ; + + *kske_state = kske->state; + +return 0 ; +} + +static long kvm_sdei_set_kevent (struct kvm *kvm, +struct kvm_sdei_kvm_event_state *kske_state) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; + +/* Sanity check */ +if (!kvm_sdei_is_valid_event_num (kske_state->num)) +return -EINVAL ; + +if (!(kske_state->route_mode ==SDEI_EVENT_REGISTER_RM_ANY || + kske_state->route_mode ==SDEI_EVENT_REGISTER_RM_PE )) +return -EINVAL ; + +/* Check if the event number is valid */
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 1034
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ kse =kvm_sdei_find_event (kvm, kske_state->num); +if (!kse) +return -ENOENT ; + +/* Check if the event has been populated */ + kske =kvm_sdei_find_kvm_event (kvm, kske_state->num); +if (kske) +return -EEXIST ; + + kske =kzalloc (sizeof (*kske),GFP_KERNEL );
userspace can exhaust the mem since there is no limit
Quoted 79 lines
arch/arm64/kvm/sdei.c +70
-0+if (!kske) +return -ENOMEM ; + + kske->state = *kske_state; + kske->kse = kse; + kske->kvm = kvm; +list_add_tail (&kske->link, &ksdei->kvm_events); + +return 0 ; +} + +long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_cmd *cmd =NULL ; +void __user *argp = (void __user *)arg; +bool copy = false; +long ret =0 ; + +/* Sanity check */ +if (!ksdei) { + ret = -EPERM ; + goto out; + } + + cmd =kzalloc (sizeof (*cmd),GFP_KERNEL ); +if (!cmd) { + ret = -ENOMEM ; + goto out; + } + +if (copy_from_user (cmd, argp,sizeof (*cmd))) { + ret = -EFAULT ; + goto out; + } + +spin_lock (&ksdei->lock); + +switch (cmd->cmd) { +case KVM_SDEI_CMD_GET_VERSION : + copy = true; + cmd->version = (1 <<16 );/* v1.0.0 */ +break ; +case KVM_SDEI_CMD_SET_EVENT : + ret =kvm_sdei_set_event (kvm, &cmd->kse_state); +break ; +case KVM_SDEI_CMD_GET_KEVENT_COUNT : + copy = true; + ret =kvm_sdei_get_kevent_count (kvm, &cmd->count); +break ; +case KVM_SDEI_CMD_GET_KEVENT : + copy = true; + ret =kvm_sdei_get_kevent (kvm, &cmd->kske_state); +break ; +case KVM_SDEI_CMD_SET_KEVENT : + ret =kvm_sdei_set_kevent (kvm, &cmd->kske_state); +break ; +default : + ret = -EINVAL ; + } + +spin_unlock (&ksdei->lock); +out: +if (!ret && copy &©_to_user (argp, cmd,sizeof (*cmd))) + ret = -EFAULT ; + +kfree (cmd); +return ret; +} +void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu) {struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei;include/uapi/linux/kvm.h +0
-0
include/uapi/linux/kvm.h struct kvm_xen_vcpu_attr { · line 1687
Quoted 9 lines
include/uapi/linux/kvm.h +3
-0@@ -1679,6 +1679,9 @@ struct kvm_xen_vcpu_attr {#define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA 0x4#define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST 0x5 +/* Available with KVM_CAP_ARM_SDEI */ +#define KVM_ARM_SDEI_COMMAND _IOWR(KVMIO, 0xce, struct kvm_sdei_cmd) +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */
Eric
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 16/21] KVM: arm64: Support SDEI ioctl commands on VM
Hi Eric,
Quoted 18 lines · Eric Auger
Quoted 3 lines · Gavin Shan
This supports ioctl commands on VM to manage the various objects. It's primarily used by VMM to accomplish live migration. The ioctl commands introduced by this are highlighted as blow:
below
Quoted 3 lines
*
KVM_SDEI_CMD_GET_VERSION
Retrieve the version of current implementationwhich implementation, SDEI?
Quoted 9 lines
*
KVM_SDEI_CMD_SET_EVENT
Add event to be exported from KVM so that guest can register against it afterwards
*KVM_SDEI_CMD_GET_KEVENT_COUNT
Retrieve number of registered SDEI events
*KVM_SDEI_CMD_GET_KEVENT
Retrieve the state of the registered SDEI event
*KVM_SDEI_CMD_SET_KEVENT
Populate the registered SDEI event
Quoted 3 lines
I think we really miss the full picture of what you want to achieve with those IOCTLs or at least I fail to get it. Please document the UAPI separately including the structs and IOCTLs.
The commit log will be improved accordingly in next revision. Yep, I will add document for UAPI and IOCTLs :)
Quoted 88 lines
Quoted 88 lines
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_sdei.h | 1 + arch/arm64/include/uapi/asm/kvm_sdei.h | 17 +++ arch/arm64/kvm/arm.c | 3 + arch/arm64/kvm/sdei.c | 171 +++++++++++++++++++++++++ include/uapi/linux/kvm.h | 3 + 5 files changed, 195 insertions(+)arch/arm64/include/asm/kvm_sdei.h +1
-0@@ -125,6 +125,7 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu);int kvm_sdei_register_notifier (struct kvm *kvm,unsigned long num,kvm_sdei_notifier notifier);void kvm_sdei_deliver (struct kvm_vcpu *vcpu); +long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg);void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vm (struct kvm *kvm);arch/arm64/include/uapi/asm/kvm_sdei.h +17
-0@@ -57,5 +57,22 @@ struct kvm_sdei_vcpu_state {struct kvm_sdei_vcpu_regs normal_regs; }; +#define KVM_SDEI_CMD_GET_VERSION 0 +#define KVM_SDEI_CMD_SET_EVENT 1 +#define KVM_SDEI_CMD_GET_KEVENT_COUNT 2 +#define KVM_SDEI_CMD_GET_KEVENT 3 +#define KVM_SDEI_CMD_SET_KEVENT 4 + +struct kvm_sdei_cmd { +__u32 cmd; +union { +__u32 version; +__u32 count; +__u64 num; +struct kvm_sdei_event_state kse_state; +struct kvm_sdei_kvm_event_state kske_state; + }; +}; +#endif /* !__ASSEMBLY__ */ #endif /* _UAPI__ASM_KVM_SDEI_H */ arch/arm64/kvm/arm.c +3
-0@@ -1389,6 +1389,9 @@ long kvm_arch_vm_ioctl(struct file *filp,return -EFAULT ;return kvm_vm_ioctl_mte_copy_tags (kvm, ©_tags); } +case KVM_ARM_SDEI_COMMAND : { +return kvm_sdei_vm_ioctl (kvm, arg); + }default :return -EINVAL ; }arch/arm64/kvm/sdei.c +17
-0@@ -931,6 +931,177 @@ void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) vcpu->arch.sdei = vsdei; } +static long kvm_sdei_set_event (struct kvm *kvm, +struct kvm_sdei_event_state *kse_state) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse =NULL ; + +if (!kvm_sdei_is_valid_event_num (kse_state->num)) +return -EINVAL ; + +if (!(kse_state->type ==SDEI_EVENT_TYPE_SHARED || + kse_state->type ==SDEI_EVENT_TYPE_PRIVATE )) +return -EINVAL ; + +if (!(kse_state->priority ==SDEI_EVENT_PRIORITY_NORMAL || + kse_state->priority ==SDEI_EVENT_PRIORITY_CRITICAL )) +return -EINVAL ; +
Quoted 9 lines
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 957
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ kse =kvm_sdei_find_event (kvm, kse_state->num); +if (kse) +return -EEXIST ; + + kse =kzalloc (sizeof (*kse),GFP_KERNEL ); +if (!kse) +return -ENOMEM ;userspace can exhaust the mem since there is no limit. There must be a max.
Ok. I think it's minor or corner case. For now, the number of defined SDEI events are only one. I leave it for something to be improved in future.
Quoted 24 lines
Quoted 24 lines
arch/arm64/kvm/sdei.c +24
-0+ + kse->state = *kse_state; + kse->kvm = kvm; +list_add_tail (&kse->link, &ksdei->events); + +return 0 ; +} + +static long kvm_sdei_get_kevent_count (struct kvm *kvm,int *count) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_kvm_event *kske =NULL ; +int total =0 ; + +list_for_each_entry (kske, &ksdei->kvm_events, link) { + total++; + } + + *count = total; +return 0 ; +} + +static long kvm_sdei_get_kevent (struct kvm *kvm, +struct kvm_sdei_kvm_event_state *kske_state)
Quoted 8 lines
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 988
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_kvm_event *kske =NULL ; + +/* +* The first entry is fetched if the event number is invalid. +* Otherwise, the next entry is fetched. why don't we return an error? What is the point returning the next entry?
The SDEI events attached to the KVM are migrated one by one. Thoese attached SDEI events are linked through a linked list:
(1) on !kvm_sdei_is_valid_event_num(kske_state->num), the first SDEI event in the linked list is retrieved from source VM and will be restored on the destination VM.
(2) Otherwise, the next SDEI event in the linked list will be retrieved from source VM and restored on the destination VM.
Another option is to introduce additional struct like below. In this way, all the attached SDEI events are retrieved and restored once. In this way, the memory block used for storing @kvm_sdei_kvm_event_state should be allocated and released by QEMU. Please let me know your preference:
struct xxx {
__u64 count;
struct kvm_sdei_kvm_event_state events;
}Quoted 9 lines
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 996
Quoted 8 lines
arch/arm64/kvm/sdei.c +8
-0+*/ +if (!kvm_sdei_is_valid_event_num (kske_state->num)) { + kske =list_first_entry_or_null (&ksdei->kvm_events, + struct kvm_sdei_kvm_event, link); + }else { + kske =kvm_sdei_find_kvm_event (kvm, kske_state->num); +if (kske && !list_is_last (&kske->link, &ksdei->kvm_events)) + kske =list_next_entry (kske, link);Sorry I don't get why we return the next one?
Please refer to the explanation above.
Quoted 31 lines
Quoted 31 lines
arch/arm64/kvm/sdei.c +31
-0+else + kske =NULL ; + } + +if (!kske) +return -ENOENT ; + + *kske_state = kske->state; + +return 0 ; +} + +static long kvm_sdei_set_kevent (struct kvm *kvm, +struct kvm_sdei_kvm_event_state *kske_state) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; + +/* Sanity check */ +if (!kvm_sdei_is_valid_event_num (kske_state->num)) +return -EINVAL ; + +if (!(kske_state->route_mode ==SDEI_EVENT_REGISTER_RM_ANY || + kske_state->route_mode ==SDEI_EVENT_REGISTER_RM_PE )) +return -EINVAL ; + +/* Check if the event number is valid */ + kse =kvm_sdei_find_event (kvm, kske_state->num); +if (!kse) +return -ENOENT ;
Quoted 8 lines
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 1034
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ +/* Check if the event has been populated */ + kske =kvm_sdei_find_kvm_event (kvm, kske_state->num); +if (kske) +return -EEXIST ; + + kske =kzalloc (sizeof (*kske),GFP_KERNEL );userspace can exhaust the mem since there is no limit
Ok.
Quoted 81 lines
Quoted 81 lines
arch/arm64/kvm/sdei.c +70
-0+if (!kske) +return -ENOMEM ; + + kske->state = *kske_state; + kske->kse = kse; + kske->kvm = kvm; +list_add_tail (&kske->link, &ksdei->kvm_events); + +return 0 ; +} + +long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg) +{ +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_cmd *cmd =NULL ; +void __user *argp = (void __user *)arg; +bool copy = false; +long ret =0 ; + +/* Sanity check */ +if (!ksdei) { + ret = -EPERM ; + goto out; + } + + cmd =kzalloc (sizeof (*cmd),GFP_KERNEL ); +if (!cmd) { + ret = -ENOMEM ; + goto out; + } + +if (copy_from_user (cmd, argp,sizeof (*cmd))) { + ret = -EFAULT ; + goto out; + } + +spin_lock (&ksdei->lock); + +switch (cmd->cmd) { +case KVM_SDEI_CMD_GET_VERSION : + copy = true; + cmd->version = (1 <<16 );/* v1.0.0 */ +break ; +case KVM_SDEI_CMD_SET_EVENT : + ret =kvm_sdei_set_event (kvm, &cmd->kse_state); +break ; +case KVM_SDEI_CMD_GET_KEVENT_COUNT : + copy = true; + ret =kvm_sdei_get_kevent_count (kvm, &cmd->count); +break ; +case KVM_SDEI_CMD_GET_KEVENT : + copy = true; + ret =kvm_sdei_get_kevent (kvm, &cmd->kske_state); +break ; +case KVM_SDEI_CMD_SET_KEVENT : + ret =kvm_sdei_set_kevent (kvm, &cmd->kske_state); +break ; +default : + ret = -EINVAL ; + } + +spin_unlock (&ksdei->lock); +out: +if (!ret && copy &©_to_user (argp, cmd,sizeof (*cmd))) + ret = -EFAULT ; + +kfree (cmd); +return ret; +} +void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu) {struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei;include/uapi/linux/kvm.h +0
-0@@ -1679,6 +1679,9 @@ struct kvm_xen_vcpu_attr {#define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA 0x4#define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST 0x5
Quoted 7 lines
include/uapi/linux/kvm.h struct kvm_xen_vcpu_attr { · line 1687
Quoted 7 lines
include/uapi/linux/kvm.h +3
-0+/* Available with KVM_CAP_ARM_SDEI */ +#define KVM_ARM_SDEI_COMMAND _IOWR(KVMIO, 0xce, struct kvm_sdei_cmd) +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */
Thanks,
Gavin
Re: [PATCH v4 16/21] KVM: arm64: Support SDEI ioctl commands on VM
Hi gavin,
Quoted 126 lines · Gavin Shan
Hi Eric,
Quoted 18 lines · Eric Auger
Quoted 3 lines · Gavin Shan
This supports ioctl commands on VM to manage the various objects. It's primarily used by VMM to accomplish live migration. The ioctl commands introduced by this are highlighted as blow:
below
Quoted 3 lines
*
KVM_SDEI_CMD_GET_VERSION
Retrieve the version of current implementationwhich implementation, SDEI?
Quoted 9 lines
*
KVM_SDEI_CMD_SET_EVENT
Add event to be exported from KVM so that guest can register against it afterwards
*KVM_SDEI_CMD_GET_KEVENT_COUNT
Retrieve number of registered SDEI events
*KVM_SDEI_CMD_GET_KEVENT
Retrieve the state of the registered SDEI event
*KVM_SDEI_CMD_SET_KEVENT
Populate the registered SDEI eventQuoted 3 lines
I think we really miss the full picture of what you want to achieve with those IOCTLs or at least I fail to get it. Please document the UAPI separately including the structs and IOCTLs.
The commit log will be improved accordingly in next revision. Yep, I will add document for UAPI and IOCTLs :)
Quoted 88 lines
Quoted 88 lines
Signed-off-by Gavin Shan <[email protected]>---
arch/arm64/include/asm/kvm_sdei.h | 1 +arch/arm64/include/uapi/asm/kvm_sdei.h| 17 +++ arch/arm64/kvm/arm.c | 3 + arch/arm64/kvm/sdei.c | 171 +++++++++++++++++++++++++ include/uapi/linux/kvm.h | 3 +5 files changed, 195 insertions(+)arch/arm64/include/asm/kvm_sdei.h +1
-0@@ -125,6 +125,7 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu); int kvm_sdei_register_notifier(struct kvm *kvm, unsigned long num, kvm_sdei_notifier notifier); void kvm_sdei_deliver(struct kvm_vcpu *vcpu); +long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg); void kvm_sdei_destroy_vcpu(struct kvm_vcpu *vcpu); void kvm_sdei_destroy_vm(struct kvm *kvm);diff --git
a/arch/arm64/include/uapi/asm/kvm_sdei.hb/arch/arm64/include/uapi/asm/kvm_sdei.hindex4ef661d106fe..35ff05be3c28100644arch/arm64/include/uapi/asm/kvm_sdei.h +0
-0@@ -57,5 +57,22 @@ struct kvm_sdei_vcpu_state { struct kvm_sdei_vcpu_regs normal_regs; };+#define KVM_SDEI_CMD_GET_VERSION 0
arch/arm64/include/uapi/asm/kvm_sdei.h +16
-0+#define KVM_SDEI_CMD_SET_EVENT 1 +#define KVM_SDEI_CMD_GET_KEVENT_COUNT 2 +#define KVM_SDEI_CMD_GET_KEVENT 3 +#define KVM_SDEI_CMD_SET_KEVENT 4 + +struct kvm_sdei_cmd { + __u32 cmd; + union { + __u32 version; + __u32 count; + __u64 num; + struct kvm_sdei_event_state kse_state; + struct kvm_sdei_kvm_event_state kske_state; + }; +}; +#endif /* !__ASSEMBLY__ */
#endif /*_UAPI__ASM_KVM_SDEI_H*/arch/arm64/kvm/arm.c +3
-0@@ -1389,6 +1389,9 @@ long kvm_arch_vm_ioctl(struct file *filp, return -EFAULT; return kvm_vm_ioctl_mte_copy_tags(kvm, ©_tags); } + case KVM_ARM_SDEI_COMMAND: { + return kvm_sdei_vm_ioctl(kvm, arg); + }default:
return-EINVAL;
}arch/arm64/kvm/sdei.c +17
-0@@ -931,6 +931,177 @@ void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) vcpu->arch.sdei = vsdei; } +static long kvm_sdei_set_event(struct kvm *kvm, + struct kvm_sdei_event_state *kse_state) +{ + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_event *kse = NULL; + + if (!kvm_sdei_is_valid_event_num(kse_state->num)) + return -EINVAL; + + if (!(kse_state->type == SDEI_EVENT_TYPE_SHARED || + kse_state->type == SDEI_EVENT_TYPE_PRIVATE)) + return -EINVAL; + + if (!(kse_state->priority == SDEI_EVENT_PRIORITY_NORMAL || + kse_state->priority == SDEI_EVENT_PRIORITY_CRITICAL)) + return -EINVAL; + + kse = kvm_sdei_find_event(kvm, kse_state->num);Quoted 9 lines
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 957
Quoted 6 lines
arch/arm64/kvm/sdei.c +6
-0+ if (kse) + return -EEXIST; + + kse = kzalloc(sizeof(*kse), GFP_KERNEL); + if (!kse) + return -ENOMEM;userspace can exhaust the mem since there is no limit. There must be a max.
Quoted 2 lines
Ok. I think it's minor or corner case. For now, the number of defined SDEI events are only one. I leave it for something to be improved in future.
Hum ok, actually this depends on kvm_sdei_is_valid_event_num's implementation.
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
arch/arm64/kvm/sdei.c +16
-0+ + kse->state = *kse_state; + kse->kvm = kvm; + list_add_tail(&kse->link, &ksdei->events); + + return 0; +} + +static long kvm_sdei_get_kevent_count (struct kvm *kvm,int *count) +{ + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_kvm_event *kske = NULL; + int total = 0; + + list_for_each_entry(kske, &ksdei->kvm_events, link) { + total++;
Quoted 8 lines
Quoted 8 lines
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 981
Quoted 8 lines
arch/arm64/kvm/sdei.c +8
-0+ } + + *count = total; + return 0; +} + +static long kvm_sdei_get_kevent (struct kvm *kvm, + struct kvm_sdei_kvm_event_state *kske_state)
shouldn't the function return a int instead?
Quoted 13 lines
Quoted 8 lines
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 988
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+{ + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_kvm_event *kske = NULL; + + /* +* The first entry is fetched if the event number is invalid. +* Otherwise, the next entry is fetched. why don't we return an error? What is the point returning the next entry?
The SDEI events attached to the KVM are migrated one by one. Thoese attached
SDEI events are linked through a linked list:
Quoted 8 lines
(1) on !kvm_sdei_is_valid_event_num(kske_state->num), the first SDEI event
in the linked list is retrieved from source VM and will be restored on
the destination VM.(2) Otherwise, the next SDEI event in the linked list will be retrieved from source VM and restored on the destination VM.
and why not returning NULL if the num is incorrect? Why do return the 1st elem?
Eric
Quoted 157 lines
Another option is to introduce additional struct like below. In this way, all
the attached SDEI events are retrieved and restored once. In this way, the memory block used for storing @kvm_sdei_kvm_event_state should be allocated and released by QEMU. Please let me know your preference:struct xxx {
__u64 count; struct kvm_sdei_kvm_event_state events; }Quoted 9 lines
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 996
Quoted 8 lines
arch/arm64/kvm/sdei.c +8
-0+*/ + if (!kvm_sdei_is_valid_event_num(kske_state->num)) { + kske = list_first_entry_or_null(&ksdei->kvm_events, + struct kvm_sdei_kvm_event, link); + } else { + kske = kvm_sdei_find_kvm_event(kvm, kske_state->num); + if (kske && !list_is_last(&kske->link, &ksdei->kvm_events)) + kske = list_next_entry(kske, link);Sorry I don't get why we return the next one?
Please refer to the explanation above.
Quoted 31 lines
Quoted 31 lines
arch/arm64/kvm/sdei.c +31
-0+ else + kske = NULL; + } + + if (!kske) + return -ENOENT; + + *kske_state = kske->state; + + return 0; +} + +static long kvm_sdei_set_kevent (struct kvm *kvm, + struct kvm_sdei_kvm_event_state *kske_state) +{ + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_event *kse = NULL; + struct kvm_sdei_kvm_event *kske = NULL; + + /* Sanity check */ + if (!kvm_sdei_is_valid_event_num(kske_state->num)) + return -EINVAL; + + if (!(kske_state->route_mode == SDEI_EVENT_REGISTER_RM_ANY || + kske_state->route_mode == SDEI_EVENT_REGISTER_RM_PE)) + return -EINVAL; + + /* Check if the event number is valid */ + kse = kvm_sdei_find_event(kvm, kske_state->num); + if (!kse) + return -ENOENT;Quoted 8 lines
arch/arm64/kvm/sdei.c void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu) · line 1034
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+ + /* Check if the event has been populated */ + kske = kvm_sdei_find_kvm_event(kvm, kske_state->num); + if (kske) + return -EEXIST; + + kske = kzalloc(sizeof(*kske), GFP_KERNEL);userspace can exhaust the mem since there is no limit
Ok.
Quoted 79 lines
Quoted 79 lines
arch/arm64/kvm/sdei.c +70
-0+ if (!kske) + return -ENOMEM; + + kske->state = *kske_state; + kske->kse = kse; + kske->kvm = kvm; + list_add_tail(&kske->link, &ksdei->kvm_events); + + return 0; +} + +long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg) +{ + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_cmd *cmd = NULL; + void __user *argp = (void __user *)arg; + bool copy = false; + long ret = 0; + + /* Sanity check */ + if (!ksdei) { + ret = -EPERM; + goto out; + } + + cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); + if (!cmd) { + ret = -ENOMEM; + goto out; + } + + if (copy_from_user(cmd, argp, sizeof(*cmd))) { + ret = -EFAULT; + goto out; + } + + spin_lock(&ksdei->lock); + + switch (cmd->cmd) { + case KVM_SDEI_CMD_GET_VERSION: + copy = true; + cmd->version = (1 << 16); /* v1.0.0 */ + break; + case KVM_SDEI_CMD_SET_EVENT: + ret = kvm_sdei_set_event(kvm, &cmd->kse_state); + break; + case KVM_SDEI_CMD_GET_KEVENT_COUNT: + copy = true; + ret = kvm_sdei_get_kevent_count(kvm, &cmd->count); + break; + case KVM_SDEI_CMD_GET_KEVENT: + copy = true; + ret = kvm_sdei_get_kevent(kvm, &cmd->kske_state); + break; + case KVM_SDEI_CMD_SET_KEVENT: + ret = kvm_sdei_set_kevent(kvm, &cmd->kske_state); + break; + default: + ret = -EINVAL; + } + + spin_unlock(&ksdei->lock); +out: + if (!ret && copy && copy_to_user(argp, cmd, sizeof(*cmd))) + ret = -EFAULT; + + kfree(cmd); + return ret; +} + void kvm_sdei_destroy_vcpu(struct kvm_vcpu *vcpu) { struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei;include/uapi/linux/kvm.h +0
-0@@ -1679,6 +1679,9 @@ struct kvm_xen_vcpu_attr { #define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA 0x4Quoted 8 lines
Quoted 8 lines
include/uapi/linux/kvm.h +0
-0#define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST 0x5+/* Available with
KVM_CAP_ARM_SDEI*/include/uapi/linux/kvm.h +2
-0+#define KVM_ARM_SDEI_COMMAND _IOWR(KVMIO, 0xce, struct kvm_sdei_cmd) +/* Secure Encrypted Virtualization command */
enumsev_cmd_id{
/* Guest initialization commands */Thanks,
Gavin
PATCH v4 17/21 KVM: arm64: Support SDEI ioctl commands on vCPU
In reply to Gavin ShanThis supports ioctl commands on vCPU to manage the various object. It's primarily used by VMM to accomplish live migration. The ioctl commands introduced by this are highlighted as below:
* KVM_SDEI_CMD_GET_VEVENT_COUNT
Retrieve number of SDEI events that pend for handling on the vCPU
* KVM_SDEI_CMD_GET_VEVENT
Retrieve the state of SDEI event, which has been delivered to the vCPU for handling
* KVM_SDEI_CMD_SET_VEVENT
Populate the SDEI event, which has been delivered to the vCPU for handling
* KVM_SDEI_CMD_GET_VCPU_STATE
Retrieve vCPU state related to SDEI handling
* KVM_SDEI_CMD_SET_VCPU_STATE
Populate vCPU state related to SDEI handling
--- arch/arm64/include/asm/kvm_sdei.h | 1 + arch/arm64/include/uapi/asm/kvm_sdei.h | 7 + arch/arm64/kvm/arm.c | 3 + arch/arm64/kvm/sdei.c | 228 +++++++++++++++++++++++++ 4 files changed, 239 insertions(+)
arch/arm64/include/asm/kvm_sdei.h +1 -0
@@ -126,6 +126,7 @@ int kvm_sdei_register_notifier(struct kvm *kvm, unsigned long num, kvm_sdei_notifier notifier);void kvm_sdei_deliver (struct kvm_vcpu *vcpu);long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg); +long kvm_sdei_vcpu_ioctl (struct kvm_vcpu *vcpu,unsigned long arg);void kvm_sdei_destroy_vcpu (struct kvm_vcpu *vcpu);void kvm_sdei_destroy_vm (struct kvm *kvm);
arch/arm64/include/uapi/asm/kvm_sdei.h +7 -0
@@ -62,6 +62,11 @@ struct kvm_sdei_vcpu_state {#define KVM_SDEI_CMD_GET_KEVENT_COUNT 2#define KVM_SDEI_CMD_GET_KEVENT 3#define KVM_SDEI_CMD_SET_KEVENT 4 +#define KVM_SDEI_CMD_GET_VEVENT_COUNT 5 +#define KVM_SDEI_CMD_GET_VEVENT 6 +#define KVM_SDEI_CMD_SET_VEVENT 7 +#define KVM_SDEI_CMD_GET_VCPU_STATE 8 +#define KVM_SDEI_CMD_SET_VCPU_STATE 9struct kvm_sdei_cmd {__u32 cmd;
@@ -71,6 +76,8 @@ struct kvm_sdei_cmd {__u64 num;struct kvm_sdei_event_state kse_state;struct kvm_sdei_kvm_event_state kske_state; +struct kvm_sdei_vcpu_event_state ksve_state; +struct kvm_sdei_vcpu_state ksv_state; }; };
arch/arm64/kvm/arm.c +3 -0
@@ -1308,6 +1308,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,return kvm_arm_vcpu_finalize (vcpu, what); } +case KVM_ARM_SDEI_COMMAND : { +return kvm_sdei_vcpu_ioctl (vcpu, arg); + }default : r = -EINVAL ; }
arch/arm64/kvm/sdei.c +228 -0
240 lines not on this page · raw message
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 18/21 KVM: arm64: Support SDEI event injection
In reply to Gavin ShanThis supports SDEI event injection by implementing kvm_sdei_inject(). It's called by kernel directly or VMM through ioctl command to inject SDEI event to the specific vCPU.
--- arch/arm64/include/asm/kvm_sdei.h | 2 + arch/arm64/include/uapi/asm/kvm_sdei.h | 1 + arch/arm64/kvm/sdei.c | 108 +++++++++++++++++++++++++ 3 files changed, 111 insertions(+)
arch/arm64/include/asm/kvm_sdei.h +2 -0
@@ -124,6 +124,8 @@ void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu);int kvm_sdei_hypercall (struct kvm_vcpu *vcpu);int kvm_sdei_register_notifier (struct kvm *kvm,unsigned long num,kvm_sdei_notifier notifier); +int kvm_sdei_inject (struct kvm_vcpu *vcpu, +unsigned long num,bool immediate);void kvm_sdei_deliver (struct kvm_vcpu *vcpu);long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg);long kvm_sdei_vcpu_ioctl (struct kvm_vcpu *vcpu,unsigned long arg);
arch/arm64/include/uapi/asm/kvm_sdei.h +1 -0
@@ -67,6 +67,7 @@ struct kvm_sdei_vcpu_state {#define KVM_SDEI_CMD_SET_VEVENT 7#define KVM_SDEI_CMD_GET_VCPU_STATE 8#define KVM_SDEI_CMD_SET_VCPU_STATE 9 +#define KVM_SDEI_CMD_INJECT_EVENT 10struct kvm_sdei_cmd {__u32 cmd;
arch/arm64/kvm/sdei.c +108 -0
120 lines not on this page · raw message
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 18/21] KVM: arm64: Support SDEI event injection
Quoted 41 lines · Gavin Shan
This supports SDEI event injection by implementing
kvm_sdei_inject(). It's called by kernel directly or VMM through ioctl command to inject SDEI event to the specific vCPU.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_sdei.h | 2 + arch/arm64/include/uapi/asm/kvm_sdei.h | 1 + arch/arm64/kvm/sdei.c | 108 +++++++++++++++++++++++++ 3 files changed, 111 insertions(+)arch/arm64/include/asm/kvm_sdei.h +2
-0@@ -124,6 +124,8 @@ void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu);int kvm_sdei_hypercall (struct kvm_vcpu *vcpu);int kvm_sdei_register_notifier (struct kvm *kvm,unsigned long num,kvm_sdei_notifier notifier); +int kvm_sdei_inject (struct kvm_vcpu *vcpu, +unsigned long num,bool immediate);void kvm_sdei_deliver (struct kvm_vcpu *vcpu);long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg);long kvm_sdei_vcpu_ioctl (struct kvm_vcpu *vcpu,unsigned long arg);arch/arm64/include/uapi/asm/kvm_sdei.h +1
-0@@ -67,6 +67,7 @@ struct kvm_sdei_vcpu_state {#define KVM_SDEI_CMD_SET_VEVENT 7#define KVM_SDEI_CMD_GET_VCPU_STATE 8#define KVM_SDEI_CMD_SET_VCPU_STATE 9 +#define KVM_SDEI_CMD_INJECT_EVENT 10struct kvm_sdei_cmd {__u32 cmd;arch/arm64/kvm/sdei.c +0
-0
arch/arm64/kvm/sdei.c int kvm_sdei_register_notifier(struct kvm *kvm, · line 807
Quoted 6 lines
arch/arm64/kvm/sdei.c +3
-0@@ -802,6 +802,111 @@ int kvm_sdei_register_notifier(struct kvm *kvm,return ret; } +int kvm_sdei_inject (struct kvm_vcpu *vcpu, +unsigned long num, +bool immediate)
don't get the immediate param.
Quoted 36 lines
arch/arm64/kvm/sdei.c +36
-0+{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +struct kvm_sdei_vcpu_event *ksve =NULL ; +int index, ret =0 ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret = -EPERM ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (num)) { + ret = -EINVAL ; + goto out; + } + +/* Check the kvm event */ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, num); +if (!kske) { + ret = -ENOENT ; + goto unlock_kvm; + } + + kse = kske->kse; + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; +if (!(kvm_sdei_is_registered (kske, index) && +kvm_sdei_is_enabled (kske, index))) { + ret = -EPERM ; + goto unlock_kvm; + }
arch/arm64/kvm/sdei.c int kvm_sdei_register_notifier(struct kvm *kvm, · line 853
Quoted 10 lines
arch/arm64/kvm/sdei.c +10
-0+ +/* Check the vcpu state */ +spin_lock (&vsdei->lock); +if (vsdei->state.masked) { + ret = -EPERM ; + goto unlock_vcpu; + } + +/* Check if the event can be delivered immediately */ +if (immediate) {
According to the dispatcher pseudo code this should be always checked?
arch/arm64/kvm/sdei.c int kvm_sdei_register_notifier(struct kvm *kvm, · line 866
Quoted 13 lines
arch/arm64/kvm/sdei.c +13
-0+if (kse->state.priority ==SDEI_EVENT_PRIORITY_CRITICAL && + !list_empty (&vsdei->critical_events)) { + ret = -ENOSPC ; + goto unlock_vcpu; + } + +if (kse->state.priority ==SDEI_EVENT_PRIORITY_NORMAL && + (!list_empty (&vsdei->critical_events) || + !list_empty (&vsdei->normal_events))) { + ret = -ENOSPC ; + goto unlock_vcpu; + } + }
What about shared event dispatching. I don't see the afficinity checked anywhere?
arch/arm64/kvm/sdei.c int kvm_sdei_register_notifier(struct kvm *kvm, · line 872
Quoted 6 lines
arch/arm64/kvm/sdei.c +6
-0+ +/* Check if the vcpu event exists */ + ksve =kvm_sdei_find_vcpu_event (vcpu, num); +if (ksve) { + kske->state.refcount++; + ksve->state.refcount++;
why this double refcount increment??
Quoted 42 lines
arch/arm64/kvm/sdei.c +37
-0+kvm_make_request (KVM_REQ_SDEI , vcpu); + goto unlock_vcpu; + } + +/* Allocate vcpu event */ + ksve =kzalloc (sizeof (*ksve),GFP_KERNEL ); +if (!ksve) { + ret = -ENOMEM ; + goto unlock_vcpu; + } + +/* +* We should take lock to update KVM event state because its +* reference count might be zero. In that case, the KVM event +* could be destroyed. +*/ + kske->state.refcount++; + ksve->state.num = num; + ksve->state.refcount =1 ; + ksve->kske = kske; + ksve->vcpu = vcpu; + +if (kse->state.priority ==SDEI_EVENT_PRIORITY_CRITICAL ) +list_add_tail (&ksve->link, &vsdei->critical_events); +else +list_add_tail (&ksve->link, &vsdei->normal_events); + +kvm_make_request (KVM_REQ_SDEI , vcpu); + +unlock_vcpu: +spin_unlock (&vsdei->lock); +unlock_kvm: +spin_unlock (&ksdei->lock); +out: +return ret; +} +void kvm_sdei_deliver (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;
arch/arm64/kvm/sdei.c long kvm_sdei_vcpu_ioctl(struct kvm_vcpu *vcpu, unsigned long arg) · line 1430
Quoted 9 lines
arch/arm64/kvm/sdei.c +3
-0@@ -1317,6 +1422,9 @@ long kvm_sdei_vcpu_ioctl(struct kvm_vcpu *vcpu, unsigned long arg)case KVM_SDEI_CMD_SET_VCPU_STATE : ret =kvm_sdei_set_vcpu_state (vcpu, &cmd->ksv_state);break ; +case KVM_SDEI_CMD_INJECT_EVENT : + ret =kvm_sdei_inject (vcpu, cmd->num, false); +break ;default : ret = -EINVAL ; }
Eric
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 18/21] KVM: arm64: Support SDEI event injection
Hi Eric,
Quoted 45 lines · Eric Auger
Quoted 44 lines · Gavin Shan
This supports SDEI event injection by implementing
kvm_sdei_inject(). It's called by kernel directly or VMM through ioctl command to inject SDEI event to the specific vCPU.Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_sdei.h | 2 + arch/arm64/include/uapi/asm/kvm_sdei.h | 1 + arch/arm64/kvm/sdei.c | 108 +++++++++++++++++++++++++ 3 files changed, 111 insertions(+)arch/arm64/include/asm/kvm_sdei.h +2
-0@@ -124,6 +124,8 @@ void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu);int kvm_sdei_hypercall (struct kvm_vcpu *vcpu);int kvm_sdei_register_notifier (struct kvm *kvm,unsigned long num,kvm_sdei_notifier notifier); +int kvm_sdei_inject (struct kvm_vcpu *vcpu, +unsigned long num,bool immediate);void kvm_sdei_deliver (struct kvm_vcpu *vcpu);long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg);long kvm_sdei_vcpu_ioctl (struct kvm_vcpu *vcpu,unsigned long arg);arch/arm64/include/uapi/asm/kvm_sdei.h +1
-0@@ -67,6 +67,7 @@ struct kvm_sdei_vcpu_state {#define KVM_SDEI_CMD_SET_VEVENT 7#define KVM_SDEI_CMD_GET_VCPU_STATE 8#define KVM_SDEI_CMD_SET_VCPU_STATE 9 +#define KVM_SDEI_CMD_INJECT_EVENT 10struct kvm_sdei_cmd {__u32 cmd;arch/arm64/kvm/sdei.c +0
-0@@ -802,6 +802,111 @@ int kvm_sdei_register_notifier(struct kvm *kvm,return ret; }
Quoted 4 lines
arch/arm64/kvm/sdei.c int kvm_sdei_register_notifier(struct kvm *kvm, · line 807
Quoted 3 lines
arch/arm64/kvm/sdei.c +3
-0+int kvm_sdei_inject (struct kvm_vcpu *vcpu, +unsigned long num, +bool immediate)don't get the immediate param.
I definitely need comments to explain @immediate here. It means the injected SDEI event should be handled and delivered immediately. For example, if one of the following conditions is met, the injected event can't be delivered immediately. This mechanism is needed by Async PF to inject event for page-not-present notification and it's expected to be delivered immediately.
(a) Current event is critical, another critical event is being delivered.
(b) Current event is normal, another critical or normal event is being delivered.
Quoted 39 lines
Quoted 39 lines
arch/arm64/kvm/sdei.c +39
-0+{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_event *kse =NULL ; +struct kvm_sdei_kvm_event *kske =NULL ; +struct kvm_sdei_vcpu_event *ksve =NULL ; +int index, ret =0 ; + +/* Sanity check */ +if (!(ksdei && vsdei)) { + ret = -EPERM ; + goto out; + } + +if (!kvm_sdei_is_valid_event_num (num)) { + ret = -EINVAL ; + goto out; + } + +/* Check the kvm event */ +spin_lock (&ksdei->lock); + kske =kvm_sdei_find_kvm_event (kvm, num); +if (!kske) { + ret = -ENOENT ; + goto unlock_kvm; + } + + kse = kske->kse; + index = (kse->state.type ==SDEI_EVENT_TYPE_PRIVATE ) ? + vcpu->vcpu_idx :0 ; +if (!(kvm_sdei_is_registered (kske, index) && +kvm_sdei_is_enabled (kske, index))) { + ret = -EPERM ; + goto unlock_kvm; + } + +/* Check the vcpu state */ +spin_lock (&vsdei->lock);
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_register_notifier(struct kvm *kvm, · line 853
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+if (vsdei->state.masked) { + ret = -EPERM ; + goto unlock_vcpu; + } + +/* Check if the event can be delivered immediately */ +if (immediate) {According to the dispatcher pseudo code this should be always checked?
Nope, The spec doesn't require that the event is delivered immediately. It means the event can be delayed.
Quoted 7 lines
Quoted 7 lines
arch/arm64/kvm/sdei.c +7
-0+if (kse->state.priority ==SDEI_EVENT_PRIORITY_CRITICAL && + !list_empty (&vsdei->critical_events)) { + ret = -ENOSPC ; + goto unlock_vcpu; + } + + if (kse->state.priority == SDEI_EVENT_PRIORITY_NORMAL &&
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_register_notifier(struct kvm *kvm, · line 866
Quoted 6 lines
arch/arm64/kvm/sdei.c +6
-0+ (!list_empty(&vsdei->critical_events) || + !list_empty(&vsdei->normal_events))) { + ret = -ENOSPC ; + goto unlock_vcpu; + } + }What about shared event dispatching. I don't see the afficinity checked anywhere?
You're correct. I ignore affinity stuff for now for two reasons: (1) I didn't figure out the mechanism to verify the affinity, as I mentioned before.
(2) Currently, the affinity isn't used by SDEI client driver in the guest kernel.
Quoted 7 lines
arch/arm64/kvm/sdei.c int kvm_sdei_register_notifier(struct kvm *kvm, · line 872
Quoted 6 lines
arch/arm64/kvm/sdei.c +6
-0+ +/* Check if the vcpu event exists */ + ksve =kvm_sdei_find_vcpu_event (vcpu, num); +if (ksve) { + kske->state.refcount++; + ksve->state.refcount++;why this double refcount increment??
Yep, As I explained before, "ksve->state.refcount" should be increased only when the corresponding vCPU event is created.
Quoted 43 lines
Quoted 43 lines
arch/arm64/kvm/sdei.c +37
-0+kvm_make_request (KVM_REQ_SDEI , vcpu); + goto unlock_vcpu; + } + +/* Allocate vcpu event */ + ksve =kzalloc (sizeof (*ksve),GFP_KERNEL ); +if (!ksve) { + ret = -ENOMEM ; + goto unlock_vcpu; + } + +/* +* We should take lock to update KVM event state because its +* reference count might be zero. In that case, the KVM event +* could be destroyed. +*/ + kske->state.refcount++; + ksve->state.num = num; + ksve->state.refcount =1 ; + ksve->kske = kske; + ksve->vcpu = vcpu; + +if (kse->state.priority ==SDEI_EVENT_PRIORITY_CRITICAL ) +list_add_tail (&ksve->link, &vsdei->critical_events); +else +list_add_tail (&ksve->link, &vsdei->normal_events); + +kvm_make_request (KVM_REQ_SDEI , vcpu); + +unlock_vcpu: +spin_unlock (&vsdei->lock); +unlock_kvm: +spin_unlock (&ksdei->lock); +out: +return ret; +} +void kvm_sdei_deliver (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;@@ -1317,6 +1422,9 @@ long kvm_sdei_vcpu_ioctl(struct kvm_vcpu *vcpu, unsigned long arg)case KVM_SDEI_CMD_SET_VCPU_STATE : ret =kvm_sdei_set_vcpu_state (vcpu, &cmd->ksv_state);
Quoted 8 lines
arch/arm64/kvm/sdei.c long kvm_sdei_vcpu_ioctl(struct kvm_vcpu *vcpu, unsigned long arg) · line 1430
Quoted 8 lines
arch/arm64/kvm/sdei.c +3
-0break ; +case KVM_SDEI_CMD_INJECT_EVENT : + ret =kvm_sdei_inject (vcpu, cmd->num, false); +break ;default : ret = -EINVAL ; }
Thanks,
Gavin
PATCH v4 19/21 KVM: arm64: Support SDEI event cancellation
In reply to Gavin ShanThe injected SDEI event is to send notification to guest. The SDEI event might not be needed after it's injected. This introduces API to support cancellation on the injected SDEI event if it's not fired to the guest yet.
This mechanism will be needed when we're going to support asynchronous page fault.
--- arch/arm64/include/asm/kvm_sdei.h | 1 + arch/arm64/kvm/sdei.c | 49 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)
arch/arm64/include/asm/kvm_sdei.h +1 -0
@@ -126,6 +126,7 @@ int kvm_sdei_register_notifier(struct kvm *kvm, unsigned long num, kvm_sdei_notifier notifier);int kvm_sdei_inject (struct kvm_vcpu *vcpu,unsigned long num,bool immediate); +int kvm_sdei_cancel (struct kvm_vcpu *vcpu,unsigned long num);void kvm_sdei_deliver (struct kvm_vcpu *vcpu);long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg);long kvm_sdei_vcpu_ioctl (struct kvm_vcpu *vcpu,unsigned long arg);
arch/arm64/kvm/sdei.c +49 -0
55 lines not on this page · raw message
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 19/21] KVM: arm64: Support SDEI event cancellation
Quoted 7 lines · Gavin Shan
The injected SDEI event is to send notification to guest. The SDEI event might not be needed after it's injected. This introduces API to support cancellation on the injected SDEI event if it's not fired to the guest yet.
This mechanism will be needed when we're going to support asynchronous page fault.
if we are able to manage the migration of an executing SDEI why can't we manage the migration of pending SDEIs?
Eric
Quoted 70 lines
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_sdei.h | 1 + arch/arm64/kvm/sdei.c | 49 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)arch/arm64/include/asm/kvm_sdei.h +1
-0@@ -126,6 +126,7 @@ int kvm_sdei_register_notifier(struct kvm *kvm, unsigned long num, kvm_sdei_notifier notifier);int kvm_sdei_inject (struct kvm_vcpu *vcpu,unsigned long num,bool immediate); +int kvm_sdei_cancel (struct kvm_vcpu *vcpu,unsigned long num);void kvm_sdei_deliver (struct kvm_vcpu *vcpu);long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg);long kvm_sdei_vcpu_ioctl (struct kvm_vcpu *vcpu,unsigned long arg);arch/arm64/kvm/sdei.c +42
-0@@ -907,6 +907,55 @@ int kvm_sdei_inject(struct kvm_vcpu *vcpu,return ret; } +int kvm_sdei_cancel (struct kvm_vcpu *vcpu,unsigned long num) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_kvm_event *kske =NULL ; +struct kvm_sdei_vcpu_event *ksve =NULL ; +int ret =0 ; + +if (!(ksdei && vsdei)) { + ret = -EPERM ; + goto out; + } + +/* Find the vCPU event */ +spin_lock (&vsdei->lock); + ksve =kvm_sdei_find_vcpu_event (vcpu, num); +if (!ksve) { + ret = -EINVAL ; + goto unlock; + } + +/* Event can't be cancelled if it has been delivered */ +if (ksve->state.refcount <=1 && + (vsdei->critical_event == ksve || + vsdei->normal_event == ksve)) { + ret = -EINPROGRESS ; + goto unlock; + } + +/* Free the vCPU event if necessary */ + kske = ksve->kske; + ksve->state.refcount--; +if (!ksve->state.refcount) { +list_del (&ksve->link); +kfree (ksve); + } + +unlock: +spin_unlock (&vsdei->lock); +if (kske) { +spin_lock (&ksdei->lock);
arch/arm64/kvm/sdei.c int kvm_sdei_inject(struct kvm_vcpu *vcpu, · line 961
Quoted 10 lines
arch/arm64/kvm/sdei.c +7
-0+ kske->state.refcount--; +spin_unlock (&ksdei->lock); + } +out: +return ret; +} +void kvm_sdei_deliver (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 19/21] KVM: arm64: Support SDEI event cancellation
Hi Eric,
Quoted 6 lines · Eric Auger
Quoted 5 lines · Gavin Shan
The injected SDEI event is to send notification to guest. The SDEI event might not be needed after it's injected. This introduces API to support cancellation on the injected SDEI event if it's not fired to the guest yet.
Quoted 6 lines
Quoted 2 lines
This mechanism will be needed when we're going to support asynchronous page fault.
if we are able to manage the migration of an executing SDEI why can't we manage the migration of pending SDEIs?
I think the commit log needs to explain the use case in a clearer way. It's about Async PF's performance, not migration. In Async PF, the page fault is delivered in asynchronous way using worker. The page fault can be completed before the injected SDEI event for page-not-present notification is delivered. In this case, we needn't the overhead caused by the injected SDEI event.
I will think about it and may drop this patch from the series, to detach SDEI and async PF as much as possible :)
Quoted 72 lines
Quoted 72 lines
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/include/asm/kvm_sdei.h | 1 + arch/arm64/kvm/sdei.c | 49 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)arch/arm64/include/asm/kvm_sdei.h +1
-0@@ -126,6 +126,7 @@ int kvm_sdei_register_notifier(struct kvm *kvm, unsigned long num, kvm_sdei_notifier notifier);int kvm_sdei_inject (struct kvm_vcpu *vcpu,unsigned long num,bool immediate); +int kvm_sdei_cancel (struct kvm_vcpu *vcpu,unsigned long num);void kvm_sdei_deliver (struct kvm_vcpu *vcpu);long kvm_sdei_vm_ioctl (struct kvm *kvm,unsigned long arg);long kvm_sdei_vcpu_ioctl (struct kvm_vcpu *vcpu,unsigned long arg);arch/arm64/kvm/sdei.c +45
-0@@ -907,6 +907,55 @@ int kvm_sdei_inject(struct kvm_vcpu *vcpu,return ret; } +int kvm_sdei_cancel (struct kvm_vcpu *vcpu,unsigned long num) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; +struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; +struct kvm_sdei_kvm_event *kske =NULL ; +struct kvm_sdei_vcpu_event *ksve =NULL ; +int ret =0 ; + +if (!(ksdei && vsdei)) { + ret = -EPERM ; + goto out; + } + +/* Find the vCPU event */ +spin_lock (&vsdei->lock); + ksve =kvm_sdei_find_vcpu_event (vcpu, num); +if (!ksve) { + ret = -EINVAL ; + goto unlock; + } + +/* Event can't be cancelled if it has been delivered */ +if (ksve->state.refcount <=1 && + (vsdei->critical_event == ksve || + vsdei->normal_event == ksve)) { + ret = -EINPROGRESS ; + goto unlock; + } + +/* Free the vCPU event if necessary */ + kske = ksve->kske; + ksve->state.refcount--; +if (!ksve->state.refcount) { +list_del (&ksve->link); +kfree (ksve); + } + +unlock: +spin_unlock (&vsdei->lock); +if (kske) { +spin_lock (&ksdei->lock); + kske->state.refcount--; +spin_unlock (&ksdei->lock); + }
Quoted 8 lines
arch/arm64/kvm/sdei.c int kvm_sdei_inject(struct kvm_vcpu *vcpu, · line 961
Quoted 8 lines
arch/arm64/kvm/sdei.c +4
-0+out: +return ret; +} +void kvm_sdei_deliver (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;
Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 20/21 KVM: arm64: Export SDEI capability
In reply to Gavin ShanThe SDEI functionality is ready to be exported so far. This adds new capability (KVM_CAP_ARM_SDEI) and exports it.
--- arch/arm64/kvm/arm.c | 3 +++ include/uapi/linux/kvm.h | 1 + 2 files changed, 4 insertions(+)
arch/arm64/kvm/arm.c +3 -0
@@ -278,6 +278,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_ARM_PTRAUTH_GENERIC : r =system_has_full_ptr_auth ();break ; +case KVM_CAP_ARM_SDEI : + r =1 ; +break ;default : r =0 ; }
include/uapi/linux/kvm.h +1 -0
@@ -1112,6 +1112,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_BINARY_STATS_FD 203#define KVM_CAP_EXIT_ON_EMULATION_FAILURE 204#define KVM_CAP_ARM_MTE 205 +#define KVM_CAP_ARM_SDEI 206#ifdef KVM_CAP_IRQ_ROUTING
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 20/21] KVM: arm64: Export SDEI capability
Quoted 2 lines · Gavin Shan
The SDEI functionality is ready to be exported so far. This adds new capability (
KVM_CAP_ARM_SDEI) and exports it.
Need to be documented inkvm/api.rst
as the rest of the API
Eric
Quoted 27 lines
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/arm.c | 3 +++ include/uapi/linux/kvm.h | 1 + 2 files changed, 4 insertions(+)arch/arm64/kvm/arm.c +3
-0@@ -278,6 +278,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_ARM_PTRAUTH_GENERIC : r =system_has_full_ptr_auth ();break ; +case KVM_CAP_ARM_SDEI : + r =1 ; +break ;default : r =0 ; }include/uapi/linux/kvm.h +0
-0
include/uapi/linux/kvm.h struct kvm_ppc_resize_hpt { · line 1118
Quoted 7 lines
include/uapi/linux/kvm.h +1
-0@@ -1112,6 +1112,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_BINARY_STATS_FD 203#define KVM_CAP_EXIT_ON_EMULATION_FAILURE 204#define KVM_CAP_ARM_MTE 205 +#define KVM_CAP_ARM_SDEI 206#ifdef KVM_CAP_IRQ_ROUTING
Eric
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 20/21] KVM: arm64: Export SDEI capability
Quoted 8 lines · Eric Auger
Quoted 2 lines · Gavin Shan
The SDEI functionality is ready to be exported so far. This adds new capability (
KVM_CAP_ARM_SDEI) and exports it.Need to be documented in
kvm/api.rst
as the rest of the API
Ok, Thanks, Eric :)
Quoted 31 lines
Quoted 31 lines
Signed-off-by Gavin Shan <[email protected]>--- arch/arm64/kvm/arm.c | 3 +++ include/uapi/linux/kvm.h | 1 + 2 files changed, 4 insertions(+)arch/arm64/kvm/arm.c +3
-0@@ -278,6 +278,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_ARM_PTRAUTH_GENERIC : r =system_has_full_ptr_auth ();break ; +case KVM_CAP_ARM_SDEI : + r =1 ; +break ;default : r =0 ; }include/uapi/linux/kvm.h +1
-0@@ -1112,6 +1112,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_BINARY_STATS_FD 203#define KVM_CAP_EXIT_ON_EMULATION_FAILURE 204#define KVM_CAP_ARM_MTE 205 +#define KVM_CAP_ARM_SDEI 206
Quoted 5 lines
include/uapi/linux/kvm.h struct kvm_ppc_resize_hpt { · line 1118
Quoted 3 lines
include/uapi/linux/kvm.h +0
-0#ifdef KVM_CAP_IRQ_ROUTING Eric
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 21/21 KVM: selftests: Add SDEI test case
In reply to Gavin ShanThis adds SDEI test case into selftests where the various hypercalls are issued to kvm private event (0x40200000) and then ensure that's completed without error. Note that two vCPUs are started up by default to run same consequence. Actually, it's simulating what SDEI client driver does and the following hypercalls are issued in sequence:
SDEI_1_0_FN_SDEI_VERSION (probing SDEI capability) SDEI_1_0_FN_SDEI_PE_UNMASK (CPU online) SDEI_1_0_FN_SDEI_PRIVATE_RESET (restart SDEI) SDEI_1_0_FN_SDEI_SHARED_RESET SDEI_1_0_FN_SDEI_EVENT_GET_INFO (register event) SDEI_1_0_FN_SDEI_EVENT_GET_INFO SDEI_1_0_FN_SDEI_EVENT_GET_INFO SDEI_1_0_FN_SDEI_EVENT_REGISTER SDEI_1_0_FN_SDEI_EVENT_ENABLE (enable event) SDEI_1_0_FN_SDEI_EVENT_DISABLE (disable event) SDEI_1_0_FN_SDEI_EVENT_UNREGISTER (unregister event) SDEI_1_0_FN_SDEI_PE_MASK (CPU offline)
--- tools/testing/selftests/kvm/Makefile | 1 + tools/testing/selftests/kvm/aarch64/sdei.c | 171 +++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 tools/testing/selftests/kvm/aarch64/sdei.c
tools/testing/selftests/kvm/Makefile +1 -0
@@ -87,6 +87,7 @@ TEST_GEN_PROGS_x86_64 += kvm_binary_stats_test TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list TEST_GEN_PROGS_aarch64 += aarch64/vgic_init +TEST_GEN_PROGS_aarch64 += aarch64/sdei TEST_GEN_PROGS_aarch64 += demand_paging_test TEST_GEN_PROGS_aarch64 += dirty_log_test TEST_GEN_PROGS_aarch64 += dirty_log_perf_test
tools/testing/selftests/kvm/aarch64/sdei.c new file +171 -0
171 lines not on this page · raw message
Signature · 6 lines
2.23.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 39 lines · Gavin Shan
This series intends to virtualize Software Delegated Exception Interface (SDEI), which is defined by DEN0054A. It allows the hypervisor to deliver NMI-alike event to guest and it's needed by asynchronous page fault to deliver page-not-present notification from hypervisor to guest. The code and the required qemu changes can be found from:
https://developer.arm.com/documentation/den0054/latest https://github.com/gwshan/linux ("kvm/arm64_sdei") https://github.com/gwshan/qemu ("kvm/arm64_sdei")The SDEI event is identified by a 32-bits number. Bits[31:24] are used to indicate the SDEI event properties while bits[23:0] are identifying the unique number. The implementation takes bits[23:22] to indicate the owner of the SDEI event. For example, those SDEI events owned by KVM should have these two bits set to 0b01. Besides, the implementation supports SDEI events owned by KVM only.
The design is pretty straightforward and the implementation is just following the SDEI specification, to support the defined SMCCC intefaces, except the IRQ binding stuff. There are several data structures introduced. Some of the objects have to be migrated by VMM. So their definitions are split up for VMM to include the corresponding states for migration.
struct
kvm_sdei_kvm
Associated with VM and used to track the KVM exposed SDEI events and those registered by guest.
structkvm_sdei_vcpu
Associated with vCPU and used to track SDEI event delivery. The preempted context is saved prior to the delivery and restored after that.
structkvm_sdei_event
SDEI events exposed by KVM so that guest can register and enable.
structkvm_sdei_kvm_event
SDEI events that have been registered by guest.
structkvm_sdei_vcpu_event
SDEI events that have been queued to specific vCPU for delivery.The series is organized as below:
Quoted 9 lines
PATCH[01] Introduces template for
smccc_get_argx()
PATCH[02] Introduces the data structures and infrastructure
PATCH[03-14] Supports various SDEI related hypercalls
PATCH[15] Supports SDEI event notification
PATCH[16-17] Introduces ioctl command for migration PATCH[18-19] Supports SDEI event injection and cancellation
PATCH[20] Exports SDEI capability
PATCH[21] Adds self-test case for SDEI virtualization
[...]
I explicitly copied James Morse and Mark Rutland when posting the series, but something unknown went wrong. I'm including them here to avoid reposting the whole series.
Thanks,
Gavin
Hi Gavin,
Quoted 51 lines · Gavin Shan
Quoted 40 lines · Gavin Shan
This series intends to virtualize Software Delegated Exception Interface (SDEI), which is defined by DEN0054A. It allows the hypervisor to deliver NMI-alike event to guest and it's needed by asynchronous page fault to deliver page-not-present notification from hypervisor to guest. The code and the required qemu changes can be found from:
https://developer.arm.com/documentation/den0054/latest
https://github.com/gwshan/linux ("kvm/arm64_sdei")
https://github.com/gwshan/qemu ("kvm/arm64_sdei")The SDEI event is identified by a 32-bits number. Bits[31:24] are used to indicate the SDEI event properties while bits[23:0] are identifying the unique number. The implementation takes bits[23:22] to indicate the owner of the SDEI event. For example, those SDEI events owned by KVM should have these two bits set to 0b01. Besides, the implementation supports SDEI events owned by KVM only.
The design is pretty straightforward and the implementation is just following the SDEI specification, to support the defined SMCCC intefaces, except the IRQ binding stuff. There are several data structures introduced.
Some of the objects have to be migrated by VMM. So their definitions are split up for VMM to include the corresponding states for migration.struct
kvm_sdei_kvm
Associated with VM and used to track the KVM exposed SDEI events and those registered by guest.
structkvm_sdei_vcpu
Associated with vCPU and used to track SDEI event delivery. The preempted context is saved prior to the delivery and restored after that.
structkvm_sdei_event
SDEI events exposed by KVM so that guest can register and enable. structkvm_sdei_kvm_event
SDEI events that have been registered by guest. structkvm_sdei_vcpu_event
SDEI events that have been queued to specific vCPU for delivery.The series is organized as below:
Quoted 9 lines
PATCH[01] Introduces template for
smccc_get_argx()PATCH[02] Introduces the data structures and infrastructure PATCH[03-14] Supports various SDEI related hypercalls PATCH[15] Supports SDEI event notification PATCH[16-17] Introduces ioctl command for migration PATCH[18-19] Supports SDEI event injection and cancellation PATCH[20] Exports SDEI capability
PATCH[21] Adds self-test case for SDEI virtualization
Quoted 5 lines
[...]
I explicitly copied James Morse and Mark Rutland when posting the series, but something unknown went wrong. I'm including them here to avoid reposting the whole series.
I don't see James nor Mark included here either
Eric
Quoted 9 lines
Thanks,
Gavin_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Hi Eric,
Quoted 52 lines · Eric Auger
Quoted 51 lines · Gavin Shan
Quoted 49 lines · Gavin Shan
This series intends to virtualize Software Delegated Exception Interface (SDEI), which is defined by DEN0054A. It allows the hypervisor to deliver NMI-alike event to guest and it's needed by asynchronous page fault to deliver page-not-present notification from hypervisor to guest. The code and the required qemu changes can be found from:
https://developer.arm.com/documentation/den0054/latest
https://github.com/gwshan/linux ("kvm/arm64_sdei")
https://github.com/gwshan/qemu ("kvm/arm64_sdei")The SDEI event is identified by a 32-bits number. Bits[31:24] are used to indicate the SDEI event properties while bits[23:0] are identifying the unique number. The implementation takes bits[23:22] to indicate the owner of the SDEI event. For example, those SDEI events owned by KVM should have these two bits set to 0b01. Besides, the implementation supports SDEI events owned by KVM only.
The design is pretty straightforward and the implementation is just following the SDEI specification, to support the defined SMCCC intefaces, except the IRQ binding stuff. There are several data structures introduced.
Some of the objects have to be migrated by VMM. So their definitions are split up for VMM to include the corresponding states for migration.struct
kvm_sdei_kvm
Associated with VM and used to track the KVM exposed SDEI events and those registered by guest.
structkvm_sdei_vcpu
Associated with vCPU and used to track SDEI event delivery. The preempted context is saved prior to the delivery and restored after that.
structkvm_sdei_event
SDEI events exposed by KVM so that guest can register and enable. structkvm_sdei_kvm_event
SDEI events that have been registered by guest. structkvm_sdei_vcpu_event
SDEI events that have been queued to specific vCPU for delivery.The series is organized as below:
PATCH[01] Introduces template for
smccc_get_argx()PATCH[02] Introduces the data structures and infrastructure PATCH[03-14] Supports various SDEI related hypercalls PATCH[15] Supports SDEI event notification PATCH[16-17] Introduces ioctl command for migration PATCH[18-19] Supports SDEI event injection and cancellation PATCH[20] Exports SDEI capability
PATCH[21] Adds self-test case for SDEI virtualization
Quoted 7 lines
Quoted 5 lines
[...]
I explicitly copied James Morse and Mark Rutland when posting the series, but something unknown went wrong. I'm including them here to avoid reposting the whole series.
I don't see James nor Mark included here either
Yeah, I used the following command to post the series, but I don't know why James/Mark are missed. I'm not sure it's git-sendemail issue or not so far. The issue appears some times on my laptop :)
# git-sendemail --to=<mail0> --cc=<mail1> --cc=<mail2> *.patch
Thanks,
Gavin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm