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 8E952C433EF for ; Wed, 8 Dec 2021 19:17:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233399AbhLHTUw (ORCPT ); Wed, 8 Dec 2021 14:20:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233594AbhLHTUu (ORCPT ); Wed, 8 Dec 2021 14:20:50 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1586C0617A1 for ; Wed, 8 Dec 2021 11:17:17 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id z6so2182871plk.6 for ; Wed, 08 Dec 2021 11:17:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=DGnuOBwhoBGsqcbwh1V3s8v4tkBJox5VDKCuMWrCxRI=; b=fbvEgdJVp9DubGUA5+/dSVLMkuGd39qD7pKitXNbCxQQ25h2rtA0U8zDfgG10+48kk Z7fIDyR9H1m0bwe4YLYvIaJC2G+ZMyAlcUGwQ2vF3GLc0WtMed4x4mUd/+wslThcz9q3 WMf3jd8KpucybyJF03UVWdix26Kt8uhTxOgQGv3VHvySbxTkdiBl0gchTrLtaBnADLVv UHquEeLRlh1cfmfH/ffMjCLkZ050whAVjX+Vvm8yFOqPRiD3OCKm8PIiN14meMoZ4+Qv WYoh5vPhWsrSAUVpm020kApSUL2qGbplbKV5h/Nnr56+/YC/dQKLbewmqvoqNR4ZUH+z XaSA== 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:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=DGnuOBwhoBGsqcbwh1V3s8v4tkBJox5VDKCuMWrCxRI=; b=fnisERI30C/GKmGOZrZztNmlqyz9ob6urZgJEyzibHe0v9UAmQbAqQOd1a8UHPNV3Q hMvRl9n9fkqrvsQeZQG42hNdVEnyCUNzPnsH8pdcPQhTkgVs3ExaVkwtISi0nYxOQZQr m9OKno5C18HTrw37FOys9AOqHscjwBWaVrjVwjlVJbZL8DrMRtdfvy8fYMHiCTvHBv6D WeXIqQCpC1KUyn2mln/NtK6E9HnirKBvpalyzVEMiemEZkWMy4V3bTmYqeAOQefSz5hq baH5M5YdUtwLuq38ZHg5/pnPMJ7sCF27EV9X+tcgmdC6o2DPoox09tZYTaEkK9b6K2YW ox+w== X-Gm-Message-State: AOAM531J/vej5cJhI7oeXP4n7QBGClwRhtOJfPGJB53TIdX/opcHDzIH 8I1MbR+bjGfp/621NFaqsDOYMQ== X-Google-Smtp-Source: ABdhPJzErlY5eV+qzr52TnFF6JnHqQk+b9rFrt/flyTqyxNA1fc1JM6Cv//8XdHYPVs/YWjN1lmSog== X-Received: by 2002:a17:902:b20b:b0:141:a92c:a958 with SMTP id t11-20020a170902b20b00b00141a92ca958mr61874259plr.24.1638991037051; Wed, 08 Dec 2021 11:17:17 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id y31sm4952081pfa.92.2021.12.08.11.17.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 11:17:16 -0800 (PST) Date: Wed, 8 Dec 2021 19:17:13 +0000 From: Sean Christopherson To: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Hou Wenlong , Ben Gardon Subject: Re: [PATCH 04/28] KVM: x86/mmu: Retry page fault if root is invalidated by memslot update Message-ID: References: <20211120045046.3940942-1-seanjc@google.com> <20211120045046.3940942-5-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211120045046.3940942-5-seanjc@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Nov 20, 2021, Sean Christopherson wrote: > @@ -3976,6 +3980,20 @@ static bool kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, > return true; > } > > +/* > + * Returns true if the page fault is stale and needs to be retried, i.e. if the > + * root was invalidated by a memslot update or a relevant mmu_notifier fired. > + */ > +static bool is_page_fault_stale(struct kvm_vcpu *vcpu, > + struct kvm_page_fault *fault, int mmu_seq) > +{ > + if (is_obsolete_sp(vcpu->kvm, to_shadow_page(vcpu->arch.mmu->root_hpa))) Ugh, I got so focused on TDP MMU that I completely forgot to test this with shadow paging. PAE roots are not backed by shadow pages, which means this explodes on the very first page fault with TDP disabled. Nested NPT will suffer the same fate. I'll figure out a patch for 5.16. Long term, it might be nice to actually allocate shadow pages for the special roots. > + return true; > + > + return fault->slot && > + mmu_notifier_retry_hva(vcpu->kvm, mmu_seq, fault->hva); > +}