cregit-Linux how code gets into the kernel

Release 4.14 arch/s390/kvm/sigp.c

Directory: arch/s390/kvm
/*
 * handling interprocessor communication
 *
 * Copyright IBM Corp. 2008, 2013
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License (version 2 only)
 * as published by the Free Software Foundation.
 *
 *    Author(s): Carsten Otte <cotte@de.ibm.com>
 *               Christian Borntraeger <borntraeger@de.ibm.com>
 *               Christian Ehrhardt <ehrhardt@de.ibm.com>
 */

#include <linux/kvm.h>
#include <linux/kvm_host.h>
#include <linux/slab.h>
#include <asm/sigp.h>
#include "gaccess.h"
#include "kvm-s390.h"
#include "trace.h"


static int __sigp_sense(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu, u64 *reg) { struct kvm_s390_local_interrupt *li; int cpuflags; int rc; int ext_call_pending; li = &dst_vcpu->arch.local_int; cpuflags = atomic_read(li->cpuflags); ext_call_pending = kvm_s390_ext_call_pending(dst_vcpu); if (!(cpuflags & CPUSTAT_STOPPED) && !ext_call_pending) rc = SIGP_CC_ORDER_CODE_ACCEPTED; else { *reg &= 0xffffffff00000000UL; if (ext_call_pending) *reg |= SIGP_STATUS_EXT_CALL_PENDING; if (cpuflags & CPUSTAT_STOPPED) *reg |= SIGP_STATUS_STOPPED; rc = SIGP_CC_STATUS_STORED; } VCPU_EVENT(vcpu, 4, "sensed status of cpu %x rc %x", dst_vcpu->vcpu_id, rc); return rc; }

Contributors

PersonTokensPropCommitsCommitProp
Christian Bornträger6451.20%222.22%
David Hildenbrand2116.80%222.22%
Jens Freimann1915.20%111.11%
Cornelia Huck1915.20%222.22%
Heiko Carstens21.60%222.22%
Total125100.00%9100.00%


static int __inject_sigp_emergency(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu) { struct kvm_s390_irq irq = { .type = KVM_S390_INT_EMERGENCY, .u.emerg.code = vcpu->vcpu_id, }; int rc = 0; rc = kvm_s390_inject_vcpu(dst_vcpu, &irq); if (!rc) VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x", dst_vcpu->vcpu_id); return rc ? rc : SIGP_CC_ORDER_CODE_ACCEPTED; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Freimann3646.15%342.86%
Christian Bornträger2126.92%114.29%
Christian Ehrhardt1316.67%114.29%
David Hildenbrand810.26%228.57%
Total78100.00%7100.00%


static int __sigp_emergency(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu) { return __inject_sigp_emergency(vcpu, dst_vcpu); }

Contributors

PersonTokensPropCommitsCommitProp
David Hildenbrand24100.00%1100.00%
Total24100.00%1100.00%


static int __sigp_conditional_emergency(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu, u16 asn, u64 *reg) { const u64 psw_int_mask = PSW_MASK_IO | PSW_MASK_EXT; u16 p_asn, s_asn; psw_t *psw; bool idle; idle = is_vcpu_idle(vcpu); psw = &dst_vcpu->arch.sie_block->gpsw; p_asn = dst_vcpu->arch.sie_block->gcr[4] & 0xffff; /* Primary ASN */ s_asn = dst_vcpu->arch.sie_block->gcr[3] & 0xffff; /* Secondary ASN */ /* Inject the emergency signal? */ if (!is_vcpu_stopped(vcpu) || (psw->mask & psw_int_mask) != psw_int_mask || (idle && psw->addr != 0) || (!idle && (asn == p_asn || asn == s_asn))) { return __inject_sigp_emergency(vcpu, dst_vcpu); } else { *reg &= 0xffffffff00000000UL; *reg |= SIGP_STATUS_INCORRECT_STATE; return SIGP_CC_STATUS_STORED; } }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Huth14588.96%125.00%
David Hildenbrand1811.04%375.00%
Total163100.00%4100.00%


static int __sigp_external_call(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu, u64 *reg) { struct kvm_s390_irq irq = { .type = KVM_S390_INT_EXTERNAL_CALL, .u.extcall.code = vcpu->vcpu_id, }; int rc; rc = kvm_s390_inject_vcpu(dst_vcpu, &irq); if (rc == -EBUSY) { *reg &= 0xffffffff00000000UL; *reg |= SIGP_STATUS_EXT_CALL_PENDING; return SIGP_CC_STATUS_STORED; } else if (rc == 0) { VCPU_EVENT(vcpu, 4, "sent sigp ext call to cpu %x", dst_vcpu->vcpu_id); } return rc ? rc : SIGP_CC_ORDER_CODE_ACCEPTED; }

Contributors

PersonTokensPropCommitsCommitProp
David Hildenbrand3835.85%228.57%
Jens Freimann3331.13%342.86%
Christian Ehrhardt2321.70%114.29%
Christian Bornträger1211.32%114.29%
Total106100.00%7100.00%


static int __sigp_stop(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu) { struct kvm_s390_irq irq = { .type = KVM_S390_SIGP_STOP, }; int rc; rc = kvm_s390_inject_vcpu(dst_vcpu, &irq); if (rc == -EBUSY) rc = SIGP_CC_BUSY; else if (rc == 0) VCPU_EVENT(vcpu, 4, "sent sigp stop to cpu %x", dst_vcpu->vcpu_id); return rc; }

Contributors

PersonTokensPropCommitsCommitProp
David Hildenbrand4459.46%562.50%
Christian Bornträger2331.08%112.50%
Thomas Huth56.76%112.50%
Jens Freimann22.70%112.50%
Total74100.00%8100.00%


static int __sigp_stop_and_store_status(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu, u64 *reg) { struct kvm_s390_irq irq = { .type = KVM_S390_SIGP_STOP, .u.stop.flags = KVM_S390_STOP_FLAG_STORE_STATUS, }; int rc; rc = kvm_s390_inject_vcpu(dst_vcpu, &irq); if (rc == -EBUSY) rc = SIGP_CC_BUSY; else if (rc == 0) VCPU_EVENT(vcpu, 4, "sent sigp stop and store status to cpu %x", dst_vcpu->vcpu_id); return rc; }

Contributors

PersonTokensPropCommitsCommitProp
David Hildenbrand8395.40%266.67%
Christian Bornträger44.60%133.33%
Total87100.00%3100.00%


static int __sigp_set_arch(struct kvm_vcpu *vcpu, u32 parameter, u64 *status_reg) { unsigned int i; struct kvm_vcpu *v; bool all_stopped = true; kvm_for_each_vcpu(i, v, vcpu->kvm) { if (v == vcpu) continue; if (!is_vcpu_stopped(v)) all_stopped = false; } *status_reg &= 0xffffffff00000000UL; /* Reject set arch order, with czam we're always in z/Arch mode. */ *status_reg |= (all_stopped ? SIGP_STATUS_INVALID_PARAMETER : SIGP_STATUS_INCORRECT_STATE); return SIGP_CC_STATUS_STORED; }

Contributors

PersonTokensPropCommitsCommitProp
Jason J. Herne3948.15%133.33%
Dominik Dingel2429.63%133.33%
Christian Bornträger1822.22%133.33%
Total81100.00%3100.00%


static int __sigp_set_prefix(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu, u32 address, u64 *reg) { struct kvm_s390_irq irq = { .type = KVM_S390_SIGP_SET_PREFIX, .u.prefix.address = address & 0x7fffe000u, }; int rc; /* * Make sure the new value is valid memory. We only need to check the * first page, since address is 8k aligned and memory pieces are always * at least 1MB aligned and have at least a size of 1MB. */ if (kvm_is_error_gpa(vcpu->kvm, irq.u.prefix.address)) { *reg &= 0xffffffff00000000UL; *reg |= SIGP_STATUS_INVALID_PARAMETER; return SIGP_CC_STATUS_STORED; } rc = kvm_s390_inject_vcpu(dst_vcpu, &irq); if (rc == -EBUSY) { *reg &= 0xffffffff00000000UL; *reg |= SIGP_STATUS_INCORRECT_STATE; return SIGP_CC_STATUS_STORED; } return rc; }

Contributors

PersonTokensPropCommitsCommitProp
Christian Bornträger5547.41%222.22%
David Hildenbrand4236.21%222.22%
Heiko Carstens1815.52%444.44%
Carsten Otte10.86%111.11%
Total116100.00%9100.00%


static int __sigp_store_status_at_addr(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu, u32 addr, u64 *reg) { int flags; int rc; flags = atomic_read(dst_vcpu->arch.local_int.cpuflags); if (!(flags & CPUSTAT_STOPPED)) { *reg &= 0xffffffff00000000UL; *reg |= SIGP_STATUS_INCORRECT_STATE; return SIGP_CC_STATUS_STORED; } addr &= 0x7ffffe00; rc = kvm_s390_store_status_unloaded(dst_vcpu, addr); if (rc == -EFAULT) { *reg &= 0xffffffff00000000UL; *reg |= SIGP_STATUS_INVALID_PARAMETER; rc = SIGP_CC_STATUS_STORED; } return rc; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Huth10196.19%150.00%
David Hildenbrand43.81%150.00%
Total105100.00%2100.00%


static int __sigp_sense_running(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu, u64 *reg) { struct kvm_s390_local_interrupt *li; int rc; if (!test_kvm_facility(vcpu->kvm, 9)) { *reg &= 0xffffffff00000000UL; *reg |= SIGP_STATUS_INVALID_ORDER; return SIGP_CC_STATUS_STORED; } li = &dst_vcpu->arch.local_int; if (atomic_read(li->cpuflags) & CPUSTAT_RUNNING) { /* running */ rc = SIGP_CC_ORDER_CODE_ACCEPTED; } else { /* not running */ *reg &= 0xffffffff00000000UL; *reg |= SIGP_STATUS_NOT_RUNNING; rc = SIGP_CC_STATUS_STORED; } VCPU_EVENT(vcpu, 4, "sensed running status of cpu %x rc %x", dst_vcpu->vcpu_id, rc); return rc; }

Contributors

PersonTokensPropCommitsCommitProp
Cornelia Huck6555.08%114.29%
David Hildenbrand3428.81%228.57%
Jens Freimann1512.71%114.29%
Heiko Carstens32.54%228.57%
Christian Bornträger10.85%114.29%
Total118100.00%7100.00%


static int __prepare_sigp_re_start(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu, u8 order_code) { struct kvm_s390_local_interrupt *li = &dst_vcpu->arch.local_int; /* handle (RE)START in user space */ int rc = -EOPNOTSUPP; /* make sure we don't race with STOP irq injection */ spin_lock(&li->lock); if (kvm_s390_is_stop_irq_pending(dst_vcpu)) rc = SIGP_CC_BUSY; spin_unlock(&li->lock); return rc; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Freimann4463.77%228.57%
David Hildenbrand2333.33%457.14%
Heiko Carstens22.90%114.29%
Total69100.00%7100.00%


static int __prepare_sigp_cpu_reset(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu, u8 order_code) { /* handle (INITIAL) CPU RESET in user space */ return -EOPNOTSUPP; }

Contributors

PersonTokensPropCommitsCommitProp
David Hildenbrand24100.00%1100.00%
Total24100.00%1100.00%


static int __prepare_sigp_unknown(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu) { /* handle unknown orders in user space */ return -EOPNOTSUPP; }

Contributors

PersonTokensPropCommitsCommitProp
David Hildenbrand21100.00%1100.00%
Total21100.00%1100.00%


static int handle_sigp_dst(struct kvm_vcpu *vcpu, u8 order_code, u16 cpu_addr, u32 parameter, u64 *status_reg) { int rc; struct kvm_vcpu *dst_vcpu = kvm_get_vcpu_by_id(vcpu->kvm, cpu_addr); if (!dst_vcpu) return SIGP_CC_NOT_OPERATIONAL; switch (order_code) { case SIGP_SENSE: vcpu->stat.instruction_sigp_sense++; rc = __sigp_sense(vcpu, dst_vcpu, status_reg); break; case SIGP_EXTERNAL_CALL: vcpu->stat.instruction_sigp_external_call++; rc = __sigp_external_call(vcpu, dst_vcpu, status_reg); break; case SIGP_EMERGENCY_SIGNAL: vcpu->stat.instruction_sigp_emergency++; rc = __sigp_emergency(vcpu, dst_vcpu); break; case SIGP_STOP: vcpu->stat.instruction_sigp_stop++; rc = __sigp_stop(vcpu, dst_vcpu); break; case SIGP_STOP_AND_STORE_STATUS: vcpu->stat.instruction_sigp_stop_store_status++; rc = __sigp_stop_and_store_status(vcpu, dst_vcpu, status_reg); break; case SIGP_STORE_STATUS_AT_ADDRESS: vcpu->stat.instruction_sigp_store_status++; rc = __sigp_store_status_at_addr(vcpu, dst_vcpu, parameter, status_reg); break; case SIGP_SET_PREFIX: vcpu->stat.instruction_sigp_prefix++; rc = __sigp_set_prefix(vcpu, dst_vcpu, parameter, status_reg); break; case SIGP_COND_EMERGENCY_SIGNAL: vcpu->stat.instruction_sigp_cond_emergency++; rc = __sigp_conditional_emergency(vcpu, dst_vcpu, parameter, status_reg); break; case SIGP_SENSE_RUNNING: vcpu->stat.instruction_sigp_sense_running++; rc = __sigp_sense_running(vcpu, dst_vcpu, status_reg); break; case SIGP_START: vcpu->stat.instruction_sigp_start++; rc = __prepare_sigp_re_start(vcpu, dst_vcpu, order_code); break; case SIGP_RESTART: vcpu->stat.instruction_sigp_restart++; rc = __prepare_sigp_re_start(vcpu, dst_vcpu, order_code); break; case SIGP_INITIAL_CPU_RESET: vcpu->stat.instruction_sigp_init_cpu_reset++; rc = __prepare_sigp_cpu_reset(vcpu, dst_vcpu, order_code); break; case SIGP_CPU_RESET: vcpu->stat.instruction_sigp_cpu_reset++; rc = __prepare_sigp_cpu_reset(vcpu, dst_vcpu, order_code); break; default: vcpu->stat.instruction_sigp_unknown++; rc = __prepare_sigp_unknown(vcpu, dst_vcpu); } if (rc == -EOPNOTSUPP) VCPU_EVENT(vcpu, 4, "sigp order %u -> cpu %x: handled in user space", order_code, dst_vcpu->vcpu_id); return rc; }

Contributors

PersonTokensPropCommitsCommitProp
David Hildenbrand16041.56%741.18%
Christian Bornträger12833.25%15.88%
Thomas Huth4712.21%423.53%
Cornelia Huck205.19%15.88%
Christian Ehrhardt194.94%15.88%
Jens Freimann82.08%15.88%
Heiko Carstens30.78%211.76%
Total385100.00%17100.00%


static int handle_sigp_order_in_user_space(struct kvm_vcpu *vcpu, u8 order_code, u16 cpu_addr) { if (!vcpu->kvm->arch.user_sigp) return 0; switch (order_code) { case SIGP_SENSE: case SIGP_EXTERNAL_CALL: case SIGP_EMERGENCY_SIGNAL: case SIGP_COND_EMERGENCY_SIGNAL: case SIGP_SENSE_RUNNING: return 0; /* update counters as we're directly dropping to user space */ case SIGP_STOP: vcpu->stat.instruction_sigp_stop++; break; case SIGP_STOP_AND_STORE_STATUS: vcpu->stat.instruction_sigp_stop_store_status++; break; case SIGP_STORE_STATUS_AT_ADDRESS: vcpu->stat.instruction_sigp_store_status++; break; case SIGP_STORE_ADDITIONAL_STATUS: vcpu->stat.instruction_sigp_store_adtl_status++; break; case SIGP_SET_PREFIX: vcpu->stat.instruction_sigp_prefix++; break; case SIGP_START: vcpu->stat.instruction_sigp_start++; break; case SIGP_RESTART: vcpu->stat.instruction_sigp_restart++; break; case SIGP_INITIAL_CPU_RESET: vcpu->stat.instruction_sigp_init_cpu_reset++; break; case SIGP_CPU_RESET: vcpu->stat.instruction_sigp_cpu_reset++; break; default: vcpu->stat.instruction_sigp_unknown++; } VCPU_EVENT(vcpu, 3, "SIGP: order %u for CPU %d handled in userspace", order_code, cpu_addr); return 1; }

Contributors

PersonTokensPropCommitsCommitProp
David Hildenbrand16189.94%133.33%
Eric Farman116.15%133.33%
Christian Bornträger73.91%133.33%
Total179100.00%3100.00%


int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu) { int r1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; int r3 = vcpu->arch.sie_block->ipa & 0x000f; u32 parameter; u16 cpu_addr = vcpu->run->s.regs.gprs[r3]; u8 order_code; int rc; /* sigp in userspace can exit */ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); order_code = kvm_s390_get_base_disp_rs(vcpu, NULL); if (handle_sigp_order_in_user_space(vcpu, order_code, cpu_addr)) return -EOPNOTSUPP; if (r1 % 2) parameter = vcpu->run->s.regs.gprs[r1]; else parameter = vcpu->run->s.regs.gprs[r1 + 1]; trace_kvm_s390_handle_sigp(vcpu, order_code, cpu_addr, parameter); switch (order_code) { case SIGP_SET_ARCHITECTURE: vcpu->stat.instruction_sigp_arch++; rc = __sigp_set_arch(vcpu, parameter, &vcpu->run->s.regs.gprs[r1]); break; default: rc = handle_sigp_dst(vcpu, order_code, cpu_addr, parameter, &vcpu->run->s.regs.gprs[r1]); } if (rc < 0) return rc; kvm_s390_set_psw_cc(vcpu, rc); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David Hildenbrand20983.94%228.57%
Christian Bornträger208.03%228.57%
Jason J. Herne145.62%114.29%
Thomas Huth41.61%114.29%
Alexander Yarygin20.80%114.29%
Total249100.00%7100.00%

/* * Handle SIGP partial execution interception. * * This interception will occur at the source cpu when a source cpu sends an * external call to a target cpu and the target cpu has the WAIT bit set in * its cpuflags. Interception will occurr after the interrupt indicator bits at * the target cpu have been set. All error cases will lead to instruction * interception, therefore nothing is to be checked or prepared. */
int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu) { int r3 = vcpu->arch.sie_block->ipa & 0x000f; u16 cpu_addr = vcpu->run->s.regs.gprs[r3]; struct kvm_vcpu *dest_vcpu; u8 order_code = kvm_s390_get_base_disp_rs(vcpu, NULL); trace_kvm_s390_handle_sigp_pei(vcpu, order_code, cpu_addr); if (order_code == SIGP_EXTERNAL_CALL) { dest_vcpu = kvm_get_vcpu_by_id(vcpu->kvm, cpu_addr); BUG_ON(dest_vcpu == NULL); kvm_s390_vcpu_wakeup(dest_vcpu); kvm_s390_set_psw_cc(vcpu, SIGP_CC_ORDER_CODE_ACCEPTED); return 0; } return -EOPNOTSUPP; }

Contributors

PersonTokensPropCommitsCommitProp
David Hildenbrand10698.15%375.00%
Alexander Yarygin21.85%125.00%
Total108100.00%4100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
David Hildenbrand102147.82%1736.17%
Christian Bornträger36517.10%36.38%
Thomas Huth30314.19%612.77%
Jens Freimann1577.35%510.64%
Cornelia Huck1075.01%48.51%
Christian Ehrhardt552.58%12.13%
Jason J. Herne532.48%12.13%
Heiko Carstens311.45%510.64%
Dominik Dingel241.12%12.13%
Eric Farman110.52%12.13%
Alexander Yarygin40.19%12.13%
Tejun Heo30.14%12.13%
Carsten Otte10.05%12.13%
Total2135100.00%47100.00%
Directory: arch/s390/kvm
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.