public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Fuad Tabba <tabba@google.com>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	maz@kernel.org, oliver.upton@linux.dev, will@kernel.org,
	joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com,
	catalin.marinas@arm.com, vdonnefort@google.com,
	qperret@google.com, sebastianene@google.com, keirf@google.com,
	smostafa@google.com
Subject: Re: [PATCH v3 3/3] arm64: sysreg: Add validation checks to sysreg header generation script
Date: Fri, 29 Aug 2025 11:14:49 +0100	[thread overview]
Message-ID: <aLF9mSCs1B2gk8BU@J2N7QTR9R3> (raw)
In-Reply-To: <20250829095143.123476-4-tabba@google.com>

On Fri, Aug 29, 2025 at 10:51:43AM +0100, Fuad Tabba wrote:
> The gen_sysreg.awk script processes the system register specification in
> the sysreg text file to generate C macro definitions. The current script
> will silently accept certain errors in the specification file, leading
> to incorrect header generation.
> 
> For example, a Sysreg or SysregFields can be accidentally duplicated,
> causing its macros to be emitted twice. An Enum can contain duplicate
> values for different items, which is architecturally incorrect.
> 
> Add checks to catch these errors at build time. The script now tracks
> all seen Sysreg and SysregFields definitions and checks for duplicates.
> It also tracks values within each Enum block to ensure entries are
> unique.
> 
> Acked-by: Marc Zyngier <maz@kernel.org>
> Signed-off-by: Fuad Tabba <tabba@google.com>

I wonder if it would make sense to treat SysregFields and Sysregs as one
group (both using defined_regs), so that we can catch:

	Sysreg	FOO_EL1	...
		...
	EndSysreg

	SysregFields	FOO_EL1
		...
	EndSysregFields

I have no strong feelings either way, so for this as-is OR for using
`defined_regs` for both:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  arch/arm64/tools/gen-sysreg.awk | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/arch/arm64/tools/gen-sysreg.awk b/arch/arm64/tools/gen-sysreg.awk
> index f2a1732cb1f6..bbbb812603e8 100755
> --- a/arch/arm64/tools/gen-sysreg.awk
> +++ b/arch/arm64/tools/gen-sysreg.awk
> @@ -122,6 +122,10 @@ $1 == "SysregFields" && block_current() == "Root" {
>  	res1 = "UL(0)"
>  	unkn = "UL(0)"
>  
> +	if (reg in defined_fields)
> +		fatal("Duplicate SysregFields definition for " reg)
> +	defined_fields[reg] = 1
> +
>  	next_bit = 63
>  
>  	next
> @@ -162,6 +166,10 @@ $1 == "Sysreg" && block_current() == "Root" {
>  	res1 = "UL(0)"
>  	unkn = "UL(0)"
>  
> +	if (reg in defined_regs)
> +		fatal("Duplicate Sysreg definition for " reg)
> +	defined_regs[reg] = 1
> +
>  	define("REG_" reg, "S" op0 "_" op1 "_C" crn "_C" crm "_" op2)
>  	define("SYS_" reg, "sys_reg(" op0 ", " op1 ", " crn ", " crm ", " op2 ")")
>  
> @@ -284,6 +292,8 @@ $1 == "SignedEnum" && (block_current() == "Sysreg" || block_current() == "Sysreg
>  	define_field(reg, field, msb, lsb)
>  	define_field_sign(reg, field, "true")
>  
> +	delete seen_enum_vals
> +
>  	next
>  }
>  
> @@ -297,6 +307,8 @@ $1 == "UnsignedEnum" && (block_current() == "Sysreg" || block_current() == "Sysr
>  	define_field(reg, field, msb, lsb)
>  	define_field_sign(reg, field, "false")
>  
> +	delete seen_enum_vals
> +
>  	next
>  }
>  
> @@ -309,6 +321,8 @@ $1 == "Enum" && (block_current() == "Sysreg" || block_current() == "SysregFields
>  
>  	define_field(reg, field, msb, lsb)
>  
> +	delete seen_enum_vals
> +
>  	next
>  }
>  
> @@ -320,6 +334,8 @@ $1 == "EndEnum" && block_current() == "Enum" {
>  	lsb = null
>  	print ""
>  
> +	delete seen_enum_vals
> +
>  	block_pop()
>  	next
>  }
> @@ -329,6 +345,10 @@ $1 == "EndEnum" && block_current() == "Enum" {
>  	val = $1
>  	name = $2
>  
> +	if (val in seen_enum_vals)
> +		fatal("Duplicate Enum value " val " for " name)
> +	seen_enum_vals[val] = 1
> +
>  	define(reg "_" field "_" name, "UL(" val ")")
>  	next
>  }
> -- 
> 2.51.0.338.gd7d06c2dae-goog
> 
> 


  reply	other threads:[~2025-08-29 12:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-29  9:51 [PATCH v3 0/3] arm64: sysreg: Fix sysreg field definitions and generation script Fuad Tabba
2025-08-29  9:51 ` [PATCH v3 1/3] arm64: sysreg: Fix and tidy up sysreg field definitions Fuad Tabba
2025-08-29 10:07   ` Mark Rutland
2025-08-29  9:51 ` [PATCH v3 2/3] arm64: sysreg: Correct sign definitions for EIESB and DoubleLock Fuad Tabba
2025-08-29 10:10   ` Mark Rutland
2025-08-29  9:51 ` [PATCH v3 3/3] arm64: sysreg: Add validation checks to sysreg header generation script Fuad Tabba
2025-08-29 10:14   ` Mark Rutland [this message]
2025-09-11 16:11 ` [PATCH v3 0/3] arm64: sysreg: Fix sysreg field definitions and " Will Deacon

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=aLF9mSCs1B2gk8BU@J2N7QTR9R3 \
    --to=mark.rutland@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=keirf@google.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=qperret@google.com \
    --cc=sebastianene@google.com \
    --cc=smostafa@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tabba@google.com \
    --cc=vdonnefort@google.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /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