Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull more KVM updates from Paolo Bonzini:
- ARM bugfix and MSI injection support
- x86 nested virt tweak and OOPS fix
- Simplify pvclock code (vdso bits acked by Andy Lutomirski).

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
nvmx: mark ept single context invalidation as supported
nvmx: remove comment about missing nested vpid support
KVM: lapic: fix access preemption timer stuff even if kernel_irqchip=off
KVM: documentation: fix KVM_CAP_X2APIC_API information
x86: vdso: use __pvclock_read_cycles
pvclock: introduce seqcount-like API
arm64: KVM: Set cpsr before spsr on fault injection
KVM: arm: vgic-irqfd: Workaround changing kvm_set_routing_entry prototype
KVM: arm/arm64: Enable MSI routing
KVM: arm/arm64: Enable irqchip routing
KVM: Move kvm_setup_default/empty_irq_routing declaration in arch specific header
KVM: irqchip: Convey devid to kvm_set_msi
KVM: Add devid in kvm_kernel_irq_routing_entry
KVM: api: Pass the devid in the msi routing entry

+276 -120
+37 -16
Documentation/virtual/kvm/api.txt
··· 1433 1433 4.52 KVM_SET_GSI_ROUTING 1434 1434 1435 1435 Capability: KVM_CAP_IRQ_ROUTING 1436 - Architectures: x86 s390 1436 + Architectures: x86 s390 arm arm64 1437 1437 Type: vm ioctl 1438 1438 Parameters: struct kvm_irq_routing (in) 1439 1439 Returns: 0 on success, -1 on error 1440 1440 1441 1441 Sets the GSI routing table entries, overwriting any previously set entries. 1442 + 1443 + On arm/arm64, GSI routing has the following limitation: 1444 + - GSI routing does not apply to KVM_IRQ_LINE but only to KVM_IRQFD. 1442 1445 1443 1446 struct kvm_irq_routing { 1444 1447 __u32 nr; ··· 1471 1468 #define KVM_IRQ_ROUTING_S390_ADAPTER 3 1472 1469 #define KVM_IRQ_ROUTING_HV_SINT 4 1473 1470 1474 - No flags are specified so far, the corresponding field must be set to zero. 1471 + flags: 1472 + - KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry 1473 + type, specifies that the devid field contains a valid value. The per-VM 1474 + KVM_CAP_MSI_DEVID capability advertises the requirement to provide 1475 + the device ID. If this capability is not available, userspace should 1476 + never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail. 1477 + - zero otherwise 1475 1478 1476 1479 struct kvm_irq_routing_irqchip { 1477 1480 __u32 irqchip; ··· 1488 1479 __u32 address_lo; 1489 1480 __u32 address_hi; 1490 1481 __u32 data; 1491 - __u32 pad; 1482 + union { 1483 + __u32 pad; 1484 + __u32 devid; 1485 + }; 1492 1486 }; 1487 + 1488 + If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier 1489 + for the device that wrote the MSI message. For PCI, this is usually a 1490 + BFD identifier in the lower 16 bits. 1493 1491 1494 1492 On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS 1495 1493 feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled, ··· 2215 2199 __u8 pad[12]; 2216 2200 }; 2217 2201 2218 - flags: KVM_MSI_VALID_DEVID: devid contains a valid value 2219 - devid: If KVM_MSI_VALID_DEVID is set, contains a unique device identifier 2220 - for the device that wrote the MSI message. 2221 - For PCI, this is usually a BFD identifier in the lower 16 bits. 2202 + flags: KVM_MSI_VALID_DEVID: devid contains a valid value. The per-VM 2203 + KVM_CAP_MSI_DEVID capability advertises the requirement to provide 2204 + the device ID. If this capability is not available, userspace 2205 + should never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail. 2222 2206 2223 - The per-VM KVM_CAP_MSI_DEVID capability advertises the need to provide 2224 - the device ID. If this capability is not set, userland cannot rely on 2225 - the kernel to allow the KVM_MSI_VALID_DEVID flag being set. 2207 + If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier 2208 + for the device that wrote the MSI message. For PCI, this is usually a 2209 + BFD identifier in the lower 16 bits. 2226 2210 2227 - On x86, address_hi is ignored unless the KVM_CAP_X2APIC_API capability is 2228 - enabled. If it is enabled, address_hi bits 31-8 provide bits 31-8 of the 2229 - destination id. Bits 7-0 of address_hi must be zero. 2211 + On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS 2212 + feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled, 2213 + address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of 2214 + address_hi must be zero. 2230 2215 2231 2216 2232 2217 4.71 KVM_CREATE_PIT2 ··· 2400 2383 irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment 2401 2384 and need not be specified with KVM_IRQFD_FLAG_DEASSIGN. 2402 2385 2403 - On ARM/ARM64, the gsi field in the kvm_irqfd struct specifies the Shared 2404 - Peripheral Interrupt (SPI) index, such that the GIC interrupt ID is 2405 - given by gsi + 32. 2386 + On arm/arm64, gsi routing being supported, the following can happen: 2387 + - in case no routing entry is associated to this gsi, injection fails 2388 + - in case the gsi is associated to an irqchip routing entry, 2389 + irqchip.pin + 32 corresponds to the injected SPI ID. 2390 + - in case the gsi is associated to an MSI routing entry, the MSI 2391 + message and device ID are translated into an LPI (support restricted 2392 + to GICv3 ITS in-kernel emulation). 2406 2393 2407 2394 4.76 KVM_PPC_ALLOCATE_HTAB 2408 2395
+2
arch/arm/kvm/Kconfig
··· 32 32 select KVM_VFIO 33 33 select HAVE_KVM_EVENTFD 34 34 select HAVE_KVM_IRQFD 35 + select HAVE_KVM_IRQCHIP 36 + select HAVE_KVM_IRQ_ROUTING 35 37 depends on ARM_VIRT_EXT && ARM_LPAE && ARM_ARCH_TIMER 36 38 ---help--- 37 39 Support hosting virtualized guest machines.
+1
arch/arm/kvm/Makefile
··· 29 29 obj-y += $(KVM)/arm/vgic/vgic-mmio.o 30 30 obj-y += $(KVM)/arm/vgic/vgic-mmio-v2.o 31 31 obj-y += $(KVM)/arm/vgic/vgic-kvm-device.o 32 + obj-y += $(KVM)/irqchip.o 32 33 obj-y += $(KVM)/arm/arch_timer.o
+19
arch/arm/kvm/irq.h
··· 1 + /* 2 + * irq.h: in kernel interrupt controller related definitions 3 + * Copyright (c) 2016 Red Hat, Inc. 4 + * 5 + * This program is free software; you can redistribute it and/or modify it 6 + * under the terms and conditions of the GNU General Public License, 7 + * version 2, as published by the Free Software Foundation. 8 + * 9 + * This header is included by irqchip.c. However, on ARM, interrupt 10 + * controller declarations are located in include/kvm/arm_vgic.h since 11 + * they are mostly shared between arm and arm64. 12 + */ 13 + 14 + #ifndef __IRQ_H 15 + #define __IRQ_H 16 + 17 + #include <kvm/arm_vgic.h> 18 + 19 + #endif
+2
arch/arm64/kvm/Kconfig
··· 37 37 select KVM_ARM_VGIC_V3 38 38 select KVM_ARM_PMU if HW_PERF_EVENTS 39 39 select HAVE_KVM_MSI 40 + select HAVE_KVM_IRQCHIP 41 + select HAVE_KVM_IRQ_ROUTING 40 42 ---help--- 41 43 Support hosting virtualized guest machines. 42 44 We don't support KVM with 16K page tables yet, due to the multiple
+1
arch/arm64/kvm/Makefile
··· 30 30 kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-mmio-v3.o 31 31 kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-kvm-device.o 32 32 kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-its.o 33 + kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/irqchip.o 33 34 kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/arch_timer.o 34 35 kvm-$(CONFIG_KVM_ARM_PMU) += $(KVM)/arm/pmu.o
+5 -7
arch/arm64/kvm/inject_fault.c
··· 132 132 static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addr) 133 133 { 134 134 unsigned long cpsr = *vcpu_cpsr(vcpu); 135 - bool is_aarch32; 135 + bool is_aarch32 = vcpu_mode_is_32bit(vcpu); 136 136 u32 esr = 0; 137 137 138 - is_aarch32 = vcpu_mode_is_32bit(vcpu); 139 - 140 - *vcpu_spsr(vcpu) = cpsr; 141 138 *vcpu_elr_el1(vcpu) = *vcpu_pc(vcpu); 142 - 143 139 *vcpu_pc(vcpu) = get_except_vector(vcpu, except_type_sync); 140 + 144 141 *vcpu_cpsr(vcpu) = PSTATE_FAULT_BITS_64; 142 + *vcpu_spsr(vcpu) = cpsr; 145 143 146 144 vcpu_sys_reg(vcpu, FAR_EL1) = addr; 147 145 ··· 170 172 unsigned long cpsr = *vcpu_cpsr(vcpu); 171 173 u32 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT); 172 174 173 - *vcpu_spsr(vcpu) = cpsr; 174 175 *vcpu_elr_el1(vcpu) = *vcpu_pc(vcpu); 175 - 176 176 *vcpu_pc(vcpu) = get_except_vector(vcpu, except_type_sync); 177 + 177 178 *vcpu_cpsr(vcpu) = PSTATE_FAULT_BITS_64; 179 + *vcpu_spsr(vcpu) = cpsr; 178 180 179 181 /* 180 182 * Build an unknown exception, depending on the instruction
+19
arch/arm64/kvm/irq.h
··· 1 + /* 2 + * irq.h: in kernel interrupt controller related definitions 3 + * Copyright (c) 2016 Red Hat, Inc. 4 + * 5 + * This program is free software; you can redistribute it and/or modify it 6 + * under the terms and conditions of the GNU General Public License, 7 + * version 2, as published by the Free Software Foundation. 8 + * 9 + * This header is included by irqchip.c. However, on ARM, interrupt 10 + * controller declarations are located in include/kvm/arm_vgic.h since 11 + * they are mostly shared between arm and arm64. 12 + */ 13 + 14 + #ifndef __IRQ_H 15 + #define __IRQ_H 16 + 17 + #include <kvm/arm_vgic.h> 18 + 19 + #endif
+5 -20
arch/x86/entry/vdso/vclock_gettime.c
··· 96 96 { 97 97 const struct pvclock_vcpu_time_info *pvti = &get_pvti0()->pvti; 98 98 cycle_t ret; 99 - u64 tsc, pvti_tsc; 100 - u64 last, delta, pvti_system_time; 101 - u32 version, pvti_tsc_to_system_mul, pvti_tsc_shift; 99 + u64 last; 100 + u32 version; 102 101 103 102 /* 104 103 * Note: The kernel and hypervisor must guarantee that cpu ID ··· 122 123 */ 123 124 124 125 do { 125 - version = pvti->version; 126 - 127 - smp_rmb(); 126 + version = pvclock_read_begin(pvti); 128 127 129 128 if (unlikely(!(pvti->flags & PVCLOCK_TSC_STABLE_BIT))) { 130 129 *mode = VCLOCK_NONE; 131 130 return 0; 132 131 } 133 132 134 - tsc = rdtsc_ordered(); 135 - pvti_tsc_to_system_mul = pvti->tsc_to_system_mul; 136 - pvti_tsc_shift = pvti->tsc_shift; 137 - pvti_system_time = pvti->system_time; 138 - pvti_tsc = pvti->tsc_timestamp; 139 - 140 - /* Make sure that the version double-check is last. */ 141 - smp_rmb(); 142 - } while (unlikely((version & 1) || version != pvti->version)); 143 - 144 - delta = tsc - pvti_tsc; 145 - ret = pvti_system_time + 146 - pvclock_scale_delta(delta, pvti_tsc_to_system_mul, 147 - pvti_tsc_shift); 133 + ret = __pvclock_read_cycles(pvti); 134 + } while (pvclock_read_retry(pvti, version)); 148 135 149 136 /* refer to vread_tsc() comment for rationale */ 150 137 last = gtod->cycle_last;
+23 -16
arch/x86/include/asm/pvclock.h
··· 25 25 26 26 void pvclock_touch_watchdogs(void); 27 27 28 + static __always_inline 29 + unsigned pvclock_read_begin(const struct pvclock_vcpu_time_info *src) 30 + { 31 + unsigned version = src->version & ~1; 32 + /* Make sure that the version is read before the data. */ 33 + virt_rmb(); 34 + return version; 35 + } 36 + 37 + static __always_inline 38 + bool pvclock_read_retry(const struct pvclock_vcpu_time_info *src, 39 + unsigned version) 40 + { 41 + /* Make sure that the version is re-read after the data. */ 42 + virt_rmb(); 43 + return unlikely(version != src->version); 44 + } 45 + 28 46 /* 29 47 * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction, 30 48 * yielding a 64-bit result. ··· 87 69 } 88 70 89 71 static __always_inline 90 - unsigned __pvclock_read_cycles(const struct pvclock_vcpu_time_info *src, 91 - cycle_t *cycles, u8 *flags) 72 + cycle_t __pvclock_read_cycles(const struct pvclock_vcpu_time_info *src) 92 73 { 93 - unsigned version; 94 - cycle_t offset; 95 - u64 delta; 96 - 97 - version = src->version; 98 - /* Make the latest version visible */ 99 - smp_rmb(); 100 - 101 - delta = rdtsc_ordered() - src->tsc_timestamp; 102 - offset = pvclock_scale_delta(delta, src->tsc_to_system_mul, 103 - src->tsc_shift); 104 - *cycles = src->system_time + offset; 105 - *flags = src->flags; 106 - return version; 74 + u64 delta = rdtsc_ordered() - src->tsc_timestamp; 75 + cycle_t offset = pvclock_scale_delta(delta, src->tsc_to_system_mul, 76 + src->tsc_shift); 77 + return src->system_time + offset; 107 78 } 108 79 109 80 struct pvclock_vsyscall_time_info {
+6 -11
arch/x86/kernel/pvclock.c
··· 64 64 u8 flags; 65 65 66 66 do { 67 - version = src->version; 68 - /* Make the latest version visible */ 69 - smp_rmb(); 70 - 67 + version = pvclock_read_begin(src); 71 68 flags = src->flags; 72 - /* Make sure that the version double-check is last. */ 73 - smp_rmb(); 74 - } while ((src->version & 1) || version != src->version); 69 + } while (pvclock_read_retry(src, version)); 75 70 76 71 return flags & valid_flags; 77 72 } ··· 79 84 u8 flags; 80 85 81 86 do { 82 - version = __pvclock_read_cycles(src, &ret, &flags); 83 - /* Make sure that the version double-check is last. */ 84 - smp_rmb(); 85 - } while ((src->version & 1) || version != src->version); 87 + version = pvclock_read_begin(src); 88 + ret = __pvclock_read_cycles(src); 89 + flags = src->flags; 90 + } while (pvclock_read_retry(src, version)); 86 91 87 92 if (unlikely((flags & PVCLOCK_GUEST_STOPPED) != 0)) { 88 93 src->flags &= ~PVCLOCK_GUEST_STOPPED;
+3
arch/x86/kvm/irq.h
··· 120 120 121 121 int apic_has_pending_timer(struct kvm_vcpu *vcpu); 122 122 123 + int kvm_setup_default_irq_routing(struct kvm *kvm); 124 + int kvm_setup_empty_irq_routing(struct kvm *kvm); 125 + 123 126 #endif
+3
arch/x86/kvm/lapic.c
··· 1349 1349 1350 1350 bool kvm_lapic_hv_timer_in_use(struct kvm_vcpu *vcpu) 1351 1351 { 1352 + if (!lapic_in_kernel(vcpu)) 1353 + return false; 1354 + 1352 1355 return vcpu->arch.apic->lapic_timer.hv_timer_in_use; 1353 1356 } 1354 1357 EXPORT_SYMBOL_GPL(kvm_lapic_hv_timer_in_use);
+7 -8
arch/x86/kvm/vmx.c
··· 2809 2809 vmx->nested.nested_vmx_ept_caps |= 2810 2810 VMX_EPT_EXECUTE_ONLY_BIT; 2811 2811 vmx->nested.nested_vmx_ept_caps &= vmx_capability.ept; 2812 - /* 2813 - * For nested guests, we don't do anything specific 2814 - * for single context invalidation. Hence, only advertise 2815 - * support for global context invalidation. 2816 - */ 2817 - vmx->nested.nested_vmx_ept_caps |= VMX_EPT_EXTENT_GLOBAL_BIT; 2812 + vmx->nested.nested_vmx_ept_caps |= VMX_EPT_EXTENT_GLOBAL_BIT | 2813 + VMX_EPT_EXTENT_CONTEXT_BIT; 2818 2814 } else 2819 2815 vmx->nested.nested_vmx_ept_caps = 0; 2820 2816 ··· 2941 2945 vmx->nested.nested_vmx_secondary_ctls_high); 2942 2946 break; 2943 2947 case MSR_IA32_VMX_EPT_VPID_CAP: 2944 - /* Currently, no nested vpid support */ 2945 2948 *pdata = vmx->nested.nested_vmx_ept_caps | 2946 2949 ((u64)vmx->nested.nested_vmx_vpid_caps << 32); 2947 2950 break; ··· 7604 7609 7605 7610 switch (type) { 7606 7611 case VMX_EPT_EXTENT_GLOBAL: 7612 + /* 7613 + * TODO: track mappings and invalidate 7614 + * single context requests appropriately 7615 + */ 7616 + case VMX_EPT_EXTENT_CONTEXT: 7607 7617 kvm_mmu_sync_roots(vcpu); 7608 7618 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu); 7609 7619 nested_vmx_succeed(vcpu); 7610 7620 break; 7611 7621 default: 7612 - /* Trap single context invalidation invept calls */ 7613 7622 BUG_ON(1); 7614 7623 break; 7615 7624 }
+7
include/kvm/arm_vgic.h
··· 34 34 #define VGIC_MAX_SPI 1019 35 35 #define VGIC_MAX_RESERVED 1023 36 36 #define VGIC_MIN_LPI 8192 37 + #define KVM_IRQCHIP_NUM_PINS (1020 - 32) 37 38 38 39 enum vgic_type { 39 40 VGIC_V2, /* Good ol' GICv2 */ ··· 314 313 } 315 314 316 315 int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi); 316 + 317 + /** 318 + * kvm_vgic_setup_default_irq_routing: 319 + * Setup a default flat gsi routing table mapping all SPIs 320 + */ 321 + int kvm_vgic_setup_default_irq_routing(struct kvm *kvm); 317 322 318 323 #endif /* __KVM_ARM_VGIC_H */
+9 -3
include/linux/kvm_host.h
··· 317 317 unsigned irqchip; 318 318 unsigned pin; 319 319 } irqchip; 320 - struct msi_msg msi; 320 + struct { 321 + u32 address_lo; 322 + u32 address_hi; 323 + u32 data; 324 + u32 flags; 325 + u32 devid; 326 + } msi; 321 327 struct kvm_s390_adapter_int adapter; 322 328 struct kvm_hv_sint hv_sint; 323 329 }; ··· 1009 1003 1010 1004 #ifdef CONFIG_S390 1011 1005 #define KVM_MAX_IRQ_ROUTES 4096 //FIXME: we can have more than that... 1006 + #elif defined(CONFIG_ARM64) 1007 + #define KVM_MAX_IRQ_ROUTES 4096 1012 1008 #else 1013 1009 #define KVM_MAX_IRQ_ROUTES 1024 1014 1010 #endif 1015 1011 1016 - int kvm_setup_default_irq_routing(struct kvm *kvm); 1017 - int kvm_setup_empty_irq_routing(struct kvm *kvm); 1018 1012 int kvm_set_irq_routing(struct kvm *kvm, 1019 1013 const struct kvm_irq_routing_entry *entries, 1020 1014 unsigned nr,
+4 -1
include/uapi/linux/kvm.h
··· 882 882 __u32 address_lo; 883 883 __u32 address_hi; 884 884 __u32 data; 885 - __u32 pad; 885 + union { 886 + __u32 pad; 887 + __u32 devid; 888 + }; 886 889 }; 887 890 888 891 struct kvm_irq_routing_s390_adapter {
+4
virt/kvm/arm/vgic/vgic-init.c
··· 264 264 kvm_for_each_vcpu(i, vcpu, kvm) 265 265 kvm_vgic_vcpu_init(vcpu); 266 266 267 + ret = kvm_vgic_setup_default_irq_routing(kvm); 268 + if (ret) 269 + goto out; 270 + 267 271 dist->initialized = true; 268 272 out: 269 273 return ret;
+101 -21
virt/kvm/arm/vgic/vgic-irqfd.c
··· 17 17 #include <linux/kvm.h> 18 18 #include <linux/kvm_host.h> 19 19 #include <trace/events/kvm.h> 20 + #include <kvm/arm_vgic.h> 21 + #include "vgic.h" 20 22 21 - int kvm_irq_map_gsi(struct kvm *kvm, 22 - struct kvm_kernel_irq_routing_entry *entries, 23 - int gsi) 23 + /** 24 + * vgic_irqfd_set_irq: inject the IRQ corresponding to the 25 + * irqchip routing entry 26 + * 27 + * This is the entry point for irqfd IRQ injection 28 + */ 29 + static int vgic_irqfd_set_irq(struct kvm_kernel_irq_routing_entry *e, 30 + struct kvm *kvm, int irq_source_id, 31 + int level, bool line_status) 24 32 { 25 - return 0; 33 + unsigned int spi_id = e->irqchip.pin + VGIC_NR_PRIVATE_IRQS; 34 + 35 + if (!vgic_valid_spi(kvm, spi_id)) 36 + return -EINVAL; 37 + return kvm_vgic_inject_irq(kvm, 0, spi_id, level); 26 38 } 27 39 28 - int kvm_irq_map_chip_pin(struct kvm *kvm, unsigned int irqchip, 29 - unsigned int pin) 40 + /** 41 + * kvm_set_routing_entry: populate a kvm routing entry 42 + * from a user routing entry 43 + * 44 + * @kvm: the VM this entry is applied to 45 + * @e: kvm kernel routing entry handle 46 + * @ue: user api routing entry handle 47 + * return 0 on success, -EINVAL on errors. 48 + */ 49 + #ifdef KVM_CAP_X2APIC_API 50 + int kvm_set_routing_entry(struct kvm *kvm, 51 + struct kvm_kernel_irq_routing_entry *e, 52 + const struct kvm_irq_routing_entry *ue) 53 + #else 54 + /* Remove this version and the ifdefery once merged into 4.8 */ 55 + int kvm_set_routing_entry(struct kvm_kernel_irq_routing_entry *e, 56 + const struct kvm_irq_routing_entry *ue) 57 + #endif 30 58 { 31 - return pin; 59 + int r = -EINVAL; 60 + 61 + switch (ue->type) { 62 + case KVM_IRQ_ROUTING_IRQCHIP: 63 + e->set = vgic_irqfd_set_irq; 64 + e->irqchip.irqchip = ue->u.irqchip.irqchip; 65 + e->irqchip.pin = ue->u.irqchip.pin; 66 + if ((e->irqchip.pin >= KVM_IRQCHIP_NUM_PINS) || 67 + (e->irqchip.irqchip >= KVM_NR_IRQCHIPS)) 68 + goto out; 69 + break; 70 + case KVM_IRQ_ROUTING_MSI: 71 + e->set = kvm_set_msi; 72 + e->msi.address_lo = ue->u.msi.address_lo; 73 + e->msi.address_hi = ue->u.msi.address_hi; 74 + e->msi.data = ue->u.msi.data; 75 + e->msi.flags = ue->flags; 76 + e->msi.devid = ue->u.msi.devid; 77 + break; 78 + default: 79 + goto out; 80 + } 81 + r = 0; 82 + out: 83 + return r; 32 84 } 33 85 34 - int kvm_set_irq(struct kvm *kvm, int irq_source_id, 35 - u32 irq, int level, bool line_status) 36 - { 37 - unsigned int spi = irq + VGIC_NR_PRIVATE_IRQS; 38 - 39 - trace_kvm_set_irq(irq, level, irq_source_id); 40 - 41 - BUG_ON(!vgic_initialized(kvm)); 42 - 43 - return kvm_vgic_inject_irq(kvm, 0, spi, level); 44 - } 45 - 46 - /* MSI not implemented yet */ 86 + /** 87 + * kvm_set_msi: inject the MSI corresponding to the 88 + * MSI routing entry 89 + * 90 + * This is the entry point for irqfd MSI injection 91 + * and userspace MSI injection. 92 + */ 47 93 int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, 48 94 struct kvm *kvm, int irq_source_id, 49 95 int level, bool line_status) 50 96 { 51 - return 0; 97 + struct kvm_msi msi; 98 + 99 + msi.address_lo = e->msi.address_lo; 100 + msi.address_hi = e->msi.address_hi; 101 + msi.data = e->msi.data; 102 + msi.flags = e->msi.flags; 103 + msi.devid = e->msi.devid; 104 + 105 + if (!vgic_has_its(kvm)) 106 + return -ENODEV; 107 + 108 + return vgic_its_inject_msi(kvm, &msi); 109 + } 110 + 111 + int kvm_vgic_setup_default_irq_routing(struct kvm *kvm) 112 + { 113 + struct kvm_irq_routing_entry *entries; 114 + struct vgic_dist *dist = &kvm->arch.vgic; 115 + u32 nr = dist->nr_spis; 116 + int i, ret; 117 + 118 + entries = kcalloc(nr, sizeof(struct kvm_kernel_irq_routing_entry), 119 + GFP_KERNEL); 120 + if (!entries) 121 + return -ENOMEM; 122 + 123 + for (i = 0; i < nr; i++) { 124 + entries[i].gsi = i; 125 + entries[i].type = KVM_IRQ_ROUTING_IRQCHIP; 126 + entries[i].u.irqchip.irqchip = 0; 127 + entries[i].u.irqchip.pin = i; 128 + } 129 + ret = kvm_set_irq_routing(kvm, entries, nr, 0); 130 + kfree(entries); 131 + return ret; 52 132 }
-7
virt/kvm/arm/vgic/vgic.c
··· 711 711 return map_is_active; 712 712 } 713 713 714 - int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi) 715 - { 716 - if (vgic_has_its(kvm)) 717 - return vgic_its_inject_msi(kvm, msi); 718 - else 719 - return -ENODEV; 720 - }
+18 -10
virt/kvm/irqchip.c
··· 62 62 { 63 63 struct kvm_kernel_irq_routing_entry route; 64 64 65 - if (!irqchip_in_kernel(kvm) || msi->flags != 0) 65 + if (!irqchip_in_kernel(kvm) || (msi->flags & ~KVM_MSI_VALID_DEVID)) 66 66 return -EINVAL; 67 67 68 68 route.msi.address_lo = msi->address_lo; 69 69 route.msi.address_hi = msi->address_hi; 70 70 route.msi.data = msi->data; 71 + route.msi.flags = msi->flags; 72 + route.msi.devid = msi->devid; 71 73 72 74 return kvm_set_msi(&route, kvm, KVM_USERSPACE_IRQ_SOURCE_ID, 1, false); 73 75 } ··· 179 177 unsigned flags) 180 178 { 181 179 struct kvm_irq_routing_table *new, *old; 180 + struct kvm_kernel_irq_routing_entry *e; 182 181 u32 i, j, nr_rt_entries = 0; 183 182 int r; 184 183 ··· 203 200 new->chip[i][j] = -1; 204 201 205 202 for (i = 0; i < nr; ++i) { 206 - struct kvm_kernel_irq_routing_entry *e; 207 - 208 203 r = -ENOMEM; 209 204 e = kzalloc(sizeof(*e), GFP_KERNEL); 210 205 if (!e) 211 206 goto out; 212 207 213 208 r = -EINVAL; 214 - if (ue->flags) { 215 - kfree(e); 216 - goto out; 209 + switch (ue->type) { 210 + case KVM_IRQ_ROUTING_MSI: 211 + if (ue->flags & ~KVM_MSI_VALID_DEVID) 212 + goto free_entry; 213 + break; 214 + default: 215 + if (ue->flags) 216 + goto free_entry; 217 + break; 217 218 } 218 219 r = setup_routing_entry(kvm, new, e, ue); 219 - if (r) { 220 - kfree(e); 221 - goto out; 222 - } 220 + if (r) 221 + goto free_entry; 223 222 ++ue; 224 223 } 225 224 ··· 238 233 239 234 new = old; 240 235 r = 0; 236 + goto out; 241 237 238 + free_entry: 239 + kfree(e); 242 240 out: 243 241 free_irq_routing_table(new); 244 242