interrupt.c (201ae986ead7582f8d9506a5d11459b280b954c8) | interrupt.c (0890ddea1a90e57114b5704cd560192c743f3d2e) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * handling kvm guest interrupts 4 * 5 * Copyright IBM Corp. 2008, 2020 6 * 7 * Author(s): Carsten Otte <cotte@de.ibm.com> 8 */ --- 310 unchanged lines hidden (view full) --- 319 320static inline int gisa_tac_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc) 321{ 322 return test_and_clear_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa); 323} 324 325static inline unsigned long pending_irqs_no_gisa(struct kvm_vcpu *vcpu) 326{ | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * handling kvm guest interrupts 4 * 5 * Copyright IBM Corp. 2008, 2020 6 * 7 * Author(s): Carsten Otte <cotte@de.ibm.com> 8 */ --- 310 unchanged lines hidden (view full) --- 319 320static inline int gisa_tac_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc) 321{ 322 return test_and_clear_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa); 323} 324 325static inline unsigned long pending_irqs_no_gisa(struct kvm_vcpu *vcpu) 326{ |
327 return vcpu->kvm->arch.float_int.pending_irqs | 328 vcpu->arch.local_int.pending_irqs; | 327 unsigned long pending = vcpu->kvm->arch.float_int.pending_irqs | 328 vcpu->arch.local_int.pending_irqs; 329 330 pending &= ~vcpu->kvm->arch.float_int.masked_irqs; 331 return pending; |
329} 330 331static inline unsigned long pending_irqs(struct kvm_vcpu *vcpu) 332{ 333 struct kvm_s390_gisa_interrupt *gi = &vcpu->kvm->arch.gisa_int; 334 unsigned long pending_mask; 335 336 pending_mask = pending_irqs_no_gisa(vcpu); --- 41 unchanged lines hidden (view full) --- 378 if (!(vcpu->arch.sie_block->gcr[0] & CR0_EXTERNAL_CALL_SUBMASK)) 379 __clear_bit(IRQ_PEND_EXT_EXTERNAL, &active_mask); 380 if (!(vcpu->arch.sie_block->gcr[0] & CR0_EMERGENCY_SIGNAL_SUBMASK)) 381 __clear_bit(IRQ_PEND_EXT_EMERGENCY, &active_mask); 382 if (!(vcpu->arch.sie_block->gcr[0] & CR0_CLOCK_COMPARATOR_SUBMASK)) 383 __clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &active_mask); 384 if (!(vcpu->arch.sie_block->gcr[0] & CR0_CPU_TIMER_SUBMASK)) 385 __clear_bit(IRQ_PEND_EXT_CPU_TIMER, &active_mask); | 332} 333 334static inline unsigned long pending_irqs(struct kvm_vcpu *vcpu) 335{ 336 struct kvm_s390_gisa_interrupt *gi = &vcpu->kvm->arch.gisa_int; 337 unsigned long pending_mask; 338 339 pending_mask = pending_irqs_no_gisa(vcpu); --- 41 unchanged lines hidden (view full) --- 381 if (!(vcpu->arch.sie_block->gcr[0] & CR0_EXTERNAL_CALL_SUBMASK)) 382 __clear_bit(IRQ_PEND_EXT_EXTERNAL, &active_mask); 383 if (!(vcpu->arch.sie_block->gcr[0] & CR0_EMERGENCY_SIGNAL_SUBMASK)) 384 __clear_bit(IRQ_PEND_EXT_EMERGENCY, &active_mask); 385 if (!(vcpu->arch.sie_block->gcr[0] & CR0_CLOCK_COMPARATOR_SUBMASK)) 386 __clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &active_mask); 387 if (!(vcpu->arch.sie_block->gcr[0] & CR0_CPU_TIMER_SUBMASK)) 388 __clear_bit(IRQ_PEND_EXT_CPU_TIMER, &active_mask); |
386 if (!(vcpu->arch.sie_block->gcr[0] & CR0_SERVICE_SIGNAL_SUBMASK)) | 389 if (!(vcpu->arch.sie_block->gcr[0] & CR0_SERVICE_SIGNAL_SUBMASK)) { |
387 __clear_bit(IRQ_PEND_EXT_SERVICE, &active_mask); | 390 __clear_bit(IRQ_PEND_EXT_SERVICE, &active_mask); |
391 __clear_bit(IRQ_PEND_EXT_SERVICE_EV, &active_mask); 392 } |
|
388 if (psw_mchk_disabled(vcpu)) 389 active_mask &= ~IRQ_PEND_MCHK_MASK; 390 /* PV guest cpus can have a single interruption injected at a time. */ 391 if (kvm_s390_pv_cpu_is_protected(vcpu) && 392 vcpu->arch.sie_block->iictl != IICTL_CODE_NONE) 393 active_mask &= ~(IRQ_PEND_EXT_II_MASK | 394 IRQ_PEND_IO_MASK | 395 IRQ_PEND_MCHK_MASK); --- 545 unchanged lines hidden (view full) --- 941 (u16 *)__LC_PGM_INT_CODE); 942 rc |= write_guest_lc(vcpu, __LC_PGM_OLD_PSW, 943 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); 944 rc |= read_guest_lc(vcpu, __LC_PGM_NEW_PSW, 945 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); 946 return rc ? -EFAULT : 0; 947} 948 | 393 if (psw_mchk_disabled(vcpu)) 394 active_mask &= ~IRQ_PEND_MCHK_MASK; 395 /* PV guest cpus can have a single interruption injected at a time. */ 396 if (kvm_s390_pv_cpu_is_protected(vcpu) && 397 vcpu->arch.sie_block->iictl != IICTL_CODE_NONE) 398 active_mask &= ~(IRQ_PEND_EXT_II_MASK | 399 IRQ_PEND_IO_MASK | 400 IRQ_PEND_MCHK_MASK); --- 545 unchanged lines hidden (view full) --- 946 (u16 *)__LC_PGM_INT_CODE); 947 rc |= write_guest_lc(vcpu, __LC_PGM_OLD_PSW, 948 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); 949 rc |= read_guest_lc(vcpu, __LC_PGM_NEW_PSW, 950 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); 951 return rc ? -EFAULT : 0; 952} 953 |
954#define SCCB_MASK 0xFFFFFFF8 955#define SCCB_EVENT_PENDING 0x3 956 957static int write_sclp(struct kvm_vcpu *vcpu, u32 parm) 958{ 959 int rc; 960 961 if (kvm_s390_pv_cpu_get_handle(vcpu)) { 962 vcpu->arch.sie_block->iictl = IICTL_CODE_EXT; 963 vcpu->arch.sie_block->eic = EXT_IRQ_SERVICE_SIG; 964 vcpu->arch.sie_block->eiparams = parm; 965 return 0; 966 } 967 968 rc = put_guest_lc(vcpu, EXT_IRQ_SERVICE_SIG, (u16 *)__LC_EXT_INT_CODE); 969 rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR); 970 rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, 971 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); 972 rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, 973 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); 974 rc |= put_guest_lc(vcpu, parm, 975 (u32 *)__LC_EXT_PARAMS); 976 977 return rc ? -EFAULT : 0; 978} 979 |
|
949static int __must_check __deliver_service(struct kvm_vcpu *vcpu) 950{ 951 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; 952 struct kvm_s390_ext_info ext; | 980static int __must_check __deliver_service(struct kvm_vcpu *vcpu) 981{ 982 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; 983 struct kvm_s390_ext_info ext; |
953 int rc = 0; | |
954 955 spin_lock(&fi->lock); | 984 985 spin_lock(&fi->lock); |
956 if (!(test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs))) { | 986 if (test_bit(IRQ_PEND_EXT_SERVICE, &fi->masked_irqs) || 987 !(test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs))) { |
957 spin_unlock(&fi->lock); 958 return 0; 959 } 960 ext = fi->srv_signal; 961 memset(&fi->srv_signal, 0, sizeof(ext)); 962 clear_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs); | 988 spin_unlock(&fi->lock); 989 return 0; 990 } 991 ext = fi->srv_signal; 992 memset(&fi->srv_signal, 0, sizeof(ext)); 993 clear_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs); |
994 clear_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs); 995 if (kvm_s390_pv_cpu_is_protected(vcpu)) 996 set_bit(IRQ_PEND_EXT_SERVICE, &fi->masked_irqs); |
|
963 spin_unlock(&fi->lock); 964 965 VCPU_EVENT(vcpu, 4, "deliver: sclp parameter 0x%x", 966 ext.ext_params); 967 vcpu->stat.deliver_service_signal++; 968 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_SERVICE, 969 ext.ext_params, 0); 970 | 997 spin_unlock(&fi->lock); 998 999 VCPU_EVENT(vcpu, 4, "deliver: sclp parameter 0x%x", 1000 ext.ext_params); 1001 vcpu->stat.deliver_service_signal++; 1002 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_SERVICE, 1003 ext.ext_params, 0); 1004 |
971 rc = put_guest_lc(vcpu, EXT_IRQ_SERVICE_SIG, (u16 *)__LC_EXT_INT_CODE); 972 rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR); 973 rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, 974 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); 975 rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, 976 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); 977 rc |= put_guest_lc(vcpu, ext.ext_params, 978 (u32 *)__LC_EXT_PARAMS); | 1005 return write_sclp(vcpu, ext.ext_params); 1006} |
979 | 1007 |
980 return rc ? -EFAULT : 0; | 1008static int __must_check __deliver_service_ev(struct kvm_vcpu *vcpu) 1009{ 1010 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; 1011 struct kvm_s390_ext_info ext; 1012 1013 spin_lock(&fi->lock); 1014 if (!(test_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs))) { 1015 spin_unlock(&fi->lock); 1016 return 0; 1017 } 1018 ext = fi->srv_signal; 1019 /* only clear the event bit */ 1020 fi->srv_signal.ext_params &= ~SCCB_EVENT_PENDING; 1021 clear_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs); 1022 spin_unlock(&fi->lock); 1023 1024 VCPU_EVENT(vcpu, 4, "%s", "deliver: sclp parameter event"); 1025 vcpu->stat.deliver_service_signal++; 1026 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_SERVICE, 1027 ext.ext_params, 0); 1028 1029 return write_sclp(vcpu, SCCB_EVENT_PENDING); |
981} 982 983static int __must_check __deliver_pfault_done(struct kvm_vcpu *vcpu) 984{ 985 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; 986 struct kvm_s390_interrupt_info *inti; 987 int rc = 0; 988 --- 388 unchanged lines hidden (view full) --- 1377 rc = __deliver_set_prefix(vcpu); 1378 break; 1379 case IRQ_PEND_PFAULT_INIT: 1380 rc = __deliver_pfault_init(vcpu); 1381 break; 1382 case IRQ_PEND_EXT_SERVICE: 1383 rc = __deliver_service(vcpu); 1384 break; | 1030} 1031 1032static int __must_check __deliver_pfault_done(struct kvm_vcpu *vcpu) 1033{ 1034 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; 1035 struct kvm_s390_interrupt_info *inti; 1036 int rc = 0; 1037 --- 388 unchanged lines hidden (view full) --- 1426 rc = __deliver_set_prefix(vcpu); 1427 break; 1428 case IRQ_PEND_PFAULT_INIT: 1429 rc = __deliver_pfault_init(vcpu); 1430 break; 1431 case IRQ_PEND_EXT_SERVICE: 1432 rc = __deliver_service(vcpu); 1433 break; |
1434 case IRQ_PEND_EXT_SERVICE_EV: 1435 rc = __deliver_service_ev(vcpu); 1436 break; |
|
1385 case IRQ_PEND_PFAULT_DONE: 1386 rc = __deliver_pfault_done(vcpu); 1387 break; 1388 case IRQ_PEND_VIRTIO: 1389 rc = __deliver_virtio(vcpu); 1390 break; 1391 default: 1392 WARN_ONCE(1, "Unknown pending irq type %ld", irq_type); --- 336 unchanged lines hidden (view full) --- 1729 kvm_s390_reinject_io_int(kvm, inti); 1730 inti = tmp_inti; 1731 } else 1732 gisa_set_ipm_gisc(gi->origin, isc); 1733out: 1734 return inti; 1735} 1736 | 1437 case IRQ_PEND_PFAULT_DONE: 1438 rc = __deliver_pfault_done(vcpu); 1439 break; 1440 case IRQ_PEND_VIRTIO: 1441 rc = __deliver_virtio(vcpu); 1442 break; 1443 default: 1444 WARN_ONCE(1, "Unknown pending irq type %ld", irq_type); --- 336 unchanged lines hidden (view full) --- 1781 kvm_s390_reinject_io_int(kvm, inti); 1782 inti = tmp_inti; 1783 } else 1784 gisa_set_ipm_gisc(gi->origin, isc); 1785out: 1786 return inti; 1787} 1788 |
1737#define SCCB_MASK 0xFFFFFFF8 1738#define SCCB_EVENT_PENDING 0x3 1739 | |
1740static int __inject_service(struct kvm *kvm, 1741 struct kvm_s390_interrupt_info *inti) 1742{ 1743 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; 1744 1745 kvm->stat.inject_service_signal++; 1746 spin_lock(&fi->lock); 1747 fi->srv_signal.ext_params |= inti->ext.ext_params & SCCB_EVENT_PENDING; | 1789static int __inject_service(struct kvm *kvm, 1790 struct kvm_s390_interrupt_info *inti) 1791{ 1792 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; 1793 1794 kvm->stat.inject_service_signal++; 1795 spin_lock(&fi->lock); 1796 fi->srv_signal.ext_params |= inti->ext.ext_params & SCCB_EVENT_PENDING; |
1797 1798 /* We always allow events, track them separately from the sccb ints */ 1799 if (fi->srv_signal.ext_params & SCCB_EVENT_PENDING) 1800 set_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs); 1801 |
|
1748 /* 1749 * Early versions of the QEMU s390 bios will inject several 1750 * service interrupts after another without handling a 1751 * condition code indicating busy. 1752 * We will silently ignore those superfluous sccb values. 1753 * A future version of QEMU will take care of serialization 1754 * of servc requests 1755 */ --- 380 unchanged lines hidden (view full) --- 2136 } 2137} 2138 2139void kvm_s390_clear_float_irqs(struct kvm *kvm) 2140{ 2141 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; 2142 int i; 2143 | 1802 /* 1803 * Early versions of the QEMU s390 bios will inject several 1804 * service interrupts after another without handling a 1805 * condition code indicating busy. 1806 * We will silently ignore those superfluous sccb values. 1807 * A future version of QEMU will take care of serialization 1808 * of servc requests 1809 */ --- 380 unchanged lines hidden (view full) --- 2190 } 2191} 2192 2193void kvm_s390_clear_float_irqs(struct kvm *kvm) 2194{ 2195 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; 2196 int i; 2197 |
2198 mutex_lock(&kvm->lock); 2199 if (!kvm_s390_pv_is_protected(kvm)) 2200 fi->masked_irqs = 0; 2201 mutex_unlock(&kvm->lock); |
|
2144 spin_lock(&fi->lock); 2145 fi->pending_irqs = 0; 2146 memset(&fi->srv_signal, 0, sizeof(fi->srv_signal)); 2147 memset(&fi->mchk, 0, sizeof(fi->mchk)); 2148 for (i = 0; i < FIRQ_LIST_COUNT; i++) 2149 clear_irq_list(&fi->lists[i]); 2150 for (i = 0; i < FIRQ_MAX_COUNT; i++) 2151 fi->counters[i] = 0; --- 50 unchanged lines hidden (view full) --- 2202 /* signal userspace to try again */ 2203 ret = -ENOMEM; 2204 goto out; 2205 } 2206 inti_to_irq(inti, &buf[n]); 2207 n++; 2208 } 2209 } | 2202 spin_lock(&fi->lock); 2203 fi->pending_irqs = 0; 2204 memset(&fi->srv_signal, 0, sizeof(fi->srv_signal)); 2205 memset(&fi->mchk, 0, sizeof(fi->mchk)); 2206 for (i = 0; i < FIRQ_LIST_COUNT; i++) 2207 clear_irq_list(&fi->lists[i]); 2208 for (i = 0; i < FIRQ_MAX_COUNT; i++) 2209 fi->counters[i] = 0; --- 50 unchanged lines hidden (view full) --- 2260 /* signal userspace to try again */ 2261 ret = -ENOMEM; 2262 goto out; 2263 } 2264 inti_to_irq(inti, &buf[n]); 2265 n++; 2266 } 2267 } |
2210 if (test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs)) { | 2268 if (test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs) || 2269 test_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs)) { |
2211 if (n == max_irqs) { 2212 /* signal userspace to try again */ 2213 ret = -ENOMEM; 2214 goto out; 2215 } 2216 irq = (struct kvm_s390_irq *) &buf[n]; 2217 irq->type = KVM_S390_INT_SERVICE; 2218 irq->u.ext = fi->srv_signal; --- 1029 unchanged lines hidden --- | 2270 if (n == max_irqs) { 2271 /* signal userspace to try again */ 2272 ret = -ENOMEM; 2273 goto out; 2274 } 2275 irq = (struct kvm_s390_irq *) &buf[n]; 2276 irq->type = KVM_S390_INT_SERVICE; 2277 irq->u.ext = fi->srv_signal; --- 1029 unchanged lines hidden --- |