Home | History | Annotate | Download | only in kern
History log of /src/sys/kern/subr_copy.c
RevisionDateAuthorComments
 1.19  22-May-2023  riastradh uiomove(9): Add uiopeek/uioskip operations.

This allows a caller to grab some data, consume part of it, and
atomically update the uio with only the amount it consumed. This
way, the caller can use a buffer of a size that doesn't depend on how
much it will actually consume, which it may not know in advance --
e.g., because it depends on how much an underlying hardware tty
device will accept before it decides it has had too much.

Proposed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/05/09/msg028883.html

(Opinions were divided between `uioadvance' and `uioskip'. I stuck
with `uioskip' because that was less work for me.)
 1.18  11-Apr-2023  riastradh uiomove(9): Stronger assertions about iov array.
 1.17  24-Feb-2023  riastradh kern: Eliminate most __HAVE_ATOMIC_AS_MEMBAR conditionals.

I'm leaving in the conditional around the legacy membar_enters
(store-before-load, store-before-store) in kern_mutex.c and in
kern_lock.c because they may still matter: store-before-load barriers
tend to be the most expensive kind, so eliding them is probably
worthwhile on x86. (It also may not matter; I just don't care to do
measurements right now, and it's a single valid and potentially
justifiable use case in the whole tree.)

However, membar_release/acquire can be mere instruction barriers on
all TSO platforms including x86, so there's no need to go out of our
way with a bad API to conditionalize them. If the procedure call
overhead is measurable we just could change them to be macros on x86
that expand into __insn_barrier.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/02/23/msg028729.html
 1.16  09-Apr-2022  riastradh ucas(9): Convert membar_exit to membar_release.
 1.15  11-Feb-2022  riastradh ucas(9): Membar audit.

- Omit needless membar_enter before ipi_trigger_broadcast. This was
presumably intended to imply a happens-before relation for the
following two CPUs:

/* CPU doing ucas */
ucas_critical_enter()
ucas_critical_pausing_cpus = ncpu - 1 (A)
ipi_trigger_broadcast()

/* other CPU walking by whistling innocently */
IPI handler
ucas_critical_cpu_gate()
load ucas_critical_pausing_cpus (B)

That is, this was presumably meant to ensure (A) happens-before (B).
This relation is already guaranteed by ipi(9), so there is no need
for any explicit memory barrier.

- Issue a store-release in ucas_critical_cpu_gate so we have the
following happens-before relation which was otherwise not guaranteed
except if __HAVE_ATOMIC_AS_MEMBAR:

/* other CPU walking by whistling innocently */
...other logic touching the target ucas word... (A)
IPI handler
ucas_critical_cpu_gate()
...
atomic_dec_uint(&ucas_critical_pausing_cpus)

happens-before

/* CPU doing ucas */
ucas_critical_enter() -> ucas_critical_wait();
...touching the word with ufetch/ustore... (B)

We need to ensure the logic (A) on another CPU touching the target
ucas word happens-before we actually do the ucas at (B).

(a) This requires the other CPU to do a store-release on
ucas_critical_pausing_cpus in ucas_critical_cpu_gate, and

(b) this requires the ucas CPU to do a load-acquire on
ucas_critical_pausing_cpus in ucas_critical_wait.

Without _both_ sides -- store-release and then load-acquire -- there
is no such happens-before guarantee; another CPU may have a buffered
store, for instance, that clobbers the ucas.

For now, do the store-release with membar_exit conditional on
__HAVE_ATOMIC_AS_MEMBAR and then atomic_dec_uint -- later with the
C11 API we can dispense with the #ifdef and just use
atomic_fetch_add_explicit(..., memory_order_release). The
load-acquire we can do with atomic_load_acquire.

- Issue a load-acquire in ucas_critical_cpu_gate so we have the
following happens-before relation which was otherwise not guaranteed:

/* CPU doing ucas */
...ufetch/ustore... (A)
ucas_critical_exit()
ucas_critical_pausing_cpus = -1;

/* other CPU walking by whistling innocently */
IPI handler
ucas_critical_cpu_gate()
...
while (ucas_critical_pausing_cpus != -1)
spin;
...other logic touching the target ucas word... (B)

We need to ensure the logic (A) to do the ucas happens-before logic
that might use it on another CPU at (B).

(a) This requires that the ucas CPU do a store-release on
ucas_critical_pausing_cpus in ucas_critical_exit, and

(b) this requires that the other CPU do a load-acquire on
ucas_critical_pausing_cpus in ucas_critical_cpu_gate.

Without _both_ sides -- store-release and then load-acquire -- there
is no such happens-before guarantee; the other CPU might witness a
cached stale value of the target location but a new value of some
other location in the wrong order.

- Use atomic_load/store_* to avoid the appearance of races, e.g. for
sanitizers.

- Document which barriers pair up with which barriers and what they're
doing.
 1.14  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.13  14-Mar-2020  ad - Hide the details of SPCF_SHOULDYIELD and related behind a couple of small
functions: preempt_point() and preempt_needed().

- preempt(): if the LWP has exceeded its timeslice in kernel, strip it of
any priority boost gained earlier from blocking.
 1.12  22-Feb-2020  chs check for errors from proc_vmspace_getref().
 1.11  07-Apr-2019  thorpej branches: 1.11.6;
Exclude references to _ucas_{32,64}_mp() for _RUMPKERNEL.
 1.10  06-Apr-2019  thorpej Treat _RUMPKERNEL like a __HAVE_UCAS_FULL platform. Add a comment
explaining what's going on. Fixes librump build on sparc.
 1.9  06-Apr-2019  thorpej Overhaul the API used to fetch and store individual memory cells in
userspace. The old fetch(9) and store(9) APIs (fubyte(), fuword(),
subyte(), suword(), etc.) are retired and replaced with new ufetch(9)
and ustore(9) APIs that can return proper error codes, etc. and are
implemented consistently across all platforms. The interrupt-safe
variants are no longer supported (and several of the existing attempts
at fuswintr(), etc. were buggy and not actually interrupt-safe).

Also augmement the ucas(9) API, making it consistently available on
all plaforms, supporting uniprocessor and multiprocessor systems, even
those that do not have CAS or LL/SC primitives.

Welcome to NetBSD 8.99.37.
 1.8  28-May-2018  chs branches: 1.8.2;
add copyin_pid(), to copyin from a different user address space.
 1.7  25-May-2016  christos branches: 1.7.16;
Introduce security.pax.mprotect.ptrace sysctl which can be used to bypass
mprotect settings so that debuggers can write to the text segment of traced
processes so that they can insert breakpoints. Turned off by default.
Ok: chuq (for now)
 1.6  21-Apr-2015  riastradh #ifdef DIAGNOSTIC panic -> KASSERT
 1.5  29-Mar-2015  riastradh Back this out, per pooka's request.
 1.4  29-Mar-2015  riastradh Use #ifdef _RUMPKERNEL for now to prefer copyout over kcopy in tests.

Gross -- please fix me if you have a better approach.
 1.3  29-Mar-2015  riastradh Back out previous.

It appears to be causing anita install to fail. Evidently
VM_SPACE_IS_KERNEL_P(vm) is not mutually exclusive with `vm ==
curproc->p_vmspace' -- in particular, proc0's VM space is kernel.

Making this work in rump for tests will require another approach.
 1.2  28-Mar-2015  riastradh Swap kernel/curproc tests in copy*_vmspace so rump can catch EFAULT.
 1.1  04-Nov-2009  pooka branches: 1.1.4; 1.1.24; 1.1.42;
Split uiomove() and high-level copy routines out of the crowded
kern_subr and into their own cozy home in subr_copy.
 1.1.42.3  29-May-2016  skrll Sync with HEAD
 1.1.42.2  06-Jun-2015  skrll Sync with HEAD
 1.1.42.1  06-Apr-2015  skrll Sync with HEAD
 1.1.24.1  03-Dec-2017  jdolecek update from HEAD
 1.1.4.2  11-Mar-2010  yamt sync with head
 1.1.4.1  04-Nov-2009  yamt file subr_copy.c was added on branch yamt-nfs-mp on 2010-03-11 15:04:18 +0000
 1.7.16.1  25-Jun-2018  pgoyette Sync with HEAD
 1.8.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.8.2.1  10-Jun-2019  christos Sync with HEAD
 1.11.6.1  29-Feb-2020  ad Sync with head.

RSS XML Feed