get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.0/patches/2221140/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2221140,
    "url": "http://patchwork.ozlabs.org/api/1.0/patches/2221140/?format=api",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/1.0/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": "<20260408165559.157108-9-peterx@redhat.com>",
    "date": "2026-04-08T16:55:52",
    "name": "[08/14] migration: Make qemu_savevm_query_pending() available anytime",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "8d5a0976cc9b335cf63dc30eb63309c463b52448",
    "submitter": {
        "id": 67717,
        "url": "http://patchwork.ozlabs.org/api/1.0/people/67717/?format=api",
        "name": "Peter Xu",
        "email": "peterx@redhat.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260408165559.157108-9-peterx@redhat.com/mbox/",
    "series": [
        {
            "id": 499176,
            "url": "http://patchwork.ozlabs.org/api/1.0/series/499176/?format=api",
            "date": "2026-04-08T16:55:55",
            "name": "migration/vfio: Fix a few issues on API misuse or statistic reports",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/499176/mbox/"
        }
    ],
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2221140/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=R/iGrigD;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=google header.b=ltUE37aQ;\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=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"
        ],
        "Received": [
            "from lists.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 4frY0d2Fjxz1yD6\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 05:24:33 +1000 (AEST)",
            "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wAYSo-0004PM-MK; Wed, 08 Apr 2026 15:21:22 -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 <peterx@redhat.com>) id 1wAY3p-00066S-0S\n for qemu-devel@nongnu.org; Wed, 08 Apr 2026 14:55:33 -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 <peterx@redhat.com>) id 1wAWCO-00028r-VA\n for qemu-devel@nongnu.org; Wed, 08 Apr 2026 12:56:18 -0400",
            "from mail-qk1-f200.google.com (mail-qk1-f200.google.com\n [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-147-nH0Zvgx6MlmtCQkut6TcMg-1; Wed, 08 Apr 2026 12:56:15 -0400",
            "by mail-qk1-f200.google.com with SMTP id\n af79cd13be357-8d411d0c1faso32841385a.0\n for <qemu-devel@nongnu.org>; Wed, 08 Apr 2026 09:56:15 -0700 (PDT)",
            "from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id\n d75a77b69052e-50d712c2617sm130491901cf.31.2026.04.08.09.56.12\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 08 Apr 2026 09:56:12 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1775667376;\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=9pBpMxP6DqkQFj1pPDgFhUWgDgyZXFHvFl5cTHTGA8Q=;\n b=R/iGrigDDM3J1SigIXBea7EeZNP6Ik0+r7VoswR0FJY0uKPKHKEaPYOSLTl7MlWYeSTTrk\n 1Mpynh3faTmVbpX3p17AVyqNjaALdZJNzTklNJOjmvteceFXr1dckOidd+0AJm+CY497At\n BE3uJHNWtFGWejVAk/FQvC1k0VSryyI=",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=redhat.com; s=google; t=1775667375; x=1776272175; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=9pBpMxP6DqkQFj1pPDgFhUWgDgyZXFHvFl5cTHTGA8Q=;\n b=ltUE37aQsL1XvzZCFtWckJwIhBDufxfbVSRYplcOeiq/MxHQwrBJlwUwYH5PL5CYrI\n MWJslWRnkhl33mii6TdW1a4juuM7E6HWLUPUwDtt8g+2PtO5N3pFK3++xHEUfKeJUfXE\n 3uHeTvcdcmlcZeUa3F2mkOk5Hax9xTq9LoJ9xCNWnB2H2RZZsCq9qoC0g/wBUmDUDuXk\n LAop7sy/x1ND3fIFoigpjGg2wqUEmOJt0mII8wuDFIQB1L/Q0xWBpKxRFfyhvmyze6mc\n V/dSXJ8qi+PpoVuJ0GrllWl0Ef1jf5yr1lVHxFwUAR6di5yyrynGZUD0NVxNwJr8Isx2\n /Y7A=="
        ],
        "X-MC-Unique": "nH0Zvgx6MlmtCQkut6TcMg-1",
        "X-Mimecast-MFC-AGG-ID": "nH0Zvgx6MlmtCQkut6TcMg_1775667375",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775667375; x=1776272175;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=9pBpMxP6DqkQFj1pPDgFhUWgDgyZXFHvFl5cTHTGA8Q=;\n b=Ovzbg631aolq/t8bFqgbRNRa0CuIO4PCOG88JIy46CumI1yQG0mh1OnCvCdNgHhn5t\n OiF2I3fimwHM8LRT134fK00O8jIGo+eUl6YL3tFTJh0yPDTvkiLDi/PP1yN0HpvVLbnJ\n 0aIAB3klf81LJCaaS6xu0lQnElvWsX6WpZEiT1+EuENhdBAiO8kqy11+97zt5zloCQHJ\n LiB2Fs0zbGCr7gN9eQRHnOpNl2R8eafbxRyK64Quj/tCp3z0Jt0MaDsxc+NiuSma0kKR\n LYEaJ3mPcx+BBs6C8uL/PLFUvZb0FsYBpeXdToORRVunwTeybMhwrZs8u0WcgD3HVxge\n 3FkQ==",
        "X-Gm-Message-State": "AOJu0YzryOYzoqCkIrDTlDIaeewVnxa2KFWURFnDYpgxqkwHk/c5gaZl\n 9d7D2U2qXgP+K45yjo0bqcj6fTNjh6Crx5T4qgVPNWZ6ItEyl9kb6pFKoPU/ZBzdkoqIU39xMjQ\n DQwSD1PXoszdXTmOqPj9NdDO4Ea7cIBNFHRYijxEL9gj3l3zBOJSAvc3Htl58Bk+NNYWlVzAVlD\n W9vwh6aNN0+iiymFuC0S8EgfdbPzbgnjJlfwe/AA==",
        "X-Gm-Gg": "AeBDiesOPtoQAoRlY1qPOeqjJAtVgB7L9ljDan0MBARxMRxSdAqANzENnKQxjAMmwme\n 9EZn1XGGRty1U0YbAaAoEXiRwf+JS93EeHU5r+/zPDrmnzo2dixkwyLqluGWBIAANWZzHrwtVzK\n p1WgGzm6TBsGOzRgPUqiAwts0Pz9nbLtFg4xavrt5H9HESudBV9ghSCu7AZ+E4dgwrBmLIG+Zjr\n kXUCbEx6zhrtgSat4SVLRt+Dj4iUtjXzTONW5sX0qBvBhXJix96huOj1rabLCfyqlgDTqtv1Q1W\n NfD/GJZgAoPok1fEEf0aB4MAxSOIONCGiRQkKUZFMEp9uNquFpt5YtX0Xm4CXPR+7w7WIxFoeMK\n 0JrHriXdSCDOGmdhMy7N+CTXxfBJyxJmsxka8y8TiC0Pc",
        "X-Received": [
            "by 2002:a05:622a:288:b0:50d:ab9d:33bc with SMTP id\n d75a77b69052e-50dc20d670fmr1801491cf.8.1775667374285;\n Wed, 08 Apr 2026 09:56:14 -0700 (PDT)",
            "by 2002:a05:622a:288:b0:50d:ab9d:33bc with SMTP id\n d75a77b69052e-50dc20d670fmr1800691cf.8.1775667373506;\n Wed, 08 Apr 2026 09:56:13 -0700 (PDT)"
        ],
        "From": "Peter Xu <peterx@redhat.com>",
        "To": "qemu-devel@nongnu.org",
        "Cc": "\"Maciej S . Szmigiero\" <mail@maciej.szmigiero.name>, =?utf-8?q?Daniel_P_?=\n\t=?utf-8?q?=2E_Berrang=C3=A9?= <berrange@redhat.com>,\n Zhiyi Guo <zhguo@redhat.com>, Juraj Marcin <jmarcin@redhat.com>,\n Peter Xu <peterx@redhat.com>, Prasad Pandit <ppandit@redhat.com>,\n Avihai Horon <avihaih@nvidia.com>, Kirti Wankhede <kwankhede@nvidia.com>,\n\t=?utf-8?q?C=C3=A9dric_Le_Goater?= <clg@redhat.com>,\n Fabiano Rosas <farosas@suse.de>, Joao Martins <joao.m.martins@oracle.com>,\n Markus Armbruster <armbru@redhat.com>, Alex Williamson <alex@shazbot.org>",
        "Subject": "[PATCH 08/14] migration: Make qemu_savevm_query_pending() available\n anytime",
        "Date": "Wed,  8 Apr 2026 12:55:52 -0400",
        "Message-ID": "<20260408165559.157108-9-peterx@redhat.com>",
        "X-Mailer": "git-send-email 2.53.0",
        "In-Reply-To": "<20260408165559.157108-1-peterx@redhat.com>",
        "References": "<20260408165559.157108-1-peterx@redhat.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Received-SPF": "pass client-ip=170.10.129.124; envelope-from=peterx@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, 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 <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": "After qemu_savevm_query_pending() be exposed to more code paths, it can be\nused at very early stage when migration started and this may expose some\nrace conditions that we don't use to have.  This patch make it prepared\nfor such use cases so this API is fine to be used almost anytime.\n\nWhat matters here is, querying pending for each module normally depends on\nsave_setup() being run first, otherwise modules may not be ready for the\nquery request.\n\nConsider an early cancellation of migration after SETUP status but before\ninvocations of save_setup() hooks, source QEMU may fall into CANCELLING\nstage directly from SETUP (not ACTIVE, which is the normal use case), in\nwhich case save_setup() may not have been invoked and modules are not\nready.  However qemu_savevm_query_pending() may still be used in QMP\ncommands like query-migrate and causing crashes.\n\nGuard such use case by introducing a boolean reflecting the availability of\nvmstate save handlers on correct completions of save_setup()s.  So far,\nonly protect qemu_savevm_query_pending() with it.  Logically other hooks\nface similar concern, but most of them shouldn't be reachable from random\ncode path except migration thread so it should be fine.\n\nSigned-off-by: Peter Xu <peterx@redhat.com>\n---\n migration/migration.h |  8 ++++++++\n migration/savevm.h    |  2 +-\n migration/migration.c |  2 +-\n migration/savevm.c    | 37 +++++++++++++++++++++++++++++++++----\n 4 files changed, 43 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/migration/migration.h b/migration/migration.h\nindex b6888daced..e504df6915 100644\n--- a/migration/migration.h\n+++ b/migration/migration.h\n@@ -522,6 +522,14 @@ struct MigrationState {\n      * anything as input.\n      */\n     bool has_block_bitmap_mapping;\n+\n+    /*\n+     * This boolean reflects if the vmstate handlers have been properly\n+     * setup on source side.  It is set after vmstate save_setup() hooks\n+     * are successfully invoked, and cleared after save_cleanup()s.  It\n+     * reflects a general availability of vmstate hooks on the source side.\n+     */\n+    bool save_setup_ready;\n };\n \n void migrate_set_state(MigrationStatus *state, MigrationStatus old_state,\ndiff --git a/migration/savevm.h b/migration/savevm.h\nindex 96fdf96d4e..04ed09cec2 100644\n--- a/migration/savevm.h\n+++ b/migration/savevm.h\n@@ -42,7 +42,7 @@ int qemu_savevm_state_resume_prepare(MigrationState *s);\n void qemu_savevm_send_header(QEMUFile *f);\n void qemu_savevm_state_header(QEMUFile *f);\n int qemu_savevm_state_iterate(QEMUFile *f, bool postcopy);\n-void qemu_savevm_state_cleanup(void);\n+void qemu_savevm_state_cleanup(MigrationState *s);\n void qemu_savevm_state_complete_postcopy(QEMUFile *f);\n int qemu_savevm_state_complete_precopy(MigrationState *s);\n void qemu_savevm_query_pending(MigPendingData *pending, bool exact);\ndiff --git a/migration/migration.c b/migration/migration.c\nindex bb17bd0e68..a9ee3360e1 100644\n--- a/migration/migration.c\n+++ b/migration/migration.c\n@@ -1283,7 +1283,7 @@ static void migration_cleanup(MigrationState *s)\n     g_free(s->hostname);\n     s->hostname = NULL;\n \n-    qemu_savevm_state_cleanup();\n+    qemu_savevm_state_cleanup(s);\n     cpr_state_close();\n     cpr_transfer_source_destroy(s);\n \ndiff --git a/migration/savevm.c b/migration/savevm.c\nindex b75c311a95..1d3fce45b9 100644\n--- a/migration/savevm.c\n+++ b/migration/savevm.c\n@@ -1387,7 +1387,8 @@ int qemu_savevm_state_non_iterable_early(QEMUFile *f,\n     return 0;\n }\n \n-static int qemu_savevm_state_setup(QEMUFile *f, Error **errp)\n+static int qemu_savevm_state_setup(MigrationState *s, QEMUFile *f,\n+                                   Error **errp)\n {\n     SaveStateEntry *se;\n     int ret;\n@@ -1409,6 +1410,13 @@ static int qemu_savevm_state_setup(QEMUFile *f, Error **errp)\n         }\n     }\n \n+    /*\n+     * Logically, it should be paired with any hook being used who needs to\n+     * load_acquire() the flag first.  So far, only save_query_pending()\n+     * uses it.\n+     */\n+    qatomic_store_release(&s->save_setup_ready, true);\n+\n     return 0;\n }\n \n@@ -1429,7 +1437,7 @@ int qemu_savevm_state_do_setup(QEMUFile *f, Error **errp)\n         return ret;\n     }\n \n-    ret = qemu_savevm_state_setup(f, errp);\n+    ret = qemu_savevm_state_setup(ms, f, errp);\n     if (ret) {\n         return ret;\n     }\n@@ -1764,10 +1772,23 @@ int qemu_savevm_state_complete_precopy(MigrationState *s)\n \n void qemu_savevm_query_pending(MigPendingData *pending, bool exact)\n {\n+    MigrationState *s = migrate_get_current();\n     SaveStateEntry *se;\n \n     memset(pending, 0, sizeof(*pending));\n \n+    /*\n+     * This API can be invoked very early before SETUP is properly done, in\n+     * that case don't invoke module queries because they're not ready.\n+     * Just report all zeros.\n+     *\n+     * This is paired with save_setup_ready updates on save_setup() and\n+     * save_cleanup().\n+     */\n+    if (!s || !qatomic_load_acquire(&s->save_setup_ready)) {\n+        return;\n+    }\n+\n     QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {\n         if (!se->ops || !se->ops->save_query_pending) {\n             continue;\n@@ -1786,7 +1807,7 @@ void qemu_savevm_query_pending(MigPendingData *pending, bool exact)\n                                     pending->postcopy_bytes);\n }\n \n-void qemu_savevm_state_cleanup(void)\n+void qemu_savevm_state_cleanup(MigrationState *s)\n {\n     SaveStateEntry *se;\n     Error *local_err = NULL;\n@@ -1795,6 +1816,14 @@ void qemu_savevm_state_cleanup(void)\n         error_report_err(local_err);\n     }\n \n+    s->save_setup_ready = false;\n+    /*\n+     * Make sure we clear the flag before invoking save_cleanup(), so any\n+     * racy QMP query-migrate won't try to invoke any save hooks.  Just use\n+     * an explicit barrier to be simple.\n+     */\n+    smp_mb();\n+\n     trace_savevm_state_cleanup();\n     QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {\n         if (se->ops && se->ops->save_cleanup) {\n@@ -1841,7 +1870,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)\n         error_setg_errno(errp, -ret, \"Error while writing VM state\");\n     }\n cleanup:\n-    qemu_savevm_state_cleanup();\n+    qemu_savevm_state_cleanup(ms);\n \n     if (ret != 0) {\n         status = MIGRATION_STATUS_FAILED;\n",
    "prefixes": [
        "08/14"
    ]
}