* [PATCH v2 00/10] arm64: sysreg: More input checks in the sysreg generator
@ 2026-11-27 7:44 Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 02/10] arm64: sysreg: Remove the dead range check from parse_bitdef() Fuad Tabba
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Fuad Tabba @ 2026-11-27 7:44 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Mark Rutland, Marc Zyngier, Oliver Upton, Mark Brown,
Sascha Bischoff, Steffen Eiden, linux-arm-kernel, linux-kernel,
Fuad Tabba
Hi folks,
Changes since v1 [1]:
- Split the TRFCR_ELx.TS change into its own patch. (Steffen)
- Reworded the leading-zero error message. (Steffen)
- Collected tags from Steffen and Mark Brown. (thanks!)
After finding yet another bug in the sysreg file, I think it's time to
stop filling potholes and have the generator reject them instead.
The bug is in MPAM1_EL12. Its Fields line refers to a SysregFields
block that doesn't exist, so its RES0, RES1 and UNKN masks expand to
undefined names. The masks aren't used yet. Patch 1 fixes it.
The rest of the series adds checks to gen-sysreg.awk for input it
accepts while the kernel still builds: a Sysreg and a SysregFields with
the same name (Mark Rutland's suggestion [2]), a Fields or Mapping
target that isn't defined, an enum value not written at its field's
width, a macro defined twice, an encoding that's out of range or has a
leading zero, and a bit position with a leading zero. Three patches
prepare for the checks. One removes a range check that can never fail,
one stops the end-of-file checks from running after an error, and one
drops the leading zeros from the TRFCR_ELx.TS values.
With gawk, mawk and busybox awk, the generated header is the same
before and after the series, apart from the MPAM1_EL12 lines and the
number of digits in the TRFCR_ELx.TS values.
Based on Linux 7.4-rc3 (aebb727447640).
Cheers,
/fuad
[1] https://lore.kernel.org/all/20261123075219.369042-1-fuad.tabba@linux.dev/
[2] https://lore.kernel.org/all/aLF9mSCs1B2gk8BU@J2N7QTR9R3/
Fuad Tabba (10):
arm64: sysreg: Map MPAM1_EL12 to MPAM1_EL1
arm64: sysreg: Remove the dead range check from parse_bitdef()
arm64: sysreg: Reject a Sysreg and a SysregFields with the same name
arm64: sysreg: Don't run the end-of-file checks after an error
arm64: sysreg: Reject a Fields or Mapping line with an undefined
target
arm64: sysreg: Drop the leading zeros from the TRFCR_ELx.TS values
arm64: sysreg: Reject an enum value not written at its field's width
arm64: sysreg: Reject a macro name defined twice
arm64: sysreg: Reject an out-of-range register encoding
arm64: sysreg: Reject a bit position written with a leading zero
arch/arm64/tools/gen-sysreg.awk | 48 ++++++++++++++++++++++++++-------
arch/arm64/tools/sysreg | 16 +++++------
2 files changed, 47 insertions(+), 17 deletions(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 02/10] arm64: sysreg: Remove the dead range check from parse_bitdef()
2026-11-27 7:44 [PATCH v2 00/10] arm64: sysreg: More input checks in the sysreg generator Fuad Tabba
@ 2026-11-27 7:44 ` Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 04/10] arm64: sysreg: Don't run the end-of-file checks after an error Fuad Tabba
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Fuad Tabba @ 2026-11-27 7:44 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Mark Rutland, Marc Zyngier, Oliver Upton, Mark Brown,
Sascha Bischoff, Steffen Eiden, linux-arm-kernel, linux-kernel,
Fuad Tabba
parse_bitdef() ends by testing "low > high", but the script doesn't
assign either variable, so the test compares two empty values and never
fires. The "msb < lsb" test just above it already rejects an inverted
range.
Remove the dead test.
No functional change intended.
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/tools/gen-sysreg.awk | 2 --
1 file changed, 2 deletions(-)
diff --git a/arch/arm64/tools/gen-sysreg.awk b/arch/arm64/tools/gen-sysreg.awk
index 53844f5c5e525..b299342463631 100755
--- a/arch/arm64/tools/gen-sysreg.awk
+++ b/arch/arm64/tools/gen-sysreg.awk
@@ -100,8 +100,6 @@ function parse_bitdef(reg, field, bitdef, _bits)
fatal(reg "." field " invalid low bit in '" bitdef "'")
if (msb < lsb)
fatal(reg "." field " invalid bit-range '" bitdef "'")
- if (low > high)
- fatal(reg "." field " has invalid range " high "-" low)
next_bit = lsb - 1
}
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 04/10] arm64: sysreg: Don't run the end-of-file checks after an error
2026-11-27 7:44 [PATCH v2 00/10] arm64: sysreg: More input checks in the sysreg generator Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 02/10] arm64: sysreg: Remove the dead range check from parse_bitdef() Fuad Tabba
@ 2026-11-27 7:44 ` Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 05/10] arm64: sysreg: Reject a Fields or Mapping line with an undefined target Fuad Tabba
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Fuad Tabba @ 2026-11-27 7:44 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Mark Rutland, Marc Zyngier, Oliver Upton, Mark Brown,
Sascha Bischoff, Steffen Eiden, linux-arm-kernel, linux-kernel,
Fuad Tabba
fatal() ends the run with exit, but awk still runs the END rule after
it, and END checks the file as though it had been read to the end. An
error inside a block leaves that block open, so the error is followed by
a second, bogus one about a missing terminator.
Skip the END checks once fatal() has run.
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/tools/gen-sysreg.awk | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/arm64/tools/gen-sysreg.awk b/arch/arm64/tools/gen-sysreg.awk
index 8ce4981273dd3..c4fa27cd9beff 100755
--- a/arch/arm64/tools/gen-sysreg.awk
+++ b/arch/arm64/tools/gen-sysreg.awk
@@ -19,6 +19,7 @@ function fatal(msg) {
}
printf "\n"
+ __fatal = 1
exit 1
}
@@ -116,6 +117,10 @@ BEGIN {
}
END {
+ # fatal() exits before the whole file is read, and exit still runs END.
+ if (__fatal)
+ exit 1
+
if (__current_block_depth != 0)
fatal("Missing terminator for " block_current() " block")
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 05/10] arm64: sysreg: Reject a Fields or Mapping line with an undefined target
2026-11-27 7:44 [PATCH v2 00/10] arm64: sysreg: More input checks in the sysreg generator Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 02/10] arm64: sysreg: Remove the dead range check from parse_bitdef() Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 04/10] arm64: sysreg: Don't run the end-of-file checks after an error Fuad Tabba
@ 2026-11-27 7:44 ` Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 06/10] arm64: sysreg: Drop the leading zeros from the TRFCR_ELx.TS values Fuad Tabba
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Fuad Tabba @ 2026-11-27 7:44 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Mark Rutland, Marc Zyngier, Oliver Upton, Mark Brown,
Sascha Bischoff, Steffen Eiden, linux-arm-kernel, linux-kernel,
Fuad Tabba
A Sysreg block can use another block's layout. "Fields X" names a
SysregFields block and "Mapping X" another Sysreg. The generator emits
the register's RESx and UNKN masks as X_RES0, X_RES1 and X_UNKN, but it
doesn't check that X exists. A misspelt or missing X gives macros that
expand to undefined names, and the build fails only once something uses
them. MPAM1_EL12 had such a line.
Check every Fields and Mapping target once the whole file is read, since
a target may be defined after the register that names it (MPAM1_EL1
follows MPAM1_EL12). Either kind of block defines the masks, so the
check accepts either kind as the target of a Fields or a Mapping line.
Give fatal() an optional line number, so that the error is reported at
the Fields or Mapping line.
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/tools/gen-sysreg.awk | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/tools/gen-sysreg.awk b/arch/arm64/tools/gen-sysreg.awk
index c4fa27cd9beff..1843d283192d2 100755
--- a/arch/arm64/tools/gen-sysreg.awk
+++ b/arch/arm64/tools/gen-sysreg.awk
@@ -9,8 +9,8 @@ function block_current() {
}
# Log an error and terminate
-function fatal(msg) {
- print "Error at " NR ": " msg > "/dev/stderr"
+function fatal(msg, line) {
+ print "Error at " (line ? line : NR) ": " msg > "/dev/stderr"
printf "Current block nesting:"
@@ -124,6 +124,11 @@ END {
if (__current_block_depth != 0)
fatal("Missing terminator for " block_current() " block")
+ # A Fields or Mapping target may be defined after its user.
+ for (line in refs)
+ if (!(refs[line] in defined_regs))
+ fatal("Undefined Fields or Mapping target " refs[line], line)
+
print "#endif /* __ASM_SYSREG_DEFS_H */"
}
@@ -241,6 +246,8 @@ $1 == "EndSysreg" && block_current() == "Sysreg" {
print "/* For " reg " fields see " $2 " */"
print ""
+ refs[NR] = $2
+
next_bit = -1
res0 = $2 "_RES0"
res1 = $2 "_RES1"
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 06/10] arm64: sysreg: Drop the leading zeros from the TRFCR_ELx.TS values
2026-11-27 7:44 [PATCH v2 00/10] arm64: sysreg: More input checks in the sysreg generator Fuad Tabba
` (2 preceding siblings ...)
2026-11-27 7:44 ` [PATCH v2 05/10] arm64: sysreg: Reject a Fields or Mapping line with an undefined target Fuad Tabba
@ 2026-11-27 7:44 ` Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 08/10] arm64: sysreg: Reject a macro name defined twice Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 10/10] arm64: sysreg: Reject a bit position written with a leading zero Fuad Tabba
5 siblings, 0 replies; 7+ messages in thread
From: Fuad Tabba @ 2026-11-27 7:44 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Mark Rutland, Marc Zyngier, Oliver Upton, Mark Brown,
Sascha Bischoff, Steffen Eiden, linux-arm-kernel, linux-kernel,
Fuad Tabba
TS in TRFCR_EL1 and TRFCR_EL2 is a two-bit field, but its enum values
are written with four binary digits. They're the only enum values in the
sysreg file whose number of digits differs from their field's width, and
the values themselves fit.
Drop the two leading zeros from each, ahead of a check that requires
every enum value to have as many digits as its field has bits.
No functional change intended.
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/tools/sysreg | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg
index ebe5c5bd6fef6..5b587a7544e40 100644
--- a/arch/arm64/tools/sysreg
+++ b/arch/arm64/tools/sysreg
@@ -2919,9 +2919,9 @@ EndSysreg
Sysreg TRFCR_EL1 3 0 1 2 1
Res0 63:7
UnsignedEnum 6:5 TS
- 0b0001 VIRTUAL
- 0b0010 GUEST_PHYSICAL
- 0b0011 PHYSICAL
+ 0b01 VIRTUAL
+ 0b10 GUEST_PHYSICAL
+ 0b11 PHYSICAL
EndEnum
Res0 4:2
Field 1 ExTRE
@@ -4300,10 +4300,10 @@ EndSysreg
Sysreg TRFCR_EL2 3 4 1 2 1
Res0 63:7
UnsignedEnum 6:5 TS
- 0b0000 USE_TRFCR_EL1_TS
- 0b0001 VIRTUAL
- 0b0010 GUEST_PHYSICAL
- 0b0011 PHYSICAL
+ 0b00 USE_TRFCR_EL1_TS
+ 0b01 VIRTUAL
+ 0b10 GUEST_PHYSICAL
+ 0b11 PHYSICAL
EndEnum
Res0 4
Field 3 CX
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 08/10] arm64: sysreg: Reject a macro name defined twice
2026-11-27 7:44 [PATCH v2 00/10] arm64: sysreg: More input checks in the sysreg generator Fuad Tabba
` (3 preceding siblings ...)
2026-11-27 7:44 ` [PATCH v2 06/10] arm64: sysreg: Drop the leading zeros from the TRFCR_ELx.TS values Fuad Tabba
@ 2026-11-27 7:44 ` Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 10/10] arm64: sysreg: Reject a bit position written with a leading zero Fuad Tabba
5 siblings, 0 replies; 7+ messages in thread
From: Fuad Tabba @ 2026-11-27 7:44 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Mark Rutland, Marc Zyngier, Oliver Upton, Mark Brown,
Sascha Bischoff, Steffen Eiden, linux-arm-kernel, linux-kernel,
Fuad Tabba
The generator rejects a duplicate register, SysregFields block, prefix
or enum value, but not two definitions of the same macro. Two fields
called F in REG make it emit REG_F twice with different masks, which the
compiler reports only as a redefinition warning against the generated
header, in every file that includes it. Two values of one enum sharing a
name do the same, and so do names that collide only once the generator
joins them: a field A_B beside value B of field A, a field F_MASK beside
F, or a field B_C in FOO beside a field C in FOO_B.
Record every macro name the generator defines, and fail on the second
definition. This covers a duplicate block or prefix too, but their own
checks stay, since they report the duplicate at the block's own line, by
block name.
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/tools/gen-sysreg.awk | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm64/tools/gen-sysreg.awk b/arch/arm64/tools/gen-sysreg.awk
index cde526896ed96..0bd6aab8aae0f 100755
--- a/arch/arm64/tools/gen-sysreg.awk
+++ b/arch/arm64/tools/gen-sysreg.awk
@@ -46,6 +46,10 @@ function expect_fields(nf) {
# Print a CPP macro definition, padded with spaces so that the macro bodies
# line up in a column
function define(prefix, name, val) {
+ if ((prefix name) in defined_macros)
+ fatal("Duplicate macro " prefix name)
+ defined_macros[prefix name] = 1
+
printf "%-56s%s\n", "#define " prefix name, val
}
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 10/10] arm64: sysreg: Reject a bit position written with a leading zero
2026-11-27 7:44 [PATCH v2 00/10] arm64: sysreg: More input checks in the sysreg generator Fuad Tabba
` (4 preceding siblings ...)
2026-11-27 7:44 ` [PATCH v2 08/10] arm64: sysreg: Reject a macro name defined twice Fuad Tabba
@ 2026-11-27 7:44 ` Fuad Tabba
5 siblings, 0 replies; 7+ messages in thread
From: Fuad Tabba @ 2026-11-27 7:44 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Mark Rutland, Marc Zyngier, Oliver Upton, Mark Brown,
Sascha Bischoff, Steffen Eiden, linux-arm-kernel, linux-kernel,
Fuad Tabba
parse_bitdef() reads a field's msb and lsb as decimal and checks the
layout with them, but the generator copies the digits into GENMASK()
unchanged, and C reads a leading zero as octal. "Field 63:010 A" is
accepted as bits 63 to 10, with the next field starting at bit 9, while
its mask is GENMASK(63, 010), bits 63 to 8, which overlaps that field.
Require both ends of a bit range to be decimal numbers without a leading
zero.
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/tools/gen-sysreg.awk | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/tools/gen-sysreg.awk b/arch/arm64/tools/gen-sysreg.awk
index 057dc98082b5e..103420b58d24c 100755
--- a/arch/arm64/tools/gen-sysreg.awk
+++ b/arch/arm64/tools/gen-sysreg.awk
@@ -102,7 +102,8 @@ function parse_bitdef(reg, field, bitdef, _bits)
fatal("invalid bit-range definition '" bitdef "'")
}
-
+ if (msb !~ /^(0|[1-9][0-9]*)$/ || lsb !~ /^(0|[1-9][0-9]*)$/)
+ fatal(reg "." field " non-decimal bit-range '" bitdef "'")
if (msb != next_bit)
fatal(reg "." field " starts at " msb " not " next_bit)
if (63 < msb || msb < 0)
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-27 7:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 7:44 [PATCH v2 00/10] arm64: sysreg: More input checks in the sysreg generator Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 02/10] arm64: sysreg: Remove the dead range check from parse_bitdef() Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 04/10] arm64: sysreg: Don't run the end-of-file checks after an error Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 05/10] arm64: sysreg: Reject a Fields or Mapping line with an undefined target Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 06/10] arm64: sysreg: Drop the leading zeros from the TRFCR_ELx.TS values Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 08/10] arm64: sysreg: Reject a macro name defined twice Fuad Tabba
2026-11-27 7:44 ` [PATCH v2 10/10] arm64: sysreg: Reject a bit position written with a leading zero Fuad Tabba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox