Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1111251pxb; Thu, 21 Oct 2021 16:09:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyv2XWqTWnHtpwKx1KsHUKBA6tUBMEoI/4LpKiO+I8W2d0X2ynHZutzf/a9gpZDzGBSfynf X-Received: by 2002:a17:902:b691:b029:12d:2b6:d116 with SMTP id c17-20020a170902b691b029012d02b6d116mr7732273pls.71.1634857765273; Thu, 21 Oct 2021 16:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634857765; cv=none; d=google.com; s=arc-20160816; b=QBce0jb+bvZOQw49pzLnG/L4qKyYSQK3D+Df0fl9h/SSKxD13mBZ98yp/UeoTGhYOq sIoyByv6x1Xd9OwHnvLx8DVy4swrG3WPpnqK0Dm8SIVrFiq12sVnsJEi24QntxiKVVts Tii6S4nL0T/DVjYFoSfO/ehqMMrvaxEhrELSP/sjAohD+O4yIIMyXceFeVh6YxDC/n0L ytwB8SUIs24DOvfqATyH8obi7OUcosLltIbfQ21/P5D0JQCDYHdEhGzzyo24g6o21bJ9 ZNER15YD35Unj7TrEKoCfDxk0ludAjAx7Vmz8aixU3nPOJoR4LyKxyIswHUuW03VnQBS RUaA== 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=q3nukKicmueiAlXWDaGS0YJ15y05uTljGMuCdyPQGoE=; b=m2r24L9lNyeKts8fIu9fYFJNS0g5svzV1jVuU9fadIvQ+lNGM5naZvhE9VIZN8A0Jy HbyiM6j3h/4xXVsAOHjjwFuWZgefzVpAa1KpKNht2hA9o5AohuHZw0mEEg2YfPZl3Ctc DB0ek68NKMZy+5xvUe03lgI4+YhZrSbjWCL/WZAuF4rWchFMYET+j9TssrLu3uXxqeu3 Sk8RV/Kos9KNVwM4iI4CAyfJpGjpEGLZsVyHd4nhG4oDO4BMiKncC2Zoqw0J0xtpzUqc XipvEspt0w1bNOz6bkuUCSiKBi2uwBehNEjI6xkI5er5XiTJFxA4RrXwKJej06YAiKCh wRHQ== 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 l16si2956705pgc.45.2021.10.21.16.09.06; Thu, 21 Oct 2021 16:09:25 -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 S232465AbhJUXIe (ORCPT + 99 others); Thu, 21 Oct 2021 19:08:34 -0400 Received: from mga07.intel.com ([134.134.136.100]:4523 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232562AbhJUXID (ORCPT ); Thu, 21 Oct 2021 19:08:03 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10144"; a="292634920" X-IronPort-AV: E=Sophos;i="5.87,170,1631602800"; d="scan'208";a="292634920" 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:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,170,1631602800"; d="scan'208";a="445033477" Received: from chang-linux-3.sc.intel.com ([172.25.66.175]) by orsmga006.jf.intel.com with ESMTP; 21 Oct 2021 16:02:29 -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 22/23] x86/fpu: Add XFD handling for dynamic states Date: Thu, 21 Oct 2021 15:55:26 -0700 Message-Id: <20211021225527.10184-23-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 To handle the dynamic sizing of buffers on first use the XFD MSR has to be armed. Store the delta between the maximum available and the default feature bits in init_fpstate where it can be retrieved for task creation. If the delta is non zero then dynamic features are enabled. This needs also to enable the static key which guards the XFD updates. This is delayed to an initcall because the FPU setup runs before jump labels are initialized. Signed-off-by: Chang S. Bae Signed-off-by: Thomas Gleixner Signed-off-by: Chang S. Bae --- arch/x86/kernel/fpu/xstate.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index dcc1dd2d8f2d..81b40f119ce7 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -835,6 +835,12 @@ static void __init fpu__init_disable_system_xstate(unsigned int legacy_size) fpu_user_cfg.max_size = legacy_size; fpu_user_cfg.default_size = legacy_size; + /* + * Prevent enabling the static branch which enables writes to the + * XFD MSR. + */ + init_fpstate.xfd = 0; + fpstate_reset(¤t->thread.fpu); } @@ -918,6 +924,14 @@ void __init fpu__init_system_xstate(unsigned int legacy_size) /* Store it for paranoia check at the end */ xfeatures = fpu_kernel_cfg.max_features; + /* + * Initialize the default XFD state in initfp_state and enable the + * dynamic sizing mechanism if dynamic states are available. The + * static key cannot be enabled here because this runs before + * jump_label_init(). This is delayed to an initcall. + */ + init_fpstate.xfd = fpu_user_cfg.max_features & XFEATURE_MASK_USER_DYNAMIC; + /* Enable xstate instructions to be able to continue with initialization: */ fpu__init_cpu_xstate(); err = init_xstate_size(); @@ -1463,9 +1477,21 @@ void xfd_validate_state(struct fpstate *fpstate, u64 mask, bool rstor) } #endif /* CONFIG_X86_DEBUG_FPU */ +static int __init xfd_update_static_branch(void) +{ + /* + * If init_fpstate.xfd has bits set then dynamic features are + * available and the dynamic sizing must be enabled. + */ + if (init_fpstate.xfd) + static_branch_enable(&__fpu_state_size_dynamic); + return 0; +} +arch_initcall(xfd_update_static_branch) + void fpstate_free(struct fpu *fpu) { - if (fpu->fpstate || fpu->fpstate != &fpu->__fpstate) + if (fpu->fpstate && fpu->fpstate != &fpu->__fpstate) vfree(fpu->fpstate); } -- 2.17.1