summaryrefslogtreecommitdiffstats
path: root/sys/amd64/amd64/mp_machdep.c
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2009-08-13 17:09:45 +0000
committerattilio <attilio@FreeBSD.org>2009-08-13 17:09:45 +0000
commite85ca71aadcc42a3f7cc90e6cff96c28f1c54290 (patch)
treefa01b2cb8792e972d05922a5507e082efa4d4c1d /sys/amd64/amd64/mp_machdep.c
parentb1786d80d2f6e85141431d158b4cf3a47a2f71ec (diff)
downloadFreeBSD-src-e85ca71aadcc42a3f7cc90e6cff96c28f1c54290.zip
FreeBSD-src-e85ca71aadcc42a3f7cc90e6cff96c28f1c54290.tar.gz
* Completely Remove the option STOP_NMI from the kernel. This option
has proven to have a good effect when entering KDB by using a NMI, but it completely violates all the good rules about interrupts disabled while holding a spinlock in other occasions. This can be the cause of deadlocks on events where a normal IPI_STOP is expected. * Adds an new IPI called IPI_STOP_HARD on all the supported architectures. This IPI is responsible for sending a stop message among CPUs using a privileged channel when disponible. In other cases it just does match a normal IPI_STOP. Right now the IPI_STOP_HARD functionality uses a NMI on ia32 and amd64 architectures, while on the other has a normal IPI_STOP effect. It is responsibility of maintainers to eventually implement an hard stop when necessary and possible. * Use the new IPI facility in order to implement a new userend SMP kernel function called stop_cpus_hard(). That is specular to stop_cpu() but it does use the privileged channel for the stopping facility. * Let KDB use the newly introduced function stop_cpus_hard() and leave stop_cpus() for all the other cases * Disable interrupts on CPU0 when starting the process of APs suspension. * Style cleanup and comments adding This patch should fix the reboot/shutdown deadlocks many users are constantly reporting on mailing lists. Please don't forget to update your config file with the STOP_NMI option removal Reviewed by: jhb Tested by: pho, bz, rink Approved by: re (kib)
Diffstat (limited to 'sys/amd64/amd64/mp_machdep.c')
-rw-r--r--sys/amd64/amd64/mp_machdep.c100
1 files changed, 31 insertions, 69 deletions
diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c
index 52c209c..0ef8017 100644
--- a/sys/amd64/amd64/mp_machdep.c
+++ b/sys/amd64/amd64/mp_machdep.c
@@ -114,31 +114,12 @@ volatile int smp_tlb_wait;
extern inthand_t IDTVEC(fast_syscall), IDTVEC(fast_syscall32);
-#ifdef STOP_NMI
-static volatile cpumask_t ipi_nmi_pending;
-
-static void ipi_nmi_selected(cpumask_t cpus);
-#endif
-
/*
* Local data and functions.
*/
-#ifdef STOP_NMI
-/*
- * Provide an alternate method of stopping other CPUs. If another CPU has
- * disabled interrupts the conventional STOP IPI will be blocked. This
- * NMI-based stop should get through in that case.
- */
-static int stop_cpus_with_nmi = 1;
-SYSCTL_INT(_debug, OID_AUTO, stop_cpus_with_nmi, CTLTYPE_INT | CTLFLAG_RW,
- &stop_cpus_with_nmi, 0, "");
-TUNABLE_INT("debug.stop_cpus_with_nmi", &stop_cpus_with_nmi);
-#else
-#define stop_cpus_with_nmi 0
-#endif
-
static u_int logical_cpus;
+static volatile cpumask_t ipi_nmi_pending;
/* used to hold the AP's until we are ready to release them */
static struct mtx ap_boot_mtx;
@@ -1158,12 +1139,14 @@ ipi_selected(cpumask_t cpus, u_int ipi)
ipi = IPI_BITMAP_VECTOR;
}
-#ifdef STOP_NMI
- if (ipi == IPI_STOP && stop_cpus_with_nmi) {
- ipi_nmi_selected(cpus);
- return;
- }
-#endif
+ /*
+ * IPI_STOP_HARD maps to a NMI and the trap handler needs a bit
+ * of help in order to understand what is the source.
+ * Set the mask of receiving CPUs for this purpose.
+ */
+ if (ipi == IPI_STOP_HARD)
+ atomic_set_int(&ipi_nmi_pending, cpus);
+
CTR3(KTR_SMP, "%s: cpus: %x ipi: %x", __func__, cpus, ipi);
while ((cpu = ffs(cpus)) != 0) {
cpu--;
@@ -1194,64 +1177,43 @@ void
ipi_all_but_self(u_int ipi)
{
- if (IPI_IS_BITMAPED(ipi) || (ipi == IPI_STOP && stop_cpus_with_nmi)) {
+ if (IPI_IS_BITMAPED(ipi)) {
ipi_selected(PCPU_GET(other_cpus), ipi);
return;
}
- CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
- lapic_ipi_vectored(ipi, APIC_IPI_DEST_OTHERS);
-}
-#ifdef STOP_NMI
-/*
- * send NMI IPI to selected CPUs
- */
-
-#define BEFORE_SPIN 1000000
-
-static void
-ipi_nmi_selected(cpumask_t cpus)
-{
- int cpu;
- register_t icrlo;
-
- icrlo = APIC_DELMODE_NMI | APIC_DESTMODE_PHY | APIC_LEVEL_ASSERT
- | APIC_TRIGMOD_EDGE;
-
- CTR2(KTR_SMP, "%s: cpus: %x nmi", __func__, cpus);
-
- atomic_set_int(&ipi_nmi_pending, cpus);
-
- while ((cpu = ffs(cpus)) != 0) {
- cpu--;
- cpus &= ~(1 << cpu);
-
- KASSERT(cpu_apic_ids[cpu] != -1,
- ("IPI NMI to non-existent CPU %d", cpu));
-
- /* Wait for an earlier IPI to finish. */
- if (!lapic_ipi_wait(BEFORE_SPIN))
- panic("ipi_nmi_selected: previous IPI has not cleared");
+ /*
+ * IPI_STOP_HARD maps to a NMI and the trap handler needs a bit
+ * of help in order to understand what is the source.
+ * Set the mask of receiving CPUs for this purpose.
+ */
+ if (ipi == IPI_STOP_HARD)
+ atomic_set_int(&ipi_nmi_pending, PCPU_GET(other_cpus));
- lapic_ipi_raw(icrlo, cpu_apic_ids[cpu]);
- }
+ CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
+ lapic_ipi_vectored(ipi, APIC_IPI_DEST_OTHERS);
}
int
-ipi_nmi_handler(void)
+ipi_nmi_handler()
{
- int cpumask = PCPU_GET(cpumask);
+ cpumask_t cpumask;
- if (!(ipi_nmi_pending & cpumask))
- return 1;
+ /*
+ * As long as there is not a simple way to know about a NMI's
+ * source, if the bitmask for the current CPU is present in
+ * the global pending bitword an IPI_STOP_HARD has been issued
+ * and should be handled.
+ */
+ cpumask = PCPU_GET(cpumask);
+ if ((ipi_nmi_pending & cpumask) == 0)
+ return (1);
atomic_clear_int(&ipi_nmi_pending, cpumask);
cpustop_handler();
- return 0;
+ return (0);
}
-#endif /* STOP_NMI */
-
/*
* Handle an IPI_STOP by saving our current context and spinning until we
* are resumed.
OpenPOWER on IntegriCloud