From nobody Mon Dec 15 02:55:01 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615409257; cv=none; d=zohomail.com; s=zohoarc; b=kMxI8QoVwIvxNCy6jV+mw8H0vV5J7TS6Ynjdfr6kscRfjWPd0ONpepLZ+qkx5bnkHvEYD0N/2G6N/cF14MdRxuZJVi5Vithn4avLqvKypySprVFtyjMbpUS7ftXVYYmtOORjF9ItNyyPLZjAD+RSnjM7WTFvp14fGF7Fca8pN1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615409257; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O+AomLI9wrG5xhM1xQmZ+/NRUp82zimm1r3k6Rcg5v0=; b=Km6e6yx+lqTkDSzS7NnISuLjM4DIvYwzzWBBkI27AkZGDxPoMBkO+oB64IFPjDs4GpxAN9C4bY4nIM7VdvO2rjZ255cGfnRbA35Lpm3F5JGhC6Me+IAbGGa4JkGEl3hqihqNI4KO8BBoDuAi14YMyofHotATdMTDMsJ9QbKGv1k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615409257002273.3325366932095; Wed, 10 Mar 2021 12:47:37 -0800 (PST) Received: from localhost ([::1]:38530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5jz-0005EE-Rs for importer@patchew.org; Wed, 10 Mar 2021 15:47:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK5WC-000604-JJ for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lK5W9-0000ga-Cb for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:20 -0500 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-4mMdSS7LOxaVQtMAmeG-ug-1; Wed, 10 Mar 2021 15:33:15 -0500 Received: by mail-qv1-f69.google.com with SMTP id da16so13597839qvb.2 for ; Wed, 10 Mar 2021 12:33:15 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.89.138]) by smtp.gmail.com with ESMTPSA id z89sm306746qtd.5.2021.03.10.12.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 12:33:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615408396; 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=O+AomLI9wrG5xhM1xQmZ+/NRUp82zimm1r3k6Rcg5v0=; b=KGXA5xaRxYYXIUP4z4xYmexGZVBb8dbOmBc3tTMmnbxGILs1wih8fk53T0DZwx8zQSLeqW Gmr5G3T6e2FuG4mWf/iQz0h5O6H5EGZXyj8Uk0/AuG9ZnHa3WTO1kqRNWnjDSaHfs2P267 207Q+VojcqlDqik0T/B1h2GkqpIoduo= X-MC-Unique: 4mMdSS7LOxaVQtMAmeG-ug-1 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=O+AomLI9wrG5xhM1xQmZ+/NRUp82zimm1r3k6Rcg5v0=; b=MkK23KRBR/SIVtX3bdYNxQRYXqxmjI/FPaE2fQfPAWgEZL7Oeobjb6SWlwaWh7GcFb 0MiPDvQAsGRBRnkZIO/xyMp8cjO4Z9PtgE1Xwu1YdLwCiAOdoLMAZwQYpt8wjR6wvvIf Y1vzvjGZPzuk8popQWFPHbHRBtlouHfJwi5Sd9fKxPKzsagHYQqiyp8uGtR6HD6OwmIO AzsCJX4AdlSO947Jbdw7+VCRbN+A5eSD7NvxoV/oNUUsCGGxiJboh5BPHxEO6xxIzQyF 2hEmZCaYESXIsL529eTNhDteb1cb7J0n3n4tKiMGG2hcZLosSCHl93Hk9MlPnV18CP4l nPPA== X-Gm-Message-State: AOAM532AxvUWeDrn9Y4dn9qDi4DpzYdqnvmY+r+vIPc9i196LW7Vtb9i T6xM/O547CoH2i9bEuaJKIMLDJlk6+c73bKepqYhSqBE75s9jxbS9CXgc1lNOSYWxQ2h0bs1hpz sEOvonoRRh9+KpFspZhs2yhyZYatZDTQB69qFhrlo6n/vH6P4M5sYe1UXWsCkY/Eu X-Received: by 2002:a05:620a:16b9:: with SMTP id s25mr4390205qkj.500.1615408394445; Wed, 10 Mar 2021 12:33:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJz87UpWZXa71qQfE6+9PWke738LMs2yURI+AFAFujWokvcUMdkiNvzsLvHb060UoSBlFkSunA== X-Received: by 2002:a05:620a:16b9:: with SMTP id s25mr4390183qkj.500.1615408394132; Wed, 10 Mar 2021 12:33:14 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 09/10] KVM: Disable manual dirty log when dirty ring enabled Date: Wed, 10 Mar 2021 15:33:00 -0500 Message-Id: <20210310203301.194842-10-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310203301.194842-1-peterx@redhat.com> References: <20210310203301.194842-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.243, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is for KVM_CLEAR_DIRTY_LOG, which is only useful for KVM_GET_DIRTY_LOG. Skip enabling it for kvm dirty ring. More importantly, KVM_DIRTY_LOG_INITIALLY_SET will not wr-protect all the p= ages initially, which is against how kvm dirty ring is used - there's no way for= kvm dirty ring to re-protect a page before it's notified as being written first with a GFN entry in the ring! So when KVM_DIRTY_LOG_INITIALLY_SET is enabl= ed with dirty ring, we'll see silent data loss after migration. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 10137b6af11..ae9393266b2 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2173,20 +2173,29 @@ static int kvm_init(MachineState *ms) } } =20 - dirty_log_manual_caps =3D - kvm_check_extension(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); - dirty_log_manual_caps &=3D (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | - KVM_DIRTY_LOG_INITIALLY_SET); - s->manual_dirty_log_protect =3D dirty_log_manual_caps; - if (dirty_log_manual_caps) { - ret =3D kvm_vm_enable_cap(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2, 0, - dirty_log_manual_caps); - if (ret) { - warn_report("Trying to enable capability %"PRIu64" of " - "KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 but failed. " - "Falling back to the legacy mode. ", - dirty_log_manual_caps); - s->manual_dirty_log_protect =3D 0; + /* + * KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is not needed when dirty ring is + * enabled. More importantly, KVM_DIRTY_LOG_INITIALLY_SET will assume= no + * page is wr-protected initially, which is against how kvm dirty ring= is + * usage - kvm dirty ring requires all pages are wr-protected at the v= ery + * beginning. Enabling this feature for dirty ring causes data corrup= tion. + */ + if (!s->kvm_dirty_ring_enabled) { + dirty_log_manual_caps =3D + kvm_check_extension(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); + dirty_log_manual_caps &=3D (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | + KVM_DIRTY_LOG_INITIALLY_SET); + s->manual_dirty_log_protect =3D dirty_log_manual_caps; + if (dirty_log_manual_caps) { + ret =3D kvm_vm_enable_cap(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2= , 0, + dirty_log_manual_caps); + if (ret) { + warn_report("Trying to enable capability %"PRIu64" of " + "KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 but failed.= " + "Falling back to the legacy mode. ", + dirty_log_manual_caps); + s->manual_dirty_log_protect =3D 0; + } } } =20 --=20 2.26.2