Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5421801pxu; Tue, 22 Dec 2020 17:19:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJyps/9XJ2rsWvTQ2HeNH7Bd2/6lbmbTSV+rH+H9we3dlu0Q2w7fxzT2jLs0wTRAw2g3Fx89 X-Received: by 2002:a17:906:7f13:: with SMTP id d19mr22779246ejr.54.1608686371222; Tue, 22 Dec 2020 17:19:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608686371; cv=none; d=google.com; s=arc-20160816; b=gTgnBs+PMUbkOjdbTi1DmGcBPR5RpToLS4KmQE/ELkJwskdN4t5/bROOttbm0F7jdY Z5QXkAjpDVBz5rpl0aWqAEUm9qZXCfHmDOZJLiLtXJYyBu14iiSoBNt0+ffTlcq4tY0T 1ZLZMdVpnEEeYktuPcwStmj68odyKNJFMletgNiq5htcIihwjF6oqkPRSKKhXVFCeXQq t+jFNQJrfCd4n4H+7MogZfZQM3pvQqXlMdUt61ZVWOIBIU59wMlNTuiHKbkH4Wr/N8c6 QvECj3cxvk9CT3CYoLuGtJ+IKSy+MZ/VbgrKhxkqlBhPb06ZRiUAW019ZLe3/seruAU5 q2uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=I9ZmKasAm4bfXl7qIShGujNR3oYll41kyERcEx01gn8=; b=bRusF94yeDJJrOkSHgKvNcjmqlGrGkfsyhW0s/mfuJF1/3b+on6IURXaE2VDzqGLSc C9wIXwaNInpNSm18Xnqg+C97IwGo0EOIZN1YECmyeOswzzU5fYAwNls1WBJy/tn0izU8 JXr723ipPFDARPJB7cEu8skDf/mSGKRY/rlLrnhyBSVIcRAt/nwWdESHBDVx6nvxvEcR YL626xhrf8U8fsro7dtGTw0O8bbxPdQ7h48KEO3cxS019k8YJAZ9mKZcaulnHdlFjRFZ S4FFzZhbBOQR1iwowvvkqSX/YeXPwF4Qxe52klMTmZWf2hcgXc/u2/NsNA1Jn1E6rmgo Rbzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=NytTp+d2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id no7si11085850ejb.586.2020.12.22.17.19.09; Tue, 22 Dec 2020 17:19:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=NytTp+d2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727100AbgLWBRJ (ORCPT + 99 others); Tue, 22 Dec 2020 20:17:09 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:29922 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726934AbgLWBRH (ORCPT ); Tue, 22 Dec 2020 20:17:07 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0BN11qP5070008; Tue, 22 Dec 2020 20:16:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=I9ZmKasAm4bfXl7qIShGujNR3oYll41kyERcEx01gn8=; b=NytTp+d2RzDOgtFUbwV7VzS9IMrJhbEpj8lxSkd414vgOzgJ3NC0kPe/wrnK2a3CBqQo xoTlYJes2tyjBHuFuphrA6v+yRkc8KQpv04BAQtE3/AAvIXORMZ3x/xFoTNWQuLojuTf MRScCpuYplQp7dGkPLYdfs6EQJamXr2JwuAeecJ5C3bVjR9x/CCpBDQW7TkkUQeWvV3U zO6zDXrT7aAgaoAZ/p5I1b8dB8l5qSvFPW1PkR2B1ec2EmqmpTnjvxMXSNZAMHoVLanl //jdlhMb6H7Chc/RysolmTaCwZqMeNium93F33pkt/KLSng4dklm3IKbIob5M7nrXjYe Gg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 35ksty2nh1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 20:16:25 -0500 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0BN13HBW075100; Tue, 22 Dec 2020 20:16:24 -0500 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0b-001b2d01.pphosted.com with ESMTP id 35ksty2nga-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 20:16:24 -0500 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0BN1CoUW014196; Wed, 23 Dec 2020 01:16:23 GMT Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by ppma01dal.us.ibm.com with ESMTP id 35kejb61c3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Dec 2020 01:16:23 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0BN1GLc530081420 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Dec 2020 01:16:21 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BFC8E112063; Wed, 23 Dec 2020 01:16:21 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F3F2112061; Wed, 23 Dec 2020 01:16:20 +0000 (GMT) Received: from cpe-66-24-58-13.stny.res.rr.com.com (unknown [9.85.193.150]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 23 Dec 2020 01:16:20 +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, pasic@linux.ibm.com, alex.williamson@redhat.com, kwankhede@nvidia.com, fiuczy@linux.ibm.com, frankja@linux.ibm.com, david@redhat.com, hca@linux.ibm.com, gor@linux.ibm.com, Tony Krowiak Subject: [PATCH v13 07/15] s390/vfio-ap: introduce shadow APCB Date: Tue, 22 Dec 2020 20:15:58 -0500 Message-Id: <20201223011606.5265-8-akrowiak@linux.ibm.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20201223011606.5265-1-akrowiak@linux.ibm.com> References: <20201223011606.5265-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.343,18.0.737 definitions=2020-12-22_13:2020-12-21,2020-12-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 impostorscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012230003 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The APCB is a field within the CRYCB that provides the AP configuration to a KVM guest. Let's introduce a shadow copy of the KVM guest's APCB and maintain it for the lifespan of the guest. Signed-off-by: Tony Krowiak Reviewed-by: Halil Pasic --- drivers/s390/crypto/vfio_ap_ops.c | 15 +++++++++++++++ drivers/s390/crypto/vfio_ap_private.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 2d58b39977be..44b3a81cadfb 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -293,6 +293,20 @@ static void vfio_ap_matrix_init(struct ap_config_info *info, matrix->adm_max = info->apxa ? info->Nd : 15; } +static bool vfio_ap_mdev_has_crycb(struct ap_matrix_mdev *matrix_mdev) +{ + return (matrix_mdev->kvm && matrix_mdev->kvm->arch.crypto.crycbd); +} + +static void vfio_ap_mdev_commit_shadow_apcb(struct ap_matrix_mdev *matrix_mdev) +{ + if (vfio_ap_mdev_has_crycb(matrix_mdev)) + kvm_arch_crypto_set_masks(matrix_mdev->kvm, + matrix_mdev->shadow_apcb.apm, + matrix_mdev->shadow_apcb.aqm, + matrix_mdev->shadow_apcb.adm); +} + static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev) { struct ap_matrix_mdev *matrix_mdev; @@ -308,6 +322,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_apcb); hash_init(matrix_mdev->qtable); mdev_set_drvdata(mdev, matrix_mdev); matrix_mdev->pqap_hook.hook = handle_pqap; diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h index 4e5cc72fc0db..d2d26ba18602 100644 --- a/drivers/s390/crypto/vfio_ap_private.h +++ b/drivers/s390/crypto/vfio_ap_private.h @@ -75,6 +75,7 @@ struct ap_matrix { * @list: allows the ap_matrix_mdev struct to be added to a list * @matrix: the adapters, usage domains and control domains assigned to the * mediated matrix device. + * @shadow_apcb: the shadow copy of the APCB field of the KVM guest's CRYCB * @group_notifier: notifier block used for specifying callback function for * handling the VFIO_GROUP_NOTIFY_SET_KVM event * @kvm: the struct holding guest's state @@ -82,6 +83,7 @@ struct ap_matrix { struct ap_matrix_mdev { struct list_head node; struct ap_matrix matrix; + struct ap_matrix shadow_apcb; struct notifier_block group_notifier; struct notifier_block iommu_notifier; struct kvm *kvm; -- 2.21.1