Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1885169pxv; Fri, 2 Jul 2021 15:08:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFAS9fgbIpTw4uvqiL5FoolAvfbq+DlX/3/QBf3SR4PsBm5xwgyXVqdWdpa7eb/SIqjzO8 X-Received: by 2002:a17:906:a108:: with SMTP id t8mr1859816ejy.407.1625263716285; Fri, 02 Jul 2021 15:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263716; cv=none; d=google.com; s=arc-20160816; b=EARGuNe7HhAyzhjW/T+39lngv0eZ76URuh+VpNhd1G6z2ZMhOlwTaDuCgX6GmCqEZ6 PqrPf/gy2eJzFGJMjSa4gsCgBzKLmqAwdVMRZyc+e4abUpqi56RKq13Qo6aFoeSau+Ac MLGmbG5ddkaRx0q2RgDV0KHrg/VepCq6NSKTd+DWgG7UWRmhWA9siTzKbjG/0Q0MJ072 kmIMm9DZKKYY96GO26MGYQHkZ7+rSMAnbdFUU3rDuYJprOfPCYlTLtbIL8WUoDuArlja AW5W4dNEuj06z5TGkrZA0t+MBpvt11xxeqAlD2Pd+L4+TUCap3fVyG7iPjRutVZvhGdE a3SQ== 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; bh=knjuOsCtk9n7x7CPTdEXZw8Qek1QmOMouJu/AX27/4w=; b=xLyI8J+kRk9e59duljmuGqb1yxDfpXg4nBn+3e4WWVYp3BTNOOz9wa/0RXP+87f0Lo IE1V0QL11icKQp+WeZquiTnBjI+A+HlBBtc7qCACHCle44YZ77KcCuVa06Z6mjKRWVr9 TLSClsLGzE1TOUB9cC4Gyj+zVZ+igcMLYMme3c0yA8CLrW69lEtefxofQtOdG8N/bHPX Jdn92Ut5k6Q8el5+yJiHb4fRGu+nS219HgPk6oB9RqSxyy93e739Jrg+2mDflghlSEAT LCnO/y4dxxfdU/eSCbTFMU8V0pOdcEz5gnLpFkmnumPTWP6Y0zzjNM81bGFJAG6rUNox 952g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d21si4262970edz.357.2021.07.02.15.08.11; Fri, 02 Jul 2021 15:08:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233487AbhGBWI7 (ORCPT + 99 others); Fri, 2 Jul 2021 18:08:59 -0400 Received: from mga17.intel.com ([192.55.52.151]:15270 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233257AbhGBWIC (ORCPT ); Fri, 2 Jul 2021 18:08:02 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="189168369" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="189168369" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:28 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814836" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:28 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson Subject: [RFC PATCH v2 48/69] KVM: x86/mmu: Introduce kvm_mmu_map_tdp_page() for use by TDX Date: Fri, 2 Jul 2021 15:04:54 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Introduce a helper to directly (pun intended) fault-in a TDP page without having to go through the full page fault path. This allows TDX to get the resulting pfn and also allows the RET_PF_* enums to stay in mmu.c where they belong. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/kvm/mmu.h | 3 +++ arch/x86/kvm/mmu/mmu.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index c3e241088851..8bf1c6dbac78 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -125,6 +125,9 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, return vcpu->arch.mmu->page_fault(vcpu, cr2_or_gpa, err, prefault); } +kvm_pfn_t kvm_mmu_map_tdp_page(struct kvm_vcpu *vcpu, gpa_t gpa, + u32 error_code, int max_level); + /* * Currently, we have two sorts of write-protection, a) the first one * write-protects guest page to sync the guest modification, b) another one is diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 96a99450f114..82db62753acb 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4098,6 +4098,31 @@ int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, max_level, true, &pfn); } +kvm_pfn_t kvm_mmu_map_tdp_page(struct kvm_vcpu *vcpu, gpa_t gpa, + u32 error_code, int max_level) +{ + kvm_pfn_t pfn; + int r; + + if (mmu_topup_memory_caches(vcpu, false)) + return KVM_PFN_ERR_FAULT; + + /* + * Loop on the page fault path to handle the case where an mmu_notifier + * invalidation triggers RET_PF_RETRY. In the normal page fault path, + * KVM needs to resume the guest in case the invalidation changed any + * of the page fault properties, i.e. the gpa or error code. For this + * path, the gpa and error code are fixed by the caller, and the caller + * expects failure if and only if the page fault can't be fixed. + */ + do { + r = direct_page_fault(vcpu, gpa, error_code, false, max_level, + true, &pfn); + } while (r == RET_PF_RETRY && !is_error_noslot_pfn(pfn)); + return pfn; +} +EXPORT_SYMBOL_GPL(kvm_mmu_map_tdp_page); + static void nonpaging_init_context(struct kvm_vcpu *vcpu, struct kvm_mmu *context) { -- 2.25.1