Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2928122pxb; Tue, 12 Jan 2021 01:58:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHBA7R5f1ReL5FSHTQKIYw9mWtz+ZjSvb9G3smFrvBlabdZvB9OgsdFL5odNWwkxXKTXsZ X-Received: by 2002:a17:906:32d6:: with SMTP id k22mr2629601ejk.457.1610445521057; Tue, 12 Jan 2021 01:58:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610445521; cv=none; d=google.com; s=arc-20160816; b=Bz9BRJJflFrCs+Bd3+41Oy4AtGW8sbvD2EpSWlar2hoTYgBV9yXIG6MWyecxUj5yug TO4YzeKqMEUvY98u50WfPOZMtoKbgOG/8WmNkojNQ4ajs51Rlehw1Zx3GXQUyZ84fGCc 07LUaFDgRIvmAcPHsAPrz22DsHIkuScCaxqZBunSBswYAiz5QW3QwbR5clKa7R3zzgds 603ZJads/A1mptUXF5NmW90nDsSdTq/TsQTKUQArUIFuq3n2xtC6RR/iTyvG7uglw+aP Lr7GTc7Agp60SBjjd6U5Y75KcQQb64MeGrhPPOheGdzmngAyGhaVfqFQ+QBymQG9fZqU 6zMw== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=gFlsFNC1Oe0RvfBumwJid1hGTPKfT0h2UQQ/7FjjipI=; b=YrsJ+7J51ljg06bpyetRA9fBzZsZjc4x96Uw/X9m/9RyAlTRpUwC5yeIyrbNuuiH36 SdPuxVX6JZ7v9VvPMTlGsmyWR3SD27HP2Ofp7v6THNujt7OpfxJBozejmVvc9cxWZsLk CI2P4LlwO+eylE7fALfLQ0KrnH7MZ6M4Zj6GENPt3t10Q8392b+HJuPGlddkzr/gu5Mq X27mbDLVAfWGhIATnn567KK5xUk7q9J95CUOlvQACn59phcyIYQoJKX0pPC1MV8fBRiZ eSExdfloyrUHzEL5wL1i8maodtfyrvu4Ha7EGk4KH87FOZqwwWkBS/bSX1lVkxQlZD1b 3d/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=QxMc0RU1; 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 o11si1094436edq.506.2021.01.12.01.58.17; Tue, 12 Jan 2021 01:58:41 -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=QxMc0RU1; 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 S2390987AbhALAYk (ORCPT + 99 others); Mon, 11 Jan 2021 19:24:40 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:15778 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390779AbhAKWvv (ORCPT ); Mon, 11 Jan 2021 17:51:51 -0500 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 10BMgo5U073366; Mon, 11 Jan 2021 17:51:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=gFlsFNC1Oe0RvfBumwJid1hGTPKfT0h2UQQ/7FjjipI=; b=QxMc0RU1KK5Zyf7JQBFjVUoHzUNEUqqgJ6lw5RxAlJhFX8uDglm/QMQUL/yJj8P2E6yU bDkDuF+nzDF8rMThvCE6oxrU7VJoGf4BVyCUewqoGnC+YrDo/bK92zbH0+HlNnX9nXbT KW1tzwbwmZxTczMiRmCb+ta8dr24SgVA5KOMv8dvJ5QCeRqXZuVAUPLyRbM42fRQQ137 QcjhtOl2lZxCedVD9WX228D/07OJdoqRBB75EoFuz5A3VAGcwppRVaHsJM95MX2Tf3jv 6H4h3j+wJKMsx861t2XryCA3sJJyn/3XFAhQdoB8pjNCFa44EgW3c5UYtKS6ktKVfQSq Sg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 360yq185fq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Jan 2021 17:51:06 -0500 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 10BMihOL081865; Mon, 11 Jan 2021 17:51:06 -0500 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 360yq185fc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Jan 2021 17:51:06 -0500 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 10BMlwCM025548; Mon, 11 Jan 2021 22:51:04 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06ams.nl.ibm.com with ESMTP id 35ydrdadyy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Jan 2021 22:51:04 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 10BMouTR30540188 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Jan 2021 22:50:56 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 491C5A405B; Mon, 11 Jan 2021 22:51:01 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 86787A4051; Mon, 11 Jan 2021 22:51:00 +0000 (GMT) Received: from li-e979b1cc-23ba-11b2-a85c-dfd230f6cf82 (unknown [9.171.92.32]) by d06av23.portsmouth.uk.ibm.com (Postfix) with SMTP; Mon, 11 Jan 2021 22:51:00 +0000 (GMT) Date: Mon, 11 Jan 2021 23:50:58 +0100 From: Halil Pasic To: Tony Krowiak Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, freude@linux.ibm.com, borntraeger@de.ibm.com, cohuck@redhat.com, mjrosato@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 Subject: Re: [PATCH v13 07/15] s390/vfio-ap: introduce shadow APCB Message-ID: <20210111235058.32ed94b5.pasic@linux.ibm.com> In-Reply-To: <20201223011606.5265-8-akrowiak@linux.ibm.com> References: <20201223011606.5265-1-akrowiak@linux.ibm.com> <20201223011606.5265-8-akrowiak@linux.ibm.com> Organization: IBM X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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=2021-01-11_32:2021-01-11,2021-01-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 mlxlogscore=999 bulkscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 adultscore=0 impostorscore=0 mlxscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101110122 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 22 Dec 2020 20:15:58 -0500 Tony Krowiak wrote: > 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; What happened to the following hunk from v12? @@ -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; }