Re: single-threaded wq lockdep is broken

From: Tejun Heo
Date: Tue Jun 13 2017 - 12:06:25 EST


Hello,

Johannes reported that lockdep warning on single threaded workqueues
doesn't work anymore. Nothing really changed there and all the
relevant lockdep annotaitons are being invoked correctly. The
following is the extracted lockdep-only reproducer.

The culprit seems to be lock_map_acquire_read() being mapped to
lock_map_acquire_shared_recursive() instead of
lock_map_acquire_shared(). Is the following expected to not trigger
lockdep warning? Should workqueue be using
rwsem_acquire[_read]/release() instead of lock_map*()?

Thanks.

#include <linux/kernel.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/module.h>

DEFINE_MUTEX(mtx);

static int init(void)
{
static struct lock_class_key key;
struct lockdep_map *map;

printk("XXX lockdep test start\n");

map = kzalloc(sizeof(*map), GFP_KERNEL);
lockdep_init_map(map, "test_map", &key, 0);

mutex_lock(&mtx);
lock_map_acquire(map);
lock_map_release(map);
mutex_unlock(&mtx);

lock_map_acquire_read(map);
mutex_lock(&mtx);
mutex_unlock(&mtx);
lock_map_release(map);

printk("XXX lockdep test end\n");
return 0;
}
module_init(init);