Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2136444rdb; Mon, 20 Nov 2023 03:08:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHK5nKDPZrCXJ0Z8Ypkfno7tuutgCh8S/ph3KqaN1j14zGHIGsFytvs4ncymfnsRVVrnYnC X-Received: by 2002:a05:6a00:1806:b0:6cb:8dba:ce6c with SMTP id y6-20020a056a00180600b006cb8dbace6cmr2683539pfa.18.1700478528226; Mon, 20 Nov 2023 03:08:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700478528; cv=none; d=google.com; s=arc-20160816; b=rt3XSkJNDXh2OYln5ja54YNUjmZQegwOc+u/Oh1x1uqVFxVulhG95h/XLD9p06iInD NCldsxc9fqPzn9ExBYd38e2QYeBURIXQ9kZqKt9g6AVLmZaSYZI/YA/gLFFzvPNdFu+D 1BnZKi1mkCWgwna/g2hM5TxGJZsGJlk0nJuKmmrAtSaBY/v4Hv/2bkRksptje3Jv6J8o jEqML+H0hk0gMdZfl6VjfeTky99EEK/zP+YUuQgg82Z+7b7ewY4OzqQG9ngvp7Szvsj/ q+dJdG9G91YRIp+22rv9GLlKxQxnmxYnx4pSQhkAwkPBv+KZDmc/zB6sGDX5KjfqGHRV R1EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=FK+8QQsGIpBGEYh+wDbNXhOp1PgweoR4NPRvQmJrRDc=; fh=SSl64FBK0Lhy77ytVxLm3gRT6oITPT9jTW5tmAf+4Dk=; b=QKCZO8hF/gfhU3QdofuqlyylLUv8m34R4jHCovlxx4ES/IataU+JuGKwDJmBcWl5B9 4/KJyxsf2J3EnmLl0S+j/kt/pQo1uLLyfv5ZVUjBZl8jrdFTbPzSzXZYaq5KdjwUYdIY eaCVBDRdsIdOHM/JjUxuTmAQ05SPaQXpvwc1kFZoSC3UYRwfIKsZz/iJ9l0BISVAueH9 sXIrDeCuOGb1gF27FirspWeKYHzDVubg6gwLxw53SBIYj+FOWgfogtNa9eugoHWfvfcW LbsOjpNQEUQKSU+DI5C8uAAsyjlpuI+4ARSesjCvAgYtzALFgsLdO+cOq5mEYhz1mu6V qfVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VJ6302By; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k2-20020a633d02000000b005bd2ab86667si8180212pga.651.2023.11.20.03.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:08:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VJ6302By; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3DAC580792F0; Mon, 20 Nov 2023 03:05:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232711AbjKTLFw (ORCPT + 99 others); Mon, 20 Nov 2023 06:05:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232663AbjKTLFv (ORCPT ); Mon, 20 Nov 2023 06:05:51 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 326A3CF; Mon, 20 Nov 2023 03:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700478347; x=1732014347; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=kLUkhWA7nu+d56b6TrdPL9i8bfhz5RDkdDJy89fQBCY=; b=VJ6302Bya1nSXxSY5oWfiZgiMtQzfJfPjaMVbb97jYgFs47b89zuQPyr Q780LVUGB0hFczIQJ1N00Wq2PFnd8XC09IO0XsY4AYCkveh3uVjyu0ud7 aqBVDNC2HEep3QayhCIBf18wmyz9UTSal9gjWGNqzdzZvOOJhj3sfcHrA HdyZCsLd0R+JLCOXmXssNHxyGEXn+BdQ4TVGjVu/vEwehVWlbzdb0wf+4 Y9trZ/ibT/AFpsQ/HBK3MRGE2ywKjuvihwjwVqrE4cNQ27uf9JQyroTwg UdRS14MLU/YUGvBKW/c5QAXTTkMUh3B9zbYY7FEQYYA2GGk012/z3/2Wj w==; X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="477807616" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="477807616" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:05:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="7521450" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.93.8.180]) ([10.93.8.180]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:05:42 -0800 Message-ID: Date: Mon, 20 Nov 2023 19:05:39 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 08/16] KVM: TDX: Pin pages via get_page() right before ADD/AUG'ed to TDs To: isaku.yamahata@intel.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Xiaoyao Li References: From: Binbin Wu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 03:05:57 -0800 (PST) On 11/7/2023 11:00 PM, isaku.yamahata@intel.com wrote: > From: Xiaoyao Li > > When kvm_faultin_pfn(), it doesn't have the info regarding which page level > will the gfn be mapped at. Hence it doesn't know to pin a 4K page or a > 2M page. > > Move the guest private pages pinning logic right before > TDH_MEM_PAGE_ADD/AUG() since at that time it knows the page level info. This patch looks strange, the code has nothing to do with the shortlog. It seems that the change of this patch has already been covered by 06/16. Something went wrong when formatting the patch? > > Signed-off-by: Xiaoyao Li > --- > arch/x86/kvm/vmx/tdx.c | 15 ++++++++------- > 1 file changed, 8 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c > index e4167f08b58b..7b81811eb404 100644 > --- a/arch/x86/kvm/vmx/tdx.c > +++ b/arch/x86/kvm/vmx/tdx.c > @@ -1454,7 +1454,8 @@ static void tdx_measure_page(struct kvm_tdx *kvm_tdx, hpa_t gpa, int size) > } > } > > -static void tdx_unpin(struct kvm *kvm, kvm_pfn_t pfn, int level) > +static void tdx_unpin(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, > + enum pg_level level) > { > int i; > > @@ -1476,7 +1477,7 @@ static int tdx_sept_page_aug(struct kvm *kvm, gfn_t gfn, > > err = tdh_mem_page_aug(kvm_tdx->tdr_pa, gpa, tdx_level, hpa, &out); > if (unlikely(err == TDX_ERROR_SEPT_BUSY)) { > - tdx_unpin(kvm, pfn, level); > + tdx_unpin(kvm, gfn, pfn, level); > return -EAGAIN; > } > if (unlikely(err == (TDX_EPT_ENTRY_STATE_INCORRECT | TDX_OPERAND_ID_RCX))) { > @@ -1493,7 +1494,7 @@ static int tdx_sept_page_aug(struct kvm *kvm, gfn_t gfn, > } > if (KVM_BUG_ON(err, kvm)) { > pr_tdx_error(TDH_MEM_PAGE_AUG, err, &out); > - tdx_unpin(kvm, pfn, level); > + tdx_unpin(kvm, gfn, pfn, level); > return -EIO; > } > > @@ -1529,7 +1530,7 @@ static int tdx_sept_page_add(struct kvm *kvm, gfn_t gfn, > * always uses vcpu 0's page table and protected by vcpu->mutex). > */ > if (KVM_BUG_ON(kvm_tdx->source_pa == INVALID_PAGE, kvm)) { > - tdx_unpin(kvm, pfn, level); > + tdx_unpin(kvm, gfn, pfn, level); > return -EINVAL; > } > > @@ -1547,7 +1548,7 @@ static int tdx_sept_page_add(struct kvm *kvm, gfn_t gfn, > } while (unlikely(err == TDX_ERROR_SEPT_BUSY)); > if (KVM_BUG_ON(err, kvm)) { > pr_tdx_error(TDH_MEM_PAGE_ADD, err, &out); > - tdx_unpin(kvm, pfn, level); > + tdx_unpin(kvm, gfn, pfn, level); > return -EIO; > } else if (measure) > tdx_measure_page(kvm_tdx, gpa, KVM_HPAGE_SIZE(level)); > @@ -1600,7 +1601,7 @@ static int tdx_sept_drop_private_spte(struct kvm *kvm, gfn_t gfn, > err = tdx_reclaim_page(hpa, level); > if (KVM_BUG_ON(err, kvm)) > return -EIO; > - tdx_unpin(kvm, pfn, level); > + tdx_unpin(kvm, gfn, pfn, level); > return 0; > } > > @@ -1633,7 +1634,7 @@ static int tdx_sept_drop_private_spte(struct kvm *kvm, gfn_t gfn, > r = -EIO; > } else { > tdx_clear_page(hpa, PAGE_SIZE); > - tdx_unpin(kvm, pfn + i, PG_LEVEL_4K); > + tdx_unpin(kvm, gfn + i, pfn + i, PG_LEVEL_4K); > } > hpa += PAGE_SIZE; > }