From nobody Fri May 3 06:48:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1563115917; cv=none; d=zoho.com; s=zohoarc; b=Q8KF7qwPTTfnaMcrTsGyd7Z9zk3AWRAFNOY7teuT1NWNXVf5DdExwZMHOwT/Tk9pSjHCHO1+pcqIjsknjxFCIIbf6MBKwp3RyuefuAoAoW5SuT2mrVN2FaG7/WRm6pxzhwQXEgHq4otIzk2yeRC0yVkhH9y0T4By/xcCAcLY9s4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563115917; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=wbXQ0ReYPaw6cL6QJZRR5dXQ3MmUpeCBsUBi8cnTKK4=; b=I7GhYHaHUDg3C+vSDGkccsIQrsz9RCJxfCGMOXQC+WpOTVh87sk6PUvJjP69s/oLHXzrOB2TY2XnQCDlA6SnBD2y/ji2kOkWCn+QXFVCjyxfOEBCIaNlXBJOJUuANxFGOeAOkugIwA4Q85fa5AtvoYRnLj/u9A49hSfh5dgTdNw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563115917075240.21822028216593; Sun, 14 Jul 2019 07:51:57 -0700 (PDT) Received: from localhost ([::1]:60902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmfqp-0002XZ-E8 for importer@patchew.org; Sun, 14 Jul 2019 10:51:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54879) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmfqf-00027B-22 for qemu-devel@nongnu.org; Sun, 14 Jul 2019 10:51:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hmfqd-0002QO-7o for qemu-devel@nongnu.org; Sun, 14 Jul 2019 10:51:33 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:40063) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hmfqc-0002PN-N7 for qemu-devel@nongnu.org; Sun, 14 Jul 2019 10:51:31 -0400 Received: by mail-pg1-x544.google.com with SMTP id w10so6526736pgj.7 for ; Sun, 14 Jul 2019 07:51:29 -0700 (PDT) Received: from VM_0_37_centos.localdomain ([129.226.63.251]) by smtp.gmail.com with ESMTPSA id v27sm17216403pgn.76.2019.07.14.07.51.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Jul 2019 07:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=wbXQ0ReYPaw6cL6QJZRR5dXQ3MmUpeCBsUBi8cnTKK4=; b=hkJgUmfoOZgPYcH7+LK7ptvnEHS1PsZDXBsP99P5OGlyL8ihIRz7gWDHmjLQc9ST5y m1pCC2/aNfY9SPM5BLEshpYlkocMezI3INw6ow++WE3y087m02UbplFMY/R1Ft8yHSfG 0XCeyvwujaWLNejQ+/k+ReivbXCG2cYIf3AgIYYR0RTDN3Nm3yQ9EMjFkb7iZ5Nt+Xw9 toqPvnPokWnjEe8o/zSofGVAHOfIIUgVZLkms9j10pKgXGK2aAVGFiV6V32Lb2KWIbNR mmO36LcRTfF/tEQGsLq4U5CbBXAeC5T0ZhbyqorHCC+bT5TWoOsWq2T4JITnrMXledr+ KQgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=wbXQ0ReYPaw6cL6QJZRR5dXQ3MmUpeCBsUBi8cnTKK4=; b=AHyrtp3PJ0q8/HkgH1mJwHB4SoT27MvHKNu41+lKu0P9EkkmquckGBUTkQaFeIKpYW 79xnjKyOC9X4PI7U8IZsvAqWA0SHJ5LuXD9GbWuWkPXItY5A6vgPBD65YUD8LmvWarX5 4NiJ8vqQ1c+2aWYCaW08vmoFR1p2RWTTXZLoYOoRCSw7ckn0eVGExEyTq8KFq0NtKpln CXg6VrKyHtOcca6rDJa4btclnlZPPMwMT7V5k+mGippvIJ2amoRD0Mg+dLEp+Y4FqLQF UtdpEYZ+CJSSv9IWMA7qtw6KzPG60e6VQcKHCKFKqFrPRojKXD4JVnZ4vPxwblXOjIiV ia0A== X-Gm-Message-State: APjAAAV7jADwmhzuH9sBkDWqPj4AI2ggflTng9Jj6MbHKFe6UZtlMhXK ip/l3/xSr94qdoZKggIMkTo= X-Google-Smtp-Source: APXvYqxTw3eb2T9JLQtf/eG+qAGDvLG2WJzYznDn9E8KErEJPR0vMzbqk1CQZum9UksXGV9nLQ3dPg== X-Received: by 2002:a17:90a:7d04:: with SMTP id g4mr24128726pjl.41.1563115888138; Sun, 14 Jul 2019 07:51:28 -0700 (PDT) From: Ivan Ren X-Google-Original-From: Ivan Ren To: quintela@redhat.com, dgilbert@redhat.com Date: Sun, 14 Jul 2019 22:51:19 +0800 Message-Id: <1563115879-2715-1-git-send-email-ivanren@tencent.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH] migration: always initial RAMBlock.bmap to 1 for new migration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Reproduce the problem: migrate migrate_cancel migrate Error happen for memory migration The reason as follows: 1. qemu start, ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] all set to 1 by a series of cpu_physical_memory_set_dirty_range 2. migration start:ram_init_bitmaps - memory_global_dirty_log_start: begin log diry - memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] - migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero 3. migration data... 4. migrate_cancel, will stop log dirty 5. migration start:ram_init_bitmaps - memory_global_dirty_log_start: begin log diry - memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] - migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero Here RAMBlock.bmap only have new logged dirty pages, don't contain the whole guest pages. Signed-off-by: Ivan Ren Reviewed-by: Peter Xu Reviewed-by: Wei Yang --- migration/ram.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 908517fc2b..bbebaee0c1 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3173,11 +3173,11 @@ static int ram_state_init(RAMState **rsp) QSIMPLEQ_INIT(&(*rsp)->src_page_requests); =20 /* + * Count the total number of pages used by ram blocks not including any + * gaps due to alignment or unplugs. * This must match with the initial values of dirty bitmap. - * Currently we initialize the dirty bitmap to all zeros so - * here the total dirty page count is zero. */ - (*rsp)->migration_dirty_pages =3D 0; + (*rsp)->migration_dirty_pages =3D ram_bytes_total() >> TARGET_PAGE_BIT= S; ram_state_reset(*rsp); =20 return 0; @@ -3196,12 +3196,13 @@ static void ram_list_init_bitmaps(void) * The initial dirty bitmap for migration must be set with all * ones to make sure we'll migrate every guest RAM page to * destination. - * Here we didn't set RAMBlock.bmap simply because it is alrea= dy - * set in ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] in - * ram_block_add, and that's where we'll sync the dirty bitmap= s. - * Here setting RAMBlock.bmap would be fine too but not necess= ary. + * Here we set RAMBlock.bmap all to 1 because when rebegin a + * new migration after a failed migration, ram_list. + * dirty_memory[DIRTY_MEMORY_MIGRATION] don't include the whole + * guest memory. */ block->bmap =3D bitmap_new(pages); + bitmap_set(block->bmap, 0, pages); if (migrate_postcopy_ram()) { block->unsentmap =3D bitmap_new(pages); bitmap_set(block->unsentmap, 0, pages); --=20 2.17.2 (Apple Git-113)