Skip to contentSkip to conversation

workqueue: make workqueue available very early during boot

PATCH In review Tejun Heo 8 participants 40 messages Sep 15, 2016 – Oct 19, 2016

Subsystems (9)
lore
Share & tools
lore
author maintainer
#33 lore raw

PATCH 5/7 slab, workqueue: remove keventd_up() usage

In reply to Tejun Heo

Now that workqueue can handle work item queueing from very early during boot, there is no need to gate schedule_delayed_work_on() while !keventd_up(). Remove it.

Cc Christoph Lameter <[email protected]>
Cc Pekka Enberg <[email protected]>
Cc David Rientjes <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc Andrew Morton <[email protected]>

---
Hello,

This change depends on an earlier workqueue patch and is followed by a patch to remove keventd_up(). It'd be great if it can be routed through the wq/for-4.9 branch.

Thanks.

 mm/slab.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
mm/slab.c +1 -6
index b672710..dc69b6b 100644
@@ -550,12 +550,7 @@ static void start_cpu_timer(int cpu)
 {
 	struct delayed_work *reap_work = &per_cpu(slab_reap_work, cpu);
 
-	/*
-	 * When this gets called from do_initcalls via cpucache_init(),
-	 * init_workqueues() has already run, so keventd will be setup
-	 * at that time.
-	 */
-	if (keventd_up() && reap_work->work.func == NULL) {
+	if (reap_work->work.func == NULL) {
 		init_reap_node(cpu);
 		INIT_DEFERRABLE_WORK(reap_work, cache_reap);
 		schedule_delayed_work_on(cpu, reap_work,
Signature · 7 lines
2.7.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Tejun Heo

author maintainer
#0 lore raw

PATCH 1/1 workqueue: make workqueue available very early during boot

Hello,

Workqueue is currently initialized in an early init call; however, there are cases where early boot code has to be split and reordered to come after workqueue initialization or the same code path which makes use of workqueues is used both before workqueue initailization and after. The latter cases have to gate workqueue usages with keventd_up() tests, which is nasty and easy to get wrong.

This patchset makes workqueue creation and work item queueing/canceling available from very early during boot which allows all existing usages of keventd_up() which is removed by the last patch.

This patchset contains the following seven patches.

0001-workqueue-make-workqueue-available-early-during-boot.patch 0002-mce-workqueue-remove-keventd_up-usage.patch 0003-tty-workqueue-remove-keventd_up-usage.patch 0004-power-workqueue-remove-keventd_up-usage.patch 0005-slab-workqueue-remove-keventd_up-usage.patch 0006-debugobj-workqueue-remove-keventd_up-usage.patch 0007-workqueue-remove-keventd_up.patch

The patchset is also available in the following git branch.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git review-wq-early

Once the patches are reviewed, I'll route the patches through the wq/for-4.9 branch. diffstat follows. Thanks.

 arch/x86/kernel/cpu/mcheck/mce.c |    2 -
 drivers/tty/vt/vt.c              |    4 --
 include/linux/workqueue.h        |   11 +----
 init/main.c                      |   10 +++++
 kernel/power/qos.c               |   11 -----
 kernel/workqueue.c               |   77 ++++++++++++++++++++++++++++++---------
 lib/debugobjects.c               |    2 -
 mm/slab.c                        |    7 ---
 8 files changed, 78 insertions(+), 46 deletions(-)

--
tejun

author maintainer
#37 lore raw

PATCH 7/7 workqueue: remove keventd_up()

keventd_up() no longer has in-kernel users. Remove it and make wq_online static.

---
 include/linux/workqueue.h | 10 ----------
 kernel/workqueue.c        |  2 +-
 2 files changed, 1 insertion(+), 11 deletions(-)
include/linux/workqueue.h +0 -10
index 91d416f..5641713 100644
@@ -358,8 +358,6 @@ extern struct workqueue_struct *system_freezable_wq;
 extern struct workqueue_struct *system_power_efficient_wq;
 extern struct workqueue_struct *system_freezable_power_efficient_wq;
 
-extern bool wq_online;
-
 extern struct workqueue_struct *
 __alloc_workqueue_key(const char *fmt, unsigned int flags, int max_active,
 	struct lock_class_key *key, const char *lock_name, ...) __printf(1, 6);
@@ -591,14 +589,6 @@ static inline bool schedule_delayed_work(struct delayed_work *dwork,
 	return queue_delayed_work(system_wq, dwork, delay);
 }
 
-/**
- * keventd_up - is workqueue initialized yet?
- */
-static inline bool keventd_up(void)
-{
-	return wq_online;
-}
-
 #ifndef CONFIG_SMP
 static inline long work_on_cpu(int cpu, long (*fn)(void *), void *arg)
 {
kernel/workqueue.c +1 -1
index a05ab14..3bef80a 100644
@@ -290,7 +290,7 @@ module_param_named(disable_numa, wq_disable_numa, bool, 0444);
 static bool wq_power_efficient = IS_ENABLED(CONFIG_WQ_POWER_EFFICIENT_DEFAULT);
 module_param_named(power_efficient, wq_power_efficient, bool, 0444);
 
-bool wq_online;				/* can kworkers be created yet? */
+static bool wq_online;			/* can kworkers be created yet? */
 
 static bool wq_numa_enabled;		/* unbound NUMA affinity enabled */
 
Signature · 1 line
2.7.4
author maintainer
#35 lore raw

PATCH 6/7 debugobj, workqueue: remove keventd_up() usage

In reply to Tejun Heo

Now that workqueue can handle work item queueing from very early during boot, there is no need to gate schedule_work() while !keventd_up(). Remove it.

Cc Thomas Gleixner <[email protected]>
Cc Andrew Morton <[email protected]>

---
Hello,

This change depends on an earlier workqueue patch and is followed by a patch to remove keventd_up(). It'd be great if it can be routed through the wq/for-4.9 branch.

Thanks.

 lib/debugobjects.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/debugobjects.c +1 -1
index a8e1260..8458ec9 100644
@@ -199,7 +199,7 @@ static void free_object(struct debug_obj *obj)
 	 * initialized:
 	 */
 	if (obj_pool_free > ODEBUG_POOL_SIZE && obj_cache)
-		sched = keventd_up();
+		sched = 1;
 	hlist_add_head(&obj->node, &obj_pool);
 	obj_pool_free++;
 	obj_pool_used--;
Signature · 1 line
2.7.4
author maintainer
#31 lore raw

PATCH 4/7 power, workqueue: remove keventd_up() usage

In reply to Tejun Heo

Now that workqueue can handle work item queueing/cancelling from very early during boot, there is no need to gate cancel_delayed_work_sync() while !keventd_up(). Remove it.

Cc Qiao Zhou <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---
Hello,

This change depends on an earlier workqueue patch and is followed by a patch to remove keventd_up(). It'd be great if it can be routed through the wq/for-4.9 branch.

Thanks.

 kernel/power/qos.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
kernel/power/qos.c +1 -10
index 168ff44..97b0df7 100644
@@ -482,16 +482,7 @@ void pm_qos_update_request(struct pm_qos_request *req,
 		return;
 	}
 
-	/*
-	 * This function may be called very early during boot, for example,
-	 * from of_clk_init(), where irq needs to stay disabled.
-	 * cancel_delayed_work_sync() assumes that irq is enabled on
-	 * invocation and re-enables it on return.  Avoid calling it until
-	 * workqueue is initialized.
-	 */
-	if (keventd_up())
-		cancel_delayed_work_sync(&req->work);
-
+	cancel_delayed_work_sync(&req->work);
 	__pm_qos_update_request(req, new_value);
 }
 EXPORT_SYMBOL_GPL(pm_qos_update_request);
Signature · 1 line
2.7.4
author maintainer
#30 lore raw

PATCH 3/7 tty, workqueue: remove keventd_up() usage

In reply to Tejun Heo

Now that workqueue can handle work item queueing from very early during boot, there is no need to delay schedule_work() while !keventd_up(). Remove it.

Cc Jiri Slaby <[email protected]>
Cc Alan Cox <[email protected]>

---
Hello,

This change depends on an earlier workqueue patch and is followed by a patch to remove keventd_up(). It'd be great if it can be routed through the wq/for-4.9 branch.

Thanks.

 drivers/tty/vt/vt.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/tty/vt/vt.c +0 -4
index 2705ca9..f76ad4c 100644
@@ -3924,10 +3924,6 @@ void unblank_screen(void)
  */
 static void blank_screen_t(unsigned long dummy)
 {
-	if (unlikely(!keventd_up())) {
-		mod_timer(&console_timer, jiffies + (blankinterval * HZ));
-		return;
-	}
 	blank_timer_expired = 1;
 	schedule_work(&console_work);
 }
Signature · 1 line
2.7.4
author maintainer
#26 lore raw

PATCH 2/7 mce, workqueue: remove keventd_up() usage

In reply to Tejun Heo

Now that workqueue can handle work item queueing from very early during boot, there is no need to gate schedule_work() with keventd_up(). Remove it.

---
Hello,

This change depends on an earlier workqueue patch and is followed by a patch to remove keventd_up(). It'd be great if it can be routed through the wq/for-4.9 branch.

Thanks.

 arch/x86/kernel/cpu/mcheck/mce.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mcheck/mce.c +1 -1
index 79d8ec8..675b7d8 100644
@@ -491,7 +491,7 @@ int mce_available(struct cpuinfo_x86 *c)
 
 static void mce_schedule_work(void)
 {
-	if (!mce_gen_pool_empty() && keventd_up())
+	if (!mce_gen_pool_empty())
 		schedule_work(&mce_work);
 }
 
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH 1/7 workqueue: make workqueue available early during boot

In reply to Tejun Heo

Workqueue is currently initialized in an early init call; however, there are cases where early boot code has to be split and reordered to come after workqueue initialization or the same code path which makes use of workqueues is used both before workqueue initailization and after. The latter cases have to gate workqueue usages with keventd_up() tests, which is nasty and easy to get wrong.

Workqueue usages have become widespread and it'd be a lot more convenient if it can be used very early from boot. This patch splits workqueue initialization into two steps. workqueue_init_early() which sets up the basic data structures so that workqueues can be created and work items queued, and workqueue_init() which actually brings up workqueues online and starts executing queued work items. The former step can be done very early during boot once memory allocation, cpumasks and idr are initialized. The latter right after kthreads become available.

This allows work item queueing and canceling from very early boot which is what most of these use cases want.

* As systemd_wq being initialized doesn't indicate that workqueue is fully online anymore, update keventd_up() to test wq_online instead. The follow-up patches will get rid of all its usages and the function itself.

* Flushing doesn't make sense before workqueue is fully initialized. The flush functions trigger WARN and return immediately before fully online.

* Work items are never in-flight before fully online. Canceling can always succeed by skipping the flush step.

* Some code paths can no longer assume to be called with irq enabled as irq is disabled during early boot. Use irqsave/restore operations instead.

---
 include/linux/workqueue.h |  7 ++++-
 init/main.c               | 10 ++++++
 kernel/workqueue.c        | 77 +++++++++++++++++++++++++++++++++++++----------
 3 files changed, 77 insertions(+), 17 deletions(-)
include/linux/workqueue.h +6 -1
index 26cc1df..91d416f 100644
@@ -358,6 +358,8 @@ extern struct workqueue_struct *system_freezable_wq;
 extern struct workqueue_struct *system_power_efficient_wq;
 extern struct workqueue_struct *system_freezable_power_efficient_wq;
 
+extern bool wq_online;
+
 extern struct workqueue_struct *
 __alloc_workqueue_key(const char *fmt, unsigned int flags, int max_active,
 	struct lock_class_key *key, const char *lock_name, ...) __printf(1, 6);
@@ -594,7 +596,7 @@ static inline bool schedule_delayed_work(struct delayed_work *dwork,
  */
 static inline bool keventd_up(void)
 {
-	return system_wq != NULL;
+	return wq_online;
 }
 
 #ifndef CONFIG_SMP
@@ -631,4 +633,7 @@ int workqueue_online_cpu(unsigned int cpu);
 int workqueue_offline_cpu(unsigned int cpu);
 #endif
 
+int __init workqueue_init_early(void);
+int __init workqueue_init(void);
+
 #endif
init/main.c +10 -0
index a8a58e2..5c4fd68 100644
@@ -551,6 +551,14 @@ asmlinkage __visible void __init start_kernel(void)
 		 "Interrupts were enabled *very* early, fixing it\n"))
 		local_irq_disable();
 	idr_init_cache();
+
+	/*
+	 * Allow workqueue creation and work item queueing/cancelling
+	 * early.  Work item execution depends on kthreads and starts after
+	 * workqueue_init().
+	 */
+	workqueue_init_early();
+
 	rcu_init();
 
 	/* trace_printk() and trace points may be used after this */
@@ -1005,6 +1013,8 @@ static noinline void __init kernel_init_freeable(void)
 
 	smp_prepare_cpus(setup_max_cpus);
 
+	workqueue_init();
+
 	do_pre_smp_initcalls();
 	lockup_detector_init();
 
kernel/workqueue.c +61 -16

140 lines not on this page · raw message

Signature · 1 line
2.7.4
#38 lore raw
In reply to Tejun Heo
Quoted 5 lines · Tejun Heo

This patchset makes workqueue creation and work item queueing/canceling available from very early during boot which allows all existing usages of keventd_up() which is removed by the last patch.

Looks good to me. I didn't *test* it, just looking at the patches..

Linus

#32 lore raw

Re: [PATCH 4/7] power, workqueue: remove keventd_up() usage

In reply to Tejun Heo
Quoted 7 lines · Tejun Heo

Now that workqueue can handle work item queueing/cancelling from very early during boot, there is no need to gate cancel_delayed_work_sync() while !keventd_up(). Remove it.

Cc Qiao Zhou <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
Quoted 6 lines

---
Hello,

This change depends on an earlier workqueue patch and is followed by a patch to remove keventd_up(). It'd be great if it can be routed through the wq/for-4.9 branch.

I don't see any problems with that.

Please feel free to add my ACK to the patch if necessary/useful.

Thanks,
Rafael

Quoted 25 lines
  kernel/power/qos.c | 11 +----------
  1 file changed, 1 insertion(+), 10 deletions(-)
kernel/power/qos.c +1 -10
index 168ff44..97b0df7 100644
@@ -482,16 +482,7 @@ void pm_qos_update_request(struct pm_qos_request *req,
  		return;
  	}
 
-	/*
-	 * This function may be called very early during boot, for example,
-	 * from of_clk_init(), where irq needs to stay disabled.
-	 * cancel_delayed_work_sync() assumes that irq is enabled on
-	 * invocation and re-enables it on return.  Avoid calling it until
-	 * workqueue is initialized.
-	 */
-	if (keventd_up())
-		cancel_delayed_work_sync(&req->work);
-
+	cancel_delayed_work_sync(&req->work);
  	__pm_qos_update_request(req, new_value);
  }
  EXPORT_SYMBOL_GPL(pm_qos_update_request);
author maintainer
#39 lore raw
In reply to Tejun Heo
Quoted 9 lines · Tejun Heo

This patchset contains the following seven patches.

0001-workqueue-make-workqueue-available-early-during-boot.patch 0002-mce-workqueue-remove-keventd_up-usage.patch 0003-tty-workqueue-remove-keventd_up-usage.patch 0004-power-workqueue-remove-keventd_up-usage.patch 0005-slab-workqueue-remove-keventd_up-usage.patch 0006-debugobj-workqueue-remove-keventd_up-usage.patch 0007-workqueue-remove-keventd_up.patch

Applied 1-7 to wq/for-4.9.

Thanks.

Signature · 1 line
tejun
maintainer
#27 lore raw

Re: [PATCH 2/7] mce, workqueue: remove keventd_up() usage

In reply to Tejun Heo
Quoted 8 lines · Tejun Heo

Now that workqueue can handle work item queueing from very early during boot, there is no need to gate schedule_work() with keventd_up(). Remove it.

Quoted 6 lines

---
Hello,

This change depends on an earlier workqueue patch and is followed by a patch to remove keventd_up(). It'd be great if it can be routed through the wq/for-4.9 branch.

I don't mind as long as I can call it as early as:

->x86_64_start_reservations
|->start_kernel
|->check_bugs

     |->identify_boot_cpu
        |->identify_cpu
	   |->mcheck_cpu_init
	     |->do_machine_check
	       |->mce_report_event
	          |->mce_schedule_work

because this is the earliest callchain I can see.

Thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
author maintainer
#2 lore raw

PATCH v2 1/7 workqueue: make workqueue available early during boot

In reply to Tejun Heo
Quoted 1 line

From f85002f627f7fdc7b3cda526863f5c9a8d36b997 Mon Sep 17 00:00:00 2001

From: Tejun Heo <[email protected]>
Date: Fri, 16 Sep 2016 15:49:32 -0400
Subject: [PATCH] workqueue: make workqueue available early during boot

Workqueue is currently initialized in an early init call; however, there are cases where early boot code has to be split and reordered to come after workqueue initialization or the same code path which makes use of workqueues is used both before workqueue initailization and after. The latter cases have to gate workqueue usages with keventd_up() tests, which is nasty and easy to get wrong.

Workqueue usages have become widespread and it'd be a lot more convenient if it can be used very early from boot. This patch splits workqueue initialization into two steps. workqueue_init_early() which sets up the basic data structures so that workqueues can be created and work items queued, and workqueue_init() which actually brings up workqueues online and starts executing queued work items. The former step can be done very early during boot once memory allocation, cpumasks and idr are initialized. The latter right after kthreads become available.

This allows work item queueing and canceling from very early boot which is what most of these use cases want.

* As systemd_wq being initialized doesn't indicate that workqueue is fully online anymore, update keventd_up() to test wq_online instead. The follow-up patches will get rid of all its usages and the function itself.

* Flushing doesn't make sense before workqueue is fully initialized. The flush functions trigger WARN and return immediately before fully online.

* Work items are never in-flight before fully online. Canceling can always succeed by skipping the flush step.

* Some code paths can no longer assume to be called with irq enabled as irq is disabled during early boot. Use irqsave/restore operations instead.

v2: Watchdog init, which requires timer to be running, moved from
workqueue_init_early() to workqueue_init().

---
Hello,

0day bot detected warning during boot due to workqueue hang watchdog being initialized before timer subsystem is online. Moved watchdog init to late init.

Thanks.

 include/linux/workqueue.h |    7 +++-
 init/main.c               |   10 ++++++
 kernel/workqueue.c        |   76 ++++++++++++++++++++++++++++++++++++----------
 3 files changed, 76 insertions(+), 17 deletions(-)
include/linux/workqueue.h +6 -1
@@ -358,6 +358,8 @@ extern struct workqueue_struct *system_f
 extern struct workqueue_struct *system_power_efficient_wq;
 extern struct workqueue_struct *system_freezable_power_efficient_wq;
 
+extern bool wq_online;
+
 extern struct workqueue_struct *
 __alloc_workqueue_key(const char *fmt, unsigned int flags, int max_active,
 	struct lock_class_key *key, const char *lock_name, ...) __printf(1, 6);
@@ -594,7 +596,7 @@ static inline bool schedule_delayed_work
  */
 static inline bool keventd_up(void)
 {
-	return system_wq != NULL;
+	return wq_online;
 }
 
 #ifndef CONFIG_SMP
@@ -631,4 +633,7 @@ int workqueue_online_cpu(unsigned int cp
 int workqueue_offline_cpu(unsigned int cpu);
 #endif
 
+int __init workqueue_init_early(void);
+int __init workqueue_init(void);
+
 #endif
init/main.c +10 -0
@@ -551,6 +551,14 @@ asmlinkage __visible void __init start_k
 		 "Interrupts were enabled *very* early, fixing it\n"))
 		local_irq_disable();
 	idr_init_cache();
+
+	/*
+	 * Allow workqueue creation and work item queueing/cancelling
+	 * early.  Work item execution depends on kthreads and starts after
+	 * workqueue_init().
+	 */
+	workqueue_init_early();
+
 	rcu_init();
 
 	/* trace_printk() and trace points may be used after this */
@@ -1005,6 +1013,8 @@ static noinline void __init kernel_init_
 
 	smp_prepare_cpus(setup_max_cpus);
 
+	workqueue_init();
+
 	do_pre_smp_initcalls();
 	lockup_detector_init();
 
kernel/workqueue.c +60 -16

143 lines not on this page · raw message

author maintainer
#28 lore raw

Re: [PATCH 2/7] mce, workqueue: remove keventd_up() usage

In reply to Borislav Petkov
Quoted 9 lines · Borislav Petkov
Quoted 3 lines

This change depends on an earlier workqueue patch and is followed by a patch to remove keventd_up(). It'd be great if it can be routed through the wq/for-4.9 branch.

I don't mind as long as I can call it as early as:

->x86_64_start_reservations
|->start_kernel
|->check_bugs

Quoted 8 lines
     |->identify_boot_cpu
        |->identify_cpu
	   |->mcheck_cpu_init
	     |->do_machine_check
	       |->mce_report_event
	          |->mce_schedule_work

because this is the earliest callchain I can see.

Yeah, that's way after workqueue early init. Should be fine.

Thanks.

Signature · 1 line
tejun
maintainer Acked-by
#29 lore raw

Re: [PATCH 2/7] mce, workqueue: remove keventd_up() usage

Quoted 1 line · Tejun Heo

Yeah, that's way after workqueue early init. Should be fine.

Ok.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
Acked-by on v1 5/7
#34 lore raw

Re: [PATCH 5/7] slab, workqueue: remove keventd_up() usage

In reply to Tejun Heo
Quoted 11 lines · Tejun Heo

Now that workqueue can handle work item queueing from very early during boot, there is no need to gate schedule_delayed_work_on() while !keventd_up(). Remove it.

Cc Christoph Lameter <[email protected]>
Cc Pekka Enberg <[email protected]>
Cc David Rientjes <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc Andrew Morton <[email protected]>
Quoted 6 lines

---
Hello,

This change depends on an earlier workqueue patch and is followed by a patch to remove keventd_up(). It'd be great if it can be routed through the wq/for-4.9 branch.

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw

Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Tejun Heo

Hi Tejun,

Quoted 41 lines · Tejun Heo

From f85002f627f7fdc7b3cda526863f5c9a8d36b997 Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Fri, 16 Sep 2016 15:49:32 -0400
Subject: [PATCH] workqueue: make workqueue available early during boot

Workqueue is currently initialized in an early init call; however, there are cases where early boot code has to be split and reordered to come after workqueue initialization or the same code path which makes use of workqueues is used both before workqueue initailization and after. The latter cases have to gate workqueue usages with keventd_up() tests, which is nasty and easy to get wrong.

Workqueue usages have become widespread and it'd be a lot more convenient if it can be used very early from boot. This patch splits workqueue initialization into two steps. workqueue_init_early() which sets up the basic data structures so that workqueues can be created and work items queued, and workqueue_init() which actually brings up workqueues online and starts executing queued work items. The former step can be done very early during boot once memory allocation, cpumasks and idr are initialized. The latter right after kthreads become available.

This allows work item queueing and canceling from very early boot which is what most of these use cases want.

* As systemd_wq being initialized doesn't indicate that workqueue is fully online anymore, update keventd_up() to test wq_online instead. The follow-up patches will get rid of all its usages and the function itself.

* Flushing doesn't make sense before workqueue is fully initialized. The flush functions trigger WARN and return immediately before fully online.

* Work items are never in-flight before fully online. Canceling can always succeed by skipping the flush step.

* Some code paths can no longer assume to be called with irq enabled as irq is disabled during early boot. Use irqsave/restore operations instead.

Quoted 6 lines

v2: Watchdog init, which requires timer to be running, moved from
workqueue_init_early() to workqueue_init().

This patch seems to be causing one of my Power8 boxes not to boot.

Specifically commit 3347fa092821 ("workqueue: make workqueue available early during boot") in linux-next.

If I revert this on top of next-20161005 then the machine boots again.

I've attached the oops below. It looks like the cfs_rq of p->se is NULL?

cheers

bootconsole [udbg0] disabled
bootconsole [udbg0] disabled
mempolicy: Enabling automatic NUMA balancing. Configure with numa_balancing= or the kernel.numa_balancing sysctl
pid_max: default: 163840 minimum: 1280
Dentry cache hash table entries: 16777216 (order: 11, 134217728 bytes)
Inode-cache hash table entries: 8388608 (order: 10, 67108864 bytes)
Mount-cache hash table entries: 262144 (order: 5, 2097152 bytes)
Mountpoint-cache hash table entries: 262144 (order: 5, 2097152 bytes)

Unable to handle kernel paging request for data at address 0x00000038
Faulting instruction address: 0xc0000000000fc0cc
Oops: Kernel access of bad area, sig: 11 [#1]
SMP NR_CPUS=2048 NUMA PowerNV
Modules linked in:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.8.0-compiler_gcc-6.2.0-next-20161005 #94

task: c0000007f5400000 task.stack: c000001ffc084000
NIP: c0000000000fc0cc LR: c0000000000ed928 CTR: c0000000000fbfd0
REGS: c000001ffc087780 TRAP: 0300 Not tainted (4.8.0-compiler_gcc-6.2.0-next-20161005)
MSR: 9000000002009033 <SF,HV,VEC,EE,ME,IR,DR,RI,LE> CR: 48000424 XER: 00000000
CFAR: c0000000000089dc DAR: 0000000000000038 DSISR: 40000000 SOFTE: 0
GPR00: c0000000000ed928 c000001ffc087a00 c000000000e63200 c000000010d6d600
GPR04: c0000007f5409200 0000000000000021 000000000748e08c 000000000000001f
GPR08: 0000000000000000 0000000000000021 000000000748f1f8 0000000000000000
GPR12: 0000000028000422 c00000000fb80000 c00000000000e0c8 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000021 0000000000000001
GPR20: ffffffffafb50401 0000000000000000 c000000010d6d600 000000000000ba7e
GPR24: 000000000000ba7e c000000000d8bc58 afb504000afb5041 0000000000000001
GPR28: 0000000000000000 0000000000000004 c0000007f5409280 0000000000000000 NIP [c0000000000fc0cc] enqueue_task_fair+0xfc/0x18b0
LR [c0000000000ed928] activate_task+0x78/0xe0

Call Trace:

[c000001ffc087a00] [c0000007f5409200] 0xc0000007f5409200 (unreliable) [c000001ffc087b10] [c0000000000ed928] activate_task+0x78/0xe0 [c000001ffc087b50] [c0000000000ede58] ttwu_do_activate+0x68/0xc0 [c000001ffc087b90] [c0000000000ef1b8] try_to_wake_up+0x208/0x4f0 [c000001ffc087c10] [c0000000000d3484] create_worker+0x144/0x250 [c000001ffc087cb0] [c000000000cd72d0] workqueue_init+0x124/0x150 [c000001ffc087d00] [c000000000cc0e74] kernel_init_freeable+0x158/0x360 [c000001ffc087dc0] [c00000000000e0e4] kernel_init+0x24/0x160 [c000001ffc087e30] [c00000000000bfa0] ret_from_kernel_thread+0x5c/0xbc Instruction dump:
62940401 3b800000 3aa00000 7f17c378 3a600001 3b600001 60000000 60000000 60420000 72490021 ebfe0150 2f890001 <ebbf0038> 419e0de0 7fbee840 419e0e58

---[ end trace 0000000000000000 ]---

c0000000000fbfd0 <enqueue_task_fair>:
r4 = p
...
c0000000000fc040: 80 00 c4 3b addi r30,r4,128 r30 = r4 + 128 (&p->se)
...

c0000000000fc0c4:	50 01 fe eb 	ld      r31,336(r30)	r31 = *(r30 + 336) = se->cfs_rq
c0000000000fc0c8:	01 00 89 2f 	cmpwi   cr7,r9,1
c0000000000fc0cc:	38 00 bf eb 	ld      r29,56(r31)	r29 = cfs_rq->curr
#4 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

Quoted 109 lines · Michael Ellerman

Hi Tejun,

Quoted 41 lines · Tejun Heo

From f85002f627f7fdc7b3cda526863f5c9a8d36b997 Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Fri, 16 Sep 2016 15:49:32 -0400
Subject: [PATCH] workqueue: make workqueue available early during boot

Workqueue is currently initialized in an early init call; however, there are cases where early boot code has to be split and reordered to come after workqueue initialization or the same code path which makes use of workqueues is used both before workqueue initailization and after. The latter cases have to gate workqueue usages with keventd_up() tests, which is nasty and easy to get wrong.

Workqueue usages have become widespread and it'd be a lot more convenient if it can be used very early from boot. This patch splits workqueue initialization into two steps. workqueue_init_early() which sets up the basic data structures so that workqueues can be created and work items queued, and workqueue_init() which actually brings up workqueues online and starts executing queued work items. The former step can be done very early during boot once memory allocation, cpumasks and idr are initialized. The latter right after kthreads become available.

This allows work item queueing and canceling from very early boot which is what most of these use cases want.

* As systemd_wq being initialized doesn't indicate that workqueue is fully online anymore, update keventd_up() to test wq_online instead. The follow-up patches will get rid of all its usages and the function itself.

* Flushing doesn't make sense before workqueue is fully initialized. The flush functions trigger WARN and return immediately before fully online.

* Work items are never in-flight before fully online. Canceling can always succeed by skipping the flush step.

* Some code paths can no longer assume to be called with irq enabled as irq is disabled during early boot. Use irqsave/restore operations instead.

Quoted 6 lines

v2: Watchdog init, which requires timer to be running, moved from
workqueue_init_early() to workqueue_init().

This patch seems to be causing one of my Power8 boxes not to boot.

Specifically commit 3347fa092821 ("workqueue: make workqueue available early during boot") in linux-next.

If I revert this on top of next-20161005 then the machine boots again.

I've attached the oops below. It looks like the cfs_rq of p->se is NULL?

cheers

bootconsole [udbg0] disabled
bootconsole [udbg0] disabled
mempolicy: Enabling automatic NUMA balancing. Configure with numa_balancing= or the kernel.numa_balancing sysctl
pid_max: default: 163840 minimum: 1280
Dentry cache hash table entries: 16777216 (order: 11, 134217728 bytes)
Inode-cache hash table entries: 8388608 (order: 10, 67108864 bytes)
Mount-cache hash table entries: 262144 (order: 5, 2097152 bytes)
Mountpoint-cache hash table entries: 262144 (order: 5, 2097152 bytes)

Unable to handle kernel paging request for data at address 0x00000038
Faulting instruction address: 0xc0000000000fc0cc
Oops: Kernel access of bad area, sig: 11 [#1]
SMP NR_CPUS=2048 NUMA PowerNV
Modules linked in:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.8.0-compiler_gcc-6.2.0-next-20161005 #94

task: c0000007f5400000 task.stack: c000001ffc084000
NIP: c0000000000fc0cc LR: c0000000000ed928 CTR: c0000000000fbfd0
REGS: c000001ffc087780 TRAP: 0300 Not tainted (4.8.0-compiler_gcc-6.2.0-next-20161005)
MSR: 9000000002009033 <SF,HV,VEC,EE,ME,IR,DR,RI,LE> CR: 48000424 XER: 00000000
CFAR: c0000000000089dc DAR: 0000000000000038 DSISR: 40000000 SOFTE: 0
GPR00: c0000000000ed928 c000001ffc087a00 c000000000e63200 c000000010d6d600
GPR04: c0000007f5409200 0000000000000021 000000000748e08c 000000000000001f
GPR08: 0000000000000000 0000000000000021 000000000748f1f8 0000000000000000
GPR12: 0000000028000422 c00000000fb80000 c00000000000e0c8 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000021 0000000000000001
GPR20: ffffffffafb50401 0000000000000000 c000000010d6d600 000000000000ba7e
GPR24: 000000000000ba7e c000000000d8bc58 afb504000afb5041 0000000000000001
GPR28: 0000000000000000 0000000000000004 c0000007f5409280 0000000000000000 NIP [c0000000000fc0cc] enqueue_task_fair+0xfc/0x18b0
LR [c0000000000ed928] activate_task+0x78/0xe0

Call Trace:

[c000001ffc087a00] [c0000007f5409200] 0xc0000007f5409200 (unreliable) [c000001ffc087b10] [c0000000000ed928] activate_task+0x78/0xe0 [c000001ffc087b50] [c0000000000ede58] ttwu_do_activate+0x68/0xc0 [c000001ffc087b90] [c0000000000ef1b8] try_to_wake_up+0x208/0x4f0 [c000001ffc087c10] [c0000000000d3484] create_worker+0x144/0x250 [c000001ffc087cb0] [c000000000cd72d0] workqueue_init+0x124/0x150 [c000001ffc087d00] [c000000000cc0e74] kernel_init_freeable+0x158/0x360 [c000001ffc087dc0] [c00000000000e0e4] kernel_init+0x24/0x160 [c000001ffc087e30] [c00000000000bfa0] ret_from_kernel_thread+0x5c/0xbc Instruction dump:
62940401 3b800000 3aa00000 7f17c378 3a600001 3b600001 60000000 60000000 60420000 72490021 ebfe0150 2f890001 <ebbf0038> 419e0de0 7fbee840 419e0e58

---[ end trace 0000000000000000 ]---
Quoted 9 lines

c0000000000fbfd0 <enqueue_task_fair>:
r4 = p
...
c0000000000fc040: 80 00 c4 3b addi r30,r4,128 r30 = r4 + 128 (&p->se)
...

c0000000000fc0c4:	50 01 fe eb 	ld      r31,336(r30)	r31 = *(r30 + 336) = se->cfs_rq
c0000000000fc0c8:	01 00 89 2f 	cmpwi   cr7,r9,1
c0000000000fc0cc:	38 00 bf eb 	ld      r29,56(r31)	r29 = cfs_rq->curr

I think there is a race

rest_init()

{
	...
	kernel_thread(kernel_init, NULL, CLONE_FS);
	numa_default_policy();
	pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
	rcu_read_lock();
	kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
	...

}

create_worker() needs kthreadd, it wakes up kthreadd in kthread_create_on_node, workqueue_init() is called from kernel_init() , but kthreadd is created after the call to kernel_init(), so its touch and go

Balbir Singh.

author maintainer
#5 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

Quoted 10 lines · Balbir Singh

rest_init()

{
	...
	kernel_thread(kernel_init, NULL, CLONE_FS);
	numa_default_policy();
	pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
	rcu_read_lock();
	kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
	...
Quoted 5 lines

}

create_worker() needs kthreadd, it wakes up kthreadd in kthread_create_on_node, workqueue_init() is called from kernel_init() , but kthreadd is created after the call to kernel_init(), so its touch and go

But the first thing kernel_init_freeable() does is wait_for_completion(&kthreadd_done).

Thanks.

Signature · 1 line
tejun
author maintainer
#7 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Michael Ellerman

Hello, Michael.

Quoted 8 lines · Michael Ellerman

This patch seems to be causing one of my Power8 boxes not to boot.

Specifically commit 3347fa092821 ("workqueue: make workqueue available early during boot") in linux-next.

If I revert this on top of next-20161005 then the machine boots again.

I've attached the oops below. It looks like the cfs_rq of p->se is NULL?

Hah, weird that it's arch dependent, or maybe it's just different config options. Most likely, it's caused by workqueue_init() call being moved too early. Can you please try the following patch and see whether the problem goes away?

Thanks.

init/main.c +1 -1
index 5c4fd68..fe4fa47 100644
@@ -1013,7 +1013,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	smp_prepare_cpus(setup_max_cpus);
 
-	workqueue_init();
+	//workqueue_init();
 
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/workqueue.c +1 -0
index ad0cd43..400f5e2 100644
@@ -5585,3 +5585,4 @@ int __init workqueue_init(void)
 
 	return 0;
 }
+early_initcall(workqueue_init);
author maintainer
#8 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

Quoted 8 lines · Tejun Heo

Hello, Michael.

Quoted 5 lines · Michael Ellerman

This patch seems to be causing one of my Power8 boxes not to boot.

Specifically commit 3347fa092821 ("workqueue: make workqueue available early during boot") in linux-next.

Quoted 8 lines
Quoted 3 lines

If I revert this on top of next-20161005 then the machine boots again.

I've attached the oops below. It looks like the cfs_rq of p->se is NULL?

Hah, weird that it's arch dependent, or maybe it's just different config options. Most likely, it's caused by workqueue_init() call being moved too early. Can you please try the following patch and see whether the problem goes away?

And if it does, can you please post the boot log with kernel boot option "initcall_debug=1" specified?

Thanks.

Signature · 1 line
tejun
#6 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Tejun Heo
Quoted 11 lines · Tejun Heo
Quoted 10 lines · Balbir Singh

rest_init()

{
	...
	kernel_thread(kernel_init, NULL, CLONE_FS);
	numa_default_policy();
	pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
	rcu_read_lock();
	kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
	...
Quoted 9 lines
Quoted 5 lines

}

create_worker() needs kthreadd, it wakes up kthreadd in kthread_create_on_node, workqueue_init() is called from kernel_init() , but kthreadd is created after the call to kernel_init(), so its touch and go

But the first thing kernel_init_freeable() does is wait_for_completion(&kthreadd_done).

Yes, Of course, looking at the stack trace again, it was not the wake_up itself, but the absence of cfs_rq of p->se that caused the issue. Will try and chase it down. Quick look shows cgroup_init() has occurred before workqueue_init(), so ideally p->se.cfs_rq should be allocated.

Sorry for the noise,

Balbir

#9 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Tejun Heo
Quoted 8 lines · Tejun Heo

Hello, Michael.

Quoted 5 lines · Michael Ellerman

This patch seems to be causing one of my Power8 boxes not to boot.

Specifically commit 3347fa092821 ("workqueue: make workqueue available early during boot") in linux-next.

Quoted 8 lines
Quoted 3 lines

If I revert this on top of next-20161005 then the machine boots again.

I've attached the oops below. It looks like the cfs_rq of p->se is NULL?

Hah, weird that it's arch dependent, or maybe it's just different config options. Most likely, it's caused by workqueue_init() call being moved too early. Can you please try the following patch and see whether the problem goes away?

No that doesn't help.

What does is this:

kernel/sched/core.c +2 -1
index 94732d1ab00a..4e79549d242f 100644
@@ -1614,7 +1614,8 @@ int select_task_rq(struct task_struct *p, int cpu, int sd_flags, int wake_flags)
 	 * [ this allows ->select_task() to simply return task_cpu(p) and
 	 *   not worry about this generic constraint ]
 	 */
-	if (unlikely(!cpumask_test_cpu(cpu, tsk_cpus_allowed(p)) ||
+	if (unlikely(cpu >= nr_cpu_ids ||
+		     !cpumask_test_cpu(cpu, tsk_cpus_allowed(p)) ||
 		     !cpu_online(cpu)))
 		cpu = select_fallback_rq(task_cpu(p), p);
 

The oops happens because we're in enqueue_task_fair() and p->se->cfs_rq is NULL.

The cfs_rq is NULL because we did set_task_rq(p, 2048), where 2048 is NR_CPUS. That causes us to index past the end of the tg->cfs_rq array in set_task_rq() and happen to get NULL.

We never should have done set_task_rq(p, 2048), because 2048 is >= nr_cpu_ids, which means it's not a valid CPU number, and set_task_rq() doesn't cope with that.

The reason we're calling set_task_rq() with CPU 2048 is because in select_task_rq() we had tsk_nr_cpus_allowed() = 0, because tsk_cpus_allowed(p) is an empty cpu mask.

That means we do in select_task_rq():
cpu = cpumask_any(tsk_cpus_allowed(p));

And when tsk_cpus_allowed(p) is empty cpumask_any() returns nr_cpu_ids, causing cpu to be set to 2048 in my case.

select_task_rq() then does the check to see if it should use a fallback rq:

if (unlikely(!cpumask_test_cpu(cpu, tsk_cpus_allowed(p)) ||

	     !cpu_online(cpu)))
	cpu = select_fallback_rq(task_cpu(p), p);

But in both those checks we end up indexing off the end of the cpu mask, because cpu is >= nr_cpu_ids. At least on my system they both return true and so we return cpu == 2048.

The patch above is pretty clearly not the right fix, though maybe it's a good safety measure.

Presumably we shouldn't be ending up with tsk_cpus_allowed() being empty, but I haven't had time to track down why that's happening.

cheers

#10 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

Quoted 71 lines · Michael Ellerman
Quoted 8 lines · Tejun Heo

Hello, Michael.

Quoted 5 lines · Michael Ellerman

This patch seems to be causing one of my Power8 boxes not to boot.

Specifically commit 3347fa092821 ("workqueue: make workqueue available early during boot") in linux-next.

Quoted 8 lines
Quoted 3 lines

If I revert this on top of next-20161005 then the machine boots again.

I've attached the oops below. It looks like the cfs_rq of p->se is NULL?

Hah, weird that it's arch dependent, or maybe it's just different config options. Most likely, it's caused by workqueue_init() call being moved too early. Can you please try the following patch and see whether the problem goes away?

No that doesn't help.

What does is this:

kernel/sched/core.c +2 -1
index 94732d1ab00a..4e79549d242f 100644
@@ -1614,7 +1614,8 @@ int select_task_rq(struct task_struct *p, int cpu, int sd_flags, int wake_flags)
 	 * [ this allows ->select_task() to simply return task_cpu(p) and
 	 *   not worry about this generic constraint ]
 	 */
-	if (unlikely(!cpumask_test_cpu(cpu, tsk_cpus_allowed(p)) ||
+	if (unlikely(cpu >= nr_cpu_ids ||
+		     !cpumask_test_cpu(cpu, tsk_cpus_allowed(p)) ||
 		     !cpu_online(cpu)))
 		cpu = select_fallback_rq(task_cpu(p), p);
 

The oops happens because we're in enqueue_task_fair() and p->se->cfs_rq is NULL.

The cfs_rq is NULL because we did set_task_rq(p, 2048), where 2048 is NR_CPUS. That causes us to index past the end of the tg->cfs_rq array in set_task_rq() and happen to get NULL.

We never should have done set_task_rq(p, 2048), because 2048 is >= nr_cpu_ids, which means it's not a valid CPU number, and set_task_rq() doesn't cope with that.

The reason we're calling set_task_rq() with CPU 2048 is because in select_task_rq() we had tsk_nr_cpus_allowed() = 0, because tsk_cpus_allowed(p) is an empty cpu mask.

That means we do in select_task_rq():
cpu = cpumask_any(tsk_cpus_allowed(p));

And when tsk_cpus_allowed(p) is empty cpumask_any() returns nr_cpu_ids, causing cpu to be set to 2048 in my case.

select_task_rq() then does the check to see if it should use a fallback rq:

if (unlikely(!cpumask_test_cpu(cpu, tsk_cpus_allowed(p)) ||

	     !cpu_online(cpu)))
	cpu = select_fallback_rq(task_cpu(p), p);

But in both those checks we end up indexing off the end of the cpu mask, because cpu is >= nr_cpu_ids. At least on my system they both return true and so we return cpu == 2048.

Quoted 8 lines

The patch above is pretty clearly not the right fix, though maybe it's a good safety measure.

Presumably we shouldn't be ending up with tsk_cpus_allowed() being empty, but I haven't had time to track down why that's happening.

cheers

+peterz

FYI: I see the samething on my cpu as well, its just that I get lucky and cpu_online(cpu) returns false.

I think from a functional perspective we may want to get some additional debug checks for places where the cpumask is empty early during boot.

Looks like there is a dependency between cpumasks and cpus coming online. I wonder if we can hit similar issues during hotplug

FWIW, your patch looks correct to me, though one might argue that cpumask_test_cpu() is a better place to fix it

Balbir Singh

author maintainer
#13 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Michael Ellerman

Hello, Michael.

Quoted 10 lines · Michael Ellerman

The oops happens because we're in enqueue_task_fair() and p->se->cfs_rq is NULL.

The cfs_rq is NULL because we did set_task_rq(p, 2048), where 2048 is NR_CPUS. That causes us to index past the end of the tg->cfs_rq array in set_task_rq() and happen to get NULL.

We never should have done set_task_rq(p, 2048), because 2048 is >= nr_cpu_ids, which means it's not a valid CPU number, and set_task_rq() doesn't cope with that.

Hmm... it doesn't reproduce it here and can't see how the commit would affect this given that it doesn't really change when the kworker kthreads are being created.

Quoted 2 lines

Presumably we shouldn't be ending up with tsk_cpus_allowed() being empty, but I haven't had time to track down why that's happening.

Can you please add WARN_ON_ONCE(!tsk_nr_cpus_allowed(p)) to select_task_rq() and post what that says?

Thanks.

Signature · 1 line
tejun
author maintainer
#11 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Balbir Singh

Hello, Balbir.

Quoted 2 lines · Balbir Singh

FYI: I see the samething on my cpu as well, its just that I get lucky and cpu_online(cpu) returns false.

Are you seeing this on x86 or is your test setup also a power machine?

Thanks.

Signature · 1 line
tejun
#14 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Tejun Heo
Quoted 10 lines · Tejun Heo

Hello, Michael.

Quoted 7 lines · Michael Ellerman

The oops happens because we're in enqueue_task_fair() and p->se->cfs_rq is NULL.

The cfs_rq is NULL because we did set_task_rq(p, 2048), where 2048 is NR_CPUS. That causes us to index past the end of the tg->cfs_rq array in set_task_rq() and happen to get NULL.

Quoted 11 lines
Quoted 3 lines

We never should have done set_task_rq(p, 2048), because 2048 is >= nr_cpu_ids, which means it's not a valid CPU number, and set_task_rq() doesn't cope with that.

Hmm... it doesn't reproduce it here and can't see how the commit would affect this given that it doesn't really change when the kworker kthreads are being created.

Quoted 2 lines

Presumably we shouldn't be ending up with tsk_cpus_allowed() being empty, but I haven't had time to track down why that's happening.

I think the basic analysis shows the change to creation of unbounded workqueues from the unbound_hash, but those have a pool cpumask empty.

Quoted 5 lines

Can you please add WARN_ON_ONCE(!tsk_nr_cpus_allowed(p)) to select_task_rq() and post what that says?

Thanks.

Balbir Singh.

#12 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Tejun Heo
Quoted 10 lines · Tejun Heo

Hello, Balbir.

Quoted 2 lines · Balbir Singh

FYI: I see the samething on my cpu as well, its just that I get lucky and cpu_online(cpu) returns false.

Are you seeing this on x86 or is your test setup also a power machine?

Thanks.

I saw this on a powerpc box

Balbir Singh.

#15 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Tejun Heo
Quoted 10 lines · Tejun Heo

Hello, Michael.

Quoted 7 lines · Michael Ellerman

The oops happens because we're in enqueue_task_fair() and p->se->cfs_rq is NULL.

The cfs_rq is NULL because we did set_task_rq(p, 2048), where 2048 is NR_CPUS. That causes us to index past the end of the tg->cfs_rq array in set_task_rq() and happen to get NULL.

Quoted 7 lines
Quoted 3 lines

We never should have done set_task_rq(p, 2048), because 2048 is >= nr_cpu_ids, which means it's not a valid CPU number, and set_task_rq() doesn't cope with that.

Hmm... it doesn't reproduce it here and can't see how the commit would affect this given that it doesn't really change when the kworker kthreads are being created.

Try turning on CONFIG_DEBUG_PER_CPU_MAPS=y ?

That will warn if you're indexing off the end of a cpu mask and just getting lucky with the result.

Quoted 5 lines
Quoted 2 lines

Presumably we shouldn't be ending up with tsk_cpus_allowed() being empty, but I haven't had time to track down why that's happening.

Can you please add WARN_ON_ONCE(!tsk_nr_cpus_allowed(p)) to select_task_rq() and post what that says?

It says:

------------[ cut here ]------------
WARNING: CPU: 0 PID: 1 at ../kernel/sched/core.c:1602 try_to_wake_up+0x3f4/0x5c0
Modules linked in:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.8.0-compiler_gcc-6.2.0-next-20161014-dirty #116

task: c000000ff9200000 task.stack: c000001ffc084000
NIP: c0000000000f1ba4 LR: c0000000000f180c CTR: 0000000000000000
REGS: c000001ffc0878f0 TRAP: 0700 Not tainted (4.8.0-compiler_gcc-6.2.0-next-20161014-dirty)
MSR: 9000000002029033 <SF,HV,VEC,EE,ME,IR,DR,RI,LE> CR: 28000422 XER: 00000000
CFAR: c0000000000f18bc SOFTE: 0
GPR00: c0000000000f180c c000001ffc087b70 c000000000e83400 0000000000000000
GPR04: 0000000000000002 0000000000000000 0000000000000000 0000000000000000
GPR08: c000000000dc3400 0000000000000001 0000000000000002 0000000000000000
GPR12: 0000000000000000 c00000000fb80000 c00000000000e0c8 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 0000000000000000 c000000000eb8960
GPR24: 0000000000000000 c000000000d8ce00 0000000000000000 0000000000000000
GPR28: c0000007f54050f4 0000000000000000 0000000000000000 c0000007f5404900 NIP [c0000000000f1ba4] try_to_wake_up+0x3f4/0x5c0
LR [c0000000000f180c] try_to_wake_up+0x5c/0x5c0

Call Trace:
[c000001ffc087b70] [c0000000000f180c] try_to_wake_up+0x5c/0x5c0 (unreliable)
[c000001ffc087bf0] [c0000000000d53e4] create_worker+0x144/0x250
[c000001ffc087c90] [c000000000cf7930] workqueue_init+0x170/0x19c
[c000001ffc087d00] [c000000000ce0e74] kernel_init_freeable+0x158/0x360
[c000001ffc087dc0] [c00000000000e0e4] kernel_init+0x24/0x160
[c000001ffc087e30] [c00000000000bfa0] ret_from_kernel_thread+0x5c/0xbc
Instruction dump:
e8790890 4bff6ed9 2fa30000 419e00dc 60000000 4bfffe54 3d02fff4 8928d7f9 
2f890000 409e0018 39200001 9928d7f9 <0fe00000> 60000000 60420000 3b5f0368 
---[ end trace 0000000000000000 ]---

But I'm not sure that tells us anything new?

cheers

#17 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Tejun Heo
Quoted 10 lines · Tejun Heo

Hello, Michael.

Quoted 7 lines · Michael Ellerman

The oops happens because we're in enqueue_task_fair() and p->se->cfs_rq is NULL.

The cfs_rq is NULL because we did set_task_rq(p, 2048), where 2048 is NR_CPUS. That causes us to index past the end of the tg->cfs_rq array in set_task_rq() and happen to get NULL.

Quoted 7 lines
Quoted 3 lines

We never should have done set_task_rq(p, 2048), because 2048 is >= nr_cpu_ids, which means it's not a valid CPU number, and set_task_rq() doesn't cope with that.

Hmm... it doesn't reproduce it here and can't see how the commit would affect this given that it doesn't really change when the kworker kthreads are being created.

It changes when the pool attributes are created, which is the source of the bug.

The original crash happens because we have a task with an empty cpus_allowed mask. That mask originally comes from pool->attrs->cpumask.

The attrs for the pool are created early via workqueue_init_early() in apply_wqattrs_prepare():

start_here_common
-> start_kernel

     -> workqueue_init_early
        -> __alloc_workqueue_key
           -> apply_workqueue_attrs
              -> apply_workqueue_attrs_locked
                 -> apply_wqattrs_prepare

In there we do:

	copy_workqueue_attrs(new_attrs, attrs);
	cpumask_and(new_attrs->cpumask, new_attrs->cpumask, wq_unbound_cpumask);
	if (unlikely(cpumask_empty(new_attrs->cpumask)))
		cpumask_copy(new_attrs->cpumask, wq_unbound_cpumask);
	...
	copy_workqueue_attrs(tmp_attrs, new_attrs);
	...
	for_each_node(node) {
		if (wq_calc_node_cpumask(new_attrs, node, -1, tmp_attrs->cpumask)) {
+			BUG_ON(cpumask_empty(tmp_attrs->cpumask));
			ctx->pwq_tbl[node] = alloc_unbound_pwq(wq, tmp_attrs);

The bad case (where we hit the BUG_ON I added above) is where we are creating a wq for node 1.

In wq_calc_node_cpumask() we do:

	cpumask_and(cpumask, attrs->cpumask, wq_numa_possible_cpumask[node]);
	return !cpumask_equal(cpumask, attrs->cpumask);

Which with the arguments inserted is:

	cpumask_and(tmp_attrs->cpumask, new_attrs->cpumask, wq_numa_possible_cpumask[1]);
	return !cpumask_equal(tmp_attrs->cpumask, new_attrs->cpumask);

And that results in tmp_attrs->cpumask being empty, because wq_numa_possible_cpumask[1] is an empty cpumask.

The reason wq_numa_possible_cpumask[1] is an empty mask is because in wq_numa_init() we did:

	for_each_possible_cpu(cpu) {
		node = cpu_to_node(cpu);
		if (WARN_ON(node == NUMA_NO_NODE)) {
			pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu);
			/* happens iff arch is bonkers, let's just proceed */
			return;
		}
		cpumask_set_cpu(cpu, tbl[node]);
	}

And cpu_to_node() returned node 0 for every CPU in the system, despite there being multiple nodes.

That happened because we haven't yet called set_cpu_numa_node() for the non-boot cpus, because that happens in smp_prepare_cpus(), and workqueue_init_early() is called much earlier than that.

This doesn't trigger on x86 because it does set_cpu_numa_node() in setup_per_cpu_areas(), which is called prior to workqueue_init_early().

We can (should) probably do the same on powerpc, I'll look at that tomorrow. But other arches may have a similar problem, and at the very least we need to document that workqueue_init_early() relies on cpu_to_node() working.

cheers

#18 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

Quoted 88 lines · Michael Ellerman
Quoted 10 lines · Tejun Heo

Hello, Michael.

Quoted 7 lines · Michael Ellerman

The oops happens because we're in enqueue_task_fair() and p->se->cfs_rq is NULL.

The cfs_rq is NULL because we did set_task_rq(p, 2048), where 2048 is NR_CPUS. That causes us to index past the end of the tg->cfs_rq array in set_task_rq() and happen to get NULL.

Quoted 7 lines
Quoted 3 lines

We never should have done set_task_rq(p, 2048), because 2048 is >= nr_cpu_ids, which means it's not a valid CPU number, and set_task_rq() doesn't cope with that.

Hmm... it doesn't reproduce it here and can't see how the commit would affect this given that it doesn't really change when the kworker kthreads are being created.

It changes when the pool attributes are created, which is the source of the bug.

The original crash happens because we have a task with an empty cpus_allowed mask. That mask originally comes from pool->attrs->cpumask.

The attrs for the pool are created early via workqueue_init_early() in apply_wqattrs_prepare():

start_here_common
-> start_kernel

     -> workqueue_init_early
        -> __alloc_workqueue_key
           -> apply_workqueue_attrs
              -> apply_workqueue_attrs_locked
                 -> apply_wqattrs_prepare

In there we do:

	copy_workqueue_attrs(new_attrs, attrs);
	cpumask_and(new_attrs->cpumask, new_attrs->cpumask, wq_unbound_cpumask);
	if (unlikely(cpumask_empty(new_attrs->cpumask)))
		cpumask_copy(new_attrs->cpumask, wq_unbound_cpumask);
	...
	copy_workqueue_attrs(tmp_attrs, new_attrs);
	...
	for_each_node(node) {
		if (wq_calc_node_cpumask(new_attrs, node, -1, tmp_attrs->cpumask)) {
(quoted diff) +1 -0
+			BUG_ON(cpumask_empty(tmp_attrs->cpumask));
			ctx->pwq_tbl[node] = alloc_unbound_pwq(wq, tmp_attrs);

The bad case (where we hit the BUG_ON I added above) is where we are creating a wq for node 1.

In wq_calc_node_cpumask() we do:

	cpumask_and(cpumask, attrs->cpumask, wq_numa_possible_cpumask[node]);
	return !cpumask_equal(cpumask, attrs->cpumask);

Which with the arguments inserted is:

	cpumask_and(tmp_attrs->cpumask, new_attrs->cpumask, wq_numa_possible_cpumask[1]);
	return !cpumask_equal(tmp_attrs->cpumask, new_attrs->cpumask);

And that results in tmp_attrs->cpumask being empty, because wq_numa_possible_cpumask[1] is an empty cpumask.

The reason wq_numa_possible_cpumask[1] is an empty mask is because in wq_numa_init() we did:

	for_each_possible_cpu(cpu) {
		node = cpu_to_node(cpu);
		if (WARN_ON(node == NUMA_NO_NODE)) {
			pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu);
			/* happens iff arch is bonkers, let's just proceed */
			return;
		}
		cpumask_set_cpu(cpu, tbl[node]);
	}

And cpu_to_node() returned node 0 for every CPU in the system, despite there being multiple nodes.

That happened because we haven't yet called set_cpu_numa_node() for the non-boot cpus, because that happens in smp_prepare_cpus(), and workqueue_init_early() is called much earlier than that.

Quoted 7 lines

This doesn't trigger on x86 because it does set_cpu_numa_node() in setup_per_cpu_areas(), which is called prior to workqueue_init_early().

We can (should) probably do the same on powerpc, I'll look at that tomorrow. But other arches may have a similar problem, and at the very least we need to document that workqueue_init_early() relies on cpu_to_node() working.

Don't we do the setup cpu->node mapings in initmem_init()? Ideally we have setup_arch->intmem_init->numa_setup_cpu

Will look at it tomorrow
Balbir Singh

author maintainer
#16 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Michael Ellerman

Hello,

Quoted 8 lines · Michael Ellerman
Quoted 3 lines

Hmm... it doesn't reproduce it here and can't see how the commit would affect this given that it doesn't really change when the kworker kthreads are being created.

Try turning on CONFIG_DEBUG_PER_CPU_MAPS=y ?

That will warn if you're indexing off the end of a cpu mask and just getting lucky with the result.

That's not happening on x86. That could mean that powerpc is initializing cpu_possible_mask after workqueue_init_early(). Looking into it.

Quoted 31 lines
------------[ cut here ]------------
WARNING: CPU: 0 PID: 1 at ../kernel/sched/core.c:1602 try_to_wake_up+0x3f4/0x5c0
Modules linked in:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.8.0-compiler_gcc-6.2.0-next-20161014-dirty #116

task: c000000ff9200000 task.stack: c000001ffc084000
NIP: c0000000000f1ba4 LR: c0000000000f180c CTR: 0000000000000000
REGS: c000001ffc0878f0 TRAP: 0700 Not tainted (4.8.0-compiler_gcc-6.2.0-next-20161014-dirty)
MSR: 9000000002029033 <SF,HV,VEC,EE,ME,IR,DR,RI,LE> CR: 28000422 XER: 00000000
CFAR: c0000000000f18bc SOFTE: 0
GPR00: c0000000000f180c c000001ffc087b70 c000000000e83400 0000000000000000
GPR04: 0000000000000002 0000000000000000 0000000000000000 0000000000000000
GPR08: c000000000dc3400 0000000000000001 0000000000000002 0000000000000000
GPR12: 0000000000000000 c00000000fb80000 c00000000000e0c8 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 0000000000000000 c000000000eb8960
GPR24: 0000000000000000 c000000000d8ce00 0000000000000000 0000000000000000
GPR28: c0000007f54050f4 0000000000000000 0000000000000000 c0000007f5404900 NIP [c0000000000f1ba4] try_to_wake_up+0x3f4/0x5c0
LR [c0000000000f180c] try_to_wake_up+0x5c/0x5c0

Call Trace:
[c000001ffc087b70] [c0000000000f180c] try_to_wake_up+0x5c/0x5c0 (unreliable)
[c000001ffc087bf0] [c0000000000d53e4] create_worker+0x144/0x250
[c000001ffc087c90] [c000000000cf7930] workqueue_init+0x170/0x19c
[c000001ffc087d00] [c000000000ce0e74] kernel_init_freeable+0x158/0x360
[c000001ffc087dc0] [c00000000000e0e4] kernel_init+0x24/0x160
[c000001ffc087e30] [c00000000000bfa0] ret_from_kernel_thread+0x5c/0xbc
Instruction dump:
e8790890 4bff6ed9 2fa30000 419e00dc 60000000 4bfffe54 3d02fff4 8928d7f9 
2f890000 409e0018 39200001 9928d7f9 <0fe00000> 60000000 60420000 3b5f0368 
---[ end trace 0000000000000000 ]---
Quoted 1 line

But I'm not sure that tells us anything new?

Yeah, I should have asked to print out information of the target task but it looks like we have enough information now.

Thanks.

Signature · 1 line
tejun
author maintainer
#20 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Michael Ellerman

Hello, Michael.

Quoted 8 lines · Michael Ellerman

The bad case (where we hit the BUG_ON I added above) is where we are creating a wq for node 1.

In wq_calc_node_cpumask() we do:

	cpumask_and(cpumask, attrs->cpumask, wq_numa_possible_cpumask[node]);
	return !cpumask_equal(cpumask, attrs->cpumask);
Quoted 7 lines

Which with the arguments inserted is:

	cpumask_and(tmp_attrs->cpumask, new_attrs->cpumask, wq_numa_possible_cpumask[1]);
	return !cpumask_equal(tmp_attrs->cpumask, new_attrs->cpumask);

And that results in tmp_attrs->cpumask being empty, because wq_numa_possible_cpumask[1] is an empty cpumask.

Ah, should have read this before replying to the previous mail, so it's the numa mask, not the cpu_possible_mask.

Quoted 20 lines

The reason wq_numa_possible_cpumask[1] is an empty mask is because in wq_numa_init() we did:

	for_each_possible_cpu(cpu) {
		node = cpu_to_node(cpu);
		if (WARN_ON(node == NUMA_NO_NODE)) {
			pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu);
			/* happens iff arch is bonkers, let's just proceed */
			return;
		}
		cpumask_set_cpu(cpu, tbl[node]);
	}

And cpu_to_node() returned node 0 for every CPU in the system, despite there being multiple nodes.

That happened because we haven't yet called set_cpu_numa_node() for the non-boot cpus, because that happens in smp_prepare_cpus(), and workqueue_init_early() is called much earlier than that.

Quoted 7 lines

This doesn't trigger on x86 because it does set_cpu_numa_node() in setup_per_cpu_areas(), which is called prior to workqueue_init_early().

We can (should) probably do the same on powerpc, I'll look at that tomorrow. But other arches may have a similar problem, and at the very least we need to document that workqueue_init_early() relies on cpu_to_node() working.

I should be able to move the numa part of initialization to the later init function. Working on it.

Thanks.

Signature · 1 line
tejun
author maintainer
#21 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

Hello, Michael.

Other NUMA archs are lazy-initializing cpu to node mapping too, so we need to fix it from workqueue side. This also means that we've been getting NUMA node wrong for percpu pools on those archs.

Can you please try the following patch and if it resolves the issue, report the workqueue part (it's at the end) of sysrq-t dump?

Thanks.

kernel/workqueue.c +12 -9
index 984f6ff..276557b 100644
@@ -4411,14 +4411,14 @@ void show_workqueue_state(void)
 				break;
 			}
 		}
-		if (idle)
-			continue;
+		//if (idle)
+		//	continue;
 
 		pr_info("workqueue %s: flags=0x%x\n", wq->name, wq->flags);
 
 		for_each_pwq(pwq, wq) {
 			spin_lock_irqsave(&pwq->pool->lock, flags);
-			if (pwq->nr_active || !list_empty(&pwq->delayed_works))
+			//if (pwq->nr_active || !list_empty(&pwq->delayed_works))
 				show_pwq(pwq);
 			spin_unlock_irqrestore(&pwq->pool->lock, flags);
 		}
@@ -4429,8 +4429,8 @@ void show_workqueue_state(void)
 		bool first = true;
 
 		spin_lock_irqsave(&pool->lock, flags);
-		if (pool->nr_workers == pool->nr_idle)
-			goto next_pool;
+		//if (pool->nr_workers == pool->nr_idle)
+		//	goto next_pool;
 
 		pr_info("pool %d:", pool->id);
 		pr_cont_pool_info(pool);
@@ -4649,10 +4649,12 @@ int workqueue_online_cpu(unsigned int cpu)
 	for_each_pool(pool, pi) {
 		mutex_lock(&pool->attach_mutex);
 
-		if (pool->cpu == cpu)
+		if (pool->cpu == cpu) {
+			pool->node = cpu_to_node(cpu);
 			rebind_workers(pool);
-		else if (pool->cpu < 0)
+		} else if (pool->cpu < 0) {
 			restore_unbound_workers_cpumask(pool, cpu);
+		}
 
 		mutex_unlock(&pool->attach_mutex);
 	}
@@ -5495,8 +5497,6 @@ int __init workqueue_init_early(void)
 
 	pwq_cache = KMEM_CACHE(pool_workqueue, SLAB_PANIC);
 
-	wq_numa_init();
-
 	/* initialize CPU pools */
 	for_each_possible_cpu(cpu) {
 		struct worker_pool *pool;
@@ -5571,6 +5571,9 @@ int __init workqueue_init(void)
 	struct worker_pool *pool;
 	int cpu, bkt;
 
+	wq_numa_init();
+	wq_update_unbound_numa(wq, smp_processor_id(), true);
+
 	/* create the initial workers */
 	for_each_online_cpu(cpu) {
 		for_each_cpu_worker_pool(pool, cpu) {
#19 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Balbir Singh
Quoted 8 lines · Balbir Singh
Quoted 7 lines · Michael Ellerman

That happened because we haven't yet called set_cpu_numa_node() for the non-boot cpus, because that happens in smp_prepare_cpus(), and workqueue_init_early() is called much earlier than that.

This doesn't trigger on x86 because it does set_cpu_numa_node() in setup_per_cpu_areas(), which is called prior to workqueue_init_early().

Quoted 7 lines
Quoted 4 lines

We can (should) probably do the same on powerpc, I'll look at that tomorrow. But other arches may have a similar problem, and at the very least we need to document that workqueue_init_early() relies on cpu_to_node() working.

Don't we do the setup cpu->node mapings in initmem_init()? Ideally we have setup_arch->intmem_init->numa_setup_cpu

That sets up numa_cpu_lookup_table, which is a powerpc only data structure.

But it doesn't setup the percpu numa_node variables, used by cpu_to_node(), because percpu areas are not setup yet.

cheers

#22 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

In reply to Tejun Heo
Quoted 15 lines · Tejun Heo

Hello, Michael.

Other NUMA archs are lazy-initializing cpu to node mapping too, so we need to fix it from workqueue side. This also means that we've been getting NUMA node wrong for percpu pools on those archs.

Can you please try the following patch and if it resolves the issue, report the workqueue part (it's at the end) of sysrq-t dump?

kernel/workqueue.c +0 -0
index 984f6ff..276557b 100644
@@ -4411,14 +4411,14 @@ void show_workqueue_state(void)

kernel/workqueue.c int __init workqueue_init(void) · line 5576

Quoted 6 lines
kernel/workqueue.c +3 -0
@@ -5571,6 +5571,9 @@ int __init workqueue_init(void)
 	struct worker_pool *pool;
 	int cpu, bkt;
 
+	wq_numa_init();
+	wq_update_unbound_numa(wq, smp_processor_id(), true);
+

That doesn't compile, wq doesn't exist.

I guessed that you meant:

+ wq_numa_init();
+ list_for_each_entry(wq, &workqueues, list)
+ wq_update_unbound_numa(wq, smp_processor_id(), true);

And that does boot.

The sysrq-t output is below, it's rather large.

cheers

9,924 lines not shown · raw message

Part of this message is not shown here. View the raw message.

author maintainer
#23 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

Hello, Michael.

kernel/workqueue.c int __init workqueue_init(void) · line 5575

Quoted 7 lines · Michael Ellerman

That doesn't compile, wq doesn't exist.

I guessed that you meant:

kernel/workqueue.c +3 -0
+       wq_numa_init();
+       list_for_each_entry(wq, &workqueues, list)
+               wq_update_unbound_numa(wq, smp_processor_id(), true);

Yeap, sorry about that.

Quoted 3 lines

And that does boot.

The sysrq-t output is below, it's rather large.

Didn't expect that many cpus but it looks good. I'll post proper patches soon.

Thanks!

Signature · 1 line
tejun
#24 lore raw

Re: Oops on Power8 (was Re: [PATCH v2 1/7] workqueue: make workqueue available early during boot)

Quoted 5 lines · Tejun Heo

Hello, Michael.

Quoted 2 lines · Michael Ellerman

That doesn't compile, wq doesn't exist.

Quoted 7 lines

kernel/workqueue.c int __init workqueue_init(void) · line 5575

Quoted 5 lines

I guessed that you meant:

kernel/workqueue.c +3 -0
+       wq_numa_init();
+       list_for_each_entry(wq, &workqueues, list)
+               wq_update_unbound_numa(wq, smp_processor_id(), true);

Yeap, sorry about that.

No worries.

Quoted 5 lines
Quoted 3 lines

And that does boot.

The sysrq-t output is below, it's rather large.

Didn't expect that many cpus but it looks good.

I have another system here with twice as many CPUs if that would help ;)

Quoted 1 line

I'll post proper patches soon.

Thanks. Can you pull the current series out of linux-next for now until you merge the new series?

cheers

author maintainer
#25 lore raw

PATCH 1/1 workqueue: move wq_numa_init() to workqueue_init()

Hello, Michael.

I simplified the patch a bit and applied the following to for-4.10 and updated for-next accordingly. The coming next snapshot should be fine.

Thanks!

------ 8< ------

Quoted 1 line

From 2186d9f940b6a04f263a3bacd48f2a7ba96df4cf Mon Sep 17 00:00:00 2001

From: Tejun Heo <[email protected]>
Date: Wed, 19 Oct 2016 12:01:27 -0400

While splitting up workqueue initialization into two parts, ac8f73400782 ("workqueue: make workqueue available early during boot") put wq_numa_init() into workqueue_init_early(). Unfortunately, on some archs including power and arm64, cpu to node mapping isn't yet established by the time the early init is called leading to incorrect NUMA initialization and subsequently the following oops due to zero cpumask on node-specific unbound pools.

  Unable to handle kernel paging request for data at address 0x00000038
  Faulting instruction address: 0xc0000000000fc0cc
  Oops: Kernel access of bad area, sig: 11 [#1]
  SMP NR_CPUS=2048 NUMA PowerNV
  Modules linked in:
  CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.8.0-compiler_gcc-6.2.0-next-20161005 #94
  task: c0000007f5400000 task.stack: c000001ffc084000
  NIP: c0000000000fc0cc LR: c0000000000ed928 CTR: c0000000000fbfd0
  REGS: c000001ffc087780 TRAP: 0300   Not tainted  (4.8.0-compiler_gcc-6.2.0-next-20161005)
  MSR: 9000000002009033 <SF,HV,VEC,EE,ME,IR,DR,RI,LE>  CR: 48000424  XER: 00000000
  CFAR: c0000000000089dc DAR: 0000000000000038 DSISR: 40000000 SOFTE: 0
  GPR00: c0000000000ed928 c000001ffc087a00 c000000000e63200 c000000010d6d600
  GPR04: c0000007f5409200 0000000000000021 000000000748e08c 000000000000001f
  GPR08: 0000000000000000 0000000000000021 000000000748f1f8 0000000000000000
  GPR12: 0000000028000422 c00000000fb80000 c00000000000e0c8 0000000000000000
  GPR16: 0000000000000000 0000000000000000 0000000000000021 0000000000000001
  GPR20: ffffffffafb50401 0000000000000000 c000000010d6d600 000000000000ba7e
  GPR24: 000000000000ba7e c000000000d8bc58 afb504000afb5041 0000000000000001
  GPR28: 0000000000000000 0000000000000004 c0000007f5409280 0000000000000000
  NIP [c0000000000fc0cc] enqueue_task_fair+0xfc/0x18b0
  LR [c0000000000ed928] activate_task+0x78/0xe0
  Call Trace:
  [c000001ffc087a00] [c0000007f5409200] 0xc0000007f5409200 (unreliable)
  [c000001ffc087b10] [c0000000000ed928] activate_task+0x78/0xe0
  [c000001ffc087b50] [c0000000000ede58] ttwu_do_activate+0x68/0xc0
  [c000001ffc087b90] [c0000000000ef1b8] try_to_wake_up+0x208/0x4f0
  [c000001ffc087c10] [c0000000000d3484] create_worker+0x144/0x250
  [c000001ffc087cb0] [c000000000cd72d0] workqueue_init+0x124/0x150
  [c000001ffc087d00] [c000000000cc0e74] kernel_init_freeable+0x158/0x360
  [c000001ffc087dc0] [c00000000000e0e4] kernel_init+0x24/0x160
  [c000001ffc087e30] [c00000000000bfa0] ret_from_kernel_thread+0x5c/0xbc
  Instruction dump:
  62940401 3b800000 3aa00000 7f17c378 3a600001 3b600001 60000000 60000000
  60420000 72490021 ebfe0150 2f890001 <ebbf0038> 419e0de0 7fbee840 419e0e58
  ---[ end trace 0000000000000000 ]---

Fix it by moving wq_numa_init() to workqueue_init(). As this means that the early intialization may not have full NUMA info for per-cpu pools and ignores NUMA affinity for unbound pools, fix them up from workqueue_init() after wq_numa_init().

Fixes ac8f73400782 ("workqueue: make workqueue available early during boot")
---
 kernel/workqueue.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
kernel/workqueue.c +23 -2
index ad0cd43..c56479b 100644
@@ -5495,8 +5495,6 @@ int __init workqueue_init_early(void)
 
 	pwq_cache = KMEM_CACHE(pool_workqueue, SLAB_PANIC);
 
-	wq_numa_init();
-
 	/* initialize CPU pools */
 	for_each_possible_cpu(cpu) {
 		struct worker_pool *pool;
@@ -5566,9 +5564,32 @@ int __init workqueue_init_early(void)
  */
 int __init workqueue_init(void)
 {
+	struct workqueue_struct *wq;
 	struct worker_pool *pool;
 	int cpu, bkt;
 
+	/*
+	 * It'd be simpler to initialize NUMA in workqueue_init_early() but
+	 * CPU to node mapping may not be available that early on some
+	 * archs such as power and arm64.  As per-cpu pools created
+	 * previously could be missing node hint and unbound pools NUMA
+	 * affinity, fix them up.
+	 */
+	wq_numa_init();
+
+	mutex_lock(&wq_pool_mutex);
+
+	for_each_possible_cpu(cpu) {
+		for_each_cpu_worker_pool(pool, cpu) {
+			pool->node = cpu_to_node(cpu);
+		}
+	}
+
+	list_for_each_entry(wq, &workqueues, list)
+		wq_update_unbound_numa(wq, smp_processor_id(), true);
+
+	mutex_unlock(&wq_pool_mutex);
+
 	/* create the initial workers */
 	for_each_online_cpu(cpu) {
 		for_each_cpu_worker_pool(pool, cpu) {
Signature · 1 line
2.7.4