Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp152235lqp; Fri, 12 Apr 2024 13:19:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXyZCYmo5yoJI4eeat4M0ek5gvIQFR0pWHbeN3BoHjHyNT/F1ziXyBXvF3qM4T1/azGbHRJA0AWgel08hCqUkyJurJwJQ/KSgkpGzOweQ== X-Google-Smtp-Source: AGHT+IFfvltZS6rZBfW4itTJzzo1e86ImstFL2144zyJXKUDFylZFUywnTUBlUt8mSLPsfkGz9Ee X-Received: by 2002:a50:cc9d:0:b0:56e:2b31:b111 with SMTP id q29-20020a50cc9d000000b0056e2b31b111mr2621170edi.7.1712953153318; Fri, 12 Apr 2024 13:19:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712953153; cv=pass; d=google.com; s=arc-20160816; b=Q4z7DdHdFN9+jA8I8JUF1s/SpCw+4XtCdNheZ0EIn5j8UavYKi/FXvAJq89s1RxAji 0/2CPeCXUPFxdFO3XMY5d1HcrSkGJY1+vK7YQN6yBJwUNzqNBgOGLHMw/1D76IWfq20F qkI6MSRrCyJgrdlALvdxVs0GNmvAEtFBlZKLhi/aEniBDrtrBHGFlJWuholOxHakrujI fhLeJQ34+D3oLHU0ULuHOKcXQQSy+DTdcRAMQqRiVkt2qtuKP4rgFQGyos/fH4fMZlN2 EHa8e5Up3M5QrGHo0aDRM89pW+Cx/HY2UA1j/xwGME0lyuhvpMj4nn36eX82lFxrAllS pQ7A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=rbQBncNdegYpN8Qn52ZbVNhhYWmgszr72QCilw5jyOY=; fh=P/quV/w7uXmndbL78FtEpLTNkJRPx4LJS51PzREvtL8=; b=A3RTYe70HOm31h2r6sZyS5NodcCBl/Ih83GQ78wJ6T8gUSPLp7cZFUMW/zHJ/Z5YRJ dsrsiHVnKSjC5gG7YiRK+R95weiqQwXPWI/7ZYr6I78v4WpJaShyWelNq2NlEi8XF6if xXPj0UAZL/VcW+N3cKydTlBn+c0cndZPA25GZaDijEdfEUDSuzMwdOIqi4G0Sw5m3Chi mata6/yjCmfFraHezNf+DVJ1dNZULfOFG8CAPR26QoBtEYxcXtGqtgM3+hAdjZ1/m0xd RY3DzJD6L7Xasg6Q1dGq7+nfe0WJuGzbjQ2pmYV9iA2ul5CUr2lQPW7jZPIwJJWeEv35 UEiw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZA+bJo15; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-143299-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143299-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y5-20020a056402440500b005700c8eaf00si109929eda.85.2024.04.12.13.19.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 13:19:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143299-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZA+bJo15; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-143299-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143299-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0DE571F21E99 for ; Fri, 12 Apr 2024 20:19:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF7BF1514C8; Fri, 12 Apr 2024 20:19:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZA+bJo15" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4967214A091; Fri, 12 Apr 2024 20:19:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712953143; cv=none; b=PTRelW0I/4kjVhLlJA1j4rmLdhzpEv47arah/FtPOsbqNqPxgQCDr6/u7O88DURXi3pko9DIOEt9gxmQVkEzCWFlSqbubWIpibyh020jVdcezetGBPkNchi5oJ8sWKAY/CaaIDmjrHplCOIyBWzNFCIFUVe2yf9cll73BDHF2/0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712953143; c=relaxed/simple; bh=IrUgnuln+72xJ472g+onjqmOEecUVLRY/dkhYblU0KU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FlYwaSi5NBon52iG/QA+jqpV1WERgo2kTCZmUwWvXE80Pje7kdxKsePTQQieeNl8Y4y26oedHy77n1plpuwh5SnWUq/HcV1zCNgyy+rRZoNK21cJCw7lV4yx+1YzE7nfh3/oT09RzCmgD02C2QiYvG8nQcftWDSTWoHc3PewSwU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZA+bJo15; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712953142; x=1744489142; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=IrUgnuln+72xJ472g+onjqmOEecUVLRY/dkhYblU0KU=; b=ZA+bJo15e0bVs9zRzrK/fVRSot5nrtPQqg/WU29weJ1/ZYh+J/XQEgvv UiQ2bfDL5PKYSwyjSqODOSnFj0fE6/ghJyufRWeRbQ50YLbQyNhaCCcUe RYilMJ6weZn/VhEGKb7UjllWniZBdMDO1VJHnSLraWeIYPFssGJREnvNf 38+KmvMzVcdSldGRWV6V2SY+ttgu9Uc0uVRDY3YbBUVYpCnJSEYC1oV1C EW/qmfYKQI48vjYWVGy4qJfT2d33Nz6D4tnESqIoYL7TfOSz48ber2nqJ GZPHsC39FmOYWhD5xCH5MNWBeymuuZ4x582gMl+bw1wgz9sxTleBFuaCN g==; X-CSE-ConnectionGUID: dQ/Qv+ziS8Csx2n3a829nA== X-CSE-MsgGUID: WRGiyciHTRS+r9TXYo1xaw== X-IronPort-AV: E=McAfee;i="6600,9927,11042"; a="18983202" X-IronPort-AV: E=Sophos;i="6.07,197,1708416000"; d="scan'208";a="18983202" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2024 13:19:01 -0700 X-CSE-ConnectionGUID: C3oOFipARtGuROw7YXTjlw== X-CSE-MsgGUID: slfodUq8T6mwNojyHtN1IA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,197,1708416000"; d="scan'208";a="21399438" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2024 13:19:00 -0700 Date: Fri, 12 Apr 2024 13:19:00 -0700 From: Isaku Yamahata To: Binbin Wu Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, isaku.yamahata@linux.intel.com Subject: Re: [PATCH v19 080/130] KVM: TDX: restore host xsave state when exit from the guest TD Message-ID: <20240412201900.GK3039520@ls.amr.corp.intel.com> References: <2894ed10014279f4b8caab582e3b7e7061b5dad3.1708933498.git.isaku.yamahata@intel.com> <57c1a18b-b8b0-4368-99b3-b6ad4ad0e614@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <57c1a18b-b8b0-4368-99b3-b6ad4ad0e614@linux.intel.com> On Sun, Apr 07, 2024 at 11:47:00AM +0800, Binbin Wu wrote: > > > On 2/26/2024 4:26 PM, isaku.yamahata@intel.com wrote: > > From: Isaku Yamahata > > > > On exiting from the guest TD, xsave state is clobbered. Restore xsave > > state on TD exit. > > > > Signed-off-by: Isaku Yamahata > > --- > > v19: > > - Add EXPORT_SYMBOL_GPL(host_xcr0) > > > > v15 -> v16: > > - Added CET flag mask > > > > Signed-off-by: Isaku Yamahata > > --- > > arch/x86/kvm/vmx/tdx.c | 19 +++++++++++++++++++ > > arch/x86/kvm/x86.c | 1 + > > 2 files changed, 20 insertions(+) > > > > diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c > > index 9616b1aab6ce..199226c6cf55 100644 > > --- a/arch/x86/kvm/vmx/tdx.c > > +++ b/arch/x86/kvm/vmx/tdx.c > > @@ -2,6 +2,7 @@ > > #include > > #include > > +#include > > #include > > #include "capabilities.h" > > @@ -534,6 +535,23 @@ void tdx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) > > */ > > } > > +static void tdx_restore_host_xsave_state(struct kvm_vcpu *vcpu) > > +{ > > + struct kvm_tdx *kvm_tdx = to_kvm_tdx(vcpu->kvm); > > + > > + if (static_cpu_has(X86_FEATURE_XSAVE) && > > + host_xcr0 != (kvm_tdx->xfam & kvm_caps.supported_xcr0)) > > + xsetbv(XCR_XFEATURE_ENABLED_MASK, host_xcr0); > > + if (static_cpu_has(X86_FEATURE_XSAVES) && > > + /* PT can be exposed to TD guest regardless of KVM's XSS support */ > The comment needs to be updated to reflect the case for CET. > > > + host_xss != (kvm_tdx->xfam & > > + (kvm_caps.supported_xss | XFEATURE_MASK_PT | TDX_TD_XFAM_CET))) > > For TDX_TD_XFAM_CET, maybe no need to make it TDX specific? > > BTW, the definitions for XFEATURE_MASK_CET_USER/XFEATURE_MASK_CET_KERNEL > have been merged. > https://lore.kernel.org/all/20230613001108.3040476-25-rick.p.edgecombe%40intel.com > You can resolve the TODO in https://lore.kernel.org/kvm/5eca97e6a3978cf4dcf1cff21be6ec8b639a66b9.1708933498.git.isaku.yamahata@intel.com/ Yes, will update those constants to use the one in arch/x86/include/asm/fpu/types.h -- Isaku Yamahata