[02/18] arm64: move SCTLR_EL{1,2} assertions to <asm/sysreg.h>

Message ID 20180514094640.27569-3-mark.rutland@arm.com
State Superseded
Headers show
Series
  • arm64: invoke syscalls with pt_regs
Related show

Commit Message

Mark Rutland May 14, 2018, 9:46 a.m.
Currently we assert that the SCTLR_EL{1,2}_{SET,CLEAR} bits are
self-consistent with an assertion in config_sctlr_el1(). This is a bit
unusual, since config_sctlr_el1() doesn't make use of these definitions,
and is far away from the definitions themselves.

We can use the CPP #error directive to have equivalent assertions in
<asm/sysreg.h>, next to the definitions of the set/clear bits, which is
a bit clearer and simpler.

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

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
---
 arch/arm64/include/asm/sysreg.h | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

-- 
2.11.0

Comments

Dave Martin May 14, 2018, 10 a.m. | #1
On Mon, May 14, 2018 at 10:46:24AM +0100, Mark Rutland wrote:
> Currently we assert that the SCTLR_EL{1,2}_{SET,CLEAR} bits are

> self-consistent with an assertion in config_sctlr_el1(). This is a bit

> unusual, since config_sctlr_el1() doesn't make use of these definitions,

> and is far away from the definitions themselves.

> 

> We can use the CPP #error directive to have equivalent assertions in

> <asm/sysreg.h>, next to the definitions of the set/clear bits, which is

> a bit clearer and simpler.

> 

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

> Cc: Catalin Marinas <catalin.marinas@arm.com>

> Cc: James Morse <james.morse@arm.com>

> Cc: Will Deacon <will.deacon@arm.com>

> ---

>  arch/arm64/include/asm/sysreg.h | 14 ++++++--------

>  1 file changed, 6 insertions(+), 8 deletions(-)

> 

> diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h

> index 6171178075dc..bd1d1194a5e7 100644

> --- a/arch/arm64/include/asm/sysreg.h

> +++ b/arch/arm64/include/asm/sysreg.h

> @@ -452,9 +452,9 @@

>  			 SCTLR_ELx_SA     | SCTLR_ELx_I    | SCTLR_ELx_WXN | \

>  			 ENDIAN_CLEAR_EL2 | SCTLR_EL2_RES0)

>  

> -/* Check all the bits are accounted for */

> -#define SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS	BUILD_BUG_ON((SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != ~0)

> -

> +#if (SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != 0xffffffff

> +#error "Inconsistent SCTLR_EL2 set/clear bits"

> +#endif


Can we have a comment on the != 0xffffffff versus != ~0 here?

The subtle differences in evaluation semantics between #if and
other contexts here may well trip people up during maintenance...


With that, Reviewed-by: Dave Martin <Dave.Martin@arm.com>

Cheers
---Dave

>  

>  /* SCTLR_EL1 specific flags. */

>  #define SCTLR_EL1_UCI		(1 << 26)

> @@ -492,8 +492,9 @@

>  			 SCTLR_EL1_UMA | SCTLR_ELx_WXN     | ENDIAN_CLEAR_EL1 |\

>  			 SCTLR_EL1_RES0)

>  

> -/* Check all the bits are accounted for */

> -#define SCTLR_EL1_BUILD_BUG_ON_MISSING_BITS	BUILD_BUG_ON((SCTLR_EL1_SET ^ SCTLR_EL1_CLEAR) != ~0)

> +#if (SCTLR_EL1_SET ^ SCTLR_EL1_CLEAR) != 0xffffffff

> +#error "Inconsistent SCTLR_EL1 set/clear bits"

> +#endif

>  

>  /* id_aa64isar0 */

>  #define ID_AA64ISAR0_TS_SHIFT		52

> @@ -732,9 +733,6 @@ static inline void config_sctlr_el1(u32 clear, u32 set)

>  {

>  	u32 val;

>  

> -	SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS;

> -	SCTLR_EL1_BUILD_BUG_ON_MISSING_BITS;

> -

>  	val = read_sysreg(sctlr_el1);

>  	val &= ~clear;

>  	val |= set;

> -- 

> 2.11.0

> 

> 

> _______________________________________________

> linux-arm-kernel mailing list

> linux-arm-kernel@lists.infradead.org

> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mark Rutland May 14, 2018, 10:08 a.m. | #2
On Mon, May 14, 2018 at 11:00:53AM +0100, Dave Martin wrote:
> On Mon, May 14, 2018 at 10:46:24AM +0100, Mark Rutland wrote:

> > -/* Check all the bits are accounted for */

> > -#define SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS	BUILD_BUG_ON((SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != ~0)

> > -

> > +#if (SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != 0xffffffff

> > +#error "Inconsistent SCTLR_EL2 set/clear bits"

> > +#endif

> 

> Can we have a comment on the != 0xffffffff versus != ~0 here?

> 

> The subtle differences in evaluation semantics between #if and

> other contexts here may well trip people up during maintenance...


Do you have any suggestion as to the wording?

I'm happy to add a comment, but I don't really know what to say.

Thanks,
Mark.
Dave Martin May 14, 2018, 11:20 a.m. | #3
On Mon, May 14, 2018 at 11:08:59AM +0100, Mark Rutland wrote:
> On Mon, May 14, 2018 at 11:00:53AM +0100, Dave Martin wrote:

> > On Mon, May 14, 2018 at 10:46:24AM +0100, Mark Rutland wrote:

> > > -/* Check all the bits are accounted for */

> > > -#define SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS	BUILD_BUG_ON((SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != ~0)

> > > -

> > > +#if (SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != 0xffffffff

> > > +#error "Inconsistent SCTLR_EL2 set/clear bits"

> > > +#endif

> > 

> > Can we have a comment on the != 0xffffffff versus != ~0 here?

> > 

> > The subtle differences in evaluation semantics between #if and

> > other contexts here may well trip people up during maintenance...

> 

> Do you have any suggestion as to the wording?

> 

> I'm happy to add a comment, but I don't really know what to say.



How about the following?

/* Watch out for #if evaluation rules: ~0 is not ~(int)0! */

Cheers
---Dave
Robin Murphy May 14, 2018, 11:56 a.m. | #4
On 14/05/18 12:20, Dave Martin wrote:
> On Mon, May 14, 2018 at 11:08:59AM +0100, Mark Rutland wrote:

>> On Mon, May 14, 2018 at 11:00:53AM +0100, Dave Martin wrote:

>>> On Mon, May 14, 2018 at 10:46:24AM +0100, Mark Rutland wrote:

>>>> -/* Check all the bits are accounted for */

>>>> -#define SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS	BUILD_BUG_ON((SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != ~0)

>>>> -

>>>> +#if (SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != 0xffffffff

>>>> +#error "Inconsistent SCTLR_EL2 set/clear bits"

>>>> +#endif

>>>

>>> Can we have a comment on the != 0xffffffff versus != ~0 here?

>>>

>>> The subtle differences in evaluation semantics between #if and

>>> other contexts here may well trip people up during maintenance...

>>

>> Do you have any suggestion as to the wording?

>>

>> I'm happy to add a comment, but I don't really know what to say.

> 

> 

> How about the following?

> 

> /* Watch out for #if evaluation rules: ~0 is not ~(int)0! */


Or, more formally, perhaps something even less vague like "Note that in 
preprocessor arithmetic these constants are effectively of type 
intmax_t, which is 64-bit, thus ~0 is not what we want."

Robin.
Mark Rutland May 14, 2018, 12:06 p.m. | #5
On Mon, May 14, 2018 at 12:56:09PM +0100, Robin Murphy wrote:
> On 14/05/18 12:20, Dave Martin wrote:

> > On Mon, May 14, 2018 at 11:08:59AM +0100, Mark Rutland wrote:

> > > On Mon, May 14, 2018 at 11:00:53AM +0100, Dave Martin wrote:

> > > > On Mon, May 14, 2018 at 10:46:24AM +0100, Mark Rutland wrote:

> > > > > -/* Check all the bits are accounted for */

> > > > > -#define SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS	BUILD_BUG_ON((SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != ~0)

> > > > > -

> > > > > +#if (SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != 0xffffffff

> > > > > +#error "Inconsistent SCTLR_EL2 set/clear bits"

> > > > > +#endif

> > > > 

> > > > Can we have a comment on the != 0xffffffff versus != ~0 here?

> > > > 

> > > > The subtle differences in evaluation semantics between #if and

> > > > other contexts here may well trip people up during maintenance...

> > > 

> > > Do you have any suggestion as to the wording?

> > > 

> > > I'm happy to add a comment, but I don't really know what to say.

> > 

> > 

> > How about the following?

> > 

> > /* Watch out for #if evaluation rules: ~0 is not ~(int)0! */

> 

> Or, more formally, perhaps something even less vague like "Note that in

> preprocessor arithmetic these constants are effectively of type intmax_t,

> which is 64-bit, thus ~0 is not what we want."


I'll drop something in the commit message to that effect, rather than a
comment.

A comment will end up terse and vague or large and bloatsome (and
redundant as we have this pattern twice).

Anyone attempting to "clean" this up will find things break, and they can
look at the git log to find out why it is the way it is...

Thanks,
Mark.
Dave Martin May 14, 2018, 12:41 p.m. | #6
On Mon, May 14, 2018 at 01:06:10PM +0100, Mark Rutland wrote:
> On Mon, May 14, 2018 at 12:56:09PM +0100, Robin Murphy wrote:

> > On 14/05/18 12:20, Dave Martin wrote:

> > > On Mon, May 14, 2018 at 11:08:59AM +0100, Mark Rutland wrote:

> > > > On Mon, May 14, 2018 at 11:00:53AM +0100, Dave Martin wrote:

> > > > > On Mon, May 14, 2018 at 10:46:24AM +0100, Mark Rutland wrote:

> > > > > > -/* Check all the bits are accounted for */

> > > > > > -#define SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS	BUILD_BUG_ON((SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != ~0)

> > > > > > -

> > > > > > +#if (SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != 0xffffffff

> > > > > > +#error "Inconsistent SCTLR_EL2 set/clear bits"

> > > > > > +#endif

> > > > > 

> > > > > Can we have a comment on the != 0xffffffff versus != ~0 here?

> > > > > 

> > > > > The subtle differences in evaluation semantics between #if and

> > > > > other contexts here may well trip people up during maintenance...

> > > > 

> > > > Do you have any suggestion as to the wording?

> > > > 

> > > > I'm happy to add a comment, but I don't really know what to say.

> > > 

> > > 

> > > How about the following?

> > > 

> > > /* Watch out for #if evaluation rules: ~0 is not ~(int)0! */

> > 

> > Or, more formally, perhaps something even less vague like "Note that in

> > preprocessor arithmetic these constants are effectively of type intmax_t,

> > which is 64-bit, thus ~0 is not what we want."

> 

> I'll drop something in the commit message to that effect, rather than a

> comment.

> 

> A comment will end up terse and vague or large and bloatsome (and

> redundant as we have this pattern twice).

> 

> Anyone attempting to "clean" this up will find things break, and they can

> look at the git log to find out why it is the way it is...


Fair enough.  So long as we say something somewhere, that's
sufficient for me.

With that,

Reviewed-by: Dave Martin <Dave.Martin@arm.com>


(as previously stated).

Cheers
---Dave
Mark Rutland May 14, 2018, 1:10 p.m. | #7
On Mon, May 14, 2018 at 01:41:23PM +0100, Dave Martin wrote:
> On Mon, May 14, 2018 at 01:06:10PM +0100, Mark Rutland wrote:

> > On Mon, May 14, 2018 at 12:56:09PM +0100, Robin Murphy wrote:

> > > On 14/05/18 12:20, Dave Martin wrote:

> > > > How about the following?

> > > > 

> > > > /* Watch out for #if evaluation rules: ~0 is not ~(int)0! */

> > > 

> > > Or, more formally, perhaps something even less vague like "Note that in

> > > preprocessor arithmetic these constants are effectively of type intmax_t,

> > > which is 64-bit, thus ~0 is not what we want."

> > 

> > I'll drop something in the commit message to that effect, rather than a

> > comment.

> > 

> > A comment will end up terse and vague or large and bloatsome (and

> > redundant as we have this pattern twice).

> > 

> > Anyone attempting to "clean" this up will find things break, and they can

> > look at the git log to find out why it is the way it is...

> 

> Fair enough.  So long as we say something somewhere, that's

> sufficient for me.

> 

> With that,

> 

> Reviewed-by: Dave Martin <Dave.Martin@arm.com>

> 

> (as previously stated).


Cheers!

Mark.

Patch

diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 6171178075dc..bd1d1194a5e7 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -452,9 +452,9 @@ 
 			 SCTLR_ELx_SA     | SCTLR_ELx_I    | SCTLR_ELx_WXN | \
 			 ENDIAN_CLEAR_EL2 | SCTLR_EL2_RES0)
 
-/* Check all the bits are accounted for */
-#define SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS	BUILD_BUG_ON((SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != ~0)
-
+#if (SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != 0xffffffff
+#error "Inconsistent SCTLR_EL2 set/clear bits"
+#endif
 
 /* SCTLR_EL1 specific flags. */
 #define SCTLR_EL1_UCI		(1 << 26)
@@ -492,8 +492,9 @@ 
 			 SCTLR_EL1_UMA | SCTLR_ELx_WXN     | ENDIAN_CLEAR_EL1 |\
 			 SCTLR_EL1_RES0)
 
-/* Check all the bits are accounted for */
-#define SCTLR_EL1_BUILD_BUG_ON_MISSING_BITS	BUILD_BUG_ON((SCTLR_EL1_SET ^ SCTLR_EL1_CLEAR) != ~0)
+#if (SCTLR_EL1_SET ^ SCTLR_EL1_CLEAR) != 0xffffffff
+#error "Inconsistent SCTLR_EL1 set/clear bits"
+#endif
 
 /* id_aa64isar0 */
 #define ID_AA64ISAR0_TS_SHIFT		52
@@ -732,9 +733,6 @@  static inline void config_sctlr_el1(u32 clear, u32 set)
 {
 	u32 val;
 
-	SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS;
-	SCTLR_EL1_BUILD_BUG_ON_MISSING_BITS;
-
 	val = read_sysreg(sctlr_el1);
 	val &= ~clear;
 	val |= set;