Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1109822pxb; Thu, 21 Oct 2021 16:07:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyU3OHHjWxlMyUCrHji2htrToGG0K+VXt4ad9OKHspkVsPvkmhpprzsWngotSlYEPwHo4U+ X-Received: by 2002:a17:902:9a41:b0:140:4ca:761e with SMTP id x1-20020a1709029a4100b0014004ca761emr4794130plv.51.1634857658653; Thu, 21 Oct 2021 16:07:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634857658; cv=none; d=google.com; s=arc-20160816; b=IuJVCty2n89lZ69kXcFFsBhUEyy5SJOzWt5HQumAG3sqcCv/Ggo5Ed+7HrJypuXpb/ HH43tPDUH8FBEGzl6GpLAzgYc08w9JpHRXEeuUx3UBdfG/zbIqS2nYglvoSXbL/XZHc8 r3Z5d94JLEEpCiw3wk9ZphQBtgUfjVEL8K0iQldbIZuMQn4YstIWnH09tdWRS/5HRSnX 4Ma3wj6+MFoCQS4nw5Roh/p8MQNYxQXKjOUfQZEG21LMlL6719TxHVy6xw4SU1O3eCp0 E+NVYDhpPZlJgh+6CTqEebH/Is5O00xVMpBJqX3rkeUUL5/dO2qp381XCdS/FY5ogtTh a0xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=ODsO75+7Ax9Wtr7/eG1ebHepMo+VJKThWDvkM/Sw/L0=; b=lqaNC0fpA7JJvyYQ2f5DQoGm5skfiF28Drvzi+GcrEp/vM+yG2gUNLhx2W0LJi3wfB Er0/x2A2zIOb/CHbjtTfJQsqvA13HKAIk2ekg4X8Z9k7CkR29JiubFRztFnBGg7GSG4+ FK/kZYXTxH/85jkLIJhQn2UUFOd6wc1dvD3/piTGJg6pU7LCfAMl498JHA+LWnKTAZ3K efC0mEORsyieYrur90WP1yO9QL/1vY0kibV1CRnJ51Hh9Xiyctdl/yaRyiIywdj3sTjb NdwyV23fiQNwi3k9LqOKX3V1eFwbMs3u/BYRx4K6FjkC+mNlPQmwmdU9AIVCqUu2q6hZ YpDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jz2si5780619pjb.159.2021.10.21.16.07.24; Thu, 21 Oct 2021 16:07:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232609AbhJUXHx (ORCPT + 99 others); Thu, 21 Oct 2021 19:07:53 -0400 Received: from mga07.intel.com ([134.134.136.100]:4522 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232391AbhJUXHb (ORCPT ); Thu, 21 Oct 2021 19:07:31 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10144"; a="292634853" X-IronPort-AV: E=Sophos;i="5.87,170,1631602800"; d="scan'208";a="292634853" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2021 16:02:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,170,1631602800"; d="scan'208";a="445033393" Received: from chang-linux-3.sc.intel.com ([172.25.66.175]) by orsmga006.jf.intel.com with ESMTP; 21 Oct 2021 16:02:25 -0700 From: "Chang S. Bae" To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, tglx@linutronix.de, dave.hansen@linux.intel.com, arjan@linux.intel.com, ravi.v.shankar@intel.com, chang.seok.bae@intel.com Subject: [PATCH 14/23] x86/fpu: Add XFD state to fpstate Date: Thu, 21 Oct 2021 15:55:18 -0700 Message-Id: <20211021225527.10184-15-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211021225527.10184-1-chang.seok.bae@intel.com> References: <20211021225527.10184-1-chang.seok.bae@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add storage for XFD register state to struct fpstate. This will be used to store the XFD MSR state. This will be used for switching the XFD MSR when FPU content is restored. Add a per-CPU variable to cache the current MSR value so the MSR has only to be written when the values are different. Signed-off-by: Chang S. Bae Signed-off-by: Thomas Gleixner Signed-off-by: Chang S. Bae --- Changes from the tglx tree: * Add a missing #ifdeffery. --- arch/x86/include/asm/fpu/types.h | 3 +++ arch/x86/kernel/fpu/core.c | 2 ++ arch/x86/kernel/fpu/xstate.h | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/arch/x86/include/asm/fpu/types.h b/arch/x86/include/asm/fpu/types.h index d27ad4842fa1..c956db14b011 100644 --- a/arch/x86/include/asm/fpu/types.h +++ b/arch/x86/include/asm/fpu/types.h @@ -322,6 +322,9 @@ struct fpstate { /* @user_xfeatures: xfeatures valid in UABI buffers */ u64 user_xfeatures; + /* @xfd: xfeatures disabled to trap userspace use. */ + u64 xfd; + /* @is_valloc: Indicator for dynamically allocated state */ unsigned int is_valloc : 1; diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index 073a8fc281d8..e92c9d79441c 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -27,6 +27,7 @@ #ifdef CONFIG_X86_64 DEFINE_STATIC_KEY_FALSE(__fpu_state_size_dynamic); +DEFINE_PER_CPU(u64, xfd_state); #endif /* The FPU state configuration data for kernel and user space */ @@ -412,6 +413,7 @@ static void __fpstate_reset(struct fpstate *fpstate) fpstate->user_size = fpu_user_cfg.default_size; fpstate->xfeatures = fpu_kernel_cfg.default_features; fpstate->user_xfeatures = fpu_user_cfg.default_features; + fpstate->xfd = init_fpstate.xfd; } void fpstate_reset(struct fpu *fpu) diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h index 4ce1dc030f38..32a4dee4de3b 100644 --- a/arch/x86/kernel/fpu/xstate.h +++ b/arch/x86/kernel/fpu/xstate.h @@ -5,6 +5,10 @@ #include #include +#ifdef CONFIG_X86_64 +DECLARE_PER_CPU(u64, xfd_state); +#endif + static inline void xstate_init_xcomp_bv(struct xregs_state *xsave, u64 mask) { /* -- 2.17.1