summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2018-02-02 18:38:29 +0000
committermav <mav@FreeBSD.org>2018-02-02 18:38:29 +0000
commit30915abc08d28c1240eba05ab621b7620cd2c0a4 (patch)
treefc0124b7e68c08ef49e317e7d1b59b2c5b9da7a3
parentaa5e7fe536ff9a3ac60ed90a96798b0fbd82c659 (diff)
downloadFreeBSD-src-30915abc08d28c1240eba05ab621b7620cd2c0a4.zip
FreeBSD-src-30915abc08d28c1240eba05ab621b7620cd2c0a4.tar.gz
MFC r312293,312305,312434,312698,312759,312760,312814,312815,322672:
Synchronize gtaskqueue vs SMP initialization order with head. This should fix panics on boot, caused by recent Linux KPI merges.
-rw-r--r--sys/kern/subr_gtaskqueue.c40
-rw-r--r--sys/sys/gtaskqueue.h24
2 files changed, 36 insertions, 28 deletions
diff --git a/sys/kern/subr_gtaskqueue.c b/sys/kern/subr_gtaskqueue.c
index f6f6c13..bb83412 100644
--- a/sys/kern/subr_gtaskqueue.c
+++ b/sys/kern/subr_gtaskqueue.c
@@ -633,6 +633,31 @@ taskqgroup_find(struct taskqgroup *qgroup, void *uniq)
return (idx);
}
+/*
+ * smp_started is unusable since it is not set for UP kernels or even for
+ * SMP kernels when there is 1 CPU. This is usually handled by adding a
+ * (mp_ncpus == 1) test, but that would be broken here since we need to
+ * to synchronize with the SI_SUB_SMP ordering. Even in the pure SMP case
+ * smp_started only gives a fuzzy ordering relative to SI_SUB_SMP.
+ *
+ * So maintain our own flag. It must be set after all CPUs are started
+ * and before SI_SUB_SMP:SI_ORDER_ANY so that the SYSINIT for delayed
+ * adjustment is properly delayed. SI_ORDER_FOURTH is clearly before
+ * SI_ORDER_ANY and unclearly after the CPUs are started. It would be
+ * simpler for adjustment to pass a flag indicating if it is delayed.
+ */
+
+static int tqg_smp_started;
+
+static void
+tqg_record_smp_started(void *arg)
+{
+ tqg_smp_started = 1;
+}
+
+SYSINIT(tqg_record_smp_started, SI_SUB_SMP, SI_ORDER_FOURTH,
+ tqg_record_smp_started, NULL);
+
void
taskqgroup_attach(struct taskqgroup *qgroup, struct grouptask *gtask,
void *uniq, int irq, char *name)
@@ -649,7 +674,7 @@ taskqgroup_attach(struct taskqgroup *qgroup, struct grouptask *gtask,
qgroup->tqg_queue[qid].tgc_cnt++;
LIST_INSERT_HEAD(&qgroup->tqg_queue[qid].tgc_tasks, gtask, gt_list);
gtask->gt_taskqueue = qgroup->tqg_queue[qid].tgc_taskq;
- if (irq != -1 && (smp_started || mp_ncpus == 1)) {
+ if (irq != -1 && tqg_smp_started) {
gtask->gt_cpu = qgroup->tqg_queue[qid].tgc_cpu;
CPU_ZERO(&mask);
CPU_SET(qgroup->tqg_queue[qid].tgc_cpu, &mask);
@@ -699,7 +724,7 @@ taskqgroup_attach_cpu(struct taskqgroup *qgroup, struct grouptask *gtask,
gtask->gt_irq = irq;
gtask->gt_cpu = cpu;
mtx_lock(&qgroup->tqg_lock);
- if (smp_started || mp_ncpus == 1) {
+ if (tqg_smp_started) {
for (i = 0; i < qgroup->tqg_cnt; i++)
if (qgroup->tqg_queue[i].tgc_cpu == cpu) {
qid = i;
@@ -719,7 +744,7 @@ taskqgroup_attach_cpu(struct taskqgroup *qgroup, struct grouptask *gtask,
CPU_ZERO(&mask);
CPU_SET(cpu, &mask);
- if (irq != -1 && (smp_started || mp_ncpus == 1))
+ if (irq != -1 && tqg_smp_started)
intr_setaffinity(irq, &mask);
return (0);
}
@@ -733,7 +758,7 @@ taskqgroup_attach_cpu_deferred(struct taskqgroup *qgroup, struct grouptask *gtas
qid = -1;
irq = gtask->gt_irq;
cpu = gtask->gt_cpu;
- MPASS(smp_started || mp_ncpus == 1);
+ MPASS(tqg_smp_started);
mtx_lock(&qgroup->tqg_lock);
for (i = 0; i < qgroup->tqg_cnt; i++)
if (qgroup->tqg_queue[i].tgc_cpu == cpu) {
@@ -826,9 +851,10 @@ _taskqgroup_adjust(struct taskqgroup *qgroup, int cnt, int stride)
mtx_assert(&qgroup->tqg_lock, MA_OWNED);
- if (cnt < 1 || cnt * stride > mp_ncpus || (!smp_started && (mp_ncpus != 1))) {
- printf("taskqgroup_adjust failed cnt: %d stride: %d mp_ncpus: %d smp_started: %d\n",
- cnt, stride, mp_ncpus, smp_started);
+ if (cnt < 1 || cnt * stride > mp_ncpus || !tqg_smp_started) {
+ printf("%s: failed cnt: %d stride: %d "
+ "mp_ncpus: %d tqg_smp_started: %d\n",
+ __func__, cnt, stride, mp_ncpus, tqg_smp_started);
return (EINVAL);
}
if (qgroup->tqg_adjusting) {
diff --git a/sys/sys/gtaskqueue.h b/sys/sys/gtaskqueue.h
index cd0f774..525f4bd 100644
--- a/sys/sys/gtaskqueue.h
+++ b/sys/sys/gtaskqueue.h
@@ -80,8 +80,6 @@ int taskqgroup_adjust(struct taskqgroup *qgroup, int cnt, int stride);
#define TASKQGROUP_DECLARE(name) \
extern struct taskqgroup *qgroup_##name
-
-#ifdef EARLY_AP_STARTUP
#define TASKQGROUP_DEFINE(name, cnt, stride) \
\
struct taskqgroup *qgroup_##name; \
@@ -90,23 +88,9 @@ static void \
taskqgroup_define_##name(void *arg) \
{ \
qgroup_##name = taskqgroup_create(#name); \
- taskqgroup_adjust(qgroup_##name, (cnt), (stride)); \
} \
\
-SYSINIT(taskqgroup_##name, SI_SUB_INIT_IF, SI_ORDER_FIRST, \
- taskqgroup_define_##name, NULL)
-#else
-#define TASKQGROUP_DEFINE(name, cnt, stride) \
- \
-struct taskqgroup *qgroup_##name; \
- \
-static void \
-taskqgroup_define_##name(void *arg) \
-{ \
- qgroup_##name = taskqgroup_create(#name); \
-} \
- \
-SYSINIT(taskqgroup_##name, SI_SUB_INIT_IF, SI_ORDER_FIRST, \
+SYSINIT(taskqgroup_##name, SI_SUB_TASKQ, SI_ORDER_FIRST, \
taskqgroup_define_##name, NULL); \
\
static void \
@@ -116,10 +100,8 @@ taskqgroup_adjust_##name(void *arg) \
} \
\
SYSINIT(taskqgroup_adj_##name, SI_SUB_SMP, SI_ORDER_ANY, \
- taskqgroup_adjust_##name, NULL); \
- \
-struct __hack
-#endif
+ taskqgroup_adjust_##name, NULL)
+
TASKQGROUP_DECLARE(net);
TASKQGROUP_DECLARE(softirq);
OpenPOWER on IntegriCloud