From mboxrd@z Thu Jan 1 00:00:00 1970 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 5B368C433F5 for ; Thu, 10 Feb 2022 23:11:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345487AbiBJXLD (ORCPT ); Thu, 10 Feb 2022 18:11:03 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345101AbiBJXLB (ORCPT ); Thu, 10 Feb 2022 18:11:01 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F7A41105 for ; Thu, 10 Feb 2022 15:11:02 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id on2so6511931pjb.4 for ; Thu, 10 Feb 2022 15:11:02 -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:in-reply-to; bh=G6h4BaCdrqdbFhFcxIl9IdHmu9enCO1yunXO86W7eOE=; b=fgUXjVCC65eMisH+QxSH8aEPf5l9+N39zoxRgxP323KCp0K/cN4FZ6k3tr5ZsSh+gY qvRCe1oJbD2vEsRKFX+72ZgpgcM8cejJ16Ux6tPK0Nq74ZJABFaDqqLRtnedeXXuGfLp nWj+Kxy0oRzjwL4GHw1oPgh3yrzqk0SGp3PIOUQezPUEHiOmWRbmQs7VhmN+HKSF+wSO LYBRr9Mi2q18uxKppIR7mfX0oDxaHBBivZy6pj6OQGLuieVwdhd0l2QeMrinP+0eF7l4 5F34wcao4dDvj4NMhQns/WvRgc1Oei4MMJwaKKqk3PjqSRQZ5JrI6LvfYtoUmy7NQ4+5 dyCw== 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:in-reply-to; bh=G6h4BaCdrqdbFhFcxIl9IdHmu9enCO1yunXO86W7eOE=; b=DAeXU3AhklicEOxFiqerPC+k5TUPw3WvI84CqABA+SyBEiwiqKk9gqgq3M0H90pTv1 Dfvcu7r44Slk9kuBtuOtdr0z4Ww6JY+qgQa5N9a8MAVhqtzs7lPYamrbapW+qHz0zkcp 9VcPcOwBLwWnGth1aCUSIhqPHStYK6wUMvA2lEFEbtz/0YnAROjP/+P0vuQzQRZbqCua LbZ6tP62jxYu+NMMYPKsmjo2B2bsCxVPastPkBj6ssyqXEbewOfrInxlN+jPfFES0PLf n9PVpyG1Bw46asDxW0NyjOEsFV3oBc4TJDOWg2AYKIQ+oC2PytC/R5BejXogBBH0SVaX MgNw== X-Gm-Message-State: AOAM531oKYWGG2rOxAycsEZ5NajhYRpNAv8ATURP6UmoafEjKySJtRh7 tyXOPYcwkV72euxI86zycVFFaA== X-Google-Smtp-Source: ABdhPJz/EaccljVntzlr26C+gJqik/vn3hF52wWE4j4iG6jH0Zzf1GrlbXsuwbU+8ODnz0gG3JAWhg== X-Received: by 2002:a17:902:680f:: with SMTP id h15mr9858207plk.17.1644534661358; Thu, 10 Feb 2022 15:11:01 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id q21sm25673162pfu.104.2022.02.10.15.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:11:00 -0800 (PST) Date: Thu, 10 Feb 2022 23:10:57 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, vkuznets@redhat.com, mlevitsk@redhat.com, dmatlack@google.com Subject: Re: [PATCH 03/12] KVM: x86: do not deliver asynchronous page faults if CR0.PG=0 Message-ID: References: <20220209170020.1775368-1-pbonzini@redhat.com> <20220209170020.1775368-4-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220209170020.1775368-4-pbonzini@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 09, 2022, Paolo Bonzini wrote: > Enabling async page faults is nonsensical if paging is disabled, but > it is allowed because CR0.PG=0 does not clear the async page fault > MSR. Just ignore them and only use the artificial halt state, > similar to what happens in guest mode if async #PF vmexits are disabled. > > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/x86.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 5e1298aef9e2..98aca0f2af12 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -12272,7 +12272,9 @@ static inline bool apf_pageready_slot_free(struct kvm_vcpu *vcpu) > > static bool kvm_can_deliver_async_pf(struct kvm_vcpu *vcpu) > { > - if (!vcpu->arch.apf.delivery_as_pf_vmexit && is_guest_mode(vcpu)) > + if (is_guest_mode(vcpu) > + ? !vcpu->arch.apf.delivery_as_pf_vmexit > + : !is_cr0_pg(vcpu->arch.mmu)) As suggested in the previous patch, is_paging(vcpu). I find a more tradition if-elif marginally easier to understand the implication that CR0.PG is L2's CR0 and thus irrelevant if is_guest_mode()==true. Not a big deal though. if (is_guest_mode(vcpu)) { if (!vcpu->arch.apf.delivery_as_pf_vmexit) return false; } else if (!is_paging(vcpu)) { return false; } > return false; > > if (!kvm_pv_async_pf_enabled(vcpu) || > -- > 2.31.1 > >