Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2053474pxu; Tue, 24 Nov 2020 16:00:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzj2JsN/1KgNR8AVN/qwpOJwpWrvJXM5QcBFQbRQfFMW+Gh6KHS3lIyq9Ttshgxq7PxQ5d X-Received: by 2002:a17:906:76c2:: with SMTP id q2mr845370ejn.444.1606262456772; Tue, 24 Nov 2020 16:00:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606262456; cv=none; d=google.com; s=arc-20160816; b=eIqsBMYY4py5opCUxtD0culDAFY0mkhmObIfPoCKy5aSMDK7b4aeRwpHymDTsiURUC fBDj+JXPPqxKNxra5hPGUXcEZ4ELBDCKPbykBeVG4HMNn79XYJAh9Nc99f1z635WTRPR 8AaMgwYY0fCU91HpZ37rjNcXS0j8PA15yXVnsUm9xzSyzypj5WtbBDxyMXrvJaRVBy9q E2opi2IDUAoxZXCQh0HAcLWr4KNcmSrPLISwjJkvkg/f0efvAg2rws55FXZygjTgeaas LaydyrLdpAUe89oHru4KRxvsIik6Od4oOH10XmPMPEtknvD9/hai06FIaZZCOHZ7/jbB xA2w== 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=vMikA9n5kjdXS8kLIMK7N5v87/Xeme3vvORzlRXFTMA=; b=lTPHzq4lpLLJRXXdsKZUR+tM7qNZbtr6ArvOpCPb05Soy5zRFTOzRS0EVR3W+IJlGV RRouxiRHIaTHUHThiCNd96bVAO9xAchoRRQWXqsTLg36G2h0rmHO6C0PO8qNcrj3n/cc Rwlbm44TkZgrt0faPh0+gQD85uN7ErupyrV9wrLL45iap+IPRU2pG7T08LL3PcWwTk+B 3IcLI9dUzdeQzMtEwxUWKGuR1gNjsN3jYtj/Q6SI1Va8a1dmHschbtWWaqa8wEIw+e2U /zpT2H6URPMgQMWOYuM2kGEwb8GgvzHbxy6jgEyt32mOv9AAE0WYzkBBBc/wOxKzf6IA tI1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="s/jCe3MJ"; 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 p15si161864edx.69.2020.11.24.16.00.34; Tue, 24 Nov 2020 16:00:56 -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="s/jCe3MJ"; 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 S1733213AbgKXVkm (ORCPT + 99 others); Tue, 24 Nov 2020 16:40:42 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41740 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733139AbgKXVkl (ORCPT ); Tue, 24 Nov 2020 16:40:41 -0500 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 0AOLXqf0009301; Tue, 24 Nov 2020 16:40:38 -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=vMikA9n5kjdXS8kLIMK7N5v87/Xeme3vvORzlRXFTMA=; b=s/jCe3MJwmtC/ZdsqGIMKtg90yh+gexvpu/NjHk6zuCjNtVUIfd4WlnRzYMPJZNc/b+k B839Z6ZvjE/c/Bh4utexSf/EEBKm63fUZ3/NPM1KBgP0AntCm5HZXFrfa70rJjwEs4IU B30gnheAsqeaFDJyCXM5GQJWcWxqD6KBPIFl6gBBCnTBXV0YO5qauGs3/MkNWFT0z1C4 U1Fsk6FGnbV7jZJ34Zt3dHypSBQnuRxTwbs+gq4TMBVnBLuyrqM5vHQrGG3JTiWfuHnw e+2FXdBBopqxnCHoS0Rw9ZTArUTPm6AhOOxymrBdqQ4iXblKjyheiyrgp45gNl1PPIbt FQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 350fe1mxgq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 24 Nov 2020 16:40:38 -0500 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 0AOLXxJV011598; Tue, 24 Nov 2020 16:40:38 -0500 Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com with ESMTP id 350fe1mxg0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 24 Nov 2020 16:40:37 -0500 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0AOLbLPb009342; Tue, 24 Nov 2020 21:40:36 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma02wdc.us.ibm.com with ESMTP id 34xth92kqh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 24 Nov 2020 21:40:36 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0AOLeZn715335818 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Nov 2020 21:40:35 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F79DAE066; Tue, 24 Nov 2020 21:40:35 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E94BAE05C; Tue, 24 Nov 2020 21:40:34 +0000 (GMT) Received: from cpe-66-24-58-13.stny.res.rr.com.com (unknown [9.85.195.249]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 24 Nov 2020 21:40:33 +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 v12 08/17] s390/vfio-ap: introduce shadow APCB Date: Tue, 24 Nov 2020 16:40:07 -0500 Message-Id: <20201124214016.3013-9-akrowiak@linux.ibm.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20201124214016.3013-1-akrowiak@linux.ibm.com> References: <20201124214016.3013-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.312,18.0.737 definitions=2020-11-24_09:2020-11-24,2020-11-24 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=999 phishscore=0 impostorscore=0 suspectscore=3 mlxscore=0 spamscore=0 clxscore=1015 adultscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011240126 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 | 25 ++++++++++++++++++------- drivers/s390/crypto/vfio_ap_private.h | 2 ++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 3c2479d7e674..89b0e81657ca 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -318,6 +318,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; @@ -333,6 +347,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; @@ -1218,13 +1233,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_apcb, &matrix_mdev->matrix, + sizeof(matrix_mdev->shadow_apcb)); + vfio_ap_mdev_commit_shadow_apcb(matrix_mdev); return NOTIFY_OK; } diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h index 8b9b5255abfe..15b7cd74843b 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