From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796533976; b=ksTB5I+0LCmyFqI1elZxtBchIOg64tijrXdvCV3naHpiYgizO/w1O1houFh5yvU8n2xA U2AulAbQq1Ja7nK8lepIl29P9gq4FGLqSABWtzy6TQpv+GEkUn9AzC/h8IhxASBsOT+25 uYEw5lD6Fwg7OjYpumrE3W7O2CdCOG5sIcuHAKQr7swzrxnlsfNv8/vP66zI1i7Ct54Pu 9H0KtZVgnZEXH3AWHW03Y0uyI8Vnr7mYR92qzSxaCR3kFz/n0tp81GKI/0716kA7JSWGG 3CK/49xiMSnGxpd46+g0DwvH1nZN3j98qVel6pjzlZTDQKuJrXMBMgYg8E372LasnLA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796533976; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=2V6tnKR9ATGdkvwf389A9leYzQS+8rDFpZVfPo4QTW8=; b=L45HgGTPXPmRdMkkTYczSyXF9nl0v4MQo5uvsHTdVlhoeZVzpRSkCuCkhyN9gOAtm5k9 5eM4juVCU1WIyOSlXEmHvbmEDAMPUsges5y5Vqgz47J9lgxKJmAcJhLoG05F3TDie5hp9 IobckvyL76fuLsnbqIOuX/p/l+gYoHpT6kxCB309x4RI5i0C7YRKnvSYVrUS62aEBlQoi 3mvJTlQrKE8+vt7Ln0/BAQaddBFPn1eRdWC6f7XRqCSTAiTHZR85MFF/z6ID8O/7GxYq8 ffWbOygcp022qsstL1LYkmObEUnvkTx3vBiaawFRYvE9EafgBdVyEz0SqUFhG1Rc8aw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=T3lpFPu+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3FB8606A321 for ; Sun, 6 Dec 2026 05:12:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=T3lpFPu+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 386121F00A07; Sun, 6 Dec 2026 05:12:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796533976; bh=2V6tnKR9ATGdkvwf389A9leYzQS+8rDFpZVfPo4QTW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=T3lpFPu+1ra+Dw3NrTi/+bZdbk9GCeWxa5CdmhzJ35ml0SJrGV4RucMOjyRBTHSY5 cKYSTSVblZkGrnAzKUyRDAQt6WTyUk1qeIMco0UhHsie+PqZYeoJ7t1dZBA58JA/rF 0B1m38Ce1x4C4Xr9ON2TGuIaK+6/UZfxdcbKkjXdYS9XmihNpV2S4EuK3hSxOpzTRC ArvTs+6cc7XcI2YhYt4zyZQKsf4HfuUDpqtEFkpE5Mb2E4s5Ns+c25EuxFoAcpIkmh qzH/6K5dgX3wxXG06uQkOUqAzktUQ2SZzvjIeiD/1HTU5TwojjioJKm3tZyWIdBGbq yOCgTtrsqF3Jw== From: Eric Biggers To: x86@kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Dapeng Mi , Kan Liang , Peter Zijlstra , Jiaming Zhang , Eric Biggers Subject: [PATCH 4/4] x86/fpu: Remove cpu_has_xfeatures() Date: Sat, 5 Dec 2026 21:12:25 -0800 Message-ID: <20261206051225.298193-5-ebiggers@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261206051225.298193-1-ebiggers@kernel.org> References: <20261206051225.298193-1-ebiggers@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The only remaining caller of cpu_has_xfeatures() is print_xstate_features(), which uses it only to check and get the name of a single feature. Remove cpu_has_xfeatures() and inline the needed check directly into print_xstate_features(). This also makes the trailing "unknown xstate feature" entry at index XFEATURE_MAX of xfeature_names[] unnecessary, so remove it and add a static_assert() verifying ARRAY_SIZE(xfeature_names) == XFEATURE_MAX. Finally, make xfeature_names[] an __initconst, as it is no longer accessed from any non-__init functions. Signed-off-by: Eric Biggers --- arch/x86/include/asm/fpu/api.h | 9 ------- arch/x86/kernel/fpu/xstate.c | 46 +++------------------------------- 2 files changed, 4 insertions(+), 51 deletions(-) diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h index 90c63fe19c0fb..cfed8b24d64f0 100644 --- a/arch/x86/include/asm/fpu/api.h +++ b/arch/x86/include/asm/fpu/api.h @@ -99,15 +99,6 @@ static inline void fpregs_assert_state_consistent(void) { } */ extern void switch_fpu_return(void); -/* - * Query the presence of one or more xfeatures. Works on any legacy CPU as well. - * - * If 'feature_name' is set then put a human-readable description of - * the feature there as well - this can be used to print error (or success) - * messages. - */ -extern int cpu_has_xfeatures(u64 xfeatures_mask, const char **feature_name); - /* Trap handling */ extern int fpu__exception_code(struct fpu *fpu, int trap_nr); extern void fpu_sync_fpstate(struct fpu *fpu); diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 12759e17f3410..30f22434e897f 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -44,7 +44,7 @@ * xfeature is completely unused. We use other mechanisms * to save/restore PT state in Linux. */ -static const char *xfeature_names[] = +static const char * const xfeature_names[] __initconst = { "x87 floating point registers", "SSE registers", @@ -66,8 +66,8 @@ static const char *xfeature_names[] = "AMX Tile config", "AMX Tile data", "APX registers", - "unknown xstate feature", }; +static_assert(ARRAY_SIZE(xfeature_names) == XFEATURE_MAX); static unsigned short xsave_cpuid_features[] __initdata = { [XFEATURE_FP] = X86_FEATURE_FPU, @@ -122,44 +122,6 @@ static inline unsigned int next_xfeature_order(unsigned int i, u64 mask) #define XSTATE_FLAG_SUPERVISOR BIT(0) #define XSTATE_FLAG_ALIGNED64 BIT(1) -/* - * Return whether the system supports a given xfeature. - * - * Also return the name of the (most advanced) feature that the caller requested: - */ -int cpu_has_xfeatures(u64 xfeatures_needed, const char **feature_name) -{ - u64 xfeatures_missing = xfeatures_needed & ~fpu_kernel_cfg.max_features; - - if (unlikely(feature_name)) { - long xfeature_idx, max_idx; - u64 xfeatures_print; - /* - * So we use FLS here to be able to print the most advanced - * feature that was requested but is missing. So if a driver - * asks about "XFEATURE_MASK_SSE | XFEATURE_MASK_YMM" we'll print the - * missing AVX feature - this is the most informative message - * to users: - */ - if (xfeatures_missing) - xfeatures_print = xfeatures_missing; - else - xfeatures_print = xfeatures_needed; - - xfeature_idx = fls64(xfeatures_print)-1; - max_idx = ARRAY_SIZE(xfeature_names)-1; - xfeature_idx = min(xfeature_idx, max_idx); - - *feature_name = xfeature_names[xfeature_idx]; - } - - if (xfeatures_missing) - return 0; - - return 1; -} -EXPORT_SYMBOL_GPL(cpu_has_xfeatures); - static bool xfeature_is_aligned64(int xfeature_nr) { return xstate_flags[xfeature_nr] & XSTATE_FLAG_ALIGNED64; @@ -302,9 +264,9 @@ static void __init print_xstate_features(void) for (i = 0; i < XFEATURE_MAX; i++) { u64 mask = BIT_ULL(i); - const char *name; + const char *name = xfeature_names[i]; - if (cpu_has_xfeatures(mask, &name)) + if (fpu_kernel_cfg.max_features & mask) pr_info("x86/fpu: Supporting XSAVE feature 0x%03Lx: '%s'\n", mask, name); } } -- 2.56.1