diff mbox series

[v8,05/25] dept: Tie to Lockdep and IRQ tracing

Message ID 1674782358-25542-6-git-send-email-max.byungchul.park@gmail.com
State Not Applicable
Headers show
Series DEPT(Dependency Tracker) | expand

Commit Message

Byungchul Park Jan. 27, 2023, 1:18 a.m. UTC
Yes. How to place Dept in here looks so ugly. But it's inevitable as
long as relying on Lockdep. The way should be enhanced gradually.

   1. Basically relies on Lockdep to track typical locks and IRQ things.

   2. Dept fails to recognize IRQ situation so it generates false alarms
      when raw_local_irq_*() APIs are used. So made it track those too.

   3. Lockdep doesn't track the outmost {hard,soft}irq entracnes but
      Dept makes use of it. So made it track those too.

Signed-off-by: Byungchul Park <max.byungchul.park@gmail.com>
---
 include/linux/irqflags.h            |  23 ++++++--
 include/linux/local_lock_internal.h |   1 +
 include/linux/lockdep.h             | 102 ++++++++++++++++++++++++++++--------
 include/linux/lockdep_types.h       |   3 ++
 include/linux/mutex.h               |   1 +
 include/linux/percpu-rwsem.h        |   2 +-
 include/linux/rtmutex.h             |   1 +
 include/linux/rwlock_types.h        |   1 +
 include/linux/rwsem.h               |   1 +
 include/linux/seqlock.h             |   2 +-
 include/linux/spinlock_types_raw.h  |   3 ++
 include/linux/srcu.h                |   2 +-
 kernel/dependency/dept.c            |   4 +-
 kernel/locking/lockdep.c            |  23 ++++++++
 14 files changed, 140 insertions(+), 29 deletions(-)

Comments

kernel test robot Jan. 28, 2023, 7:24 a.m. UTC | #1
Hi Byungchul,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tip/locking/core]
[also build test ERROR on tip/sched/core drm-misc/drm-misc-next linus/master v6.2-rc5 next-20230127]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Byungchul-Park/llist-Move-llist_-head-node-definition-to-types-h/20230128-102456
patch link:    https://lore.kernel.org/r/1674782358-25542-6-git-send-email-max.byungchul.park%40gmail.com
patch subject: [PATCH v8 05/25] dept: Tie to Lockdep and IRQ tracing
config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20230128/202301281551.sSDuxg0O-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/aed5169e3b6767146ee602447fcf75b4c734d2db
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Byungchul-Park/llist-Move-llist_-head-node-definition-to-types-h/20230128-102456
        git checkout aed5169e3b6767146ee602447fcf75b4c734d2db
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=parisc olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=parisc prepare

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   In file included from include/linux/bitops.h:68,
                    from include/linux/kernel.h:22,
                    from include/linux/irqflags.h:16,
                    from include/asm-generic/cmpxchg-local.h:6,
                    from arch/parisc/include/asm/cmpxchg.h:89,
                    from arch/parisc/include/asm/atomic.h:10,
                    from include/linux/atomic.h:7,
                    from include/linux/rcupdate.h:25,
                    from include/linux/rculist.h:11,
                    from include/linux/pid.h:5,
                    from include/linux/sched.h:14,
                    from arch/parisc/kernel/asm-offsets.c:18:
   arch/parisc/include/asm/bitops.h: In function 'set_bit':
>> arch/parisc/include/asm/bitops.h:27:9: error: implicit declaration of function '_atomic_spin_lock_irqsave'; did you mean '__atomic_is_lock_free'? [-Werror=implicit-function-declaration]
      27 |         _atomic_spin_lock_irqsave(addr, flags);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~
         |         __atomic_is_lock_free
>> arch/parisc/include/asm/bitops.h:29:9: error: implicit declaration of function '_atomic_spin_unlock_irqrestore' [-Werror=implicit-function-declaration]
      29 |         _atomic_spin_unlock_irqrestore(addr, flags);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   In file included from arch/parisc/include/asm/bitops.h:204:
   include/asm-generic/bitops/lock.h: In function 'arch_test_and_set_bit_lock':
>> include/asm-generic/bitops/lock.h:28:15: error: implicit declaration of function 'arch_atomic_long_fetch_or_acquire' [-Werror=implicit-function-declaration]
      28 |         old = arch_atomic_long_fetch_or_acquire(mask, (atomic_long_t *)p);
         |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/asm-generic/bitops/lock.h:28:56: error: 'atomic_long_t' undeclared (first use in this function); did you mean 'atomic_t'?
      28 |         old = arch_atomic_long_fetch_or_acquire(mask, (atomic_long_t *)p);
         |                                                        ^~~~~~~~~~~~~
         |                                                        atomic_t
   include/asm-generic/bitops/lock.h:28:56: note: each undeclared identifier is reported only once for each function it appears in
>> include/asm-generic/bitops/lock.h:28:71: error: expected expression before ')' token
      28 |         old = arch_atomic_long_fetch_or_acquire(mask, (atomic_long_t *)p);
         |                                                                       ^
   include/asm-generic/bitops/lock.h: In function 'arch_clear_bit_unlock':
>> include/asm-generic/bitops/lock.h:44:9: error: implicit declaration of function 'arch_atomic_long_fetch_andnot_release' [-Werror=implicit-function-declaration]
      44 |         arch_atomic_long_fetch_andnot_release(BIT_MASK(nr), (atomic_long_t *)p);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/bitops/lock.h:44:62: error: 'atomic_long_t' undeclared (first use in this function); did you mean 'atomic_t'?
      44 |         arch_atomic_long_fetch_andnot_release(BIT_MASK(nr), (atomic_long_t *)p);
         |                                                              ^~~~~~~~~~~~~
         |                                                              atomic_t
   include/asm-generic/bitops/lock.h:44:77: error: expected expression before ')' token
      44 |         arch_atomic_long_fetch_andnot_release(BIT_MASK(nr), (atomic_long_t *)p);
         |                                                                             ^
   include/asm-generic/bitops/lock.h: In function 'arch___clear_bit_unlock':
>> include/asm-generic/bitops/lock.h:66:9: error: implicit declaration of function 'arch_atomic_long_set_release' [-Werror=implicit-function-declaration]
      66 |         arch_atomic_long_set_release((atomic_long_t *)p, old);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/bitops/lock.h:66:39: error: 'atomic_long_t' undeclared (first use in this function); did you mean 'atomic_t'?
      66 |         arch_atomic_long_set_release((atomic_long_t *)p, old);
         |                                       ^~~~~~~~~~~~~
         |                                       atomic_t
   include/asm-generic/bitops/lock.h:66:54: error: expected expression before ')' token
      66 |         arch_atomic_long_set_release((atomic_long_t *)p, old);
         |                                                      ^
   include/asm-generic/bitops/lock.h: In function 'arch_clear_bit_unlock_is_negative_byte':
   include/asm-generic/bitops/lock.h:86:60: error: 'atomic_long_t' undeclared (first use in this function); did you mean 'atomic_t'?
      86 |         old = arch_atomic_long_fetch_andnot_release(mask, (atomic_long_t *)p);
         |                                                            ^~~~~~~~~~~~~
         |                                                            atomic_t
   include/asm-generic/bitops/lock.h:86:75: error: expected expression before ')' token
      86 |         old = arch_atomic_long_fetch_andnot_release(mask, (atomic_long_t *)p);
         |                                                                           ^
   In file included from include/linux/atomic.h:81:
   include/linux/atomic/atomic-long.h: At top level:
>> include/linux/atomic/atomic-long.h:539:1: warning: conflicting types for 'arch_atomic_long_set_release'; have 'void(atomic_long_t *, long int)' {aka 'void(atomic_t *, long int)'}
     539 | arch_atomic_long_set_release(atomic_long_t *v, long i)
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/atomic/atomic-long.h:539:1: error: static declaration of 'arch_atomic_long_set_release' follows non-static declaration
   include/asm-generic/bitops/lock.h:66:9: note: previous implicit declaration of 'arch_atomic_long_set_release' with type 'void(atomic_long_t *, long int)' {aka 'void(atomic_t *, long int)'}
      66 |         arch_atomic_long_set_release((atomic_long_t *)p, old);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/atomic/atomic-long.h:809:1: error: conflicting types for 'arch_atomic_long_fetch_andnot_release'; have 'long int(long int,  atomic_long_t *)' {aka 'long int(long int,  atomic_t *)'}
     809 | arch_atomic_long_fetch_andnot_release(long i, atomic_long_t *v)
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/bitops/lock.h:44:9: note: previous implicit declaration of 'arch_atomic_long_fetch_andnot_release' with type 'int()'
      44 |         arch_atomic_long_fetch_andnot_release(BIT_MASK(nr), (atomic_long_t *)p);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/atomic/atomic-long.h:833:1: error: conflicting types for 'arch_atomic_long_fetch_or_acquire'; have 'long int(long int,  atomic_long_t *)' {aka 'long int(long int,  atomic_t *)'}
     833 | arch_atomic_long_fetch_or_acquire(long i, atomic_long_t *v)
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/bitops/lock.h:28:15: note: previous implicit declaration of 'arch_atomic_long_fetch_or_acquire' with type 'int()'
      28 |         old = arch_atomic_long_fetch_or_acquire(mask, (atomic_long_t *)p);
         |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors
   make[2]: *** [scripts/Makefile.build:114: arch/parisc/kernel/asm-offsets.s] Error 1
   make[2]: Target 'prepare' not remade because of errors.
   make[1]: *** [Makefile:1298: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:242: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.


vim +27 arch/parisc/include/asm/bitops.h

^1da177e4c3f41 include/asm-parisc/bitops.h      Linus Torvalds 2005-04-16  14  
a366064c3ff46c include/asm-parisc/bitops.h      Grant Grundler 2005-10-21  15  /* See http://marc.theaimsgroup.com/?t=108826637900003 for discussion
a366064c3ff46c include/asm-parisc/bitops.h      Grant Grundler 2005-10-21  16   * on use of volatile and __*_bit() (set/clear/change):
a366064c3ff46c include/asm-parisc/bitops.h      Grant Grundler 2005-10-21  17   *	*_bit() want use of volatile.
a366064c3ff46c include/asm-parisc/bitops.h      Grant Grundler 2005-10-21  18   *	__*_bit() are "relaxed" and don't use spinlock or volatile.
a366064c3ff46c include/asm-parisc/bitops.h      Grant Grundler 2005-10-21  19   */
a366064c3ff46c include/asm-parisc/bitops.h      Grant Grundler 2005-10-21  20  
a366064c3ff46c include/asm-parisc/bitops.h      Grant Grundler 2005-10-21  21  static __inline__ void set_bit(int nr, volatile unsigned long * addr)
^1da177e4c3f41 include/asm-parisc/bitops.h      Linus Torvalds 2005-04-16  22  {
208151bfb70fb7 arch/parisc/include/asm/bitops.h Helge Deller   2020-06-14  23  	unsigned long mask = BIT_MASK(nr);
^1da177e4c3f41 include/asm-parisc/bitops.h      Linus Torvalds 2005-04-16  24  	unsigned long flags;
^1da177e4c3f41 include/asm-parisc/bitops.h      Linus Torvalds 2005-04-16  25  
208151bfb70fb7 arch/parisc/include/asm/bitops.h Helge Deller   2020-06-14  26  	addr += BIT_WORD(nr);
^1da177e4c3f41 include/asm-parisc/bitops.h      Linus Torvalds 2005-04-16 @27  	_atomic_spin_lock_irqsave(addr, flags);
^1da177e4c3f41 include/asm-parisc/bitops.h      Linus Torvalds 2005-04-16  28  	*addr |= mask;
^1da177e4c3f41 include/asm-parisc/bitops.h      Linus Torvalds 2005-04-16 @29  	_atomic_spin_unlock_irqrestore(addr, flags);
^1da177e4c3f41 include/asm-parisc/bitops.h      Linus Torvalds 2005-04-16  30  }
^1da177e4c3f41 include/asm-parisc/bitops.h      Linus Torvalds 2005-04-16  31
kernel test robot Jan. 29, 2023, 8:56 a.m. UTC | #2
Hi Byungchul,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tip/locking/core]
[also build test WARNING on tip/sched/core drm-misc/drm-misc-next linus/master v6.2-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Byungchul-Park/llist-Move-llist_-head-node-definition-to-types-h/20230128-102456
patch link:    https://lore.kernel.org/r/1674782358-25542-6-git-send-email-max.byungchul.park%40gmail.com
patch subject: [PATCH v8 05/25] dept: Tie to Lockdep and IRQ tracing
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230129/202301291601.7591xziv-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/aed5169e3b6767146ee602447fcf75b4c734d2db
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Byungchul-Park/llist-Move-llist_-head-node-definition-to-types-h/20230128-102456
        git checkout aed5169e3b6767146ee602447fcf75b4c734d2db
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 olddefconfig
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/net/ethernet/microchip/vcap/ drivers/platform/chrome/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/platform/chrome/cros_ec_proto_test.c: In function 'cros_ec_proto_test_get_sensor_count_xfer_error':
>> drivers/platform/chrome/cros_ec_proto_test.c:2528:1: warning: the frame size of 2072 bytes is larger than 2048 bytes [-Wframe-larger-than=]
    2528 | }
         | ^
   drivers/platform/chrome/cros_ec_proto_test.c: In function 'cros_ec_proto_test_get_sensor_count_normal':
   drivers/platform/chrome/cros_ec_proto_test.c:2488:1: warning: the frame size of 2072 bytes is larger than 2048 bytes [-Wframe-larger-than=]
    2488 | }
         | ^
   drivers/platform/chrome/cros_ec_proto_test.c: In function 'cros_ec_proto_test_get_sensor_count_legacy':
   drivers/platform/chrome/cros_ec_proto_test.c:2593:1: warning: the frame size of 2136 bytes is larger than 2048 bytes [-Wframe-larger-than=]
    2593 | }
         | ^
   drivers/platform/chrome/cros_ec_proto_test.c: In function 'cros_ec_proto_test_check_features_not_cached':
   drivers/platform/chrome/cros_ec_proto_test.c:2443:1: warning: the frame size of 2056 bytes is larger than 2048 bytes [-Wframe-larger-than=]
    2443 | }
         | ^
--
   In file included from drivers/net/ethernet/microchip/vcap/vcap_api.c:2882:
   drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c: In function 'vcap_api_next_lookup_advanced_test':
>> drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c:1955:1: warning: the frame size of 2240 bytes is larger than 2048 bytes [-Wframe-larger-than=]
    1955 | }
         | ^


vim +2528 drivers/platform/chrome/cros_ec_proto_test.c

33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2489  
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2490  static void cros_ec_proto_test_get_sensor_count_xfer_error(struct kunit *test)
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2491  {
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2492  	struct cros_ec_proto_test_priv *priv = test->priv;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2493  	struct cros_ec_device *ec_dev = &priv->ec_dev;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2494  	struct ec_xfer_mock *mock;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2495  	int ret;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2496  	struct cros_ec_dev ec;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2497  
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2498  	ec_dev->max_request = 0xff;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2499  	ec_dev->max_response = 0xee;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2500  	ec.ec_dev = ec_dev;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2501  	ec.dev = ec_dev->dev;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2502  	ec.cmd_offset = 0;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2503  
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2504  	/* For EC_CMD_MOTION_SENSE_CMD. */
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2505  	{
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2506  		mock = cros_kunit_ec_xfer_mock_addx(test, -EPROTO, EC_RES_SUCCESS, 0);
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2507  		KUNIT_ASSERT_PTR_NE(test, mock, NULL);
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2508  	}
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2509  
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2510  	ret = cros_ec_get_sensor_count(&ec);
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2511  	KUNIT_EXPECT_EQ(test, ret, -EPROTO);
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2512  
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2513  	/* For EC_CMD_MOTION_SENSE_CMD. */
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2514  	{
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2515  		struct ec_params_motion_sense *data;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2516  
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2517  		mock = cros_kunit_ec_xfer_mock_next();
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2518  		KUNIT_EXPECT_PTR_NE(test, mock, NULL);
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2519  
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2520  		KUNIT_EXPECT_EQ(test, mock->msg.version, 1);
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2521  		KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_MOTION_SENSE_CMD);
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2522  		KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(struct ec_response_motion_sense));
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2523  		KUNIT_EXPECT_EQ(test, mock->msg.outsize, sizeof(*data));
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2524  
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2525  		data = (struct ec_params_motion_sense *)mock->i_data;
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2526  		KUNIT_EXPECT_EQ(test, data->cmd, MOTIONSENSE_CMD_DUMP);
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2527  	}
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22 @2528  }
33f0fdba6066b5 Tzung-Bi Shih 2022-06-22  2529
diff mbox series

Patch

diff --git a/include/linux/irqflags.h b/include/linux/irqflags.h
index 5ec0fa7..51750ef 100644
--- a/include/linux/irqflags.h
+++ b/include/linux/irqflags.h
@@ -13,6 +13,8 @@ 
 #define _LINUX_TRACE_IRQFLAGS_H
 
 #include <linux/typecheck.h>
+#include <linux/kernel.h>
+#include <linux/dept.h>
 #include <asm/irqflags.h>
 #include <asm/percpu.h>
 
@@ -60,8 +62,10 @@  struct irqtrace_events {
 # define lockdep_softirqs_enabled(p)	((p)->softirqs_enabled)
 # define lockdep_hardirq_enter()			\
 do {							\
-	if (__this_cpu_inc_return(hardirq_context) == 1)\
+	if (__this_cpu_inc_return(hardirq_context) == 1) { \
 		current->hardirq_threaded = 0;		\
+		dept_hardirq_enter();			\
+	}						\
 } while (0)
 # define lockdep_hardirq_threaded()		\
 do {						\
@@ -136,6 +140,8 @@  struct irqtrace_events {
 # define lockdep_softirq_enter()		\
 do {						\
 	current->softirq_context++;		\
+	if (current->softirq_context == 1)	\
+		dept_softirq_enter();		\
 } while (0)
 # define lockdep_softirq_exit()			\
 do {						\
@@ -170,17 +176,28 @@  struct irqtrace_events {
 /*
  * Wrap the arch provided IRQ routines to provide appropriate checks.
  */
-#define raw_local_irq_disable()		arch_local_irq_disable()
-#define raw_local_irq_enable()		arch_local_irq_enable()
+#define raw_local_irq_disable()				\
+	do {						\
+		arch_local_irq_disable();		\
+		dept_hardirqs_off(_THIS_IP_);		\
+	} while (0)
+#define raw_local_irq_enable()				\
+	do {						\
+		dept_hardirqs_on(_THIS_IP_);		\
+		arch_local_irq_enable();		\
+	} while (0)
 #define raw_local_irq_save(flags)			\
 	do {						\
 		typecheck(unsigned long, flags);	\
 		flags = arch_local_irq_save();		\
+		dept_hardirqs_off(_THIS_IP_);		\
 	} while (0)
 #define raw_local_irq_restore(flags)			\
 	do {						\
 		typecheck(unsigned long, flags);	\
 		raw_check_bogus_irq_restore();		\
+		if (!arch_irqs_disabled_flags(flags))	\
+			dept_hardirqs_on(_THIS_IP_);	\
 		arch_local_irq_restore(flags);		\
 	} while (0)
 #define raw_local_save_flags(flags)			\
diff --git a/include/linux/local_lock_internal.h b/include/linux/local_lock_internal.h
index 975e33b..39f6778 100644
--- a/include/linux/local_lock_internal.h
+++ b/include/linux/local_lock_internal.h
@@ -21,6 +21,7 @@ 
 		.name = #lockname,			\
 		.wait_type_inner = LD_WAIT_CONFIG,	\
 		.lock_type = LD_LOCK_PERCPU,		\
+		.dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\
 	},						\
 	.owner = NULL,
 
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 1f1099d..9996102 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -12,6 +12,7 @@ 
 
 #include <linux/lockdep_types.h>
 #include <linux/smp.h>
+#include <linux/dept_ldt.h>
 #include <asm/percpu.h>
 
 struct task_struct;
@@ -39,6 +40,8 @@  static inline void lockdep_copy_map(struct lockdep_map *to,
 	 */
 	for (i = 0; i < NR_LOCKDEP_CACHING_CLASSES; i++)
 		to->class_cache[i] = NULL;
+
+	dept_map_copy(&to->dmap, &from->dmap);
 }
 
 /*
@@ -441,7 +444,8 @@  enum xhlock_context_t {
  * Note that _name must not be NULL.
  */
 #define STATIC_LOCKDEP_MAP_INIT(_name, _key) \
-	{ .name = (_name), .key = (void *)(_key), }
+	{ .name = (_name), .key = (void *)(_key), \
+	  .dmap = DEPT_MAP_INITIALIZER(_name, _key) }
 
 static inline void lockdep_invariant_state(bool force) {}
 static inline void lockdep_free_task(struct task_struct *task) {}
@@ -523,33 +527,89 @@  static inline void print_irqtrace_events(struct task_struct *curr)
 #define lock_acquire_shared(l, s, t, n, i)		lock_acquire(l, s, t, 1, 1, n, i)
 #define lock_acquire_shared_recursive(l, s, t, n, i)	lock_acquire(l, s, t, 2, 1, n, i)
 
-#define spin_acquire(l, s, t, i)		lock_acquire_exclusive(l, s, t, NULL, i)
-#define spin_acquire_nest(l, s, t, n, i)	lock_acquire_exclusive(l, s, t, n, i)
-#define spin_release(l, i)			lock_release(l, i)
-
-#define rwlock_acquire(l, s, t, i)		lock_acquire_exclusive(l, s, t, NULL, i)
+#define spin_acquire(l, s, t, i)					\
+do {									\
+	ldt_lock(&(l)->dmap, s, t, NULL, i);				\
+	lock_acquire_exclusive(l, s, t, NULL, i);			\
+} while (0)
+#define spin_acquire_nest(l, s, t, n, i)				\
+do {									\
+	ldt_lock(&(l)->dmap, s, t, n, i);				\
+	lock_acquire_exclusive(l, s, t, n, i);				\
+} while (0)
+#define spin_release(l, i)						\
+do {									\
+	ldt_unlock(&(l)->dmap, i);					\
+	lock_release(l, i);						\
+} while (0)
+#define rwlock_acquire(l, s, t, i)					\
+do {									\
+	ldt_wlock(&(l)->dmap, s, t, NULL, i);				\
+	lock_acquire_exclusive(l, s, t, NULL, i);			\
+} while (0)
 #define rwlock_acquire_read(l, s, t, i)					\
 do {									\
+	ldt_rlock(&(l)->dmap, s, t, NULL, i, !read_lock_is_recursive());\
 	if (read_lock_is_recursive())					\
 		lock_acquire_shared_recursive(l, s, t, NULL, i);	\
 	else								\
 		lock_acquire_shared(l, s, t, NULL, i);			\
 } while (0)
-
-#define rwlock_release(l, i)			lock_release(l, i)
-
-#define seqcount_acquire(l, s, t, i)		lock_acquire_exclusive(l, s, t, NULL, i)
-#define seqcount_acquire_read(l, s, t, i)	lock_acquire_shared_recursive(l, s, t, NULL, i)
-#define seqcount_release(l, i)			lock_release(l, i)
-
-#define mutex_acquire(l, s, t, i)		lock_acquire_exclusive(l, s, t, NULL, i)
-#define mutex_acquire_nest(l, s, t, n, i)	lock_acquire_exclusive(l, s, t, n, i)
-#define mutex_release(l, i)			lock_release(l, i)
-
-#define rwsem_acquire(l, s, t, i)		lock_acquire_exclusive(l, s, t, NULL, i)
-#define rwsem_acquire_nest(l, s, t, n, i)	lock_acquire_exclusive(l, s, t, n, i)
-#define rwsem_acquire_read(l, s, t, i)		lock_acquire_shared(l, s, t, NULL, i)
-#define rwsem_release(l, i)			lock_release(l, i)
+#define rwlock_release(l, i)						\
+do {									\
+	ldt_unlock(&(l)->dmap, i);					\
+	lock_release(l, i);						\
+} while (0)
+#define seqcount_acquire(l, s, t, i)					\
+do {									\
+	ldt_wlock(&(l)->dmap, s, t, NULL, i);				\
+	lock_acquire_exclusive(l, s, t, NULL, i);			\
+} while (0)
+#define seqcount_acquire_read(l, s, t, i)				\
+do {									\
+	ldt_rlock(&(l)->dmap, s, t, NULL, i, false);			\
+	lock_acquire_shared_recursive(l, s, t, NULL, i);		\
+} while (0)
+#define seqcount_release(l, i)						\
+do {									\
+	ldt_unlock(&(l)->dmap, i);					\
+	lock_release(l, i);						\
+} while (0)
+#define mutex_acquire(l, s, t, i)					\
+do {									\
+	ldt_lock(&(l)->dmap, s, t, NULL, i);				\
+	lock_acquire_exclusive(l, s, t, NULL, i);			\
+} while (0)
+#define mutex_acquire_nest(l, s, t, n, i)				\
+do {									\
+	ldt_lock(&(l)->dmap, s, t, n, i);				\
+	lock_acquire_exclusive(l, s, t, n, i);				\
+} while (0)
+#define mutex_release(l, i)						\
+do {									\
+	ldt_unlock(&(l)->dmap, i);					\
+	lock_release(l, i);						\
+} while (0)
+#define rwsem_acquire(l, s, t, i)					\
+do {									\
+	ldt_lock(&(l)->dmap, s, t, NULL, i);				\
+	lock_acquire_exclusive(l, s, t, NULL, i);			\
+} while (0)
+#define rwsem_acquire_nest(l, s, t, n, i)				\
+do {									\
+	ldt_lock(&(l)->dmap, s, t, n, i);				\
+	lock_acquire_exclusive(l, s, t, n, i);				\
+} while (0)
+#define rwsem_acquire_read(l, s, t, i)					\
+do {									\
+	ldt_lock(&(l)->dmap, s, t, NULL, i);				\
+	lock_acquire_shared(l, s, t, NULL, i);				\
+} while (0)
+#define rwsem_release(l, i)						\
+do {									\
+	ldt_unlock(&(l)->dmap, i);					\
+	lock_release(l, i);						\
+} while (0)
 
 #define lock_map_acquire(l)			lock_acquire_exclusive(l, 0, 0, NULL, _THIS_IP_)
 #define lock_map_acquire_read(l)		lock_acquire_shared_recursive(l, 0, 0, NULL, _THIS_IP_)
diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h
index d224308..50c8879 100644
--- a/include/linux/lockdep_types.h
+++ b/include/linux/lockdep_types.h
@@ -11,6 +11,7 @@ 
 #define __LINUX_LOCKDEP_TYPES_H
 
 #include <linux/types.h>
+#include <linux/dept.h>
 
 #define MAX_LOCKDEP_SUBCLASSES		8UL
 
@@ -76,6 +77,7 @@  struct lock_class_key {
 		struct hlist_node		hash_entry;
 		struct lockdep_subclass_key	subkeys[MAX_LOCKDEP_SUBCLASSES];
 	};
+	struct dept_key				dkey;
 };
 
 extern struct lock_class_key __lockdep_no_validate__;
@@ -185,6 +187,7 @@  struct lockdep_map {
 	int				cpu;
 	unsigned long			ip;
 #endif
+	struct dept_map			dmap;
 };
 
 struct pin_cookie { unsigned int val; };
diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index 8f226d4..58bf314 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -25,6 +25,7 @@ 
 		, .dep_map = {					\
 			.name = #lockname,			\
 			.wait_type_inner = LD_WAIT_SLEEP,	\
+			.dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\
 		}
 #else
 # define __DEP_MAP_MUTEX_INITIALIZER(lockname)
diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h
index 36b942b..e871aca 100644
--- a/include/linux/percpu-rwsem.h
+++ b/include/linux/percpu-rwsem.h
@@ -21,7 +21,7 @@  struct percpu_rw_semaphore {
 };
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
-#define __PERCPU_RWSEM_DEP_MAP_INIT(lockname)	.dep_map = { .name = #lockname },
+#define __PERCPU_RWSEM_DEP_MAP_INIT(lockname)	.dep_map = { .name = #lockname, .dmap = DEPT_MAP_INITIALIZER(lockname, NULL) },
 #else
 #define __PERCPU_RWSEM_DEP_MAP_INIT(lockname)
 #endif
diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h
index 7d04988..35889ac 100644
--- a/include/linux/rtmutex.h
+++ b/include/linux/rtmutex.h
@@ -81,6 +81,7 @@  static inline void rt_mutex_debug_task_free(struct task_struct *tsk) { }
 	.dep_map = {					\
 		.name = #mutexname,			\
 		.wait_type_inner = LD_WAIT_SLEEP,	\
+		.dmap = DEPT_MAP_INITIALIZER(mutexname, NULL),\
 	}
 #else
 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)
diff --git a/include/linux/rwlock_types.h b/include/linux/rwlock_types.h
index 1948442..6e58dfc 100644
--- a/include/linux/rwlock_types.h
+++ b/include/linux/rwlock_types.h
@@ -10,6 +10,7 @@ 
 	.dep_map = {							\
 		.name = #lockname,					\
 		.wait_type_inner = LD_WAIT_CONFIG,			\
+		.dmap = DEPT_MAP_INITIALIZER(lockname, NULL),		\
 	}
 #else
 # define RW_DEP_MAP_INIT(lockname)
diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
index efa5c32..4f856e7 100644
--- a/include/linux/rwsem.h
+++ b/include/linux/rwsem.h
@@ -21,6 +21,7 @@ 
 	.dep_map = {					\
 		.name = #lockname,			\
 		.wait_type_inner = LD_WAIT_SLEEP,	\
+		.dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\
 	},
 #else
 # define __RWSEM_DEP_MAP_INIT(lockname)
diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index 3926e90..6ba00bc 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -81,7 +81,7 @@  static inline void __seqcount_init(seqcount_t *s, const char *name,
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 
 # define SEQCOUNT_DEP_MAP_INIT(lockname)				\
-		.dep_map = { .name = #lockname }
+		.dep_map = { .name = #lockname, .dmap = DEPT_MAP_INITIALIZER(lockname, NULL) }
 
 /**
  * seqcount_init() - runtime initializer for seqcount_t
diff --git a/include/linux/spinlock_types_raw.h b/include/linux/spinlock_types_raw.h
index 91cb36b..3dcc551 100644
--- a/include/linux/spinlock_types_raw.h
+++ b/include/linux/spinlock_types_raw.h
@@ -31,11 +31,13 @@ 
 	.dep_map = {					\
 		.name = #lockname,			\
 		.wait_type_inner = LD_WAIT_SPIN,	\
+		.dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\
 	}
 # define SPIN_DEP_MAP_INIT(lockname)			\
 	.dep_map = {					\
 		.name = #lockname,			\
 		.wait_type_inner = LD_WAIT_CONFIG,	\
+		.dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\
 	}
 
 # define LOCAL_SPIN_DEP_MAP_INIT(lockname)		\
@@ -43,6 +45,7 @@ 
 		.name = #lockname,			\
 		.wait_type_inner = LD_WAIT_CONFIG,	\
 		.lock_type = LD_LOCK_PERCPU,		\
+		.dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\
 	}
 #else
 # define RAW_SPIN_DEP_MAP_INIT(lockname)
diff --git a/include/linux/srcu.h b/include/linux/srcu.h
index 9b9d0bb..c934158 100644
--- a/include/linux/srcu.h
+++ b/include/linux/srcu.h
@@ -35,7 +35,7 @@  int __init_srcu_struct(struct srcu_struct *ssp, const char *name,
 	__init_srcu_struct((ssp), #ssp, &__srcu_key); \
 })
 
-#define __SRCU_DEP_MAP_INIT(srcu_name)	.dep_map = { .name = #srcu_name },
+#define __SRCU_DEP_MAP_INIT(srcu_name)	.dep_map = { .name = #srcu_name, .dmap = DEPT_MAP_INITIALIZER(srcu_name, NULL) },
 #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
 
 int init_srcu_struct(struct srcu_struct *ssp);
diff --git a/kernel/dependency/dept.c b/kernel/dependency/dept.c
index 6686583..72040c8 100644
--- a/kernel/dependency/dept.c
+++ b/kernel/dependency/dept.c
@@ -244,10 +244,10 @@  static inline bool dept_working(void)
  * Even k == NULL is considered as a valid key because it would use
  * &->map_key as the key in that case.
  */
-struct dept_key __dept_no_validate__;
+extern struct lock_class_key __lockdep_no_validate__;
 static inline bool valid_key(struct dept_key *k)
 {
-	return &__dept_no_validate__ != k;
+	return &__lockdep_no_validate__.dkey != k;
 }
 
 /*
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index e3375bc..abe9298 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -1220,6 +1220,8 @@  void lockdep_register_key(struct lock_class_key *key)
 	struct lock_class_key *k;
 	unsigned long flags;
 
+	dept_key_init(&key->dkey);
+
 	if (WARN_ON_ONCE(static_obj(key)))
 		return;
 	hash_head = keyhashentry(key);
@@ -4327,6 +4329,8 @@  void noinstr lockdep_hardirqs_on(unsigned long ip)
 {
 	struct irqtrace_events *trace = &current->irqtrace;
 
+	dept_hardirqs_on(ip);
+
 	if (unlikely(!debug_locks))
 		return;
 
@@ -4392,6 +4396,8 @@  void noinstr lockdep_hardirqs_on(unsigned long ip)
  */
 void noinstr lockdep_hardirqs_off(unsigned long ip)
 {
+	dept_hardirqs_off(ip);
+
 	if (unlikely(!debug_locks))
 		return;
 
@@ -4436,6 +4442,8 @@  void lockdep_softirqs_on(unsigned long ip)
 {
 	struct irqtrace_events *trace = &current->irqtrace;
 
+	dept_softirqs_on(ip);
+
 	if (unlikely(!lockdep_enabled()))
 		return;
 
@@ -4474,6 +4482,9 @@  void lockdep_softirqs_on(unsigned long ip)
  */
 void lockdep_softirqs_off(unsigned long ip)
 {
+
+	dept_softirqs_off(ip);
+
 	if (unlikely(!lockdep_enabled()))
 		return;
 
@@ -4806,6 +4817,8 @@  void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
 {
 	int i;
 
+	ldt_init(&lock->dmap, &key->dkey, subclass, name);
+
 	for (i = 0; i < NR_LOCKDEP_CACHING_CLASSES; i++)
 		lock->class_cache[i] = NULL;
 
@@ -5544,6 +5557,12 @@  void lock_set_class(struct lockdep_map *lock, const char *name,
 {
 	unsigned long flags;
 
+	/*
+	 * dept_map_(re)init() might be called twice redundantly. But
+	 * there's no choice as long as Dept relies on Lockdep.
+	 */
+	ldt_set_class(&lock->dmap, name, &key->dkey, subclass, ip);
+
 	if (unlikely(!lockdep_enabled()))
 		return;
 
@@ -5561,6 +5580,8 @@  void lock_downgrade(struct lockdep_map *lock, unsigned long ip)
 {
 	unsigned long flags;
 
+	ldt_downgrade(&lock->dmap, ip);
+
 	if (unlikely(!lockdep_enabled()))
 		return;
 
@@ -6333,6 +6354,8 @@  void lockdep_unregister_key(struct lock_class_key *key)
 	unsigned long flags;
 	bool found = false;
 
+	dept_key_destroy(&key->dkey);
+
 	might_sleep();
 
 	if (WARN_ON_ONCE(static_obj(key)))