Skip to content

Commit

Permalink
lockdep: change a held lock's class
Browse files Browse the repository at this point in the history
Impact: introduce new lockdep API

Allow to change a held lock's class. Basically the same as the existing
code to change a subclass therefore reuse all that.

The XFS code will be able to use this to annotate their inode locking.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Dec 4, 2008
1 parent cb9c34e commit 00ef9f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
12 changes: 10 additions & 2 deletions include/linux/lockdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,15 @@ extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
extern void lock_release(struct lockdep_map *lock, int nested,
unsigned long ip);

extern void lock_set_subclass(struct lockdep_map *lock, unsigned int subclass,
unsigned long ip);
extern void lock_set_class(struct lockdep_map *lock, const char *name,
struct lock_class_key *key, unsigned int subclass,
unsigned long ip);

static inline void lock_set_subclass(struct lockdep_map *lock,
unsigned int subclass, unsigned long ip)
{
lock_set_class(lock, lock->name, lock->key, subclass, ip);
}

# define INIT_LOCKDEP .lockdep_recursion = 0,

Expand All @@ -333,6 +340,7 @@ static inline void lockdep_on(void)

# define lock_acquire(l, s, t, r, c, n, i) do { } while (0)
# define lock_release(l, n, i) do { } while (0)
# 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_info() do { } while (0)
Expand Down
24 changes: 9 additions & 15 deletions kernel/lockdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,12 @@ void lockdep_off(void)
{
current->lockdep_recursion++;
}

EXPORT_SYMBOL(lockdep_off);

void lockdep_on(void)
{
current->lockdep_recursion--;
}

EXPORT_SYMBOL(lockdep_on);

/*
Expand Down Expand Up @@ -2513,7 +2511,6 @@ void lockdep_init_map(struct lockdep_map *lock, const char *name,
if (subclass)
register_lock_class(lock, subclass, 1);
}

EXPORT_SYMBOL_GPL(lockdep_init_map);

/*
Expand Down Expand Up @@ -2694,8 +2691,9 @@ static int check_unlock(struct task_struct *curr, struct lockdep_map *lock,
}

static int
__lock_set_subclass(struct lockdep_map *lock,
unsigned int subclass, unsigned long ip)
__lock_set_class(struct lockdep_map *lock, const char *name,
struct lock_class_key *key, unsigned int subclass,
unsigned long ip)
{
struct task_struct *curr = current;
struct held_lock *hlock, *prev_hlock;
Expand All @@ -2722,6 +2720,7 @@ __lock_set_subclass(struct lockdep_map *lock,
return print_unlock_inbalance_bug(curr, lock, ip);

found_it:
lockdep_init_map(lock, name, key, 0);
class = register_lock_class(lock, subclass, 0);
hlock->class_idx = class - lock_classes + 1;

Expand Down Expand Up @@ -2906,9 +2905,9 @@ static void check_flags(unsigned long flags)
#endif
}

void
lock_set_subclass(struct lockdep_map *lock,
unsigned int subclass, unsigned long ip)
void lock_set_class(struct lockdep_map *lock, const char *name,
struct lock_class_key *key, unsigned int subclass,
unsigned long ip)
{
unsigned long flags;

Expand All @@ -2918,13 +2917,12 @@ lock_set_subclass(struct lockdep_map *lock,
raw_local_irq_save(flags);
current->lockdep_recursion = 1;
check_flags(flags);
if (__lock_set_subclass(lock, subclass, ip))
if (__lock_set_class(lock, name, key, subclass, ip))
check_chain_key(current);
current->lockdep_recursion = 0;
raw_local_irq_restore(flags);
}

EXPORT_SYMBOL_GPL(lock_set_subclass);
EXPORT_SYMBOL_GPL(lock_set_class);

/*
* We are not always called with irqs disabled - do that here,
Expand All @@ -2948,7 +2946,6 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
current->lockdep_recursion = 0;
raw_local_irq_restore(flags);
}

EXPORT_SYMBOL_GPL(lock_acquire);

void lock_release(struct lockdep_map *lock, int nested,
Expand All @@ -2966,7 +2963,6 @@ void lock_release(struct lockdep_map *lock, int nested,
current->lockdep_recursion = 0;
raw_local_irq_restore(flags);
}

EXPORT_SYMBOL_GPL(lock_release);

#ifdef CONFIG_LOCK_STAT
Expand Down Expand Up @@ -3451,7 +3447,6 @@ void debug_show_all_locks(void)
if (unlock)
read_unlock(&tasklist_lock);
}

EXPORT_SYMBOL_GPL(debug_show_all_locks);

/*
Expand All @@ -3472,7 +3467,6 @@ void debug_show_held_locks(struct task_struct *task)
{
__debug_show_held_locks(task);
}

EXPORT_SYMBOL_GPL(debug_show_held_locks);

void lockdep_sys_exit(void)
Expand Down

0 comments on commit 00ef9f7

Please sign in to comment.