Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4806357iob; Mon, 9 May 2022 02:00:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvmzVMbGa2XR5AxJfpFpjAXrLKE4aprHgVA0KwH8Q0WT4U2Wcd+zccI2jE6hR3BqHom1pP X-Received: by 2002:a05:6a00:88f:b0:510:7a49:b72f with SMTP id q15-20020a056a00088f00b005107a49b72fmr14767327pfj.21.1652086807740; Mon, 09 May 2022 02:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652086807; cv=none; d=google.com; s=arc-20160816; b=Qro3DNiQvq36D1/UMtyNkBEx7wFIsrM2rsUXB+IrC7RlObGMdAsJMTDtJP3Gj35ffK kOd+bJLRiDnFmkp5yGwJWpkBa+zL9Jqs1ZZLN0QpPzMM870Neeg/oMpwhhWI8ozvK+oW iH3qO7AczlUPheCr3NhHNmf1Uvfd40P8V2HQVd1zgRcVrldgtC1FQc5tYyxiiAuHAR2z KC0zqCo2zE3ymQevg1qJ4DA3AxwlaoLQ6qc99DoTzDTOZmJBC0aAE215Sj+T+haO7Ki8 Y9CBANUGWxL8sjaKHpqRorVJxeDzELa2/35bm3l4xHuZxG9++mqrmkRgeaPSm75VBKF2 Bqxg== 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=eIpnVeUBDTL8ZejuPvZYatyB5jJC7OU3SsQxLfx6EA4=; b=Jr4wnSH13BxTNiE2UySbi2iTdmjzBK9nh9GoBOEmLoqG2O8fwE4u1fDtjLBGhf0HZY zXL0YcwGfy3BnOXbUk6QrSuoFhn+WEDayhpOuPoTJmSUbcYWUjnhzsGsNejsB6H2UEQX e/ABpEdMRHXxoY8hIfO1GBpLXrPEVZIfQ92RJHqYy7Znp4FMdlC3cWIABtwcjyjRx2c2 oi1nLLjmVgJ0FZuCLqVXvQVLDotVL/LNKVe8+6zg+wUB2RCXhEFq2SBZEnPWtYdaCMsc Ons3/N+7goJPnQDi1+WOiptDVyiHF3y0AChG+vUJQejq6mVGQa/hsX85nL6ZGR3Q2/Qh 4R7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nlFjGtGZ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y70-20020a638a49000000b003ab019ed015si13542984pgd.533.2022.05.09.02.00.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:00:07 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nlFjGtGZ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D10541A831; Mon, 9 May 2022 01:46:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384028AbiEES1h (ORCPT + 99 others); Thu, 5 May 2022 14:27:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383218AbiEESTl (ORCPT ); Thu, 5 May 2022 14:19:41 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21BFF49684; Thu, 5 May 2022 11:15:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651774554; x=1683310554; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pVoiIWs/KT0rFFHvpPmgf/2kpDklS0hKSk3efqDHWmY=; b=nlFjGtGZMRAjNvI9XnOrWmjdsOFz4O6UL4lFCgryqCUwA6Dh+r4H5A0p rN4DdKBGUs46m0FC0QYMTV333s7di+FkcXVlpI3vBs/f75thpJgGPPwxA ZHZUA4h2TtF6pBikliccu8jm0oOio4Y+Q23tJOxv2TmrPcnyUxUg8bDZH tOEXszZJyhkM4/LuYttXZIbN4MNPubPoE//yuChPHB2A9phcOETQWYUPP XLVZdo6KggMJACAxbejtQm7W3YcoAdb2bG5WgHHQ4S3qGnYYsRw1lLx0f R8Q7sYXRZV+hg4Aj7X24PzBE2HvOXOv6qSz2X9VIYsv4GiCQMUoMGAMRy g==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="328746282" X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="328746282" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:46 -0700 X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="665083298" 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; 05 May 2022 11:15:46 -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: [RFC PATCH v6 046/104] KVM: x86/tdp_mmu: refactor kvm_tdp_mmu_map() Date: Thu, 5 May 2022 11:14:40 -0700 Message-Id: <4744ed20a4d9db95b515559e7525623781261b0c.1651774250.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=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 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 b7e13061e57d..9e015b3e0578 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1149,6 +1149,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. @@ -1157,7 +1175,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); @@ -1203,13 +1220,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