Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2E2CC433EF for ; Mon, 22 Nov 2021 18:49:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233392AbhKVSw4 (ORCPT ); Mon, 22 Nov 2021 13:52:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233227AbhKVSwu (ORCPT ); Mon, 22 Nov 2021 13:52:50 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4D30C061714 for ; Mon, 22 Nov 2021 10:49:43 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id b68so16958423pfg.11 for ; Mon, 22 Nov 2021 10:49:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=SxyojBVqeaMPTAohryY0gMBBMQdskNaj/27cUyyvEcg=; b=E/y1Pj2+aJIiLou8CqMiukr0R8bAAo39P9fIFHYiZAB1TbjdSALxZOu/gO4icwQ8HN pBq2gy9C88qNBjU0tP0xbnF09tj/Dbf4vubPmp0WhUVgggHeC7NAtiGNEWXcVGOlL6Y4 /culURmitKhs75/Wv8X1cIsDFRrrDuJDp0g8Pz6B1xrlAoq/fcyjPEpMgWJDgaWqYz42 4xTiCqJ+gCaQ4CgldXctQjTMcqEpZPM2bq+nfbKEY0LTn8qSIxz/XaqfJWs+lbtifW5Q TefNXpa/SGNaQMdTasIKZzRaE0aKbPfoLGx7mrLXu+V64e24O/jfu7dTEP70imdx7A1U pjmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=SxyojBVqeaMPTAohryY0gMBBMQdskNaj/27cUyyvEcg=; b=qVfTMa7B9an2xDUJ43XrKGNKIUOyQi4AKMb0u8SZtvegzoQoYPAG07gl5abbDXPM5f iQDx8+8ub9xVNyBEMS0bT/skykcw0RCb5JcB9/OshHLLMsyuHSMAXX8xTFVMziQXk0IC 1O1ycxtMjPJlHiU7r4w2lmwIYdkwXsd7FKAkfnk7XgtSwQEEXsw3hkIyPfFtcPH/glrO MZ1fyNbqEXIMkRt6fi0tl+ic3E/z6edNYlnxdvqQROUbWdNrMi2WVLpRN3xVT68WD+zj oa9gBWrXIUw+KZjAcyzg4ypZtD5/BaKqk07Rju73qkbkkJuCEL9KYuM0SuP13LwYPEbI Nlew== X-Gm-Message-State: AOAM530fUevQWCnBnYJKheTcDMmkFQ2F/KyeXJkGqxrE+YmEBK4cdKS+ 5EO8CeYjnJFeg8B1hLWNRnilHQ== X-Google-Smtp-Source: ABdhPJy6vQvpO9AA3EUN/NOxIUg/gapr34v5QUIwYSn7IPS6idN+DBYnD4AKQnVLingib+jUtEDqUQ== X-Received: by 2002:a05:6a00:1991:b0:4a4:f002:66f0 with SMTP id d17-20020a056a00199100b004a4f00266f0mr8565162pfl.81.1637606983105; Mon, 22 Nov 2021 10:49:43 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id oc10sm20851413pjb.26.2021.11.22.10.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 10:49:42 -0800 (PST) Date: Mon, 22 Nov 2021 18:49:38 +0000 From: Sean Christopherson To: David Woodhouse Cc: Paolo Bonzini , butt3rflyh4ck , kvm@vger.kernel.org, LKML Subject: Re: KVM: Warn if mark_page_dirty() is called without an active vCPU Message-ID: References: <9eb83cdd-9314-0d1f-0d4b-0cf4432e1e84@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 22, 2021, David Woodhouse wrote: > 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. Fair enough. And probably a moot point since Paolo hasn't vehemently objected to the dirty quota idea.