mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
introduce __fcheck_files() to fix rcu_dereference_check_fdtable(), kill rcu_my_thread_group_empty()
rcu_dereference_check_fdtable() looks very wrong,
1. rcu_my_thread_group_empty() was added by 844b9a8707 "vfs: fix
RCU-lockdep false positive due to /proc" but it doesn't really
fix the problem. A CLONE_THREAD (without CLONE_FILES) task can
hit the same race with get_files_struct().
And otoh rcu_my_thread_group_empty() can suppress the correct
warning if the caller is the CLONE_FILES (without CLONE_THREAD)
task.
2. files->count == 1 check is not really right too. Even if this
files_struct is not shared it is not safe to access it lockless
unless the caller is the owner.
Otoh, this check is sub-optimal. files->count == 0 always means
it is safe to use it lockless even if files != current->files,
but put_files_struct() has to take rcu_read_lock(). See the next
patch.
This patch removes the buggy checks and turns fcheck_files() into
__fcheck_files() which uses rcu_dereference_raw(), the "unshared"
callers, fget_light() and fget_raw_light(), can use it to avoid
the warning from RCU-lockdep.
fcheck_files() is trivially reimplemented as rcu_lockdep_assert()
plus __fcheck_files().
Signed-off-by: Oleg Nesterov <[email protected]>
Signed-off-by: Al Viro <[email protected]>
This commit is contained in:
parent
2ccdc41319
commit
a8d4b8345e
4 changed files with 23 additions and 29 deletions
|
|
@ -707,7 +707,7 @@ struct file *fget_light(unsigned int fd, int *fput_needed)
|
|||
|
||||
*fput_needed = 0;
|
||||
if (atomic_read(&files->count) == 1) {
|
||||
file = fcheck_files(files, fd);
|
||||
file = __fcheck_files(files, fd);
|
||||
if (file && (file->f_mode & FMODE_PATH))
|
||||
file = NULL;
|
||||
} else {
|
||||
|
|
@ -735,7 +735,7 @@ struct file *fget_raw_light(unsigned int fd, int *fput_needed)
|
|||
|
||||
*fput_needed = 0;
|
||||
if (atomic_read(&files->count) == 1) {
|
||||
file = fcheck_files(files, fd);
|
||||
file = __fcheck_files(files, fd);
|
||||
} else {
|
||||
rcu_read_lock();
|
||||
file = fcheck_files(files, fd);
|
||||
|
|
|
|||
Loading…
Reference in a new issue