summaryrefslogtreecommitdiff
path: root/sys/kern
AgeCommit message (Collapse)Author
2018-07-22Avoid a NULL pointer deref when calling fchown() on a file descriptor belonginganton
to a cloned device. ok kettenis@
2018-07-20Remove a few leftovers from the days of emulation, which could result inTheo de Raadt
a bad/corrupt binary not returning ENOEXEC but some other error. ok guenther kettenis bluhm
2018-07-20Fail if a PT_LOAD segment has a memory size of 0. This prevents a panicMark Kettenis
later on, and it makes no sense for a binary to have such a segment. ok bluhm@, guenther@
2018-07-20Correctly copy across unveil's from parent to child process on fork().Bob Beck
2018-07-18Revert the change that delivers process signals to any threads. AsAlexander Bluhm
side effect pending signals specifically sent to the main thread were handled by other threads. This made gcj in textproc/pdftk port build stall. Noticed and tested by espie@.
2018-07-17unvname_new() is passed something that is always 64-bits so theKenneth R Westerback
parameter should be declared uint64_t and not int. From & for semarie@ who isn't committing at the moment and ok beck@ who is on the road.
2018-07-15Restore correct behaviour to pledge for access and stat, which was brokenBob Beck
by the unveil diff. Noticed at, and diff from semarie@
2018-07-14Don't pass an uninitialised size value to free(9). Pointer argument isJonathan Gray
NULL in this path so free will return early without accessing it. ok jca@ tb@
2018-07-13unbreak gcc4 buildJonathan Gray
2018-07-13Make the default failure for unveil while disabled return successBob Beck
so that people don't get screwed when playing with it on their machines
2018-07-13Unveiling unveil(2).Bob Beck
This brings unveil into the tree, disabled by default - Currently this will return EPERM on all attempts to use it until we are fully certain it is ready for people to start using, but this now allows for others to do more tweaking and experimentation. Still needs to send the unveil's across forks and execs before fully enabling. Many thanks to robert@ and deraadt@ for extensive testing. ok deraadt@
2018-07-12Add hw.ncpuonline to count the number of online CPUs.cheloha
The introduction of hw.smt means that logical CPUs can be disabled after boot and prior to suspend/resume. If hw.smt=0 (the default), there needs to be a way to count the number of hardware threads available on the system at any given time. So, import HW_NCPUONLINE/hw.ncpuonline from NetBSD and document it. hw.ncpu becomes equal to the number of CPUs given to sched_init_cpu() during boot, while hw.ncpuonline is equal to the number of CPUs available to the scheduler in the cpuset "sched_all_cpus". Set_SC_NPROCESSORS_ONLN equal to this new sysctl and keep _SC_NPROCESSORS_CONF equal to hw.ncpu. This is preferable to adding a new sysctl to count the number of configured CPUs and keeping hw.ncpu equal to the number of online CPUs because such a change would break software in the ecosystem that relies on HW_NCPU/hw.ncpu to measure CPU usage and the like. Such software in base includes top(1), systat(1), and snmpd(8), and perhaps others. We don't need additional locking to count the cardinality of a cpuset in this case because the only interfaces that can modify said cardinality are sysctl(2) and ioctl(2), both of which are under the KERNEL_LOCK. Software using HW_NCPU/hw.ncpu to determine optimal parallism will need to be updated to use HW_NCPUONLINE/hw.ncpuonline. Until then, such software may perform suboptimally. However, most changes will be similar to the change included here for libcxx's std::thread:hardware_concurrency(): using HW_NCPUONLINE in lieu of HW_NCPU should be sufficient for determining optimal parallelism for most software if the change to _SC_NPROCESSORS_ONLN is insufficient. Prompted by deraadt. Discussed at length with kettenis, deraadt, and sthen. Lots of patch tweaks from kettenis. ok kettenis, "proceed" deraadt
2018-07-11If no thread can immediately handle a signal, which has been sentAlexander Bluhm
to the process, it is made pending at the main thread. There it could hang forever. So also check the main thread for signal delivery. This workaround fixes hung tests in posixtestsuite. The proper solution would be to split pending signals for process and threads. input visa@; OK guenther@
2018-07-10In free(9) call wakeup() after mtx_leave() consistently.Alexander Bluhm
OK kettenis@ visa@ mpi@
2018-07-10After removing raw_usrreq() from route and pfkey, the global sockaddrAlexander Bluhm
variables can be delared constant. OK claudio@ mpi@
2018-07-10Move socket & pipe specific logic in their ioctl handler.Martin Pieuchot
ok visa@, tb@
2018-07-10Move from sendsig() to its callers the initsiginfo() calls andPhilip Guenther
instead of passing sendsig() the code+type+val, pass a siginfo_t* to copy from. Eliminate the indirection through struct emul for sendsig(); we no longer have a SunOS4-compat version of sendsig() ok deraadt@
2018-07-09Fix trailing whitespaces and too long line.Alexander Bluhm
2018-07-09Use function name in panic string, like in some other places.Claudio Jeker
OK henning@ benno@
2018-07-09Make free(9) MP safe. It was wrong to set ku_indx to 0 after freeingAlexander Bluhm
the memory in uvm. Another process could use the false 0 then. To be on the safe side, protect all access to ku_indx and ku_pagecnt with a mutex. Update ku_indx and ku_pagecnt before calling uvm_km_free(). Update ksp after uvm_km_free() to keep accounting correct. tested by sthen@; OK mpi@ visa@ deraadt@
2018-07-07Fix an argument type error that happens when translating fcntl(F_SETOWN)Visa Hankala
to ioctl(TIOCSPGRP). The ioctl handlers expect a pointer to an int, so read the argument into a local int variable and pass the variable's address to the handler instead of referencing SCARG(uap, arg) directly. OK guenther@, mpi@
2018-07-07Remember to lock v_specparent for VOP operations.Visa Hankala
OK anton@, mpi@
2018-07-07Fix a locking error in spec_setattr(). Unlike many VOP operations,Visa Hankala
VOP_SETATTR() does not release the vnode lock (and it has never done the unlocking in the past). Therefore spec_setattr() has to keep the argument vnode locked and unlock v_specparent instead after the nested VOP_SETATTR() call. Fixes a WITNESS panic found by anton@ OK anton@, mpi@
2018-07-07Release the kernel lock fully on thread exit. This prevents a lockingVisa Hankala
error that would happen otherwise when a traced and stopped multithreaded process is forced to exit. The error shows up as a kernel panic when WITNESS is enabled. Without WITNESS, the error causes a system hang. sched_exit() has expected that a single KERNEL_UNLOCK() would release the lock completely. That assumption is wrong when an exit happens through the signal tracing logic: sched_exit exit1 single_thread_check single_thread_set issignal <-- KERNEL_LOCK() userret <-- KERNEL_LOCK() syscall The error is a regression of r1.216 of kern_sig.c. Panic reported and fix tested by Laurence Tratt OK mpi@
2018-07-05regenMartin Pieuchot
2018-07-05Put back sendto(2) and sendmsg(2) under KERNEL_LOCK().Martin Pieuchot
malloc(9) is apparently not mpsafe as found the hardway by sthen@.
2018-07-05Serialize the sosplice taskq allocation. This prevents an unlikelyVisa Hankala
duplicate allocation that could happen in the future when each socket has a dedicated lock. Right now, the code path is serialized also by the NET_LOCK() (and the KERNEL_LOCK()). OK mpi@
2018-07-05Grab the KERNEL_LOCK() in kthread_create(9) to enable unlocked codeVisa Hankala
paths create kernel threads. This will be utilized by sosplice() for the taskq allocation. OK mpi@
2018-07-05Plug a vnode leak in namei(). If the file system is unmountedAlexander Bluhm
during name lookup, the directory vnode was not released. Add a vrele() to the error return path. NetBSD has added a vput() there after we imported the check. OK krw@ visa@
2018-07-03Add a new so_seek member to "struct file" such that we can have seekableMark Kettenis
files that aren't vnodes. Move the vnode-specific code into its own function. Add an implementation for the "DMA buffers" that can be used by DRI3/prime code to find out the size of the graphics buffer. This implementation is very limited and only supports offset 0 and only for SEEK_SET and SEEK_END. This doesn't really make sense; implementing stat(2) would be a more obvious choice. But this is what Linux does. ok guenther@, visa@
2018-07-03Avoid NULL pointer deref in vn_writechk() when calling ftruncate() on a fileanton
descriptor belonging to a cloned device. ok kettenis@
2018-07-02Use more list macros for v_dirtyblkhd.Alexander Bluhm
OK mpi@
2018-07-02Update the file reference count field `f_count' using atomic operationsVisa Hankala
instead of using a mutex for update serialization. Use a per-fdp mutex to manage updating of file instance pointers in the `fd_ofiles' array to let fd_getfile() acquire file references safely with concurrent file reference releases. OK mpi@
2018-07-02Assert that fdp is locked in fdalloc().Visa Hankala
OK mpi@
2018-07-01Lock the file descriptor table when accessing the `fd_ofileflags' array.Visa Hankala
This prevents the array from being freed too early. In the function unp_internalize(), the locking also ensures the per-fdp flags stay coherent with the file instance. OK mpi@
2018-06-30Don't steal processes from other CPUs if we're not scheduling processes onMark Kettenis
a CPU. ok deraadt@
2018-06-27regenMartin Pieuchot
2018-06-27Revert previous, at least one pool need its IPL to be IPL_MPFLOOR asMartin Pieuchot
found by visa@.
2018-06-27Raise file_pool's IPL to prevent deadlocks with the newly unlockedVisa Hankala
system calls. OK mpi@
2018-06-27regenMartin Pieuchot
2018-06-27Unlock 12 network-related syscalls.Martin Pieuchot
This is possible now that the code doing file refcounting is mp-safe. Tested by many, ok tb@, visa@
2018-06-26Make the system cache a small number of free lock list entries per CPU.Visa Hankala
This reduces the contention of the `w_mtx' lock. OK mpi@
2018-06-26Remove a duplicate fd_used() call. The new file descriptor passedVisa Hankala
to dupfdopen() has already been registered with fd_used() in fdalloc(). The duplicate call distorted the number of open file descriptors returned by getdtablecount(2) if a file was opened via /dev/fd/. While there, assert that the file instance should already be in the file list. OK mpi@
2018-06-25Implement DRI3/prime support. This allows graphics buffers to be passedMark Kettenis
between processes using file descriptors. This provides an alternative to eporting them with guesable 32-bit IDs. This implementation does not (yet) allow sharing of graphics buffers between GPUs. ok mpi@, visa@
2018-06-25During open(2), release the fdp lock before calling vn_open(9).Visa Hankala
This lets other threads of the process modify the file descriptor table even if the vn_open(9) call blocks. The change has an effect on dup2(2) and dup3(2). If the new descriptor is the same as the one reserved by an unfinished open(2), the system call will fail with error EBUSY. The accept(2) system call already behaves like this. Issue pointed out by art@ via mpi@ Tested in a bulk build by ajacoutot@ OK mpi@
2018-06-25Introduce fnew(), a function to initialize a `struct file'.Martin Pieuchot
Commiting now to help refactoring of DRI3 and diskmap rewrite. ok visa@, kettenis@ as part of a larger diff.
2018-06-24Use atomic operations for updating `numfiles'. This makes the file countVisa Hankala
tracking work without locks. OK kettenis@, deraadt@
2018-06-23Replace value with a constantdenis
OK bluhm@, jca@
2018-06-23Improve the consistency of variable naming in unp_externalize().Visa Hankala
Rename the int array `fdp' to `fds', and use the name `fdp' for a variable that points to the filedesc struct of the current process. This use of `fdp' puts unp_externalize() in line with filesystem code. OK millert@, kettenis@
2018-06-22tweak commentVisa Hankala