Received: by 10.213.65.68 with SMTP id h4csp3512878imn; Tue, 3 Apr 2018 06:20:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Fdl+Ryp52fhlgKTPzM1UNNEo+FM137m9KbdQd+iqE7tGKGeM+cC5S07UziH25LaUUcr6V X-Received: by 2002:a17:902:1a4:: with SMTP id b33-v6mr14168189plb.303.1522761638992; Tue, 03 Apr 2018 06:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522761638; cv=none; d=google.com; s=arc-20160816; b=e1NxZWW52iXiRd6WrWkKcIGUNLipL0n3hLjtDBYaBhceX48fHn32XDJuseWMz1ETNy +QRdLikXbrUt9Vxjpcy+t6jHHHqy4N/EFhbu7dZY1OA6J3ludJEknGTIkm71AtjRoy4g yzHV+pcWeprlcyZi7QZKgv7HrAi2mnggdqkEo0zagqpZgkSsepc7Fx85OdVLDHh0y4Xd pMmFuOkizdkT4NNV1O36Efona82b+niMtP2szDdteM9+Ufm4sifiAgO5Xzk9bh4sSbi/ 7gMaHSa5U4JXQCAOGpGB2UH2AP1Hy74BxH2l4pvWwry574WU6QVfOFjTG7GMJCuOvHFG mhCw== 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=c3X4RiEVBXNN57MVGVR8EbZI1daSaj94sEhv3u8R99w=; b=NhRdOpdyR9e8QoaNYqHriREaOwYwWsntSvSJKkLhQdA0dg3mvZqbv6/MbA48T6FMrS cjnOi1MlX9kqzVXPQtQWVComCpsQNSNMBgBkBXWrJEe4W8iTHa8G0mA1ic1oMIn9ix8J SN3HALm5yIn5kSu2aknCjOvw6zk6xPVemNzBJW+YCJCbkJteU2PxuQuRFLn78qc9pI0r 2P43UyNfBPFvRi6qRJlA9ZKk0AnTAAafvR0PQdSG2uvmG2RAGJ5FdKRsPLicdqBNlNID PdvaA9BtnePPUfPfUr/snuOROvNQPF3VV+NJizX9qYKrxhwz9N8QGwssG7DRMBW8+eEc SBqg== 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 v12si366041pfe.164.2018.04.03.06.20.21; Tue, 03 Apr 2018 06:20:38 -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 S932272AbeDCNSr (ORCPT + 99 others); Tue, 3 Apr 2018 09:18:47 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:55278 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932151AbeDCNSq (ORCPT ); Tue, 3 Apr 2018 09:18:46 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w33DHWwA128454 for ; Tue, 3 Apr 2018 09:18:45 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0b-001b2d01.pphosted.com with ESMTP id 2h4aaxr8dh-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Tue, 03 Apr 2018 09:18:44 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 3 Apr 2018 07:18:08 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 3 Apr 2018 07:18:05 -0600 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w33DI39f9371930; Tue, 3 Apr 2018 06:18:03 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 22D12136044; Tue, 3 Apr 2018 07:18:03 -0600 (MDT) Received: from oc8043147753.ibm.com (unknown [9.60.75.175]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP id A147E136040; Tue, 3 Apr 2018 07:18:00 -0600 (MDT) Subject: Re: [PATCH v3 07/14] KVM: s390: interfaces to configure/deconfigure guest's AP matrix To: Cornelia Huck Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, freude@de.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, borntraeger@de.ibm.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 References: <1521051954-25715-1-git-send-email-akrowiak@linux.vnet.ibm.com> <1521051954-25715-8-git-send-email-akrowiak@linux.vnet.ibm.com> <20180403130758.43851026.cohuck@redhat.com> From: Tony Krowiak Date: Tue, 3 Apr 2018 09:17:59 -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: <20180403130758.43851026.cohuck@redhat.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: 18040313-0004-0000-0000-000013E57B20 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008795; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000255; SDB=6.01012515; UDB=6.00516034; IPR=6.00791779; MB=3.00020390; MTD=3.00000008; XFM=3.00000015; UTC=2018-04-03 13:18:08 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18040313-0005-0000-0000-000086BA07D1 Message-Id: <474b7d18-69ea-631f-214c-f9345119e537@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-04-03_05:,, 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-1804030140 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/03/2018 07:07 AM, Cornelia Huck wrote: > On Wed, 14 Mar 2018 14:25:47 -0400 > Tony Krowiak wrote: > >> Provides interfaces to assign AP adapters, usage domains >> and control domains to a KVM guest. >> >> A KVM guest is started by executing the Start Interpretive Execution (SIE) >> instruction. The SIE state description is a control block that contains the >> state information for a KVM guest and is supplied as input to the SIE >> instruction. The SIE state description has a satellite structure called the >> Crypto Control Block (CRYCB). The CRYCB contains three bitmask fields >> identifying the adapters, queues (domains) and control domains assigned to >> the KVM guest: >> >> * The AP Adapter Mask (APM) field identifies the AP adapters assigned to >> the KVM guest >> >> * The AP Queue Mask (AQM) field identifies the AP queues assigned to >> the KVM guest. Each AP queue is connected to a usage domain within >> an AP adapter. >> >> * The AP Domain Mask (ADM) field identifies the control domains >> assigned to the KVM guest. >> >> Each adapter, queue (usage domain) and control domain are identified by >> a number from 0 to 255. The bits in each mask, from most significant to >> least significant bit, correspond to the numbers 0-255. When a bit is >> set, the corresponding adapter, queue (usage domain) or control domain >> is assigned to the KVM guest. >> >> This patch will set the bits in the APM, AQM and ADM fields of the >> CRYCB referenced by the KVM guest's SIE state description. The process >> used is: >> >> 1. Verify that the bits to be set do not exceed the maximum bit >> number for the given mask. >> >> 2. Verify that the APQNs that can be derived from the intersection >> of the bits set in the APM and AQM fields of the KVM guest's CRYCB >> are not assigned to any other KVM guest running on the same linux >> host. >> >> 3. Set the APM, AQM and ADM in the CRYCB according to the matrix >> configured for the mediated matrix device via its sysfs >> adapter, domain and control domain attribute files respectively. >> >> Signed-off-by: Tony Krowiak >> --- >> arch/s390/include/asm/kvm-ap.h | 36 +++++ >> arch/s390/kvm/kvm-ap.c | 268 +++++++++++++++++++++++++++++++++ >> drivers/s390/crypto/vfio_ap_ops.c | 19 +++ >> drivers/s390/crypto/vfio_ap_private.h | 4 + >> 4 files changed, 327 insertions(+), 0 deletions(-) >> >> diff --git a/arch/s390/kvm/kvm-ap.c b/arch/s390/kvm/kvm-ap.c >> index a2c6ad2..eb365e2 100644 >> --- a/arch/s390/kvm/kvm-ap.c >> +++ b/arch/s390/kvm/kvm-ap.c >> @@ -8,9 +8,129 @@ >> >> #include >> #include >> +#include >> >> #include "kvm-s390.h" >> >> +static inline void kvm_ap_clear_crycb_masks(struct kvm *kvm) >> +{ >> + int crycb_fmt = kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK; >> + >> + if (crycb_fmt == CRYCB_FORMAT2) >> + memset(&kvm->arch.crypto.crycb->apcb1, 0, >> + sizeof(kvm->arch.crypto.crycb->apcb1)); >> + else >> + memset(&kvm->arch.crypto.crycb->apcb0, 0, >> + sizeof(kvm->arch.crypto.crycb->apcb0)); >> +} > Should that rather be a switch/case? If there's a CRYCB_FORMAT3 in the > future, I'd think that it's more likely that it uses apcb1 and not > apcb0. Can't comment further without the architecture, obviously. Maybe we should just clear both structures without regard to the CRYCB format. > > (...) > >> +static void kvm_ap_set_crycb_masks(struct kvm *kvm, >> + struct kvm_ap_matrix *matrix) >> +{ >> + unsigned long *apm = kvm_ap_get_crycb_apm(kvm); >> + unsigned long *aqm = kvm_ap_get_crycb_aqm(kvm); >> + unsigned long *adm = kvm_ap_get_crycb_adm(kvm); >> + >> + kvm_ap_clear_crycb_masks(kvm); >> + memcpy(apm, matrix->apm, KVM_AP_MASK_BYTES(matrix->apm_max)); >> + memcpy(aqm, matrix->aqm, KVM_AP_MASK_BYTES(matrix->aqm_max)); >> + >> + /* >> + * Merge the AQM and ADM since the ADM is a superset of the >> + * AQM by architectural convention. > Is this 'architectural convention' in the sense of 'there's a statement > in the architecture that it always is like that', or in the sense of > 'all real-life systems are like that'? > [From my sketchy memory, this convention makes sense but is not > enshrined; but I might misremember.] The documentation states it is an agreed upon convention. > >> + */ >> + bitmap_or(adm, adm, aqm, matrix->adm_max); >> +}