linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Valentin Schneider <valentin.schneider@arm.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@redhat.com, peterz@infradead.org, morten.rasmussen@arm.com,
	sudeep.holla@arm.com, quentin.perret@arm.com,
	Dietmar.Eggemann@arm.com
Subject: [PATCH] sched/core: Take the hotplug lock in sched_init_smp()
Date: Tue, 23 Oct 2018 14:37:31 +0100	[thread overview]
Message-ID: <1540301851-3048-1-git-send-email-valentin.schneider@arm.com> (raw)

When running on linux-next (8c60c36d0b8c ("Add linux-next specific files
for 20181019")) + CONFIG_PROVE_LOCKING=y on a big.LITTLE system (e.g.
Juno or HiKey960), we get the following report:

[    0.748225] Call trace:
[    0.750685]  lockdep_assert_cpus_held+0x30/0x40
[    0.755236]  static_key_enable_cpuslocked+0x20/0xc8
[    0.760137]  build_sched_domains+0x1034/0x1108
[    0.764601]  sched_init_domains+0x68/0x90
[    0.768628]  sched_init_smp+0x30/0x80
[    0.772309]  kernel_init_freeable+0x278/0x51c
[    0.776685]  kernel_init+0x10/0x108
[    0.780190]  ret_from_fork+0x10/0x18

The static_key in question is sched_asym_cpucapacity introduced by
commit df054e8445a4 ("sched/topology: Add static_key for asymmetric CPU
capacity optimizations"). In this particular case, we enable it because
smp_prepare_cpus() will end up fetching the capacity-dmips-mhz entry
from the devicetree, so we already have some asymmetry detected when
entering sched_init_smp().

This didn't get detected in tip/sched/core because we were missing
commit cb538267ea1e ("jump_label/lockdep: Assert we hold the hotplug
lock for _cpuslocked() operations").

Calls to build_sched_domains() post sched_init_smp() will hold the
hotplug lock, it just so happens that this very first call is a
special case. As stated by a comment in sched_init_smp(), "There's no
userspace yet to cause hotplug operations" so this is a harmless
warning.

However, to both respect the semantics of underlying
callees and make lockdep happy, take the hotplug lock in
sched_init_smp(). This also satisfies the comment atop
sched_init_domains() that says "Callers must hold the hotplug lock".

Reported-by: Sudeep Holla <sudeep.holla@arm.com>
Tested-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
---
 kernel/sched/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index fd2fce8..02a20ef 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5859,11 +5859,14 @@ void __init sched_init_smp(void)
 	/*
 	 * There's no userspace yet to cause hotplug operations; hence all the
 	 * CPU masks are stable and all blatant races in the below code cannot
-	 * happen.
+	 * happen. The hotplug lock is nevertheless taken to satisfy lockdep,
+	 * but there won't be any contention on it.
 	 */
+	cpus_read_lock();
 	mutex_lock(&sched_domains_mutex);
 	sched_init_domains(cpu_active_mask);
 	mutex_unlock(&sched_domains_mutex);
+	cpus_read_unlock();
 
 	/* Move init over to a non-isolated CPU */
 	if (set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0)
--
2.7.4


             reply	other threads:[~2018-10-23 13:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-23 13:37 Valentin Schneider [this message]
2018-11-04  0:01 ` [tip:sched/urgent] sched/core: Take the hotplug lock in sched_init_smp() tip-bot for Valentin Schneider

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1540301851-3048-1-git-send-email-valentin.schneider@arm.com \
    --to=valentin.schneider@arm.com \
    --cc=Dietmar.Eggemann@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=morten.rasmussen@arm.com \
    --cc=peterz@infradead.org \
    --cc=quentin.perret@arm.com \
    --cc=sudeep.holla@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).