From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796407969; b=NTOPe+19Wbh2PKSnR9E/OBCtnbska6TFG7mFNCawvAkg65kEuc43R2QzLuVpjwgf66mc ZLTuiIt6KqMYnD6QsJbcewuoyKXYuUYqin53z+h6wQP6qect+TR1lxM57IJcstbcm0y9x 5SZO4n+RaqvP27pI6+V3eVtjhTDbk0AbMVwjdNrrqYtMJp8Z9ELC9FV0n/PQ+Ml4HkrW6 jzYjHm4oLW0Pfi5pic5/rcZ+nbFOIbcLp7aaqZBfrx1+O8tIsA5sYenHUALyLcHVGEZod oQQCQbp7+Udkm6hOF500zgwUcO6Z/hiiG+1lYNE3eN08XJ0EkdnFlG3KFn3VptUa27w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796407969; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-TM-AS-GCONF: X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Spam-Info: X-Authority-Analysis:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=oN+Ib+3kXrhsYXE/J4+Fl6U9pVPeQit0dxXpbvm0iCM=; b=3T4inZIY0sQq9Vge04sTqdXWdcfwO1PdRxfNESJ03jyQQ3HoWRs4hrmjQXrmpJG8MYSJ ZiLakoOn9mxnjFE5JRCBFPPawsimnIIz8mXg1U9nwBSTbYeEHFi0g8nCvEiLvedmmOcJg 8LsuqRZpQzMX2+hkcuq6T2/KJUuPxQSqrOGse5SK6K22mBDDav6Ij8ntAEYqQso05MZTX JW2QJnNJiXxRTsJUIMdzXxNStC+twlpimhLpcSJSNNnwOpRRNUXoCmPRD3OODiLv69jei quPm+An4wy+gYNeFTAQ3pQP9AwgOyj0E0ft17s3LXqlbI7liSW/MWJfTez1LLwL3D7w== 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=oFcU1LtZ; 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 233E9606A32C; Fri, 4 Dec 2026 18:12:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 233E9606A32C 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, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=oFcU1LtZ Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B4I6tl52797025; Fri, 4 Dec 2026 18:12:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=oN+Ib+ 3kXrhsYXE/J4+Fl6U9pVPeQit0dxXpbvm0iCM=; b=oFcU1LtZm3DSr6RyzNo+AE emrZrW6KzD0GzWceadbr0/drAAY4XaUL1M5cCx3lbR3Jm7JTTKbuNI5LKlRMOxk2 FKtRZNEnMBqj2hS+iXtl15eY4oRUSflmfdYu9IkmeFsOmnRTCdQ+zkxan1GM9wUw YUyuiNtniMKaXGIgplMrgd432wdHyYE/x7HL+YnXKFV39xsuuFvRJrDGxdkkYq4G GZhsH/JIYQMpaQoWvPb/bV9UOmisM5zHC0/ycBrd6xdjEvHpwFvtSfgJwss3rXIU kRVO1O1egn0NiObLtODawS6JQ1Y7vFJC8slVLJi/COad3m5ZbXtB8rskFJPUl4Fw == Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4jbqghk7ak-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 04 Dec 2026 18:12:45 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B4I8WdG2411138; Fri, 4 Dec 2026 18:12:45 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4jb5a1psqt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 04 Dec 2026 18:12:45 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B4IChYm62128456 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 4 Dec 2026 18:12:43 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 24D4058052; Fri, 4 Dec 2026 18:12:43 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 663FF58065; Fri, 4 Dec 2026 18:12:42 +0000 (GMT) Received: from [9.61.23.56] (unknown [9.61.23.56]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 4 Dec 2026 18:12:42 +0000 (GMT) Message-ID: <710e7d53-901d-4408-951d-5326e16d5bbc@linux.ibm.com> Date: Fri, 4 Dec 2026 13:12:42 -0500 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/5] s390/vfio-ap: bound the wait for queue reset verification To: "Jason J. Herne" , linux-s390@vger.kernel.org Cc: linux-kernel@vger.kernel.org, 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 References: <20261203214531.1395796-1-jjherne@linux.ibm.com> <20261203214531.1395796-3-jjherne@linux.ibm.com> Content-Language: en-US From: Anthony Krowiak In-Reply-To: <20261203214531.1395796-3-jjherne@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: OSU2C6xXcvlxN-P5iB7IETGVt0zek2hP X-Proofpoint-GUID: OSU2C6xXcvlxN-P5iB7IETGVt0zek2hP X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjA0MDA3MiBTYWx0ZWRfXx9Pjnz+BfHGB 4qwlckFjJzk2yiT0nzj5qXMhYlKpaEwHrioLtXNYBhnkcCKc6N4aMCHjFQPA80KqRSVDrV/PqG0 ows90lZ/3NLZzEVfmSQNxU+dYo3YJqPhWQXaLes3Y3p893hyVdySennwHPV7sabnwYX4nK8kxCN icKnJiaA2QWK/Sm3KfDpWvMc0wE3EM77GvTrUY+0U/C4PRShu5NmxtLqoeLsCJCwsNh18l/7JrF V7E3qK8nP7qSa1rDevGz9RXBPDwc3rc04yQ8Jb1psm3TSHl2V/oi+V+4F/H6ZM+YUwKXCzqwevY 61pKAc+Jocrsna/U6Mw7s1o55As873ITIvue5ZWMKTz4gzaZMI6FcfjfbxCN1hqveXZ2tqzZDZu qy9XH+zb6/v9RLjnxD881M6iQEUeQS1Ag6b8ZE7iV0Gd+4r28wyNroOIOVteYdAXmfPf+t9ek6C Wy9qrcBnURN85bnk56g== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjA0MDA3MiBTYWx0ZWRfX4U2OkdyWxiol wJ2JXjOgaSChuQ7d52qjJf/MOOswXgocnbbPZi3MQ5HmBtfLLdDbRRgqsSildeBCOezd5qckE9M uagpJDd49ufsB5IA/71iUWDXxf7uY90= X-Authority-Analysis: v=2.4 cv=Uc7E26SN c=1 sm=1 tr=0 ts=6b13029d cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=QuxrKLKGPk0XRHWkT4sA:9 a=QEXdDO2ut3YA:10 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-04_04,2026-12-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 phishscore=0 malwarescore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612040072 On 12/3/26 4:45 PM, Jason J. Herne wrote: > apq_reset_check() TAPQ polls the queue until reset/zeroize is confirmed. > Commit dd174833e44e ("s390/vfio-ap: remove upper limit on wait for queue > reset to complete") removed the time limit, because the architecture > defines no upper bound for a RAPQ/ZAPQ and giving up early and freeing the > AQIC resources could let a still-active queue write to a reused NIB page. > > That left the loop with no exit if the reset never completes. This can > happen when TAPQ keeps returning a busy/reset-in-progress response, or > when the ZAPQ is repeatedly rejected with reset-in-progress or > state-change-in-progress (or the queue keeps reporting an asynchronous > association failure) and is reissued on every pass. The work item then > spins forever, and anything that flushes it, such as > vfio_ap_mdev_reset_queues() and vfio_ap_mdev_reset_qlist(), waits > forever with it. > > Give up after 2 seconds. A timeout does not confirm the queue was > reset, so do not free the AQIC resources, which leaks the pinned NIB page > rather than risk a write to memory that has been reused. > Record the last TAPQ status in q->reset_status, substituting > AP_RESPONSE_BUSY if it was AP_RESPONSE_NORMAL, so the queue is not > considered passable and the reset callers report -EIO. > > This keeps the original safety property (never free resources for a queue > whose reset is unconfirmed) while removing the hang. > > Fixes: dd174833e44e ("s390/vfio-ap: remove upper limit on wait for queue reset to complete") > Cc: stable@vger.kernel.org > Signed-off-by: Jason J. Herne > --- > drivers/s390/crypto/vfio_ap_ops.c | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c > index 10430b9446db..fba6f256ce77 100644 > --- a/drivers/s390/crypto/vfio_ap_ops.c > +++ b/drivers/s390/crypto/vfio_ap_ops.c > @@ -31,6 +31,7 @@ > #define AP_QUEUE_IN_USE "in use" > > #define AP_RESET_INTERVAL 20 /* Reset sleep interval (20ms) */ > +#define VFIOAP_RESET_TIMEOUT 2000 /* Max wait for reset to complete (2s) */ > > static int vfio_ap_mdev_reset_queues(struct ap_matrix_mdev *matrix_mdev); > static int vfio_ap_mdev_reset_qlist(struct list_head *qlist); > @@ -1974,6 +1975,20 @@ static void apq_reset_check(struct work_struct *reset_work) > q = container_of(reset_work, struct vfio_ap_queue, reset_work); > memcpy(&status, &q->reset_status, sizeof(status)); I don't think this is necessary. In the initial call to the function as well as all succeeding calls, the status is obtained from the TAPQ call below. > while (true) { > + if (elapsed >= VFIOAP_RESET_TIMEOUT) { > + /* > + * Reset timed out. The queue could still be active so > + * leak AQIC resources rather than risk wild DMA write. > + */ > + pr_warn_ratelimited("Reset timed out for APQN %02x.%04x: leaking NIB page to prevent host crash\n", > + AP_QID_CARD(q->apqn), > + AP_QID_QUEUE(q->apqn)); Since this block will be entered only after a call to TAPQ followed by a call to apq_status_check(), we need to check the return code (ret) from apq_status_check() to see if it returned 0 which means the ZAPQ succeeded. If that is the case, then the AQIC resources can be freed and the status response code can be set to or left as 0. > + memcpy(&q->reset_status, &status, sizeof(status)); !q->reset_status.response_code indicates the ZAPQ completed successfully. Of course, in patch 1/5, no verification was done to determine whether the ZAPQ completed; a response code of 0 only indicates that the reset was initiated. It's an asychronous instruction, so the following needs to be verified before we know that ZAPQ completed: if (status->queue_empty && !status->replies_waiting && !status->irq_enabled && !status->async) return 0; Note also that you would have to check if the return code from TAPQ is -ENODEV in which case you can free AQIC resources. By putting this timeout check before the TAPQ and apq_status_check() calls, you are going to have to duplicate some of the succeeding checks in side this block. > + if (!q->reset_status.response_code) > + /* Record BUSY status so queue is not passable. */ > + q->reset_status.response_code = AP_RESPONSE_BUSY; > + return; > + } > msleep(AP_RESET_INTERVAL); > elapsed += AP_RESET_INTERVAL; > status = ap_tapq(q->apqn, NULL);