···78557855:Architectures: s39078567856:Parameters: none7857785778587858-With this capability enabled, all illegal instructions 0x0000 (2 bytes) will78587858+With this capability enabled, the illegal instruction 0x0000 (2 bytes) will78597859be intercepted and forwarded to user space. User space can use this78607860mechanism e.g. to realize 2-byte software breakpoints. The kernel will78617861not inject an operating exception for these instructions, user space has···87278727When this capability is enabled, KVM resets the VCPU when setting87288728MP_STATE_INIT_RECEIVED through IOCTL. The original MP_STATE is preserved.8729872987308730-7.43 KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED87308730+7.44 KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED87318731-------------------------------------------8732873287338733:Architectures: arm64···87498749When this capability is enabled, KVM may exit to userspace for SEAs taken to87508750EL2 resulting from a guest access. See ``KVM_EXIT_ARM_SEA`` for more87518751information.87528752+87538753+7.46 KVM_CAP_S390_USER_OPEREXEC87548754+-------------------------------87558755+87568756+:Architectures: s39087578757+:Parameters: none87588758+87598759+When this capability is enabled KVM forwards all operation exceptions87608760+that it doesn't handle itself to user space. This also includes the87618761+0x0000 instructions managed by KVM_CAP_S390_USER_INSTR0. This is87628762+helpful if user space wants to emulate instructions which are not87638763+(yet) implemented in hardware.87648764+87658765+This capability can be enabled dynamically even if VCPUs were already87668766+created and are running.87528767875387688. Other capabilities.87548769======================
+4-4
arch/s390/include/asm/kvm_host.h
···146146 u64 instruction_diagnose_500;147147 u64 instruction_diagnose_other;148148 u64 pfault_sync;149149+ u64 signal_exits;149150};150151151152#define PGM_OPERATION 0x01···632631 struct mmu_notifier mmu_notifier;633632};634633635635-struct kvm_arch{636636- void *sca;637637- int use_esca;638638- rwlock_t sca_lock;634634+struct kvm_arch {635635+ struct esca_block *sca;639636 debug_info_t *dbf;640637 struct kvm_s390_float_interrupt float_int;641638 struct kvm_device *flic;···649650 int user_sigp;650651 int user_stsi;651652 int user_instr0;653653+ int user_operexec;652654 struct s390_io_adapter *adapters[MAX_S390_IO_ADAPTERS];653655 wait_queue_head_t ipte_wq;654656 int ipte_lock_count;
+1
arch/s390/include/asm/stacktrace.h
···6666 unsigned long sie_flags;6767 unsigned long sie_control_block_phys;6868 unsigned long sie_guest_asce;6969+ unsigned long sie_irq;6970 };7071 };7172 unsigned long gprs[10];
···189189 mvc __SF_SIE_FLAGS(8,%r15),__TI_flags(%r14) # copy thread flags190190 lmg %r0,%r13,0(%r4) # load guest gprs 0-13191191 mvi __TI_sie(%r14),1192192+ stosm __SF_SIE_IRQ(%r15),0x03 # enable interrupts192193 lctlg %c1,%c1,__SF_SIE_GUEST_ASCE(%r15) # load primary asce193194 lg %r14,__SF_SIE_CONTROL(%r15) # get control block pointer194195 oi __SIE_PROG0C+3(%r14),1 # we are going into SIE now···213212 lg %r14,__LC_CURRENT(%r14)214213 mvi __TI_sie(%r14),0215214SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL)215215+ stnsm __SF_SIE_IRQ(%r15),0xfc # disable interrupts216216 lg %r14,__SF_SIE_SAVEAREA(%r15) # load guest register save area217217 stmg %r0,%r13,0(%r14) # save guest gprs 0-13218218 xgr %r0,%r0 # clear guest registers to
+1
arch/s390/kvm/Kconfig
···2929 select HAVE_KVM_NO_POLL3030 select KVM_VFIO3131 select MMU_NOTIFIER3232+ select VIRT_XFER_TO_GUEST_WORK3233 help3334 Support hosting paravirtualized guest machines using the SIE3435 virtualization capability on the mainframe. This should work
+6-21
arch/s390/kvm/gaccess.c
···109109110110int ipte_lock_held(struct kvm *kvm)111111{112112- if (sclp.has_siif) {113113- int rc;112112+ if (sclp.has_siif)113113+ return kvm->arch.sca->ipte_control.kh != 0;114114115115- read_lock(&kvm->arch.sca_lock);116116- rc = kvm_s390_get_ipte_control(kvm)->kh != 0;117117- read_unlock(&kvm->arch.sca_lock);118118- return rc;119119- }120115 return kvm->arch.ipte_lock_count != 0;121116}122117···124129 if (kvm->arch.ipte_lock_count > 1)125130 goto out;126131retry:127127- read_lock(&kvm->arch.sca_lock);128128- ic = kvm_s390_get_ipte_control(kvm);132132+ ic = &kvm->arch.sca->ipte_control;129133 old = READ_ONCE(*ic);130134 do {131135 if (old.k) {132132- read_unlock(&kvm->arch.sca_lock);133136 cond_resched();134137 goto retry;135138 }136139 new = old;137140 new.k = 1;138141 } while (!try_cmpxchg(&ic->val, &old.val, new.val));139139- read_unlock(&kvm->arch.sca_lock);140142out:141143 mutex_unlock(&kvm->arch.ipte_mutex);142144}···146154 kvm->arch.ipte_lock_count--;147155 if (kvm->arch.ipte_lock_count)148156 goto out;149149- read_lock(&kvm->arch.sca_lock);150150- ic = kvm_s390_get_ipte_control(kvm);157157+ ic = &kvm->arch.sca->ipte_control;151158 old = READ_ONCE(*ic);152159 do {153160 new = old;154161 new.k = 0;155162 } while (!try_cmpxchg(&ic->val, &old.val, new.val));156156- read_unlock(&kvm->arch.sca_lock);157163 wake_up(&kvm->arch.ipte_wq);158164out:159165 mutex_unlock(&kvm->arch.ipte_mutex);···162172 union ipte_control old, new, *ic;163173164174retry:165165- read_lock(&kvm->arch.sca_lock);166166- ic = kvm_s390_get_ipte_control(kvm);175175+ ic = &kvm->arch.sca->ipte_control;167176 old = READ_ONCE(*ic);168177 do {169178 if (old.kg) {170170- read_unlock(&kvm->arch.sca_lock);171179 cond_resched();172180 goto retry;173181 }···173185 new.k = 1;174186 new.kh++;175187 } while (!try_cmpxchg(&ic->val, &old.val, new.val));176176- read_unlock(&kvm->arch.sca_lock);177188}178189179190static void ipte_unlock_siif(struct kvm *kvm)180191{181192 union ipte_control old, new, *ic;182193183183- read_lock(&kvm->arch.sca_lock);184184- ic = kvm_s390_get_ipte_control(kvm);194194+ ic = &kvm->arch.sca->ipte_control;185195 old = READ_ONCE(*ic);186196 do {187197 new = old;···187201 if (!new.kh)188202 new.k = 0;189203 } while (!try_cmpxchg(&ic->val, &old.val, new.val));190190- read_unlock(&kvm->arch.sca_lock);191204 if (!new.kh)192205 wake_up(&kvm->arch.ipte_wq);193206}
+3
arch/s390/kvm/intercept.c
···471471 if (vcpu->arch.sie_block->ipa == 0xb256)472472 return handle_sthyi(vcpu);473473474474+ if (vcpu->kvm->arch.user_operexec)475475+ return -EOPNOTSUPP;476476+474477 if (vcpu->arch.sie_block->ipa == 0 && vcpu->kvm->arch.user_instr0)475478 return -EOPNOTSUPP;476479 rc = read_guest_lc(vcpu, __LC_PGM_NEW_PSW, &newpsw, sizeof(psw_t));
+17-63
arch/s390/kvm/interrupt.c
···4545/* handle external calls via sigp interpretation facility */4646static int sca_ext_call_pending(struct kvm_vcpu *vcpu, int *src_id)4747{4848- int c, scn;4848+ struct esca_block *sca = vcpu->kvm->arch.sca;4949+ union esca_sigp_ctrl sigp_ctrl = sca->cpu[vcpu->vcpu_id].sigp_ctrl;49505051 if (!kvm_s390_test_cpuflags(vcpu, CPUSTAT_ECALL_PEND))5152 return 0;52535354 BUG_ON(!kvm_s390_use_sca_entries());5454- read_lock(&vcpu->kvm->arch.sca_lock);5555- if (vcpu->kvm->arch.use_esca) {5656- struct esca_block *sca = vcpu->kvm->arch.sca;5757- union esca_sigp_ctrl sigp_ctrl =5858- sca->cpu[vcpu->vcpu_id].sigp_ctrl;5959-6060- c = sigp_ctrl.c;6161- scn = sigp_ctrl.scn;6262- } else {6363- struct bsca_block *sca = vcpu->kvm->arch.sca;6464- union bsca_sigp_ctrl sigp_ctrl =6565- sca->cpu[vcpu->vcpu_id].sigp_ctrl;6666-6767- c = sigp_ctrl.c;6868- scn = sigp_ctrl.scn;6969- }7070- read_unlock(&vcpu->kvm->arch.sca_lock);71557256 if (src_id)7373- *src_id = scn;5757+ *src_id = sigp_ctrl.scn;74587575- return c;5959+ return sigp_ctrl.c;7660}77617862static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id)7963{6464+ struct esca_block *sca = vcpu->kvm->arch.sca;6565+ union esca_sigp_ctrl *sigp_ctrl = &sca->cpu[vcpu->vcpu_id].sigp_ctrl;6666+ union esca_sigp_ctrl old_val, new_val = {.scn = src_id, .c = 1};8067 int expect, rc;81688269 BUG_ON(!kvm_s390_use_sca_entries());8383- read_lock(&vcpu->kvm->arch.sca_lock);8484- if (vcpu->kvm->arch.use_esca) {8585- struct esca_block *sca = vcpu->kvm->arch.sca;8686- union esca_sigp_ctrl *sigp_ctrl =8787- &(sca->cpu[vcpu->vcpu_id].sigp_ctrl);8888- union esca_sigp_ctrl new_val = {0}, old_val;89709090- old_val = READ_ONCE(*sigp_ctrl);9191- new_val.scn = src_id;9292- new_val.c = 1;9393- old_val.c = 0;7171+ old_val = READ_ONCE(*sigp_ctrl);7272+ old_val.c = 0;94739595- expect = old_val.value;9696- rc = cmpxchg(&sigp_ctrl->value, old_val.value, new_val.value);9797- } else {9898- struct bsca_block *sca = vcpu->kvm->arch.sca;9999- union bsca_sigp_ctrl *sigp_ctrl =100100- &(sca->cpu[vcpu->vcpu_id].sigp_ctrl);101101- union bsca_sigp_ctrl new_val = {0}, old_val;102102-103103- old_val = READ_ONCE(*sigp_ctrl);104104- new_val.scn = src_id;105105- new_val.c = 1;106106- old_val.c = 0;107107-108108- expect = old_val.value;109109- rc = cmpxchg(&sigp_ctrl->value, old_val.value, new_val.value);110110- }111111- read_unlock(&vcpu->kvm->arch.sca_lock);7474+ expect = old_val.value;7575+ rc = cmpxchg(&sigp_ctrl->value, old_val.value, new_val.value);1127611377 if (rc != expect) {11478 /* another external call is pending */···8412085121static void sca_clear_ext_call(struct kvm_vcpu *vcpu)86122{123123+ struct esca_block *sca = vcpu->kvm->arch.sca;124124+ union esca_sigp_ctrl *sigp_ctrl = &sca->cpu[vcpu->vcpu_id].sigp_ctrl;125125+87126 if (!kvm_s390_use_sca_entries())88127 return;89128 kvm_s390_clear_cpuflags(vcpu, CPUSTAT_ECALL_PEND);9090- read_lock(&vcpu->kvm->arch.sca_lock);9191- if (vcpu->kvm->arch.use_esca) {9292- struct esca_block *sca = vcpu->kvm->arch.sca;9393- union esca_sigp_ctrl *sigp_ctrl =9494- &(sca->cpu[vcpu->vcpu_id].sigp_ctrl);951299696- WRITE_ONCE(sigp_ctrl->value, 0);9797- } else {9898- struct bsca_block *sca = vcpu->kvm->arch.sca;9999- union bsca_sigp_ctrl *sigp_ctrl =100100- &(sca->cpu[vcpu->vcpu_id].sigp_ctrl);101101-102102- WRITE_ONCE(sigp_ctrl->value, 0);103103- }104104- read_unlock(&vcpu->kvm->arch.sca_lock);130130+ WRITE_ONCE(sigp_ctrl->value, 0);105131}106132107133int psw_extint_disabled(struct kvm_vcpu *vcpu)···11781224{11791225 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;1180122611811181- if (!sclp.has_sigpif)12271227+ if (!kvm_s390_use_sca_entries())11821228 return test_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs);1183122911841230 return sca_ext_call_pending(vcpu, NULL);···15031549 if (kvm_get_vcpu_by_id(vcpu->kvm, src_id) == NULL)15041550 return -EINVAL;1505155115061506- if (sclp.has_sigpif && !kvm_s390_pv_cpu_get_handle(vcpu))15521552+ if (kvm_s390_use_sca_entries() && !kvm_s390_pv_cpu_get_handle(vcpu))15071553 return sca_inject_ext_call(vcpu, src_id);1508155415091555 if (test_and_set_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs))
+62-167
arch/s390/kvm/kvm-s390.c
···1414#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt15151616#include <linux/compiler.h>1717+#include <linux/entry-virt.h>1718#include <linux/export.h>1819#include <linux/err.h>1920#include <linux/fs.h>···186185 STATS_DESC_COUNTER(VCPU, instruction_diagnose_308),187186 STATS_DESC_COUNTER(VCPU, instruction_diagnose_500),188187 STATS_DESC_COUNTER(VCPU, instruction_diagnose_other),189189- STATS_DESC_COUNTER(VCPU, pfault_sync)188188+ STATS_DESC_COUNTER(VCPU, pfault_sync),189189+ STATS_DESC_COUNTER(VCPU, signal_exits)190190};191191192192const struct kvm_stats_header kvm_vcpu_stats_header = {···274272/* forward declarations */275273static void kvm_gmap_notifier(struct gmap *gmap, unsigned long start,276274 unsigned long end);277277-static int sca_switch_to_extended(struct kvm *kvm);278275279276static void kvm_clock_sync_scb(struct kvm_s390_sie_block *scb, u64 delta)280277{···608607 case KVM_CAP_SET_GUEST_DEBUG:609608 case KVM_CAP_S390_DIAG318:610609 case KVM_CAP_IRQFD_RESAMPLE:610610+ case KVM_CAP_S390_USER_OPEREXEC:611611 r = 1;612612 break;613613 case KVM_CAP_SET_GUEST_DEBUG2:···634632 case KVM_CAP_NR_VCPUS:635633 case KVM_CAP_MAX_VCPUS:636634 case KVM_CAP_MAX_VCPU_ID:637637- r = KVM_S390_BSCA_CPU_SLOTS;635635+ /*636636+ * Return the same value for KVM_CAP_MAX_VCPUS and637637+ * KVM_CAP_MAX_VCPU_ID to conform with the KVM API.638638+ */639639+ r = KVM_S390_ESCA_CPU_SLOTS;638640 if (!kvm_s390_use_sca_entries())639641 r = KVM_MAX_VCPUS;640640- else if (sclp.has_esca && sclp.has_64bscao)641641- r = KVM_S390_ESCA_CPU_SLOTS;642642 if (ext == KVM_CAP_NR_VCPUS)643643 r = min_t(unsigned int, num_online_cpus(), r);644644 break;···923919 mutex_unlock(&kvm->lock);924920 VM_EVENT(kvm, 3, "ENABLE: CAP_S390_CPU_TOPOLOGY %s",925921 r ? "(not available)" : "(success)");922922+ break;923923+ case KVM_CAP_S390_USER_OPEREXEC:924924+ VM_EVENT(kvm, 3, "%s", "ENABLE: CAP_S390_USER_OPEREXEC");925925+ kvm->arch.user_operexec = 1;926926+ icpt_operexc_on_all_vcpus(kvm);927927+ r = 0;926928 break;927929 default:928930 r = -EINVAL;···19411931 * Updates the Multiprocessor Topology-Change-Report bit to signal19421932 * the guest with a topology change.19431933 * This is only relevant if the topology facility is present.19441944- *19451945- * The SCA version, bsca or esca, doesn't matter as offset is the same.19461934 */19471935static void kvm_s390_update_topology_change_report(struct kvm *kvm, bool val)19481936{19491937 union sca_utility new, old;19501950- struct bsca_block *sca;19381938+ struct esca_block *sca;1951193919521952- read_lock(&kvm->arch.sca_lock);19531940 sca = kvm->arch.sca;19541941 old = READ_ONCE(sca->utility);19551942 do {19561943 new = old;19571944 new.mtcr = val;19581945 } while (!try_cmpxchg(&sca->utility.val, &old.val, new.val));19591959- read_unlock(&kvm->arch.sca_lock);19601946}1961194719621948static int kvm_s390_set_topo_change_indication(struct kvm *kvm,···19731967 if (!test_kvm_facility(kvm, 11))19741968 return -ENXIO;1975196919761976- read_lock(&kvm->arch.sca_lock);19771977- topo = ((struct bsca_block *)kvm->arch.sca)->utility.mtcr;19781978- read_unlock(&kvm->arch.sca_lock);19701970+ topo = kvm->arch.sca->utility.mtcr;1979197119801972 return put_user(topo, (u8 __user *)attr->addr);19811973}···26712667 if (kvm_s390_pv_is_protected(kvm))26722668 break;2673266926742674- /*26752675- * FMT 4 SIE needs esca. As we never switch back to bsca from26762676- * esca, we need no cleanup in the error cases below26772677- */26782678- r = sca_switch_to_extended(kvm);26792679- if (r)26802680- break;26812681-26822670 mmap_write_lock(kvm->mm);26832671 r = gmap_helper_disable_cow_sharing();26842672 mmap_write_unlock(kvm->mm);···3313331733143318static void sca_dispose(struct kvm *kvm)33153319{33163316- if (kvm->arch.use_esca)33173317- free_pages_exact(kvm->arch.sca, sizeof(struct esca_block));33183318- else33193319- free_page((unsigned long)(kvm->arch.sca));33203320+ free_pages_exact(kvm->arch.sca, sizeof(*kvm->arch.sca));33203321 kvm->arch.sca = NULL;33213322}33223323···3327333433283335int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)33293336{33303330- gfp_t alloc_flags = GFP_KERNEL_ACCOUNT;33313331- int i, rc;33373337+ gfp_t alloc_flags = GFP_KERNEL_ACCOUNT | __GFP_ZERO;33323338 char debug_name[16];33333333- static unsigned long sca_offset;33393339+ int i, rc;3334334033353341 rc = -EINVAL;33363342#ifdef CONFIG_KVM_S390_UCONTROL···3350335833513359 if (!sclp.has_64bscao)33523360 alloc_flags |= GFP_DMA;33533353- rwlock_init(&kvm->arch.sca_lock);33543354- /* start with basic SCA */33553355- kvm->arch.sca = (struct bsca_block *) get_zeroed_page(alloc_flags);33613361+ mutex_lock(&kvm_lock);33623362+33633363+ kvm->arch.sca = alloc_pages_exact(sizeof(*kvm->arch.sca), alloc_flags);33643364+ mutex_unlock(&kvm_lock);33563365 if (!kvm->arch.sca)33573366 goto out_err;33583358- mutex_lock(&kvm_lock);33593359- sca_offset += 16;33603360- if (sca_offset + sizeof(struct bsca_block) > PAGE_SIZE)33613361- sca_offset = 0;33623362- kvm->arch.sca = (struct bsca_block *)33633363- ((char *) kvm->arch.sca + sca_offset);33643364- mutex_unlock(&kvm_lock);3365336733663366- sprintf(debug_name, "kvm-%u", current->pid);33683368+ snprintf(debug_name, sizeof(debug_name), "kvm-%u", current->pid);3367336933683370 kvm->arch.dbf = debug_register(debug_name, 32, 1, 7 * sizeof(long));33693371 if (!kvm->arch.dbf)···3534354835353549static void sca_del_vcpu(struct kvm_vcpu *vcpu)35363550{35513551+ struct esca_block *sca = vcpu->kvm->arch.sca;35523552+35373553 if (!kvm_s390_use_sca_entries())35383554 return;35393539- read_lock(&vcpu->kvm->arch.sca_lock);35403540- if (vcpu->kvm->arch.use_esca) {35413541- struct esca_block *sca = vcpu->kvm->arch.sca;3542355535433543- clear_bit_inv(vcpu->vcpu_id, (unsigned long *) sca->mcn);35443544- sca->cpu[vcpu->vcpu_id].sda = 0;35453545- } else {35463546- struct bsca_block *sca = vcpu->kvm->arch.sca;35473547-35483548- clear_bit_inv(vcpu->vcpu_id, (unsigned long *) &sca->mcn);35493549- sca->cpu[vcpu->vcpu_id].sda = 0;35503550- }35513551- read_unlock(&vcpu->kvm->arch.sca_lock);35563556+ clear_bit_inv(vcpu->vcpu_id, (unsigned long *)sca->mcn);35573557+ sca->cpu[vcpu->vcpu_id].sda = 0;35523558}3553355935543560static void sca_add_vcpu(struct kvm_vcpu *vcpu)35553561{35563556- if (!kvm_s390_use_sca_entries()) {35573557- phys_addr_t sca_phys = virt_to_phys(vcpu->kvm->arch.sca);35623562+ struct esca_block *sca = vcpu->kvm->arch.sca;35633563+ phys_addr_t sca_phys = virt_to_phys(sca);3558356435593559- /* we still need the basic sca for the ipte control */35603560- vcpu->arch.sie_block->scaoh = sca_phys >> 32;35613561- vcpu->arch.sie_block->scaol = sca_phys;35653565+ /* we still need the sca header for the ipte control */35663566+ vcpu->arch.sie_block->scaoh = sca_phys >> 32;35673567+ vcpu->arch.sie_block->scaol = sca_phys & ESCA_SCAOL_MASK;35683568+ vcpu->arch.sie_block->ecb2 |= ECB2_ESCA;35693569+35703570+ if (!kvm_s390_use_sca_entries())35623571 return;35633563- }35643564- read_lock(&vcpu->kvm->arch.sca_lock);35653565- if (vcpu->kvm->arch.use_esca) {35663566- struct esca_block *sca = vcpu->kvm->arch.sca;35673567- phys_addr_t sca_phys = virt_to_phys(sca);3568357235693569- sca->cpu[vcpu->vcpu_id].sda = virt_to_phys(vcpu->arch.sie_block);35703570- vcpu->arch.sie_block->scaoh = sca_phys >> 32;35713571- vcpu->arch.sie_block->scaol = sca_phys & ESCA_SCAOL_MASK;35723572- vcpu->arch.sie_block->ecb2 |= ECB2_ESCA;35733573- set_bit_inv(vcpu->vcpu_id, (unsigned long *) sca->mcn);35743574- } else {35753575- struct bsca_block *sca = vcpu->kvm->arch.sca;35763576- phys_addr_t sca_phys = virt_to_phys(sca);35773577-35783578- sca->cpu[vcpu->vcpu_id].sda = virt_to_phys(vcpu->arch.sie_block);35793579- vcpu->arch.sie_block->scaoh = sca_phys >> 32;35803580- vcpu->arch.sie_block->scaol = sca_phys;35813581- set_bit_inv(vcpu->vcpu_id, (unsigned long *) &sca->mcn);35823582- }35833583- read_unlock(&vcpu->kvm->arch.sca_lock);35843584-}35853585-35863586-/* Basic SCA to Extended SCA data copy routines */35873587-static inline void sca_copy_entry(struct esca_entry *d, struct bsca_entry *s)35883588-{35893589- d->sda = s->sda;35903590- d->sigp_ctrl.c = s->sigp_ctrl.c;35913591- d->sigp_ctrl.scn = s->sigp_ctrl.scn;35923592-}35933593-35943594-static void sca_copy_b_to_e(struct esca_block *d, struct bsca_block *s)35953595-{35963596- int i;35973597-35983598- d->ipte_control = s->ipte_control;35993599- d->mcn[0] = s->mcn;36003600- for (i = 0; i < KVM_S390_BSCA_CPU_SLOTS; i++)36013601- sca_copy_entry(&d->cpu[i], &s->cpu[i]);36023602-}36033603-36043604-static int sca_switch_to_extended(struct kvm *kvm)36053605-{36063606- struct bsca_block *old_sca = kvm->arch.sca;36073607- struct esca_block *new_sca;36083608- struct kvm_vcpu *vcpu;36093609- unsigned long vcpu_idx;36103610- u32 scaol, scaoh;36113611- phys_addr_t new_sca_phys;36123612-36133613- if (kvm->arch.use_esca)36143614- return 0;36153615-36163616- new_sca = alloc_pages_exact(sizeof(*new_sca), GFP_KERNEL_ACCOUNT | __GFP_ZERO);36173617- if (!new_sca)36183618- return -ENOMEM;36193619-36203620- new_sca_phys = virt_to_phys(new_sca);36213621- scaoh = new_sca_phys >> 32;36223622- scaol = new_sca_phys & ESCA_SCAOL_MASK;36233623-36243624- kvm_s390_vcpu_block_all(kvm);36253625- write_lock(&kvm->arch.sca_lock);36263626-36273627- sca_copy_b_to_e(new_sca, old_sca);36283628-36293629- kvm_for_each_vcpu(vcpu_idx, vcpu, kvm) {36303630- vcpu->arch.sie_block->scaoh = scaoh;36313631- vcpu->arch.sie_block->scaol = scaol;36323632- vcpu->arch.sie_block->ecb2 |= ECB2_ESCA;36333633- }36343634- kvm->arch.sca = new_sca;36353635- kvm->arch.use_esca = 1;36363636-36373637- write_unlock(&kvm->arch.sca_lock);36383638- kvm_s390_vcpu_unblock_all(kvm);36393639-36403640- free_page((unsigned long)old_sca);36413641-36423642- VM_EVENT(kvm, 2, "Switched to ESCA (0x%p -> 0x%p)",36433643- old_sca, kvm->arch.sca);36443644- return 0;35733573+ set_bit_inv(vcpu->vcpu_id, (unsigned long *)sca->mcn);35743574+ sca->cpu[vcpu->vcpu_id].sda = virt_to_phys(vcpu->arch.sie_block);36453575}3646357636473577static int sca_can_add_vcpu(struct kvm *kvm, unsigned int id)36483578{36493649- int rc;35793579+ if (!kvm_s390_use_sca_entries())35803580+ return id < KVM_MAX_VCPUS;3650358136513651- if (!kvm_s390_use_sca_entries()) {36523652- if (id < KVM_MAX_VCPUS)36533653- return true;36543654- return false;36553655- }36563656- if (id < KVM_S390_BSCA_CPU_SLOTS)36573657- return true;36583658- if (!sclp.has_esca || !sclp.has_64bscao)36593659- return false;36603660-36613661- rc = kvm->arch.use_esca ? 0 : sca_switch_to_extended(kvm);36623662-36633663- return rc == 0 && id < KVM_S390_ESCA_CPU_SLOTS;35823582+ return id < KVM_S390_ESCA_CPU_SLOTS;36643583}3665358436663585/* needs disabled preemption to protect from TOD sync and vcpu_load/put */···38113920 vcpu->arch.sie_block->eca |= ECA_IB;38123921 if (sclp.has_siif)38133922 vcpu->arch.sie_block->eca |= ECA_SII;38143814- if (sclp.has_sigpif)39233923+ if (kvm_s390_use_sca_entries())38153924 vcpu->arch.sie_block->eca |= ECA_SIGPI;38163925 if (test_kvm_facility(vcpu->kvm, 129)) {38173926 vcpu->arch.sie_block->eca |= ECA_VX;···4258436742594368int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)42604369{42614261- int ret = 0;42624262-42634370 vcpu_load(vcpu);4264437142654372 vcpu->run->s.regs.fpc = fpu->fpc;···42684379 memcpy(vcpu->run->s.regs.fprs, &fpu->fprs, sizeof(fpu->fprs));4269438042704381 vcpu_put(vcpu);42714271- return ret;43824382+ return 0;42724383}4273438442744385int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)···46764787 vcpu->arch.sie_block->gg14 = vcpu->run->s.regs.gprs[14];46774788 vcpu->arch.sie_block->gg15 = vcpu->run->s.regs.gprs[15];4678478946794679- if (need_resched())46804680- schedule();46814681-46824790 if (!kvm_is_ucontrol(vcpu->kvm)) {46834791 rc = kvm_s390_deliver_pending_interrupts(vcpu);46844792 if (rc || guestdbg_exit_pending(vcpu))···49605074 * The guest_state_{enter,exit}_irqoff() functions inform lockdep and49615075 * tracing that entry to the guest will enable host IRQs, and exit from49625076 * the guest will disable host IRQs.49634963- *49644964- * We must not use lockdep/tracing/RCU in this critical section, so we49654965- * use the low-level arch_local_irq_*() helpers to enable/disable IRQs.49665077 */49674967- arch_local_irq_enable();49685078 ret = sie64a(scb, gprs, gasce);49694969- arch_local_irq_disable();4970507949715080 guest_state_exit_irqoff();49725081···49805099 */49815100 kvm_vcpu_srcu_read_lock(vcpu);4982510149834983- do {51025102+ while (true) {49845103 rc = vcpu_pre_run(vcpu);51045104+ kvm_vcpu_srcu_read_unlock(vcpu);49855105 if (rc || guestdbg_exit_pending(vcpu))49865106 break;4987510749884988- kvm_vcpu_srcu_read_unlock(vcpu);49895108 /*49905109 * As PF_VCPU will be used in fault handler, between49915110 * guest_timing_enter_irqoff and guest_timing_exit_irqoff···49975116 sizeof(sie_page->pv_grregs));49985117 }4999511851195119+xfer_to_guest_mode_check:50005120 local_irq_disable();51215121+ xfer_to_guest_mode_prepare();51225122+ if (xfer_to_guest_mode_work_pending()) {51235123+ local_irq_enable();51245124+ rc = kvm_xfer_to_guest_mode_handle_work(vcpu);51255125+ if (rc)51265126+ break;51275127+ goto xfer_to_guest_mode_check;51285128+ }51295129+50015130 guest_timing_enter_irqoff();50025131 __disable_cpu_timer_accounting(vcpu);50035132···50375146 kvm_vcpu_srcu_read_lock(vcpu);5038514750395148 rc = vcpu_post_run(vcpu, exit_reason);50405040- } while (!signal_pending(current) && !guestdbg_exit_pending(vcpu) && !rc);51495149+ if (rc || guestdbg_exit_pending(vcpu)) {51505150+ kvm_vcpu_srcu_read_unlock(vcpu);51515151+ break;51525152+ }51535153+ }5041515450425042- kvm_vcpu_srcu_read_unlock(vcpu);50435155 return rc;50445156}50455157···5258536452595365 if (signal_pending(current) && !rc) {52605366 kvm_run->exit_reason = KVM_EXIT_INTR;53675367+ vcpu->stat.signal_exits++;52615368 rc = -EINTR;52625369 }52635370
+1-8
arch/s390/kvm/kvm-s390.h
···570570int kvm_s390_handle_per_ifetch_icpt(struct kvm_vcpu *vcpu);571571int kvm_s390_handle_per_event(struct kvm_vcpu *vcpu);572572573573-/* support for Basic/Extended SCA handling */574574-static inline union ipte_control *kvm_s390_get_ipte_control(struct kvm *kvm)575575-{576576- struct bsca_block *sca = kvm->arch.sca; /* SCA version doesn't matter */577577-578578- return &sca->ipte_control;579579-}580573static inline int kvm_s390_use_sca_entries(void)581574{582575 /*···577584 * might use the entries. By not setting the entries and keeping them578585 * invalid, hardware will not access them but intercept.579586 */580580- return sclp.has_sigpif;587587+ return sclp.has_sigpif && sclp.has_esca;581588}582589void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu,583590 struct mcck_volatile_info *mcck_info);
+14-6
arch/s390/kvm/vsie.c
···782782 else if ((gpa & ~0x1fffUL) == kvm_s390_get_prefix(vcpu))783783 rc = set_validity_icpt(scb_s, 0x0011U);784784 else if ((gpa & PAGE_MASK) !=785785- ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK))785785+ ((gpa + offsetof(struct bsca_block, cpu[0]) - 1) & PAGE_MASK))786786 rc = set_validity_icpt(scb_s, 0x003bU);787787 if (!rc) {788788 rc = pin_guest_page(vcpu->kvm, gpa, &hpa);···11801180 current->thread.gmap_int_code = 0;11811181 barrier();11821182 if (!kvm_s390_vcpu_sie_inhibited(vcpu)) {11831183+xfer_to_guest_mode_check:11831184 local_irq_disable();11851185+ xfer_to_guest_mode_prepare();11861186+ if (xfer_to_guest_mode_work_pending()) {11871187+ local_irq_enable();11881188+ rc = kvm_xfer_to_guest_mode_handle_work(vcpu);11891189+ if (rc)11901190+ goto skip_sie;11911191+ goto xfer_to_guest_mode_check;11921192+ }11841193 guest_timing_enter_irqoff();11851194 rc = kvm_s390_enter_exit_sie(scb_s, vcpu->run->s.regs.gprs, vsie_page->gmap->asce);11861195 guest_timing_exit_irqoff();11871196 local_irq_enable();11881197 }11981198+11991199+skip_sie:11891200 barrier();11901201 vcpu->arch.sie_block->prog0c &= ~PROG_IN_SIE;11911202···13561345 * but rewind the PSW to re-enter SIE once that's completed13571346 * instead of passing a "no action" intercept to the guest.13581347 */13591359- if (signal_pending(current) ||13601360- kvm_s390_vcpu_has_irq(vcpu, 0) ||13481348+ if (kvm_s390_vcpu_has_irq(vcpu, 0) ||13611349 kvm_s390_vcpu_sie_inhibited(vcpu)) {13621350 kvm_s390_rewind_psw(vcpu, 4);13631351 break;13641352 }13651365- cond_resched();13661353 }1367135413681355 if (rc == -EFAULT) {···14921483 if (unlikely(scb_addr & 0x1ffUL))14931484 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);1494148514951495- if (signal_pending(current) || kvm_s390_vcpu_has_irq(vcpu, 0) ||14961496- kvm_s390_vcpu_sie_inhibited(vcpu)) {14861486+ if (kvm_s390_vcpu_has_irq(vcpu, 0) || kvm_s390_vcpu_sie_inhibited(vcpu)) {14971487 kvm_s390_rewind_psw(vcpu, 4);14981488 return 0;14991489 }