Skip to content

Commit babaed9

Browse files
karis79popcornmix
authored andcommitted
usb: dwc: fix lockdep false positive
Os wrapper function for spinlock init causes lockdep to show this false positive splat during boot: [ 3.789851] ============================================= [ 3.796603] [ INFO: possible recursive locking detected ] [ 3.803320] 3.16.1+ raspberrypi#5 Not tainted [ 3.808015] --------------------------------------------- [ 3.814730] khubd/18 is trying to acquire lock: [ 3.820537] (&(sl)->rlock){-.-...}, at: [<c0357168>] DWC_SPINLOCK_IRQSAVE+0xc/0x14 [ 3.830932] [ 3.830932] but task is already holding lock: [ 3.839274] (&(sl)->rlock){-.-...}, at: [<c0357168>] DWC_SPINLOCK_IRQSAVE+0xc/0x14 [ 3.849704] [ 3.849704] other info that might help us debug this: [ 3.858826] Possible unsafe locking scenario: [ 3.858826] [ 3.867334] CPU0 [ 3.871052] ---- [ 3.874721] lock(&(sl)->rlock); [ 3.879302] lock(&(sl)->rlock); [ 3.883815] [ 3.883815] *** DEADLOCK *** [ 3.883815] [ 3.892869] May be due to missing lock nesting notation [ 3.892869] [ 3.901736] 4 locks held by khubd/18: [ 3.906438] #0: (&dev->mutex){......}, at: [<c0321da8>] hub_thread+0x98/0x1000 [ 3.916026] raspberrypi#1: (&port_dev->status_lock){+.+.+.}, at: [<c032234c>] hub_thread+0x63c/0x1000 [ 3.926847] raspberrypi#2: (&bus->usb_address0_mutex){+.+.+.}, at: [<c031f164>] hub_port_init+0x5c/0xb24 [ 3.938015] raspberrypi#3: (&(sl)->rlock){-.-...}, at: [<c0357168>] DWC_SPINLOCK_IRQSAVE+0xc/0x14 [ 3.948730] [ 3.948730] stack backtrace: [ 3.955457] CPU: 0 PID: 18 Comm: khubd Not tainted 3.16.1+ raspberrypi#5 [ 3.962541] [<c00137e4>] (unwind_backtrace) from [<c0011530>] (show_stack+0x10/0x14) [ 3.972998] [<c0011530>] (show_stack) from [<c005985c>] (__lock_acquire+0x1420/0x1ae0) [ 3.983910] [<c005985c>] (__lock_acquire) from [<c005a6c8>] (lock_acquire+0x6c/0x8c) [ 3.994908] [<c005a6c8>] (lock_acquire) from [<c04a872c>] (_raw_spin_lock_irqsave+0x50/0x64) [ 4.006756] [<c04a872c>] (_raw_spin_lock_irqsave) from [<c0357168>] (DWC_SPINLOCK_IRQSAVE+0xc/0x14) [ 4.019382] [<c0357168>] (DWC_SPINLOCK_IRQSAVE) from [<c034ba9c>] (dwc_otg_hcd_select_transactions+0x20c/0x368) [ 4.033064] [<c034ba9c>] (dwc_otg_hcd_select_transactions) from [<c034c0f8>] (dwc_otg_hcd_urb_enqueue+0x158/0x1ec) [ 4.047017] [<c034c0f8>] (dwc_otg_hcd_urb_enqueue) from [<c034d8a0>] (dwc_otg_urb_enqueue+0x1a8/0x2e0) [ 4.059889] [<c034d8a0>] (dwc_otg_urb_enqueue) from [<c03258e4>] (usb_hcd_submit_urb+0xb8/0x870) [ 4.072316] [<c03258e4>] (usb_hcd_submit_urb) from [<c03276a0>] (usb_start_wait_urb+0x44/0xbc) [ 4.084786] [<c03276a0>] (usb_start_wait_urb) from [<c03277cc>] (usb_control_msg+0xb4/0xec) [ 4.097045] [<c03277cc>] (usb_control_msg) from [<c031f528>] (hub_port_init+0x420/0xb24) [ 4.109018] [<c031f528>] (hub_port_init) from [<c0322360>] (hub_thread+0x650/0x1000) [ 4.120667] [<c0322360>] (hub_thread) from [<c003ec3c>] (kthread+0xc8/0xe4) [ 4.129668] [<c003ec3c>] (kthread) from [<c000e128>] (ret_from_fork+0x14/0x2c) This is false positive because the lockdep uses the lock variable name to keep track of locks. To fix this, the spin_lock_init function can't be in a wrapper function for spinlock name to recorder correctly. I noticed similar fix was already made for mutex debugging so used similar approach and added extra macro to be used to spinlock allocation when spinlock debugging is on. Signed-off-by: Kari Suvanto <karis79@gmail.com>
1 parent 56f577f commit babaed9

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎drivers/usb/host/dwc_common_port/dwc_common_linux.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,11 @@ dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
766766
goto no_name;
767767
}
768768

769+
#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
770+
DWC_SPINLOCK_ALLOC_LINUX_DEBUG(t->lock);
771+
#else
769772
t->lock = DWC_SPINLOCK_ALLOC();
773+
#endif
770774
if (!t->lock) {
771775
DWC_ERROR("Cannot allocate memory for lock");
772776
goto no_lock;
@@ -1083,7 +1087,11 @@ dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
10831087

10841088
wq->pending = 0;
10851089

1090+
#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
1091+
DWC_SPINLOCK_ALLOC_LINUX_DEBUG(wq->lock);
1092+
#else
10861093
wq->lock = DWC_SPINLOCK_ALLOC();
1094+
#endif
10871095
if (!wq->lock) {
10881096
goto no_lock;
10891097
}

‎drivers/usb/host/dwc_common_port/dwc_os.h‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extern "C" {
5959
# ifdef CONFIG_DEBUG_MUTEXES
6060
# include <linux/mutex.h>
6161
# endif
62+
# include <linux/spinlock.h>
6263
# include <linux/errno.h>
6364
# include <stdarg.h>
6465
#endif
@@ -1039,9 +1040,22 @@ typedef unsigned long dwc_irqflags_t;
10391040
/** Returns an initialized lock variable. This function should allocate and
10401041
* initialize the OS-specific data structure used for locking. This data
10411042
* structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
1042-
* be freed by the DWC_FREE_LOCK when it is no longer used. */
1043+
* be freed by the DWC_FREE_LOCK when it is no longer used.
1044+
*
1045+
* For Linux Spinlock Debugging make it macro because the debugging routines use
1046+
* the symbol name to determine recursive locking. Using a wrapper function
1047+
* makes it falsely think recursive locking occurs. */
1048+
#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK)
1049+
#define DWC_SPINLOCK_ALLOC_LINUX_DEBUG(lock) ({ \
1050+
lock = DWC_ALLOC(sizeof(spinlock_t)); \
1051+
if (lock) { \
1052+
spin_lock_init((spinlock_t *)lock); \
1053+
} \
1054+
})
1055+
#else
10431056
extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
10441057
#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
1058+
#endif
10451059

10461060
/** Frees an initialized lock variable. */
10471061
extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);

‎drivers/usb/host/dwc_otg/dwc_otg_hcd.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,13 @@ int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
951951
int i;
952952
dwc_hc_t *channel;
953953

954+
#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
955+
DWC_SPINLOCK_ALLOC_LINUX_DEBUG(hcd->lock);
956+
DWC_SPINLOCK_ALLOC_LINUX_DEBUG(hcd->channel_lock);
957+
#else
954958
hcd->lock = DWC_SPINLOCK_ALLOC();
955959
hcd->channel_lock = DWC_SPINLOCK_ALLOC();
960+
#endif
956961
DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
957962
hcd, core_if);
958963
if (!hcd->lock) {

‎drivers/usb/host/dwc_otg/dwc_otg_pcd.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,11 @@ dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
11201120
return NULL;
11211121
}
11221122

1123+
#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
1124+
DWC_SPINLOCK_ALLOC_LINUX_DEBUG(pcd->lock);
1125+
#else
11231126
pcd->lock = DWC_SPINLOCK_ALLOC();
1127+
#endif
11241128
DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
11251129
pcd, core_if);//GRAYG
11261130
if (!pcd->lock) {

0 commit comments

Comments
 (0)