Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1435779rwl; Wed, 29 Mar 2023 18:18:58 -0700 (PDT) X-Google-Smtp-Source: AKy350YxGDLBFTVgw/V6xATJPoUoWF2Nlms4+IYYszKq8s31YjVcuV02RtPC2P1JQRt94AE4e435 X-Received: by 2002:a17:902:d482:b0:19f:27fe:95c3 with SMTP id c2-20020a170902d48200b0019f27fe95c3mr24307550plg.41.1680139138357; Wed, 29 Mar 2023 18:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680139138; cv=none; d=google.com; s=arc-20160816; b=f5J2NS/ASTY7T64QRylHdcRhP3RsGLDC8puzLY9xfO0YIPjN+dlbz+qmznViB11qaT 3UpBfG+81Ao0p9bBbvFcCq6XUlbn5xMp1vxBGvcdKeDjWj7eUQ02gDH7AVns77//gFd7 1a4oIRp0+pomF1iv5295cw23T2cJzHKYziNPZVwxNrju/7+gXsEJd9J6GHqaHgK0ZWng jw25ayjsl4wibt+KBe2KttOqSCRxF8uXKEtCYz+yGSg96waDUwmPPuCLmBx4LEP1mZnq /M2pEToWYCsoVsRB9jJrn7N+TyC6tG2AwpUs+46ULFRjCOep26ZBaV0E7cCo5qUrRlvw xIHw== 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=TihRUSuIbcyCr0lFNEjhUbfKbaamQ0uPf3hyuIDE6gQ=; b=Dc1CRZWYIiFTiGGtvMcIbA55jIV0PkfnThYQPKfQ8PtEvYUbNHeIT6OZAsevnz58cJ 4YNmkFUou4S50dqLgtd5tFp/t+f87m3lgySfYsrs67nJ33YvSnO2z6UVB1nyaO91oqdA Fc7KdxgpOvIEgveIaIcrfOKLJoMjqOsxE6L4TFYZatOq76EKdgoxx3gclIbypecTCyzl ClnmVXF/ytWEYPWBwmqwv7Wf1Ng+o7Ts7VJj0Uzren3yPLls3zXvnKUzA+SmvRmmixj+ 6kG4spb6DMYLLX+JFTrLicImTPqR2Cww8YEn/FWAN34coH6/XMYMmxqzvFr3BfpimuMs qKJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RTCry2uE; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a17090341cb00b001a18307d78asi35483669ple.491.2023.03.29.18.18.44; Wed, 29 Mar 2023 18:18:58 -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=@gmail.com header.s=20210112 header.b=RTCry2uE; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbjC3BP7 (ORCPT + 99 others); Wed, 29 Mar 2023 21:15:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbjC3BP6 (ORCPT ); Wed, 29 Mar 2023 21:15:58 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11E0D19A; Wed, 29 Mar 2023 18:15:57 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id z19so16671676plo.2; Wed, 29 Mar 2023 18:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680138956; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=TihRUSuIbcyCr0lFNEjhUbfKbaamQ0uPf3hyuIDE6gQ=; b=RTCry2uEnJf3RnYi048V1AACEOoeINBihN3daGEThrK7Bq+36P6NP1q9dkpULWbie8 uQ+5BgrxGjr7TFybutkeCUNROz8jAAU2iJAYvbAeJat1n3Y84fIlGB5JO8bQN2fILctV weQomRf25JCSNirmMlrZaZXWqMY+Ndlv4D7ywqjsk4uGOFl2jRWEjPrDLVe+qEUwtVb7 gHIGhoXDOIjAZBJu0GAc9dXoeWWsZa95TZ3WNZxAeeqOtwj4ggXyBUQA91tbJh7MSABN 4Q8h5m17gFc6yi4pAJjEumavn5466GH9ZVOjZe9MX8KInbActnX91Mc0xDbj3tPgLqIk M2tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680138956; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TihRUSuIbcyCr0lFNEjhUbfKbaamQ0uPf3hyuIDE6gQ=; b=a97sSIxFPhaBR4gUofMdtd0njRI9NNvGYc0hJree1Mpwtx+Gn12tm6SVTz4HqnK9tG ytGf9e8vmBfWpLBxsvW0Yr7+/9DfE8x4QqcJK4yyiZSJfxa4mRhw7iXP46vj06maKiyx iCFxFyMCSn+UA87kITzduEAPzEsvgxaptBQPZZgpjx5Pmak7yb0a/DrGmuSLDyNa/vqQ Sxqw9ZAZmeWqSa3N0Ly1AbfJM1Ei376djTL7uYXs5DWzUT/QIbctv7AdU5tsFMPuUC5S RWZO6KYYfpewE/wKWYsn/KbeVr4XHP/7VDljvPHUf+6P+XyQTdC92+Q4S3R56CNPWhO6 pd/w== X-Gm-Message-State: AAQBX9dCnhsDQhgfBQ0gMOub4YCto9HApE82OPBoKPCaDpiRm6evN33j 89OAhqtfIauuR2USCUM/IAc= X-Received: by 2002:a17:903:7c3:b0:19c:b4e3:c65b with SMTP id ko3-20020a17090307c300b0019cb4e3c65bmr16884174plb.8.1680138956389; Wed, 29 Mar 2023 18:15:56 -0700 (PDT) Received: from localhost ([192.55.54.55]) by smtp.gmail.com with ESMTPSA id f12-20020a170902ab8c00b001a1a9a5e53fsm6979478plr.136.2023.03.29.18.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 18:15:55 -0700 (PDT) Date: Wed, 29 Mar 2023 18:15:54 -0700 From: Isaku Yamahata To: "Huang, Kai" Cc: "isaku.yamahata@gmail.com" , "Christopherson,, Sean" , "Shahar, Sagi" , "linux-kernel@vger.kernel.org" , "Aktas, Erdem" , "dmatlack@google.com" , "kvm@vger.kernel.org" , "zhi.wang.linux@gmail.com" , "pbonzini@redhat.com" , "Yamahata, Isaku" Subject: Re: [PATCH v13 057/113] KVM: TDX: MTRR: implement get_mt_mask() for TDX Message-ID: <20230330011554.GD1112017@ls.amr.corp.intel.com> References: <20230325011200.GB214881@ls.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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, Mar 27, 2023 at 09:54:40AM +0000, "Huang, Kai" wrote: > > diff -u b/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c > > --- b/arch/x86/kvm/vmx/tdx.c > > +++ b/arch/x86/kvm/vmx/tdx.c > > @@ -347,6 +347,25 @@ > > return 0; > > } > > > > +u8 tdx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) > > +{ > > + /* TDX private GPA is always WB. */ > > + if (!(gfn & kvm_gfn_shared_mask(vcpu->kvm))) { > > Are you still passing a "raw" GFN? Could you explain why you choose this way? > > > + /* MMIO is only for shared GPA. */ > > + WARN_ON_ONCE(is_mmio); > > + return MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT; > > I guess it's better to include VMX_EPT_IPAT_BIT bit. On second thought, there is no need to check it. We can simply drop this check. u8 tdx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) { if (is_mmio) return MTRR_TYPE_UNCACHABLE << VMX_EPT_MT_EPTE_SHIFT; if (!kvm_arch_has_noncoherent_dma(vcpu->kvm)) return (MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT; /* TDX enforces CR0.CD = 0 and KVM MTRR emulation enforces writeback. */ return MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT; } -- Isaku Yamahata