Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3841770pxj; Tue, 11 May 2021 13:08:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxR1zfnkc1Ddm88sQbxXnMQ8wG5zHPybRH3r85M7nntNKyBhfeDTfGax32YBgDrgt/xiBK3 X-Received: by 2002:a05:6402:17d9:: with SMTP id s25mr7219683edy.337.1620763698859; Tue, 11 May 2021 13:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620763698; cv=none; d=google.com; s=arc-20160816; b=Q33a0opn/Iuqcl0iBHCBTKBb1NiOr19QwutOjnaUaVfTyv2GQkqP93mD9tR+TvyoGb pLP9g76sdXR69TTDL3uLk8qskmynLIDQenmjy26WYvAi3QBKeoOx0FDxxnW+uKOT5wDq BmX5z7l2Pul3K7Sx42n6W7rThJJ89i4O7kGxjHP0t5sCIrOch69xifhkDW6ovd+WVSo8 rvxfoTnTytggrXLrRkPoTe6zufkpq3E6qZ0n+Eczb0cyGS0G+fnOq3p16Wxy0XxPyepB RkqsBP7/ukJGatefytmAwkD2NeSaiWyhORQOMNz9Fp6nHgBF58oCsYWtwNcGpqznhYTH NvUg== 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=JsnqFKIC2tGbo9fUD1ZGMSarx8qK1pajpyGE4uvcpZM=; b=TmkHaLPzV75EboZkvAbXQUiO6gRDLMpPgDC1qkIZragUr4kPrNQdvg44LmnbY8O/Nj xIG4+QafeIarwr3hg41MCumKeZB88v1+H3thXiR3/5Ff/QyE3BHS8VDorQANuTYjfFMD mzGUYLc2dwg5l9v0cILW2HMqMhTR8xw+Vj2LKIZH6g2GAknPUc7R8/uRqH0x3/sT+mXW RUDtd/iH8NPCS+f1R38IR+sWZ/Vkqpmq1iBZF19kHxRmoeXKLTpdsIm+RNrNn/PAPMA7 /wG+MGhQGSdh68zOzr50JBBB6/gItD85t4uNApnJpNuJwshdVanPbjaOiwCz9CVsrAJ0 4sww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ym1qO0z3; 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 ch7si17615748ejb.164.2021.05.11.13.07.54; Tue, 11 May 2021 13:08:18 -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=Ym1qO0z3; 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 S229973AbhEKUFq (ORCPT + 99 others); Tue, 11 May 2021 16:05:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229934AbhEKUFm (ORCPT ); Tue, 11 May 2021 16:05:42 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C1B4C061574 for ; Tue, 11 May 2021 13:04:32 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id b21so9771723pft.10 for ; Tue, 11 May 2021 13:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=JsnqFKIC2tGbo9fUD1ZGMSarx8qK1pajpyGE4uvcpZM=; b=Ym1qO0z3wRDaV4Gx4Brtsa8x8M8SU+4hIdkXIRpGZrgtJm18UBlQBiNyKGGWWKq59M fi+8zW1hssLlj0Kkj3uY2lxK3qkXF3yULAD3iIKGzgT5jp9usBej3WqqAdzQlTK8TAft uGjqwoXBMbyYHIbil1nqLb6abMS24h6Bdz2EAx1I0MI7DxAJB/OFbbEe2atP/+KpBo+S m1Pu4IoOLll6J2cpH3xSCbBkzmDzoLvZO/YkWGKSxk2SICDz8XTCJ9diu1Fbxj7iAQYr w5SBDsU5+rW68vctwmzBuP0xO7PyACduokmPS5JdRJwC+QnauraDSA/lzLMo5uLklV9X 4zgg== 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:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JsnqFKIC2tGbo9fUD1ZGMSarx8qK1pajpyGE4uvcpZM=; b=UuUSYj+bmtyggBUz4F8TCwsb7BbcQqUyJScrSa6oTnWlu2J8rBZ7vtPguUSxldiv4g GqaFygU0cXqlOQaGHjgoBaiBDQ0SOgTCIvHsssVqlAAC8yezv+cC9EenaLNmASVwjeky lUeyMCx0LDriKylYQrgE5BHK66pRBSiNjxAO0NX6uhQkxp3lYteLdMyH+i+YO/3kGcgD c4OqhBeyYS/mEQTrmwcsPJ6HCisYK+bIIaxd+TJbsiU+Q2PpnMm0HaTB1NRnDieQ58NS 7wSdYayoiLvc4hO0AvKDsCttZ5dwxGknKbfGfBaQh43Z49zpxUIBnMhwM+WwRcovDl+t AwEg== X-Gm-Message-State: AOAM5320Km7L2ycFMnXVOT/UV1yD+EUaJ5TRI2MJOL+YG7q4dWck+Aqg 94t+KdiThkDlFMIr+E6LS6xQCA== X-Received: by 2002:a63:465b:: with SMTP id v27mr32643961pgk.445.1620763471537; Tue, 11 May 2021 13:04:31 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id s14sm1391586pjp.16.2021.05.11.13.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 13:04:31 -0700 (PDT) Date: Tue, 11 May 2021 20:04:27 +0000 From: Sean Christopherson To: Ben Gardon Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Peter Xu , Peter Shier , Yulei Zhang , Wanpeng Li , Xiao Guangrong , Kai Huang , Keqian Zhu , David Hildenbrand Subject: Re: [PATCH v4 7/7] KVM: x86/mmu: Lazily allocate memslot rmaps Message-ID: References: <20210511171610.170160-1-bgardon@google.com> <20210511171610.170160-8-bgardon@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 Tue, May 11, 2021, Sean Christopherson wrote: > On Tue, May 11, 2021, Ben Gardon wrote: > > If the TDP MMU is in use, wait to allocate the rmaps until the shadow > > MMU is actually used. (i.e. a nested VM is launched.) This saves memory > > equal to 0.2% of guest memory in cases where the TDP MMU is used and > > there are no nested guests involved. > > > > Signed-off-by: Ben Gardon > > --- > > arch/x86/include/asm/kvm_host.h | 2 ++ > > arch/x86/kvm/mmu/mmu.c | 53 +++++++++++++++++++++++---------- > > arch/x86/kvm/mmu/tdp_mmu.c | 6 ++-- > > arch/x86/kvm/mmu/tdp_mmu.h | 4 +-- > > arch/x86/kvm/x86.c | 45 +++++++++++++++++++++++++++- > > 5 files changed, 89 insertions(+), 21 deletions(-) > > > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > > index fc75ed49bfee..7b65f82ade1c 100644 > > --- a/arch/x86/include/asm/kvm_host.h > > +++ b/arch/x86/include/asm/kvm_host.h > > @@ -1868,4 +1868,6 @@ static inline int kvm_cpu_get_apicid(int mps_cpu) > > > > int kvm_cpu_dirty_log_size(void); > > > > +int alloc_all_memslots_rmaps(struct kvm *kvm); > > + > > #endif /* _ASM_X86_KVM_HOST_H */ > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > index b0bdb924d519..183afccd2944 100644 > > --- a/arch/x86/kvm/mmu/mmu.c > > +++ b/arch/x86/kvm/mmu/mmu.c > > @@ -1190,7 +1190,8 @@ static void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, > > kvm_tdp_mmu_clear_dirty_pt_masked(kvm, slot, > > slot->base_gfn + gfn_offset, mask, true); > > > > - if (!kvm->arch.memslots_have_rmaps) > > + /* Read memslots_have_rmaps before the rmaps themselves */ > > IIRC, you open coded reading memslots_have_rmaps because of a circular > dependency, but you can solve that simply by defining the helper in mmu.h > instead of kvm_host.h. > > And I think you could even make it static in mmu.c and omit the smp_load_acuquire > from the three users in x86.c, though that's probably not worth it. > > Either way, reading the same comment over and over and over, just to make > checkpatch happy, gets more than a bit tedious. > > That would also allow you to elaborate on why the smp_load_acquire() is > necessary, and preferably what it pairs with. Belated thought: you could also introduce the helper in patch 06 in order to miminize thrash in this patch.