proc/fd: In proc_fd_link use fget_task
authorEric W. Biederman <ebiederm@xmission.com>
Fri, 20 Nov 2020 23:14:23 +0000 (17:14 -0600)
committerEric W. Biederman <ebiederm@xmission.com>
Thu, 10 Dec 2020 18:39:48 +0000 (12:39 -0600)
commit439be32656035d3239fd56f9b83353ec06cb3b45
tree019377cd0b079b710aded2fdec028ed85016e455
parentb48845af0152d790a54b8ab78cc2b7c07485fc98
proc/fd: In proc_fd_link use fget_task

When discussing[1] exec and posix file locks it was realized that none
of the callers of get_files_struct fundamentally needed to call
get_files_struct, and that by switching them to helper functions
instead it will both simplify their code and remove unnecessary
increments of files_struct.count.  Those unnecessary increments can
result in exec unnecessarily unsharing files_struct which breaking
posix locks, and it can result in fget_light having to fallback to
fget reducing system performance.

Simplifying proc_fd_link is a little bit tricky.  It is necessary to
know that there is a reference to fd_f  ile while path_get is running.
This reference can either be guaranteed to exist either by locking the
fdtable as the code currently does or by taking a reference on the
file in question.

Use fget_task to remove the need for get_files_struct and
to take a reference to file in question.

[1] https://lkml.kernel.org/r/20180915160423.GA31461@redhat.com
Suggested-by: Oleg Nesterov <oleg@redhat.com>
v1: https://lkml.kernel.org/r/20200817220425.9389-8-ebiederm@xmission.com
Link: https://lkml.kernel.org/r/20201120231441.29911-6-ebiederm@xmission.com
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
fs/proc/fd.c