Received: by 2002:a17:906:4810:b0:965:a47e:1721 with SMTP id w16csp2433185ejq; Mon, 8 May 2023 19:22:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4dM2alqRYs8dr288riNUgZ+svE32Z3WVTDq7iYhU0Sh0DWJpd4ddmcs+dij7cg+LDiua/t X-Received: by 2002:a05:6214:4116:b0:5ef:67b9:8d37 with SMTP id kc22-20020a056214411600b005ef67b98d37mr14973338qvb.13.1683598967070; Mon, 08 May 2023 19:22:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683598967; cv=none; d=google.com; s=arc-20160816; b=SvFy1I9IilUSY72S2ijx0g2ENxgJk8cv5cxL0MDj4+gvpSl1IJrbfDUnV4IuOWn6Bv CnzJBA9ieCA+AboBdvA6itPf2Z5t1bR555NaGmWuT50/tWSRfGrjv0FfybFfnetbS7On VkV2zgsFy84DE0rXkNHuU7neAiW7j3hbkYL9fiGkCZudKk9ttQY133UyQoHnjczOx34I Lo2qztx43w9ffJMc5IlgR7EWbcYm6omx4NyBPjr3tWMUak6kqBb40emKCwUBca2YDRWY 9FVMHMveM/LUD8hNsRUAl7aoIw9YRtcxJm1m8xpFrwiaqoXRzszYvQEVPtlG3v25PJuM iOow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IS1+bURvSYSv/+e3clB+KHrM4sbKl7OvnNf/nWpIgCw=; b=rhLEhn/X0qNR23urR0XeZcrBmmoomZTq4ITrl3fPMwxhGaME9YDgN1HUIgCmOI1E+k usV/P62TI3lOrc0I4JmWe/DSbQ9sSG5SJOL2rW0TAzq82wwG7IEVGyqgHVy3qXmGx1Vs tH90H15lMwYJsTUMgFdWX6wvGbMbzjPxZ71H7UYZmbMrZBiFDriMBSNYdH3kR87ax4v3 vHQzpts4fYc3KSaei1zJ3R1OCnz3J921kKV/FPcf79QlQCQTRagaEAqY67M6CRx4/hr/ S+GISn/1ZSJJ9Hp44zYjpToSqUBqVshCj7xLMRKZTzz4vusLFRyZtcMQ/E2eQcYMm+c6 UdAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IsTncCdC; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s2-20020a0562140ca200b006213574d8a6si375202qvs.29.2023.05.08.19.22.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 May 2023 19:22:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IsTncCdC; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwCzQ-0004IQ-HW; Mon, 08 May 2023 22:22:09 -0400 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 1pwCzM-0004GH-ID for qemu-devel@nongnu.org; Mon, 08 May 2023 22:22:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwCzL-0001yP-0g for qemu-devel@nongnu.org; Mon, 08 May 2023 22:22:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683598922; 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=IS1+bURvSYSv/+e3clB+KHrM4sbKl7OvnNf/nWpIgCw=; b=IsTncCdCdIBUwDkMYCDb8tmSxwFXL7k+JGBzQC1dHqARQKj9K2JiqdXCt1PF8D8kG3AHf0 QiPDwY0BHxEplJgRZVqmh8bPa5K7SYV0/uX5lLm4MBNY4YrPhFpND5nhtiSfyLW1E44IN+ ZXP+HvUtsesb2Y5a8CHzVlnKRmrBO3o= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-458-Vu38PGrZMQyS1pbegxX8xg-1; Mon, 08 May 2023 22:21:51 -0400 X-MC-Unique: Vu38PGrZMQyS1pbegxX8xg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0D42D1C0A585; Tue, 9 May 2023 02:21:51 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-118.bne.redhat.com [10.64.54.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A42D492B00; Tue, 9 May 2023 02:21:45 +0000 (UTC) From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, pbonzini@redhat.com, peter.maydell@linaro.org, peterx@redhat.com, david@redhat.com, philmd@linaro.org, mst@redhat.com, cohuck@redhat.com, quintela@redhat.com, dgilbert@redhat.com, maz@kernel.org, zhenyzha@redhat.com, shan.gavin@gmail.com Subject: [PATCH v3 2/4] kvm: Synchronize the backup bitmap in the last stage Date: Tue, 9 May 2023 12:21:20 +1000 Message-Id: <20230509022122.20888-3-gshan@redhat.com> In-Reply-To: <20230509022122.20888-1-gshan@redhat.com> References: <20230509022122.20888-1-gshan@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+alex.bennee=linaro.org@nongnu.org Sender: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: Ie+cZmhiUsao In the last stage of live migration or memory slot removal, the backup bitmap needs to be synchronized when it has been enabled. Signed-off-by: Gavin Shan Reviewed-by: Peter Xu Tested-by: Zhenyu Zhang --- accel/kvm/kvm-all.c | 11 +++++++++++ include/sysemu/kvm_int.h | 1 + 2 files changed, 12 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 870abad826..c3aaabf304 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1361,6 +1361,10 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, */ if (kvm_state->kvm_dirty_ring_size) { kvm_dirty_ring_reap_locked(kvm_state, NULL); + if (kvm_state->kvm_dirty_ring_with_bitmap) { + kvm_slot_sync_dirty_pages(mem); + kvm_slot_get_dirty_log(kvm_state, mem); + } } else { kvm_slot_get_dirty_log(kvm_state, mem); } @@ -1582,6 +1586,12 @@ static void kvm_log_sync_global(MemoryListener *l, bool last_stage) mem = &kml->slots[i]; if (mem->memory_size && mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { kvm_slot_sync_dirty_pages(mem); + + if (s->kvm_dirty_ring_with_bitmap && last_stage && + kvm_slot_get_dirty_log(s, mem)) { + kvm_slot_sync_dirty_pages(mem); + } + /* * This is not needed by KVM_GET_DIRTY_LOG because the * ioctl will unconditionally overwrite the whole region. @@ -3710,6 +3720,7 @@ static void kvm_accel_instance_init(Object *obj) s->kernel_irqchip_split = ON_OFF_AUTO_AUTO; /* KVM dirty ring is by default off */ s->kvm_dirty_ring_size = 0; + s->kvm_dirty_ring_with_bitmap = false; s->notify_vmexit = NOTIFY_VMEXIT_OPTION_RUN; s->notify_window = 0; s->xen_version = 0; diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index a641c974ea..511b42bde5 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -115,6 +115,7 @@ struct KVMState } *as; uint64_t kvm_dirty_ring_bytes; /* Size of the per-vcpu dirty ring */ uint32_t kvm_dirty_ring_size; /* Number of dirty GFNs per ring */ + bool kvm_dirty_ring_with_bitmap; struct KVMDirtyRingReaper reaper; NotifyVmexitOption notify_vmexit; uint32_t notify_window; -- 2.23.0