Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3330414pxb; Thu, 10 Feb 2022 18:54:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnooGYcK2gmcl8szpfgE4K64f81ShZHphm424r2G8bCq5NcrzHKT3c9ZHSJpsFR55spIOu X-Received: by 2002:a05:6a00:2451:: with SMTP id d17mr10397501pfj.70.1644548041358; Thu, 10 Feb 2022 18:54:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644548041; cv=none; d=google.com; s=arc-20160816; b=RjedVfv0zm9lq5hJ/28pfMWpBA/q1sV+jpp25ejCcl4lHxctHJJk9qynA0V/0bAGNO 7Hr0q4tj2TH2YqDC5IqAzDCTIO0wUgiK0S+HYrxgc3lAIH8lthnpUvSLeT8TnMb9FZ3M ILgeipCkVwKfhEpjgdwN5gW1+h7LYFGdVUASCJ9ONN8MLAxUbb37fcTup4LERuOw7AfI IeiAmcOFEwk+bT6f+gjgBv40+Hn0TlH5l5eYHJSybdddO+o1twzwxkx5hcb6WMQ+Hi5p vBPyN1drZ8+Kaflf0MX66NtP0MgrI5QfsHCo+4iZIOEnHdT2LGWbsBgJZ/+logKWQ814 7B4w== 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=zFYMirPh/eR5GwuGXASD2X9MTPiihD/L5+hpXzIMHiI=; b=07XctNE5Tkal+fFVwnaVgVKNpTav2PskMbYftIOfjKRlDM0tphJJtwHRFKmwTvYzCn ieRgjq2AYavJ1Id1negv9+4YxSRW07Fi35hLEdG12BaBWiRey2FWvahvSLGTL2lwnHsQ Bd81tf5tGKyTcmaKelHOezU2+jBBZvqpcdhjVHE2OUSslUlHl/Sbr7KTDBfO+Qt+8prO dc821gSaIpitQUf0T5WX5l0T9RArOzbSyq4kWufFpdotYXLS5zEpHDxMtoQh9M0ZVBtG kb+yBoeunAejl1UtFhnSBeMc3vUxI/mgE6ggTBIlm6tlHEoTABzy2BjdnYhK4PYlEuAs f3aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GmdTpGFK; 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 mi17si3526470pjb.99.2022.02.10.18.53.47; Thu, 10 Feb 2022 18:54:01 -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=GmdTpGFK; 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 S1346967AbiBKBoM (ORCPT + 99 others); Thu, 10 Feb 2022 20:44:12 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346916AbiBKBoK (ORCPT ); Thu, 10 Feb 2022 20:44:10 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB36A5F92 for ; Thu, 10 Feb 2022 17:44:10 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id t14-20020a17090a3e4e00b001b8f6032d96so7382142pjm.2 for ; Thu, 10 Feb 2022 17:44:10 -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=zFYMirPh/eR5GwuGXASD2X9MTPiihD/L5+hpXzIMHiI=; b=GmdTpGFKQzioEF0Jf0JcBEozVqOU2xVWey7zx7lp3v2gy8AEE5yrjDHxjaw0vQSUz9 +/pNQtpS/5rn1OVHRoUnXI/ZRHTCSbR8HJulhBjXEZ+LVfyyV16SSQcYB7XbW2QMx3+J AmpnVhmiryCEejtJVxeAxgAKVHR/LAy0pTpfMeX9oGx+1Ghf8e7Q0tkVBCkcbPT3DIEI iuRvTtaqY6UaXn/ThIGKEg1wBGeR6Ay19O66DevB2cSvDQDTXEVOIJraaISQTaMciFC8 +TWgHta9TH6w02B2Eu3AfZjfFJINLBFvkl5W4oeHMrw0MvcKojsNsU/M5XjkK1gIXAcx eFCw== 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=zFYMirPh/eR5GwuGXASD2X9MTPiihD/L5+hpXzIMHiI=; b=kJvlLosKM7gj9ckdMwZ0oAfNXkBt/99OqXYaWABQctFwczYBhCfsXvQE6mBtVGXTQw OZ936FwhSuzfpyHXX6ftRXBOQOIVGLEiizPf/1QQMV21Xm5voAWJvJORorLESIy7o7ay WXp6xzfbHFU+DCRXL7ksuH1NvofChpIiqaqsRnda/mka7ObPcPkiSXQK/pTvsxrHjftH SHPBZF43RXbuT+RPAhePDh38HVWCE9671n8FiZmq6eXH7TDX/WVMwBxuXnFnc7Qub8Qo 9936iBvFlo6XjFljtZGpN4ftwJfZB+OnaTA/MNe4fsE96jk4/Ly+4qJzxXOhGo++G2Eb JtdA== X-Gm-Message-State: AOAM530GIGyS6fF21y4f60kC8TwZ2GFd09MYC/29Yrxb7jVIARxh6jwp nJzAAKxsUFDpjv8EDs0J3T7ZhA== X-Received: by 2002:a17:90a:2e87:: with SMTP id r7mr243914pjd.61.1644543850056; Thu, 10 Feb 2022 17:44:10 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id f12sm25108727pfv.30.2022.02.10.17.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 17:44:09 -0800 (PST) Date: Fri, 11 Feb 2022 01:44:06 +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=ham 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, 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. Probably worth a comment? Actually, can't this be if (to_shadow_page(mmu->root.hpa)) { ... else if (!WARN_ON(!mmu->pae_root)) { ... } now that it's wrapped with VALID_PAGE(root.hpa)?