support exception state migration and set VSESR_EL2 by user space
Subsystems (5)
v7 cover support exception state migration and set VSESR_EL2 by user space
Hi guys,
This is GengDongjiu's get/set events series[0], with additional plumbing for 32bit.
This series adds the get/set events API to KVM for arm/arm64 so that user-space can migrate pending SError, (which KVM may have made pending as part of its device emulation), and for RAS make a new SError with a specific ESR value pending. (Only systems with the v8.2 RAS Extensions can specify an ESR, KVM advertises this capability with a new cap:KVM_CAP_ARM_INJECT_SERROR_ESR)
User-space can use this for emulation of the v8.2 CPU RAS features (using error nodes backed by mmio) or as part of NOTIFY_SEI which extends a v8.2 RAS SError to also have firmware-first CPER records.
Thanks,
James
[0] https://lists.cs.columbia.edu/pipermail/kvmarm/2018-July/032010.html
Dongjiu Geng (2):
arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS
arm64: KVM: export the capability to set guest SError syndrome
James Morse (2):
KVM: arm64: Share the parts of get/set events useful to 32bit
KVM: arm: Add 32bit get/set events support
Documentation/virtual/kvm/api.txt | 44 +++++++++++++++++++++++--- arch/arm/include/asm/kvm_host.h | 5 +++ arch/arm/include/uapi/asm/kvm.h | 13 ++++++++ arch/arm/kvm/guest.c | 23 ++++++++++++++ arch/arm64/include/asm/kvm_emulate.h | 5 +++ arch/arm64/include/asm/kvm_host.h | 7 +++++ arch/arm64/include/uapi/asm/kvm.h | 13 ++++++++ arch/arm64/kvm/guest.c | 33 +++++++++++++++++++ arch/arm64/kvm/inject_fault.c | 6 ++-- arch/arm64/kvm/reset.c | 4 +++ include/uapi/linux/kvm.h | 1 + virt/kvm/arm/arm.c | 47 ++++++++++++++++++++++++++++ 12 files changed, 194 insertions(+), 7 deletions(-)
Signature · 1 line
2.18.0
PATCH v7 1/4 arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS
From: Dongjiu Geng <[email protected]>
For the migrating VMs, user space may need to know the exception state. For example, in the machine A, KVM make an SError pending, when migrate to B, KVM also needs to pend an SError.
This new IOCTL exports user-invisible states related to SError. Together with appropriate user space changes, user space can get/set the SError exception state to do migrate/snapshot/suspend.
--- Documentation/virtual/kvm/api.txt | 33 +++++++++++++++++--- arch/arm64/include/asm/kvm_emulate.h | 5 +++ arch/arm64/include/asm/kvm_host.h | 7 +++++ arch/arm64/include/uapi/asm/kvm.h | 13 ++++++++ arch/arm64/kvm/guest.c | 46 ++++++++++++++++++++++++++++ arch/arm64/kvm/inject_fault.c | 6 ++-- arch/arm64/kvm/reset.c | 1 + virt/kvm/arm/arm.c | 21 +++++++++++++ 8 files changed, 125 insertions(+), 7 deletions(-)
Documentation/virtual/kvm/api.txt +29 -4
@@ -835,11 +835,13 @@ struct kvm_clock_data { Capability: KVM_CAP_VCPU_EVENTS Extended by: KVM_CAP_INTR_SHADOW -Architectures: x86 -Type: vm ioctl +Architectures: x86, arm64 +Type: vcpu ioctl Parameters: struct kvm_vcpu_event (out) Returns: 0 on success, -1 on error +X86: + Gets currently pending exceptions, interrupts, and NMIs as well as related states of the vcpu.
@@ -881,15 +883,32 @@ Only two fields are defined in the flags field: - KVM_VCPUEVENT_VALID_SMM may be set in the flags field to signal that smi contains a valid state. +ARM64: + +Gets currently pending SError exceptions as well as related states of the vcpu. + +struct kvm_vcpu_events { + struct { + __u8 serror_pending; + __u8 serror_has_esr; + /* Align it to 8 bytes */ + __u8 pad[6]; + __u64 serror_esr; + } exception; + __u32 reserved[12]; +}; + 4.32 KVM_SET_VCPU_EVENTS Capability: KVM_CAP_VCPU_EVENTS Extended by: KVM_CAP_INTR_SHADOW -Architectures: x86 -Type: vm ioctl +Architectures: x86, arm64 +Type: vcpu ioctl Parameters: struct kvm_vcpu_event (in) Returns: 0 on success, -1 on error +X86: + Set pending exceptions, interrupts, and NMIs as well as related states of the vcpu.
@@ -910,6 +929,12 @@ shall be written into the VCPU. KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available. +ARM64: + +Set pending SError exceptions as well as related states of the vcpu. + +See KVM_GET_VCPU_EVENTS for the data structure. + 4.33 KVM_GET_DEBUGREGS
arch/arm64/include/asm/kvm_emulate.h +5 -0
@@ -81,6 +81,11 @@ static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu)return (unsigned long *)&vcpu->arch.hcr_el2; } +static inline unsigned long vcpu_get_vsesr (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.vsesr_el2; +} +static inline void vcpu_set_vsesr (struct kvm_vcpu *vcpu,u64 vsesr) { vcpu->arch.vsesr_el2 = vsesr;
arch/arm64/include/asm/kvm_host.h +7 -0
@@ -350,6 +350,11 @@ unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);int kvm_arm_copy_reg_indices (struct kvm_vcpu *vcpu,u64 __user *indices);int kvm_arm_get_reg (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg);int kvm_arm_set_reg (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg); +int kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events); + +int kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events);#define KVM_ARCH_WANT_MMU_NOTIFIER int kvm_unmap_hva (struct kvm *kvm,unsigned long hva);
@@ -378,6 +383,8 @@ void handle_exit_early(struct kvm_vcpu *vcpu, struct kvm_run *run,int kvm_perf_init (void );int kvm_perf_teardown (void ); +void kvm_set_sei_esr (struct kvm_vcpu *vcpu,u64 syndrome); +struct kvm_vcpu *kvm_mpidr_to_vcpu (struct kvm *kvm,unsigned long mpidr);void __kvm_set_tpidr_el2 (u64 tpidr_el2);
arch/arm64/include/uapi/asm/kvm.h +13 -0
@@ -39,6 +39,7 @@#define __KVM_HAVE_GUEST_DEBUG#define __KVM_HAVE_IRQ_LINE#define __KVM_HAVE_READONLY_MEM +#define __KVM_HAVE_VCPU_EVENTS#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
@@ -154,6 +155,18 @@ struct kvm_sync_regs {struct kvm_arch_memory_slot { }; +/* for KVM_GET/SET_VCPU_EVENTS */ +struct kvm_vcpu_events { +struct { +__u8 serror_pending; +__u8 serror_has_esr; +/* Align it to 8 bytes */ +__u8 pad[6 ]; +__u64 serror_esr; + } exception; +__u32 reserved[12 ]; +}; +/* If you need to interpret the index values, here is the key: */ #define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000#define KVM_REG_ARM_COPROC_SHIFT 16
arch/arm64/kvm/guest.c +46 -0
52 lines not on this page · raw message
arch/arm64/kvm/inject_fault.c +3 -3
@@ -164,9 +164,9 @@ void kvm_inject_undefined(struct kvm_vcpu *vcpu)inject_undef64 (vcpu); } -static void pend_guest_serror (struct kvm_vcpu *vcpu,u64 esr) +void kvm_set_sei_esr (struct kvm_vcpu *vcpu,u64 esr) { -vcpu_set_vsesr (vcpu, esr); +vcpu_set_vsesr (vcpu, esr & ESR_ELx_ISS_MASK); *vcpu_hcr (vcpu) |=HCR_VSE ; }
@@ -184,5 +184,5 @@ static void pend_guest_serror(struct kvm_vcpu *vcpu, u64 esr)*/ void kvm_inject_vabt (struct kvm_vcpu *vcpu) { -pend_guest_serror (vcpu, ESR_ELx_ISV); +kvm_set_sei_esr (vcpu, ESR_ELx_ISV); }
arch/arm64/kvm/reset.c +1 -0
@@ -79,6 +79,7 @@ int kvm_arch_dev_ioctl_check_extension(struct kvm *kvm, long ext)break ;case KVM_CAP_SET_GUEST_DEBUG :case KVM_CAP_VCPU_ATTRIBUTES : +case KVM_CAP_VCPU_EVENTS : r =1 ;break ;default :
virt/kvm/arm/arm.c +21 -0
@@ -1124,6 +1124,27 @@ long kvm_arch_vcpu_ioctl(struct file *filp, r =kvm_arm_vcpu_has_attr (vcpu, &attr);break ; } +#ifdef __KVM_HAVE_VCPU_EVENTS +case KVM_GET_VCPU_EVENTS : { +struct kvm_vcpu_events events; + +if (kvm_arm_vcpu_get_events (vcpu, &events)) +return -EINVAL ; + +if (copy_to_user (argp, &events,sizeof (events))) +return -EFAULT ; + +return 0 ; + } +case KVM_SET_VCPU_EVENTS : { +struct kvm_vcpu_events events; + +if (copy_from_user (&events, argp,sizeof (events))) +return -EFAULT ; + +return kvm_arm_vcpu_set_events (vcpu, &events); + } +#endif default : r = -EINVAL ; }
Signature · 1 line
2.18.0
Re: [PATCH v7 1/4] arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS
Hi, James,
[...]
Documentation/virtual/kvm/api.txt struct kvm_clock_data { · line 838
Quoted 11 lines
Documentation/virtual/kvm/api.txt +1
-2@@ -835,11 +835,13 @@ struct kvm_clock_data { Capability: KVM_CAP_VCPU_EVENTS Extended by: KVM_CAP_INTR_SHADOW -Architectures: x86 -Type: vm ioctl +Architectures: x86, arm64
In my previous patch, I only add the arm64 support, now you add patches to support arm32 platform, so you can add "ARM" to the Architectures, for example: "Architectures: x86, ARM, arm64"
Quoted 10 lines
Documentation/virtual/kvm/api.txt +3
-0+Type: vcpu ioctl Parameters: struct kvm_vcpu_event (out) Returns: 0 on success, -1 on error +X86: + Gets currently pending exceptions, interrupts, and NMIs as well as related states of the vcpu.
Documentation/virtual/kvm/api.txt Only two fields are defined in the flags field: · line 886
Quoted 4 lines
Documentation/virtual/kvm/api.txt +1
-0@@ -881,15 +883,32 @@ Only two fields are defined in the flags field: - KVM_VCPUEVENT_VALID_SMM may be set in the flags field to signal that smi contains a valid state. +ARM64:
"ARM, ARM64:" or "arm/arm64:"
Quoted 11 lines
Documentation/virtual/kvm/api.txt +11
-0+ +Gets currently pending SError exceptions as well as related states of the vcpu. + +struct kvm_vcpu_events { + struct { + __u8 serror_pending; + __u8 serror_has_esr; + /* Align it to 8 bytes */ + __u8 pad[6]; + __u64 serror_esr; + } exception;
Documentation/virtual/kvm/api.txt Only two fields are defined in the flags field: · line 905
Quoted 10 lines
Documentation/virtual/kvm/api.txt +4
-2+ __u32 reserved[12]; +}; + 4.32 KVM_SET_VCPU_EVENTS Capability: KVM_CAP_VCPU_EVENTS Extended by: KVM_CAP_INTR_SHADOW -Architectures: x86 -Type: vm ioctl +Architectures: x86, arm64
+Architectures: x86, ARM, arm64
Quoted 10 lines
Documentation/virtual/kvm/api.txt +3
-0+Type: vcpu ioctl Parameters: struct kvm_vcpu_event (in) Returns: 0 on success, -1 on error +X86: + Set pending exceptions, interrupts, and NMIs as well as related states of the vcpu.
Documentation/virtual/kvm/api.txt shall be written into the VCPU. · line 932
Quoted 4 lines
Documentation/virtual/kvm/api.txt +1
-0@@ -910,6 +929,12 @@ shall be written into the VCPU. KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available. +ARM64:
"ARM, ARM64:" or "arm/arm64:"
Quoted 2 lines
Documentation/virtual/kvm/api.txt +2
-0+ +Set pending SError exceptions as well as related states of the vcpu.
[...]
Re: [PATCH v7 1/4] arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS
Quoted 9 lines · gengdongjiu
Hi, James,
[...]
Quoted 6 lines
Documentation/virtual/kvm/api.txt +0
-0@@ -835,11 +835,13 @@ struct kvm_clock_data {
Quoted 8 lines
Documentation/virtual/kvm/api.txt struct kvm_clock_data { · line 838
Quoted 5 lines
Documentation/virtual/kvm/api.txt +1
-2Capability: KVM_CAP_VCPU_EVENTS Extended by: KVM_CAP_INTR_SHADOW -Architectures: x86 -Type: vm ioctl +Architectures: x86, arm64In my previous patch, I only add the arm64 support, now you add patches to support arm32 platform, so you can add "ARM" to the Architectures, for example: "Architectures: x86, ARM, arm64"
That should be the job of the last patch, shouldn't it? At this point in the series, there is no 32bit support whatsoever.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v7 2/4 arm64: KVM: export the capability to set guest SError syndrome
In reply to James MorseFrom: Dongjiu Geng <[email protected]>
For the arm64 RAS Extension, user space can inject a virtual-SError with specified ESR. So user space needs to know whether KVM support to inject such SError, this interface adds this query for this capability.
KVM will check whether system support RAS Extension, if supported, KVM returns true to user space, otherwise returns false.
--- Documentation/virtual/kvm/api.txt | 11 +++++++++++ arch/arm64/kvm/reset.c | 3 +++ include/uapi/linux/kvm.h | 1 + 3 files changed, 15 insertions(+)
Documentation/virtual/kvm/api.txt +11 -0
@@ -4643,3 +4643,14 @@ This capability indicates that KVM supports paravirtualized Hyper-V TLB Flush hypercalls: HvFlushVirtualAddressSpace, HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressList, HvFlushVirtualAddressListEx. + +8.19 KVM_CAP_ARM_SET_SERROR_ESR + +Architectures: arm, arm64 + +This capability indicates that userspace can specify the syndrome value reported +to the guest OS when guest takes a virtual SError interrupt exception. +If KVM has this capability, userspace can only specify the ISS field for the ESR +syndrome, it can not specify the EC field which is not under control by KVM. +If this virtual SError is taken to EL1 using AArch64, this value will be reported +in ISS filed of ESR_EL1.
arch/arm64/kvm/reset.c +3 -0
@@ -77,6 +77,9 @@ int kvm_arch_dev_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_ARM_PMU_V3 : r =kvm_arm_support_pmu_v3 ();break ; +case KVM_CAP_ARM_INJECT_SERROR_ESR : + r =cpus_have_const_cap (ARM64_HAS_RAS_EXTN ); +break ;case KVM_CAP_SET_GUEST_DEBUG :case KVM_CAP_VCPU_ATTRIBUTES :case KVM_CAP_VCPU_EVENTS :
include/uapi/linux/kvm.h +1 -0
@@ -949,6 +949,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_GET_MSR_FEATURES 153#define KVM_CAP_HYPERV_EVENTFD 154#define KVM_CAP_HYPERV_TLBFLUSH 155 +#define KVM_CAP_ARM_INJECT_SERROR_ESR 156#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
2.18.0
PATCH v7 3/4 KVM: arm64: Share the parts of get/set events useful to 32bit
In reply to James MorseThe get/set events helpers to do some work to check reserved and padding fields are zero. This is useful on 32bit too.
Move this code into virt/kvm/arm/arm.c, and give the arch code some underscores.
This is temporarily hidden behind __KVM_HAVE_VCPU_EVENTS until 32bit is wired up.
--- arch/arm64/include/asm/kvm_host.h | 8 ++++---- arch/arm64/kvm/guest.c | 21 ++++----------------- virt/kvm/arm/arm.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 21 deletions(-)
arch/arm64/include/asm/kvm_host.h +4 -4
@@ -350,11 +350,11 @@ unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);int kvm_arm_copy_reg_indices (struct kvm_vcpu *vcpu,u64 __user *indices);int kvm_arm_get_reg (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg);int kvm_arm_set_reg (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg); -int kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, -struct kvm_vcpu_events *events); +int __kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events); -int kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, -struct kvm_vcpu_events *events); +int __kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events);#define KVM_ARCH_WANT_MMU_NOTIFIER int kvm_unmap_hva (struct kvm *kvm,unsigned long hva);
arch/arm64/kvm/guest.c +4 -17
@@ -289,11 +289,9 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,return -EINVAL ; } -int kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, -struct kvm_vcpu_events *events) +int __kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events) { -memset (events,0 ,sizeof (*events)); - events->exception.serror_pending = !!(vcpu->arch.hcr_el2 &HCR_VSE ); events->exception.serror_has_esr =cpus_have_const_cap (ARM64_HAS_RAS_EXTN );
@@ -303,23 +301,12 @@ int kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,return 0 ; } -int kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, -struct kvm_vcpu_events *events) +int __kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events) { -int i;bool serror_pending = events->exception.serror_pending;bool has_esr = events->exception.serror_has_esr; -/* check whether the reserved field is zero */ -for (i =0 ; i <ARRAY_SIZE (events->reserved); i++) -if (events->reserved[i]) -return -EINVAL ; - -/* check whether the pad field is zero */ -for (i =0 ; i <ARRAY_SIZE (events->exception.pad); i++) -if (events->exception.pad[i]) -return -EINVAL ; -if (serror_pending && has_esr) {if (!cpus_have_const_cap (ARM64_HAS_RAS_EXTN ))return -EINVAL ;
virt/kvm/arm/arm.c +28 -0
@@ -1044,6 +1044,34 @@ static int kvm_arm_vcpu_has_attr(struct kvm_vcpu *vcpu,return ret; } +#ifdef __KVM_HAVE_VCPU_EVENTS/* temporary: until 32bit is wired up */ +static int kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events) +{ +memset (events,0 ,sizeof (*events)); + +return __kvm_arm_vcpu_get_events (vcpu, events); +} + +static int kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events) +{ +int i; + +/* check whether the reserved field is zero */ +for (i =0 ; i <ARRAY_SIZE (events->reserved); i++) +if (events->reserved[i]) +return -EINVAL ; + +/* check whether the pad field is zero */ +for (i =0 ; i <ARRAY_SIZE (events->exception.pad); i++) +if (events->exception.pad[i]) +return -EINVAL ; + +return __kvm_arm_vcpu_set_events (vcpu, events); +} +#endif /* __KVM_HAVE_VCPU_EVENTS */ +long kvm_arch_vcpu_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {
Signature · 1 line
2.18.0
Re: [PATCH v7 3/4] KVM: arm64: Share the parts of get/set events useful to 32bit
Hi James,
Quoted 106 lines · James Morse
The get/set events helpers to do some work to check reserved and padding fields are zero. This is useful on 32bit too.
Move this code into
virt/kvm/arm/arm.c, and give the arch code some underscores.This is temporarily hidden behind
__KVM_HAVE_VCPU_EVENTSuntil 32bit is wired up.Signed-off-by James Morse <[email protected]>CC Dongjiu Geng <[email protected]>--- arch/arm64/include/asm/kvm_host.h | 8 ++++---- arch/arm64/kvm/guest.c | 21 ++++----------------- virt/kvm/arm/arm.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 21 deletions(-)arch/arm64/include/asm/kvm_host.h +4
-4@@ -350,11 +350,11 @@ unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);int kvm_arm_copy_reg_indices (struct kvm_vcpu *vcpu,u64 __user *indices);int kvm_arm_get_reg (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg);int kvm_arm_set_reg (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg); -int kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, -struct kvm_vcpu_events *events); +int __kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events); -int kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, -struct kvm_vcpu_events *events); +int __kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events);#define KVM_ARCH_WANT_MMU_NOTIFIER int kvm_unmap_hva (struct kvm *kvm,unsigned long hva);arch/arm64/kvm/guest.c +4
-17@@ -289,11 +289,9 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,return -EINVAL ; } -int kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, -struct kvm_vcpu_events *events) +int __kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events) { -memset (events,0 ,sizeof (*events)); - events->exception.serror_pending = !!(vcpu->arch.hcr_el2 &HCR_VSE ); events->exception.serror_has_esr =cpus_have_const_cap (ARM64_HAS_RAS_EXTN );@@ -303,23 +301,12 @@ int kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,return 0 ; } -int kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, -struct kvm_vcpu_events *events) +int __kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events) { -int i;bool serror_pending = events->exception.serror_pending;bool has_esr = events->exception.serror_has_esr; -/* check whether the reserved field is zero */ -for (i =0 ; i <ARRAY_SIZE (events->reserved); i++) -if (events->reserved[i]) -return -EINVAL ; - -/* check whether the pad field is zero */ -for (i =0 ; i <ARRAY_SIZE (events->exception.pad); i++) -if (events->exception.pad[i]) -return -EINVAL ; -if (serror_pending && has_esr) {if (!cpus_have_const_cap (ARM64_HAS_RAS_EXTN ))return -EINVAL ;virt/kvm/arm/arm.c +17
-0@@ -1044,6 +1044,34 @@ static int kvm_arm_vcpu_has_attr(struct kvm_vcpu *vcpu,return ret; } +#ifdef __KVM_HAVE_VCPU_EVENTS/* temporary: until 32bit is wired up */ +static int kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events) +{ +memset (events,0 ,sizeof (*events)); + +return __kvm_arm_vcpu_get_events (vcpu, events); +} + +static int kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events) +{ +int i; + +/* check whether the reserved field is zero */ +for (i =0 ; i <ARRAY_SIZE (events->reserved); i++) +if (events->reserved[i])
virt/kvm/arm/arm.c static int kvm_arm_vcpu_has_attr(struct kvm_vcpu *vcpu, · line 1073
Quoted 10 lines
virt/kvm/arm/arm.c +10
-0+return -EINVAL ; + +/* check whether the pad field is zero */ +for (i =0 ; i <ARRAY_SIZE (events->exception.pad); i++) +if (events->exception.pad[i]) +return -EINVAL ; + + return __kvm_arm_vcpu_set_events(vcpu, events); +} +#endif /* __KVM_HAVE_VCPU_EVENTS */
In [PATCH v7 4/4] KVM: arm: Add 32bit get/set events support, I see you remove "__KVM_HAVE_VCPU_EVENTS" in kvm_arch_vcpu_ioctl() but here it adds, it looks like strange.
so maybe it is better keep it in both place, or remove them both.
Quoted 7 lines
From the comments /* temporary: until 32bit is wired up */, do you forget to remove the
__KVM_HAVE_VCPU_EVENTSafter wiring up the 32bit?virt/kvm/arm/arm.c +1
-0+long kvm_arch_vcpu_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {
Re: [PATCH v7 3/4] KVM: arm64: Share the parts of get/set events useful to 32bit
Hi gengdongjiu,
Quoted 17 lines · gengdongjiu
Quoted 16 lines · James Morse
The get/set events helpers to do some work to check reserved and padding fields are zero. This is useful on 32bit too.
Move this code into
virt/kvm/arm/arm.c, and give the arch code some underscores.This is temporarily hidden behind
__KVM_HAVE_VCPU_EVENTSuntil 32bit is wired up.virt/kvm/arm/arm.c +1
-0@@ -1044,6 +1044,34 @@ static int kvm_arm_vcpu_has_attr(struct kvm_vcpu *vcpu, +#ifdef __KVM_HAVE_VCPU_EVENTS/* temporary: until 32bit is wired up */
[..]
Quoted 8 lines
Quoted 1 line
+#endif /*
__KVM_HAVE_VCPU_EVENTS*/In [PATCH v7 4/4] KVM: arm: Add 32bit get/set events support, I see you> remove "
__KVM_HAVE_VCPU_EVENTS" inkvm_arch_vcpu_ioctl()but here it adds, it looks like strange.
so maybe it is better keep it in both place, or remove them both.From the comments /* temporary: until 32bit is wired up */, do you forget
to remove the__KVM_HAVE_VCPU_EVENTSafter wiring up the 32bit?
Indeed I did, the 'temporary' note was meant to remind me! (and I forgot about the documentation too)
Thanks!
James
PATCH v7 4/4 KVM: arm: Add 32bit get/set events support
In reply to James Morsearm64's new use of KVMs get_events/set_events API calls isn't just for RAS, it allows an SError that has been made pending by KVM as part of its device emulation to be migrated.
Wire this up for 32bit too.
We only need to read/write the HCR_VA bit, and check that no esr has been provided, as we don't yet support VDFSR.
--- arch/arm/include/asm/kvm_host.h | 5 +++++ arch/arm/include/uapi/asm/kvm.h | 13 +++++++++++++ arch/arm/kvm/guest.c | 23 +++++++++++++++++++++++ virt/kvm/arm/arm.c | 2 -- 4 files changed, 41 insertions(+), 2 deletions(-)
arch/arm/include/asm/kvm_host.h +5 -0
@@ -216,6 +216,11 @@ int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);int kvm_arm_set_reg (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg);unsigned long kvm_call_hyp (void *hypfn, ...);void force_vm_exit (const cpumask_t *mask); +int __kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events); + +int __kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events);#define KVM_ARCH_WANT_MMU_NOTIFIER int kvm_unmap_hva (struct kvm *kvm,unsigned long hva);
arch/arm/include/uapi/asm/kvm.h +13 -0
@@ -27,6 +27,7 @@#define __KVM_HAVE_GUEST_DEBUG#define __KVM_HAVE_IRQ_LINE#define __KVM_HAVE_READONLY_MEM +#define __KVM_HAVE_VCPU_EVENTS#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
@@ -125,6 +126,18 @@ struct kvm_sync_regs {struct kvm_arch_memory_slot { }; +/* for KVM_GET/SET_VCPU_EVENTS */ +struct kvm_vcpu_events { +struct { +__u8 serror_pending; +__u8 serror_has_esr; +/* Align it to 8 bytes */ +__u8 pad[6 ]; +__u64 serror_esr; + } exception; +__u32 reserved[12 ]; +}; +/* If you need to interpret the index values, here is the key: */ #define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000#define KVM_REG_ARM_COPROC_SHIFT 16
arch/arm/kvm/guest.c +23 -0
@@ -261,6 +261,29 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,return -EINVAL ; } + +int __kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events) +{ + events->exception.serror_pending = !!(*vcpu_hcr (vcpu) &HCR_VA ); + +return 0 ; +} + +int __kvm_arm_vcpu_set_events (struct kvm_vcpu *vcpu, +struct kvm_vcpu_events *events) +{ +bool serror_pending = events->exception.serror_pending; +bool has_esr = events->exception.serror_has_esr; + +if (serror_pending && has_esr) +return -EINVAL ; +else if (serror_pending) +kvm_inject_vabt (vcpu); + +return 0 ; +} + int __attribute_const__ kvm_target_cpu(void) {switch (read_cpuid_part ()) {
virt/kvm/arm/arm.c +0 -2
@@ -1152,7 +1152,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp, r =kvm_arm_vcpu_has_attr (vcpu, &attr);break ; } -#ifdef __KVM_HAVE_VCPU_EVENTScase KVM_GET_VCPU_EVENTS : {struct kvm_vcpu_events events;
@@ -1172,7 +1171,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp,return kvm_arm_vcpu_set_events (vcpu, &events); } -#endif default : r = -EINVAL ; }
Signature · 1 line
2.18.0
Hi James,
Quoted 4 lines · James Morse
Hi guys,
This is GengDongjiu's get/set events series[0], with additional plumbing for 32bit.
Thanks for the extension to support 32bits platform, it is great
Quoted 41 lines
This series adds the get/set events API to KVM for arm/arm64 so that user-space can migrate pending SError, (which KVM may have made pending as part of its device emulation), and for RAS make a new SError with a specific ESR value pending. (Only systems with the v8.2 RAS Extensions can specify an ESR, KVM advertises this capability with a new cap:
KVM_CAP_ARM_INJECT_SERROR_ESR)User-space can use this for emulation of the v8.2 CPU RAS features (using error nodes backed by mmio) or as part of
NOTIFY_SEIwhich extends a v8.2 RAS SError to also have firmware-first CPER records.Thanks,
James
[0] https://lists.cs.columbia.edu/pipermail/kvmarm/2018-July/032010.html
Dongjiu Geng (2):
arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS
arm64: KVM: export the capability to set guest SError syndromeJames Morse (2):
KVM: arm64: Share the parts of get/set events useful to 32bit
KVM: arm: Add 32bit get/set events supportDocumentation/virtual/kvm/api.txt | 44 +++++++++++++++++++++++--- arch/arm/include/asm/kvm_host.h | 5 +++ arch/arm/include/uapi/asm/kvm.h | 13 ++++++++ arch/arm/kvm/guest.c | 23 ++++++++++++++ arch/arm64/include/asm/kvm_emulate.h | 5 +++ arch/arm64/include/asm/kvm_host.h | 7 +++++ arch/arm64/include/uapi/asm/kvm.h | 13 ++++++++ arch/arm64/kvm/guest.c | 33 +++++++++++++++++++ arch/arm64/kvm/inject_fault.c | 6 ++-- arch/arm64/kvm/reset.c | 4 +++ include/uapi/linux/kvm.h | 1 + virt/kvm/arm/arm.c | 47 ++++++++++++++++++++++++++++ 12 files changed, 194 insertions(+), 7 deletions(-)