aboutsummaryrefslogtreecommitdiff
path: root/sys/x86/x86
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2018-06-22 10:44:33 +0000
committerAndriy Gapon <avg@FreeBSD.org>2018-06-22 10:44:33 +0000
commitff821799e093f770bc8c5fe7ba249d9928fa9b45 (patch)
tree9ebb7e0c92c1c72a5dd93d05ba2c5526f0aa6f12 /sys/x86/x86
parent4ac82e598be361803bebd5f90e2ad490bd5eb9b0 (diff)
downloadsrc-ff821799e093f770bc8c5fe7ba249d9928fa9b45.tar.gz
src-ff821799e093f770bc8c5fe7ba249d9928fa9b45.zip
MFC r333321,r333707: x86 cpususpend_handler: call wbinvd after setting suspend state bits
Without a subsequent wbinvd the changes to suspended_cpus (and resuming_cpus) can be lost at least on AMD systems that use MOESI cache coherency protocol. That can happen because one of APs ends up as an Owner of the corresponding cache line(s) and the changes may never reach the main memory before the AP is reset. This change fixed suspend to RAM a previously broken AMD-based system.
Notes
Notes: svn path=/stable/11/; revision=335555
Diffstat (limited to 'sys/x86/x86')
-rw-r--r--sys/x86/x86/mp_x86.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c
index da8852e9cfcf..8ddf9d16dcf9 100644
--- a/sys/x86/x86/mp_x86.c
+++ b/sys/x86/x86/mp_x86.c
@@ -1317,15 +1317,33 @@ cpususpend_handler(void)
#else
npxsuspend(susppcbs[cpu]->sp_fpususpend);
#endif
- wbinvd();
- CPU_SET_ATOMIC(cpu, &suspended_cpus);
/*
- * Hack for xen, which does not use resumectx() so never
- * uses the next clause: set resuming_cpus early so that
- * resume_cpus() can wait on the same bitmap for acpi and
- * xen. resuming_cpus now means eventually_resumable_cpus.
+ * suspended_cpus is cleared shortly after each AP is restarted
+ * by a Startup IPI, so that the BSP can proceed to restarting
+ * the next AP.
+ *
+ * resuming_cpus gets cleared when the AP completes
+ * initialization after having been released by the BSP.
+ * resuming_cpus is probably not the best name for the
+ * variable, because it is actually a set of processors that
+ * haven't resumed yet and haven't necessarily started resuming.
+ *
+ * Note that suspended_cpus is meaningful only for ACPI suspend
+ * as it's not really used for Xen suspend since the APs are
+ * automatically restored to the running state and the correct
+ * context. For the same reason resumectx is never called in
+ * that case.
*/
+ CPU_SET_ATOMIC(cpu, &suspended_cpus);
CPU_SET_ATOMIC(cpu, &resuming_cpus);
+
+ /*
+ * Invalidate the cache after setting the global status bits.
+ * The last AP to set its bit may end up being an Owner of the
+ * corresponding cache line in MOESI protocol. The AP may be
+ * stopped before the cache line is written to the main memory.
+ */
+ wbinvd();
} else {
#ifdef __amd64__
fpuresume(susppcbs[cpu]->sp_fpususpend);
@@ -1337,7 +1355,7 @@ cpususpend_handler(void)
PCPU_SET(switchtime, 0);
PCPU_SET(switchticks, ticks);
- /* Indicate that we are resuming */
+ /* Indicate that we have restarted and restored the context. */
CPU_CLR_ATOMIC(cpu, &suspended_cpus);
}