Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2260589pxm; Fri, 4 Mar 2022 12:33:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJFqJQVAEAV9nHWSRp+JhGCSqZToUz4Nbwpvp8j6wVXlQRWmY1O8uxXVCOr7KJ6VFjAkID X-Received: by 2002:a17:90a:7885:b0:1be:d757:fa73 with SMTP id x5-20020a17090a788500b001bed757fa73mr12498725pjk.169.1646425987830; Fri, 04 Mar 2022 12:33:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646425987; cv=none; d=google.com; s=arc-20160816; b=cBZ8SyxaQeoqc9buWGyPiSglkOf3oMd4TpF8i0kInsDMUYUyNvCdxUEJTtXd3p6mJ4 ZT3rQcj+k1ZsCjnOwh/Djsb7GZ52Tz55L2ZneiGXC2KKhaULygfE+Low0S6Kl1pybP+n jlbnmj0uIa4AnJAc4aoYGybXMT+9R2lf10HeV/QbrL7J5X1ou+3z7Zepv0BLC0I381ug 0sdOjmiiMqiQ3gKkYusM1eoOHsdSDF504FHYowr0QgjIoGDLYvRFaTC2ajHYHe+XSLbh pM+TmnaNJDas3ModniGaxxfcVPow7PR+f5d76hMQIvD5uVMCcmNbh+o88tNFzhuibUSK h0Iw== 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=K3dxe4teKpZRWOs7eq2f/AxzeOS3QSf6uDuVsBvbr4k=; b=hyGFgzANYQEIPqeIm5YskuvJCux7BoDE2ENk7dxmhd+5/dT1DruFdFnnVnM8aGdksq RPW35RnruA5yP428+XiPXXGLUevkf4MnycVxr6U8sVS1XZXt9EbWdLBzpGrOa5hCbDXa VN3A8uzwWt/UjLVTE+IIN8Qk0AzX0wQGNLHQKaCU+SkV/VTpWVCvboZZY8F1s1zILDs7 +FnFxjp5cFAUKXKFYQMef6jKdzFCmmofPCKEEkDPqbVofeog8lm/vl5+aCR8Vp5zThcM xpK+M/vm7aZYyY1gMzrmTff4SuKDb5j9MB6gCrHoilXC8Vk5K00CbjpQihOQwi8xzxxH HIUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aisMNkai; 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 x1-20020a170902ec8100b001519d03da99si5684872plg.407.2022.03.04.12.32.52; Fri, 04 Mar 2022 12:33:07 -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=aisMNkai; 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 S229501AbiCDUcl (ORCPT + 99 others); Fri, 4 Mar 2022 15:32:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229992AbiCDUcV (ORCPT ); Fri, 4 Mar 2022 15:32:21 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55C551E6EBE; Fri, 4 Mar 2022 12:31:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646425891; x=1677961891; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NWtwA1Mcge7E6YZfOv6akPgOyt4W/fs13Ve2SrnZD4s=; b=aisMNkai4wZygW8qFw8hFiDluu5Y5cThwv2dkx/TCu7PM/HIzmmRtQmt /WngeN7MSiKwdlG3r1ygS1yauO4Bl9TJCFfWL01umbwHqf0SqFUKSm2Tm XmmZ0u3W/7ILpBqtT3KLmPBl6v+F+6Dd/m+YRDT06kiWMCBSVZFh2FWHE 8aJv6Rp4cyPoRvERHvN7E4sFEvoiy/TvboSGVKz+hou8ISzEJfBZG9D2A MUQF7fCJCP3S72J7H8s+DTQ2PS/vxut7p8BTRixWGF5TmzyoMhqygLZJI MK2drXq+aDl5YNSkPTGdcMQbeIAQpA5MyLp4TusI5JRFVhziLHL8qRw03 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10276"; a="251624266" X-IronPort-AV: E=Sophos;i="5.90,156,1643702400"; d="scan'208";a="251624266" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2022 11:50:33 -0800 X-IronPort-AV: E=Sophos;i="5.90,156,1643702400"; d="scan'208";a="552344466" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2022 11:50:33 -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 , Jim Mattson , erdemaktas@google.com, Connor Kuehl , Sean Christopherson Subject: [RFC PATCH v5 068/104] KVM: TDX: restore user ret MSRs Date: Fri, 4 Mar 2022 11:49:24 -0800 Message-Id: <7c421339d5b2bd5d2e29f79ac1cdf5d269c5cf96.1646422845.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=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H2,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: Isaku Yamahata Several user ret MSRs are clobbered on TD exit. Restore those values on TD exit and before returning to ring 3. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/tdx.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 54be5be1a06c..c1366aac7d96 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -550,6 +550,28 @@ void tdx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) vcpu->kvm->vm_bugged = true; } +struct tdx_uret_msr { + u32 msr; + unsigned int slot; + u64 defval; +}; + +static struct tdx_uret_msr tdx_uret_msrs[] = { + {.msr = MSR_SYSCALL_MASK,}, + {.msr = MSR_STAR,}, + {.msr = MSR_LSTAR,}, + {.msr = MSR_TSC_AUX,}, +}; + +static void tdx_user_return_update_cache(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(tdx_uret_msrs); i++) + kvm_user_return_update_cache(tdx_uret_msrs[i].slot, + tdx_uret_msrs[i].defval); +} + static void tdx_restore_host_xsave_state(struct kvm_vcpu *vcpu) { struct kvm_tdx *kvm_tdx = to_kvm_tdx(vcpu->kvm); @@ -589,6 +611,7 @@ fastpath_t tdx_vcpu_run(struct kvm_vcpu *vcpu) tdx_vcpu_enter_exit(vcpu, tdx); + tdx_user_return_update_cache(); tdx_restore_host_xsave_state(vcpu); tdx->host_state_need_restore = true; @@ -1371,6 +1394,16 @@ static int __init __tdx_hardware_setup(struct kvm_x86_ops *x86_ops) if (WARN_ON_ONCE(x86_ops->tlb_remote_flush)) return -EIO; + for (i = 0; i < ARRAY_SIZE(tdx_uret_msrs); i++) { + tdx_uret_msrs[i].slot = kvm_find_user_return_msr(tdx_uret_msrs[i].msr); + if (tdx_uret_msrs[i].slot == -1) { + /* If any MSR isn't supported, it is a KVM bug */ + pr_err("MSR %x isn't included by kvm_find_user_return_msr\n", + tdx_uret_msrs[i].msr); + return -EIO; + } + } + max_pkgs = topology_max_packages(); tdx_mng_key_config_lock = kcalloc(max_pkgs, sizeof(*tdx_mng_key_config_lock), GFP_KERNEL); -- 2.25.1