Received: by 10.192.165.156 with SMTP id m28csp2994203imm; Sun, 15 Apr 2018 14:28:00 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+JEq+LdMniuHYLhPgzqxtG9ZEdXmZ1YPqFRUcdwNtwsGQiLT84WHlM1NPORmBERinQG/R5 X-Received: by 10.98.194.195 with SMTP id w64mr19294209pfk.83.1523827680637; Sun, 15 Apr 2018 14:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523827680; cv=none; d=google.com; s=arc-20160816; b=Zg8MrAkBbMb/yiCVYFAHzL+nBugN9CuuFlBQcfwFBpA0yy2jBN6nHLyxfD+AiojoZg 4yxGMF4reGBSEqtr386yzGyhoCecKwz1FFmKUorjOX0E/XXf1zGKbsg/38ZvOt4Oox5C 1GFDikRf7V8WdajKmprYq5evZgREb+TPCH/ZBev5ulHOnazBN7hIbiM/zjoCsgkq9Up+ 88KZkBj8pY+q4MpC/IFQcf7IPmwTUR6CqcwBCTKhGY/2D+/UvkUUkif1EEFfKf+76eZL NQIIKrMvPKtmtUBXp+SxN017zJpptZe+doyWMIyLLJw8wkUibCAuiRyYRcMJ6z8LUh5Z Ufeg== 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=g0DhYUkkzbgfEaqZ1t8DaGqenrvvIBQZIVYp9VrOM6g=; b=Z/q1EsC+Zt2/eLabgWpe7r+W2s3SjbM6rTgzWC7BWE/JZAzcLUvJWUqzm31dFVx0BZ QLmibQHoWbFGbU0ys0kntyVAfrxyx7o9htvkgz68jx4fuZRMMAmSazp5w2/9Oe7BwU51 Pgby0IHdw7VnQUiOaI3XkUm9mwhv/ldDpt7Kt5L1qTWTkRXcMl7+lIjSEbxPid/MouWV 3dT/RVwVG9HJ6jo/DMf5TN+U0sw6RO4nTLG9xM2WFBrvyWeujJkFdnxi+ZP/pD/SHiGD 1aypCzG9D7AEpvhCjeMVaz7m4e3HOR3qnxSc7moccJdWVt8oYPResIesnpBQy7FtAH3A c7nA== 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 p1si8410450pgn.468.2018.04.15.14.27.46; Sun, 15 Apr 2018 14:28:00 -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 S1753501AbeDOVZx (ORCPT + 99 others); Sun, 15 Apr 2018 17:25:53 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:57010 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753094AbeDOVWq (ORCPT ); Sun, 15 Apr 2018 17:22:46 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3FLJOAW057655 for ; Sun, 15 Apr 2018 17:22:46 -0400 Received: from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202]) by mx0b-001b2d01.pphosted.com with ESMTP id 2hcdu793m4-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Sun, 15 Apr 2018 17:22:45 -0400 Received: from localhost by e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 15 Apr 2018 17:22:44 -0400 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e12.ny.us.ibm.com (146.89.104.199) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 15 Apr 2018 17:22:40 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3FLMdu447382760; Sun, 15 Apr 2018 21:22:39 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B8600AE043; Sun, 15 Apr 2018 17:24:25 -0400 (EDT) Received: from localhost.localdomain (unknown [9.85.139.141]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTPS id B1C4BAE034; Sun, 15 Apr 2018 17:24:24 -0400 (EDT) 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 v4 05/15] KVM: s390: enable/disable AP interpretive execution Date: Sun, 15 Apr 2018 17:22:15 -0400 X-Mailer: git-send-email 1.7.1 In-Reply-To: <1523827345-11600-1-git-send-email-akrowiak@linux.vnet.ibm.com> References: <1523827345-11600-1-git-send-email-akrowiak@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041521-0048-0000-0000-0000025C4D5F X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008862; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000257; SDB=6.01018429; UDB=6.00519481; IPR=6.00797666; MB=3.00020592; MTD=3.00000008; XFM=3.00000015; UTC=2018-04-15 21:22:43 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041521-0049-0000-0000-000044C9804C Message-Id: <1523827345-11600-6-git-send-email-akrowiak@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-15_10:,, 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-1804150214 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The VFIO AP device model exploits interpretive execution of AP instructions (APIE) to provide guests passthrough access to AP devices. This patch introduces a new interface to enable and disable APIE. Signed-off-by: Tony Krowiak --- arch/s390/include/asm/kvm-ap.h | 16 ++++++++++++++++ arch/s390/include/asm/kvm_host.h | 1 + arch/s390/kvm/kvm-ap.c | 20 ++++++++++++++++++++ arch/s390/kvm/kvm-s390.c | 9 +++++++++ 4 files changed, 46 insertions(+), 0 deletions(-) diff --git a/arch/s390/include/asm/kvm-ap.h b/arch/s390/include/asm/kvm-ap.h index 736e93e..a6c092e 100644 --- a/arch/s390/include/asm/kvm-ap.h +++ b/arch/s390/include/asm/kvm-ap.h @@ -35,4 +35,20 @@ */ void kvm_ap_build_crycbd(struct kvm *kvm); +/** + * kvm_ap_interpret_instructions + * + * Indicate whether AP instructions shall be interpreted. If they are not + * interpreted, all AP instructions will be intercepted and routed back to + * userspace. + * + * @kvm: the virtual machine attributes + * @enable: indicates whether AP instructions are to be interpreted (true) or + * or not (false). + * + * Returns 0 if completed successfully; otherwise, returns -EOPNOTSUPP + * indicating that AP instructions are not installed on the guest. + */ +int kvm_ap_interpret_instructions(struct kvm *kvm, bool enable); + #endif /* _ASM_KVM_AP */ diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h index 3162783..5470685 100644 --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h @@ -715,6 +715,7 @@ struct kvm_s390_crypto { __u32 crycbd; __u8 aes_kw; __u8 dea_kw; + __u8 apie; }; #define APCB0_MASK_SIZE 1 diff --git a/arch/s390/kvm/kvm-ap.c b/arch/s390/kvm/kvm-ap.c index 991bae4..55d11b5 100644 --- a/arch/s390/kvm/kvm-ap.c +++ b/arch/s390/kvm/kvm-ap.c @@ -58,3 +58,23 @@ void kvm_ap_build_crycbd(struct kvm *kvm) } } EXPORT_SYMBOL(kvm_ap_build_crycbd); + +int kvm_ap_interpret_instructions(struct kvm *kvm, bool enable) +{ + int ret = 0; + + mutex_lock(&kvm->lock); + + if (!test_kvm_cpu_feat(kvm, KVM_S390_VM_CPU_FEAT_AP)) { + ret = -EOPNOTSUPP; + goto done; + } + + kvm->arch.crypto.apie = enable; + kvm_s390_vcpu_crypto_reset_all(kvm); + +done: + mutex_unlock(&kvm->lock); + return ret; +} +EXPORT_SYMBOL(kvm_ap_interpret_instructions); diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 55cd897..1dc8566 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -1901,6 +1901,9 @@ static void kvm_s390_crypto_init(struct kvm *kvm) kvm->arch.crypto.crycb = &kvm->arch.sie_page2->crycb; kvm_ap_build_crycbd(kvm); + /* Default setting indicating SIE shall interpret AP instructions */ + kvm->arch.crypto.apie = 1; + if (!test_kvm_facility(kvm, 76)) return; @@ -2434,6 +2437,12 @@ static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu) { vcpu->arch.sie_block->crycbd = vcpu->kvm->arch.crypto.crycbd; + vcpu->arch.sie_block->eca &= ~ECA_APIE; + if (vcpu->kvm->arch.crypto.apie && + test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_AP)) + vcpu->arch.sie_block->eca |= ECA_APIE; + + if (!test_kvm_facility(vcpu->kvm, 76)) return; -- 1.7.1