explicit VGIC initialization in finalize function
v4 cover explicit VGIC initialization in finalize function
With current implementation the vgic is initialized implicitly, on-demand. This patch forces the init in the vgic finalize function. At that point all the dimensioning parameters are known.
A new group/attribute in VGIC KVM device is used for that:
KVM_DEV_ARM_VGIC_GRP_CTRL/KVM_DEV_ARM_VGIC_CTRL_INIT.
Among other things, this earlier VGIC initialization allows to have a simpler handling of VFIO. VFIO platform signaling can be setup on reset handler, making sure the VGIC is ready, at that time, to accept injected virtual IRQs.
Tested on Calxeda Midway with VFIO platform use case
Can be found on
http://git.linaro.org/people/eric.auger/qemu.git,
branch early_vgic_init_v4
v3 -> v4:
- now integrates all the header updates of update-linux-headers.sh applied on top of 4.0-rc2 kernel (and not a partial export as in v3).
- VIRTIO_TRANSPORT_F_END value needed to be changed to 33 in include/hw/virtio/virtio.h to fix a duplicate definition compilation error (also defined in virtio_config.h)
- integrates a new patch file that add export of virtio_types.h, now included by virtio_ring.h.
v2 -> v3:
- changed to a patch since the kernel dependency was pulled
v1 -> v2:
- The init is not mandated to be done in a machine init done notifier anymore since only the number of vcpus and number of IRQs must be known at init time.
Eric Auger (3):
update-linux-headers.sh: export virtio_types.h
linux-headers: update to 4.0-rc2
hw/intc/arm_gic: Initialize the vgic in the realize function
hw/intc/arm_gic_kvm.c | 6 +++++ include/hw/virtio/virtio.h | 4 +-- linux-headers/asm-arm/kvm.h | 2 ++ linux-headers/asm-arm64/kvm.h | 9 +++++++ linux-headers/asm-s390/kvm.h | 37 ++++++++++++++++++++++++++ linux-headers/asm-x86/hyperv.h | 11 ++++++++ linux-headers/linux/kvm.h | 20 +++++++------- linux-headers/linux/vfio.h | 1 + linux-headers/linux/virtio_config.h | 11 ++++++-- linux-headers/linux/virtio_ring.h | 52 +++++++++++++++++++++---------------- linux-headers/linux/virtio_types.h | 46 ++++++++++++++++++++++++++++++++ scripts/update-linux-headers.sh | 2 +- 12 files changed, 163 insertions(+), 38 deletions(-) create mode 100644 linux-headers/linux/virtio_types.h
Signature · 1 line
1.8.3.2
PATCH v4 1/3 update-linux-headers.sh: export virtio_types.h
virtio_ring.h now includes virtio_types.h. update-linux-headers.sh now exports this latter.
--- scripts/update-linux-headers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/update-linux-headers.sh +1 -1
@@ -62,7 +62,7 @@ done rm -rf "$output/linux-headers/linux" mkdir -p "$output/linux-headers/linux" for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h \ - psci.h; do + virtio_types.h psci.h; do cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux" done rm -rf "$output/linux-headers/asm-generic"
Signature · 1 line
1.8.3.2
Re: [PATCH v4 1/3] update-linux-headers.sh: export virtio_types.h
Quoted 4 lines · Eric Auger
virtio_ring.hnow includesvirtio_types.h.update-linux-headers.shnow exports this latter.Signed-off-by Eric Auger <[email protected]>
This is already included in my tree, but in a different place. Pull request sent today, pls wait for it to be pulled, don't apply this one.
Quoted 19 lines
--- scripts/update-linux-headers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/update-linux-headers.sh +1
-1@@ -62,7 +62,7 @@ done rm -rf "$output/linux-headers/linux" mkdir -p "$output/linux-headers/linux" for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h \ - psci.h; do + virtio_types.h psci.h; do cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux" done rm -rf "$output/linux-headers/asm-generic"Signature · 1 line
1.8.3.2
Re: [PATCH v4 1/3] update-linux-headers.sh: export virtio_types.h
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Eric Auger
virtio_ring.hnow includesvirtio_types.h.update-linux-headers.shnow exports this latter.Signed-off-by Eric Auger <[email protected]>This is already included in my tree, but in a different place. Pull request sent today, pls wait for it to be pulled, don't apply this one.
OK Thanks
- Eric
Quoted 22 lines
Quoted 22 lines
--- scripts/update-linux-headers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/update-linux-headers.sh +1
-1@@ -62,7 +62,7 @@ done rm -rf "$output/linux-headers/linux" mkdir -p "$output/linux-headers/linux" for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h \ - psci.h; do + virtio_types.h psci.h; do cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux" done rm -rf "$output/linux-headers/asm-generic"Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH v4 1/3] update-linux-headers.sh: export virtio_types.h
In reply to Michael S. TsirkinAm 04.03.2015 um 16:37 schrieb Michael S. Tsirkin:
Quoted 9 lines · Eric Auger
Quoted 4 lines
virtio_ring.hnow includesvirtio_types.h.update-linux-headers.shnow exports this latter.Signed-off-by Eric Auger <[email protected]>This is already included in my tree, but in a different place. Pull request sent today, pls wait for it to be pulled, don't apply this one.
The s390 tree also depends on the header update. So if my vote counts, I prefer to have that pull request sorted out sooner than later.
Peter, welcome back :-)
Quoted 23 lines
Quoted 22 lines
--- scripts/update-linux-headers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/update-linux-headers.sh +1
-1@@ -62,7 +62,7 @@ done rm -rf "$output/linux-headers/linux" mkdir -p "$output/linux-headers/linux" for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h \ - psci.h; do + virtio_types.h psci.h; do cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux" done rm -rf "$output/linux-headers/asm-generic"Signature · 1 line
1.8.3.2
PATCH v4 2/3 linux-headers: update to 4.0-rc2
In reply to Eric AugerThis updates the Linux header to version 4.0-rc2.
Besides virtio_config.h now sets VIRTIO_TRANSPORT_F_END to 33. Use the same value in duplicate definition located in include/hw/virtio/virtio.h.
--- include/hw/virtio/virtio.h | 4 +-- linux-headers/asm-arm/kvm.h | 2 ++ linux-headers/asm-arm64/kvm.h | 9 +++++++ linux-headers/asm-s390/kvm.h | 37 ++++++++++++++++++++++++++ linux-headers/asm-x86/hyperv.h | 11 ++++++++ linux-headers/linux/kvm.h | 20 +++++++------- linux-headers/linux/vfio.h | 1 + linux-headers/linux/virtio_config.h | 11 ++++++-- linux-headers/linux/virtio_ring.h | 52 +++++++++++++++++++++---------------- linux-headers/linux/virtio_types.h | 46 ++++++++++++++++++++++++++++++++ 10 files changed, 156 insertions(+), 37 deletions(-) create mode 100644 linux-headers/linux/virtio_types.h
include/hw/virtio/virtio.h +2 -2
@@ -35,10 +35,10 @@/* We've given up on this device. */ #define VIRTIO_CONFIG_S_FAILED 0x80 -/* Some virtio feature bits (currently bits 28 through 31) are reserved for the +/* Some virtio feature bits (currently bits 28 through 33) are reserved for the * transport being used (eg. virtio_ring), the rest are per-device feature bits. */ #define VIRTIO_TRANSPORT_F_START 28 -#define VIRTIO_TRANSPORT_F_END 32 +#define VIRTIO_TRANSPORT_F_END 33/* We notify when the ring is completely used, even if the guest is suppressing * callbacks */
linux-headers/asm-arm/kvm.h +2 -0
@@ -175,6 +175,8 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3 +#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 +#define KVM_DEV_ARM_VGIC_CTRL_INIT 0/* KVM_IRQ_LINE irq field index values */ #define KVM_ARM_IRQ_TYPE_SHIFT 24
linux-headers/asm-arm64/kvm.h +9 -0
@@ -78,6 +78,13 @@ struct kvm_regs {#define KVM_VGIC_V2_DIST_SIZE 0x1000#define KVM_VGIC_V2_CPU_SIZE 0x2000 +/* Supported VGICv3 address types */ +#define KVM_VGIC_V3_ADDR_TYPE_DIST 2 +#define KVM_VGIC_V3_ADDR_TYPE_REDIST 3 + +#define KVM_VGIC_V3_DIST_SIZE SZ_64K +#define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K) +#define KVM_ARM_VCPU_POWER_OFF 0/* CPU is started in OFF state */ #define KVM_ARM_VCPU_EL1_32BIT 1/* CPU running a 32bit VM */ #define KVM_ARM_VCPU_PSCI_0_2 2/* CPU uses PSCI v0.2 */
@@ -161,6 +168,8 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3 +#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 +#define KVM_DEV_ARM_VGIC_CTRL_INIT 0/* KVM_IRQ_LINE irq field index values */ #define KVM_ARM_IRQ_TYPE_SHIFT 24
linux-headers/asm-s390/kvm.h +37 -0
@@ -57,10 +57,44 @@ struct kvm_s390_io_adapter_req {/* kvm attr_group on vm fd */ #define KVM_S390_VM_MEM_CTRL 0 +#define KVM_S390_VM_TOD 1 +#define KVM_S390_VM_CRYPTO 2 +#define KVM_S390_VM_CPU_MODEL 3/* kvm attributes for mem_ctrl */ #define KVM_S390_VM_MEM_ENABLE_CMMA 0#define KVM_S390_VM_MEM_CLR_CMMA 1 +#define KVM_S390_VM_MEM_LIMIT_SIZE 2 + +/* kvm attributes for KVM_S390_VM_TOD */ +#define KVM_S390_VM_TOD_LOW 0 +#define KVM_S390_VM_TOD_HIGH 1 + +/* kvm attributes for KVM_S390_VM_CPU_MODEL */ +/* processor related attributes are r/w */ +#define KVM_S390_VM_CPU_PROCESSOR 0 +struct kvm_s390_vm_cpu_processor { +__u64 cpuid; +__u16 ibc; +__u8 pad[6 ]; +__u64 fac_list[256 ]; +}; + +/* machine related attributes are r/o */ +#define KVM_S390_VM_CPU_MACHINE 1 +struct kvm_s390_vm_cpu_machine { +__u64 cpuid; +__u32 ibc; +__u8 pad[4 ]; +__u64 fac_mask[256 ]; +__u64 fac_list[256 ]; +}; + +/* kvm attributes for crypto */ +#define KVM_S390_VM_CRYPTO_ENABLE_AES_KW 0 +#define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW 1 +#define KVM_S390_VM_CRYPTO_DISABLE_AES_KW 2 +#define KVM_S390_VM_CRYPTO_DISABLE_DEA_KW 3/* for KVM_GET_REGS and KVM_SET_REGS */ struct kvm_regs {
@@ -107,6 +141,9 @@ struct kvm_guest_debug_arch {struct kvm_hw_breakpoint *hw_bp; }; +/* for KVM_SYNC_PFAULT and KVM_REG_S390_PFTOKEN */ +#define KVM_S390_PFAULT_TOKEN_INVALID 0xffffffffffffffffULL +#define KVM_SYNC_PREFIX (1UL << 0)#define KVM_SYNC_GPRS (1UL << 1)#define KVM_SYNC_ACRS (1UL << 2)
linux-headers/asm-x86/hyperv.h +11 -0
@@ -187,6 +187,17 @@#define HV_X64_MSR_SINT14 0x4000009E#define HV_X64_MSR_SINT15 0x4000009F +/* +* Synthetic Timer MSRs. Four timers per vcpu. +*/ +#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0 +#define HV_X64_MSR_STIMER0_COUNT 0x400000B1 +#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2 +#define HV_X64_MSR_STIMER1_COUNT 0x400000B3 +#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4 +#define HV_X64_MSR_STIMER2_COUNT 0x400000B5 +#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6 +#define HV_X64_MSR_STIMER3_COUNT 0x400000B7#define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12
linux-headers/linux/kvm.h +9 -11
@@ -491,6 +491,11 @@ struct kvm_s390_emerg_info {__u16 code; }; +#define KVM_S390_STOP_FLAG_STORE_STATUS 0x01 +struct kvm_s390_stop_info { +__u32 flags; +}; +struct kvm_s390_mchk_info {__u64 cr14;__u64 mcic;
@@ -509,6 +514,7 @@ struct kvm_s390_irq {struct kvm_s390_emerg_info emerg;struct kvm_s390_extcall_info extcall;struct kvm_s390_prefix_info prefix; +struct kvm_s390_stop_info stop;struct kvm_s390_mchk_info mchk;char reserved[64 ]; } u;
@@ -647,11 +653,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_MP_STATE 14#define KVM_CAP_COALESCED_MMIO 15#define KVM_CAP_SYNC_MMU 16/* Changes to host mmap are reflected in guest */ -#define KVM_CAP_DEVICE_ASSIGNMENT 17#define KVM_CAP_IOMMU 18 -#ifdef __KVM_HAVE_MSI -#define KVM_CAP_DEVICE_MSI 20 -#endif /* Bug in KVM_SET_USER_MEMORY_REGION fixed: */ #define KVM_CAP_DESTROY_MEMORY_REGION_WORKS 21#define KVM_CAP_USER_NMI 22
@@ -663,10 +665,6 @@ struct kvm_ppc_smmu_info {#endif #define KVM_CAP_IRQ_ROUTING 25#define KVM_CAP_IRQ_INJECT_STATUS 26 -#define KVM_CAP_DEVICE_DEASSIGNMENT 27 -#ifdef __KVM_HAVE_MSIX -#define KVM_CAP_DEVICE_MSIX 28 -#endif #define KVM_CAP_ASSIGN_DEV_IRQ 29/* Another bug in KVM_SET_USER_MEMORY_REGION fixed: */ #define KVM_CAP_JOIN_MEMORY_REGIONS_WORKS 30
@@ -761,6 +759,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_PPC_FIXUP_HCALL 103#define KVM_CAP_PPC_ENABLE_HCALL 104#define KVM_CAP_CHECK_EXTENSION_VM 105 +#define KVM_CAP_S390_USER_SIGP 106#ifdef KVM_CAP_IRQ_ROUTING
@@ -960,6 +959,8 @@ enum kvm_device_type {#define KVM_DEV_TYPE_ARM_VGIC_V2 KVM_DEV_TYPE_ARM_VGIC_V2 KVM_DEV_TYPE_FLIC,#define KVM_DEV_TYPE_FLIC KVM_DEV_TYPE_FLIC + KVM_DEV_TYPE_ARM_VGIC_V3, +#define KVM_DEV_TYPE_ARM_VGIC_V3 KVM_DEV_TYPE_ARM_VGIC_V3 KVM_DEV_TYPE_MAX, };
@@ -1107,9 +1108,6 @@ struct kvm_s390_ucas_mapping {#define KVM_X86_SETUP_MCE _IOW(KVMIO, 0x9c, __u64)#define KVM_X86_GET_MCE_CAP_SUPPORTED _IOR(KVMIO, 0x9d, __u64)#define KVM_X86_SET_MCE _IOW(KVMIO, 0x9e, struct kvm_x86_mce) -/* IA64 stack access */ -#define KVM_IA64_VCPU_GET_STACK _IOR(KVMIO, 0x9a, void *) -#define KVM_IA64_VCPU_SET_STACK _IOW(KVMIO, 0x9b, void *)/* Available with KVM_CAP_VCPU_EVENTS */ #define KVM_GET_VCPU_EVENTS _IOR(KVMIO, 0x9f, struct kvm_vcpu_events)#define KVM_SET_VCPU_EVENTS _IOW(KVMIO, 0xa0, struct kvm_vcpu_events)
linux-headers/linux/vfio.h +1 -0
@@ -333,6 +333,7 @@ enum {VFIO_PCI_MSI_IRQ_INDEX ,VFIO_PCI_MSIX_IRQ_INDEX ,VFIO_PCI_ERR_IRQ_INDEX , +VFIO_PCI_REQ_IRQ_INDEX , VFIO_PCI_NUM_IRQS };
linux-headers/linux/virtio_config.h +9 -2
@@ -38,20 +38,27 @@#define VIRTIO_CONFIG_S_DRIVER 2/* Driver has used its parts of the config, and is happy */ #define VIRTIO_CONFIG_S_DRIVER_OK 4 +/* Driver has finished configuring features */ +#define VIRTIO_CONFIG_S_FEATURES_OK 8/* We've given up on this device. */ #define VIRTIO_CONFIG_S_FAILED 0x80 -/* Some virtio feature bits (currently bits 28 through 31) are reserved for the +/* Some virtio feature bits (currently bits 28 through 32) are reserved for the * transport being used (eg. virtio_ring), the rest are per-device feature * bits. */ #define VIRTIO_TRANSPORT_F_START 28 -#define VIRTIO_TRANSPORT_F_END 32 +#define VIRTIO_TRANSPORT_F_END 33 +#ifndef VIRTIO_CONFIG_NO_LEGACY /* Do we get callbacks when the ring is completely used, even if we've * suppressed them? */ #define VIRTIO_F_NOTIFY_ON_EMPTY 24/* Can the device handle any descriptor layout? */ #define VIRTIO_F_ANY_LAYOUT 27 +#endif /* VIRTIO_CONFIG_NO_LEGACY */ + +/* v1.0 compliant. */ +#define VIRTIO_F_VERSION_1 32#endif /* _LINUX_VIRTIO_CONFIG_H */
linux-headers/linux/virtio_ring.h +30 -22
114 lines not on this page · raw message
linux-headers/linux/virtio_types.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH v4 3/3 hw/intc/arm_gic: Initialize the vgic in the realize function
In reply to Eric AugerThis patch forces vgic initialization in the vgic realize function. It uses a new group/attribute that allows such operation:
KVM_DEV_ARM_VGIC_GRP_CTRL/KVM_DEV_ARM_VGIC_CTRL_INIT
This earlier initialization allows, for example, to setup VFIO signaling and irqfd after vgic initialization, on a reset notifier.
--- hw/intc/arm_gic_kvm.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/intc/arm_gic_kvm.c +6 -0
@@ -573,6 +573,12 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)kvm_gic_access (s,KVM_DEV_ARM_VGIC_GRP_NR_IRQS ,0 ,0 , &numirqs,1 ); } +if (kvm_gic_supports_attr (s,KVM_DEV_ARM_VGIC_GRP_CTRL , +KVM_DEV_ARM_VGIC_CTRL_INIT )) { +kvm_gic_access (s,KVM_DEV_ARM_VGIC_GRP_CTRL , +KVM_DEV_ARM_VGIC_CTRL_INIT ,0 ,0 ,1 ); + } +/* Distributor */ memory_region_init_reservation (&s->iomem,OBJECT (s),"kvm-gic_dist" ,0x1000 );
Signature · 1 line
1.8.3.2
Re: [PATCH v4 3/3] hw/intc/arm_gic: Initialize the vgic in the realize function
Quoted 17 lines · Eric Auger
This patch forces vgic initialization in the vgic realize function. It uses a new group/attribute that allows such operation:
KVM_DEV_ARM_VGIC_GRP_CTRL/KVM_DEV_ARM_VGIC_CTRL_INITThis earlier initialization allows, for example, to setup VFIO signaling and irqfd after vgic initialization, on a reset notifier.
Signed-off-by Eric Auger <[email protected]>--- hw/intc/arm_gic_kvm.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/intc/arm_gic_kvm.c +0
-0
hw/intc/arm_gic_kvm.c static void kvm_arm_gic_realize(DeviceState *dev, Error **errp) · line 580
Quoted 8 lines
hw/intc/arm_gic_kvm.c +5
-0@@ -573,6 +573,12 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)kvm_gic_access (s,KVM_DEV_ARM_VGIC_GRP_NR_IRQS ,0 ,0 , &numirqs,1 ); } +if (kvm_gic_supports_attr (s,KVM_DEV_ARM_VGIC_GRP_CTRL , +KVM_DEV_ARM_VGIC_CTRL_INIT )) { +kvm_gic_access (s,KVM_DEV_ARM_VGIC_GRP_CTRL , +KVM_DEV_ARM_VGIC_CTRL_INIT ,0 ,0 ,1 ); + }
This is opaque enough that I think a comment in front of it would be nice; something like
/* Tell the kernel to complete initialization of the VGIC now */
Otherwise
thanks
-- PMM