From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 CF54629E113 for ; Mon, 24 Nov 2025 16:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764003005; cv=none; b=AYTF+MgWBkvgy7/aTHI67AuwwMgBG9Fhk1AA2ERPpy8SvKBrj/gx0rD0RbmRvma10xL/3iOxBWgGYeoYVhuDpmCkZcQ80MhBFMxOI4meFzuwMnqSC+CemtZWcLc56a3TtfKO5kgfxqN3UgAa99QYBIynNJWDl98Kivb5GuAG0Yg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764003005; c=relaxed/simple; bh=4pushvMQK9rIxfywFSzTL8nzVwPqHogBPX8YrLycsJ0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=IJ4Aq/y9s7JD+IN7i0M8czUANtYD/CcacJPzp9xNHI5RkZIsRYykSruXvqZOQgfBWOZhPUCT7S21feo0NwMX/F/K0F1kecbS3MKyhgKo7Ira04OF/BHdxSNswNPFPrPG9eeuaVs6G/3JEDIMW59bgXdWAM9K/q3GPfZXtYFn92Q= 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=OyFoMp1o; arc=none smtp.client-ip=205.220.177.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="OyFoMp1o" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5AOCVFT31085492; Mon, 24 Nov 2025 16:49:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=corp-2025-04-25; bh=055GAml+QfxgP/pzZTf9QS80wDs5d 77bYFNGmj/KFfE=; b=OyFoMp1ooEkaHEQbOc/nsog+/BDSBQYbyZ7vHcWCyvuh+ nrqqh7pHW87WGnteQ6SLGJCLJjiVu2x+dSjoi7kjE4ZCsd55w2IBu9MnHfm7EHP1 zXFOuIRlD8iRrtwlHtaXssGSs+V66QFASXfnvDD7l+OG62lwLhs16hfEJY6Mx2eD 2oFKtdcrP9YXv+WcSY5Mo+4dOqrPP57MAGlyqe0lgssgbubLOiS87ZIdHTWYhVoU a0XVznWQ+8UqYgPnR8s50xYKLLBuSjDG8j2ZFKsnPjYMq+yNxg8WoM9oVXDMeMKM ZYYm7YFjPb5YltvUJPlqE0i1ySgUodwiPNBL1DqoA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4ak811jeau-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Nov 2025 16:49:51 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AOF53TF022440; Mon, 24 Nov 2025 16:49:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4ak3mjbxp9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Nov 2025 16:49:50 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5AOGkwmH022626; Mon, 24 Nov 2025 16:49:48 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-160-26.vpn.oracle.com [10.154.160.26]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 4ak3mjbwu0-1; Mon, 24 Nov 2025 16:49:48 +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 v6 26/30 (mawk fix)] objtool: Add function to get the name of a CPU feature Date: Mon, 24 Nov 2025 17:48:55 +0100 Message-ID: <20251124164855.1036513-1-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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-24_06,2025-11-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 phishscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511240147 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTI0MDE0NyBTYWx0ZWRfX2/2I66HaxWPS sX57eBfsrzT/Ig5q7jhRd9cMFTUwGKpi0xhnGL2ATPlSOydLQq3epISZp1QUbuKmTHeWWnEVlqA mO2BvLqBxEnefwzoqjHmN1a0XcSrVYClY8iP6tFCWWEl5eka/3Wf4oNf3TUaEgqmi4pVUvDOJOj a6ZCKpQJqymZN18HB0F2RtjOvbaideZwKFgYTlI9/QLnqPIETduNaI7A0MgpRiI4bQerSPiedTv Pz740xnu5lyfngXwaYnSC1OIKUIc7P2SNtYSVX5LtjnO22dT7vVL5SmWTAgsRbBNitUPHjMSY4r nt+KQvmbwhZlu4/oBME7Od9xvQ8lKCltGlJ5VmqQptlsYsGoTD4nGirDjCCWV0VLSg9apx99YFy 37CmW8OSoUu6qU4o2nuWGclhv53mvwrGrf5eKOF0/1MI7nXgJGQ= X-Proofpoint-GUID: s7pvVvDoOguAyyhfRGHMfogPSmFaw573 X-Proofpoint-ORIG-GUID: s7pvVvDoOguAyyhfRGHMfogPSmFaw573 X-Authority-Analysis: v=2.4 cv=KKpXzVFo c=1 sm=1 tr=0 ts=69248cb0 b=1 cx=c_pps a=e1sVV491RgrpLwSTMOnk8w==:117 a=e1sVV491RgrpLwSTMOnk8w==:17 a=BmP2q_L__UogPSo-:21 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=bC-a23v3AAAA:8 a=yPCof4ZbAAAA:8 a=JfrnYn6hAAAA:8 a=VwQbUJbxAAAA:8 a=pMlTRUUgVTb7_b65wjsA:9 a=FO4_E8m0qiDe52t0p3_H:22 a=1CNFftbPRP8L7MoqJWF3:22 cc=ntf awl=host:13642 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 Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf Link: https://patch.msgid.link/20251121095340.464045-27-alexandre.chartre@oracle.com --- .../x86/tools/gen-cpu-feature-names-x86.awk | 34 +++++++++++++++++++ tools/objtool/.gitignore | 1 + tools/objtool/Makefile | 1 + tools/objtool/arch/loongarch/special.c | 5 +++ tools/objtool/arch/powerpc/special.c | 5 +++ tools/objtool/arch/x86/Build | 10 ++++++ tools/objtool/arch/x86/special.c | 10 ++++++ tools/objtool/include/objtool/special.h | 2 ++ 8 files changed, 68 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/arch/x86/tools/gen-cpu-feature-names-x86.awk new file mode 100644 index 0000000000000..cc4c7a3e6c2e2 --- /dev/null +++ b/tools/arch/x86/tools/gen-cpu-feature-names-x86.awk @@ -0,0 +1,34 @@ +#!/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] = {" + + value_expr = "\\([0-9*+ ]+\\)" +} + +/^#define X86_FEATURE_/ { + if (match($0, value_expr)) { + value = substr($0, RSTART + 1, RLENGTH - 2) + print "\t[" value "] = \"" $2 "\"," + } +} + +/^#define X86_BUG_/ { + if (match($0, value_expr)) { + value = substr($0, RSTART + 1, RLENGTH - 2) + print "\t[NCAPINTS*32+(" value ")] = \"" $2 "\"," + } +} + +END { + print "};" +} diff --git a/tools/objtool/.gitignore b/tools/objtool/.gitignore index 759303657bd7c..73d883128511f 100644 --- a/tools/objtool/.gitignore +++ b/tools/objtool/.gitignore @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +arch/x86/lib/cpu-feature-names.c arch/x86/lib/inat-tables.c /objtool feature diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index df793ca6fc1a1..66397d755fe4b 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -125,6 +125,7 @@ $(LIBSUBCMD)-clean: clean: $(LIBSUBCMD)-clean $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete + $(Q)$(RM) $(OUTPUT)arch/x86/lib/cpu-feature-names.c $(OUTPUT)fixdep $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.objtool $(Q)$(RM) -r -- $(OUTPUT)feature diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/loongarch/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_file *file, 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/powerpc/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..b95448ee01ee4 100644 --- a/tools/objtool/arch/x86/Build +++ b/tools/objtool/arch/x86/Build @@ -12,3 +12,13 @@ $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) $(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/lib/inat-tables.c CFLAGS_decode.o += -I$(OUTPUT)arch/x86/lib + +cpu_features = ../arch/x86/include/asm/cpufeatures.h +cpu_features_script = ../arch/x86/tools/gen-cpu-feature-names-x86.awk + +$(OUTPUT)arch/x86/lib/cpu-feature-names.c: $(cpu_features_script) $(cpu_features) + $(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_special.o := -I$(OUTPUT)arch/x86/lib diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/special.c index 09300761f1085..e817a3fff4491 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 "cpu-feature-names.c" void arch_handle_alternative(struct special_alt *alt) { @@ -134,3 +138,9 @@ struct reloc *arch_find_switch_table(struct objtool_file *file, *table_size = 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/include/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 *special_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 */ -- 2.43.5