Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796334339; b=iM0q3ebYpKEGABk0BdIfkrHioYXJFflh4h14CNHlDibFYQ77AEZvgheKyNIkQ4uAMeco EFPGVXIZWEjcFYo9L0LANqZxZ4rXQuuzDG+fZ+ZkuQX1Pmc5cBfuNf9yHBGAvzAMWScLO 1qryXcre2CrJojO3oYl8PFAfKVs3wqTL0X7gBwhKrQ9/GX0jrTUOGLC6JbbaU8oYEgqYd uVkqPI6x1J47KF3KoO2bHKtpN1kBl0MqeXSHDxGbROhEOj2FN+166PHT5E5KR8vu/Jopf v6ryqK+ZPG9wQD8RDKCF1pNjCcoA/5C4wbRIwavAr8Qxm2LSqp54oqWAcTCV585Q3ow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796334339; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-TM-AS-GCONF:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Info:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-GUID:X-Authority-Analysis:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=ySeQbdOMgUhGL7gNCh9FmDHq2k4tVnMYye2qPW4Yd4Y=; b=VTve3cvI0NRiRMupJnL5h7fD7q3fQJMnirLR3b/xJSLynrdrv83cfTjGgQwvMqZh31O5 lOIPriG5sggQhdd61mUXNC5w5prV/JDHBJRdoVCfSLqVIyVZNKx/zMmtuVwBOVvVuViap cmnAUfTgeo1SmNIc4lAyYF3VsSjVH95/fJjPPmPGtdoqVbRUcj5FTqtzxVh3inwEkvknF 6PVVzawgIFgJqHVcMRhq9cMMueyGnbDBbjEesv6rYp2haSxG9+/tiN3xdP4AryjYVnX3E ABerAvtl8bB8T8T1lw/k7ddJav5Qx3k9h2EY5eCNysu1G1gLwk0t2b0nJzQhcdraluA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=cL8Uva67; arc=none smtp.remote-ip=148.163.158.5 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A92F606A691; Thu, 3 Dec 2026 21:45:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3A92F606A691 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=cL8Uva67 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B3LYt603258427; Thu, 3 Dec 2026 21:45:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=ySeQbdOMgUhGL7gNC h9FmDHq2k4tVnMYye2qPW4Yd4Y=; b=cL8Uva67Pt7H9+3+ucXQaUKJnuEaUlNkt CL9PP4QyNVTC5bibe+gL32Ydiow6ZCrw+ZAh4QFBKF5fmnDU9cuGJ5KHApL+nZ24 xz39i+pZQv+caho3LU98q6lKebCmpwSV1HT50c/jtY4lZe685Y5jn3CzMGEzXaOy mhCQqQJJnbbKhXjSJp3DrUu8JIYi302PY8U+WVnDhlB30enZvDynmwtDTSksmFoa Q+hQ94Y03cS3ryegfT+xQ+RrhGHbW531LAorkuSP85x5eke1zdrFsYKgWkhOIZNv a2GPGnFAdbT+tSV/TL2yhE2YeULMmCKCBKOjJ1w186kuQS/UMYSYg== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4jbgfdg0tj-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 03 Dec 2026 21:45:37 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B3IKjjG2008568; Thu, 3 Dec 2026 21:45:37 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([172.16.1.72]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ja2uv9t0w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Dec 2026 21:45:37 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B3Ljagp23921162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Dec 2026 21:45:36 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D37A458052; Thu, 3 Dec 2026 21:45:35 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1789C5805D; Thu, 3 Dec 2026 21:45:35 +0000 (GMT) Received: from li-2227244c-2a68-11b2-a85c-fc811bb24bca.ibm.com (unknown [9.61.13.210]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Dec 2026 21:45:35 +0000 (GMT) From: "Jason J. Herne" To: linux-s390@vger.kernel.org Cc: linux-kernel@vger.kernel.org, akrowiak@linux.ibm.com, borntraeger@linux.ibm.com, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, mjrosato@linux.ibm.com, frankja@linux.ibm.com, imbrenda@linux.ibm.com, jrossi@linux.ibm.com, stable@vger.kernel.org Subject: [PATCH 4/5] s390/vfio-ap: clear matrix_mdev link for queues not reset on unassign Date: Thu, 3 Dec 2026 16:45:30 -0500 Message-ID: <20261203214531.1395796-5-jjherne@linux.ibm.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203214531.1395796-1-jjherne@linux.ibm.com> References: <20261203214531.1395796-1-jjherne@linux.ibm.com> X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: zU1xMP8r9aKQH6KErMB-xFdDxxoZU2MP X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAzMDA4NiBTYWx0ZWRfX4MoDLcsiLCrI Q3nY3CXJ+ZSutk97ODstnIEXItTH8smSUJl1oIjLwIXWj2x0gfH2j/Js6Ed2V/UTcgHW6xdJjCw DtMOUV21uK/HxRUvKRjb8vXnMQeVYxI= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAzMDA4NiBTYWx0ZWRfX2y6VnaXmrHPT kqjbru4+mnNKVjfdcHOGV9semN0KLcdTKlXudNyMvI8c1bxoi6+XPZ/qzSCDtTk9a8peGo/PnMf P6iVK+FTrrKB/xa9TDVII1Ie6cB1Ro0R/TY0/mO1QV5Y2/zA5g39bkcyiepRd4h6qee1BJn7Jbd cjMsLoJ5t2J0Bc9Ta6fjhbv57O3fSB0o3Ap7nAsgqFpBNB1BX7n3KO8kjzwNJllVXlTL38AB0dw uAKzpjLeOY+is7aSbjIQn9ciNAkQKgKNn+qZQhh5NlsLZA5Mic3FmxeLW/JE1eNGsPWpegMhXLx WPGgq0Zci3xMhlDb3FIACCUQ2a0iZRKsdinpoTxHiIqbi1f9V+zRBWMAjewqxXkU8CaHucYTnjk SlT5G26zk5RCUOEaHN0zhUyeCtKxfrEEi1FAFsaMja9higlbDPOH8GmSgXA6ieMZDoF5vOWOyxu HE6frdKjJ1fYQGmoa7g== X-Proofpoint-GUID: zU1xMP8r9aKQH6KErMB-xFdDxxoZU2MP X-Authority-Analysis: v=2.4 cv=DaKCOftW c=1 sm=1 tr=0 ts=6b11e301 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=5l8Vr2Tizv7YdC9F_TgA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-03_05,2026-12-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 malwarescore=0 priorityscore=1501 adultscore=0 spamscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2612010000 definitions=main-2612030086 When an adapter or domain is unassigned from a matrix mdev, vfio_ap_mdev_unlink_adapter() and vfio_ap_mdev_unlink_domain() remove each affected queue from the mdev's hash table. Only queues that are in the guest's APCB are added to the reset list. A queue that was already filtered from the APCB is unlinked but never added to that list, so vfio_ap_unlink_mdev_fr_queue() is never called for it. Its q->matrix_mdev keeps pointing at the mdev. The mdev's matrix.apm/aqm no longer include the adapter or domain at this point, so vfio_ap_mdev_unlink_fr_queues() called from vfio_ap_mdev_remove() will not visit the queue either. When the mdev is freed, q->matrix_mdev is left dangling. Later paths that dereference it, such as vfio_ap_mdev_remove_queue(), can then access freed memory. Clear the link for these queues in an else branch. Queues that are added to the reset list keep their link until the reset completes, as before. Clearing the link has a side effect. vfio_ap_free_aqic_resources() needs q->matrix_mdev to unpin the NIB page and unregister the ISC, and vfio_ap_mdev_remove_queue() calls it for queues that are no longer in the host's AP configuration. Such a queue can still hold AQIC resources. This happens when the adapter or domain is removed from the host configuration while a guest is using AP interrupts. That path only clears the shadow APCB bits and does not reset the queue. If the adapter or domain is then unassigned before the AP bus removes the queue device, the link is cleared first. The later cleanup hits WARN_ON(!q->matrix_mdev) and leaks the pinned page and the ISC registration. A queue outside the host configuration is deconfigured, so it cannot write to the NIB. Release its AQIC resources before clearing the link. Queues still in the host configuration that were filtered from the APCB have already been reset, or had their resources released or leaked by the reset, so they have nothing left to free here. Also drop the "qlist" NULL check. Both helpers have a single caller, and that caller always passes a freshly initialized list. Fixes: 70aeefe574cb ("s390/vfio-ap: reset queues after adapter/domain unassignment") Cc: stable@vger.kernel.org Signed-off-by: Jason J. Herne --- drivers/s390/crypto/vfio_ap_ops.c | 40 +++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index d460337e365f..836551e9f65b 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -1173,6 +1173,22 @@ static struct vfio_ap_queue return q; } +/* + * Unlink a queue that is not being reset. If it is no longer in the host's AP + * configuration it is gone, but vfio_ap_mdev_remove_queue() can't release its + * AQIC resources once the mdev link is cleared, so release them here. + */ +static void vfio_ap_unlink_mdev_fr_unreset_queue(struct vfio_ap_queue *q) +{ + if (!test_bit_inv(AP_QID_CARD(q->apqn), + (unsigned long *)matrix_dev->info.apm) || + !test_bit_inv(AP_QID_QUEUE(q->apqn), + (unsigned long *)matrix_dev->info.aqm)) + vfio_ap_free_aqic_resources(q); + + vfio_ap_unlink_mdev_fr_queue(q); +} + /** * vfio_ap_mdev_unlink_adapter - unlink all queues associated with unassigned * adapter from the matrix mdev to which the @@ -1191,12 +1207,14 @@ static void vfio_ap_mdev_unlink_adapter(struct ap_matrix_mdev *matrix_mdev, for_each_set_bit_inv(apqi, matrix_mdev->matrix.aqm, AP_DOMAINS) { q = vfio_ap_unlink_apqn_fr_mdev(matrix_mdev, apid, apqi); + if (!q) + continue; - if (q && qlist) { - if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) && - test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm)) - list_add_tail(&q->reset_qnode, qlist); - } + if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) && + test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm)) + list_add_tail(&q->reset_qnode, qlist); + else + vfio_ap_unlink_mdev_fr_unreset_queue(q); } } @@ -1392,12 +1410,14 @@ static void vfio_ap_mdev_unlink_domain(struct ap_matrix_mdev *matrix_mdev, for_each_set_bit_inv(apid, matrix_mdev->matrix.apm, AP_DEVICES) { q = vfio_ap_unlink_apqn_fr_mdev(matrix_mdev, apid, apqi); + if (!q) + continue; - if (q && qlist) { - if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) && - test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm)) - list_add_tail(&q->reset_qnode, qlist); - } + if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) && + test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm)) + list_add_tail(&q->reset_qnode, qlist); + else + vfio_ap_unlink_mdev_fr_unreset_queue(q); } } -- 2.56.1