From patchwork Sun Jul 14 14:51:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Ren X-Patchwork-Id: 1131737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hkJgUmfo"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45mqPB6Qfzz9sNC for ; Mon, 15 Jul 2019 00:51:41 +1000 (AEST) Received: from localhost ([::1]:60900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmfqk-00027I-8i for incoming@patchwork.ozlabs.org; Sun, 14 Jul 2019 10:51:38 -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) 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) 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) 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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); /* + * 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 = 0; + (*rsp)->migration_dirty_pages = ram_bytes_total() >> TARGET_PAGE_BITS; ram_state_reset(*rsp); 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 already - * set in ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] in - * ram_block_add, and that's where we'll sync the dirty bitmaps. - * Here setting RAMBlock.bmap would be fine too but not necessary. + * 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 = bitmap_new(pages); + bitmap_set(block->bmap, 0, pages); if (migrate_postcopy_ram()) { block->unsentmap = bitmap_new(pages); bitmap_set(block->unsentmap, 0, pages);