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 D9A38C433F5 for ; Fri, 11 Feb 2022 01:44:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346968AbiBKBoN (ORCPT ); Thu, 10 Feb 2022 20:44:13 -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-Google-Smtp-Source: ABdhPJwRDTYmEVxd6eI4oS0+B3NsHy6+EBsvEaPdupHQ9iogPGY0X79JuyiAIUwlFlUqS+kApgvQYw== 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: 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)?