xref: /linux/arch/s390/kvm/intercept.c (revision 6cddd432e3da5e25eccbc13844d03c871674a62e)
18f2abe6aSChristian Borntraeger /*
2a53c8fabSHeiko Carstens  * in-kernel handling for sie intercepts
38f2abe6aSChristian Borntraeger  *
49a558ee3SThomas Huth  * Copyright IBM Corp. 2008, 2014
58f2abe6aSChristian Borntraeger  *
68f2abe6aSChristian Borntraeger  * This program is free software; you can redistribute it and/or modify
78f2abe6aSChristian Borntraeger  * it under the terms of the GNU General Public License (version 2 only)
88f2abe6aSChristian Borntraeger  * as published by the Free Software Foundation.
98f2abe6aSChristian Borntraeger  *
108f2abe6aSChristian Borntraeger  *    Author(s): Carsten Otte <cotte@de.ibm.com>
118f2abe6aSChristian Borntraeger  *               Christian Borntraeger <borntraeger@de.ibm.com>
128f2abe6aSChristian Borntraeger  */
138f2abe6aSChristian Borntraeger 
148f2abe6aSChristian Borntraeger #include <linux/kvm_host.h>
158f2abe6aSChristian Borntraeger #include <linux/errno.h>
168f2abe6aSChristian Borntraeger #include <linux/pagemap.h>
178f2abe6aSChristian Borntraeger 
188f2abe6aSChristian Borntraeger #include <asm/kvm_host.h>
19a86dcc24SMichael Mueller #include <asm/asm-offsets.h>
20f14d82e0SThomas Huth #include <asm/irq.h>
218f2abe6aSChristian Borntraeger 
228f2abe6aSChristian Borntraeger #include "kvm-s390.h"
23ba5c1e9bSCarsten Otte #include "gaccess.h"
245786fffaSCornelia Huck #include "trace.h"
25ade38c31SCornelia Huck #include "trace-s390.h"
26ba5c1e9bSCarsten Otte 
27f379aae5SCornelia Huck 
2877975357SCornelia Huck static const intercept_handler_t instruction_handlers[256] = {
298c3f61e2SCornelia Huck 	[0x01] = kvm_s390_handle_01,
3048a3e950SCornelia Huck 	[0x82] = kvm_s390_handle_lpsw,
31e28acfeaSChristian Borntraeger 	[0x83] = kvm_s390_handle_diag,
325288fbf0SChristian Borntraeger 	[0xae] = kvm_s390_handle_sigp,
3370455a36SChristian Borntraeger 	[0xb2] = kvm_s390_handle_b2,
34aba07508SDavid Hildenbrand 	[0xb6] = kvm_s390_handle_stctl,
35953ed88dSThomas Huth 	[0xb7] = kvm_s390_handle_lctl,
3648a3e950SCornelia Huck 	[0xb9] = kvm_s390_handle_b9,
37bb25b9baSChristian Borntraeger 	[0xe5] = kvm_s390_handle_e5,
38953ed88dSThomas Huth 	[0xeb] = kvm_s390_handle_eb,
39ba5c1e9bSCarsten Otte };
408f2abe6aSChristian Borntraeger 
4104b41acdSThomas Huth void kvm_s390_rewind_psw(struct kvm_vcpu *vcpu, int ilc)
4204b41acdSThomas Huth {
4304b41acdSThomas Huth 	struct kvm_s390_sie_block *sie_block = vcpu->arch.sie_block;
4404b41acdSThomas Huth 
4504b41acdSThomas Huth 	/* Use the length of the EXECUTE instruction if necessary */
4604b41acdSThomas Huth 	if (sie_block->icptstatus & 1) {
4704b41acdSThomas Huth 		ilc = (sie_block->icptstatus >> 4) & 0x6;
4804b41acdSThomas Huth 		if (!ilc)
4904b41acdSThomas Huth 			ilc = 4;
5004b41acdSThomas Huth 	}
5104b41acdSThomas Huth 	sie_block->gpsw.addr = __rewind_psw(sie_block->gpsw, ilc);
5204b41acdSThomas Huth }
5304b41acdSThomas Huth 
548f2abe6aSChristian Borntraeger static int handle_noop(struct kvm_vcpu *vcpu)
558f2abe6aSChristian Borntraeger {
568f2abe6aSChristian Borntraeger 	switch (vcpu->arch.sie_block->icptcode) {
570eaeafa1SChristian Borntraeger 	case 0x0:
580eaeafa1SChristian Borntraeger 		vcpu->stat.exit_null++;
590eaeafa1SChristian Borntraeger 		break;
608f2abe6aSChristian Borntraeger 	case 0x10:
618f2abe6aSChristian Borntraeger 		vcpu->stat.exit_external_request++;
628f2abe6aSChristian Borntraeger 		break;
638f2abe6aSChristian Borntraeger 	default:
648f2abe6aSChristian Borntraeger 		break; /* nothing */
658f2abe6aSChristian Borntraeger 	}
668f2abe6aSChristian Borntraeger 	return 0;
678f2abe6aSChristian Borntraeger }
688f2abe6aSChristian Borntraeger 
698f2abe6aSChristian Borntraeger static int handle_stop(struct kvm_vcpu *vcpu)
708f2abe6aSChristian Borntraeger {
71*6cddd432SDavid Hildenbrand 	struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
729ace903dSChristian Ehrhardt 	int rc = 0;
73*6cddd432SDavid Hildenbrand 	uint8_t flags, stop_pending;
745288fbf0SChristian Borntraeger 
758f2abe6aSChristian Borntraeger 	vcpu->stat.exit_stop_request++;
76ade38c31SCornelia Huck 
77*6cddd432SDavid Hildenbrand 	/* avoid races with the injection/SIGP STOP code */
78*6cddd432SDavid Hildenbrand 	spin_lock(&li->lock);
79*6cddd432SDavid Hildenbrand 	flags = li->irq.stop.flags;
80*6cddd432SDavid Hildenbrand 	stop_pending = kvm_s390_is_stop_irq_pending(vcpu);
81*6cddd432SDavid Hildenbrand 	spin_unlock(&li->lock);
829ace903dSChristian Ehrhardt 
83*6cddd432SDavid Hildenbrand 	trace_kvm_s390_stop_request(stop_pending, flags);
84*6cddd432SDavid Hildenbrand 	if (!stop_pending)
8532f5ff63SDavid Hildenbrand 		return 0;
8632f5ff63SDavid Hildenbrand 
87*6cddd432SDavid Hildenbrand 	if (flags & KVM_S390_STOP_FLAG_STORE_STATUS) {
889e0d5473SJens Freimann 		rc = kvm_s390_vcpu_store_status(vcpu,
899e0d5473SJens Freimann 						KVM_S390_STORE_STATUS_NOADDR);
9032f5ff63SDavid Hildenbrand 		if (rc)
915288fbf0SChristian Borntraeger 			return rc;
928f2abe6aSChristian Borntraeger 	}
938f2abe6aSChristian Borntraeger 
946352e4d2SDavid Hildenbrand 	if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm))
9532f5ff63SDavid Hildenbrand 		kvm_s390_vcpu_stop(vcpu);
9632f5ff63SDavid Hildenbrand 	return -EOPNOTSUPP;
9732f5ff63SDavid Hildenbrand }
9832f5ff63SDavid Hildenbrand 
998f2abe6aSChristian Borntraeger static int handle_validity(struct kvm_vcpu *vcpu)
1008f2abe6aSChristian Borntraeger {
1018f2abe6aSChristian Borntraeger 	int viwhy = vcpu->arch.sie_block->ipb >> 16;
1023edbcff9SCarsten Otte 
1038f2abe6aSChristian Borntraeger 	vcpu->stat.exit_validity++;
1045786fffaSCornelia Huck 	trace_kvm_s390_intercept_validity(vcpu, viwhy);
1052c70fe44SChristian Borntraeger 	WARN_ONCE(true, "kvm: unhandled validity intercept 0x%x\n", viwhy);
1062c70fe44SChristian Borntraeger 	return -EOPNOTSUPP;
1078f2abe6aSChristian Borntraeger }
1088f2abe6aSChristian Borntraeger 
109ba5c1e9bSCarsten Otte static int handle_instruction(struct kvm_vcpu *vcpu)
110ba5c1e9bSCarsten Otte {
111ba5c1e9bSCarsten Otte 	intercept_handler_t handler;
112ba5c1e9bSCarsten Otte 
113ba5c1e9bSCarsten Otte 	vcpu->stat.exit_instruction++;
1145786fffaSCornelia Huck 	trace_kvm_s390_intercept_instruction(vcpu,
1155786fffaSCornelia Huck 					     vcpu->arch.sie_block->ipa,
1165786fffaSCornelia Huck 					     vcpu->arch.sie_block->ipb);
117ba5c1e9bSCarsten Otte 	handler = instruction_handlers[vcpu->arch.sie_block->ipa >> 8];
118ba5c1e9bSCarsten Otte 	if (handler)
119ba5c1e9bSCarsten Otte 		return handler(vcpu);
120b8e660b8SHeiko Carstens 	return -EOPNOTSUPP;
121ba5c1e9bSCarsten Otte }
122ba5c1e9bSCarsten Otte 
123439716a5SDavid Hildenbrand static void __extract_prog_irq(struct kvm_vcpu *vcpu,
124439716a5SDavid Hildenbrand 			       struct kvm_s390_pgm_info *pgm_info)
125439716a5SDavid Hildenbrand {
126439716a5SDavid Hildenbrand 	memset(pgm_info, 0, sizeof(struct kvm_s390_pgm_info));
127439716a5SDavid Hildenbrand 	pgm_info->code = vcpu->arch.sie_block->iprcc;
128439716a5SDavid Hildenbrand 
129439716a5SDavid Hildenbrand 	switch (vcpu->arch.sie_block->iprcc & ~PGM_PER) {
130439716a5SDavid Hildenbrand 	case PGM_AFX_TRANSLATION:
131439716a5SDavid Hildenbrand 	case PGM_ASX_TRANSLATION:
132439716a5SDavid Hildenbrand 	case PGM_EX_TRANSLATION:
133439716a5SDavid Hildenbrand 	case PGM_LFX_TRANSLATION:
134439716a5SDavid Hildenbrand 	case PGM_LSTE_SEQUENCE:
135439716a5SDavid Hildenbrand 	case PGM_LSX_TRANSLATION:
136439716a5SDavid Hildenbrand 	case PGM_LX_TRANSLATION:
137439716a5SDavid Hildenbrand 	case PGM_PRIMARY_AUTHORITY:
138439716a5SDavid Hildenbrand 	case PGM_SECONDARY_AUTHORITY:
139439716a5SDavid Hildenbrand 	case PGM_SPACE_SWITCH:
140439716a5SDavid Hildenbrand 		pgm_info->trans_exc_code = vcpu->arch.sie_block->tecmc;
141439716a5SDavid Hildenbrand 		break;
142439716a5SDavid Hildenbrand 	case PGM_ALEN_TRANSLATION:
143439716a5SDavid Hildenbrand 	case PGM_ALE_SEQUENCE:
144439716a5SDavid Hildenbrand 	case PGM_ASTE_INSTANCE:
145439716a5SDavid Hildenbrand 	case PGM_ASTE_SEQUENCE:
146439716a5SDavid Hildenbrand 	case PGM_ASTE_VALIDITY:
147439716a5SDavid Hildenbrand 	case PGM_EXTENDED_AUTHORITY:
148439716a5SDavid Hildenbrand 		pgm_info->exc_access_id = vcpu->arch.sie_block->eai;
149439716a5SDavid Hildenbrand 		break;
150439716a5SDavid Hildenbrand 	case PGM_ASCE_TYPE:
151439716a5SDavid Hildenbrand 	case PGM_PAGE_TRANSLATION:
152439716a5SDavid Hildenbrand 	case PGM_REGION_FIRST_TRANS:
153439716a5SDavid Hildenbrand 	case PGM_REGION_SECOND_TRANS:
154439716a5SDavid Hildenbrand 	case PGM_REGION_THIRD_TRANS:
155439716a5SDavid Hildenbrand 	case PGM_SEGMENT_TRANSLATION:
156439716a5SDavid Hildenbrand 		pgm_info->trans_exc_code = vcpu->arch.sie_block->tecmc;
157439716a5SDavid Hildenbrand 		pgm_info->exc_access_id  = vcpu->arch.sie_block->eai;
158439716a5SDavid Hildenbrand 		pgm_info->op_access_id  = vcpu->arch.sie_block->oai;
159439716a5SDavid Hildenbrand 		break;
160439716a5SDavid Hildenbrand 	case PGM_MONITOR:
161439716a5SDavid Hildenbrand 		pgm_info->mon_class_nr = vcpu->arch.sie_block->mcn;
162439716a5SDavid Hildenbrand 		pgm_info->mon_code = vcpu->arch.sie_block->tecmc;
163439716a5SDavid Hildenbrand 		break;
164439716a5SDavid Hildenbrand 	case PGM_DATA:
165439716a5SDavid Hildenbrand 		pgm_info->data_exc_code = vcpu->arch.sie_block->dxc;
166439716a5SDavid Hildenbrand 		break;
167439716a5SDavid Hildenbrand 	case PGM_PROTECTION:
168439716a5SDavid Hildenbrand 		pgm_info->trans_exc_code = vcpu->arch.sie_block->tecmc;
169439716a5SDavid Hildenbrand 		pgm_info->exc_access_id  = vcpu->arch.sie_block->eai;
170439716a5SDavid Hildenbrand 		break;
171439716a5SDavid Hildenbrand 	default:
172439716a5SDavid Hildenbrand 		break;
173439716a5SDavid Hildenbrand 	}
174439716a5SDavid Hildenbrand 
175439716a5SDavid Hildenbrand 	if (vcpu->arch.sie_block->iprcc & PGM_PER) {
176439716a5SDavid Hildenbrand 		pgm_info->per_code = vcpu->arch.sie_block->perc;
177439716a5SDavid Hildenbrand 		pgm_info->per_atmid = vcpu->arch.sie_block->peratmid;
178439716a5SDavid Hildenbrand 		pgm_info->per_address = vcpu->arch.sie_block->peraddr;
179439716a5SDavid Hildenbrand 		pgm_info->per_access_id = vcpu->arch.sie_block->peraid;
180439716a5SDavid Hildenbrand 	}
181439716a5SDavid Hildenbrand }
182439716a5SDavid Hildenbrand 
183e325fe69SMichael Mueller /*
184e325fe69SMichael Mueller  * restore ITDB to program-interruption TDB in guest lowcore
185e325fe69SMichael Mueller  * and set TX abort indication if required
186e325fe69SMichael Mueller */
187e325fe69SMichael Mueller static int handle_itdb(struct kvm_vcpu *vcpu)
188e325fe69SMichael Mueller {
189e325fe69SMichael Mueller 	struct kvm_s390_itdb *itdb;
190e325fe69SMichael Mueller 	int rc;
191e325fe69SMichael Mueller 
192e325fe69SMichael Mueller 	if (!IS_TE_ENABLED(vcpu) || !IS_ITDB_VALID(vcpu))
193e325fe69SMichael Mueller 		return 0;
194e325fe69SMichael Mueller 	if (current->thread.per_flags & PER_FLAG_NO_TE)
195e325fe69SMichael Mueller 		return 0;
196e325fe69SMichael Mueller 	itdb = (struct kvm_s390_itdb *)vcpu->arch.sie_block->itdba;
197e325fe69SMichael Mueller 	rc = write_guest_lc(vcpu, __LC_PGM_TDB, itdb, sizeof(*itdb));
198e325fe69SMichael Mueller 	if (rc)
199e325fe69SMichael Mueller 		return rc;
200e325fe69SMichael Mueller 	memset(itdb, 0, sizeof(*itdb));
201e325fe69SMichael Mueller 
202e325fe69SMichael Mueller 	return 0;
203e325fe69SMichael Mueller }
204e325fe69SMichael Mueller 
20527291e21SDavid Hildenbrand #define per_event(vcpu) (vcpu->arch.sie_block->iprcc & PGM_PER)
20627291e21SDavid Hildenbrand 
207ba5c1e9bSCarsten Otte static int handle_prog(struct kvm_vcpu *vcpu)
208ba5c1e9bSCarsten Otte {
209439716a5SDavid Hildenbrand 	struct kvm_s390_pgm_info pgm_info;
210684135e0SThomas Huth 	psw_t psw;
2110040e7d2SHeiko Carstens 	int rc;
2120040e7d2SHeiko Carstens 
213ba5c1e9bSCarsten Otte 	vcpu->stat.exit_program_interruption++;
2147feb6bb8SMichael Mueller 
21527291e21SDavid Hildenbrand 	if (guestdbg_enabled(vcpu) && per_event(vcpu)) {
21627291e21SDavid Hildenbrand 		kvm_s390_handle_per_event(vcpu);
21727291e21SDavid Hildenbrand 		/* the interrupt might have been filtered out completely */
21827291e21SDavid Hildenbrand 		if (vcpu->arch.sie_block->iprcc == 0)
21927291e21SDavid Hildenbrand 			return 0;
22027291e21SDavid Hildenbrand 	}
22127291e21SDavid Hildenbrand 
222e325fe69SMichael Mueller 	trace_kvm_s390_intercept_prog(vcpu, vcpu->arch.sie_block->iprcc);
223684135e0SThomas Huth 	if (vcpu->arch.sie_block->iprcc == PGM_SPECIFICATION) {
224684135e0SThomas Huth 		rc = read_guest_lc(vcpu, __LC_PGM_NEW_PSW, &psw, sizeof(psw_t));
225684135e0SThomas Huth 		if (rc)
226684135e0SThomas Huth 			return rc;
227684135e0SThomas Huth 		/* Avoid endless loops of specification exceptions */
228684135e0SThomas Huth 		if (!is_valid_psw(&psw))
229684135e0SThomas Huth 			return -EOPNOTSUPP;
230684135e0SThomas Huth 	}
231e325fe69SMichael Mueller 	rc = handle_itdb(vcpu);
2320040e7d2SHeiko Carstens 	if (rc)
2330040e7d2SHeiko Carstens 		return rc;
234439716a5SDavid Hildenbrand 
235e325fe69SMichael Mueller 	__extract_prog_irq(vcpu, &pgm_info);
236439716a5SDavid Hildenbrand 	return kvm_s390_inject_prog_irq(vcpu, &pgm_info);
237ba5c1e9bSCarsten Otte }
238ba5c1e9bSCarsten Otte 
239ba5c1e9bSCarsten Otte static int handle_instruction_and_prog(struct kvm_vcpu *vcpu)
240ba5c1e9bSCarsten Otte {
241ba5c1e9bSCarsten Otte 	int rc, rc2;
242ba5c1e9bSCarsten Otte 
243ba5c1e9bSCarsten Otte 	vcpu->stat.exit_instr_and_program++;
244ba5c1e9bSCarsten Otte 	rc = handle_instruction(vcpu);
245ba5c1e9bSCarsten Otte 	rc2 = handle_prog(vcpu);
246ba5c1e9bSCarsten Otte 
247b8e660b8SHeiko Carstens 	if (rc == -EOPNOTSUPP)
248ba5c1e9bSCarsten Otte 		vcpu->arch.sie_block->icptcode = 0x04;
249ba5c1e9bSCarsten Otte 	if (rc)
250ba5c1e9bSCarsten Otte 		return rc;
251ba5c1e9bSCarsten Otte 	return rc2;
252ba5c1e9bSCarsten Otte }
253ba5c1e9bSCarsten Otte 
2549a558ee3SThomas Huth /**
255f14d82e0SThomas Huth  * handle_external_interrupt - used for external interruption interceptions
256f14d82e0SThomas Huth  *
257f14d82e0SThomas Huth  * This interception only occurs if the CPUSTAT_EXT_INT bit was set, or if
258f14d82e0SThomas Huth  * the new PSW does not have external interrupts disabled. In the first case,
259f14d82e0SThomas Huth  * we've got to deliver the interrupt manually, and in the second case, we
260f14d82e0SThomas Huth  * drop to userspace to handle the situation there.
261f14d82e0SThomas Huth  */
262f14d82e0SThomas Huth static int handle_external_interrupt(struct kvm_vcpu *vcpu)
263f14d82e0SThomas Huth {
264f14d82e0SThomas Huth 	u16 eic = vcpu->arch.sie_block->eic;
265383d0b05SJens Freimann 	struct kvm_s390_irq irq;
266f14d82e0SThomas Huth 	psw_t newpsw;
267f14d82e0SThomas Huth 	int rc;
268f14d82e0SThomas Huth 
269f14d82e0SThomas Huth 	vcpu->stat.exit_external_interrupt++;
270f14d82e0SThomas Huth 
271f14d82e0SThomas Huth 	rc = read_guest_lc(vcpu, __LC_EXT_NEW_PSW, &newpsw, sizeof(psw_t));
272f14d82e0SThomas Huth 	if (rc)
273f14d82e0SThomas Huth 		return rc;
274f14d82e0SThomas Huth 	/* We can not handle clock comparator or timer interrupt with bad PSW */
275f14d82e0SThomas Huth 	if ((eic == EXT_IRQ_CLK_COMP || eic == EXT_IRQ_CPU_TIMER) &&
276f14d82e0SThomas Huth 	    (newpsw.mask & PSW_MASK_EXT))
277f14d82e0SThomas Huth 		return -EOPNOTSUPP;
278f14d82e0SThomas Huth 
279f14d82e0SThomas Huth 	switch (eic) {
280f14d82e0SThomas Huth 	case EXT_IRQ_CLK_COMP:
281f14d82e0SThomas Huth 		irq.type = KVM_S390_INT_CLOCK_COMP;
282f14d82e0SThomas Huth 		break;
283f14d82e0SThomas Huth 	case EXT_IRQ_CPU_TIMER:
284f14d82e0SThomas Huth 		irq.type = KVM_S390_INT_CPU_TIMER;
285f14d82e0SThomas Huth 		break;
286f14d82e0SThomas Huth 	case EXT_IRQ_EXTERNAL_CALL:
2874953919fSDavid Hildenbrand 		if (kvm_s390_si_ext_call_pending(vcpu))
2884953919fSDavid Hildenbrand 			return 0;
289f14d82e0SThomas Huth 		irq.type = KVM_S390_INT_EXTERNAL_CALL;
290383d0b05SJens Freimann 		irq.u.extcall.code = vcpu->arch.sie_block->extcpuaddr;
291f14d82e0SThomas Huth 		break;
292f14d82e0SThomas Huth 	default:
293f14d82e0SThomas Huth 		return -EOPNOTSUPP;
294f14d82e0SThomas Huth 	}
295f14d82e0SThomas Huth 
296f14d82e0SThomas Huth 	return kvm_s390_inject_vcpu(vcpu, &irq);
297f14d82e0SThomas Huth }
298f14d82e0SThomas Huth 
299f14d82e0SThomas Huth /**
3009a558ee3SThomas Huth  * Handle MOVE PAGE partial execution interception.
3019a558ee3SThomas Huth  *
3029a558ee3SThomas Huth  * This interception can only happen for guests with DAT disabled and
3039a558ee3SThomas Huth  * addresses that are currently not mapped in the host. Thus we try to
3049a558ee3SThomas Huth  * set up the mappings for the corresponding user pages here (or throw
3059a558ee3SThomas Huth  * addressing exceptions in case of illegal guest addresses).
3069a558ee3SThomas Huth  */
3079a558ee3SThomas Huth static int handle_mvpg_pei(struct kvm_vcpu *vcpu)
3089a558ee3SThomas Huth {
309f22166dcSThomas Huth 	unsigned long srcaddr, dstaddr;
3109a558ee3SThomas Huth 	int reg1, reg2, rc;
3119a558ee3SThomas Huth 
3129a558ee3SThomas Huth 	kvm_s390_get_regs_rre(vcpu, &reg1, &reg2);
3139a558ee3SThomas Huth 
3149a558ee3SThomas Huth 	/* Make sure that the source is paged-in */
315f22166dcSThomas Huth 	srcaddr = kvm_s390_real_to_abs(vcpu, vcpu->run->s.regs.gprs[reg2]);
316f22166dcSThomas Huth 	if (kvm_is_error_gpa(vcpu->kvm, srcaddr))
3179a558ee3SThomas Huth 		return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
318f22166dcSThomas Huth 	rc = kvm_arch_fault_in_page(vcpu, srcaddr, 0);
319f22166dcSThomas Huth 	if (rc != 0)
3209a558ee3SThomas Huth 		return rc;
3219a558ee3SThomas Huth 
3229a558ee3SThomas Huth 	/* Make sure that the destination is paged-in */
323f22166dcSThomas Huth 	dstaddr = kvm_s390_real_to_abs(vcpu, vcpu->run->s.regs.gprs[reg1]);
324f22166dcSThomas Huth 	if (kvm_is_error_gpa(vcpu->kvm, dstaddr))
3259a558ee3SThomas Huth 		return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
326f22166dcSThomas Huth 	rc = kvm_arch_fault_in_page(vcpu, dstaddr, 1);
327f22166dcSThomas Huth 	if (rc != 0)
3289a558ee3SThomas Huth 		return rc;
3299a558ee3SThomas Huth 
33004b41acdSThomas Huth 	kvm_s390_rewind_psw(vcpu, 4);
3319a558ee3SThomas Huth 
3329a558ee3SThomas Huth 	return 0;
3339a558ee3SThomas Huth }
3349a558ee3SThomas Huth 
3359a558ee3SThomas Huth static int handle_partial_execution(struct kvm_vcpu *vcpu)
3369a558ee3SThomas Huth {
3379a558ee3SThomas Huth 	if (vcpu->arch.sie_block->ipa == 0xb254)	/* MVPG */
3389a558ee3SThomas Huth 		return handle_mvpg_pei(vcpu);
3394953919fSDavid Hildenbrand 	if (vcpu->arch.sie_block->ipa >> 8 == 0xae)	/* SIGP */
3404953919fSDavid Hildenbrand 		return kvm_s390_handle_sigp_pei(vcpu);
3419a558ee3SThomas Huth 
3429a558ee3SThomas Huth 	return -EOPNOTSUPP;
3439a558ee3SThomas Huth }
3449a558ee3SThomas Huth 
345062d5e9bSChristian Borntraeger static const intercept_handler_t intercept_funcs[] = {
3468f2abe6aSChristian Borntraeger 	[0x00 >> 2] = handle_noop,
347ba5c1e9bSCarsten Otte 	[0x04 >> 2] = handle_instruction,
348ba5c1e9bSCarsten Otte 	[0x08 >> 2] = handle_prog,
349ba5c1e9bSCarsten Otte 	[0x0C >> 2] = handle_instruction_and_prog,
3508f2abe6aSChristian Borntraeger 	[0x10 >> 2] = handle_noop,
351f14d82e0SThomas Huth 	[0x14 >> 2] = handle_external_interrupt,
352fa6b7fe9SCornelia Huck 	[0x18 >> 2] = handle_noop,
353ba5c1e9bSCarsten Otte 	[0x1C >> 2] = kvm_s390_handle_wait,
3548f2abe6aSChristian Borntraeger 	[0x20 >> 2] = handle_validity,
3558f2abe6aSChristian Borntraeger 	[0x28 >> 2] = handle_stop,
3569a558ee3SThomas Huth 	[0x38 >> 2] = handle_partial_execution,
3578f2abe6aSChristian Borntraeger };
3588f2abe6aSChristian Borntraeger 
3598f2abe6aSChristian Borntraeger int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
3608f2abe6aSChristian Borntraeger {
3618f2abe6aSChristian Borntraeger 	intercept_handler_t func;
3628f2abe6aSChristian Borntraeger 	u8 code = vcpu->arch.sie_block->icptcode;
3638f2abe6aSChristian Borntraeger 
364062d5e9bSChristian Borntraeger 	if (code & 3 || (code >> 2) >= ARRAY_SIZE(intercept_funcs))
365b8e660b8SHeiko Carstens 		return -EOPNOTSUPP;
3668f2abe6aSChristian Borntraeger 	func = intercept_funcs[code >> 2];
3678f2abe6aSChristian Borntraeger 	if (func)
3688f2abe6aSChristian Borntraeger 		return func(vcpu);
369b8e660b8SHeiko Carstens 	return -EOPNOTSUPP;
3708f2abe6aSChristian Borntraeger }
371