init: Enable might_sleep() and smp_processor_id() debugging early
Subsystems (16)
v2 cover init: Enable might_sleep() and smp_processor_id() debugging early
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 SMP bootup and builtin driver initialization are not covered by these checks at all.
The patch series addresses this by adding an intermediate state which enables both debug features right when scheduling starts, i.e. the boot CPU idle task schedules the first time.
Changes since V1:
- Use only one new state
- Enable both debug facilities right before scheduling starts
- Add more commentry about state ordering and placement of the state switch
- CC ACPI folks on the relevant patch and amend changelog.
- Collected acks/reviewed-by's
Thanks,
tglx
PATCH v2 1/17 init: Pin init task to boot cpu initially
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.
--- init/main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
init/main.c +12 -5
@@ -389,6 +389,7 @@ static __initdata DECLARE_COMPLETION(kth static noinline void __ref rest_init(void) { +struct task_struct *tsk;int pid;rcu_scheduler_starting ();
@@ -397,7 +398,17 @@ static noinline void __ref rest_init(voi* the init task will end up wanting to create kthreads, which, if * we schedule it before we create kthreadd, will OOPS. */ -kernel_thread (kernel_init,NULL ,CLONE_FS ); + pid =kernel_thread (kernel_init,NULL ,CLONE_FS ); +/* +* 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. +*/ +rcu_read_lock (); + tsk =find_task_by_pid_ns (pid, &init_pid_ns); +set_cpus_allowed_ptr (tsk,cpumask_of (smp_processor_id ())); +rcu_read_unlock (); +numa_default_policy (); pid =kernel_thread (kthreadd,NULL ,CLONE_FS |CLONE_FILES );rcu_read_lock ();
@@ -1015,10 +1026,6 @@ 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. -*/ -set_cpus_allowed_ptr (current, cpu_all_mask); cad_pid =task_pid (current);
Steven Rostedt
reviewerRe: [patch V2 01/17] init: Pin init task to boot cpu initially
Quoted 34 lines · On Tue, 16 May 2017 20:42:32 +0200 Thomas Gleixner <[email protected]> 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 usesmp_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 <[email protected]>--- init/main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)init/main.c +1
-0@@ -389,6 +389,7 @@ static __initdata DECLARE_COMPLETION(kth static noinline void __ref rest_init(void) { +struct task_struct *tsk;int pid;rcu_scheduler_starting ();@@ -397,7 +398,17 @@ static noinline void __ref rest_init(voi* the init task will end up wanting to create kthreads, which, if * we schedule it before we create kthreadd, will OOPS.
init/main.c static noinline void __ref rest_init(voi · line 408
Quoted 10 lines
init/main.c +8
-1*/ -kernel_thread (kernel_init,NULL ,CLONE_FS ); + pid =kernel_thread (kernel_init,NULL ,CLONE_FS ); +/* +* 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. +*/ +rcu_read_lock (); + tsk =find_task_by_pid_ns (pid, &init_pid_ns);
Should we have a:
BUG_ON(!tsk);
Just to be paranoid?
-- Steve
Quoted 18 lines
init/main.c +3
-4+set_cpus_allowed_ptr (tsk,cpumask_of (smp_processor_id ())); +rcu_read_unlock (); +numa_default_policy (); pid =kernel_thread (kthreadd,NULL ,CLONE_FS |CLONE_FILES );rcu_read_lock ();@@ -1015,10 +1026,6 @@ 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. -*/ -set_cpus_allowed_ptr (current, cpu_all_mask); cad_pid =task_pid (current);
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] init: Pin init task to the boot CPU, initially
In reply to Thomas Gleixnerinit: Pin init task to the boot CPU, initially
Commit-ID: 8fb12156b8db61af3d49f3e5e104568494581d1f Gitweb: http://git.kernel.org/tip/8fb12156b8db61af3d49f3e5e104568494581d1f Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:32 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:34 +0200
init: Pin init task to the boot CPU, initially
Some of the boot code in init_kernel_freeable() which runs before SMP bringup assumes (rightfully) that it runs on the boot CPU and therefore 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.
--- init/main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
init/main.c +12 -5
@@ -389,6 +389,7 @@ static __initdata DECLARE_COMPLETION(kthreadd_done); static noinline void __ref rest_init(void) { +struct task_struct *tsk;int pid;rcu_scheduler_starting ();
@@ -397,7 +398,17 @@ static noinline void __ref rest_init(void)* the init task will end up wanting to create kthreads, which, if * we schedule it before we create kthreadd, will OOPS. */ -kernel_thread (kernel_init,NULL ,CLONE_FS ); + pid =kernel_thread (kernel_init,NULL ,CLONE_FS ); +/* +* 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. +*/ +rcu_read_lock (); + tsk =find_task_by_pid_ns (pid, &init_pid_ns); +set_cpus_allowed_ptr (tsk,cpumask_of (smp_processor_id ())); +rcu_read_unlock (); +numa_default_policy (); pid =kernel_thread (kthreadd,NULL ,CLONE_FS |CLONE_FILES );rcu_read_lock ();
@@ -1015,10 +1026,6 @@ static noinline void __init kernel_init_freeable(void)* init can allocate pages on any node */ set_mems_allowed (node_states[N_MEMORY ]); -/* -* init can run on any cpu. -*/ -set_cpus_allowed_ptr (current, cpu_all_mask); cad_pid =task_pid (current);
PATCH v2 2/17 arm: Adjust system_state check
In reply to Thomas GleixnerTo 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.
--- arch/arm/kernel/smp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/kernel/smp.c +1 -2
@@ -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 ();
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] arm: Adjust system_state check
arm: Adjust system_state check
Commit-ID: 5976a66913a8bf42465d96776fd37fb5631edc19 Gitweb: http://git.kernel.org/tip/5976a66913a8bf42465d96776fd37fb5631edc19 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:33 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:35 +0200
arm: Adjust system_state check
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.
--- arch/arm/kernel/smp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/kernel/smp.c +1 -2
@@ -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 ();
PATCH v2 3/17 arm64: Adjust system_state check
In reply to Thomas GleixnerTo 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.
--- arch/arm64/kernel/smp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm64/kernel/smp.c +1 -2
@@ -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 ); }
Re: [patch V2 03/17] arm64: Adjust system_state check
Quoted 5 lines · Thomas Gleixner
To enable
smp_processor_id()andmight_sleep()debug checks earlier, it's required to add system states betweenSYSTEM_BOOTINGandSYSTEM_RUNNING.Adjust the
system_statecheck insmp_send_stop()to handle the extra states.
Quoted 8 lines
Signed-off-by Thomas Gleixner <[email protected]>Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Mark Rutland <[email protected]>Cc linux-arm-kernel at lists.infradead.org--- arch/arm64/kernel/smp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
FWIW:
Mark.
Quoted 15 lines
arch/arm64/kernel/smp.c +1
-2@@ -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 ); }
Re: [patch V2 03/17] arm64: Adjust system_state check
In reply to Thomas GleixnerQuoted 10 lines · Thomas Gleixner
To enable
smp_processor_id()andmight_sleep()debug checks earlier, it's required to add system states betweenSYSTEM_BOOTINGandSYSTEM_RUNNING.Adjust the
system_statecheck insmp_send_stop()to handle the extra states.Signed-off-by Thomas Gleixner <[email protected]>Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Mark Rutland <[email protected]>Cc linux-arm-kernel at lists.infradead.org
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] arm64: Adjust system_state check
In reply to Thomas Gleixnerarm64: Adjust system_state check
Commit-ID: ef284f5ca5f102bf855e599305c0c16d6e844635 Gitweb: http://git.kernel.org/tip/ef284f5ca5f102bf855e599305c0c16d6e844635 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:34 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:35 +0200
arm64: Adjust system_state check
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.
--- arch/arm64/kernel/smp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm64/kernel/smp.c +1 -2
@@ -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 ); }
PATCH v2 4/17 x86/smp: Adjust system_state check
In reply to Thomas GleixnerTo 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.
--- arch/x86/kernel/smpboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/smpboot.c +1 -1
@@ -863,7 +863,7 @@ static void announce_cpu(int cpu, int apif (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" );
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] x86/smp: Adjust system_state check
x86/smp: Adjust system_state check
Commit-ID: 719b3680d1f789c1e3054e3fcb26bfff07c3c623 Gitweb: http://git.kernel.org/tip/719b3680d1f789c1e3054e3fcb26bfff07c3c623 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:35 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:35 +0200
x86/smp: Adjust system_state check
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.
--- arch/x86/kernel/smpboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/smpboot.c +1 -1
@@ -863,7 +863,7 @@ static void announce_cpu(int cpu, int apicid)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" );
PATCH v2 5/17 metag: Adjust system_state check
In reply to Thomas GleixnerTo 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.
--- arch/metag/kernel/smp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/metag/kernel/smp.c +1 -2
@@ -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 ();
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] metag: Adjust system_state check
metag: Adjust system_state check
Commit-ID: dcd2e4734b428709984e2fa35ebbd6cccc246d47 Gitweb: http://git.kernel.org/tip/dcd2e4734b428709984e2fa35ebbd6cccc246d47 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:36 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:35 +0200
metag: Adjust system_state check
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.
--- arch/metag/kernel/smp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/metag/kernel/smp.c +1 -2
@@ -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 ();
PATCH v2 6/17 powerpc: Adjust system_state check
In reply to Thomas GleixnerTo 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.
--- arch/powerpc/kernel/smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/smp.c +1 -1
@@ -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
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] powerpc: Adjust system_state check
powerpc: Adjust system_state check
Commit-ID: a8fcfc1917681ba1ccc23a429543a67aad8bfd00 Gitweb: http://git.kernel.org/tip/a8fcfc1917681ba1ccc23a429543a67aad8bfd00 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:37 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:35 +0200
powerpc: Adjust system_state check
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.
--- arch/powerpc/kernel/smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/smp.c +1 -1
@@ -97,7 +97,7 @@ int smp_generic_cpu_bootable(unsigned int nr)/* 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
PATCH v2 7/17 ACPI: Adjust system_state check
In reply to Thomas GleixnerTo 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 whether a pci root is hotplugged depend on SYSTEM_RUNNING instead of !SYSTEM_BOOTING. It makes no sense to cover states greater than SYSTEM_RUNNING as there are not hotplug events on reboot and poweroff.
--- drivers/acpi/pci_root.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/pci_root.c +1 -1
@@ -523,7 +523,7 @@ static int acpi_pci_root_add(struct acpistruct 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)
Re: [patch V2 07/17] ACPI: Adjust system_state check
Quoted 8 lines · On Tue, 16 May 2017 20:42:38 +0200 Thomas Gleixner <[email protected]> wrote:
To enable
smp_processor_id()andmight_sleep()debug checks earlier, it's required to add system states betweenSYSTEM_BOOTINGandSYSTEM_RUNNING.Make the decision whether a pci root is hotplugged depend on
SYSTEM_RUNNINGinstead of !SYSTEM_BOOTING. It makes no sense to cover states greater thanSYSTEM_RUNNINGas there are not hotplug events on reboot and poweroff.Signed-off-by Thomas Gleixner <[email protected]>
-- Steve
Quoted 19 lines
--- drivers/acpi/pci_root.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/acpi/pci_root.c +1
-1@@ -523,7 +523,7 @@ static int acpi_pci_root_add(struct acpistruct 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)
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] ACPI: Adjust system_state check
In reply to Thomas GleixnerACPI: Adjust system_state check
Commit-ID: 9762b33dc31c67e34b36ba4e787e64084b3136ff Gitweb: http://git.kernel.org/tip/9762b33dc31c67e34b36ba4e787e64084b3136ff Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:38 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:36 +0200
ACPI: Adjust system_state check
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 whether a pci root is hotplugged depend on SYSTEM_RUNNING instead of !SYSTEM_BOOTING. It makes no sense to cover states greater than SYSTEM_RUNNING as there are not hotplug events on reboot and poweroff.
--- drivers/acpi/pci_root.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/pci_root.c +1 -1
@@ -523,7 +523,7 @@ static int acpi_pci_root_add(struct acpi_device *device,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)
PATCH v2 8/17 mm: Adjust system_state check
In reply to Thomas GleixnerTo 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.
--- drivers/base/node.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/node.c +1 -1
@@ -377,7 +377,7 @@ static int __ref get_nid_for_pfn(unsigneif (!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);
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] mm: Adjust system_state check
mm: Adjust system_state check
Commit-ID: 8cdde385c7a33afbe13fd71351da0968540fa566 Gitweb: http://git.kernel.org/tip/8cdde385c7a33afbe13fd71351da0968540fa566 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:39 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:36 +0200
mm: Adjust system_state check
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.
--- drivers/base/node.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/node.c +1 -1
@@ -377,7 +377,7 @@ static int __ref get_nid_for_pfn(unsigned long pfn)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);
PATCH v2 9/17 cpufreq/pasemi: Adjust system_state check
In reply to Thomas GleixnerTo 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.
--- drivers/cpufreq/pasemi-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/pasemi-cpufreq.c +1 -1
@@ -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)
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] cpufreq/pasemi: Adjust system_state check
cpufreq/pasemi: Adjust system_state check
Commit-ID: d04e31a23c3c828456cb5613f391ce4ac4e5765f Gitweb: http://git.kernel.org/tip/d04e31a23c3c828456cb5613f391ce4ac4e5765f Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:40 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:36 +0200
cpufreq/pasemi: Adjust system_state check
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.
--- drivers/cpufreq/pasemi-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/pasemi-cpufreq.c +1 -1
@@ -226,7 +226,7 @@ static int pas_cpufreq_cpu_exit(struct cpufreq_policy *policy)* 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)
PATCH v2 10/17 iommu/vt-d: Adjust system_state checks
In reply to Thomas GleixnerTo 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.
--- drivers/iommu/intel-iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/intel-iommu.c +2 -2
@@ -4312,7 +4312,7 @@ int dmar_parse_one_atsr(struct acpi_dmarstruct 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 dstruct 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) {
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] iommu/vt-d: Adjust system_state checks
iommu/vt-d: Adjust system_state checks
Commit-ID: b608fe356fe8328665445a26ec75dfac918c8c5d Gitweb: http://git.kernel.org/tip/b608fe356fe8328665445a26ec75dfac918c8c5d Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:41 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:36 +0200
iommu/vt-d: Adjust system_state checks
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.
--- drivers/iommu/intel-iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/intel-iommu.c +2 -2
@@ -4315,7 +4315,7 @@ int dmar_parse_one_atsr(struct acpi_dmar_header *hdr, void *arg)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);
@@ -4565,7 +4565,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info)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) {
PATCH v2 11/17 iommu/of: Adjust system_state check
In reply to Thomas GleixnerTo 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.
--- drivers/iommu/of_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/of_iommu.c +1 -1
@@ -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);
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] iommu/of: Adjust system_state check
iommu/of: Adjust system_state check
Commit-ID: b903dfb277c09e53d499480e9670557dcce36fbd Gitweb: http://git.kernel.org/tip/b903dfb277c09e53d499480e9670557dcce36fbd Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:42 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:37 +0200
iommu/of: Adjust system_state check
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.
--- drivers/iommu/of_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/of_iommu.c +1 -1
@@ -103,7 +103,7 @@ static bool of_iommu_driver_present(struct device_node *np)* 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);
PATCH v2 12/17 async: Adjust system_state checks
In reply to Thomas GleixnerTo 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.
--- kernel/async.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/async.c +4 -4
@@ -114,14 +114,14 @@ static void async_run_entry_fn(struct woktime_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);
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] async: Adjust system_state checks
async: Adjust system_state checks
Commit-ID: b4def42724594cd399cfee365221f5b38639711d Gitweb: http://git.kernel.org/tip/b4def42724594cd399cfee365221f5b38639711d Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:43 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:37 +0200
async: Adjust system_state checks
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.
--- kernel/async.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/async.c +4 -4
@@ -114,14 +114,14 @@ static void async_run_entry_fn(struct work_struct *work)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(async_cookie_t cookie, struct async_domain {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);
PATCH v2 13/17 extable: Adjust system_state checks
In reply to Thomas GleixnerTo 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.
--- kernel/extable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/extable.c +1 -1
@@ -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 ;
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] extable: Adjust system_state checks
extable: Adjust system_state checks
Commit-ID: 0594729c24d846889408a07057b5cc9e8d931419 Gitweb: http://git.kernel.org/tip/0594729c24d846889408a07057b5cc9e8d931419 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:44 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:37 +0200
extable: Adjust system_state checks
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.
--- kernel/extable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/extable.c +1 -1
@@ -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 ;
PATCH v2 14/17 printk: Adjust system_state checks
In reply to Thomas GleixnerTo 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.
--- kernel/printk/printk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/printk/printk.c +1 -1
@@ -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 ; }
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] printk: Adjust system_state checks
printk: Adjust system_state checks
Commit-ID: ff48cd26fc4889b9deb5f9333d3c61746e450b7f Gitweb: http://git.kernel.org/tip/ff48cd26fc4889b9deb5f9333d3c61746e450b7f Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:45 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:37 +0200
printk: Adjust system_state checks
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.
--- kernel/printk/printk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/printk/printk.c +1 -1
@@ -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 ; }
PATCH v2 15/17 mm/vmscan: Adjust system_state checks
In reply to Thomas GleixnerTo 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.
--- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmscan.c +1 -1
@@ -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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch V2 15/17] mm/vmscan: Adjust system_state checks
Quoted 5 lines · Thomas Gleixner
To enable
smp_processor_id()andmight_sleep()debug checks earlier, it's required to add system states betweenSYSTEM_BOOTINGandSYSTEM_RUNNING.Adjust the
system_statecheck inkswapd_run()to handle the extra states.
Quoted 8 lines
Signed-off-by Thomas Gleixner <[email protected]>Reviewed-by Steven Rostedt (VMware) <[email protected]>Cc Andrew Morton <[email protected]>Cc Johannes Weiner <[email protected]>Cc Mel Gorman <[email protected]>Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>
Quoted 9 lines
--- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmscan.c int kswapd_run(int nid) · line 3649
Quoted 8 lines
mm/vmscan.c +1
-1@@ -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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] mm/vmscan: Adjust system_state checks
In reply to Thomas Gleixnermm/vmscan: Adjust system_state checks
Commit-ID: c6202adf3a0969514299cf10ff07376a84ad09bb Gitweb: http://git.kernel.org/tip/c6202adf3a0969514299cf10ff07376a84ad09bb Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:46 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:37 +0200
mm/vmscan: Adjust system_state checks
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.
--- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmscan.c +1 -1
@@ -3652,7 +3652,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 ;
PATCH v2 16/17 init: Introduce SYSTEM_SCHEDULING state
In reply to Thomas Gleixnermight_sleep() debugging and smp_processor_id() debugging should be active right after the scheduler starts working. The init task can invoke smp_processor_id() from preemptible context as it is pinned on the boot cpu until sched_smp_init() removes the pinning and lets it schedule on all non isolated cpus.
Add a new state which allows to enable those checks earlier and add it to the xen do_poweroff() function.
No functional change.
---
V2: Use only one intermediate state and document that state order matters.
drivers/xen/manage.c | 1 + include/linux/kernel.h | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/xen/manage.c +1 -0
@@ -190,6 +190,7 @@ static void do_poweroff(void) {switch (system_state) {case SYSTEM_BOOTING : +case SYSTEM_SCHEDULING :orderly_poweroff (true);break ;case SYSTEM_RUNNING :
include/linux/kernel.h +5 -1
@@ -490,9 +490,13 @@ extern int root_mountflags;extern bool early_boot_irqs_disabled; -/* Values used for system_state */ +/* +* Values used for system_state. Ordering of the states must not be changed +* as code checks for <, <=, >, >= STATE. +*/ extern enum system_states { SYSTEM_BOOTING, + SYSTEM_SCHEDULING, SYSTEM_RUNNING, SYSTEM_HALT, SYSTEM_POWER_OFF,
Re: [patch V2 16/17] init: Introduce SYSTEM_SCHEDULING state
Quoted 9 lines · Thomas Gleixner
might_sleep()debugging andsmp_processor_id()debugging should be active right after the scheduler starts working. The init task can invokesmp_processor_id()from preemptible context as it is pinned on the boot cpu untilsched_smp_init()removes the pinning and lets it schedule on all non isolated cpus.Add a new state which allows to enable those checks earlier and add it to the xen
do_poweroff()function.
Quoted 6 lines
No functional change.
Signed-off-by Thomas Gleixner <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc Juergen Gross <[email protected]>Cc Greg Kroah-Hartman <[email protected]>
Makes sense to me. FWIW:
Mark.
Quoted 37 lines
---
V2: Use only one intermediate state and document that state order matters.
drivers/xen/manage.c | 1 + include/linux/kernel.h | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-)drivers/xen/manage.c +1
-0@@ -190,6 +190,7 @@ static void do_poweroff(void) {switch (system_state) {case SYSTEM_BOOTING : +case SYSTEM_SCHEDULING :orderly_poweroff (true);break ;case SYSTEM_RUNNING :include/linux/kernel.h +5
-1@@ -490,9 +490,13 @@ extern int root_mountflags;extern bool early_boot_irqs_disabled; -/* Values used for system_state */ +/* +* Values used for system_state. Ordering of the states must not be changed +* as code checks for <, <=, >, >= STATE. +*/ extern enum system_states { SYSTEM_BOOTING, + SYSTEM_SCHEDULING, SYSTEM_RUNNING, SYSTEM_HALT, SYSTEM_POWER_OFF,
Re: [patch V2 16/17] init: Introduce SYSTEM_SCHEDULING state
In reply to Thomas GleixnerQuoted 9 lines · Thomas Gleixner
might_sleep()debugging andsmp_processor_id()debugging should be active right after the scheduler starts working. The init task can invokesmp_processor_id()from preemptible context as it is pinned on the boot cpu untilsched_smp_init()removes the pinning and lets it schedule on all non isolated cpus.Add a new state which allows to enable those checks earlier and add it to the xen
do_poweroff()function.
Quoted 6 lines
No functional change.
Signed-off-by Thomas Gleixner <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc Juergen Gross <[email protected]>Cc Greg Kroah-Hartman <[email protected]>
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] init: Introduce SYSTEM_SCHEDULING state
In reply to Thomas Gleixnerinit: Introduce SYSTEM_SCHEDULING state
Commit-ID: 69a78ff226fe0241ab6cb9dd961667be477e3cf7 Gitweb: http://git.kernel.org/tip/69a78ff226fe0241ab6cb9dd961667be477e3cf7 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:47 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:38 +0200
init: Introduce SYSTEM_SCHEDULING state
might_sleep() debugging and smp_processor_id() debugging should be active right after the scheduler starts working. The init task can invoke smp_processor_id() from preemptible context as it is pinned on the boot cpu until sched_smp_init() removes the pinning and lets it schedule on all non isolated cpus.
Add a new state which allows to enable those checks earlier and add it to the xen do_poweroff() function.
No functional change.
--- drivers/xen/manage.c | 1 + include/linux/kernel.h | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/xen/manage.c +1 -0
@@ -190,6 +190,7 @@ static void do_poweroff(void) {switch (system_state) {case SYSTEM_BOOTING : +case SYSTEM_SCHEDULING :orderly_poweroff (true);break ;case SYSTEM_RUNNING :
include/linux/kernel.h +5 -1
@@ -490,9 +490,13 @@ extern int root_mountflags;extern bool early_boot_irqs_disabled; -/* Values used for system_state */ +/* +* Values used for system_state. Ordering of the states must not be changed +* as code checks for <, <=, >, >= STATE. +*/ extern enum system_states { SYSTEM_BOOTING, + SYSTEM_SCHEDULING, SYSTEM_RUNNING, SYSTEM_HALT, SYSTEM_POWER_OFF,
PATCH v2 17/17 sched: Enable might_sleep() and smp_processor_id() checks early
In reply to Thomas Gleixnermight_sleep() and 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 when the scheduler starts working, i.e. when init task and kthreadd have been created and right before the idle task enables preemption.
--- init/main.c | 10 ++++++++++ kernel/sched/core.c | 4 +++- lib/smp_processor_id.c | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-)
init/main.c +10 -0
@@ -414,6 +414,16 @@ static noinline void __ref rest_init(voircu_read_lock (); kthreadd_task =find_task_by_pid_ns (pid, &init_pid_ns);rcu_read_unlock (); + +/* +* Enable might_sleep() and smp_processor_id() checks. +* They cannot be enabled earlier because with CONFIG_PRREMPT=y +* kernel_thread() would trigger might_sleep() splats. With +* CONFIG_PREEMPT_VOLUNTARY=y the init task might have scheduled +* already, but it's stuck on the kthreadd_done completion. +*/ + system_state =SYSTEM_SCHEDULING ; +complete (&kthreadd_done);/*
kernel/sched/core.c +3 -1
@@ -6226,8 +6226,10 @@ void ___might_sleep(const char *file, inif ((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;
lib/smp_processor_id.c +1 -1
@@ -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_SCHEDULING ) goto out;/*
Steven Rostedt
reviewerRe: [patch V2 17/17] sched: Enable might_sleep() and smp_processor_id() checks early
Quoted 18 lines · On Tue, 16 May 2017 20:42:48 +0200 Thomas Gleixner <[email protected]> wrote:
might_sleep()andsmp_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 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 <[email protected]>--- init/main.c | 10 ++++++++++ kernel/sched/core.c | 4 +++- lib/smp_processor_id.c | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-)
init/main.c static noinline void __ref rest_init(voi · line 420
Quoted 7 lines
init/main.c +4
-0@@ -414,6 +414,16 @@ static noinline void __ref rest_init(voircu_read_lock (); kthreadd_task =find_task_by_pid_ns (pid, &init_pid_ns);rcu_read_unlock (); + +/* +* Enable might_sleep() and smp_processor_id() checks. +* They cannot be enabled earlier because with CONFIG_PRREMPT=y
My cat's version of CONFIG_PREEMPT, it's CONFIG_ PRR EMPT!
Quoted 26 lines
init/main.c +6
-0+* kernel_thread() would trigger might_sleep() splats. With +* CONFIG_PREEMPT_VOLUNTARY=y the init task might have scheduled +* already, but it's stuck on the kthreadd_done completion. +*/ + system_state =SYSTEM_SCHEDULING ; +complete (&kthreadd_done);/* kernel/sched/core.c +3
-1@@ -6226,8 +6226,10 @@ void ___might_sleep(const char *file, inif ((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;
lib/smp_processor_id.c notrace static unsigned int check_preemp · line 31
Quoted 5 lines
lib/smp_processor_id.c +1
-1@@ -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_SCHEDULING )
Do we want to ignore halting or rebooting too?
-- Steve
Quoted 4 lines
lib/smp_processor_id.c +0
-0goto out;/*
Re: [patch V2 17/17] sched: Enable might_sleep() and smp_processor_id() checks early
Quoted 8 lines · Steven Rostedt
init/main.c static noinline void __ref rest_init(voi · line 420
Quoted 4 lines · On Tue, 16 May 2017 20:42:48 +0200 Thomas Gleixner <[email protected]> wrote:
init/main.c +4
-0+ +/* +* Enable might_sleep() and smp_processor_id() checks. +* They cannot be enabled earlier because with CONFIG_PRREMPT=y My cat's version of
CONFIG_PREEMPT, it'sCONFIG_PRR EMPT!
I don't have a cat and I don't need one for creating typos. I'm perfectly able to do that myself :)
Quoted 25 lines
Quoted 25 lines
init/main.c +6
-0+* kernel_thread() would trigger might_sleep() splats. With +* CONFIG_PREEMPT_VOLUNTARY=y the init task might have scheduled +* already, but it's stuck on the kthreadd_done completion. +*/ + system_state =SYSTEM_SCHEDULING ; +complete (&kthreadd_done);/* kernel/sched/core.c +3
-1@@ -6226,8 +6226,10 @@ void ___might_sleep(const char *file, inif ((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;lib/smp_processor_id.c +0
-0
Quoted 8 lines
lib/smp_processor_id.c notrace static unsigned int check_preemp · line 31
Quoted 6 lines
lib/smp_processor_id.c +1
-1@@ -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_SCHEDULING )Do we want to ignore halting or rebooting too?
I don't think so. After setting those states, interesting stuff like device_shutdown() gets invoked. We want the coverage there.
Thanks,
tglx
Steven Rostedt
reviewerRe: [patch V2 17/17] sched: Enable might_sleep() and smp_processor_id() checks early
Quoted 11 lines · On Wed, 17 May 2017 00:46:37 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 10 lines
lib/smp_processor_id.c notrace static unsigned int check_preemp · line 31
Quoted 8 lines
lib/smp_processor_id.c +1
-1@@ -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_SCHEDULING )Do we want to ignore halting or rebooting too?
Quoted 2 lines
I don't think so. After setting those states, interesting stuff like
device_shutdown()gets invoked. We want the coverage there.
Then I'd suggest that you update the change log, as this patch also adds coverage to those states as well.
-- Steve
Re: [patch V2 17/17] sched: Enable might_sleep() and smp_processor_id() checks early
In reply to Thomas GleixnerQuoted 9 lines · Thomas Gleixner
might_sleep()andsmp_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 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 <[email protected]>
Modulo Steve's comments, FWIW:
Mark.
Quoted 52 lines
--- init/main.c | 10 ++++++++++ kernel/sched/core.c | 4 +++- lib/smp_processor_id.c | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-)init/main.c +10
-0@@ -414,6 +414,16 @@ static noinline void __ref rest_init(voircu_read_lock (); kthreadd_task =find_task_by_pid_ns (pid, &init_pid_ns);rcu_read_unlock (); + +/* +* Enable might_sleep() and smp_processor_id() checks. +* They cannot be enabled earlier because with CONFIG_PRREMPT=y +* kernel_thread() would trigger might_sleep() splats. With +* CONFIG_PREEMPT_VOLUNTARY=y the init task might have scheduled +* already, but it's stuck on the kthreadd_done completion. +*/ + system_state =SYSTEM_SCHEDULING ; +complete (&kthreadd_done);/* kernel/sched/core.c +3
-1@@ -6226,8 +6226,10 @@ void ___might_sleep(const char *file, inif ((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;lib/smp_processor_id.c +1
-1@@ -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_SCHEDULING ) goto out;/*
tip-bot for Thomas Gleixner
merge bot[tip:sched/core] sched/core: Enable might_sleep() and smp_processor_id() checks early
In reply to Thomas Gleixnersched/core: Enable might_sleep() and smp_processor_id() checks early
Commit-ID: 1c3c5eab171590f86edd8d31389d61dd1efe3037 Gitweb: http://git.kernel.org/tip/1c3c5eab171590f86edd8d31389d61dd1efe3037 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 16 May 2017 20:42:48 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:38 +0200
sched/core: Enable might_sleep() and smp_processor_id() checks early
might_sleep() and 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 when the scheduler starts working, i.e. when init task and kthreadd have been created and right before the idle task enables preemption.
--- init/main.c | 10 ++++++++++ kernel/sched/core.c | 4 +++- lib/smp_processor_id.c | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-)
init/main.c +10 -0
@@ -414,6 +414,16 @@ static noinline void __ref rest_init(void)rcu_read_lock (); kthreadd_task =find_task_by_pid_ns (pid, &init_pid_ns);rcu_read_unlock (); + +/* +* Enable might_sleep() and smp_processor_id() checks. +* They cannot be enabled earlier because with CONFIG_PRREMPT=y +* kernel_thread() would trigger might_sleep() splats. With +* CONFIG_PREEMPT_VOLUNTARY=y the init task might have scheduled +* already, but it's stuck on the kthreadd_done completion. +*/ + system_state =SYSTEM_SCHEDULING ; +complete (&kthreadd_done);/*
kernel/sched/core.c +3 -1
@@ -6238,8 +6238,10 @@ void ___might_sleep(const char *file, int line, int preempt_offset)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;
lib/smp_processor_id.c +1 -1
@@ -28,7 +28,7 @@ notrace static unsigned int check_preemption_disabled(const char *what1,/* * It is valid to assume CPU-locality during early bootup: */ -if (system_state !=SYSTEM_RUNNING ) +if (system_state <SYSTEM_SCHEDULING ) goto out;/*
Mark Rutland
reviewerHi,
Quoted 7 lines · Thomas Gleixner
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.
Quoted 6 lines
That means that SMP bootup and builtin driver initialization are not covered by these checks at all.
The patch series addresses this by adding an intermediate state which enables both debug features right when scheduling starts, i.e. the boot CPU idle task schedules the first time.
Thanks again for attacking this.
I gave this a spin atop of v4.12-rc1 on an ARM Juno platform. It picks up the mutex issue, and I see no other new warnings. With a fix [1] for the mutex issue appplied, I see no warnings.
Feel free to add my Tested-by for the arm64 and common bits.
Thanks,
Mark.
[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2017-May/506558.html