Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3473241rwb; Fri, 30 Sep 2022 04:14:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Z0SDgpM5v80HM0npNcOdQoqEjHlT65MYz6bKzrHHkWt9A3xGtx3D4voNEdgsyorq+XC8R X-Received: by 2002:a17:90a:641:b0:202:8568:4180 with SMTP id q1-20020a17090a064100b0020285684180mr9253551pje.227.1664536480617; Fri, 30 Sep 2022 04:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664536480; cv=none; d=google.com; s=arc-20160816; b=qbf74H9hIfQB6EmX9qeZuGmCXmTZAcTCBHW2QKG6b3x7SoBJjiPR627xRYhrPqYI5u Zg3/eWhT7cx/ePeWQpYnTzZQZ5C/7tGW0Ok2LsRMXj29YOt12ID+vAPSlhS0F9li0gTR I6gBApI28ADRnHyyCvGb1Gedx0ww8548h8C6giUrdA3cC3l0CAxp0cZq7JLO/kO5s7Nv DOhvHLC1E1nhuIsCxc4eLngbXY5DMFV7/dPT2J7H9oEvSl1ar2A3sv9d1gaXAVKryqjE vHm/vnbXPze2+nCCg6O3q9HCv3cfMNgvHHZDUgS53v8i1IDoY9dan9nZSd2jOTiD4tT7 nxJw== 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=22nnNtpjXxFtOhuoijxHVWh7cBSTI/SzoP/R2q+gqsM=; b=b187LsexE9SzyWrnyH1iD3rPAU53W8n14FergKx9f5Byi9OU7P61bTvxOC5X00n3wd u3i5Oxx5ZoBY26baSSPHxqaFxY3xfUnMXLkbHAivnTipPsysYYCAadHxLWwN78LAJjYQ rDr8yC64nRGyoibu8ExI2vbjwuoRWxJwzXw4kPHqfsRjL5R1dzeChDe7VMqnhznypeo3 lHAFagR+tNTOsA82fXzVRHKbD2FsYw7JDow3YViyI+1LgA0vpH06szIQCQHUllKFPcn9 BrZ8/aJCg0bAFTBHvrtQ7nl79lSJpHk9XFyUD8mn0lQw9Hw5aexjC1iY+MDmrljPYtJX OytQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fb+syh55; 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 lp12-20020a17090b4a8c00b001fbbcd6f8eesi2501896pjb.73.2022.09.30.04.14.28; Fri, 30 Sep 2022 04:14:40 -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=fb+syh55; 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 S232116AbiI3KWM (ORCPT + 99 others); Fri, 30 Sep 2022 06:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231530AbiI3KTE (ORCPT ); Fri, 30 Sep 2022 06:19:04 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38814166F2D; Fri, 30 Sep 2022 03:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533142; x=1696069142; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=egSdmBDWUZIcewFDKHSSDYx6qc0YZSUEykKZr8M2EK4=; b=fb+syh55GvAKKxqwqeD61sa2ZikpXmh/Zg34gCuVZrH/sZ6S4hnCtmHU viyd7rRGg+hBZrt38mzKP0ssyc7aA4ocGdp/Mz52BaN+Z1PFWzLpoQiMc tLzc+//c6THSTA2J8kk1XjBrBSqz95b12HkGhB/2uenVqYgsy3dYejFru NDHN1zLs3XgazphscCnaqdbBNnUGzzhZ4WtiIhe+sByV9HChC+YlqPDCj x2szuyfzRs5lcThcWb7A2dG3Py4aDdhP2LK267xH5a5CbRg98AocLpdcZ X63wILTxFp1j+i0zVoEePK4fWMN8pBOBPadctIbIbqRDKXv0hCmLbA48S w==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="281870091" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="281870091" 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:57 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807616" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807616" 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:57 -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 035/105] KVM: TDX: Enable mmio spte caching always for TDX Date: Fri, 30 Sep 2022 03:17:29 -0700 Message-Id: <8eac5ca057eb23b851dadcbae39f267edf50d8d3.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 TDX needs to set shared spte for MMIO GFN to !SUPPRES_VE_BIT | !RWX so that guest TD can get #VE and then issue TDG.VP.VMCALL. Enable mmio caching always for TDX irrelevant the module parameter enable_mmio_caching. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/mmu/mmu.c | 3 ++- arch/x86/kvm/mmu/spte.h | 2 +- arch/x86/kvm/mmu/tdp_mmu.c | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index fdd773ef9400..f4d7432cd9fc 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3216,7 +3216,8 @@ static int handle_abnormal_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fau * and only if L1's MAXPHYADDR is inaccurate with respect to * the hardware's). */ - if (unlikely(!enable_mmio_caching) || + if (unlikely(!enable_mmio_caching && + !kvm_gfn_shared_mask(vcpu->kvm)) || unlikely(fault->gfn > kvm_mmu_max_gfn())) return RET_PF_EMULATE; } diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index 82f0d5c08b77..fecfdcb5f321 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -244,7 +244,7 @@ extern u64 __read_mostly shadow_nonpresent_or_rsvd_lower_gfn_mask; static inline bool is_mmio_spte(struct kvm *kvm, u64 spte) { return (spte & shadow_mmio_mask) == kvm->arch.shadow_mmio_value && - likely(enable_mmio_caching); + likely(enable_mmio_caching || kvm_gfn_shared_mask(kvm)); } static inline bool is_shadow_present_pte(u64 pte) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index b80422ea798d..5ecb976ed954 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1863,6 +1863,13 @@ int kvm_tdp_mmu_get_walk(struct kvm_vcpu *vcpu, u64 addr, u64 *sptes, *root_level = vcpu->arch.mmu->root_role.level; + /* + * mmio page fault isn't supported for protected guest because + * instructions in protected guest memory can't be parsed by VMM. + */ + if (WARN_ON_ONCE(kvm_gfn_shared_mask(vcpu->kvm))) + return leaf; + tdp_mmu_for_each_pte(iter, mmu, gfn, gfn + 1) { leaf = iter.level; sptes[leaf] = iter.old_spte; -- 2.25.1