mbox series

[0/6] fs: deduplicate compat logic

Message ID 20210112003017.4010304-1-willemdebruijn.kernel@gmail.com (mailing list archive)
Headers show
Series fs: deduplicate compat logic | expand

Message

Willem de Bruijn Jan. 12, 2021, 12:30 a.m. UTC
From: Willem de Bruijn <willemb@google.com>

Use in_compat_syscall() to differentiate compat handling exactly
where needed, including in nested function calls. Then remove
duplicated code in callers.

Changes
  RFC[1]->v1
  - remove kselftest dependency on variant support in teardown
    (patch is out for review, not available in linux-next/akpm yet)
  - add patch 5: deduplicate set_user_sigmask compat handling
  - add patch 6: deduplicate io_pgetevents sigmask compat handling

[1] RFC: https://github.com/wdebruij/linux-next-mirror/tree/select-compat-1

Willem de Bruijn (6):
  selftests/filesystems: add initial select and poll selftest
  select: deduplicate compat logic
  ppoll: deduplicate compat logic
  epoll: deduplicate compat logic
  compat: add set_maybe_compat_user_sigmask helper
  io_pgetevents: deduplicate compat logic

 fs/aio.c                                      |  94 ++---
 fs/eventpoll.c                                |  35 +-
 fs/io_uring.c                                 |   9 +-
 fs/select.c                                   | 339 +++++-------------
 include/linux/compat.h                        |  10 +
 .../testing/selftests/filesystems/.gitignore  |   1 +
 tools/testing/selftests/filesystems/Makefile  |   2 +-
 .../selftests/filesystems/selectpoll.c        | 207 +++++++++++
 8 files changed, 344 insertions(+), 353 deletions(-)
 create mode 100644 tools/testing/selftests/filesystems/selectpoll.c

Comments

Al Viro Jan. 12, 2021, 12:58 a.m. UTC | #1
On Mon, Jan 11, 2021 at 07:30:11PM -0500, Willem de Bruijn wrote:
> From: Willem de Bruijn <willemb@google.com>
> 
> Use in_compat_syscall() to differentiate compat handling exactly
> where needed, including in nested function calls. Then remove
> duplicated code in callers.

IMO it's a bad idea.  Use of in_compat_syscall() is hard to avoid
in some cases, but let's not use it without a good reason.  It
makes the code harder to reason about.
Willem de Bruijn Jan. 12, 2021, 1:16 a.m. UTC | #2
On Mon, Jan 11, 2021 at 7:58 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> On Mon, Jan 11, 2021 at 07:30:11PM -0500, Willem de Bruijn wrote:
> > From: Willem de Bruijn <willemb@google.com>
> >
> > Use in_compat_syscall() to differentiate compat handling exactly
> > where needed, including in nested function calls. Then remove
> > duplicated code in callers.
>
> IMO it's a bad idea.  Use of in_compat_syscall() is hard to avoid
> in some cases, but let's not use it without a good reason.  It
> makes the code harder to reason about.

In the specific cases of select, poll and epoll, this removes quite a
bit of duplicate code that may diverge over time. Indeed, for select
already has. Reduction of duplication may also make subsequent changes
more feasible. We discussed avoiding in epoll an unnecessary
ktime_get_ts64 in select_estimate_accuracy, which requires plumbing a
variable through these intermediate helpers.

I also personally find the code simpler to understand without the
various near duplicates. The change exposes their differences
more clearly. select is the best example of this.

The last two patches I added based on earlier comments. Perhaps
the helper in 5 adds more churn than it's worth.