Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp84659pxu; Wed, 2 Dec 2020 15:48:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxh5kGCchfbt5pRlfgWpt7XC1RvNeovrpJxG8+1zDlM14sxAcontdzuQ9yamNEU2DzbkjpQ X-Received: by 2002:aa7:c58a:: with SMTP id g10mr402200edq.315.1606952885912; Wed, 02 Dec 2020 15:48:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606952885; cv=none; d=google.com; s=arc-20160816; b=jvvZJJGXRqpk7DcVTIJJ6mUoKymw2nwYUdYDjDJjjxsncL92mp/QfO5+VCHyiGbUCb FVypdwdYHGAeh8rbcHTZVAPoTpCU+QUb7qFaAnkvSEch9B/EBpopdoMpeKf4ufughDGv JmwHmsAoK7RIzOD06KzZb71FWEg78Xrb7L4MTZHSaUFJxb/fPcXi60Na+NOZhp1W6ORC R/xtSUALtAzINzGT9BYNTqU52lVueHm13vAk95KW8luvkd5z7jukUJVEsuTJqDFRNI+d Ifr56wz5lkwrIfBUMWoRmouQNCIXaZA9LCW+sgIojR1xBgCPOFOAq92+MiwrlXwaAQuI UGsA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=HZLCVTOJklfB/d+YwxQ45wGtBPnDTEIvfKqqNrqkEoU=; b=0YXYtpgDOv4FNvo3PzzP+FfP0atXuSrtNnJZpATueI7EazLkhPLyj8Jx/RJyqKLi96 wMjccOhAkEoZ5U9sidUHAz0r9fPHwuNlHwgrzks3UQM+ImQEjMq2jfJYVJ5zMfcmtKxR bYlLNfxEOEumSBJU9rSR02ZWYYEgbc/ozd68JRULBGUefbEORuEuqLEiL9zXvIi1M1O1 +GaCuo0kKztp58tK9piqTFZimBWovG8y3DL6/lULNV7Q6hW4j2LUXkiTFhBM3k6vLzNW S3/7xdVpQ964Ng1s0d49MELasmq0YszCb9ktcU4DsQfoXCC+HXLFtadtsag1zrLOumNP ClTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=FUiAd3YF; 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 c23si91351ejx.330.2020.12.02.15.47.42; Wed, 02 Dec 2020 15:48:05 -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=FUiAd3YF; 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 S1729204AbgLBXnJ (ORCPT + 99 others); Wed, 2 Dec 2020 18:43:09 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:13994 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728186AbgLBXnJ (ORCPT ); Wed, 2 Dec 2020 18:43:09 -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 0B2NYSiJ083175; Wed, 2 Dec 2020 18:42:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=HZLCVTOJklfB/d+YwxQ45wGtBPnDTEIvfKqqNrqkEoU=; b=FUiAd3YFKnQMHnmftvsGx9f8XXgHVWDwYDpXLC60mzzP/3spSBfy1GUuurKxBfPGLcy4 CMQ5Kk54vsGW5eBkf2NWW8w5LVOpkl/7i9fd3iU2iLXBqlKltshw7HqDd9Vgt3I8VdUj oQx+PFFPG4r1dq8Tlp7NGBgj4dqj5mBEJrHCz+yKeIgRftNRpbJGhdb7mP2NpMJEyJIe qc5xcz7cGsL+bFav7tTNlE3Sk1OMWK5fMiATbhA5bnLsKqvFznRTI3GG/yfHUsQcRU49 qOA+9meiXLD9kfcikfkJ3dCOOHMZkMacCChbDzlZpjfJYZ5oyRQa8y0I6Wp18jJaOnkM OQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 356jg83p03-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Dec 2020 18:42:28 -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 0B2NbRJn094468; Wed, 2 Dec 2020 18:42:27 -0500 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 356jg83nyr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Dec 2020 18:42:27 -0500 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0B2NXDdT019938; Wed, 2 Dec 2020 23:42:26 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma01wdc.us.ibm.com with ESMTP id 355vrfu3me-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Dec 2020 23:42:26 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0B2NfBQ29175708 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 Dec 2020 23:41:11 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 653DD112065; Wed, 2 Dec 2020 23:41:11 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C9190112061; Wed, 2 Dec 2020 23:41:10 +0000 (GMT) Received: from cpe-66-24-58-13.stny.res.rr.com.com (unknown [9.85.195.249]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 2 Dec 2020 23:41:10 +0000 (GMT) From: Tony Krowiak To: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: borntraeger@de.ibm.com, cohuck@redhat.com, pasic@linux.ibm.com, alex.williamson@redhat.com, kwankhede@nvidia.com, david@redhat.com, Tony Krowiak Subject: [PATCH] s390/vfio-ap: Clean up vfio_ap resources when KVM pointer invalidated Date: Wed, 2 Dec 2020 18:41:01 -0500 Message-Id: <20201202234101.32169-1-akrowiak@linux.ibm.com> X-Mailer: git-send-email 2.21.1 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-12-02_14:2020-11-30,2020-12-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 spamscore=0 clxscore=1015 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 impostorscore=0 phishscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012020146 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The vfio_ap device driver registers a group notifier with VFIO when the file descriptor for a VFIO mediated device for a KVM guest is opened to receive notification that the KVM pointer is set (VFIO_GROUP_NOTIFY_SET_KVM event). When the KVM pointer is set, the vfio_ap driver stashes the pointer and calls the kvm_get_kvm() function to increment its reference counter. When the notifier is called to make notification that the KVM pointer has been set to NULL, the driver should clean up any resources associated with the KVM pointer and decrement its reference counter. The current implementation does not take care of this clean up. Signed-off-by: Tony Krowiak --- drivers/s390/crypto/vfio_ap_ops.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index e0bde8518745..eeb9c9130756 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -1083,6 +1083,17 @@ static int vfio_ap_mdev_iommu_notifier(struct notifier_block *nb, return NOTIFY_DONE; } +static void vfio_ap_mdev_put_kvm(struct ap_matrix_mdev *matrix_mdev) +{ + if (matrix_mdev->kvm) { + kvm_arch_crypto_clear_masks(matrix_mdev->kvm); + matrix_mdev->kvm->arch.crypto.pqap_hook = NULL; + vfio_ap_mdev_reset_queues(matrix_mdev->mdev); + kvm_put_kvm(matrix_mdev->kvm); + matrix_mdev->kvm = NULL; + } +} + static int vfio_ap_mdev_group_notifier(struct notifier_block *nb, unsigned long action, void *data) { @@ -1095,7 +1106,7 @@ static int vfio_ap_mdev_group_notifier(struct notifier_block *nb, matrix_mdev = container_of(nb, struct ap_matrix_mdev, group_notifier); if (!data) { - matrix_mdev->kvm = NULL; + vfio_ap_mdev_put_kvm(matrix_mdev); return NOTIFY_OK; } @@ -1222,13 +1233,7 @@ static void vfio_ap_mdev_release(struct mdev_device *mdev) struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); mutex_lock(&matrix_dev->lock); - if (matrix_mdev->kvm) { - kvm_arch_crypto_clear_masks(matrix_mdev->kvm); - matrix_mdev->kvm->arch.crypto.pqap_hook = NULL; - vfio_ap_mdev_reset_queues(mdev); - kvm_put_kvm(matrix_mdev->kvm); - matrix_mdev->kvm = NULL; - } + vfio_ap_mdev_put_kvm(matrix_mdev); mutex_unlock(&matrix_dev->lock); vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, -- 2.21.1