diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2015-04-07 12:10:03 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2015-04-07 12:10:03 -0400 |
commit | 7f22b45d66b8e603e2e85e78f209531779f8b1cc (patch) | |
tree | 6abed0cec23ed9c6bb5a1e3dbfd15b4345fa9b62 | |
parent | bf0fb67cf957fc8ecfaaa2819b7d6a0f795e2ef2 (diff) | |
parent | 816c7667ea97c61884e014cfeedaede5b67b0e58 (diff) |
Merge tag 'kvm-s390-next-20150331' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD
Features and fixes for 4.1 (kvm/next)
1. Assorted changes
1.1 allow more feature bits for the guest
1.2 Store breaking event address on program interrupts
2. Interrupt handling rework
2.1 Fix copy_to_user while holding a spinlock (cc stable)
2.2 Rework floating interrupts to follow the priorities
2.3 Allow to inject all local interrupts via new ioctl
2.4 allow to get/set the full local irq state, e.g. for migration
and introspection
-rw-r--r-- | Documentation/virtual/kvm/api.txt | 117 | ||||
-rw-r--r-- | Documentation/virtual/kvm/devices/s390_flic.txt | 3 | ||||
-rw-r--r-- | arch/s390/include/asm/kvm_host.h | 30 | ||||
-rw-r--r-- | arch/s390/kvm/interrupt.c | 1073 | ||||
-rw-r--r-- | arch/s390/kvm/kvm-s390.c | 54 | ||||
-rw-r--r-- | arch/s390/kvm/kvm-s390.h | 6 | ||||
-rw-r--r-- | arch/s390/kvm/priv.c | 9 | ||||
-rw-r--r-- | include/uapi/linux/kvm.h | 14 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 2 |
9 files changed, 906 insertions, 402 deletions
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index 57d25fdd3d7e..bc9f6fe44e27 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt | |||
@@ -2861,6 +2861,123 @@ single frame starting at start_gfn for count frames. | |||
2861 | Note: If any architecturally invalid key value is found in the given data then | 2861 | Note: If any architecturally invalid key value is found in the given data then |
2862 | the ioctl will return -EINVAL. | 2862 | the ioctl will return -EINVAL. |
2863 | 2863 | ||
2864 | 4.92 KVM_S390_IRQ | ||
2865 | |||
2866 | Capability: KVM_CAP_S390_INJECT_IRQ | ||
2867 | Architectures: s390 | ||
2868 | Type: vcpu ioctl | ||
2869 | Parameters: struct kvm_s390_irq (in) | ||
2870 | Returns: 0 on success, -1 on error | ||
2871 | Errors: | ||
2872 | EINVAL: interrupt type is invalid | ||
2873 | type is KVM_S390_SIGP_STOP and flag parameter is invalid value | ||
2874 | type is KVM_S390_INT_EXTERNAL_CALL and code is bigger | ||
2875 | than the maximum of VCPUs | ||
2876 | EBUSY: type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped | ||
2877 | type is KVM_S390_SIGP_STOP and a stop irq is already pending | ||
2878 | type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt | ||
2879 | is already pending | ||
2880 | |||
2881 | Allows to inject an interrupt to the guest. | ||
2882 | |||
2883 | Using struct kvm_s390_irq as a parameter allows | ||
2884 | to inject additional payload which is not | ||
2885 | possible via KVM_S390_INTERRUPT. | ||
2886 | |||
2887 | Interrupt parameters are passed via kvm_s390_irq: | ||
2888 | |||
2889 | struct kvm_s390_irq { | ||
2890 | __u64 type; | ||
2891 | union { | ||
2892 | struct kvm_s390_io_info io; | ||
2893 | struct kvm_s390_ext_info ext; | ||
2894 | struct kvm_s390_pgm_info pgm; | ||
2895 | struct kvm_s390_emerg_info emerg; | ||
2896 | struct kvm_s390_extcall_info extcall; | ||
2897 | struct kvm_s390_prefix_info prefix; | ||
2898 | struct kvm_s390_stop_info stop; | ||
2899 | struct kvm_s390_mchk_info mchk; | ||
2900 | char reserved[64]; | ||
2901 | } u; | ||
2902 | }; | ||
2903 | |||
2904 | type can be one of the following: | ||
2905 | |||
2906 | KVM_S390_SIGP_STOP - sigp stop; parameter in .stop | ||
2907 | KVM_S390_PROGRAM_INT - program check; parameters in .pgm | ||
2908 | KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix | ||
2909 | KVM_S390_RESTART - restart; no parameters | ||
2910 | KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters | ||
2911 | KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters | ||
2912 | KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg | ||
2913 | KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall | ||
2914 | KVM_S390_MCHK - machine check interrupt; parameters in .mchk | ||
2915 | |||
2916 | |||
2917 | Note that the vcpu ioctl is asynchronous to vcpu execution. | ||
2918 | |||
2919 | 4.94 KVM_S390_GET_IRQ_STATE | ||
2920 | |||
2921 | Capability: KVM_CAP_S390_IRQ_STATE | ||
2922 | Architectures: s390 | ||
2923 | Type: vcpu ioctl | ||
2924 | Parameters: struct kvm_s390_irq_state (out) | ||
2925 | Returns: >= number of bytes copied into buffer, | ||
2926 | -EINVAL if buffer size is 0, | ||
2927 | -ENOBUFS if buffer size is too small to fit all pending interrupts, | ||
2928 | -EFAULT if the buffer address was invalid | ||
2929 | |||
2930 | This ioctl allows userspace to retrieve the complete state of all currently | ||
2931 | pending interrupts in a single buffer. Use cases include migration | ||
2932 | and introspection. The parameter structure contains the address of a | ||
2933 | userspace buffer and its length: | ||
2934 | |||
2935 | struct kvm_s390_irq_state { | ||
2936 | __u64 buf; | ||
2937 | __u32 flags; | ||
2938 | __u32 len; | ||
2939 | __u32 reserved[4]; | ||
2940 | }; | ||
2941 | |||
2942 | Userspace passes in the above struct and for each pending interrupt a | ||
2943 | struct kvm_s390_irq is copied to the provided buffer. | ||
2944 | |||
2945 | If -ENOBUFS is returned the buffer provided was too small and userspace | ||
2946 | may retry with a bigger buffer. | ||
2947 | |||
2948 | 4.95 KVM_S390_SET_IRQ_STATE | ||
2949 | |||
2950 | Capability: KVM_CAP_S390_IRQ_STATE | ||
2951 | Architectures: s390 | ||
2952 | Type: vcpu ioctl | ||
2953 | Parameters: struct kvm_s390_irq_state (in) | ||
2954 | Returns: 0 on success, | ||
2955 | -EFAULT if the buffer address was invalid, | ||
2956 | -EINVAL for an invalid buffer length (see below), | ||
2957 | -EBUSY if there were already interrupts pending, | ||
2958 | errors occurring when actually injecting the | ||
2959 | interrupt. See KVM_S390_IRQ. | ||
2960 | |||
2961 | This ioctl allows userspace to set the complete state of all cpu-local | ||
2962 | interrupts currently pending for the vcpu. It is intended for restoring | ||
2963 | interrupt state after a migration. The input parameter is a userspace buffer | ||
2964 | containing a struct kvm_s390_irq_state: | ||
2965 | |||
2966 | struct kvm_s390_irq_state { | ||
2967 | __u64 buf; | ||
2968 | __u32 len; | ||
2969 | __u32 pad; | ||
2970 | }; | ||
2971 | |||
2972 | The userspace memory referenced by buf contains a struct kvm_s390_irq | ||
2973 | for each interrupt to be injected into the guest. | ||
2974 | If one of the interrupts could not be injected for some reason the | ||
2975 | ioctl aborts. | ||
2976 | |||
2977 | len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0 | ||
2978 | and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq), | ||
2979 | which is the maximum number of possibly pending cpu-local interrupts. | ||
2980 | |||
2864 | 5. The kvm_run structure | 2981 | 5. The kvm_run structure |
2865 | ------------------------ | 2982 | ------------------------ |
2866 | 2983 | ||
diff --git a/Documentation/virtual/kvm/devices/s390_flic.txt b/Documentation/virtual/kvm/devices/s390_flic.txt index 4ceef53164b0..d1ad9d5cae46 100644 --- a/Documentation/virtual/kvm/devices/s390_flic.txt +++ b/Documentation/virtual/kvm/devices/s390_flic.txt | |||
@@ -27,6 +27,9 @@ Groups: | |||
27 | Copies all floating interrupts into a buffer provided by userspace. | 27 | Copies all floating interrupts into a buffer provided by userspace. |
28 | When the buffer is too small it returns -ENOMEM, which is the indication | 28 | When the buffer is too small it returns -ENOMEM, which is the indication |
29 | for userspace to try again with a bigger buffer. | 29 | for userspace to try again with a bigger buffer. |
30 | -ENOBUFS is returned when the allocation of a kernelspace buffer has | ||
31 | failed. | ||
32 | -EFAULT is returned when copying data to userspace failed. | ||
30 | All interrupts remain pending, i.e. are not deleted from the list of | 33 | All interrupts remain pending, i.e. are not deleted from the list of |
31 | currently pending interrupts. | 34 | currently pending interrupts. |
32 | attr->addr contains the userspace address of the buffer into which all | 35 | attr->addr contains the userspace address of the buffer into which all |
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h index b8d1e97fb201..d01fc588b5c3 100644 --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h | |||
@@ -344,6 +344,11 @@ enum irq_types { | |||
344 | IRQ_PEND_COUNT | 344 | IRQ_PEND_COUNT |
345 | }; | 345 | }; |
346 | 346 | ||
347 | /* We have 2M for virtio device descriptor pages. Smallest amount of | ||
348 | * memory per page is 24 bytes (1 queue), so (2048*1024) / 24 = 87381 | ||
349 | */ | ||
350 | #define KVM_S390_MAX_VIRTIO_IRQS 87381 | ||
351 | |||
347 | /* | 352 | /* |
348 | * Repressible (non-floating) machine check interrupts | 353 | * Repressible (non-floating) machine check interrupts |
349 | * subclass bits in MCIC | 354 | * subclass bits in MCIC |
@@ -421,13 +426,32 @@ struct kvm_s390_local_interrupt { | |||
421 | unsigned long pending_irqs; | 426 | unsigned long pending_irqs; |
422 | }; | 427 | }; |
423 | 428 | ||
429 | #define FIRQ_LIST_IO_ISC_0 0 | ||
430 | #define FIRQ_LIST_IO_ISC_1 1 | ||
431 | #define FIRQ_LIST_IO_ISC_2 2 | ||
432 | #define FIRQ_LIST_IO_ISC_3 3 | ||
433 | #define FIRQ_LIST_IO_ISC_4 4 | ||
434 | #define FIRQ_LIST_IO_ISC_5 5 | ||
435 | #define FIRQ_LIST_IO_ISC_6 6 | ||
436 | #define FIRQ_LIST_IO_ISC_7 7 | ||
437 | #define FIRQ_LIST_PFAULT 8 | ||
438 | #define FIRQ_LIST_VIRTIO 9 | ||
439 | #define FIRQ_LIST_COUNT 10 | ||
440 | #define FIRQ_CNTR_IO 0 | ||
441 | #define FIRQ_CNTR_SERVICE 1 | ||
442 | #define FIRQ_CNTR_VIRTIO 2 | ||
443 | #define FIRQ_CNTR_PFAULT 3 | ||
444 | #define FIRQ_MAX_COUNT 4 | ||
445 | |||
424 | struct kvm_s390_float_interrupt { | 446 | struct kvm_s390_float_interrupt { |
447 | unsigned long pending_irqs; | ||
425 | spinlock_t lock; | 448 | spinlock_t lock; |
426 | struct list_head list; | 449 | struct list_head lists[FIRQ_LIST_COUNT]; |
427 | atomic_t active; | 450 | int counters[FIRQ_MAX_COUNT]; |
451 | struct kvm_s390_mchk_info mchk; | ||
452 | struct kvm_s390_ext_info srv_signal; | ||
428 | int next_rr_cpu; | 453 | int next_rr_cpu; |
429 | unsigned long idle_mask[BITS_TO_LONGS(KVM_MAX_VCPUS)]; | 454 | unsigned long idle_mask[BITS_TO_LONGS(KVM_MAX_VCPUS)]; |
430 | unsigned int irq_count; | ||
431 | }; | 455 | }; |
432 | 456 | ||
433 | struct kvm_hw_wp_info_arch { | 457 | struct kvm_hw_wp_info_arch { |
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 2afec6006def..9de47265ef73 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c | |||
@@ -17,10 +17,12 @@ | |||
17 | #include <linux/signal.h> | 17 | #include <linux/signal.h> |
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/bitmap.h> | 19 | #include <linux/bitmap.h> |
20 | #include <linux/vmalloc.h> | ||
20 | #include <asm/asm-offsets.h> | 21 | #include <asm/asm-offsets.h> |
21 | #include <asm/dis.h> | 22 | #include <asm/dis.h> |
22 | #include <asm/uaccess.h> | 23 | #include <asm/uaccess.h> |
23 | #include <asm/sclp.h> | 24 | #include <asm/sclp.h> |
25 | #include <asm/isc.h> | ||
24 | #include "kvm-s390.h" | 26 | #include "kvm-s390.h" |
25 | #include "gaccess.h" | 27 | #include "gaccess.h" |
26 | #include "trace-s390.h" | 28 | #include "trace-s390.h" |
@@ -33,11 +35,6 @@ | |||
33 | #define PFAULT_DONE 0x0680 | 35 | #define PFAULT_DONE 0x0680 |
34 | #define VIRTIO_PARAM 0x0d00 | 36 | #define VIRTIO_PARAM 0x0d00 |
35 | 37 | ||
36 | static int is_ioint(u64 type) | ||
37 | { | ||
38 | return ((type & 0xfffe0000u) != 0xfffe0000u); | ||
39 | } | ||
40 | |||
41 | int psw_extint_disabled(struct kvm_vcpu *vcpu) | 38 | int psw_extint_disabled(struct kvm_vcpu *vcpu) |
42 | { | 39 | { |
43 | return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT); | 40 | return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT); |
@@ -73,70 +70,45 @@ static int ckc_interrupts_enabled(struct kvm_vcpu *vcpu) | |||
73 | return 1; | 70 | return 1; |
74 | } | 71 | } |
75 | 72 | ||
76 | static u64 int_word_to_isc_bits(u32 int_word) | 73 | static int ckc_irq_pending(struct kvm_vcpu *vcpu) |
77 | { | 74 | { |
78 | u8 isc = (int_word & 0x38000000) >> 27; | 75 | if (!(vcpu->arch.sie_block->ckc < |
76 | get_tod_clock_fast() + vcpu->arch.sie_block->epoch)) | ||
77 | return 0; | ||
78 | return ckc_interrupts_enabled(vcpu); | ||
79 | } | ||
80 | |||
81 | static int cpu_timer_interrupts_enabled(struct kvm_vcpu *vcpu) | ||
82 | { | ||
83 | return !psw_extint_disabled(vcpu) && | ||
84 | (vcpu->arch.sie_block->gcr[0] & 0x400ul); | ||
85 | } | ||
86 | |||
87 | static int cpu_timer_irq_pending(struct kvm_vcpu *vcpu) | ||
88 | { | ||
89 | return (vcpu->arch.sie_block->cputm >> 63) && | ||
90 | cpu_timer_interrupts_enabled(vcpu); | ||
91 | } | ||
79 | 92 | ||
93 | static inline int is_ioirq(unsigned long irq_type) | ||
94 | { | ||
95 | return ((irq_type >= IRQ_PEND_IO_ISC_0) && | ||
96 | (irq_type <= IRQ_PEND_IO_ISC_7)); | ||
97 | } | ||
98 | |||
99 | static uint64_t isc_to_isc_bits(int isc) | ||
100 | { | ||
80 | return (0x80 >> isc) << 24; | 101 | return (0x80 >> isc) << 24; |
81 | } | 102 | } |
82 | 103 | ||
83 | static int __must_check __interrupt_is_deliverable(struct kvm_vcpu *vcpu, | 104 | static inline u8 int_word_to_isc(u32 int_word) |
84 | struct kvm_s390_interrupt_info *inti) | ||
85 | { | 105 | { |
86 | switch (inti->type) { | 106 | return (int_word & 0x38000000) >> 27; |
87 | case KVM_S390_INT_EXTERNAL_CALL: | 107 | } |
88 | if (psw_extint_disabled(vcpu)) | 108 | |
89 | return 0; | 109 | static inline unsigned long pending_floating_irqs(struct kvm_vcpu *vcpu) |
90 | if (vcpu->arch.sie_block->gcr[0] & 0x2000ul) | 110 | { |
91 | return 1; | 111 | return vcpu->kvm->arch.float_int.pending_irqs; |
92 | return 0; | ||
93 | case KVM_S390_INT_EMERGENCY: | ||
94 | if (psw_extint_disabled(vcpu)) | ||
95 | return 0; | ||
96 | if (vcpu->arch.sie_block->gcr[0] & 0x4000ul) | ||
97 | return 1; | ||
98 | return 0; | ||
99 | case KVM_S390_INT_CLOCK_COMP: | ||
100 | return ckc_interrupts_enabled(vcpu); | ||
101 | case KVM_S390_INT_CPU_TIMER: | ||
102 | if (psw_extint_disabled(vcpu)) | ||
103 | return 0; | ||
104 | if (vcpu->arch.sie_block->gcr[0] & 0x400ul) | ||
105 | return 1; | ||
106 | return 0; | ||
107 | case KVM_S390_INT_SERVICE: | ||
108 | case KVM_S390_INT_PFAULT_INIT: | ||
109 | case KVM_S390_INT_PFAULT_DONE: | ||
110 | case KVM_S390_INT_VIRTIO: | ||
111 | if (psw_extint_disabled(vcpu)) | ||
112 | return 0; | ||
113 | if (vcpu->arch.sie_block->gcr[0] & 0x200ul) | ||
114 | return 1; | ||
115 | return 0; | ||
116 | case KVM_S390_PROGRAM_INT: | ||
117 | case KVM_S390_SIGP_STOP: | ||
118 | case KVM_S390_SIGP_SET_PREFIX: | ||
119 | case KVM_S390_RESTART: | ||
120 | return 1; | ||
121 | case KVM_S390_MCHK: | ||
122 | if (psw_mchk_disabled(vcpu)) | ||
123 | return 0; | ||
124 | if (vcpu->arch.sie_block->gcr[14] & inti->mchk.cr14) | ||
125 | return 1; | ||
126 | return 0; | ||
127 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: | ||
128 | if (psw_ioint_disabled(vcpu)) | ||
129 | return 0; | ||
130 | if (vcpu->arch.sie_block->gcr[6] & | ||
131 | int_word_to_isc_bits(inti->io.io_int_word)) | ||
132 | return 1; | ||
133 | return 0; | ||
134 | default: | ||
135 | printk(KERN_WARNING "illegal interrupt type %llx\n", | ||
136 | inti->type); | ||
137 | BUG(); | ||
138 | } | ||
139 | return 0; | ||
140 | } | 112 | } |
141 | 113 | ||
142 | static inline unsigned long pending_local_irqs(struct kvm_vcpu *vcpu) | 114 | static inline unsigned long pending_local_irqs(struct kvm_vcpu *vcpu) |
@@ -144,12 +116,31 @@ static inline unsigned long pending_local_irqs(struct kvm_vcpu *vcpu) | |||
144 | return vcpu->arch.local_int.pending_irqs; | 116 | return vcpu->arch.local_int.pending_irqs; |
145 | } | 117 | } |
146 | 118 | ||
147 | static unsigned long deliverable_local_irqs(struct kvm_vcpu *vcpu) | 119 | static unsigned long disable_iscs(struct kvm_vcpu *vcpu, |
120 | unsigned long active_mask) | ||
121 | { | ||
122 | int i; | ||
123 | |||
124 | for (i = 0; i <= MAX_ISC; i++) | ||
125 | if (!(vcpu->arch.sie_block->gcr[6] & isc_to_isc_bits(i))) | ||
126 | active_mask &= ~(1UL << (IRQ_PEND_IO_ISC_0 + i)); | ||
127 | |||
128 | return active_mask; | ||
129 | } | ||
130 | |||
131 | static unsigned long deliverable_irqs(struct kvm_vcpu *vcpu) | ||
148 | { | 132 | { |
149 | unsigned long active_mask = pending_local_irqs(vcpu); | 133 | unsigned long active_mask; |
134 | |||
135 | active_mask = pending_local_irqs(vcpu); | ||
136 | active_mask |= pending_floating_irqs(vcpu); | ||
150 | 137 | ||
151 | if (psw_extint_disabled(vcpu)) | 138 | if (psw_extint_disabled(vcpu)) |
152 | active_mask &= ~IRQ_PEND_EXT_MASK; | 139 | active_mask &= ~IRQ_PEND_EXT_MASK; |
140 | if (psw_ioint_disabled(vcpu)) | ||
141 | active_mask &= ~IRQ_PEND_IO_MASK; | ||
142 | else | ||
143 | active_mask = disable_iscs(vcpu, active_mask); | ||
153 | if (!(vcpu->arch.sie_block->gcr[0] & 0x2000ul)) | 144 | if (!(vcpu->arch.sie_block->gcr[0] & 0x2000ul)) |
154 | __clear_bit(IRQ_PEND_EXT_EXTERNAL, &active_mask); | 145 | __clear_bit(IRQ_PEND_EXT_EXTERNAL, &active_mask); |
155 | if (!(vcpu->arch.sie_block->gcr[0] & 0x4000ul)) | 146 | if (!(vcpu->arch.sie_block->gcr[0] & 0x4000ul)) |
@@ -158,8 +149,13 @@ static unsigned long deliverable_local_irqs(struct kvm_vcpu *vcpu) | |||
158 | __clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &active_mask); | 149 | __clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &active_mask); |
159 | if (!(vcpu->arch.sie_block->gcr[0] & 0x400ul)) | 150 | if (!(vcpu->arch.sie_block->gcr[0] & 0x400ul)) |
160 | __clear_bit(IRQ_PEND_EXT_CPU_TIMER, &active_mask); | 151 | __clear_bit(IRQ_PEND_EXT_CPU_TIMER, &active_mask); |
152 | if (!(vcpu->arch.sie_block->gcr[0] & 0x200ul)) | ||
153 | __clear_bit(IRQ_PEND_EXT_SERVICE, &active_mask); | ||
161 | if (psw_mchk_disabled(vcpu)) | 154 | if (psw_mchk_disabled(vcpu)) |
162 | active_mask &= ~IRQ_PEND_MCHK_MASK; | 155 | active_mask &= ~IRQ_PEND_MCHK_MASK; |
156 | if (!(vcpu->arch.sie_block->gcr[14] & | ||
157 | vcpu->kvm->arch.float_int.mchk.cr14)) | ||
158 | __clear_bit(IRQ_PEND_MCHK_REP, &active_mask); | ||
163 | 159 | ||
164 | /* | 160 | /* |
165 | * STOP irqs will never be actively delivered. They are triggered via | 161 | * STOP irqs will never be actively delivered. They are triggered via |
@@ -201,6 +197,16 @@ static void __set_cpuflag(struct kvm_vcpu *vcpu, u32 flag) | |||
201 | atomic_set_mask(flag, &vcpu->arch.sie_block->cpuflags); | 197 | atomic_set_mask(flag, &vcpu->arch.sie_block->cpuflags); |
202 | } | 198 | } |
203 | 199 | ||
200 | static void set_intercept_indicators_io(struct kvm_vcpu *vcpu) | ||
201 | { | ||
202 | if (!(pending_floating_irqs(vcpu) & IRQ_PEND_IO_MASK)) | ||
203 | return; | ||
204 | else if (psw_ioint_disabled(vcpu)) | ||
205 | __set_cpuflag(vcpu, CPUSTAT_IO_INT); | ||
206 | else | ||
207 | vcpu->arch.sie_block->lctl |= LCTL_CR6; | ||
208 | } | ||
209 | |||
204 | static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu) | 210 | static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu) |
205 | { | 211 | { |
206 | if (!(pending_local_irqs(vcpu) & IRQ_PEND_EXT_MASK)) | 212 | if (!(pending_local_irqs(vcpu) & IRQ_PEND_EXT_MASK)) |
@@ -227,43 +233,15 @@ static void set_intercept_indicators_stop(struct kvm_vcpu *vcpu) | |||
227 | __set_cpuflag(vcpu, CPUSTAT_STOP_INT); | 233 | __set_cpuflag(vcpu, CPUSTAT_STOP_INT); |
228 | } | 234 | } |
229 | 235 | ||
230 | /* Set interception request for non-deliverable local interrupts */ | 236 | /* Set interception request for non-deliverable interrupts */ |
231 | static void set_intercept_indicators_local(struct kvm_vcpu *vcpu) | 237 | static void set_intercept_indicators(struct kvm_vcpu *vcpu) |
232 | { | 238 | { |
239 | set_intercept_indicators_io(vcpu); | ||
233 | set_intercept_indicators_ext(vcpu); | 240 | set_intercept_indicators_ext(vcpu); |
234 | set_intercept_indicators_mchk(vcpu); | 241 | set_intercept_indicators_mchk(vcpu); |
235 | set_intercept_indicators_stop(vcpu); | 242 | set_intercept_indicators_stop(vcpu); |
236 | } | 243 | } |
237 | 244 | ||
238 | static void __set_intercept_indicator(struct kvm_vcpu *vcpu, | ||
239 | struct kvm_s390_interrupt_info *inti) | ||
240 | { | ||
241 | switch (inti->type) { | ||
242 | case KVM_S390_INT_SERVICE: | ||
243 | case KVM_S390_INT_PFAULT_DONE: | ||
244 | case KVM_S390_INT_VIRTIO: | ||
245 | if (psw_extint_disabled(vcpu)) | ||
246 | __set_cpuflag(vcpu, CPUSTAT_EXT_INT); | ||
247 | else | ||
248 | vcpu->arch.sie_block->lctl |= LCTL_CR0; | ||
249 | break; | ||
250 | case KVM_S390_MCHK: | ||
251 | if (psw_mchk_disabled(vcpu)) | ||
252 | vcpu->arch.sie_block->ictl |= ICTL_LPSW; | ||
253 | else | ||
254 | vcpu->arch.sie_block->lctl |= LCTL_CR14; | ||
255 | break; | ||
256 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: | ||
257 | if (psw_ioint_disabled(vcpu)) | ||
258 | __set_cpuflag(vcpu, CPUSTAT_IO_INT); | ||
259 | else | ||
260 | vcpu->arch.sie_block->lctl |= LCTL_CR6; | ||
261 | break; | ||
262 | default: | ||
263 | BUG(); | ||
264 | } | ||
265 | } | ||
266 | |||
267 | static u16 get_ilc(struct kvm_vcpu *vcpu) | 245 | static u16 get_ilc(struct kvm_vcpu *vcpu) |
268 | { | 246 | { |
269 | switch (vcpu->arch.sie_block->icptcode) { | 247 | switch (vcpu->arch.sie_block->icptcode) { |
@@ -349,42 +327,72 @@ static int __must_check __deliver_pfault_init(struct kvm_vcpu *vcpu) | |||
349 | 327 | ||
350 | static int __must_check __deliver_machine_check(struct kvm_vcpu *vcpu) | 328 | static int __must_check __deliver_machine_check(struct kvm_vcpu *vcpu) |
351 | { | 329 | { |
330 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; | ||
352 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; | 331 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
353 | struct kvm_s390_mchk_info mchk; | 332 | struct kvm_s390_mchk_info mchk = {}; |
354 | unsigned long adtl_status_addr; | 333 | unsigned long adtl_status_addr; |
355 | int rc; | 334 | int deliver = 0; |
335 | int rc = 0; | ||
356 | 336 | ||
337 | spin_lock(&fi->lock); | ||
357 | spin_lock(&li->lock); | 338 | spin_lock(&li->lock); |
358 | mchk = li->irq.mchk; | 339 | if (test_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs) || |
340 | test_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs)) { | ||
341 | /* | ||
342 | * If there was an exigent machine check pending, then any | ||
343 | * repressible machine checks that might have been pending | ||
344 | * are indicated along with it, so always clear bits for | ||
345 | * repressible and exigent interrupts | ||
346 | */ | ||
347 | mchk = li->irq.mchk; | ||
348 | clear_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs); | ||
349 | clear_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs); | ||
350 | memset(&li->irq.mchk, 0, sizeof(mchk)); | ||
351 | deliver = 1; | ||
352 | } | ||
359 | /* | 353 | /* |
360 | * If there was an exigent machine check pending, then any repressible | 354 | * We indicate floating repressible conditions along with |
361 | * machine checks that might have been pending are indicated along | 355 | * other pending conditions. Channel Report Pending and Channel |
362 | * with it, so always clear both bits | 356 | * Subsystem damage are the only two and and are indicated by |
357 | * bits in mcic and masked in cr14. | ||
363 | */ | 358 | */ |
364 | clear_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs); | 359 | if (test_and_clear_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs)) { |
365 | clear_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs); | 360 | mchk.mcic |= fi->mchk.mcic; |
366 | memset(&li->irq.mchk, 0, sizeof(mchk)); | 361 | mchk.cr14 |= fi->mchk.cr14; |
362 | memset(&fi->mchk, 0, sizeof(mchk)); | ||
363 | deliver = 1; | ||
364 | } | ||
367 | spin_unlock(&li->lock); | 365 | spin_unlock(&li->lock); |
366 | spin_unlock(&fi->lock); | ||
368 | 367 | ||
369 | VCPU_EVENT(vcpu, 4, "interrupt: machine check mcic=%llx", | 368 | if (deliver) { |
370 | mchk.mcic); | 369 | VCPU_EVENT(vcpu, 4, "interrupt: machine check mcic=%llx", |
371 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_MCHK, | 370 | mchk.mcic); |
372 | mchk.cr14, mchk.mcic); | 371 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
373 | 372 | KVM_S390_MCHK, | |
374 | rc = kvm_s390_vcpu_store_status(vcpu, KVM_S390_STORE_STATUS_PREFIXED); | 373 | mchk.cr14, mchk.mcic); |
375 | rc |= read_guest_lc(vcpu, __LC_VX_SAVE_AREA_ADDR, | 374 | |
376 | &adtl_status_addr, sizeof(unsigned long)); | 375 | rc = kvm_s390_vcpu_store_status(vcpu, |
377 | rc |= kvm_s390_vcpu_store_adtl_status(vcpu, adtl_status_addr); | 376 | KVM_S390_STORE_STATUS_PREFIXED); |
378 | rc |= put_guest_lc(vcpu, mchk.mcic, | 377 | rc |= read_guest_lc(vcpu, __LC_VX_SAVE_AREA_ADDR, |
379 | (u64 __user *) __LC_MCCK_CODE); | 378 | &adtl_status_addr, |
380 | rc |= put_guest_lc(vcpu, mchk.failing_storage_address, | 379 | sizeof(unsigned long)); |
381 | (u64 __user *) __LC_MCCK_FAIL_STOR_ADDR); | 380 | rc |= kvm_s390_vcpu_store_adtl_status(vcpu, |
382 | rc |= write_guest_lc(vcpu, __LC_PSW_SAVE_AREA, | 381 | adtl_status_addr); |
383 | &mchk.fixed_logout, sizeof(mchk.fixed_logout)); | 382 | rc |= put_guest_lc(vcpu, mchk.mcic, |
384 | rc |= write_guest_lc(vcpu, __LC_MCK_OLD_PSW, | 383 | (u64 __user *) __LC_MCCK_CODE); |
385 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | 384 | rc |= put_guest_lc(vcpu, mchk.failing_storage_address, |
386 | rc |= read_guest_lc(vcpu, __LC_MCK_NEW_PSW, | 385 | (u64 __user *) __LC_MCCK_FAIL_STOR_ADDR); |
387 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | 386 | rc |= write_guest_lc(vcpu, __LC_PSW_SAVE_AREA, |
387 | &mchk.fixed_logout, | ||
388 | sizeof(mchk.fixed_logout)); | ||
389 | rc |= write_guest_lc(vcpu, __LC_MCK_OLD_PSW, | ||
390 | &vcpu->arch.sie_block->gpsw, | ||
391 | sizeof(psw_t)); | ||
392 | rc |= read_guest_lc(vcpu, __LC_MCK_NEW_PSW, | ||
393 | &vcpu->arch.sie_block->gpsw, | ||
394 | sizeof(psw_t)); | ||
395 | } | ||
388 | return rc ? -EFAULT : 0; | 396 | return rc ? -EFAULT : 0; |
389 | } | 397 | } |
390 | 398 | ||
@@ -585,6 +593,8 @@ static int __must_check __deliver_prog(struct kvm_vcpu *vcpu) | |||
585 | kvm_s390_rewind_psw(vcpu, ilc); | 593 | kvm_s390_rewind_psw(vcpu, ilc); |
586 | 594 | ||
587 | rc |= put_guest_lc(vcpu, ilc, (u16 *) __LC_PGM_ILC); | 595 | rc |= put_guest_lc(vcpu, ilc, (u16 *) __LC_PGM_ILC); |
596 | rc |= put_guest_lc(vcpu, vcpu->arch.sie_block->gbea, | ||
597 | (u64 *) __LC_LAST_BREAK); | ||
588 | rc |= put_guest_lc(vcpu, pgm_info.code, | 598 | rc |= put_guest_lc(vcpu, pgm_info.code, |
589 | (u16 *)__LC_PGM_INT_CODE); | 599 | (u16 *)__LC_PGM_INT_CODE); |
590 | rc |= write_guest_lc(vcpu, __LC_PGM_OLD_PSW, | 600 | rc |= write_guest_lc(vcpu, __LC_PGM_OLD_PSW, |
@@ -594,16 +604,27 @@ static int __must_check __deliver_prog(struct kvm_vcpu *vcpu) | |||
594 | return rc ? -EFAULT : 0; | 604 | return rc ? -EFAULT : 0; |
595 | } | 605 | } |
596 | 606 | ||
597 | static int __must_check __deliver_service(struct kvm_vcpu *vcpu, | 607 | static int __must_check __deliver_service(struct kvm_vcpu *vcpu) |
598 | struct kvm_s390_interrupt_info *inti) | ||
599 | { | 608 | { |
600 | int rc; | 609 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
610 | struct kvm_s390_ext_info ext; | ||
611 | int rc = 0; | ||
612 | |||
613 | spin_lock(&fi->lock); | ||
614 | if (!(test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs))) { | ||
615 | spin_unlock(&fi->lock); | ||
616 | return 0; | ||
617 | } | ||
618 | ext = fi->srv_signal; | ||
619 | memset(&fi->srv_signal, 0, sizeof(ext)); | ||
620 | clear_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs); | ||
621 | spin_unlock(&fi->lock); | ||
601 | 622 | ||
602 | VCPU_EVENT(vcpu, 4, "interrupt: sclp parm:%x", | 623 | VCPU_EVENT(vcpu, 4, "interrupt: sclp parm:%x", |
603 | inti->ext.ext_params); | 624 | ext.ext_params); |
604 | vcpu->stat.deliver_service_signal++; | 625 | vcpu->stat.deliver_service_signal++; |
605 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, | 626 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_SERVICE, |
606 | inti->ext.ext_params, 0); | 627 | ext.ext_params, 0); |
607 | 628 | ||
608 | rc = put_guest_lc(vcpu, EXT_IRQ_SERVICE_SIG, (u16 *)__LC_EXT_INT_CODE); | 629 | rc = put_guest_lc(vcpu, EXT_IRQ_SERVICE_SIG, (u16 *)__LC_EXT_INT_CODE); |
609 | rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR); | 630 | rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR); |
@@ -611,106 +632,146 @@ static int __must_check __deliver_service(struct kvm_vcpu *vcpu, | |||
611 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | 632 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
612 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, | 633 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
613 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | 634 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
614 | rc |= put_guest_lc(vcpu, inti->ext.ext_params, | 635 | rc |= put_guest_lc(vcpu, ext.ext_params, |
615 | (u32 *)__LC_EXT_PARAMS); | 636 | (u32 *)__LC_EXT_PARAMS); |
637 | |||
616 | return rc ? -EFAULT : 0; | 638 | return rc ? -EFAULT : 0; |
617 | } | 639 | } |
618 | 640 | ||
619 | static int __must_check __deliver_pfault_done(struct kvm_vcpu *vcpu, | 641 | static int __must_check __deliver_pfault_done(struct kvm_vcpu *vcpu) |
620 | struct kvm_s390_interrupt_info *inti) | ||
621 | { | 642 | { |
622 | int rc; | 643 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
644 | struct kvm_s390_interrupt_info *inti; | ||
645 | int rc = 0; | ||
623 | 646 | ||
624 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, | 647 | spin_lock(&fi->lock); |
625 | KVM_S390_INT_PFAULT_DONE, 0, | 648 | inti = list_first_entry_or_null(&fi->lists[FIRQ_LIST_PFAULT], |
626 | inti->ext.ext_params2); | 649 | struct kvm_s390_interrupt_info, |
650 | list); | ||
651 | if (inti) { | ||
652 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, | ||
653 | KVM_S390_INT_PFAULT_DONE, 0, | ||
654 | inti->ext.ext_params2); | ||
655 | list_del(&inti->list); | ||
656 | fi->counters[FIRQ_CNTR_PFAULT] -= 1; | ||
657 | } | ||
658 | if (list_empty(&fi->lists[FIRQ_LIST_PFAULT])) | ||
659 | clear_bit(IRQ_PEND_PFAULT_DONE, &fi->pending_irqs); | ||
660 | spin_unlock(&fi->lock); | ||
627 | 661 | ||
628 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, (u16 *)__LC_EXT_INT_CODE); | 662 | if (inti) { |
629 | rc |= put_guest_lc(vcpu, PFAULT_DONE, (u16 *)__LC_EXT_CPU_ADDR); | 663 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, |
630 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, | 664 | (u16 *)__LC_EXT_INT_CODE); |
631 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | 665 | rc |= put_guest_lc(vcpu, PFAULT_DONE, |
632 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, | 666 | (u16 *)__LC_EXT_CPU_ADDR); |
633 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | 667 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
634 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, | 668 | &vcpu->arch.sie_block->gpsw, |
635 | (u64 *)__LC_EXT_PARAMS2); | 669 | sizeof(psw_t)); |
670 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, | ||
671 | &vcpu->arch.sie_block->gpsw, | ||
672 | sizeof(psw_t)); | ||
673 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, | ||
674 | (u64 *)__LC_EXT_PARAMS2); | ||
675 | kfree(inti); | ||
676 | } | ||
636 | return rc ? -EFAULT : 0; | 677 | return rc ? -EFAULT : 0; |
637 | } | 678 | } |
638 | 679 | ||
639 | static int __must_check __deliver_virtio(struct kvm_vcpu *vcpu, | 680 | static int __must_check __deliver_virtio(struct kvm_vcpu *vcpu) |
640 | struct kvm_s390_interrupt_info *inti) | ||
641 | { | 681 | { |
642 | int rc; | 682 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
683 | struct kvm_s390_interrupt_info *inti; | ||
684 | int rc = 0; | ||
643 | 685 | ||
644 | VCPU_EVENT(vcpu, 4, "interrupt: virtio parm:%x,parm64:%llx", | 686 | spin_lock(&fi->lock); |
645 | inti->ext.ext_params, inti->ext.ext_params2); | 687 | inti = list_first_entry_or_null(&fi->lists[FIRQ_LIST_VIRTIO], |
646 | vcpu->stat.deliver_virtio_interrupt++; | 688 | struct kvm_s390_interrupt_info, |
647 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, | 689 | list); |
648 | inti->ext.ext_params, | 690 | if (inti) { |
649 | inti->ext.ext_params2); | 691 | VCPU_EVENT(vcpu, 4, |
692 | "interrupt: virtio parm:%x,parm64:%llx", | ||
693 | inti->ext.ext_params, inti->ext.ext_params2); | ||
694 | vcpu->stat.deliver_virtio_interrupt++; | ||
695 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, | ||
696 | inti->type, | ||
697 | inti->ext.ext_params, | ||
698 | inti->ext.ext_params2); | ||
699 | list_del(&inti->list); | ||
700 | fi->counters[FIRQ_CNTR_VIRTIO] -= 1; | ||
701 | } | ||
702 | if (list_empty(&fi->lists[FIRQ_LIST_VIRTIO])) | ||
703 | clear_bit(IRQ_PEND_VIRTIO, &fi->pending_irqs); | ||
704 | spin_unlock(&fi->lock); | ||
650 | 705 | ||
651 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, (u16 *)__LC_EXT_INT_CODE); | 706 | if (inti) { |
652 | rc |= put_guest_lc(vcpu, VIRTIO_PARAM, (u16 *)__LC_EXT_CPU_ADDR); | 707 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, |
653 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, | 708 | (u16 *)__LC_EXT_INT_CODE); |
654 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | 709 | rc |= put_guest_lc(vcpu, VIRTIO_PARAM, |
655 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, | 710 | (u16 *)__LC_EXT_CPU_ADDR); |
656 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | 711 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
657 | rc |= put_guest_lc(vcpu, inti->ext.ext_params, | 712 | &vcpu->arch.sie_block->gpsw, |
658 | (u32 *)__LC_EXT_PARAMS); | 713 | sizeof(psw_t)); |
659 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, | 714 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
660 | (u64 *)__LC_EXT_PARAMS2); | 715 | &vcpu->arch.sie_block->gpsw, |
716 | sizeof(psw_t)); | ||
717 | rc |= put_guest_lc(vcpu, inti->ext.ext_params, | ||
718 | (u32 *)__LC_EXT_PARAMS); | ||
719 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, | ||
720 | (u64 *)__LC_EXT_PARAMS2); | ||
721 | kfree(inti); | ||
722 | } | ||
661 | return rc ? -EFAULT : 0; | 723 | return rc ? -EFAULT : 0; |
662 | } | 724 | } |
663 | 725 | ||
664 | static int __must_check __deliver_io(struct kvm_vcpu *vcpu, | 726 | static int __must_check __deliver_io(struct kvm_vcpu *vcpu, |
665 | struct kvm_s390_interrupt_info *inti) | 727 | unsigned long irq_type) |
666 | { | 728 | { |
667 | int rc; | 729 | struct list_head *isc_list; |
730 | struct kvm_s390_float_interrupt *fi; | ||
731 | struct kvm_s390_interrupt_info *inti = NULL; | ||
732 | int rc = 0; | ||
668 | 733 | ||
669 | VCPU_EVENT(vcpu, 4, "interrupt: I/O %llx", inti->type); | 734 | fi = &vcpu->kvm->arch.float_int; |
670 | vcpu->stat.deliver_io_int++; | ||
671 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, | ||
672 | ((__u32)inti->io.subchannel_id << 16) | | ||
673 | inti->io.subchannel_nr, | ||
674 | ((__u64)inti->io.io_int_parm << 32) | | ||
675 | inti->io.io_int_word); | ||
676 | |||
677 | rc = put_guest_lc(vcpu, inti->io.subchannel_id, | ||
678 | (u16 *)__LC_SUBCHANNEL_ID); | ||
679 | rc |= put_guest_lc(vcpu, inti->io.subchannel_nr, | ||
680 | (u16 *)__LC_SUBCHANNEL_NR); | ||
681 | rc |= put_guest_lc(vcpu, inti->io.io_int_parm, | ||
682 | (u32 *)__LC_IO_INT_PARM); | ||
683 | rc |= put_guest_lc(vcpu, inti->io.io_int_word, | ||
684 | (u32 *)__LC_IO_INT_WORD); | ||
685 | rc |= write_guest_lc(vcpu, __LC_IO_OLD_PSW, | ||
686 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | ||
687 | rc |= read_guest_lc(vcpu, __LC_IO_NEW_PSW, | ||
688 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | ||
689 | return rc ? -EFAULT : 0; | ||
690 | } | ||
691 | 735 | ||
692 | static int __must_check __deliver_mchk_floating(struct kvm_vcpu *vcpu, | 736 | spin_lock(&fi->lock); |
693 | struct kvm_s390_interrupt_info *inti) | 737 | isc_list = &fi->lists[irq_type - IRQ_PEND_IO_ISC_0]; |
694 | { | 738 | inti = list_first_entry_or_null(isc_list, |
695 | struct kvm_s390_mchk_info *mchk = &inti->mchk; | 739 | struct kvm_s390_interrupt_info, |
696 | int rc; | 740 | list); |
741 | if (inti) { | ||
742 | VCPU_EVENT(vcpu, 4, "interrupt: I/O %llx", inti->type); | ||
743 | vcpu->stat.deliver_io_int++; | ||
744 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, | ||
745 | inti->type, | ||
746 | ((__u32)inti->io.subchannel_id << 16) | | ||
747 | inti->io.subchannel_nr, | ||
748 | ((__u64)inti->io.io_int_parm << 32) | | ||
749 | inti->io.io_int_word); | ||
750 | list_del(&inti->list); | ||
751 | fi->counters[FIRQ_CNTR_IO] -= 1; | ||
752 | } | ||
753 | if (list_empty(isc_list)) | ||
754 | clear_bit(irq_type, &fi->pending_irqs); | ||
755 | spin_unlock(&fi->lock); | ||
756 | |||
757 | if (inti) { | ||
758 | rc = put_guest_lc(vcpu, inti->io.subchannel_id, | ||
759 | (u16 *)__LC_SUBCHANNEL_ID); | ||
760 | rc |= put_guest_lc(vcpu, inti->io.subchannel_nr, | ||
761 | (u16 *)__LC_SUBCHANNEL_NR); | ||
762 | rc |= put_guest_lc(vcpu, inti->io.io_int_parm, | ||
763 | (u32 *)__LC_IO_INT_PARM); | ||
764 | rc |= put_guest_lc(vcpu, inti->io.io_int_word, | ||
765 | (u32 *)__LC_IO_INT_WORD); | ||
766 | rc |= write_guest_lc(vcpu, __LC_IO_OLD_PSW, | ||
767 | &vcpu->arch.sie_block->gpsw, | ||
768 | sizeof(psw_t)); | ||
769 | rc |= read_guest_lc(vcpu, __LC_IO_NEW_PSW, | ||
770 | &vcpu->arch.sie_block->gpsw, | ||
771 | sizeof(psw_t)); | ||
772 | kfree(inti); | ||
773 | } | ||
697 | 774 | ||
698 | VCPU_EVENT(vcpu, 4, "interrupt: machine check mcic=%llx", | ||
699 | mchk->mcic); | ||
700 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_MCHK, | ||
701 | mchk->cr14, mchk->mcic); | ||
702 | |||
703 | rc = kvm_s390_vcpu_store_status(vcpu, KVM_S390_STORE_STATUS_PREFIXED); | ||
704 | rc |= put_guest_lc(vcpu, mchk->mcic, | ||
705 | (u64 __user *) __LC_MCCK_CODE); | ||
706 | rc |= put_guest_lc(vcpu, mchk->failing_storage_address, | ||
707 | (u64 __user *) __LC_MCCK_FAIL_STOR_ADDR); | ||
708 | rc |= write_guest_lc(vcpu, __LC_PSW_SAVE_AREA, | ||
709 | &mchk->fixed_logout, sizeof(mchk->fixed_logout)); | ||
710 | rc |= write_guest_lc(vcpu, __LC_MCK_OLD_PSW, | ||
711 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | ||
712 | rc |= read_guest_lc(vcpu, __LC_MCK_NEW_PSW, | ||
713 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); | ||
714 | return rc ? -EFAULT : 0; | 775 | return rc ? -EFAULT : 0; |
715 | } | 776 | } |
716 | 777 | ||
@@ -718,6 +779,7 @@ typedef int (*deliver_irq_t)(struct kvm_vcpu *vcpu); | |||
718 | 779 | ||
719 | static const deliver_irq_t deliver_irq_funcs[] = { | 780 | static const deliver_irq_t deliver_irq_funcs[] = { |
720 | [IRQ_PEND_MCHK_EX] = __deliver_machine_check, | 781 | [IRQ_PEND_MCHK_EX] = __deliver_machine_check, |
782 | [IRQ_PEND_MCHK_REP] = __deliver_machine_check, | ||
721 | [IRQ_PEND_PROG] = __deliver_prog, | 783 | [IRQ_PEND_PROG] = __deliver_prog, |
722 | [IRQ_PEND_EXT_EMERGENCY] = __deliver_emergency_signal, | 784 | [IRQ_PEND_EXT_EMERGENCY] = __deliver_emergency_signal, |
723 | [IRQ_PEND_EXT_EXTERNAL] = __deliver_external_call, | 785 | [IRQ_PEND_EXT_EXTERNAL] = __deliver_external_call, |
@@ -726,36 +788,11 @@ static const deliver_irq_t deliver_irq_funcs[] = { | |||
726 | [IRQ_PEND_RESTART] = __deliver_restart, | 788 | [IRQ_PEND_RESTART] = __deliver_restart, |
727 | [IRQ_PEND_SET_PREFIX] = __deliver_set_prefix, | 789 | [IRQ_PEND_SET_PREFIX] = __deliver_set_prefix, |
728 | [IRQ_PEND_PFAULT_INIT] = __deliver_pfault_init, | 790 | [IRQ_PEND_PFAULT_INIT] = __deliver_pfault_init, |
791 | [IRQ_PEND_EXT_SERVICE] = __deliver_service, | ||
792 | [IRQ_PEND_PFAULT_DONE] = __deliver_pfault_done, | ||
793 | [IRQ_PEND_VIRTIO] = __deliver_virtio, | ||
729 | }; | 794 | }; |
730 | 795 | ||
731 | static int __must_check __deliver_floating_interrupt(struct kvm_vcpu *vcpu, | ||
732 | struct kvm_s390_interrupt_info *inti) | ||
733 | { | ||
734 | int rc; | ||
735 | |||
736 | switch (inti->type) { | ||
737 | case KVM_S390_INT_SERVICE: | ||
738 | rc = __deliver_service(vcpu, inti); | ||
739 | break; | ||
740 | case KVM_S390_INT_PFAULT_DONE: | ||
741 | rc = __deliver_pfault_done(vcpu, inti); | ||
742 | break; | ||
743 | case KVM_S390_INT_VIRTIO: | ||
744 | rc = __deliver_virtio(vcpu, inti); | ||
745 | break; | ||
746 | case KVM_S390_MCHK: | ||
747 | rc = __deliver_mchk_floating(vcpu, inti); | ||
748 | break; | ||
749 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: | ||
750 | rc = __deliver_io(vcpu, inti); | ||
751 | break; | ||
752 | default: | ||
753 | BUG(); | ||
754 | } | ||
755 | |||
756 | return rc; | ||
757 | } | ||
758 | |||
759 | /* Check whether an external call is pending (deliverable or not) */ | 796 | /* Check whether an external call is pending (deliverable or not) */ |
760 | int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu) | 797 | int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu) |
761 | { | 798 | { |
@@ -771,21 +808,9 @@ int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu) | |||
771 | 808 | ||
772 | int kvm_s390_vcpu_has_irq(struct kvm_vcpu *vcpu, int exclude_stop) | 809 | int kvm_s390_vcpu_has_irq(struct kvm_vcpu *vcpu, int exclude_stop) |
773 | { | 810 | { |
774 | struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int; | ||
775 | struct kvm_s390_interrupt_info *inti; | ||
776 | int rc; | 811 | int rc; |
777 | 812 | ||
778 | rc = !!deliverable_local_irqs(vcpu); | 813 | rc = !!deliverable_irqs(vcpu); |
779 | |||
780 | if ((!rc) && atomic_read(&fi->active)) { | ||
781 | spin_lock(&fi->lock); | ||
782 | list_for_each_entry(inti, &fi->list, list) | ||
783 | if (__interrupt_is_deliverable(vcpu, inti)) { | ||
784 | rc = 1; | ||
785 | break; | ||
786 | } | ||
787 | spin_unlock(&fi->lock); | ||
788 | } | ||
789 | 814 | ||
790 | if (!rc && kvm_cpu_has_pending_timer(vcpu)) | 815 | if (!rc && kvm_cpu_has_pending_timer(vcpu)) |
791 | rc = 1; | 816 | rc = 1; |
@@ -804,12 +829,7 @@ int kvm_s390_vcpu_has_irq(struct kvm_vcpu *vcpu, int exclude_stop) | |||
804 | 829 | ||
805 | int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) | 830 | int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) |
806 | { | 831 | { |
807 | if (!(vcpu->arch.sie_block->ckc < | 832 | return ckc_irq_pending(vcpu) || cpu_timer_irq_pending(vcpu); |
808 | get_tod_clock_fast() + vcpu->arch.sie_block->epoch)) | ||
809 | return 0; | ||
810 | if (!ckc_interrupts_enabled(vcpu)) | ||
811 | return 0; | ||
812 | return 1; | ||
813 | } | 833 | } |
814 | 834 | ||
815 | int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) | 835 | int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) |
@@ -904,60 +924,45 @@ void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu) | |||
904 | int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu) | 924 | int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu) |
905 | { | 925 | { |
906 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; | 926 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
907 | struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int; | ||
908 | struct kvm_s390_interrupt_info *n, *inti = NULL; | ||
909 | deliver_irq_t func; | 927 | deliver_irq_t func; |
910 | int deliver; | ||
911 | int rc = 0; | 928 | int rc = 0; |
912 | unsigned long irq_type; | 929 | unsigned long irq_type; |
913 | unsigned long deliverable_irqs; | 930 | unsigned long irqs; |
914 | 931 | ||
915 | __reset_intercept_indicators(vcpu); | 932 | __reset_intercept_indicators(vcpu); |
916 | 933 | ||
917 | /* pending ckc conditions might have been invalidated */ | 934 | /* pending ckc conditions might have been invalidated */ |
918 | clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); | 935 | clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); |
919 | if (kvm_cpu_has_pending_timer(vcpu)) | 936 | if (ckc_irq_pending(vcpu)) |
920 | set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); | 937 | set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); |
921 | 938 | ||
939 | /* pending cpu timer conditions might have been invalidated */ | ||
940 | clear_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); | ||
941 | if (cpu_timer_irq_pending(vcpu)) | ||
942 | set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); | ||
943 | |||
922 | do { | 944 | do { |
923 | deliverable_irqs = deliverable_local_irqs(vcpu); | 945 | irqs = deliverable_irqs(vcpu); |
924 | /* bits are in the order of interrupt priority */ | 946 | /* bits are in the order of interrupt priority */ |
925 | irq_type = find_first_bit(&deliverable_irqs, IRQ_PEND_COUNT); | 947 | irq_type = find_first_bit(&irqs, IRQ_PEND_COUNT); |
926 | if (irq_type == IRQ_PEND_COUNT) | 948 | if (irq_type == IRQ_PEND_COUNT) |
927 | break; | 949 | break; |
928 | func = deliver_irq_funcs[irq_type]; | 950 | if (is_ioirq(irq_type)) { |
929 | if (!func) { | 951 | rc = __deliver_io(vcpu, irq_type); |
930 | WARN_ON_ONCE(func == NULL); | 952 | } else { |
931 | clear_bit(irq_type, &li->pending_irqs); | 953 | func = deliver_irq_funcs[irq_type]; |
932 | continue; | 954 | if (!func) { |
955 | WARN_ON_ONCE(func == NULL); | ||
956 | clear_bit(irq_type, &li->pending_irqs); | ||
957 | continue; | ||
958 | } | ||
959 | rc = func(vcpu); | ||
933 | } | 960 | } |
934 | rc = func(vcpu); | 961 | if (rc) |
935 | } while (!rc && irq_type != IRQ_PEND_COUNT); | 962 | break; |
963 | } while (!rc); | ||
936 | 964 | ||
937 | set_intercept_indicators_local(vcpu); | 965 | set_intercept_indicators(vcpu); |
938 | |||
939 | if (!rc && atomic_read(&fi->active)) { | ||
940 | do { | ||
941 | deliver = 0; | ||
942 | spin_lock(&fi->lock); | ||
943 | list_for_each_entry_safe(inti, n, &fi->list, list) { | ||
944 | if (__interrupt_is_deliverable(vcpu, inti)) { | ||
945 | list_del(&inti->list); | ||
946 | fi->irq_count--; | ||
947 | deliver = 1; | ||
948 | break; | ||
949 | } | ||
950 | __set_intercept_indicator(vcpu, inti); | ||
951 | } | ||
952 | if (list_empty(&fi->list)) | ||
953 | atomic_set(&fi->active, 0); | ||
954 | spin_unlock(&fi->lock); | ||
955 | if (deliver) { | ||
956 | rc = __deliver_floating_interrupt(vcpu, inti); | ||
957 | kfree(inti); | ||
958 | } | ||
959 | } while (!rc && deliver); | ||
960 | } | ||
961 | 966 | ||
962 | return rc; | 967 | return rc; |
963 | } | 968 | } |
@@ -1192,80 +1197,182 @@ static int __inject_cpu_timer(struct kvm_vcpu *vcpu) | |||
1192 | return 0; | 1197 | return 0; |
1193 | } | 1198 | } |
1194 | 1199 | ||
1200 | static struct kvm_s390_interrupt_info *get_io_int(struct kvm *kvm, | ||
1201 | int isc, u32 schid) | ||
1202 | { | ||
1203 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; | ||
1204 | struct list_head *isc_list = &fi->lists[FIRQ_LIST_IO_ISC_0 + isc]; | ||
1205 | struct kvm_s390_interrupt_info *iter; | ||
1206 | u16 id = (schid & 0xffff0000U) >> 16; | ||
1207 | u16 nr = schid & 0x0000ffffU; | ||
1208 | |||
1209 | spin_lock(&fi->lock); | ||
1210 | list_for_each_entry(iter, isc_list, list) { | ||
1211 | if (schid && (id != iter->io.subchannel_id || | ||
1212 | nr != iter->io.subchannel_nr)) | ||
1213 | continue; | ||
1214 | /* found an appropriate entry */ | ||
1215 | list_del_init(&iter->list); | ||
1216 | fi->counters[FIRQ_CNTR_IO] -= 1; | ||
1217 | if (list_empty(isc_list)) | ||
1218 | clear_bit(IRQ_PEND_IO_ISC_0 + isc, &fi->pending_irqs); | ||
1219 | spin_unlock(&fi->lock); | ||
1220 | return iter; | ||
1221 | } | ||
1222 | spin_unlock(&fi->lock); | ||
1223 | return NULL; | ||
1224 | } | ||
1195 | 1225 | ||
1226 | /* | ||
1227 | * Dequeue and return an I/O interrupt matching any of the interruption | ||
1228 | * subclasses as designated by the isc mask in cr6 and the schid (if != 0). | ||
1229 | */ | ||
1196 | struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, | 1230 | struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, |
1197 | u64 cr6, u64 schid) | 1231 | u64 isc_mask, u32 schid) |
1232 | { | ||
1233 | struct kvm_s390_interrupt_info *inti = NULL; | ||
1234 | int isc; | ||
1235 | |||
1236 | for (isc = 0; isc <= MAX_ISC && !inti; isc++) { | ||
1237 | if (isc_mask & isc_to_isc_bits(isc)) | ||
1238 | inti = get_io_int(kvm, isc, schid); | ||
1239 | } | ||
1240 | return inti; | ||
1241 | } | ||
1242 | |||
1243 | #define SCCB_MASK 0xFFFFFFF8 | ||
1244 | #define SCCB_EVENT_PENDING 0x3 | ||
1245 | |||
1246 | static int __inject_service(struct kvm *kvm, | ||
1247 | struct kvm_s390_interrupt_info *inti) | ||
1248 | { | ||
1249 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; | ||
1250 | |||
1251 | spin_lock(&fi->lock); | ||
1252 | fi->srv_signal.ext_params |= inti->ext.ext_params & SCCB_EVENT_PENDING; | ||
1253 | /* | ||
1254 | * Early versions of the QEMU s390 bios will inject several | ||
1255 | * service interrupts after another without handling a | ||
1256 | * condition code indicating busy. | ||
1257 | * We will silently ignore those superfluous sccb values. | ||
1258 | * A future version of QEMU will take care of serialization | ||
1259 | * of servc requests | ||
1260 | */ | ||
1261 | if (fi->srv_signal.ext_params & SCCB_MASK) | ||
1262 | goto out; | ||
1263 | fi->srv_signal.ext_params |= inti->ext.ext_params & SCCB_MASK; | ||
1264 | set_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs); | ||
1265 | out: | ||
1266 | spin_unlock(&fi->lock); | ||
1267 | kfree(inti); | ||
1268 | return 0; | ||
1269 | } | ||
1270 | |||
1271 | static int __inject_virtio(struct kvm *kvm, | ||
1272 | struct kvm_s390_interrupt_info *inti) | ||
1273 | { | ||
1274 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; | ||
1275 | |||
1276 | spin_lock(&fi->lock); | ||
1277 | if (fi->counters[FIRQ_CNTR_VIRTIO] >= KVM_S390_MAX_VIRTIO_IRQS) { | ||
1278 | spin_unlock(&fi->lock); | ||
1279 | return -EBUSY; | ||
1280 | } | ||
1281 | fi->counters[FIRQ_CNTR_VIRTIO] += 1; | ||
1282 | list_add_tail(&inti->list, &fi->lists[FIRQ_LIST_VIRTIO]); | ||
1283 | set_bit(IRQ_PEND_VIRTIO, &fi->pending_irqs); | ||
1284 | spin_unlock(&fi->lock); | ||
1285 | return 0; | ||
1286 | } | ||
1287 | |||
1288 | static int __inject_pfault_done(struct kvm *kvm, | ||
1289 | struct kvm_s390_interrupt_info *inti) | ||
1290 | { | ||
1291 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; | ||
1292 | |||
1293 | spin_lock(&fi->lock); | ||
1294 | if (fi->counters[FIRQ_CNTR_PFAULT] >= | ||
1295 | (ASYNC_PF_PER_VCPU * KVM_MAX_VCPUS)) { | ||
1296 | spin_unlock(&fi->lock); | ||
1297 | return -EBUSY; | ||
1298 | } | ||
1299 | fi->counters[FIRQ_CNTR_PFAULT] += 1; | ||
1300 | list_add_tail(&inti->list, &fi->lists[FIRQ_LIST_PFAULT]); | ||
1301 | set_bit(IRQ_PEND_PFAULT_DONE, &fi->pending_irqs); | ||
1302 | spin_unlock(&fi->lock); | ||
1303 | return 0; | ||
1304 | } | ||
1305 | |||
1306 | #define CR_PENDING_SUBCLASS 28 | ||
1307 | static int __inject_float_mchk(struct kvm *kvm, | ||
1308 | struct kvm_s390_interrupt_info *inti) | ||
1309 | { | ||
1310 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; | ||
1311 | |||
1312 | spin_lock(&fi->lock); | ||
1313 | fi->mchk.cr14 |= inti->mchk.cr14 & (1UL << CR_PENDING_SUBCLASS); | ||
1314 | fi->mchk.mcic |= inti->mchk.mcic; | ||
1315 | set_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs); | ||
1316 | spin_unlock(&fi->lock); | ||
1317 | kfree(inti); | ||
1318 | return 0; | ||
1319 | } | ||
1320 | |||
1321 | static int __inject_io(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) | ||
1198 | { | 1322 | { |
1199 | struct kvm_s390_float_interrupt *fi; | 1323 | struct kvm_s390_float_interrupt *fi; |
1200 | struct kvm_s390_interrupt_info *inti, *iter; | 1324 | struct list_head *list; |
1325 | int isc; | ||
1201 | 1326 | ||
1202 | if ((!schid && !cr6) || (schid && cr6)) | ||
1203 | return NULL; | ||
1204 | fi = &kvm->arch.float_int; | 1327 | fi = &kvm->arch.float_int; |
1205 | spin_lock(&fi->lock); | 1328 | spin_lock(&fi->lock); |
1206 | inti = NULL; | 1329 | if (fi->counters[FIRQ_CNTR_IO] >= KVM_S390_MAX_FLOAT_IRQS) { |
1207 | list_for_each_entry(iter, &fi->list, list) { | 1330 | spin_unlock(&fi->lock); |
1208 | if (!is_ioint(iter->type)) | 1331 | return -EBUSY; |
1209 | continue; | ||
1210 | if (cr6 && | ||
1211 | ((cr6 & int_word_to_isc_bits(iter->io.io_int_word)) == 0)) | ||
1212 | continue; | ||
1213 | if (schid) { | ||
1214 | if (((schid & 0x00000000ffff0000) >> 16) != | ||
1215 | iter->io.subchannel_id) | ||
1216 | continue; | ||
1217 | if ((schid & 0x000000000000ffff) != | ||
1218 | iter->io.subchannel_nr) | ||
1219 | continue; | ||
1220 | } | ||
1221 | inti = iter; | ||
1222 | break; | ||
1223 | } | ||
1224 | if (inti) { | ||
1225 | list_del_init(&inti->list); | ||
1226 | fi->irq_count--; | ||
1227 | } | 1332 | } |
1228 | if (list_empty(&fi->list)) | 1333 | fi->counters[FIRQ_CNTR_IO] += 1; |
1229 | atomic_set(&fi->active, 0); | 1334 | |
1335 | isc = int_word_to_isc(inti->io.io_int_word); | ||
1336 | list = &fi->lists[FIRQ_LIST_IO_ISC_0 + isc]; | ||
1337 | list_add_tail(&inti->list, list); | ||
1338 | set_bit(IRQ_PEND_IO_ISC_0 + isc, &fi->pending_irqs); | ||
1230 | spin_unlock(&fi->lock); | 1339 | spin_unlock(&fi->lock); |
1231 | return inti; | 1340 | return 0; |
1232 | } | 1341 | } |
1233 | 1342 | ||
1234 | static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) | 1343 | static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) |
1235 | { | 1344 | { |
1236 | struct kvm_s390_local_interrupt *li; | 1345 | struct kvm_s390_local_interrupt *li; |
1237 | struct kvm_s390_float_interrupt *fi; | 1346 | struct kvm_s390_float_interrupt *fi; |
1238 | struct kvm_s390_interrupt_info *iter; | ||
1239 | struct kvm_vcpu *dst_vcpu = NULL; | 1347 | struct kvm_vcpu *dst_vcpu = NULL; |
1240 | int sigcpu; | 1348 | int sigcpu; |
1241 | int rc = 0; | 1349 | u64 type = READ_ONCE(inti->type); |
1350 | int rc; | ||
1242 | 1351 | ||
1243 | fi = &kvm->arch.float_int; | 1352 | fi = &kvm->arch.float_int; |
1244 | spin_lock(&fi->lock); | 1353 | |
1245 | if (fi->irq_count >= KVM_S390_MAX_FLOAT_IRQS) { | 1354 | switch (type) { |
1355 | case KVM_S390_MCHK: | ||
1356 | rc = __inject_float_mchk(kvm, inti); | ||
1357 | break; | ||
1358 | case KVM_S390_INT_VIRTIO: | ||
1359 | rc = __inject_virtio(kvm, inti); | ||
1360 | break; | ||
1361 | case KVM_S390_INT_SERVICE: | ||
1362 | rc = __inject_service(kvm, inti); | ||
1363 | break; | ||
1364 | case KVM_S390_INT_PFAULT_DONE: | ||
1365 | rc = __inject_pfault_done(kvm, inti); | ||
1366 | break; | ||
1367 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: | ||
1368 | rc = __inject_io(kvm, inti); | ||
1369 | break; | ||
1370 | default: | ||
1246 | rc = -EINVAL; | 1371 | rc = -EINVAL; |
1247 | goto unlock_fi; | ||
1248 | } | 1372 | } |
1249 | fi->irq_count++; | 1373 | if (rc) |
1250 | if (!is_ioint(inti->type)) { | 1374 | return rc; |
1251 | list_add_tail(&inti->list, &fi->list); | ||
1252 | } else { | ||
1253 | u64 isc_bits = int_word_to_isc_bits(inti->io.io_int_word); | ||
1254 | 1375 | ||
1255 | /* Keep I/O interrupts sorted in isc order. */ | ||
1256 | list_for_each_entry(iter, &fi->list, list) { | ||
1257 | if (!is_ioint(iter->type)) | ||
1258 | continue; | ||
1259 | if (int_word_to_isc_bits(iter->io.io_int_word) | ||
1260 | <= isc_bits) | ||
1261 | continue; | ||
1262 | break; | ||
1263 | } | ||
1264 | list_add_tail(&inti->list, &iter->list); | ||
1265 | } | ||
1266 | atomic_set(&fi->active, 1); | ||
1267 | if (atomic_read(&kvm->online_vcpus) == 0) | ||
1268 | goto unlock_fi; | ||
1269 | sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS); | 1376 | sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS); |
1270 | if (sigcpu == KVM_MAX_VCPUS) { | 1377 | if (sigcpu == KVM_MAX_VCPUS) { |
1271 | do { | 1378 | do { |
@@ -1277,7 +1384,7 @@ static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) | |||
1277 | dst_vcpu = kvm_get_vcpu(kvm, sigcpu); | 1384 | dst_vcpu = kvm_get_vcpu(kvm, sigcpu); |
1278 | li = &dst_vcpu->arch.local_int; | 1385 | li = &dst_vcpu->arch.local_int; |
1279 | spin_lock(&li->lock); | 1386 | spin_lock(&li->lock); |
1280 | switch (inti->type) { | 1387 | switch (type) { |
1281 | case KVM_S390_MCHK: | 1388 | case KVM_S390_MCHK: |
1282 | atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags); | 1389 | atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags); |
1283 | break; | 1390 | break; |
@@ -1290,9 +1397,8 @@ static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) | |||
1290 | } | 1397 | } |
1291 | spin_unlock(&li->lock); | 1398 | spin_unlock(&li->lock); |
1292 | kvm_s390_vcpu_wakeup(kvm_get_vcpu(kvm, sigcpu)); | 1399 | kvm_s390_vcpu_wakeup(kvm_get_vcpu(kvm, sigcpu)); |
1293 | unlock_fi: | 1400 | return 0; |
1294 | spin_unlock(&fi->lock); | 1401 | |
1295 | return rc; | ||
1296 | } | 1402 | } |
1297 | 1403 | ||
1298 | int kvm_s390_inject_vm(struct kvm *kvm, | 1404 | int kvm_s390_inject_vm(struct kvm *kvm, |
@@ -1408,12 +1514,10 @@ void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu) | |||
1408 | spin_unlock(&li->lock); | 1514 | spin_unlock(&li->lock); |
1409 | } | 1515 | } |
1410 | 1516 | ||
1411 | int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) | 1517 | static int do_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) |
1412 | { | 1518 | { |
1413 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; | ||
1414 | int rc; | 1519 | int rc; |
1415 | 1520 | ||
1416 | spin_lock(&li->lock); | ||
1417 | switch (irq->type) { | 1521 | switch (irq->type) { |
1418 | case KVM_S390_PROGRAM_INT: | 1522 | case KVM_S390_PROGRAM_INT: |
1419 | VCPU_EVENT(vcpu, 3, "inject: program check %d (from user)", | 1523 | VCPU_EVENT(vcpu, 3, "inject: program check %d (from user)", |
@@ -1453,83 +1557,130 @@ int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) | |||
1453 | default: | 1557 | default: |
1454 | rc = -EINVAL; | 1558 | rc = -EINVAL; |
1455 | } | 1559 | } |
1560 | |||
1561 | return rc; | ||
1562 | } | ||
1563 | |||
1564 | int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) | ||
1565 | { | ||
1566 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; | ||
1567 | int rc; | ||
1568 | |||
1569 | spin_lock(&li->lock); | ||
1570 | rc = do_inject_vcpu(vcpu, irq); | ||
1456 | spin_unlock(&li->lock); | 1571 | spin_unlock(&li->lock); |
1457 | if (!rc) | 1572 | if (!rc) |
1458 | kvm_s390_vcpu_wakeup(vcpu); | 1573 | kvm_s390_vcpu_wakeup(vcpu); |
1459 | return rc; | 1574 | return rc; |
1460 | } | 1575 | } |
1461 | 1576 | ||
1462 | void kvm_s390_clear_float_irqs(struct kvm *kvm) | 1577 | static inline void clear_irq_list(struct list_head *_list) |
1463 | { | 1578 | { |
1464 | struct kvm_s390_float_interrupt *fi; | 1579 | struct kvm_s390_interrupt_info *inti, *n; |
1465 | struct kvm_s390_interrupt_info *n, *inti = NULL; | ||
1466 | 1580 | ||
1467 | fi = &kvm->arch.float_int; | 1581 | list_for_each_entry_safe(inti, n, _list, list) { |
1468 | spin_lock(&fi->lock); | ||
1469 | list_for_each_entry_safe(inti, n, &fi->list, list) { | ||
1470 | list_del(&inti->list); | 1582 | list_del(&inti->list); |
1471 | kfree(inti); | 1583 | kfree(inti); |
1472 | } | 1584 | } |
1473 | fi->irq_count = 0; | ||
1474 | atomic_set(&fi->active, 0); | ||
1475 | spin_unlock(&fi->lock); | ||
1476 | } | 1585 | } |
1477 | 1586 | ||
1478 | static inline int copy_irq_to_user(struct kvm_s390_interrupt_info *inti, | 1587 | static void inti_to_irq(struct kvm_s390_interrupt_info *inti, |
1479 | u8 *addr) | 1588 | struct kvm_s390_irq *irq) |
1480 | { | 1589 | { |
1481 | struct kvm_s390_irq __user *uptr = (struct kvm_s390_irq __user *) addr; | 1590 | irq->type = inti->type; |
1482 | struct kvm_s390_irq irq = {0}; | ||
1483 | |||
1484 | irq.type = inti->type; | ||
1485 | switch (inti->type) { | 1591 | switch (inti->type) { |
1486 | case KVM_S390_INT_PFAULT_INIT: | 1592 | case KVM_S390_INT_PFAULT_INIT: |
1487 | case KVM_S390_INT_PFAULT_DONE: | 1593 | case KVM_S390_INT_PFAULT_DONE: |
1488 | case KVM_S390_INT_VIRTIO: | 1594 | case KVM_S390_INT_VIRTIO: |
1489 | case KVM_S390_INT_SERVICE: | 1595 | irq->u.ext = inti->ext; |
1490 | irq.u.ext = inti->ext; | ||
1491 | break; | 1596 | break; |
1492 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: | 1597 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
1493 | irq.u.io = inti->io; | 1598 | irq->u.io = inti->io; |
1494 | break; | 1599 | break; |
1495 | case KVM_S390_MCHK: | ||
1496 | irq.u.mchk = inti->mchk; | ||
1497 | break; | ||
1498 | default: | ||
1499 | return -EINVAL; | ||
1500 | } | 1600 | } |
1601 | } | ||
1501 | 1602 | ||
1502 | if (copy_to_user(uptr, &irq, sizeof(irq))) | 1603 | void kvm_s390_clear_float_irqs(struct kvm *kvm) |
1503 | return -EFAULT; | 1604 | { |
1605 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; | ||
1606 | int i; | ||
1504 | 1607 | ||
1505 | return 0; | 1608 | spin_lock(&fi->lock); |
1506 | } | 1609 | for (i = 0; i < FIRQ_LIST_COUNT; i++) |
1610 | clear_irq_list(&fi->lists[i]); | ||
1611 | for (i = 0; i < FIRQ_MAX_COUNT; i++) | ||
1612 | fi->counters[i] = 0; | ||
1613 | spin_unlock(&fi->lock); | ||
1614 | }; | ||
1507 | 1615 | ||
1508 | static int get_all_floating_irqs(struct kvm *kvm, __u8 *buf, __u64 len) | 1616 | static int get_all_floating_irqs(struct kvm *kvm, u8 __user *usrbuf, u64 len) |
1509 | { | 1617 | { |
1510 | struct kvm_s390_interrupt_info *inti; | 1618 | struct kvm_s390_interrupt_info *inti; |
1511 | struct kvm_s390_float_interrupt *fi; | 1619 | struct kvm_s390_float_interrupt *fi; |
1620 | struct kvm_s390_irq *buf; | ||
1621 | struct kvm_s390_irq *irq; | ||
1622 | int max_irqs; | ||
1512 | int ret = 0; | 1623 | int ret = 0; |
1513 | int n = 0; | 1624 | int n = 0; |
1625 | int i; | ||
1626 | |||
1627 | if (len > KVM_S390_FLIC_MAX_BUFFER || len == 0) | ||
1628 | return -EINVAL; | ||
1629 | |||
1630 | /* | ||
1631 | * We are already using -ENOMEM to signal | ||
1632 | * userspace it may retry with a bigger buffer, | ||
1633 | * so we need to use something else for this case | ||
1634 | */ | ||
1635 | buf = vzalloc(len); | ||
1636 | if (!buf) | ||
1637 | return -ENOBUFS; | ||
1638 | |||
1639 | max_irqs = len / sizeof(struct kvm_s390_irq); | ||
1514 | 1640 | ||
1515 | fi = &kvm->arch.float_int; | 1641 | fi = &kvm->arch.float_int; |
1516 | spin_lock(&fi->lock); | 1642 | spin_lock(&fi->lock); |
1517 | 1643 | for (i = 0; i < FIRQ_LIST_COUNT; i++) { | |
1518 | list_for_each_entry(inti, &fi->list, list) { | 1644 | list_for_each_entry(inti, &fi->lists[i], list) { |
1519 | if (len < sizeof(struct kvm_s390_irq)) { | 1645 | if (n == max_irqs) { |
1646 | /* signal userspace to try again */ | ||
1647 | ret = -ENOMEM; | ||
1648 | goto out; | ||
1649 | } | ||
1650 | inti_to_irq(inti, &buf[n]); | ||
1651 | n++; | ||
1652 | } | ||
1653 | } | ||
1654 | if (test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs)) { | ||
1655 | if (n == max_irqs) { | ||
1520 | /* signal userspace to try again */ | 1656 | /* signal userspace to try again */ |
1521 | ret = -ENOMEM; | 1657 | ret = -ENOMEM; |
1522 | break; | 1658 | goto out; |
1523 | } | 1659 | } |
1524 | ret = copy_irq_to_user(inti, buf); | 1660 | irq = (struct kvm_s390_irq *) &buf[n]; |
1525 | if (ret) | 1661 | irq->type = KVM_S390_INT_SERVICE; |
1526 | break; | 1662 | irq->u.ext = fi->srv_signal; |
1527 | buf += sizeof(struct kvm_s390_irq); | ||
1528 | len -= sizeof(struct kvm_s390_irq); | ||
1529 | n++; | 1663 | n++; |
1530 | } | 1664 | } |
1665 | if (test_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs)) { | ||
1666 | if (n == max_irqs) { | ||
1667 | /* signal userspace to try again */ | ||
1668 | ret = -ENOMEM; | ||
1669 | goto out; | ||
1670 | } | ||
1671 | irq = (struct kvm_s390_irq *) &buf[n]; | ||
1672 | irq->type = KVM_S390_MCHK; | ||
1673 | irq->u.mchk = fi->mchk; | ||
1674 | n++; | ||
1675 | } | ||
1531 | 1676 | ||
1677 | out: | ||
1532 | spin_unlock(&fi->lock); | 1678 | spin_unlock(&fi->lock); |
1679 | if (!ret && n > 0) { | ||
1680 | if (copy_to_user(usrbuf, buf, sizeof(struct kvm_s390_irq) * n)) | ||
1681 | ret = -EFAULT; | ||
1682 | } | ||
1683 | vfree(buf); | ||
1533 | 1684 | ||
1534 | return ret < 0 ? ret : n; | 1685 | return ret < 0 ? ret : n; |
1535 | } | 1686 | } |
@@ -1540,7 +1691,7 @@ static int flic_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr) | |||
1540 | 1691 | ||
1541 | switch (attr->group) { | 1692 | switch (attr->group) { |
1542 | case KVM_DEV_FLIC_GET_ALL_IRQS: | 1693 | case KVM_DEV_FLIC_GET_ALL_IRQS: |
1543 | r = get_all_floating_irqs(dev->kvm, (u8 *) attr->addr, | 1694 | r = get_all_floating_irqs(dev->kvm, (u8 __user *) attr->addr, |
1544 | attr->attr); | 1695 | attr->attr); |
1545 | break; | 1696 | break; |
1546 | default: | 1697 | default: |
@@ -1972,3 +2123,143 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm, | |||
1972 | { | 2123 | { |
1973 | return -EINVAL; | 2124 | return -EINVAL; |
1974 | } | 2125 | } |
2126 | |||
2127 | int kvm_s390_set_irq_state(struct kvm_vcpu *vcpu, void __user *irqstate, int len) | ||
2128 | { | ||
2129 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; | ||
2130 | struct kvm_s390_irq *buf; | ||
2131 | int r = 0; | ||
2132 | int n; | ||
2133 | |||
2134 | buf = vmalloc(len); | ||
2135 | if (!buf) | ||
2136 | return -ENOMEM; | ||
2137 | |||
2138 | if (copy_from_user((void *) buf, irqstate, len)) { | ||
2139 | r = -EFAULT; | ||
2140 | goto out_free; | ||
2141 | } | ||
2142 | |||
2143 | /* | ||
2144 | * Don't allow setting the interrupt state | ||
2145 | * when there are already interrupts pending | ||
2146 | */ | ||
2147 | spin_lock(&li->lock); | ||
2148 | if (li->pending_irqs) { | ||
2149 | r = -EBUSY; | ||
2150 | goto out_unlock; | ||
2151 | } | ||
2152 | |||
2153 | for (n = 0; n < len / sizeof(*buf); n++) { | ||
2154 | r = do_inject_vcpu(vcpu, &buf[n]); | ||
2155 | if (r) | ||
2156 | break; | ||
2157 | } | ||
2158 | |||
2159 | out_unlock: | ||
2160 | spin_unlock(&li->lock); | ||
2161 | out_free: | ||
2162 | vfree(buf); | ||
2163 | |||
2164 | return r; | ||
2165 | } | ||
2166 | |||
2167 | static void store_local_irq(struct kvm_s390_local_interrupt *li, | ||
2168 | struct kvm_s390_irq *irq, | ||
2169 | unsigned long irq_type) | ||
2170 | { | ||
2171 | switch (irq_type) { | ||
2172 | case IRQ_PEND_MCHK_EX: | ||
2173 | case IRQ_PEND_MCHK_REP: | ||
2174 | irq->type = KVM_S390_MCHK; | ||
2175 | irq->u.mchk = li->irq.mchk; | ||
2176 | break; | ||
2177 | case IRQ_PEND_PROG: | ||
2178 | irq->type = KVM_S390_PROGRAM_INT; | ||
2179 | irq->u.pgm = li->irq.pgm; | ||
2180 | break; | ||
2181 | case IRQ_PEND_PFAULT_INIT: | ||
2182 | irq->type = KVM_S390_INT_PFAULT_INIT; | ||
2183 | irq->u.ext = li->irq.ext; | ||
2184 | break; | ||
2185 | case IRQ_PEND_EXT_EXTERNAL: | ||
2186 | irq->type = KVM_S390_INT_EXTERNAL_CALL; | ||
2187 | irq->u.extcall = li->irq.extcall; | ||
2188 | break; | ||
2189 | case IRQ_PEND_EXT_CLOCK_COMP: | ||
2190 | irq->type = KVM_S390_INT_CLOCK_COMP; | ||
2191 | break; | ||
2192 | case IRQ_PEND_EXT_CPU_TIMER: | ||
2193 | irq->type = KVM_S390_INT_CPU_TIMER; | ||
2194 | break; | ||
2195 | case IRQ_PEND_SIGP_STOP: | ||
2196 | irq->type = KVM_S390_SIGP_STOP; | ||
2197 | irq->u.stop = li->irq.stop; | ||
2198 | break; | ||
2199 | case IRQ_PEND_RESTART: | ||
2200 | irq->type = KVM_S390_RESTART; | ||
2201 | break; | ||
2202 | case IRQ_PEND_SET_PREFIX: | ||
2203 | irq->type = KVM_S390_SIGP_SET_PREFIX; | ||
2204 | irq->u.prefix = li->irq.prefix; | ||
2205 | break; | ||
2206 | } | ||
2207 | } | ||
2208 | |||
2209 | int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu, __u8 __user *buf, int len) | ||
2210 | { | ||
2211 | uint8_t sigp_ctrl = vcpu->kvm->arch.sca->cpu[vcpu->vcpu_id].sigp_ctrl; | ||
2212 | unsigned long sigp_emerg_pending[BITS_TO_LONGS(KVM_MAX_VCPUS)]; | ||
2213 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; | ||
2214 | unsigned long pending_irqs; | ||
2215 | struct kvm_s390_irq irq; | ||
2216 | unsigned long irq_type; | ||
2217 | int cpuaddr; | ||
2218 | int n = 0; | ||
2219 | |||
2220 | spin_lock(&li->lock); | ||
2221 | pending_irqs = li->pending_irqs; | ||
2222 | memcpy(&sigp_emerg_pending, &li->sigp_emerg_pending, | ||
2223 | sizeof(sigp_emerg_pending)); | ||
2224 | spin_unlock(&li->lock); | ||
2225 | |||
2226 | for_each_set_bit(irq_type, &pending_irqs, IRQ_PEND_COUNT) { | ||
2227 | memset(&irq, 0, sizeof(irq)); | ||
2228 | if (irq_type == IRQ_PEND_EXT_EMERGENCY) | ||
2229 | continue; | ||
2230 | if (n + sizeof(irq) > len) | ||
2231 | return -ENOBUFS; | ||
2232 | store_local_irq(&vcpu->arch.local_int, &irq, irq_type); | ||
2233 | if (copy_to_user(&buf[n], &irq, sizeof(irq))) | ||
2234 | return -EFAULT; | ||
2235 | n += sizeof(irq); | ||
2236 | } | ||
2237 | |||
2238 | if (test_bit(IRQ_PEND_EXT_EMERGENCY, &pending_irqs)) { | ||
2239 | for_each_set_bit(cpuaddr, sigp_emerg_pending, KVM_MAX_VCPUS) { | ||
2240 | memset(&irq, 0, sizeof(irq)); | ||
2241 | if (n + sizeof(irq) > len) | ||
2242 | return -ENOBUFS; | ||
2243 | irq.type = KVM_S390_INT_EMERGENCY; | ||
2244 | irq.u.emerg.code = cpuaddr; | ||
2245 | if (copy_to_user(&buf[n], &irq, sizeof(irq))) | ||
2246 | return -EFAULT; | ||
2247 | n += sizeof(irq); | ||
2248 | } | ||
2249 | } | ||
2250 | |||
2251 | if ((sigp_ctrl & SIGP_CTRL_C) && | ||
2252 | (atomic_read(&vcpu->arch.sie_block->cpuflags) & | ||
2253 | CPUSTAT_ECALL_PEND)) { | ||
2254 | if (n + sizeof(irq) > len) | ||
2255 | return -ENOBUFS; | ||
2256 | memset(&irq, 0, sizeof(irq)); | ||
2257 | irq.type = KVM_S390_INT_EXTERNAL_CALL; | ||
2258 | irq.u.extcall.code = sigp_ctrl & SIGP_CTRL_SCN_MASK; | ||
2259 | if (copy_to_user(&buf[n], &irq, sizeof(irq))) | ||
2260 | return -EFAULT; | ||
2261 | n += sizeof(irq); | ||
2262 | } | ||
2263 | |||
2264 | return n; | ||
2265 | } | ||
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 9072127bd51b..3040b14751b8 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <asm/pgtable.h> | 31 | #include <asm/pgtable.h> |
32 | #include <asm/nmi.h> | 32 | #include <asm/nmi.h> |
33 | #include <asm/switch_to.h> | 33 | #include <asm/switch_to.h> |
34 | #include <asm/isc.h> | ||
34 | #include <asm/sclp.h> | 35 | #include <asm/sclp.h> |
35 | #include "kvm-s390.h" | 36 | #include "kvm-s390.h" |
36 | #include "gaccess.h" | 37 | #include "gaccess.h" |
@@ -40,6 +41,9 @@ | |||
40 | #include "trace-s390.h" | 41 | #include "trace-s390.h" |
41 | 42 | ||
42 | #define MEM_OP_MAX_SIZE 65536 /* Maximum transfer size for KVM_S390_MEM_OP */ | 43 | #define MEM_OP_MAX_SIZE 65536 /* Maximum transfer size for KVM_S390_MEM_OP */ |
44 | #define LOCAL_IRQS 32 | ||
45 | #define VCPU_IRQS_MAX_BUF (sizeof(struct kvm_s390_irq) * \ | ||
46 | (KVM_MAX_VCPUS + LOCAL_IRQS)) | ||
43 | 47 | ||
44 | #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU | 48 | #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU |
45 | 49 | ||
@@ -105,8 +109,8 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { | |||
105 | 109 | ||
106 | /* upper facilities limit for kvm */ | 110 | /* upper facilities limit for kvm */ |
107 | unsigned long kvm_s390_fac_list_mask[] = { | 111 | unsigned long kvm_s390_fac_list_mask[] = { |
108 | 0xff82fffbf4fc2000UL, | 112 | 0xffe6fffbfcfdfc40UL, |
109 | 0x005c000000000000UL, | 113 | 0x205c800000000000UL, |
110 | }; | 114 | }; |
111 | 115 | ||
112 | unsigned long kvm_s390_fac_list_mask_size(void) | 116 | unsigned long kvm_s390_fac_list_mask_size(void) |
@@ -176,9 +180,11 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) | |||
176 | case KVM_CAP_S390_IRQCHIP: | 180 | case KVM_CAP_S390_IRQCHIP: |
177 | case KVM_CAP_VM_ATTRIBUTES: | 181 | case KVM_CAP_VM_ATTRIBUTES: |
178 | case KVM_CAP_MP_STATE: | 182 | case KVM_CAP_MP_STATE: |
183 | case KVM_CAP_S390_INJECT_IRQ: | ||
179 | case KVM_CAP_S390_USER_SIGP: | 184 | case KVM_CAP_S390_USER_SIGP: |
180 | case KVM_CAP_S390_USER_STSI: | 185 | case KVM_CAP_S390_USER_STSI: |
181 | case KVM_CAP_S390_SKEYS: | 186 | case KVM_CAP_S390_SKEYS: |
187 | case KVM_CAP_S390_IRQ_STATE: | ||
182 | r = 1; | 188 | r = 1; |
183 | break; | 189 | break; |
184 | case KVM_CAP_S390_MEM_OP: | 190 | case KVM_CAP_S390_MEM_OP: |
@@ -1069,7 +1075,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) | |||
1069 | goto out_err; | 1075 | goto out_err; |
1070 | 1076 | ||
1071 | spin_lock_init(&kvm->arch.float_int.lock); | 1077 | spin_lock_init(&kvm->arch.float_int.lock); |
1072 | INIT_LIST_HEAD(&kvm->arch.float_int.list); | 1078 | for (i = 0; i < FIRQ_LIST_COUNT; i++) |
1079 | INIT_LIST_HEAD(&kvm->arch.float_int.lists[i]); | ||
1073 | init_waitqueue_head(&kvm->arch.ipte_wq); | 1080 | init_waitqueue_head(&kvm->arch.ipte_wq); |
1074 | mutex_init(&kvm->arch.ipte_mutex); | 1081 | mutex_init(&kvm->arch.ipte_mutex); |
1075 | 1082 | ||
@@ -2389,6 +2396,15 @@ long kvm_arch_vcpu_ioctl(struct file *filp, | |||
2389 | long r; | 2396 | long r; |
2390 | 2397 | ||
2391 | switch (ioctl) { | 2398 | switch (ioctl) { |
2399 | case KVM_S390_IRQ: { | ||
2400 | struct kvm_s390_irq s390irq; | ||
2401 | |||
2402 | r = -EFAULT; | ||
2403 | if (copy_from_user(&s390irq, argp, sizeof(s390irq))) | ||
2404 | break; | ||
2405 | r = kvm_s390_inject_vcpu(vcpu, &s390irq); | ||
2406 | break; | ||
2407 | } | ||
2392 | case KVM_S390_INTERRUPT: { | 2408 | case KVM_S390_INTERRUPT: { |
2393 | struct kvm_s390_interrupt s390int; | 2409 | struct kvm_s390_interrupt s390int; |
2394 | struct kvm_s390_irq s390irq; | 2410 | struct kvm_s390_irq s390irq; |
@@ -2488,6 +2504,38 @@ long kvm_arch_vcpu_ioctl(struct file *filp, | |||
2488 | r = -EFAULT; | 2504 | r = -EFAULT; |
2489 | break; | 2505 | break; |
2490 | } | 2506 | } |
2507 | case KVM_S390_SET_IRQ_STATE: { | ||
2508 | struct kvm_s390_irq_state irq_state; | ||
2509 | |||
2510 | r = -EFAULT; | ||
2511 | if (copy_from_user(&irq_state, argp, sizeof(irq_state))) | ||
2512 | break; | ||
2513 | if (irq_state.len > VCPU_IRQS_MAX_BUF || | ||
2514 | irq_state.len == 0 || | ||
2515 | irq_state.len % sizeof(struct kvm_s390_irq) > 0) { | ||
2516 | r = -EINVAL; | ||
2517 | break; | ||
2518 | } | ||
2519 | r = kvm_s390_set_irq_state(vcpu, | ||
2520 | (void __user *) irq_state.buf, | ||
2521 | irq_state.len); | ||
2522 | break; | ||
2523 | } | ||
2524 | case KVM_S390_GET_IRQ_STATE: { | ||
2525 | struct kvm_s390_irq_state irq_state; | ||
2526 | |||
2527 | r = -EFAULT; | ||
2528 | if (copy_from_user(&irq_state, argp, sizeof(irq_state))) | ||
2529 | break; | ||
2530 | if (irq_state.len == 0) { | ||
2531 | r = -EINVAL; | ||
2532 | break; | ||
2533 | } | ||
2534 | r = kvm_s390_get_irq_state(vcpu, | ||
2535 | (__u8 __user *) irq_state.buf, | ||
2536 | irq_state.len); | ||
2537 | break; | ||
2538 | } | ||
2491 | default: | 2539 | default: |
2492 | r = -ENOTTY; | 2540 | r = -ENOTTY; |
2493 | } | 2541 | } |
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h index c5aefef158e5..ca108b90ae56 100644 --- a/arch/s390/kvm/kvm-s390.h +++ b/arch/s390/kvm/kvm-s390.h | |||
@@ -178,7 +178,7 @@ int __must_check kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, | |||
178 | struct kvm_s390_irq *irq); | 178 | struct kvm_s390_irq *irq); |
179 | int __must_check kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code); | 179 | int __must_check kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code); |
180 | struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, | 180 | struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, |
181 | u64 cr6, u64 schid); | 181 | u64 isc_mask, u32 schid); |
182 | int kvm_s390_reinject_io_int(struct kvm *kvm, | 182 | int kvm_s390_reinject_io_int(struct kvm *kvm, |
183 | struct kvm_s390_interrupt_info *inti); | 183 | struct kvm_s390_interrupt_info *inti); |
184 | int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked); | 184 | int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked); |
@@ -272,6 +272,10 @@ int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu); | |||
272 | extern struct kvm_device_ops kvm_flic_ops; | 272 | extern struct kvm_device_ops kvm_flic_ops; |
273 | int kvm_s390_is_stop_irq_pending(struct kvm_vcpu *vcpu); | 273 | int kvm_s390_is_stop_irq_pending(struct kvm_vcpu *vcpu); |
274 | void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu); | 274 | void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu); |
275 | int kvm_s390_set_irq_state(struct kvm_vcpu *vcpu, | ||
276 | void __user *buf, int len); | ||
277 | int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu, | ||
278 | __u8 __user *buf, int len); | ||
275 | 279 | ||
276 | /* implemented in guestdbg.c */ | 280 | /* implemented in guestdbg.c */ |
277 | void kvm_s390_backup_guest_per_regs(struct kvm_vcpu *vcpu); | 281 | void kvm_s390_backup_guest_per_regs(struct kvm_vcpu *vcpu); |
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c index 5e4658d20c77..d22d8ee1ff9d 100644 --- a/arch/s390/kvm/priv.c +++ b/arch/s390/kvm/priv.c | |||
@@ -294,10 +294,13 @@ reinject_interrupt: | |||
294 | 294 | ||
295 | static int handle_tsch(struct kvm_vcpu *vcpu) | 295 | static int handle_tsch(struct kvm_vcpu *vcpu) |
296 | { | 296 | { |
297 | struct kvm_s390_interrupt_info *inti; | 297 | struct kvm_s390_interrupt_info *inti = NULL; |
298 | const u64 isc_mask = 0xffUL << 24; /* all iscs set */ | ||
298 | 299 | ||
299 | inti = kvm_s390_get_io_int(vcpu->kvm, 0, | 300 | /* a valid schid has at least one bit set */ |
300 | vcpu->run->s.regs.gprs[1]); | 301 | if (vcpu->run->s.regs.gprs[1]) |
302 | inti = kvm_s390_get_io_int(vcpu->kvm, isc_mask, | ||
303 | vcpu->run->s.regs.gprs[1]); | ||
301 | 304 | ||
302 | /* | 305 | /* |
303 | * Prepare exit to userspace. | 306 | * Prepare exit to userspace. |
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 05a2083f7a28..f574d7be7631 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h | |||
@@ -558,6 +558,13 @@ struct kvm_s390_irq { | |||
558 | } u; | 558 | } u; |
559 | }; | 559 | }; |
560 | 560 | ||
561 | struct kvm_s390_irq_state { | ||
562 | __u64 buf; | ||
563 | __u32 flags; | ||
564 | __u32 len; | ||
565 | __u32 reserved[4]; | ||
566 | }; | ||
567 | |||
561 | /* for KVM_SET_GUEST_DEBUG */ | 568 | /* for KVM_SET_GUEST_DEBUG */ |
562 | 569 | ||
563 | #define KVM_GUESTDBG_ENABLE 0x00000001 | 570 | #define KVM_GUESTDBG_ENABLE 0x00000001 |
@@ -804,6 +811,8 @@ struct kvm_ppc_smmu_info { | |||
804 | #define KVM_CAP_S390_SKEYS 110 | 811 | #define KVM_CAP_S390_SKEYS 110 |
805 | #define KVM_CAP_MIPS_FPU 111 | 812 | #define KVM_CAP_MIPS_FPU 111 |
806 | #define KVM_CAP_MIPS_MSA 112 | 813 | #define KVM_CAP_MIPS_MSA 112 |
814 | #define KVM_CAP_S390_INJECT_IRQ 113 | ||
815 | #define KVM_CAP_S390_IRQ_STATE 114 | ||
807 | 816 | ||
808 | #ifdef KVM_CAP_IRQ_ROUTING | 817 | #ifdef KVM_CAP_IRQ_ROUTING |
809 | 818 | ||
@@ -1184,6 +1193,11 @@ struct kvm_s390_ucas_mapping { | |||
1184 | /* Available with KVM_CAP_S390_SKEYS */ | 1193 | /* Available with KVM_CAP_S390_SKEYS */ |
1185 | #define KVM_S390_GET_SKEYS _IOW(KVMIO, 0xb2, struct kvm_s390_skeys) | 1194 | #define KVM_S390_GET_SKEYS _IOW(KVMIO, 0xb2, struct kvm_s390_skeys) |
1186 | #define KVM_S390_SET_SKEYS _IOW(KVMIO, 0xb3, struct kvm_s390_skeys) | 1195 | #define KVM_S390_SET_SKEYS _IOW(KVMIO, 0xb3, struct kvm_s390_skeys) |
1196 | /* Available with KVM_CAP_S390_INJECT_IRQ */ | ||
1197 | #define KVM_S390_IRQ _IOW(KVMIO, 0xb4, struct kvm_s390_irq) | ||
1198 | /* Available with KVM_CAP_S390_IRQ_STATE */ | ||
1199 | #define KVM_S390_SET_IRQ_STATE _IOW(KVMIO, 0xb5, struct kvm_s390_irq_state) | ||
1200 | #define KVM_S390_GET_IRQ_STATE _IOW(KVMIO, 0xb6, struct kvm_s390_irq_state) | ||
1187 | 1201 | ||
1188 | #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) | 1202 | #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) |
1189 | #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) | 1203 | #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) |
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index efe59ae64dc3..0d06b7b63e95 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -2113,7 +2113,7 @@ static long kvm_vcpu_ioctl(struct file *filp, | |||
2113 | * Special cases: vcpu ioctls that are asynchronous to vcpu execution, | 2113 | * Special cases: vcpu ioctls that are asynchronous to vcpu execution, |
2114 | * so vcpu_load() would break it. | 2114 | * so vcpu_load() would break it. |
2115 | */ | 2115 | */ |
2116 | if (ioctl == KVM_S390_INTERRUPT || ioctl == KVM_INTERRUPT) | 2116 | if (ioctl == KVM_S390_INTERRUPT || ioctl == KVM_S390_IRQ || ioctl == KVM_INTERRUPT) |
2117 | return kvm_arch_vcpu_ioctl(filp, ioctl, arg); | 2117 | return kvm_arch_vcpu_ioctl(filp, ioctl, arg); |
2118 | #endif | 2118 | #endif |
2119 | 2119 | ||