Received: by 10.192.165.148 with SMTP id m20csp3200998imm; Mon, 7 May 2018 08:17:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpsBMuvkD/GSfcvn+jvhgosABpjadme7oe0YacQGTqYDVjBgMZRwg1TVzcEvL4fL+AT2dyS X-Received: by 2002:a24:ecc6:: with SMTP id g189-v6mr1706502ith.18.1525706228325; Mon, 07 May 2018 08:17:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525706228; cv=none; d=google.com; s=arc-20160816; b=dJKkPtFmnZJH5QFmQYF7bCAM24L2umE4GEYor1tY+NhWe4ad4ZkriX5s13G16+BfFv 7TWblqe+icH8SCe2XzoQ5f8cIR22RypqEp5oRPe/9j5t0nZWK8SHMdELgCgcUnMDNqbz M63pWqh2h+uXgd5TDlIhYBribqwNglW09RR4fOkpuxiXbVgPAqai3prnlrwiuQ5AOsSU XrBjjHXaoSUJO/l8WR0n1GeXMklvybmGP7q577mmepy4ahuUjp0BrA60DnYa6xs0T9Co +IUVTPIsUBOD9l70bmTIvx7+k+Rw802bXXzKnYs6EfPdEnJermWWT522TT73zSzubHBZ 8rdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=yWlKmBllMcH26IO8WF72O8KDtHorY3HX++YOYfQgYg0=; b=fBm2e6AaCPJCfsteXVZmh1GDUu7qUHxvtSLhB3jGI+Rnp5y8bYyGnpWbnQVWzKqGKJ Yop4t7Wkjm/aQQ51pDD7yqgADvhcHseH7JfSxisFOYZauzhiZRDRJggn2fOB5L2SDYxC y+4Cmo1aXLkVJtJOjKpWN3iPuhQYR8zrEdPPiLi3RhKmMCkDzbTQ2MMBe4DvVmsG0I/a vVzMOUQXSsbYOMxs6NLmAcpJi184OQ4DuZtyg2GCz1wqbNQnC/CS3IBqMWAsaOP4REb9 acUZTIqo7Bcns7SXKmTzjBV9J3pWZ+P7YIhM95Dz8AdVrlxohEUReygldiuHjYrxaXHt Ni6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s83-v6si7207163itd.17.2018.05.07.08.16.55; Mon, 07 May 2018 08:17:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752389AbeEGPMT (ORCPT + 99 others); Mon, 7 May 2018 11:12:19 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46840 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752280AbeEGPMM (ORCPT ); Mon, 7 May 2018 11:12:12 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w47F9IHq140229 for ; Mon, 7 May 2018 11:12:12 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2htqduwcuv-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 07 May 2018 11:12:09 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 7 May 2018 09:12:08 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 7 May 2018 09:12:03 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w47FC2Jr6554084; Mon, 7 May 2018 08:12:02 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DE267C604C; Mon, 7 May 2018 09:12:01 -0600 (MDT) Received: from localhost.localdomain (unknown [9.85.146.27]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTPS id 92165C6037; Mon, 7 May 2018 09:11:59 -0600 (MDT) From: Tony Krowiak 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 X-Mailer: git-send-email 1.7.1 In-Reply-To: <1525705912-12815-1-git-send-email-akrowiak@linux.vnet.ibm.com> References: <1525705912-12815-1-git-send-email-akrowiak@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18050715-8235-0000-0000-00000D713E7F X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008987; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000258; SDB=6.01028858; UDB=6.00525678; IPR=6.00807992; MB=3.00020972; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-07 15:12:06 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18050715-8236-0000-0000-000040D4A9D0 Message-Id: <1525705912-12815-2-git-send-email-akrowiak@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-07_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805070154 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 M: Janosch Frank R: David Hildenbrand R: Cornelia Huck +R: Tony Krowiak 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 + */ + +#ifndef _ASM_KVM_AP +#define _ASM_KVM_AP + +#include +#include +#include + +/** + * 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 + */ +#include +#include + +#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 #include #include +#include #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