xref: /linux/arch/s390/kvm/intercept.c (revision 403c8648cb191ef88555bfa72deaa969c0367f41)
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 {
716cddd432SDavid Hildenbrand 	struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
729ace903dSChristian Ehrhardt 	int rc = 0;
736cddd432SDavid Hildenbrand 	uint8_t flags, stop_pending;
745288fbf0SChristian Borntraeger 
758f2abe6aSChristian Borntraeger 	vcpu->stat.exit_stop_request++;
76ade38c31SCornelia Huck 
779a022067SDavid Hildenbrand 	/* delay the stop if any non-stop irq is pending */
789a022067SDavid Hildenbrand 	if (kvm_s390_vcpu_has_irq(vcpu, 1))
799a022067SDavid Hildenbrand 		return 0;
809a022067SDavid Hildenbrand 
816cddd432SDavid Hildenbrand 	/* avoid races with the injection/SIGP STOP code */
826cddd432SDavid Hildenbrand 	spin_lock(&li->lock);
836cddd432SDavid Hildenbrand 	flags = li->irq.stop.flags;
846cddd432SDavid Hildenbrand 	stop_pending = kvm_s390_is_stop_irq_pending(vcpu);
856cddd432SDavid Hildenbrand 	spin_unlock(&li->lock);
869ace903dSChristian Ehrhardt 
876cddd432SDavid Hildenbrand 	trace_kvm_s390_stop_request(stop_pending, flags);
886cddd432SDavid Hildenbrand 	if (!stop_pending)
8932f5ff63SDavid Hildenbrand 		return 0;
9032f5ff63SDavid Hildenbrand 
916cddd432SDavid Hildenbrand 	if (flags & KVM_S390_STOP_FLAG_STORE_STATUS) {
929e0d5473SJens Freimann 		rc = kvm_s390_vcpu_store_status(vcpu,
939e0d5473SJens Freimann 						KVM_S390_STORE_STATUS_NOADDR);
9432f5ff63SDavid Hildenbrand 		if (rc)
955288fbf0SChristian Borntraeger 			return rc;
968f2abe6aSChristian Borntraeger 	}
978f2abe6aSChristian Borntraeger 
986352e4d2SDavid Hildenbrand 	if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm))
9932f5ff63SDavid Hildenbrand 		kvm_s390_vcpu_stop(vcpu);
10032f5ff63SDavid Hildenbrand 	return -EOPNOTSUPP;
10132f5ff63SDavid Hildenbrand }
10232f5ff63SDavid Hildenbrand 
1038f2abe6aSChristian Borntraeger static int handle_validity(struct kvm_vcpu *vcpu)
1048f2abe6aSChristian Borntraeger {
1058f2abe6aSChristian Borntraeger 	int viwhy = vcpu->arch.sie_block->ipb >> 16;
1063edbcff9SCarsten Otte 
1078f2abe6aSChristian Borntraeger 	vcpu->stat.exit_validity++;
1085786fffaSCornelia Huck 	trace_kvm_s390_intercept_validity(vcpu, viwhy);
1092c70fe44SChristian Borntraeger 	WARN_ONCE(true, "kvm: unhandled validity intercept 0x%x\n", viwhy);
1102c70fe44SChristian Borntraeger 	return -EOPNOTSUPP;
1118f2abe6aSChristian Borntraeger }
1128f2abe6aSChristian Borntraeger 
113ba5c1e9bSCarsten Otte static int handle_instruction(struct kvm_vcpu *vcpu)
114ba5c1e9bSCarsten Otte {
115ba5c1e9bSCarsten Otte 	intercept_handler_t handler;
116ba5c1e9bSCarsten Otte 
117ba5c1e9bSCarsten Otte 	vcpu->stat.exit_instruction++;
1185786fffaSCornelia Huck 	trace_kvm_s390_intercept_instruction(vcpu,
1195786fffaSCornelia Huck 					     vcpu->arch.sie_block->ipa,
1205786fffaSCornelia Huck 					     vcpu->arch.sie_block->ipb);
121ba5c1e9bSCarsten Otte 	handler = instruction_handlers[vcpu->arch.sie_block->ipa >> 8];
122ba5c1e9bSCarsten Otte 	if (handler)
123ba5c1e9bSCarsten Otte 		return handler(vcpu);
124b8e660b8SHeiko Carstens 	return -EOPNOTSUPP;
125ba5c1e9bSCarsten Otte }
126ba5c1e9bSCarsten Otte 
127439716a5SDavid Hildenbrand static void __extract_prog_irq(struct kvm_vcpu *vcpu,
128439716a5SDavid Hildenbrand 			       struct kvm_s390_pgm_info *pgm_info)
129439716a5SDavid Hildenbrand {
130439716a5SDavid Hildenbrand 	memset(pgm_info, 0, sizeof(struct kvm_s390_pgm_info));
131439716a5SDavid Hildenbrand 	pgm_info->code = vcpu->arch.sie_block->iprcc;
132439716a5SDavid Hildenbrand 
133439716a5SDavid Hildenbrand 	switch (vcpu->arch.sie_block->iprcc & ~PGM_PER) {
134439716a5SDavid Hildenbrand 	case PGM_AFX_TRANSLATION:
135439716a5SDavid Hildenbrand 	case PGM_ASX_TRANSLATION:
136439716a5SDavid Hildenbrand 	case PGM_EX_TRANSLATION:
137439716a5SDavid Hildenbrand 	case PGM_LFX_TRANSLATION:
138439716a5SDavid Hildenbrand 	case PGM_LSTE_SEQUENCE:
139439716a5SDavid Hildenbrand 	case PGM_LSX_TRANSLATION:
140439716a5SDavid Hildenbrand 	case PGM_LX_TRANSLATION:
141439716a5SDavid Hildenbrand 	case PGM_PRIMARY_AUTHORITY:
142439716a5SDavid Hildenbrand 	case PGM_SECONDARY_AUTHORITY:
143439716a5SDavid Hildenbrand 	case PGM_SPACE_SWITCH:
144439716a5SDavid Hildenbrand 		pgm_info->trans_exc_code = vcpu->arch.sie_block->tecmc;
145439716a5SDavid Hildenbrand 		break;
146439716a5SDavid Hildenbrand 	case PGM_ALEN_TRANSLATION:
147439716a5SDavid Hildenbrand 	case PGM_ALE_SEQUENCE:
148439716a5SDavid Hildenbrand 	case PGM_ASTE_INSTANCE:
149439716a5SDavid Hildenbrand 	case PGM_ASTE_SEQUENCE:
150439716a5SDavid Hildenbrand 	case PGM_ASTE_VALIDITY:
151439716a5SDavid Hildenbrand 	case PGM_EXTENDED_AUTHORITY:
152439716a5SDavid Hildenbrand 		pgm_info->exc_access_id = vcpu->arch.sie_block->eai;
153439716a5SDavid Hildenbrand 		break;
154439716a5SDavid Hildenbrand 	case PGM_ASCE_TYPE:
155439716a5SDavid Hildenbrand 	case PGM_PAGE_TRANSLATION:
156439716a5SDavid Hildenbrand 	case PGM_REGION_FIRST_TRANS:
157439716a5SDavid Hildenbrand 	case PGM_REGION_SECOND_TRANS:
158439716a5SDavid Hildenbrand 	case PGM_REGION_THIRD_TRANS:
159439716a5SDavid Hildenbrand 	case PGM_SEGMENT_TRANSLATION:
160439716a5SDavid Hildenbrand 		pgm_info->trans_exc_code = vcpu->arch.sie_block->tecmc;
161439716a5SDavid Hildenbrand 		pgm_info->exc_access_id  = vcpu->arch.sie_block->eai;
162439716a5SDavid Hildenbrand 		pgm_info->op_access_id  = vcpu->arch.sie_block->oai;
163439716a5SDavid Hildenbrand 		break;
164439716a5SDavid Hildenbrand 	case PGM_MONITOR:
165439716a5SDavid Hildenbrand 		pgm_info->mon_class_nr = vcpu->arch.sie_block->mcn;
166439716a5SDavid Hildenbrand 		pgm_info->mon_code = vcpu->arch.sie_block->tecmc;
167439716a5SDavid Hildenbrand 		break;
168*403c8648SEric Farman 	case PGM_VECTOR_PROCESSING:
169439716a5SDavid Hildenbrand 	case PGM_DATA:
170439716a5SDavid Hildenbrand 		pgm_info->data_exc_code = vcpu->arch.sie_block->dxc;
171439716a5SDavid Hildenbrand 		break;
172439716a5SDavid Hildenbrand 	case PGM_PROTECTION:
173439716a5SDavid Hildenbrand 		pgm_info->trans_exc_code = vcpu->arch.sie_block->tecmc;
174439716a5SDavid Hildenbrand 		pgm_info->exc_access_id  = vcpu->arch.sie_block->eai;
175439716a5SDavid Hildenbrand 		break;
176439716a5SDavid Hildenbrand 	default:
177439716a5SDavid Hildenbrand 		break;
178439716a5SDavid Hildenbrand 	}
179439716a5SDavid Hildenbrand 
180439716a5SDavid Hildenbrand 	if (vcpu->arch.sie_block->iprcc & PGM_PER) {
181439716a5SDavid Hildenbrand 		pgm_info->per_code = vcpu->arch.sie_block->perc;
182439716a5SDavid Hildenbrand 		pgm_info->per_atmid = vcpu->arch.sie_block->peratmid;
183439716a5SDavid Hildenbrand 		pgm_info->per_address = vcpu->arch.sie_block->peraddr;
184439716a5SDavid Hildenbrand 		pgm_info->per_access_id = vcpu->arch.sie_block->peraid;
185439716a5SDavid Hildenbrand 	}
186439716a5SDavid Hildenbrand }
187439716a5SDavid Hildenbrand 
188e325fe69SMichael Mueller /*
189e325fe69SMichael Mueller  * restore ITDB to program-interruption TDB in guest lowcore
190e325fe69SMichael Mueller  * and set TX abort indication if required
191e325fe69SMichael Mueller */
192e325fe69SMichael Mueller static int handle_itdb(struct kvm_vcpu *vcpu)
193e325fe69SMichael Mueller {
194e325fe69SMichael Mueller 	struct kvm_s390_itdb *itdb;
195e325fe69SMichael Mueller 	int rc;
196e325fe69SMichael Mueller 
197e325fe69SMichael Mueller 	if (!IS_TE_ENABLED(vcpu) || !IS_ITDB_VALID(vcpu))
198e325fe69SMichael Mueller 		return 0;
199e325fe69SMichael Mueller 	if (current->thread.per_flags & PER_FLAG_NO_TE)
200e325fe69SMichael Mueller 		return 0;
201e325fe69SMichael Mueller 	itdb = (struct kvm_s390_itdb *)vcpu->arch.sie_block->itdba;
202e325fe69SMichael Mueller 	rc = write_guest_lc(vcpu, __LC_PGM_TDB, itdb, sizeof(*itdb));
203e325fe69SMichael Mueller 	if (rc)
204e325fe69SMichael Mueller 		return rc;
205e325fe69SMichael Mueller 	memset(itdb, 0, sizeof(*itdb));
206e325fe69SMichael Mueller 
207e325fe69SMichael Mueller 	return 0;
208e325fe69SMichael Mueller }
209e325fe69SMichael Mueller 
21027291e21SDavid Hildenbrand #define per_event(vcpu) (vcpu->arch.sie_block->iprcc & PGM_PER)
21127291e21SDavid Hildenbrand 
212ba5c1e9bSCarsten Otte static int handle_prog(struct kvm_vcpu *vcpu)
213ba5c1e9bSCarsten Otte {
214439716a5SDavid Hildenbrand 	struct kvm_s390_pgm_info pgm_info;
215684135e0SThomas Huth 	psw_t psw;
2160040e7d2SHeiko Carstens 	int rc;
2170040e7d2SHeiko Carstens 
218ba5c1e9bSCarsten Otte 	vcpu->stat.exit_program_interruption++;
2197feb6bb8SMichael Mueller 
22027291e21SDavid Hildenbrand 	if (guestdbg_enabled(vcpu) && per_event(vcpu)) {
22127291e21SDavid Hildenbrand 		kvm_s390_handle_per_event(vcpu);
22227291e21SDavid Hildenbrand 		/* the interrupt might have been filtered out completely */
22327291e21SDavid Hildenbrand 		if (vcpu->arch.sie_block->iprcc == 0)
22427291e21SDavid Hildenbrand 			return 0;
22527291e21SDavid Hildenbrand 	}
22627291e21SDavid Hildenbrand 
227e325fe69SMichael Mueller 	trace_kvm_s390_intercept_prog(vcpu, vcpu->arch.sie_block->iprcc);
228684135e0SThomas Huth 	if (vcpu->arch.sie_block->iprcc == PGM_SPECIFICATION) {
229684135e0SThomas Huth 		rc = read_guest_lc(vcpu, __LC_PGM_NEW_PSW, &psw, sizeof(psw_t));
230684135e0SThomas Huth 		if (rc)
231684135e0SThomas Huth 			return rc;
232684135e0SThomas Huth 		/* Avoid endless loops of specification exceptions */
233684135e0SThomas Huth 		if (!is_valid_psw(&psw))
234684135e0SThomas Huth 			return -EOPNOTSUPP;
235684135e0SThomas Huth 	}
236e325fe69SMichael Mueller 	rc = handle_itdb(vcpu);
2370040e7d2SHeiko Carstens 	if (rc)
2380040e7d2SHeiko Carstens 		return rc;
239439716a5SDavid Hildenbrand 
240e325fe69SMichael Mueller 	__extract_prog_irq(vcpu, &pgm_info);
241439716a5SDavid Hildenbrand 	return kvm_s390_inject_prog_irq(vcpu, &pgm_info);
242ba5c1e9bSCarsten Otte }
243ba5c1e9bSCarsten Otte 
244ba5c1e9bSCarsten Otte static int handle_instruction_and_prog(struct kvm_vcpu *vcpu)
245ba5c1e9bSCarsten Otte {
246ba5c1e9bSCarsten Otte 	int rc, rc2;
247ba5c1e9bSCarsten Otte 
248ba5c1e9bSCarsten Otte 	vcpu->stat.exit_instr_and_program++;
249ba5c1e9bSCarsten Otte 	rc = handle_instruction(vcpu);
250ba5c1e9bSCarsten Otte 	rc2 = handle_prog(vcpu);
251ba5c1e9bSCarsten Otte 
252b8e660b8SHeiko Carstens 	if (rc == -EOPNOTSUPP)
253ba5c1e9bSCarsten Otte 		vcpu->arch.sie_block->icptcode = 0x04;
254ba5c1e9bSCarsten Otte 	if (rc)
255ba5c1e9bSCarsten Otte 		return rc;
256ba5c1e9bSCarsten Otte 	return rc2;
257ba5c1e9bSCarsten Otte }
258ba5c1e9bSCarsten Otte 
2599a558ee3SThomas Huth /**
260f14d82e0SThomas Huth  * handle_external_interrupt - used for external interruption interceptions
261f14d82e0SThomas Huth  *
262f14d82e0SThomas Huth  * This interception only occurs if the CPUSTAT_EXT_INT bit was set, or if
263f14d82e0SThomas Huth  * the new PSW does not have external interrupts disabled. In the first case,
264f14d82e0SThomas Huth  * we've got to deliver the interrupt manually, and in the second case, we
265f14d82e0SThomas Huth  * drop to userspace to handle the situation there.
266f14d82e0SThomas Huth  */
267f14d82e0SThomas Huth static int handle_external_interrupt(struct kvm_vcpu *vcpu)
268f14d82e0SThomas Huth {
269f14d82e0SThomas Huth 	u16 eic = vcpu->arch.sie_block->eic;
270383d0b05SJens Freimann 	struct kvm_s390_irq irq;
271f14d82e0SThomas Huth 	psw_t newpsw;
272f14d82e0SThomas Huth 	int rc;
273f14d82e0SThomas Huth 
274f14d82e0SThomas Huth 	vcpu->stat.exit_external_interrupt++;
275f14d82e0SThomas Huth 
276f14d82e0SThomas Huth 	rc = read_guest_lc(vcpu, __LC_EXT_NEW_PSW, &newpsw, sizeof(psw_t));
277f14d82e0SThomas Huth 	if (rc)
278f14d82e0SThomas Huth 		return rc;
279f14d82e0SThomas Huth 	/* We can not handle clock comparator or timer interrupt with bad PSW */
280f14d82e0SThomas Huth 	if ((eic == EXT_IRQ_CLK_COMP || eic == EXT_IRQ_CPU_TIMER) &&
281f14d82e0SThomas Huth 	    (newpsw.mask & PSW_MASK_EXT))
282f14d82e0SThomas Huth 		return -EOPNOTSUPP;
283f14d82e0SThomas Huth 
284f14d82e0SThomas Huth 	switch (eic) {
285f14d82e0SThomas Huth 	case EXT_IRQ_CLK_COMP:
286f14d82e0SThomas Huth 		irq.type = KVM_S390_INT_CLOCK_COMP;
287f14d82e0SThomas Huth 		break;
288f14d82e0SThomas Huth 	case EXT_IRQ_CPU_TIMER:
289f14d82e0SThomas Huth 		irq.type = KVM_S390_INT_CPU_TIMER;
290f14d82e0SThomas Huth 		break;
291f14d82e0SThomas Huth 	case EXT_IRQ_EXTERNAL_CALL:
292f14d82e0SThomas Huth 		irq.type = KVM_S390_INT_EXTERNAL_CALL;
293383d0b05SJens Freimann 		irq.u.extcall.code = vcpu->arch.sie_block->extcpuaddr;
294ea5f4969SDavid Hildenbrand 		rc = kvm_s390_inject_vcpu(vcpu, &irq);
295ea5f4969SDavid Hildenbrand 		/* ignore if another external call is already pending */
296ea5f4969SDavid Hildenbrand 		if (rc == -EBUSY)
297ea5f4969SDavid Hildenbrand 			return 0;
298ea5f4969SDavid Hildenbrand 		return rc;
299f14d82e0SThomas Huth 	default:
300f14d82e0SThomas Huth 		return -EOPNOTSUPP;
301f14d82e0SThomas Huth 	}
302f14d82e0SThomas Huth 
303f14d82e0SThomas Huth 	return kvm_s390_inject_vcpu(vcpu, &irq);
304f14d82e0SThomas Huth }
305f14d82e0SThomas Huth 
306f14d82e0SThomas Huth /**
3079a558ee3SThomas Huth  * Handle MOVE PAGE partial execution interception.
3089a558ee3SThomas Huth  *
3099a558ee3SThomas Huth  * This interception can only happen for guests with DAT disabled and
3109a558ee3SThomas Huth  * addresses that are currently not mapped in the host. Thus we try to
3119a558ee3SThomas Huth  * set up the mappings for the corresponding user pages here (or throw
3129a558ee3SThomas Huth  * addressing exceptions in case of illegal guest addresses).
3139a558ee3SThomas Huth  */
3149a558ee3SThomas Huth static int handle_mvpg_pei(struct kvm_vcpu *vcpu)
3159a558ee3SThomas Huth {
316f22166dcSThomas Huth 	unsigned long srcaddr, dstaddr;
3179a558ee3SThomas Huth 	int reg1, reg2, rc;
3189a558ee3SThomas Huth 
3199a558ee3SThomas Huth 	kvm_s390_get_regs_rre(vcpu, &reg1, &reg2);
3209a558ee3SThomas Huth 
3219a558ee3SThomas Huth 	/* Make sure that the source is paged-in */
3223cfad023SThomas Huth 	rc = guest_translate_address(vcpu, vcpu->run->s.regs.gprs[reg2],
3233cfad023SThomas Huth 				     &srcaddr, 0);
3243cfad023SThomas Huth 	if (rc)
3253cfad023SThomas Huth 		return kvm_s390_inject_prog_cond(vcpu, rc);
326f22166dcSThomas Huth 	rc = kvm_arch_fault_in_page(vcpu, srcaddr, 0);
327f22166dcSThomas Huth 	if (rc != 0)
3289a558ee3SThomas Huth 		return rc;
3299a558ee3SThomas Huth 
3309a558ee3SThomas Huth 	/* Make sure that the destination is paged-in */
3313cfad023SThomas Huth 	rc = guest_translate_address(vcpu, vcpu->run->s.regs.gprs[reg1],
3323cfad023SThomas Huth 				     &dstaddr, 1);
3333cfad023SThomas Huth 	if (rc)
3343cfad023SThomas Huth 		return kvm_s390_inject_prog_cond(vcpu, rc);
335f22166dcSThomas Huth 	rc = kvm_arch_fault_in_page(vcpu, dstaddr, 1);
336f22166dcSThomas Huth 	if (rc != 0)
3379a558ee3SThomas Huth 		return rc;
3389a558ee3SThomas Huth 
33904b41acdSThomas Huth 	kvm_s390_rewind_psw(vcpu, 4);
3409a558ee3SThomas Huth 
3419a558ee3SThomas Huth 	return 0;
3429a558ee3SThomas Huth }
3439a558ee3SThomas Huth 
3449a558ee3SThomas Huth static int handle_partial_execution(struct kvm_vcpu *vcpu)
3459a558ee3SThomas Huth {
3469a558ee3SThomas Huth 	if (vcpu->arch.sie_block->ipa == 0xb254)	/* MVPG */
3479a558ee3SThomas Huth 		return handle_mvpg_pei(vcpu);
3484953919fSDavid Hildenbrand 	if (vcpu->arch.sie_block->ipa >> 8 == 0xae)	/* SIGP */
3494953919fSDavid Hildenbrand 		return kvm_s390_handle_sigp_pei(vcpu);
3509a558ee3SThomas Huth 
3519a558ee3SThomas Huth 	return -EOPNOTSUPP;
3529a558ee3SThomas Huth }
3539a558ee3SThomas Huth 
354062d5e9bSChristian Borntraeger static const intercept_handler_t intercept_funcs[] = {
3558f2abe6aSChristian Borntraeger 	[0x00 >> 2] = handle_noop,
356ba5c1e9bSCarsten Otte 	[0x04 >> 2] = handle_instruction,
357ba5c1e9bSCarsten Otte 	[0x08 >> 2] = handle_prog,
358ba5c1e9bSCarsten Otte 	[0x0C >> 2] = handle_instruction_and_prog,
3598f2abe6aSChristian Borntraeger 	[0x10 >> 2] = handle_noop,
360f14d82e0SThomas Huth 	[0x14 >> 2] = handle_external_interrupt,
361fa6b7fe9SCornelia Huck 	[0x18 >> 2] = handle_noop,
362ba5c1e9bSCarsten Otte 	[0x1C >> 2] = kvm_s390_handle_wait,
3638f2abe6aSChristian Borntraeger 	[0x20 >> 2] = handle_validity,
3648f2abe6aSChristian Borntraeger 	[0x28 >> 2] = handle_stop,
3659a558ee3SThomas Huth 	[0x38 >> 2] = handle_partial_execution,
3668f2abe6aSChristian Borntraeger };
3678f2abe6aSChristian Borntraeger 
3688f2abe6aSChristian Borntraeger int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
3698f2abe6aSChristian Borntraeger {
3708f2abe6aSChristian Borntraeger 	intercept_handler_t func;
3718f2abe6aSChristian Borntraeger 	u8 code = vcpu->arch.sie_block->icptcode;
3728f2abe6aSChristian Borntraeger 
373062d5e9bSChristian Borntraeger 	if (code & 3 || (code >> 2) >= ARRAY_SIZE(intercept_funcs))
374b8e660b8SHeiko Carstens 		return -EOPNOTSUPP;
3758f2abe6aSChristian Borntraeger 	func = intercept_funcs[code >> 2];
3768f2abe6aSChristian Borntraeger 	if (func)
3778f2abe6aSChristian Borntraeger 		return func(vcpu);
378b8e660b8SHeiko Carstens 	return -EOPNOTSUPP;
3798f2abe6aSChristian Borntraeger }
380