Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4689698ybb; Tue, 7 Apr 2020 12:24:03 -0700 (PDT) X-Google-Smtp-Source: APiQypKunzQX54LubhsHgOrhpBWWVM+GqaJMF/c2YXSKUa/r7QgbLd35PPBwbocho+I/dtQWcpal X-Received: by 2002:a4a:3ec1:: with SMTP id t184mr1826674oot.3.1586287443312; Tue, 07 Apr 2020 12:24:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586287443; cv=none; d=google.com; s=arc-20160816; b=XjplgIaWYAzbkNhHKly25qG5CeonX0xTH7n2o2e730sVPcQO1QtQ9TnUr0DWrXiNHz v/UA3sF6q4hwsXiEx0ct3QGrm+xZszKOZ9R1GtPyOaP91W9fvEzP+LHXjDxN9zj+VY/4 iF9A7wEZ1Wv8aDIEnkR7uv41npM6Sumst5IVvPIkoRBSdDr1L6QX5D1PNfqIwxOUb8pc mvlYPYq37yi9eleDD+AbB1wO/b32CwDt0a/DRvAWIj6Q9h0TJVCXNDn6E+/eSwQdYtci kLfRlLBgybc4NeXu2bAh0PR0MTClWTJAOcCn4k9Mc5RmeZ4gveW/YRzxsE24wYRuKT2n 7vZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dcm0N4xftbDl0WPzXG+iIPsZ1k7/FVGbDcdiJNdT8lU=; b=a6LyAle7aqR8RAnZHpGOD+a80vTT+dfSeYJyh9iRYYeDhMu15ZdJlS2IbNqnvU8dwo WpR0BPeAEEvJq81qyiKnCqi0qauuRhF9C3X1xLzrI23ublC9rXBtA6lfo044zoqaHV2b Zk/85KPBn2dqcDuzYvLshrZRwJ8KV5CgGoJMx9+G8vDbcNHNupHPH2mOf6eegl0thNGv L4zEhDOfUn0Ju7KLFydvaIrisGcAohCf8TCXMVXtlGTIRpsOyi4lvA9btEOXo8oXtd+L /gKE0e5az801T42yZYoXimTgOhbDIwyDJaB9ST5YjQuxbldxZI5oKzdJ23ayXB9aLtmC XokQ== 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 e1si204500ooa.26.2020.04.07.12.23.49; Tue, 07 Apr 2020 12:24:03 -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 S1727942AbgDGTV1 (ORCPT + 99 others); Tue, 7 Apr 2020 15:21:27 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58938 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727078AbgDGTUg (ORCPT ); Tue, 7 Apr 2020 15:20:36 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 037J3QW7175408; Tue, 7 Apr 2020 15:20:35 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3082j93ej5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Apr 2020 15:20:35 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 037J3XMm176261; Tue, 7 Apr 2020 15:20:35 -0400 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com with ESMTP id 3082j93eht-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Apr 2020 15:20:35 -0400 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 037JKC8x026989; Tue, 7 Apr 2020 19:20:34 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma02dal.us.ibm.com with ESMTP id 306hv71382-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Apr 2020 19:20:34 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 037JKWoe53477690 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 7 Apr 2020 19:20:32 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7488628058; Tue, 7 Apr 2020 19:20:32 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BBCBF2805A; Tue, 7 Apr 2020 19:20:31 +0000 (GMT) Received: from cpe-172-100-173-215.stny.res.rr.com.com (unknown [9.85.207.206]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 7 Apr 2020 19:20:31 +0000 (GMT) From: Tony Krowiak To: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: freude@linux.ibm.com, borntraeger@de.ibm.com, cohuck@redhat.com, mjrosato@linux.ibm.com, pmorel@linux.ibm.com, pasic@linux.ibm.com, alex.williamson@redhat.com, kwankhede@nvidia.com, jjherne@linux.ibm.com, fiuczy@linux.ibm.com, Tony Krowiak Subject: [PATCH v7 05/15] s390/vfio-ap: introduce shadow CRYCB Date: Tue, 7 Apr 2020 15:20:05 -0400 Message-Id: <20200407192015.19887-6-akrowiak@linux.ibm.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200407192015.19887-1-akrowiak@linux.ibm.com> References: <20200407192015.19887-1-akrowiak@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-04-07_08:2020-04-07,2020-04-07 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 malwarescore=0 suspectscore=3 impostorscore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 mlxlogscore=999 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004070153 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's introduce a shadow copy of the KVM guest's CRYCB and maintain it for the lifespan of the guest. The shadow CRYCB will be used to provide the AP configuration for a KVM guest. Signed-off-by: Tony Krowiak --- drivers/s390/crypto/vfio_ap_ops.c | 31 +++++++++++++++++++++------ drivers/s390/crypto/vfio_ap_private.h | 1 + 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 8ece0d52ff4c..b8b678032ab7 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -280,14 +280,32 @@ static int handle_pqap(struct kvm_vcpu *vcpu) return 0; } +static void vfio_ap_matrix_clear(struct ap_matrix *matrix) +{ + bitmap_clear(matrix->apm, 0, AP_DEVICES); + bitmap_clear(matrix->aqm, 0, AP_DOMAINS); + bitmap_clear(matrix->adm, 0, AP_DOMAINS); +} + static void vfio_ap_matrix_init(struct ap_config_info *info, struct ap_matrix *matrix) { + vfio_ap_matrix_clear(matrix); matrix->apm_max = info->apxa ? info->Na : 63; matrix->aqm_max = info->apxa ? info->Nd : 15; matrix->adm_max = info->apxa ? info->Nd : 15; } +static bool vfio_ap_mdev_commit_crycb(struct ap_matrix_mdev *matrix_mdev) +{ + if (matrix_mdev->kvm && matrix_mdev->kvm->arch.crypto.crycbd) { + kvm_arch_crypto_set_masks(matrix_mdev->kvm, + matrix_mdev->shadow_crycb.apm, + matrix_mdev->shadow_crycb.aqm, + matrix_mdev->shadow_crycb.adm); + } +} + static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev) { struct ap_matrix_mdev *matrix_mdev; @@ -303,6 +321,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev) matrix_mdev->mdev = mdev; vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->matrix); + vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->shadow_crycb); mdev_set_drvdata(mdev, matrix_mdev); matrix_mdev->pqap_hook.hook = handle_pqap; matrix_mdev->pqap_hook.owner = THIS_MODULE; @@ -1126,13 +1145,9 @@ static int vfio_ap_mdev_group_notifier(struct notifier_block *nb, if (ret) return NOTIFY_DONE; - /* If there is no CRYCB pointer, then we can't copy the masks */ - if (!matrix_mdev->kvm->arch.crypto.crycbd) - return NOTIFY_DONE; - - kvm_arch_crypto_set_masks(matrix_mdev->kvm, matrix_mdev->matrix.apm, - matrix_mdev->matrix.aqm, - matrix_mdev->matrix.adm); + memcpy(&matrix_mdev->shadow_crycb, &matrix_mdev->matrix, + sizeof(matrix_mdev->shadow_crycb)); + vfio_ap_mdev_commit_crycb(matrix_mdev); return NOTIFY_OK; } @@ -1247,6 +1262,8 @@ static void vfio_ap_mdev_release(struct mdev_device *mdev) kvm_put_kvm(matrix_mdev->kvm); matrix_mdev->kvm = NULL; } + + vfio_ap_matrix_clear(&matrix_mdev->shadow_crycb); mutex_unlock(&matrix_dev->lock); vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h index 4b6e144bab17..87cc270c3212 100644 --- a/drivers/s390/crypto/vfio_ap_private.h +++ b/drivers/s390/crypto/vfio_ap_private.h @@ -83,6 +83,7 @@ struct ap_matrix { struct ap_matrix_mdev { struct list_head node; struct ap_matrix matrix; + struct ap_matrix shadow_crycb; struct notifier_block group_notifier; struct notifier_block iommu_notifier; struct kvm *kvm; -- 2.21.1