Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3432922iog; Mon, 27 Jun 2022 16:17:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vd26MwvXh3go0gCyhsRH4a1q6LQ7BdTTcdu8dgXcNNav+GBkwoZ7Pk+XHaJsR9u5Gwql8H X-Received: by 2002:a17:906:4f:b0:712:af2:29d9 with SMTP id 15-20020a170906004f00b007120af229d9mr15156162ejg.751.1656371836004; Mon, 27 Jun 2022 16:17:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656371835; cv=none; d=google.com; s=arc-20160816; b=YNR16Oiw9DgL94FxTFkZf/Dv8gLSedRFbO8jBKvC59CEeoDWoOROJN3zQRK4fFtFaE thBEkaNXOF7T10Q7bE6zp0cF/3gEWNgakS+ZZ5Ymg5T1pujivQEmLANpaz7eKvqHfIVL PgswTFv749fVnh2Yp6qI96Mjo2NDT+83k54M8hevgW+hDJN7JW+LnIHUcjivjZWYG6bz WC2TWcCF29Xilux3f7v7TUmYOlZcYorLs2hPNki8HftaI3Pq/GM0IUIXXEi7w7wBaOt7 bI4pnl/Acjd8nCFuALanwI5QOPTQHM8J7QJaRlBsXCkuhuSvn0q1bAIJx976kc0NjsvV rNqg== 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=kJQ8uic51T/XViLGbxwP9hHId7D3cQlt8W+5T7sNeSI=; b=TUGdUSKTbgt/ht8h4tIlGcq0O9F/MiUNFMYUuD/AeQkoBlssULjvTeuSB6r7gvfTvQ J5g4gI3hNLi9xbLjT/AJpjqahYAWdMLIdmJ9jW5aFYtolAINlW77w/0k6dsmE9H8pVQM h1wRgmG2hei3HnCEAQ6Ns52H4e6iADuuRpl+AWPWLj4AHqsQwJ79Bl5iaZ8ly/EecbgC S/3b3RdqZ7kaNGJNKrMjUJyCxv7CTKEhebJDSVQ39MeLirWiRTtsciBgr74lp9OMoiks w05KiuSfdnC8JN4VZB7vUjnLbLwFszYkBIaC2CBCI0QKvqivBn4TGuxfOVUn3z6Hq2wF stkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=htpbHsEm; 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 la3-20020a170906ad8300b00711ee53603esi13053222ejb.595.2022.06.27.16.16.51; Mon, 27 Jun 2022 16:17:15 -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=htpbHsEm; 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 S242040AbiF0V65 (ORCPT + 99 others); Mon, 27 Jun 2022 17:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241444AbiF0VzL (ORCPT ); Mon, 27 Jun 2022 17:55:11 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D8D36575; Mon, 27 Jun 2022 14:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656366899; x=1687902899; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YCcHmggMtwAeLv3YsLtGRVNWucYv30TZgo0KUbnpCbk=; b=htpbHsEmQh/UHbGUXGAkmXPIXG31EUfEO9wbT934ZhdS5S7w9r2NsOWF e3mAuYhp4iDz4Xs3VE/yeFcbw9CGSftOLEA9whOr6ri9Zo8wHwZuYOlQ2 hcl/ErtapJwOUzbWQA4GNS7gR1y/DuVgGKM7anOEgqAQvP66iXqrq53Lg xx2Rj1fT6J31YW2cWkFRo2WJ5v4jBaa9FT3nDnqHnPBSB0uQacN7kHuwA 2KB3aOblSi2ZdwKZazKZVUUcOK9W8oHt3DVR8ebN/uCEr/iMxv1USuUK6 Y77+qRgMrDFh1xVWsTSrt5kJebHYIoUzSNrBdbUNfof/DCzEfGx4McWh6 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="281609564" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="281609564" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:54 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="657863581" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:54 -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 Subject: [PATCH v7 045/102] KVM: x86/tdp_mmu: refactor kvm_tdp_mmu_map() Date: Mon, 27 Jun 2022 14:53:37 -0700 Message-Id: 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=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 b2568b062faa..d874c79ab96c 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1167,6 +1167,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. @@ -1175,7 +1193,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); @@ -1221,13 +1238,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