Re: [PATCH 3/4] x86/bitops: Remove ADDR

2026-09-02 Thread Andrew Cooper
On 02/09/2026 1:50 pm, Jan Beulich wrote:
> On 02.09.2026 13:43, Andrew Cooper wrote:
>> 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.

>
>> --- a/xen/arch/x86/include/asm/bitops.h
>> +++ b/xen/arch/x86/include/asm/bitops.h
>> @@ -9,16 +9,6 @@
>>  #include 
>>  #include 
>>  
>> -/*
>> - * 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 3/4] x86/bitops: Remove ADDR

2026-09-02 Thread Andrew Cooper
All this does is obfuscate the usage sites.

No functional change.

Signed-off-by: Andrew Cooper 
---
CC: Jan Beulich 
CC: Roger Pau Monné 
CC: Teddy Astie 
CC: Stefano Stabellini 
CC: Julien Grall 
CC: Bertrand Marquis 
CC: Michal Orzel 
CC: Volodymyr Babchuk 
---
 docs/misra/rules.rst  |  3 ++-
 xen/arch/x86/include/asm/bitops.h | 34 ---
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/docs/misra/rules.rst b/docs/misra/rules.rst
index b3e929307d51..d6be4b0c5d43 100644
--- a/docs/misra/rules.rst
+++ b/docs/misra/rules.rst
@@ -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(); \
diff --git a/xen/arch/x86/include/asm/bitops.h 
b/xen/arch/x86/include/asm/bitops.h
index fbcab32fd239..45fc64474344 100644
--- a/xen/arch/x86/include/asm/bitops.h
+++ b/xen/arch/x86/include/asm/bitops.h
@@ -9,16 +9,6 @@
 #include 
 #include 
 
-/*
- * 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)
 {
 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(); \
@@ -73,7 +65,9 @@ static inline void constant_set_bit(int nr, void *addr)
 static inline void clear_bit(int nr, volatile void *addr)
 {
 asm volatile ( "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)
 {
 asm volatile ( "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;
 }
-- 
2.34.1




Re: [PATCH 3/4] x86/bitops: Remove ADDR

2026-09-02 Thread Jan Beulich
On 02.09.2026 13:43, Andrew Cooper wrote:
> 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).

> --- a/xen/arch/x86/include/asm/bitops.h
> +++ b/xen/arch/x86/include/asm/bitops.h
> @@ -9,16 +9,6 @@
>  #include 
>  #include 
>  
> -/*
> - * 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

2026-09-02 Thread Teddy Astie

Le 02/09/2026 à 13:43, Andrew Cooper a écrit :

All this does is obfuscate the usage sites.

No functional change.

Signed-off-by: Andrew Cooper 
---
CC: Jan Beulich 
CC: Roger Pau Monné 
CC: Teddy Astie 
CC: Stefano Stabellini 
CC: Julien Grall 
CC: Bertrand Marquis 
CC: Michal Orzel 
CC: Volodymyr Babchuk 
---
  docs/misra/rules.rst  |  3 ++-
  xen/arch/x86/include/asm/bitops.h | 34 ---
  2 files changed, 20 insertions(+), 17 deletions(-)



(...)

Reviewed-by: Teddy Astie 


OpenPGP_signature.asc
Description: OpenPGP digital signature