From patchwork Tue Apr 28 19:42:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 283848 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9E24C83000 for ; Tue, 28 Apr 2020 19:44:26 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7418F20BED for ; Tue, 28 Apr 2020 19:44:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ILMdzVFb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7418F20BED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTW9Z-0007xG-J4 for qemu-devel@archiver.kernel.org; Tue, 28 Apr 2020 15:44:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33404) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTW7Z-0005dv-Lr for qemu-devel@nongnu.org; Tue, 28 Apr 2020 15:42:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTW7Y-0006sg-NA for qemu-devel@nongnu.org; Tue, 28 Apr 2020 15:42:21 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:25344 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jTW7Y-0006sC-8L for qemu-devel@nongnu.org; Tue, 28 Apr 2020 15:42:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588102939; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EZznPfOzrDLzLrIvwsRJ50QCk3D2FtsvBi3yPYnpJWI=; b=ILMdzVFbFFz1tLAYcZUu9YutdrmOKB+irlamkvpJrhZK1F8jfKNmCrCDZaN9rtuA36zGyh EYFfAjYs7KvSM1ASgmqpBnsYg9JUpk/sURGeLYtBKPdUWkVhhfB8c+LeHJ3vKMOOpp5mLL msmueoy1v6krk85XGShNHq4rK9AV6Ok= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-397-1atRpVX6P_a6HtK8DEG1bw-1; Tue, 28 Apr 2020 15:42:17 -0400 X-MC-Unique: 1atRpVX6P_a6HtK8DEG1bw-1 Received: by mail-qk1-f197.google.com with SMTP id a187so24442856qkg.18 for ; Tue, 28 Apr 2020 12:42:17 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=j8HZaXRpKqMlGVGZxC3vqXUpalYaLscomhn30S95wLk=; b=P/1s0lFUkr8CoxNx0Y6L99jAeN90VrGhSwcdE3zLTyIlUaPZwM8YqL6AokuBtf/8FP Tm8CldPLAnsTeMNbLWqmbn+AGb/ILXddVKLcQq/qOS6BG7lBk8N+GqjMrAO68nA4PWLW HS9bqPS1L55UqZ4Nmz+w7vLMDyGJYB16tN2cg1k2U7pCHZqTS7w5nuTWqcMaYzEFmBIx HMCslOHE0m7yNEbR4OsTyukl+Kq4oBGZ9KDG7rt6Emx5+S+0Y7YAqb7qJU1negGK5Bv1 CZirs9IaVYujEAVa14l8QHiqRE7eyh1giue3R10jW9uTUxglo70N5Byz8HIhRm5IQgeJ xFdQ== X-Gm-Message-State: AGi0PuZ9/GmiSm/qhJxKdI95jvu2HNlTvDdXa0UaYwZHUPsIL4zVNUVy mxd9uV7ZS1/sqCZvzgC8Gd4cQr937ho8hf5mHL28jKUR3qk6+4aygQoNRkomizwV3KRG4ymk0ct 2t0ti3WMI6oggKOw= X-Received: by 2002:a37:6191:: with SMTP id v139mr26818554qkb.469.1588102937155; Tue, 28 Apr 2020 12:42:17 -0700 (PDT) X-Google-Smtp-Source: APiQypI/1TuGLJnOpmLJPszo7iUOvTCnD2YASytQt0QUljLXX9AwU7HLc9zbNuiEIxKXBh/R6yzZRQ== X-Received: by 2002:a37:6191:: with SMTP id v139mr26818522qkb.469.1588102936904; Tue, 28 Apr 2020 12:42:16 -0700 (PDT) Received: from xz-x1.hitronhub.home ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id j92sm14275237qtd.58.2020.04.28.12.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 12:42:16 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH RFC 1/4] migration: Export migration_bitmap_sync_precopy() Date: Tue, 28 Apr 2020 15:42:16 -0400 Message-Id: <20200428194219.10963-2-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200428194219.10963-1-peterx@redhat.com> References: <20200428194219.10963-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.120; envelope-from=peterx@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/28 04:15:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: Paolo Bonzini , Tian Kevin , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Make it usable outside migration. To make it easier to use, remove the RAMState parameter since after all ram.c has the reference of ram_state directly from its context. Signed-off-by: Peter Xu --- include/migration/misc.h | 1 + migration/ram.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index d2762257aa..e338be8c30 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -66,6 +66,7 @@ void remove_migration_state_change_notifier(Notifier *notify); bool migration_in_setup(MigrationState *); bool migration_has_finished(MigrationState *); bool migration_has_failed(MigrationState *); +void migration_bitmap_sync_precopy(void); /* ...and after the device transmission */ bool migration_in_postcopy_after_devices(MigrationState *); void migration_global_dump(Monitor *mon); diff --git a/migration/ram.c b/migration/ram.c index 04f13feb2e..d737175d4e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -970,7 +970,7 @@ static void migration_bitmap_sync(RAMState *rs) } } -static void migration_bitmap_sync_precopy(RAMState *rs) +void migration_bitmap_sync_precopy(void) { Error *local_err = NULL; @@ -983,7 +983,7 @@ static void migration_bitmap_sync_precopy(RAMState *rs) local_err = NULL; } - migration_bitmap_sync(rs); + migration_bitmap_sync(ram_state); if (precopy_notify(PRECOPY_NOTIFY_AFTER_BITMAP_SYNC, &local_err)) { error_report_err(local_err); @@ -2303,7 +2303,7 @@ static void ram_init_bitmaps(RAMState *rs) WITH_RCU_READ_LOCK_GUARD() { ram_list_init_bitmaps(); memory_global_dirty_log_start(); - migration_bitmap_sync_precopy(rs); + migration_bitmap_sync_precopy(); } qemu_mutex_unlock_ramlist(); qemu_mutex_unlock_iothread(); @@ -2592,7 +2592,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque) WITH_RCU_READ_LOCK_GUARD() { if (!migration_in_postcopy()) { - migration_bitmap_sync_precopy(rs); + migration_bitmap_sync_precopy(); } ram_control_before_iterate(f, RAM_CONTROL_FINISH); @@ -2642,7 +2642,7 @@ static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size, remaining_size < max_size) { qemu_mutex_lock_iothread(); WITH_RCU_READ_LOCK_GUARD() { - migration_bitmap_sync_precopy(rs); + migration_bitmap_sync_precopy(); } qemu_mutex_unlock_iothread(); remaining_size = rs->migration_dirty_pages * TARGET_PAGE_SIZE; From patchwork Tue Apr 28 19:42:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 283847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B18EEC83000 for ; Tue, 28 Apr 2020 19:45:52 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7BBE721973 for ; Tue, 28 Apr 2020 19:45:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="J2iPg9/G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BBE721973 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTWAx-0002cy-GU for qemu-devel@archiver.kernel.org; Tue, 28 Apr 2020 15:45:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33418) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTW7h-0005iI-Qo for qemu-devel@nongnu.org; Tue, 28 Apr 2020 15:42:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTW7f-0006uj-EJ for qemu-devel@nongnu.org; Tue, 28 Apr 2020 15:42:29 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:20295 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jTW7d-0006tS-UZ for qemu-devel@nongnu.org; Tue, 28 Apr 2020 15:42:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588102944; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zuy1iMRmPIFo+AO2BN7flgYL2QbOrH67o5VmfdIqjvI=; b=J2iPg9/GUxavurcDRu0bV2BjJyG7MsC4/QM+H2xZUhdX/vTkaoJCRgX+SbgRXlPR5lUcpF 5FX+aCKZmJRS5ICq3rJIZ6Vowzy7fIb0c2Ebx8KunKKvPd74kKRcf/nRIXaQlgdQ5hODY2 YGZhzwQyW7uH7JF81jd99diz98pMkw0= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-188-sBZsa508OdOebFTOawZ95A-1; Tue, 28 Apr 2020 15:42:20 -0400 X-MC-Unique: sBZsa508OdOebFTOawZ95A-1 Received: by mail-qk1-f199.google.com with SMTP id 11so19519638qkh.7 for ; Tue, 28 Apr 2020 12:42:20 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=xuRNcZqOedqLdZtDlBrMErqG8jwgO5FGr6fT7gMV6U0=; b=YHuVoaLTCMGqG2MCbTxQGdxbA2QWRaRWeM5cdoKZgej1N/3DRYmK/J6PRNjDOb2UBs KMh/d/dRq5+vWjL6NZnKbR6cn57ubs9DUCDNrVMhwBToRABNTIqzkKYCLDgUuK5ZdjmB Q+wnIVsMsLpc7ill6Ykuagnuz6/hhpb4kUm9Jir46DzbqXLHsrANFQSmMYu8x5ZnU+oL C3ph208y1wsCgwXLGKFS0+kiw+1jKEDzRVzeTSyIR8rtmiQzPGDgZtfZQur5M/Ecu7MN /CziczpI+zb+4pLAdttXdcKiF1NSm39zzMGRjnoknzDxGkaZxLAbONYjFL9ha1512LNQ 9biw== X-Gm-Message-State: AGi0PubN7ORVDKc+xM6CORx6mhZ4fEy38zw4zVz8FhWcn3SFcrMNJr2Z B/bzxDf4mWpA35xWPNOeMHewWESM5TjToRP+VJvu+3rpi0uIcTkUd63dA5Aju0Af8xHAdaf5ZCl l/VRLVCJk5XizdYs= X-Received: by 2002:a37:5744:: with SMTP id l65mr30286835qkb.470.1588102940202; Tue, 28 Apr 2020 12:42:20 -0700 (PDT) X-Google-Smtp-Source: APiQypIVpkZMo/e+bCoONrLDgj6/d0/g5VJRBmytw7HmuYUyErWUzOP1kxPmZccdIYlgsoQ4CHxigA== X-Received: by 2002:a37:5744:: with SMTP id l65mr30286816qkb.470.1588102939983; Tue, 28 Apr 2020 12:42:19 -0700 (PDT) Received: from xz-x1.hitronhub.home ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id n92sm14133460qtd.68.2020.04.28.12.42.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 12:42:19 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH RFC 2/4] migration: Introduce migrate_is_precopy() Date: Tue, 28 Apr 2020 15:42:17 -0400 Message-Id: <20200428194219.10963-3-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200428194219.10963-1-peterx@redhat.com> References: <20200428194219.10963-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=peterx@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/28 02:16:38 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: Paolo Bonzini , Tian Kevin , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Export a helper globally to check whether we're during a precopy. Signed-off-by: Peter Xu --- include/migration/misc.h | 1 + migration/migration.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/migration/misc.h b/include/migration/misc.h index e338be8c30..b4f6bf7842 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -61,6 +61,7 @@ void migration_shutdown(void); void qemu_start_incoming_migration(const char *uri, Error **errp); bool migration_is_idle(void); bool migration_is_active(MigrationState *); +bool migration_is_precopy(void); void add_migration_state_change_notifier(Notifier *notify); void remove_migration_state_change_notifier(Notifier *notify); bool migration_in_setup(MigrationState *); diff --git a/migration/migration.c b/migration/migration.c index 187ac0410c..0082880279 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1795,6 +1795,13 @@ bool migration_is_active(MigrationState *s) s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE); } +bool migration_is_precopy(void) +{ + MigrationState *s = migrate_get_current(); + + return s && s->state == MIGRATION_STATUS_ACTIVE; +} + void migrate_init(MigrationState *s) { /* From patchwork Tue Apr 28 19:42:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 283846 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B530FC83000 for ; Tue, 28 Apr 2020 19:47:24 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7BAF021707 for ; Tue, 28 Apr 2020 19:47:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ENWQ1YNj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BAF021707 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTWCR-0005F0-J8 for qemu-devel@archiver.kernel.org; Tue, 28 Apr 2020 15:47:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33538) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTW8j-0006oQ-Ru for qemu-devel@nongnu.org; Tue, 28 Apr 2020 15:43:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTW8j-0007Az-B5 for qemu-devel@nongnu.org; Tue, 28 Apr 2020 15:43:33 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:60502 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jTW8i-0007As-U6 for qemu-devel@nongnu.org; Tue, 28 Apr 2020 15:43:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588103012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KWiKFx7T2RcB/8ceBskFUXxef1SdqAE1qyzvy2ePBgA=; b=ENWQ1YNj7MKl5cZEgDr/nWcvcNvYC2Irz/cJo/cnGh48/dzvz/6PNRpkFX2fq3l36fsKCd gR+ASMUxPgGGtE9sITGmgBP4Ea0zWAVJ+Ilv0iaDB+3O1XJFnLwVZ0wejFAydhcvaaoKMJ 0HiN087C7n+7H/yhxI+LGSqbvrlhZkk= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-46-JJO1Meg_PVamgTTddoM4Jw-1; Tue, 28 Apr 2020 15:43:30 -0400 X-MC-Unique: JJO1Meg_PVamgTTddoM4Jw-1 Received: by mail-qk1-f199.google.com with SMTP id x7so24473666qkb.17 for ; Tue, 28 Apr 2020 12:43:30 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=l9EJm6lx5UW6V7ifVpZVbM1fIyRcFIsgTY1TmlPa2ZA=; b=ctzr3aAYnaHspEN9egXmCb0OnnMEDNulfetynhWa2+qwuAj0MlJBoqZfZKrRSULDtc 7fr3CPBA/73aMqMhuvTlxWygPxASTHW+vqS/tZ3qi5mD8evZi9G/U91+v4pBiLBhwr8y qEpoYN5iG4WUCDjhw3V/mHQp70+jAZkWn4OZHJSs70MGOSRY4+hV8aFpLOAhCO4Z9gI0 rBFIA2UNqEMTkVwvvz7U6cWi51w3ti9WLhCHfQBqfafpWRnnhI8i3pZCPIE0egFvyjo5 4qddADPy7ACTHyWa2B0YqN/T34RadRTpH3xn8iML+1fMcenTQ/cYYhFg+CL4dyxEYFee tG/w== X-Gm-Message-State: AGi0PuYpn1ceUozznh/yItp4clEGVY2N6Dbds8xkRQfA2fGyuRShLYiB bzci/eeOvSyYHaqwA9N2EocJg1lxjruL1euG824e1XE/GHJu+uXMz6DaauRI//+egzGy//xeTYp UJspzN8FpLHNNYvk= X-Received: by 2002:a37:a090:: with SMTP id j138mr29953692qke.168.1588103009498; Tue, 28 Apr 2020 12:43:29 -0700 (PDT) X-Google-Smtp-Source: APiQypLpD/bS2J5EyCoFE9zrsM73H3G52b3w5H7U4t7mnMuvlwvlpzdkMhqq9+flZsofYaZSH6H5qQ== X-Received: by 2002:a37:a090:: with SMTP id j138mr29953508qke.168.1588103006960; Tue, 28 Apr 2020 12:43:26 -0700 (PDT) Received: from xz-x1.hitronhub.home ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id j92sm14277695qtd.58.2020.04.28.12.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 12:43:26 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH RFC 3/4] vl: Sync dirty bits for system resets during precopy Date: Tue, 28 Apr 2020 15:42:18 -0400 Message-Id: <20200428194219.10963-4-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200428194219.10963-1-peterx@redhat.com> References: <20200428194219.10963-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=peterx@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/28 02:16:38 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: Paolo Bonzini , Tian Kevin , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" System resets will also reset system memory layout. Although the memory layout after the reset should probably the same as before the reset, we still need to do frequent memory section removals and additions during the reset process. Those operations could accidentally lose per-mem-section information like KVM memslot dirty bitmaps. Previously we keep those dirty bitmaps by sync it during memory removal. However that's hard to make it right after all [1]. Instead, we sync dirty pages before system reset if we know we're during a precopy migration. This should solve the same problem explicitly. [1] https://lore.kernel.org/qemu-devel/20200327150425.GJ422390@xz-x1/ Signed-off-by: Peter Xu --- softmmu/vl.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/softmmu/vl.c b/softmmu/vl.c index 32c0047889..8f864fee43 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1387,6 +1387,22 @@ void qemu_system_reset(ShutdownCause reason) cpu_synchronize_all_states(); + /* + * System reboot could reset memory layout. Although the final status of + * the memory layout should be the same as before the reset, the memory + * sections can still be removed and added back frequently due to the reset + * process. This could potentially drop dirty bits in track for those + * memory sections before the reset. + * + * Do a global dirty sync before the reset happens if we are during a + * precopy, so we don't lose the dirty bits during the memory shuffles. + */ + if (migration_is_precopy()) { + WITH_RCU_READ_LOCK_GUARD() { + migration_bitmap_sync_precopy(); + } + } + if (mc && mc->reset) { mc->reset(current_machine); } else {