Message ID | 20230116040405.260935-5-gshan@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1011490wrn; Sun, 15 Jan 2023 20:12:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXt3HqZ+W3BJvWKx0eLiN5e9SQShDL4KsyTYRMaXuRw0ycx+R1rQSTbjCGqbWm+R6HvjX4hV X-Received: by 2002:a17:906:75b:b0:7e0:eed0:8beb with SMTP id z27-20020a170906075b00b007e0eed08bebmr10858180ejb.41.1673842369994; Sun, 15 Jan 2023 20:12:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673842369; cv=none; d=google.com; s=arc-20160816; b=LK+MLN/2vUR54h8RX1S13nhA3bfG0aNgNqu3Xw8lzxsO888SMLteOtu10Dts2eRy+0 K7CKLFTqTKM1mfMdg+uaHXDU7MRgyu/wslJMuC2NPsLKvHzOFusqqltvNxYnYsuSjSOr mIwxS4mUOogCiCqOTWWxb+swmxx98vh1/UnoAZSF10IhqL3CaE/2ZFSsEKZoaGSXnbD0 SHpYP/0rBmWgXT7t1saV73OfNTNjjXRx6i7oSSbmBrVcq5z223mQeNOucIjJDu/zi3hB 3KBZXf12wqmTy6eRcYpx0/6HR+cFZ98T3QKfOqsDzbh8OEEVY1LXohaLz8BYDilWuzh9 Ojkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ohcJPZKvAgOpbS44T4QtlSyb+QSlTiMgmt0MSyKR4Gk=; b=FWUa+SDLns45LSuct+1aFAVG6SKF0oPFi+N0Vd2G+QYQAZBxps81hGBpaiECNKk3vQ j+cRaM8WXTx2eMxksYMTVDdIN3IfuAng2ibxj5ZrHKNJ30Z0rtmv6k6GISu7hcm1TWGB 9Bhmgp7iJLEGQBBz8k8pLUULHKcmsX1kmwMUitdBTCqb6u3M0JvQclbe0qgoFyEmYZcQ LtIiuGwmddcSqlrAbLeP1b3EVicaayOeTEEUrj154oPrt53+IgInmbyL/GhZTBOQ/T/R 8RIwzlsyt2/EhtLhA6oAOR4fL1Et5xVzyKHQUeQfoRTv5ikmse9JWGDZYBSeu1kqFVBC 4qVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dByWWlzJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd34-20020a1709076e2200b008705d5bb5d1si2517882ejc.951.2023.01.15.20.12.26; Sun, 15 Jan 2023 20:12:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dByWWlzJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231781AbjAPEGl (ORCPT <rfc822;stefanalexe802@gmail.com> + 99 others); Sun, 15 Jan 2023 23:06:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231932AbjAPEGO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 15 Jan 2023 23:06:14 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 357A683F4 for <linux-kernel@vger.kernel.org>; Sun, 15 Jan 2023 20:05:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673841911; 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=ohcJPZKvAgOpbS44T4QtlSyb+QSlTiMgmt0MSyKR4Gk=; b=dByWWlzJUlJr4Ilzvfb/vn2zJBtGAdEkS1umPLChqlx/OIekOuVLwkK2ED6xblUFGE13Bq JUaUml7h/yxIRiWdGOJz7q7b7IF0M3aVHmBcSdUX5y7CTAb+APGDXSWN2k38eySkuquzYC tQ86uN2qlorQaaZQOjVLN6jO4Z46otY= 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-404-oZ03pT2jOM-OSGkw5ehlOg-1; Sun, 15 Jan 2023 23:05:08 -0500 X-MC-Unique: oZ03pT2jOM-OSGkw5ehlOg-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 61A6F3828883; Mon, 16 Jan 2023 04:05:07 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-98.bne.redhat.com [10.64.54.98]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4DDB0492B05; Mon, 16 Jan 2023 04:05:00 +0000 (UTC) From: Gavin Shan <gshan@redhat.com> To: kvmarm@lists.linux.dev Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, maz@kernel.org, corbet@lwn.net, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, ricarkol@google.com, eric.auger@redhat.com, yuzhe@nfschina.com, renzhengeek@gmail.com, ardb@kernel.org, peterx@redhat.com, seanjc@google.com, shan.gavin@gmail.com Subject: [PATCH 4/4] KVM: Improve warning report in mark_page_dirty_in_slot() Date: Mon, 16 Jan 2023 12:04:05 +0800 Message-Id: <20230116040405.260935-5-gshan@redhat.com> In-Reply-To: <20230116040405.260935-1-gshan@redhat.com> References: <20230116040405.260935-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755150936849976380?= X-GMAIL-MSGID: =?utf-8?q?1755150936849976380?= |
Series |
Improve dirty ring warning report
|
|
Commit Message
Gavin Shan
Jan. 16, 2023, 4:04 a.m. UTC
There are two warning reports about the dirty ring in the function.
We have the wrong assumption that the dirty ring is always enabled when
CONFIG_HAVE_KVM_DIRTY_RING is selected. This leads to warning messages
about the dirty ring is reported even the dirty ring isn't enabled by
the user space. Actually, the expected behaviour is to report the
warning messages only when the dirty ring is enabled, instead of
being configured.
Fix it by enabling the checks and warning reports when the dirty ring
has been enabled by the user space.
Signed-off-by: Gavin Shan <gshan@redhat.com>
---
include/linux/kvm_dirty_ring.h | 5 +++++
virt/kvm/kvm_main.c | 25 ++++++++++++++-----------
2 files changed, 19 insertions(+), 11 deletions(-)
Comments
On Mon, Jan 16, 2023, Gavin Shan wrote: > There are two warning reports about the dirty ring in the function. > We have the wrong assumption that the dirty ring is always enabled when > CONFIG_HAVE_KVM_DIRTY_RING is selected. No, it's not a wrong assumption, becuase it's not an assumption. The intent is to warn irrespective of dirty ring/log enabling. The orignal code actually warned irrespective of dirty ring support[1], again intentionally. The CONFIG_HAVE_KVM_DIRTY_RING check was added because s390 can mark pages dirty from an worker thread[2] and s390 has no plans to support the dirty ring. The reason for warning even if dirty ring isn't enabled is so that bots can catch potential KVM bugs without having to set up a dirty ring or enable dirty logging. [1] 2efd61a608b0 ("KVM: Warn if mark_page_dirty() is called without an active vCPU") [2] e09fccb5435d ("KVM: avoid warning on s390 in mark_page_dirty")
Hi Sean, On 1/18/23 2:42 AM, Sean Christopherson wrote: > On Mon, Jan 16, 2023, Gavin Shan wrote: >> There are two warning reports about the dirty ring in the function. >> We have the wrong assumption that the dirty ring is always enabled when >> CONFIG_HAVE_KVM_DIRTY_RING is selected. > > No, it's not a wrong assumption, becuase it's not an assumption. The intent is > to warn irrespective of dirty ring/log enabling. The orignal code actually warned > irrespective of dirty ring support[1], again intentionally. The > CONFIG_HAVE_KVM_DIRTY_RING check was added because s390 can mark pages dirty from > an worker thread[2] and s390 has no plans to support the dirty ring. > > The reason for warning even if dirty ring isn't enabled is so that bots can catch > potential KVM bugs without having to set up a dirty ring or enable dirty logging. > > [1] 2efd61a608b0 ("KVM: Warn if mark_page_dirty() is called without an active vCPU") > [2] e09fccb5435d ("KVM: avoid warning on s390 in mark_page_dirty") > Thanks for the linker. I was confused when looking at the code, but now it's clear to me. Thanks for your explanation. How about to add a comment there? /* * The warning is expected when the dirty ring is configured, * but not enabled. */ Thanks, Gavin
On Thu, Jan 19, 2023, Gavin Shan wrote: > Hi Sean, > > On 1/18/23 2:42 AM, Sean Christopherson wrote: > > On Mon, Jan 16, 2023, Gavin Shan wrote: > > > There are two warning reports about the dirty ring in the function. > > > We have the wrong assumption that the dirty ring is always enabled when > > > CONFIG_HAVE_KVM_DIRTY_RING is selected. > > > > No, it's not a wrong assumption, becuase it's not an assumption. The intent is > > to warn irrespective of dirty ring/log enabling. The orignal code actually warned > > irrespective of dirty ring support[1], again intentionally. The > > CONFIG_HAVE_KVM_DIRTY_RING check was added because s390 can mark pages dirty from > > an worker thread[2] and s390 has no plans to support the dirty ring. > > > > The reason for warning even if dirty ring isn't enabled is so that bots can catch > > potential KVM bugs without having to set up a dirty ring or enable dirty logging. > > > > [1] 2efd61a608b0 ("KVM: Warn if mark_page_dirty() is called without an active vCPU") > > [2] e09fccb5435d ("KVM: avoid warning on s390 in mark_page_dirty") > > > > Thanks for the linker. I was confused when looking at the code, but now it's clear to > me. Thanks for your explanation. How about to add a comment there? > > /* > * The warning is expected when the dirty ring is configured, > * but not enabled. > */ That's not correct either. By design, the warning can also fire if the dirty ring is enabled. KVM's rule is that writes to guest memory always need to be done in the context of a running vCPU, with the recently added exception of kvm_arch_allow_write_without_running_vcpu(). That intent of the warning is to enforce that rule regardless of the state of the VM. Concretely, I think you can just drop patches 3 and 4, and just fix the arm64 issues.
Hi Sean, On 1/20/23 2:19 AM, Sean Christopherson wrote: > On Thu, Jan 19, 2023, Gavin Shan wrote: >> On 1/18/23 2:42 AM, Sean Christopherson wrote: >>> On Mon, Jan 16, 2023, Gavin Shan wrote: >>>> There are two warning reports about the dirty ring in the function. >>>> We have the wrong assumption that the dirty ring is always enabled when >>>> CONFIG_HAVE_KVM_DIRTY_RING is selected. >>> >>> No, it's not a wrong assumption, becuase it's not an assumption. The intent is >>> to warn irrespective of dirty ring/log enabling. The orignal code actually warned >>> irrespective of dirty ring support[1], again intentionally. The >>> CONFIG_HAVE_KVM_DIRTY_RING check was added because s390 can mark pages dirty from >>> an worker thread[2] and s390 has no plans to support the dirty ring. >>> >>> The reason for warning even if dirty ring isn't enabled is so that bots can catch >>> potential KVM bugs without having to set up a dirty ring or enable dirty logging. >>> >>> [1] 2efd61a608b0 ("KVM: Warn if mark_page_dirty() is called without an active vCPU") >>> [2] e09fccb5435d ("KVM: avoid warning on s390 in mark_page_dirty") >>> >> >> Thanks for the linker. I was confused when looking at the code, but now it's clear to >> me. Thanks for your explanation. How about to add a comment there? >> >> /* >> * The warning is expected when the dirty ring is configured, >> * but not enabled. >> */ > > That's not correct either. By design, the warning can also fire if the dirty ring > is enabled. KVM's rule is that writes to guest memory always need to be done in > the context of a running vCPU, with the recently added exception of > kvm_arch_allow_write_without_running_vcpu(). That intent of the warning is to > enforce that rule regardless of the state of the VM. > > Concretely, I think you can just drop patches 3 and 4, and just fix the arm64 issues. > Right, the warning report is still expected when dirty ring is enabled. My attempt was to have comment for the confused case. Anyway, it's not a big deal. I will drop PATCH[3] and PATCH[4] in v2. Thanks, Gavin
diff --git a/include/linux/kvm_dirty_ring.h b/include/linux/kvm_dirty_ring.h index 4862c98d80d3..3fda0aa42858 100644 --- a/include/linux/kvm_dirty_ring.h +++ b/include/linux/kvm_dirty_ring.h @@ -42,6 +42,11 @@ static inline bool kvm_use_dirty_bitmap(struct kvm *kvm) return true; } +static inline bool kvm_arch_allow_write_without_running_vcpu(struct kvm *kvm) +{ + return false; +} + static inline int kvm_dirty_ring_alloc(struct kvm_dirty_ring *ring, int index, u32 size) { diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 90f538433916..a35c32bc84e1 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3316,26 +3316,29 @@ void mark_page_dirty_in_slot(struct kvm *kvm, const struct kvm_memory_slot *memslot, gfn_t gfn) { - struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); + struct kvm_vcpu *vcpu; unsigned long rel_gfn; u32 slot; -#ifdef CONFIG_HAVE_KVM_DIRTY_RING - if (WARN_ON_ONCE(vcpu && vcpu->kvm != kvm)) - return; - - WARN_ON_ONCE(!vcpu && !kvm_arch_allow_write_without_running_vcpu(kvm)); -#endif - if (!memslot || !kvm_slot_dirty_track_enabled(memslot)) return; rel_gfn = gfn - memslot->base_gfn; slot = (memslot->as_id << 16) | memslot->id; - if (kvm->dirty_ring_size && vcpu) - kvm_dirty_ring_push(vcpu, slot, rel_gfn); - else if (memslot->dirty_bitmap) + if (kvm->dirty_ring_size) { + vcpu = kvm_get_running_vcpu(); + if (vcpu) { + if (!WARN_ON_ONCE(vcpu->kvm != kvm)) + kvm_dirty_ring_push(vcpu, slot, rel_gfn); + + return; + } + + WARN_ON_ONCE(!kvm_arch_allow_write_without_running_vcpu(kvm)); + } + + if (memslot->dirty_bitmap) set_bit_le(rel_gfn, memslot->dirty_bitmap); } EXPORT_SYMBOL_GPL(mark_page_dirty_in_slot);