Skip to contentSkip to conversation

Enable UBSAN on ppc

PATCH In review Shawn Anastasio 4 participants 5 messages Feb 26, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover Enable UBSAN on ppc

Extend Andrew's UBSAN enablement work to ppc.

Changes in v2:
- Drop opal.c unaligned access patch
- Enable -fno-sanitize=alignment like x86 does

Andrew Cooper (1):
PPC: Activate UBSAN in testing

 automation/gitlab-ci/build.yaml      | 3 +++
 xen/arch/ppc/Kconfig                 | 1 +
 xen/arch/ppc/arch.mk                 | 6 ++++++
 xen/arch/ppc/include/asm/processor.h | 2 ++
 xen/arch/ppc/stubs.c                 | 2 +-
 5 files changed, 13 insertions(+), 1 deletion(-)

--
2.30.2

#1 lore raw

PATCH v2 1/1 PPC: Activate UBSAN in testing

From: Andrew Cooper <[email protected]>

Also enable -fno-sanitize=alignment like x86 since support for unaligned accesses is guaranteed by the ISA and the existing OPAL setup code relies on it.

---
Changes in v2:
- Add -fno-sanitize=alignment flag per discussion in v1

 automation/gitlab-ci/build.yaml      | 3 +++
 xen/arch/ppc/Kconfig                 | 1 +
 xen/arch/ppc/arch.mk                 | 6 ++++++
 xen/arch/ppc/include/asm/processor.h | 2 ++
 xen/arch/ppc/stubs.c                 | 2 +-
 5 files changed, 13 insertions(+), 1 deletion(-)
automation/gitlab-ci/build.yaml +3 -0
index 35e224366f..6a2e491534 100644
@@ -352,6 +352,9 @@ debian-12-ppc64le-gcc-debug:
     CONTAINER: debian:12-ppc64le
     KBUILD_DEFCONFIG: ppc64_defconfig
     HYPERVISOR_ONLY: y
+    EXTRA_XEN_CONFIG: |
+      CONFIG_UBSAN=y
+      CONFIG_UBSAN_FATAL=y
 
 debian-12-riscv64-gcc-debug:
   extends: .gcc-riscv64-cross-build-debug
xen/arch/ppc/Kconfig +1 -0
index 6db575a48d..917f5d53a6 100644
@@ -2,6 +2,7 @@ config PPC
 	def_bool y
 	select FUNCTION_ALIGNMENT_4B
 	select HAS_DEVICE_TREE
+	select HAS_UBSAN
 	select HAS_VMAP
 
 config PPC64
xen/arch/ppc/arch.mk +6 -0
index 917ad0e6a8..c2ca419242 100644
@@ -7,3 +7,9 @@ CFLAGS += -m64 -mlittle-endian -mcpu=$(ppc-march-y)
 CFLAGS += -mstrict-align -mcmodel=medium -mabi=elfv2 -fPIC -mno-altivec -mno-vsx -msoft-float
 
 LDFLAGS += -m elf64lppc
+
+ifeq ($(CONFIG_UBSAN),y)
+# Don't enable alignment sanitisation since Power ISA guarantees hardware
+# support for unaligned accesses.
+$(call cc-option-add,CFLAGS_UBSAN,CC,-fno-sanitize=alignment)
+endif
xen/arch/ppc/include/asm/processor.h +2 -0
index a01b62b8a4..50161cc32d 100644
@@ -219,6 +219,8 @@ static inline void noreturn die(void)
  */
 #define cpu_relax() asm volatile ( "or %r1, %r1, %r1; or %r2, %r2, %r2" )
 
+#define dump_execution_state() run_in_exception_handler(show_execution_state)
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_PPC_PROCESSOR_H */
xen/arch/ppc/stubs.c +1 -1
index fff82f5cf3..671e71aa0a 100644
@@ -47,7 +47,7 @@ void send_timer_event(struct vcpu *v)
 
 void show_execution_state(const struct cpu_user_regs *regs)
 {
-    BUG_ON("unimplemented");
+    printk("TODO: Implement show_execution_state(regs)\n");
 }
 
 void arch_hypercall_tasklet_result(struct vcpu *v, long res)

--
2.30.2

#3 lore raw

Re: [PATCH v2 1/1] PPC: Activate UBSAN in testing (for 4.20?)

Quoted 10 lines · Jan Beulich
Quoted 8 lines · Shawn Anastasio

From: Andrew Cooper <[email protected]>

Also enable -fno-sanitize=alignment like x86 since support for unaligned accesses is guaranteed by the ISA and the existing OPAL setup code relies on it.

Thanks. I've committed this.

Oleksii, seeing as how simple it ended up, and seeing as how you're currently writing the release notes for 4.20 while excluding PPC from the list...

Views on this sneaking in at the last moment?

~Andrew

#4 lore raw

Re: [PATCH v2 1/1] PPC: Activate UBSAN in testing (for 4.20?)

Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Shawn Anastasio

From: Andrew Cooper<[email protected]>

Also enable -fno-sanitize=alignment like x86 since support for unaligned accesses is guaranteed by the ISA and the existing OPAL setup code relies on it.

Quoted 8 lines
Quoted 1 line

Thanks. I've committed this.

Oleksii, seeing as how simple it ended up, and seeing as how you're currently writing the release notes for 4.20 while excluding PPC from the list...

Views on this sneaking in at the last moment?

As it touches only PPC part, then I am okay to have it in 4.20:

I'll update release notes too then.

Thanks.

~ Oleksii