]> git.ipfire.org Git - thirdparty/linux.git/commit
Add RWF_NOSIGNAL flag for pwritev2
authorLauri Vasama <git@vasama.org>
Wed, 27 Aug 2025 13:39:00 +0000 (16:39 +0300)
committerChristian Brauner <brauner@kernel.org>
Fri, 29 Aug 2025 13:08:07 +0000 (15:08 +0200)
commitdb2ab24a341ce89351a1bede37a96a3e3ce1726a
treeaf6f553031332ae234888f4238dadb75126c3b59
parent38d1227fa71d96b470172df50e241775a802a8e7
Add RWF_NOSIGNAL flag for pwritev2

For a user mode library to avoid generating SIGPIPE signals (e.g.
because this behaviour is not portable across operating systems) is
cumbersome. It is generally bad form to change the process-wide signal
mask in a library, so a local solution is needed instead.

For I/O performed directly using system calls (synchronous or readiness
based asynchronous) this currently involves applying a thread-specific
signal mask before the operation and reverting it afterwards. This can be
avoided when it is known that the file descriptor refers to neither a
pipe nor a socket, but a conservative implementation must always apply
the mask. This incurs the cost of two additional system calls. In the
case of sockets, the existing MSG_NOSIGNAL flag can be used with send.

For asynchronous I/O performed using io_uring, currently the only option
(apart from MSG_NOSIGNAL for sockets), is to mask SIGPIPE entirely in the
call to io_uring_enter. Thankfully io_uring_enter takes a signal mask, so
only a single syscall is needed. However, copying the signal mask on
every call incurs a non-zero performance penalty. Furthermore, this mask
applies to all completions, meaning that if the non-signaling behaviour
is desired only for some subset of operations, the desired signals must
be raised manually from user-mode depending on the completed operation.

Add RWF_NOSIGNAL flag for pwritev2. This flag prevents the SIGPIPE signal
from being raised when writing on disconnected pipes or sockets. The flag
is handled directly by the pipe filesystem and converted to the existing
MSG_NOSIGNAL flag for sockets.

Signed-off-by: Lauri Vasama <git@vasama.org>
Link: https://lore.kernel.org/20250827133901.1820771-1-git@vasama.org
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/pipe.c
include/linux/fs.h
include/uapi/linux/fs.h
net/socket.c