All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early
@ 2017-05-14 18:27 Thomas Gleixner
  2017-05-14 18:27 ` [patch 01/18] init: Pin init task to boot cpu initially Thomas Gleixner
                   ` (18 more replies)
  0 siblings, 19 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML; +Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland

We recentlty discovered a call path which takes a mutex from the low level
secondary CPU bringup code and wondered why this was not caught by
might_sleep().

The reason is that both debug facilities depend on system_state ==
SYSTEM_RUNNING, which is set after init memory is freed.

That means that the SMP bootup and the builtin driver initialization is not
covered by these checks at all.

The patch series addresses this by adding two intermediate
states. might_sleep() debugging is enabled right when scheduling starts,
i.e. the boot CPU idle task schedules the first time. smp_processor_id()
debugging is enabled right before SMP bringup happens.

Thanks,

	tglx
----
 arch/arm/kernel/smp.c            |    3 +--
 arch/metag/kernel/smp.c          |    3 +--
 arch/x86/kernel/smpboot.c        |    2 +-
 b/arch/arm64/kernel/smp.c        |    3 +--
 b/arch/powerpc/kernel/smp.c      |    2 +-
 drivers/acpi/pci_root.c          |    2 +-
 drivers/base/node.c              |    2 +-
 drivers/cpufreq/pasemi-cpufreq.c |    2 +-
 drivers/iommu/intel-iommu.c      |    4 ++--
 drivers/iommu/of_iommu.c         |    2 +-
 drivers/xen/manage.c             |    2 ++
 include/linux/kernel.h           |    2 ++
 init/main.c                      |   12 ++++++++++--
 kernel/async.c                   |    8 ++++----
 kernel/extable.c                 |    2 +-
 kernel/printk/printk.c           |    2 +-
 kernel/sched/core.c              |    4 +++-
 lib/smp_processor_id.c           |    2 +-
 mm/vmscan.c                      |    2 +-
 19 files changed, 36 insertions(+), 25 deletions(-)

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 01/18] init: Pin init task to boot cpu initially
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
@ 2017-05-14 18:27 ` Thomas Gleixner
  2017-05-15 14:10   ` Steven Rostedt
  2017-05-14 18:27   ` Thomas Gleixner
                   ` (17 subsequent siblings)
  18 siblings, 1 reply; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML; +Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland

[-- Attachment #1: init--Pin-init-task-to-boot-cpu-initially.patch --]
[-- Type: text/plain, Size: 1408 bytes --]

Some of the boot code in init_kernel_freeable() which runs before SMP
bringup assumes (rightfully) that it runs on the boot cpu and therefor can
use smp_processor_id() in preemptible context.

That works so far because the smp_processor_id() check starts to be
effective after smp bringup. That's just wrong. Starting with SMP bringup
and the ability to move threads around, smp_processor_id() in preemptible
context is broken.

Aside of that it does not make sense to allow init to run on all cpus
before sched_smp_init() has been run.

Pin the init to the boot cpu so the existing code can continue to use
smp_processor_id() without triggering the checks when the enabling of those
checks starts earlier.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 init/main.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

--- a/init/main.c
+++ b/init/main.c
@@ -1015,10 +1015,13 @@ static noinline void __init kernel_init_
 	 * init can allocate pages on any node
 	 */
 	set_mems_allowed(node_states[N_MEMORY]);
+
 	/*
-	 * init can run on any cpu.
+	 * Pin init on the boot cpu. Task migration is not properly working
+	 * until sched_init_smp() has been run. It will set the allowed
+	 * cpus for init to the non isolated cpus.
 	 */
-	set_cpus_allowed_ptr(current, cpu_all_mask);
+	set_cpus_allowed_ptr(current, cpumask_of(raw_smp_processor_id()));
 
 	cad_pid = task_pid(current);
 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 02/18] arm: Adjust system_state check
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
@ 2017-05-14 18:27   ` Thomas Gleixner
  2017-05-14 18:27   ` Thomas Gleixner
                     ` (17 subsequent siblings)
  18 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Russell King, linux-arm-kernel

[-- Attachment #1: arm--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 818 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in ipi_cpu_stop() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Russell King <linux@armlinux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
---
 arch/arm/kernel/smp.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -555,8 +555,7 @@ static DEFINE_RAW_SPINLOCK(stop_lock);
  */
 static void ipi_cpu_stop(unsigned int cpu)
 {
-	if (system_state == SYSTEM_BOOTING ||
-	    system_state == SYSTEM_RUNNING) {
+	if (system_state <= SYSTEM_RUNNING) {
 		raw_spin_lock(&stop_lock);
 		pr_crit("CPU%u: stopping\n", cpu);
 		dump_stack();

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 02/18] arm: Adjust system_state check
@ 2017-05-14 18:27   ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: linux-arm-kernel

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in ipi_cpu_stop() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Russell King <linux@armlinux.org.uk>
Cc: linux-arm-kernel at lists.infradead.org
---
 arch/arm/kernel/smp.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -555,8 +555,7 @@ static DEFINE_RAW_SPINLOCK(stop_lock);
  */
 static void ipi_cpu_stop(unsigned int cpu)
 {
-	if (system_state == SYSTEM_BOOTING ||
-	    system_state == SYSTEM_RUNNING) {
+	if (system_state <= SYSTEM_RUNNING) {
 		raw_spin_lock(&stop_lock);
 		pr_crit("CPU%u: stopping\n", cpu);
 		dump_stack();

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 03/18] arm64: Adjust system_state check
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
@ 2017-05-14 18:27   ` Thomas Gleixner
  2017-05-14 18:27   ` Thomas Gleixner
                     ` (17 subsequent siblings)
  18 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Catalin Marinas, Will Deacon, linux-arm-kernel

[-- Attachment #1: arm64--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 939 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in smp_send_stop() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
---
 arch/arm64/kernel/smp.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -961,8 +961,7 @@ void smp_send_stop(void)
 		cpumask_copy(&mask, cpu_online_mask);
 		cpumask_clear_cpu(smp_processor_id(), &mask);
 
-		if (system_state == SYSTEM_BOOTING ||
-		    system_state == SYSTEM_RUNNING)
+		if (system_state <= SYSTEM_RUNNING)
 			pr_crit("SMP: stopping secondary CPUs\n");
 		smp_cross_call(&mask, IPI_CPU_STOP);
 	}

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 03/18] arm64: Adjust system_state check
@ 2017-05-14 18:27   ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: linux-arm-kernel

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in smp_send_stop() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel at lists.infradead.org
---
 arch/arm64/kernel/smp.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -961,8 +961,7 @@ void smp_send_stop(void)
 		cpumask_copy(&mask, cpu_online_mask);
 		cpumask_clear_cpu(smp_processor_id(), &mask);
 
-		if (system_state == SYSTEM_BOOTING ||
-		    system_state == SYSTEM_RUNNING)
+		if (system_state <= SYSTEM_RUNNING)
 			pr_crit("SMP: stopping secondary CPUs\n");
 		smp_cross_call(&mask, IPI_CPU_STOP);
 	}

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 04/18] x86/smp: Adjust system_state check
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
                   ` (2 preceding siblings ...)
  2017-05-14 18:27   ` Thomas Gleixner
@ 2017-05-14 18:27 ` Thomas Gleixner
  2017-05-15 14:17   ` Steven Rostedt
  2017-05-14 18:27   ` Thomas Gleixner
                   ` (14 subsequent siblings)
  18 siblings, 1 reply; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML; +Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland

[-- Attachment #1: x86-smp--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 726 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in announce_cpu() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/smpboot.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -863,7 +863,7 @@ static void announce_cpu(int cpu, int ap
 	if (cpu == 1)
 		printk(KERN_INFO "x86: Booting SMP configuration:\n");
 
-	if (system_state == SYSTEM_BOOTING) {
+	if (system_state < SYSTEM_RUNNING) {
 		if (node != current_node) {
 			if (current_node > (-1))
 				pr_cont("\n");

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 05/18] metag: Adjust system_state check
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
@ 2017-05-14 18:27   ` Thomas Gleixner
  2017-05-14 18:27   ` Thomas Gleixner
                     ` (17 subsequent siblings)
  18 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	James Hogan, linux-metag

[-- Attachment #1: metag--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 805 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in stop_this_cpu() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: linux-metag@vger.kernel.org
---
 arch/metag/kernel/smp.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/arch/metag/kernel/smp.c
+++ b/arch/metag/kernel/smp.c
@@ -567,8 +567,7 @@ static void stop_this_cpu(void *data)
 {
 	unsigned int cpu = smp_processor_id();
 
-	if (system_state == SYSTEM_BOOTING ||
-	    system_state == SYSTEM_RUNNING) {
+	if (system_state <= SYSTEM_RUNNING) {
 		spin_lock(&stop_lock);
 		pr_crit("CPU%u: stopping\n", cpu);
 		dump_stack();

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 05/18] metag: Adjust system_state check
@ 2017-05-14 18:27   ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	James Hogan, linux-metag-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: metag--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 885 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in stop_this_cpu() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Cc: James Hogan <james.hogan-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
Cc: linux-metag-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
---
 arch/metag/kernel/smp.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/arch/metag/kernel/smp.c
+++ b/arch/metag/kernel/smp.c
@@ -567,8 +567,7 @@ static void stop_this_cpu(void *data)
 {
 	unsigned int cpu = smp_processor_id();
 
-	if (system_state == SYSTEM_BOOTING ||
-	    system_state == SYSTEM_RUNNING) {
+	if (system_state <= SYSTEM_RUNNING) {
 		spin_lock(&stop_lock);
 		pr_crit("CPU%u: stopping\n", cpu);
 		dump_stack();


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 06/18] powerpc: Adjust system_state check
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
@ 2017-05-14 18:27   ` Thomas Gleixner
  2017-05-14 18:27   ` Thomas Gleixner
                     ` (17 subsequent siblings)
  18 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	linuxppc-dev

[-- Attachment #1: powerpc--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 1017 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in smp_generic_cpu_bootable() to handle the
extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
---
 arch/powerpc/kernel/smp.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -97,7 +97,7 @@ int smp_generic_cpu_bootable(unsigned in
 	/* Special case - we inhibit secondary thread startup
 	 * during boot if the user requests it.
 	 */
-	if (system_state == SYSTEM_BOOTING && cpu_has_feature(CPU_FTR_SMT)) {
+	if (system_state < SYSTEM_RUNNING && cpu_has_feature(CPU_FTR_SMT)) {
 		if (!smt_enabled_at_boot && cpu_thread_in_core(nr) != 0)
 			return 0;
 		if (smt_enabled_at_boot

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 06/18] powerpc: Adjust system_state check
@ 2017-05-14 18:27   ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	linuxppc-dev

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in smp_generic_cpu_bootable() to handle the
extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
---
 arch/powerpc/kernel/smp.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -97,7 +97,7 @@ int smp_generic_cpu_bootable(unsigned in
 	/* Special case - we inhibit secondary thread startup
 	 * during boot if the user requests it.
 	 */
-	if (system_state == SYSTEM_BOOTING && cpu_has_feature(CPU_FTR_SMT)) {
+	if (system_state < SYSTEM_RUNNING && cpu_has_feature(CPU_FTR_SMT)) {
 		if (!smt_enabled_at_boot && cpu_thread_in_core(nr) != 0)
 			return 0;
 		if (smt_enabled_at_boot

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 07/18] ACPI: Adjust system_state check
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
@ 2017-05-14 18:27   ` Thomas Gleixner
  2017-05-14 18:27   ` Thomas Gleixner
                     ` (17 subsequent siblings)
  18 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Catalin Marinas, Will Deacon, linux-arm-kernel

[-- Attachment #1: ACPI--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 936 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Make the decision wether a pci root is hotplugged depend on SYSTEM_RUNNING
instead of !SYSTEM_BOOTING.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
---
 drivers/acpi/pci_root.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -523,7 +523,7 @@ static int acpi_pci_root_add(struct acpi
 	struct acpi_pci_root *root;
 	acpi_handle handle = device->handle;
 	int no_aspm = 0;
-	bool hotadd = system_state != SYSTEM_BOOTING;
+	bool hotadd = system_state == SYSTEM_RUNNING;
 
 	root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
 	if (!root)

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 07/18] ACPI: Adjust system_state check
@ 2017-05-14 18:27   ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: linux-arm-kernel

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Make the decision wether a pci root is hotplugged depend on SYSTEM_RUNNING
instead of !SYSTEM_BOOTING.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel at lists.infradead.org
---
 drivers/acpi/pci_root.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -523,7 +523,7 @@ static int acpi_pci_root_add(struct acpi
 	struct acpi_pci_root *root;
 	acpi_handle handle = device->handle;
 	int no_aspm = 0;
-	bool hotadd = system_state != SYSTEM_BOOTING;
+	bool hotadd = system_state == SYSTEM_RUNNING;
 
 	root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
 	if (!root)

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 08/18] mm: Adjust system_state check
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
                   ` (6 preceding siblings ...)
  2017-05-14 18:27   ` Thomas Gleixner
@ 2017-05-14 18:27 ` Thomas Gleixner
  2017-05-15  6:18   ` Greg Kroah-Hartman
  2017-05-14 18:27   ` Thomas Gleixner
                   ` (10 subsequent siblings)
  18 siblings, 1 reply; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Mel Gorman, Greg Kroah-Hartman

[-- Attachment #1: mm--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 1073 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

get_nid_for_pfn() checks for system_state == BOOTING to decide whether to
use early_pfn_to_nid() when CONFIG_DEFERRED_STRUCT_PAGE_INIT=y.

That check is dubious, because the switch to state RUNNING happes way after
page_alloc_init_late() has been invoked.

Change the check to less than RUNNING state so it covers the new
intermediate states as well.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/base/node.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -377,7 +377,7 @@ static int __ref get_nid_for_pfn(unsigne
 	if (!pfn_valid_within(pfn))
 		return -1;
 #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
-	if (system_state == SYSTEM_BOOTING)
+	if (system_state < SYSTEM_RUNNING)
 		return early_pfn_to_nid(pfn);
 #endif
 	page = pfn_to_page(pfn);

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 09/18] cpufreq/pasemi: Adjust system_state check
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
@ 2017-05-14 18:27   ` Thomas Gleixner
  2017-05-14 18:27   ` Thomas Gleixner
                     ` (17 subsequent siblings)
  18 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Rafael J. Wysocki, Viresh Kumar, linuxppc-dev

[-- Attachment #1: cpufreq-pasemi--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 869 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in pas_cpufreq_cpu_exit() to handle the extra
states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
 drivers/cpufreq/pasemi-cpufreq.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/cpufreq/pasemi-cpufreq.c
+++ b/drivers/cpufreq/pasemi-cpufreq.c
@@ -226,7 +226,7 @@ static int pas_cpufreq_cpu_exit(struct c
 	 * We don't support CPU hotplug. Don't unmap after the system
 	 * has already made it to a running state.
 	 */
-	if (system_state != SYSTEM_BOOTING)
+	if (system_state >= SYSTEM_RUNNING)
 		return 0;
 
 	if (sdcasr_mapbase)

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 09/18] cpufreq/pasemi: Adjust system_state check
@ 2017-05-14 18:27   ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Rafael J. Wysocki, Viresh Kumar, linuxppc-dev

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in pas_cpufreq_cpu_exit() to handle the extra
states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
 drivers/cpufreq/pasemi-cpufreq.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/cpufreq/pasemi-cpufreq.c
+++ b/drivers/cpufreq/pasemi-cpufreq.c
@@ -226,7 +226,7 @@ static int pas_cpufreq_cpu_exit(struct c
 	 * We don't support CPU hotplug. Don't unmap after the system
 	 * has already made it to a running state.
 	 */
-	if (system_state != SYSTEM_BOOTING)
+	if (system_state >= SYSTEM_RUNNING)
 		return 0;
 
 	if (sdcasr_mapbase)

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 10/18] iommu/vt-d: Adjust system_state checks
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
@ 2017-05-14 18:27   ` Thomas Gleixner
  2017-05-14 18:27   ` Thomas Gleixner
                     ` (17 subsequent siblings)
  18 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	David Woodhouse, Joerg Roedel, iommu

[-- Attachment #1: iommu-vt-d--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 1254 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state checks in dmar_parse_one_atsr() and
dmar_iommu_notify_scope_dev() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: iommu@lists.linux-foundation.org
---
 drivers/iommu/intel-iommu.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -4312,7 +4312,7 @@ int dmar_parse_one_atsr(struct acpi_dmar
 	struct acpi_dmar_atsr *atsr;
 	struct dmar_atsr_unit *atsru;
 
-	if (system_state != SYSTEM_BOOTING && !intel_iommu_enabled)
+	if (system_state >= SYSTEM_RUNNING && !intel_iommu_enabled)
 		return 0;
 
 	atsr = container_of(hdr, struct acpi_dmar_atsr, header);
@@ -4562,7 +4562,7 @@ int dmar_iommu_notify_scope_dev(struct d
 	struct acpi_dmar_atsr *atsr;
 	struct acpi_dmar_reserved_memory *rmrr;
 
-	if (!intel_iommu_enabled && system_state != SYSTEM_BOOTING)
+	if (!intel_iommu_enabled && system_state >= SYSTEM_RUNNING)
 		return 0;
 
 	list_for_each_entry(rmrru, &dmar_rmrr_units, list) {

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 10/18] iommu/vt-d: Adjust system_state checks
@ 2017-05-14 18:27   ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Mark Rutland, Peter Zijlstra, Steven Rostedt,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	David Woodhouse, Ingo Molnar

[-- Attachment #1: iommu-vt-d--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 1369 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state checks in dmar_parse_one_atsr() and
dmar_iommu_notify_scope_dev() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Cc: David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
Cc: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
---
 drivers/iommu/intel-iommu.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -4312,7 +4312,7 @@ int dmar_parse_one_atsr(struct acpi_dmar
 	struct acpi_dmar_atsr *atsr;
 	struct dmar_atsr_unit *atsru;
 
-	if (system_state != SYSTEM_BOOTING && !intel_iommu_enabled)
+	if (system_state >= SYSTEM_RUNNING && !intel_iommu_enabled)
 		return 0;
 
 	atsr = container_of(hdr, struct acpi_dmar_atsr, header);
@@ -4562,7 +4562,7 @@ int dmar_iommu_notify_scope_dev(struct d
 	struct acpi_dmar_atsr *atsr;
 	struct acpi_dmar_reserved_memory *rmrr;
 
-	if (!intel_iommu_enabled && system_state != SYSTEM_BOOTING)
+	if (!intel_iommu_enabled && system_state >= SYSTEM_RUNNING)
 		return 0;
 
 	list_for_each_entry(rmrru, &dmar_rmrr_units, list) {

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 11/18] iommu/of: Adjust system_state check
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
@ 2017-05-14 18:27   ` Thomas Gleixner
  2017-05-14 18:27   ` Thomas Gleixner
                     ` (17 subsequent siblings)
  18 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Joerg Roedel, iommu

[-- Attachment #1: iommu-of--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 850 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in of_iommu_driver_present() to handle the
extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: iommu@lists.linux-foundation.org
---
 drivers/iommu/of_iommu.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/iommu/of_iommu.c
+++ b/drivers/iommu/of_iommu.c
@@ -103,7 +103,7 @@ static bool of_iommu_driver_present(stru
 	 * it never will be. We don't want to defer indefinitely, nor attempt
 	 * to dereference __iommu_of_table after it's been freed.
 	 */
-	if (system_state > SYSTEM_BOOTING)
+	if (system_state >= SYSTEM_RUNNING)
 		return false;
 
 	return of_match_node(&__iommu_of_table, np);

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 11/18] iommu/of: Adjust system_state check
@ 2017-05-14 18:27   ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Mark Rutland, Peter Zijlstra, Steven Rostedt,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Ingo Molnar

[-- Attachment #1: iommu-of--Adjust-system_state-check.patch --]
[-- Type: text/plain, Size: 939 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in of_iommu_driver_present() to handle the
extra states.

Signed-off-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Cc: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
---
 drivers/iommu/of_iommu.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/iommu/of_iommu.c
+++ b/drivers/iommu/of_iommu.c
@@ -103,7 +103,7 @@ static bool of_iommu_driver_present(stru
 	 * it never will be. We don't want to defer indefinitely, nor attempt
 	 * to dereference __iommu_of_table after it's been freed.
 	 */
-	if (system_state > SYSTEM_BOOTING)
+	if (system_state >= SYSTEM_RUNNING)
 		return false;
 
 	return of_match_node(&__iommu_of_table, np);

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 12/18] async: Adjust system_state checks
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
                   ` (10 preceding siblings ...)
  2017-05-14 18:27   ` Thomas Gleixner
@ 2017-05-14 18:27 ` Thomas Gleixner
  2017-05-14 18:39   ` Arjan van de Ven
  2017-05-14 18:27 ` [patch 13/18] extable: " Thomas Gleixner
                   ` (6 subsequent siblings)
  18 siblings, 1 reply; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Arjan van de Ven

[-- Attachment #1: async--Adjust-system_state-checks.patch --]
[-- Type: text/plain, Size: 1777 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in async_run_entry_fn() and
async_synchronize_cookie_domain() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Arjan van de Ven <arjan@linux.intel.com>
---
 kernel/async.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/kernel/async.c
+++ b/kernel/async.c
@@ -114,14 +114,14 @@ static void async_run_entry_fn(struct wo
 	ktime_t uninitialized_var(calltime), delta, rettime;
 
 	/* 1) run (and print duration) */
-	if (initcall_debug && system_state == SYSTEM_BOOTING) {
+	if (initcall_debug && system_state < SYSTEM_RUNNING) {
 		pr_debug("calling  %lli_%pF @ %i\n",
 			(long long)entry->cookie,
 			entry->func, task_pid_nr(current));
 		calltime = ktime_get();
 	}
 	entry->func(entry->data, entry->cookie);
-	if (initcall_debug && system_state == SYSTEM_BOOTING) {
+	if (initcall_debug && system_state < SYSTEM_RUNNING) {
 		rettime = ktime_get();
 		delta = ktime_sub(rettime, calltime);
 		pr_debug("initcall %lli_%pF returned 0 after %lld usecs\n",
@@ -284,14 +284,14 @@ void async_synchronize_cookie_domain(asy
 {
 	ktime_t uninitialized_var(starttime), delta, endtime;
 
-	if (initcall_debug && system_state == SYSTEM_BOOTING) {
+	if (initcall_debug && system_state < SYSTEM_RUNNING) {
 		pr_debug("async_waiting @ %i\n", task_pid_nr(current));
 		starttime = ktime_get();
 	}
 
 	wait_event(async_done, lowest_in_progress(domain) >= cookie);
 
-	if (initcall_debug && system_state == SYSTEM_BOOTING) {
+	if (initcall_debug && system_state < SYSTEM_RUNNING) {
 		endtime = ktime_get();
 		delta = ktime_sub(endtime, starttime);
 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 13/18] extable: Adjust system_state checks
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
                   ` (11 preceding siblings ...)
  2017-05-14 18:27 ` [patch 12/18] async: Adjust system_state checks Thomas Gleixner
@ 2017-05-14 18:27 ` Thomas Gleixner
  2017-05-15 14:37   ` Steven Rostedt
  2017-05-14 18:27 ` [patch 14/18] printk: " Thomas Gleixner
                   ` (5 subsequent siblings)
  18 siblings, 1 reply; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML; +Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland

[-- Attachment #1: extable--Adjust-system_state-checks.patch --]
[-- Type: text/plain, Size: 735 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in core_kernel_text() to handle the extra
states, i.e. to cover init text up to the point where the system switches
to state RUNNING.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/extable.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -75,7 +75,7 @@ int core_kernel_text(unsigned long addr)
 	    addr < (unsigned long)_etext)
 		return 1;
 
-	if (system_state == SYSTEM_BOOTING &&
+	if (system_state < SYSTEM_RUNNING &&
 	    init_kernel_text(addr))
 		return 1;
 	return 0;

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 14/18] printk: Adjust system_state checks
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
                   ` (12 preceding siblings ...)
  2017-05-14 18:27 ` [patch 13/18] extable: " Thomas Gleixner
@ 2017-05-14 18:27 ` Thomas Gleixner
  2017-05-15 14:53   ` Steven Rostedt
  2017-05-14 18:27   ` Thomas Gleixner
                   ` (4 subsequent siblings)
  18 siblings, 1 reply; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML; +Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland

[-- Attachment #1: printk--Adjust-system_state-checks.patch --]
[-- Type: text/plain, Size: 709 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in boot_delay_msec() to handle the extra
states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/printk/printk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1176,7 +1176,7 @@ static void boot_delay_msec(int level)
 	unsigned long long k;
 	unsigned long timeout;
 
-	if ((boot_delay == 0 || system_state != SYSTEM_BOOTING)
+	if ((boot_delay == 0 || system_state >= SYSTEM_RUNNING)
 		|| suppress_message_printing(level)) {
 		return;
 	}

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 15/18] mm/vmscan: Adjust system_state checks
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
@ 2017-05-14 18:27   ` Thomas Gleixner
  2017-05-14 18:27   ` Thomas Gleixner
                     ` (17 subsequent siblings)
  18 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Andrew Morton, Johannes Weiner, Mel Gorman, Michal Hocko,
	Vlastimil Babka, linux-mm

[-- Attachment #1: mm-vmscan--Adjust-system_state-checks.patch --]
[-- Type: text/plain, Size: 985 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in kswapd_run() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-mm@kvack.org
---
 mm/vmscan.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3643,7 +3643,7 @@ int kswapd_run(int nid)
 	pgdat->kswapd = kthread_run(kswapd, pgdat, "kswapd%d", nid);
 	if (IS_ERR(pgdat->kswapd)) {
 		/* failure at boot is fatal */
-		BUG_ON(system_state == SYSTEM_BOOTING);
+		BUG_ON(system_state < SYSTEM_RUNNING);
 		pr_err("Failed to start kswapd on node %d\n", nid);
 		ret = PTR_ERR(pgdat->kswapd);
 		pgdat->kswapd = NULL;

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 15/18] mm/vmscan: Adjust system_state checks
@ 2017-05-14 18:27   ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Andrew Morton, Johannes Weiner, Mel Gorman, Michal Hocko,
	Vlastimil Babka, linux-mm

[-- Attachment #1: mm-vmscan--Adjust-system_state-checks.patch --]
[-- Type: text/plain, Size: 1212 bytes --]

To enable smp_processor_id() and might_sleep() debug checks earlier, it's
required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

Adjust the system_state check in kswapd_run() to handle the extra states.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-mm@kvack.org
---
 mm/vmscan.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3643,7 +3643,7 @@ int kswapd_run(int nid)
 	pgdat->kswapd = kthread_run(kswapd, pgdat, "kswapd%d", nid);
 	if (IS_ERR(pgdat->kswapd)) {
 		/* failure at boot is fatal */
-		BUG_ON(system_state == SYSTEM_BOOTING);
+		BUG_ON(system_state < SYSTEM_RUNNING);
 		pr_err("Failed to start kswapd on node %d\n", nid);
 		ret = PTR_ERR(pgdat->kswapd);
 		pgdat->kswapd = NULL;


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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 16/18] init: Introduce SYSTEM_BOOTING_UP/SMP states
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
                   ` (14 preceding siblings ...)
  2017-05-14 18:27   ` Thomas Gleixner
@ 2017-05-14 18:27 ` Thomas Gleixner
  2017-05-15  9:58   ` Juergen Gross
  2017-05-15 14:58   ` Steven Rostedt
  2017-05-14 18:27 ` [patch 17/18] sched: Enable might_sleep() checks early Thomas Gleixner
                   ` (2 subsequent siblings)
  18 siblings, 2 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Boris Ostrovsky

[-- Attachment #1: init--Introduce-SYSTEM_BOOTING_UP-SMP-states.patch --]
[-- Type: text/plain, Size: 1073 bytes --]

might_sleep() debugging should be active right after the scheduler starts
working and smp_processor_id() debugging right before the first non boot
cpu is brought up.

Add two new states which allow to enable those checks earlier and add them
to the xen do_poweroff() function.

No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
 drivers/xen/manage.c   |    2 ++
 include/linux/kernel.h |    2 ++
 2 files changed, 4 insertions(+)

--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -190,6 +190,8 @@ static void do_poweroff(void)
 {
 	switch (system_state) {
 	case SYSTEM_BOOTING:
+	case SYSTEM_BOOTING_UP:
+	case SYSTEM_BOOTING_SMP:
 		orderly_poweroff(true);
 		break;
 	case SYSTEM_RUNNING:
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -493,6 +493,8 @@ extern bool early_boot_irqs_disabled;
 /* Values used for system_state */
 extern enum system_states {
 	SYSTEM_BOOTING,
+	SYSTEM_BOOTING_UP,
+	SYSTEM_BOOTING_SMP,
 	SYSTEM_RUNNING,
 	SYSTEM_HALT,
 	SYSTEM_POWER_OFF,

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 17/18] sched: Enable might_sleep() checks early
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
                   ` (15 preceding siblings ...)
  2017-05-14 18:27 ` [patch 16/18] init: Introduce SYSTEM_BOOTING_UP/SMP states Thomas Gleixner
@ 2017-05-14 18:27 ` Thomas Gleixner
  2017-05-15 15:10   ` Steven Rostedt
  2017-05-14 18:27 ` [patch 18/18] sched: Enable smp_processor_id() " Thomas Gleixner
  2017-05-15 11:53 ` [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Mark Rutland
  18 siblings, 1 reply; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML; +Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland

[-- Attachment #1: sched--Enable-might_sleep---checks-early.patch --]
[-- Type: text/plain, Size: 1303 bytes --]

might_sleep() checks are enabled after the boot process is done. That hides
bugs in the smp bringup and driver initialization code.

Enable it right when the scheduler starts working, i.e. when init task and
kthreadd have been created and right before the idle task enables
preemption.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 init/main.c         |    2 ++
 kernel/sched/core.c |    4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

--- a/init/main.c
+++ b/init/main.c
@@ -410,6 +410,8 @@ static noinline void __ref rest_init(voi
 	 * at least once to get things moving:
 	 */
 	init_idle_bootup_task(current);
+	/* Enable might_sleep() checks */
+	system_state = SYSTEM_BOOTING_UP;
 	schedule_preempt_disabled();
 	/* Call into cpu_idle with preempt disabled */
 	cpu_startup_entry(CPUHP_ONLINE);
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6226,8 +6226,10 @@ void ___might_sleep(const char *file, in
 
 	if ((preempt_count_equals(preempt_offset) && !irqs_disabled() &&
 	     !is_idle_task(current)) ||
-	    system_state != SYSTEM_RUNNING || oops_in_progress)
+	    system_state == SYSTEM_BOOTING || system_state > SYSTEM_RUNNING ||
+	    oops_in_progress)
 		return;
+
 	if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
 		return;
 	prev_jiffy = jiffies;

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 18/18] sched: Enable smp_processor_id() checks early
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
                   ` (16 preceding siblings ...)
  2017-05-14 18:27 ` [patch 17/18] sched: Enable might_sleep() checks early Thomas Gleixner
@ 2017-05-14 18:27 ` Thomas Gleixner
  2017-05-15 15:12   ` Steven Rostedt
  2017-05-15 11:53 ` [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Mark Rutland
  18 siblings, 1 reply; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-14 18:27 UTC (permalink / raw)
  To: LKML; +Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland

[-- Attachment #1: sched--Enable-smp_processor_id---checks-early.patch --]
[-- Type: text/plain, Size: 1164 bytes --]

smp_processor_id() checks are enabled after the boot process is done. That
hides bugs in the smp bringup and driver initialization code.

Enable it right before the first non-boot CPU is brought up.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 init/main.c            |    3 +++
 lib/smp_processor_id.c |    2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)


Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 init/main.c            |    3 +++
 lib/smp_processor_id.c |    2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

--- a/init/main.c
+++ b/init/main.c
@@ -1025,6 +1025,9 @@ static noinline void __init kernel_init_
 	 */
 	set_cpus_allowed_ptr(current, cpumask_of(raw_smp_processor_id()));
 
+	/* Enable smp_processor_id() checks */
+	system_state = SYSTEM_BOOTING_SMP;
+
 	cad_pid = task_pid(current);
 
 	smp_prepare_cpus(setup_max_cpus);
--- a/lib/smp_processor_id.c
+++ b/lib/smp_processor_id.c
@@ -28,7 +28,7 @@ notrace static unsigned int check_preemp
 	/*
 	 * It is valid to assume CPU-locality during early bootup:
 	 */
-	if (system_state != SYSTEM_RUNNING)
+	if (system_state < SYSTEM_BOOTING_SMP)
 		goto out;
 
 	/*

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 12/18] async: Adjust system_state checks
  2017-05-14 18:27 ` [patch 12/18] async: Adjust system_state checks Thomas Gleixner
@ 2017-05-14 18:39   ` Arjan van de Ven
  0 siblings, 0 replies; 61+ messages in thread
From: Arjan van de Ven @ 2017-05-14 18:39 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland

On 5/14/2017 11:27 AM, Thomas Gleixner wrote:

looks good .. ack

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 09/18] cpufreq/pasemi: Adjust system_state check
  2017-05-14 18:27   ` Thomas Gleixner
  (?)
@ 2017-05-15  5:24   ` Viresh Kumar
  2017-05-15 14:34     ` Steven Rostedt
  -1 siblings, 1 reply; 61+ messages in thread
From: Viresh Kumar @ 2017-05-15  5:24 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Rafael J. Wysocki, linuxppc-dev

On 14-05-17, 20:27, Thomas Gleixner wrote:
> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Adjust the system_state check in pas_cpufreq_cpu_exit() to handle the extra
> states.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Cc: linuxppc-dev@lists.ozlabs.org
> ---
>  drivers/cpufreq/pasemi-cpufreq.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/drivers/cpufreq/pasemi-cpufreq.c
> +++ b/drivers/cpufreq/pasemi-cpufreq.c
> @@ -226,7 +226,7 @@ static int pas_cpufreq_cpu_exit(struct c
>  	 * We don't support CPU hotplug. Don't unmap after the system
>  	 * has already made it to a running state.
>  	 */
> -	if (system_state != SYSTEM_BOOTING)
> +	if (system_state >= SYSTEM_RUNNING)
>  		return 0;
>  
>  	if (sdcasr_mapbase)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 08/18] mm: Adjust system_state check
  2017-05-14 18:27 ` [patch 08/18] mm: " Thomas Gleixner
@ 2017-05-15  6:18   ` Greg Kroah-Hartman
  2017-05-15 14:33     ` Steven Rostedt
  0 siblings, 1 reply; 61+ messages in thread
From: Greg Kroah-Hartman @ 2017-05-15  6:18 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Mel Gorman

On Sun, May 14, 2017 at 08:27:24PM +0200, Thomas Gleixner wrote:
> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> get_nid_for_pfn() checks for system_state == BOOTING to decide whether to
> use early_pfn_to_nid() when CONFIG_DEFERRED_STRUCT_PAGE_INIT=y.
> 
> That check is dubious, because the switch to state RUNNING happes way after
> page_alloc_init_late() has been invoked.
> 
> Change the check to less than RUNNING state so it covers the new
> intermediate states as well.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Mel Gorman <mgorman@techsingularity.net>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  drivers/base/node.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/drivers/base/node.c
> +++ b/drivers/base/node.c
> @@ -377,7 +377,7 @@ static int __ref get_nid_for_pfn(unsigne
>  	if (!pfn_valid_within(pfn))
>  		return -1;
>  #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
> -	if (system_state == SYSTEM_BOOTING)
> +	if (system_state < SYSTEM_RUNNING)

Someone better comment the place where these are defined that they need
to be in a specific order, I don't think they have been tested this way
in the past...

With that change:
	Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 06/18] powerpc: Adjust system_state check
  2017-05-14 18:27   ` Thomas Gleixner
  (?)
@ 2017-05-15  9:19   ` Michael Ellerman
  -1 siblings, 0 replies; 61+ messages in thread
From: Michael Ellerman @ 2017-05-15  9:19 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Benjamin Herrenschmidt, Paul Mackerras, linuxppc-dev

Thomas Gleixner <tglx@linutronix.de> writes:

> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
>
> Adjust the system_state check in smp_generic_cpu_bootable() to handle the
> extra states.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: linuxppc-dev@lists.ozlabs.org
> ---
>  arch/powerpc/kernel/smp.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Michael Ellerman <mpe@ellerman.id.au>

cheers

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 16/18] init: Introduce SYSTEM_BOOTING_UP/SMP states
  2017-05-14 18:27 ` [patch 16/18] init: Introduce SYSTEM_BOOTING_UP/SMP states Thomas Gleixner
@ 2017-05-15  9:58   ` Juergen Gross
  2017-05-15 14:58   ` Steven Rostedt
  1 sibling, 0 replies; 61+ messages in thread
From: Juergen Gross @ 2017-05-15  9:58 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	Boris Ostrovsky

On 14/05/17 20:27, Thomas Gleixner wrote:
> might_sleep() debugging should be active right after the scheduler starts
> working and smp_processor_id() debugging right before the first non boot
> cpu is brought up.
> 
> Add two new states which allow to enable those checks earlier and add them
> to the xen do_poweroff() function.
> 
> No functional change.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>

Acked-by: Juergen Gross <jgross@suse.com>


Juergen

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 07/18] ACPI: Adjust system_state check
  2017-05-14 18:27   ` Thomas Gleixner
@ 2017-05-15 10:20     ` Mark Rutland
  -1 siblings, 0 replies; 61+ messages in thread
From: Mark Rutland @ 2017-05-15 10:20 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Peter Zijlstra, Ingo Molnar, Steven Rostedt,
	Catalin Marinas, Will Deacon, linux-arm-kernel

On Sun, May 14, 2017 at 08:27:23PM +0200, Thomas Gleixner wrote:
> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Make the decision wether a pci root is hotplugged depend on SYSTEM_RUNNING
> instead of !SYSTEM_BOOTING.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: linux-arm-kernel@lists.infradead.org
> ---
>  drivers/acpi/pci_root.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

This looks sane to me, but I assume this was meant to be Cc'd to the
ACPI folk rather than the arm64 folk?

Mark.

> --- a/drivers/acpi/pci_root.c
> +++ b/drivers/acpi/pci_root.c
> @@ -523,7 +523,7 @@ static int acpi_pci_root_add(struct acpi
>  	struct acpi_pci_root *root;
>  	acpi_handle handle = device->handle;
>  	int no_aspm = 0;
> -	bool hotadd = system_state != SYSTEM_BOOTING;
> +	bool hotadd = system_state == SYSTEM_RUNNING;
>  
>  	root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
>  	if (!root)
> 
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 07/18] ACPI: Adjust system_state check
@ 2017-05-15 10:20     ` Mark Rutland
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Rutland @ 2017-05-15 10:20 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, May 14, 2017 at 08:27:23PM +0200, Thomas Gleixner wrote:
> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Make the decision wether a pci root is hotplugged depend on SYSTEM_RUNNING
> instead of !SYSTEM_BOOTING.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: linux-arm-kernel at lists.infradead.org
> ---
>  drivers/acpi/pci_root.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

This looks sane to me, but I assume this was meant to be Cc'd to the
ACPI folk rather than the arm64 folk?

Mark.

> --- a/drivers/acpi/pci_root.c
> +++ b/drivers/acpi/pci_root.c
> @@ -523,7 +523,7 @@ static int acpi_pci_root_add(struct acpi
>  	struct acpi_pci_root *root;
>  	acpi_handle handle = device->handle;
>  	int no_aspm = 0;
> -	bool hotadd = system_state != SYSTEM_BOOTING;
> +	bool hotadd = system_state == SYSTEM_RUNNING;
>  
>  	root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
>  	if (!root)
> 
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 07/18] ACPI: Adjust system_state check
  2017-05-15 10:20     ` Mark Rutland
@ 2017-05-15 10:25       ` Thomas Gleixner
  -1 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-15 10:25 UTC (permalink / raw)
  To: Mark Rutland
  Cc: LKML, Peter Zijlstra, Ingo Molnar, Steven Rostedt,
	Catalin Marinas, Will Deacon, linux-arm-kernel

On Mon, 15 May 2017, Mark Rutland wrote:

> On Sun, May 14, 2017 at 08:27:23PM +0200, Thomas Gleixner wrote:
> > To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> > required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> > 
> > Make the decision wether a pci root is hotplugged depend on SYSTEM_RUNNING
> > instead of !SYSTEM_BOOTING.
> > 
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > Cc: Will Deacon <will.deacon@arm.com>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: linux-arm-kernel@lists.infradead.org
> > ---
> >  drivers/acpi/pci_root.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> This looks sane to me, but I assume this was meant to be Cc'd to the
> ACPI folk rather than the arm64 folk?

Indeed.

> Mark.
> 
> > --- a/drivers/acpi/pci_root.c
> > +++ b/drivers/acpi/pci_root.c
> > @@ -523,7 +523,7 @@ static int acpi_pci_root_add(struct acpi
> >  	struct acpi_pci_root *root;
> >  	acpi_handle handle = device->handle;
> >  	int no_aspm = 0;
> > -	bool hotadd = system_state != SYSTEM_BOOTING;
> > +	bool hotadd = system_state == SYSTEM_RUNNING;
> >  
> >  	root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
> >  	if (!root)
> > 
> > 
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [patch 07/18] ACPI: Adjust system_state check
@ 2017-05-15 10:25       ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-15 10:25 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 15 May 2017, Mark Rutland wrote:

> On Sun, May 14, 2017 at 08:27:23PM +0200, Thomas Gleixner wrote:
> > To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> > required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> > 
> > Make the decision wether a pci root is hotplugged depend on SYSTEM_RUNNING
> > instead of !SYSTEM_BOOTING.
> > 
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > Cc: Will Deacon <will.deacon@arm.com>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: linux-arm-kernel at lists.infradead.org
> > ---
> >  drivers/acpi/pci_root.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> This looks sane to me, but I assume this was meant to be Cc'd to the
> ACPI folk rather than the arm64 folk?

Indeed.

> Mark.
> 
> > --- a/drivers/acpi/pci_root.c
> > +++ b/drivers/acpi/pci_root.c
> > @@ -523,7 +523,7 @@ static int acpi_pci_root_add(struct acpi
> >  	struct acpi_pci_root *root;
> >  	acpi_handle handle = device->handle;
> >  	int no_aspm = 0;
> > -	bool hotadd = system_state != SYSTEM_BOOTING;
> > +	bool hotadd = system_state == SYSTEM_RUNNING;
> >  
> >  	root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
> >  	if (!root)
> > 
> > 
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 11/18] iommu/of: Adjust system_state check
@ 2017-05-15 10:45     ` Robin Murphy
  0 siblings, 0 replies; 61+ messages in thread
From: Robin Murphy @ 2017-05-15 10:45 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: Mark Rutland, Peter Zijlstra, Steven Rostedt, iommu, Ingo Molnar

On 14/05/17 19:27, Thomas Gleixner wrote:
> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Adjust the system_state check in of_iommu_driver_present() to handle the
> extra states.

FWIW,

Acked-by: Robin Murphy <robin.murphy@arm.com>

> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Joerg Roedel <joro@8bytes.org>
> Cc: iommu@lists.linux-foundation.org
> ---
>  drivers/iommu/of_iommu.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/drivers/iommu/of_iommu.c
> +++ b/drivers/iommu/of_iommu.c
> @@ -103,7 +103,7 @@ static bool of_iommu_driver_present(stru
>  	 * it never will be. We don't want to defer indefinitely, nor attempt
>  	 * to dereference __iommu_of_table after it's been freed.
>  	 */
> -	if (system_state > SYSTEM_BOOTING)
> +	if (system_state >= SYSTEM_RUNNING)
>  		return false;
>  
>  	return of_match_node(&__iommu_of_table, np);
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 11/18] iommu/of: Adjust system_state check
@ 2017-05-15 10:45     ` Robin Murphy
  0 siblings, 0 replies; 61+ messages in thread
From: Robin Murphy @ 2017-05-15 10:45 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: Mark Rutland, Peter Zijlstra,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Ingo Molnar,
	Steven Rostedt

On 14/05/17 19:27, Thomas Gleixner wrote:
> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Adjust the system_state check in of_iommu_driver_present() to handle the
> extra states.

FWIW,

Acked-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>

> Signed-off-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
> Cc: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
> Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
> ---
>  drivers/iommu/of_iommu.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/drivers/iommu/of_iommu.c
> +++ b/drivers/iommu/of_iommu.c
> @@ -103,7 +103,7 @@ static bool of_iommu_driver_present(stru
>  	 * it never will be. We don't want to defer indefinitely, nor attempt
>  	 * to dereference __iommu_of_table after it's been freed.
>  	 */
> -	if (system_state > SYSTEM_BOOTING)
> +	if (system_state >= SYSTEM_RUNNING)
>  		return false;
>  
>  	return of_match_node(&__iommu_of_table, np);
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early
  2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
                   ` (17 preceding siblings ...)
  2017-05-14 18:27 ` [patch 18/18] sched: Enable smp_processor_id() " Thomas Gleixner
@ 2017-05-15 11:53 ` Mark Rutland
  18 siblings, 0 replies; 61+ messages in thread
From: Mark Rutland @ 2017-05-15 11:53 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Steven Rostedt

Hi Thomas,

On Sun, May 14, 2017 at 08:27:16PM +0200, Thomas Gleixner wrote:
> We recentlty discovered a call path which takes a mutex from the low level
> secondary CPU bringup code and wondered why this was not caught by
> might_sleep().
> 
> The reason is that both debug facilities depend on system_state ==
> SYSTEM_RUNNING, which is set after init memory is freed.
> 
> That means that the SMP bootup and the builtin driver initialization is not
> covered by these checks at all.
> 
> The patch series addresses this by adding two intermediate
> states. might_sleep() debugging is enabled right when scheduling starts,
> i.e. the boot CPU idle task schedules the first time. smp_processor_id()
> debugging is enabled right before SMP bringup happens.

Thanks for putting this together!

I've tested the series on a Juno R1 (arm64) system, with both DT and
ACPI.

Patch 17 finds the arm64 mutex issue [1] we discussed previously.

Otherwise, no new issues spotted with this on arm64, just an (existing)
ACPI PMU issue for which I've evidently not run sufficient checks on.

So for the bits relevant to arm64 (patches 1, 3, 7, 8, and 12-18):

Tested-by: Mark Rutland <mark.rutland@arm.com>

Thanks,
Mark.

[1] https://lkml.kernel.org/r/20170511125430.GD14766@leverpostej

> 
> Thanks,
> 
> 	tglx
> ----
>  arch/arm/kernel/smp.c            |    3 +--
>  arch/metag/kernel/smp.c          |    3 +--
>  arch/x86/kernel/smpboot.c        |    2 +-
>  b/arch/arm64/kernel/smp.c        |    3 +--
>  b/arch/powerpc/kernel/smp.c      |    2 +-
>  drivers/acpi/pci_root.c          |    2 +-
>  drivers/base/node.c              |    2 +-
>  drivers/cpufreq/pasemi-cpufreq.c |    2 +-
>  drivers/iommu/intel-iommu.c      |    4 ++--
>  drivers/iommu/of_iommu.c         |    2 +-
>  drivers/xen/manage.c             |    2 ++
>  include/linux/kernel.h           |    2 ++
>  init/main.c                      |   12 ++++++++++--
>  kernel/async.c                   |    8 ++++----
>  kernel/extable.c                 |    2 +-
>  kernel/printk/printk.c           |    2 +-
>  kernel/sched/core.c              |    4 +++-
>  lib/smp_processor_id.c           |    2 +-
>  mm/vmscan.c                      |    2 +-
>  19 files changed, 36 insertions(+), 25 deletions(-)
> 
> 
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 01/18] init: Pin init task to boot cpu initially
  2017-05-14 18:27 ` [patch 01/18] init: Pin init task to boot cpu initially Thomas Gleixner
@ 2017-05-15 14:10   ` Steven Rostedt
  0 siblings, 0 replies; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 14:10 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland

On Sun, 14 May 2017 20:27:17 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:

> Some of the boot code in init_kernel_freeable() which runs before SMP
> bringup assumes (rightfully) that it runs on the boot cpu and therefor can
> use smp_processor_id() in preemptible context.
> 
> That works so far because the smp_processor_id() check starts to be
> effective after smp bringup. That's just wrong. Starting with SMP bringup
> and the ability to move threads around, smp_processor_id() in preemptible
> context is broken.
> 
> Aside of that it does not make sense to allow init to run on all cpus
> before sched_smp_init() has been run.
> 
> Pin the init to the boot cpu so the existing code can continue to use
> smp_processor_id() without triggering the checks when the enabling of those
> checks starts earlier.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

> ---
>  init/main.c |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> --- a/init/main.c
> +++ b/init/main.c
> @@ -1015,10 +1015,13 @@ static noinline void __init kernel_init_
>  	 * init can allocate pages on any node
>  	 */
>  	set_mems_allowed(node_states[N_MEMORY]);
> +
>  	/*
> -	 * init can run on any cpu.
> +	 * Pin init on the boot cpu. Task migration is not properly working
> +	 * until sched_init_smp() has been run. It will set the allowed
> +	 * cpus for init to the non isolated cpus.
>  	 */
> -	set_cpus_allowed_ptr(current, cpu_all_mask);
> +	set_cpus_allowed_ptr(current, cpumask_of(raw_smp_processor_id()));
>  
>  	cad_pid = task_pid(current);
>  
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 04/18] x86/smp: Adjust system_state check
  2017-05-14 18:27 ` [patch 04/18] x86/smp: " Thomas Gleixner
@ 2017-05-15 14:17   ` Steven Rostedt
  0 siblings, 0 replies; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 14:17 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland

On Sun, 14 May 2017 20:27:20 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:

> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Adjust the system_state check in announce_cpu() to handle the extra states.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

> ---
>  arch/x86/kernel/smpboot.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/arch/x86/kernel/smpboot.c
> +++ b/arch/x86/kernel/smpboot.c
> @@ -863,7 +863,7 @@ static void announce_cpu(int cpu, int ap
>  	if (cpu == 1)
>  		printk(KERN_INFO "x86: Booting SMP configuration:\n");
>  
> -	if (system_state == SYSTEM_BOOTING) {
> +	if (system_state < SYSTEM_RUNNING) {
>  		if (node != current_node) {
>  			if (current_node > (-1))
>  				pr_cont("\n");
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 07/18] ACPI: Adjust system_state check
  2017-05-14 18:27   ` Thomas Gleixner
  (?)
  (?)
@ 2017-05-15 14:27   ` Steven Rostedt
  2017-05-16 18:13     ` Thomas Gleixner
  -1 siblings, 1 reply; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 14:27 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland, Catalin Marinas,
	Will Deacon, linux-acpi, Len Brown


[ added linux-acpi and took off arm list ;-) ]

On Sun, 14 May 2017 20:27:23 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:

> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Make the decision wether a pci root is hotplugged depend on SYSTEM_RUNNING
> instead of !SYSTEM_BOOTING.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: linux-arm-kernel@lists.infradead.org
> ---
>  drivers/acpi/pci_root.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/drivers/acpi/pci_root.c
> +++ b/drivers/acpi/pci_root.c
> @@ -523,7 +523,7 @@ static int acpi_pci_root_add(struct acpi
>  	struct acpi_pci_root *root;
>  	acpi_handle handle = device->handle;
>  	int no_aspm = 0;
> -	bool hotadd = system_state != SYSTEM_BOOTING;
> +	bool hotadd = system_state == SYSTEM_RUNNING;

What about the other boot states greater than SYSTEM_RUNNING? Can this
be called then too?

IOW, should it be:

	bool hotadd = system_state >= SYSTEM_RUNNING;

?

-- Steve

>  
>  	root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
>  	if (!root)
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 08/18] mm: Adjust system_state check
  2017-05-15  6:18   ` Greg Kroah-Hartman
@ 2017-05-15 14:33     ` Steven Rostedt
  0 siblings, 0 replies; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 14:33 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Thomas Gleixner, LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Mel Gorman

On Mon, 15 May 2017 08:18:26 +0200
Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:


> > --- a/drivers/base/node.c
> > +++ b/drivers/base/node.c
> > @@ -377,7 +377,7 @@ static int __ref get_nid_for_pfn(unsigne
> >  	if (!pfn_valid_within(pfn))
> >  		return -1;
> >  #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
> > -	if (system_state == SYSTEM_BOOTING)
> > +	if (system_state < SYSTEM_RUNNING)  
> 
> Someone better comment the place where these are defined that they need
> to be in a specific order, I don't think they have been tested this way
> in the past...

Comments never hurt but it has been used before this patch set.

$ git grep  SYSTEM_RUNNING v4.12-rc1 | grep -e '<' -e '>'
v4.12-rc1:arch/powerpc/kernel/smp.c:    if (system_state < SYSTEM_RUNNING)
v4.12-rc1:arch/powerpc/platforms/powernv/eeh-powernv.c:         if (system_state < SYSTEM_RUNNING)
v4.12-rc1:arch/powerpc/platforms/powernv/eeh-powernv.c:         if (system_state < SYSTEM_RUNNING)
v4.12-rc1:drivers/cpuidle/cpuidle-powernv.c:    if (unlikely(system_state < SYSTEM_RUNNING))
v4.12-rc1:drivers/xen/xenbus/xenbus_probe.c:    if (system_state > SYSTEM_RUNNING) {

-- Steve

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 09/18] cpufreq/pasemi: Adjust system_state check
  2017-05-15  5:24   ` Viresh Kumar
@ 2017-05-15 14:34     ` Steven Rostedt
  0 siblings, 0 replies; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 14:34 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Thomas Gleixner, LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Rafael J. Wysocki, linuxppc-dev, Olof Johansson

On Mon, 15 May 2017 10:54:03 +0530
Viresh Kumar <viresh.kumar@linaro.org> wrote:

> On 14-05-17, 20:27, Thomas Gleixner wrote:
> > To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> > required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> > 
> > Adjust the system_state check in pas_cpufreq_cpu_exit() to handle the extra
> > states.
> > 
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> > Cc: Viresh Kumar <viresh.kumar@linaro.org>
> > Cc: linuxppc-dev@lists.ozlabs.org
> > ---
> >  drivers/cpufreq/pasemi-cpufreq.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > --- a/drivers/cpufreq/pasemi-cpufreq.c
> > +++ b/drivers/cpufreq/pasemi-cpufreq.c
> > @@ -226,7 +226,7 @@ static int pas_cpufreq_cpu_exit(struct c
> >  	 * We don't support CPU hotplug. Don't unmap after the system
> >  	 * has already made it to a running state.
> >  	 */
> > -	if (system_state != SYSTEM_BOOTING)
> > +	if (system_state >= SYSTEM_RUNNING)
> >  		return 0;
> >  
> >  	if (sdcasr_mapbase)  
> 
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
> 

This reminds me. My pasemi died. I was trying to see if anyone had an
extra one they could send me ;-)

-- Steve

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 13/18] extable: Adjust system_state checks
  2017-05-14 18:27 ` [patch 13/18] extable: " Thomas Gleixner
@ 2017-05-15 14:37   ` Steven Rostedt
  0 siblings, 0 replies; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 14:37 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland

On Sun, 14 May 2017 20:27:29 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:

> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Adjust the system_state check in core_kernel_text() to handle the extra
> states, i.e. to cover init text up to the point where the system switches
> to state RUNNING.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve


> ---
>  kernel/extable.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/kernel/extable.c
> +++ b/kernel/extable.c
> @@ -75,7 +75,7 @@ int core_kernel_text(unsigned long addr)
>  	    addr < (unsigned long)_etext)
>  		return 1;
>  
> -	if (system_state == SYSTEM_BOOTING &&
> +	if (system_state < SYSTEM_RUNNING &&
>  	    init_kernel_text(addr))
>  		return 1;
>  	return 0;
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 10/18] iommu/vt-d: Adjust system_state checks
  2017-05-14 18:27   ` Thomas Gleixner
  (?)
@ 2017-05-15 14:42   ` Joerg Roedel
  -1 siblings, 0 replies; 61+ messages in thread
From: Joerg Roedel @ 2017-05-15 14:42 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland,
	David Woodhouse, iommu

On Sun, May 14, 2017 at 08:27:26PM +0200, Thomas Gleixner wrote:
> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Adjust the system_state checks in dmar_parse_one_atsr() and
> dmar_iommu_notify_scope_dev() to handle the extra states.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: David Woodhouse <dwmw2@infradead.org>
> Cc: Joerg Roedel <joro@8bytes.org>
> Cc: iommu@lists.linux-foundation.org
> ---
>  drivers/iommu/intel-iommu.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Acked-by: Joerg Roedel <jroedel@suse.de>

> 
> --- a/drivers/iommu/intel-iommu.c
> +++ b/drivers/iommu/intel-iommu.c
> @@ -4312,7 +4312,7 @@ int dmar_parse_one_atsr(struct acpi_dmar
>  	struct acpi_dmar_atsr *atsr;
>  	struct dmar_atsr_unit *atsru;
>  
> -	if (system_state != SYSTEM_BOOTING && !intel_iommu_enabled)
> +	if (system_state >= SYSTEM_RUNNING && !intel_iommu_enabled)
>  		return 0;
>  
>  	atsr = container_of(hdr, struct acpi_dmar_atsr, header);
> @@ -4562,7 +4562,7 @@ int dmar_iommu_notify_scope_dev(struct d
>  	struct acpi_dmar_atsr *atsr;
>  	struct acpi_dmar_reserved_memory *rmrr;
>  
> -	if (!intel_iommu_enabled && system_state != SYSTEM_BOOTING)
> +	if (!intel_iommu_enabled && system_state >= SYSTEM_RUNNING)
>  		return 0;
>  
>  	list_for_each_entry(rmrru, &dmar_rmrr_units, list) {
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 11/18] iommu/of: Adjust system_state check
@ 2017-05-15 14:42     ` Joerg Roedel
  0 siblings, 0 replies; 61+ messages in thread
From: Joerg Roedel @ 2017-05-15 14:42 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Peter Zijlstra, Ingo Molnar, Steven Rostedt, Mark Rutland, iommu

On Sun, May 14, 2017 at 08:27:27PM +0200, Thomas Gleixner wrote:
> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Adjust the system_state check in of_iommu_driver_present() to handle the
> extra states.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Joerg Roedel <joro@8bytes.org>
> Cc: iommu@lists.linux-foundation.org

Acked-by: Joerg Roedel <jroedel@suse.de>

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 11/18] iommu/of: Adjust system_state check
@ 2017-05-15 14:42     ` Joerg Roedel
  0 siblings, 0 replies; 61+ messages in thread
From: Joerg Roedel @ 2017-05-15 14:42 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Mark Rutland, Peter Zijlstra, LKML, Steven Rostedt,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Ingo Molnar

On Sun, May 14, 2017 at 08:27:27PM +0200, Thomas Gleixner wrote:
> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Adjust the system_state check in of_iommu_driver_present() to handle the
> extra states.
> 
> Signed-off-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
> Cc: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
> Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org

Acked-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 14/18] printk: Adjust system_state checks
  2017-05-14 18:27 ` [patch 14/18] printk: " Thomas Gleixner
@ 2017-05-15 14:53   ` Steven Rostedt
  0 siblings, 0 replies; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 14:53 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland

On Sun, 14 May 2017 20:27:30 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:

> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Adjust the system_state check in boot_delay_msec() to handle the extra
> states.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

> ---
>  kernel/printk/printk.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -1176,7 +1176,7 @@ static void boot_delay_msec(int level)
>  	unsigned long long k;
>  	unsigned long timeout;
>  
> -	if ((boot_delay == 0 || system_state != SYSTEM_BOOTING)
> +	if ((boot_delay == 0 || system_state >= SYSTEM_RUNNING)
>  		|| suppress_message_printing(level)) {
>  		return;
>  	}
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 15/18] mm/vmscan: Adjust system_state checks
  2017-05-14 18:27   ` Thomas Gleixner
@ 2017-05-15 14:54     ` Steven Rostedt
  -1 siblings, 0 replies; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 14:54 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland, Andrew Morton,
	Johannes Weiner, Mel Gorman, Michal Hocko, Vlastimil Babka,
	linux-mm

On Sun, 14 May 2017 20:27:31 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:

> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Adjust the system_state check in kswapd_run() to handle the extra states.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Mel Gorman <mgorman@techsingularity.net>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: linux-mm@kvack.org
> ---
>  mm/vmscan.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -3643,7 +3643,7 @@ int kswapd_run(int nid)
>  	pgdat->kswapd = kthread_run(kswapd, pgdat, "kswapd%d", nid);
>  	if (IS_ERR(pgdat->kswapd)) {
>  		/* failure at boot is fatal */
> -		BUG_ON(system_state == SYSTEM_BOOTING);
> +		BUG_ON(system_state < SYSTEM_RUNNING);
>  		pr_err("Failed to start kswapd on node %d\n", nid);
>  		ret = PTR_ERR(pgdat->kswapd);
>  		pgdat->kswapd = NULL;
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 15/18] mm/vmscan: Adjust system_state checks
@ 2017-05-15 14:54     ` Steven Rostedt
  0 siblings, 0 replies; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 14:54 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland, Andrew Morton,
	Johannes Weiner, Mel Gorman, Michal Hocko, Vlastimil Babka,
	linux-mm

On Sun, 14 May 2017 20:27:31 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:

> To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> 
> Adjust the system_state check in kswapd_run() to handle the extra states.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Mel Gorman <mgorman@techsingularity.net>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: linux-mm@kvack.org
> ---
>  mm/vmscan.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -3643,7 +3643,7 @@ int kswapd_run(int nid)
>  	pgdat->kswapd = kthread_run(kswapd, pgdat, "kswapd%d", nid);
>  	if (IS_ERR(pgdat->kswapd)) {
>  		/* failure at boot is fatal */
> -		BUG_ON(system_state == SYSTEM_BOOTING);
> +		BUG_ON(system_state < SYSTEM_RUNNING);
>  		pr_err("Failed to start kswapd on node %d\n", nid);
>  		ret = PTR_ERR(pgdat->kswapd);
>  		pgdat->kswapd = NULL;
> 

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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 16/18] init: Introduce SYSTEM_BOOTING_UP/SMP states
  2017-05-14 18:27 ` [patch 16/18] init: Introduce SYSTEM_BOOTING_UP/SMP states Thomas Gleixner
  2017-05-15  9:58   ` Juergen Gross
@ 2017-05-15 14:58   ` Steven Rostedt
  1 sibling, 0 replies; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 14:58 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland, Boris Ostrovsky

On Sun, 14 May 2017 20:27:32 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:

> might_sleep() debugging should be active right after the scheduler starts
> working and smp_processor_id() debugging right before the first non boot
> cpu is brought up.
> 
> Add two new states which allow to enable those checks earlier and add them
> to the xen do_poweroff() function.
> 
> No functional change.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> ---
>  drivers/xen/manage.c   |    2 ++
>  include/linux/kernel.h |    2 ++
>  2 files changed, 4 insertions(+)
> 
> --- a/drivers/xen/manage.c
> +++ b/drivers/xen/manage.c
> @@ -190,6 +190,8 @@ static void do_poweroff(void)
>  {
>  	switch (system_state) {
>  	case SYSTEM_BOOTING:
> +	case SYSTEM_BOOTING_UP:
> +	case SYSTEM_BOOTING_SMP:
>  		orderly_poweroff(true);
>  		break;
>  	case SYSTEM_RUNNING:
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -493,6 +493,8 @@ extern bool early_boot_irqs_disabled;
>  /* Values used for system_state */
>  extern enum system_states {
>  	SYSTEM_BOOTING,
> +	SYSTEM_BOOTING_UP,
> +	SYSTEM_BOOTING_SMP,
>  	SYSTEM_RUNNING,
>  	SYSTEM_HALT,
>  	SYSTEM_POWER_OFF,
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 17/18] sched: Enable might_sleep() checks early
  2017-05-14 18:27 ` [patch 17/18] sched: Enable might_sleep() checks early Thomas Gleixner
@ 2017-05-15 15:10   ` Steven Rostedt
  2017-05-15 19:12     ` Thomas Gleixner
  0 siblings, 1 reply; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 15:10 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland

On Sun, 14 May 2017 20:27:33 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:

> might_sleep() checks are enabled after the boot process is done. That hides
> bugs in the smp bringup and driver initialization code.
> 
> Enable it right when the scheduler starts working, i.e. when init task and
> kthreadd have been created and right before the idle task enables
> preemption.

Looking at commit b433c3d4549ae749, it appears that on very slow
machines, there is a possibility that the init task can start running.
Should system_state be updated before that complete() is called?

-- Steve

> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  init/main.c         |    2 ++
>  kernel/sched/core.c |    4 +++-
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> --- a/init/main.c
> +++ b/init/main.c
> @@ -410,6 +410,8 @@ static noinline void __ref rest_init(voi
>  	 * at least once to get things moving:
>  	 */
>  	init_idle_bootup_task(current);
> +	/* Enable might_sleep() checks */
> +	system_state = SYSTEM_BOOTING_UP;
>  	schedule_preempt_disabled();
>  	/* Call into cpu_idle with preempt disabled */
>  	cpu_startup_entry(CPUHP_ONLINE);
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -6226,8 +6226,10 @@ void ___might_sleep(const char *file, in
>  
>  	if ((preempt_count_equals(preempt_offset) && !irqs_disabled() &&
>  	     !is_idle_task(current)) ||
> -	    system_state != SYSTEM_RUNNING || oops_in_progress)
> +	    system_state == SYSTEM_BOOTING || system_state > SYSTEM_RUNNING ||
> +	    oops_in_progress)
>  		return;
> +
>  	if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
>  		return;
>  	prev_jiffy = jiffies;
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 18/18] sched: Enable smp_processor_id() checks early
  2017-05-14 18:27 ` [patch 18/18] sched: Enable smp_processor_id() " Thomas Gleixner
@ 2017-05-15 15:12   ` Steven Rostedt
  2017-05-15 15:36     ` Thomas Gleixner
  0 siblings, 1 reply; 61+ messages in thread
From: Steven Rostedt @ 2017-05-15 15:12 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland

On Sun, 14 May 2017 20:27:34 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:

> smp_processor_id() checks are enabled after the boot process is done. That
> hides bugs in the smp bringup and driver initialization code.
> 
> Enable it right before the first non-boot CPU is brought up.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  init/main.c            |    3 +++
>  lib/smp_processor_id.c |    2 +-
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  init/main.c            |    3 +++
>  lib/smp_processor_id.c |    2 +-
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 
> --- a/init/main.c
> +++ b/init/main.c
> @@ -1025,6 +1025,9 @@ static noinline void __init kernel_init_
>  	 */
>  	set_cpus_allowed_ptr(current, cpumask_of(raw_smp_processor_id()));
>  
> +	/* Enable smp_processor_id() checks */
> +	system_state = SYSTEM_BOOTING_SMP;
> +

Just a nit, but why set this here and not just before
smp_prepare_cpus()? Anyway...


Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve


>  	cad_pid = task_pid(current);
>  
>  	smp_prepare_cpus(setup_max_cpus);
> --- a/lib/smp_processor_id.c
> +++ b/lib/smp_processor_id.c
> @@ -28,7 +28,7 @@ notrace static unsigned int check_preemp
>  	/*
>  	 * It is valid to assume CPU-locality during early bootup:
>  	 */
> -	if (system_state != SYSTEM_RUNNING)
> +	if (system_state < SYSTEM_BOOTING_SMP)
>  		goto out;
>  
>  	/*
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 18/18] sched: Enable smp_processor_id() checks early
  2017-05-15 15:12   ` Steven Rostedt
@ 2017-05-15 15:36     ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-15 15:36 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland

On Mon, 15 May 2017, Steven Rostedt wrote:

> On Sun, 14 May 2017 20:27:34 +0200
> Thomas Gleixner <tglx@linutronix.de> wrote:
> 
> > smp_processor_id() checks are enabled after the boot process is done. That
> > hides bugs in the smp bringup and driver initialization code.
> > 
> > Enable it right before the first non-boot CPU is brought up.
> > 
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > ---
> >  init/main.c            |    3 +++
> >  lib/smp_processor_id.c |    2 +-
> >  2 files changed, 4 insertions(+), 1 deletion(-)
> > 
> > 
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > ---
> >  init/main.c            |    3 +++
> >  lib/smp_processor_id.c |    2 +-
> >  2 files changed, 4 insertions(+), 1 deletion(-)
> > 
> > --- a/init/main.c
> > +++ b/init/main.c
> > @@ -1025,6 +1025,9 @@ static noinline void __init kernel_init_
> >  	 */
> >  	set_cpus_allowed_ptr(current, cpumask_of(raw_smp_processor_id()));
> >  
> > +	/* Enable smp_processor_id() checks */
> > +	system_state = SYSTEM_BOOTING_SMP;
> > +
> 
> Just a nit, but why set this here and not just before
> smp_prepare_cpus()? Anyway...

Because smp_prepare_cpus() is full of "UP" assumptions. Thinking more about
it, we just can set the cpus allowed ptr right after creating it and just
have a single state which enables both checks. I'll have a look.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 17/18] sched: Enable might_sleep() checks early
  2017-05-15 15:10   ` Steven Rostedt
@ 2017-05-15 19:12     ` Thomas Gleixner
  2017-05-16  7:14       ` Peter Zijlstra
  0 siblings, 1 reply; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-15 19:12 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland

On Mon, 15 May 2017, Steven Rostedt wrote:

> On Sun, 14 May 2017 20:27:33 +0200
> Thomas Gleixner <tglx@linutronix.de> wrote:
> 
> > might_sleep() checks are enabled after the boot process is done. That hides
> > bugs in the smp bringup and driver initialization code.
> > 
> > Enable it right when the scheduler starts working, i.e. when init task and
> > kthreadd have been created and right before the idle task enables
> > preemption.
> 
> Looking at commit b433c3d4549ae749, it appears that on very slow
> machines, there is a possibility that the init task can start running.
> Should system_state be updated before that complete() is called?

That commit is magic voodoo with exactly no effect at all.

rest_init() is called with preemption disabled and nothing can schedule
there _before_ schedule_preempt_disabled().

Both threads - init task and kthreadd - are only created and woken up. They
cannot get on the CPU simply because preemption is disabled. And this was
the case back then in 2.6.35 as well.

It does not matter at all whether the machine is slow or not. That
completion is pointless.

Peter, can you explain what the heck this patch is actually doing?

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 17/18] sched: Enable might_sleep() checks early
  2017-05-15 19:12     ` Thomas Gleixner
@ 2017-05-16  7:14       ` Peter Zijlstra
  2017-05-16  7:33         ` Thomas Gleixner
  0 siblings, 1 reply; 61+ messages in thread
From: Peter Zijlstra @ 2017-05-16  7:14 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Steven Rostedt, LKML, Ingo Molnar, Mark Rutland

On Mon, May 15, 2017 at 09:12:03PM +0200, Thomas Gleixner wrote:
> On Mon, 15 May 2017, Steven Rostedt wrote:
> 
> > On Sun, 14 May 2017 20:27:33 +0200
> > Thomas Gleixner <tglx@linutronix.de> wrote:
> > 
> > > might_sleep() checks are enabled after the boot process is done. That hides
> > > bugs in the smp bringup and driver initialization code.
> > > 
> > > Enable it right when the scheduler starts working, i.e. when init task and
> > > kthreadd have been created and right before the idle task enables
> > > preemption.
> > 
> > Looking at commit b433c3d4549ae749, it appears that on very slow
> > machines, there is a possibility that the init task can start running.
> > Should system_state be updated before that complete() is called?
> 
> That commit is magic voodoo with exactly no effect at all.
> 
> rest_init() is called with preemption disabled and nothing can schedule
> there _before_ schedule_preempt_disabled().
> 
> Both threads - init task and kthreadd - are only created and woken up. They
> cannot get on the CPU simply because preemption is disabled. And this was
> the case back then in 2.6.35 as well.
> 
> It does not matter at all whether the machine is slow or not. That
> completion is pointless.
> 
> Peter, can you explain what the heck this patch is actually doing?

Argh.. what a shit Changelog, who wrote that crap!?

So the problem was with PREEMPT_VOLUNTARY (where, as you know,
preempt_disable() has no meaning).

Supposedly there's a might_sleep()/cond_resched() point somewhere around
there (every alloc in the fork path for example), which will happily
reschedule us.

So if we schedule to the kernel_init() task before we set kthreadd_task
we'll try and spawn kthreads and OOPS.

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 17/18] sched: Enable might_sleep() checks early
  2017-05-16  7:14       ` Peter Zijlstra
@ 2017-05-16  7:33         ` Thomas Gleixner
  2017-05-16 13:14           ` Steven Rostedt
  0 siblings, 1 reply; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-16  7:33 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: Steven Rostedt, LKML, Ingo Molnar, Mark Rutland

On Tue, 16 May 2017, Peter Zijlstra wrote:
> On Mon, May 15, 2017 at 09:12:03PM +0200, Thomas Gleixner wrote:
> > On Mon, 15 May 2017, Steven Rostedt wrote:
> > 
> > > On Sun, 14 May 2017 20:27:33 +0200
> > > Thomas Gleixner <tglx@linutronix.de> wrote:
> > > 
> > > > might_sleep() checks are enabled after the boot process is done. That hides
> > > > bugs in the smp bringup and driver initialization code.
> > > > 
> > > > Enable it right when the scheduler starts working, i.e. when init task and
> > > > kthreadd have been created and right before the idle task enables
> > > > preemption.
> > > 
> > > Looking at commit b433c3d4549ae749, it appears that on very slow
> > > machines, there is a possibility that the init task can start running.
> > > Should system_state be updated before that complete() is called?
> > 
> > That commit is magic voodoo with exactly no effect at all.
> > 
> > rest_init() is called with preemption disabled and nothing can schedule
> > there _before_ schedule_preempt_disabled().
> > 
> > Both threads - init task and kthreadd - are only created and woken up. They
> > cannot get on the CPU simply because preemption is disabled. And this was
> > the case back then in 2.6.35 as well.
> > 
> > It does not matter at all whether the machine is slow or not. That
> > completion is pointless.
> > 
> > Peter, can you explain what the heck this patch is actually doing?
> 
> Argh.. what a shit Changelog, who wrote that crap!?

Indeed.

> So the problem was with PREEMPT_VOLUNTARY (where, as you know,
> preempt_disable() has no meaning).
> 
> Supposedly there's a might_sleep()/cond_resched() point somewhere around
> there (every alloc in the fork path for example), which will happily
> reschedule us.

Darn, forgot about PREEMPT_VOLUNTARY and that excellent changelog does not
mention it either. 

> So if we schedule to the kernel_init() task before we set kthreadd_task
> we'll try and spawn kthreads and OOPS.

So back to Stevens question. No, we can't set the state earlier than right
before schedule() simply because with PREEMPT preemption _is_ actually
disabled and kernel_kthread() will trigger might_sleep() splats.

What a mess.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 17/18] sched: Enable might_sleep() checks early
  2017-05-16  7:33         ` Thomas Gleixner
@ 2017-05-16 13:14           ` Steven Rostedt
  0 siblings, 0 replies; 61+ messages in thread
From: Steven Rostedt @ 2017-05-16 13:14 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Peter Zijlstra, LKML, Ingo Molnar, Mark Rutland

On Tue, 16 May 2017 09:33:52 +0200 (CEST)
Thomas Gleixner <tglx@linutronix.de> wrote:


> Darn, forgot about PREEMPT_VOLUNTARY and that excellent changelog does not
> mention it either. 
> 
> > So if we schedule to the kernel_init() task before we set kthreadd_task
> > we'll try and spawn kthreads and OOPS.  
> 
> So back to Stevens question. No, we can't set the state earlier than right
> before schedule() simply because with PREEMPT preemption _is_ actually
> disabled and kernel_kthread() will trigger might_sleep() splats.

So a comment in the code mentioning PREEMPT_VOLUNTARY might be
advantageous.

> 
> What a mess.

Indeed.

-- Steve

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [patch 07/18] ACPI: Adjust system_state check
  2017-05-15 14:27   ` Steven Rostedt
@ 2017-05-16 18:13     ` Thomas Gleixner
  0 siblings, 0 replies; 61+ messages in thread
From: Thomas Gleixner @ 2017-05-16 18:13 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: LKML, Peter Zijlstra, Ingo Molnar, Mark Rutland, Catalin Marinas,
	Will Deacon, linux-acpi, Len Brown

On Mon, 15 May 2017, Steven Rostedt wrote:

> 
> [ added linux-acpi and took off arm list ;-) ]
> 
> On Sun, 14 May 2017 20:27:23 +0200
> Thomas Gleixner <tglx@linutronix.de> wrote:
> 
> > To enable smp_processor_id() and might_sleep() debug checks earlier, it's
> > required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.
> > 
> > Make the decision wether a pci root is hotplugged depend on SYSTEM_RUNNING
> > instead of !SYSTEM_BOOTING.
> > 
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > Cc: Will Deacon <will.deacon@arm.com>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: linux-arm-kernel@lists.infradead.org
> > ---
> >  drivers/acpi/pci_root.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > --- a/drivers/acpi/pci_root.c
> > +++ b/drivers/acpi/pci_root.c
> > @@ -523,7 +523,7 @@ static int acpi_pci_root_add(struct acpi
> >  	struct acpi_pci_root *root;
> >  	acpi_handle handle = device->handle;
> >  	int no_aspm = 0;
> > -	bool hotadd = system_state != SYSTEM_BOOTING;
> > +	bool hotadd = system_state == SYSTEM_RUNNING;
> 
> What about the other boot states greater than SYSTEM_RUNNING? Can this
> be called then too?
> 
> IOW, should it be:
> 
> 	bool hotadd = system_state >= SYSTEM_RUNNING;

Greater than RUNNING is HALT,POWEROFF,RESTART. Having a PCI hotplug event
there would be interesting :) I'll amend the changelog.

Thanks,

	tglx





^ permalink raw reply	[flat|nested] 61+ messages in thread

end of thread, other threads:[~2017-05-16 18:13 UTC | newest]

Thread overview: 61+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-14 18:27 [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Thomas Gleixner
2017-05-14 18:27 ` [patch 01/18] init: Pin init task to boot cpu initially Thomas Gleixner
2017-05-15 14:10   ` Steven Rostedt
2017-05-14 18:27 ` [patch 02/18] arm: Adjust system_state check Thomas Gleixner
2017-05-14 18:27   ` Thomas Gleixner
2017-05-14 18:27 ` [patch 03/18] arm64: " Thomas Gleixner
2017-05-14 18:27   ` Thomas Gleixner
2017-05-14 18:27 ` [patch 04/18] x86/smp: " Thomas Gleixner
2017-05-15 14:17   ` Steven Rostedt
2017-05-14 18:27 ` [patch 05/18] metag: " Thomas Gleixner
2017-05-14 18:27   ` Thomas Gleixner
2017-05-14 18:27 ` [patch 06/18] powerpc: " Thomas Gleixner
2017-05-14 18:27   ` Thomas Gleixner
2017-05-15  9:19   ` Michael Ellerman
2017-05-14 18:27 ` [patch 07/18] ACPI: " Thomas Gleixner
2017-05-14 18:27   ` Thomas Gleixner
2017-05-15 10:20   ` Mark Rutland
2017-05-15 10:20     ` Mark Rutland
2017-05-15 10:25     ` Thomas Gleixner
2017-05-15 10:25       ` Thomas Gleixner
2017-05-15 14:27   ` Steven Rostedt
2017-05-16 18:13     ` Thomas Gleixner
2017-05-14 18:27 ` [patch 08/18] mm: " Thomas Gleixner
2017-05-15  6:18   ` Greg Kroah-Hartman
2017-05-15 14:33     ` Steven Rostedt
2017-05-14 18:27 ` [patch 09/18] cpufreq/pasemi: " Thomas Gleixner
2017-05-14 18:27   ` Thomas Gleixner
2017-05-15  5:24   ` Viresh Kumar
2017-05-15 14:34     ` Steven Rostedt
2017-05-14 18:27 ` [patch 10/18] iommu/vt-d: Adjust system_state checks Thomas Gleixner
2017-05-14 18:27   ` Thomas Gleixner
2017-05-15 14:42   ` Joerg Roedel
2017-05-14 18:27 ` [patch 11/18] iommu/of: Adjust system_state check Thomas Gleixner
2017-05-14 18:27   ` Thomas Gleixner
2017-05-15 10:45   ` Robin Murphy
2017-05-15 10:45     ` Robin Murphy
2017-05-15 14:42   ` Joerg Roedel
2017-05-15 14:42     ` Joerg Roedel
2017-05-14 18:27 ` [patch 12/18] async: Adjust system_state checks Thomas Gleixner
2017-05-14 18:39   ` Arjan van de Ven
2017-05-14 18:27 ` [patch 13/18] extable: " Thomas Gleixner
2017-05-15 14:37   ` Steven Rostedt
2017-05-14 18:27 ` [patch 14/18] printk: " Thomas Gleixner
2017-05-15 14:53   ` Steven Rostedt
2017-05-14 18:27 ` [patch 15/18] mm/vmscan: " Thomas Gleixner
2017-05-14 18:27   ` Thomas Gleixner
2017-05-15 14:54   ` Steven Rostedt
2017-05-15 14:54     ` Steven Rostedt
2017-05-14 18:27 ` [patch 16/18] init: Introduce SYSTEM_BOOTING_UP/SMP states Thomas Gleixner
2017-05-15  9:58   ` Juergen Gross
2017-05-15 14:58   ` Steven Rostedt
2017-05-14 18:27 ` [patch 17/18] sched: Enable might_sleep() checks early Thomas Gleixner
2017-05-15 15:10   ` Steven Rostedt
2017-05-15 19:12     ` Thomas Gleixner
2017-05-16  7:14       ` Peter Zijlstra
2017-05-16  7:33         ` Thomas Gleixner
2017-05-16 13:14           ` Steven Rostedt
2017-05-14 18:27 ` [patch 18/18] sched: Enable smp_processor_id() " Thomas Gleixner
2017-05-15 15:12   ` Steven Rostedt
2017-05-15 15:36     ` Thomas Gleixner
2017-05-15 11:53 ` [patch 00/18] init: Enable might_sleep() and smp_processor_id() debugging early Mark Rutland

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.