Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp823649pxj; Thu, 27 May 2021 12:29:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7RSv+ZM7Gpl1AvIw1StGTdeQ61RKtfyljjrblBUib4OoDmBFgTmYPs5em+rdOn7V1hBii X-Received: by 2002:a05:6602:164c:: with SMTP id y12mr4111543iow.78.1622143754456; Thu, 27 May 2021 12:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622143754; cv=none; d=google.com; s=arc-20160816; b=kLoHSJ4/dmDA8UVQpr9JX7tNX8MvtDFOfvZl83a7GqkAALANOyiYThjohza5T0UGxB Adnc5rHL58WQ5F22s3v72s6rjJIaUmER497F6+jvs54kOLt30HuvQlZaNuWfVO0cEJGS Dd5Iz6c9GACQAPbmhS3qgXIGOtfXxBE1E66LemfwG5deuAKCbF96JWI6svg+mOiXry7i Rioz+H6PHIzBQ3gd++lE1tAjwg3eCFPf4jshA9wfbDc3CDzXttdl6QUXYdCpj1p2cC7Y c1qe+dat4x1WrRJlhVMLglxs0JA9ZJGZp9ZK319gR2L2PSQ6Tn7u8Fed4ISaBV8aEMkX BAlA== 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:to:from:date:dkim-signature; bh=dy2taTgwwYXF8T7BA2RvIvYOzohHJC1sakBN5DAw9rU=; b=DEMLSyYc1HVafoSAlEEHIJf18QN6uq2xtgriXqA9rdZlsn8YARr3AJsVIkMt5U9NQS BytdE5tK+qPiiDiyPwWoVVe7UfDO1ILe+CPCXCUE+ZDsGStkaNz4N24TupfUeV63dAYK YDWBePhbwCgv2YSxAtHWPLwF8Lp/iA/I4CrQ0npBBuWkBCMXYmLcXzt87D3aLgDVnSDc qc9/S3TZMxbiOYKzB5zayR1P0vh3O2HlBEm5eWo+q/hefREH8xNlLlkVq1sbV5N2PLpa KR7bcgKaG5xECDjYYpm+s+Krcc+oF6j8gvfxUpwc2oC/f4LsQwzJax91PmEhFtyQqxef moxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kZsyyPid; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f184si3131900jac.102.2021.05.27.12.29.00; Thu, 27 May 2021 12:29:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kZsyyPid; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S234775AbhE0T0u (ORCPT + 99 others); Thu, 27 May 2021 15:26:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229764AbhE0T0t (ORCPT ); Thu, 27 May 2021 15:26:49 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39FCEC061574 for ; Thu, 27 May 2021 12:25:15 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id e17so1364867pfl.5 for ; Thu, 27 May 2021 12:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=dy2taTgwwYXF8T7BA2RvIvYOzohHJC1sakBN5DAw9rU=; b=kZsyyPidY3aMZ6sqg+Z8jRUlIrkGioM3ep3zOC+GWJ/I5O6FebpsXhBqee2pgxMdaK D4RscqYo3TTr6WS+tbx4CHHoJUwmM0tp6VIJZQPNZtlBMcCMa9f3Ecr8Q7x9nqblEVO4 e9Ds/KfXTDGN/qzW2kfox+IHlKdp4IeU9Jjy0wwMPmQJJm80wZq9yTthXCQ7I5Fd9rnA SpNnjq/HzoWt+MizRz7gW/dm4RhhgVWSvgCE8ck/MOzLbpJSoy8EOGp1WEHEt8slX2as HMAUVMMXWN7p7TvGRZaQws69G1e1XnZpQou9llvapTU16fUhKnsQipEK9Ij3ujPALB3Z pNvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dy2taTgwwYXF8T7BA2RvIvYOzohHJC1sakBN5DAw9rU=; b=oDQRvxhU/P5IgyeiEfCw5b5DWtRgvtmayBE4mibBeMnPi1DAINvQJlDEqrMT7iXpH2 0lU0SVtEMLBiJXAGVnr0j8cuHoovwOAUC0U6UAbHR99RtVAyYs2JYiJD0DYezSpZ9++0 2oIbhZl8m9SE8GcPJSwV2de8KccMnhYezPaKR9sjp2gmiRHAxoaJKAnhGCYrSdrEnQY9 5uRHIOsRVEOoy36YylXSNDl4rozqiNFQfeE+hpU2pzvkM6bpngYViaZCiv3+27IbLC8z KAWXbgxQvAl9d1wFSdjVCSQ7szil8PVEEMByT4CFJHrse2PFhf+nbtmVU5zwVPk7DZ6l Nn/g== X-Gm-Message-State: AOAM5309VXm4eKxqmp+VsYrdmsSMNV6da+0s+fZeh1xHxOTta6ecGvmu jM3EWHIqZD3JiBhDxYxWQ5zS7g== X-Received: by 2002:a62:3003:0:b029:28e:74d9:1e16 with SMTP id w3-20020a6230030000b029028e74d91e16mr59428pfw.21.1622143514581; Thu, 27 May 2021 12:25:14 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id j17sm2566731pff.77.2021.05.27.12.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 12:25:13 -0700 (PDT) Date: Thu, 27 May 2021 19:25:10 +0000 From: Sean Christopherson To: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 43/43] KVM: x86: Drop pointless @reset_roots from kvm_init_mmu() Message-ID: References: <20210424004645.3950558-1-seanjc@google.com> <20210424004645.3950558-44-seanjc@google.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 Thu, May 27, 2021, Sean Christopherson wrote: > On Fri, Apr 23, 2021, Sean Christopherson wrote: > > Remove the @reset_roots param from kvm_init_mmu(), the one user, > > kvm_mmu_reset_context() has already unloaded the MMU and thus freed and > > invalidated all roots. This also happens to be why the reset_roots=true > > paths doesn't leak roots; they're already invalid. > > > > No functional change intended. > > > > Signed-off-by: Sean Christopherson > > --- > > arch/x86/kvm/mmu.h | 2 +- > > arch/x86/kvm/mmu/mmu.c | 13 ++----------- > > arch/x86/kvm/svm/nested.c | 2 +- > > arch/x86/kvm/vmx/nested.c | 2 +- > > 4 files changed, 5 insertions(+), 14 deletions(-) > > > > diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h > > index 88d0ed5225a4..63b49725fb24 100644 > > --- a/arch/x86/kvm/mmu.h > > +++ b/arch/x86/kvm/mmu.h > > @@ -65,7 +65,7 @@ void kvm_mmu_set_ept_masks(bool has_ad_bits, bool has_exec_only); > > void > > reset_shadow_zero_bits_mask(struct kvm_vcpu *vcpu, struct kvm_mmu *context); > > > > -void kvm_init_mmu(struct kvm_vcpu *vcpu, bool reset_roots); > > +void kvm_init_mmu(struct kvm_vcpu *vcpu); > > void kvm_init_shadow_npt_mmu(struct kvm_vcpu *vcpu, u32 cr0, u32 cr4, u32 efer, > > gpa_t nested_cr3); > > void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly, > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > index 930ac8a7e7c9..ff3e200b32dd 100644 > > --- a/arch/x86/kvm/mmu/mmu.c > > +++ b/arch/x86/kvm/mmu/mmu.c > > @@ -4793,17 +4793,8 @@ static void init_kvm_nested_mmu(struct kvm_vcpu *vcpu) > > update_last_nonleaf_level(vcpu, g_context); > > } > > > > -void kvm_init_mmu(struct kvm_vcpu *vcpu, bool reset_roots) > > +void kvm_init_mmu(struct kvm_vcpu *vcpu) > > { > > - if (reset_roots) { > > - uint i; > > - > > - vcpu->arch.mmu->root_hpa = INVALID_PAGE; > > - > > - for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++) > > - vcpu->arch.mmu->prev_roots[i] = KVM_MMU_ROOT_INFO_INVALID; > > Egad! This is wrong. mmu->root_hpa is guaranteed to be INVALID_PAGE, but the > prev_roots are not! I'll drop this patch and do cleanup of this code in a > separate series. *sigh* Jumped the gun, I was right the first time. kvm_mmu_free_roots() does invalidate prev_roots[*] via mmu_free_root_page(). I still think I'll drop this patch from this series, I don't think there's anything in this series that is needed to purge @reset_roots. for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++) if (roots_to_free & KVM_MMU_ROOT_PREVIOUS(i)) mmu_free_root_page(kvm, &mmu->prev_roots[i].hpa, <-- tricky little devil &invalid_list); > > > - } > > - > > if (mmu_is_nested(vcpu)) > > init_kvm_nested_mmu(vcpu); > > else if (tdp_enabled)