Received: by 10.192.165.156 with SMTP id m28csp973957imm; Wed, 18 Apr 2018 01:32:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx49giMOftxyqAtlwf7yv+oezecKV2XrB/mw11GM99CUmfaLkh+DHiQl3m1t6BW0KLzzR7xFu X-Received: by 2002:a17:902:7c0e:: with SMTP id x14-v6mr1243452pll.392.1524040371692; Wed, 18 Apr 2018 01:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524040371; cv=none; d=google.com; s=arc-20160816; b=slfMkYiJkmrlCsoY98ZyQqkI+MaEmqDF7oNXBE7i6XEnB7nrh2SwPCFmKsoTwGEcZN LL3T6BFAv9ScVJw6aNM6aquvXQ+/R1x+6bxJk1Nf1wYyhQccZlunwtWvZcj5Fa8K6yTy Y3KN2eetSRGDisLb3or3keeDw+BpeL/FAwWdj1eDrUl1J9sYErUOhXoQ2w0XlwOISQ5L 3P5WipX0GY6kR51brr8ZGsq18t1KoqQi/4VwBSM2FB44lN/K5AbgcDrOUmP8BCyemGqp fVpGloJgdAVB0MPQg8WR7YTSi4qMvFwIK/qkACirWwTWQDtyZ37KOXNT3FGyRs94IAqY 36qg== 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=kMgq7awhwDXHwNTFq6uCgVoDauzs/E2YVDU053bP7co=; b=fU/Zh1Pd8ONW6BP12LWOXEX79PlAnn5tcsJRaq+8vb4UBSWAxhc0wfKRmzQXJpFqGj 0b6lkF/R3URKzcMlT0qVhIx1FnEyp9E+RcuPO6KTOH1LlXgFdQzX/CgzLIwsiWPQgwo1 npMgB521zExXm1zc4MFzK7gb5aD5M75f5YOgQ1AKL0VN5R0Lj3sI89mKpjary/sU5r7/ WVZ1BiIp2Xs9jaNYwu4YMyMr7SW+FmlZ96cQzBpSP9G+SMcwjs79EQYgfaFKLC9t01kN 6EG8Hlij1oePOxyZ1lRJISMof7+ooFGP4Ix312hQPKYFxaEXY8OR1e7NZ4VAC2zKrBR2 99kA== 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 s6-v6si892472plp.18.2018.04.18.01.32.37; Wed, 18 Apr 2018 01:32:51 -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 S1753540AbeDRIbT (ORCPT + 99 others); Wed, 18 Apr 2018 04:31:19 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:60828 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753164AbeDRIbQ (ORCPT ); Wed, 18 Apr 2018 04:31:16 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3I8U7KM054441 for ; Wed, 18 Apr 2018 04:31:16 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0b-001b2d01.pphosted.com with ESMTP id 2he24qsgfg-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Wed, 18 Apr 2018 04:31:15 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 18 Apr 2018 09:31:14 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 18 Apr 2018 09:31:11 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3I8V9SN58720260; Wed, 18 Apr 2018 08:31:09 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3987011C052; Wed, 18 Apr 2018 09:23:05 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 482C511C050; Wed, 18 Apr 2018 09:23:04 +0100 (BST) Received: from [9.152.224.146] (unknown [9.152.224.146]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 18 Apr 2018 09:23:04 +0100 (BST) Subject: Re: [PATCH v4 05/15] KVM: s390: enable/disable AP interpretive execution To: Tony Krowiak , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, buendgen@de.ibm.com 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 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> <6cba35df-b0de-8000-bb39-c4cec8622c57@linux.vnet.ibm.com> <2b053349-071e-17ed-6ebd-a37bcfd2f330@linux.vnet.ibm.com> <0d18aeef-dfe7-89b6-f91e-022a71fb5ed9@linux.vnet.ibm.com> From: Pierre Morel Date: Wed, 18 Apr 2018 10:31:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <0d18aeef-dfe7-89b6-f91e-022a71fb5ed9@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 18041808-0044-0000-0000-000005497EA5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041808-0045-0000-0000-0000288991CA Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-18_02:,, 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-1804180080 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/04/2018 20:11, Tony Krowiak wrote: > On 04/17/2018 12:55 PM, Pierre Morel wrote: >> On 17/04/2018 18:22, Tony Krowiak wrote: >>> On 04/17/2018 12:13 PM, Pierre Morel wrote: >>>> On 17/04/2018 17:02, Tony Krowiak wrote: >>>>> On 04/16/2018 06:51 AM, 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? >>>>> >>>>> Yes we do. >>>> >>>> really? why? >>> >>> The KVM_S390_VM_CPU_FEAT_AP will not be enabled by KVM if the AP >>> instructions are not installed on the host. I assume - but have >>> no way of verifying - that if the AP instructions are not installed >>> on the host, that interpretation would fail. Do you know what would >>> happen if AP instructions are interpreted when not installed on >>> the host? >> >> If the host has no AP instructions (his ECA.28=0) but it set ECA.28 >> for a guest, >> there will be no AP instructions available in the guest. > > Then there's the answer to your question; this is why we to test > CPU_FEAT_AP. We can postpone this discussion when we discuss on VSIE. For this specific call I just wanted to point out that obviously this function should not be called if the guest has no AP instructions. > >> >> >>> >>>> >>>> >>>>> >>>>>> >>>>>> >>>>>> 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 >>>>> >>>>> KVM_S390_VM_CPU_FEAT_AP does NOT mean AP instructions are >>>>> interpreted, it means >>>>> AP instructions are installed. >>>> >>>> Right same error I made all along this review. >>>> But AFAIK it means AP instructions are provided to the guest. >>>> Then should this function be called if the guest has no AP >>>> instructions ? >>>> >>>> >>>>> >>>>>> >>>>>>> +        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? >>>>> >>>>> Yes, kvm_s390_vcpu_crypto_setup(vcpu) is called by >>>>> kvm_arch_vcpu_setup(vcpu) >>>>> as well as from kvm_s390_vcpu_crypto_reset_all(kvm). Calling it >>>>> has nothing >>>>> to do with whether AP interpretation is supported or not as it >>>>> does much >>>>> more than that, including setting up of wrapping keys and the CRYCBD. >>>> >>>> Sorry, still the same error I made about CPU_FEAT_AP meaning AP >>>> instructions in the guest >>>> and not AP interpretation available. >>>> Could apie be set if AP instruction are not supported? >>>> >>>>> >>>>>> >>>>>>> + vcpu->arch.sie_block->eca |= ECA_APIE; >>>>>>> + >>>>>>> + >>>>>>>       if (!test_kvm_facility(vcpu->kvm, 76)) >>>>>>>           return; >>>>>>> >>>>>> >>>>> >>>> >>> >> > -- Pierre Morel Linux/KVM/QEMU in Böblingen - Germany