Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4105416rwb; Sun, 7 Aug 2022 15:09:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR55ml12A4Ez4qZ4JT39/xn0mws1iKb67i8Y6Hxk5E1tBf4AbxoPPJ9HzGG0h9gz+A1KJEpl X-Received: by 2002:a17:907:a420:b0:731:5809:9593 with SMTP id sg32-20020a170907a42000b0073158099593mr1963252ejc.213.1659910197695; Sun, 07 Aug 2022 15:09:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659910197; cv=none; d=google.com; s=arc-20160816; b=e0efVcgFIZYjc/GeACRXSMnrGuB14TCBkjk0RCNQD9nVHeDLVTIYSsiuRuV/ixarbr h+Oyx11mIDND+3fnxOFL9OQnIWFY9MIxf+UMCOGndvtFQ4GcXOijKAyWR3sGeXgNiPWJ ZAsd0qMPtQak1zJlOWBDTuxYbvkyz/PnavdFX0hO3QGffgKktLn+D23I4b0RHda1ylXK G6BZc91sEvek8CbuHu0fBbL0VRknkwceZDwRZaBBBH4a5L+a0kMBMl/BzXDnAWmvE5fh 7X7EeiPpQX3ZJtSd8VmPpjWwjU5fszfvrzW3rhOp+nAmYszUYrAwIqQfPZFBBzhOzr1P IeIw== 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=pxZHG+sYdikWbqsqGpk6lrhA4oVhVIWnm1N6o/eX34E=; b=fNVX8TMrWn7jcsWqPHlmc4fXm9wlq69MlIEhK6otiL8saqQTgLl1ZhBnYGFr660Wki sGkcgG47nZ+f55MUm6Rbsb0biJObwEcBSIiag0F1JtJL7VX3yx/oEQLJsU5wOJzVl/aW Lc9iCn0blbdzWVwG5COq5rAVo/jO0z91JNIsjbvLPTCHZubz50QrvUAPWegSUzi9eKv0 C9SI7X90n+3JACTdztCR0i/VEuc0CNBOoXgF6drFwsWTpBzgBTPVSuqALczvL9ouP0/8 zvm9EJqWI7oQAD4RuG51J35aJED7VxNQaO5iTj/mCiOWcNHKhxg7FNMq6fPIEhRffxeA RRCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eGA75bHG; 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 gt9-20020a1709072d8900b00730729458d5si7591272ejc.687.2022.08.07.15.09.32; Sun, 07 Aug 2022 15:09:57 -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=eGA75bHG; 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 S236257AbiHGWFg (ORCPT + 99 others); Sun, 7 Aug 2022 18:05:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234406AbiHGWCu (ORCPT ); Sun, 7 Aug 2022 18:02:50 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4174D64D9; Sun, 7 Aug 2022 15:02:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659909758; x=1691445758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bh3JBpPI4YqUSB7snXoKEOW1gXyZtvo+DPTc9vCyft8=; b=eGA75bHGtOCTlLoG9FJh/8KoTKSX5eDjnyXOmXMCUT0D6KJsQeLt6zvg 1xMH1AY7xXoVWgSei4rlj5v+sVykB1SwdlZLYMiGixA69Vm6ICqWluV2x vbrkgnA7xXQtVcpJyS2FYdEIvxhYnJKzKrOiP6BTiU1FyhJeO6wK94I7n xPghLSZYEYUwDJ+d2KzGte64gkH1R2cHJ8u5jgcm43VwuT9KifU2rz/iz ReG/m5lrJ/qdXcSuWXI3zvhJmTjGWe1KtFCGWrLKJMZKJB77uhTllUL78 yKiYnBkZgCjdS8ScDK+EN8y7qRwuHSW/vDgbyYEihYfDFHiHcjmoAG7VQ A==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="291695688" X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="291695688" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:37 -0700 X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="663682606" 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; 07 Aug 2022 15:02:36 -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 v8 050/103] KVM: TDX: Add load_mmu_pgd method for TDX Date: Sun, 7 Aug 2022 15:01:35 -0700 Message-Id: <7586ef03744bdf529532e1dd1bff59ef8939dc23.1659854790.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=-5.0 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,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: 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 f0f8eecf55ac..e169ace97e83 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 9f4c3a0bcc12..252b7298b230 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -110,6 +110,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)) @@ -228,7 +237,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 36d2127cb7b7..7a631ae78e59 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -518,6 +518,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 62f1d1cdd44b..185481ee5f2f 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -145,6 +145,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 bool tdx_is_vm_type_supported(unsigned long type) { return false; } @@ -162,6 +164,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