Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * definition for kvm on s390
^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)  *               Christian Borntraeger <borntraeger@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *               Christian Ehrhardt <ehrhardt@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #ifndef ARCH_S390_KVM_S390_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define ARCH_S390_KVM_S390_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^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/kvm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/kvm_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/lockdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/facility.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/sclp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /* Transactional Memory Execution related macros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define IS_TE_ENABLED(vcpu)	((vcpu->arch.sie_block->ecb & ECB_TE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define TDB_FORMAT1		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define IS_ITDB_VALID(vcpu)	((*(char *)vcpu->arch.sie_block->itdba == TDB_FORMAT1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) extern debug_info_t *kvm_s390_dbf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) extern debug_info_t *kvm_s390_dbf_uv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define KVM_UV_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	debug_sprintf_event((d_kvm)->arch.dbf, d_loglevel, d_string "\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	  d_args); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	debug_sprintf_event(kvm_s390_dbf_uv, d_loglevel, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 			    "%d: " d_string "\n", (d_kvm)->userspace_pid, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			    d_args); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define KVM_EVENT(d_loglevel, d_string, d_args...)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	debug_sprintf_event(kvm_s390_dbf, d_loglevel, d_string "\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	  d_args); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define VM_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	  d_args); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define VCPU_EVENT(d_vcpu, d_loglevel, d_string, d_args...)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	debug_sprintf_event(d_vcpu->kvm->arch.dbf, d_loglevel, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	  "%02d[%016lx-%016lx]: " d_string "\n", d_vcpu->vcpu_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	  d_vcpu->arch.sie_block->gpsw.mask, d_vcpu->arch.sie_block->gpsw.addr,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	  d_args); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static inline void kvm_s390_set_cpuflags(struct kvm_vcpu *vcpu, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	atomic_or(flags, &vcpu->arch.sie_block->cpuflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static inline void kvm_s390_clear_cpuflags(struct kvm_vcpu *vcpu, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	atomic_andnot(flags, &vcpu->arch.sie_block->cpuflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static inline bool kvm_s390_test_cpuflags(struct kvm_vcpu *vcpu, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return (atomic_read(&vcpu->arch.sie_block->cpuflags) & flags) == flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return kvm_s390_test_cpuflags(vcpu, CPUSTAT_STOPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static inline int is_vcpu_idle(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return test_bit(kvm_vcpu_get_idx(vcpu), vcpu->kvm->arch.idle_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static inline int kvm_is_ucontrol(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #ifdef CONFIG_KVM_S390_UCONTROL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (kvm->arch.gmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #define GUEST_PREFIX_SHIFT 13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static inline u32 kvm_s390_get_prefix(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return vcpu->arch.sie_block->prefix << GUEST_PREFIX_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static inline void kvm_s390_set_prefix(struct kvm_vcpu *vcpu, u32 prefix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	VCPU_EVENT(vcpu, 3, "set prefix of cpu %03u to 0x%x", vcpu->vcpu_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		   prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	vcpu->arch.sie_block->prefix = prefix >> GUEST_PREFIX_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static inline u64 kvm_s390_get_base_disp_s(struct kvm_vcpu *vcpu, u8 *ar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	u32 base2 = vcpu->arch.sie_block->ipb >> 28;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (ar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		*ar = base2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static inline void kvm_s390_get_base_disp_sse(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 					      u64 *address1, u64 *address2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 					      u8 *ar_b1, u8 *ar_b2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	u32 base1 = (vcpu->arch.sie_block->ipb & 0xf0000000) >> 28;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	u32 disp1 = (vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	u32 base2 = (vcpu->arch.sie_block->ipb & 0xf000) >> 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	u32 disp2 = vcpu->arch.sie_block->ipb & 0x0fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	*address1 = (base1 ? vcpu->run->s.regs.gprs[base1] : 0) + disp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	*address2 = (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (ar_b1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		*ar_b1 = base1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (ar_b2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		*ar_b2 = base2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static inline void kvm_s390_get_regs_rre(struct kvm_vcpu *vcpu, int *r1, int *r2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		*r1 = (vcpu->arch.sie_block->ipb & 0x00f00000) >> 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (r2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		*r2 = (vcpu->arch.sie_block->ipb & 0x000f0000) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static inline u64 kvm_s390_get_base_disp_rsy(struct kvm_vcpu *vcpu, u8 *ar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	u32 base2 = vcpu->arch.sie_block->ipb >> 28;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			((vcpu->arch.sie_block->ipb & 0xff00) << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/* The displacement is a 20bit _SIGNED_ value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (disp2 & 0x80000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		disp2+=0xfff00000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (ar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		*ar = base2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + (long)(int)disp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static inline u64 kvm_s390_get_base_disp_rs(struct kvm_vcpu *vcpu, u8 *ar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	u32 base2 = vcpu->arch.sie_block->ipb >> 28;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (ar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		*ar = base2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* Set the condition code in the guest program status word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static inline void kvm_s390_set_psw_cc(struct kvm_vcpu *vcpu, unsigned long cc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	vcpu->arch.sie_block->gpsw.mask &= ~(3UL << 44);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	vcpu->arch.sie_block->gpsw.mask |= cc << 44;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* test availability of facility in a kvm instance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static inline int test_kvm_facility(struct kvm *kvm, unsigned long nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return __test_facility(nr, kvm->arch.model.fac_mask) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		__test_facility(nr, kvm->arch.model.fac_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static inline int set_kvm_facility(u64 *fac_list, unsigned long nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	unsigned char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (nr >= MAX_FACILITY_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	ptr = (unsigned char *) fac_list + (nr >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	*ptr |= (0x80UL >> (nr & 7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static inline int test_kvm_cpu_feat(struct kvm *kvm, unsigned long nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	WARN_ON_ONCE(nr >= KVM_S390_VM_CPU_FEAT_NR_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return test_bit_inv(nr, kvm->arch.cpu_feat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /* are cpu states controlled by user space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	return kvm->arch.user_cpu_state_ctrl != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* implemented in pv.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) int kvm_s390_pv_destroy_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int kvm_s390_pv_deinit_vm(struct kvm *kvm, u16 *rc, u16 *rrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			      u16 *rrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		       unsigned long tweak, u16 *rc, u16 *rrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) int kvm_s390_pv_set_cpu_state(struct kvm_vcpu *vcpu, u8 state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static inline u64 kvm_s390_pv_get_handle(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return kvm->arch.pv.handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static inline u64 kvm_s390_pv_cpu_get_handle(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return vcpu->arch.pv.handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static inline bool kvm_s390_pv_is_protected(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	lockdep_assert_held(&kvm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	return !!kvm_s390_pv_get_handle(kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static inline bool kvm_s390_pv_cpu_is_protected(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	lockdep_assert_held(&vcpu->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return !!kvm_s390_pv_cpu_get_handle(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* implemented in interrupt.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int kvm_s390_handle_wait(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) void kvm_s390_clear_float_irqs(struct kvm *kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) int __must_check kvm_s390_inject_vm(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				    struct kvm_s390_interrupt *s390int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int __must_check kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				      struct kvm_s390_irq *irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static inline int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 					   struct kvm_s390_pgm_info *pgm_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct kvm_s390_irq irq = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		.type = KVM_S390_PROGRAM_INT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		.u.pgm = *pgm_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	return kvm_s390_inject_vcpu(vcpu, &irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static inline int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct kvm_s390_irq irq = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		.type = KVM_S390_PROGRAM_INT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		.u.pgm.code = code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	return kvm_s390_inject_vcpu(vcpu, &irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 						    u64 isc_mask, u32 schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) int kvm_s390_reinject_io_int(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			     struct kvm_s390_interrupt_info *inti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /* implemented in intercept.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) u8 kvm_s390_get_ilen(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static inline void kvm_s390_rewind_psw(struct kvm_vcpu *vcpu, int ilen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct kvm_s390_sie_block *sie_block = vcpu->arch.sie_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	sie_block->gpsw.addr = __rewind_psw(sie_block->gpsw, ilen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static inline void kvm_s390_forward_psw(struct kvm_vcpu *vcpu, int ilen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	kvm_s390_rewind_psw(vcpu, -ilen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static inline void kvm_s390_retry_instr(struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	/* don't inject PER events if we re-execute the instruction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	vcpu->arch.sie_block->icptstatus &= ~0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	kvm_s390_rewind_psw(vcpu, kvm_s390_get_ilen(vcpu));
^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) int handle_sthyi(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /* implemented in priv.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) int is_valid_psw(psw_t *psw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int kvm_s390_handle_aa(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int kvm_s390_handle_b2(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int kvm_s390_handle_e3(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int kvm_s390_handle_e5(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int kvm_s390_handle_01(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) int kvm_s390_handle_b9(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) int kvm_s390_handle_stctl(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int kvm_s390_handle_eb(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) int kvm_s390_skey_check_enable(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /* implemented in vsie.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) void kvm_s390_vsie_kick(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) void kvm_s390_vsie_gmap_notifier(struct gmap *gmap, unsigned long start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 				 unsigned long end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) void kvm_s390_vsie_init(struct kvm *kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) void kvm_s390_vsie_destroy(struct kvm *kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* implemented in sigp.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /* implemented in kvm-s390.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) void kvm_s390_set_tod_clock(struct kvm *kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			    const struct kvm_s390_vm_tod_clock *gtod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) long kvm_arch_fault_in_page(struct kvm_vcpu *vcpu, gpa_t gpa, int writable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) int kvm_s390_vcpu_start(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) int kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) void kvm_s390_vcpu_block(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) void kvm_s390_vcpu_unblock(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) bool kvm_s390_vcpu_sie_inhibited(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) void exit_sie(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) void kvm_s390_sync_request(int req, struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) void kvm_s390_set_cpu_timer(struct kvm_vcpu *vcpu, __u64 cputm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) __u64 kvm_s390_get_cpu_timer(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* implemented in diag.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static inline void kvm_s390_vcpu_block_all(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	struct kvm_vcpu *vcpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	WARN_ON(!mutex_is_locked(&kvm->lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	kvm_for_each_vcpu(i, vcpu, kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		kvm_s390_vcpu_block(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static inline void kvm_s390_vcpu_unblock_all(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	struct kvm_vcpu *vcpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	kvm_for_each_vcpu(i, vcpu, kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		kvm_s390_vcpu_unblock(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static inline u64 kvm_s390_get_tod_clock_fast(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	u64 rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	rc = get_tod_clock_fast() + kvm->arch.epoch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)  * kvm_s390_inject_prog_cond - conditionally inject a program check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)  * @vcpu: virtual cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)  * @rc: original return/error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  * This function is supposed to be used after regular guest access functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  * failed, to conditionally inject a program check to a vcpu. The typical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)  * pattern would look like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)  * rc = write_guest(vcpu, addr, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  * if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)  *	return kvm_s390_inject_prog_cond(vcpu, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  * A negative return code from guest access functions implies an internal error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  * like e.g. out of memory. In these cases no program check should be injected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  * to the guest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  * A positive value implies that an exception happened while accessing a guest's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  * memory. In this case all data belonging to the corresponding program check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  * has been stored in vcpu->arch.pgm and can be injected with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  * kvm_s390_inject_prog_irq().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  * Returns: - the original @rc value if @rc was negative (internal error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  *	    - zero if @rc was already zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  *	    - zero or error code from injecting if @rc was positive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  *	      (program check injected to @vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static inline int kvm_s390_inject_prog_cond(struct kvm_vcpu *vcpu, int rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	if (rc <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	return kvm_s390_inject_prog_irq(vcpu, &vcpu->arch.pgm);
^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) int s390int_to_s390irq(struct kvm_s390_interrupt *s390int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			struct kvm_s390_irq *s390irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* implemented in interrupt.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) int kvm_s390_vcpu_has_irq(struct kvm_vcpu *vcpu, int exclude_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int psw_extint_disabled(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) void kvm_s390_destroy_adapters(struct kvm *kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) extern struct kvm_device_ops kvm_flic_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) int kvm_s390_is_stop_irq_pending(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) int kvm_s390_is_restart_irq_pending(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) int kvm_s390_set_irq_state(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			   void __user *buf, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			   __u8 __user *buf, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) void kvm_s390_gisa_init(struct kvm *kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) void kvm_s390_gisa_clear(struct kvm *kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) void kvm_s390_gisa_destroy(struct kvm *kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) int kvm_s390_gib_init(u8 nisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) void kvm_s390_gib_destroy(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* implemented in guestdbg.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) void kvm_s390_backup_guest_per_regs(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) void kvm_s390_restore_guest_per_regs(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) void kvm_s390_patch_guest_per_regs(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			    struct kvm_guest_debug *dbg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) void kvm_s390_clear_bp_data(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) void kvm_s390_prepare_debug_exit(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) int kvm_s390_handle_per_ifetch_icpt(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int kvm_s390_handle_per_event(struct kvm_vcpu *vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /* support for Basic/Extended SCA handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static inline union ipte_control *kvm_s390_get_ipte_control(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	struct bsca_block *sca = kvm->arch.sca; /* SCA version doesn't matter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	return &sca->ipte_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static inline int kvm_s390_use_sca_entries(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	 * Without SIGP interpretation, only SRS interpretation (if available)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	 * might use the entries. By not setting the entries and keeping them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	 * invalid, hardware will not access them but intercept.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	return sclp.has_sigpif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 				     struct mcck_volatile_info *mcck_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)  * kvm_s390_vcpu_crypto_reset_all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)  * Reset the crypto attributes for each vcpu. This can be done while the vcpus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)  * are running as each vcpu will be removed from SIE before resetting the crypt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)  * attributes and restored to SIE afterward.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  * Note: The kvm->lock must be held while calling this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  * @kvm: the KVM guest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) #endif