From nobody Thu Oct 22 19:25:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791559949; cv=none; d=zohomail.com; s=zohoarc; b=JCmjs+QIXUvoCSxYu5gbv7YF2yuv+7baRkQHKq6NmqDBIyMYx/xjZdLHRriymGOYPau6oZ5une6605MIF+Wq2BeH5bMU6R50LlX5G3w03ZAut2YWYpShT+Z/eLvuiLoR+lLO4QQPhv3QcKDpi69LzWsQtOaVsI1CPo0kJ27xaGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791559949; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Bv3ksCHGCjVkKAAuuSNnmuqMiXJAuUhzV+MU+W1Y5AY=; b=TTn1sDFwrORQTNl5r/n9yWmdB8sSh/XD+JwqeyeSXfFuUh9TUlGwcxI1tfHQZ8qOavGtkGWtGFSafTOLuTLd2hJbUWoPD1StP32uOc0rSap3xBXPcgU6+njCFyVKuItdooPqbnzlOdKwa33FRTlM3STgMkiJbniBx88bec6ECQM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791559949201570.5896876713945; Fri, 9 Oct 2026 08:32:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xFCZG-0001SH-9T; Fri, 09 Oct 2026 11:31:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCYv-0001Qs-2n for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCYt-0007ye-1r for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:08 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-374-Fnsm5QHHOi-yhc_4jSjFhg-1; Fri, 9 Oct 2026 15:31:03 +0000 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 06EAD195DE7B; Fri, 9 Oct 2026 15:31:02 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 49B8730000E8; Fri, 9 Oct 2026 15:31:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791559865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Bv3ksCHGCjVkKAAuuSNnmuqMiXJAuUhzV+MU+W1Y5AY=; b=Fm1NpuuTNjPmMOB6Xqw7rV/MEBFtDIS4GSM7b/x5/iFOP2mmiOQIoKzgW8smaUmjX2ych5 3yG5QW0QaNDASHrSUD9E2RZSD6/WArE8u+wJNpWYhLb+ZP7T7VWyQSWSouSPbK2Hn/12+e G62pGU4LFjBdNJ9UCV08ABZmq8eE9As= X-MC-Unique: Fnsm5QHHOi-yhc_4jSjFhg-1 X-Mimecast-MFC-AGG-ID: Fnsm5QHHOi-yhc_4jSjFhg_1791559862 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: akalenyu@redhat.com, , Pierrick Bouvier , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Benjamin Marzinski , Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Stefan Hajnoczi Subject: [PATCH 1/8] pr-manager-helper: fix sense buffer overflow Date: Fri, 9 Oct 2026 11:30:51 -0400 Message-ID: <20261009153058.1089786-2-stefanha@redhat.com> In-Reply-To: <20261009153058.1089786-1-stefanha@redhat.com> References: <20261009153058.1089786-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791559951242158500 Content-Type: text/plain; charset="utf-8" scsi_build_sense() assumes the sense buffer is SCSI_SENSE_LEN (18) bytes long, so the caller's buffer with an arbitrary size cannot be used. Use our own sense buffer (resp.sense) as an intermediate buffer and honor the caller's sense buffer size (io_hdr->mx_sb_len). This is triggered when scsi-generic.c:scsi_SG_IO() calls blk_ioctl() with an 8-byte sense buffer. There does not appear to be a way for the guest to trigger this buffer overflow directly since SCSIRequest->sense[] is 252 bytes long. Fixes: 9bad2a6b9d0a ("scsi: add persistent reservation manager using qemu-p= r-helper") Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- scsi/pr-manager-helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scsi/pr-manager-helper.c b/scsi/pr-manager-helper.c index 53432e6d606..26ef3876f0e 100644 --- a/scsi/pr-manager-helper.c +++ b/scsi/pr-manager-helper.c @@ -234,10 +234,11 @@ static int pr_manager_helper_run(PRManager *p, =20 out: if (ret < 0) { - int sense_len =3D scsi_build_sense(io_hdr->sbp, + int sense_len =3D scsi_build_sense(resp.sense, SENSE_CODE(LUN_COMM_FAILURE)); io_hdr->driver_status =3D SG_ERR_DRIVER_SENSE; io_hdr->sb_len_wr =3D MIN(io_hdr->mx_sb_len, sense_len); + memcpy(io_hdr->sbp, resp.sense, io_hdr->sb_len_wr); io_hdr->status =3D CHECK_CONDITION; } qemu_mutex_unlock(&pr_mgr->lock); --=20 2.56.0 From nobody Thu Oct 22 19:25:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791559949; cv=none; d=zohomail.com; s=zohoarc; b=S1izhTYK0vgZ9yup9SFuhSAX2cWKGC4Yr/keKe+7ZZ6T3ll0tI8c1SXNqrXzZp0fiwjsZzbHxoSW6YNDl9tXDDCzpYjHovMLAWXn8htszmhB/9yWS/5vgzcfU8hA3ZhiveHLOh5fTWyZlvcGgHTyOtlwlaYRVsVVy6HUKuHjce8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791559949; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OobCKqtAno6tcheEnGg69jGbwQ9liU9tK+7iTZfAfx4=; b=O9AkRUrhgMtmfo7zJxfWnZw/BAuiIlEKYZot+ajsqfJac5OhRXXzgP+iILoNipJeOyOzD1PWhWMvB1dwMBrd/rr9P59a+1v4qpMjZummZxMlf9oqe4TzkhFpwCgxFy6VLsWuVcMm5eCC3LNnAAtWuQtSifRBHD5ic/Jxld5Ld3M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791559949400242.93779166226648; Fri, 9 Oct 2026 08:32:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xFCZw-0001ZL-Uh; Fri, 09 Oct 2026 11:32:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ1-0001S1-Bd for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCYz-0007zj-SA for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:15 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-D4rBIoKCPlWS_7xZOa6Bsg-1; Fri, 9 Oct 2026 15:31:05 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1F19E18021FD; Fri, 9 Oct 2026 15:31:04 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EFF0918005B3; Fri, 9 Oct 2026 15:31:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791559873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OobCKqtAno6tcheEnGg69jGbwQ9liU9tK+7iTZfAfx4=; b=dTC7DIHz5NRqeVHnvlpdNw4WZoxq4lVB6dE+sgroDamMtok+Bq33NvPm93ASnfmNjZMCDK lL5QurvsI+aRByJkDlDTMs6HvNJkF6NQAFOH72Q30abjYgWzgTqEHhVjl5sl3uQFZLjHEv Qd62BcKlPy5IJt+mjRB1Ejgo3RTKiM4= X-MC-Unique: D4rBIoKCPlWS_7xZOa6Bsg-1 X-Mimecast-MFC-AGG-ID: D4rBIoKCPlWS_7xZOa6Bsg_1791559864 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: akalenyu@redhat.com, , Pierrick Bouvier , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Benjamin Marzinski , Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Stefan Hajnoczi Subject: [PATCH 2/8] scsi: increase sense buffer size in scsi_SG_IO() Date: Fri, 9 Oct 2026 11:30:52 -0400 Message-ID: <20261009153058.1089786-3-stefanha@redhat.com> In-Reply-To: <20261009153058.1089786-1-stefanha@redhat.com> References: <20261009153058.1089786-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791559951160158500 Content-Type: text/plain; charset="utf-8" There are different SCSI sense formats. Increase the size so we can get more detailed sense data. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- hw/scsi/scsi-generic.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 8999f3b7200..153a5275567 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -923,7 +923,7 @@ int scsi_SG_IO(BlockBackend *blk, int direction, uint8_= t *cmd, uint32_t timeout, Error **errp) { sg_io_hdr_t io_header; - uint8_t sensebuf[8] =3D {}; + uint8_t sensebuf[SCSI_SENSE_LEN] =3D {}; int ret; =20 memset(&io_header, 0, sizeof(io_header)); @@ -947,15 +947,18 @@ int scsi_SG_IO(BlockBackend *blk, int direction, uint= 8_t *cmd, error_setg_errno(errp, -ret, "SG_IO ioctl failed"); } else { g_autofree char *sensebuf_hex =3D - g_strdup_printf("%02x%02x%02x%02x%02x%02x%02x%02x", - sensebuf[0], - sensebuf[1], - sensebuf[2], - sensebuf[3], - sensebuf[4], - sensebuf[5], - sensebuf[6], - sensebuf[7]); + g_strdup_printf("%02x%02x%02x%02x%02x%02x%02x%02x" + "%02x%02x%02x%02x%02x%02x%02x%02x" + "%02x%02x", + sensebuf[0], sensebuf[1], + sensebuf[2], sensebuf[3], + sensebuf[4], sensebuf[5], + sensebuf[6], sensebuf[7], + sensebuf[8], sensebuf[9], + sensebuf[10], sensebuf[11], + sensebuf[12], sensebuf[13], + sensebuf[14], sensebuf[15], + sensebuf[16], sensebuf[17]); =20 error_setg(errp, "SG_IO SCSI command failed with status=3D0x%x= " "driver_status=3D0x%x host_status=3D0x%x sensebuf=3D%s= " --=20 2.56.0 From nobody Thu Oct 22 19:25:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791559998; cv=none; d=zohomail.com; s=zohoarc; b=lhFXt4NHgXPAX+6CmAoHg9PeYDQLqeBRphAfkoVsNZeicLe60pgtOdTvmZaZQHCWdgHnbQkeYgp/0gwA+f0LPxrv2Us1yIZsuxSeH+g4sfOE8PSopyp94+LWwHXfLxjCu3jipJhWUSkbSGGB1XIzMoiwBRhLhr5yYd+aaYcXk9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791559998; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=w6BtoRW+1MiLxfbSmGQadwo7l0abOPtZZ54uJBQ5yBg=; b=Bbe6l3dfRJaCq1wSFRGwwV0A0JWrv2dX/hg2xbrKO8oIvqEnOxn64F+qREamWKfJyMWeZlvsxe9Z2TXyq0Dxxc/uTUONnGqzWv90q63dYjF+oEnrn5mUsClOdR8ESYL+G8dWi256gxn59O82xh/s1NVJAbvQuaazSFMKmHtR7cs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791559998187107.40310736291121; Fri, 9 Oct 2026 08:33:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xFCa4-0001b9-Qi; Fri, 09 Oct 2026 11:32:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ2-0001S9-7k for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ0-000801-FN for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:15 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631--NCRT7p9OVidYdeSDbyIaw-1; Fri, 9 Oct 2026 15:31:06 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 458941800C3C; Fri, 9 Oct 2026 15:31:05 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F28E118004D2; Fri, 9 Oct 2026 15:31:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791559873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w6BtoRW+1MiLxfbSmGQadwo7l0abOPtZZ54uJBQ5yBg=; b=aPdKLFGxVC+R8JFqDepb5s3VEANnKD8SNW4kEMvdqhQIszECZTdflLO99PjLgun5Yapr6t KDJ+dgnVGoyUT4f24UJBZGYK+iD97Rx4Vtxy+eFOI7+M6H+6wcHd+4V55yEfmho7R7/rW/ YwjY8Qb8PVb7mLkBsOMutTrsVYXsCmU= X-MC-Unique: -NCRT7p9OVidYdeSDbyIaw-1 X-Mimecast-MFC-AGG-ID: -NCRT7p9OVidYdeSDbyIaw_1791559865 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: akalenyu@redhat.com, , Pierrick Bouvier , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Benjamin Marzinski , Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Stefan Hajnoczi Subject: [PATCH 3/8] hw/scsi-disk: move MIG_EVENT_FAILED into a new function Date: Fri, 9 Oct 2026 11:30:53 -0400 Message-ID: <20261009153058.1089786-4-stefanha@redhat.com> In-Reply-To: <20261009153058.1089786-1-stefanha@redhat.com> References: <20261009153058.1089786-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791559999542158500 Content-Type: text/plain; charset="utf-8" Move the MIG_EVENT_FAILED logic from scsi_block_migration_notifier() into its own new scsi_block_migration_failed() function. The next commit adds logic for handling another event, so doing that in dedicated functions makes the code easier to read. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- hw/scsi/scsi-disk.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index deb33ac1dda..3d88e57eded 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2761,20 +2761,26 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d,= uint32_t tag, uint32_t lun, * fails because the destination may have already preempted and we need to= get * the reservation back. */ +static void scsi_block_migration_failed(SCSIDiskState *s) +{ + SCSIDevice *d =3D &s->qdev; + Error *local_err =3D NULL; + + if (!scsi_generic_pr_state_preempt(d, &local_err)) { + /* MIG_EVENT_FAILED cannot fail, so just warn */ + error_prepend(&local_err, "scsi-block migration rollback: "); + warn_report_err(local_err); + } +} + static int scsi_block_migration_notifier(NotifierWithReturn *notifier, MigrationEvent *e, Error **errp) { - if (e->type =3D=3D MIG_EVENT_FAILED) { - SCSIDiskState *s =3D - container_of(notifier, SCSIDiskState, migration_notifier); - SCSIDevice *d =3D &s->qdev; - Error *local_err =3D NULL; + SCSIDiskState *s =3D + container_of(notifier, SCSIDiskState, migration_notifier); =20 - if (!scsi_generic_pr_state_preempt(d, &local_err)) { - /* MIG_EVENT_FAILED cannot fail, so just warn */ - error_prepend(&local_err, "scsi-block migration rollback: "); - warn_report_err(local_err); - } + if (e->type =3D=3D MIG_EVENT_FAILED) { + scsi_block_migration_failed(s); } return 0; } --=20 2.56.0 From nobody Thu Oct 22 19:25:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791560052; cv=none; d=zohomail.com; s=zohoarc; b=OHx/jLu8tEnXqA7XML8KUyQ7HV0bbaBbvwggOQjB1zzFen0zoZivRo7FaVlM8386V3r4OTgqObqQO5pQb9oOBN8gV/swXUEzFmM/IqhaSJeYcPE7WVa5auIbSMIpe1QPb9TWBRz4Dalh0v+AwqBchooqOoSzLqCshcLLcgahGT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791560052; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FUM3C45s1SojI5HXslRhO+jefZG1IMb2lB5VwEKWEsE=; b=Fy1Apj3F8KbUiQnahWsVqxs9PMxz6y935zTykrkT12SrO7mxNX9z/ohglMMPmBLMukx9ZptzwXTXC9+7478Ahb+jOyG+shdWnfNMNCAOMKh6UHb6/pzU5/7IIQddf4tyNd8q/6I9Kak0PbAJPRHlhKkXdQrLEHjP1gx2tK95aC4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791560052915485.9762808513119; Fri, 9 Oct 2026 08:34:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xFCZv-0001Yq-58; Fri, 09 Oct 2026 11:32:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ0-0001Rx-1W for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCYy-0007zQ-4G for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:13 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-673-o-qHirSCMWuPLMvP78vi-w-1; Fri, 9 Oct 2026 15:31:07 +0000 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8C4091955E8D; Fri, 9 Oct 2026 15:31:06 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4176C1956086; Fri, 9 Oct 2026 15:31:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791559871; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FUM3C45s1SojI5HXslRhO+jefZG1IMb2lB5VwEKWEsE=; b=fLCJoxeVsnQZ9FACIl/o/l28uMt5xqzeJX5fUWRhQ22b6E1iliJ8XZwa9OvLZKO9u7jz5/ D2hWedSmle8OBn/dt4xnEZFa/5J77oQpKf304Jr3jwGkezE+SbkubVCN1PT4zhBi+H0ILS hE46tXbsIzAp19bDZ3DsAEx69soBJqo= X-MC-Unique: o-qHirSCMWuPLMvP78vi-w-1 X-Mimecast-MFC-AGG-ID: o-qHirSCMWuPLMvP78vi-w_1791559866 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: akalenyu@redhat.com, , Pierrick Bouvier , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Benjamin Marzinski , Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Stefan Hajnoczi Subject: [PATCH 4/8] qemu-pr-helper: add PR_HELPER_CLEANUP for live migration Date: Fri, 9 Oct 2026 11:30:54 -0400 Message-ID: <20261009153058.1089786-5-stefanha@redhat.com> In-Reply-To: <20261009153058.1089786-1-stefanha@redhat.com> References: <20261009153058.1089786-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791560054635158500 Content-Type: text/plain; charset="utf-8" Introduce a new vendor-specific SCSI command that acts similar to REGISTER AND IGNORE EXISTING KEY but also discards multipathd's state (including /etc/multipath/prkeys). This command will be used on the source after live migration completes successfully. This cleanup step is necessary because multipathd will register the key it has stored when the path comes up again. This is undesirable when the guest has migrated to another host and can interfere with the migration process or the application running inside the guest. Add a qemu-pr-manager protocol feature bit indicating that the new PR_HELPER_CLEANUP command is available. The command has no CDB fields other than OPCODE and the response contains no data aside from the usual result and sense data. Note that the linker needs an explicit libmpathcmd dependency for mpath_disconnect() even though qemu-pr-helper.c already #included the mpath_cmd.h header before. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- meson.build | 2 + include/scsi/constants.h | 1 + scsi/pr-helper.h | 3 + scsi/qemu-pr-helper.c | 146 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 143 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index 828100de816..34038eb8e52 100644 --- a/meson.build +++ b/meson.build @@ -1486,6 +1486,8 @@ if host_os =3D=3D 'linux' and have_tools and get_opti= on('mpath').allowed() endif mpathlibs +=3D cc.find_library('multipath', required: get_option('mpath')) + mpathlibs +=3D cc.find_library('mpathcmd', + required: get_option('mpath')) foreach lib: mpathlibs if not lib.found() mpathlibs =3D [] diff --git a/include/scsi/constants.h b/include/scsi/constants.h index 717e470a5d4..bb3981a779b 100644 --- a/include/scsi/constants.h +++ b/include/scsi/constants.h @@ -149,6 +149,7 @@ #define MECHANISM_STATUS 0xbd #define READ_CD 0xbe #define SEND_DVD_STRUCTURE 0xbf +#define PR_HELPER_CLEANUP 0xff /* vendor-specific QEMU command */ =20 /* * SERVICE ACTION IN subcodes diff --git a/scsi/pr-helper.h b/scsi/pr-helper.h index e26e104ec76..d088d0dc193 100644 --- a/scsi/pr-helper.h +++ b/scsi/pr-helper.h @@ -31,6 +31,9 @@ #define PR_HELPER_SENSE_SIZE 96 #define PR_HELPER_DATA_SIZE 8192 =20 +/* Protocol features */ +#define PR_HELPER_FEATURE_CLEANUP (1u << 0) + typedef struct PRHelperResponse { int32_t result; int32_t sz; diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index 9dcd3ec7111..fdbb4748dc0 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -537,6 +537,110 @@ static int coroutine_fn multipath_pr_out(int fd, cons= t uint8_t *cdb, uint8_t *se paramp, noisy, verbose); return mpath_reconstruct_sense(fd, r, sense); } + +/* Get the device-mapper device name given its block device fd */ +static char *get_dm_name(int fd, Error **errp) +{ + struct stat st; + int ret; + + assert(is_mpath(fd)); + + ret =3D fstat(fd, &st); + if (ret !=3D 0) { + error_setg_errno(errp, errno, "fstat failed on fd %d", fd); + return NULL; + } + + return g_strdup_printf("dm-%u", minor(st.st_rdev)); +} + +/* Perform a multipathd command */ +static bool multipathd_cmd(int fd, const char *cmd, Error **errp) +{ + const unsigned int timeout_ms =3D 60000; + char *reply =3D NULL; + int last_errno; + int ret; + + ret =3D mpath_process_cmd(fd, cmd, &reply, timeout_ms); + last_errno =3D errno; + if (reply && strcmp(reply, "ok\n") !=3D 0) { + error_setg(errp, "mpath_process_cmd(%d, \"%s\") replied \"%s\"", + fd, cmd, reply); + free(reply); + return false; + } + free(reply); + if (ret =3D=3D -1) { + error_setg_errno(errp, last_errno, + "mpath_process_cmd(%d, \"%s\") failed", + fd, cmd); + return false; + } + return true; +} + +/* Unregister so this I_T nexus has no key registered anymore */ +static int coroutine_fn multipath_pr_cleanup_unregister(int fd, uint8_t *s= ense, + Error **errp) +{ + uint8_t cdb[PR_HELPER_CDB_SIZE] =3D {}; + uint8_t param[PR_OUT_FIXED_PARAM_SIZE] =3D {}; + + /* Fill in CDB */ + cdb[0] =3D PERSISTENT_RESERVE_OUT; /* OPERATION CODE */ + cdb[1] =3D PRO_REGISTER_AND_IGNORE_EXISTING_KEY; /* SERVICE ACTION */ + stl_be_p(&cdb[5], sizeof(param)); /* PARAMETER LIST LENGT= H */ + + /* The parameter list is all zeroes, so there is nothing to fill in */ + + return multipath_pr_out(fd, cdb, sense, param, sizeof(param)); +} + +/* + * A special version of REGISTER AND IGNORE EXISTING KEY with sark=3D0 to + * unregister the key without triggering multipathd's preemption. This suc= ceeds + * when no key is registered too. This is essential so the migration source + * cleans up its registered key without multipathd preempting the destinat= ion + * host. + */ +static int coroutine_fn multipath_pr_cleanup(int bdev_fd, uint8_t *sense, + Error **errp) +{ + g_autofree char *bdev_dm_name =3D get_dm_name(bdev_fd, errp); + g_autofree char *cmd =3D NULL; + int multipathd_fd; + + if (bdev_dm_name =3D=3D NULL) { + return -1; + } + + /* First make multipathd the key and reservation state */ + multipathd_fd =3D mpath_connect(); + if (multipathd_fd =3D=3D -1) { + error_setg_errno(errp, errno, "mpath_connect() failed"); + return -1; + } + + cmd =3D g_strdup_printf("unsetprkey map %s", bdev_dm_name); + if (!multipathd_cmd(multipathd_fd, cmd, errp)) { + mpath_disconnect(multipathd_fd); + return -1; + } + + g_free(cmd); + cmd =3D g_strdup_printf("unsetprstatus map %s", bdev_dm_name); + if (!multipathd_cmd(multipathd_fd, cmd, errp)) { + mpath_disconnect(multipathd_fd); + return -1; + } + + mpath_disconnect(multipathd_fd); + + /* Now unregister the key at the SCSI level */ + return multipath_pr_cleanup_unregister(bdev_fd, sense, errp); +} #endif =20 static int coroutine_fn do_pr_in(int fd, const uint8_t *cdb, uint8_t *sens= e, @@ -578,6 +682,21 @@ static int coroutine_fn do_pr_out(int fd, const uint8_= t *cdb, uint8_t *sense, SG_DXFER_TO_DEV); } =20 +static int coroutine_fn do_pr_cleanup(int fd, uint8_t *sense, Error **errp) +{ + if ((fcntl(fd, F_GETFL) & O_ACCMODE) =3D=3D O_RDONLY) { + scsi_build_sense(sense, SENSE_CODE(INVALID_OPCODE)); + return CHECK_CONDITION; + } + +#ifdef CONFIG_MPATH + if (is_mpath(fd)) { + return multipath_pr_cleanup(fd, sense, errp); + } +#endif + return GOOD; +} + /* Client */ =20 typedef struct PRHelperClient { @@ -667,7 +786,8 @@ static int coroutine_fn prh_read_request(PRHelperClient= *client, } =20 if (req->cdb[0] !=3D PERSISTENT_RESERVE_OUT && - req->cdb[0] !=3D PERSISTENT_RESERVE_IN) { + req->cdb[0] !=3D PERSISTENT_RESERVE_IN && + req->cdb[0] !=3D PR_HELPER_CLEANUP) { error_setg(errp, "Invalid CDB, closing socket."); goto out_close; } @@ -703,7 +823,8 @@ static int coroutine_fn prh_write_response(PRHelperClie= nt *client, ssize_t r; size_t sz; =20 - if (req->cdb[0] =3D=3D PERSISTENT_RESERVE_IN && resp->result =3D=3D GO= OD) { + if (req->cdb[0] =3D=3D PERSISTENT_RESERVE_IN && + resp->result =3D=3D GOOD) { assert(resp->sz <=3D req->sz && resp->sz <=3D sizeof(client->data)= ); } else { assert(resp->sz =3D=3D 0); @@ -739,10 +860,8 @@ static void coroutine_fn prh_co_entry(void *opaque) =20 qio_channel_set_follow_coroutine_ctx(QIO_CHANNEL(client->ioc), true); =20 - /* A very simple negotiation for future extensibility. No features - * are defined so write 0. - */ - flags =3D cpu_to_be32(0); + /* A very simple negotiation for future extensibility */ + flags =3D cpu_to_be32(PR_HELPER_FEATURE_CLEANUP); r =3D qio_channel_write_all(QIO_CHANNEL(client->ioc), (char *) &flags, sizeof(flags), NULL); if (r < 0) { @@ -751,7 +870,7 @@ static void coroutine_fn prh_co_entry(void *opaque) =20 r =3D qio_channel_read_all(QIO_CHANNEL(client->ioc), (char *) &flags, sizeof(flags), NULL); - if (be32_to_cpu(flags) !=3D 0 || r < 0) { + if ((be32_to_cpu(flags) & ~PR_HELPER_FEATURE_CLEANUP) !=3D 0 || r < 0)= { goto out; } =20 @@ -766,15 +885,24 @@ static void coroutine_fn prh_co_entry(void *opaque) } =20 num_active_sockets++; - if (req.cdb[0] =3D=3D PERSISTENT_RESERVE_OUT) { + switch (req.cdb[0]) { + case PERSISTENT_RESERVE_OUT: r =3D do_pr_out(req.fd, req.cdb, resp.sense, client->data, sz); resp.sz =3D 0; - } else { + break; + case PERSISTENT_RESERVE_IN: resp.sz =3D sizeof(client->data); r =3D do_pr_in(req.fd, req.cdb, resp.sense, client->data, &resp.sz); resp.sz =3D MIN(resp.sz, sz); + break; + case PR_HELPER_CLEANUP: + r =3D do_pr_cleanup(req.fd, resp.sense, &local_err); + resp.sz =3D 0; + break; + default: + abort(); } num_active_sockets--; close(req.fd); --=20 2.56.0 From nobody Thu Oct 22 19:25:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791560048; cv=none; d=zohomail.com; s=zohoarc; b=IxHvb3/NPHqtwWjZBXWlQr5GU3YUc70Aj0/VwXWSdVwrq672UhrDgmIlBNcsY1/T7geTBNsPPK31heSvzzaSXmJbcehgM6R4ldScXL38KbA1Gz6fMudQdgkgDNVly1DbY6BR14U7ZGSeCDu+bqT+D2CNY6npOG3AyPJ/7dJyRvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791560048; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IA704wAeoDB8vavu6DoaN71Zbtw9BZUbE43n3y+Elro=; b=Rh81xyH1EPT1mv8cqs9FbcwIyvkJWAqrLpnnJqKyEd0zn94F8QUicnCiGtKg1u/t90pDIMEPEc88EQFfd8B/l3+f9PKe7+NRk6BBWeY7CFCgw+EgHjNQi0SdveqF402Ym7bOCQOSt08jW73TzxVwNOqK6yte9N/MOXkLaK+n6UY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179156004837091.37644557221518; Fri, 9 Oct 2026 08:34:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xFCb5-0002ET-A9; Fri, 09 Oct 2026 11:33:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ7-0001SS-2L for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ5-00081G-J6 for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:20 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-53--B6uBTZRMO6K0r5r_4cvUw-1; Fri, 9 Oct 2026 15:31:09 +0000 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 38EB219541AA; Fri, 9 Oct 2026 15:31:08 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 87CCC471; Fri, 9 Oct 2026 15:31:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791559878; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IA704wAeoDB8vavu6DoaN71Zbtw9BZUbE43n3y+Elro=; b=eBw7uytq/RniXHnxiJasL0nact1iLwegeLLu4yy8W/WtrJMqfZabD5cQd3FCoSRuWbn1Jw u31KLs/KKPRseSILpUJv2K6N74fG8TSYd3CJ4f/LmpT8mYVJMP8ak843KEke5bZyn7/0QV dr7c2oXxtwlIgtjBBhhwkPAVCuQj4H8= X-MC-Unique: -B6uBTZRMO6K0r5r_4cvUw-1 X-Mimecast-MFC-AGG-ID: -B6uBTZRMO6K0r5r_4cvUw_1791559868 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: akalenyu@redhat.com, , Pierrick Bouvier , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Benjamin Marzinski , Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Stefan Hajnoczi Subject: [PATCH 5/8] pr-manager-helper: add PR_HELPER_CLEANUP command support Date: Fri, 9 Oct 2026 11:30:55 -0400 Message-ID: <20261009153058.1089786-6-stefanha@redhat.com> In-Reply-To: <20261009153058.1089786-1-stefanha@redhat.com> References: <20261009153058.1089786-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791560050422158500 Content-Type: text/plain; charset="utf-8" qemu-pr-helper now supports the vendor-specific PR_HELPER_CLEANUP SCSI command. Add support to the client side. Signed-off-by: Stefan Hajnoczi --- scsi/pr-manager-helper.c | 20 ++++++++++++++++---- scsi/utils.c | 3 +++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/scsi/pr-manager-helper.c b/scsi/pr-manager-helper.c index 26ef3876f0e..fa6611ed676 100644 --- a/scsi/pr-manager-helper.c +++ b/scsi/pr-manager-helper.c @@ -38,6 +38,8 @@ struct PRManagerHelper { =20 QemuMutex lock; QIOChannel *ioc; + + uint32_t proto_flags; /* flags negotiated with pr-helper */ }; =20 static void pr_manager_send_status_changed_event(PRManagerHelper *pr_mgr) @@ -129,8 +131,9 @@ static int pr_manager_helper_initialize(PRManagerHelper= *pr_mgr, goto out_close; } =20 - flags =3D 0; - r =3D pr_manager_helper_write(pr_mgr, -1, &flags, sizeof(flags), errp); + pr_mgr->proto_flags =3D flags & PR_HELPER_FEATURE_CLEANUP; + r =3D pr_manager_helper_write(pr_mgr, -1, &pr_mgr->proto_flags, + sizeof(pr_mgr->proto_flags), errp); if (r < 0) { goto out_close; } @@ -160,10 +163,19 @@ static int pr_manager_helper_run(PRManager *p, return -EINVAL; } =20 + /* The command is only available when pr-helper supports it */ + if (cdb[0] =3D=3D PR_HELPER_CLEANUP && + !(pr_mgr->proto_flags & PR_HELPER_FEATURE_CLEANUP)) { + return -ENOTSUP; + } + memcpy(cdb, io_hdr->cmdp, io_hdr->cmd_len); - assert(cdb[0] =3D=3D PERSISTENT_RESERVE_OUT || cdb[0] =3D=3D PERSISTEN= T_RESERVE_IN); + assert(cdb[0] =3D=3D PERSISTENT_RESERVE_OUT || + cdb[0] =3D=3D PERSISTENT_RESERVE_IN || + cdb[0] =3D=3D PR_HELPER_CLEANUP); expected_dir =3D - (cdb[0] =3D=3D PERSISTENT_RESERVE_OUT ? SG_DXFER_TO_DEV : SG_DXFER= _FROM_DEV); + (cdb[0] =3D=3D PERSISTENT_RESERVE_IN ? + SG_DXFER_FROM_DEV : SG_DXFER_TO_DEV); if (io_hdr->dxfer_direction !=3D expected_dir) { return -EINVAL; } diff --git a/scsi/utils.c b/scsi/utils.c index daee90ecf0e..1ee68e68221 100644 --- a/scsi/utils.c +++ b/scsi/utils.c @@ -29,6 +29,9 @@ uint32_t scsi_data_cdb_xfer(uint8_t *buf) =20 uint32_t scsi_cdb_xfer(uint8_t *buf) { + if (buf[0] =3D=3D PR_HELPER_CLEANUP) { + return 0; + } switch (buf[0] >> 5) { case 0: return buf[4]; --=20 2.56.0 From nobody Thu Oct 22 19:25:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791559989; cv=none; d=zohomail.com; s=zohoarc; b=WKrufrxE4oFoJgIR+GTXL355k8RxkRJyXcA5kIBgQ2FEEI6xED0nQBOkfmaT0si+NiNMMJTOxoPyjCBRVtqBD0N2TJ+z+lU5MmX91RigRxFUsrg3ZXcNtxnnnPoR7uH0t2mWAvFU8RAiE/lsWVDYHzg7GhLCeTuwnM+sN2mrv/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791559989; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mJzAMPZ6e0brbYiCmNk80QKH3XKYB/yuwV8M7fX86cw=; b=PQu0uf786y0ahTKFuA4TafPp8HvE3fCZKgFCIAXm4poNY3EMCT+vOC5r1h4+m5pfGZWHmrEB88hQn3x1pgny4Ms+D8SN+HOqK7LzafNBuh4Mk7on0HDIqUd+HFHPAyfL6S6ckW92NfidFAQLtcVcuF8FmYaSDbl76ASIskWQmAo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791559989930860.0312788057864; Fri, 9 Oct 2026 08:33:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xFCaM-0001jW-59; Fri, 09 Oct 2026 11:32:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ2-0001SB-Qk for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ1-00080J-Gw for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:16 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-492-rTO5IxckPF-uNBLbjp5Nxw-1; Fri, 9 Oct 2026 15:31:10 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 679831955E8D; Fri, 9 Oct 2026 15:31:09 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1DB501800361; Fri, 9 Oct 2026 15:31:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791559874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mJzAMPZ6e0brbYiCmNk80QKH3XKYB/yuwV8M7fX86cw=; b=cThKHYQu1WXIPAE8fZH/6yTXfc6VR5py43du6VdQT0Dy7y9hmmI3G24nCKaa76Zkmc+a4h D0Kj9ACEwmYF2XS6qU5FPm6k1zJNfSdmbwXt1KkNmkKPRJvIXj/8LLw0HYgmllRgcAt88w C9NqxyefDbq7TMKEQYi//8mUYIamsr4= X-MC-Unique: rTO5IxckPF-uNBLbjp5Nxw-1 X-Mimecast-MFC-AGG-ID: rTO5IxckPF-uNBLbjp5Nxw_1791559869 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: akalenyu@redhat.com, , Pierrick Bouvier , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Benjamin Marzinski , Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Stefan Hajnoczi Subject: [PATCH 6/8] file-posix: forward PR_HELPER_CLEANUP commands to pr-manager Date: Fri, 9 Oct 2026 11:30:56 -0400 Message-ID: <20261009153058.1089786-7-stefanha@redhat.com> In-Reply-To: <20261009153058.1089786-1-stefanha@redhat.com> References: <20261009153058.1089786-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791559991522158502 Content-Type: text/plain; charset="utf-8" Signed-off-by: Stefan Hajnoczi --- block/file-posix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index 9aad156aad4..75c71e83106 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -4346,7 +4346,8 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int= req, void *buf) if (req =3D=3D SG_IO && s->pr_mgr) { struct sg_io_hdr *io_hdr =3D buf; if (io_hdr->cmdp[0] =3D=3D PERSISTENT_RESERVE_OUT || - io_hdr->cmdp[0] =3D=3D PERSISTENT_RESERVE_IN) { + io_hdr->cmdp[0] =3D=3D PERSISTENT_RESERVE_IN || + io_hdr->cmdp[0] =3D=3D PR_HELPER_CLEANUP) { return pr_manager_execute(s->pr_mgr, qemu_get_current_aio_cont= ext(), s->fd, io_hdr); } --=20 2.56.0 From nobody Thu Oct 22 19:25:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791560050; cv=none; d=zohomail.com; s=zohoarc; b=WEeuhr/lndonW7Xs1kUAmo43QD5ZcAWbI3YPwNTg9Ptf/kuFemcZW+r3geEgiQSTe5je1c+T/FgmGVo3bS7etvgBzgXcLzwAt2xGA9qRFgOV63sujDbT3OSp0u5pTnMiv9R9KCxj+Cun6oOw2rjUOMkXRRai6NZmffbPHXTaX90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791560050; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ruYUiqnvkXpnnMZU/2JbBxQTjG/hxmv35K/gMq0x8Y4=; b=gxh9xLc9WjK2ioFawq17svQXNeWPcFoJd3SuZLx/PHLVMRa+a4OK+j6Md7TSxqnjym1vxNxWXk2u5aMsaDgpyHvzhbregTkgyqMQfYGJlZNUUhWFZHkM2VVWUhunsFxZ4I7Rr5NcRHu9UW5AjJ5EOkoKgHHmFzawWAipEs0hTVU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791560050845113.39607952505366; Fri, 9 Oct 2026 08:34:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xFCbR-0002S1-Fk; Fri, 09 Oct 2026 11:33:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ5-0001SO-CH for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ1-00080Y-Vs for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:17 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-225-rvTAQVMCOB2RyCFBXIjmWg-1; Fri, 9 Oct 2026 15:31:12 +0000 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E51B618011DB; Fri, 9 Oct 2026 15:31:10 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 652A7426; Fri, 9 Oct 2026 15:31:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791559875; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ruYUiqnvkXpnnMZU/2JbBxQTjG/hxmv35K/gMq0x8Y4=; b=PtiQ+xBMGD++kT6+IFKOfZQupo05YEN/lOmm3+FcDypHeayzvxlbm02psVVWqK8rTP4TVH ew8qLdMcfnabsFOCy4Msb07UdfNpmKpNj5QChh8SjVqey39lJ/jPgFLZorNcvt+k36Sy25 gWR1n13Cl+g8BGz8tJMHTyiS0zAASPU= X-MC-Unique: rvTAQVMCOB2RyCFBXIjmWg-1 X-Mimecast-MFC-AGG-ID: rvTAQVMCOB2RyCFBXIjmWg_1791559871 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: akalenyu@redhat.com, , Pierrick Bouvier , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Benjamin Marzinski , Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Stefan Hajnoczi Subject: [PATCH 7/8] scsi: clean up persistent reservation state after migration Date: Fri, 9 Oct 2026 11:30:57 -0400 Message-ID: <20261009153058.1089786-8-stefanha@redhat.com> In-Reply-To: <20261009153058.1089786-1-stefanha@redhat.com> References: <20261009153058.1089786-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791560052519158500 Content-Type: text/plain; charset="utf-8" Live migration of persistent reservations is designed to work without coordination between the source and destination. The destination uses the PREEMPT command to atomically take over the reservation or unregister keys belonging to the source. This approach avoids race conditions where other nodes in the cluster might acquire the reservation and it minimizes communication during the downtime window. While this works at the SCSI level, this approach is incomplete when using multipathd. Multipathd tracks registered keys and automatically registers them again when paths come up. It is unaware that the destination has preempted the reservation and therefore it will still attempt to register the key on the source host. Use the new pr-helper CLEANUP command to communicate with multipathd on the source after migration completes successfully. The effect is similar to REGISTER AND IGNORE EXISTING KEY, except it also discards multipathd's state so that the source will no longer attempt to register the key. Buglink: https://redhat.atlassian.net/browse/RHEL-274966 Signed-off-by: Stefan Hajnoczi --- include/hw/scsi/scsi.h | 1 + hw/scsi/scsi-disk.c | 21 ++++++++++++++++++++- hw/scsi/scsi-generic.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index 3eab339b0d2..a2f6f0be7fc 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -256,6 +256,7 @@ SCSIDevice *scsi_device_get(SCSIBus *bus, int channel, = int target, int lun); /* scsi-generic.c. */ extern const SCSIReqOps scsi_generic_req_ops; bool scsi_generic_pr_state_preempt(SCSIDevice *s, Error **errp); +bool scsi_generic_pr_state_cleanup(SCSIDevice *s, Error **errp); =20 /* scsi-disk.c */ #define SCSI_DISK_QUIRK_MODE_PAGE_APPLE_VENDOR 0 diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 3d88e57eded..6341089ddf2 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2773,13 +2773,32 @@ static void scsi_block_migration_failed(SCSIDiskSta= te *s) } } =20 +/* + * Unregister keys on the source after migration since the destination has + * preempted and taken over. This cleanup is not necessary at the SCSI lev= el + * but multipathd tracks registered keys and must be informed that this ho= st no + * longer wishes to be registered. + */ +static void scsi_block_migration_done(SCSIDiskState *s) +{ + SCSIDevice *d =3D &s->qdev; + Error *local_err =3D NULL; + + if (!scsi_generic_pr_state_cleanup(d, &local_err)) { + error_prepend(&local_err, "scsi-block migration done: "); + warn_report_err(local_err); + } +} + static int scsi_block_migration_notifier(NotifierWithReturn *notifier, MigrationEvent *e, Error **errp) { SCSIDiskState *s =3D container_of(notifier, SCSIDiskState, migration_notifier); =20 - if (e->type =3D=3D MIG_EVENT_FAILED) { + if (e->type =3D=3D MIG_EVENT_DONE) { + scsi_block_migration_done(s); + } else if (e->type =3D=3D MIG_EVENT_FAILED) { scsi_block_migration_failed(s); } return 0; diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 153a5275567..e41e973aa92 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -652,6 +652,35 @@ bool scsi_generic_pr_state_preempt(SCSIDevice *s, Erro= r **errp) return true; } =20 +/* Clean up keys on source after migration */ +bool scsi_generic_pr_state_cleanup(SCSIDevice *s, Error **errp) +{ + SCSIPRState *pr_state =3D &s->pr_state; + uint8_t cmd[10] =3D { + PR_HELPER_CLEANUP, /* OPCODE */ + }; + int ret; + + WITH_QEMU_LOCK_GUARD(&pr_state->mutex) { + if (pr_state->key =3D=3D 0) { + return true; /* nothing to do */ + } + } + + ret =3D scsi_SG_IO(s->conf.blk, SG_DXFER_TO_DEV, cmd, sizeof(cmd), NUL= L, 0, + s->io_timeout, errp); + if (ret < 0) { + error_prepend(errp, "pr-helper CLEANUP failed: "); + return false; + } + + WITH_QEMU_LOCK_GUARD(&pr_state->mutex) { + pr_state->key =3D 0; + pr_state->resv_type =3D 0; + } + return true; +} + static void scsi_read_complete(void * opaque, int ret) { SCSIGenericReq *r =3D (SCSIGenericReq *)opaque; --=20 2.56.0 From nobody Thu Oct 22 19:25:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791560157; cv=none; d=zohomail.com; s=zohoarc; b=QxaT/49OUCfArWd59IJWC+aALxaSNq9ns/02NVpFdz2SA0wH6ZEAaul9tcvJoyEDMr8HJrZzg5JDvMqXpjylCLW+o8uvywOSqhTuRSOFe6EETFbrfo9SD7UxCew4lwZ7zKAkB5qP1WGGHiq6CUT/z1btt7tXo1oWAD24S8HWs64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791560157; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wyJrL50gtdvm3FTztrrzURWMCb9Tz1QgOWWG3qZnCgg=; b=Xzf8qMGEteluVX9FyLD4Zp8xxvnchLU4AQcM4pdYI0Y0HfrWVMDJww+TjVmWf6Hk9ootTkuKqh6f4rMalLbJFjYeeoyXWFBYcli6avC1aSm+z7HjB2HWpDaeSOUO5xFgfJPWQcdPfyF33Eo7CxN7JeBMzIF0c7JpAyZ9248DAPw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791560157427376.3857391163923; Fri, 9 Oct 2026 08:35:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xFCa8-0001bQ-Ry; Fri, 09 Oct 2026 11:32:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ5-0001SP-D6 for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xFCZ3-00080u-5V for qemu-devel@nongnu.org; Fri, 09 Oct 2026 11:31:18 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-vXhMczZQPd2OPZ4jqty6RQ-1; Fri, 9 Oct 2026 15:31:13 +0000 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3C6451964CCB; Fri, 9 Oct 2026 15:31:12 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DF02E30000E8; Fri, 9 Oct 2026 15:31:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791559876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wyJrL50gtdvm3FTztrrzURWMCb9Tz1QgOWWG3qZnCgg=; b=AVOnCt5qp1eOgJ3jlYZ3hmPi4r+2vf4QVV0ZI4YcxvqLm5fNxHOHIt4N/O09Rr1Pryuy+c ZbaCgAbHiIURS/it2yEkVjpklTkf3bY9WSsusNandlBPeWDk/nTdkyQ3CZdMtqiOte2usk KEMfCYOis8dXFwqtb9iXLj46PepYP+0= X-MC-Unique: vXhMczZQPd2OPZ4jqty6RQ-1 X-Mimecast-MFC-AGG-ID: vXhMczZQPd2OPZ4jqty6RQ_1791559872 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: akalenyu@redhat.com, , Pierrick Bouvier , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Benjamin Marzinski , Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Stefan Hajnoczi Subject: [PATCH 8/8] scsi: use REGISTER AND IGNORE EXISTING KEY for robustness Date: Fri, 9 Oct 2026 11:30:58 -0400 Message-ID: <20261009153058.1089786-9-stefanha@redhat.com> In-Reply-To: <20261009153058.1089786-1-stefanha@redhat.com> References: <20261009153058.1089786-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791560158303158500 Content-Type: text/plain; charset="utf-8" The regular REGISTER service action fails with RESERVATION CONFLICT when the I_T nexus already has a key registered. While we don't expect a key to be registered, it is fragile to rely on this. If there is a key registered for some reason, live migration will fail when the destination hits the RESERVATION CONFLICT error. Use REGISTER AND IGNORE EXISTING KEY so that the command is likely to succeed. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- hw/scsi/scsi-generic.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index e41e973aa92..e48fcb926f1 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -424,7 +424,8 @@ static void scsi_handle_persistent_reserve_out_reply( } } =20 -static bool scsi_generic_pr_register(SCSIDevice *s, uint64_t key, Error **= errp) +static bool scsi_generic_pr_register_ignore(SCSIDevice *s, uint64_t key, + Error **errp) { uint8_t cmd[10] =3D {}; uint8_t buf[24] =3D {}; @@ -432,14 +433,15 @@ static bool scsi_generic_pr_register(SCSIDevice *s, u= int64_t key, Error **errp) int ret; =20 cmd[0] =3D PERSISTENT_RESERVE_OUT; - cmd[1] =3D PRO_REGISTER; + cmd[1] =3D PRO_REGISTER_AND_IGNORE_EXISTING_KEY; cmd[8] =3D sizeof(buf); memcpy(&buf[8], &key_be, sizeof(key_be)); =20 ret =3D scsi_SG_IO(s->conf.blk, SG_DXFER_TO_DEV, cmd, sizeof(cmd), buf, sizeof(buf), s->io_timeout, errp); if (ret < 0) { - error_prepend(errp, "PERSISTENT RESERVE OUT with REGISTER: "); + error_prepend(errp, "PERSISTENT RESERVE OUT with " + "REGISTER AND IGNORE EXISTING KEY: "); return false; } return true; @@ -620,7 +622,7 @@ bool scsi_generic_pr_state_preempt(SCSIDevice *s, Error= **errp) return true; /* no PR state, do nothing */ } =20 - if (!scsi_generic_pr_register(s, key, errp)) { + if (!scsi_generic_pr_register_ignore(s, key, errp)) { return false; } =20 @@ -647,7 +649,7 @@ bool scsi_generic_pr_state_preempt(SCSIDevice *s, Error= **errp) * CONFLICT is expected if our registration remained in place. */ if (resv_type =3D=3D 0) { - scsi_generic_pr_register(s, key, NULL); + scsi_generic_pr_register_ignore(s, key, NULL); } return true; } --=20 2.56.0