Re: [PATCH] atomic: Specify natural alignment for atomic_t
From: Google
Date: Tue Aug 26 2025 - 22:45:27 EST
On Mon, 25 Aug 2025 12:03:05 +1000
Finn Thain <fthain@xxxxxxxxxxxxxx> wrote:
> Some recent commits incorrectly assumed the natural alignment of locks.
> That assumption fails on Linux/m68k (and, interestingly, would have failed
> on Linux/cris also). This leads to spurious warnings from the hang check
> code. Fix this bug by adding the necessary 'aligned' attribute.
>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> Cc: Lance Yang <lance.yang@xxxxxxxxx>
> Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
> Cc: Eero Tamminen <oak@xxxxxxxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Will Deacon <will@xxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Eero Tamminen <oak@xxxxxxxxxxxxxx>
> Closes: https://lore.kernel.org/lkml/CAMuHMdW7Ab13DdGs2acMQcix5ObJK0O2dG_Fxzr8_g58Rc1_0g@xxxxxxxxxxxxxx/
> Fixes: e711faaafbe5 ("hung_task: replace blocker_mutex with encoded blocker")
> Signed-off-by: Finn Thain <fthain@xxxxxxxxxxxxxx>
This seems good anyway because unaligned atomic memory access
sounds insane. So looks good to me.
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
Anyway, Lance's patch[1] is still needed. We'd better gracefully
ignore if the blocker is not aligned, because hung_task blocker
detection is an optional for debugging and not necessary for
the kernel operation.
[1] https://lore.kernel.org/all/20250823050036.7748-1-lance.yang@xxxxxxxxx/
Thank you,
> ---
> I tested this on m68k using GCC and it fixed the problem for me. AFAIK,
> the other architectures naturally align ints already so I'm expecting to
> see no effect there.
> ---
> include/linux/types.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/types.h b/include/linux/types.h
> index 6dfdb8e8e4c3..cd5b2b0f4b02 100644
> --- a/include/linux/types.h
> +++ b/include/linux/types.h
> @@ -179,7 +179,7 @@ typedef phys_addr_t resource_size_t;
> typedef unsigned long irq_hw_number_t;
>
> typedef struct {
> - int counter;
> + int counter __aligned(sizeof(int));
> } atomic_t;
>
> #define ATOMIC_INIT(i) { (i) }
> --
> 2.49.1
>
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>