Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp863283rdb; Tue, 23 Jan 2024 18:46:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNDyVWdBnmAXg/9VIilncQpo4ms18Z5L/286FQAlNmVuDsi+/oOkAk8NKxSTfde5sBqhd/ X-Received: by 2002:a05:6a20:c507:b0:19c:4e28:379 with SMTP id gm7-20020a056a20c50700b0019c4e280379mr107426pzb.125.1706064419415; Tue, 23 Jan 2024 18:46:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706064419; cv=pass; d=google.com; s=arc-20160816; b=ySZjEH7ahjzx2JbZ6o0g4lFZhHUhck4WpQOoeh1KgcDU6lwCVc5Qcn4Iepf2yNnM/H 3lpCKN7XDZTlUkiPrf8kXSUUyJBblurOiBgJOEcrhmAkeYj8Fj7VHpqQpAkHrY2UBOgX ja9LuKNk5BP3mBcEYVKznELauf4ehnPJ21/WAVONjTewAjpri1fRMvZxnyMMeBGLE14x Jd4vV8IVGO0jAxilby5FJpiP7CozdYU7TnoyjT34PdIEWrVU5xRHvCslkCm4yTzbBjqV OjmJiWu5ntSsUDn3LBhd4P8yRkdv9/7Gne/z/g/xJ4EtXQzEtzDrQPCg47vRM2ah4x38 w5Ew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1ekGdcMFVxPGs9clN0D0hnyamSpg0ZyuSdIVA+yyno4=; fh=D+u40KSnYgjUYLGDRdXdD62xsMHg3nFDmpf3sEnyojA=; b=vZKOBTTg4tp+nKQQjCzcTiCvoiQi6qSu1CdELGROfINRP6FC09cnRz/s9aA9QCogi1 U617s9s0BJBNDjsZX2hFxJ+yjoTyqkrfUkVT3mY7VGsCwJUXcdAs2F2zGMzr2WHK5z3u x528AEX1yGvGt7RAcnVn5S8d1V2sA5PVpKF+e5T+hg3KZlRZvgzK6fVngn6U388lw6u9 a8Etqs3BPN9HJcHN7r1KaQeqNIOpvuzsV0q3yDudZm1u0jls756iXFGwDESzRvCgo5KE vQ/qZBcRblF8Zz01U5ELPfguEMg5x0l+larGp/0tgufcVrnj9njMLCm4oIk1hQvSIL/J ODNw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bgINgB9t; 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-36325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36325-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id o6-20020a1709026b0600b001d4931a0bfcsi10571044plk.638.2024.01.23.18.46.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 18:46:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bgINgB9t; 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-36325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36325-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id DBF31B2835E for ; Wed, 24 Jan 2024 02:44:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 79D5716415; Wed, 24 Jan 2024 02:42:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bgINgB9t" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 22B4DC120; Wed, 24 Jan 2024 02:42:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706064157; cv=none; b=tEsbjKjpjOQRYQyFEg0Mpsk0lkOPbfxvCDz8o2lxeR+9X9hl/8K+zlm5TxBnnSfn9TYdp/RWphOB8Wq0Tk6WhFNRmzxPY8ouiXhN2t8tYl6lNk52IrPZpmEkZMrknUMqlYC55AAIfhN+pPSb8sSnAbbMQ9EyG2cwoSTLfvC1XJ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706064157; c=relaxed/simple; bh=f4g1pickiFt8Es6a14IkTLu0NwpeGAkFFhCSd8aA94E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HEQYBVp0BTQiDn9FGBpL9VSYc4Yn0rhSPEQ+kN3x7DJFUPLYbymDRpzysfR9oRafglqQ5vxefpv8vVLNC9cPh8wvhiSrlhXkHRb3TD1FhnAVryeeOZGLEsbFNKVCf/ivI5E/sNwLt4SuP6yl9k0hOvfpjBrvOLpr4DcV0IUAXmU= 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=bgINgB9t; arc=none smtp.client-ip=192.55.52.120 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=1706064155; x=1737600155; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f4g1pickiFt8Es6a14IkTLu0NwpeGAkFFhCSd8aA94E=; b=bgINgB9tjyZ6jqCn6LQb2JbCfPILbWuzZqCcAqr8B3Tfa2TtxuNoDUxX rE5l+tyXpjSlEjLUgbxXF8qLGjk1vAPj6uky0VUyuHlBoP6nQlTUrnDTC lkVe5iwuvmbUEQ3Y2tLi5jeVVK4zvAFS+oJrE6splqtkQa14K2efH9s7j dzJ0wPUvGI+igWIm543Ygzk6TRVGZbEqjLDhAL1vGXFHihjTVnWJVvi9c +7CqGSU/21/7+ysVQvWORbC/CVrbiVcbthlRGb840YIj+AWrGse8JTrGg /cNjSpLzZGKWrkjYVmHhh5YwGISIw/JxJVuPgwUWM6O8k8cbdOJXJYSoj Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="400586437" X-IronPort-AV: E=Sophos;i="6.05,215,1701158400"; d="scan'208";a="400586437" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 18:42:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,215,1701158400"; d="scan'208";a="1825823" Received: from 984fee00a5ca.jf.intel.com ([10.165.9.183]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 18:42:32 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, yuan.yao@linux.intel.com Cc: peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com, weijiang.yang@intel.com Subject: [PATCH v9 04/27] x86/fpu/xstate: Introduce XFEATURE_MASK_KERNEL_DYNAMIC xfeature set Date: Tue, 23 Jan 2024 18:41:37 -0800 Message-Id: <20240124024200.102792-5-weijiang.yang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240124024200.102792-1-weijiang.yang@intel.com> References: <20240124024200.102792-1-weijiang.yang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Define a new XFEATURE_MASK_KERNEL_DYNAMIC mask to specify the features that can be optionally enabled by kernel components. This is similar to XFEATURE_MASK_USER_DYNAMIC in that it contains optional xfeatures that can allows the FPU buffer to be dynamically sized. The difference is that the KERNEL variant contains supervisor features and will be enabled by kernel components that need them, and not directly by the user. Currently it's used by KVM to configure guest dedicated fpstate for calculating the xfeature and fpstate storage size etc. The kernel dynamic xfeatures now only contain XFEATURE_CET_KERNEL, which is supported by host as they're enabled in kernel XSS MSR setting but relevant CPU feature, i.e., supervisor shadow stack, is not enabled in host kernel therefore it can be omitted for normal fpstate by default. Remove the kernel dynamic feature from fpu_kernel_cfg.default_features so that the bits in xstate_bv and xcomp_bv are cleared and xsaves/xrstors can be optimized by HW for normal fpstate. Suggested-by: Dave Hansen Signed-off-by: Yang Weijiang Reviewed-by: Rick Edgecombe --- arch/x86/include/asm/fpu/xstate.h | 5 ++++- arch/x86/kernel/fpu/xstate.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h index 3b4a038d3c57..a212d3851429 100644 --- a/arch/x86/include/asm/fpu/xstate.h +++ b/arch/x86/include/asm/fpu/xstate.h @@ -46,9 +46,12 @@ #define XFEATURE_MASK_USER_RESTORE \ (XFEATURE_MASK_USER_SUPPORTED & ~XFEATURE_MASK_PKRU) -/* Features which are dynamically enabled for a process on request */ +/* Features which are dynamically enabled per userspace request */ #define XFEATURE_MASK_USER_DYNAMIC XFEATURE_MASK_XTILE_DATA +/* Features which are dynamically enabled per kernel side request */ +#define XFEATURE_MASK_KERNEL_DYNAMIC XFEATURE_MASK_CET_KERNEL + /* All currently supported supervisor features */ #define XFEATURE_MASK_SUPERVISOR_SUPPORTED (XFEATURE_MASK_PASID | \ XFEATURE_MASK_CET_USER | \ diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 03e166a87d61..ca4b83c142eb 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -824,6 +824,7 @@ void __init fpu__init_system_xstate(unsigned int legacy_size) /* Clean out dynamic features from default */ fpu_kernel_cfg.default_features = fpu_kernel_cfg.max_features; fpu_kernel_cfg.default_features &= ~XFEATURE_MASK_USER_DYNAMIC; + fpu_kernel_cfg.default_features &= ~XFEATURE_MASK_KERNEL_DYNAMIC; fpu_user_cfg.default_features = fpu_user_cfg.max_features; fpu_user_cfg.default_features &= ~XFEATURE_MASK_USER_DYNAMIC; -- 2.39.3