Home | History | Annotate | Download | only in kern
History log of /src/sys/kern/kern_lwp.c
RevisionDateAuthorComments
 1.270  11-Apr-2025  andvar s/LSSUPENDED/LSSUSPENDED/ in comment.
 1.269  20-Dec-2023  andvar branches: 1.269.2;
s/deatched/detached/ in comment. While here, fix an article before annoyance.
 1.268  20-Dec-2023  andvar fix tripple n typos in "running"/"domainname", also one missing n in comments.
 1.267  15-Oct-2023  riastradh kern_lwp: Sort includes. No functional change intended.
 1.266  15-Oct-2023  riastradh sys/lwp.h: Nix sys/syncobj.h dependency.

Remove it in ddb/db_syncobj.h too.

New sys/wchan.h defines wchan_t so that users need not pull in
sys/syncobj.h to get it.

Sprinkle #include <sys/syncobj.h> in .c files where it is now needed.
 1.265  05-Oct-2023  ad Arrange to update cached LWP credentials in userret() rather than during
syscall/trap entry, eliminating a test+branch on every syscall/trap.

This wasn't possible in the 3.99.x timeframe when l->l_cred came about
because there wasn't a reliable/timely way to force an ONPROC LWP running on
a remote CPU into the kernel (which is just about the only new thing in
this scheme).
 1.264  05-Oct-2023  riastradh lwp_pctr(9): Make this a little more robust.

No substantive change to machine code on aarch64. (Instructions and
registers got reordered a little but not in a way that matters.)
 1.263  04-Oct-2023  ad kauth_cred_hold(): return cred verbatim so that donating a reference to
another data structure can be done more elegantly.
 1.262  04-Oct-2023  ad Do cv_broadcast(&p->p_lwpcv) after dropping p->p_lock in a few places, to
reduce contention.
 1.261  04-Oct-2023  ad lwp_wait(): restart the loop if p->p_lock dropped to reap zombie (paranoid).
 1.260  04-Oct-2023  ad Sprinkle a bunch more calls to lwp_need_userret(). There should be no
functional change but it does get rid of a bunch of assumptions about how
mi_userret() works making it easier to adjust in that in the future, and
works as a kind of documentation too.
 1.259  04-Oct-2023  ad Sprinkle a bunch more calls to lwp_need_userret(). There should be no
functional change but it does get rid of a bunch of assumptions about how
mi_userret() works making it easier to adjust in that in the future, and
works as a kind of documentation too.
 1.258  04-Oct-2023  ad Eliminate l->l_ncsw and l->l_nivcsw. From memory think they were added
before we had per-LWP struct rusage; the same is now tracked there.
 1.257  23-Sep-2023  ad Sigh.. Adjust previous to work as intended. The boosted LWP priority
didn't persist as far as the run queue because l_syncobj gets reset
earlier than I recalled.
 1.256  23-Sep-2023  ad - Simplify how priority boost for blocking in kernel is handled. Rather
than setting it up at each site where we block, make it a property of
syncobj_t. Then, do not hang onto the priority boost until userret(),
drop it as soon as the LWP is out of the run queue and onto a CPU.
Holding onto it longer is of questionable benefit.

- This allows two members of lwp_t to be deleted, and mi_userret() to be
simplified a lot (next step: trim it down to a single conditional).

- While here, constify syncobj_t and de-inline a bunch of small functions
like lwp_lock() which turn out not to be small after all (I don't know
why, but atomic_*_relaxed() seem to provoke a compiler shitfit above and
beyond what volatile does).
 1.255  23-Sep-2023  ad Repply this change with a couple of bugs fixed:

- Do away with separate pool_cache for some kernel objects that have no special
requirements and use the general purpose allocator instead. On one of my
test systems this makes for a small (~1%) but repeatable reduction in system
time during builds presumably because it decreases the kernel's cache /
memory bandwidth footprint a little.
- vfs_lockf: cache a pointer to the uidinfo and put mutex in the data segment.
 1.254  12-Sep-2023  ad Back out recent change to replace pool_cache with then general allocator.
Will return to this when I have time again.
 1.253  10-Sep-2023  ad - Do away with separate pool_cache for some kernel objects that have no special
requirements and use the general purpose allocator instead. On one of my
test systems this makes for a small (~1%) but repeatable reduction in system
time during builds presumably because it decreases the kernel's cache /
memory bandwidth footprint a little.
- vfs_lockf: cache a pointer to the uidinfo and put mutex in the data segment.
 1.252  09-Apr-2023  riastradh kern: KASSERT(A && B) -> KASSERT(A); KASSERT(B)
 1.251  01-Jul-2022  riastradh kern: Fix comment about precondition of lwp_update_creds.
 1.250  22-May-2022  andvar fix various small typos, mainly in comments.
 1.249  07-May-2022  mrg bump maxthreads default.

bump the default MAXLWP to 4096 from 2048, and adjust the default
limits seen to be 2048 cur / 4096 max. remove the linkage to
maxuprc entirely.

remove cpu_maxlwp() that isn't implemented anywhere. instead,
grow the maxlwp for larger memory systems, picking 1 lwp per 1MiB
of ram, limited to 65535 like the system limit.

remove some magic numbers.


i've been having weird firefox issues for a few months now and
it turns out i was having pthread_create() failures and since
bumping the defaults i've had none of the recent issues.
 1.248  09-Apr-2022  riastradh kern: Handle l_mutex with atomic_store_release, atomic_load_consume.

- Where the lock is held and known to be correct, no atomic.
- In loops to acquire the lock, use atomic_load_relaxed before we
restart with atomic_load_consume.

Nix membar_exit.

(Who knows, using atomic_load_consume here might fix bugs on Alpha!)
 1.247  10-Mar-2022  riastradh kern: Fix synchronization of clearing LP_RUNNING and lwp_free.

1. membar_sync is not necessary here -- only a store-release is
required.

2. membar_consumer _before_ loading l->l_pflag is not enough; a
load-acquire is required.

Actually it's not really clear to me why any barriers are needed, since
the store-release and load-acquire should be implied by releasing and
acquiring the lwp lock (and maybe we could spin with the lock instead
of reading l->l_pflag unlocked). But maybe there's something subtle
about access to l->l_mutex that's not obvious here.
 1.246  22-Dec-2021  thorpej Do the last change differently:

Instead of having a pre-destruct hook, put knowledge of passive
serialization into the pool allocator directly, enabled by PR_PSERIALIZE
when the pool / pool_cache is initialized. This will guarantee that
a passive serialization barrier will be performed before the object's
destructor is called, or before the page containing the object is freed
back to the system (in the case of no destructor). Note that the internal
allocator overhead is different when PR_PSERIALIZE is used (it implies
PR_NOTOUCH, because the objects must remain in a valid state).

In the DRM Linux API shim, this allows us to remove the custom page
allocator for SLAB_TYPESAFE_BY_RCU.
 1.245  21-Dec-2021  thorpej Rather than calling xc_barrier() in lwp_dtor(), set a pre-destruct hook
on the lwp_cache and invoke the barrier there.
 1.244  28-Sep-2021  thorpej futex_release_all_lwp(): No need to pass the "tid" argument separately; that
is a vestige of an older version of the code. Also, move a KASSERT() that
both futex_release_all_lwp() call sites had inside of futex_release_all_lwp()
itself.
 1.243  13-Jan-2021  skrll branches: 1.243.12;
Improve English in comments
 1.242  22-Jun-2020  maxv branches: 1.242.2;
Permanent node doesn't need a log, plus the log gets leaked anyway. Found
by kLSan.
 1.241  06-Jun-2020  ad lwp_exit(): add a warning about (l != curlwp)
 1.240  01-Jun-2020  thorpej lwp_thread_cleanup(): Remove overly-aggressive assertion.
 1.239  23-May-2020  ad Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.
 1.238  23-May-2020  ad - Replace pid_table_lock with a lockless lookup covered by pserialize, with
the "writer" side being pid_table expansion. The basic idea is that when
doing an LWP lookup there is usually already a lock held (p->p_lock), or a
spin mutex that needs to be taken (l->l_mutex), and either can be used to
get the found LWP stable and confidently determine that all is correct.

- For user processes LSLARVAL implies the same thing as LSIDL ("not visible
by ID"), and lookup by ID in proc0 doesn't really happen. In-tree the new
state should be understood by top(1), the tty subsystem and so on, and
would attract the attention of 3rd party kernel grovellers in time, so
remove it and just rely on LSIDL.
 1.237  29-Apr-2020  thorpej - proc_find() retains traditional semantics of requiring the canonical
PID to look up a proc. Add a separate proc_find_lwpid() to look up a
proc by the ID of any of its LWPs.
- Add proc_find_lwp_acquire_proc(), which enables looking up the LWP
*and* a proc given the ID of any LWP. Returns with the proc::p_lock
held.
- Rewrite lwp_find2() in terms of proc_find_lwp_acquire_proc(), and add
allow the proc to be wildcarded, rather than just curproc or specific
proc.
- lwp_find2() now subsumes the original intent of lwp_getref_lwpid(), but
in a much nicer way, so garbage-collect the remnants of that recently
added mechanism.
 1.236  26-Apr-2020  thorpej Add a NetBSD native futex implementation, mostly written by riastradh@.
Map the COMPAT_LINUX futex calls to the native ones.
 1.235  24-Apr-2020  thorpej Overhaul the way LWP IDs are allocated. Instead of each LWP having it's
own LWP ID space, LWP IDs came from the same number space as PIDs. The
lead LWP of a process gets the PID as its LID. If a multi-LWP process's
lead LWP exits, the PID persists for the process.

In addition to providing system-wide unique thread IDs, this also lets us
eliminate the per-process LWP radix tree, and some associated locks.

Remove the separate "global thread ID" map added previously; it is no longer
needed to provide this functionality.

Nudged in this direction by ad@ and chs@.
 1.234  19-Apr-2020  ad lwp_wait(): don't need to check for process exit, cv_wait_sig() does it.
 1.233  04-Apr-2020  thorpej branches: 1.233.2;
Add support for lazily generating a "global thread ID" for a LWP. This
identifier uniquely identifies an LWP across the entire system, and will
be used in future improvements in user-space synchronization primitives.

(Test disabled and libc stub not included intentionally so as to avoid
multiple libc version bumps.)
 1.232  04-Apr-2020  maxv Drop specificdata from KCOV, kMSan doesn't interact well with it. Also
reduces the overhead.
 1.231  26-Mar-2020  ad Fix crash observed with procfs on current-users by David Hopper. LWP refcnt
and p_zomblwp both must reach the needed state, and LSZOMB be set, under a
single hold of p_lock.
 1.230  26-Mar-2020  ad softint_overlay() (slow case) gains ~nothing but creates potential headaches.
In the interests of simplicity remove it and always use the kthreads.
 1.229  08-Mar-2020  ad PR kern/55020: dbregs_dr?_dont_inherit_lwp test cases fail on real hardware

lwp_wait(): make the check for deadlock much more permissive.
 1.228  27-Feb-2020  ad Remove an unneeded ifdef MULTIPROCESSOR.
 1.227  15-Feb-2020  ad - Move the LW_RUNNING flag back into l_pflag: updating l_flag without lock
in softint_dispatch() is risky. May help with the "softint screwup"
panic.

- Correct the memory barriers around zombies switching into oblivion.
 1.226  15-Feb-2020  ad PR kern/54922: 9.99.45@20200202 panic: diagnostic assertion linux ldconfig triggers vpp != NULL in exit1()->radixtree.c line 674

Create an lwp_renumber() from the code in emulexec() and use in
linux_e_proc_exec() and linux_e_proc_fork() too.
 1.225  11-Feb-2020  dogcow fix compilation failure for arches without l_pcu_valid
ok riastradh
 1.224  11-Feb-2020  riastradh Preserve pcu(9) state in fork.

There should perhaps be a pcu_fork operation to keep this factored
neatly but this will be simpler to pull up.

In practical terms, this may not affect most architecture that use
pcu(9) -- alpha, arm32, mips, powerpc, riscv -- but it does affect
aarch64, in which v8-v15 are callee-saves, and GCC actually takes
advantage of them, and for more than just floating-point data too.

XXX pullup
 1.223  29-Jan-2020  ad - Track LWPs in a per-process radixtree. It uses no extra memory in the
single threaded case. Replace scans of p->p_lwps with lookups in the
tree. Find free LIDs for new LWPs in the tree. Replace the hashed sleep
queues for park/unpark with lookups in the tree under cover of a RW lock.

- lwp_wait(): if waiting on a specific LWP, find the LWP via tree lookup and
return EINVAL if it's detached, not ESRCH.

- Group the locks in struct proc at the end of the struct in their own cache
line.

- Add some comments.
 1.222  27-Jan-2020  ad - lwp_wait(): if the process is exiting and no progress is being made, wake
every clock tick and kick all the LWPs again.

- lwp_create(): copy the LW_WEXIT etc flags while holding the parent's
p_lock. Copy only LW_WREBOOT in the case of fork(), since a pending
coredump or exit() in the parent process isn't for the child.
 1.221  26-Jan-2020  ad Update a comment.
 1.220  22-Jan-2020  ad Catch a leaked hold of kernel_lock sooner with DIAGNOSTIC and make the
message a bit more informative.
 1.219  12-Jan-2020  ad Remove some unneeded kernel_lock handling.
 1.218  08-Jan-2020  ad Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

- mi_switch(): undo the ~2007ish optimisation to unlock curlwp before
calling cpu_switchto(). It's not safe to let other actors mess with the
LWP (in particular l->l_cpu) while it's still context switching. This
removes l->l_ctxswtch.

- Move the LP_RUNNING flag into l->l_flag and rename to LW_RUNNING since
it's now covered by the LWP's lock.

- Ditch lwp_exit_switchaway() and just call mi_switch() instead. Everything
is in cache anyway so it wasn't buying much by trying to avoid saving old
state. This means cpu_switchto() will never be called with prevlwp ==
NULL.

- Remove some KERNEL_LOCK handling which hasn't been needed for years.
 1.217  06-Dec-2019  ad branches: 1.217.2;
Make it possible to call mi_switch() and immediately switch to another CPU.
This seems to take about 3us on my Intel system. Two changes required:

- Have the caller to mi_switch() be responsible for calling spc_lock().
- Avoid using l->l_cpu in mi_switch().

While here:

- Add a couple of calls to membar_enter()
- Have the idle LWP set itself to LSIDL, to match softint_thread().
- Remove unused return value from mi_switch().
 1.216  03-Dec-2019  riastradh Rip out pserialize(9) logic now that the RCU patent has expired.

pserialize_perform() is now basically just xc_barrier(XC_HIGHPRI).
No more tentacles throughout the scheduler. Simplify the psz read
count for diagnostic assertions by putting it unconditionally into
cpu_info.

From rmind@, tidied up by me.
 1.215  01-Dec-2019  ad Fix a longstanding problem with LWP limits. When changing the user's
LWP count, we must use the process credentials because that's what
the accounting entity is tied to.

Reported-by: syzbot+d193266676f635661c62@syzkaller.appspotmail.com
 1.214  24-Nov-2019  ad lwp_start(): don't try to change the target CPU. Fixes potential panic
in setrunnable(). Oops, experimental change that escaped.
 1.213  24-Nov-2019  ad Put section attribute for turnstile0 in the correct place. For LLVM.
 1.212  23-Nov-2019  ad Minor scheduler cleanup:

- Adapt to cpu_need_resched() changes. Avoid lost & duplicate IPIs and ASTs.
sched_resched_cpu() and sched_resched_lwp() contain the logic for this.
- Changes for LSIDL to make the locking scheme match the intended design.
- Reduce lock contention and false sharing further.
- Numerous small bugfixes, including some corrections for SCHED_FIFO/RT.
- Use setrunnable() in more places, and merge cut & pasted code.
 1.211  21-Nov-2019  ad lwp_setlock(): return pointer to the kmutex_t that we replaced
 1.210  21-Nov-2019  ad lwp_create:
- Don't need to check for PK_SYSTEM when inheriting an affinity mask.
- Inherit processor set ID under proc_lock, to sync with pset syscalls.
 1.209  21-Nov-2019  ad - lwp_need_userret(): only do it if ONPROC and !curlwp, and explain why.
- Use signotify() in a couple more places.
 1.208  14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.207  10-Nov-2019  joerg Ensure that the second LWP of a new process uses a free LWP ID.
Document overflow behavior.
 1.206  07-Nov-2019  joerg Preserve the LWP ID of the calling thread on (v)fork. This ensures that
_lwp_self() remains invariant as necessary for the locking in the
dynamic linker. Otherwise if a process creates a thread and forks from
it, the main thread of the parent would share the LWP ID of the main
thread of the child, even though they have different origins.

Partial fix for pkg/54192.
 1.205  06-Oct-2019  uwe xc_barrier - convenience function to xc_broadcast() a nop.

Make the intent more clear and also avoid a bunch of (xcfunc_t)nullop
casts that gcc 8 -Wcast-function-type is not happy about.
 1.204  03-Oct-2019  kamil Separate flag for suspended by _lwp_suspend and suspended by a debugger

Once a thread was stopped with ptrace(2), userland process must not
be able to unstop it deliberately or by an accident.

This was a Windows-style behavior that makes threading tracing fragile.
 1.203  30-Sep-2019  kamil Move TRAP_CHLD/TRAP_LWP ptrace information from struct proc to siginfo

Storing struct ptrace_state information inside struct proc was vulnerable
to synchronization bugs, as multiple events emitted in the same time were
overwritting other ones.

Cache the original parent process id in p_oppid. Reusing here p_opptr is
in theory prone to slight race codition.

Change the semantics of PT_GET_PROCESS_STATE, reutning EINVAL for calls
prompting for the value in cases when there wasn't registered an
appropriate event.

Add an alternative approach to check the ptrace_state information, directly
from the siginfo_t value returned from PT_GET_SIGINFO. The original
PT_GET_PROCESS_STATE approach is kept for compat with older NetBSD and
OpenBSD. New code is recommended to keep using PT_GET_PROCESS_STATE.

Add a couple of compile-time asserts for assumptions in the code.

No functional change intended in existing ptrace(2) software.

All ATF ptrace(2) and ATF GDB tests pass.

This change improves reliability of the threading ptrace(2) code.
 1.202  04-Jun-2019  kamil branches: 1.202.2;
Stop trying to inform debugger about events from an exiting child

Do not emit signals to parent for if a process is demising:

- fork/vfork/similar
- lwp created/exited
- exec
- syscall entry/exit

With these changes Go applications can be traced without a clash under
a debugger, at least without deadlocking always. The culprit reason was
an attempt to inform a debugger in the middle of exit1() call about
a dying LWP. Go applications perform exit(2) without collecting threads
first. Verified with GDB and picotrace-based utilities like sigtracer.

PR kern/53120
PR port-arm/51677
PR bin/54060
PR bin/49662
PR kern/52548
 1.201  17-May-2019  ozaki-r Implement an aggressive psref leak detector

It is yet another psref leak detector that enables to tell where a leak occurs
while a simpler version that is already committed just tells an occurrence of a
leak.

Investigating of psref leaks is hard because once a leak occurs a percpu list of
psref that tracks references can be corrupted. A reference to a tracking object
is memorized in the list via an intermediate object (struct psref) that is
normally allocated on a stack of a thread. Thus, the intermediate object can be
overwritten on a leak resulting in corruption of the list.

The tracker makes a shadow entry to an intermediate object and stores some hints
into it (currently it's a caller address of psref_acquire). We can detect a
leak by checking the entries on certain points where any references should be
released such as the return point of syscalls and the end of each softint
handler.

The feature is expensive and enabled only if the kernel is built with
PSREF_DEBUG.

Proposed on tech-kern
 1.200  03-May-2019  kamil Register KTR events for debugger related signals

Register signals for:

- crashes (FPE, SEGV, FPE, ILL, BUS)
- LWP events
- CHLD (FORK/VFORK/VFORK_DONE) events -- temporarily disabled
- EXEC events

While there refactor related functions in order to simplify the code.

Add missing comment documentation for recently added kernel functions.
 1.199  02-May-2019  kamil Introduce fixes for ptrace(2)

Stop disabling LWP create and exit events for PT_SYSCALL tracing.
PT_SYSCALL disabled EXEC reporting for legacy reasons, there is no need
to repeat it for LWP and CHLD events.

Pass full siginfo from trapsignal events (SEGV, BUS, ILL, TRAP, FPE).
This adds missing information about signals like fault address.

Set ps_lwp always.

Before passing siginfo to userland through p_sigctx.ps_info, make sure
that it was zeroed for unused bytes. LWP and CHLD events do not set si_addr
and si_trap, these pieces of information are passed for crashes (like
software breakpoint).

LLDB crash reporting works now correctly:

(lldb) r
Process 552 launched: '/tmp/a.out' (x86_64)
Process 552 stopped
* thread #1, stop reason = signal SIGSEGV: invalid address (fault address: 0x123456)
 1.198  01-May-2019  kamil Correct passing debugger related events for LWP create and exit

Add MI toplevel startlwp function.

Switch all userland LWPs to go through lwp_create using a shared
mi_startlwp() function between all MD ABIs.

Add debugger related event handling in mi_startlwp() and continue with
standard p->p_emul->e_startlwp at the end of this routine.

Use eventswitch() to notify the event of LWP exit in lwp_exit().

ATF ptrace(2) tests signal9 and signal10 now pass.
 1.197  19-Apr-2019  ozaki-r Implement a simple psref leak detector

It detects leaks by counting up the number of held psref by an LWP and checking
its zeroness at the end of syscalls and softint handlers. For the counter, a
unused field of struct lwp is reused.

The detector runs only if DIAGNOSTIC is turned on.
 1.196  01-Mar-2019  hannken Move pointer to fstrans private data into "struct lwp".

Ride NetBSD 8.99.35
 1.195  26-Nov-2018  skrll Use cpu_index(). NFC.
 1.194  04-Jul-2018  kamil Avoid undefined behavior in lwp_ctl_free()

Do not left shift signed integer in a way that the signedness bit is
changed.

sys/kern/kern_lwp.c:1892:29, left shift of 1 by 31 places cannot be represented in type 'int'

Detected with Kernel Undefined Behavior Sanitizer.

Reported by <Harry Pantazis>
 1.193  04-Jul-2018  kamil Avoid undefined behavior in lwp_ctl_alloc()

Do not left shift signed integer in a way that the signedness bit is
changed.

sys/kern/kern_lwp.c:1849:27, left shift of 1 by 31 places cannot be represented in type 'int'

Detected with Kernel Undefined Behavior Sanitizer.

Reported by <Harry Pantazis>
 1.192  23-Apr-2018  christos branches: 1.192.2;
PR/kern/53202: Kernel hangs running t_ptrace_wait:resume1 test, revert
previous.
 1.191  02-Dec-2017  christos branches: 1.191.2;
Also wait interruptibly when exiting. Avoids deadlocked on exit processes
create by golang.
 1.190  22-Jun-2017  skrll Unwrap two lines. NFC.
 1.189  01-Jun-2017  chs branches: 1.189.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
 1.188  21-Apr-2017  christos - Propagate the signal mask from the ucontext_t to the newly created thread
as specified by _lwp_create(2)
- Reset the signal stack for threads created with _lwp_create(2)
 1.187  14-Jan-2017  kamil branches: 1.187.2;
Fix generation of PTRACE_LWP_EXIT event

Set p_lwp_exited instead of p_lwp_created for PTRACE_LWP_EXIT.

This made the lwp_exit1 ATF test passing.

Sponsored by <The NetBSD Foundation>
 1.186  14-Jan-2017  kamil Introduce PTRACE_LWP_{CREATE,EXIT} in ptrace(2) and TRAP_LWP in siginfo(5)

Add interface in ptrace(2) to track thread (LWP) events:
- birth,
- termination.

The purpose of this thread is to keep track of the current thread state in
a tracee and apply e.g. per-thread designed hardware assisted watchpoints.

This interface reuses the EVENT_MASK and PROCESS_STATE interface, and
shares it with PTRACE_FORK, PTRACE_VFORK and PTRACE_VFORK_DONE.

Change the following structure:

typedef struct ptrace_state {
int pe_report_event;
pid_t pe_other_pid;
} ptrace_state_t;

to

typedef struct ptrace_state {
int pe_report_event;
union {
pid_t _pe_other_pid;
lwpid_t _pe_lwp;
} _option;
} ptrace_state_t;

#define pe_other_pid _option._pe_other_pid
#define pe_lwp _option._pe_lwp

This keeps size of ptrace_state_t unchanged as both pid_t and lwpid_t are
defined as int32_t-like integer. This change does not break existing
prebuilt software and has minimal effect on necessity for source-code
changes. In summary, this change should be binary compatible and shouldn't
break build of existing software.


Introduce new siginfo(5) type for LWP events under the SIGTRAP signal:
TRAP_LWP. This change will help debuggers to distinguish exact source of
SIGTRAP.


Add two basic t_ptrace_wait* tests:
lwp_create1:
Verify that 1 LWP creation is intercepted by ptrace(2) with
EVENT_MASK set to PTRACE_LWP_CREATE

lwp_exit1:
Verify that 1 LWP creation is intercepted by ptrace(2) with
EVENT_MASK set to PTRACE_LWP_EXIT

All tests are passing.


Surfing the previous kernel ABI bump to 7.99.59 for PTRACE_VFORK{,_DONE}.

Sponsored by <The NetBSD Foundation>
 1.185  03-Jul-2016  christos branches: 1.185.2;
GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.184  04-Apr-2016  christos no need to pass the coredump flag to exit1() since it is set and known
in one place.
 1.183  04-Apr-2016  christos Split p_xstat (composite wait(2) status code, or signal number depending
on context) into:
1. p_xexit: exit code
2. p_xsig: signal number
3. p_sflag & WCOREFLAG bit to indicated that the process core-dumped.

Fix the documentation of the flag bits in <sys/proc.h>
 1.182  26-Nov-2015  martin We never exec(2) with a kernel vmspace, so do not test for that, but instead
KASSERT() that we don't.
When calculating the load address for the interpreter (e.g. ld.elf_so),
we need to take into account wether the exec'd process will run with
topdown memory or bottom up. We can not use the current vmspace's flags
to test for that, as this happens too early. Luckily the execpack already
knows what the new state will be later, so instead of testing the current
vmspace, pass the info as additional argument to struct emul
e_vm_default_addr.
Fix all such functions and adopt all callers.
 1.181  12-Nov-2015  skrll Drop to spl0 after the pmap_activate call. Should address

PR port-arm/50420: curcpu()->ci_pmap_cur != pm || pm->pm_pai[0].pai_asid == curcpu()->ci_pmap_asid_cur" failed

Discussed with matt@ and rmind@
 1.180  02-Oct-2015  christos Change SDT (Statically Defined Tracing) probes to use link sets so that it
is easier to add probes. (From FreeBSD)
 1.179  18-Oct-2014  snj branches: 1.179.2;
src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.178  05-Sep-2014  matt Don't next structure and enum definitions.
Don't use C++ keywords new, try, class, private, etc.
 1.177  25-Nov-2013  christos Use the process credentials instead of the lwp credentials because if the
process just did a setuid() call, the lwp might not have had a chance to
refresh l->l_cred (still has LPR_CRMOD), and we don't want to bother spending
time syncing the creds of a dying lwp. Should fix the problem with hald
people have been observing.
 1.176  22-Nov-2013  christos convert vmem, signals, powerhooks from CIRCLEQ -> TAILQ.
 1.175  09-Jun-2013  riz branches: 1.175.2;
Add another field to the SDT_PROBE_DEFINE macro, so our DTrace probes
can named the same as those on other platforms.

For example, proc:::exec-success, not proc:::exec_success.

Implementation follows the same basic principle as FreeBSD's; add
another field to the SDT_PROBE_DEFINE macro which is the name
as exposed to userland.
 1.174  16-Dec-2012  dsl The lwp_id in a process are supposed to be non-zero and unique.
This stops being true once a process has allocated (and freed) 2^32 lwps.
(I've not timed it!)
There is also some code lurking (eg ld.elf_so) that doesn't expect the
high be be set.
Once the lwp_id wraps, scan the list to find the first free id higher
than the last one allocated.
Maintain the sort order to make the possible.
Note that if some lwp (but not all) are allocated numbers from the pid
space it will go horribly wrong.
Tested by setting the limit to 128 and getting firefox to create threads.
 1.173  27-Sep-2012  rmind exit_lwps, lwp_wait: fix a race condition by re-trying if p_lock was dropped
in a case of process exit. Necessary to re-flag all LWPs for exit, as their
state might have changed or new LWPs spawned.

Should fix PR/46168 and PR/46402.
 1.172  30-Aug-2012  matt branches: 1.172.2;
A few more KASSERT/KASSERTMSG.
 1.171  22-Jul-2012  rmind fork1: fix use-after-free problems. Addresses PR/46128 from Andrew Doran.
Note: PL_PPWAIT should be fully replaced and modificaiton of l_pflag by
other LWP is undesirable, but this is enough for netbsd-6.
 1.170  09-Jun-2012  christos Remove debugging.
 1.169  09-Jun-2012  christos Add a new resource to limit the number of lwps per user, RLIMIT_NTHR. There
is a global sysctl kern.maxlwp to control this, which is by default 2048.
The first lwp of each process or kernel threads are not counted against the
limit. To show the current resource usage per user, I added a new sysctl
that dumps the uidinfo structure fields.
 1.168  13-Apr-2012  yamt comment
 1.167  19-Feb-2012  rmind Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.
 1.166  11-Feb-2012  martin branches: 1.166.2; 1.166.4;
Add a posix_spawn syscall, as discussed on tech-kern.
Based on the summer of code project by Charles Zhang, heavily reworked
later by me - all bugs are likely mine.
Ok: core, releng.
 1.165  15-Dec-2011  jmcneill In lwp_create, copy l_sigstk from the template. Previously sigaltstack wasn't
inherited across fork (but SA_ONSTACK handlers was), causing the child
process to crash when the handler is invoked. ok martin@, christos@
 1.164  19-Oct-2011  yamt branches: 1.164.2; 1.164.6;
don't forget to call kdtrace_thread_ctor for lwp0
 1.163  31-Aug-2011  christos make lwp_unstop look like proc_unstop. If p->p_xstat is set, then make it
runnable so that it can receive the signal.
 1.162  07-Aug-2011  rmind Remove LW_AFFINITY flag and fix some bugs affinity mask handling.
 1.161  30-Jul-2011  christos Add an implementation of passive serialization as described in expired
US patent 4809168. This is a reader / writer synchronization mechanism,
designed for lock-less read operations.
 1.160  26-Jul-2011  yamt assertion
 1.159  13-Jun-2011  matt Deal with PCU state when performing coredumps. As the kernel moves each LWP
into LSSUSPENDED state, have that LWP save its PCU state for the coredump and
release its PCU status since its probably going to be exiting very soon.
Make pcu_save_all tolerate for being called for non-curlwp if that lwp belongs
to the same process, has a state of LSSUSPENDED, and no PCUs are in use.

Make the MD coredump code use pcu_save_all(l) since it'll need to save all
the PCU state anyways and can take advantage of the above tests.
 1.158  06-Jun-2011  matt Add some more MI hook points for PCU. Discard the PCU state at lwp_exit and
at exec time. Before forking, save the PCU state so that cpu_lwp_fork
doesn't have. Remove MD code which did that before.
 1.157  20-Mar-2011  rmind branches: 1.157.2;
Optimise mutex_onproc() and rw_onproc() by making them O(1), instead
of O(ncpu) for adaptive paths. Add an LWP destructor, lwp_dtor() with
a comment describing the principle of this barrier.

Reviewed by yamt@ and ad@.
 1.156  21-Feb-2011  pooka Borrow the lwpctl data area from the parent for the vfork() child.
Otherwise the child will incorrectly see it is not running on any
CPU. Among other things, this fixes crashes from having
LD_PRELOAD=libpthread.so set in the env.

reviewed by tech-kern
 1.155  17-Feb-2011  matt When freeing a lwp, make sure it's biglock count is 0.
 1.154  17-Jan-2011  matt branches: 1.154.2;
If LWP0_MD_INITIALIZER is defined, use it to initalize .l_md (avoid runtime
to do it if possible).
 1.153  14-Jan-2011  rmind branches: 1.153.2;
Retire struct user, remove sys/user.h inclusions. Note sys/user.h header
as obsolete. Remove USER_TO_UAREA/UAREA_TO_USER macros.

Various #include fixes and review by matt@.
 1.152  18-Dec-2010  rmind - Fix a few possible locking issues in execve1() and exit1(). Add a note
that scheduler locks are special in this regard - adaptive locks cannot
be in the path due to turnstiles. Randomly spotted/reported by uebayasi@.
- Remove unused lwp_relock() and replace lwp_lock_retry() by simplifying
lwp_lock() and sleepq_enter() a little.
- Give alllwp its own cache-line and mark lwp_cache pointer as read-mostly.

OK ad@
 1.151  07-Jul-2010  chs many changes for COMPAT_LINUX:
- update the linux syscall table for each platform.
- support new-style (NPTL) linux pthreads on all platforms.
clone() with CLONE_THREAD uses 1 process with many LWPs
instead of separate processes.
- move the contents of sys__lwp_setprivate() into a new
lwp_setprivate() and use that everywhere.
- update linux_release[] and linux32_release[] to "2.6.18".
- adjust placement of emul fork/exec/exit hooks as needed
and adjust other emul code to match.
- convert all struct emul definitions to use named initializers.
- change the pid allocator to allow multiple pids to refer to the same proc.
- remove a few fields from struct proc that are no longer needed.
- disable the non-functional "vdso" code in linux32/amd64,
glibc works fine without it.
- fix a race in the futex code where we could miss a wakeup after
a requeue operation.
- redo futex locking to be a little more efficient.
 1.150  01-Jul-2010  rmind Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.
 1.149  13-Jun-2010  yamt increment p_nrlwps in lwp_create rather than letting callers do so
as it's always decremented by lwp_exit. this fixes error recovery of
eg. aio_procinit.
 1.148  11-Jun-2010  pooka Fix DIAGNOSTIC. Moral of the story: don't comment xen kernels out of the
build even if you'd like to go to sleep earlier.
 1.147  10-Jun-2010  pooka lwp0 seems like an lwp instead of a process, so move bits related
to it from kern_proc.c to kern_lwp.c. This makes kern_proc
"scheduling-clean" and more easily usable in environments with a
non-integrated scheduler (like, to take a random example, rump).
 1.146  23-Apr-2010  rmind Remove lwp_uc_pool, replace it with kmem(9), plus add some consistency.
As discussed, a while ago, with ad@.
 1.145  12-Apr-2010  pooka tyop
 1.144  12-Apr-2010  pooka Separate lwp specificdata data structure management from lwp cpu/vm
management.

No functional change.

(specificdata routines went from kern_lwp.c to subr_lwp_specificdata.c)
 1.143  09-Apr-2010  njoly Make lwp_ctl_alloc() return 0 instead of EINVAL, when lwpctl user
address already exists. This allow calling _lwp_ctl(2) more than once
on the same LWP.
 1.142  06-Apr-2010  christos PR/43128: Paul Koning: Threads support in ptrace() is insufficient for gdb to
debug threaded live apps: Add an optional lwpid in PT_STEP and PT_CONTINUE to
indicate which lwp to operate on, and implement the glue required to make it
work.
 1.141  01-Mar-2010  darran branches: 1.141.2;
DTrace: Add an SDT (Statically Defined Tracing) provider framework, and
implement most of the proc provider. Adds proc:::create, exec,
exec_success, exec_faillure, signal_send, signal_discard, signal_handle,
lwp_create, lwp_start, lwp_exit.
 1.140  23-Feb-2010  darran DTrace: Get rid of the KDTRACE_HOOKS ifdefs in the kernel. Replace the
functions with inline function that are empty when KDTRACE_HOOKS is not
defined.
 1.139  21-Feb-2010  darran Added a defflag option for KDTRACE_HOOKS and included opt_dtrace.h in the
relevant files. (Per Quentin Garnier - thanks!).
 1.138  21-Feb-2010  darran Add the DTrace hooks to the kernel (KDTRACE_HOOKS config option).
DTrace adds a pointer to the lwp and proc structures which it uses to
manage its state. These are opaque from the kernel perspective to keep
the kernel free of CDDL code. The state arenas are kmem_alloced and freed
as proccesses and threads are created and destoyed.

Also add a check for trap06 (privileged/illegal instruction) so that
DTrace can check for D scripts that may have triggered the trap so it
can clean up after them and resume normal operation.

Ok with core@.
 1.137  17-Dec-2009  rmind branches: 1.137.2;
Replace few USER_TO_UAREA/UAREA_TO_USER uses, reduce sys/user.h inclusions.
 1.136  27-Oct-2009  rmind - Amend fd_hold() to take an argument and add assert (reflects two cases,
fork1() and the rest, e.g. kthread_create(), when creating from lwp0).

- lwp_create(): do not touch filedesc internals, use fd_hold().
 1.135  22-Oct-2009  rmind Avoid #ifndef __NO_CPU_LWP_FREE, only ia64 is missing cpu_lwp_free
routines and it can/should provide stubs.
 1.134  21-Oct-2009  rmind Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.
 1.133  13-Sep-2009  pooka Wipe out the last vestiges of POOL_INIT with one swift stroke. In
most cases, use a proper constructor. For proplib, give a local
equivalent of POOL_INIT for the kernel object implementation. This
way the code structure can be preserved, and a local link set is
not hazardous anyway (unless proplib is split to several modules,
but that'll be the day).

tested by booting a kernel in qemu and compile-testing i386/ALL
 1.132  10-Jul-2009  dyoung In lwp_create(), take a reference to l2's filedesc_t instead of
taking a reference to curlwp's by calling fd_hold(). If lwp_create()
is called from fork1(), then l2 != curlwp, but l2's and not curlwp's
filedesc_t whose reference we should take.

This change stops the problem I describe in
<http://mail-index.netbsd.org/tech-kern/2009/07/09/msg005422.html>,
where /dev/rsd0a is never properly closed after fsck / runs on it.
This change seems to quiet my USB backup drive, sd0 at scsibus0 at
umass0, which had stopped spinning down when it was not in use:
The unit probably stayed open after mount(8) tried (and failed:
errant fstab entry) to mount it.

I am confident that this change is an improvement, but I doubt that
it is the last word on the matter. I hate to get under the filedesc_t
abstraction by fiddling with fd_refcnt, and there may be something
I have missed, so somebody with greater understanding of the file
descriptors code should have a look.
 1.131  23-May-2009  ad Make descriptor access and file allocation cheaper in many cases,
mostly by avoiding a bunch of atomic operations.
 1.130  23-May-2009  ad - Add lwp_pctr(), get an LWP's preemption/ctxsw counter.
- Fix a preemption bug in CURCPU_IDLE_P() that can lead to a bogus
assertion failure on DEBUG kernels.
- Fix MP/preemption races with timecounter detachment.
 1.129  04-Apr-2009  ad Update the big comment block.
 1.128  03-Mar-2009  rmind lwp_create: fix the locking bugs on affinity ingerition path (mea culpa).
pset_assign: traverse the list of LWPs safely.
sched_setaffinity: free cpuset (unused path) outside the lock.

Reviewed (with feedback) by <ad>.
 1.127  04-Feb-2009  ad branches: 1.127.2;
PR kern/36183 problem with ptrace and multithreaded processes

Fix the crashy test case that Thor provided.
 1.126  28-Oct-2008  wrstuden branches: 1.126.2;
Tweak change to move SA support from userret() to lwp_userret().

1) Since we want to check for upcalls only once, take LW_SA_UPCALL
out of the while(l->l_flags & LW_USERRET) loop.

2) since the goal is to keep SA code out of userret() (and especially
all the emulations that include userret() but will never do SA),
ALWAYS set LW_SA_UPCALL when we set SAVP_FLAG_NOUPCALLS. Drop the
test for it in lwp_userret() since it will never be set bare.

3) Adapt sa_upcall_userret() to clear LW_SA_UPCALL if it's no longer
needed. If we have gained upcalls since sa_yield(), we will deliver
them next time around.

Tested by skrll at.
 1.125  21-Oct-2008  ad branches: 1.125.2;
Undo revivesa damage to userret().
 1.124  15-Oct-2008  wrstuden Merge wrstuden-revivesa into HEAD.
 1.123  07-Oct-2008  rmind - Replace lwp_t::l_sched_info with union: pointer and timeslice.
- Change minimal time-quantum to ~20 ms.
- Thus remove unneeded pool in M2, and unused sched_lwp_exit().
- Do not increase l_slptime twice for SCHED_4BSD (regression fix).
 1.122  14-Jul-2008  rmind - Disallow setting of affinity for zombie LWPs.
- Fix the possible NULL dereference when LWP exiting.
- Fix the inhertance of affinity.
 1.121  02-Jul-2008  rmind branches: 1.121.2;
lwp_migrate: if LWP is still on the CPU (LP_RUNNING), it must be handled
like LSONPROC. Should fix PR/38588. OK by <ad>.
 1.120  02-Jul-2008  rmind Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.
 1.119  16-Jun-2008  ad lwp_lock_retry: return a pointer to the lock acquired. No functional change.
 1.118  16-Jun-2008  rmind - Add general cpuset macros.
- Use kcpuset name for kernel-only functions.
- Use cpuid_t to specify CPU ID.
- Unify all cpuset users.

API is expected to be stable now.
 1.117  15-Jun-2008  christos Don't expose struct cpuset, share the l_affinity flag and only allocate it
if we need to. This is not a compatible change, but the syscalls are new
enough and they don't need to be versioned. Approved by rmind.
 1.116  02-Jun-2008  ad branches: 1.116.2;
If vfork(), we want the LWP to run fast and on the same CPU
as its parent, so that it can reuse the VM context and cache
footprint on the local CPU.
 1.115  31-May-2008  ad PR kern/38812 race between lwp_exit_switchaway and exit1/coredump

Move the LWP RUNNING and TIMEINTR flags into the thread-private flag word.
 1.114  29-May-2008  rmind Simplifcation for running LWP migration. Removes double-locking in
mi_switch(), migration for LSONPROC is now performed via idle loop.
Handles/fixes on-CPU case in lwp_migrate(), misc.

Closes PR/38169, idea of migration via idle loop by Andrew Doran.
 1.113  27-May-2008  ad Move lwp_exit_switchaway() into kern_synch.c. Instead of always switching
to the idle loop, pick a new LWP from the run queue.
 1.112  26-May-2008  ad Take the mutex pointer and waiters count out of sleepq_t: the values can
be or are maintained elsewhere. Now a sleepq_t is just a TAILQ_HEAD.
 1.111  19-May-2008  ad Reduce ifdefs due to MULTIPROCESSOR slightly.
 1.110  06-May-2008  ad branches: 1.110.2;
LOCKDEBUG: try to speed it up a bit by not using so much global state.

This will break the build briefly but will be followed by another commit
to fix that..
 1.109  01-May-2008  rmind lwp_suspend: check for LW_* flags in l_flag, not l_stat.
 1.108  28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.107  28-Apr-2008  ad Add MI code to support in-kernel preemption. Preemption is deferred by
one of the following:

- Holding kernel_lock (indicating that the code is not MT safe).
- Bracketing critical sections with kpreempt_disable/kpreempt_enable.
- Holding the interrupt priority level above IPL_NONE.

Statistics on kernel preemption are reported via event counters, and
where preemption is deferred for some reason, it's also reported via
lockstat. The LWP priority at which preemption is triggered is tuneable
via sysctl.
 1.106  27-Apr-2008  ad branches: 1.106.2;
Disable preemption during the final stages of LWP exit.
 1.105  25-Apr-2008  ad lwp_startup: spl0 after pmap_activate, otherwise we could be preempted
without a pmap active.
 1.104  24-Apr-2008  ad lwp_userret: don't drop p_lock while holding a scheduler lock.
 1.103  24-Apr-2008  ad Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.
 1.102  24-Apr-2008  ad Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.
 1.101  15-Apr-2008  rmind branches: 1.101.2;
Adjust comments: spc_mutex is now always a per-CPU lock, L_INMEM -> LW_INMEM,
L_WSUSPEND -> LW_WSUSPEND, and remove white-spaces, while here.
 1.100  27-Mar-2008  ad Make rusage collection per-LWP and collate in the appropriate places.
cloned threads need a little bit more work but the locking needs to
be fixed first.
 1.99  23-Mar-2008  ad lwp_ctl_alloc: initialize lcp_kaddr to vm_map_min(kernel_map), in order to
prevent uvm_map() from spuriously failing.
 1.98  22-Mar-2008  ad LWP_CACHE_CREDS: instead of testing (l_cred != p_cred), use a per-LWP
flag bit to indicate a pending cred update. Avoids touching one item of
shared state in the syscall path.
 1.97  21-Mar-2008  ad Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.
 1.96  17-Mar-2008  ad Add a boolean parameter to syncobj_t::sobj_unsleep. If true we want the
existing behaviour: the unsleep method unlocks and wakes the swapper if
needs be. If false, the caller is doing a batch operation and will take
care of that later. This is kind of ugly, but it's difficult for the caller
to know which lock to release in some situations.
 1.95  07-Mar-2008  ad lwp_ctl_exit: fix a use-after-free that caused the following:

_lwp_ctl() <- works
execve() <- tears down lwpctl state
_lwp_ctl() <- fails erroneously
 1.94  22-Feb-2008  rmind sys__sched_getparam and sys__sched_getaffinity: Do not assume that LWP
with LID=1 exists, use LIST_FIRST(&p->p_lwps) instead.
Fixes PR/37987 by <yamt>.

While here, adjust license.
 1.93  28-Jan-2008  yamt branches: 1.93.2; 1.93.6;
wrap a long line.
 1.92  28-Jan-2008  yamt lwp_free: add assertions.
 1.91  15-Jan-2008  rmind Implementation of processor-sets, affinity and POSIX real-time extensions.
Add schedctl(8) - a program to control scheduling of processes and threads.

Notes:
- This is supported only by SCHED_M2;
- Migration of LWP mechanism will be revisited;

Proposed on: <tech-kern>. Reviewed by: <ad>.
 1.90  12-Jan-2008  ad - lwp_exit: if the LWP has a name, rename it to "(zombie)".
- lwp_free: don't leak l_name.
 1.89  07-Jan-2008  yamt lwp_ctl_alloc: fix error handling.
 1.88  02-Jan-2008  ad Merge vmlocking2 to head.
 1.87  26-Dec-2007  ad Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.
 1.86  22-Dec-2007  yamt use binuptime for l_stime/l_rtime.
 1.85  13-Dec-2007  yamt include <sys/user.h>.
 1.84  13-Dec-2007  yamt add ddb "whatis" command. inspired from solaris ::whatis dcmd.
 1.83  03-Dec-2007  ad branches: 1.83.2; 1.83.4; 1.83.6;
Soft interrupts can now take proclist_lock, so there is no need to
double-lock alllwp or allproc.
 1.82  03-Dec-2007  ad For the slow path soft interrupts, arrange to have the priority of a
borrowed user LWP raised into the 'kernel RT' range if the LWP sleeps
(which is unlikely).
 1.81  02-Dec-2007  ad - mi_switch: adjust so that we don't have to hold the old LWP locked across
context switch, since cpu_switchto() can be slow under certain conditions.
From rmind@ with adjustments by me.
- lwpctl: allow LWPs to reregister instead of returning EINVAL. Just return
their existing lwpctl user address.
 1.80  13-Nov-2007  skrll Explicitly include <uvm/uvm_object.h>
 1.79  13-Nov-2007  yamt lwp_ctl_alloc: fix a mutex_enter/exit mismatch.
 1.78  12-Nov-2007  ad Add _lwp_ctl() system call: provides a bidirectional, per-LWP communication
area between processes and the kernel.
 1.77  11-Nov-2007  matt Change some initialization of static queues to compile time.
(xxx_INIT to xxx_HEAD_INITIALIZER). Drop code which inits
non-auto (global or static) variables to 0 since that's
already implied by being non-auto. Init some static/global
cpu_simple_locks at compile time.
 1.76  07-Nov-2007  ad Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.
 1.75  06-Nov-2007  ad Merge scheduler changes from the vmlocking branch. All discussed on
tech-kern:

- Invert priority space so that zero is the lowest priority. Rearrange
number and type of priority levels into bands. Add new bands like
'kernel real time'.
- Ignore the priority level passed to tsleep. Compute priority for
sleep dynamically.
- For SCHED_4BSD, make priority adjustment per-LWP, not per-process.
 1.74  13-Oct-2007  rmind branches: 1.74.2; 1.74.4;
- Fix a comment: LSIDL is covered by spc_mutex, not spc_lwplock.
- mi_switch: Add a comment that spc_lwplock might not necessary be held.
 1.73  09-Oct-2007  rmind Import of SCHED_M2 - the implementation of new scheduler, which is based
on the original approach of SVR4 with some inspirations about balancing
and migration from Solaris. It implements per-CPU runqueues, provides a
real-time (RT) and time-sharing (TS) queues, ready to support a POSIX
real-time extensions, and also prepared for the support of CPU affinity.

The following lines in the kernel config enables the SCHED_M2:

no options SCHED_4BSD
options SCHED_M2

The scheduler seems to be stable. Further work will come soon.

http://mail-index.netbsd.org/tech-kern/2007/10/04/0001.html
http://www.netbsd.org/~rmind/m2/mysql_bench_ro_4x_local.png
Thanks <ad> for the benchmarks!
 1.72  08-Oct-2007  ad Merge from vmlocking: fix LWP reference counting problems.
 1.71  25-Sep-2007  ad curlwp appears to be set by all active copies of cpu_switchto - remove
the MI assignments and assert that it's set in mi_switch().
 1.70  06-Sep-2007  ad branches: 1.70.2;
- Fix sleepq_block() to return EINTR if the LWP is cancelled. Pointed out
by yamt@.

- Introduce SOBJ_SLEEPQ_LIFO, and use for LWPs sleeping via _lwp_park.
libpthread enqueues most waiters in LIFO order to try and wake LWPs that
ran recently, since their working set is more likely to be in cache.
Matching the order of insertion reduces the time spent searching queues
in the kernel.

- Do not boost the priority of LWPs sleeping in _lwp_park, just let them
sleep at their user priority level. LWPs waiting for some I/O event in
the kernel still wait with kernel priority and get woken more quickly.
This needs more evaluation and is to be revisited, but the effect on a
variety of benchmarks is positive.

- When waking LWPs, do not send an IPI to remote CPUs or arrange for the
current LWP to be preempted unless (a) the thread being awoken has kernel
priority and has higher priority than the currently running thread or (b)
the remote CPU is idle.
 1.69  02-Aug-2007  rmind branches: 1.69.2; 1.69.4; 1.69.6;
sys__lwp_suspend: implement waiting for target LWP status changes (or
process exiting). Removes XXXLWP.

Reviewed by <ad> some time ago..
 1.68  31-Jul-2007  tnn Fix previous; lwp status are states, not flags.
 1.67  31-Jul-2007  tnn proc_representative_lwp:
- Correct expression for checking if the lwp is running.
- Remove dead code. Ok'd by Andrew Doran.
 1.66  28-Jul-2007  ad Update the blurb to match reality.
 1.65  09-Jul-2007  ad branches: 1.65.2;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.64  17-May-2007  yamt merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.
 1.63  21-Mar-2007  ad Improvements to lwp_wait1(), for PR kern/35932:

- Better detect simple cycles of threads calling _lwp_wait and return
EDEADLK. Does not handle deeper cycles like t1 -> t2 -> t3 -> t1.
- If there are multiple threads in _lwp_wait, then make sure that
targeted waits take precedence over waits for any LWP to exit.
- When checking for deadlock, also count the number of zombies currently
in the process as potentially reapable. Whenever a zombie is murdered,
kick all waiters to make them check again for deadlock.
- Add more comments.

Also, while here:

- LOCK_ASSERT -> KASSERT in some places
- lwp_free: change boolean arguments to type 'bool'.
- proc_free: let lwp_free spin waiting for the last LWP to exit, there's
no reason to do it here.
 1.62  12-Mar-2007  ad branches: 1.62.2; 1.62.4;
Pass an ipl argument to pool_init/POOL_INIT to be used when initializing
the pool's lock.
 1.61  04-Mar-2007  ad branches: 1.61.2;
lwp_userret: if the process is exiting, don't bother looking for signals.
 1.60  26-Feb-2007  yamt implement priority inheritance.
 1.59  21-Feb-2007  thorpej Pick up some additional files that were missed before due to conflicts
with newlock2 merge:

Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.58  20-Feb-2007  ad When sending signals, only boost the priority of the receiving LWP if
the process is being killed.
 1.57  18-Feb-2007  dsl Add code to support per-system call statistics:
option SYSCALL_STATS counts the number of times each system call is made
option SYSCALL_TIMES counts the amount of time spent in each system call
Currently the counting hooks have only been added to the i386 system call
handler, and the time spent in interrupts is not subtracted.
It ought also be possible to add the times to the processes profiling
counters in order to get a more accurate user/system/interrupt split.
The counts themselves are readable via the sysctl interface.
 1.56  17-Feb-2007  pavel Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
 1.55  16-Feb-2007  ad branches: 1.55.2;
lwp_free(): pass curlwp to KERNEL_LOCK(), not 'l'.
 1.54  15-Feb-2007  ad Restore proc::p_userret in a limited way for Linux compat. XXX
 1.53  15-Feb-2007  yamt newlwp: ensure not to assign lid 0.
 1.52  09-Feb-2007  ad Merge newlock2 to head.
 1.51  23-Dec-2006  ad lwp_update_creds(): acquire the kernel lock to avoid potential deadlock.
 1.50  22-Dec-2006  ad lwp::l_acflag is no longer useful.
 1.49  03-Nov-2006  ad branches: 1.49.2;
- issignal(): acquire the kernel lock before inspecting signal state
- lwp_exit2(): don't drop the kernel lock until after doing wakeup()
 1.48  01-Nov-2006  yamt remove some __unused from function parameters.
 1.47  24-Oct-2006  hannken Remove specificdata_setspecific_nowait() as result of discussion on tech-kern.

Add _lwp_getspecific_by_lwp() to get lwp specific data from other lwp's.
Protected by #ifdef _LWP_API_PRIVATE.

Approved by: Jason Thorpe <thorpej@netbsd.org>
 1.46  12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.45  11-Oct-2006  thorpej Don't free specificdata in lwp_exit2(); it's not safe to block there.
Instead, free an LWP's specificdata from lwp_exit() (if it is not the
last LWP) or exit1() (if it is the last LWP). For consistency, free the
proc's specificdata from exit1() as well. Add lwp_finispecific() and
proc_finispecific() functions to make this more convenient.
 1.44  11-Oct-2006  thorpej Upon further reflection, make lwp_{get,set}specific() operate only on
curlwp. Things that need to operate on "other" LWPs will get a very
special (and very private) API for their needs.
 1.43  09-Oct-2006  martin Remove unused variables.
 1.42  08-Oct-2006  christos add {proc,lwp}_initspecific and use them to init proc0 and lwp0.
 1.41  08-Oct-2006  thorpej Add specificdata support to procs and lwps, each providing their own
wrappers around the speicificdata subroutines. Also:
- Call the new lwpinit() function from main() after calling procinit().
- Move some pool initialization out of kern_proc.c and into files that
are directly related to the pools in question (kern_lwp.c and kern_ras.c).
- Convert uipc_sem.c to proc_{get,set}specific(), and eliminate the p_ksems
member from struct proc.
 1.40  14-Aug-2006  ad branches: 1.40.2; 1.40.4;
sys__lwp_create: put newuc back to the pool on failure.
 1.39  30-Jul-2006  ad Single-thread updates to the process credential.
 1.38  20-Jul-2006  ad Try again.. Move l_cred into the startzero section, and fix the define.
Doesn't change the layout of struct lwp.
 1.37  19-Jul-2006  ad - Hold a reference to the process credentials in each struct lwp.
- Update the reference on syscall and user trap if p_cred has changed.
- Collect accounting flags in the LWP, and collate on LWP exit.
 1.36  22-May-2006  yamt introduce macros, UAREA_TO_USER and USER_TO_UAREA,
to convert uarea VA into a pointer to struct user and vice versa,
so that MD code can change the layout in uarea.
 1.35  26-Apr-2006  yamt branches: 1.35.2;
lwp_suspend: don't forget to decrement p_nrlwps when suspending ourselves.
fix PR/33287 from Gregory McGarry.
 1.34  29-Mar-2006  cube Rework the _lwp* and sa_* families of syscalls so some details can be
handled differently depending on the emulation. This paves the way for
COMPAT_NETBSD32 support of our pthread system.
 1.33  12-Nov-2005  chs branches: 1.33.6; 1.33.8; 1.33.10; 1.33.12; 1.33.14;
disallow non-SA LWP syscalls for SA processes. they add no value
in this context, only headaches.
 1.32  05-Oct-2005  yamt remove a redundant assignment in the previous.
 1.31  01-Oct-2005  yamt simplify lwp exit code.
 1.30  28-Aug-2005  yamt protect p_nrlwps by sched_lock. no objection on tech-kern@. PR/29652.
 1.29  12-Feb-2005  fvdl branches: 1.29.4; 1.29.6;
Don't panic when lwp_suspend finds an LWP on another CPU, just return
EINVAL for now.
 1.28  06-Oct-2004  skrll branches: 1.28.4; 1.28.6;
Correct arg name in comment.
 1.27  12-May-2004  matt In proc_representative_lwp, if there is an outstanding trap signal, return
the lwp that had the trap.
 1.26  05-Mar-2004  junyoung lwp_exit2(): set lwp state to SZOMB at more appropriate point.
 1.25  02-Mar-2004  yamt once exit1() releases big kernel lock, the struct proc can be freed and
re-used by another cpu immediately. in that case, lwp_exit2() will
access freed memory. to fix this:

- remove curlwp from p_lwps in exit1() rather than letting lwp_exit2() do so.
- add assertions to ensure freed proc has no lwps.

kern/24329 from me and kern/24574 from Havard Eidnes.
 1.24  13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.23  09-Feb-2004  yamt - borrow vmspace0 in uvm_proc_exit instead of uvmspace_free.
the latter is not a appropriate place to do so and it broke vfork.
- deactivate pmap before calling cpu_exit() to keep a balance of
pmap_activate/deactivate.
 1.22  09-Feb-2004  yamt lwp_exit2: grab kernel_lock to preserve locking order.
 1.21  06-Feb-2004  junyoung ANSIfy & zap some blank lines.
 1.20  11-Jan-2004  jdolecek g/c process state SDEAD - it's not used anymore after 'reaper' removal
 1.19  04-Jan-2004  jdolecek Rearrange process exit path to avoid need to free resources from different
process context ('reaper').

From within the exiting process context:
* deactivate pmap and free vmspace while we can still block
* introduce MD cpu_lwp_free() - this cleans all MD-specific context (such
as FPU state), and is the last potentially blocking operation;
all of cpu_wait(), and most of cpu_exit(), is now folded into cpu_lwp_free()
* process is now immediatelly marked as zombie and made available for pickup
by parent; the remaining last lwp continues the exit as fully detached
* MI (rather than MD) code bumps uvmexp.swtch, cpu_exit() is now same
for both 'process' and 'lwp' exit

uvm_lwp_exit() is modified to never block; the u-area memory is now
always just linked to the list of available u-areas. Introduce (blocking)
uvm_uarea_drain(), which is called to release the excessive u-area memory;
this is called by parent within wait4(), or by pagedaemon on memory shortage.
uvm_uarea_free() is now private function within uvm_glue.c.

MD process/lwp exit code now always calls lwp_exit2() immediatelly after
switching away from the exiting lwp.

g/c now unneeded routines and variables, including the reaper kernel thread
 1.18  03-Jan-2004  jdolecek constify a bit
 1.17  24-Dec-2003  manu Split sys_lwp_suspend, just like sys_lwp_unsuspend is split. We get
sys_lwp_suspend, with the sanity checks, and lwp_suspend, with the
actual implementation.
 1.16  20-Dec-2003  manu Introduce lwp_emuldata and the associated hooks. No hook is provided for the
exec case, as the emulation already has the ability to intercept that
with the e_proc_exec hook. It is the responsability of the emulation to
take appropriaye action about lwp_emuldata in e_proc_exec.

Patch reviewed by Christos.
 1.15  04-Nov-2003  dsl Remove p_nras from struct proc - use LIST_EMPTY(&p->p_raslist) instead.
Remove p_raslock and rename p_lwplock p_lock (one lock is enough).
Simplify window test when adding a ras and correct test on VM_MAXUSER_ADDRESS.
Avoid unpredictable branch in i386 locore.S
(pad fields left in struct proc to avoid kernel bump)
 1.14  30-Oct-2003  cl Don't grab the sched lock in lwp_continue() because lwp_continue() is
called from kpsignal2() with the sched lock held. Get the lock in
sys__lwp_continue() instead.
 1.13  19-Oct-2003  simonb Remove unreachable break after return and goto statements.
 1.12  28-Jul-2003  matt Improve _lwp_wakeup so when it wakes a thread, the target thread thinks
ltsleep has been interrupted and thus the target will not think it was
a spurious wakeup. (this makes syscalls cancellable for libpthread).
 1.11  17-Jul-2003  fvdl Return the value of 'error' instead of always 0. From Christian Limpach.
 1.10  17-Jul-2003  fvdl Changes from Stephan Uphoff to patch problems with LWPs blocking when they
shouldn't, and MP.
 1.9  14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.8  23-Jun-2003  martin branches: 1.8.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.7  21-May-2003  kristerw Use 0 instead of NULL for size parameters.
 1.6  19-Mar-2003  dsl Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.
 1.5  30-Jan-2003  matt Add a KASSERT when copying l1->l_cpu to l2->l_cpu
 1.4  29-Jan-2003  nathanw Fix _lwp_wakeup() so that it stands a chance of working (although it
turns out to be insufficent for signal-level interruption of system
calls. guess we need _lwp_kill(), ugh).
 1.3  28-Jan-2003  nathanw Fix proc_representative_lwp(); a closing brace was in the wrong place,
which means it would return the first non-dead LWP.

Pointed out by Stephan Uphoff.
 1.2  18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1  05-Mar-2001  nathanw branches: 1.1.2;
file kern_lwp.c was initially added on branch nathanw_sa.
 1.1.2.24  17-Jan-2003  thorpej Implement _lwp_getprivate(2) and _lwp_setprivate(2).
 1.1.2.23  17-Jan-2003  thorpej Minor cosmetic hanges.
 1.1.2.22  15-Dec-2002  thorpej Add an "inmem" argument to newlwp(), and use it to properly set
up L_INMEM in the new LWP. Should fix a problem mentioned to me
by Nick Hudson.
 1.1.2.21  15-Dec-2002  thorpej Use uvm_uarea_alloc().
 1.1.2.20  25-Nov-2002  nathanw Release the kernel lock in lwp_exit(), before calling cpu_exit().
 1.1.2.19  27-Oct-2002  nathanw Clean up some trailing whitespace.
 1.1.2.18  25-Oct-2002  nathanw The "trivial case" in proc_representative_lwp() is when p->p_nlwps is
1, not when p->p_nrlwps is 1.

Pointed out by Nick Hudson.
 1.1.2.17  24-Oct-2002  nathanw Rewrite proc_representative_lwp() to cope with the new way of stopping
LWPs; in particular, it can't assume that any of the LWPs are
*actually* stopped yet, as they could be sleeping, or runnable or
onproc on their way back to userland where they will be stopped.

Instead, for both SSTOP and SACTIVE procs, pick the "most live" LWP,
and include LSSTOP in the hierarchy.
 1.1.2.16  22-Oct-2002  nathanw Add a missing splx(s) in sys__lwp_suspend().
 1.1.2.15  29-Aug-2002  nathanw Move some code out of lwp_exit() to sa_yield(), which was the only place
exercising it.
 1.1.2.14  26-Jul-2002  nathanw Move the core work of sys__lwp_continue into lwp_continue().
 1.1.2.13  12-Jul-2002  nathanw In lwp_wait1, don't pass PCATCH to tsleep() in the EXITCONTROL case.
 1.1.2.12  12-Jul-2002  nathanw No longer need to pull in lwp.h; proc.h pulls it in for us.
 1.1.2.11  24-Jun-2002  nathanw Curproc->curlwp renaming.

Change uses of "curproc->l_proc" back to "curproc", which is more like the
original use. Bare uses of "curproc" are now "curlwp".

"curproc" is now #defined in proc.h as ((curlwp) ? (curlwp)->l_proc) : NULL)
so that it is always safe to reference curproc (*de*referencing curproc
is another story, but that's always been true).
 1.1.2.10  20-Jun-2002  thorpej Need to include <sys/sa.h> before <sys/savar.h>
 1.1.2.9  02-Apr-2002  nathanw - Centralize p_nrlwps handling in those functions which actually
set the LWP state to LSRUN. Simplifies matters considerably.

- Trying to keep track of the preempted LWP was a bad idea; go back
to searching for now.

- Send a PREEMPTED upcall from proc_unstop(), so that stopped processes
know that something happened, and so that all runnable LWPs of a unstopped
process have an upcall to deliver (Ideally, the LWP that was runnable
when the process was stopped should return first, and any LWPs that were
woken up while the process was stopped would interrupt it, but that's
difficult to arrange).
 1.1.2.8  06-Feb-2002  nathanw Don't panic if we return from putting ourselves on the LWP cache in lwp_exit();
it makes sense if the process tries to exit before the cached LWP has been
used.
 1.1.2.7  04-Feb-2002  nathanw In lwp_exit(), recycle SA LWPs onto the LWP cache instead of exiting.
 1.1.2.6  28-Jan-2002  nathanw Add a system call, _lwp_wakeup(), to wake up LWPs that are sleeping
interruptably. This is necessary when another thread has requested the
cancellation of a thread that is sleeping in the kernel.

This interface is slightly klugey. It might be better handled with a _lwp_kill()
interface, but that requires all of the machinery to deliver signals to
individual LWPs, which is large, complicated, and not clearly necessary.
 1.1.2.5  29-Nov-2001  nathanw Make proc_representative_lwp() non-static and move it to kern_lwp.c.
 1.1.2.4  24-Aug-2001  nathanw A few files and lwp/proc conversions I missed in the last big update.
GENERIC runs again.
 1.1.2.3  13-Jul-2001  nathanw Note copyright.
 1.1.2.2  09-Jul-2001  nathanw Minor SCHED_LOCK() paranoia.
 1.1.2.1  05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.8.2.7  11-Dec-2005  christos Sync with head.
 1.8.2.6  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.8.2.5  15-Feb-2005  skrll Sync with HEAD.
 1.8.2.4  19-Oct-2004  skrll Sync with HEAD
 1.8.2.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.2.2  18-Sep-2004  skrll Sync with HEAD.
 1.8.2.1  03-Aug-2004  skrll Sync with HEAD
 1.28.6.1  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.28.4.1  29-Apr-2005  kent sync with -current
 1.29.6.12  24-Mar-2008  yamt sync with head.
 1.29.6.11  17-Mar-2008  yamt sync with head.
 1.29.6.10  27-Feb-2008  yamt sync with head.
 1.29.6.9  04-Feb-2008  yamt sync with head.
 1.29.6.8  21-Jan-2008  yamt sync with head
 1.29.6.7  07-Dec-2007  yamt sync with head
 1.29.6.6  15-Nov-2007  yamt sync with head.
 1.29.6.5  27-Oct-2007  yamt sync with head.
 1.29.6.4  03-Sep-2007  yamt sync with head.
 1.29.6.3  26-Feb-2007  yamt sync with head.
 1.29.6.2  30-Dec-2006  yamt sync with head.
 1.29.6.1  21-Jun-2006  yamt sync with head.
 1.29.4.2  13-Nov-2005  tron Pull up following revision(s) (requested by chs in ticket #954):
sys/kern/kern_lwp.c: revision 1.33
disallow non-SA LWP syscalls for SA processes. they add no value
in this context, only headaches.
 1.29.4.1  04-Oct-2005  tron Pull up following revision(s) (requested by yamt in ticket #842):
sys/sys/proc.h: revision 1.206
sys/kern/kern_lwp.c: revision 1.30
sys/kern/kern_exit.c: revision 1.151
protect p_nrlwps by sched_lock. no objection on tech-kern@. PR/29652.
 1.33.14.2  24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.33.14.1  31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.33.12.2  11-May-2006  elad sync with head
 1.33.12.1  19-Apr-2006  elad sync with head.
 1.33.10.4  03-Sep-2006  yamt sync with head.
 1.33.10.3  11-Aug-2006  yamt sync with head
 1.33.10.2  24-May-2006  yamt sync with head.
 1.33.10.1  01-Apr-2006  yamt sync with head.
 1.33.8.2  01-Jun-2006  kardel Sync with head.
 1.33.8.1  22-Apr-2006  simonb Sync with head.
 1.33.6.1  09-Sep-2006  rpaulo sync with head
 1.35.2.1  19-Jun-2006  chap Sync with head.
 1.40.4.2  10-Dec-2006  yamt sync with head.
 1.40.4.1  22-Oct-2006  yamt sync with head
 1.40.2.20  05-Feb-2007  ad - When clearing signals dequeue siginfo first and free later, once
outside the lock permiter.
- Push kernel_lock back in a a couple of places.
- Adjust limcopy() to be MP safe (this needs redoing).
- Fix a couple of bugs noticed along the way.
- Catch up with condvar changes.
 1.40.2.19  03-Feb-2007  ad - Require that cv_signal/cv_broadcast be called with the interlock held.
- Provide 'async' versions that's don't need the interlock.
 1.40.2.18  01-Feb-2007  ad Get sh3 compiling.
 1.40.2.17  31-Jan-2007  ad - Have callers to mi_switch() drop the kernel lock.
- Fix a deadlock and some typos.
- Unbreak ptrace().
 1.40.2.16  30-Jan-2007  ad Remove support for SA. Ok core@.
 1.40.2.15  28-Jan-2007  ad - Fix sequence error between saving/raising the SPL.
- Changes for JavaStation.
- Fix bugs with mips & sparc support routines.
 1.40.2.14  27-Jan-2007  ad Rename some functions to better describe what they do.
 1.40.2.13  27-Jan-2007  ad lwp_need_userret(): don't adjust l_priority if the LWP has kernel priority.
 1.40.2.12  25-Jan-2007  ad Eliminate some uses of mtsleep().
 1.40.2.11  19-Jan-2007  yamt newlwp: don't blindly set L_INMEM for kernel lwps.
fixes double faults observed when an lwp uses more than one page
of its stack.
 1.40.2.10  16-Jan-2007  ad lwp_exit(): don't delay signal delivery if the LWP has been elected to
take a process-wide signal.
 1.40.2.9  16-Jan-2007  ad Minor corrections.
 1.40.2.8  12-Jan-2007  ad Sync with head.
 1.40.2.7  11-Jan-2007  ad Checkpoint work in progress.
 1.40.2.6  29-Dec-2006  ad Checkpoint work in progress.
 1.40.2.5  18-Nov-2006  ad Sync with head.
 1.40.2.4  17-Nov-2006  ad Checkpoint work in progress.
 1.40.2.3  24-Oct-2006  ad - Redo LWP locking slightly and fix some races.
- Fix some locking botches.
- Make signal mask / stack per-proc for SA processes.
- Add _lwp_kill().
 1.40.2.2  21-Oct-2006  ad Checkpoint work in progress on locking and per-LWP signals. Very much a
a work in progress and there is still a lot to do.
 1.40.2.1  11-Sep-2006  ad - Allocate and free turnstiles where needed.
- Split proclist_mutex and alllwp_mutex out of the proclist_lock,
and use in interrupt context.
- Fix an MP race in enterpgrp()/setsid().
- Acquire proclist_lock and p_crmutex in some obvious places.
 1.49.2.1  01-Apr-2007  bouyer Apply patch (requested by chs in ticket #554):
sys/kern/kern_exit.c patch
sys/kern/kern_lwp.c patch
sys/kern/kern_proc.c patch
sys/sys/proc.h patch
Add a new SDYING process state. In exit1() release structures before curlwp is
NULL. It should fix the problem described in PR 34892.
 1.55.2.14  13-May-2007  ad Assign a per-CPU lock to LWPs as they transition into the ONPROC state.

http://mail-index.netbsd.org/tech-kern/2007/05/06/0003.html
 1.55.2.13  21-Apr-2007  ad Some changes mainly for top/ps:

- Add an optional name field to struct lwp.
- Count the total number of context switches + involuntary,
not voluntary + involuntary.
- Mark the idle threads as LSIDL when not running, otherwise
they show up funny in a top(1) that shows threads.
- Make pctcpu and cpticks per-LWP attributes.
- Add to kinfo_lwp: cpticks, pctcpu, pid, name.
 1.55.2.12  16-Apr-2007  ad lwp_exit, lwp_free: also use the LW_RUNNING flag to synchronize collection
of the dead LWP. If an interrupt handler changes curlwp, it could be reaped
while still on the CPU.
 1.55.2.11  16-Apr-2007  ad - Nuke the seperate scheduler locking scheme for UP kernels - it has been
at the root of too many bugs.
- Add a LW_BOUND flag that indicates an LWP is bound to a specific CPU.
 1.55.2.10  24-Mar-2007  ad - Ensure that context switch always happens at least at IPL_SCHED, even
if no spin lock is held. Should fix the assertion failure seen on hppa.
- Reduce the amount of spl frobbing in mi_switch.
- Add some comments.

Reviewed by yamt@.
 1.55.2.9  24-Mar-2007  yamt sync with head.
 1.55.2.8  24-Mar-2007  rmind Checkpoint:
- Abstract for per-CPU locking of runqueues.
As a workaround for SCHED_4BSD global runqueue, covered by sched_mutex,
spc_mutex is a pointer for now. After making SCHED_4BSD runqueues
per-CPU, it will became a storage mutex.
- suspendsched: Locking is not necessary for cpu_need_resched().
- Remove mutex_spin_exit() prototype in patch.c and LOCK_ASSERT() check
in runqueue_nextlwp() in sched_4bsd.c to make them compile again.
 1.55.2.7  12-Mar-2007  rmind Sync with HEAD.
 1.55.2.6  09-Mar-2007  rmind Checkpoint:

- Addition of scheduler-specific pointers in the struct proc, lwp and
schedstate_percpu.
- Addition of sched_lwp_fork(), sched_lwp_exit() and sched_slept() hooks.
- mi_switch() now has only one argument.
- sched_nextlwp(void) becomes sched_switch(struct lwp *) and does an
enqueueing of LWP.
- Addition of general kern.sched sysctl node.
- Remove twice called uvmexp.swtch++, other cleanups.

Discussed on tech-kern@
 1.55.2.5  27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.55.2.4  25-Feb-2007  yamt move cpu_switchto to sys/cpu.h from sys/sched.h.
 1.55.2.3  18-Feb-2007  yamt remove unused lwp_exit2.
 1.55.2.2  18-Feb-2007  yamt update a comment.
 1.55.2.1  17-Feb-2007  yamt - separate context switching and thread scheduling.
- introduce idle lwp.
- change some related MD/MI interfaces and implement i386 version.
 1.61.2.27  05-Nov-2007  ad Don't acquire kernel_lock for uvm_lwp_fork().
 1.61.2.26  05-Nov-2007  ad - Locking tweaks for estcpu/nice. XXX The schedclock musn't run above
IPL_SCHED.
- Hide most references to l_estcpu.
- l_policy was here first, but l_class is referenced in more places now.
 1.61.2.25  01-Nov-2007  ad - Fix interactivity problems under high load. Beacuse soft interrupts
are being stacked on top of regular LWPs, more often than not aston()
was being called on a soft interrupt thread instead of a user thread,
meaning that preemption was not happening on EOI.

- Don't use bool in a couple of data structures. Sub-word writes are not
always atomic and may clobber other fields in the containing word.

- For SCHED_4BSD, make p_estcpu per thread (l_estcpu). Rework how the
dynamic priority level is calculated - it's much better behaved now.

- Kill the l_usrpri/l_priority split now that priorities are no longer
directly assigned by tsleep(). There are three fields describing LWP
priority:

l_priority: Dynamic priority calculated by the scheduler.
This does not change for kernel/realtime threads,
and always stays within the correct band. Eg for
timeshared LWPs it never moves out of the user
priority range. This is basically what l_usrpri
was before.

l_inheritedprio: Lent to the LWP due to priority inheritance
(turnstiles).

l_kpriority: A boolean value set true the first time an LWP
sleeps within the kernel. This indicates that the LWP
should get a priority boost as compensation for blocking.
lwp_eprio() now does the equivalent of sched_kpri() if
the flag is set. The flag is cleared in userret().

- Keep track of scheduling class (OTHER, FIFO, RR) in struct lwp, and use
this to make decisions in a few places where we previously tested for a
kernel thread.

- Partially fix itimers and usr/sys/intr time accounting in the presence
of software interrupts.

- Use kthread_create() to create idle LWPs. Move priority definitions
from the various modules into sys/param.h.

- newlwp -> lwp_create
 1.61.2.24  25-Oct-2007  ad - Simplify debugger/procfs reference counting of processes. Use a per-proc
rwlock: rw_tryenter(RW_READER) to gain a reference, and rw_enter(RW_WRITER)
by the process itself to drain out reference holders before major changes
like exiting.
- Fix numerous bugs and locking issues in procfs.
- Mark procfs MPSAFE.
 1.61.2.23  23-Oct-2007  ad Sync with head.
 1.61.2.22  18-Oct-2007  ad Update for soft interrupt changes. See kern_softint.c 1.1.2.17 for details.
 1.61.2.21  10-Oct-2007  rmind Sync with HEAD.
 1.61.2.20  09-Oct-2007  ad Sync with head.
 1.61.2.19  01-Sep-2007  ad Update for pool_cache API changes.
 1.61.2.18  23-Aug-2007  ad - Remove most calls to get kernel_lock during fault handling.
- By default start new LWPs without kernel_lock. Those returning to
userspace don't need it.
 1.61.2.17  20-Aug-2007  ad Sync with HEAD.
 1.61.2.16  18-Aug-2007  yamt lwp_delref: add assertions.
 1.61.2.15  18-Aug-2007  yamt lwp_exit: fix the case that another LWP acquires l_refcnt while
we are dropping the mutex. ok'ed by Andrew Doran.
 1.61.2.14  15-Jul-2007  ad Sync with head.
 1.61.2.13  01-Jul-2007  ad Adapt to callout API change.
 1.61.2.12  17-Jun-2007  ad - Increase the number of thread priorities from 128 to 256. How the space
is set up is to be revisited.
- Implement soft interrupts as kernel threads. A generic implementation
is provided, with hooks for fast-path MD code that can run the interrupt
threads over the top of other threads executing in the kernel.
- Split vnode::v_flag into three fields, depending on how the flag is
locked (by the interlock, by the vnode lock, by the file system).
- Miscellaneous locking fixes and improvements.
 1.61.2.11  08-Jun-2007  ad Sync with head.
 1.61.2.10  27-May-2007  ad Allow lwp_exit() to operate when (l != curlwp) if the LWP is in state IDL.
 1.61.2.9  28-Apr-2007  ad select/poll:

- Don't try to awaken LWPs more than once. Prevents unnecessary locking.
- Tidy slightly.
 1.61.2.8  10-Apr-2007  ad Sync with head.
 1.61.2.7  10-Apr-2007  ad kernel_lock isn't needed for memory allocation any more.
 1.61.2.6  10-Apr-2007  ad Changes to select/poll:

- Make them MP safe and decouple from the proc locks.
- selwakeup: don't call p_find, or traverse per-proc LWP lists (ouch).
- selwakeup: don't lock the sleep queue unless we need to.
 1.61.2.5  09-Apr-2007  ad - Add two new arguments to kthread_create1: pri_t pri, bool mpsafe.
- Fork kthreads off proc0 as new LWPs, not new processes.
 1.61.2.4  05-Apr-2007  ad - Make context switch counters 64-bit, and count the total number of
context switches + voluntary, instead of involuntary + voluntary.
- Add lwp::l_swaplock for uvm.
- PHOLD/PRELE are replaced.
 1.61.2.3  21-Mar-2007  ad GC the simplelock/spinlock debugging stuff.
 1.61.2.2  13-Mar-2007  ad Pull in the initial set of changes for the vmlocking branch.
 1.61.2.1  13-Mar-2007  ad Sync with head.
 1.62.4.1  29-Mar-2007  reinoud Pullup to -current
 1.62.2.1  11-Jul-2007  mjf Sync with head.
 1.65.2.2  10-Sep-2007  skrll Sync with HEAD.
 1.65.2.1  15-Aug-2007  skrll Sync with HEAD.
 1.69.6.2  02-Aug-2007  rmind sys__lwp_suspend: implement waiting for target LWP status changes (or
process exiting). Removes XXXLWP.

Reviewed by <ad> some time ago..
 1.69.6.1  02-Aug-2007  rmind file kern_lwp.c was added on branch matt-mips64 on 2007-08-02 01:48:45 +0000
 1.69.4.5  23-Mar-2008  matt sync with HEAD
 1.69.4.4  09-Jan-2008  matt sync with HEAD
 1.69.4.3  08-Nov-2007  matt sync with -HEAD
 1.69.4.2  06-Nov-2007  matt sync with HEAD
 1.69.4.1  28-Aug-2007  matt Pre-init the static structures (lwp0,proc0,session0,etc.) whenever possible.
Use curlwp_set()
 1.69.2.7  09-Dec-2007  jmcneill Sync with HEAD.
 1.69.2.6  03-Dec-2007  joerg Sync with HEAD.
 1.69.2.5  14-Nov-2007  joerg Sync with HEAD.
 1.69.2.4  11-Nov-2007  joerg Sync with HEAD.
 1.69.2.3  06-Nov-2007  joerg Sync with HEAD.
 1.69.2.2  26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.69.2.1  02-Oct-2007  joerg Sync with HEAD.
 1.70.2.2  14-Oct-2007  yamt sync with head.
 1.70.2.1  06-Oct-2007  yamt sync with head.
 1.74.4.4  18-Feb-2008  mjf Sync with HEAD.
 1.74.4.3  27-Dec-2007  mjf Sync with HEAD.
 1.74.4.2  08-Dec-2007  mjf Sync with HEAD.
 1.74.4.1  19-Nov-2007  mjf Sync with HEAD.
 1.74.2.1  13-Nov-2007  bouyer Sync with HEAD
 1.83.6.4  19-Jan-2008  bouyer Sync with HEAD
 1.83.6.3  08-Jan-2008  bouyer Sync with HEAD
 1.83.6.2  02-Jan-2008  bouyer Sync with HEAD
 1.83.6.1  13-Dec-2007  bouyer Sync with HEAD
 1.83.4.1  13-Dec-2007  yamt sync with head.
 1.83.2.4  26-Dec-2007  ad - Push kernel_lock back into exit, wait and sysctl system calls, mainly
for visibility.
- Serialize calls to brk() from within the same process.
- Mark more syscalls MPSAFE.
 1.83.2.3  26-Dec-2007  ad Sync with head.
 1.83.2.2  15-Dec-2007  ad - Use pool_cache for a few more items and make those caches static.
- Mark another 10 syscalls MPSAFE including execve(). A small bit of
work is required to fix a couple of issues (tty, kqueue).
 1.83.2.1  04-Dec-2007  ad Pull the vmlocking changes into a new branch.
 1.93.6.6  17-Jan-2009  mjf Sync with HEAD.
 1.93.6.5  28-Sep-2008  mjf Sync with HEAD.
 1.93.6.4  29-Jun-2008  mjf Sync with HEAD.
 1.93.6.3  05-Jun-2008  mjf Sync with HEAD.

Also fix build.
 1.93.6.2  02-Jun-2008  mjf Sync with HEAD.
 1.93.6.1  03-Apr-2008  mjf Sync with HEAD.
 1.93.2.1  24-Mar-2008  keiichi sync with head.
 1.101.2.3  17-Jun-2008  yamt sync with head.
 1.101.2.2  04-Jun-2008  yamt sync with head
 1.101.2.1  18-May-2008  yamt sync with head.
 1.106.2.7  11-Aug-2010  yamt sync with head.
 1.106.2.6  11-Mar-2010  yamt sync with head
 1.106.2.5  16-Sep-2009  yamt sync with head
 1.106.2.4  18-Jul-2009  yamt sync with head.
 1.106.2.3  20-Jun-2009  yamt sync with head
 1.106.2.2  04-May-2009  yamt sync with head.
 1.106.2.1  16-May-2008  yamt sync with head.
 1.110.2.7  10-Oct-2008  skrll Sync with HEAD.
 1.110.2.6  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.110.2.5  21-Jul-2008  wrstuden Add support for compiling SA as an option. Implied by COMPAT_40.

i386 kernels both with COMPAT_40 and with no compat options (and thus
no SA) compile.

No functional changes intended.
 1.110.2.4  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.110.2.3  27-May-2008  wrstuden First cut at porting SA timer code to -current. Slightly modified
so that we now use the timer_intr soft interrupt to do what we used
to do in itimerfire(). Also, use sa_mutex and p_lock instead of
the kernel lock.

Open question about what locks we can lock while holding
the timer lock.
 1.110.2.2  14-May-2008  wrstuden Per discussion with ad at n dot o, revert signal mask handling
changes.

The l_sigstk changes are most likely totally un-needed as SA will
never use a signal stack - we send an upcall (or will as other
diffs are brought in).

The l_sigmask changes were too controvertial. In all honesty, I
think it's probably best to revert them. The main reason they were
there is the fact that in an SA process, we don't mask signals per
kernel thread, we mask them per user thread. In the kernel, we want
them all to get turned into upcalls. Thus the normal state of
l_sigmask in an SA process is for it to always be empty.

While we are in the process of delivering a signal, we want to
temporarily mask a signal (so we don't recursively exhaust our
upcall stacks). However signal delivery is rare (important, but
rare), and delivering back-to-back signals is even rarer. So rather
than cause every user of a signal mask to be prepared for this very
rare case, we will just add a second check later in the signal
delivery code. Said change is not in this diff.

This also un-compensates all of our compatability code for dealing
with SA. SA is a NetBSD-specific thing, so there's no need for
Irix, Linux, Solaris, SVR4 and so on to cope with it.

As previously, everything other than kern_sa.c compiles in i386
GENERIC as of this checkin. I will switch to ALL soon for compile
testing.
 1.110.2.1  10-May-2008  wrstuden Initial checkin of re-adding SA. Everything except kern_sa.c
compiles in GENERIC for i386. This is still a work-in-progress, but
this checkin covers most of the mechanical work (changing signalling
to be able to accomidate SA's process-wide signalling and re-adding
includes of sys/sa.h and savar.h). Subsequent changes will be much
more interesting.

Also, kern_sa.c has received partial cleanup. There's still more
to do, though.
 1.116.2.3  18-Jul-2008  simonb Sync with head.
 1.116.2.2  03-Jul-2008  simonb Sync with head.
 1.116.2.1  18-Jun-2008  simonb Sync with head.
 1.121.2.2  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.121.2.1  19-Oct-2008  haad Sync with HEAD.
 1.125.2.3  28-Apr-2009  skrll Sync with HEAD.
 1.125.2.2  03-Mar-2009  skrll Sync with HEAD.
 1.125.2.1  19-Jan-2009  skrll Sync with HEAD.
 1.126.2.2  08-Mar-2009  snj branches: 1.126.2.2.4;
Pull up following revision(s) (requested by rmind in ticket #546):
sys/kern/kern_lwp.c: revision 1.128
sys/kern/sys_pset.c: revision 1.12
sys/kern/sys_sched.c: revision 1.33
lwp_create: fix the locking bugs on affinity ingerition path (mea culpa).
pset_assign: traverse the list of LWPs safely.
sched_setaffinity: free cpuset (unused path) outside the lock.
Reviewed (with feedback) by <ad>.
 1.126.2.1  06-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #414):
sys/kern/kern_lwp.c: revision 1.127
sys/kern/sys_process.c: revision 1.146
sys/sys/lwp.h: revision 1.117
PR kern/36183 problem with ptrace and multithreaded processes
Fix the crashy test case that Thor provided.
 1.126.2.2.4.2  29-Apr-2011  matt Pull in lwp_setprivate/cpu_lwp_setprivate from -current.
Also pull in lwp_getpcb
 1.126.2.2.4.1  05-Feb-2011  cliff - include opt_multiprocessor.h for explicit MULTIPROCESSOR dependency
 1.127.2.2  23-Jul-2009  jym Sync with HEAD.
 1.127.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.137.2.2  17-Aug-2010  uebayasi Sync with HEAD.
 1.137.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.141.2.5  12-Jun-2011  rmind sync with head
 1.141.2.4  21-Apr-2011  rmind sync with head
 1.141.2.3  05-Mar-2011  rmind sync with head
 1.141.2.2  03-Jul-2010  rmind sync with head
 1.141.2.1  30-May-2010  rmind sync with head
 1.153.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.154.2.1  05-Mar-2011  bouyer Sync with HEAD
 1.157.2.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.164.6.3  29-Apr-2012  mrg sync to latest -current.
 1.164.6.2  24-Feb-2012  mrg sync to -current.
 1.164.6.1  18-Feb-2012  mrg merge to -current.
 1.164.2.4  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.164.2.3  23-Jan-2013  yamt sync with head
 1.164.2.2  30-Oct-2012  yamt sync with head
 1.164.2.1  17-Apr-2012  yamt sync with head
 1.166.4.1  01-Nov-2012  matt sync with netbsd-6-0-RELEASE.
 1.166.2.1  01-Oct-2012  riz Pull up following revision(s) (requested by rmind in ticket #583):
sys/kern/sys_lwp.c: revision 1.55
sys/sys/lwp.h: revision 1.164
sys/kern/kern_exit.c: revision 1.242
sys/kern/kern_lwp.c: revision 1.173
exit_lwps, lwp_wait: fix a race condition by re-trying if p_lock was dropped
in a case of process exit. Necessary to re-flag all LWPs for exit, as their
state might have changed or new LWPs spawned.
Should fix PR/46168 and PR/46402.
 1.172.2.5  03-Dec-2017  jdolecek update from HEAD
 1.172.2.4  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.172.2.3  23-Jun-2013  tls resync from head
 1.172.2.2  25-Feb-2013  tls resync with head
 1.172.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.175.2.1  18-May-2014  rmind sync with head
 1.179.2.5  28-Aug-2017  skrll Sync with HEAD
 1.179.2.4  05-Feb-2017  skrll Sync with HEAD
 1.179.2.3  09-Jul-2016  skrll Sync with HEAD
 1.179.2.2  22-Apr-2016  skrll Sync with HEAD
 1.179.2.1  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.185.2.2  26-Apr-2017  pgoyette Sync with HEAD
 1.185.2.1  20-Mar-2017  pgoyette Sync with HEAD
 1.187.2.1  21-Apr-2017  bouyer Sync with HEAD
 1.189.2.2  14-May-2018  martin Pull up following revision(s) (requested by gson in ticket #805):

sys/kern/kern_lwp.c: revision 1.192

PR/kern/53202: Kernel hangs running t_ptrace_wait:resume1 test, revert
previous.
 1.189.2.1  10-Dec-2017  snj Pull up following revision(s) (requested by christos in ticket #417):
sys/kern/kern_lwp.c: revision 1.191
Also wait interruptibly when exiting. Avoids deadlocked on exit processes
create by golang.
 1.191.2.3  26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.191.2.2  28-Jul-2018  pgoyette Sync with HEAD
 1.191.2.1  02-May-2018  pgoyette Synch with HEAD
 1.192.2.3  21-Apr-2020  martin Sync with HEAD
 1.192.2.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.192.2.1  10-Jun-2019  christos Sync with HEAD
 1.202.2.3  12-Feb-2020  martin Pull up following revision(s) (requested by maya in ticket #697):

sys/kern/kern_lwp.c: revision 1.224
sys/kern/kern_lwp.c: revision 1.225

Preserve pcu(9) state in fork.

There should perhaps be a pcu_fork operation to keep this factored
neatly but this will be simpler to pull up.

In practical terms, this may not affect most architecture that use
pcu(9) -- alpha, arm32, mips, powerpc, riscv -- but it does affect
aarch64, in which v8-v15 are callee-saves, and GCC actually takes
advantage of them, and for more than just floating-point data too.

XXX pullup

fix compilation failure for arches without l_pcu_valid
ok riastradh
 1.202.2.2  15-Oct-2019  martin Pull up following revision(s) (requested by kamil in ticket #320):

sys/kern/kern_synch.c: revision 1.324
sys/kern/kern_sig.c: revision 1.366
sys/kern/kern_exit.c: revision 1.277
sys/kern/kern_lwp.c: revision 1.204
sys/kern/sys_ptrace_common.c: revision 1.62

Separate flag for suspended by _lwp_suspend and suspended by a debugger

Once a thread was stopped with ptrace(2), userland process must not
be able to unstop it deliberately or by an accident.

This was a Windows-style behavior that makes threading tracing fragile.
 1.202.2.1  15-Oct-2019  martin Pull up following revision(s) (requested by kamil in ticket #311):

sys/sys/siginfo.h: revision 1.34
sys/kern/sys_ptrace_common.c: revision 1.59
sys/kern/sys_lwp.c: revision 1.70
sys/compat/sys/siginfo.h: revision 1.8
sys/kern/kern_sig.c: revision 1.365
sys/kern/kern_lwp.c: revision 1.203
sys/sys/signalvar.h: revision 1.96
sys/kern/kern_exec.c: revision 1.482
sys/kern/kern_fork.c: revision 1.214

Move TRAP_CHLD/TRAP_LWP ptrace information from struct proc to siginfo

Storing struct ptrace_state information inside struct proc was vulnerable
to synchronization bugs, as multiple events emitted in the same time were
overwritting other ones.

Cache the original parent process id in p_oppid. Reusing here p_opptr is
in theory prone to slight race codition.

Change the semantics of PT_GET_PROCESS_STATE, reutning EINVAL for calls
prompting for the value in cases when there wasn't registered an
appropriate event.

Add an alternative approach to check the ptrace_state information, directly
from the siginfo_t value returned from PT_GET_SIGINFO. The original
PT_GET_PROCESS_STATE approach is kept for compat with older NetBSD and
OpenBSD. New code is recommended to keep using PT_GET_PROCESS_STATE.
Add a couple of compile-time asserts for assumptions in the code.

No functional change intended in existing ptrace(2) software.

All ATF ptrace(2) and ATF GDB tests pass.

This change improves reliability of the threading ptrace(2) code.
 1.217.2.3  29-Feb-2020  ad Sync with head.
 1.217.2.2  25-Jan-2020  ad Sync with head.
 1.217.2.1  17-Jan-2020  ad Sync with head.
 1.233.2.2  25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.233.2.1  20-Apr-2020  bouyer Sync with HEAD
 1.242.2.1  03-Apr-2021  thorpej Sync with HEAD.
 1.243.12.1  03-Nov-2021  thorpej Cherry-pick this sys_futex.c revision and associated changes:

revision 1.13
date: 2021-09-28 08:05:42 -0700; author: thorpej; state: Exp; lines: +11 -9; commitid: FPndTp2ZDjYuyJaD;
futex_release_all_lwp(): No need to pass the "tid" argument separately; that
is a vestige of an older version of the code. Also, move a KASSERT() that
both futex_release_all_lwp() call sites had inside of futex_release_all_lwp()
itself.

...so make this easier to test this sys_futex.c with trunk.
 1.269.2.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed