Skip to contentSkip to conversation

powerpc: Fix data corruption on IPI

PATCH In review Timothy Pearson 3 participants 4 messages Nov 14, 2023 – Nov 15, 2023

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

PATCH 1/1 powerpc: Fix data corruption on IPI

From 0b2678b7cdada1a3d9aec8626f31a988d81373fa Mon Sep 17 00:00:00 2001
From: Timothy Pearson <[email protected]>
Date: Mon, 13 Nov 2023 22:42:58 -0600
Subject: [PATCH] powerpc: Fix data corruption on IPI

On multithreaded SMP workloads such as those using io_uring, it is possible for multiple threads to hold an inconsistent view of system memory when an IPI is issued. This in turn leads to userspace memory corruption with varying degrees of probability based on workload and inter-thread timing.

io_uring provokes this bug by its use of TWA_SIGNAL during thread creation, which is especially noticeable as significant userspace data corruption with certain workloads such as MariaDB (bug MDEV-30728). While using TWA_SIGNAL_NO_IPI works around the corruption, no other architecture requires this workaround.

Issue an lwsync barrier instruction prior to sending the IPI. This ensures the receiving CPU has a consistent view of system memory, in line with other architectures.

Tested under QEMU in kvm mode, running on a Talos II workstation with dual POWER9 DD2.2 CPUs.

---
 arch/powerpc/kernel/smp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kernel/smp.c +3 -1
index ab691c89d787..ba42238de518 100644
@@ -369,8 +369,10 @@ static inline void do_message_pass(int cpu, int msg)
 
 void arch_smp_send_reschedule(int cpu)
 {
-	if (likely(smp_ops))
+	if (likely(smp_ops)) {
+		__smp_lwsync();
 		do_message_pass(cpu, PPC_MSG_RESCHEDULE);
+	}
 }
 EXPORT_SYMBOL_GPL(arch_smp_send_reschedule);
 
Signature · 1 line
2.39.2
#1 lore raw
Quoted 34 lines · Timothy Pearson
Quoted 1 line

From 0b2678b7cdada1a3d9aec8626f31a988d81373fa Mon Sep 17 00:00:00 2001

From: Timothy Pearson <[email protected]>
Date: Mon, 13 Nov 2023 22:42:58 -0600
Subject: [PATCH] powerpc: Fix data corruption on IPI

On multithreaded SMP workloads such as those using io_uring, it is possible for multiple threads to hold an inconsistent view of system memory when an IPI is issued. This in turn leads to userspace memory corruption with varying degrees of probability based on workload and inter-thread timing.

io_uring provokes this bug by its use of TWA_SIGNAL during thread creation, which is especially noticeable as significant userspace data corruption with certain workloads such as MariaDB (bug MDEV-30728). While using TWA_SIGNAL_NO_IPI works around the corruption, no other architecture requires this workaround.

Issue an lwsync barrier instruction prior to sending the IPI. This ensures the receiving CPU has a consistent view of system memory, in line with other architectures.

Tested under QEMU in kvm mode, running on a Talos II workstation with dual POWER9 DD2.2 CPUs.

---
 arch/powerpc/kernel/smp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kernel/smp.c +0 -0
index ab691c89d787..ba42238de518 100644

arch/powerpc/kernel/smp.c static inline void do_message_pass(int cpu, int msg) · line 377

Quoted 10 lines
arch/powerpc/kernel/smp.c +3 -1
@@ -369,8 +369,10 @@ static inline void do_message_pass(int cpu, int msg)
 
 void arch_smp_send_reschedule(int cpu)
 {
-	if (likely(smp_ops))
+	if (likely(smp_ops)) {
+		__smp_lwsync();
 		do_message_pass(cpu, PPC_MSG_RESCHEDULE);
+	}
 }
 EXPORT_SYMBOL_GPL(arch_smp_send_reschedule);

Once this is accepted in mainline, can you ensure that it get backported to the needed relevant stable series? (Should it be CC'ed as well for stable@?).

For context, and maybe worth adding a Link: reference as well this is hit in Debian in https://bugs.debian.org/1032104

Regards,
Salvatore

#2 lore raw

----- Original Message -----

Quoted 44 lines

From: "Salvatore Bonaccorso" <[email protected]>
To: "Timothy Pearson" <[email protected]>
Cc: "Linuxppc-dev" <linuxppc-dev-bounces+tpearson=raptorengineering.com@lists.ozlabs.org>, "Jens Axboe" <[email protected]>, "regressions" <[email protected]>, "Michael Ellerman" <[email protected]>, "npiggin" <[email protected]>, "christophe leroy" <[email protected]>
Sent: Tuesday, November 14, 2023 1:59:14 AM
Subject: Re: [PATCH] powerpc: Fix data corruption on IPI

Quoted 35 lines · Timothy Pearson
Quoted 1 line

From 0b2678b7cdada1a3d9aec8626f31a988d81373fa Mon Sep 17 00:00:00 2001

From: Timothy Pearson <[email protected]>
Date: Mon, 13 Nov 2023 22:42:58 -0600
Subject: [PATCH] powerpc: Fix data corruption on IPI

On multithreaded SMP workloads such as those using io_uring, it is possible for multiple threads to hold an inconsistent view of system memory when an IPI is issued. This in turn leads to userspace memory corruption with varying degrees of probability based on workload and inter-thread timing.

io_uring provokes this bug by its use of TWA_SIGNAL during thread creation, which is especially noticeable as significant userspace data corruption with certain workloads such as MariaDB (bug MDEV-30728). While using TWA_SIGNAL_NO_IPI works around the corruption, no other architecture requires this workaround.

Issue an lwsync barrier instruction prior to sending the IPI. This ensures the receiving CPU has a consistent view of system memory, in line with other architectures.

Tested under QEMU in kvm mode, running on a Talos II workstation with dual POWER9 DD2.2 CPUs.

---
 arch/powerpc/kernel/smp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kernel/smp.c +0 -0
index ab691c89d787..ba42238de518 100644
@@ -369,8 +369,10 @@ static inline void do_message_pass(int cpu, int msg)
 
Quoted 13 lines

arch/powerpc/kernel/smp.c static inline void do_message_pass(int cpu, int msg) · line 377

Quoted 9 lines
arch/powerpc/kernel/smp.c +3 -1
 void arch_smp_send_reschedule(int cpu)
 {
-	if (likely(smp_ops))
+	if (likely(smp_ops)) {
+		__smp_lwsync();
 		do_message_pass(cpu, PPC_MSG_RESCHEDULE);
+	}
 }
 EXPORT_SYMBOL_GPL(arch_smp_send_reschedule);

Once this is accepted in mainline, can you ensure that it get backported to the needed relevant stable series? (Should it be CC'ed as well for stable@?).

Absolutely! We've been blocked on kernel upgrades for production database systems for a while due to this particular bug.

Quoted 2 lines

For context, and maybe worth adding a Link: reference as well this is hit in Debian in https://bugs.debian.org/1032104

Sounds good. If anyone here needs a v2 with that line added just let me know.

Thanks!

#3 lore raw
In reply to Timothy Pearson
Quoted 34 lines · Timothy Pearson

From 0b2678b7cdada1a3d9aec8626f31a988d81373fa Mon Sep 17 00:00:00 2001
From: Timothy Pearson <[email protected]>
Date: Mon, 13 Nov 2023 22:42:58 -0600
Subject: [PATCH] powerpc: Fix data corruption on IPI

On multithreaded SMP workloads such as those using io_uring, it is possible for multiple threads to hold an inconsistent view of system memory when an IPI is issued. This in turn leads to userspace memory corruption with varying degrees of probability based on workload and inter-thread timing.

io_uring provokes this bug by its use of TWA_SIGNAL during thread creation, which is especially noticeable as significant userspace data corruption with certain workloads such as MariaDB (bug MDEV-30728). While using TWA_SIGNAL_NO_IPI works around the corruption, no other architecture requires this workaround.

Issue an lwsync barrier instruction prior to sending the IPI. This ensures the receiving CPU has a consistent view of system memory, in line with other architectures.

Tested under QEMU in kvm mode, running on a Talos II workstation with dual POWER9 DD2.2 CPUs.

---
 arch/powerpc/kernel/smp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kernel/smp.c +0 -0
index ab691c89d787..ba42238de518 100644

arch/powerpc/kernel/smp.c static inline void do_message_pass(int cpu, int msg) · line 376

Quoted 9 lines
arch/powerpc/kernel/smp.c +3 -1
@@ -369,8 +369,10 @@ static inline void do_message_pass(int cpu, int msg)
 
 void arch_smp_send_reschedule(int cpu)
 {
-	if (likely(smp_ops))
+	if (likely(smp_ops)) {
+		__smp_lwsync();
 		do_message_pass(cpu, PPC_MSG_RESCHEDULE);
+	}
 }

do_message_pass() on powernv and pseries is smp_muxed_ipi_message_pass(), and the first thing that ends up doing is the smp_mb() in smp_muxed_ipi_set_message() AFAIKS, which is a hwsync, which is a stronger barrier than lwsync. So I can't see what this really fixes.

Thanks,
Nick