^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * handling kvm guest interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright IBM Corp. 2008, 2020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author(s): Carsten Otte <cotte@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define KMSG_COMPONENT "kvm-s390"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kvm_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/hrtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/nospec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/bitmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/dis.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/sclp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/isc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/gmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <asm/switch_to.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/airq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "kvm-s390.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "gaccess.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "trace-s390.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define PFAULT_INIT 0x0600
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define PFAULT_DONE 0x0680
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define VIRTIO_PARAM 0x0d00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static struct kvm_s390_gib *gib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* handle external calls via sigp interpretation facility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static int sca_ext_call_pending(struct kvm_vcpu *vcpu, int *src_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int c, scn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (!kvm_s390_test_cpuflags(vcpu, CPUSTAT_ECALL_PEND))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) BUG_ON(!kvm_s390_use_sca_entries());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) read_lock(&vcpu->kvm->arch.sca_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (vcpu->kvm->arch.use_esca) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct esca_block *sca = vcpu->kvm->arch.sca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) union esca_sigp_ctrl sigp_ctrl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) sca->cpu[vcpu->vcpu_id].sigp_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) c = sigp_ctrl.c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) scn = sigp_ctrl.scn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct bsca_block *sca = vcpu->kvm->arch.sca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) union bsca_sigp_ctrl sigp_ctrl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) sca->cpu[vcpu->vcpu_id].sigp_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) c = sigp_ctrl.c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) scn = sigp_ctrl.scn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) read_unlock(&vcpu->kvm->arch.sca_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (src_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) *src_id = scn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int expect, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) BUG_ON(!kvm_s390_use_sca_entries());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) read_lock(&vcpu->kvm->arch.sca_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (vcpu->kvm->arch.use_esca) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct esca_block *sca = vcpu->kvm->arch.sca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) union esca_sigp_ctrl *sigp_ctrl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) &(sca->cpu[vcpu->vcpu_id].sigp_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) union esca_sigp_ctrl new_val = {0}, old_val = *sigp_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) new_val.scn = src_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) new_val.c = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) old_val.c = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) expect = old_val.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) rc = cmpxchg(&sigp_ctrl->value, old_val.value, new_val.value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct bsca_block *sca = vcpu->kvm->arch.sca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) union bsca_sigp_ctrl *sigp_ctrl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) &(sca->cpu[vcpu->vcpu_id].sigp_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) union bsca_sigp_ctrl new_val = {0}, old_val = *sigp_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) new_val.scn = src_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) new_val.c = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) old_val.c = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) expect = old_val.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) rc = cmpxchg(&sigp_ctrl->value, old_val.value, new_val.value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) read_unlock(&vcpu->kvm->arch.sca_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (rc != expect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* another external call is pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) kvm_s390_set_cpuflags(vcpu, CPUSTAT_ECALL_PEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static void sca_clear_ext_call(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int rc, expect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (!kvm_s390_use_sca_entries())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) kvm_s390_clear_cpuflags(vcpu, CPUSTAT_ECALL_PEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) read_lock(&vcpu->kvm->arch.sca_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (vcpu->kvm->arch.use_esca) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct esca_block *sca = vcpu->kvm->arch.sca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) union esca_sigp_ctrl *sigp_ctrl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) &(sca->cpu[vcpu->vcpu_id].sigp_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) union esca_sigp_ctrl old = *sigp_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) expect = old.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) rc = cmpxchg(&sigp_ctrl->value, old.value, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct bsca_block *sca = vcpu->kvm->arch.sca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) union bsca_sigp_ctrl *sigp_ctrl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) &(sca->cpu[vcpu->vcpu_id].sigp_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) union bsca_sigp_ctrl old = *sigp_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) expect = old.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) rc = cmpxchg(&sigp_ctrl->value, old.value, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) read_unlock(&vcpu->kvm->arch.sca_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) WARN_ON(rc != expect); /* cannot clear? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int psw_extint_disabled(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static int psw_ioint_disabled(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static int psw_mchk_disabled(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static int psw_interrupts_disabled(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return psw_extint_disabled(vcpu) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) psw_ioint_disabled(vcpu) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) psw_mchk_disabled(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int ckc_interrupts_enabled(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (psw_extint_disabled(vcpu) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) !(vcpu->arch.sie_block->gcr[0] & CR0_CLOCK_COMPARATOR_SUBMASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (guestdbg_enabled(vcpu) && guestdbg_sstep_enabled(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* No timer interrupts when single stepping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int ckc_irq_pending(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) const u64 now = kvm_s390_get_tod_clock_fast(vcpu->kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) const u64 ckc = vcpu->arch.sie_block->ckc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (vcpu->arch.sie_block->gcr[0] & CR0_CLOCK_COMPARATOR_SIGN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if ((s64)ckc >= (s64)now)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) } else if (ckc >= now) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return ckc_interrupts_enabled(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static int cpu_timer_interrupts_enabled(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return !psw_extint_disabled(vcpu) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) (vcpu->arch.sie_block->gcr[0] & CR0_CPU_TIMER_SUBMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int cpu_timer_irq_pending(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (!cpu_timer_interrupts_enabled(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return kvm_s390_get_cpu_timer(vcpu) >> 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static uint64_t isc_to_isc_bits(int isc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return (0x80 >> isc) << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static inline u32 isc_to_int_word(u8 isc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return ((u32)isc << 27) | 0x80000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static inline u8 int_word_to_isc(u32 int_word)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return (int_word & 0x38000000) >> 27;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * To use atomic bitmap functions, we have to provide a bitmap address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * that is u64 aligned. However, the ipm might be u32 aligned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * Therefore, we logically start the bitmap at the very beginning of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * struct and fixup the bit number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #define IPM_BIT_OFFSET (offsetof(struct kvm_s390_gisa, ipm) * BITS_PER_BYTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * gisa_set_iam - change the GISA interruption alert mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * @gisa: gisa to operate on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * @iam: new IAM value to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * Change the IAM atomically with the next alert address and the IPM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * of the GISA if the GISA is not part of the GIB alert list. All three
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * fields are located in the first long word of the GISA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * Returns: 0 on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * -EBUSY in case the gisa is part of the alert list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static inline int gisa_set_iam(struct kvm_s390_gisa *gisa, u8 iam)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) u64 word, _word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) word = READ_ONCE(gisa->u64.word[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if ((u64)gisa != word >> 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) _word = (word & ~0xffUL) | iam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) } while (cmpxchg(&gisa->u64.word[0], word, _word) != word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * gisa_clear_ipm - clear the GISA interruption pending mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * @gisa: gisa to operate on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * Clear the IPM atomically with the next alert address and the IAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * of the GISA unconditionally. All three fields are located in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * first long word of the GISA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static inline void gisa_clear_ipm(struct kvm_s390_gisa *gisa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) u64 word, _word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) word = READ_ONCE(gisa->u64.word[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) _word = word & ~(0xffUL << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) } while (cmpxchg(&gisa->u64.word[0], word, _word) != word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * gisa_get_ipm_or_restore_iam - return IPM or restore GISA IAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * @gi: gisa interrupt struct to work on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * Atomically restores the interruption alert mask if none of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * relevant ISCs are pending and return the IPM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * Returns: the relevant pending ISCs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static inline u8 gisa_get_ipm_or_restore_iam(struct kvm_s390_gisa_interrupt *gi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) u8 pending_mask, alert_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) u64 word, _word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) word = READ_ONCE(gi->origin->u64.word[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) alert_mask = READ_ONCE(gi->alert.mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) pending_mask = (u8)(word >> 24) & alert_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (pending_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return pending_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) _word = (word & ~0xffUL) | alert_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) } while (cmpxchg(&gi->origin->u64.word[0], word, _word) != word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static inline int gisa_in_alert_list(struct kvm_s390_gisa *gisa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return READ_ONCE(gisa->next_alert) != (u32)(u64)gisa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static inline void gisa_set_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) set_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static inline u8 gisa_get_ipm(struct kvm_s390_gisa *gisa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return READ_ONCE(gisa->ipm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static inline void gisa_clear_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) clear_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static inline int gisa_tac_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return test_and_clear_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static inline unsigned long pending_irqs_no_gisa(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) unsigned long pending = vcpu->kvm->arch.float_int.pending_irqs |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) vcpu->arch.local_int.pending_irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) pending &= ~vcpu->kvm->arch.float_int.masked_irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static inline unsigned long pending_irqs(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct kvm_s390_gisa_interrupt *gi = &vcpu->kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) unsigned long pending_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) pending_mask = pending_irqs_no_gisa(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (gi->origin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) pending_mask |= gisa_get_ipm(gi->origin) << IRQ_PEND_IO_ISC_7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return pending_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static inline int isc_to_irq_type(unsigned long isc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return IRQ_PEND_IO_ISC_0 - isc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static inline int irq_type_to_isc(unsigned long irq_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return IRQ_PEND_IO_ISC_0 - irq_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static unsigned long disable_iscs(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) unsigned long active_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) for (i = 0; i <= MAX_ISC; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (!(vcpu->arch.sie_block->gcr[6] & isc_to_isc_bits(i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) active_mask &= ~(1UL << (isc_to_irq_type(i)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return active_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static unsigned long deliverable_irqs(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) unsigned long active_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) active_mask = pending_irqs(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (!active_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (psw_extint_disabled(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) active_mask &= ~IRQ_PEND_EXT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (psw_ioint_disabled(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) active_mask &= ~IRQ_PEND_IO_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) active_mask = disable_iscs(vcpu, active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (!(vcpu->arch.sie_block->gcr[0] & CR0_EXTERNAL_CALL_SUBMASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) __clear_bit(IRQ_PEND_EXT_EXTERNAL, &active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (!(vcpu->arch.sie_block->gcr[0] & CR0_EMERGENCY_SIGNAL_SUBMASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) __clear_bit(IRQ_PEND_EXT_EMERGENCY, &active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (!(vcpu->arch.sie_block->gcr[0] & CR0_CLOCK_COMPARATOR_SUBMASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) __clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (!(vcpu->arch.sie_block->gcr[0] & CR0_CPU_TIMER_SUBMASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) __clear_bit(IRQ_PEND_EXT_CPU_TIMER, &active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (!(vcpu->arch.sie_block->gcr[0] & CR0_SERVICE_SIGNAL_SUBMASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) __clear_bit(IRQ_PEND_EXT_SERVICE, &active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) __clear_bit(IRQ_PEND_EXT_SERVICE_EV, &active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (psw_mchk_disabled(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) active_mask &= ~IRQ_PEND_MCHK_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /* PV guest cpus can have a single interruption injected at a time. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (kvm_s390_pv_cpu_get_handle(vcpu) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) vcpu->arch.sie_block->iictl != IICTL_CODE_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) active_mask &= ~(IRQ_PEND_EXT_II_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) IRQ_PEND_IO_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) IRQ_PEND_MCHK_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * Check both floating and local interrupt's cr14 because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * bit IRQ_PEND_MCHK_REP could be set in both cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (!(vcpu->arch.sie_block->gcr[14] &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) (vcpu->kvm->arch.float_int.mchk.cr14 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) vcpu->arch.local_int.irq.mchk.cr14)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) __clear_bit(IRQ_PEND_MCHK_REP, &active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * STOP irqs will never be actively delivered. They are triggered via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * intercept requests and cleared when the stop intercept is performed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) __clear_bit(IRQ_PEND_SIGP_STOP, &active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return active_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static void __set_cpu_idle(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) kvm_s390_set_cpuflags(vcpu, CPUSTAT_WAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) set_bit(kvm_vcpu_get_idx(vcpu), vcpu->kvm->arch.idle_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static void __unset_cpu_idle(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) kvm_s390_clear_cpuflags(vcpu, CPUSTAT_WAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) clear_bit(kvm_vcpu_get_idx(vcpu), vcpu->kvm->arch.idle_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static void __reset_intercept_indicators(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) kvm_s390_clear_cpuflags(vcpu, CPUSTAT_IO_INT | CPUSTAT_EXT_INT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) CPUSTAT_STOP_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) vcpu->arch.sie_block->lctl = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) vcpu->arch.sie_block->ictl &= ~(ICTL_LPSW | ICTL_STCTL | ICTL_PINT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (guestdbg_enabled(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) vcpu->arch.sie_block->lctl |= (LCTL_CR0 | LCTL_CR9 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) LCTL_CR10 | LCTL_CR11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) vcpu->arch.sie_block->ictl |= (ICTL_STCTL | ICTL_PINT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static void set_intercept_indicators_io(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (!(pending_irqs_no_gisa(vcpu) & IRQ_PEND_IO_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) if (psw_ioint_disabled(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) kvm_s390_set_cpuflags(vcpu, CPUSTAT_IO_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) vcpu->arch.sie_block->lctl |= LCTL_CR6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (!(pending_irqs_no_gisa(vcpu) & IRQ_PEND_EXT_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (psw_extint_disabled(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) vcpu->arch.sie_block->lctl |= LCTL_CR0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static void set_intercept_indicators_mchk(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (!(pending_irqs_no_gisa(vcpu) & IRQ_PEND_MCHK_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (psw_mchk_disabled(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) vcpu->arch.sie_block->ictl |= ICTL_LPSW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) vcpu->arch.sie_block->lctl |= LCTL_CR14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static void set_intercept_indicators_stop(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (kvm_s390_is_stop_irq_pending(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) kvm_s390_set_cpuflags(vcpu, CPUSTAT_STOP_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) /* Set interception request for non-deliverable interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) static void set_intercept_indicators(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) set_intercept_indicators_io(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) set_intercept_indicators_ext(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) set_intercept_indicators_mchk(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) set_intercept_indicators_stop(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static int __must_check __deliver_cpu_timer(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) vcpu->stat.deliver_cputm++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_CPU_TIMER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (kvm_s390_pv_cpu_is_protected(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) vcpu->arch.sie_block->iictl = IICTL_CODE_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) vcpu->arch.sie_block->eic = EXT_IRQ_CPU_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) rc = put_guest_lc(vcpu, EXT_IRQ_CPU_TIMER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) (u16 *)__LC_EXT_INT_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) clear_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static int __must_check __deliver_ckc(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) vcpu->stat.deliver_ckc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_CLOCK_COMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (kvm_s390_pv_cpu_is_protected(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) vcpu->arch.sie_block->iictl = IICTL_CODE_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) vcpu->arch.sie_block->eic = EXT_IRQ_CLK_COMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) rc = put_guest_lc(vcpu, EXT_IRQ_CLK_COMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) (u16 __user *)__LC_EXT_INT_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static int __must_check __deliver_pfault_init(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct kvm_s390_ext_info ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) spin_lock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) ext = li->irq.ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) clear_bit(IRQ_PEND_PFAULT_INIT, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) li->irq.ext.ext_params2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) spin_unlock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) VCPU_EVENT(vcpu, 4, "deliver: pfault init token 0x%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) ext.ext_params2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) KVM_S390_INT_PFAULT_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 0, ext.ext_params2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, (u16 *) __LC_EXT_INT_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) rc |= put_guest_lc(vcpu, PFAULT_INIT, (u16 *) __LC_EXT_CPU_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) rc |= put_guest_lc(vcpu, ext.ext_params2, (u64 *) __LC_EXT_PARAMS2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static int __write_machine_check(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) struct kvm_s390_mchk_info *mchk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) unsigned long ext_sa_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) unsigned long lc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) freg_t fprs[NUM_FPRS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) union mci mci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * All other possible payload for a machine check (e.g. the register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * contents in the save area) will be handled by the ultravisor, as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) * the hypervisor does not not have the needed information for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * protected guests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (kvm_s390_pv_cpu_is_protected(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) vcpu->arch.sie_block->iictl = IICTL_CODE_MCHK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) vcpu->arch.sie_block->mcic = mchk->mcic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) vcpu->arch.sie_block->faddr = mchk->failing_storage_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) vcpu->arch.sie_block->edc = mchk->ext_damage_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) mci.val = mchk->mcic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) /* take care of lazy register loading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) save_fpu_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) save_access_regs(vcpu->run->s.regs.acrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (MACHINE_HAS_GS && vcpu->arch.gs_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) save_gs_cb(current->thread.gs_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /* Extended save area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) rc = read_guest_lc(vcpu, __LC_MCESAD, &ext_sa_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) sizeof(unsigned long));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) /* Only bits 0 through 63-LC are used for address formation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) lc = ext_sa_addr & MCESA_LC_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (test_kvm_facility(vcpu->kvm, 133)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) switch (lc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) case 10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) ext_sa_addr &= ~0x3ffUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) case 11:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) ext_sa_addr &= ~0x7ffUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) case 12:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) ext_sa_addr &= ~0xfffUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) ext_sa_addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) ext_sa_addr &= ~0x3ffUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (!rc && mci.vr && ext_sa_addr && test_kvm_facility(vcpu->kvm, 129)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (write_guest_abs(vcpu, ext_sa_addr, vcpu->run->s.regs.vrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 512))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) mci.vr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) mci.vr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (!rc && mci.gs && ext_sa_addr && test_kvm_facility(vcpu->kvm, 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) && (lc == 11 || lc == 12)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (write_guest_abs(vcpu, ext_sa_addr + 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) &vcpu->run->s.regs.gscb, 32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) mci.gs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) mci.gs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) /* General interruption information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) rc |= put_guest_lc(vcpu, 1, (u8 __user *) __LC_AR_MODE_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) rc |= write_guest_lc(vcpu, __LC_MCK_OLD_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) rc |= read_guest_lc(vcpu, __LC_MCK_NEW_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) rc |= put_guest_lc(vcpu, mci.val, (u64 __user *) __LC_MCCK_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) /* Register-save areas */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) if (MACHINE_HAS_VX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) convert_vx_to_fp(fprs, (__vector128 *) vcpu->run->s.regs.vrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) rc |= write_guest_lc(vcpu, __LC_FPREGS_SAVE_AREA, fprs, 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) rc |= write_guest_lc(vcpu, __LC_FPREGS_SAVE_AREA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) vcpu->run->s.regs.fprs, 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) rc |= write_guest_lc(vcpu, __LC_GPREGS_SAVE_AREA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) vcpu->run->s.regs.gprs, 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) rc |= put_guest_lc(vcpu, current->thread.fpu.fpc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) (u32 __user *) __LC_FP_CREG_SAVE_AREA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) rc |= put_guest_lc(vcpu, vcpu->arch.sie_block->todpr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) (u32 __user *) __LC_TOD_PROGREG_SAVE_AREA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) rc |= put_guest_lc(vcpu, kvm_s390_get_cpu_timer(vcpu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) (u64 __user *) __LC_CPU_TIMER_SAVE_AREA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) rc |= put_guest_lc(vcpu, vcpu->arch.sie_block->ckc >> 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) (u64 __user *) __LC_CLOCK_COMP_SAVE_AREA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) rc |= write_guest_lc(vcpu, __LC_AREGS_SAVE_AREA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) &vcpu->run->s.regs.acrs, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) rc |= write_guest_lc(vcpu, __LC_CREGS_SAVE_AREA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) &vcpu->arch.sie_block->gcr, 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* Extended interruption information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) rc |= put_guest_lc(vcpu, mchk->ext_damage_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) (u32 __user *) __LC_EXT_DAMAGE_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) rc |= put_guest_lc(vcpu, mchk->failing_storage_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) (u64 __user *) __LC_MCCK_FAIL_STOR_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) rc |= write_guest_lc(vcpu, __LC_PSW_SAVE_AREA, &mchk->fixed_logout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) sizeof(mchk->fixed_logout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) static int __must_check __deliver_machine_check(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) struct kvm_s390_mchk_info mchk = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) int deliver = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) spin_lock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (test_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) test_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) * If there was an exigent machine check pending, then any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) * repressible machine checks that might have been pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) * are indicated along with it, so always clear bits for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * repressible and exigent interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) mchk = li->irq.mchk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) clear_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) clear_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) memset(&li->irq.mchk, 0, sizeof(mchk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) deliver = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) * We indicate floating repressible conditions along with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * other pending conditions. Channel Report Pending and Channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * Subsystem damage are the only two and and are indicated by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) * bits in mcic and masked in cr14.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (test_and_clear_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) mchk.mcic |= fi->mchk.mcic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) mchk.cr14 |= fi->mchk.cr14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) memset(&fi->mchk, 0, sizeof(mchk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) deliver = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) spin_unlock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (deliver) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) VCPU_EVENT(vcpu, 3, "deliver: machine check mcic 0x%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) mchk.mcic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) KVM_S390_MCHK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) mchk.cr14, mchk.mcic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) vcpu->stat.deliver_machine_check++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) rc = __write_machine_check(vcpu, &mchk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) static int __must_check __deliver_restart(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) VCPU_EVENT(vcpu, 3, "%s", "deliver: cpu restart");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) vcpu->stat.deliver_restart_signal++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (kvm_s390_pv_cpu_is_protected(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) vcpu->arch.sie_block->iictl = IICTL_CODE_RESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) rc = write_guest_lc(vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) offsetof(struct lowcore, restart_old_psw),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) rc |= read_guest_lc(vcpu, offsetof(struct lowcore, restart_psw),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) clear_bit(IRQ_PEND_RESTART, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) static int __must_check __deliver_set_prefix(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) struct kvm_s390_prefix_info prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) spin_lock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) prefix = li->irq.prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) li->irq.prefix.address = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) clear_bit(IRQ_PEND_SET_PREFIX, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) spin_unlock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) vcpu->stat.deliver_prefix_signal++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) KVM_S390_SIGP_SET_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) prefix.address, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) kvm_s390_set_prefix(vcpu, prefix.address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) static int __must_check __deliver_emergency_signal(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) int cpu_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) spin_lock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) cpu_addr = find_first_bit(li->sigp_emerg_pending, KVM_MAX_VCPUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) clear_bit(cpu_addr, li->sigp_emerg_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (bitmap_empty(li->sigp_emerg_pending, KVM_MAX_VCPUS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) clear_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) spin_unlock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) VCPU_EVENT(vcpu, 4, "%s", "deliver: sigp emerg");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) vcpu->stat.deliver_emergency_signal++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_EMERGENCY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) cpu_addr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (kvm_s390_pv_cpu_is_protected(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) vcpu->arch.sie_block->iictl = IICTL_CODE_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) vcpu->arch.sie_block->eic = EXT_IRQ_EMERGENCY_SIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) vcpu->arch.sie_block->extcpuaddr = cpu_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) rc = put_guest_lc(vcpu, EXT_IRQ_EMERGENCY_SIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) (u16 *)__LC_EXT_INT_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) rc |= put_guest_lc(vcpu, cpu_addr, (u16 *)__LC_EXT_CPU_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) static int __must_check __deliver_external_call(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) struct kvm_s390_extcall_info extcall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) spin_lock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) extcall = li->irq.extcall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) li->irq.extcall.code = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) clear_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) spin_unlock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) VCPU_EVENT(vcpu, 4, "%s", "deliver: sigp ext call");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) vcpu->stat.deliver_external_call++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) KVM_S390_INT_EXTERNAL_CALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) extcall.code, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) if (kvm_s390_pv_cpu_is_protected(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) vcpu->arch.sie_block->iictl = IICTL_CODE_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) vcpu->arch.sie_block->eic = EXT_IRQ_EXTERNAL_CALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) vcpu->arch.sie_block->extcpuaddr = extcall.code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) rc = put_guest_lc(vcpu, EXT_IRQ_EXTERNAL_CALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) (u16 *)__LC_EXT_INT_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) rc |= put_guest_lc(vcpu, extcall.code, (u16 *)__LC_EXT_CPU_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, &vcpu->arch.sie_block->gpsw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) static int __deliver_prog_pv(struct kvm_vcpu *vcpu, u16 code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) switch (code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) case PGM_SPECIFICATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) vcpu->arch.sie_block->iictl = IICTL_CODE_SPECIFICATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) case PGM_OPERAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) vcpu->arch.sie_block->iictl = IICTL_CODE_OPERAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) static int __must_check __deliver_prog(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) struct kvm_s390_pgm_info pgm_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) int rc = 0, nullifying = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) u16 ilen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) spin_lock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) pgm_info = li->irq.pgm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) clear_bit(IRQ_PEND_PROG, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) memset(&li->irq.pgm, 0, sizeof(pgm_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) spin_unlock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) ilen = pgm_info.flags & KVM_S390_PGM_FLAGS_ILC_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) VCPU_EVENT(vcpu, 3, "deliver: program irq code 0x%x, ilen:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) pgm_info.code, ilen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) vcpu->stat.deliver_program++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_PROGRAM_INT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) pgm_info.code, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) /* PER is handled by the ultravisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) if (kvm_s390_pv_cpu_is_protected(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) return __deliver_prog_pv(vcpu, pgm_info.code & ~PGM_PER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) switch (pgm_info.code & ~PGM_PER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) case PGM_AFX_TRANSLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) case PGM_ASX_TRANSLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) case PGM_EX_TRANSLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) case PGM_LFX_TRANSLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) case PGM_LSTE_SEQUENCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) case PGM_LSX_TRANSLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) case PGM_LX_TRANSLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) case PGM_PRIMARY_AUTHORITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) case PGM_SECONDARY_AUTHORITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) nullifying = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) case PGM_SPACE_SWITCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) rc = put_guest_lc(vcpu, pgm_info.trans_exc_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) (u64 *)__LC_TRANS_EXC_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) case PGM_ALEN_TRANSLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) case PGM_ALE_SEQUENCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) case PGM_ASTE_INSTANCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) case PGM_ASTE_SEQUENCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) case PGM_ASTE_VALIDITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) case PGM_EXTENDED_AUTHORITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) rc = put_guest_lc(vcpu, pgm_info.exc_access_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) (u8 *)__LC_EXC_ACCESS_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) nullifying = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) case PGM_ASCE_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) case PGM_PAGE_TRANSLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) case PGM_REGION_FIRST_TRANS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) case PGM_REGION_SECOND_TRANS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) case PGM_REGION_THIRD_TRANS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) case PGM_SEGMENT_TRANSLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) rc = put_guest_lc(vcpu, pgm_info.trans_exc_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) (u64 *)__LC_TRANS_EXC_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) rc |= put_guest_lc(vcpu, pgm_info.exc_access_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) (u8 *)__LC_EXC_ACCESS_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) rc |= put_guest_lc(vcpu, pgm_info.op_access_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) (u8 *)__LC_OP_ACCESS_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) nullifying = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) case PGM_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) rc = put_guest_lc(vcpu, pgm_info.mon_class_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) (u16 *)__LC_MON_CLASS_NR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) rc |= put_guest_lc(vcpu, pgm_info.mon_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) (u64 *)__LC_MON_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) case PGM_VECTOR_PROCESSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) case PGM_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) rc = put_guest_lc(vcpu, pgm_info.data_exc_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) (u32 *)__LC_DATA_EXC_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) case PGM_PROTECTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) rc = put_guest_lc(vcpu, pgm_info.trans_exc_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) (u64 *)__LC_TRANS_EXC_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) rc |= put_guest_lc(vcpu, pgm_info.exc_access_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) (u8 *)__LC_EXC_ACCESS_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) case PGM_STACK_FULL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) case PGM_STACK_EMPTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) case PGM_STACK_SPECIFICATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) case PGM_STACK_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) case PGM_STACK_OPERATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) case PGM_TRACE_TABEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) case PGM_CRYPTO_OPERATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) nullifying = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (pgm_info.code & PGM_PER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) rc |= put_guest_lc(vcpu, pgm_info.per_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) (u8 *) __LC_PER_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) rc |= put_guest_lc(vcpu, pgm_info.per_atmid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) (u8 *)__LC_PER_ATMID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) rc |= put_guest_lc(vcpu, pgm_info.per_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) (u64 *) __LC_PER_ADDRESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) rc |= put_guest_lc(vcpu, pgm_info.per_access_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) (u8 *) __LC_PER_ACCESS_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (nullifying && !(pgm_info.flags & KVM_S390_PGM_FLAGS_NO_REWIND))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) kvm_s390_rewind_psw(vcpu, ilen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) /* bit 1+2 of the target are the ilc, so we can directly use ilen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) rc |= put_guest_lc(vcpu, ilen, (u16 *) __LC_PGM_ILC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) rc |= put_guest_lc(vcpu, vcpu->arch.sie_block->gbea,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) (u64 *) __LC_LAST_BREAK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) rc |= put_guest_lc(vcpu, pgm_info.code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) (u16 *)__LC_PGM_INT_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) rc |= write_guest_lc(vcpu, __LC_PGM_OLD_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) rc |= read_guest_lc(vcpu, __LC_PGM_NEW_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) #define SCCB_MASK 0xFFFFFFF8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) #define SCCB_EVENT_PENDING 0x3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) static int write_sclp(struct kvm_vcpu *vcpu, u32 parm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) if (kvm_s390_pv_cpu_get_handle(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) vcpu->arch.sie_block->iictl = IICTL_CODE_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) vcpu->arch.sie_block->eic = EXT_IRQ_SERVICE_SIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) vcpu->arch.sie_block->eiparams = parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) rc = put_guest_lc(vcpu, EXT_IRQ_SERVICE_SIG, (u16 *)__LC_EXT_INT_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) rc |= put_guest_lc(vcpu, parm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) (u32 *)__LC_EXT_PARAMS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) static int __must_check __deliver_service(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) struct kvm_s390_ext_info ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (test_bit(IRQ_PEND_EXT_SERVICE, &fi->masked_irqs) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) !(test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) ext = fi->srv_signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) memset(&fi->srv_signal, 0, sizeof(ext));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) clear_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) clear_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) if (kvm_s390_pv_cpu_is_protected(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) set_bit(IRQ_PEND_EXT_SERVICE, &fi->masked_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) VCPU_EVENT(vcpu, 4, "deliver: sclp parameter 0x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) ext.ext_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) vcpu->stat.deliver_service_signal++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_SERVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) ext.ext_params, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) return write_sclp(vcpu, ext.ext_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) static int __must_check __deliver_service_ev(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) struct kvm_s390_ext_info ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) if (!(test_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) ext = fi->srv_signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) /* only clear the event bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) fi->srv_signal.ext_params &= ~SCCB_EVENT_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) clear_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) VCPU_EVENT(vcpu, 4, "%s", "deliver: sclp parameter event");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) vcpu->stat.deliver_service_signal++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_SERVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) ext.ext_params, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) return write_sclp(vcpu, SCCB_EVENT_PENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) static int __must_check __deliver_pfault_done(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) struct kvm_s390_interrupt_info *inti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) inti = list_first_entry_or_null(&fi->lists[FIRQ_LIST_PFAULT],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) struct kvm_s390_interrupt_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) if (inti) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) list_del(&inti->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) fi->counters[FIRQ_CNTR_PFAULT] -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (list_empty(&fi->lists[FIRQ_LIST_PFAULT]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) clear_bit(IRQ_PEND_PFAULT_DONE, &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) if (inti) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) KVM_S390_INT_PFAULT_DONE, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) inti->ext.ext_params2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) VCPU_EVENT(vcpu, 4, "deliver: pfault done token 0x%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) inti->ext.ext_params2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) (u16 *)__LC_EXT_INT_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) rc |= put_guest_lc(vcpu, PFAULT_DONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) (u16 *)__LC_EXT_CPU_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) &vcpu->arch.sie_block->gpsw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) &vcpu->arch.sie_block->gpsw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) rc |= put_guest_lc(vcpu, inti->ext.ext_params2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) (u64 *)__LC_EXT_PARAMS2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) kfree(inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) static int __must_check __deliver_virtio(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) struct kvm_s390_interrupt_info *inti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) inti = list_first_entry_or_null(&fi->lists[FIRQ_LIST_VIRTIO],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) struct kvm_s390_interrupt_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) if (inti) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) VCPU_EVENT(vcpu, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) "deliver: virtio parm: 0x%x,parm64: 0x%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) inti->ext.ext_params, inti->ext.ext_params2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) vcpu->stat.deliver_virtio++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) inti->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) inti->ext.ext_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) inti->ext.ext_params2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) list_del(&inti->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) fi->counters[FIRQ_CNTR_VIRTIO] -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) if (list_empty(&fi->lists[FIRQ_LIST_VIRTIO]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) clear_bit(IRQ_PEND_VIRTIO, &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) if (inti) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) (u16 *)__LC_EXT_INT_CODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) rc |= put_guest_lc(vcpu, VIRTIO_PARAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) (u16 *)__LC_EXT_CPU_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) &vcpu->arch.sie_block->gpsw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) &vcpu->arch.sie_block->gpsw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) rc |= put_guest_lc(vcpu, inti->ext.ext_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) (u32 *)__LC_EXT_PARAMS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) rc |= put_guest_lc(vcpu, inti->ext.ext_params2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) (u64 *)__LC_EXT_PARAMS2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) kfree(inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) static int __do_deliver_io(struct kvm_vcpu *vcpu, struct kvm_s390_io_info *io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) if (kvm_s390_pv_cpu_is_protected(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) vcpu->arch.sie_block->iictl = IICTL_CODE_IO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) vcpu->arch.sie_block->subchannel_id = io->subchannel_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) vcpu->arch.sie_block->subchannel_nr = io->subchannel_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) vcpu->arch.sie_block->io_int_parm = io->io_int_parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) vcpu->arch.sie_block->io_int_word = io->io_int_word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) rc = put_guest_lc(vcpu, io->subchannel_id, (u16 *)__LC_SUBCHANNEL_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) rc |= put_guest_lc(vcpu, io->subchannel_nr, (u16 *)__LC_SUBCHANNEL_NR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) rc |= put_guest_lc(vcpu, io->io_int_parm, (u32 *)__LC_IO_INT_PARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) rc |= put_guest_lc(vcpu, io->io_int_word, (u32 *)__LC_IO_INT_WORD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) rc |= write_guest_lc(vcpu, __LC_IO_OLD_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) &vcpu->arch.sie_block->gpsw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) rc |= read_guest_lc(vcpu, __LC_IO_NEW_PSW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) &vcpu->arch.sie_block->gpsw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) sizeof(psw_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) return rc ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) static int __must_check __deliver_io(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) unsigned long irq_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) struct list_head *isc_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) struct kvm_s390_float_interrupt *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) struct kvm_s390_gisa_interrupt *gi = &vcpu->kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) struct kvm_s390_interrupt_info *inti = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) struct kvm_s390_io_info io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) u32 isc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) fi = &vcpu->kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) isc = irq_type_to_isc(irq_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) isc_list = &fi->lists[isc];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) inti = list_first_entry_or_null(isc_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) struct kvm_s390_interrupt_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) if (inti) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) if (inti->type & KVM_S390_INT_IO_AI_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) VCPU_EVENT(vcpu, 4, "%s", "deliver: I/O (AI)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) VCPU_EVENT(vcpu, 4, "deliver: I/O %x ss %x schid %04x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) inti->io.subchannel_id >> 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) inti->io.subchannel_id >> 1 & 0x3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) inti->io.subchannel_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) vcpu->stat.deliver_io++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) inti->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) ((__u32)inti->io.subchannel_id << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) inti->io.subchannel_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) ((__u64)inti->io.io_int_parm << 32) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) inti->io.io_int_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) list_del(&inti->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) fi->counters[FIRQ_CNTR_IO] -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) if (list_empty(isc_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) clear_bit(irq_type, &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) if (inti) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) rc = __do_deliver_io(vcpu, &(inti->io));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) kfree(inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) if (gi->origin && gisa_tac_ipm_gisc(gi->origin, isc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) * in case an adapter interrupt was not delivered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) * in SIE context KVM will handle the delivery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) VCPU_EVENT(vcpu, 4, "%s isc %u", "deliver: I/O (AI/gisa)", isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) memset(&io, 0, sizeof(io));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) io.io_int_word = isc_to_int_word(isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) vcpu->stat.deliver_io++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) KVM_S390_INT_IO(1, 0, 0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) ((__u32)io.subchannel_id << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) io.subchannel_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) ((__u64)io.io_int_parm << 32) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) io.io_int_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) rc = __do_deliver_io(vcpu, &io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) /* Check whether an external call is pending (deliverable or not) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) if (!sclp.has_sigpif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) return test_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) return sca_ext_call_pending(vcpu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) int kvm_s390_vcpu_has_irq(struct kvm_vcpu *vcpu, int exclude_stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) if (deliverable_irqs(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) if (kvm_cpu_has_pending_timer(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) /* external call pending and deliverable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) if (kvm_s390_ext_call_pending(vcpu) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) !psw_extint_disabled(vcpu) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) (vcpu->arch.sie_block->gcr[0] & CR0_EXTERNAL_CALL_SUBMASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) if (!exclude_stop && kvm_s390_is_stop_irq_pending(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) return ckc_irq_pending(vcpu) || cpu_timer_irq_pending(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) static u64 __calculate_sltime(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) const u64 now = kvm_s390_get_tod_clock_fast(vcpu->kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) const u64 ckc = vcpu->arch.sie_block->ckc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) u64 cputm, sltime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) if (ckc_interrupts_enabled(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (vcpu->arch.sie_block->gcr[0] & CR0_CLOCK_COMPARATOR_SIGN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) if ((s64)now < (s64)ckc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) sltime = tod_to_ns((s64)ckc - (s64)now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) } else if (now < ckc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) sltime = tod_to_ns(ckc - now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) /* already expired */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) if (!sltime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) if (cpu_timer_interrupts_enabled(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) cputm = kvm_s390_get_cpu_timer(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) /* already expired? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (cputm >> 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) return min(sltime, tod_to_ns(cputm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) } else if (cpu_timer_interrupts_enabled(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) sltime = kvm_s390_get_cpu_timer(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) /* already expired? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (sltime >> 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) return sltime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) struct kvm_s390_gisa_interrupt *gi = &vcpu->kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) u64 sltime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) vcpu->stat.exit_wait_state++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) /* fast path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) if (kvm_arch_vcpu_runnable(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) if (psw_interrupts_disabled(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) VCPU_EVENT(vcpu, 3, "%s", "disabled wait");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) return -EOPNOTSUPP; /* disabled wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) if (gi->origin &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) (gisa_get_ipm_or_restore_iam(gi) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) vcpu->arch.sie_block->gcr[6] >> 24))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if (!ckc_interrupts_enabled(vcpu) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) !cpu_timer_interrupts_enabled(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) VCPU_EVENT(vcpu, 3, "%s", "enabled wait w/o timer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) __set_cpu_idle(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) goto no_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) sltime = __calculate_sltime(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) if (!sltime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) __set_cpu_idle(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) hrtimer_start(&vcpu->arch.ckc_timer, sltime, HRTIMER_MODE_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) VCPU_EVENT(vcpu, 4, "enabled wait: %llu ns", sltime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) no_timer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) kvm_vcpu_block(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) __unset_cpu_idle(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) hrtimer_cancel(&vcpu->arch.ckc_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) vcpu->valid_wakeup = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) kvm_vcpu_wake_up(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) * The VCPU might not be sleeping but rather executing VSIE. Let's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) * kick it, so it leaves the SIE to process the request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) kvm_s390_vsie_kick(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) struct kvm_vcpu *vcpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) u64 sltime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) sltime = __calculate_sltime(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) * If the monotonic clock runs faster than the tod clock we might be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) * woken up too early and have to go back to sleep to avoid deadlocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) if (sltime && hrtimer_forward_now(timer, ns_to_ktime(sltime)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) return HRTIMER_RESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) kvm_s390_vcpu_wakeup(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) return HRTIMER_NORESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) spin_lock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) li->pending_irqs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) bitmap_zero(li->sigp_emerg_pending, KVM_MAX_VCPUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) memset(&li->irq, 0, sizeof(li->irq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) spin_unlock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) sca_clear_ext_call(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) unsigned long irq_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) unsigned long irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) __reset_intercept_indicators(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) /* pending ckc conditions might have been invalidated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) if (ckc_irq_pending(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) /* pending cpu timer conditions might have been invalidated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) clear_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) if (cpu_timer_irq_pending(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) while ((irqs = deliverable_irqs(vcpu)) && !rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) /* bits are in the reverse order of interrupt priority */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) irq_type = find_last_bit(&irqs, IRQ_PEND_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) switch (irq_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) case IRQ_PEND_IO_ISC_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) case IRQ_PEND_IO_ISC_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) case IRQ_PEND_IO_ISC_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) case IRQ_PEND_IO_ISC_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) case IRQ_PEND_IO_ISC_4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) case IRQ_PEND_IO_ISC_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) case IRQ_PEND_IO_ISC_6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) case IRQ_PEND_IO_ISC_7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) rc = __deliver_io(vcpu, irq_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) case IRQ_PEND_MCHK_EX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) case IRQ_PEND_MCHK_REP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) rc = __deliver_machine_check(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) case IRQ_PEND_PROG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) rc = __deliver_prog(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) case IRQ_PEND_EXT_EMERGENCY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) rc = __deliver_emergency_signal(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) case IRQ_PEND_EXT_EXTERNAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) rc = __deliver_external_call(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) case IRQ_PEND_EXT_CLOCK_COMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) rc = __deliver_ckc(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) case IRQ_PEND_EXT_CPU_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) rc = __deliver_cpu_timer(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) case IRQ_PEND_RESTART:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) rc = __deliver_restart(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) case IRQ_PEND_SET_PREFIX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) rc = __deliver_set_prefix(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) case IRQ_PEND_PFAULT_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) rc = __deliver_pfault_init(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) case IRQ_PEND_EXT_SERVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) rc = __deliver_service(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) case IRQ_PEND_EXT_SERVICE_EV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) rc = __deliver_service_ev(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) case IRQ_PEND_PFAULT_DONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) rc = __deliver_pfault_done(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) case IRQ_PEND_VIRTIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) rc = __deliver_virtio(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) WARN_ONCE(1, "Unknown pending irq type %ld", irq_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) clear_bit(irq_type, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) set_intercept_indicators(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) static int __inject_prog(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) vcpu->stat.inject_program++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) VCPU_EVENT(vcpu, 3, "inject: program irq code 0x%x", irq->u.pgm.code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_PROGRAM_INT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) irq->u.pgm.code, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) if (!(irq->u.pgm.flags & KVM_S390_PGM_FLAGS_ILC_VALID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) /* auto detection if no valid ILC was given */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) irq->u.pgm.flags &= ~KVM_S390_PGM_FLAGS_ILC_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) irq->u.pgm.flags |= kvm_s390_get_ilen(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) irq->u.pgm.flags |= KVM_S390_PGM_FLAGS_ILC_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) if (irq->u.pgm.code == PGM_PER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) li->irq.pgm.code |= PGM_PER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) li->irq.pgm.flags = irq->u.pgm.flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) /* only modify PER related information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) li->irq.pgm.per_address = irq->u.pgm.per_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) li->irq.pgm.per_code = irq->u.pgm.per_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) li->irq.pgm.per_atmid = irq->u.pgm.per_atmid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) li->irq.pgm.per_access_id = irq->u.pgm.per_access_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) } else if (!(irq->u.pgm.code & PGM_PER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) li->irq.pgm.code = (li->irq.pgm.code & PGM_PER) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) irq->u.pgm.code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) li->irq.pgm.flags = irq->u.pgm.flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) /* only modify non-PER information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) li->irq.pgm.trans_exc_code = irq->u.pgm.trans_exc_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) li->irq.pgm.mon_code = irq->u.pgm.mon_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) li->irq.pgm.data_exc_code = irq->u.pgm.data_exc_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) li->irq.pgm.mon_class_nr = irq->u.pgm.mon_class_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) li->irq.pgm.exc_access_id = irq->u.pgm.exc_access_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) li->irq.pgm.op_access_id = irq->u.pgm.op_access_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) li->irq.pgm = irq->u.pgm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) set_bit(IRQ_PEND_PROG, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) static int __inject_pfault_init(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) vcpu->stat.inject_pfault_init++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) VCPU_EVENT(vcpu, 4, "inject: pfault init parameter block at 0x%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) irq->u.ext.ext_params2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_PFAULT_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) irq->u.ext.ext_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) irq->u.ext.ext_params2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) li->irq.ext = irq->u.ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) set_bit(IRQ_PEND_PFAULT_INIT, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) static int __inject_extcall(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) struct kvm_s390_extcall_info *extcall = &li->irq.extcall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) uint16_t src_id = irq->u.extcall.code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) vcpu->stat.inject_external_call++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) VCPU_EVENT(vcpu, 4, "inject: external call source-cpu:%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) src_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_EXTERNAL_CALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) src_id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) /* sending vcpu invalid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) if (kvm_get_vcpu_by_id(vcpu->kvm, src_id) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) if (sclp.has_sigpif && !kvm_s390_pv_cpu_get_handle(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) return sca_inject_ext_call(vcpu, src_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) if (test_and_set_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) *extcall = irq->u.extcall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) static int __inject_set_prefix(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) struct kvm_s390_prefix_info *prefix = &li->irq.prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) vcpu->stat.inject_set_prefix++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) VCPU_EVENT(vcpu, 3, "inject: set prefix to %x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) irq->u.prefix.address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_SIGP_SET_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) irq->u.prefix.address, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) if (!is_vcpu_stopped(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) *prefix = irq->u.prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) set_bit(IRQ_PEND_SET_PREFIX, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) #define KVM_S390_STOP_SUPP_FLAGS (KVM_S390_STOP_FLAG_STORE_STATUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) static int __inject_sigp_stop(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) struct kvm_s390_stop_info *stop = &li->irq.stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) vcpu->stat.inject_stop_signal++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_SIGP_STOP, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) if (irq->u.stop.flags & ~KVM_S390_STOP_SUPP_FLAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) if (is_vcpu_stopped(vcpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) if (irq->u.stop.flags & KVM_S390_STOP_FLAG_STORE_STATUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) rc = kvm_s390_store_status_unloaded(vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) KVM_S390_STORE_STATUS_NOADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) if (test_and_set_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) stop->flags = irq->u.stop.flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) kvm_s390_set_cpuflags(vcpu, CPUSTAT_STOP_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) static int __inject_sigp_restart(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) vcpu->stat.inject_restart++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) VCPU_EVENT(vcpu, 3, "%s", "inject: restart int");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) set_bit(IRQ_PEND_RESTART, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) static int __inject_sigp_emergency(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) struct kvm_s390_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) vcpu->stat.inject_emergency_signal++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) VCPU_EVENT(vcpu, 4, "inject: emergency from cpu %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) irq->u.emerg.code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_EMERGENCY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) irq->u.emerg.code, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) /* sending vcpu invalid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) if (kvm_get_vcpu_by_id(vcpu->kvm, irq->u.emerg.code) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) set_bit(irq->u.emerg.code, li->sigp_emerg_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) set_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) static int __inject_mchk(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) struct kvm_s390_mchk_info *mchk = &li->irq.mchk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) vcpu->stat.inject_mchk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) VCPU_EVENT(vcpu, 3, "inject: machine check mcic 0x%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) irq->u.mchk.mcic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_MCHK, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) irq->u.mchk.mcic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) * Because repressible machine checks can be indicated along with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) * exigent machine checks (PoP, Chapter 11, Interruption action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) * we need to combine cr14, mcic and external damage code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) * Failing storage address and the logout area should not be or'ed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) * together, we just indicate the last occurrence of the corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) * machine check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) mchk->cr14 |= irq->u.mchk.cr14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) mchk->mcic |= irq->u.mchk.mcic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) mchk->ext_damage_code |= irq->u.mchk.ext_damage_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) mchk->failing_storage_address = irq->u.mchk.failing_storage_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) memcpy(&mchk->fixed_logout, &irq->u.mchk.fixed_logout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) sizeof(mchk->fixed_logout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) if (mchk->mcic & MCHK_EX_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) set_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) else if (mchk->mcic & MCHK_REP_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) set_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) static int __inject_ckc(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) vcpu->stat.inject_ckc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) VCPU_EVENT(vcpu, 3, "%s", "inject: clock comparator external");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CLOCK_COMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) static int __inject_cpu_timer(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) vcpu->stat.inject_cputm++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) VCPU_EVENT(vcpu, 3, "%s", "inject: cpu timer external");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CPU_TIMER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) static struct kvm_s390_interrupt_info *get_io_int(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) int isc, u32 schid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) struct list_head *isc_list = &fi->lists[FIRQ_LIST_IO_ISC_0 + isc];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) struct kvm_s390_interrupt_info *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) u16 id = (schid & 0xffff0000U) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) u16 nr = schid & 0x0000ffffU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) list_for_each_entry(iter, isc_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) if (schid && (id != iter->io.subchannel_id ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) nr != iter->io.subchannel_nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) /* found an appropriate entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) list_del_init(&iter->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) fi->counters[FIRQ_CNTR_IO] -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) if (list_empty(isc_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) clear_bit(isc_to_irq_type(isc), &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) return iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) static struct kvm_s390_interrupt_info *get_top_io_int(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) u64 isc_mask, u32 schid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) struct kvm_s390_interrupt_info *inti = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) int isc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) for (isc = 0; isc <= MAX_ISC && !inti; isc++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) if (isc_mask & isc_to_isc_bits(isc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) inti = get_io_int(kvm, isc, schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) return inti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) static int get_top_gisa_isc(struct kvm *kvm, u64 isc_mask, u32 schid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) unsigned long active_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) int isc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) if (schid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) if (!gi->origin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) active_mask = (isc_mask & gisa_get_ipm(gi->origin) << 24) << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) while (active_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) isc = __fls(active_mask) ^ (BITS_PER_LONG - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) if (gisa_tac_ipm_gisc(gi->origin, isc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) return isc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) clear_bit_inv(isc, &active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) * Dequeue and return an I/O interrupt matching any of the interruption
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) * subclasses as designated by the isc mask in cr6 and the schid (if != 0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) * Take into account the interrupts pending in the interrupt list and in GISA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) * Note that for a guest that does not enable I/O interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) * but relies on TPI, a flood of classic interrupts may starve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) * out adapter interrupts on the same isc. Linux does not do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) * that, and it is possible to work around the issue by configuring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) * different iscs for classic and adapter interrupts in the guest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) * but we may want to revisit this in the future.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) u64 isc_mask, u32 schid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) struct kvm_s390_interrupt_info *inti, *tmp_inti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) int isc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) inti = get_top_io_int(kvm, isc_mask, schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) isc = get_top_gisa_isc(kvm, isc_mask, schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) if (isc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) /* no AI in GISA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) if (!inti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) /* AI in GISA but no classical IO int */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) goto gisa_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) /* both types of interrupts present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) if (int_word_to_isc(inti->io.io_int_word) <= isc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) /* classical IO int with higher priority */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) gisa_set_ipm_gisc(gi->origin, isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) gisa_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) tmp_inti = kzalloc(sizeof(*inti), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) if (tmp_inti) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) tmp_inti->type = KVM_S390_INT_IO(1, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) tmp_inti->io.io_int_word = isc_to_int_word(isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) if (inti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) kvm_s390_reinject_io_int(kvm, inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) inti = tmp_inti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) gisa_set_ipm_gisc(gi->origin, isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) return inti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) static int __inject_service(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) struct kvm_s390_interrupt_info *inti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) kvm->stat.inject_service_signal++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) fi->srv_signal.ext_params |= inti->ext.ext_params & SCCB_EVENT_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) /* We always allow events, track them separately from the sccb ints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) if (fi->srv_signal.ext_params & SCCB_EVENT_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) set_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) * Early versions of the QEMU s390 bios will inject several
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) * service interrupts after another without handling a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) * condition code indicating busy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) * We will silently ignore those superfluous sccb values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) * A future version of QEMU will take care of serialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) * of servc requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) if (fi->srv_signal.ext_params & SCCB_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) fi->srv_signal.ext_params |= inti->ext.ext_params & SCCB_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) set_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) kfree(inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) static int __inject_virtio(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) struct kvm_s390_interrupt_info *inti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) kvm->stat.inject_virtio++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) if (fi->counters[FIRQ_CNTR_VIRTIO] >= KVM_S390_MAX_VIRTIO_IRQS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) fi->counters[FIRQ_CNTR_VIRTIO] += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) list_add_tail(&inti->list, &fi->lists[FIRQ_LIST_VIRTIO]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) set_bit(IRQ_PEND_VIRTIO, &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) static int __inject_pfault_done(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) struct kvm_s390_interrupt_info *inti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) kvm->stat.inject_pfault_done++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) if (fi->counters[FIRQ_CNTR_PFAULT] >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) (ASYNC_PF_PER_VCPU * KVM_MAX_VCPUS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) fi->counters[FIRQ_CNTR_PFAULT] += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) list_add_tail(&inti->list, &fi->lists[FIRQ_LIST_PFAULT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) set_bit(IRQ_PEND_PFAULT_DONE, &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) #define CR_PENDING_SUBCLASS 28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) static int __inject_float_mchk(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) struct kvm_s390_interrupt_info *inti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) kvm->stat.inject_float_mchk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) fi->mchk.cr14 |= inti->mchk.cr14 & (1UL << CR_PENDING_SUBCLASS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) fi->mchk.mcic |= inti->mchk.mcic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) set_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) kfree(inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) static int __inject_io(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) struct kvm_s390_float_interrupt *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) struct list_head *list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) int isc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) kvm->stat.inject_io++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) isc = int_word_to_isc(inti->io.io_int_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) * Do not make use of gisa in protected mode. We do not use the lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) * checking variant as this is just a performance optimization and we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) * do not hold the lock here. This is ok as the code will pick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) * interrupts from both "lists" for delivery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) if (!kvm_s390_pv_get_handle(kvm) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) gi->origin && inti->type & KVM_S390_INT_IO_AI_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) VM_EVENT(kvm, 4, "%s isc %1u", "inject: I/O (AI/gisa)", isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) gisa_set_ipm_gisc(gi->origin, isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) kfree(inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) if (fi->counters[FIRQ_CNTR_IO] >= KVM_S390_MAX_FLOAT_IRQS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) fi->counters[FIRQ_CNTR_IO] += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) if (inti->type & KVM_S390_INT_IO_AI_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) VM_EVENT(kvm, 4, "%s", "inject: I/O (AI)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) VM_EVENT(kvm, 4, "inject: I/O %x ss %x schid %04x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) inti->io.subchannel_id >> 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) inti->io.subchannel_id >> 1 & 0x3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) inti->io.subchannel_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) list = &fi->lists[FIRQ_LIST_IO_ISC_0 + isc];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) list_add_tail(&inti->list, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) set_bit(isc_to_irq_type(isc), &fi->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) * Find a destination VCPU for a floating irq and kick it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) static void __floating_irq_kick(struct kvm *kvm, u64 type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) struct kvm_vcpu *dst_vcpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) int sigcpu, online_vcpus, nr_tries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) online_vcpus = atomic_read(&kvm->online_vcpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) if (!online_vcpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) /* find idle VCPUs first, then round robin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) sigcpu = find_first_bit(kvm->arch.idle_mask, online_vcpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) if (sigcpu == online_vcpus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) sigcpu = kvm->arch.float_int.next_rr_cpu++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) kvm->arch.float_int.next_rr_cpu %= online_vcpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) /* avoid endless loops if all vcpus are stopped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) if (nr_tries++ >= online_vcpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) } while (is_vcpu_stopped(kvm_get_vcpu(kvm, sigcpu)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) dst_vcpu = kvm_get_vcpu(kvm, sigcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) /* make the VCPU drop out of the SIE, or wake it up if sleeping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) case KVM_S390_MCHK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_STOP_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) if (!(type & KVM_S390_INT_IO_AI_MASK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) kvm->arch.gisa_int.origin) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) kvm_s390_pv_cpu_get_handle(dst_vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_IO_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_EXT_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) kvm_s390_vcpu_wakeup(dst_vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) u64 type = READ_ONCE(inti->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) case KVM_S390_MCHK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) rc = __inject_float_mchk(kvm, inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) case KVM_S390_INT_VIRTIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) rc = __inject_virtio(kvm, inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) case KVM_S390_INT_SERVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) rc = __inject_service(kvm, inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) case KVM_S390_INT_PFAULT_DONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) rc = __inject_pfault_done(kvm, inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) rc = __inject_io(kvm, inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) __floating_irq_kick(kvm, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) int kvm_s390_inject_vm(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) struct kvm_s390_interrupt *s390int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) struct kvm_s390_interrupt_info *inti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) inti = kzalloc(sizeof(*inti), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) if (!inti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) inti->type = s390int->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) switch (inti->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) case KVM_S390_INT_VIRTIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) VM_EVENT(kvm, 5, "inject: virtio parm:%x,parm64:%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) s390int->parm, s390int->parm64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) inti->ext.ext_params = s390int->parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) inti->ext.ext_params2 = s390int->parm64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) case KVM_S390_INT_SERVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) VM_EVENT(kvm, 4, "inject: sclp parm:%x", s390int->parm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) inti->ext.ext_params = s390int->parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) case KVM_S390_INT_PFAULT_DONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) inti->ext.ext_params2 = s390int->parm64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) case KVM_S390_MCHK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) VM_EVENT(kvm, 3, "inject: machine check mcic 0x%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) s390int->parm64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) inti->mchk.cr14 = s390int->parm; /* upper bits are not used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) inti->mchk.mcic = s390int->parm64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) inti->io.subchannel_id = s390int->parm >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) inti->io.subchannel_nr = s390int->parm & 0x0000ffffu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) inti->io.io_int_parm = s390int->parm64 >> 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) inti->io.io_int_word = s390int->parm64 & 0x00000000ffffffffull;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) kfree(inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) trace_kvm_s390_inject_vm(s390int->type, s390int->parm, s390int->parm64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) rc = __inject_vm(kvm, inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) kfree(inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) int kvm_s390_reinject_io_int(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) struct kvm_s390_interrupt_info *inti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) return __inject_vm(kvm, inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) int s390int_to_s390irq(struct kvm_s390_interrupt *s390int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) struct kvm_s390_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) irq->type = s390int->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) switch (irq->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) case KVM_S390_PROGRAM_INT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) if (s390int->parm & 0xffff0000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) irq->u.pgm.code = s390int->parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) case KVM_S390_SIGP_SET_PREFIX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) irq->u.prefix.address = s390int->parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) case KVM_S390_SIGP_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) irq->u.stop.flags = s390int->parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) case KVM_S390_INT_EXTERNAL_CALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) if (s390int->parm & 0xffff0000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) irq->u.extcall.code = s390int->parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) case KVM_S390_INT_EMERGENCY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) if (s390int->parm & 0xffff0000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) irq->u.emerg.code = s390int->parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) case KVM_S390_MCHK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) irq->u.mchk.mcic = s390int->parm64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) case KVM_S390_INT_PFAULT_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) irq->u.ext.ext_params = s390int->parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) irq->u.ext.ext_params2 = s390int->parm64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) case KVM_S390_RESTART:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) case KVM_S390_INT_CLOCK_COMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) case KVM_S390_INT_CPU_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) int kvm_s390_is_stop_irq_pending(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) return test_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) int kvm_s390_is_restart_irq_pending(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) return test_bit(IRQ_PEND_RESTART, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) spin_lock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) li->irq.stop.flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) clear_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) spin_unlock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) static int do_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) switch (irq->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) case KVM_S390_PROGRAM_INT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) rc = __inject_prog(vcpu, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) case KVM_S390_SIGP_SET_PREFIX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) rc = __inject_set_prefix(vcpu, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) case KVM_S390_SIGP_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) rc = __inject_sigp_stop(vcpu, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) case KVM_S390_RESTART:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) rc = __inject_sigp_restart(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) case KVM_S390_INT_CLOCK_COMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) rc = __inject_ckc(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) case KVM_S390_INT_CPU_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) rc = __inject_cpu_timer(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) case KVM_S390_INT_EXTERNAL_CALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) rc = __inject_extcall(vcpu, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) case KVM_S390_INT_EMERGENCY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) rc = __inject_sigp_emergency(vcpu, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) case KVM_S390_MCHK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) rc = __inject_mchk(vcpu, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) case KVM_S390_INT_PFAULT_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) rc = __inject_pfault_init(vcpu, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) case KVM_S390_INT_VIRTIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) case KVM_S390_INT_SERVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) spin_lock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) rc = do_inject_vcpu(vcpu, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) spin_unlock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) kvm_s390_vcpu_wakeup(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) static inline void clear_irq_list(struct list_head *_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) struct kvm_s390_interrupt_info *inti, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) list_for_each_entry_safe(inti, n, _list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) list_del(&inti->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) kfree(inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) static void inti_to_irq(struct kvm_s390_interrupt_info *inti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) struct kvm_s390_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) irq->type = inti->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) switch (inti->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) case KVM_S390_INT_PFAULT_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) case KVM_S390_INT_PFAULT_DONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) case KVM_S390_INT_VIRTIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) irq->u.ext = inti->ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) irq->u.io = inti->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) void kvm_s390_clear_float_irqs(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) mutex_lock(&kvm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) if (!kvm_s390_pv_is_protected(kvm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) fi->masked_irqs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) mutex_unlock(&kvm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) fi->pending_irqs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) memset(&fi->srv_signal, 0, sizeof(fi->srv_signal));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) memset(&fi->mchk, 0, sizeof(fi->mchk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) for (i = 0; i < FIRQ_LIST_COUNT; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) clear_irq_list(&fi->lists[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) for (i = 0; i < FIRQ_MAX_COUNT; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) fi->counters[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) kvm_s390_gisa_clear(kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) static int get_all_floating_irqs(struct kvm *kvm, u8 __user *usrbuf, u64 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) struct kvm_s390_interrupt_info *inti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) struct kvm_s390_float_interrupt *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) struct kvm_s390_irq *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) struct kvm_s390_irq *irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) int max_irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) if (len > KVM_S390_FLIC_MAX_BUFFER || len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) * We are already using -ENOMEM to signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) * userspace it may retry with a bigger buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) * so we need to use something else for this case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) buf = vzalloc(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) max_irqs = len / sizeof(struct kvm_s390_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) if (gi->origin && gisa_get_ipm(gi->origin)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) for (i = 0; i <= MAX_ISC; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) if (n == max_irqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) /* signal userspace to try again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) goto out_nolock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) if (gisa_tac_ipm_gisc(gi->origin, i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) irq = (struct kvm_s390_irq *) &buf[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) irq->type = KVM_S390_INT_IO(1, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) irq->u.io.io_int_word = isc_to_int_word(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) for (i = 0; i < FIRQ_LIST_COUNT; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) list_for_each_entry(inti, &fi->lists[i], list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) if (n == max_irqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) /* signal userspace to try again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) inti_to_irq(inti, &buf[n]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) if (test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) test_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) if (n == max_irqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) /* signal userspace to try again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) irq = (struct kvm_s390_irq *) &buf[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) irq->type = KVM_S390_INT_SERVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) irq->u.ext = fi->srv_signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) if (test_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) if (n == max_irqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) /* signal userspace to try again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) irq = (struct kvm_s390_irq *) &buf[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) irq->type = KVM_S390_MCHK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) irq->u.mchk = fi->mchk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) out_nolock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) if (!ret && n > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) if (copy_to_user(usrbuf, buf, sizeof(struct kvm_s390_irq) * n))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) vfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) return ret < 0 ? ret : n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) static int flic_ais_mode_get_all(struct kvm *kvm, struct kvm_device_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) struct kvm_s390_ais_all ais;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) if (attr->attr < sizeof(ais))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) if (!test_kvm_facility(kvm, 72))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) mutex_lock(&fi->ais_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) ais.simm = fi->simm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) ais.nimm = fi->nimm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) mutex_unlock(&fi->ais_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) if (copy_to_user((void __user *)attr->addr, &ais, sizeof(ais)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) static int flic_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) switch (attr->group) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) case KVM_DEV_FLIC_GET_ALL_IRQS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) r = get_all_floating_irqs(dev->kvm, (u8 __user *) attr->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) attr->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) case KVM_DEV_FLIC_AISM_ALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) r = flic_ais_mode_get_all(dev->kvm, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) static inline int copy_irq_from_user(struct kvm_s390_interrupt_info *inti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) u64 addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) struct kvm_s390_irq __user *uptr = (struct kvm_s390_irq __user *) addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) void *target = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) void __user *source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) u64 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) if (get_user(inti->type, (u64 __user *)addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) switch (inti->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) case KVM_S390_INT_PFAULT_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) case KVM_S390_INT_PFAULT_DONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) case KVM_S390_INT_VIRTIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) case KVM_S390_INT_SERVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) target = (void *) &inti->ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) source = &uptr->u.ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) size = sizeof(inti->ext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) target = (void *) &inti->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) source = &uptr->u.io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) size = sizeof(inti->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) case KVM_S390_MCHK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) target = (void *) &inti->mchk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) source = &uptr->u.mchk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) size = sizeof(inti->mchk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) if (copy_from_user(target, source, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) static int enqueue_floating_irq(struct kvm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) struct kvm_device_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) struct kvm_s390_interrupt_info *inti = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) int len = attr->attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) if (len % sizeof(struct kvm_s390_irq) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) else if (len > KVM_S390_FLIC_MAX_BUFFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) while (len >= sizeof(struct kvm_s390_irq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) inti = kzalloc(sizeof(*inti), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) if (!inti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) r = copy_irq_from_user(inti, attr->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) kfree(inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) r = __inject_vm(dev->kvm, inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) kfree(inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) len -= sizeof(struct kvm_s390_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) attr->addr += sizeof(struct kvm_s390_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) static struct s390_io_adapter *get_io_adapter(struct kvm *kvm, unsigned int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) if (id >= MAX_S390_IO_ADAPTERS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) id = array_index_nospec(id, MAX_S390_IO_ADAPTERS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) return kvm->arch.adapters[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) static int register_io_adapter(struct kvm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) struct kvm_device_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) struct s390_io_adapter *adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) struct kvm_s390_io_adapter adapter_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) if (copy_from_user(&adapter_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) (void __user *)attr->addr, sizeof(adapter_info)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) if (adapter_info.id >= MAX_S390_IO_ADAPTERS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) adapter_info.id = array_index_nospec(adapter_info.id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) MAX_S390_IO_ADAPTERS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) if (dev->kvm->arch.adapters[adapter_info.id] != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) if (!adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) adapter->id = adapter_info.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) adapter->isc = adapter_info.isc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) adapter->maskable = adapter_info.maskable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) adapter->masked = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) adapter->swap = adapter_info.swap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) adapter->suppressible = (adapter_info.flags) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) KVM_S390_ADAPTER_SUPPRESSIBLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) dev->kvm->arch.adapters[adapter->id] = adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) struct s390_io_adapter *adapter = get_io_adapter(kvm, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) if (!adapter || !adapter->maskable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) ret = adapter->masked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) adapter->masked = masked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) void kvm_s390_destroy_adapters(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) for (i = 0; i < MAX_S390_IO_ADAPTERS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) kfree(kvm->arch.adapters[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) static int modify_io_adapter(struct kvm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) struct kvm_device_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) struct kvm_s390_io_adapter_req req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) struct s390_io_adapter *adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) if (copy_from_user(&req, (void __user *)attr->addr, sizeof(req)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) adapter = get_io_adapter(dev->kvm, req.id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) if (!adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) switch (req.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) case KVM_S390_IO_ADAPTER_MASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) ret = kvm_s390_mask_adapter(dev->kvm, req.id, req.mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) * The following operations are no longer needed and therefore no-ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) * The gpa to hva translation is done when an IRQ route is set up. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) * set_irq code uses get_user_pages_remote() to do the actual write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) case KVM_S390_IO_ADAPTER_MAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) case KVM_S390_IO_ADAPTER_UNMAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) static int clear_io_irq(struct kvm *kvm, struct kvm_device_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) const u64 isc_mask = 0xffUL << 24; /* all iscs set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) u32 schid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) if (attr->flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) if (attr->attr != sizeof(schid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) if (copy_from_user(&schid, (void __user *) attr->addr, sizeof(schid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) if (!schid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) kfree(kvm_s390_get_io_int(kvm, isc_mask, schid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) * If userspace is conforming to the architecture, we can have at most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) * one pending I/O interrupt per subchannel, so this is effectively a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) * clear all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) static int modify_ais_mode(struct kvm *kvm, struct kvm_device_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) struct kvm_s390_ais_req req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) if (!test_kvm_facility(kvm, 72))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) if (copy_from_user(&req, (void __user *)attr->addr, sizeof(req)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) if (req.isc > MAX_ISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) trace_kvm_s390_modify_ais_mode(req.isc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) (fi->simm & AIS_MODE_MASK(req.isc)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) (fi->nimm & AIS_MODE_MASK(req.isc)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 2 : KVM_S390_AIS_MODE_SINGLE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) KVM_S390_AIS_MODE_ALL, req.mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) mutex_lock(&fi->ais_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) switch (req.mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) case KVM_S390_AIS_MODE_ALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) fi->simm &= ~AIS_MODE_MASK(req.isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) fi->nimm &= ~AIS_MODE_MASK(req.isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) case KVM_S390_AIS_MODE_SINGLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) fi->simm |= AIS_MODE_MASK(req.isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) fi->nimm &= ~AIS_MODE_MASK(req.isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) mutex_unlock(&fi->ais_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) static int kvm_s390_inject_airq(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) struct s390_io_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) struct kvm_s390_interrupt s390int = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) .type = KVM_S390_INT_IO(1, 0, 0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) .parm = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) .parm64 = isc_to_int_word(adapter->isc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) if (!test_kvm_facility(kvm, 72) || !adapter->suppressible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) return kvm_s390_inject_vm(kvm, &s390int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) mutex_lock(&fi->ais_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) if (fi->nimm & AIS_MODE_MASK(adapter->isc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) trace_kvm_s390_airq_suppressed(adapter->id, adapter->isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) ret = kvm_s390_inject_vm(kvm, &s390int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) if (!ret && (fi->simm & AIS_MODE_MASK(adapter->isc))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) fi->nimm |= AIS_MODE_MASK(adapter->isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) trace_kvm_s390_modify_ais_mode(adapter->isc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) KVM_S390_AIS_MODE_SINGLE, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) mutex_unlock(&fi->ais_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) static int flic_inject_airq(struct kvm *kvm, struct kvm_device_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) unsigned int id = attr->attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) struct s390_io_adapter *adapter = get_io_adapter(kvm, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) if (!adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) return kvm_s390_inject_airq(kvm, adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) static int flic_ais_mode_set_all(struct kvm *kvm, struct kvm_device_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) struct kvm_s390_ais_all ais;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) if (!test_kvm_facility(kvm, 72))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) if (copy_from_user(&ais, (void __user *)attr->addr, sizeof(ais)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) mutex_lock(&fi->ais_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) fi->simm = ais.simm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) fi->nimm = ais.nimm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) mutex_unlock(&fi->ais_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) static int flic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) struct kvm_vcpu *vcpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) switch (attr->group) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) case KVM_DEV_FLIC_ENQUEUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) r = enqueue_floating_irq(dev, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) case KVM_DEV_FLIC_CLEAR_IRQS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) kvm_s390_clear_float_irqs(dev->kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) case KVM_DEV_FLIC_APF_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) dev->kvm->arch.gmap->pfault_enabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) case KVM_DEV_FLIC_APF_DISABLE_WAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) dev->kvm->arch.gmap->pfault_enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) * Make sure no async faults are in transition when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) * clearing the queues. So we don't need to worry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) * about late coming workers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) synchronize_srcu(&dev->kvm->srcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) kvm_for_each_vcpu(i, vcpu, dev->kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) kvm_clear_async_pf_completion_queue(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) case KVM_DEV_FLIC_ADAPTER_REGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) r = register_io_adapter(dev, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) case KVM_DEV_FLIC_ADAPTER_MODIFY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) r = modify_io_adapter(dev, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) case KVM_DEV_FLIC_CLEAR_IO_IRQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) r = clear_io_irq(dev->kvm, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) case KVM_DEV_FLIC_AISM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) r = modify_ais_mode(dev->kvm, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) case KVM_DEV_FLIC_AIRQ_INJECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) r = flic_inject_airq(dev->kvm, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) case KVM_DEV_FLIC_AISM_ALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) r = flic_ais_mode_set_all(dev->kvm, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) static int flic_has_attr(struct kvm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) struct kvm_device_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) switch (attr->group) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) case KVM_DEV_FLIC_GET_ALL_IRQS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) case KVM_DEV_FLIC_ENQUEUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) case KVM_DEV_FLIC_CLEAR_IRQS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) case KVM_DEV_FLIC_APF_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) case KVM_DEV_FLIC_APF_DISABLE_WAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) case KVM_DEV_FLIC_ADAPTER_REGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) case KVM_DEV_FLIC_ADAPTER_MODIFY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) case KVM_DEV_FLIC_CLEAR_IO_IRQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) case KVM_DEV_FLIC_AISM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) case KVM_DEV_FLIC_AIRQ_INJECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) case KVM_DEV_FLIC_AISM_ALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) static int flic_create(struct kvm_device *dev, u32 type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) if (dev->kvm->arch.flic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) dev->kvm->arch.flic = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) static void flic_destroy(struct kvm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) dev->kvm->arch.flic = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) /* s390 floating irq controller (flic) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) struct kvm_device_ops kvm_flic_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) .name = "kvm-flic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) .get_attr = flic_get_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) .set_attr = flic_set_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) .has_attr = flic_has_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) .create = flic_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) .destroy = flic_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) unsigned long bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) bit = bit_nr + (addr % PAGE_SIZE) * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) return swap ? (bit ^ (BITS_PER_LONG - 1)) : bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) static struct page *get_map_page(struct kvm *kvm, u64 uaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) mmap_read_lock(kvm->mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) get_user_pages_remote(kvm->mm, uaddr, 1, FOLL_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) &page, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) mmap_read_unlock(kvm->mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) static int adapter_indicators_set(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) struct s390_io_adapter *adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) struct kvm_s390_adapter_int *adapter_int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) unsigned long bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) int summary_set, idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) struct page *ind_page, *summary_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) void *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) ind_page = get_map_page(kvm, adapter_int->ind_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) if (!ind_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) summary_page = get_map_page(kvm, adapter_int->summary_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) if (!summary_page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) put_page(ind_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) idx = srcu_read_lock(&kvm->srcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) map = page_address(ind_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) bit = get_ind_bit(adapter_int->ind_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) adapter_int->ind_offset, adapter->swap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) set_bit(bit, map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) mark_page_dirty(kvm, adapter_int->ind_addr >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) set_page_dirty_lock(ind_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) map = page_address(summary_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) bit = get_ind_bit(adapter_int->summary_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) adapter_int->summary_offset, adapter->swap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) summary_set = test_and_set_bit(bit, map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) mark_page_dirty(kvm, adapter_int->summary_addr >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) set_page_dirty_lock(summary_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) srcu_read_unlock(&kvm->srcu, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) put_page(ind_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) put_page(summary_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) return summary_set ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) * < 0 - not injected due to error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) * = 0 - coalesced, summary indicator already active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) * > 0 - injected interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) static int set_adapter_int(struct kvm_kernel_irq_routing_entry *e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) struct kvm *kvm, int irq_source_id, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) bool line_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) struct s390_io_adapter *adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) /* We're only interested in the 0->1 transition. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) if (!level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) adapter = get_io_adapter(kvm, e->adapter.adapter_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) if (!adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) ret = adapter_indicators_set(kvm, adapter, &e->adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) if ((ret > 0) && !adapter->masked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) ret = kvm_s390_inject_airq(kvm, adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) * Inject the machine check to the guest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) struct mcck_volatile_info *mcck_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) struct kvm_s390_interrupt_info inti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) struct kvm_s390_irq irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) struct kvm_s390_mchk_info *mchk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) union mci mci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) __u64 cr14 = 0; /* upper bits are not used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) mci.val = mcck_info->mcic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) if (mci.sr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) cr14 |= CR14_RECOVERY_SUBMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) if (mci.dg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) cr14 |= CR14_DEGRADATION_SUBMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) if (mci.w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) cr14 |= CR14_WARNING_SUBMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) mchk = mci.ck ? &inti.mchk : &irq.u.mchk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) mchk->cr14 = cr14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) mchk->mcic = mcck_info->mcic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) mchk->ext_damage_code = mcck_info->ext_damage_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) mchk->failing_storage_address = mcck_info->failing_storage_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) if (mci.ck) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) /* Inject the floating machine check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) inti.type = KVM_S390_MCHK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) rc = __inject_vm(vcpu->kvm, &inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) /* Inject the machine check to specified vcpu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) irq.type = KVM_S390_MCHK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) rc = kvm_s390_inject_vcpu(vcpu, &irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) WARN_ON_ONCE(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) int kvm_set_routing_entry(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) struct kvm_kernel_irq_routing_entry *e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) const struct kvm_irq_routing_entry *ue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) u64 uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) switch (ue->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) /* we store the userspace addresses instead of the guest addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) case KVM_IRQ_ROUTING_S390_ADAPTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) e->set = set_adapter_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.summary_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) if (uaddr == -EFAULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) e->adapter.summary_addr = uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.ind_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) if (uaddr == -EFAULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) e->adapter.ind_addr = uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) e->adapter.summary_offset = ue->u.adapter.summary_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) e->adapter.ind_offset = ue->u.adapter.ind_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) e->adapter.adapter_id = ue->u.adapter.adapter_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) int irq_source_id, int level, bool line_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) int kvm_s390_set_irq_state(struct kvm_vcpu *vcpu, void __user *irqstate, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) struct kvm_s390_irq *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) buf = vmalloc(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) if (copy_from_user((void *) buf, irqstate, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) r = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) * Don't allow setting the interrupt state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) * when there are already interrupts pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) spin_lock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) if (li->pending_irqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) r = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) for (n = 0; n < len / sizeof(*buf); n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) r = do_inject_vcpu(vcpu, &buf[n]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) spin_unlock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) vfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) static void store_local_irq(struct kvm_s390_local_interrupt *li,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) struct kvm_s390_irq *irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) unsigned long irq_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) switch (irq_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) case IRQ_PEND_MCHK_EX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) case IRQ_PEND_MCHK_REP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) irq->type = KVM_S390_MCHK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) irq->u.mchk = li->irq.mchk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) case IRQ_PEND_PROG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) irq->type = KVM_S390_PROGRAM_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) irq->u.pgm = li->irq.pgm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) case IRQ_PEND_PFAULT_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) irq->type = KVM_S390_INT_PFAULT_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) irq->u.ext = li->irq.ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) case IRQ_PEND_EXT_EXTERNAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) irq->type = KVM_S390_INT_EXTERNAL_CALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) irq->u.extcall = li->irq.extcall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) case IRQ_PEND_EXT_CLOCK_COMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) irq->type = KVM_S390_INT_CLOCK_COMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) case IRQ_PEND_EXT_CPU_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) irq->type = KVM_S390_INT_CPU_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) case IRQ_PEND_SIGP_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) irq->type = KVM_S390_SIGP_STOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) irq->u.stop = li->irq.stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) case IRQ_PEND_RESTART:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) irq->type = KVM_S390_RESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) case IRQ_PEND_SET_PREFIX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) irq->type = KVM_S390_SIGP_SET_PREFIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) irq->u.prefix = li->irq.prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu, __u8 __user *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) int scn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) unsigned long pending_irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) struct kvm_s390_irq irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) unsigned long irq_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) int cpuaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) spin_lock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) pending_irqs = li->pending_irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) memcpy(&sigp_emerg_pending, &li->sigp_emerg_pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) sizeof(sigp_emerg_pending));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) spin_unlock(&li->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) for_each_set_bit(irq_type, &pending_irqs, IRQ_PEND_COUNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) memset(&irq, 0, sizeof(irq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) if (irq_type == IRQ_PEND_EXT_EMERGENCY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) if (n + sizeof(irq) > len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) store_local_irq(&vcpu->arch.local_int, &irq, irq_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) if (copy_to_user(&buf[n], &irq, sizeof(irq)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) n += sizeof(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) if (test_bit(IRQ_PEND_EXT_EMERGENCY, &pending_irqs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) for_each_set_bit(cpuaddr, sigp_emerg_pending, KVM_MAX_VCPUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) memset(&irq, 0, sizeof(irq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) if (n + sizeof(irq) > len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) irq.type = KVM_S390_INT_EMERGENCY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) irq.u.emerg.code = cpuaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) if (copy_to_user(&buf[n], &irq, sizeof(irq)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) n += sizeof(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) if (sca_ext_call_pending(vcpu, &scn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) if (n + sizeof(irq) > len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) memset(&irq, 0, sizeof(irq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) irq.type = KVM_S390_INT_EXTERNAL_CALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) irq.u.extcall.code = scn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) if (copy_to_user(&buf[n], &irq, sizeof(irq)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) n += sizeof(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) static void __airqs_kick_single_vcpu(struct kvm *kvm, u8 deliverable_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) int vcpu_idx, online_vcpus = atomic_read(&kvm->online_vcpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) struct kvm_vcpu *vcpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) u8 vcpu_isc_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) for_each_set_bit(vcpu_idx, kvm->arch.idle_mask, online_vcpus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) vcpu = kvm_get_vcpu(kvm, vcpu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) if (psw_ioint_disabled(vcpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) vcpu_isc_mask = (u8)(vcpu->arch.sie_block->gcr[6] >> 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) if (deliverable_mask & vcpu_isc_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) /* lately kicked but not yet running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) if (test_and_set_bit(vcpu_idx, gi->kicked_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) kvm_s390_vcpu_wakeup(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) static enum hrtimer_restart gisa_vcpu_kicker(struct hrtimer *timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) struct kvm_s390_gisa_interrupt *gi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) container_of(timer, struct kvm_s390_gisa_interrupt, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) struct kvm *kvm =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) container_of(gi->origin, struct sie_page2, gisa)->kvm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) u8 pending_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) pending_mask = gisa_get_ipm_or_restore_iam(gi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) if (pending_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) __airqs_kick_single_vcpu(kvm, pending_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) hrtimer_forward_now(timer, ns_to_ktime(gi->expires));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) return HRTIMER_RESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) return HRTIMER_NORESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) #define NULL_GISA_ADDR 0x00000000UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) #define NONE_GISA_ADDR 0x00000001UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) #define GISA_ADDR_MASK 0xfffff000UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) static void process_gib_alert_list(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) struct kvm_s390_gisa_interrupt *gi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) struct kvm_s390_gisa *gisa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) struct kvm *kvm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) u32 final, origin = 0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) * If the NONE_GISA_ADDR is still stored in the alert list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) * origin, we will leave the outer loop. No further GISA has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) * been added to the alert list by millicode while processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) * the current alert list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) final = (origin & NONE_GISA_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) * Cut off the alert list and store the NONE_GISA_ADDR in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) * alert list origin to avoid further GAL interruptions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) * A new alert list can be build up by millicode in parallel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) * for guests not in the yet cut-off alert list. When in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) * final loop, store the NULL_GISA_ADDR instead. This will re-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) * enable GAL interruptions on the host again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) origin = xchg(&gib->alert_list_origin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) (!final) ? NONE_GISA_ADDR : NULL_GISA_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) * Loop through the just cut-off alert list and start the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) * gisa timers to kick idle vcpus to consume the pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) * interruptions asap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) while (origin & GISA_ADDR_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) gisa = (struct kvm_s390_gisa *)(u64)origin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) origin = gisa->next_alert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) gisa->next_alert = (u32)(u64)gisa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) kvm = container_of(gisa, struct sie_page2, gisa)->kvm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) gi = &kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) if (hrtimer_active(&gi->timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) hrtimer_cancel(&gi->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) hrtimer_start(&gi->timer, 0, HRTIMER_MODE_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) } while (!final);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) void kvm_s390_gisa_clear(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) if (!gi->origin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) gisa_clear_ipm(gi->origin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) VM_EVENT(kvm, 3, "gisa 0x%pK cleared", gi->origin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) void kvm_s390_gisa_init(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) if (!css_general_characteristics.aiv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) gi->origin = &kvm->arch.sie_page2->gisa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) gi->alert.mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) spin_lock_init(&gi->alert.ref_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) gi->expires = 50 * 1000; /* 50 usec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) hrtimer_init(&gi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) gi->timer.function = gisa_vcpu_kicker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) memset(gi->origin, 0, sizeof(struct kvm_s390_gisa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) gi->origin->next_alert = (u32)(u64)gi->origin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) VM_EVENT(kvm, 3, "gisa 0x%pK initialized", gi->origin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) void kvm_s390_gisa_destroy(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) if (!gi->origin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) if (gi->alert.mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) KVM_EVENT(3, "vm 0x%pK has unexpected iam 0x%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) kvm, gi->alert.mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) while (gisa_in_alert_list(gi->origin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) hrtimer_cancel(&gi->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) gi->origin = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) * kvm_s390_gisc_register - register a guest ISC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) * @kvm: the kernel vm to work with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) * @gisc: the guest interruption sub class to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) * The function extends the vm specific alert mask to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) * The effective IAM mask in the GISA is updated as well
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) * in case the GISA is not part of the GIB alert list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) * It will be updated latest when the IAM gets restored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) * by gisa_get_ipm_or_restore_iam().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) * Returns: the nonspecific ISC (NISC) the gib alert mechanism
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) * has registered with the channel subsystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) * -ENODEV in case the vm uses no GISA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) * -ERANGE in case the guest ISC is invalid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) if (!gi->origin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) if (gisc > MAX_ISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) spin_lock(&gi->alert.ref_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) gi->alert.ref_count[gisc]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) if (gi->alert.ref_count[gisc] == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) gi->alert.mask |= 0x80 >> gisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) gisa_set_iam(gi->origin, gi->alert.mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) spin_unlock(&gi->alert.ref_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) return gib->nisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) EXPORT_SYMBOL_GPL(kvm_s390_gisc_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) * kvm_s390_gisc_unregister - unregister a guest ISC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) * @kvm: the kernel vm to work with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) * @gisc: the guest interruption sub class to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) * The function reduces the vm specific alert mask to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) * The effective IAM mask in the GISA is updated as well
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) * in case the GISA is not part of the GIB alert list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) * It will be updated latest when the IAM gets restored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) * by gisa_get_ipm_or_restore_iam().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) * Returns: the nonspecific ISC (NISC) the gib alert mechanism
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) * has registered with the channel subsystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) * -ENODEV in case the vm uses no GISA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) * -ERANGE in case the guest ISC is invalid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) * -EINVAL in case the guest ISC is not registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) if (!gi->origin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) if (gisc > MAX_ISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) spin_lock(&gi->alert.ref_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) if (gi->alert.ref_count[gisc] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) gi->alert.ref_count[gisc]--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) if (gi->alert.ref_count[gisc] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) gi->alert.mask &= ~(0x80 >> gisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) gisa_set_iam(gi->origin, gi->alert.mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) spin_unlock(&gi->alert.ref_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) EXPORT_SYMBOL_GPL(kvm_s390_gisc_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) static void gib_alert_irq_handler(struct airq_struct *airq, bool floating)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) inc_irq_stat(IRQIO_GAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) process_gib_alert_list();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) static struct airq_struct gib_alert_irq = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) .handler = gib_alert_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) .lsi_ptr = &gib_alert_irq.lsi_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) void kvm_s390_gib_destroy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) if (!gib)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) chsc_sgib(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) unregister_adapter_interrupt(&gib_alert_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) free_page((unsigned long)gib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) gib = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) int kvm_s390_gib_init(u8 nisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) if (!css_general_characteristics.aiv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) KVM_EVENT(3, "%s", "gib not initialized, no AIV facility");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) gib = (struct kvm_s390_gib *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) if (!gib) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) gib_alert_irq.isc = nisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) if (register_adapter_interrupt(&gib_alert_irq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) pr_err("Registering the GIB alert interruption handler failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) goto out_free_gib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) gib->nisc = nisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) if (chsc_sgib((u32)(u64)gib)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) pr_err("Associating the GIB with the AIV facility failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) free_page((unsigned long)gib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) gib = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) goto out_unreg_gal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) KVM_EVENT(3, "gib 0x%pK (nisc=%d) initialized", gib, gib->nisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) out_unreg_gal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) unregister_adapter_interrupt(&gib_alert_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) out_free_gib:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) free_page((unsigned long)gib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) gib = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) }