Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3443593pxb; Thu, 10 Feb 2022 22:56:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsrcjxZqeyVfw7d/yOUYKhVqiQPPXxAzrvdGhtv3gI8+K4nSiiV5d3xo9fAmmcf7NJX7PG X-Received: by 2002:a17:906:5918:: with SMTP id h24mr195719ejq.471.1644562574106; Thu, 10 Feb 2022 22:56:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644562574; cv=none; d=google.com; s=arc-20160816; b=viCGg0gZ8NBfNlWwtFgzLgXsfKfPuYoo3a7qPN9EPkg4B/qMJsgcbeFEfY1EZzHKxo zb5RFQQ5SIaX5kKahBiI6opaqzPK1gaB9lsYf+gmoeReaDuVdG2Ku/KjOixfWOSDO805 GSs2KqDFX9fx7x97AjJ4iqskE6+OhRH+kAnprojZKHi95qU1Q4X0slE/lYcgBRRNfwGf zD9d64tymB25zRJ/j0BlRMBxNmOjPtnBt/aNFeIKT0C0uAUdSbWJv+eK+nZT+064/Kub rm8FOFdOLGnO2NjIIwvInelneXeulWN9fv/L91qqvHxGPGhlTe1bjQA3UHYvxKuA8aCH D0Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=IO2ZpcAtYXMrjlM61WFlDXdotEwcy2m14gn1xrwbE5c=; b=bM6lh7zwGd/NHBMJ2J5MP4HBBWI8f5zhLqkL5FQfzlKCeKAR4oOc2tvW/GluaR18bR 1qUP8n/e7t+LGBrsCEWeoTdTl5rNwn1ZqgzPL3qZPChmlSbm17xBWHhCob7RrRRt4DS3 v3nIQtR7qR9ctuhBJW4AEzjk7jUk0jy3rP/wgVWzKcTQM0aaWA7NkE7oFpZ2LY8ijFLZ 9shGTvdeLe1b6T0GubmvrYXU7nb57REifyevArAb+xuwtAtlA+PFz+szAdeVSAjIvQkO yV4qvibMW2n4SJ0s/Zt3Z+/m+jXTjXX5r9i5TkAgt/Mxig64a9COVCdE43tEXQFE0xAp MNKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cofBBUBM; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb17si4834728ejc.465.2022.02.10.22.55.49; Thu, 10 Feb 2022 22:56:14 -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=@google.com header.s=20210112 header.b=cofBBUBM; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347241AbiBKCUX (ORCPT + 99 others); Thu, 10 Feb 2022 21:20:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240043AbiBKCUW (ORCPT ); Thu, 10 Feb 2022 21:20:22 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88774B31 for ; Thu, 10 Feb 2022 18:20:22 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id u12so3465285plf.13 for ; Thu, 10 Feb 2022 18:20:22 -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=IO2ZpcAtYXMrjlM61WFlDXdotEwcy2m14gn1xrwbE5c=; b=cofBBUBML8Xp8mOt3FYpkYsBWRS3bMUJgqhIy9SOHztUWAp46a8QvcAkXumzS3yidc RoeSXQAV9UA6e7oUVGWaR6zEcUMiYyNat3fEDg0+73gngPKG4/6wa8BI9VIskLSuHCS5 JN4t2jN+DhqqZxqrSiyljEc0JP4uZQmtqRDNF8wL4wwxzHY587JzfJFmVt9QrTIqBsCT D+6hAtRakoCv+5LSNLLveurnm6sKgNbkyesiZk6nSmdUboqo+d56Y6ZqtqiR4P50Lneu vi2YXIxtVKNBxB4S7E7ly3DXochUZ7JQmMe+GC/e/wh+3wWAQOg3dGDweBO+DIYbEHBW NMSw== 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=IO2ZpcAtYXMrjlM61WFlDXdotEwcy2m14gn1xrwbE5c=; b=eIgKueqGYih258iJDA71fFKjsiq4BgNaNhANaREFKD2kBng/vCeokrS9gOASxmrgsJ If0wiLC+C2D2YAn5511aLlWDKc6lQPOx7AIDZl3Gq5re/IHqm2rrHW7dQsmcBNDhBvF8 5tr9sva886y7CaeuEFNozdrQy4gRZ6EwhQr9h8eDiAC6RVG/9oXt/EFZn2C8OQzKoAmL zSJJrhGQudLYoaan+5+po4RjZBBCWsyuBXt6rnt7ndlJGIdBgqr3TumbIwsZ7XzAelYi MGwgr2Vwxa8POXiaBdAdliHSBpWoHQglDySsTucQ3EnFRiKP2N3ZKpBhDVYsD2C+laLB H9sA== X-Gm-Message-State: AOAM532KlXeuHYOlvXtgEv//PXBxTon3jvSURU+51Qr2VJJLozTfUcuS 5GzObqv7refyGd/7zREZlsr2rA== X-Received: by 2002:a17:902:694c:: with SMTP id k12mr10462860plt.98.1644546021525; Thu, 10 Feb 2022 18:20:21 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id j8sm26393351pfc.48.2022.02.10.18.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 18:20:20 -0800 (PST) Date: Fri, 11 Feb 2022 02:20:17 +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 08/12] KVM: MMU: do not consult levels when freeing roots Message-ID: References: <20220209170020.1775368-1-pbonzini@redhat.com> <20220209170020.1775368-9-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 11, 2022, Sean Christopherson wrote: > On Fri, Feb 11, 2022, Sean Christopherson wrote: > > On Fri, Feb 11, 2022, Paolo Bonzini wrote: > > > On 2/11/22 01:54, Sean Christopherson wrote: > > > > > > @@ -3242,8 +3245,7 @@ void kvm_mmu_free_roots(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, > > > > > > &invalid_list); > > > > > > if (free_active_root) { > > > > > > - if (mmu->shadow_root_level >= PT64_ROOT_4LEVEL && > > > > > > - (mmu->root_level >= PT64_ROOT_4LEVEL || mmu->direct_map)) { > > > > > > + if (to_shadow_page(mmu->root.hpa)) { > > > > > > mmu_free_root_page(kvm, &mmu->root.hpa, &invalid_list); > > > > > > } else if (mmu->pae_root) { > > > > > > > > Gah, this is technically wrong. It shouldn't truly matter, but it's wrong. root.hpa > > > > will not be backed by shadow page if the root is pml4_root or pml5_root, in which > > > > case freeing the PAE root is wrong. They should obviously be invalid already, but > > > > it's a little confusing because KVM wanders down a path that may not be relevant > > > > to the current mode. > > > > > > pml4_root and pml5_root are dummy, and the first "real" level of page tables > > > is stored in pae_root for that case too, so I think that should DTRT. > > > > Ugh, completely forgot that detail. You're correct. Mostly correct. The first "real" level will be PML4 in the hCR4.LA57=1, gCR4.LA57=0 nested NPT case. Ditto for shadowing PAE NPT with 4/5-level NPT, though in that case KVM still allocates pae_root entries, it just happens to be a "real" level. And now I realize why I'm so confused, mmu_alloc_shadow_roots() is also broken with respect to 5-level shadowing 4-level. I believe the part that got fixed was 5-level with a 32-bit guest. Ugh. For the stuff that actually works in KVM, this will do just fine. 5-level nNPT can be punted to the future.