Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3429817imw; Mon, 11 Jul 2022 08:29:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uFUfAK8ZsOeBKofg0oGhJkidRcbdu5OFJ0uKY9EVSgOEPr1JP7rnFfrSbWJwZUGiy4kQMN X-Received: by 2002:a17:902:ecca:b0:16b:d519:d1df with SMTP id a10-20020a170902ecca00b0016bd519d1dfmr15346199plh.170.1657553395275; Mon, 11 Jul 2022 08:29:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657553395; cv=none; d=google.com; s=arc-20160816; b=x2XR5GYnt8P3hLqmS+qYcl8iVeX5OBzoZFV0Y4ow91MmNbxM2rm5/ugiatVEEfTgBv ykjmi1oceQ9wskB35P5wSvrWM8KmjFr+MQkQVM1hiWw0Qeesrdg+S3ToSsXLtQmZ1xWW HnAZaMtdABFbv7Fwf4bIp9HBlqPFALURMofh8aJW5fRGM6wO3GFBkd3q3cr2me2PyvH1 LDUpRKM/kSzQR/q3hG7J5bb95bAW7wYP3yVwINAng2hnECqOFhpNTtEbdbhUjqlSUERe 2KzkGc8VzeJEQSUOCwG/etNyHSdiwlOYxpxDq0Wd4rT+FrpiQqAIgSQfg66hxPj+bafW VNMA== 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=4chYHKGMXvFRAL0720LnjWx1zElGjVyxHR36HOxWZ70=; b=nDRWnBdorY5DPHFOxwS7Jeo+eE1CHL34tkVsv+bB7Ad9ZtTIz1Q3pEWah++rAiQN+R Z1mF+7JLJfxJb+Mn4ShAS1O3cpiMd5ASzB344Ve4nBz8g9QrsCr5cXNhZ91KdgfkiqMv j5qy/+gW2G67bO81a4fp3iAQdXJCeOR4IuJj6vHgLKpObuWDi/gKvPQvIUrREHFIjuP3 ch8bpHUdGxxtokgHcw+PHY0EGyQ9+EA5ogg9LgY8vU2Uvf48W8oBh4SCersojt5ZiB5P V46WruRyZF/NADKWjVoPqXJSkWPa7hGPPFvYLgOIGG3DO2P665+i5ttgjE3XKjKDU7XK 7bEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=m36etuUJ; 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 b6-20020a170902d50600b00163fbb1f1fasi12918590plg.252.2022.07.11.08.29.43; Mon, 11 Jul 2022 08:29:55 -0700 (PDT) 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=m36etuUJ; 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 S231678AbiGKOrX (ORCPT + 99 others); Mon, 11 Jul 2022 10:47:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231704AbiGKOrT (ORCPT ); Mon, 11 Jul 2022 10:47:19 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2BC16E882 for ; Mon, 11 Jul 2022 07:47:15 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id bf13so4894058pgb.11 for ; Mon, 11 Jul 2022 07:47:15 -0700 (PDT) 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=4chYHKGMXvFRAL0720LnjWx1zElGjVyxHR36HOxWZ70=; b=m36etuUJx0HQcE5/Pqbd+7RhmxNhM0wdYBGcdQB9kFYMZ8vl2+DHoICoYTNvO35rJu uH+YoxZh4O4EvgzA0XJjwTK47tTew2Mp5yF1nPsrm+EjvolweI3zLx3I60tHIGl5ZfD5 VqUwnGXfYyq9JtwJ9RxEIDB7NGJxnIyNv5MQA6H/8QLjopH81hbDV8Oq4Rc34V0ZVqd9 VyvIY7Y/LRFwa3WFOzsFJI7ESh9YUVoUfp5VhFfU/yOgAmk+AS9UTD5GDbimOwGRZfeM 1OUjekj8gaOHnKrCeT9P1FoYq5nLhEFr7s5z/nsa7dAfDIrpunwl4dl2alsyJb9BYd00 GVcA== 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=4chYHKGMXvFRAL0720LnjWx1zElGjVyxHR36HOxWZ70=; b=Lg2QOGJTx/ZIrC/Eg+tHOhPO/slOef5YzlnRc3xicPMsyoBhJsBDHpqnmIu7ZEjzPJ BxSh9Tc4JZpugM1GBGGTptWGTVal70biI8eUpe0WJON9zajhycMj3tyvD05WI0+nCfD5 /Tr1I8/z66VlfScjCgQ2TmNfF2GsJQdr1DxaIbXqWi9KOmygbksR8b2L51k3uhY/6yyC rBhobxoO7tSHgtbl1F5AKz16NcZWfoqrITu5btV1r1dOPddH5FTuLQo1TgeJyH5XyveX Iyui+uMZcMY47FNUw3UycQ8PBZmi/RAvcbelG8/9ILCle7dFzK/XiZScBqmRuk/2QBJG S0EQ== X-Gm-Message-State: AJIora8x5+X7N0OZGIWkAdKMUMgY34hmmr8mNyqjn2K52fLraRgN7OoD IewSkrJypaYWhjMJIS23sHZ+WA== X-Received: by 2002:a63:d54c:0:b0:412:562e:6964 with SMTP id v12-20020a63d54c000000b00412562e6964mr16043982pgi.528.1657550835031; Mon, 11 Jul 2022 07:47:15 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id q11-20020aa7982b000000b005289fad1bbesm5004033pfl.94.2022.07.11.07.47.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 07:47:14 -0700 (PDT) Date: Mon, 11 Jul 2022 14:47:11 +0000 From: Sean Christopherson To: Yuan Yao Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , Sean Christopherson Subject: Re: [PATCH v7 036/102] KVM: x86/mmu: Allow non-zero value for non-present SPTE Message-ID: References: <20220708051847.prn254ukwvgkdl3c@yy-desk-7060> <20220711070510.dm4am2miy5lcwlzq@yy-desk-7060> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220711070510.dm4am2miy5lcwlzq@yy-desk-7060> 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 Mon, Jul 11, 2022, Yuan Yao wrote: > On Fri, Jul 08, 2022 at 03:30:23PM +0000, Sean Christopherson wrote: > > Please trim replies. > > > I'm not sure why skip this for TDX, arch.mmu_shadow_page_cache is > > > still used for allocating sp->spt which used to track the S-EPT in kvm > > > for tdx guest. Anything I missed for this ? > > > > Shared EPTEs need to be initialized with SUPPRESS_VE=1, otherwise not-present > > EPT violations would be reflected into the guest by hardware as #VE exceptions. > > This is handled by initializing page allocations via kvm_init_shadow_page() during > > cache topup if shadow_nonpresent_value is non-zero. In that case, telling the > > page allocation to zero-initialize the page would be wasted effort. > > > > The initialization is harmless for S-EPT entries because KVM's copy of the S-EPT > > isn't consumed by hardware, and because under the hood S-EPT entries should never > > #VE (I forget if this is enforced by hardware or if the TDX module sets SUPPRESS_VE). > > Ah I see, you're right, thanks for the explanation! I think with > changes you suggested above the __GFP_ZERO can be removed from > mmu_shadow_page_cache for VMs which is_tdp_mmu_enabled() is true: Yep. > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 8de26cbde295..0b412f3eb0c5 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -6483,8 +6483,8 @@ int kvm_mmu_create(struct kvm_vcpu *vcpu) > vcpu->arch.mmu_page_header_cache.kmem_cache = mmu_page_header_cache; > vcpu->arch.mmu_page_header_cache.gfp_zero = __GFP_ZERO; > > - if (!(tdp_enabled && shadow_nonpresent_value)) > - vcpu->arch.mmu_shadow_page_cache.gfp_zero = __GFP_ZERO; > + if (!(is_tdp_mmu_enabled(vcpu->kvm)) > + vcpu->arch.mmu_shadow_page_cache.gfp_zero = __GFP_ZERO; > > vcpu->arch.mmu = &vcpu->arch.root_mmu; > vcpu->arch.walk_mmu = &vcpu->arch.root_mmu;