Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4117816rwb; Sun, 7 Aug 2022 15:33:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR7gv/YPsoCyvgTc+GRErAO2VoxsmeviUYEl1BwaZpebZRf2YT3xh8wlcheRIFxDVhvuF1ge X-Received: by 2002:a17:902:f78b:b0:16a:4ad:f359 with SMTP id q11-20020a170902f78b00b0016a04adf359mr16128011pln.99.1659911612755; Sun, 07 Aug 2022 15:33:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659911612; cv=none; d=google.com; s=arc-20160816; b=PHl4WaLv1eWrE9Bx5ZiZl+YafKaR6rVuguRD/WQB+GryiD1spTK+GyQ+tMukaU3HAR cAQnFctBGlR3WSrhkkvGK2i/XArsaQxPNcP7Eun/oOoLC//2y8rAsO+4Nas6sh/jF/yE +908kPKeaZGSf5qTYtdTRomvK9Cj/Klg4M9bID2NdSYLxsqR8fEd6xSjcJdGjL+Gnc6z M2spuHW2bTXRs6hMpZhHRd6Z8eOCd2ovBNMtRH9W/GwmvIcTGMloKBEl1E6Bllef2XBE MryIWl/yTp93Xtk18BfSj07XgNPwtqcRN8RC/hd3ukZcFASQbunt7MhsW1ke7RyMQKHx WGsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rcWSXS+pZkOtX6dV9Ov9oYNudkpWTvW0qGaBYIZkKdw=; b=ozNGp89FXbw6S68kercucOcBz2p1C7P3M8zYJ/26TnN6zTeU4IaMh0IQQh1AZb7z1v 4P+aDepgpp8sncavi3sY6wUAfJSkpC0ChWnyqhFNcAaclXAf6FRip5jYi20ltxm7oNIw zn6TJGh6mdYr1j+npHeOwfCaLsc5yWM23+tsafTVAJ2Ev4j526GHOpJh+dA6eMWPM3iN 4ae1xbwx3+0l48Yr2Vtx1ruSS5MeY3N2IEASrJ0InE2vq+7gCHvbUOaY/52vfdtBFg27 c+GMCtRHeuEueOZ7K4xoiRm6etnMCHRnwiDewQhI8t5w3ikJZ6s6KJ1RZjqvZgMfs3pA Qlcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cZqYeOS8; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u8-20020a056a00098800b005186df822dfsi10111726pfg.378.2022.08.07.15.33.19; Sun, 07 Aug 2022 15:33:32 -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=@intel.com header.s=Intel header.b=cZqYeOS8; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242080AbiHGWJF (ORCPT + 99 others); Sun, 7 Aug 2022 18:09:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236432AbiHGWEU (ORCPT ); Sun, 7 Aug 2022 18:04:20 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02364B48C; Sun, 7 Aug 2022 15:02:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659909774; x=1691445774; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mFQa8eTHQqRGxpnGOtA/K1vSOToebRgj88qGFnjbHEo=; b=cZqYeOS8E4H1Pvk/mA1zWDLQ8XHpfuL5yz9FA804uK6ZcN0SEJ99Nl81 MU4KrguWT493k8b4GD0ZqBVaAwmCA1nAbvsI/vih07EXrJHQvDjlPNJ8M SYT63HZ6OCNCzorzvNjyea6B/HoqIdJb34rsWvmOajCIAI7OtHUb8YtoW euHXoyarerwEF1glJUpWKf4anLFNMBtVZMIMRs0mEosGM+pm4tN4aSyY2 7rCBiIIZV4cnWEaC4MPXsmkCgEWwkmM10j4Y4BNkkha0B1LJ8T76XpuIt d1+kdbB9MSC6ByXDnS603xOg8uVn+ic/Mk+5Ody0ra6gp6p05J53Ckaw0 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="289224123" X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="289224123" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:34 -0700 X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="663682562" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:34 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar Subject: [PATCH v8 038/103] KVM: x86/tdp_mmu: refactor kvm_tdp_mmu_map() Date: Sun, 7 Aug 2022 15:01:23 -0700 Message-Id: <021cf72b904933f23743d74b2a67341298ae5328.1659854790.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 From: Isaku Yamahata Factor out non-leaf SPTE population logic from kvm_tdp_mmu_map(). MapGPA hypercall needs to populate non-leaf SPTE to record which GPA, private or shared, is allowed in the leaf EPT entry. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/mmu/tdp_mmu.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 8bc3a8d1803e..90b468a3a1a2 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1145,6 +1145,24 @@ static int tdp_mmu_link_sp(struct kvm *kvm, struct tdp_iter *iter, return 0; } +static int tdp_mmu_populate_nonleaf( + struct kvm_vcpu *vcpu, struct tdp_iter *iter, bool account_nx) +{ + struct kvm_mmu_page *sp; + int ret; + + WARN_ON(is_shadow_present_pte(iter->old_spte)); + WARN_ON(is_removed_spte(iter->old_spte)); + + sp = tdp_mmu_alloc_sp(vcpu); + tdp_mmu_init_child_sp(sp, iter); + + ret = tdp_mmu_link_sp(vcpu->kvm, iter, sp, account_nx, true); + if (ret) + tdp_mmu_free_sp(sp); + return ret; +} + /* * Handle a TDP page fault (NPT/EPT violation/misconfiguration) by installing * page tables and SPTEs to translate the faulting guest physical address. @@ -1153,7 +1171,6 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) { struct kvm_mmu *mmu = vcpu->arch.mmu; struct tdp_iter iter; - struct kvm_mmu_page *sp; int ret; kvm_mmu_hugepage_adjust(vcpu, fault); @@ -1199,13 +1216,8 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) if (is_removed_spte(iter.old_spte)) break; - sp = tdp_mmu_alloc_sp(vcpu); - tdp_mmu_init_child_sp(sp, &iter); - - if (tdp_mmu_link_sp(vcpu->kvm, &iter, sp, account_nx, true)) { - tdp_mmu_free_sp(sp); + if (tdp_mmu_populate_nonleaf(vcpu, &iter, account_nx)) break; - } } } -- 2.25.1