Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3463322rwb; Fri, 30 Sep 2022 04:06:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5TLuyTZX0lrnsjnsJs5rNyBF1ql+38rsubkOODjOlDtSJLbsJOvJ57TUgGEH6GLCXzXPjc X-Received: by 2002:a05:6402:5489:b0:43b:b935:db37 with SMTP id fg9-20020a056402548900b0043bb935db37mr7572855edb.347.1664535988818; Fri, 30 Sep 2022 04:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664535988; cv=none; d=google.com; s=arc-20160816; b=J+ICy26wpaL8rYCIhKrYtyTsVowiwdwgDt/lruQYJFWjBRkbCMRSSRlkGscHMHtj0b A/KyRrFgM0nLq6ZRwu+3S3BRCTQPPkfg1OH9PUCpkRavdrwuRhmTHD5olQucg2Vno3is 2+9LncYX1xqZ3H8dOT6gP5GbeJwT9cYCse2higOIj+4dDb9c4d9FgxMwgnQnTC/Y+483 lLPhAf8X36QLAMUomkAZl3ScrtwcIFPt3pVEyCYUdBx9vxtVdZvF2QCME21sjjWr7hLb 34PlCQJqrsIC8RtXPNKCueH7B7pZtKp5d0NZHokcDtsDGltBn9Pa6oSAZIqtk7Dzeffs AGwg== 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=pokwM2/n4JSOfwswF2kq7jvW7R4dkoUU48/AcJrEytQ=; b=KGyi1sdOvg/XIOTPaJeaIVsmIkVNlHktTDaAEd53BQdZo4YClfQLbsuq50RvDJ5KGG VRC1VHC5kAo7TXnXU64QY3O5gKzJQnlDc/HMR+HOHv6ZJCgViQKTVAzan0h2PxdOlVHW AQcMRHDrxyo1q4DbiyqCEc+1MZ893QZzydzsCckrussc/K47ocmLti2w6pG8ZHchTBQx AMuYLL9YeJfRe9JRf6YoBJVpTcHKpBjVafqI+5vFovsF2jXUcNb+EEzMN0ygIzH3z7iZ +L1XLMMBY71tSQOqeFmDiKIV7Nd0W1ggcd5NHbYyzfKwXT6KGmZU44nGkrxsjfUn8Q4q lQtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h1ZvlFpS; 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 qu7-20020a170907110700b0077f92be81adsi1311452ejb.212.2022.09.30.04.06.02; Fri, 30 Sep 2022 04:06:28 -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=h1ZvlFpS; 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 S232184AbiI3KWd (ORCPT + 99 others); Fri, 30 Sep 2022 06:22:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231543AbiI3KTF (ORCPT ); Fri, 30 Sep 2022 06:19:05 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F4C916EABD; Fri, 30 Sep 2022 03:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533144; x=1696069144; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wamxAOh4thSrU2qmpuymJBKWtZQH6fNwm0ilxwILaF4=; b=h1ZvlFpS2Q2jqVnndUlKB5m3bkyjUj+vXFfutP2sN/DnDYapf6XCviH5 RvbZYipdk+2p2P6LPu2ATUNTc1Pblo5dBNcYyjz008f8k3yL5FamMXpV2 ExJ7K5NjvYsylVtTJqgggb7wqsc3qPmEOvfIzmpMXPfUhoeEZBWFY+aKw FFCL2LxOY+nbUqQwniEmVzDNj3HiP4ABjEgL2C9ignG4fwyTHqM2/3v03 9LSp1aas6ZRDlBlWKDYZJPVX1VhvEHRCeKo7guCrunNIOuVPI6WcTTmIj GisVQ2QjaQTlE6yC91QLDIGnAr0UZgHOimmYrj0T7H/XrOBimO6hEMnqD Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="281870097" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="281870097" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:18:58 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807631" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807631" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:18:58 -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 v9 040/105] KVM: x86/tdp_mmu: refactor kvm_tdp_mmu_map() Date: Fri, 30 Sep 2022 03:17:34 -0700 Message-Id: <6dbf687ab23f696fa5591818769ee90b0201fe3f.1664530907.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=-4.5 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_PASS,SPF_NONE 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 5ecb976ed954..9e7b18c3f3e3 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; + + KVM_BUG_ON(is_shadow_present_pte(iter->old_spte), vcpu->kvm); + KVM_BUG_ON(is_removed_spte(iter->old_spte), vcpu->kvm); + + 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