All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] kernel/isolation: Assert that a housekeeping CPU comes up at boot time
@ 2019-06-25  0:17 Nicholas Piggin
  2019-06-25  1:11 ` Frederic Weisbecker
  2019-06-25  9:27 ` Qais Yousef
  0 siblings, 2 replies; 3+ messages in thread
From: Nicholas Piggin @ 2019-06-25  0:17 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Nicholas Piggin, linux-kernel, Frederic Weisbecker, Ingo Molnar,
	Qais Yousef

With the change to allow the boot CPU0 to be isolated, it is possible
to specify command line options that result in no housekeeping CPU
online at boot.

An 8 CPU system booted with "nohz_full=0-6 maxcpus=4", for example.

It is not easily possible at housekeeping init time to know all the
various SMP options that will result in an invalid configuration, so
this patch adds a sanity check after SMP init, to ensure that a
housekeeping CPU has been onlined.

The panic is undesirable, but it's better than the alternative of an
obscure non deterministic failure. The panic will reliably happen
when advanced parameters are used incorrectly.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
v2: Fix a NULL pointer dereference when not overriding housekeeping,
    noticed by kernel test robot and Qais, who fixed it and verified
    the fix (thanks!)

 kernel/sched/isolation.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
index 123ea07a3f3b..a9ca8628c1a2 100644
--- a/kernel/sched/isolation.c
+++ b/kernel/sched/isolation.c
@@ -63,6 +63,32 @@ void __init housekeeping_init(void)
 	WARN_ON_ONCE(cpumask_empty(housekeeping_mask));
 }
 
+static int __init housekeeping_verify_smp(void)
+{
+	int cpu;
+
+	if (!housekeeping_flags)
+		return 0;
+
+	/*
+	 * Early housekeeping setup is done before CPUs come up, and there are
+	 * a range of options scattered around that can restrict which CPUs
+	 * come up. It is possible to pass in a combination of housekeeping
+	 * and SMP arguments that result in housekeeping assigned to an
+	 * offline CPU.
+	 *
+	 * Check that condition here after SMP comes up, and give a useful
+	 * error message rather than an obscure non deterministic crash or
+	 * hang later.
+	 */
+	for_each_online_cpu(cpu) {
+		if (cpumask_test_cpu(cpu, housekeeping_mask))
+			return 0;
+	}
+	panic("Housekeeping: nohz_full= or isolcpus= resulted in no online CPUs for housekeeping.\n");
+}
+core_initcall(housekeeping_verify_smp);
+
 static int __init housekeeping_setup(char *str, enum hk_flags flags)
 {
 	cpumask_var_t non_housekeeping_mask;
-- 
2.20.1


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

* Re: [PATCH v2] kernel/isolation: Assert that a housekeeping CPU comes up at boot time
  2019-06-25  0:17 [PATCH v2] kernel/isolation: Assert that a housekeeping CPU comes up at boot time Nicholas Piggin
@ 2019-06-25  1:11 ` Frederic Weisbecker
  2019-06-25  9:27 ` Qais Yousef
  1 sibling, 0 replies; 3+ messages in thread
From: Frederic Weisbecker @ 2019-06-25  1:11 UTC (permalink / raw)
  To: Nicholas Piggin; +Cc: Peter Zijlstra, linux-kernel, Ingo Molnar, Qais Yousef

On Tue, Jun 25, 2019 at 10:17:20AM +1000, Nicholas Piggin wrote:
> +static int __init housekeeping_verify_smp(void)
> +{
> +	int cpu;
> +
> +	if (!housekeeping_flags)
> +		return 0;
> +
> +	/*
> +	 * Early housekeeping setup is done before CPUs come up, and there are
> +	 * a range of options scattered around that can restrict which CPUs
> +	 * come up. It is possible to pass in a combination of housekeeping
> +	 * and SMP arguments that result in housekeeping assigned to an
> +	 * offline CPU.
> +	 *
> +	 * Check that condition here after SMP comes up, and give a useful
> +	 * error message rather than an obscure non deterministic crash or
> +	 * hang later.
> +	 */
> +	for_each_online_cpu(cpu) {
> +		if (cpumask_test_cpu(cpu, housekeeping_mask))
> +			return 0;
> +	}
> +	panic("Housekeeping: nohz_full= or isolcpus= resulted in no online CPUs for housekeeping.\n");

Ok let's keep the panic. But let's simplify and spare long iterations off boot load:

    if (!cpumask_intersects(cpu_online_mask, housekeeping_mask))
        panic(...);

Thanks.

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

* Re: [PATCH v2] kernel/isolation: Assert that a housekeeping CPU comes up at boot time
  2019-06-25  0:17 [PATCH v2] kernel/isolation: Assert that a housekeeping CPU comes up at boot time Nicholas Piggin
  2019-06-25  1:11 ` Frederic Weisbecker
@ 2019-06-25  9:27 ` Qais Yousef
  1 sibling, 0 replies; 3+ messages in thread
From: Qais Yousef @ 2019-06-25  9:27 UTC (permalink / raw)
  To: Nicholas Piggin
  Cc: Peter Zijlstra, linux-kernel, Frederic Weisbecker, Ingo Molnar

On 06/25/19 10:17, Nicholas Piggin wrote:
> With the change to allow the boot CPU0 to be isolated, it is possible
> to specify command line options that result in no housekeeping CPU
> online at boot.
> 
> An 8 CPU system booted with "nohz_full=0-6 maxcpus=4", for example.
> 
> It is not easily possible at housekeeping init time to know all the
> various SMP options that will result in an invalid configuration, so
> this patch adds a sanity check after SMP init, to ensure that a
> housekeeping CPU has been onlined.
> 
> The panic is undesirable, but it's better than the alternative of an
> obscure non deterministic failure. The panic will reliably happen
> when advanced parameters are used incorrectly.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> v2: Fix a NULL pointer dereference when not overriding housekeeping,
>     noticed by kernel test robot and Qais, who fixed it and verified
>     the fix (thanks!)

Glad I could help. But for the record my problem wasn't a NULL pointer
dereference and simply the loop didn't hit the condition to 'return 0' so I hit
the panic.

I tested that the fix does indeed skip the verification if no nohz_full nor
isolcpus is passed. But I didn't do the reverse check, although from the code
this flag is only set in housekeeping_setup() so it should continue to work as
intended.

Thanks!

--
Qais Yousef

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

end of thread, other threads:[~2019-06-25  9:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-25  0:17 [PATCH v2] kernel/isolation: Assert that a housekeeping CPU comes up at boot time Nicholas Piggin
2019-06-25  1:11 ` Frederic Weisbecker
2019-06-25  9:27 ` Qais Yousef

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.