summaryrefslogtreecommitdiff
path: root/sys/kern/sys_pipe.c
AgeCommit message (Collapse)Author
2022-08-14remove unneeded includes in sys/kernJonathan Gray
ok mpi@ miod@
2022-07-09Unwrap klist from struct selinfo as this code no longer uses selwakeup().Visa Hankala
OK jsg@
2022-06-20Remove unused struct fileops field fo_poll and callbacks.Visa Hankala
OK mpi@
2022-05-30Replace selwakeup() with KNOTE() in pipe event activation.Visa Hankala
Recommit the reverted change selectively so that only pipes are affected. Leave sockets untouched for now.
2022-05-09Revert "Replace selwakeup() with KNOTE() in pipe and socket event activation."Visa Hankala
The commit caused hangs with NFS. Reported by ajacoutot@ and naddy@
2022-05-06Replace selwakeup() with KNOTE() in pipe and socket event activation.Visa Hankala
OK mpi@
2022-02-13Use knote_modify() and knote_process() in obvious places.Visa Hankala
2022-02-13Rename knote_modify() to knote_assign()Visa Hankala
This avoids verb overlap with f_modify.
2022-02-12Reduce code duplication in pipe event filtersVisa Hankala
Use the f_event callback for checking event state within the pipe event filters. This enables the same f_modify and f_process functions to handle the different filter types. OK anton@
2021-12-13Revise EVFILT_EXCEPT filtersVisa Hankala
Restrict the circumstances where EVFILT_EXCEPT filters trigger: * when out-of-band data is present and NOTE_OOB is requested. * when the channel is fully closed and consumer is poll(2). This should clarify the logic and suppress events that kqueue-based poll(2) does not except. OK mpi@
2021-12-13Prevent kevent(2) use of EVFILT_EXCEPT with FIFOs and pipesVisa Hankala
Currently, the only intended direct usage of the EVFILT_EXCEPT filter is with NOTE_OOB to detect out-of-band data in ptys and sockets. NOTE_OOB does not apply to FIFOs or pipes. Prevent the user from registering the filter with these file types. The filter code is for the kernel's internal use. OK mpi@
2021-12-08Fix select(2) exceptfds handling of FIFOs and pipesVisa Hankala
Prevent select(2) from indicating an exceptional condition when the other end of a FIFO or pipe is closed. Originally, select(2) returned an exceptfds event only with a pty or socket that has out-of-band data pending. millert@ says that OpenBSD diverged from this by accident when poll(2) and select(2) were changed to use the same backend code in year 2003. OK millert@
2021-12-07Add EVFILT_EXCEPT filter for pipesVisa Hankala
The kqueue-based select(2) needs the filter to replicate the old exceptfds behaviour. The upcoming new poll(2) code will use the filter for POLLHUP condition checking when the events bitmap is clear of read/write events. OK anton@
2021-10-24Make pipe event filters MP-safeVisa Hankala
Add the missing f_modify and f_process callbacks so that pipe_lock serializes pipe knote handling. As pipe klist locking is already in place, pipe event filters should now be MP-safe. This uses write locking everywhere in the callbacks for simplicity. There is not much multiple-readers parallelism to utilize. OK mpi@ anton@
2021-10-22Revert "Preserve select(2) semantics when the other end of the pipe is gone".Martin Pieuchot
The logic to emulate the current poll/select behavior is better implemented at the syscall layer and not in the kqueue backend. Discussed with deraadt@, ok anton@
2021-10-22Preserve pipe select(2) semantics when the other end of the pipe is gone.Anton Lindqvist
In preparation for implementing select(2) on top of kqueue. ok mpi@
2020-12-30Set klist lock for pipes.Visa Hankala
OK anton@, mpi@
2020-12-25Refactor klist insertion and removalVisa Hankala
Rename klist_{insert,remove}() to klist_{insert,remove}_locked(). These functions assume that the caller has locked the klist. The current state of locking remains intact because the kernel lock is still used with all klists. Add new functions klist_insert() and klist_remove() that lock the klist internally. This allows some code simplification. OK mpi@
2020-12-11Simplify filt_pipedetach()Visa Hankala
By storing pipe pointer in kn_hook, filt_pipedetach() does not need extra logic to find the correct pipe instance. This also lets the kernel clear the knote lists fully. OK anton@, mpi@
2020-06-29Bring back revision 1.122 with a fix preventing a use-after-free byanton
serializing calls to pipe_buffer_free(). Repeating the previous commit message: Instead of performing three distinct allocations per created pipe, reduce it to a single one. Not only should this be more performant, it also solves a kqueue related issue found by visa@ who also requested this change: if you attach an EVFILT_WRITE filter to a pipe fd, the knote gets added to the peer's klist. This is a problem for kqueue because if you close the peer's fd, the knote is left in the list whose head is about to be freed. knote_fdclose() is not able to clear the knote because it is not registered with the peer's fd. FreeBSD also takes a similar approach to pipe allocations. once again ok mpi@ visa@
2020-06-19backout pipe change, it crashes some archTheo de Raadt
2020-06-17Instead of performing three distinct allocations per created pipe,anton
reduce it to a single one. Not only should this be more performant, it also solves a kqueue related issue found by visa@ who also requested this change: if you attach an EVFILT_WRITE filter to a pipe fd, the knote gets added to the peer's klist. This is a problem for kqueue because if you close the peer's fd, the knote is left in the list whose head is about to be freed. knote_fdclose() is not able to clear the knote because it is not registered with the peer's fd. FreeBSD also takes a similar approach to pipe allocations. ok mpi@ visa@
2020-06-15Set __EV_HUP when the conditions matching poll(2)'s POLLUP are found.Martin Pieuchot
This is only done in poll-compatibility mode, when __EV_POLL is set. ok visa@, millert@
2020-04-07Abstract the head of knote lists. This allows extending the lists,Visa Hankala
for example, with locking assertions. OK mpi@, anton@
2020-02-20Replace field f_isfd with field f_flags in struct filterops to allowVisa Hankala
adding more filter properties without cluttering the struct. OK mpi@, anton@
2020-02-16Unconditionally acquiring a write lock in pipe_ioctl() is quiteanton
excessive as only one command actually modifies the pipe. The sigio subsystem is already internally protected using its own lock. This is similar to what soo_ioctl() already does. ok mpi@ visa@
2020-02-14Push the KERNEL_LOCK() insidge pgsigio() and selwakeup().Martin Pieuchot
The 3 subsystems: signal, poll/select and kqueue can now be addressed separatly. Note that bpf(4) and audio(4) currently delay the wakeups to a separate context in order to respect the KERNEL_LOCK() requirement. Sockets (UDP, TCP) and pipes spin to grab the lock for the sames reasons. ok anton@, visa@
2020-02-01Back out previous. Nothing wrong with the diff per se but I should haveanton
asked for more oks; my bad!
2020-02-01Grab the kernel lock in pgsigio() as it's strictly needed whileanton
operating on the process structure and issuing signals. This is similar to what sigio_setown() already does. With this in place, the pipe subsystem is no longer required to grab the kernel lock before calling pgsigio(). ok visa@
2020-01-12condense commentanton
2020-01-12Get rid of redundant parenthesis.anton
ok millert@ ratchov@ visa@
2020-01-09Replace the global pipe_lock with a more fine-grained lock per pipeanton
pair. One lock per pipe pair is used to guarantee exclusive access to both ends of a pipe. Thanks to millert@ and tedu@ for the feedback and ok visa@
2020-01-08Unify handling of ioctls FIOSETOWN/SIOCSPGRP/TIOCSPGRP andVisa Hankala
FIOGETOWN/SIOCGPGRP/TIOCGPGRP. Do this by determining the meaning of the ID parameter inside the sigio code. Also add cases for FIOSETOWN and FIOGETOWN where there have been TIOCSPGRP and TIOCGPGRP before. These changes allow removing the ID translation from sys_fcntl() and sys_ioctl(). Idea from NetBSD OK mpi@, claudio@
2020-01-05Constify instances of struct fileops.Visa Hankala
OK anton@, mpi@, bluhm@
2020-01-04Eliminate some minor differences between pipe_read() and pipe_write():anton
* Sort local variables by size, name * No need to initialize error in pipe_write() ok millert@ visa@
2020-01-03Rename the pipe I/O lock routines for improved clarity. This is just aanton
mere preparation for introducing a dedicated lock per pipe pair. ok mpi@ visa@
2019-12-31Use C99 designated initializers with struct filterops. In addition,Visa Hankala
make the structs const so that the data are put in .rodata. OK mpi@, deraadt@, anton@, bluhm@
2019-12-27Remove the kernel lock in pipe read and write routines since everythinganton
is serialized by the pipe_lock by now. The kernel lock is however still needed when interacting with kqueue in order to prevent a race and when potentially issuing SIGIO signals. ok visa@
2019-12-25Condense a few multi line comments into single line ones. While hereanton
turn them into proper sentences. Gets rid of 27 lines in total.
2019-12-25Protect remaining fields of `struct pipe' using the pipe_lock. In orderanton
to simplify the locking pattern, revert back to using a hand-rolled I/O lock just like FreeBSD and NetBSD does. The state of pipes is quite different compared to when I made use of a rwlock for the I/O lock in revision 1.96. Most notably, the pipe_lock can now be used while sleeping. This does imply that witness(4) tracking of the I/O lock is lost but the implementation ends up being simpler. ok visa@
2019-12-19Start protecting the pipe_peer member of `struct pipe' using theanton
pipe_lock. This add a potential sleeping point in the kqueue filter routines which should be fine by now thanks to changes made to the kqueue subsystem by visa. ok visa@
2019-11-29add missing parens around return expression and zap empty lineanton
2019-11-29Start protecting the pipe_busy field of struct pipe using a globalanton
rwlock. This lock is shared among all pipes for simplicity. In the future, the lock will probably be replaced with one lock per pipe pair, just like FreeBSD and NetBSD does. While here, extract the common rundown wakeup logic into a dedicated function. Thanks to cheloha@ for testing and feedback. ok mpi@ visa@
2019-11-19When waiting on pipe I/O, simplify the unlock/relock logic usinganton
rwsleep(). All made possible by the recent switch to using a rwlock as the exclusive pipe lock. ok visa@
2019-11-11Extended the scope of the pipelock() in pipe_write() making the lockinganton
pattern more similar to pipe_read(). This also eliminates two races caused by relocking. ok visa@
2019-11-10Invert a conditional in pipe_write() for reduced indent and inanton
preparation for further refactoring. ok cheloha@ mpi@ visa@
2019-11-09Replace the hand-rolled pipe lock with a rwlock. A necessary first stepanton
towards unlocking pipes. ok cheloha@ mpi@ visa@
2019-07-16move the whole `struct pipe' allocation and initialization inside pipe_create()Sebastien Marie
rename pipclose() to pipe_destroy(), and return early instead of having the whole code in if-body. ok claudio@ anton@ visa@ mpi@
2019-07-15revisit pipe initialization and buffer managementSebastien Marie
- in dopipe(), get an already zeroed struct (PR_ZERO) instead of manually initialize each member (in pipe_create) - rename pipespace() and pipe_free_kmem() to pipe_buffer_realloc() and pipe_buffer_free(): it is more evident that the functions works on the same thing - in pipe_buffer_free(), return early and move the if-body as function body No functional change intented. ok anton@ visa@ mpi@
2019-07-15Do not relock fdp in fdrelease(). This prevents unnecessary lockingVisa Hankala
in the common case. OK mpi@