Received: by 10.192.165.156 with SMTP id m28csp167130imm; Tue, 17 Apr 2018 08:12:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx4809xeyJCKXXLGrYxdYgKo0Ee3hneRwGf7uCEhcLRz11MSKDRI5UwpUXfi7I3sV+6N7du4q X-Received: by 2002:a17:902:30a3:: with SMTP id v32-v6mr2430476plb.123.1523977922613; Tue, 17 Apr 2018 08:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523977922; cv=none; d=google.com; s=arc-20160816; b=qAH/rSdr5YjG/HwVJZRgszrZAKCdDKBHprsms2h+rpo60DO+6ZBgCyQgVK5uwyVwux UNDEDu4vougw2W3HJqmttI3BJ16dpYhSzcX739OQ511qAiRuu0JE3QuWaZMYSCuofLH0 3AHtImB1zsu8nek3b/2/gR5A3UeQDr6E3L1Y1OJEy87vI8bGIOu58Ca9tQBtBIoANf7c wFqEm3fLH2LixDmBWegBucH+tD2e/MKR8cB5Z9hXrHkLeyELnD9kXqkURv8ycKscp4VC IINwwIIuKMxzql1c6sYi3pQNLYv5oo7mmsfrzfdifind8jd5nMiv9IhgBNMQB2EwB9Wr 6x8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :from:references:cc:to:subject:arc-authentication-results; bh=99CnpsYJjEtJuKrB9Ip/fae5NdKjg/KMmHwQEmDiqFw=; b=lntAeCJnDhDZjGra3V80boNwV7bFYk+f6lfXg7BlrUItUpZQyBiY4KJ5Vjrk4/QtH7 fBrfbCigqSmgMYNQ4t0snSkRbsFPM3VTMYZokLC4pFgG+MOki/4iO/1TB6Dnj+H3KMNp YDat4lF6aJHp2R3Ny0nUGvg7nRJve3rMvmvBtTJFdKOIPo+WW+o44jJwQ5wIcx3JnOpo ksjHggx69nwq5fbxKLsQSYX9/PdAexGe/HpqyzJR0i1F9iKZ4gKyBY1vZ/oWIrHp+rOC VhRkJgYCthCEFRIHPOAkKa7QhJAWDZR/mw2Ex079Zxh4FKLsW0O+/lqRrKKnfIkU/Hxl jcsg== 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 f123si12715834pfa.364.2018.04.17.08.11.48; Tue, 17 Apr 2018 08:12:02 -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 S1752876AbeDQPKF (ORCPT + 99 others); Tue, 17 Apr 2018 11:10:05 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38330 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752649AbeDQPKD (ORCPT ); Tue, 17 Apr 2018 11:10:03 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3HEvPbO098101 for ; Tue, 17 Apr 2018 11:10:03 -0400 Received: from e14.ny.us.ibm.com (e14.ny.us.ibm.com [129.33.205.204]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hdj165876-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Tue, 17 Apr 2018 11:10:02 -0400 Received: from localhost by e14.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Apr 2018 11:10:01 -0400 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e14.ny.us.ibm.com (146.89.104.201) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 17 Apr 2018 11:09:57 -0400 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3HF9lQT49348790; Tue, 17 Apr 2018 15:09:56 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B910F124050; Tue, 17 Apr 2018 12:11:58 -0400 (EDT) Received: from oc8043147753.ibm.com (unknown [9.85.136.174]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP id 36E0612403D; Tue, 17 Apr 2018 12:11:57 -0400 (EDT) Subject: Re: [PATCH v4 05/15] KVM: s390: enable/disable AP interpretive execution To: Pierre Morel , 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, 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 References: <1523827345-11600-1-git-send-email-akrowiak@linux.vnet.ibm.com> <1523827345-11600-6-git-send-email-akrowiak@linux.vnet.ibm.com> <15b60572-40d6-0f03-11f9-c50cb7eb00e8@linux.vnet.ibm.com> <15bb0c9b-e605-232b-4dd2-826b6ee0d045@linux.vnet.ibm.com> From: Tony Krowiak Date: Tue, 17 Apr 2018 11:09:54 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <15bb0c9b-e605-232b-4dd2-826b6ee0d045@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 18041715-0052-0000-0000-000002DD0BAF X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008871; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000257; SDB=6.01019261; UDB=6.00519973; IPR=6.00798502; MB=3.00020618; MTD=3.00000008; XFM=3.00000015; UTC=2018-04-17 15:10:00 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041715-0053-0000-0000-00005C5D59AB Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-17_08:,, 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-1804170134 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/16/2018 07:13 AM, Pierre Morel wrote: > On 16/04/2018 12:51, Pierre Morel wrote: >> On 15/04/2018 23:22, Tony Krowiak wrote: >>> 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)) { >> >> Do we really need to test CPU_FEAT_AP? >> >> I understand that KVM_S390_VM_CPU_FEAT_AP means AP instructions are >> interpreted. >> shouldn't we add this information in the name? >> like KVM_S390_VM_CPU_FEAT_APIE > > If I misunderstood and FEAT_AP really mean AP instructions available > in the guest, > same question: > is this function called if AP instructions are not available in the > guest? > >> >>> + 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)) >> >> Do we call xxx_crypto_setup() if KVM does not support AP interpretation? > > sorry, I should have written AP instructions here: > is this function called if AP instructions are not available in the guest? Yes, as I stated in a previous email, this function is called by kvm_arch_vcpu_setup(vcpu) regardless of whether AP instructions are available on the guest or not. > > >> >>> + vcpu->arch.sie_block->eca |= ECA_APIE; >>> + >>> + >>> if (!test_kvm_facility(vcpu->kvm, 76)) >>> return; >>> >> >