All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20)
@ 2015-02-04  9:44 Christian Borntraeger
  2015-02-04  9:44 ` [PATCH 1/7] KVM: s390: floating irqs: fix user triggerable endless loop Christian Borntraeger
                   ` (7 more replies)
  0 siblings, 8 replies; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04  9:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Christian Borntraeger

Paolo,

here is my remaining bunch of patches for 3.20 for review. All patches
have been in linux-next via
git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git next
(well a tiny fix went in today, so the commit id for the last 3 patches
has changed)

I think it makes sense to give some of these patches some more days
for external review. Is it ok to send a pull request early next week
or do you want it before 3.19?

There is one non-KVM s390 patch, but it has an ACK from Heiko Carstens

Christian Borntraeger (1):
  KVM: s390: reenable LPP facility

David Hildenbrand (1):
  KVM: s390: floating irqs: fix user triggerable endless loop

Ekaterina Tumanova (1):
  s390/kernel: Update /proc/sysinfo file with Extended Name and UUID

Jason J. Herne (1):
  KVM: s390: Create ioctl for Getting/Setting guest storage keys

Michael Mueller (2):
  KVM: s390: use facilities and cpu_id per KVM
  KVM: s390: add cpu model support

Tony Krowiak (1):
  KVM: s390/CPACF: Choose crypto control block format

 Documentation/virtual/kvm/api.txt        |  58 +++++
 Documentation/virtual/kvm/devices/vm.txt |  45 ++++
 arch/s390/include/asm/kvm_host.h         |  27 ++-
 arch/s390/include/asm/sysinfo.h          |  10 +-
 arch/s390/include/uapi/asm/kvm.h         |  21 ++
 arch/s390/kernel/sysinfo.c               |  29 +++
 arch/s390/kvm/gaccess.c                  |   4 +-
 arch/s390/kvm/interrupt.c                |   2 +
 arch/s390/kvm/kvm-s390.c                 | 394 ++++++++++++++++++++++++++++---
 arch/s390/kvm/kvm-s390.h                 |  13 +-
 arch/s390/kvm/priv.c                     |  13 +-
 include/uapi/linux/kvm.h                 |  14 ++
 12 files changed, 580 insertions(+), 50 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/7] KVM: s390: floating irqs: fix user triggerable endless loop
  2015-02-04  9:44 [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Christian Borntraeger
@ 2015-02-04  9:44 ` Christian Borntraeger
  2015-02-04  9:44 ` [PATCH 2/7] KVM: s390: reenable LPP facility Christian Borntraeger
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04  9:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	David Hildenbrand, stable, #, v3.15+,
	Christian Borntraeger

From: David Hildenbrand <dahi@linux.vnet.ibm.com>

If a vm with no VCPUs is created, the injection of a floating irq
leads to an endless loop in the kernel.

Let's skip the search for a destination VCPU for a floating irq if no
VCPUs were created.

Reviewed-by: Dominik Dingel <dingel@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Cc: stable@vger.kernel.org # v3.15+
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/kvm/interrupt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index c34e1d9..073b5f3 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -1244,6 +1244,8 @@ static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
 		list_add_tail(&inti->list, &iter->list);
 	}
 	atomic_set(&fi->active, 1);
+	if (atomic_read(&kvm->online_vcpus) == 0)
+		goto unlock_fi;
 	sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS);
 	if (sigcpu == KVM_MAX_VCPUS) {
 		do {
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/7] KVM: s390: reenable LPP facility
  2015-02-04  9:44 [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Christian Borntraeger
  2015-02-04  9:44 ` [PATCH 1/7] KVM: s390: floating irqs: fix user triggerable endless loop Christian Borntraeger
@ 2015-02-04  9:44 ` Christian Borntraeger
  2015-02-04 12:57   ` Paolo Bonzini
  2015-02-04  9:44 ` [PATCH 3/7] s390/kernel: Update /proc/sysinfo file with Extended Name and UUID Christian Borntraeger
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04  9:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Christian Borntraeger

commit 7be81a46695d ("KVM: s390/facilities: allow TOD-CLOCK steering
facility bit") accidentially disabled the "load program parameter"
facility bit during rebase for upstream submission (my fault).

Re-add that bit.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Fixes: 7be81a46695d ("KVM: s390/facilities: allow TOD-CLOCK steering")
---
 arch/s390/kvm/kvm-s390.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index b2371c0..57f5538 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -2073,7 +2073,7 @@ static int __init kvm_s390_init(void)
 		return -ENOMEM;
 	}
 	memcpy(vfacilities, S390_lowcore.stfle_fac_list, 16);
-	vfacilities[0] &= 0xff82fffbf47c2000UL;
+	vfacilities[0] &= 0xff82fffbf4fc2000UL;
 	vfacilities[1] &= 0x005c000000000000UL;
 	return 0;
 }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 3/7] s390/kernel: Update /proc/sysinfo file with Extended Name and UUID
  2015-02-04  9:44 [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Christian Borntraeger
  2015-02-04  9:44 ` [PATCH 1/7] KVM: s390: floating irqs: fix user triggerable endless loop Christian Borntraeger
  2015-02-04  9:44 ` [PATCH 2/7] KVM: s390: reenable LPP facility Christian Borntraeger
@ 2015-02-04  9:44 ` Christian Borntraeger
  2015-02-04 12:57   ` Paolo Bonzini
  2015-02-04  9:44 ` [PATCH 4/7] KVM: s390/CPACF: Choose crypto control block format Christian Borntraeger
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04  9:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Ekaterina Tumanova, Christian Borntraeger

From: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>

Read the additional data fields (Extended Name and UUID) from the
1KB block returned by the STSI command and reflect this information in
the /proc/sysinfo file accordingly

Signed-off-by: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/include/asm/sysinfo.h | 10 +++++++---
 arch/s390/kernel/sysinfo.c      | 29 +++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/arch/s390/include/asm/sysinfo.h b/arch/s390/include/asm/sysinfo.h
index f92428e..9f8f2b5 100644
--- a/arch/s390/include/asm/sysinfo.h
+++ b/arch/s390/include/asm/sysinfo.h
@@ -15,6 +15,7 @@
 #define __ASM_S390_SYSINFO_H
 
 #include <asm/bitsperlong.h>
+#include <linux/uuid.h>
 
 struct sysinfo_1_1_1 {
 	unsigned char p:1;
@@ -112,10 +113,13 @@ struct sysinfo_3_2_2 {
 		char name[8];
 		unsigned int caf;
 		char cpi[16];
-		char reserved_1[24];
-
+		char reserved_1[3];
+		char ext_name_encoding;
+		unsigned int reserved_2;
+		uuid_be uuid;
 	} vm[8];
-	char reserved_544[3552];
+	char reserved_3[1504];
+	char ext_names[8][256];
 };
 
 extern int topology_max_mnest;
diff --git a/arch/s390/kernel/sysinfo.c b/arch/s390/kernel/sysinfo.c
index 811f542..cebab77 100644
--- a/arch/s390/kernel/sysinfo.c
+++ b/arch/s390/kernel/sysinfo.c
@@ -196,6 +196,33 @@ static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
 	seq_printf(m, "LPAR CPUs Shared:     %d\n", info->cpus_shared);
 }
 
+static void print_ext_name(struct seq_file *m, int lvl,
+			   struct sysinfo_3_2_2 *info)
+{
+	if (info->vm[lvl].ext_name_encoding == 0)
+		return;
+	if (info->ext_names[lvl][0] == 0)
+		return;
+	switch (info->vm[lvl].ext_name_encoding) {
+	case 1: /* EBCDIC */
+		EBCASC(info->ext_names[lvl], sizeof(info->ext_names[lvl]));
+		break;
+	case 2:	/* UTF-8 */
+		break;
+	default:
+		return;
+	}
+	seq_printf(m, "VM%02d Extended Name:   %-.256s\n", lvl,
+		   info->ext_names[lvl]);
+}
+
+static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info)
+{
+	if (!memcmp(&info->vm[i].uuid, &NULL_UUID_BE, sizeof(uuid_be)))
+		return;
+	seq_printf(m, "VM%02d UUID:            %pUb\n", i, &info->vm[i].uuid);
+}
+
 static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
 {
 	int i;
@@ -213,6 +240,8 @@ static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
 		seq_printf(m, "VM%02d CPUs Configured: %d\n", i, info->vm[i].cpus_configured);
 		seq_printf(m, "VM%02d CPUs Standby:    %d\n", i, info->vm[i].cpus_standby);
 		seq_printf(m, "VM%02d CPUs Reserved:   %d\n", i, info->vm[i].cpus_reserved);
+		print_ext_name(m, i, info);
+		print_uuid(m, i, info);
 	}
 }
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 4/7] KVM: s390/CPACF: Choose crypto control block format
  2015-02-04  9:44 [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Christian Borntraeger
                   ` (2 preceding siblings ...)
  2015-02-04  9:44 ` [PATCH 3/7] s390/kernel: Update /proc/sysinfo file with Extended Name and UUID Christian Borntraeger
@ 2015-02-04  9:44 ` Christian Borntraeger
  2015-02-04 13:00   ` Paolo Bonzini
  2015-02-04  9:44 ` [PATCH 5/7] KVM: s390: use facilities and cpu_id per KVM Christian Borntraeger
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04  9:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Tony Krowiak, Christian Borntraeger

From: Tony Krowiak <akrowiak@linux.vnet.ibm.com>

We need to specify a different format for the crypto control block
depending on whether the APXA facility is installed or not. Let's test
for it by executing the PQAP(QCI) function and use either a format-1 or
a format-2 crypto control block accordingly.

Signed-off-by: Tony Krowiak <akrowiak@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/include/asm/kvm_host.h |  2 ++
 arch/s390/kvm/kvm-s390.c         | 49 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index d1ecc7f..09b6c1f 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -163,6 +163,7 @@ struct kvm_s390_sie_block {
 	__u64	tecmc;			/* 0x00e8 */
 	__u8	reservedf0[12];		/* 0x00f0 */
 #define CRYCB_FORMAT1 0x00000001
+#define CRYCB_FORMAT2 0x00000003
 	__u32	crycbd;			/* 0x00fc */
 	__u64	gcr[16];		/* 0x0100 */
 	__u64	gbea;			/* 0x0180 */
@@ -515,6 +516,7 @@ struct kvm_s390_crypto_cb {
 	__u8    reserved00[72];                 /* 0x0000 */
 	__u8    dea_wrapping_key_mask[24];      /* 0x0048 */
 	__u8    aes_wrapping_key_mask[32];      /* 0x0060 */
+	__u8    reserved80[128];                /* 0x0080 */
 };
 
 struct kvm_arch{
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 57f5538..57ba533 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -653,6 +653,52 @@ long kvm_arch_vm_ioctl(struct file *filp,
 	return r;
 }
 
+static int kvm_s390_query_ap_config(u8 *config)
+{
+	u32 fcn_code = 0x04000000UL;
+	u32 cc;
+
+	asm volatile(
+		"lgr 0,%1\n"
+		"lgr 2,%2\n"
+		".long 0xb2af0000\n"		/* PQAP(QCI) */
+		"ipm %0\n"
+		"srl %0,28\n"
+		: "=r" (cc)
+		: "r" (fcn_code), "r" (config)
+		: "cc", "0", "2", "memory"
+	);
+
+	return cc;
+}
+
+static int kvm_s390_apxa_installed(void)
+{
+	u8 config[128];
+	int cc;
+
+	if (test_facility(2) && test_facility(12)) {
+		cc = kvm_s390_query_ap_config(config);
+
+		if (cc)
+			pr_err("PQAP(QCI) failed with cc=%d", cc);
+		else
+			return config[0] & 0x40;
+	}
+
+	return 0;
+}
+
+static void kvm_s390_set_crycb_format(struct kvm *kvm)
+{
+	kvm->arch.crypto.crycbd = (__u32)(unsigned long) kvm->arch.crypto.crycb;
+
+	if (kvm_s390_apxa_installed())
+		kvm->arch.crypto.crycbd |= CRYCB_FORMAT2;
+	else
+		kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
+}
+
 static int kvm_s390_crypto_init(struct kvm *kvm)
 {
 	if (!test_vfacility(76))
@@ -663,8 +709,7 @@ static int kvm_s390_crypto_init(struct kvm *kvm)
 	if (!kvm->arch.crypto.crycb)
 		return -ENOMEM;
 
-	kvm->arch.crypto.crycbd = (__u32) (unsigned long) kvm->arch.crypto.crycb |
-				  CRYCB_FORMAT1;
+	kvm_s390_set_crycb_format(kvm);
 
 	/* Disable AES/DEA protected key functions by default */
 	kvm->arch.crypto.aes_kw = 0;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 5/7] KVM: s390: use facilities and cpu_id per KVM
  2015-02-04  9:44 [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Christian Borntraeger
                   ` (3 preceding siblings ...)
  2015-02-04  9:44 ` [PATCH 4/7] KVM: s390/CPACF: Choose crypto control block format Christian Borntraeger
@ 2015-02-04  9:44 ` Christian Borntraeger
  2015-02-04  9:44 ` [PATCH 6/7] KVM: s390: add cpu model support Christian Borntraeger
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04  9:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Michael Mueller, Christian Borntraeger

From: Michael Mueller <mimu@linux.vnet.ibm.com>

The patch introduces facilities and cpu_ids per virtual machine.
Different virtual machines may want to expose different facilities and
cpu ids to the guest, so let's make them per-vm instead of global.

Signed-off-by: Michael Mueller <mimu@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/include/asm/kvm_host.h | 21 +++++++++
 arch/s390/kvm/gaccess.c          |  4 +-
 arch/s390/kvm/kvm-s390.c         | 92 +++++++++++++++++++++++++---------------
 arch/s390/kvm/kvm-s390.h         | 13 ++++--
 arch/s390/kvm/priv.c             | 13 ++++--
 5 files changed, 99 insertions(+), 44 deletions(-)

diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 09b6c1f..995a598 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -505,6 +505,26 @@ struct s390_io_adapter {
 #define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
 #define MAX_S390_ADAPTER_MAPS 256
 
+/* maximum size of facilities and facility mask is 2k bytes */
+#define S390_ARCH_FAC_LIST_SIZE_BYTE (1<<11)
+#define S390_ARCH_FAC_LIST_SIZE_U64 \
+	(S390_ARCH_FAC_LIST_SIZE_BYTE / sizeof(u64))
+#define S390_ARCH_FAC_MASK_SIZE_BYTE S390_ARCH_FAC_LIST_SIZE_BYTE
+#define S390_ARCH_FAC_MASK_SIZE_U64 \
+	(S390_ARCH_FAC_MASK_SIZE_BYTE / sizeof(u64))
+
+struct s390_model_fac {
+	/* facilities used in SIE context */
+	__u64 sie[S390_ARCH_FAC_LIST_SIZE_U64];
+	/* subset enabled by kvm */
+	__u64 kvm[S390_ARCH_FAC_LIST_SIZE_U64];
+};
+
+struct kvm_s390_cpu_model {
+	struct s390_model_fac *fac;
+	struct cpuid cpu_id;
+};
+
 struct kvm_s390_crypto {
 	struct kvm_s390_crypto_cb *crycb;
 	__u32 crycbd;
@@ -535,6 +555,7 @@ struct kvm_arch{
 	int ipte_lock_count;
 	struct mutex ipte_mutex;
 	spinlock_t start_stop_lock;
+	struct kvm_s390_cpu_model model;
 	struct kvm_s390_crypto crypto;
 	u64 epoch;
 };
diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
index 8a1be90..267523c 100644
--- a/arch/s390/kvm/gaccess.c
+++ b/arch/s390/kvm/gaccess.c
@@ -357,8 +357,8 @@ static unsigned long guest_translate(struct kvm_vcpu *vcpu, unsigned long gva,
 	union asce asce;
 
 	ctlreg0.val = vcpu->arch.sie_block->gcr[0];
-	edat1 = ctlreg0.edat && test_vfacility(8);
-	edat2 = edat1 && test_vfacility(78);
+	edat1 = ctlreg0.edat && test_kvm_facility(vcpu->kvm, 8);
+	edat2 = edat1 && test_kvm_facility(vcpu->kvm, 78);
 	asce.val = get_vcpu_asce(vcpu);
 	if (asce.r)
 		goto real_address;
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 57ba533..ab8b016 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -30,7 +30,6 @@
 #include <asm/pgtable.h>
 #include <asm/nmi.h>
 #include <asm/switch_to.h>
-#include <asm/facility.h>
 #include <asm/sclp.h>
 #include "kvm-s390.h"
 #include "gaccess.h"
@@ -99,15 +98,20 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
 	{ NULL }
 };
 
-unsigned long *vfacilities;
-static struct gmap_notifier gmap_notifier;
+/* upper facilities limit for kvm */
+unsigned long kvm_s390_fac_list_mask[] = {
+	0xff82fffbf4fc2000UL,
+	0x005c000000000000UL,
+};
 
-/* test availability of vfacility */
-int test_vfacility(unsigned long nr)
+unsigned long kvm_s390_fac_list_mask_size(void)
 {
-	return __test_facility(nr, (void *) vfacilities);
+	BUILD_BUG_ON(ARRAY_SIZE(kvm_s390_fac_list_mask) > S390_ARCH_FAC_MASK_SIZE_U64);
+	return ARRAY_SIZE(kvm_s390_fac_list_mask);
 }
 
+static struct gmap_notifier gmap_notifier;
+
 /* Section: not file related */
 int kvm_arch_hardware_enable(void)
 {
@@ -350,7 +354,7 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
 	struct kvm_vcpu *vcpu;
 	int i;
 
-	if (!test_vfacility(76))
+	if (!test_kvm_facility(kvm, 76))
 		return -EINVAL;
 
 	mutex_lock(&kvm->lock);
@@ -699,9 +703,15 @@ static void kvm_s390_set_crycb_format(struct kvm *kvm)
 		kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
 }
 
+static void kvm_s390_get_cpu_id(struct cpuid *cpu_id)
+{
+	get_cpu_id(cpu_id);
+	cpu_id->version = 0xff;
+}
+
 static int kvm_s390_crypto_init(struct kvm *kvm)
 {
-	if (!test_vfacility(76))
+	if (!test_kvm_facility(kvm, 76))
 		return 0;
 
 	kvm->arch.crypto.crycb = kzalloc(sizeof(*kvm->arch.crypto.crycb),
@@ -720,7 +730,7 @@ static int kvm_s390_crypto_init(struct kvm *kvm)
 
 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 {
-	int rc;
+	int i, rc;
 	char debug_name[16];
 	static unsigned long sca_offset;
 
@@ -755,6 +765,34 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 	if (!kvm->arch.dbf)
 		goto out_nodbf;
 
+	/*
+	 * The architectural maximum amount of facilities is 16 kbit. To store
+	 * this amount, 2 kbyte of memory is required. Thus we need a full
+	 * page to hold the active copy (arch.model.fac->sie) and the current
+	 * facilities set (arch.model.fac->kvm). Its address size has to be
+	 * 31 bits and word aligned.
+	 */
+	kvm->arch.model.fac =
+		(struct s390_model_fac *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
+	if (!kvm->arch.model.fac)
+		goto out_nofac;
+
+	memcpy(kvm->arch.model.fac->kvm, S390_lowcore.stfle_fac_list,
+	       S390_ARCH_FAC_LIST_SIZE_U64);
+
+	/*
+	 * Apply the kvm facility mask to limit the kvm supported/tolerated
+	 * facility list.
+	 */
+	for (i = 0; i < S390_ARCH_FAC_LIST_SIZE_U64; i++) {
+		if (i < kvm_s390_fac_list_mask_size())
+			kvm->arch.model.fac->kvm[i] &= kvm_s390_fac_list_mask[i];
+		else
+			kvm->arch.model.fac->kvm[i] = 0UL;
+	}
+
+	kvm_s390_get_cpu_id(&kvm->arch.model.cpu_id);
+
 	if (kvm_s390_crypto_init(kvm) < 0)
 		goto out_crypto;
 
@@ -786,6 +824,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 out_nogmap:
 	kfree(kvm->arch.crypto.crycb);
 out_crypto:
+	free_page((unsigned long)kvm->arch.model.fac);
+out_nofac:
 	debug_unregister(kvm->arch.dbf);
 out_nodbf:
 	free_page((unsigned long)(kvm->arch.sca));
@@ -838,6 +878,7 @@ static void kvm_free_vcpus(struct kvm *kvm)
 void kvm_arch_destroy_vm(struct kvm *kvm)
 {
 	kvm_free_vcpus(kvm);
+	free_page((unsigned long)kvm->arch.model.fac);
 	free_page((unsigned long)(kvm->arch.sca));
 	debug_unregister(kvm->arch.dbf);
 	kfree(kvm->arch.crypto.crycb);
@@ -933,7 +974,7 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
 
 static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
 {
-	if (!test_vfacility(76))
+	if (!test_kvm_facility(vcpu->kvm, 76))
 		return;
 
 	vcpu->arch.sie_block->ecb3 &= ~(ECB3_AES | ECB3_DEA);
@@ -972,7 +1013,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 						    CPUSTAT_STOPPED |
 						    CPUSTAT_GED);
 	vcpu->arch.sie_block->ecb   = 6;
-	if (test_vfacility(50) && test_vfacility(73))
+	if (test_kvm_facility(vcpu->kvm, 50) && test_kvm_facility(vcpu->kvm, 73))
 		vcpu->arch.sie_block->ecb |= 0x10;
 
 	vcpu->arch.sie_block->ecb2  = 8;
@@ -981,7 +1022,6 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 		vcpu->arch.sie_block->eca |= 1;
 	if (sclp_has_sigpif())
 		vcpu->arch.sie_block->eca |= 0x10000000U;
-	vcpu->arch.sie_block->fac   = (int) (long) vfacilities;
 	vcpu->arch.sie_block->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE |
 				      ICTL_TPROT;
 
@@ -992,8 +1032,10 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 	}
 	hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	vcpu->arch.ckc_timer.function = kvm_s390_idle_wakeup;
-	get_cpu_id(&vcpu->arch.cpu_id);
-	vcpu->arch.cpu_id.version = 0xff;
+
+	vcpu->arch.cpu_id = vcpu->kvm->arch.model.cpu_id;
+	memcpy(vcpu->kvm->arch.model.fac->sie, vcpu->kvm->arch.model.fac->kvm,
+	       S390_ARCH_FAC_LIST_SIZE_BYTE);
 
 	kvm_s390_vcpu_crypto_setup(vcpu);
 
@@ -1037,6 +1079,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
 		vcpu->arch.sie_block->scaol = (__u32)(__u64)kvm->arch.sca;
 		set_bit(63 - id, (unsigned long *) &kvm->arch.sca->mcn);
 	}
+	vcpu->arch.sie_block->fac = (int) (long) kvm->arch.model.fac->sie;
 
 	spin_lock_init(&vcpu->arch.local_int.lock);
 	vcpu->arch.local_int.float_int = &kvm->arch.float_int;
@@ -2102,30 +2145,11 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
 
 static int __init kvm_s390_init(void)
 {
-	int ret;
-	ret = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE);
-	if (ret)
-		return ret;
-
-	/*
-	 * guests can ask for up to 255+1 double words, we need a full page
-	 * to hold the maximum amount of facilities. On the other hand, we
-	 * only set facilities that are known to work in KVM.
-	 */
-	vfacilities = (unsigned long *) get_zeroed_page(GFP_KERNEL|GFP_DMA);
-	if (!vfacilities) {
-		kvm_exit();
-		return -ENOMEM;
-	}
-	memcpy(vfacilities, S390_lowcore.stfle_fac_list, 16);
-	vfacilities[0] &= 0xff82fffbf4fc2000UL;
-	vfacilities[1] &= 0x005c000000000000UL;
-	return 0;
+	return kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE);
 }
 
 static void __exit kvm_s390_exit(void)
 {
-	free_page((unsigned long) vfacilities);
 	kvm_exit();
 }
 
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index c22dce8..985c211 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -18,12 +18,10 @@
 #include <linux/hrtimer.h>
 #include <linux/kvm.h>
 #include <linux/kvm_host.h>
+#include <asm/facility.h>
 
 typedef int (*intercept_handler_t)(struct kvm_vcpu *vcpu);
 
-/* declare vfacilities extern */
-extern unsigned long *vfacilities;
-
 /* Transactional Memory Execution related macros */
 #define IS_TE_ENABLED(vcpu)	((vcpu->arch.sie_block->ecb & 0x10))
 #define TDB_FORMAT1		1
@@ -127,6 +125,12 @@ static inline void kvm_s390_set_psw_cc(struct kvm_vcpu *vcpu, unsigned long cc)
 	vcpu->arch.sie_block->gpsw.mask |= cc << 44;
 }
 
+/* test availability of facility in a kvm intance */
+static inline int test_kvm_facility(struct kvm *kvm, unsigned long nr)
+{
+	return __test_facility(nr, kvm->arch.model.fac->kvm);
+}
+
 /* are cpu states controlled by user space */
 static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm)
 {
@@ -183,7 +187,8 @@ int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu);
 void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu);
 /* is cmma enabled */
 bool kvm_s390_cmma_enabled(struct kvm *kvm);
-int test_vfacility(unsigned long nr);
+unsigned long kvm_s390_fac_list_mask_size(void);
+extern unsigned long kvm_s390_fac_list_mask[];
 
 /* implemented in diag.c */
 int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 1be578d..bdd9b5b 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -337,19 +337,24 @@ static int handle_io_inst(struct kvm_vcpu *vcpu)
 static int handle_stfl(struct kvm_vcpu *vcpu)
 {
 	int rc;
+	unsigned int fac;
 
 	vcpu->stat.instruction_stfl++;
 
 	if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
 		return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
 
+	/*
+	 * We need to shift the lower 32 facility bits (bit 0-31) from a u64
+	 * into a u32 memory representation. They will remain bits 0-31.
+	 */
+	fac = *vcpu->kvm->arch.model.fac->sie >> 32;
 	rc = write_guest_lc(vcpu, offsetof(struct _lowcore, stfl_fac_list),
-			    vfacilities, 4);
+			    &fac, sizeof(fac));
 	if (rc)
 		return rc;
-	VCPU_EVENT(vcpu, 5, "store facility list value %x",
-		   *(unsigned int *) vfacilities);
-	trace_kvm_s390_handle_stfl(vcpu, *(unsigned int *) vfacilities);
+	VCPU_EVENT(vcpu, 5, "store facility list value %x", fac);
+	trace_kvm_s390_handle_stfl(vcpu, fac);
 	return 0;
 }
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 6/7] KVM: s390: add cpu model support
  2015-02-04  9:44 [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Christian Borntraeger
                   ` (4 preceding siblings ...)
  2015-02-04  9:44 ` [PATCH 5/7] KVM: s390: use facilities and cpu_id per KVM Christian Borntraeger
@ 2015-02-04  9:44 ` Christian Borntraeger
  2015-02-04  9:44 ` [PATCH 7/7] KVM: s390: Create ioctl for Getting/Setting guest storage keys Christian Borntraeger
  2015-02-04 13:03 ` [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Paolo Bonzini
  7 siblings, 0 replies; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04  9:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Michael Mueller, Christian Borntraeger

From: Michael Mueller <mimu@linux.vnet.ibm.com>

This patch enables cpu model support in kvm/s390 via the vm attribute
interface.

During KVM initialization, the host properties cpuid, IBC value and the
facility list are stored in the architecture specific cpu model structure.

During vcpu setup, these properties are taken to initialize the related SIE
state. This mechanism allows to adjust the properties from user space and thus
to implement different selectable cpu models.

This patch uses the IBC functionality to block instructions that have not
been implemented at the requested CPU type and GA level compared to the
full host capability.

Userspace has to initialize the cpu model before vcpu creation. A cpu model
change of running vcpus is not possible.

Signed-off-by: Michael Mueller <mimu@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 Documentation/virtual/kvm/devices/vm.txt |  45 +++++++++++
 arch/s390/include/asm/kvm_host.h         |   4 +-
 arch/s390/include/uapi/asm/kvm.h         |  21 +++++
 arch/s390/kvm/kvm-s390.c                 | 132 +++++++++++++++++++++++++++++++
 4 files changed, 201 insertions(+), 1 deletion(-)

diff --git a/Documentation/virtual/kvm/devices/vm.txt b/Documentation/virtual/kvm/devices/vm.txt
index c3b17c6..5542c46 100644
--- a/Documentation/virtual/kvm/devices/vm.txt
+++ b/Documentation/virtual/kvm/devices/vm.txt
@@ -38,3 +38,48 @@ Allows userspace to query the actual limit and set a new limit for
 the maximum guest memory size. The limit will be rounded up to
 2048 MB, 4096 GB, 8192 TB respectively, as this limit is governed by
 the number of page table levels.
+
+2. GROUP: KVM_S390_VM_CPU_MODEL
+Architectures: s390
+
+2.1. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE (r/o)
+
+Allows user space to retrieve machine and kvm specific cpu related information:
+
+struct kvm_s390_vm_cpu_machine {
+       __u64 cpuid;           # CPUID of host
+       __u32 ibc;             # IBC level range offered by host
+       __u8  pad[4];
+       __u64 fac_mask[256];   # set of cpu facilities enabled by KVM
+       __u64 fac_list[256];   # set of cpu facilities offered by host
+}
+
+Parameters: address of buffer to store the machine related cpu data
+            of type struct kvm_s390_vm_cpu_machine*
+Returns:    -EFAULT if the given address is not accessible from kernel space
+	    -ENOMEM if not enough memory is available to process the ioctl
+	    0 in case of success
+
+2.2. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR (r/w)
+
+Allows user space to retrieve or request to change cpu related information for a vcpu:
+
+struct kvm_s390_vm_cpu_processor {
+       __u64 cpuid;           # CPUID currently (to be) used by this vcpu
+       __u16 ibc;             # IBC level currently (to be) used by this vcpu
+       __u8  pad[6];
+       __u64 fac_list[256];   # set of cpu facilities currently (to be) used
+                              # by this vcpu
+}
+
+KVM does not enforce or limit the cpu model data in any form. Take the information
+retrieved by means of KVM_S390_VM_CPU_MACHINE as hint for reasonable configuration
+setups. Instruction interceptions triggered by additionally set facilitiy bits that
+are not handled by KVM need to by imlemented in the VM driver code.
+
+Parameters: address of buffer to store/set the processor related cpu
+	    data of type struct kvm_s390_vm_cpu_processor*.
+Returns:    -EBUSY in case 1 or more vcpus are already activated (only in write case)
+	    -EFAULT if the given address is not accessible from kernel space
+	    -ENOMEM if not enough memory is available to process the ioctl
+	    0 in case of success
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 995a598..fcfff71 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -89,7 +89,8 @@ struct kvm_s390_sie_block {
 	atomic_t cpuflags;		/* 0x0000 */
 	__u32 : 1;			/* 0x0004 */
 	__u32 prefix : 18;
-	__u32 : 13;
+	__u32 : 1;
+	__u32 ibc : 12;
 	__u8	reserved08[4];		/* 0x0008 */
 #define PROG_IN_SIE (1<<0)
 	__u32	prog0c;			/* 0x000c */
@@ -523,6 +524,7 @@ struct s390_model_fac {
 struct kvm_s390_cpu_model {
 	struct s390_model_fac *fac;
 	struct cpuid cpu_id;
+	unsigned short ibc;
 };
 
 struct kvm_s390_crypto {
diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
index 546fc3a..9c77e60 100644
--- a/arch/s390/include/uapi/asm/kvm.h
+++ b/arch/s390/include/uapi/asm/kvm.h
@@ -59,6 +59,7 @@ struct kvm_s390_io_adapter_req {
 #define KVM_S390_VM_MEM_CTRL		0
 #define KVM_S390_VM_TOD			1
 #define KVM_S390_VM_CRYPTO		2
+#define KVM_S390_VM_CPU_MODEL		3
 
 /* kvm attributes for mem_ctrl */
 #define KVM_S390_VM_MEM_ENABLE_CMMA	0
@@ -69,6 +70,26 @@ struct kvm_s390_io_adapter_req {
 #define KVM_S390_VM_TOD_LOW		0
 #define KVM_S390_VM_TOD_HIGH		1
 
+/* kvm attributes for KVM_S390_VM_CPU_MODEL */
+/* processor related attributes are r/w */
+#define KVM_S390_VM_CPU_PROCESSOR	0
+struct kvm_s390_vm_cpu_processor {
+	__u64 cpuid;
+	__u16 ibc;
+	__u8  pad[6];
+	__u64 fac_list[256];
+};
+
+/* machine related attributes are r/o */
+#define KVM_S390_VM_CPU_MACHINE		1
+struct kvm_s390_vm_cpu_machine {
+	__u64 cpuid;
+	__u32 ibc;
+	__u8  pad[4];
+	__u64 fac_mask[256];
+	__u64 fac_list[256];
+};
+
 /* kvm attributes for crypto */
 #define KVM_S390_VM_CRYPTO_ENABLE_AES_KW	0
 #define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW	1
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index ab8b016..9da937a 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -501,6 +501,106 @@ static int kvm_s390_get_tod(struct kvm *kvm, struct kvm_device_attr *attr)
 	return ret;
 }
 
+static int kvm_s390_set_processor(struct kvm *kvm, struct kvm_device_attr *attr)
+{
+	struct kvm_s390_vm_cpu_processor *proc;
+	int ret = 0;
+
+	mutex_lock(&kvm->lock);
+	if (atomic_read(&kvm->online_vcpus)) {
+		ret = -EBUSY;
+		goto out;
+	}
+	proc = kzalloc(sizeof(*proc), GFP_KERNEL);
+	if (!proc) {
+		ret = -ENOMEM;
+		goto out;
+	}
+	if (!copy_from_user(proc, (void __user *)attr->addr,
+			    sizeof(*proc))) {
+		memcpy(&kvm->arch.model.cpu_id, &proc->cpuid,
+		       sizeof(struct cpuid));
+		kvm->arch.model.ibc = proc->ibc;
+		memcpy(kvm->arch.model.fac->kvm, proc->fac_list,
+		       S390_ARCH_FAC_LIST_SIZE_BYTE);
+	} else
+		ret = -EFAULT;
+	kfree(proc);
+out:
+	mutex_unlock(&kvm->lock);
+	return ret;
+}
+
+static int kvm_s390_set_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr)
+{
+	int ret = -ENXIO;
+
+	switch (attr->attr) {
+	case KVM_S390_VM_CPU_PROCESSOR:
+		ret = kvm_s390_set_processor(kvm, attr);
+		break;
+	}
+	return ret;
+}
+
+static int kvm_s390_get_processor(struct kvm *kvm, struct kvm_device_attr *attr)
+{
+	struct kvm_s390_vm_cpu_processor *proc;
+	int ret = 0;
+
+	proc = kzalloc(sizeof(*proc), GFP_KERNEL);
+	if (!proc) {
+		ret = -ENOMEM;
+		goto out;
+	}
+	memcpy(&proc->cpuid, &kvm->arch.model.cpu_id, sizeof(struct cpuid));
+	proc->ibc = kvm->arch.model.ibc;
+	memcpy(&proc->fac_list, kvm->arch.model.fac->kvm, S390_ARCH_FAC_LIST_SIZE_BYTE);
+	if (copy_to_user((void __user *)attr->addr, proc, sizeof(*proc)))
+		ret = -EFAULT;
+	kfree(proc);
+out:
+	return ret;
+}
+
+static int kvm_s390_get_machine(struct kvm *kvm, struct kvm_device_attr *attr)
+{
+	struct kvm_s390_vm_cpu_machine *mach;
+	int ret = 0;
+
+	mach = kzalloc(sizeof(*mach), GFP_KERNEL);
+	if (!mach) {
+		ret = -ENOMEM;
+		goto out;
+	}
+	get_cpu_id((struct cpuid *) &mach->cpuid);
+	mach->ibc = sclp_get_ibc();
+	memcpy(&mach->fac_mask, kvm_s390_fac_list_mask,
+	       kvm_s390_fac_list_mask_size() * sizeof(u64));
+	memcpy((unsigned long *)&mach->fac_list, S390_lowcore.stfle_fac_list,
+	       S390_ARCH_FAC_LIST_SIZE_U64);
+	if (copy_to_user((void __user *)attr->addr, mach, sizeof(*mach)))
+		ret = -EFAULT;
+	kfree(mach);
+out:
+	return ret;
+}
+
+static int kvm_s390_get_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr)
+{
+	int ret = -ENXIO;
+
+	switch (attr->attr) {
+	case KVM_S390_VM_CPU_PROCESSOR:
+		ret = kvm_s390_get_processor(kvm, attr);
+		break;
+	case KVM_S390_VM_CPU_MACHINE:
+		ret = kvm_s390_get_machine(kvm, attr);
+		break;
+	}
+	return ret;
+}
+
 static int kvm_s390_vm_set_attr(struct kvm *kvm, struct kvm_device_attr *attr)
 {
 	int ret;
@@ -512,6 +612,9 @@ static int kvm_s390_vm_set_attr(struct kvm *kvm, struct kvm_device_attr *attr)
 	case KVM_S390_VM_TOD:
 		ret = kvm_s390_set_tod(kvm, attr);
 		break;
+	case KVM_S390_VM_CPU_MODEL:
+		ret = kvm_s390_set_cpu_model(kvm, attr);
+		break;
 	case KVM_S390_VM_CRYPTO:
 		ret = kvm_s390_vm_set_crypto(kvm, attr);
 		break;
@@ -534,6 +637,9 @@ static int kvm_s390_vm_get_attr(struct kvm *kvm, struct kvm_device_attr *attr)
 	case KVM_S390_VM_TOD:
 		ret = kvm_s390_get_tod(kvm, attr);
 		break;
+	case KVM_S390_VM_CPU_MODEL:
+		ret = kvm_s390_get_cpu_model(kvm, attr);
+		break;
 	default:
 		ret = -ENXIO;
 		break;
@@ -570,6 +676,17 @@ static int kvm_s390_vm_has_attr(struct kvm *kvm, struct kvm_device_attr *attr)
 			break;
 		}
 		break;
+	case KVM_S390_VM_CPU_MODEL:
+		switch (attr->attr) {
+		case KVM_S390_VM_CPU_PROCESSOR:
+		case KVM_S390_VM_CPU_MACHINE:
+			ret = 0;
+			break;
+		default:
+			ret = -ENXIO;
+			break;
+		}
+		break;
 	case KVM_S390_VM_CRYPTO:
 		switch (attr->attr) {
 		case KVM_S390_VM_CRYPTO_ENABLE_AES_KW:
@@ -781,6 +898,17 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 	       S390_ARCH_FAC_LIST_SIZE_U64);
 
 	/*
+	 * If this KVM host runs *not* in a LPAR, relax the facility bits
+	 * of the kvm facility mask by all missing facilities. This will allow
+	 * to determine the right CPU model by means of the remaining facilities.
+	 * Live guest migration must prohibit the migration of KVMs running in
+	 * a LPAR to non LPAR hosts.
+	 */
+	if (!MACHINE_IS_LPAR)
+		for (i = 0; i < kvm_s390_fac_list_mask_size(); i++)
+			kvm_s390_fac_list_mask[i] &= kvm->arch.model.fac->kvm[i];
+
+	/*
 	 * Apply the kvm facility mask to limit the kvm supported/tolerated
 	 * facility list.
 	 */
@@ -792,6 +920,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 	}
 
 	kvm_s390_get_cpu_id(&kvm->arch.model.cpu_id);
+	kvm->arch.model.ibc = sclp_get_ibc() & 0x0fff;
 
 	if (kvm_s390_crypto_init(kvm) < 0)
 		goto out_crypto;
@@ -1033,9 +1162,12 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 	hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	vcpu->arch.ckc_timer.function = kvm_s390_idle_wakeup;
 
+	mutex_lock(&vcpu->kvm->lock);
 	vcpu->arch.cpu_id = vcpu->kvm->arch.model.cpu_id;
 	memcpy(vcpu->kvm->arch.model.fac->sie, vcpu->kvm->arch.model.fac->kvm,
 	       S390_ARCH_FAC_LIST_SIZE_BYTE);
+	vcpu->arch.sie_block->ibc = vcpu->kvm->arch.model.ibc;
+	mutex_unlock(&vcpu->kvm->lock);
 
 	kvm_s390_vcpu_crypto_setup(vcpu);
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 7/7] KVM: s390: Create ioctl for Getting/Setting guest storage keys
  2015-02-04  9:44 [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Christian Borntraeger
                   ` (5 preceding siblings ...)
  2015-02-04  9:44 ` [PATCH 6/7] KVM: s390: add cpu model support Christian Borntraeger
@ 2015-02-04  9:44 ` Christian Borntraeger
  2015-02-04 13:03 ` [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Paolo Bonzini
  7 siblings, 0 replies; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04  9:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Jason J. Herne, Christian Borntraeger

From: "Jason J. Herne" <jjherne@linux.vnet.ibm.com>

Provide the KVM_S390_GET_SKEYS and KVM_S390_SET_SKEYS ioctl which can be used
to get/set guest storage keys. This functionality is needed for live migration
of s390 guests that use storage keys.

Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 Documentation/virtual/kvm/api.txt |  58 ++++++++++++++++++
 arch/s390/kvm/kvm-s390.c          | 121 ++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/kvm.h          |  14 +++++
 3 files changed, 193 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index b112efc..20c0dac 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -2716,6 +2716,64 @@ The fields in each entry are defined as follows:
    eax, ebx, ecx, edx: the values returned by the cpuid instruction for
          this function/index combination
 
+4.89 KVM_S390_GET_SKEYS
+
+Capability: KVM_CAP_S390_SKEYS
+Architectures: s390
+Type: vm ioctl
+Parameters: struct kvm_s390_skeys
+Returns: 0 on success, KVM_S390_GET_KEYS_NONE if guest is not using storage
+         keys, negative value on error
+
+This ioctl is used to get guest storage key values on the s390
+architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
+
+struct kvm_s390_skeys {
+	__u64 start_gfn;
+	__u64 count;
+	__u64 skeydata_addr;
+	__u32 flags;
+	__u32 reserved[9];
+};
+
+The start_gfn field is the number of the first guest frame whose storage keys
+you want to get.
+
+The count field is the number of consecutive frames (starting from start_gfn)
+whose storage keys to get. The count field must be at least 1 and the maximum
+allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
+will cause the ioctl to return -EINVAL.
+
+The skeydata_addr field is the address to a buffer large enough to hold count
+bytes. This buffer will be filled with storage key data by the ioctl.
+
+4.90 KVM_S390_SET_SKEYS
+
+Capability: KVM_CAP_S390_SKEYS
+Architectures: s390
+Type: vm ioctl
+Parameters: struct kvm_s390_skeys
+Returns: 0 on success, negative value on error
+
+This ioctl is used to set guest storage key values on the s390
+architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
+See section on KVM_S390_GET_SKEYS for struct definition.
+
+The start_gfn field is the number of the first guest frame whose storage keys
+you want to set.
+
+The count field is the number of consecutive frames (starting from start_gfn)
+whose storage keys to get. The count field must be at least 1 and the maximum
+allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
+will cause the ioctl to return -EINVAL.
+
+The skeydata_addr field is the address to a buffer containing count bytes of
+storage keys. Each byte in the buffer will be set as the storage key for a
+single frame starting at start_gfn for count frames.
+
+Note: If any architecturally invalid key value is found in the given data then
+the ioctl will return -EINVAL.
+
 5. The kvm_run structure
 ------------------------
 
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 9da937a..97c9795 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -25,6 +25,7 @@
 #include <linux/random.h>
 #include <linux/slab.h>
 #include <linux/timer.h>
+#include <linux/vmalloc.h>
 #include <asm/asm-offsets.h>
 #include <asm/lowcore.h>
 #include <asm/pgtable.h>
@@ -708,6 +709,106 @@ static int kvm_s390_vm_has_attr(struct kvm *kvm, struct kvm_device_attr *attr)
 	return ret;
 }
 
+static long kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
+{
+	uint8_t *keys;
+	uint64_t hva;
+	unsigned long curkey;
+	int i, r = 0;
+
+	if (args->flags != 0)
+		return -EINVAL;
+
+	/* Is this guest using storage keys? */
+	if (!mm_use_skey(current->mm))
+		return KVM_S390_GET_SKEYS_NONE;
+
+	/* Enforce sane limit on memory allocation */
+	if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
+		return -EINVAL;
+
+	keys = kmalloc_array(args->count, sizeof(uint8_t), GFP_KERNEL);
+	if (!keys)
+		keys = vmalloc(sizeof(uint8_t) * args->count);
+	if (!keys)
+		return -ENOMEM;
+
+	for (i = 0; i < args->count; i++) {
+		hva = gfn_to_hva(kvm, args->start_gfn + i);
+		if (kvm_is_error_hva(hva)) {
+			r = -EFAULT;
+			goto out;
+		}
+
+		curkey = get_guest_storage_key(current->mm, hva);
+		if (IS_ERR_VALUE(curkey)) {
+			r = curkey;
+			goto out;
+		}
+		keys[i] = curkey;
+	}
+
+	r = copy_to_user((uint8_t __user *)args->skeydata_addr, keys,
+			 sizeof(uint8_t) * args->count);
+	if (r)
+		r = -EFAULT;
+out:
+	kvfree(keys);
+	return r;
+}
+
+static long kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
+{
+	uint8_t *keys;
+	uint64_t hva;
+	int i, r = 0;
+
+	if (args->flags != 0)
+		return -EINVAL;
+
+	/* Enforce sane limit on memory allocation */
+	if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
+		return -EINVAL;
+
+	keys = kmalloc_array(args->count, sizeof(uint8_t), GFP_KERNEL);
+	if (!keys)
+		keys = vmalloc(sizeof(uint8_t) * args->count);
+	if (!keys)
+		return -ENOMEM;
+
+	r = copy_from_user(keys, (uint8_t __user *)args->skeydata_addr,
+			   sizeof(uint8_t) * args->count);
+	if (r) {
+		r = -EFAULT;
+		goto out;
+	}
+
+	/* Enable storage key handling for the guest */
+	s390_enable_skey();
+
+	for (i = 0; i < args->count; i++) {
+		hva = gfn_to_hva(kvm, args->start_gfn + i);
+		if (kvm_is_error_hva(hva)) {
+			r = -EFAULT;
+			goto out;
+		}
+
+		/* Lowest order bit is reserved */
+		if (keys[i] & 0x01) {
+			r = -EINVAL;
+			goto out;
+		}
+
+		r = set_guest_storage_key(current->mm, hva,
+					  (unsigned long)keys[i], 0);
+		if (r)
+			goto out;
+	}
+out:
+	kvfree(keys);
+	return r;
+}
+
 long kvm_arch_vm_ioctl(struct file *filp,
 		       unsigned int ioctl, unsigned long arg)
 {
@@ -767,6 +868,26 @@ long kvm_arch_vm_ioctl(struct file *filp,
 		r = kvm_s390_vm_has_attr(kvm, &attr);
 		break;
 	}
+	case KVM_S390_GET_SKEYS: {
+		struct kvm_s390_skeys args;
+
+		r = -EFAULT;
+		if (copy_from_user(&args, argp,
+				   sizeof(struct kvm_s390_skeys)))
+			break;
+		r = kvm_s390_get_skeys(kvm, &args);
+		break;
+	}
+	case KVM_S390_SET_SKEYS: {
+		struct kvm_s390_skeys args;
+
+		r = -EFAULT;
+		if (copy_from_user(&args, argp,
+				   sizeof(struct kvm_s390_skeys)))
+			break;
+		r = kvm_s390_set_skeys(kvm, &args);
+		break;
+	}
 	default:
 		r = -ENOTTY;
 	}
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 8055706..e1d696b 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -147,6 +147,16 @@ struct kvm_pit_config {
 
 #define KVM_PIT_SPEAKER_DUMMY     1
 
+struct kvm_s390_skeys {
+	__u64 start_gfn;
+	__u64 count;
+	__u64 skeydata_addr;
+	__u32 flags;
+	__u32 reserved[9];
+};
+#define KVM_S390_GET_SKEYS_NONE   1
+#define KVM_S390_SKEYS_MAX        1048576
+
 #define KVM_EXIT_UNKNOWN          0
 #define KVM_EXIT_EXCEPTION        1
 #define KVM_EXIT_IO               2
@@ -760,6 +770,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_PPC_ENABLE_HCALL 104
 #define KVM_CAP_CHECK_EXTENSION_VM 105
 #define KVM_CAP_S390_USER_SIGP 106
+#define KVM_CAP_S390_SKEYS 107
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -1135,6 +1146,9 @@ struct kvm_s390_ucas_mapping {
 #define KVM_ARM_VCPU_INIT	  _IOW(KVMIO,  0xae, struct kvm_vcpu_init)
 #define KVM_ARM_PREFERRED_TARGET  _IOR(KVMIO,  0xaf, struct kvm_vcpu_init)
 #define KVM_GET_REG_LIST	  _IOWR(KVMIO, 0xb0, struct kvm_reg_list)
+/* Available with KVM_CAP_S390_SKEYS */
+#define KVM_S390_GET_SKEYS      _IOW(KVMIO, 0xb1, struct kvm_s390_skeys)
+#define KVM_S390_SET_SKEYS      _IOW(KVMIO, 0xb2, struct kvm_s390_skeys)
 
 #define KVM_DEV_ASSIGN_ENABLE_IOMMU	(1 << 0)
 #define KVM_DEV_ASSIGN_PCI_2_3		(1 << 1)
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/7] KVM: s390: reenable LPP facility
  2015-02-04  9:44 ` [PATCH 2/7] KVM: s390: reenable LPP facility Christian Borntraeger
@ 2015-02-04 12:57   ` Paolo Bonzini
  2015-02-04 14:59     ` Christian Borntraeger
  0 siblings, 1 reply; 20+ messages in thread
From: Paolo Bonzini @ 2015-02-04 12:57 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf



On 04/02/2015 10:44, Christian Borntraeger wrote:
> commit 7be81a46695d ("KVM: s390/facilities: allow TOD-CLOCK steering
> facility bit") accidentially disabled the "load program parameter"
> facility bit during rebase for upstream submission (my fault).
> 
> Re-add that bit.
> 
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> Fixes: 7be81a46695d ("KVM: s390/facilities: allow TOD-CLOCK steering")

Cc: stable?

Paolo

> ---
>  arch/s390/kvm/kvm-s390.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index b2371c0..57f5538 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -2073,7 +2073,7 @@ static int __init kvm_s390_init(void)
>  		return -ENOMEM;
>  	}
>  	memcpy(vfacilities, S390_lowcore.stfle_fac_list, 16);
> -	vfacilities[0] &= 0xff82fffbf47c2000UL;
> +	vfacilities[0] &= 0xff82fffbf4fc2000UL;
>  	vfacilities[1] &= 0x005c000000000000UL;
>  	return 0;
>  }
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/7] s390/kernel: Update /proc/sysinfo file with Extended Name and UUID
  2015-02-04  9:44 ` [PATCH 3/7] s390/kernel: Update /proc/sysinfo file with Extended Name and UUID Christian Borntraeger
@ 2015-02-04 12:57   ` Paolo Bonzini
  2015-02-04 13:01     ` Christian Borntraeger
  0 siblings, 1 reply; 20+ messages in thread
From: Paolo Bonzini @ 2015-02-04 12:57 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Ekaterina Tumanova



On 04/02/2015 10:44, Christian Borntraeger wrote:
> From: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
> 
> Read the additional data fields (Extended Name and UUID) from the
> 1KB block returned by the STSI command and reflect this information in
> the /proc/sysinfo file accordingly
> 
> Signed-off-by: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
> Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>

Why should this go in via KVM? :)

Paolo

> ---
>  arch/s390/include/asm/sysinfo.h | 10 +++++++---
>  arch/s390/kernel/sysinfo.c      | 29 +++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/s390/include/asm/sysinfo.h b/arch/s390/include/asm/sysinfo.h
> index f92428e..9f8f2b5 100644
> --- a/arch/s390/include/asm/sysinfo.h
> +++ b/arch/s390/include/asm/sysinfo.h
> @@ -15,6 +15,7 @@
>  #define __ASM_S390_SYSINFO_H
>  
>  #include <asm/bitsperlong.h>
> +#include <linux/uuid.h>
>  
>  struct sysinfo_1_1_1 {
>  	unsigned char p:1;
> @@ -112,10 +113,13 @@ struct sysinfo_3_2_2 {
>  		char name[8];
>  		unsigned int caf;
>  		char cpi[16];
> -		char reserved_1[24];
> -
> +		char reserved_1[3];
> +		char ext_name_encoding;
> +		unsigned int reserved_2;
> +		uuid_be uuid;
>  	} vm[8];
> -	char reserved_544[3552];
> +	char reserved_3[1504];
> +	char ext_names[8][256];
>  };
>  
>  extern int topology_max_mnest;
> diff --git a/arch/s390/kernel/sysinfo.c b/arch/s390/kernel/sysinfo.c
> index 811f542..cebab77 100644
> --- a/arch/s390/kernel/sysinfo.c
> +++ b/arch/s390/kernel/sysinfo.c
> @@ -196,6 +196,33 @@ static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
>  	seq_printf(m, "LPAR CPUs Shared:     %d\n", info->cpus_shared);
>  }
>  
> +static void print_ext_name(struct seq_file *m, int lvl,
> +			   struct sysinfo_3_2_2 *info)
> +{
> +	if (info->vm[lvl].ext_name_encoding == 0)
> +		return;
> +	if (info->ext_names[lvl][0] == 0)
> +		return;
> +	switch (info->vm[lvl].ext_name_encoding) {
> +	case 1: /* EBCDIC */
> +		EBCASC(info->ext_names[lvl], sizeof(info->ext_names[lvl]));
> +		break;
> +	case 2:	/* UTF-8 */
> +		break;
> +	default:
> +		return;
> +	}
> +	seq_printf(m, "VM%02d Extended Name:   %-.256s\n", lvl,
> +		   info->ext_names[lvl]);
> +}
> +
> +static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info)
> +{
> +	if (!memcmp(&info->vm[i].uuid, &NULL_UUID_BE, sizeof(uuid_be)))
> +		return;
> +	seq_printf(m, "VM%02d UUID:            %pUb\n", i, &info->vm[i].uuid);
> +}
> +
>  static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
>  {
>  	int i;
> @@ -213,6 +240,8 @@ static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
>  		seq_printf(m, "VM%02d CPUs Configured: %d\n", i, info->vm[i].cpus_configured);
>  		seq_printf(m, "VM%02d CPUs Standby:    %d\n", i, info->vm[i].cpus_standby);
>  		seq_printf(m, "VM%02d CPUs Reserved:   %d\n", i, info->vm[i].cpus_reserved);
> +		print_ext_name(m, i, info);
> +		print_uuid(m, i, info);
>  	}
>  }
>  
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/7] KVM: s390/CPACF: Choose crypto control block format
  2015-02-04  9:44 ` [PATCH 4/7] KVM: s390/CPACF: Choose crypto control block format Christian Borntraeger
@ 2015-02-04 13:00   ` Paolo Bonzini
  2015-02-04 13:05     ` Christian Borntraeger
  0 siblings, 1 reply; 20+ messages in thread
From: Paolo Bonzini @ 2015-02-04 13:00 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Tony Krowiak



On 04/02/2015 10:44, Christian Borntraeger wrote:
> +static void kvm_s390_set_crycb_format(struct kvm *kvm)
> +{
> +	kvm->arch.crypto.crycbd = (__u32)(unsigned long) kvm->arch.crypto.crycb;
> +
> +	if (kvm_s390_apxa_installed())
> +		kvm->arch.crypto.crycbd |= CRYCB_FORMAT2;
> +	else
> +		kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
> +}
> +
>  static int kvm_s390_crypto_init(struct kvm *kvm)
>  {
>  	if (!test_vfacility(76))
> @@ -663,8 +709,7 @@ static int kvm_s390_crypto_init(struct kvm *kvm)
>  	if (!kvm->arch.crypto.crycb)
>  		return -ENOMEM;
>  
> -	kvm->arch.crypto.crycbd = (__u32) (unsigned long) kvm->arch.crypto.crycb |
> -				  CRYCB_FORMAT1;
> +	kvm_s390_set_crycb_format(kvm);

Could this also be part of the "things" that KVM can choose to enable,
even though it's not a facility?

Paolo

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/7] s390/kernel: Update /proc/sysinfo file with Extended Name and UUID
  2015-02-04 12:57   ` Paolo Bonzini
@ 2015-02-04 13:01     ` Christian Borntraeger
  2015-02-04 13:03       ` Paolo Bonzini
  0 siblings, 1 reply; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04 13:01 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Ekaterina Tumanova

Am 04.02.2015 um 13:57 schrieb Paolo Bonzini:
> 
> 
> On 04/02/2015 10:44, Christian Borntraeger wrote:
>> From: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
>>
>> Read the additional data fields (Extended Name and UUID) from the
>> 1KB block returned by the STSI command and reflect this information in
>> the /proc/sysinfo file accordingly
>>
>> Signed-off-by: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
>> Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
>> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
>> Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> 
> Why should this go in via KVM? :)

Because we are being the first that will implement the architecture (
the other side so to speak). 
Heiko gave his ack so this shoudl be fine. If you prefer I can certainly push
that via Martin/Heiko.


Christian

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20)
  2015-02-04  9:44 [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Christian Borntraeger
                   ` (6 preceding siblings ...)
  2015-02-04  9:44 ` [PATCH 7/7] KVM: s390: Create ioctl for Getting/Setting guest storage keys Christian Borntraeger
@ 2015-02-04 13:03 ` Paolo Bonzini
  7 siblings, 0 replies; 20+ messages in thread
From: Paolo Bonzini @ 2015-02-04 13:03 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf



On 04/02/2015 10:44, Christian Borntraeger wrote:
> here is my remaining bunch of patches for 3.20 for review. All patches
> have been in linux-next via
> git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git next
> (well a tiny fix went in today, so the commit id for the last 3 patches
> has changed)
> 
> I think it makes sense to give some of these patches some more days
> for external review. Is it ok to send a pull request early next week
> or do you want it before 3.19?

No problem, I have been a bit late myself so I don't plan to send a 3.20
pull request earlier than Wednesday or Thursday.

Paolo

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/7] s390/kernel: Update /proc/sysinfo file with Extended Name and UUID
  2015-02-04 13:01     ` Christian Borntraeger
@ 2015-02-04 13:03       ` Paolo Bonzini
  2015-02-04 19:32         ` Christian Borntraeger
  0 siblings, 1 reply; 20+ messages in thread
From: Paolo Bonzini @ 2015-02-04 13:03 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Ekaterina Tumanova



On 04/02/2015 14:01, Christian Borntraeger wrote:
> Am 04.02.2015 um 13:57 schrieb Paolo Bonzini:
>>
>>
>> On 04/02/2015 10:44, Christian Borntraeger wrote:
>>> From: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
>>>
>>> Read the additional data fields (Extended Name and UUID) from the
>>> 1KB block returned by the STSI command and reflect this information in
>>> the /proc/sysinfo file accordingly
>>>
>>> Signed-off-by: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
>>> Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
>>> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
>>> Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
>>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
>>
>> Why should this go in via KVM? :)
> 
> Because we are being the first that will implement the architecture (
> the other side so to speak). 
> Heiko gave his ack so this shoudl be fine. If you prefer I can certainly push
> that via Martin/Heiko.

No problem.  Perhaps edit the commit message?

Paolo

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/7] KVM: s390/CPACF: Choose crypto control block format
  2015-02-04 13:00   ` Paolo Bonzini
@ 2015-02-04 13:05     ` Christian Borntraeger
  2015-02-04 13:48       ` Paolo Bonzini
  0 siblings, 1 reply; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04 13:05 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Tony Krowiak

Am 04.02.2015 um 14:00 schrieb Paolo Bonzini:
> 
> 
> On 04/02/2015 10:44, Christian Borntraeger wrote:
>> +static void kvm_s390_set_crycb_format(struct kvm *kvm)
>> +{
>> +	kvm->arch.crypto.crycbd = (__u32)(unsigned long) kvm->arch.crypto.crycb;
>> +
>> +	if (kvm_s390_apxa_installed())
>> +		kvm->arch.crypto.crycbd |= CRYCB_FORMAT2;
>> +	else
>> +		kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
>> +}
>> +
>>  static int kvm_s390_crypto_init(struct kvm *kvm)
>>  {
>>  	if (!test_vfacility(76))
>> @@ -663,8 +709,7 @@ static int kvm_s390_crypto_init(struct kvm *kvm)
>>  	if (!kvm->arch.crypto.crycb)
>>  		return -ENOMEM;
>>  
>> -	kvm->arch.crypto.crycbd = (__u32) (unsigned long) kvm->arch.crypto.crycb |
>> -				  CRYCB_FORMAT1;
>> +	kvm_s390_set_crycb_format(kvm);
> 
> Could this also be part of the "things" that KVM can choose to enable,
> even though it's not a facility?

Can you re-ask that question? Not sure what you want to know. 

This is mostly a fixup for z13, which wants to have a bigger control block. but
this block is not guest visible.
Talking about key wrapping, this is actually masked via a facility bit (for MSA-3
and MSA-4), therefore we have the test_vfacility thing in that function.

Christian

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/7] KVM: s390/CPACF: Choose crypto control block format
  2015-02-04 13:05     ` Christian Borntraeger
@ 2015-02-04 13:48       ` Paolo Bonzini
  2015-02-04 14:00         ` Christian Borntraeger
  0 siblings, 1 reply; 20+ messages in thread
From: Paolo Bonzini @ 2015-02-04 13:48 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Tony Krowiak



On 04/02/2015 14:05, Christian Borntraeger wrote:
>> > 
>> > Could this also be part of the "things" that KVM can choose to enable,
>> > even though it's not a facility?
> Can you re-ask that question? Not sure what you want to know. 
> 
> This is mostly a fixup for z13, which wants to have a bigger control block. but
> this block is not guest visible.

Okay, this is what I was asking.  If the block is not guest visible
that's fine.

What happens if the guest executes PQAP(QCI)?

Paolo

> Talking about key wrapping, this is actually masked via a facility bit (for MSA-3
> and MSA-4), therefore we have the test_vfacility thing in that function.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/7] KVM: s390/CPACF: Choose crypto control block format
  2015-02-04 13:48       ` Paolo Bonzini
@ 2015-02-04 14:00         ` Christian Borntraeger
  0 siblings, 0 replies; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04 14:00 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Tony Krowiak

Am 04.02.2015 um 14:48 schrieb Paolo Bonzini:
> 
> 
> On 04/02/2015 14:05, Christian Borntraeger wrote:
>>>>
>>>> Could this also be part of the "things" that KVM can choose to enable,
>>>> even though it's not a facility?
>> Can you re-ask that question? Not sure what you want to know. 
>>
>> This is mostly a fixup for z13, which wants to have a bigger control block. but
>> this block is not guest visible.
> 
> Okay, this is what I was asking.  If the block is not guest visible
> that's fine.
> 
> What happens if the guest executes PQAP(QCI)?

It will get an illegal opcode because we dont provide the PQAP instruction 
to the guest. (We  have to provide it, if we want to virtualize the off-cpu
crypto cards - right now we only provide the on-cpu crypto instructions)

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/7] KVM: s390: reenable LPP facility
  2015-02-04 12:57   ` Paolo Bonzini
@ 2015-02-04 14:59     ` Christian Borntraeger
  0 siblings, 0 replies; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04 14:59 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf

Am 04.02.2015 um 13:57 schrieb Paolo Bonzini:
> 
> 
> On 04/02/2015 10:44, Christian Borntraeger wrote:
>> commit 7be81a46695d ("KVM: s390/facilities: allow TOD-CLOCK steering
>> facility bit") accidentially disabled the "load program parameter"
>> facility bit during rebase for upstream submission (my fault).
>>
>> Re-add that bit.
>>
>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
>> Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
>> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
>> Fixes: 7be81a46695d ("KVM: s390/facilities: allow TOD-CLOCK steering")
> 
> Cc: stable?

Its mostly about the LPP instruction which is right now only used by
KVM itself for tagging guests for hardware based sampling that perf uses
on s390 (see 
http://www-01.ibm.com/support/docview.wss?uid=isg26fcd1cc32246f4c8852574ce0044734a ) 
As KVM on s390 does not yet run  nested not doing stable should be fine as all 
others users I am aware of are lab-only.

Christian


> 
> Paolo
> 
>> ---
>>  arch/s390/kvm/kvm-s390.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
>> index b2371c0..57f5538 100644
>> --- a/arch/s390/kvm/kvm-s390.c
>> +++ b/arch/s390/kvm/kvm-s390.c
>> @@ -2073,7 +2073,7 @@ static int __init kvm_s390_init(void)
>>  		return -ENOMEM;
>>  	}
>>  	memcpy(vfacilities, S390_lowcore.stfle_fac_list, 16);
>> -	vfacilities[0] &= 0xff82fffbf47c2000UL;
>> +	vfacilities[0] &= 0xff82fffbf4fc2000UL;
>>  	vfacilities[1] &= 0x005c000000000000UL;
>>  	return 0;
>>  }
>>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/7] s390/kernel: Update /proc/sysinfo file with Extended Name and UUID
  2015-02-04 13:03       ` Paolo Bonzini
@ 2015-02-04 19:32         ` Christian Borntraeger
  2015-02-05 11:13           ` Paolo Bonzini
  0 siblings, 1 reply; 20+ messages in thread
From: Christian Borntraeger @ 2015-02-04 19:32 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Ekaterina Tumanova

Am 04.02.2015 um 14:03 schrieb Paolo Bonzini:
> 
> 
> On 04/02/2015 14:01, Christian Borntraeger wrote:
>> Am 04.02.2015 um 13:57 schrieb Paolo Bonzini:
>>>
>>>
>>> On 04/02/2015 10:44, Christian Borntraeger wrote:
>>>> From: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
>>>>
>>>> Read the additional data fields (Extended Name and UUID) from the
>>>> 1KB block returned by the STSI command and reflect this information in
>>>> the /proc/sysinfo file accordingly
>>>>
>>>> Signed-off-by: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
>>>> Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
>>>> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
>>>> Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
>>>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
>>>
>>> Why should this go in via KVM? :)
>>
>> Because we are being the first that will implement the architecture (
>> the other side so to speak). 
>> Heiko gave his ack so this shoudl be fine. If you prefer I can certainly push
>> that via Martin/Heiko.
> 
> No problem.  Perhaps edit the commit message?

Something like

A new architecture extends STSI 3.2.2 with UUID and long names. KVM will
provide the first implementation. This patch adds the additional data 
fields (Extended Name and UUID) from the 4KB block returned by the STSI 
3.2.2 command and reflect this information in the /proc/sysinfo file
accordingly. 
This is is non-KVM code, but developed by the KVM team. The patch is 
acked by Heiko Carstens to go over the KVM tree.

Signed-off-by: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>

?

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/7] s390/kernel: Update /proc/sysinfo file with Extended Name and UUID
  2015-02-04 19:32         ` Christian Borntraeger
@ 2015-02-05 11:13           ` Paolo Bonzini
  0 siblings, 0 replies; 20+ messages in thread
From: Paolo Bonzini @ 2015-02-05 11:13 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Cornelia Huck, Jens Freimann, linux-s390, Alexander Graf,
	Ekaterina Tumanova



On 04/02/2015 20:32, Christian Borntraeger wrote:
> 
> A new architecture extends STSI 3.2.2 with UUID and long names. KVM will
> provide the first implementation. This patch adds the additional data 
> fields (Extended Name and UUID) from the 4KB block returned by the STSI 
> 3.2.2 command and reflect this information in the /proc/sysinfo file
> accordingly. 

Great.

> This is is non-KVM code, but developed by the KVM team. The patch is 
> acked by Heiko Carstens to go over the KVM tree.

The last two lines are not even necessary (the explanation of "why" is
in the first paragraph, the explanation of "how" is in the
Signed-off-bys and Acked-by).

Paolo

> Signed-off-by: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
> Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2015-02-05 11:13 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-04  9:44 [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Christian Borntraeger
2015-02-04  9:44 ` [PATCH 1/7] KVM: s390: floating irqs: fix user triggerable endless loop Christian Borntraeger
2015-02-04  9:44 ` [PATCH 2/7] KVM: s390: reenable LPP facility Christian Borntraeger
2015-02-04 12:57   ` Paolo Bonzini
2015-02-04 14:59     ` Christian Borntraeger
2015-02-04  9:44 ` [PATCH 3/7] s390/kernel: Update /proc/sysinfo file with Extended Name and UUID Christian Borntraeger
2015-02-04 12:57   ` Paolo Bonzini
2015-02-04 13:01     ` Christian Borntraeger
2015-02-04 13:03       ` Paolo Bonzini
2015-02-04 19:32         ` Christian Borntraeger
2015-02-05 11:13           ` Paolo Bonzini
2015-02-04  9:44 ` [PATCH 4/7] KVM: s390/CPACF: Choose crypto control block format Christian Borntraeger
2015-02-04 13:00   ` Paolo Bonzini
2015-02-04 13:05     ` Christian Borntraeger
2015-02-04 13:48       ` Paolo Bonzini
2015-02-04 14:00         ` Christian Borntraeger
2015-02-04  9:44 ` [PATCH 5/7] KVM: s390: use facilities and cpu_id per KVM Christian Borntraeger
2015-02-04  9:44 ` [PATCH 6/7] KVM: s390: add cpu model support Christian Borntraeger
2015-02-04  9:44 ` [PATCH 7/7] KVM: s390: Create ioctl for Getting/Setting guest storage keys Christian Borntraeger
2015-02-04 13:03 ` [PATCH 0/7] KVM: s390: fixes and features for kvm/next (3.20) Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.