summaryrefslogtreecommitdiff
path: root/arch/s390/kvm
diff options
context:
space:
mode:
Diffstat (limited to 'arch/s390/kvm')
-rw-r--r--arch/s390/kvm/Kconfig1
-rw-r--r--arch/s390/kvm/Makefile2
-rw-r--r--arch/s390/kvm/gaccess.c1
-rw-r--r--arch/s390/kvm/intercept.c56
-rw-r--r--arch/s390/kvm/interrupt.c32
-rw-r--r--arch/s390/kvm/kvm-s390.c5
-rw-r--r--arch/s390/kvm/kvm-s390.h5
-rw-r--r--arch/s390/kvm/sthyi.c469
-rw-r--r--arch/s390/kvm/trace-s390.h1
-rw-r--r--arch/s390/kvm/trace.h1
-rw-r--r--arch/s390/kvm/vsie.c50
11 files changed, 108 insertions, 515 deletions
diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
index b1900239b0ab..9a4594e0a1ff 100644
--- a/arch/s390/kvm/Kconfig
+++ b/arch/s390/kvm/Kconfig
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
#
# KVM configuration
#
diff --git a/arch/s390/kvm/Makefile b/arch/s390/kvm/Makefile
index 09a9e6dfc09f..6048b1c6e580 100644
--- a/arch/s390/kvm/Makefile
+++ b/arch/s390/kvm/Makefile
@@ -12,6 +12,6 @@ common-objs = $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/async_pf.o $(KVM)/irqch
ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
kvm-objs := $(common-objs) kvm-s390.o intercept.o interrupt.o priv.o sigp.o
-kvm-objs += diag.o gaccess.o guestdbg.o sthyi.o vsie.o
+kvm-objs += diag.o gaccess.o guestdbg.o vsie.o
obj-$(CONFIG_KVM) += kvm.o
diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
index 3cc77391a102..c24bfa72baf7 100644
--- a/arch/s390/kvm/gaccess.c
+++ b/arch/s390/kvm/gaccess.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
/*
* guest access functions
*
diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c
index a4752bf6b526..8fe034beb623 100644
--- a/arch/s390/kvm/intercept.c
+++ b/arch/s390/kvm/intercept.c
@@ -18,6 +18,7 @@
#include <asm/kvm_host.h>
#include <asm/asm-offsets.h>
#include <asm/irq.h>
+#include <asm/sysinfo.h>
#include "kvm-s390.h"
#include "gaccess.h"
@@ -360,6 +361,61 @@ static int handle_partial_execution(struct kvm_vcpu *vcpu)
return -EOPNOTSUPP;
}
+/*
+ * Handle the sthyi instruction that provides the guest with system
+ * information, like current CPU resources available at each level of
+ * the machine.
+ */
+int handle_sthyi(struct kvm_vcpu *vcpu)
+{
+ int reg1, reg2, r = 0;
+ u64 code, addr, cc = 0, rc = 0;
+ struct sthyi_sctns *sctns = NULL;
+
+ if (!test_kvm_facility(vcpu->kvm, 74))
+ return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
+
+ kvm_s390_get_regs_rre(vcpu, &reg1, &reg2);
+ code = vcpu->run->s.regs.gprs[reg1];
+ addr = vcpu->run->s.regs.gprs[reg2];
+
+ vcpu->stat.instruction_sthyi++;
+ VCPU_EVENT(vcpu, 3, "STHYI: fc: %llu addr: 0x%016llx", code, addr);
+ trace_kvm_s390_handle_sthyi(vcpu, code, addr);
+
+ if (reg1 == reg2 || reg1 & 1 || reg2 & 1)
+ return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+
+ if (code & 0xffff) {
+ cc = 3;
+ rc = 4;
+ goto out;
+ }
+
+ if (addr & ~PAGE_MASK)
+ return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+
+ sctns = (void *)get_zeroed_page(GFP_KERNEL);
+ if (!sctns)
+ return -ENOMEM;
+
+ cc = sthyi_fill(sctns, &rc);
+
+out:
+ if (!cc) {
+ r = write_guest(vcpu, addr, reg2, sctns, PAGE_SIZE);
+ if (r) {
+ free_page((unsigned long)sctns);
+ return kvm_s390_inject_prog_cond(vcpu, r);
+ }
+ }
+
+ free_page((unsigned long)sctns);
+ vcpu->run->s.regs.gprs[reg2 + 1] = rc;
+ kvm_s390_set_psw_cc(vcpu, cc);
+ return r;
+}
+
static int handle_operexc(struct kvm_vcpu *vcpu)
{
psw_t oldpsw, newpsw;
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index a832ad031cee..fa557372d600 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -213,6 +213,16 @@ static inline unsigned long pending_irqs(struct kvm_vcpu *vcpu)
vcpu->arch.local_int.pending_irqs;
}
+static inline int isc_to_irq_type(unsigned long isc)
+{
+ return IRQ_PEND_IO_ISC_0 + isc;
+}
+
+static inline int irq_type_to_isc(unsigned long irq_type)
+{
+ return irq_type - IRQ_PEND_IO_ISC_0;
+}
+
static unsigned long disable_iscs(struct kvm_vcpu *vcpu,
unsigned long active_mask)
{
@@ -220,7 +230,7 @@ static unsigned long disable_iscs(struct kvm_vcpu *vcpu,
for (i = 0; i <= MAX_ISC; i++)
if (!(vcpu->arch.sie_block->gcr[6] & isc_to_isc_bits(i)))
- active_mask &= ~(1UL << (IRQ_PEND_IO_ISC_0 + i));
+ active_mask &= ~(1UL << (isc_to_irq_type(i)));
return active_mask;
}
@@ -901,7 +911,7 @@ static int __must_check __deliver_io(struct kvm_vcpu *vcpu,
fi = &vcpu->kvm->arch.float_int;
spin_lock(&fi->lock);
- isc_list = &fi->lists[irq_type - IRQ_PEND_IO_ISC_0];
+ isc_list = &fi->lists[irq_type_to_isc(irq_type)];
inti = list_first_entry_or_null(isc_list,
struct kvm_s390_interrupt_info,
list);
@@ -1074,6 +1084,12 @@ void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu)
* in kvm_vcpu_block without having the waitqueue set (polling)
*/
vcpu->valid_wakeup = true;
+ /*
+ * This is mostly to document, that the read in swait_active could
+ * be moved before other stores, leading to subtle races.
+ * All current users do not store or use an atomic like update
+ */
+ smp_mb__after_atomic();
if (swait_active(&vcpu->wq)) {
/*
* The vcpu gave up the cpu voluntarily, mark it as a good
@@ -1395,7 +1411,7 @@ static struct kvm_s390_interrupt_info *get_io_int(struct kvm *kvm,
list_del_init(&iter->list);
fi->counters[FIRQ_CNTR_IO] -= 1;
if (list_empty(isc_list))
- clear_bit(IRQ_PEND_IO_ISC_0 + isc, &fi->pending_irqs);
+ clear_bit(isc_to_irq_type(isc), &fi->pending_irqs);
spin_unlock(&fi->lock);
return iter;
}
@@ -1522,7 +1538,7 @@ static int __inject_io(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
isc = int_word_to_isc(inti->io.io_int_word);
list = &fi->lists[FIRQ_LIST_IO_ISC_0 + isc];
list_add_tail(&inti->list, list);
- set_bit(IRQ_PEND_IO_ISC_0 + isc, &fi->pending_irqs);
+ set_bit(isc_to_irq_type(isc), &fi->pending_irqs);
spin_unlock(&fi->lock);
return 0;
}
@@ -2175,6 +2191,8 @@ static int clear_io_irq(struct kvm *kvm, struct kvm_device_attr *attr)
return -EINVAL;
if (copy_from_user(&schid, (void __user *) attr->addr, sizeof(schid)))
return -EFAULT;
+ if (!schid)
+ return -EINVAL;
kfree(kvm_s390_get_io_int(kvm, isc_mask, schid));
/*
* If userspace is conforming to the architecture, we can have at most
@@ -2483,11 +2501,11 @@ void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu,
mci.val = mcck_info->mcic;
if (mci.sr)
- cr14 |= MCCK_CR14_RECOVERY_SUB_MASK;
+ cr14 |= CR14_RECOVERY_SUBMASK;
if (mci.dg)
- cr14 |= MCCK_CR14_DEGRAD_SUB_MASK;
+ cr14 |= CR14_DEGRADATION_SUBMASK;
if (mci.w)
- cr14 |= MCCK_CR14_WARN_SUB_MASK;
+ cr14 |= CR14_WARNING_SUBMASK;
mchk = mci.ck ? &inti.mchk : &irq.u.mchk;
mchk->cr14 = cr14;
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 40d0a1a97889..98ad8b9e0360 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -395,6 +395,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
case KVM_CAP_S390_USER_INSTR0:
case KVM_CAP_S390_CMMA_MIGRATION:
case KVM_CAP_S390_AIS:
+ case KVM_CAP_S390_AIS_MIGRATION:
r = 1;
break;
case KVM_CAP_S390_MEM_OP:
@@ -1884,8 +1885,6 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
rc = -ENOMEM;
- ratelimit_state_init(&kvm->arch.sthyi_limit, 5 * HZ, 500);
-
kvm->arch.use_esca = 0; /* start with basic SCA */
if (!sclp.has_64bscao)
alloc_flags |= GFP_DMA;
@@ -3283,7 +3282,7 @@ static void sync_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
*/
if ((kvm_run->kvm_dirty_regs & KVM_SYNC_RICCB) &&
test_kvm_facility(vcpu->kvm, 64) &&
- riccb->valid &&
+ riccb->v &&
!(vcpu->arch.sie_block->ecb3 & ECB3_RI)) {
VCPU_EVENT(vcpu, 3, "%s", "ENABLE: RI (sync_regs)");
vcpu->arch.sie_block->ecb3 |= ECB3_RI;
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index 9f8fdd7b2311..10d65dfbc306 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -242,6 +242,8 @@ static inline void kvm_s390_retry_instr(struct kvm_vcpu *vcpu)
kvm_s390_rewind_psw(vcpu, kvm_s390_get_ilen(vcpu));
}
+int handle_sthyi(struct kvm_vcpu *vcpu);
+
/* implemented in priv.c */
int is_valid_psw(psw_t *psw);
int kvm_s390_handle_aa(struct kvm_vcpu *vcpu);
@@ -268,9 +270,6 @@ void kvm_s390_vsie_destroy(struct kvm *kvm);
int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);
-/* implemented in sthyi.c */
-int handle_sthyi(struct kvm_vcpu *vcpu);
-
/* implemented in kvm-s390.c */
void kvm_s390_set_tod_clock_ext(struct kvm *kvm,
const struct kvm_s390_vm_tod_clock *gtod);
diff --git a/arch/s390/kvm/sthyi.c b/arch/s390/kvm/sthyi.c
deleted file mode 100644
index 395926b8c1ed..000000000000
--- a/arch/s390/kvm/sthyi.c
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * store hypervisor information instruction emulation functions.
- *
- * 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.
- *
- * Copyright IBM Corp. 2016
- * Author(s): Janosch Frank <frankja@linux.vnet.ibm.com>
- */
-#include <linux/kvm_host.h>
-#include <linux/errno.h>
-#include <linux/pagemap.h>
-#include <linux/vmalloc.h>
-#include <linux/ratelimit.h>
-
-#include <asm/kvm_host.h>
-#include <asm/asm-offsets.h>
-#include <asm/sclp.h>
-#include <asm/diag.h>
-#include <asm/sysinfo.h>
-#include <asm/ebcdic.h>
-
-#include "kvm-s390.h"
-#include "gaccess.h"
-#include "trace.h"
-
-#define DED_WEIGHT 0xffff
-/*
- * CP and IFL as EBCDIC strings, SP/0x40 determines the end of string
- * as they are justified with spaces.
- */
-#define CP 0xc3d7404040404040UL
-#define IFL 0xc9c6d34040404040UL
-
-enum hdr_flags {
- HDR_NOT_LPAR = 0x10,
- HDR_STACK_INCM = 0x20,
- HDR_STSI_UNAV = 0x40,
- HDR_PERF_UNAV = 0x80,
-};
-
-enum mac_validity {
- MAC_NAME_VLD = 0x20,
- MAC_ID_VLD = 0x40,
- MAC_CNT_VLD = 0x80,
-};
-
-enum par_flag {
- PAR_MT_EN = 0x80,
-};
-
-enum par_validity {
- PAR_GRP_VLD = 0x08,
- PAR_ID_VLD = 0x10,
- PAR_ABS_VLD = 0x20,
- PAR_WGHT_VLD = 0x40,
- PAR_PCNT_VLD = 0x80,
-};
-
-struct hdr_sctn {
- u8 infhflg1;
- u8 infhflg2; /* reserved */
- u8 infhval1; /* reserved */
- u8 infhval2; /* reserved */
- u8 reserved[3];
- u8 infhygct;
- u16 infhtotl;
- u16 infhdln;
- u16 infmoff;
- u16 infmlen;
- u16 infpoff;
- u16 infplen;
- u16 infhoff1;
- u16 infhlen1;
- u16 infgoff1;
- u16 infglen1;
- u16 infhoff2;
- u16 infhlen2;
- u16 infgoff2;
- u16 infglen2;
- u16 infhoff3;
- u16 infhlen3;
- u16 infgoff3;
- u16 infglen3;
- u8 reserved2[4];
-} __packed;
-
-struct mac_sctn {
- u8 infmflg1; /* reserved */
- u8 infmflg2; /* reserved */
- u8 infmval1;
- u8 infmval2; /* reserved */
- u16 infmscps;
- u16 infmdcps;
- u16 infmsifl;
- u16 infmdifl;
- char infmname[8];
- char infmtype[4];
- char infmmanu[16];
- char infmseq[16];
- char infmpman[4];
- u8 reserved[4];
-} __packed;
-
-struct par_sctn {
- u8 infpflg1;
- u8 infpflg2; /* reserved */
- u8 infpval1;
- u8 infpval2; /* reserved */
- u16 infppnum;
- u16 infpscps;
- u16 infpdcps;
- u16 infpsifl;
- u16 infpdifl;
- u16 reserved;
- char infppnam[8];
- u32 infpwbcp;
- u32 infpabcp;
- u32 infpwbif;
- u32 infpabif;
- char infplgnm[8];
- u32 infplgcp;
- u32 infplgif;
-} __packed;
-
-struct sthyi_sctns {
- struct hdr_sctn hdr;
- struct mac_sctn mac;
- struct par_sctn par;
-} __packed;
-
-struct cpu_inf {
- u64 lpar_cap;
- u64 lpar_grp_cap;
- u64 lpar_weight;
- u64 all_weight;
- int cpu_num_ded;
- int cpu_num_shd;
-};
-
-struct lpar_cpu_inf {
- struct cpu_inf cp;
- struct cpu_inf ifl;
-};
-
-static inline u64 cpu_id(u8 ctidx, void *diag224_buf)
-{
- return *((u64 *)(diag224_buf + (ctidx + 1) * DIAG204_CPU_NAME_LEN));
-}
-
-/*
- * Scales the cpu capping from the lpar range to the one expected in
- * sthyi data.
- *
- * diag204 reports a cap in hundredths of processor units.
- * z/VM's range for one core is 0 - 0x10000.
- */
-static u32 scale_cap(u32 in)
-{
- return (0x10000 * in) / 100;
-}
-
-static void fill_hdr(struct sthyi_sctns *sctns)
-{
- sctns->hdr.infhdln = sizeof(sctns->hdr);
- sctns->hdr.infmoff = sizeof(sctns->hdr);
- sctns->hdr.infmlen = sizeof(sctns->mac);
- sctns->hdr.infplen = sizeof(sctns->par);
- sctns->hdr.infpoff = sctns->hdr.infhdln + sctns->hdr.infmlen;
- sctns->hdr.infhtotl = sctns->hdr.infpoff + sctns->hdr.infplen;
-}
-
-static void fill_stsi_mac(struct sthyi_sctns *sctns,
- struct sysinfo_1_1_1 *sysinfo)
-{
- if (stsi(sysinfo, 1, 1, 1))
- return;
-
- sclp_ocf_cpc_name_copy(sctns->mac.infmname);
-
- memcpy(sctns->mac.infmtype, sysinfo->type, sizeof(sctns->mac.infmtype));
- memcpy(sctns->mac.infmmanu, sysinfo->manufacturer, sizeof(sctns->mac.infmmanu));
- memcpy(sctns->mac.infmpman, sysinfo->plant, sizeof(sctns->mac.infmpman));
- memcpy(sctns->mac.infmseq, sysinfo->sequence, sizeof(sctns->mac.infmseq));
-
- sctns->mac.infmval1 |= MAC_ID_VLD | MAC_NAME_VLD;
-}
-
-static void fill_stsi_par(struct sthyi_sctns *sctns,
- struct sysinfo_2_2_2 *sysinfo)
-{
- if (stsi(sysinfo, 2, 2, 2))
- return;
-
- sctns->par.infppnum = sysinfo->lpar_number;
- memcpy(sctns->par.infppnam, sysinfo->name, sizeof(sctns->par.infppnam));
-
- sctns->par.infpval1 |= PAR_ID_VLD;
-}
-
-static void fill_stsi(struct sthyi_sctns *sctns)
-{
- void *sysinfo;
-
- /* Errors are handled through the validity bits in the response. */
- sysinfo = (void *)__get_free_page(GFP_KERNEL);
- if (!sysinfo)
- return;
-
- fill_stsi_mac(sctns, sysinfo);
- fill_stsi_par(sctns, sysinfo);
-
- free_pages((unsigned long)sysinfo, 0);
-}
-
-static void fill_diag_mac(struct sthyi_sctns *sctns,
- struct diag204_x_phys_block *block,
- void *diag224_buf)
-{
- int i;
-
- for (i = 0; i < block->hdr.cpus; i++) {
- switch (cpu_id(block->cpus[i].ctidx, diag224_buf)) {
- case CP:
- if (block->cpus[i].weight == DED_WEIGHT)
- sctns->mac.infmdcps++;
- else
- sctns->mac.infmscps++;
- break;
- case IFL:
- if (block->cpus[i].weight == DED_WEIGHT)
- sctns->mac.infmdifl++;
- else
- sctns->mac.infmsifl++;
- break;
- }
- }
- sctns->mac.infmval1 |= MAC_CNT_VLD;
-}
-
-/* Returns a pointer to the the next partition block. */
-static struct diag204_x_part_block *lpar_cpu_inf(struct lpar_cpu_inf *part_inf,
- bool this_lpar,
- void *diag224_buf,
- struct diag204_x_part_block *block)
-{
- int i, capped = 0, weight_cp = 0, weight_ifl = 0;
- struct cpu_inf *cpu_inf;
-
- for (i = 0; i < block->hdr.rcpus; i++) {
- if (!(block->cpus[i].cflag & DIAG204_CPU_ONLINE))
- continue;
-
- switch (cpu_id(block->cpus[i].ctidx, diag224_buf)) {
- case CP:
- cpu_inf = &part_inf->cp;
- if (block->cpus[i].cur_weight < DED_WEIGHT)
- weight_cp |= block->cpus[i].cur_weight;
- break;
- case IFL:
- cpu_inf = &part_inf->ifl;
- if (block->cpus[i].cur_weight < DED_WEIGHT)
- weight_ifl |= block->cpus[i].cur_weight;
- break;
- default:
- continue;
- }
-
- if (!this_lpar)
- continue;
-
- capped |= block->cpus[i].cflag & DIAG204_CPU_CAPPED;
- cpu_inf->lpar_cap |= block->cpus[i].cpu_type_cap;
- cpu_inf->lpar_grp_cap |= block->cpus[i].group_cpu_type_cap;
-
- if (block->cpus[i].weight == DED_WEIGHT)
- cpu_inf->cpu_num_ded += 1;
- else
- cpu_inf->cpu_num_shd += 1;
- }
-
- if (this_lpar && capped) {
- part_inf->cp.lpar_weight = weight_cp;
- part_inf->ifl.lpar_weight = weight_ifl;
- }
- part_inf->cp.all_weight += weight_cp;
- part_inf->ifl.all_weight += weight_ifl;
- return (struct diag204_x_part_block *)&block->cpus[i];
-}
-
-static void fill_diag(struct sthyi_sctns *sctns)
-{
- int i, r, pages;
- bool this_lpar;
- void *diag204_buf;
- void *diag224_buf = NULL;
- struct diag204_x_info_blk_hdr *ti_hdr;
- struct diag204_x_part_block *part_block;
- struct diag204_x_phys_block *phys_block;
- struct lpar_cpu_inf lpar_inf = {};
-
- /* Errors are handled through the validity bits in the response. */
- pages = diag204((unsigned long)DIAG204_SUBC_RSI |
- (unsigned long)DIAG204_INFO_EXT, 0, NULL);
- if (pages <= 0)
- return;
-
- diag204_buf = vmalloc(PAGE_SIZE * pages);
- if (!diag204_buf)
- return;
-
- r = diag204((unsigned long)DIAG204_SUBC_STIB7 |
- (unsigned long)DIAG204_INFO_EXT, pages, diag204_buf);
- if (r < 0)
- goto out;
-
- diag224_buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
- if (!diag224_buf || diag224(diag224_buf))
- goto out;
-
- ti_hdr = diag204_buf;
- part_block = diag204_buf + sizeof(*ti_hdr);
-
- for (i = 0; i < ti_hdr->npar; i++) {
- /*
- * For the calling lpar we also need to get the cpu
- * caps and weights. The time information block header
- * specifies the offset to the partition block of the
- * caller lpar, so we know when we process its data.
- */
- this_lpar = (void *)part_block - diag204_buf == ti_hdr->this_part;
- part_block = lpar_cpu_inf(&lpar_inf, this_lpar, diag224_buf,
- part_block);
- }
-
- phys_block = (struct diag204_x_phys_block *)part_block;
- part_block = diag204_buf + ti_hdr->this_part;
- if (part_block->hdr.mtid)
- sctns->par.infpflg1 = PAR_MT_EN;
-
- sctns->par.infpval1 |= PAR_GRP_VLD;
- sctns->par.infplgcp = scale_cap(lpar_inf.cp.lpar_grp_cap);
- sctns->par.infplgif = scale_cap(lpar_inf.ifl.lpar_grp_cap);
- memcpy(sctns->par.infplgnm, part_block->hdr.hardware_group_name,
- sizeof(sctns->par.infplgnm));
-
- sctns->par.infpscps = lpar_inf.cp.cpu_num_shd;
- sctns->par.infpdcps = lpar_inf.cp.cpu_num_ded;
- sctns->par.infpsifl = lpar_inf.ifl.cpu_num_shd;
- sctns->par.infpdifl = lpar_inf.ifl.cpu_num_ded;
- sctns->par.infpval1 |= PAR_PCNT_VLD;
-
- sctns->par.infpabcp = scale_cap(lpar_inf.cp.lpar_cap);
- sctns->par.infpabif = scale_cap(lpar_inf.ifl.lpar_cap);
- sctns->par.infpval1 |= PAR_ABS_VLD;
-
- /*
- * Everything below needs global performance data to be
- * meaningful.
- */
- if (!(ti_hdr->flags & DIAG204_LPAR_PHYS_FLG)) {
- sctns->hdr.infhflg1 |= HDR_PERF_UNAV;
- goto out;
- }
-
- fill_diag_mac(sctns, phys_block, diag224_buf);
-
- if (lpar_inf.cp.lpar_weight) {
- sctns->par.infpwbcp = sctns->mac.infmscps * 0x10000 *
- lpar_inf.cp.lpar_weight / lpar_inf.cp.all_weight;
- }
-
- if (lpar_inf.ifl.lpar_weight) {
- sctns->par.infpwbif = sctns->mac.infmsifl * 0x10000 *
- lpar_inf.ifl.lpar_weight / lpar_inf.ifl.all_weight;
- }
- sctns->par.infpval1 |= PAR_WGHT_VLD;
-
-out:
- free_page((unsigned long)diag224_buf);
- vfree(diag204_buf);
-}
-
-static int sthyi(u64 vaddr)
-{
- register u64 code asm("0") = 0;
- register u64 addr asm("2") = vaddr;
- int cc;
-
- asm volatile(
- ".insn rre,0xB2560000,%[code],%[addr]\n"
- "ipm %[cc]\n"
- "srl %[cc],28\n"
- : [cc] "=d" (cc)
- : [code] "d" (code), [addr] "a" (addr)
- : "3", "memory", "cc");
- return cc;
-}
-
-int handle_sthyi(struct kvm_vcpu *vcpu)
-{
- int reg1, reg2, r = 0;
- u64 code, addr, cc = 0;
- struct sthyi_sctns *sctns = NULL;
-
- if (!test_kvm_facility(vcpu->kvm, 74))
- return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
-
- /*
- * STHYI requires extensive locking in the higher hypervisors
- * and is very computational/memory expensive. Therefore we
- * ratelimit the executions per VM.
- */
- if (!__ratelimit(&vcpu->kvm->arch.sthyi_limit)) {
- kvm_s390_retry_instr(vcpu);
- return 0;
- }
-
- kvm_s390_get_regs_rre(vcpu, &reg1, &reg2);
- code = vcpu->run->s.regs.gprs[reg1];
- addr = vcpu->run->s.regs.gprs[reg2];
-
- vcpu->stat.instruction_sthyi++;
- VCPU_EVENT(vcpu, 3, "STHYI: fc: %llu addr: 0x%016llx", code, addr);
- trace_kvm_s390_handle_sthyi(vcpu, code, addr);
-
- if (reg1 == reg2 || reg1 & 1 || reg2 & 1)
- return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
-
- if (code & 0xffff) {
- cc = 3;
- goto out;
- }
-
- if (addr & ~PAGE_MASK)
- return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
-
- sctns = (void *)get_zeroed_page(GFP_KERNEL);
- if (!sctns)
- return -ENOMEM;
-
- /*
- * If we are a guest, we don't want to emulate an emulated
- * instruction. We ask the hypervisor to provide the data.
- */
- if (test_facility(74)) {
- cc = sthyi((u64)sctns);
- goto out;
- }
-
- fill_hdr(sctns);
- fill_stsi(sctns);
- fill_diag(sctns);
-
-out:
- if (!cc) {
- r = write_guest(vcpu, addr, reg2, sctns, PAGE_SIZE);
- if (r) {
- free_page((unsigned long)sctns);
- return kvm_s390_inject_prog_cond(vcpu, r);
- }
- }
-
- free_page((unsigned long)sctns);
- vcpu->run->s.regs.gprs[reg2 + 1] = cc ? 4 : 0;
- kvm_s390_set_psw_cc(vcpu, cc);
- return r;
-}
diff --git a/arch/s390/kvm/trace-s390.h b/arch/s390/kvm/trace-s390.h
index 78b7e847984a..6f0209d45164 100644
--- a/arch/s390/kvm/trace-s390.h
+++ b/arch/s390/kvm/trace-s390.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
#if !defined(_TRACE_KVMS390_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_KVMS390_H
diff --git a/arch/s390/kvm/trace.h b/arch/s390/kvm/trace.h
index 4fc9d4e5be89..aa419eb6a0c8 100644
--- a/arch/s390/kvm/trace.h
+++ b/arch/s390/kvm/trace.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
#if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_KVM_H
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index b18b5652e5c5..a311938b63b3 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -443,22 +443,14 @@ static int map_prefix(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
*
* Returns: - 0 on success
* - -EINVAL if the gpa is not valid guest storage
- * - -ENOMEM if out of memory
*/
static int pin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t *hpa)
{
struct page *page;
- hva_t hva;
- int rc;
- hva = gfn_to_hva(kvm, gpa_to_gfn(gpa));
- if (kvm_is_error_hva(hva))
+ page = gfn_to_page(kvm, gpa_to_gfn(gpa));
+ if (is_error_page(page))
return -EINVAL;
- rc = get_user_pages_fast(hva, 1, 1, &page);
- if (rc < 0)
- return rc;
- else if (rc != 1)
- return -ENOMEM;
*hpa = (hpa_t) page_to_virt(page) + (gpa & ~PAGE_MASK);
return 0;
}
@@ -466,11 +458,7 @@ static int pin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t *hpa)
/* Unpins a page previously pinned via pin_guest_page, marking it as dirty. */
static void unpin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t hpa)
{
- struct page *page;
-
- page = virt_to_page(hpa);
- set_page_dirty_lock(page);
- put_page(page);
+ kvm_release_pfn_dirty(hpa >> PAGE_SHIFT);
/* mark the page always as dirty for migration */
mark_page_dirty(kvm, gpa_to_gfn(gpa));
}
@@ -557,7 +545,7 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
rc = set_validity_icpt(scb_s, 0x003bU);
if (!rc) {
rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
- if (rc == -EINVAL)
+ if (rc)
rc = set_validity_icpt(scb_s, 0x0034U);
}
if (rc)
@@ -574,10 +562,10 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
}
/* 256 bytes cannot cross page boundaries */
rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
- if (rc == -EINVAL)
+ if (rc) {
rc = set_validity_icpt(scb_s, 0x0080U);
- if (rc)
goto unpin;
+ }
scb_s->itdba = hpa;
}
@@ -592,10 +580,10 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
* if this block gets bigger, we have to shadow it.
*/
rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
- if (rc == -EINVAL)
+ if (rc) {
rc = set_validity_icpt(scb_s, 0x1310U);
- if (rc)
goto unpin;
+ }
scb_s->gvrd = hpa;
}
@@ -607,11 +595,11 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
}
/* 64 bytes cannot cross page boundaries */
rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
- if (rc == -EINVAL)
+ if (rc) {
rc = set_validity_icpt(scb_s, 0x0043U);
- /* Validity 0x0044 will be checked by SIE */
- if (rc)
goto unpin;
+ }
+ /* Validity 0x0044 will be checked by SIE */
scb_s->riccbd = hpa;
}
if ((scb_s->ecb & ECB_GS) && !(scb_s->ecd & ECD_HOSTREGMGMT)) {
@@ -635,10 +623,10 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
* cross page boundaries
*/
rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
- if (rc == -EINVAL)
+ if (rc) {
rc = set_validity_icpt(scb_s, 0x10b0U);
- if (rc)
goto unpin;
+ }
scb_s->sdnxo = hpa | sdnxc;
}
return 0;
@@ -663,7 +651,6 @@ static void unpin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
*
* Returns: - 0 if the scb was pinned.
* - > 0 if control has to be given to guest 2
- * - -ENOMEM if out of memory
*/
static int pin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
gpa_t gpa)
@@ -672,14 +659,13 @@ static int pin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
int rc;
rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
- if (rc == -EINVAL) {
+ if (rc) {
rc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
- if (!rc)
- rc = 1;
+ WARN_ON_ONCE(rc);
+ return 1;
}
- if (!rc)
- vsie_page->scb_o = (struct kvm_s390_sie_block *) hpa;
- return rc;
+ vsie_page->scb_o = (struct kvm_s390_sie_block *) hpa;
+ return 0;
}
/*