The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Steffen Eiden <seiden@linux.ibm.com>
To: Fuad Tabba <fuad.tabba@linux.dev>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
	Mark Brown <broonie@kernel.org>,
	Sascha Bischoff <Sascha.Bischoff@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Fuad Tabba <tabba@google.com>
Subject: Re: [PATCH 6/9] arm64: sysreg: Reject an enum value not written at its field's width
Date: Mon, 23 Nov 2026 11:45:53 +0100	[thread overview]
Message-ID: <20261123104553.20959-F-seiden@linux.ibm.com> (raw)
In-Reply-To: <20261123075219.369042-7-fuad.tabba@linux.dev>

On Mon, Nov 23, 2026 at 07:52:16AM +0000, Fuad Tabba wrote:
> The generator emits each enum value as written and doesn't check it
> against the width of its field, so a value wider than the field defines
> a constant the field can't hold. The duplicate value check compares the
> strings as written, so 0b01 and 0b001 in the same field pass as distinct
> values, and the rule's pattern, an unanchored /0b[01]+/, accepts 0b12
> too.
> 
> Require each value to be 0b followed by exactly as many binary digits as
> its field has bits. The one enum written otherwise is TS, a two-bit
> field of TRFCR_EL1 and TRFCR_EL2 whose values have four digits. Write
> them with two digits, which leaves the numbers unchanged.
> 
> Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
> ---
>  arch/arm64/tools/gen-sysreg.awk |  3 +++
>  arch/arm64/tools/sysreg         | 14 +++++++-------
>  2 files changed, 10 insertions(+), 7 deletions(-)
> 

Lets split this patch into two: 

1. Fix the bitwidth of the Enums
2. Add the new check to the awk script

Then the fix is split apart from the enforcement.

The actual changes LGTM.

	Steffen


> diff --git a/arch/arm64/tools/gen-sysreg.awk b/arch/arm64/tools/gen-sysreg.awk
> index 1843d283192d2..cde526896ed96 100755
> --- a/arch/arm64/tools/gen-sysreg.awk
> +++ b/arch/arm64/tools/gen-sysreg.awk
> @@ -367,6 +367,9 @@ $1 == "EndEnum" && block_current() == "Enum" {
>  	val = $1
>  	name = $2
>  
> +	if (val !~ /^0b[01]+$/ || length(val) - 2 != msb - lsb + 1)
> +		fatal("Enum value " val " for " name " is not " (msb - lsb + 1) " binary digits")
> +
>  	if (val in seen_enum_vals)
>  		fatal("Duplicate Enum value " val " for " name)
>  	seen_enum_vals[val] = 1
> 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
> 

  reply	other threads:[~2026-11-23 10:46 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  7:52 [PATCH 0/9] arm64: sysreg: More input checks in the sysreg generator Fuad Tabba
2026-11-23  7:52 ` [PATCH 1/9] arm64: sysreg: Map MPAM1_EL12 to MPAM1_EL1 Fuad Tabba
2026-11-23  8:47   ` Steffen Eiden
2026-11-23  7:52 ` [PATCH 2/9] arm64: sysreg: Remove the dead range check from parse_bitdef() Fuad Tabba
2026-11-23  8:55   ` Steffen Eiden
2026-11-23  7:52 ` [PATCH 3/9] arm64: sysreg: Reject a Sysreg and a SysregFields with the same name Fuad Tabba
2026-11-23 10:25   ` Steffen Eiden
2026-11-23  7:52 ` [PATCH 4/9] arm64: sysreg: Don't run the end-of-file checks after an error Fuad Tabba
2026-11-23 10:29   ` Steffen Eiden
2026-11-23  7:52 ` [PATCH 5/9] arm64: sysreg: Reject a Fields or Mapping line with an undefined target Fuad Tabba
2026-11-23 10:40   ` Steffen Eiden
2026-11-23  7:52 ` [PATCH 6/9] arm64: sysreg: Reject an enum value not written at its field's width Fuad Tabba
2026-11-23 10:45   ` Steffen Eiden [this message]
2026-11-23 10:47     ` Fuad Tabba
2026-11-23  7:52 ` [PATCH 7/9] arm64: sysreg: Reject a macro name defined twice Fuad Tabba
2026-11-23 11:01   ` Steffen Eiden
2026-11-23  7:52 ` [PATCH 8/9] arm64: sysreg: Reject an out-of-range register encoding Fuad Tabba
2026-11-23 11:04   ` Steffen Eiden
2026-11-23  7:52 ` [PATCH 9/9] arm64: sysreg: Reject a bit position written with a leading zero Fuad Tabba
2026-11-23 11:22   ` Steffen Eiden
2026-11-23 11:25     ` Fuad Tabba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123104553.20959-F-seiden@linux.ibm.com \
    --to=seiden@linux.ibm.com \
    --cc=Sascha.Bischoff@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=tabba@google.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox