get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 2217863,
    "url": "http://patchwork.ozlabs.org/api/patches/2217863/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260330-fast-snapshot-refactor-v1-2-22143e70c467@gmail.com/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/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": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20260330-fast-snapshot-refactor-v1-2-22143e70c467@gmail.com>",
    "list_archive_url": null,
    "date": "2026-03-30T19:04:42",
    "name": "[2/3] migration/postcopy: Factor out uffd_setup_incoming() from postcopy setup",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "252ccb48d7c770f0dc9cad1c9898044e9e5f3df4",
    "submitter": {
        "id": 87325,
        "url": "http://patchwork.ozlabs.org/api/people/87325/?format=api",
        "name": "Takeru Hayasaka",
        "email": "hayatake396@gmail.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260330-fast-snapshot-refactor-v1-2-22143e70c467@gmail.com/mbox/",
    "series": [
        {
            "id": 498082,
            "url": "http://patchwork.ozlabs.org/api/series/498082/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=498082",
            "date": "2026-03-30T19:04:41",
            "name": "migration/postcopy: Preparatory refactoring for fast snapshot load",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/498082/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2217863/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2217863/checks/",
    "tags": {},
    "related": [],
    "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 (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=nFjnuKfR;\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 (lists.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 4fl12F3XDMz1yG7\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 31 Mar 2026 06:06:45 +1100 (AEDT)",
            "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 1w7HwM-0004IE-8A; Mon, 30 Mar 2026 15:06:25 -0400",
            "from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <hayatake396@gmail.com>)\n id 1w7HvX-0003pD-En\n for qemu-devel@nongnu.org; Mon, 30 Mar 2026 15:05:33 -0400",
            "from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <hayatake396@gmail.com>)\n id 1w7HvV-0005De-88\n for qemu-devel@nongnu.org; Mon, 30 Mar 2026 15:05:31 -0400",
            "by mail-pf1-x435.google.com with SMTP id\n d2e1a72fcca58-82cd5c07f93so124195b3a.1\n for <qemu-devel@nongnu.org>; Mon, 30 Mar 2026 12:05:27 -0700 (PDT)",
            "from [127.0.1.1] (191.68.231.218.rev.ocx2915.net. [218.231.68.191])\n by smtp.gmail.com with ESMTPSA id\n d2e1a72fcca58-82ca84644d9sm8496989b3a.13.2026.03.30.12.05.24\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Mon, 30 Mar 2026 12:05:25 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1774897526; x=1775502326; darn=nongnu.org;\n h=cc:to:in-reply-to:references:message-id:content-transfer-encoding\n :mime-version:subject:date:from:from:to:cc:subject:date:message-id\n :reply-to; bh=xvDeM0TyoHIJuMI9O46gKFM23hqyKFmD6p428QNsoc8=;\n b=nFjnuKfRiMTEaoXQxV6tSu+jj6WVg9ZKsf3DXrfKHK4nYllSlLlnUM3WvoGWt1E33u\n EylmwoldGEwfyCoYoIOb6XF6kjzhsHeP4LrblXVFeF+dbvLApXzdxExDDlAtvKw60lcF\n AbTVrnhvkbu+W6f5L6fWhel2jwvTDuRpUJSpzDyuiApnFsAsUbw8iy/+PQ/3WsDsr6Qt\n ABTj9pZwAmuSbxnG3iLOkpsQSb5dpQSNGf0fAWf8q5mgohoRC3xoMfiCQoyZ9mRsrNR1\n 3xWlkfBRsA7fXCGENuJeGG9RVLBGGPocInWMXM+O5NXiLsXKTOR6JwuFN2rYNCQja1QI\n LiNg==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1774897526; x=1775502326;\n h=cc:to:in-reply-to:references:message-id:content-transfer-encoding\n :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to\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fx7HlyZ1xs0CO6noVIr1C0Ehbl3B5D85klkLppAk0SJX0QLa5l\n IPpIgS1bEW4z9BzCQ==",
        "X-Received": "by 2002:a05:6a00:1912:b0:7fb:f87d:a0aa with SMTP id\n d2e1a72fcca58-82c960a60demr12564625b3a.52.1774897526221;\n Mon, 30 Mar 2026 12:05:26 -0700 (PDT)",
        "From": "Takeru Hayasaka <hayatake396@gmail.com>",
        "Date": "Mon, 30 Mar 2026 19:04:42 +0000",
        "Subject": "[PATCH 2/3] migration/postcopy: Factor out uffd_setup_incoming()\n from postcopy setup",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "7bit",
        "Message-Id": "<20260330-fast-snapshot-refactor-v1-2-22143e70c467@gmail.com>",
        "References": "<20260330-fast-snapshot-refactor-v1-0-22143e70c467@gmail.com>",
        "In-Reply-To": "<20260330-fast-snapshot-refactor-v1-0-22143e70c467@gmail.com>",
        "To": "qemu-devel@nongnu.org",
        "Cc": "Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>,\n Takeru Hayasaka <hayatake396@gmail.com>",
        "X-Mailer": "b4 0.15.1",
        "Received-SPF": "pass client-ip=2607:f8b0:4864:20::435;\n envelope-from=hayatake396@gmail.com; helo=mail-pf1-x435.google.com",
        "X-Spam_score_int": "-12",
        "X-Spam_score": "-1.3",
        "X-Spam_bar": "-",
        "X-Spam_report": "(-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,\n URG_BIZ=0.573 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 <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": "Extract the generic userfaultfd initialization from\npostcopy_ram_incoming_setup() into a new uffd_setup_incoming() function\nthat can be shared between postcopy live migration and fast snapshot\nload.\n\nuffd_setup_incoming() handles:\n- Opening the userfaultfd and API handshake\n- Creating the eventfd for quit notification\n- Setting the page fault handler callback\n- Starting the fault handler thread\n- Registering all RAM blocks with UFFDIO_REGISTER\n- Allocating temporary page buffers for UFFDIO_COPY\n\npostcopy_ram_incoming_setup() becomes a thin wrapper that adds\npostcopy-specific logic: blocktime tracking and the preemption thread.\n\nAlso move the PostcopyPageHandler typedef from migration.h to\npostcopy-ram.h where it logically belongs and is needed for the\nuffd_setup_incoming() declaration.\n\nThe channels parameter of postcopy_temp_pages_setup() is now passed\nby the caller instead of being determined internally, so\nuffd_setup_incoming() callers can control how many temporary page\nbuffers are allocated.\n\nNo functional change for postcopy migration.\n\nSigned-off-by: Takeru Hayasaka <hayatake396@gmail.com>\n---\n migration/migration.h    | 11 --------\n migration/postcopy-ram.c | 66 +++++++++++++++++++++++++++++++++---------------\n migration/postcopy-ram.h | 27 ++++++++++++++++++++\n 3 files changed, 73 insertions(+), 31 deletions(-)",
    "diff": "diff --git a/migration/migration.h b/migration/migration.h\nindex 33525402922d..43ea32c07ba7 100644\n--- a/migration/migration.h\n+++ b/migration/migration.h\n@@ -89,17 +89,6 @@ typedef enum {\n     PREEMPT_THREAD_QUIT,\n } PreemptThreadStatus;\n \n-/*\n- * Callback to handle a page fault from the userfaultfd fault thread.\n- * Implementations resolve the fault by supplying the requested page,\n- * e.g., by requesting it from the migration source (postcopy) or by\n- * reading it from a snapshot file (fast snapshot load).\n- */\n-typedef int (*PostcopyPageHandler)(MigrationIncomingState *mis,\n-                                   RAMBlock *rb,\n-                                   ram_addr_t offset,\n-                                   void *fault_address);\n-\n /* State for the incoming migration */\n struct MigrationIncomingState {\n     QEMUFile *from_src_file;\ndiff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c\nindex 8dcd8ff35e85..7af207d6ead5 100644\n--- a/migration/postcopy-ram.c\n+++ b/migration/postcopy-ram.c\n@@ -1478,22 +1478,15 @@ retry:\n     return NULL;\n }\n \n-static int postcopy_temp_pages_setup(MigrationIncomingState *mis)\n+static int postcopy_temp_pages_setup(MigrationIncomingState *mis,\n+                                     unsigned int channels)\n {\n     PostcopyTmpPage *tmp_page;\n     int err;\n-    unsigned i, channels;\n+    unsigned i;\n     void *temp_page;\n \n-    if (migrate_postcopy_preempt()) {\n-        /* If preemption enabled, need extra channel for urgent requests */\n-        mis->postcopy_channels = RAM_CHANNEL_MAX;\n-    } else {\n-        /* Both precopy/postcopy on the same channel */\n-        mis->postcopy_channels = 1;\n-    }\n-\n-    channels = mis->postcopy_channels;\n+    mis->postcopy_channels = channels;\n     mis->postcopy_tmp_pages = g_new0(PostcopyTmpPage, channels);\n \n     for (i = 0; i < channels; i++) {\n@@ -1531,7 +1524,19 @@ static int postcopy_temp_pages_setup(MigrationIncomingState *mis)\n     return 0;\n }\n \n-int postcopy_ram_incoming_setup(MigrationIncomingState *mis)\n+/*\n+ * Generic userfaultfd setup for incoming migration.\n+ *\n+ * Opens the userfaultfd, performs the API handshake, registers all RAM\n+ * blocks for missing-page notifications, allocates temporary page buffers,\n+ * and starts the fault handler thread using the given callback.\n+ *\n+ * Both postcopy live migration and fast snapshot load use this function;\n+ * the caller supplies the appropriate page_fault_handler.\n+ */\n+int uffd_setup_incoming(MigrationIncomingState *mis,\n+                        PostcopyPageHandler handler,\n+                        unsigned int channels)\n {\n     Error *local_err = NULL;\n \n@@ -1549,15 +1554,11 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis)\n      */\n     if (!ufd_check_and_apply(mis->userfault_fd, mis, &local_err)) {\n         error_report_err(local_err);\n+        close(mis->userfault_fd);\n         return -1;\n     }\n \n-    if (migrate_postcopy_blocktime()) {\n-        assert(mis->blocktime_ctx == NULL);\n-        mis->blocktime_ctx = blocktime_context_new();\n-    }\n-\n-    /* Now an eventfd we use to tell the fault-thread to quit */\n+    /* An eventfd we use to tell the fault-thread to quit */\n     mis->userfault_event_fd = eventfd(0, EFD_CLOEXEC);\n     if (mis->userfault_event_fd == -1) {\n         error_report(\"%s: Opening userfault_event_fd: %s\", __func__,\n@@ -1566,7 +1567,7 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis)\n         return -1;\n     }\n \n-    mis->page_fault_handler = postcopy_page_fault_handler;\n+    mis->page_fault_handler = handler;\n \n     postcopy_thread_create(mis, &mis->fault_thread,\n                            MIGRATION_THREAD_DST_FAULT,\n@@ -1579,11 +1580,29 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis)\n         return -1;\n     }\n \n-    if (postcopy_temp_pages_setup(mis)) {\n+    if (postcopy_temp_pages_setup(mis, channels)) {\n         /* Error dumped in the sub-function */\n         return -1;\n     }\n \n+    return 0;\n+}\n+\n+int postcopy_ram_incoming_setup(MigrationIncomingState *mis)\n+{\n+    unsigned int channels;\n+\n+    if (migrate_postcopy_blocktime()) {\n+        assert(mis->blocktime_ctx == NULL);\n+        mis->blocktime_ctx = blocktime_context_new();\n+    }\n+\n+    channels = migrate_postcopy_preempt() ? RAM_CHANNEL_MAX : 1;\n+\n+    if (uffd_setup_incoming(mis, postcopy_page_fault_handler, channels)) {\n+        return -1;\n+    }\n+\n     if (migrate_postcopy_preempt()) {\n         /*\n          * This thread needs to be created after the temp pages because\n@@ -1745,6 +1764,13 @@ int postcopy_request_shared_page(struct PostCopyFD *pcfd, RAMBlock *rb,\n     g_assert_not_reached();\n }\n \n+int uffd_setup_incoming(MigrationIncomingState *mis,\n+                        PostcopyPageHandler handler,\n+                        unsigned int channels)\n+{\n+    g_assert_not_reached();\n+}\n+\n int postcopy_ram_incoming_setup(MigrationIncomingState *mis)\n {\n     g_assert_not_reached();\ndiff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h\nindex a080dd65a77a..3bbd1ed7e323 100644\n--- a/migration/postcopy-ram.h\n+++ b/migration/postcopy-ram.h\n@@ -15,10 +15,37 @@\n \n #include \"qapi/qapi-types-migration.h\"\n \n+/*\n+ * Callback to handle a page fault from the userfaultfd fault thread.\n+ * Implementations resolve the fault by supplying the requested page,\n+ * e.g., by requesting it from the migration source (postcopy) or by\n+ * reading it from a snapshot file (fast snapshot load).\n+ */\n+typedef int (*PostcopyPageHandler)(MigrationIncomingState *mis,\n+                                   RAMBlock *rb,\n+                                   ram_addr_t offset,\n+                                   void *fault_address);\n+\n /* Return true if the host supports everything we need to do postcopy-ram */\n bool postcopy_ram_supported_by_host(MigrationIncomingState *mis,\n                                     Error **errp);\n \n+/*\n+ * Generic userfaultfd setup for incoming migration.\n+ *\n+ * Opens userfaultfd, registers all RAM blocks, allocates temporary\n+ * page buffers and starts the fault handler thread.  The caller\n+ * supplies the page_fault_handler callback appropriate for the use\n+ * case (postcopy live migration or fast snapshot load).\n+ *\n+ * @channels: number of temporary page channels to allocate\n+ *            (1 for most cases, RAM_CHANNEL_MAX when postcopy preempt\n+ *            is enabled).\n+ */\n+int uffd_setup_incoming(MigrationIncomingState *mis,\n+                        PostcopyPageHandler handler,\n+                        unsigned int channels);\n+\n /*\n  * Make all of RAM sensitive to accesses to areas that haven't yet been written\n  * and wire up anything necessary to deal with it.\n",
    "prefixes": [
        "2/3"
    ]
}