All of lore.kernel.org
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will.deacon@arm.com>
Cc: linux-kernel@vger.kernel.org,
	Bart Van Assche <bvanassche@acm.org>,
	Waiman Long <longman@redhat.com>
Subject: [PATCH v3 7/8] locking/lockdep: Add lockdep_early_init() before any lock is taken
Date: Wed, 15 Jan 2020 16:43:12 -0500	[thread overview]
Message-ID: <20200115214313.13253-8-longman@redhat.com> (raw)
In-Reply-To: <20200115214313.13253-1-longman@redhat.com>

The lockdep_init() function is actually called after __lock_acquire()
has been called. So it is not a good place to do chain buckets
initialization. Fortunately, the check for nr_free_chain_hlocks prevents
those chain buckets from being used prematurely.

Add a lockdep_early_init() function that will be called very early in the
boot process and move chain buckets initialization over there to ensure
that the buckets are initialized before __lock_acquire() is called.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 include/linux/lockdep.h  | 2 ++
 init/main.c              | 1 +
 kernel/locking/lockdep.c | 5 ++++-
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index c50d01ef1414..efb1ec28a2cd 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -279,6 +279,7 @@ struct held_lock {
  * Initialization, self-test and debugging-output methods:
  */
 extern void lockdep_init(void);
+extern void lockdep_early_init(void);
 extern void lockdep_reset(void);
 extern void lockdep_reset_lock(struct lockdep_map *lock);
 extern void lockdep_free_key_range(void *start, unsigned long size);
@@ -432,6 +433,7 @@ static inline void lockdep_set_selftest_task(struct task_struct *task)
 # define lock_set_class(l, n, k, s, i)		do { } while (0)
 # define lock_set_subclass(l, s, i)		do { } while (0)
 # define lockdep_init()				do { } while (0)
+# define lockdep_early_init()			do { } while (0)
 # define lockdep_init_map(lock, name, key, sub) \
 		do { (void)(name); (void)(key); } while (0)
 # define lockdep_set_class(lock, key)		do { (void)(key); } while (0)
diff --git a/init/main.c b/init/main.c
index 2cd736059416..571b83981276 100644
--- a/init/main.c
+++ b/init/main.c
@@ -580,6 +580,7 @@ asmlinkage __visible void __init start_kernel(void)
 	set_task_stack_end_magic(&init_task);
 	smp_setup_processor_id();
 	debug_objects_early_init();
+	lockdep_early_init();
 
 	cgroup_init_early();
 
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index a1d839e522a9..165e2361b25e 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -5382,10 +5382,13 @@ void lockdep_unregister_key(struct lock_class_key *key)
 }
 EXPORT_SYMBOL_GPL(lockdep_unregister_key);
 
-void __init lockdep_init(void)
+void __init lockdep_early_init(void)
 {
 	init_chain_block_buckets();
+}
 
+void __init lockdep_init(void)
+{
 	printk("Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar\n");
 
 	printk("... MAX_LOCKDEP_SUBCLASSES:  %lu\n", MAX_LOCKDEP_SUBCLASSES);
-- 
2.18.1


  parent reply	other threads:[~2020-01-15 21:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-15 21:43 [PATCH v3 0/8] locking/lockdep: Reuse zapped chain_hlocks entries Waiman Long
2020-01-15 21:43 ` [PATCH v3 1/8] locking/lockdep: Decrement irq context counters when removing lock chain Waiman Long
2020-01-16 15:32   ` Peter Zijlstra
2020-01-16 15:50     ` Waiman Long
2020-01-17 18:14   ` kbuild test robot
2020-01-17 18:14     ` kbuild test robot
2020-01-15 21:43 ` [PATCH v3 2/8] locking/lockdep: Display irq_context names in /proc/lockdep_chains Waiman Long
2020-01-17 22:12   ` kbuild test robot
2020-01-17 22:12     ` kbuild test robot
2020-01-15 21:43 ` [PATCH v3 3/8] locking/lockdep: Track number of zapped classes Waiman Long
2020-01-15 21:43 ` [PATCH v3 4/8] locking/lockdep: Throw away all lock chains with zapped class Waiman Long
2020-01-15 21:43 ` [PATCH v3 5/8] locking/lockdep: Track number of zapped lock chains Waiman Long
2020-01-15 21:43 ` [PATCH v3 6/8] locking/lockdep: Reuse freed chain_hlocks entries Waiman Long
2020-01-16 21:13   ` Peter Zijlstra
2020-01-20  4:22     ` Waiman Long
2020-01-17  5:51   ` kbuild test robot
2020-01-17  5:51     ` kbuild test robot
2020-01-15 21:43 ` Waiman Long [this message]
2020-01-15 21:43 ` [PATCH v3 8/8] locking/lockdep: Enable chain block splitting as last resort Waiman Long

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=20200115214313.13253-8-longman@redhat.com \
    --to=longman@redhat.com \
    --cc=bvanassche@acm.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=will.deacon@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 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.