Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp560869rwb; Thu, 12 Jan 2023 09:19:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXsEFBT2KKjUNHRvSQ8E5oVMAhxu8WLUkEM1/IKUmb5Vh4o+Fg38wgZr9y4X6rxbvEMzLGDu X-Received: by 2002:a05:6402:50e:b0:49b:4711:f4b4 with SMTP id m14-20020a056402050e00b0049b4711f4b4mr4121590edv.0.1673543982463; Thu, 12 Jan 2023 09:19:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673543982; cv=none; d=google.com; s=arc-20160816; b=yvPSFBYsjZUeu7XnxAFrYg8wR9r8KBF70Gg3s9NBE38mtYjjSpQNPldO/2SYdZK/bl PXSb63u4O40SCubfxmCADlBG9FZq8BgeDR0kWG8BzK6bpnZI9FQ+H05Jq22lNov9cZx/ qQpt3mM1TlfI6fmu88B3pmX3O546INoX/dv6V5uLdi7v0OGbGbMmdSQ9pyGXigBae64u 4GrbmNYnejlkT+Qy0nGgAc8E109wwt1vliE1WiHQYH+6uiJHVje42MnIUSq82W/0nFyK 9GY///J7BdhG860i2Krl/wVXk9rGkaabr2dH4Byl9Wh+I1oiXhfRgvRX8oDO6tjsZD6D 5fsA== 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=0OyL0kf30ivtMkA4CRKEnal4kyVCG9/ZbW5ezWVjKiE=; b=u+8Rc+2iq39MqgAjnMh5rgQRiI8cpyTnMhiGiBwBBNQXL1SPVtYK0M7Aadm9W8TimJ G8XZkesOT+v/Ak1lJNkQq+GyeJTHsvfHWR3YQJQq9jSxg75RcN7ChGTIeDSEurRVEf8J TQhNoCIydAoewnfGHgj8oXnksx+j2dULVAaX+tNlcJY5bPHIrDsj7DcmeLSep68qHAZH P1NuUJlaVnQBnvn3tzZJ54DSotyK/3yvly6+Zr+JYWkSQHYf/inOCgZNXuu6eFosbveI L1lyLSV4xF9uq3dQ2/ySca4s5Zta1/IgeVTHTmYZBg29Lot6bnG5f7YQP+MAwFtLa/mO XiDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Iyae450Y; 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 z9-20020a056402274900b0049394fbf982si21841849edd.132.2023.01.12.09.19.30; Thu, 12 Jan 2023 09:19:42 -0800 (PST) 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=Iyae450Y; 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 S240878AbjALQr3 (ORCPT + 50 others); Thu, 12 Jan 2023 11:47:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240218AbjALQie (ORCPT ); Thu, 12 Jan 2023 11:38:34 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E862A1C43B; Thu, 12 Jan 2023 08:34:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673541244; x=1705077244; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JaWnvkwOPZNg8RZGy+Fq1EzO1om5H5hAZxxCRGKkxr8=; b=Iyae450Yt1PYXRBc04Co+4VqkKSOZmx7ubxXo4dh+vPPs93QZitwxpUT LWJNJOPVKUGeF+LwzwM5SkI9AnoFFb7iOlgVFtbuQxKnSCwUZIfvRUd8L g221NbBYQCd39F8ySq1bN8c8C+cZSsOERvJceXdUolG/kOLrDhVliJH+i Y4Fje2A+EvOMlZdWe3XDx9SltXZIwBCjBctmO2Figf/gzZGbdW/yOgsww HPI+y5auf2AayKVZ2XMYPAAfS+0n4x8NLROXZJA65O7UqUnXogR2dwWYi UImj96WgrcUgUs0JZe3+OO6VtNJp6NM3gXqXxam9vzMmKRCpqciga/3Ze A==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="323811916" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="323811916" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:29 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="721151821" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="721151821" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:29 -0800 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 , David Matlack , Sean Christopherson Subject: [PATCH v11 054/113] KVM: TDX: Add load_mmu_pgd method for TDX Date: Thu, 12 Jan 2023 08:32:02 -0800 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=-4.4 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_NONE,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: Sean Christopherson For virtual IO, the guest TD shares guest pages with VMM without encryption. Shared EPT is used to map guest pages in unprotected way. Add the VMCS field encoding for the shared EPTP, which will be used by TDX to have separate EPT walks for private GPAs (existing EPTP) versus shared GPAs (new shared EPTP). Set shared EPT pointer value for the TDX guest to initialize TDX MMU. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata Reviewed-by: Paolo Bonzini --- arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/vmx/main.c | 11 ++++++++++- arch/x86/kvm/vmx/tdx.c | 5 +++++ arch/x86/kvm/vmx/x86_ops.h | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 752d53652007..1205018b5b6b 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -234,6 +234,7 @@ enum vmcs_field { TSC_MULTIPLIER_HIGH = 0x00002033, TERTIARY_VM_EXEC_CONTROL = 0x00002034, TERTIARY_VM_EXEC_CONTROL_HIGH = 0x00002035, + SHARED_EPT_POINTER = 0x0000203C, PID_POINTER_TABLE = 0x00002042, PID_POINTER_TABLE_HIGH = 0x00002043, GUEST_PHYSICAL_ADDRESS = 0x00002400, diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 9f817f9a8c69..a2ffef95bf9d 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -100,6 +100,15 @@ static void vt_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) return vmx_vcpu_reset(vcpu, init_event); } +static void vt_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa, + int pgd_level) +{ + if (is_td_vcpu(vcpu)) + return tdx_load_mmu_pgd(vcpu, root_hpa, pgd_level); + + vmx_load_mmu_pgd(vcpu, root_hpa, pgd_level); +} + static int vt_mem_enc_ioctl(struct kvm *kvm, void __user *argp) { if (!is_td(kvm)) @@ -220,7 +229,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = { .write_tsc_offset = vmx_write_tsc_offset, .write_tsc_multiplier = vmx_write_tsc_multiplier, - .load_mmu_pgd = vmx_load_mmu_pgd, + .load_mmu_pgd = vt_load_mmu_pgd, .check_intercept = vmx_check_intercept, .handle_exit_irqoff = vmx_handle_exit_irqoff, diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index a7d42c05a758..aa07e03843b6 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -382,6 +382,11 @@ void tdx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) vcpu->kvm->vm_bugged = true; } +void tdx_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa, int pgd_level) +{ + td_vmcs_write64(to_tdx(vcpu), SHARED_EPT_POINTER, root_hpa & PAGE_MASK); +} + int tdx_dev_ioctl(void __user *argp) { struct kvm_tdx_capabilities __user *user_caps; diff --git a/arch/x86/kvm/vmx/x86_ops.h b/arch/x86/kvm/vmx/x86_ops.h index fba8d0800597..27dd778aed6a 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -154,6 +154,8 @@ void tdx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event); int tdx_vm_ioctl(struct kvm *kvm, void __user *argp); int tdx_vcpu_ioctl(struct kvm_vcpu *vcpu, void __user *argp); + +void tdx_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level); #else static inline int tdx_hardware_setup(struct kvm_x86_ops *x86_ops) { return 0; } static inline void tdx_hardware_unsetup(void) {} @@ -172,6 +174,8 @@ static inline void tdx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) {} static inline int tdx_vm_ioctl(struct kvm *kvm, void __user *argp) { return -EOPNOTSUPP; } static inline int tdx_vcpu_ioctl(struct kvm_vcpu *vcpu, void __user *argp) { return -EOPNOTSUPP; } + +static inline void tdx_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level) {} #endif #endif /* __KVM_X86_VMX_X86_OPS_H */ -- 2.25.1