xen/bitops: ADDR removal
cover xen/bitops: ADDR removal
Andrew Cooper (3):
arm/bitops: Drop unused ADDR macros
x86/bitops: Remove CONST_ADDR
x86/bitops: Remove ADDR
Jan Beulich (1):
x86/bitops: don't cast away volatile-ness
docs/misra/rules.rst | 3 +- xen/arch/arm/include/asm/bitops.h | 3 -- xen/arch/x86/include/asm/bitops.h | 51 ++++++++++++++++++------------- 3 files changed, 32 insertions(+), 25 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 arm/bitops: Drop unused ADDR macros
These are unused and do not want new users to appear.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
--- xen/arch/arm/include/asm/bitops.h | 3 --- 1 file changed, 3 deletions(-)
xen/arch/arm/include/asm/bitops.h +0 -3
@@ -22,9 +22,6 @@#define __set_bit (n,p) set_bit(n,p)#define __clear_bit (n,p) clear_bit(n,p) -#define ADDR (*(volatile int *) addr) -#define CONST_ADDR (*(const volatile int *) addr) -#if defined(CONFIG_ARM_32 )# include <asm/arm32/bitops.h> #elif defined(CONFIG_ARM_64 )
Signature · 1 line
2.34.1
Re: [PATCH 1/4] arm/bitops: Drop unused ADDR macros
Quoted 3 lines · Andrew Cooper
These are unused and do not want new users to appear.
Signed-off-by Andrew Cooper <[email protected]>
~Michal
Re: [PATCH 1/4] arm/bitops: Drop unused ADDR macros
In reply to Andrew CooperLe 02/09/2026 à 13:43, Andrew Cooper a écrit :
Quoted 21 lines
These are unused and do not want new users to appear.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Volodymyr Babchuk <[email protected]>--- xen/arch/arm/include/asm/bitops.h | 3 --- 1 file changed, 3 deletions(-)xen/arch/arm/include/asm/bitops.h +0
-0
xen/arch/arm/include/asm/bitops.h line 27
Quoted 9 lines
xen/arch/arm/include/asm/bitops.h +0
-3@@ -22,9 +22,6 @@#define __set_bit (n,p) set_bit(n,p)#define __clear_bit (n,p) clear_bit(n,p) -#define ADDR (*(volatile int *) addr) -#define CONST_ADDR (*(const volatile int *) addr) -#if defined(CONFIG_ARM_32 )# include <asm/arm32/bitops.h> #elif defined(CONFIG_ARM_64 )
PATCH 2/4 x86/bitops: Remove CONST_ADDR
In reply to Andrew CooperAll this does is obfuscate the usage sites.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
--- xen/arch/x86/include/asm/bitops.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
xen/arch/x86/include/asm/bitops.h +3 -2
@@ -18,7 +18,6 @@*/ #define ADDR (*(volatile int *) addr) -#define CONST_ADDR (*(const volatile int *) addr)/** * set_bit - Atomically set a bit in memory
@@ -285,7 +284,9 @@ static inline int variable_test_bit(int nr, const volatile void *addr) asm volatile ( "btl %[nr], %[addr]\n\t" ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t") : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit) - : [addr] "m" (CONST_ADDR), [nr] "Ir" (nr) : "memory" ); + : [addr] "m" (*(const volatile int *)addr), + [nr] "Ir" (nr) + : "memory" ); return oldbit; }
Signature · 1 line
2.34.1
Re: [PATCH 2/4] x86/bitops: Remove CONST_ADDR
Le 02/09/2026 à 13:43, Andrew Cooper a écrit :
Quoted 31 lines
All this does is obfuscate the usage sites.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Volodymyr Babchuk <[email protected]>--- xen/arch/x86/include/asm/bitops.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)xen/arch/x86/include/asm/bitops.h +0
-1@@ -18,7 +18,6 @@*/ #define ADDR (*(volatile int *) addr) -#define CONST_ADDR (*(const volatile int *) addr)/** * set_bit - Atomically set a bit in memory
xen/arch/x86/include/asm/bitops.h static inline int variable_test_bit(int nr, const volatile void *addr) · line 292
Quoted 10 lines
xen/arch/x86/include/asm/bitops.h +3
-1@@ -285,7 +284,9 @@ static inline int variable_test_bit(int nr, const volatile void *addr) asm volatile ( "btl %[nr], %[addr]\n\t" ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t") : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit) - : [addr] "m" (CONST_ADDR), [nr] "Ir" (nr) : "memory" ); + : [addr] "m" (*(const volatile int *)addr), + [nr] "Ir" (nr) + : "memory" ); return oldbit; }
Re: [PATCH 2/4] x86/bitops: Remove CONST_ADDR
In reply to Andrew Cooperxen/arch/x86/include/asm/bitops.h static inline int variable_test_bit(int nr, const volatile void *addr) · line 289
Quoted 8 lines · Andrew Cooper
xen/arch/x86/include/asm/bitops.h +3
-1@@ -285,7 +284,9 @@ static inline int variable_test_bit(int nr, const volatile void *addr) asm volatile ( "btl %[nr], %[addr]\n\t" ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t") : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit) - : [addr] "m" (CONST_ADDR), [nr] "Ir" (nr) : "memory" ); + : [addr] "m" (*(const volatile int *)addr), + [nr] "Ir" (nr) + : "memory" );
Hard tabs look to have slipped in here and in patch 3.
Jan
Re: [PATCH 2/4] x86/bitops: Remove CONST_ADDR
Quoted 10 lines · Jan Beulich
xen/arch/x86/include/asm/bitops.h static inline int variable_test_bit(int nr, const volatile void *addr) · line 289
Quoted 8 lines · Andrew Cooper
xen/arch/x86/include/asm/bitops.h +3
-1@@ -285,7 +284,9 @@ static inline int variable_test_bit(int nr, const volatile void *addr) asm volatile ( "btl %[nr], %[addr]\n\t" ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t") : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit) - : [addr] "m" (CONST_ADDR), [nr] "Ir" (nr) : "memory" ); + : [addr] "m" (*(const volatile int *)addr), + [nr] "Ir" (nr) + : "memory" );Hard tabs look to have slipped in here and in patch 3.
Yes, sorry. I only noticed after emailing out, and fixed up locally.
~Andrew
PATCH 3/4 x86/bitops: Remove ADDR
In reply to Andrew CooperAll this does is obfuscate the usage sites.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
--- docs/misra/rules.rst | 3 ++- xen/arch/x86/include/asm/bitops.h | 34 ++++++++++++++++--------------- 2 files changed, 20 insertions(+), 17 deletions(-)
docs/misra/rules.rst +2 -1
@@ -212,7 +212,8 @@ maintainers if you want to suggest a change. static inline void set_bit(int nr, volatile void *addr) { asm volatile ( "lock btsl %1,%0" - : "+m" (ADDR) : "Ir" (nr) : "memory"); + : "+m" (*(volatile int *)addr) + : "Ir" (nr) : "memory" ); } #define set_bit(nr, addr) ({ \ if ( bitop_bad_size(addr) ) __bitop_bad_size(); \
xen/arch/x86/include/asm/bitops.h +18 -16
@@ -9,16 +9,6 @@#include <asm/asm_defns.h> #include <asm/cpufeatureset.h> -/* -* We specify the memory operand as both input and output because the memory -* operand is both read from and written to. Since the operand is in fact a -* word array, we also specify "memory" in the clobbers list to indicate that -* words other than the one directly addressed by the memory operand may be -* modified. -*/ - -#define ADDR (*(volatile int *) addr) -/** * set_bit - Atomically set a bit in memory * @nr: the bit to set
@@ -32,7 +22,9 @@static inline void set_bit (int nr,volatile void *addr) { asmvolatile ("lock btsl %1,%0" - :"+m" (ADDR ) :"Ir" (nr) :"memory" ); + :"+m" (*(volatile int *)addr) + :"Ir" (nr) + :"memory" ); }#define set_bit (nr, addr) ({ \ if ( bitop_bad_size(addr) ) __bitop_bad_size(); \
@@ -73,7 +65,9 @@ static inline void constant_set_bit(int nr, void *addr)static inline void clear_bit (int nr,volatile void *addr) { asmvolatile ("lock btrl %1,%0" - :"+m" (ADDR ) :"Ir" (nr) :"memory" ); + :"+m" (*(volatile int *)addr) + :"Ir" (nr) + :"memory" ); }#define clear_bit (nr, addr) ({ \ if ( bitop_bad_size(addr) ) __bitop_bad_size(); \
@@ -140,7 +134,9 @@ static inline void constant_change_bit(int nr, void *addr)static inline void change_bit (int nr,volatile void *addr) { asmvolatile ("lock btcl %1,%0" - :"+m" (ADDR ) :"Ir" (nr) :"memory" ); + :"+m" (*(volatile int *)addr) + :"Ir" (nr) + :"memory" ); }#define change_bit (nr, addr) ({ \ if ( bitop_bad_size(addr) ) __bitop_bad_size(); \
@@ -162,7 +158,9 @@ static inline int test_and_set_bit(int nr, volatile void *addr) asm volatile ( "lock btsl %[nr], %[addr]\n\t" ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t") : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit), - [addr] "+m" (ADDR) : [nr] "Ir" (nr) : "memory" ); + [addr] "+m" (*(volatile int *)addr) + : [nr] "Ir" (nr) + : "memory" );return oldbit; }
@@ -208,7 +206,9 @@ static inline int test_and_clear_bit(int nr, volatile void *addr) asm volatile ( "lock btrl %[nr], %[addr]\n\t" ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t") : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit), - [addr] "+m" (ADDR) : [nr] "Ir" (nr) : "memory" ); + [addr] "+m" (*(volatile int *)addr) + : [nr] "Ir" (nr) + : "memory" );return oldbit; }
@@ -268,7 +268,9 @@ static inline int test_and_change_bit(int nr, volatile void *addr) asm volatile ( "lock btcl %[nr], %[addr]\n\t" ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t") : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit), - [addr] "+m" (ADDR) : [nr] "Ir" (nr) : "memory" ); + [addr] "+m" (*(volatile int *)addr) + : [nr] "Ir" (nr) + : "memory" );return oldbit; }
Signature · 1 line
2.34.1
Re: [PATCH 3/4] x86/bitops: Remove ADDR
Le 02/09/2026 à 13:43, Andrew Cooper a écrit :
Quoted 19 lines
All this does is obfuscate the usage sites.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Volodymyr Babchuk <[email protected]>--- docs/misra/rules.rst | 3 ++- xen/arch/x86/include/asm/bitops.h | 34 ++++++++++++++++--------------- 2 files changed, 20 insertions(+), 17 deletions(-)
(...)
Re: [PATCH 3/4] x86/bitops: Remove ADDR
In reply to Andrew CooperQuoted 1 line · Andrew Cooper
All this does is obfuscate the usage sites.
I don't mind these changes, yet I'd like to express that as so often there are multiple ways of looking at things. The benefit of the macros was that the use sites were textually shorter, and hence easier to process (assuming you know what ADDR stands for).
xen/arch/x86/include/asm/bitops.h line 18
Quoted 13 lines
xen/arch/x86/include/asm/bitops.h +0
-7@@ -9,16 +9,6 @@#include <asm/asm_defns.h> #include <asm/cpufeatureset.h> -/* -* We specify the memory operand as both input and output because the memory -* operand is both read from and written to. Since the operand is in fact a -* word array, we also specify "memory" in the clobbers list to indicate that -* words other than the one directly addressed by the memory operand may be -* modified. -*/
Might we not better keep this justification for the seemingly odd memory clobbers? (The first sentence, otoh, I agree can be dropped.)
Jan
Re: [PATCH 3/4] x86/bitops: Remove ADDR
Quoted 6 lines · Jan Beulich
Quoted 1 line · Andrew Cooper
All this does is obfuscate the usage sites.
I don't mind these changes, yet I'd like to express that as so often there are multiple ways of looking at things. The benefit of the macros was that the use sites were textually shorter, and hence easier to process (assuming you know what ADDR stands for).
"assuming" is the whole problem, and what makes this obfuscation. If it were a pattern we used everywhere, it would be fine, but it's unique to this header.
It hides the width and volatility of the access, which variable is being referenced, and the indirection.
The only thing it has going for it is that it is recognisable as "probably a macro", but you're still forced to look elsewhere to identify how it works.
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/include/asm/bitops.h +0
-0@@ -9,16 +9,6 @@#include <asm/asm_defns.h> #include <asm/cpufeatureset.h>
Quoted 9 lines
xen/arch/x86/include/asm/bitops.h line 18
Quoted 7 lines
xen/arch/x86/include/asm/bitops.h +0
-7-/* -* We specify the memory operand as both input and output because the memory -* operand is both read from and written to. Since the operand is in fact a -* word array, we also specify "memory" in the clobbers list to indicate that -* words other than the one directly addressed by the memory operand may be -* modified. -*/ Might we not better keep this justification for the seemingly odd memory clobbers? (The first sentence, otoh, I agree can be dropped.)
I don't think it's useful to keep, but fine...
~Andrew
PATCH 4/4 x86/bitops: don't cast away volatile-ness
In reply to Andrew CooperFrom: Jan Beulich <[email protected]>
Doing so, besides being a bad idea in general, violates Misra rule 11.8. Use the helper macro we have available anyway.
No functional change intended.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
Rebase over removal of ADDR.
--- xen/arch/x86/include/asm/bitops.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
xen/arch/x86/include/asm/bitops.h +9 -3
@@ -185,7 +185,9 @@ static inline int arch__test_and_set_bit(int nr, volatile void *addr) asm volatile ( "btsl %[nr], %[addr]\n\t" ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t") : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit), - [addr] "+m" (*(int *)addr) : [nr] "Ir" (nr) : "memory" ); + [addr] "+m" (*(volatile int *)addr) + : [nr] "Ir" (nr) + : "memory" );return oldbit; }
@@ -233,7 +235,9 @@ static inline int arch__test_and_clear_bit(int nr, volatile void *addr) asm volatile ( "btrl %[nr], %[addr]\n\t" ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t") : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit), - [addr] "+m" (*(int *)addr) : [nr] "Ir" (nr) : "memory" ); + [addr] "+m" (*(volatile int *)addr) + : [nr] "Ir" (nr) + : "memory" );return oldbit; }
@@ -247,7 +251,9 @@ static inline int arch__test_and_change_bit(int nr, volatile void *addr) asm volatile ( "btcl %[nr], %[addr]\n\t" ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t") : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit), - [addr] "+m" (*(int *)addr) : [nr] "Ir" (nr) : "memory" ); + [addr] "+m" (*(volatile int *)addr) + : [nr] "Ir" (nr) + : "memory" );return oldbit; }
Signature · 1 line
2.34.1
Re: [PATCH 4/4] x86/bitops: don't cast away volatile-ness
Le 02/09/2026 à 13:43, Andrew Cooper a écrit :
Quoted 22 lines
From: Jan Beulich <[email protected]>
Doing so, besides being a bad idea in general, violates Misra rule 11.8. Use the helper macro we have available anyway.
No functional change intended.
Fixes f1879b2c2584 ("xen: introduce generic non-atomic test_*bit()")Signed-off-by Jan Beulich <[email protected]>Reviewed-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Volodymyr Babchuk <[email protected]>Rebase over removal of ADDR.
---
(...)