From nobody Mon Feb 9 07:32:02 2026 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=1621499746; cv=none; d=zohomail.com; s=zohoarc; b=T+5VTNSRsf51Gkp83zCMO/qsEZu9aYFanhv1h1479CBOk/bbGKvmIgBP2Z6QIP22GmoDhWp1WrGb7rgDW8SCPXUAGGARxvOJjSQezvaYqggnI4sGafI7EWXO+UDTF4q2EuTJV/sPcjas28hLKGgjB6U4FzMK2dMVWIakVOaEOVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621499746; h=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=GBwYk/KWMuO+/yxHf80rqOKUhqHBFBQaoC17YufQN2w=; b=BnpiCK8sUWOXi55U6vpgzWP3+tAkYttmufW+QYE1lwoKLhiWVzvN00eOWGoEVY4wRxC17j5S25QfoAX94mx7edrbgSeL88iTph9/fvg2WiemLgTjDH/EuODw6GGMa8Z9BsZBAr17R53nuXNmiE5vL6ESc2hYYWqdpq+RMLdEzuo= 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 1621499746911149.71112842589127; Thu, 20 May 2021 01:35:46 -0700 (PDT) Received: from localhost ([::1]:47036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lje9h-0001AO-QG for importer@patchew.org; Thu, 20 May 2021 04:35:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljdxf-0005OP-9i for qemu-devel@nongnu.org; Thu, 20 May 2021 04:23:20 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:39925) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ljdxa-0001Yf-EZ for qemu-devel@nongnu.org; Thu, 20 May 2021 04:23:16 -0400 Received: by mail-wr1-x42f.google.com with SMTP id v12so16672838wrq.6 for ; Thu, 20 May 2021 01:23:11 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id v10sm2603506wrq.0.2021.05.20.01.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 01:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GBwYk/KWMuO+/yxHf80rqOKUhqHBFBQaoC17YufQN2w=; b=hJFoEmJmyFG9zwvVkX8sqnKLEOdhIE67k8ZTAQ56WJHOuUt27AXzQRTGnitMPoeaKu tzxhz+LZwHYq6Q1h8+DFTXSuIeMSKdUAgWlzQ9kel5TR7e19aWys1t+Ng2EUgvlhV4hV /xY/uETrb+6uKP+I89fyX/PeXEdnHMBXjkqoIagyIfelPyspXU+2gv2bK5pXGeYktJLb ydBWp15dQow27rJQxpKBGIVpnBfRdqGv4gA+NWrB3GjYNVPR5ygYSw3cnxv01833m6ry cAANsNk3dhXOwODqD3Bm6wyhucJIL07g/nc4DuNyFQWLtLY3JrT90t8XGdWr6qT3VpdP RkUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=GBwYk/KWMuO+/yxHf80rqOKUhqHBFBQaoC17YufQN2w=; b=UUlkiMUaRjlEHp4wHtoYo0Pi0uDFbjfgwG1DoGU6YEQ1X2VKwrTEySadsKK6IZZuOv hFmYx9z+gb2TQx8Z4Xu9oqjGqRl42/H86FMNw73vn/wV7x0TzghpS9UgB65bVw5woG6+ QvrWsd4r9I9kNyI6lxCUf484jVxysU5RLNvlGRWUviKfAWbpVhIAfPhkyT3KYb8uFBRr EET1vlrENiMMkTLK1+ubcEM9jyyuf7BSE/IBJCHdYl7c9XYuIQo2JEBg9hu1kA504FJh DjMaNdeZNIWn5MuqLV4gvzgDW2WkQYCr5M3kUKc6yB+3p2RFc3pZAmbDF6EBIVeB0Frb 02oA== X-Gm-Message-State: AOAM532zccmSIEFjOqaRj8X9fqoZvqHNa1qK4pO3y8F1+sPKHqa2/m9g fCdZOONc7YNlUKtSwkNxCI8RX3o9xl+d4w== X-Google-Smtp-Source: ABdhPJxtVNuBdY5j5VyeNOgUfDiXX7l3LYIfWqn/Hbux3I5b1FqOaEjefN09xt4fDLAtR0c1SN/ldg== X-Received: by 2002:adf:eac9:: with SMTP id o9mr2957322wrn.120.1621498990388; Thu, 20 May 2021 01:23:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 18/26] KVM: Disable manual dirty log when dirty ring enabled Date: Thu, 20 May 2021 10:22:49 +0200 Message-Id: <20210520082257.187061-19-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520082257.187061-1-pbonzini@redhat.com> References: <20210520082257.187061-1-pbonzini@redhat.com> MIME-Version: 1.0 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=2a00:1450:4864:20::42f; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42f.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: Peter Xu 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" From: Peter Xu 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 Message-Id: <20210506160549.130416-10-peterx@redhat.com> Signed-off-by: Paolo Bonzini --- 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 5afe15ae66..e1a6c7c89b 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2131,20 +2131,29 @@ static int kvm_init(MachineState *ms) s->coalesced_pio =3D s->coalesced_mmio && kvm_check_extension(s, KVM_CAP_COALESCED_PIO); =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_size) { + 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.31.1