From nobody Sat Nov 29 10:15:35 2025 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1764172071; cv=none; d=zohomail.com; s=zohoarc; b=LIJ5vyR1peFsbk1V4+LLGsox/N8yG19sUQsVifQ70Ymp2pTigpk4zGcq9HSppWs6Ykq3NB7+o9x1exGiWnUIUwmcoLiTkze4v1wFhO5T49G99RtJ1vCOYYxAfM7w67aIysgHX+vfM5P6JkyMSU9rc7cHNsUZqIfVzfVdQcgNDs0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764172071; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From: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=qLca+SjWpTyHxDEhKAsHhI0VNOBtyR6cwHKmxcrWQyI=; b=RjBOzcZvoRtEgWiAH1PJVgTqktGiWwnY5NMwEwgEJlevPjf93apMKymdsHySLWJcCAZJAxph+V0HnpZyQyZ/xg2eJZ1/vs7hQykC03dbjtX004LJSpOZiZ7++sgcSEeVmtWLr8Csc1MDn3JoMOW2ZFroVO8NgBUOyz4b8Ks7pdo= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764172071283343.38150315824885; Wed, 26 Nov 2025 07:47:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOHkC-0002Lj-OZ; Wed, 26 Nov 2025 10:47:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vOHk4-00024z-Og for qemu-devel@nongnu.org; Wed, 26 Nov 2025 10:47:40 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vOHk2-00089W-7T for qemu-devel@nongnu.org; Wed, 26 Nov 2025 10:47:39 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-47789cd2083so40653715e9.2 for ; Wed, 26 Nov 2025 07:47:37 -0800 (PST) Received: from localhost ([109.76.183.78]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-479052daee3sm43234345e9.12.2025.11.26.07.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 07:47:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764172056; x=1764776856; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qLca+SjWpTyHxDEhKAsHhI0VNOBtyR6cwHKmxcrWQyI=; b=gIyrDyle/XnHuowiopHvylFiAbR1ZfWbjZU1HGJaPZcCCsi8edS1G3ZIK5kXXaxC3w eC34ALvgAxdYn8aDoe6vufgWArWzfQFj6+jdzXzfk4CXUPO3WK4jgZWAKRwzzNTt29ho Vi4o1+C491gOyIgK0RaqYsJCmTKuwosXZtgU1Pp9VN10Q2ZZrDwVq+WmpkCGY8x3bWl+ EEULd/pnl0RCTGBaVEI0JX5kM18Q4mqgARH0DSToh2fzB5JIrmCuw9SPqJ7iZ2lrWpHU en7oMS9K8aSKB9pkORkJhmvgIDMk4KvuPlDg/QHfvIK40ZLJdlau8xSUEZyzhF+NAXQf Sz1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764172056; x=1764776856; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qLca+SjWpTyHxDEhKAsHhI0VNOBtyR6cwHKmxcrWQyI=; b=WzE/Ak0j/CNivBhoV7y5a0VoQUey1hbbN4IIW9mWOwrAhvRsqRtTfpxJxYDQzr8QGh z0xBbbhY4/8/h77Xe4PQGVxQniMi+GK+ym6osDzMxpY6cC8zsG1Cy6l0ilDLzoGxg99n 3ZvYFjVQGo2JGj+9se1OH2MoCRyL2L5JFBfHKK4RC7BA4I5rRBVILeiFnQLCVEkGyREE KZPrZConzWCf6fLBh53zc4Ok4snfNbB3qQ/cHzestW7rBEXkBHKBgvFAGojvI++l0wF/ r6h6yHrVmse2svLbNlDjkCzKBLgX92V2p2eCkPuXKnzoF3OziI3iOsftdgVXIRxrINDn atZA== X-Gm-Message-State: AOJu0Yw8RX6Oa3NWwM4GSjYgyOtRBxjL1Q2j+sOaCnC3Xhn4ahIfxq2z 1i/cMCQxx3zKEbLlLBdTFpFlaGu3TZ4uMWzCqdOskIRGoBRLnTs2cPSBB9DnxZEPlrc= X-Gm-Gg: ASbGncvxcBjmMRCdkhDp9FApAl9hrcxXhQO2wTpjpT20q25LQXD9XZPZYtlhUelCt7E ZLfuYCZN2hi1dSEXp5XrE1XMc3wFME/uVZLkg6epBAS2xKsNAttPsv2SADxM91dq5ISBtzm6LF1 83bSn3xdFKV9CmAL4S39mv8u6TFka1jtkJRMhuE6DyhJd7gRXrpRG3Cz6CqUtpVxyysA/wvsZ9U Oxnt8wPVRFfqE6za1ymMAn+sfbozGvsGi5zZC5ZhnEEqA+ShAftRM1ik940cgZAcFkB4yxQJEJb F9xgmAhhZu2sGmrj5kQ4ibo0jWEj9vJmW4HYLQbq6r2QDDxozQMXnzHvCn8zv9hup9TrRP8+PJC +qkfdXz5baiYwvIR/YOUtXlu2UQ0AhTiv1Or4OnrNXYYWwhDQWVB3tpikEy9RexZrF1bxP5Zjoe diihD1Ims= X-Google-Smtp-Source: AGHT+IHcS17YkmaeovVgvpVmEo9rL2qNdsYed+BczwsYBIKtRaphi6psCwEpaVfW30U/+7rxWgBEbw== X-Received: by 2002:a05:600c:19ca:b0:477:a978:3a7b with SMTP id 5b1f17b1804b1-477c1143073mr189621965e9.22.1764172055872; Wed, 26 Nov 2025 07:47:35 -0800 (PST) From: Pawel Zmarzly To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de Subject: [PATCH] migration: Fix writing mapped_ram + ignore_shared snapshots Date: Wed, 26 Nov 2025 15:47:34 +0000 Message-ID: <20251126154734.940066-1-pzmarzly0@gmail.com> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=pzmarzly0@gmail.com; helo=mail-wm1-x32d.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: 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 @gmail.com) X-ZM-MESSAGEID: 1764172072845019200 Content-Type: text/plain; charset="utf-8" Currently if you set these flags and have any shared memory object, saving a snapshot will fail with: Failed to write bitmap to file: Unable to write to file: Bad address We need to skip writing RAMBlocks that are backed by shared objects. Also, we should mark these RAMBlocks as skipped, so the snapshot format sta= ys readable to tools that later don't know QEMU's command line (for example scripts/analyze-migration.py). I used bitmap_offset=3D0 pages_offset=3D0 fo= r this. This minor change to snapshot format should be safe, as offset=3D0 should n= ot have ever been possible. Signed-off-by: Pawel Zmarzly --- This requires my previous patch "migration: fix parsing snapshots with x-ignore-shared flag". To make things easier, you can see the stack at https://gitlab.com/pzmarzly/qemu/-/commits/pzmarzly?ref_type=3Dheads --- migration/ram.c | 51 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 7d024b88b5..8063522a14 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3042,28 +3042,36 @@ static void mapped_ram_setup_ramblock(QEMUFile *fil= e, RAMBlock *block) header =3D g_new0(MappedRamHeader, 1); header_size =3D sizeof(MappedRamHeader); =20 - num_pages =3D block->used_length >> TARGET_PAGE_BITS; - bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(unsigned long); - - /* - * Save the file offsets of where the bitmap and the pages should - * go as they are written at the end of migration and during the - * iterative phase, respectively. - */ - block->bitmap_offset =3D qemu_get_offset(file) + header_size; - block->pages_offset =3D ROUND_UP(block->bitmap_offset + - bitmap_size, - MAPPED_RAM_FILE_OFFSET_ALIGNMENT); - header->version =3D cpu_to_be32(MAPPED_RAM_HDR_VERSION); header->page_size =3D cpu_to_be64(TARGET_PAGE_SIZE); - header->bitmap_offset =3D cpu_to_be64(block->bitmap_offset); - header->pages_offset =3D cpu_to_be64(block->pages_offset); + + if (migrate_ram_is_ignored(block)) { + header->bitmap_offset =3D 0; + header->pages_offset =3D 0; + } else { + num_pages =3D block->used_length >> TARGET_PAGE_BITS; + bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(unsigned long); + + /* + * Save the file offsets of where the bitmap and the pages should + * go as they are written at the end of migration and during the + * iterative phase, respectively. + */ + block->bitmap_offset =3D qemu_get_offset(file) + header_size; + block->pages_offset =3D ROUND_UP(block->bitmap_offset + + bitmap_size, + MAPPED_RAM_FILE_OFFSET_ALIGNMENT); + + header->bitmap_offset =3D cpu_to_be64(block->bitmap_offset); + header->pages_offset =3D cpu_to_be64(block->pages_offset); + } =20 qemu_put_buffer(file, (uint8_t *) header, header_size); =20 - /* prepare offset for next ramblock */ - qemu_set_offset(file, block->pages_offset + block->used_length, SEEK_S= ET); + if (!migrate_ram_is_ignored(block)) { + /* leave space for block data */ + qemu_set_offset(file, block->pages_offset + block->used_length, SE= EK_SET); + } } =20 static bool mapped_ram_read_header(QEMUFile *file, MappedRamHeader *header, @@ -3146,7 +3154,6 @@ static int ram_save_setup(QEMUFile *f, void *opaque, = Error **errp) if (migrate_ignore_shared()) { qemu_put_be64(f, block->mr->addr); } - if (migrate_mapped_ram()) { mapped_ram_setup_ramblock(f, block); } @@ -3217,6 +3224,10 @@ static void ram_save_file_bmap(QEMUFile *f) RAMBlock *block; =20 RAMBLOCK_FOREACH_MIGRATABLE(block) { + if (migrate_ram_is_ignored(block)) { + continue; + } + long num_pages =3D block->used_length >> TARGET_PAGE_BITS; long bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(unsigned lo= ng); =20 @@ -4162,6 +4173,10 @@ static void parse_ramblock_mapped_ram(QEMUFile *f, R= AMBlock *block, return; } =20 + if (migrate_ignore_shared() && header.bitmap_offset =3D=3D 0 && header= .pages_offset =3D=3D 0) { + return; + } + block->pages_offset =3D header.pages_offset; =20 /* --=20 2.52.0