kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	butt3rflyh4ck <butterflyhuangxx@gmail.com>,
	kvm@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: KVM: Warn if mark_page_dirty() is called without an active vCPU
Date: Mon, 22 Nov 2021 17:52:58 +0000	[thread overview]
Message-ID: <ee872549432eaf62c0c5a722b94ac4390ef3df83.camel@infradead.org> (raw)
In-Reply-To: <YZvNB0ByFmdEkUVX@google.com>

[-- Attachment #1: Type: text/plain, Size: 1663 bytes --]

On Mon, 2021-11-22 at 17:01 +0000, Sean Christopherson wrote:
> On Sat, Nov 20, 2021, David Woodhouse wrote:
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index 6c5083f2eb50..72c6453bcef4 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -3020,12 +3020,17 @@ void mark_page_dirty_in_slot(struct kvm *kvm,
> >  			     struct kvm_memory_slot *memslot,
> >  		 	     gfn_t gfn)
> >  {
> > +	struct kvm_vcpu *vcpu = kvm_get_running_vcpu();
> > +
> > +	if (WARN_ON_ONCE(!vcpu) || WARN_ON_ONCE(vcpu->kvm != kvm))
> 
> Maybe use KVM_BUG_ON?  And two separate WARNs are probably overkill.
> 
> 	if (KVM_BUG_ON(!vcpu || vcpu->kvm != kvm, kvm))
> 
> 
> I'd also prefer to not retrieve the vCPU in the dirty_bitmap path, at least not
> until it's necessary (for the proposed dirty quota throttling), though that's not
> a strong preference.

I don't think that would achieve my objective. This was my reaction to
learning that I was never supposed to have called kvm_write_guest()
when I didn't have an active vCPU context¹. I wanted there to have been
a *warning* about that, right there and then when I first did it
instead of waiting for syzkaller to find it.

I didn't want to wait for the actual circumstances to arise that made
it *crash*; I wanted an early warning. And that's also why it was a
warning not a BUG(), but I suppose KVM_BUG_ON() would be OK.


-- 
dwmw2


¹ My other reaction was wanting to remove kvm_write_guest() entirely
  and let people use kvm_vcpu_write_guest() instead. That's the path I 
  was going down with the original patch to propagate the vcpu down.


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5174 bytes --]

  reply	other threads:[~2021-11-22 17:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-18 17:14 There is a null-ptr-deref bug in kvm_dirty_ring_get in virt/kvm/dirty_ring.c butt3rflyh4ck
2021-10-21 20:08 ` Paolo Bonzini
2021-10-28  7:42   ` butt3rflyh4ck
2021-11-08  5:11   ` butt3rflyh4ck
2021-11-16 15:41   ` butt3rflyh4ck
2021-11-16 16:22   ` [EXTERNAL] " David Woodhouse
2021-11-16 17:07     ` David Woodhouse
2021-11-17  9:46   ` Woodhouse, David
2021-11-17 16:49     ` Paolo Bonzini
2021-11-17 18:10       ` Woodhouse, David
2021-11-20 10:16   ` KVM: Warn if mark_page_dirty() is called without an active vCPU David Woodhouse
2021-11-22 17:01     ` Sean Christopherson
2021-11-22 17:52       ` David Woodhouse [this message]
2021-11-22 18:49         ` Sean Christopherson
2022-01-13 12:06     ` Christian Borntraeger
2022-01-13 12:14       ` Paolo Bonzini
2022-01-13 12:29         ` [PATCH] KVM: avoid warning on s390 in mark_page_dirty Christian Borntraeger
2022-01-13 12:31           ` David Woodhouse
2022-01-18  8:37           ` Christian Borntraeger
2022-01-18  8:44             ` Paolo Bonzini
2022-01-18  8:53               ` Christian Borntraeger
2022-01-18 11:44                 ` Paolo Bonzini
2022-01-13 12:30         ` KVM: Warn if mark_page_dirty() is called without an active vCPU David Woodhouse
2022-01-13 12:51           ` Christian Borntraeger
2022-01-13 13:22             ` David Woodhouse
2022-01-13 15:09               ` Christian Borntraeger
2022-01-13 14:36           ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee872549432eaf62c0c5a722b94ac4390ef3df83.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=butterflyhuangxx@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --subject='Re: KVM: Warn if mark_page_dirty() is called without an active vCPU' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).