From nobody Tue Dec 2 02:30:05 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 D700B393DF6 for ; Wed, 19 Nov 2025 14:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562854; cv=none; b=YTK3Q6LrjZYxCy3Nc9qb8x0MykVMKUpnaJ6FiiHnCG5rV3iyqF5strn2B8FgiQ0n5ixQI53OIpyg+Nx/UnD1bd3WAjWrOt9gfhVKZ/LcfK1y+6LCoaeLwEfBwCfzzwXq8NGhHm1iDbdE0OI5aNlsXr0lhQhu9Ud39Iyy62YbykA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562854; c=relaxed/simple; bh=dih0yqYNLYG/X/YrYAGfXh8oLIWRRw8szNOm2lxcVEA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OlltVPaun9qziNwRPUXq25zA8vmn/R7zkwktEt9y2bl+3SDcjFZmW6fxueak7O4JbZyoB/SwrUGgV2gQEIXd2Y2+bK7nVp2UbO7pYlJHD1kjboTX5qVyi9y6y7Qhn4ZApIKTSmBbs36IIud0hrMC/HjFNDcheMzDrki4e2IgHeg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=G+kAtNej; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="G+kAtNej" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJERqoN011660; Wed, 19 Nov 2025 14:33:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=L0pMm a/pDWdcqYhKnf5AutK2TpRfCnU41RiKq49+Au8=; b=G+kAtNej0VYj9xyy7SSex rF682XfwG7WxDQ+Yaj3qiU/c4/gRkO71p/FzdIQH8ytFSJfITtPeSHeZ+eOubRb/ KBUN9xSyvGs9eTF/jiAq2Iuntc5/QJg5RKTzOvINdGRxb5HGwKHzzq/xo3d1yELI 4Mb9ZQrQhmYKGB5eqItQ5CxCVAHZ4CLNLK/O/1lnFoF2imuT/i24/6z7oWHkSlGG 8/cv2C10P/u+FNZWI/W4io19YkQ/JW8E4xTi+AET/bPKh+4KjceDd8St0FUrBiYj OiZax8wGXeNJ4+nRC5SAPfUlgqadoPBvvaXpcxpp/o/fuo+PfDosnB5LVIlFSjw4 Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbuq15w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:40 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJDlWrT002514; Wed, 19 Nov 2025 14:33:39 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyans38-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:39 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5AJEWnnu022495; Wed, 19 Nov 2025 14:33:39 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-160-110.vpn.oracle.com [10.154.160.110]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4aefyanr5p-27; Wed, 19 Nov 2025 14:33:38 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, david.laight.linux@gmail.com Cc: alexandre.chartre@oracle.com Subject: [PATCH v5 26/30] objtool: Function to get the name of a CPU feature Date: Wed, 19 Nov 2025 15:32:43 +0100 Message-ID: <20251119143247.3944213-27-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251119143247.3944213-1-alexandre.chartre@oracle.com> References: <20251119143247.3944213-1-alexandre.chartre@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-19_04,2025-11-18_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511190116 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX2hW6mlfALfu5 AZsKL0HM4dojYKYF7a6Z5unlZHHVnNMalUVtMCu8vgV4QDKSZKY0KdzbtAQu6NRXuQ0OO0Dk7dl Rmrpj6rOTCHFa1LVE7jjZstuDoxU8fUfmEaJJ9NrdU3yW5YVySSRu3oZA6C4nl+Fg8rz07UzNMK cerkhot1qQ4fbIm05za+M3JCrOQmbnHxby5uIQ8T32JjOowYRfToL+UJxlO9V9hXfALAX/qS4IR +MKcSF0caAD1+p+I+f0/V5EQ2BJTnJaRhdyepmszf0Q4Mlv+SYdOU+1eswO0knpyL06Yi5KdY5i PEQpHX7Ohxxa81CYa3RbTTFEMaV84LTRBmO1Dg7thKiPlVx5CapbOe0pbI3tUAlS55M3gsdRXiQ LC8L8/VY7p0VDAVACT4gM9S7TVcn6Q== X-Proofpoint-GUID: AfhUxhH7VhtKI-asmBTg7qCpdHxB6hKw X-Proofpoint-ORIG-GUID: AfhUxhH7VhtKI-asmBTg7qCpdHxB6hKw X-Authority-Analysis: v=2.4 cv=Rdydyltv c=1 sm=1 tr=0 ts=691dd544 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=BmP2q_L__UogPSo-:21 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=pMlTRUUgVTb7_b65wjsA:9 Content-Type: text/plain; charset="utf-8" Add a function to get the name of a CPU feature. The function is architecture dependent and currently only implemented for x86. The feature names are automatically generated from the cpufeatures.h include file. Signed-off-by: Alexandre Chartre --- .../x86/tools/gen-cpu-feature-names-x86.awk | 33 +++++++++++++++++++ tools/objtool/Makefile | 1 + tools/objtool/arch/loongarch/special.c | 5 +++ tools/objtool/arch/powerpc/special.c | 5 +++ tools/objtool/arch/x86/Build | 8 +++++ tools/objtool/arch/x86/special.c | 10 ++++++ tools/objtool/include/objtool/special.h | 2 ++ 7 files changed, 64 insertions(+) create mode 100644 tools/arch/x86/tools/gen-cpu-feature-names-x86.awk diff --git a/tools/arch/x86/tools/gen-cpu-feature-names-x86.awk b/tools/arc= h/x86/tools/gen-cpu-feature-names-x86.awk new file mode 100644 index 0000000000000..1b1c1d84225c2 --- /dev/null +++ b/tools/arch/x86/tools/gen-cpu-feature-names-x86.awk @@ -0,0 +1,33 @@ +#!/bin/awk -f +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2025, Oracle and/or its affiliates. +# +# Usage: awk -f gen-cpu-feature-names-x86.awk cpufeatures.h > cpu-feature-= names.c +# + +BEGIN { + print "/* cpu feature name array generated from cpufeatures.h */" + print "/* Do not change this code. */" + print + print "static const char *cpu_feature_names[(NCAPINTS+NBUGINTS)*32] =3D {" + + feature_expr =3D "(X86_FEATURE_[A-Z0-9_]+)\\s+\\(([0-9*+ ]+)\\)" + debug_expr =3D "(X86_BUG_[A-Z0-9_]+)\\s+X86_BUG\\(([0-9*+ ]+)\\)" +} + +/^#define X86_FEATURE_/ { + if (match($0, feature_expr, m)) { + print "\t[" m[2] "] =3D \"" m[1] "\"," + } +} + +/^#define X86_BUG_/ { + if (match($0, debug_expr, m)) { + print "\t[NCAPINTS*32+(" m[2] ")] =3D \"" m[1] "\"," + } +} + +END { + print "};" +} diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index fdc3d32dc79e7..ca49a11718889 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -126,6 +126,7 @@ clean: $(LIBSUBCMD)-clean $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -nam= e '\.*.d' -delete $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep + $(Q)$(RM) $(OUTPUT)arch/x86/lib/cpu-feature-names.c $(OUTPUT)fixdep =20 FORCE: =20 diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/lo= ongarch/special.c index a80b75f7b061f..aba774109437f 100644 --- a/tools/objtool/arch/loongarch/special.c +++ b/tools/objtool/arch/loongarch/special.c @@ -194,3 +194,8 @@ struct reloc *arch_find_switch_table(struct objtool_fil= e *file, =20 return rodata_reloc; } + +const char *arch_cpu_feature_name(int feature_number) +{ + return NULL; +} diff --git a/tools/objtool/arch/powerpc/special.c b/tools/objtool/arch/powe= rpc/special.c index 51610689abf72..8f9bf61ca0899 100644 --- a/tools/objtool/arch/powerpc/special.c +++ b/tools/objtool/arch/powerpc/special.c @@ -18,3 +18,8 @@ struct reloc *arch_find_switch_table(struct objtool_file = *file, { exit(-1); } + +const char *arch_cpu_feature_name(int feature_number) +{ + return NULL; +} diff --git a/tools/objtool/arch/x86/Build b/tools/objtool/arch/x86/Build index 3dedb2fd8f3a0..1067355361b56 100644 --- a/tools/objtool/arch/x86/Build +++ b/tools/objtool/arch/x86/Build @@ -11,4 +11,12 @@ $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_scrip= t) $(inat_tables_maps) =20 $(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/lib/inat-tables.c =20 +cpu_features =3D ../arch/x86/include/asm/cpufeatures.h +cpu_features_script =3D ../arch/x86/tools/gen-cpu-feature-names-x86.awk + +$(OUTPUT)arch/x86/lib/cpu-feature-names.c: $(cpu_features_script) $(cpu_fe= atures) + $(Q)$(call echo-cmd,gen)$(AWK) -f $(cpu_features_script) $(cpu_features) = > $@ + +$(OUTPUT)arch/x86/special.o: $(OUTPUT)arch/x86/lib/cpu-feature-names.c + CFLAGS_decode.o +=3D -I$(OUTPUT)arch/x86/lib diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index 09300761f1085..b6b40c56da896 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -4,6 +4,10 @@ #include #include #include +#include + +/* cpu feature name array generated from cpufeatures.h */ +#include "lib/cpu-feature-names.c" =20 void arch_handle_alternative(struct special_alt *alt) { @@ -134,3 +138,9 @@ struct reloc *arch_find_switch_table(struct objtool_fil= e *file, *table_size =3D 0; return rodata_reloc; } + +const char *arch_cpu_feature_name(int feature_number) +{ + return (feature_number < ARRAY_SIZE(cpu_feature_names)) ? + cpu_feature_names[feature_number] : NULL; +} diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/includ= e/objtool/special.h index b22410745e4a1..121c3761899c1 100644 --- a/tools/objtool/include/objtool/special.h +++ b/tools/objtool/include/objtool/special.h @@ -38,4 +38,6 @@ bool arch_support_alt_relocation(struct special_alt *spec= ial_alt, struct reloc *arch_find_switch_table(struct objtool_file *file, struct instruction *insn, unsigned long *table_size); +const char *arch_cpu_feature_name(int feature_number); + #endif /* _SPECIAL_H */ --=20 2.43.5