Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2223664/?format=api
{ "id": 2223664, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2223664/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260415232906.212349-3-stefanha@redhat.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/1.1/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260415232906.212349-3-stefanha@redhat.com>", "date": "2026-04-15T23:29:06", "name": "[2/2] scsi: handle reservation changes across migration", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "8ae455f02b4424e449e1ba671d535d35f2ed5f1b", "submitter": { "id": 17227, "url": "http://patchwork.ozlabs.org/api/1.1/people/17227/?format=api", "name": "Stefan Hajnoczi", "email": "stefanha@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260415232906.212349-3-stefanha@redhat.com/mbox/", "series": [ { "id": 500051, "url": "http://patchwork.ozlabs.org/api/1.1/series/500051/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=500051", "date": "2026-04-15T23:29:04", "name": "scsi: handle reservation changes across migration", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/500051/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2223664/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2223664/checks/", "tags": {}, "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=hArgLsOQ;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fwy6w6NDMz1yG9\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 09:30:16 +1000 (AEST)", "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wD9fv-00016F-5m; Wed, 15 Apr 2026 19:29:39 -0400", "from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <stefanha@redhat.com>)\n id 1wD9fi-00013x-IP\n for qemu-devel@nongnu.org; Wed, 15 Apr 2026 19:29:28 -0400", "from us-smtp-delivery-124.mimecast.com ([170.10.129.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <stefanha@redhat.com>)\n id 1wD9fg-00011W-4p\n for qemu-devel@nongnu.org; Wed, 15 Apr 2026 19:29:25 -0400", "from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-673-p2vHyAZfPgSei7bvYP_a7A-1; Wed,\n 15 Apr 2026 19:29:20 -0400", "from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 56F0A18005A9; Wed, 15 Apr 2026 23:29:19 +0000 (UTC)", "from localhost (unknown [10.44.34.70])\n by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 4C36B1955F43; Wed, 15 Apr 2026 23:29:17 +0000 (UTC)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776295763;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=QDdW5psnASriwqAha13B7nHWu8m/JIs4baxXcH9bxPQ=;\n b=hArgLsOQMwDrU5TJbXLwE5hIKhV/sInuVsbeY3M0yraiyI/1w4WRBn9S1anVtJ3CzvVRQD\n XJ9aNkOX+66HAjN9+QoaGGQygKB3NrFpCBH0YPGsKi8Yev+wTI3/D5dGoPwcVWWdZog+5z\n FYVHMGRVM2Mp7ThzX/Y9Hp6VxMDb3a0=", "X-MC-Unique": "p2vHyAZfPgSei7bvYP_a7A-1", "X-Mimecast-MFC-AGG-ID": "p2vHyAZfPgSei7bvYP_a7A_1776295759", "From": "Stefan Hajnoczi <stefanha@redhat.com>", "To": "qemu-devel@nongnu.org", "Cc": "Fam Zheng <fam@euphon.net>, Paolo Bonzini <pbonzini@redhat.com>,\n <qemu-block@nongnu.org>, Stefan Hajnoczi <stefanha@redhat.com>", "Subject": "[PATCH 2/2] scsi: handle reservation changes across migration", "Date": "Wed, 15 Apr 2026 19:29:06 -0400", "Message-ID": "<20260415232906.212349-3-stefanha@redhat.com>", "In-Reply-To": "<20260415232906.212349-1-stefanha@redhat.com>", "References": "<20260415232906.212349-1-stefanha@redhat.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-Scanned-By": "MIMEDefang 3.0 on 10.30.177.17", "Received-SPF": "pass client-ip=170.10.129.124;\n envelope-from=stefanha@redhat.com;\n helo=us-smtp-delivery-124.mimecast.com", "X-Spam_score_int": "-25", "X-Spam_score": "-2.6", "X-Spam_bar": "--", "X-Spam_report": "(-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_PASS=-0.001,\n SPF_PASS=-0.001 autolearn=unavailable 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 <qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org" }, "content": "Other nodes in the cluster can preempt or clear SCSI Persistent\nReservations at any time. When this happens across live migration, the\nreservation state transferred with the guest might be outdated.\n\nAttempt to handle such cases gracefully by checking the current\nreservation or registered keys to detect stale state before restoring.\nIf the actual state of the disk has changed, do not modify it and accept\nthat as the most up-to-date state.\n\nDo this using READ RESERVATION when the guest holds a reservation or\nREAD KEYS when the guest has registered a key but does not hold a\nreservation.\n\nThere is still a race condition between checking and restoring state,\nbut it seems unavoidable and is no worse than before.\n\nBuglink: https://redhat.atlassian.net/browse/RHEL-153123\nFixes: ab57b51f1375b6a6f098a74c6f79207a9630948d (\"scsi: save/load SCSI reservation state\")\nReported-by: Qing Wang\nSigned-off-by: Stefan Hajnoczi <stefanha@redhat.com>\n---\n hw/scsi/scsi-generic.c | 173 +++++++++++++++++++++++++++++++++++------\n 1 file changed, 149 insertions(+), 24 deletions(-)", "diff": "diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c\nindex 29bc952af5..8999f3b720 100644\n--- a/hw/scsi/scsi-generic.c\n+++ b/hw/scsi/scsi-generic.c\n@@ -479,13 +479,84 @@ static bool scsi_generic_pr_preempt(SCSIDevice *s, uint64_t key,\n return true;\n }\n \n+/*\n+ * Returns true if the given key is registered or false otherwise (including\n+ * errors).\n+ */\n+static bool scsi_generic_pr_key_registered(SCSIDevice *s, uint64_t key,\n+ Error **errp)\n+{\n+ const size_t key_list_offset = 8; /* in READ KEYS parameter data */\n+ uint64_t key_be = cpu_to_be64(key);\n+ uint8_t cmd[10] = {};\n+ size_t buf_len;\n+ g_autofree uint8_t *buf = NULL;\n+ uint32_t additional_length = 16 * 8; /* initial key list size */\n+\n+ /*\n+ * Loop to resize parameter data buffer when there are many keys. It would\n+ * be simpler to hardcode the maximum buffer size (it's only 64 KB), but\n+ * SG_IO can fail with EINVAL if the host kernel blkdev queue limits are\n+ * too low.\n+ */\n+ do {\n+ uint16_t allocation_length_be;\n+ int ret;\n+\n+ buf_len = key_list_offset + additional_length;\n+ buf = g_realloc(buf, buf_len);\n+ memset(buf, 0, buf_len);\n+\n+ cmd[0] = PERSISTENT_RESERVE_IN;\n+ cmd[1] = PRI_READ_KEYS;\n+ allocation_length_be = cpu_to_be16(buf_len);\n+ memcpy(&cmd[7], &allocation_length_be, sizeof(allocation_length_be));\n+\n+ ret = scsi_SG_IO(s->conf.blk, SG_DXFER_FROM_DEV, cmd, sizeof(cmd),\n+ buf, buf_len, s->io_timeout, errp);\n+ if (ret < 0) {\n+ error_prepend(errp, \"PERSISTENT RESERVE IN with READ KEYS: \");\n+ return false;\n+ }\n+\n+ memcpy(&additional_length, &buf[4], sizeof(additional_length));\n+ be32_to_cpus(&additional_length);\n+\n+ /*\n+ * The parameter data's ADDITIONAL LENGTH must not overflow the CDB's\n+ * 16-bit ALLOCATION LENGTH field since the next loop iteration will\n+ * compute ALLOCATION LENGTH based on ADDITIONAL LENGTH.\n+ */\n+ if (additional_length > UINT16_MAX - key_list_offset) {\n+ error_setg(errp, \"got invalid ADDITIONAL LENGTH %\" PRIu32\n+ \" from READ KEYS\", additional_length);\n+ return false;\n+ }\n+\n+ for (size_t i = key_list_offset; i < buf_len; i += sizeof(key_be)) {\n+ if (i - key_list_offset >= additional_length) {\n+ break; /* end of parameter list */\n+ }\n+\n+ if (memcmp(&key_be, &buf[i], sizeof(key_be)) == 0) {\n+ return true; /* key found */\n+ }\n+ }\n+ } while (additional_length > buf_len - key_list_offset);\n+\n+ return false; /* key not found */\n+}\n+\n /* Register keys and preempt reservations after live migration */\n bool scsi_generic_pr_state_preempt(SCSIDevice *s, Error **errp)\n {\n SCSIPRState *pr_state = &s->pr_state;\n+ Error *local_err = NULL;\n+ bool check_stale_key = true;\n uint64_t key;\n uint8_t resv_type;\n \n+ /* Get the migrated PR state */\n WITH_QEMU_LOCK_GUARD(&pr_state->mutex) {\n key = pr_state->key;\n resv_type = pr_state->resv_type;\n@@ -493,36 +564,90 @@ bool scsi_generic_pr_state_preempt(SCSIDevice *s, Error **errp)\n \n trace_scsi_generic_pr_state_preempt(key, resv_type);\n \n- if (key) {\n- if (!scsi_generic_pr_register(s, key, errp)) {\n+ /* Handle stale PR state (e.g. another node preempted) */\n+ if (resv_type) {\n+ uint64_t dev_key;\n+ uint8_t dev_resv_type;\n+\n+ if (scsi_generic_read_reservation(s, &dev_key, &dev_resv_type,\n+ errp) < 0) {\n return false;\n }\n \n- /*\n- * Two cases:\n- *\n- * 1. There is no reservation (resv_type is 0) and the other I_T nexus\n- * will be unregistered. This is important so the source host does\n- * not leak registered keys across live migration.\n- *\n- * 2. There is a reservation (resv_type is not 0) and the other I_T\n- * nexus will be unregistered and its reservation is atomically\n- * taken over by us. This is the scenario where a reservation is\n- * migrated along with the guest.\n- */\n- if (!scsi_generic_pr_preempt(s, key, resv_type, errp)) {\n+ if (dev_resv_type != resv_type) {\n+ /* vmstate had a stale reservation type */\n+ g_autofree char *name = qdev_get_human_name(&s->qdev);\n+ warn_report(\"Expected SCSI reservation type 0x%x on device '%s', \"\n+ \"got 0x%x, using new type\",\n+ resv_type, name, dev_resv_type);\n+ resv_type = dev_resv_type;\n+ }\n+\n+ if (dev_key == key) {\n+ /* The reservation exists, no need to check for a stale key */\n+ check_stale_key = false;\n+ } else {\n+ g_autofree char *name = qdev_get_human_name(&s->qdev);\n+ warn_report(\"Expected SCSI reservation with key 0x%\" PRIx64\n+ \" on device '%s', got 0x%\" PRIx64 \", ignoring \"\n+ \"reservation\",\n+ key, name, dev_key);\n+ resv_type = 0; /* vmstate had a stale reservation */\n+ }\n+ }\n+\n+ if (key != 0 && check_stale_key &&\n+ !scsi_generic_pr_key_registered(s, key, &local_err)) {\n+ if (local_err) {\n+ error_propagate(errp, local_err);\n return false;\n }\n \n- /*\n- * Some SCSI targets, like the Linux LIO target, remove our\n- * registration when preempting without a reservation (resv_type is 0).\n- * Try to register again but ignore the error since a RESERVATION\n- * CONFLICT is expected if our registration remained in place.\n- */\n- if (resv_type == 0) {\n- scsi_generic_pr_register(s, key, NULL);\n- }\n+ g_autofree char *name = qdev_get_human_name(&s->qdev);\n+ warn_report(\"SCSI reservation key 0x%\" PRIx64 \" on device '%s' not \"\n+ \"registered after migration, ignoring\",\n+ key, name);\n+ key = 0; /* vmstate had a stale key */\n+ }\n+\n+ /* Stale PR state may have been updated */\n+ WITH_QEMU_LOCK_GUARD(&pr_state->mutex) {\n+ pr_state->key = key;\n+ pr_state->resv_type = resv_type;\n+ }\n+\n+ if (key == 0) {\n+ return true; /* no PR state, do nothing */\n+ }\n+\n+ if (!scsi_generic_pr_register(s, key, errp)) {\n+ return false;\n+ }\n+\n+ /*\n+ * Two cases:\n+ *\n+ * 1. There is no reservation (resv_type is 0) and the other I_T nexus\n+ * will be unregistered. This is important so the source host does\n+ * not leak registered keys across live migration.\n+ *\n+ * 2. There is a reservation (resv_type is not 0) and the other I_T\n+ * nexus will be unregistered and its reservation is atomically\n+ * taken over by us. This is the scenario where a reservation is\n+ * migrated along with the guest.\n+ */\n+ if (!scsi_generic_pr_preempt(s, key, resv_type, errp)) {\n+ return false;\n+ }\n+\n+ /*\n+ * Some SCSI targets, like the Linux LIO target, remove our\n+ * registration when preempting without a reservation (resv_type is 0).\n+ * Try to register again but ignore the error since a RESERVATION\n+ * CONFLICT is expected if our registration remained in place.\n+ */\n+ if (resv_type == 0) {\n+ scsi_generic_pr_register(s, key, NULL);\n }\n return true;\n }\n", "prefixes": [ "2/2" ] }