Linux USB
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: syzkaller <syzkaller@googlegroups.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	USB list <linux-usb@vger.kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Hillf Danton <hdanton@sina.com>
Subject: Re: [PATCH] drivers/core: Replace lockdep_set_novalidate_class() with unique class keys
Date: Wed, 8 Feb 2023 10:07:34 -0500	[thread overview]
Message-ID: <Y+O6toMmAKBSILMf@rowland.harvard.edu> (raw)
In-Reply-To: <1ad499bb-0c53-7529-ff00-e4328823f6fa@I-love.SAKURA.ne.jp>

On Wed, Feb 08, 2023 at 07:30:25PM +0900, Tetsuo Handa wrote:
> Commit 1704f47b50b5 ("lockdep: Add novalidate class for dev->mutex
> conversion") made it impossible to find real deadlocks unless timing
> dependent testings manage to trigger hung task like [1] and [2]. And
> lockdep_set_novalidate_class() remained for more than one decade due to
> a fear of false positives [3]. But not sharing mutex_init() could make
> it possible to find real deadlocks without triggering hung task [4].
> Thus, let's assign a unique class key on each "struct device"->mutex.
> 
> Link: https://syzkaller.appspot.com/bug?extid=2d6ac90723742279e101 [1]
> Link: https://syzkaller.appspot.com/bug?extid=2e39bc6569d281acbcfb [2]
> Link: https://lkml.kernel.org/r/Y98FLlr7jkiFlV0k@rowland.harvard.edu [3]
> Link: https://lkml.kernel.org/r/827177aa-bb64-87a9-e1af-dfe070744045@I-love.SAKURA.ne.jp [4]
> Suggested-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Co-developed-by: Alan Stern <stern@rowland.harvard.edu>
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

You must never do this!

I did not put my Signed-off-by: on the patch I sent to you.  I do not 
want it added to that patch or to this one.  You should never put 
somebody else's Signed-off-by: on a patch unless they tell you it's okay 
to do so.

I'm happy to have people test this patch, but I do not want anybody 
think that it is ready to be merged into the kernel.

> Co-developed-by: Hillf Danton <hdanton@sina.com>
> Signed-off-by: Hillf Danton <hdanton@sina.com>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> ---
> Hello, syzkaller users.
> 
> We made a patch that keeps lockdep validation enabled on "struct dev->mutex".
> Will you try this patch and see if this patch causes boot failures and/or
> too frequent crashes to continue testing.
> 
>  drivers/base/core.c      | 7 ++++++-
>  include/linux/device.h   | 1 +
>  include/linux/lockdep.h  | 6 ++++++
>  kernel/locking/lockdep.c | 7 +++++++
>  4 files changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index a3e14143ec0c..c30ecbc4d60e 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -2322,6 +2322,9 @@ static void device_release(struct kobject *kobj)
>  	devres_release_all(dev);
>  
>  	kfree(dev->dma_range_map);
> +	mutex_destroy(&dev->mutex);
> +	if (!lockdep_static_obj(dev))
> +		lockdep_unregister_key(&dev->mutex_key);
>  
>  	if (dev->release)
>  		dev->release(dev);
> @@ -2941,7 +2944,9 @@ void device_initialize(struct device *dev)
>  	kobject_init(&dev->kobj, &device_ktype);
>  	INIT_LIST_HEAD(&dev->dma_pools);
>  	mutex_init(&dev->mutex);
> -	lockdep_set_novalidate_class(&dev->mutex);
> +	if (!lockdep_static_obj(dev))
> +		lockdep_register_key(&dev->mutex_key);
> +	lockdep_set_class(&dev->mutex, &dev->mutex_key);
>  	spin_lock_init(&dev->devres_lock);
>  	INIT_LIST_HEAD(&dev->devres_head);
>  	device_pm_init(dev);
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 44e3acae7b36..bdaca9f54dc2 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -570,6 +570,7 @@ struct device {
>  	struct mutex		mutex;	/* mutex to synchronize calls to
>  					 * its driver.
>  					 */
> +	struct lock_class_key	mutex_key;	/* Unique key for each device */
>  
>  	struct dev_links_info	links;
>  	struct dev_pm_info	power;
> diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
> index 1f1099dac3f0..5afc999a7e56 100644
> --- a/include/linux/lockdep.h
> +++ b/include/linux/lockdep.h
> @@ -172,6 +172,7 @@ do {							\
>  	current->lockdep_recursion -= LOCKDEP_OFF;	\
>  } while (0)
>  
> +extern int lockdep_static_obj(const void *obj);
>  extern void lockdep_register_key(struct lock_class_key *key);
>  extern void lockdep_unregister_key(struct lock_class_key *key);
>  
> @@ -391,6 +392,11 @@ static inline void lockdep_set_selftest_task(struct task_struct *task)
>  # define lockdep_free_key_range(start, size)	do { } while (0)
>  # define lockdep_sys_exit() 			do { } while (0)
>  
> +static inline int lockdep_static_obj(const void *obj)
> +{
> +	return 0;
> +}
> +
>  static inline void lockdep_register_key(struct lock_class_key *key)
>  {
>  }
> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> index e3375bc40dad..74c0113646f1 100644
> --- a/kernel/locking/lockdep.c
> +++ b/kernel/locking/lockdep.c
> @@ -857,6 +857,13 @@ static int static_obj(const void *obj)
>  	 */
>  	return is_module_address(addr) || is_module_percpu_address(addr);
>  }
> +
> +int lockdep_static_obj(const void *obj)
> +{
> +	return static_obj(obj);
> +}
> +EXPORT_SYMBOL_GPL(lockdep_static_obj);

What's the point of adding a new function that just calls the old 
function?  Why not simply rename the old function?

Alan Stern

> +
>  #endif
>  
>  /*
> -- 
> 2.34.1
> 

  reply	other threads:[~2023-02-08 15:07 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-04 13:32 Converting dev->mutex into dev->spinlock ? Tetsuo Handa
2023-02-04 13:47 ` Greg Kroah-Hartman
2023-02-04 14:21   ` Tetsuo Handa
2023-02-04 14:34     ` Greg Kroah-Hartman
2023-02-04 15:16       ` Tetsuo Handa
2023-02-04 15:34     ` Alan Stern
2023-02-04 16:12       ` Tetsuo Handa
2023-02-04 16:27         ` Alan Stern
2023-02-04 17:09           ` Tetsuo Handa
2023-02-04 20:01             ` Alan Stern
2023-02-04 20:14               ` Linus Torvalds
2023-02-05  1:23                 ` Alan Stern
2023-02-06 14:13                   ` Tetsuo Handa
2023-02-06 15:45                     ` Alan Stern
2023-02-07 13:07                       ` Tetsuo Handa
2023-02-07 17:46                         ` Alan Stern
2023-02-07 22:17                           ` Tetsuo Handa
2023-02-08  0:34                             ` Alan Stern
     [not found]                             ` <20230208080739.1649-1-hdanton@sina.com>
2023-02-08 10:30                               ` [PATCH] drivers/core: Replace lockdep_set_novalidate_class() with unique class keys Tetsuo Handa
2023-02-08 15:07                                 ` Alan Stern [this message]
2023-02-09  0:22                                   ` Tetsuo Handa
2023-02-09  0:46                                     ` Linus Torvalds
2023-02-09  1:50                                       ` Tetsuo Handa
2023-02-09  2:26                                     ` Alan Stern
2023-02-11  2:04                                       ` Tetsuo Handa
2023-02-11 21:41                                         ` [PATCH RFC] " Alan Stern
2023-02-11 21:51                                           ` Linus Torvalds
2023-02-11 23:06                                             ` Kent Overstreet
2023-02-11 23:08                                               ` Kent Overstreet
2023-02-11 23:24                                               ` Kent Overstreet
2023-02-12  2:40                                                 ` Alan Stern
2023-02-12  2:46                                                   ` Kent Overstreet
2023-02-12  3:03                                                     ` Alan Stern
2023-02-12  3:10                                                       ` Kent Overstreet
2023-02-12 15:23                                                         ` Alan Stern
2023-02-12 19:14                                                           ` Kent Overstreet
2023-02-12 20:19                                                             ` Alan Stern
2023-02-12 20:51                                                               ` Kent Overstreet
2023-02-13  1:23                                                                 ` Alan Stern
2023-02-13  2:21                                                                   ` Kent Overstreet
2023-02-13 15:25                                                                     ` Alan Stern
2023-02-13  9:29                                                                 ` Peter Zijlstra
2023-02-13  9:27                                                               ` Peter Zijlstra
2023-02-13 15:28                                                                 ` Alan Stern
2023-02-13 16:36                                                                   ` Peter Zijlstra
2023-02-13  9:24                                                           ` Peter Zijlstra
2023-02-13 15:25                                                             ` Alan Stern
2023-02-13 16:29                                                               ` Peter Zijlstra
2023-02-14  1:51                                                                 ` Boqun Feng
2023-02-14  1:53                                                                   ` Boqun Feng
2023-02-14  2:03                                                                   ` Alan Stern
2023-02-14  2:09                                                                     ` Boqun Feng
     [not found]                                                                     ` <20230214052733.3354-1-hdanton@sina.com>
2023-02-14  5:55                                                                       ` Boqun Feng
2023-02-14 10:48                                                                   ` Peter Zijlstra
2023-02-14 16:22                                                                     ` Boqun Feng
2023-02-15 10:45                                                                       ` Peter Zijlstra
2023-02-20 17:32                                                                         ` Boqun Feng
2023-02-13 18:46                                                             ` Kent Overstreet
2023-02-14 11:05                                                               ` Peter Zijlstra
2023-02-14 20:05                                                                 ` Alan Stern
2023-02-15 10:33                                                                   ` Peter Zijlstra
2023-02-14 20:16                                                                 ` Kent Overstreet
     [not found]                                               ` <20230212013220.2678-1-hdanton@sina.com>
2023-02-12  1:52                                                 ` Kent Overstreet
2023-02-13  9:49                                           ` Peter Zijlstra
2023-02-13 16:18                                             ` Alan Stern
2023-02-13 17:51                                               ` Greg Kroah-Hartman
2023-02-13 18:05                                                 ` Alan Stern
2023-02-05  1:31               ` Converting dev->mutex into dev->spinlock ? Tetsuo Handa
2023-02-05 16:46                 ` Alan Stern
     [not found]                 ` <20230206025629.1786-1-hdanton@sina.com>
2023-02-06  4:44                   ` Matthew Wilcox
2023-02-06  5:17                   ` Greg Kroah-Hartman
     [not found]                   ` <20230206064305.1838-1-hdanton@sina.com>
2023-02-06  6:48                     ` Greg Kroah-Hartman
2023-02-04 15:12 ` Alan Stern
2023-02-04 15:30   ` Tetsuo Handa
2023-02-04 15:40     ` Alan Stern

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=Y+O6toMmAKBSILMf@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=dvyukov@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdanton@sina.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    --cc=syzkaller@googlegroups.com \
    --cc=torvalds@linux-foundation.org \
    /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