Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc: Make sure IPI handlers see data written by IPI senders

We have been observing hangs, both of KVM guest vcpu tasks and more
generally, where a process that is woken doesn't properly wake up and
continue to run, but instead sticks in TASK_WAKING state. This
happens because the update of rq->wake_list in ttwu_queue_remote()
is not ordered with the update of ipi_message in
smp_muxed_ipi_message_pass(), and the reading of rq->wake_list in
scheduler_ipi() is not ordered with the reading of ipi_message in
smp_ipi_demux(). Thus it is possible for the IPI receiver not to see
the updated rq->wake_list and therefore conclude that there is nothing
for it to do.

In order to make sure that anything done before smp_send_reschedule()
is ordered before anything done in the resulting call to scheduler_ipi(),
this adds barriers in smp_muxed_message_pass() and smp_ipi_demux().
The barrier in smp_muxed_message_pass() is a full barrier to ensure that
there is a full ordering between the smp_send_reschedule() caller and
scheduler_ipi(). In smp_ipi_demux(), we use xchg() rather than
xchg_local() because xchg() includes release and acquire barriers.
Using xchg() rather than xchg_local() makes sense given that
ipi_message is not just accessed locally.

This moves the barrier between setting the message and calling the
cause_ipi() function into the individual cause_ipi implementations.
Most of them -- those that used outb, out_8 or similar -- already had
a full barrier because out_8 etc. include a sync before the MMIO
store. This adds an explicit barrier in the two remaining cases.

These changes made no measurable difference to the speed of IPIs as
measured using a simple ping-pong latency test across two CPUs on
different cores of a POWER7 machine.

The analysis of the reason why processes were not waking up properly
is due to Milton Miller.

Cc: stable@vger.kernel.org # v3.0+
Reported-by: Milton Miller <miltonm@bga.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Paul Mackerras and committed by
Benjamin Herrenschmidt
9fb1b36c 71433285

+16 -3
+2
arch/powerpc/kernel/dbell.c
··· 28 28 29 29 void doorbell_cause_ipi(int cpu, unsigned long data) 30 30 { 31 + /* Order previous accesses vs. msgsnd, which is treated as a store */ 32 + mb(); 31 33 ppc_msgsnd(PPC_DBELL, 0, data); 32 34 } 33 35
+9 -2
arch/powerpc/kernel/smp.c
··· 198 198 struct cpu_messages *info = &per_cpu(ipi_message, cpu); 199 199 char *message = (char *)&info->messages; 200 200 201 + /* 202 + * Order previous accesses before accesses in the IPI handler. 203 + */ 204 + smp_mb(); 201 205 message[msg] = 1; 202 - mb(); 206 + /* 207 + * cause_ipi functions are required to include a full barrier 208 + * before doing whatever causes the IPI. 209 + */ 203 210 smp_ops->cause_ipi(cpu, info->data); 204 211 } 205 212 ··· 218 211 mb(); /* order any irq clear */ 219 212 220 213 do { 221 - all = xchg_local(&info->messages, 0); 214 + all = xchg(&info->messages, 0); 222 215 223 216 #ifdef __BIG_ENDIAN 224 217 if (all & (1 << (24 - 8 * PPC_MSG_CALL_FUNCTION)))
+5 -1
arch/powerpc/sysdev/xics/icp-hv.c
··· 65 65 static inline void icp_hv_set_qirr(int n_cpu , u8 value) 66 66 { 67 67 int hw_cpu = get_hard_smp_processor_id(n_cpu); 68 - long rc = plpar_hcall_norets(H_IPI, hw_cpu, value); 68 + long rc; 69 + 70 + /* Make sure all previous accesses are ordered before IPI sending */ 71 + mb(); 72 + rc = plpar_hcall_norets(H_IPI, hw_cpu, value); 69 73 if (rc != H_SUCCESS) { 70 74 pr_err("%s: bad return code qirr cpu=%d hw_cpu=%d mfrr=0x%x " 71 75 "returned %ld\n", __func__, n_cpu, hw_cpu, value, rc);