Commit Graph

993401 Commits

Author SHA1 Message Date
Greg Kroah-Hartman
d369ac0b2a ANDROID: add flags variable back to struct proto_ops
In commit a3025359ff ("net: remove cmsg restriction from io_uring
based send/recvmsg calls") the flags variable was removed from struct
proto_ops as it is no longer needed.

But the ABI signatures break, so put it back to preserve this, there's
no functional change here.

Bug: 161946584
Bug: 268174392
Fixes: a3025359ff ("net: remove cmsg restriction from io_uring based send/recvmsg calls")
Change-Id: Ic6a868f038701a61c993e18b44cdd8ec8b0a4d58
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:16 +00:00
Jens Axboe
5756328b3f UPSTREAM: io_uring: pass in EPOLL_URING_WAKE for eventfd signaling and wakeups
[ Upstream commit 4464853277 ]

Pass in EPOLL_URING_WAKE when signaling eventfd or doing poll related
wakups, so that we can check for a circular event dependency between
eventfd and epoll. If this flag is set when our wakeup handlers are
called, then we know we have a dependency that needs to terminate
multishot requests.

eventfd and epoll are the only such possible dependencies.

Bug: 268174392
Cc: stable@vger.kernel.org # 6.0
Change-Id: I6e45fa1484657bd5caad007783785c2ee97a9929
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 189556b05e)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:16 +00:00
Jens Axboe
72d1c48675 UPSTREAM: eventfd: provide a eventfd_signal_mask() helper
[ Upstream commit 03e02acda8 ]

This is identical to eventfd_signal(), but it allows the caller to pass
in a mask to be used for the poll wakeup key. The use case is avoiding
repeated multishot triggers if we have a dependency between eventfd and
io_uring.

If we setup an eventfd context and register that as the io_uring eventfd,
and at the same time queue a multishot poll request for the eventfd
context, then any CQE posted will repeatedly trigger the multishot request
until it terminates when the CQ ring overflows.

In preparation for io_uring detecting this circular dependency, add the
mentioned helper so that io_uring can pass in EPOLL_URING as part of the
poll wakeup key.

Cc: stable@vger.kernel.org # 6.0
[axboe: fold in !CONFIG_EVENTFD fix from Zhang Qilong]
Change-Id: I0c38a56887777f85cb10673b7ca3b5ca4d70c61b
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 4ef66581d7)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:16 +00:00
Jens Axboe
d7a47b29d5 UPSTREAM: eventpoll: add EPOLL_URING_WAKE poll wakeup flag
[ Upstream commit caf1aeaffc ]

We can have dependencies between epoll and io_uring. Consider an epoll
context, identified by the epfd file descriptor, and an io_uring file
descriptor identified by iofd. If we add iofd to the epfd context, and
arm a multishot poll request for epfd with iofd, then the multishot
poll request will repeatedly trigger and generate events until terminated
by CQ ring overflow. This isn't a desired behavior.

Add EPOLL_URING so that io_uring can pass it in as part of the poll wakeup
key, and io_uring can check for that to detect a potential recursive
invocation.

Cc: stable@vger.kernel.org # 6.0
Change-Id: Ifafcb236b2cfe3ca3e7254a0155625fce00fd038
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 2f09377502)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:16 +00:00
Jens Axboe
7c9f38c09b UPSTREAM: Revert "proc: don't allow async path resolution of /proc/self components"
[ Upstream commit 9e8d9e829c ]

This reverts commit 8d4c3e76e3.

No longer needed, as the io-wq worker threads have the right identity.

Change-Id: I6c12f6f957e1c789f4fd5b21379d167f17feb3ea
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit b76c5373f0)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:15 +00:00
Jens Axboe
498b35b3c4 UPSTREAM: Revert "proc: don't allow async path resolution of /proc/thread-self components"
[ Upstream commit 2587890b5e ]

This reverts commit 0d4370cfe3.

No longer needed, as the io-wq worker threads have the right identity.

Change-Id: I7a28e02a0a1911555853cf4046e3a09c7e36d4a2
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 87cb08dc6b)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:15 +00:00
Jens Axboe
4b17dea786 UPSTREAM: net: remove cmsg restriction from io_uring based send/recvmsg calls
[ Upstream commit e54937963f ]

No need to restrict these anymore, as the worker threads are direct
clones of the original task. Hence we know for a fact that we can
support anything that the regular task can.

Since the only user of proto_ops->flags was to flag PROTO_CMSG_DATA_ONLY,
kill the member and the flag definition too.

Change-Id: Ie87e4ff3c621cf53a8e9589a7689e62d759de983
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit a3025359ff)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:15 +00:00
Jens Axboe
d10f30da0d UPSTREAM: task_work: unconditionally run task_work from get_signal()
[ Upstream commit 35d0b389f3 ]

Song reported a boot regression in a kvm image with 5.11-rc, and bisected
it down to the below patch. Debugging this issue, turns out that the boot
stalled when a task is waiting on a pipe being released. As we no longer
run task_work from get_signal() unless it's queued with TWA_SIGNAL, the
task goes idle without running the task_work. This prevents ->release()
from being called on the pipe, which another boot task is waiting on.

For now, re-instate the unconditional task_work run from get_signal().
For 5.12, we'll collapse TWA_RESUME and TWA_SIGNAL, as it no longer
makes sense to have a distinction between the two. This will turn
task_work notification into a simple boolean, whether to notify or not.

Fixes: 98b89b649f ("signal: kill JOBCTL_TASK_WORK")
Reported-by: Song Liu <songliubraving@fb.com>
Tested-by: John Stultz <john.stultz@linaro.org>
Tested-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang version 11.0.1
Change-Id: Id5ce292120cafff9ede9bb7421cde3aaf4e56924
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 6ef2b4728a)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:15 +00:00
Jens Axboe
62822bf630 UPSTREAM: signal: kill JOBCTL_TASK_WORK
[ Upstream commit 98b89b649f ]

It's no longer used, get rid of it.

Change-Id: Id14379554f3e1085c63ac4d044618f609ebc2f9f
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit c91ab04781)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:15 +00:00
Jens Axboe
5e6347b586 UPSTREAM: io_uring: import 5.15-stable io_uring
No upstream commit exists.

This imports the io_uring codebase from 5.15.85, wholesale. Changes
from that code base:

- Drop IOCB_ALLOC_CACHE, we don't have that in 5.10.
- Drop MKDIRAT/SYMLINKAT/LINKAT. Would require further VFS backports,
  and we don't support these in 5.10 to begin with.
- sock_from_file() old style calling convention.
- Use compat_get_bitmap() only for CONFIG_COMPAT=y

Change-Id: I7ce5226d6b39763ffc246fd6357cece9aafd4b59
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 788d082426)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:15 +00:00
Jens Axboe
518e02ed06 UPSTREAM: task_work: add helper for more targeted task_work canceling
[ Upstream commit c7aab1a7c5 ]

The only exported helper we have right now is task_work_cancel(), which
cancels any task_work from a given task where func matches the queued
work item. This is a bit too coarse for some use cases. Add a
task_work_cancel_match() that allows to more specifically target
individual work items outside of purely the callback function used.

task_work_cancel() can be trivially implemented on top of that, hence do
so.

Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Change-Id: Ia33480d209b26d433a3ca196972d6931aa4f8dde
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit ed30050329)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:15 +00:00
Jens Axboe
86acb6a529 UPSTREAM: kernel: don't call do_exit() for PF_IO_WORKER threads
[ Upstream commit 10442994ba ]

Right now we're never calling get_signal() from PF_IO_WORKER threads, but
in preparation for doing so, don't handle a fatal signal for them. The
workers have state they need to cleanup when exiting, so just return
instead of calling do_exit() on their behalf. The threads themselves will
detect a fatal signal and do proper shutdown.

Change-Id: Iedc3fae8cb496d003852c87fdefacc1ad7601cc5
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 831cb78a2a)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:14 +00:00
Jens Axboe
52f564e57b UPSTREAM: kernel: stop masking signals in create_io_thread()
[ Upstream commit b16b3855d8 ]

This is racy - move the blocking into when the task is created and
we're marking it as PF_IO_WORKER anyway. The IO threads are now
prepared to handle signals like SIGSTOP as well, so clear that from
the mask to allow proper stopping of IO threads.

Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Reported-by: Oleg Nesterov <oleg@redhat.com>
Change-Id: I6317c88e0723c6c97555f8ceacfee3692372ac4c
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 9ded44b69c)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:14 +00:00
Stefan Metzmacher
bcb749b0b1 UPSTREAM: x86/process: setup io_threads more like normal user space threads
[ Upstream commit 50b7b6f29d ]

As io_threads are fully set up USER threads it's clearer to separate the
code path from the KTHREAD logic.

The only remaining difference to user space threads is that io_threads
never return to user space again. Instead they loop within the given
worker function.

The fact that they never return to user space means they don't have an
user space thread stack. In order to indicate that to tools like gdb we
reset the stack and instruction pointers to 0.

This allows gdb attach to user space processes using io-uring, which like
means that they have io_threads, without printing worrying message like
this:

  warning: Selected architecture i386:x86-64 is not compatible with reported target architecture i386

  warning: Architecture rejected target-supplied description

The output will be something like this:

  (gdb) info threads
    Id   Target Id                  Frame
  * 1    LWP 4863 "io_uring-cp-for" syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
    2    LWP 4864 "iou-mgr-4863"    0x0000000000000000 in ?? ()
    3    LWP 4865 "iou-wrk-4863"    0x0000000000000000 in ?? ()
  (gdb) thread 3
  [Switching to thread 3 (LWP 4865)]
  #0  0x0000000000000000 in ?? ()
  (gdb) bt
  #0  0x0000000000000000 in ?? ()
  Backtrace stopped: Cannot access memory at address 0x0

Fixes: 4727dc20e0 ("arch: setup PF_IO_WORKER threads like PF_KTHREAD")
Link: https://lore.kernel.org/io-uring/044d0bad-6888-a211-e1d3-159a4aeed52d@polymtl.ca/T/#m1bbf5727e3d4e839603f6ec7ed79c7eebfba6267
Change-Id: I83793e9a4fbc5f9024c9aeace0640043c81a93b0
Signed-off-by: Stefan Metzmacher <metze@samba.org>
cc: Linus Torvalds <torvalds@linux-foundation.org>
cc: Jens Axboe <axboe@kernel.dk>
cc: Andy Lutomirski <luto@kernel.org>
cc: linux-kernel@vger.kernel.org
cc: io-uring@vger.kernel.org
cc: x86@kernel.org
Link: https://lore.kernel.org/r/20210505110310.237537-1-metze@samba.org
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit f0a5f0dc01)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:14 +00:00
Jens Axboe
1f4eb35546 UPSTREAM: arch: ensure parisc/powerpc handle PF_IO_WORKER in copy_thread()
[ Upstream commit 0100e6bbdb ]

In the arch addition of PF_IO_WORKER, I missed parisc and powerpc for
some reason. Fix that up, ensuring they handle PF_IO_WORKER like they do
PF_KTHREAD in copy_thread().

Reported-by: Bruno Goncalves <bgoncalv@redhat.com>
Fixes: 4727dc20e0 ("arch: setup PF_IO_WORKER threads like PF_KTHREAD")
Change-Id: I3d0289912eb9e4545fc0b680df6890b6b837ebdd
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit dd26e2cec7)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:14 +00:00
Jens Axboe
150dea15cb UPSTREAM: arch: setup PF_IO_WORKER threads like PF_KTHREAD
[ Upstream commit 4727dc20e0 ]

PF_IO_WORKER are kernel threads too, but they aren't PF_KTHREAD in the
sense that we don't assign ->set_child_tid with our own structure. Just
ensure that every arch sets up the PF_IO_WORKER threads like kthreads
in the arch implementation of copy_thread().

Change-Id: Iec4a3c42a39f016b323476d7238f3d36aaf0e6cf
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 320c8057ec)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:14 +00:00
Seth Forshee
cf487d3c6a UPSTREAM: entry/kvm: Exit to user mode when TIF_NOTIFY_SIGNAL is set
[ Upstream commit 3e684903a8 ]

A livepatch transition may stall indefinitely when a kvm vCPU is heavily
loaded. To the host, the vCPU task is a user thread which is spending a
very long time in the ioctl(KVM_RUN) syscall. During livepatch
transition, set_notify_signal() will be called on such tasks to
interrupt the syscall so that the task can be transitioned. This
interrupts guest execution, but when xfer_to_guest_mode_work() sees that
TIF_NOTIFY_SIGNAL is set but not TIF_SIGPENDING it concludes that an
exit to user mode is unnecessary, and guest execution is resumed without
transitioning the task for the livepatch.

This handling of TIF_NOTIFY_SIGNAL is incorrect, as set_notify_signal()
is expected to break tasks out of interruptible kernel loops and cause
them to return to userspace. Change xfer_to_guest_mode_work() to handle
TIF_NOTIFY_SIGNAL the same as TIF_SIGPENDING, signaling to the vCPU run
loop that an exit to userpsace is needed. Any pending task_work will be
run when get_signal() is called from exit_to_user_mode_loop(), so there
is no longer any need to run task work from xfer_to_guest_mode_work().

Suggested-by: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Petr Mladek <pmladek@suse.com>
Change-Id: If14e86a516403671ccb122cea32cc704f774e8ce
Signed-off-by: Seth Forshee <sforshee@digitalocean.com>
Message-Id: <20220504180840.2907296-1-sforshee@digitalocean.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 000de389ad)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:14 +00:00
Jens Axboe
6e4362caf9 UPSTREAM: kernel: allow fork with TIF_NOTIFY_SIGNAL pending
[ Upstream commit 66ae0d1e2d ]

fork() fails if signal_pending() is true, but there are two conditions
that can lead to that:

1) An actual signal is pending. We want fork to fail for that one, like
   we always have.

2) TIF_NOTIFY_SIGNAL is pending, because the task has pending task_work.
   We don't need to make it fail for that case.

Allow fork() to proceed if just task_work is pending, by changing the
signal_pending() check to task_sigpending().

Change-Id: Iec007746b42f5d62581a8b5f6cca4006e707b8e3
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 0f735cf52b)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:14 +00:00
Eric W. Biederman
b25b8c55ba UPSTREAM: coredump: Limit what can interrupt coredumps
[ Upstream commit 06af867944 ]

Olivier Langlois has been struggling with coredumps being incompletely written in
processes using io_uring.

Olivier Langlois <olivier@trillion01.com> writes:
> io_uring is a big user of task_work and any event that io_uring made a
> task waiting for that occurs during the core dump generation will
> generate a TIF_NOTIFY_SIGNAL.
>
> Here are the detailed steps of the problem:
> 1. io_uring calls vfs_poll() to install a task to a file wait queue
>    with io_async_wake() as the wakeup function cb from io_arm_poll_handler()
> 2. wakeup function ends up calling task_work_add() with TWA_SIGNAL
> 3. task_work_add() sets the TIF_NOTIFY_SIGNAL bit by calling
>    set_notify_signal()

The coredump code deliberately supports being interrupted by SIGKILL,
and depends upon prepare_signal to filter out all other signals.   Now
that signal_pending includes wake ups for TIF_NOTIFY_SIGNAL this hack
in dump_emitted by the coredump code no longer works.

Make the coredump code more robust by explicitly testing for all of
the wakeup conditions the coredump code supports.  This prevents
new wakeup conditions from breaking the coredump code, as well
as fixing the current issue.

The filesystem code that the coredump code uses already limits
itself to only aborting on fatal_signal_pending.  So it should
not develop surprising wake-up reasons either.

v2: Don't remove the now unnecessary code in prepare_signal.

Cc: stable@vger.kernel.org
Fixes: 12db8b6900 ("entry: Add support for TIF_NOTIFY_SIGNAL")
Reported-by: Olivier Langlois <olivier@trillion01.com>
Change-Id: I84870bf0a620a97af50d9b495dd225f9ee2b66b8
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 4b4d2c7992)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:13 +00:00
Jens Axboe
723de95c0c UPSTREAM: kernel: remove checking for TIF_NOTIFY_SIGNAL
[ Upstream commit e296dc4996 ]

It's available everywhere now, no need to check or add dummy defines.

Change-Id: I2e0950c13a90b463b848bb6bc095db02ae08a8cd
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 90a2c3821b)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:13 +00:00
Jens Axboe
8492c5dd3b UPSTREAM: task_work: remove legacy TWA_SIGNAL path
[ Upstream commit 03941ccfda ]

All archs now support TIF_NOTIFY_SIGNAL.

Change-Id: I3fc938645ac7be18300432713909ccfaa7cd2711
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 61bdeb142e)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:13 +00:00
Al Viro
1987566815 UPSTREAM: alpha: fix TIF_NOTIFY_SIGNAL handling
[ Upstream commit e2c7554cc6 ]

it needs to be added to _TIF_WORK_MASK, or we might not reach
do_work_pending() in the first place...

Fixes: 5a9a8897c2 "alpha: add support for TIF_NOTIFY_SIGNAL"
Change-Id: I9f19ad6bc9833ce0cc103163af7904862425badb
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 6e2bce21ac)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:13 +00:00
Vineet Gupta
ad4ba3038a UPSTREAM: ARC: unbork 5.11 bootup: fix snafu in _TIF_NOTIFY_SIGNAL handling
[ Upstream commit bb12433bf5 ]

Linux 5.11.rcX was failing to boot on ARC HSDK board. Turns out we have
a couple of issues, this being the first one, and I'm to blame as I
didn't pay attention during review.

TIF_NOTIFY_SIGNAL support requires checking multiple TIF_* bits in
kernel return code path. Old code only needed to check a single bit so
BBIT0 <TIF_SIGPENDING> worked. New code needs to check multiple bits so
AND <bit-mask> instruction. So needs to use bit mask variant _TIF_SIGPENDING

Cc: Jens Axboe <axboe@kernel.dk>
Fixes: 53855e1258 ("arc: add support for TIF_NOTIFY_SIGNAL")
Link: https://github.com/foss-for-synopsys-dwc-arc-processors/linux/issues/34
Change-Id: I00aa9a6c3118f72e90575fb7ca4ebc08300b542e
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit db911277a2)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:13 +00:00
Jens Axboe
bb855b51a9 UPSTREAM: ia64: don't call handle_signal() unless there's actually a signal queued
[ Upstream commit f5f4fc4649 ]

Sergei and John both reported that ia64 failed to boot in 5.11, and it
was related to signals. Turns out the ia64 signal handling is a bit odd,
it doesn't check the return value of get_signal() for whether there's a
signal to deliver or not. With the introduction of TIF_NOTIFY_SIGNAL,
then task_work could trigger it.

Fix it by only calling handle_signal() if we actually have a real signal
to deliver. This brings it in line with all other archs, too.

Fixes: b269c229b0 ("ia64: add support for TIF_NOTIFY_SIGNAL")
Reported-by: Sergei Trofimovich <slyich@gmail.com>
Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Tested-by: Sergei Trofimovich <slyich@gmail.com>
Change-Id: Id225cfc12645aa47e37c3107670ba440116c9b04
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit a1240cc413)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:13 +00:00
Jens Axboe
7140fddd84 UPSTREAM: sparc: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit f50a7052f5 ]

Wire up TIF_NOTIFY_SIGNAL handling for sparc.

Cc: sparclinux@vger.kernel.org
Change-Id: I6dc91c146efed1287ead67fa44db9185576cbce8
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit e1402ba4df)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:13 +00:00
Jens Axboe
c9c70c8cb6 UPSTREAM: riscv: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 24a31b81e3 ]

Wire up TIF_NOTIFY_SIGNAL handling for riscv.

Cc: linux-riscv@lists.infradead.org
Change-Id: Ia1d9bc9779bf2935dc5a7c83e86261123d4d6b0f
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 78a53ff026)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:13 +00:00
Jens Axboe
52a756bf17 UPSTREAM: nds32: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit b13e8bf615 ]

Wire up TIF_NOTIFY_SIGNAL handling for nds32.

Cc: Nick Hu <nickhu@andestech.com>
Cc: Greentime Hu <green.hu@gmail.com>
Cc: Vincent Chen <deanbo422@gmail.com>
Change-Id: Ic184206ffc5c6981fb590eb0103bc2f623f5402d
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 57e833a0a0)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:12 +00:00
Jens Axboe
6eaa6653e4 UPSTREAM: ia64: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit b269c229b0 ]

Wire up TIF_NOTIFY_SIGNAL handling for ia64.

Cc: linux-ia64@vger.kernel.org
[axboe: added fixes from Mike Rapoport <rppt@kernel.org>]
Change-Id: Ib1e6bb561f1a6ddf9be818d35e295b53f0d1f1fd
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 751fedb9ba)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:12 +00:00
Jens Axboe
1dcd12493b UPSTREAM: h8300: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 2f9799ad01 ]

Wire up TIF_NOTIFY_SIGNAL handling for h8300.

Cc: uclinux-h8-devel@lists.sourceforge.jp
Change-Id: Ibd30f09fc25229b5a410ec37485aac0a188ff717
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 48e9e35d33)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:12 +00:00
Jens Axboe
b265cdb085 UPSTREAM: c6x: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 6d665a4d8b ]

Wire up TIF_NOTIFY_SIGNAL handling for c6x.

Cc: linux-c6x-dev@linux-c6x.org
Change-Id: I0e38ee478eff25064bb03277a29ba273b0656b28
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit c82617d9de)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:12 +00:00
Jens Axboe
f4ece56973 UPSTREAM: alpha: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 5a9a8897c2 ]

Wire up TIF_NOTIFY_SIGNAL handling for alpha.

Cc: linux-alpha@vger.kernel.org
Change-Id: I44b3be73e9a332bfc92b8f5c34426770c9642dae
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 30b78a17ac)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:12 +00:00
Jens Axboe
01af0730c9 UPSTREAM: xtensa: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit bec58f40d6 ]

Wire up TIF_NOTIFY_SIGNAL handling for xtensa.

Thanks to Max Filippov <jcmvbkbc@gmail.com> for making the asm correct.

Cc: linux-xtensa@linux-xtensa.org
Change-Id: I246a2ab88d6fe797d5e067d3b6515cf787ba19cf
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit bf0b619593)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:12 +00:00
Jens Axboe
29420dc96b UPSTREAM: arm: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 32d59773da ]

Wire up TIF_NOTIFY_SIGNAL handling for arm.

Cc: linux-arm-kernel@lists.infradead.org
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Change-Id: Ic1385829b4c4b28cb4b1f82595fd0b2acb9ec9eb
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 1bee9dbbca)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:12 +00:00
Jens Axboe
6c3e852b4f UPSTREAM: microblaze: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit f4ea089e42 ]

Wire up TIF_NOTIFY_SIGNAL handling for microblaze.

Acked-by: Michal Simek <michal.simek@xilinx.com>
Change-Id: I6540230d4b04069323371351dde3d9c964b80058
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 02d383a59c)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:11 +00:00
Jens Axboe
8c81f539a0 UPSTREAM: hexagon: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit aeec819357 ]

Wire up TIF_NOTIFY_SIGNAL handling for hexagon.

Cc: linux-hexagon@vger.kernel.org
Acked-by: Brian Cain <bcain@codeaurora.org>
Change-Id: I68ddb4388560d3caa828b12912da7d54ff42df10
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 19f3e328b4)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:11 +00:00
Jens Axboe
175cc59b9c UPSTREAM: csky: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit f3924d763c ]

Wire up TIF_NOTIFY_SIGNAL handling for csky.

Cc: linux-csky@vger.kernel.org
Acked-by: Guo Ren <guoren@kernel.org>
Change-Id: I5aeedb22a46f89abfd86283dd1067c8ad9a5ee4a
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit c2037d61de)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:11 +00:00
Jens Axboe
2b94543d45 UPSTREAM: openrisc: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit e181c0aa2e ]

Wire up TIF_NOTIFY_SIGNAL handling for openrisc.

Cc: openrisc@lists.librecores.org
Acked-by: Stafford Horne <shorne@gmail.com>
Change-Id: I664b804e2b20332f1c529bca7e083c62e95e6d9f
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 12284aec88)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:11 +00:00
Jens Axboe
e2e4fbbceb UPSTREAM: sh: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 6d3a273355 ]

Wire up TIF_NOTIFY_SIGNAL handling for sh.

Cc: linux-sh@vger.kernel.org
Change-Id: If469e4a57e80bb31d749ca571d4039fc1680732e
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 3fde31e962)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:11 +00:00
Jens Axboe
8548375354 UPSTREAM: um: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit a5b3cd32ff ]

Wire up TIF_NOTIFY_SIGNAL handling for um.

Cc: linux-um@lists.infradead.org
Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Change-Id: Idc702390f1ba7575230aa4c81d27f80088b17afc
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit dc808ffd97)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:11 +00:00
Jens Axboe
eae40ee91c UPSTREAM: s390: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 75309018a2 ]

Wire up TIF_NOTIFY_SIGNAL handling for s390.

Cc: linux-s390@vger.kernel.org
Acked-by: Heiko Carstens <hca@linux.ibm.com>
Acked-by: Sven Schnelle <svens@linux.ibm.com>
Change-Id: I070ab3e37c109b36a2a0134b5548f424f4877dd4
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 0aef2ec063)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:11 +00:00
Jens Axboe
8489c86344 UPSTREAM: mips: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit f45c184bce ]

Wire up TIF_NOTIFY_SIGNAL handling for mips.

Cc: linux-mips@vger.kernel.org
Acked-By: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Change-Id: Ie72b5e65361dee9ab5c8059bde16a3dd0181ca07
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 8ca2e57099)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:10 +00:00
Jens Axboe
b1f0e1159f UPSTREAM: powerpc: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 900f0713fd ]

Wire up TIF_NOTIFY_SIGNAL handling for powerpc.

Cc: linuxppc-dev@lists.ozlabs.org
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
Change-Id: I30a11c05453437854c2a64be214ae557f04d2cea
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit abab3d4444)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:10 +00:00
Jens Axboe
98031aa870 UPSTREAM: parisc: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 18cb328128 ]

Wire up TIF_NOTIFY_SIGNAL handling for parisc.

Cc: linux-parisc@vger.kernel.org
Acked-by: Helge Deller <deller@gmx.de>
Change-Id: Iaa3f0b072f528bf500dc9a10901b5791eb38623f
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 45b365bc6c)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:10 +00:00
Jens Axboe
470c17bd71 UPSTREAM: nios32: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 4202006427 ]

Wire up TIF_NOTIFY_SIGNAL handling for nios32.

Cc: Ley Foon Tan <ley.foon.tan@intel.com>
Acked-by: Ley Foon Tan <ley.foon.tan@intel.com>
Change-Id: I11eed799c048247128e1acfb241f97cc3703d5b2
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit cf3c648673)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:10 +00:00
Jens Axboe
c5825095c4 UPSTREAM: m68k: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit e660653cd9 ]

Wire up TIF_NOTIFY_SIGNAL handling for m68k.

Cc: linux-m68k@lists.linux-m68k.org
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Change-Id: I28d2f9d79486d8728ff0127cd24a64dbb9b2de68
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit fe137f46d4)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:10 +00:00
Jens Axboe
fcf75a019e UPSTREAM: arm64: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 192caabd4d ]

Wire up TIF_NOTIFY_SIGNAL handling for arm64.

Cc: linux-arm-kernel@lists.infradead.org
Acked-by: Will Deacon <will@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Change-Id: Ice69a6d4cd969c76423eab8674e08827815e072a
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 79a9991e87)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:10 +00:00
Jens Axboe
d6b63ac444 UPSTREAM: arc: add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 53855e1258 ]

Wire up TIF_NOTIFY_SIGNAL handling for arc.

Cc: linux-snps-arc@lists.infradead.org
Acked-by: Vineet Gupta <vgupta@synopsys.com>
Change-Id: I958240d0f80efee85940de4f5518135267a4f3a1
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 2dbb035451)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:10 +00:00
Jens Axboe
109ccff96d UPSTREAM: x86: Wire up TIF_NOTIFY_SIGNAL
[ Upstream commit c8d5ed6793 ]

The generic entry code has support for TIF_NOTIFY_SIGNAL already. Just
provide the TIF bit.

[ tglx: Adopted to other TIF changes in x86 ]

Change-Id: I3188c956ab5ed6abac721db8a12f3229f4c7d13c
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20201026203230.386348-4-axboe@kernel.dk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 4b1dcf8ec9)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:10 +00:00
Jens Axboe
862aa233e7 UPSTREAM: task_work: Use TIF_NOTIFY_SIGNAL if available
[ Upstream commit 114518eb64 ]

If the arch supports TIF_NOTIFY_SIGNAL, then use that for TWA_SIGNAL as
it's more efficient than using the signal delivery method. This is
especially true on threaded applications, where ->sighand is shared across
threads, but it's also lighter weight on non-shared cases.

io_uring is a heavy consumer of TWA_SIGNAL based task_work. A test with
threads shows a nice improvement running an io_uring based echo server.

stock kernel:
0.01% <= 0.1 milliseconds
95.86% <= 0.2 milliseconds
98.27% <= 0.3 milliseconds
99.71% <= 0.4 milliseconds
100.00% <= 0.5 milliseconds
100.00% <= 0.6 milliseconds
100.00% <= 0.7 milliseconds
100.00% <= 0.8 milliseconds
100.00% <= 0.9 milliseconds
100.00% <= 1.0 milliseconds
100.00% <= 1.1 milliseconds
100.00% <= 2 milliseconds
100.00% <= 3 milliseconds
100.00% <= 3 milliseconds
1378930.00 requests per second
~1600% CPU

1.38M requests/second, and all 16 CPUs are maxed out.

patched kernel:
0.01% <= 0.1 milliseconds
98.24% <= 0.2 milliseconds
99.47% <= 0.3 milliseconds
99.99% <= 0.4 milliseconds
100.00% <= 0.5 milliseconds
100.00% <= 0.6 milliseconds
100.00% <= 0.7 milliseconds
100.00% <= 0.8 milliseconds
100.00% <= 0.9 milliseconds
100.00% <= 1.2 milliseconds
1666111.38 requests per second
~1450% CPU

1.67M requests/second, and we're no longer just hammering on the sighand
lock. The original reporter states:

"For 5.7.15 my benchmark achieves 1.6M qps and system cpu is at ~80%.
 for 5.7.16 or later it achieves only 1M qps and the system cpu is is
 at ~100%"

with the only difference there being that TWA_SIGNAL is used
unconditionally in 5.7.16, since it's required to be able to handle the
inability to run task_work if the application is waiting in the kernel
already on an event that needs task_work run to be satisfied. Also see
commit 0ba9c9edcd.

Reported-by: Roman Gershman <romger@amazon.com>
Change-Id: I80788634e6b91012ebf94e0ab6bf897c99f9f732
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Link: https://lore.kernel.org/r/20201026203230.386348-5-axboe@kernel.dk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit eb42e7b304)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:09 +00:00
Jens Axboe
a14b028722 UPSTREAM: entry: Add support for TIF_NOTIFY_SIGNAL
[ Upstream commit 12db8b6900 ]

Add TIF_NOTIFY_SIGNAL handling in the generic entry code, which if set,
will return true if signal_pending() is used in a wait loop. That causes an
exit of the loop so that notify_signal tracehooks can be run. If the wait
loop is currently inside a system call, the system call is restarted once
task_work has been processed.

In preparation for only having arch_do_signal() handle syscall restarts if
_TIF_SIGPENDING isn't set, rename it to arch_do_signal_or_restart().  Pass
in a boolean that tells the architecture specific signal handler if it
should attempt to get a signal, or just process a potential syscall
restart.

For !CONFIG_GENERIC_ENTRY archs, add the TIF_NOTIFY_SIGNAL handling to
get_signal(). This is done to minimize the needed architecture changes to
support this feature.

Change-Id: Iec8202baf6ec6ff5d31c339869d8f34af4182677
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Link: https://lore.kernel.org/r/20201026203230.386348-3-axboe@kernel.dk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 3c295bd2dd)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-07 13:38:09 +00:00