Skip to contentSkip to conversation

objpool: fix minimum alignment of 'struct objpool_slot'

PATCH In review Arnd Bergmann 3 participants 4 messages Feb 10 – Feb 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 objpool: fix minimum alignment of 'struct objpool_slot'

From: Arnd Bergmann <[email protected]>

Members of objpool_slot get passed into try_cmpxchg_release(), which does not work on most architectures unless they are naturally aligned. Marking the structure as packed makes it only byte-aligned, as shown by this (normally disabled) warning:

include/linux/objpool.h:156:56: warning: taking address of packed member of 'struct objpool_slot' may result in an unaligned pointer value [-Waddress-of-packed-member]
156 | if (try_cmpxchg_release(&slot->head, &head, head + 1))
| ~^~~~~~~~~~~~

As the struct members are all tightly packed on all architectures, Just remove the '__packed annotation to give it the required alignment of the native word size.

---
 include/linux/objpool.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/objpool.h +1 -1
index b713a1fe7521..f678b35b20b1 100644
@@ -56,7 +56,7 @@ struct objpool_slot {
 	uint32_t            last;
 	uint32_t            mask;
 	void               *entries[];
-} __packed;
+};
 
 struct objpool_head;
 
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Members of objpool_slot get passed into try_cmpxchg_release(), which does not work on most architectures unless they are naturally aligned. Marking the structure as packed makes it only byte-aligned, as shown by this (normally disabled) warning:

include/linux/objpool.h:156:56: warning: taking address of packed member of 'struct objpool_slot' may result in an unaligned pointer value [-Waddress-of-packed-member]
156 | if (try_cmpxchg_release(&slot->head, &head, head + 1))
| ~^~~~~~~~~~~~

Quoted 5 lines

As the struct members are all tightly packed on all architectures, Just remove the '__packed annotation to give it the required alignment of the native word size.

Quoted 19 lines
---
 include/linux/objpool.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/objpool.h +1 -1
index b713a1fe7521..f678b35b20b1 100644
@@ -56,7 +56,7 @@ struct objpool_slot {
 	uint32_t            last;
 	uint32_t            mask;
 	void               *entries[];
-} __packed;
+};
 
 struct objpool_head;
 
Signature · 1 line
2.39.5
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 25 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Members of objpool_slot get passed into try_cmpxchg_release(), which does not work on most architectures unless they are naturally aligned. Marking the structure as packed makes it only byte-aligned, as shown by this (normally disabled) warning:

include/linux/objpool.h:156:56: warning: taking address of packed member of 'struct objpool_slot' may result in an unaligned pointer value [-Waddress-of-packed-member]
156 | if (try_cmpxchg_release(&slot->head, &head, head + 1))
| ~^~~~~~~~~~~~

As the struct members are all tightly packed on all architectures, Just remove the '__packed annotation to give it the required alignment of the native word size.

---
  include/linux/objpool.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/objpool.h +0 -0
index b713a1fe7521..f678b35b20b1 100644

include/linux/objpool.h struct objpool_slot { · line 62

Quoted 8 lines
include/linux/objpool.h +1 -1
@@ -56,7 +56,7 @@ struct objpool_slot {
  	uint32_t            last;
  	uint32_t            mask;
  	void               *entries[];
-} __packed;
+};
 
  struct objpool_head;
 

Regards,
Matt Wu

#3 lore raw
In reply to Arnd Bergmann

Hi Arnd,

Would you like me to route this with my branch? Please let me know if anything needed on my side.

Thanks,
Yury

Quoted 35 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Members of objpool_slot get passed into try_cmpxchg_release(), which does not work on most architectures unless they are naturally aligned. Marking the structure as packed makes it only byte-aligned, as shown by this (normally disabled) warning:

include/linux/objpool.h:156:56: warning: taking address of packed member of 'struct objpool_slot' may result in an unaligned pointer value [-Waddress-of-packed-member]
156 | if (try_cmpxchg_release(&slot->head, &head, head + 1))
| ~^~~~~~~~~~~~

As the struct members are all tightly packed on all architectures, Just remove the '__packed annotation to give it the required alignment of the native word size.

---
 include/linux/objpool.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/objpool.h +1 -1
index b713a1fe7521..f678b35b20b1 100644
@@ -56,7 +56,7 @@ struct objpool_slot {
 	uint32_t            last;
 	uint32_t            mask;
 	void               *entries[];
-} __packed;
+};
 
 struct objpool_head;
 
Signature · 1 line
2.39.5