All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Krowiak <akrowiak@linux.vnet.ibm.com>
To: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org
Cc: freude@de.ibm.com, schwidefsky@de.ibm.com,
	heiko.carstens@de.ibm.com, borntraeger@de.ibm.com,
	cohuck@redhat.com, kwankhede@nvidia.com,
	bjsdjshi@linux.vnet.ibm.com, pbonzini@redhat.com,
	alex.williamson@redhat.com, pmorel@linux.vnet.ibm.com,
	alifm@linux.vnet.ibm.com, mjrosato@linux.vnet.ibm.com,
	jjherne@linux.vnet.ibm.com, thuth@redhat.com,
	pasic@linux.vnet.ibm.com, berrange@redhat.com,
	fiuczy@linux.vnet.ibm.com, buendgen@de.ibm.com,
	akrowiak@linux.vnet.ibm.com
Subject: [PATCH v5 01/13] KVM: s390: Interface to test whether APXA installed
Date: Mon,  7 May 2018 11:11:40 -0400	[thread overview]
Message-ID: <1525705912-12815-2-git-send-email-akrowiak@linux.vnet.ibm.com> (raw)
In-Reply-To: <1525705912-12815-1-git-send-email-akrowiak@linux.vnet.ibm.com>

Relocates an existing static function that tests whether
the AP extended addressing facility (APXA) is installed on
the linux host. The primary reason for relocating this
function is because a new compilation unit (arch/s390/kvm/kvm-ap.c)
is being created to contain all of the interfaces and logic
for configuring an AP matrix for a KVM guest. Some of its
functions will also need to determine whether APXA is installed,
so, let's go ahead and relocate this static function as a
public interface in kvm-ap.c.

Notes:
----
1. The interface to determine whether APXA is installed on the linux
   host the information returned from the AP Query Configuration
   Information (QCI) function. This function will not be available
   if the AP instructions are not installed on the linux host, so a check
   will be included to verify that.

2. Currently, the AP bus interfaces accessing the AP instructions will
   not be accessible if CONFIG_ZCRYPT=n, so the relevant code will be
   temporarily contained in the new arch/s390/kvm/kvm-ap.c file until
   the patch(es) to statically build the required AP bus interfaces are
   available.

Signed-off-by: Tony Krowiak <akrowiak@linux.vnet.ibm.com>
---
 MAINTAINERS                    |    1 +
 arch/s390/include/asm/kvm-ap.h |   60 +++++++++++++++++++++++++++++
 arch/s390/kvm/Makefile         |    2 +-
 arch/s390/kvm/kvm-ap.c         |   83 ++++++++++++++++++++++++++++++++++++++++
 arch/s390/kvm/kvm-s390.c       |   42 +-------------------
 5 files changed, 147 insertions(+), 41 deletions(-)
 create mode 100644 arch/s390/include/asm/kvm-ap.h
 create mode 100644 arch/s390/kvm/kvm-ap.c

diff --git a/MAINTAINERS b/MAINTAINERS
index eab763f..224e97b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7792,6 +7792,7 @@ M:	Christian Borntraeger <borntraeger@de.ibm.com>
 M:	Janosch Frank <frankja@linux.ibm.com>
 R:	David Hildenbrand <david@redhat.com>
 R:	Cornelia Huck <cohuck@redhat.com>
+R:	Tony Krowiak <akrowiak@linux.vnet.ibm.com>
 L:	linux-s390@vger.kernel.org
 W:	http://www.ibm.com/developerworks/linux/linux390/
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git
diff --git a/arch/s390/include/asm/kvm-ap.h b/arch/s390/include/asm/kvm-ap.h
new file mode 100644
index 0000000..6af1ff8
--- /dev/null
+++ b/arch/s390/include/asm/kvm-ap.h
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Adjunct Processor (AP) configuration management for KVM guests
+ *
+ * Copyright IBM Corp. 2018
+ *
+ * Author(s): Tony Krowiak <akrowia@linux.vnet.ibm.com>
+ */
+
+#ifndef _ASM_KVM_AP
+#define _ASM_KVM_AP
+
+#include <linux/types.h>
+#include <linux/kvm_host.h>
+#include <asm/ap.h>
+
+/**
+ * kvm_ap_apxa_installed
+ *
+ * Returns 1 if the AP extended addressing facility (APXA) is installed on the
+ * linux host; otherwise, returns 0.
+ */
+int kvm_ap_apxa_installed(void);
+
+/**
+ * kvm_ap_query_configuration
+ *
+ * @info: stores the AP configuration information
+ *
+ * Executes the AP Query Configuration Information (QCI) function and stores
+ * the configuration information in @info.
+ *
+ * Returns 0 if the operation succeeds; otherwise returns an error. If the
+ * QCI facility is not installed, returns -EOPNOTSUPP.
+ *
+ * TODO:
+ * This interface is temporary until the ap_query_configuration() interface
+ * implemented in the AP bus becomes statically available. Currently, the
+ * bus interface will not be available if CONFIG_ZCRYPT or CONFIG_ZCRYPT_MODULE
+ * is not selected. Calls to this function should be replaced by a call to
+ * the AP bus ap_query_configuration() interface at that time.
+ */
+int kvm_ap_query_configuration(struct ap_config_info *info);
+
+/**
+ * kvm_ap_instructions_available
+ *
+ * Returns 1 if the AP instructions are installed on the linux host; otherwise,
+ * returns 0.
+ *
+ * TODO:
+ * This interface is temporary until the ap_instructions_available() interface
+ * implemented in the AP bus becomes statically available. Currently, the
+ * bus interface will not be available if CONFIG_ZCRYPT or CONFIG_ZCRYPT_MODULE
+ * is not selected. Calls to this function should be replaced by a call to
+ * the AP bus ap_instructions_available() interface at that time.
+ */
+bool kvm_ap_instructions_available(void);
+
+#endif /* _ASM_KVM_AP */
diff --git a/arch/s390/kvm/Makefile b/arch/s390/kvm/Makefile
index 05ee90a..1876bfe 100644
--- a/arch/s390/kvm/Makefile
+++ b/arch/s390/kvm/Makefile
@@ -9,6 +9,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 vsie.o
+kvm-objs += diag.o gaccess.o guestdbg.o vsie.o kvm-ap.o
 
 obj-$(CONFIG_KVM) += kvm.o
diff --git a/arch/s390/kvm/kvm-ap.c b/arch/s390/kvm/kvm-ap.c
new file mode 100644
index 0000000..00bcfb0
--- /dev/null
+++ b/arch/s390/kvm/kvm-ap.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Adjunct Processor (AP) configuration management for KVM guests
+ *
+ * Copyright IBM Corp. 2018
+ *
+ * Author(s): Tony Krowiak <akrowia@linux.vnet.ibm.com>
+ */
+#include <linux/kernel.h>
+#include <asm/kvm-ap.h>
+
+#include "kvm-s390.h"
+
+static int kvm_ap_qci(struct ap_config_info *info)
+{
+	register unsigned long reg0 asm ("0") = 0x04000000UL;
+	register unsigned long reg1 asm ("1") = -EINVAL;
+	register void *reg2 asm ("2") = (void *) info;
+
+	asm volatile(
+		".long 0xb2af0000\n"		/* PQAP(QCI) */
+		"0: la    %1,0\n"
+		"1:\n"
+		EX_TABLE(0b, 1b)
+		: "+d" (reg0), "+d" (reg1), "+d" (reg2)
+		:
+		: "cc", "memory");
+
+	return reg1;
+}
+
+
+/**
+ * TODO:
+ * This interface is temporary until the ap_query_configuration() interface
+ * implemented in the AP bus becomes statically available. Currently, the
+ * bus interface will not be available if CONFIG_ZCRYPT or CONFIG_ZCRYPT_MODULE
+ * is not selected. Calls to this function should be replaced by a call to
+ * the AP bus ap_instructions_available() interface at that time.
+ */
+bool kvm_ap_instructions_available(void)
+{
+	register unsigned long reg0 asm ("0") = AP_MKQID(0, 0);
+	register unsigned long reg1 asm ("1") = -ENODEV;
+	register unsigned long reg2 asm ("2") = 0UL;
+
+	asm volatile(
+		"   .long 0xb2af0000\n"		/* PQAP(TAPQ) */
+		"0: la    %1,0\n"
+		"1:\n"
+		EX_TABLE(0b, 1b)
+		: "+d" (reg0), "+d" (reg1), "+d" (reg2) : : "cc");
+	return reg1 == 0;
+}
+EXPORT_SYMBOL(kvm_ap_instructions_available);
+
+/**
+ * TODO:
+ * This interface is temporary until the ap_query_configuration() interface
+ * implemented in the AP bus becomes statically available. Currently, the AP
+ * bus interface will not be available if CONFIG_ZCRYPT or CONFIG_ZCRYPT_MODULE
+ * is not selected. Calls to this function should be replaced by a call to
+ * the AP bus ap_query_configuration() interface at that time.
+ */
+int kvm_ap_query_configuration(struct ap_config_info *info)
+{
+	if (kvm_ap_instructions_available() && test_facility(12))
+		return kvm_ap_qci(info);
+
+	return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL(kvm_ap_query_configuration);
+
+int kvm_ap_apxa_installed(void)
+{
+	struct ap_config_info info;
+
+	if (kvm_ap_query_configuration(&info) == 0)
+		return (info.apxa == 1);
+
+	return 0;
+}
+EXPORT_SYMBOL(kvm_ap_apxa_installed);
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 64c9862..1f50de7 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -40,6 +40,7 @@
 #include <asm/sclp.h>
 #include <asm/cpacf.h>
 #include <asm/timex.h>
+#include <asm/kvm-ap.h>
 #include "kvm-s390.h"
 #include "gaccess.h"
 
@@ -1874,50 +1875,11 @@ 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 = 0;
-
-	memset(config, 0, 128);
-	asm volatile(
-		"lgr 0,%1\n"
-		"lgr 2,%2\n"
-		".long 0xb2af0000\n"		/* PQAP(QCI) */
-		"0: ipm %0\n"
-		"srl %0,28\n"
-		"1:\n"
-		EX_TABLE(0b, 1b)
-		: "+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(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())
+	if (kvm_ap_apxa_installed())
 		kvm->arch.crypto.crycbd |= CRYCB_FORMAT2;
 	else
 		kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
-- 
1.7.1

  reply	other threads:[~2018-05-07 15:12 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-07 15:11 [PATCH v5 00/13] s390: vfio-ap: guest dedicated crypto adapters Tony Krowiak
2018-05-07 15:11 ` Tony Krowiak [this message]
2018-05-16 10:21   ` [PATCH v5 01/13] KVM: s390: Interface to test whether APXA installed Cornelia Huck
2018-05-16 10:45     ` Tony Krowiak
2018-05-17  9:11       ` Harald Freudenberger
2018-05-17  9:44         ` Cornelia Huck
2018-05-07 15:11 ` [PATCH v5 02/13] KVM: s390: refactor crypto initialization Tony Krowiak
2018-05-16  8:51   ` Pierre Morel
2018-05-16 11:14     ` Tony Krowiak
2018-05-16 12:17       ` Pierre Morel
2018-05-16 12:21         ` Cornelia Huck
2018-05-07 15:11 ` [PATCH v5 03/13] KVM: s390: CPU model support for AP virtualization Tony Krowiak
2018-05-07 15:11 ` [PATCH v5 04/13] s390: vfio-ap: base implementation of VFIO AP device driver Tony Krowiak
2018-05-16  8:21   ` Pierre Morel
2018-05-16 11:29     ` Tony Krowiak
2018-05-16 11:45     ` Tony Krowiak
2018-06-07  8:57   ` Pierre Morel
2018-06-13  7:41   ` Pierre Morel
2018-06-13  7:48     ` Cornelia Huck
2018-06-13 10:54       ` Pierre Morel
2018-06-13 11:14         ` Cornelia Huck
2018-06-13 12:01           ` Pierre Morel
2018-06-13 12:12             ` Cornelia Huck
2018-06-13 12:16               ` Pierre Morel
2018-06-14 13:04                 ` Tony Krowiak
2018-05-07 15:11 ` [PATCH v5 05/13] s390: vfio-ap: register matrix device with VFIO mdev framework Tony Krowiak
2018-05-11 17:18   ` Halil Pasic
2018-05-14 19:42     ` Tony Krowiak
2018-05-15 14:17       ` Pierre Morel
2018-05-15 15:16         ` Tony Krowiak
2018-05-15 15:48           ` Halil Pasic
2018-05-15 16:11             ` Tony Krowiak
2018-05-17  7:44       ` Cornelia Huck
2018-05-21 15:13         ` Tony Krowiak
2018-05-22  8:19           ` Cornelia Huck
2018-05-22 21:41             ` Tony Krowiak
2018-05-16 10:42   ` Cornelia Huck
2018-05-16 12:48     ` Tony Krowiak
2018-05-16 12:58     ` Tony Krowiak
2018-05-07 15:11 ` [PATCH v5 06/13] KVM: s390: interfaces to manage guest's AP matrix Tony Krowiak
2018-05-11 16:08   ` Halil Pasic
2018-05-16 14:29     ` Tony Krowiak
2018-05-16 14:41       ` Pierre Morel
2018-05-21 15:23         ` Tony Krowiak
2018-05-15 14:55   ` Pierre Morel
2018-05-15 16:07     ` Tony Krowiak
2018-05-16  7:48       ` Pierre Morel
2018-05-16 13:12         ` Tony Krowiak
2018-05-16 13:15           ` Pierre Morel
2018-05-16 13:48             ` Tony Krowiak
2018-05-18  8:55               ` Pierre Morel
2018-05-23 14:29                 ` Tony Krowiak
2018-05-24  7:46                   ` Pierre Morel
2018-05-07 15:11 ` [PATCH v5 07/13] s390: vfio-ap: sysfs interfaces to configure adapters Tony Krowiak
2018-05-07 15:11 ` [PATCH v5 08/13] s390: vfio-ap: sysfs interfaces to configure domains Tony Krowiak
2018-05-07 15:11 ` [PATCH v5 09/13] s390: vfio-ap: sysfs interfaces to configure control domains Tony Krowiak
2018-05-07 15:11 ` [PATCH v5 10/13] s390: vfio-ap: sysfs interface to view matrix mdev matrix Tony Krowiak
2018-05-16  7:55   ` Pierre Morel
2018-05-23 14:38     ` Tony Krowiak
2018-05-24  9:10       ` Pierre Morel
2018-05-30 14:28         ` Tony Krowiak
2018-06-05 12:40           ` Pierre Morel
2018-06-06 14:24             ` Tony Krowiak
2018-06-06 15:10               ` Pierre Morel
2018-06-07 12:53                 ` Tony Krowiak
2018-06-07 13:16                   ` Halil Pasic
2018-06-07 14:33                     ` Tony Krowiak
2018-05-07 15:11 ` [PATCH v5 11/13] KVM: s390: implement mediated device open callback Tony Krowiak
2018-05-16  8:03   ` Pierre Morel
2018-05-23 14:45     ` Tony Krowiak
2018-05-24  9:08       ` Pierre Morel
2018-05-30 14:33         ` Tony Krowiak
2018-06-05 12:19           ` Pierre Morel
2018-06-06 14:28             ` Tony Krowiak
2018-06-06 16:08               ` Pierre Morel
2018-06-06 17:40                 ` Pierre Morel
2018-06-07 13:54                   ` Tony Krowiak
2018-06-07 15:20                     ` Pierre Morel
2018-06-07 16:30                       ` Tony Krowiak
2018-06-07 17:15                         ` Pierre Morel
2018-06-08 21:59                           ` Tony Krowiak
2018-06-11  9:23                             ` Pierre Morel
2018-06-11 11:32                               ` Halil Pasic
2018-06-11 11:49                                 ` Janosch Frank
2018-06-11 16:26                                   ` Tony Krowiak
2018-06-11 16:50                                     ` Halil Pasic
2018-06-11 16:54                                       ` Tony Krowiak
2018-06-11 12:50                                 ` Tony Krowiak
2018-06-11 12:56                               ` Tony Krowiak
2018-06-07 13:52                 ` Tony Krowiak
2018-05-07 15:11 ` [PATCH v5 12/13] s390: vfio-ap: implement VFIO_DEVICE_GET_INFO ioctl Tony Krowiak
2018-05-07 15:11 ` [PATCH v5 13/13] s390: doc: detailed specifications for AP virtualization Tony Krowiak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1525705912-12815-2-git-send-email-akrowiak@linux.vnet.ibm.com \
    --to=akrowiak@linux.vnet.ibm.com \
    --cc=alex.williamson@redhat.com \
    --cc=alifm@linux.vnet.ibm.com \
    --cc=berrange@redhat.com \
    --cc=bjsdjshi@linux.vnet.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=buendgen@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=fiuczy@linux.vnet.ibm.com \
    --cc=freude@de.ibm.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=jjherne@linux.vnet.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjrosato@linux.vnet.ibm.com \
    --cc=pasic@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=pmorel@linux.vnet.ibm.com \
    --cc=schwidefsky@de.ibm.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.