mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Align ACPI structures if ARCH_STRICT_ALIGN enabled
@ 2025-09-09  9:53 Huacai Chen
  2025-09-09 12:28 ` Jiaxun Yang
  0 siblings, 1 reply; 2+ messages in thread
From: Huacai Chen @ 2025-09-09  9:53 UTC (permalink / raw)
  To: Huacai Chen
  Cc: loongarch, Xuefeng Li, Guo Ren, Xuerui Wang, Jiaxun Yang,
	linux-kernel, Huacai Chen, Binbin Zhou, Xi Ruoyao

ARCH_STRICT_ALIGN is used for hardware without UAL, now it only control
the -mstrict-align flag. However, ACPI structures are packed by default
so will cause unaligned accesses.

To avoid this, define ACPI_MISALIGNMENT_NOT_SUPPORTED in Makefile to
align ACPI structures if ARCH_STRICT_ALIGN enabled.

Reported-by: Binbin Zhou <zhoubinbin@loongson.cn>
Suggested-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 arch/loongarch/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
index a3a9759414f4..a86de4f26264 100644
--- a/arch/loongarch/Makefile
+++ b/arch/loongarch/Makefile
@@ -147,10 +147,10 @@ ifdef CONFIG_ARCH_STRICT_ALIGN
 # Don't emit unaligned accesses.
 # Not all LoongArch cores support unaligned access, and as kernel we can't
 # rely on others to provide emulation for these accesses.
-KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
+KBUILD_CFLAGS += $(call cc-option,-mstrict-align) -DACPI_MISALIGNMENT_NOT_SUPPORTED
 else
 # Optimise for performance on hardware supports unaligned access.
-KBUILD_CFLAGS += $(call cc-option,-mno-strict-align)
+KBUILD_CFLAGS += $(call cc-option,-mno-strict-align) -UACPI_MISALIGNMENT_NOT_SUPPORTED
 endif
 
 KBUILD_CFLAGS += -isystem $(shell $(CC) -print-file-name=include)
-- 
2.47.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] LoongArch: Align ACPI structures if ARCH_STRICT_ALIGN enabled
  2025-09-09  9:53 [PATCH] LoongArch: Align ACPI structures if ARCH_STRICT_ALIGN enabled Huacai Chen
@ 2025-09-09 12:28 ` Jiaxun Yang
  0 siblings, 0 replies; 2+ messages in thread
From: Jiaxun Yang @ 2025-09-09 12:28 UTC (permalink / raw)
  To: Huacai Chen, Huacai Chen
  Cc: loongarch, Xuefeng Li, Guo Ren, Xuerui Wang, linux-kernel,
	Binbin Zhou, Xi Ruoyao



在2025年9月9日周二 下午5:53,Huacai Chen写道:
> ARCH_STRICT_ALIGN is used for hardware without UAL, now it only control
> the -mstrict-align flag. However, ACPI structures are packed by default
> so will cause unaligned accesses.
>
> To avoid this, define ACPI_MISALIGNMENT_NOT_SUPPORTED in Makefile to
> align ACPI structures if ARCH_STRICT_ALIGN enabled.
>
> Reported-by: Binbin Zhou <zhoubinbin@loongson.cn>
> Suggested-by: Xi Ruoyao <xry111@xry111.site>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
>  arch/loongarch/Makefile | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
> index a3a9759414f4..a86de4f26264 100644
> --- a/arch/loongarch/Makefile
> +++ b/arch/loongarch/Makefile
> @@ -147,10 +147,10 @@ ifdef CONFIG_ARCH_STRICT_ALIGN
>  # Don't emit unaligned accesses.
>  # Not all LoongArch cores support unaligned access, and as kernel we 
> can't
>  # rely on others to provide emulation for these accesses.
> -KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
> +KBUILD_CFLAGS += $(call cc-option,-mstrict-align) 
> -DACPI_MISALIGNMENT_NOT_SUPPORTED

This is a little bit hacky.

Maybe a better place for `ACPI_MISALIGNMENT_NOT_SUPPORTED would be
`arch/loongarch/include/asm/acenv.h`, or `include/acpi/platform/aclinux.h`

>  else
>  # Optimise for performance on hardware supports unaligned access.
> -KBUILD_CFLAGS += $(call cc-option,-mno-strict-align)
> +KBUILD_CFLAGS += $(call cc-option,-mno-strict-align) 
> -UACPI_MISALIGNMENT_NOT_SUPPORTED
>  endif
> 
>  KBUILD_CFLAGS += -isystem $(shell $(CC) -print-file-name=include)
> -- 
> 2.47.3

Thanks
-- 
- Jiaxun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-09 12:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-09  9:53 [PATCH] LoongArch: Align ACPI structures if ARCH_STRICT_ALIGN enabled Huacai Chen
2025-09-09 12:28 ` Jiaxun Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®