Commit Graph

198 Commits

Author SHA1 Message Date
maxv 154c680895 Introduce uvm_km_protect. 2016-07-20 12:38:43 +00:00
christos 19ea743456 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)
2016-05-25 17:43:58 +00:00
christos 54eb2755d8 PR/50744: NONAKA Kimihiro: Protect more stuff with _KERNEL && _KMEMUSER to
make uvm_extern.h compile standalone again for net-snmp.
2016-02-05 04:18:55 +00:00
martin 76713fa86f 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.
2015-11-26 13:15:34 +00:00
riastradh bfff803e84 Comments explaining UBC_* flags. 2015-03-20 15:41:43 +00:00
maxv 20fc3c6998 Kill kmeminit(). 2015-02-06 18:19:22 +00:00
chs 6d40f9ff57 add a new "fo_mmap" fileops method to allow use of arbitrary uvm_objects for
mappings of file objects.  move vnode-specific details of mmap()ing a vnode
from uvm_mmap() to the new vnode-specific vn_mmap().  add new uvm_mmap_dev()
and uvm_mmap_anon() convenience functions for mapping character devices
and anonymous memory, and replace all other calls to uvm_mmap() with those.
use the new fileop in drm2 so that libdrm can use mmap() to map things
like on other platforms (instead of the ioctl that we have used so far).
2014-12-14 23:48:58 +00:00
riastradh 4fa7e6020b Initialize ubchist earlier. 2014-07-07 20:14:43 +00:00
riastradh c20b71f6fe Add uao_set_pgfl to limit a uvm_aobj's pages to a specified freelist.
Brought up on tech-kern:

https://mail-index.netbsd.org/tech-kern/2014/05/20/msg017095.html
2014-05-22 14:01:46 +00:00
skrll 0785dcba86 Remove unnecessary struct simplelock forward declaration. 2014-02-21 22:08:07 +00:00
dsl 825d1920ba There is no need for uvm_coredump_walkmap() to explicity pass the proc_t
pointer to the calller's function.
If the code needs the process its address can be placed in the caller's
  cookie.
2014-01-03 21:12:18 +00:00
dsl 7a743f3de6 Minor changes to the process coredump code.
- Add some extra comments.
- Add some XXX comments because the process state might not be stable,
- Add uvm_coredump_count_segs() to simplify the calling code.
- uvm code now only returns non-empty sections/segments.
- Put the 'iocookie' into the 'cookie' block passed to uvm_coredump_walkmap()
  instead of passing it through as an additional parameter.
amd64 can still generate core dumps that gdb can read.
2014-01-03 15:15:02 +00:00
dsl be74e0a9c9 Change the type of the 'cookie' that holds the state of the core dump file
from 'void *' to the actual type 'struct coredump_iostate *'.
In most of the code the contents of the structure are still unknown.
This just stops the wrong type of pointer being passed to the 'void *'
parameter.
I hope I've found everything, amd64 GENERIC and i386 GENERIC & ALL compile.
2014-01-01 18:57:15 +00:00
martin 41de4c61e8 As discussed on tech-kern: make TOPDOWN-VM runtime selectable per process
(offer MD code or emulations to override it).
2013-11-14 12:07:11 +00:00
matt a462d18984 Add a __HAVE_CPU_UAREA_IDLELWP hook so that the MD code can allocate
special UAREAs for idle lwp's.
2012-09-01 00:26:37 +00:00
martin 94b761b6aa Rework posix_spawn locking and memory management:
- always provide a vmspace for the new proc, initially borrowing from proc0
   (this part fixes PR 46286)
 - increase parallelism between parent and child if arguments allow this,
   avoiding a potential deadlock on exec_lock
 - add a new flag for userland to request old (lockstepped) behaviour for
   better error reporting
 - adapt test cases to the previous two and add a new variant to test the
   diagnostics flag
 - fix a few memory (and lock) leaks
 - provide netbsd32 compat
2012-04-08 11:27:44 +00:00
uebayasi 57e974fbee Move base type definitions from uvm_extern.h to uvm_param.h so that
other sources can easily include part of UVM headers without the whole
uvm_extern.h (e.g. sys/vnode.h wants only uvm_object.h).
2012-03-18 13:31:14 +00:00
para 3eed4a3cfa - bringing kmeminit_nkmempages back and revert pmaps that called this early
- use nkmempages to scale the kmem_arena
- reducing diff to pre kmem/vmem change
   (NKMEMPAGES_MAX_DEFAULT will need adjusting on some archs)
2012-02-02 18:59:44 +00:00
para e62ee4d475 extending vmem(9) to be able to allocated resources for it's own needs.
simplifying uvm_map handling (no special kernel entries anymore no relocking)
make malloc(9) a thin wrapper around kmem(9)
(with private interface for interrupt safety reasons)

releng@ acknowledged
2012-01-27 19:48:38 +00:00
reinoud 5bd510aeaa Revert MAP_NOSYSCALLS patch. 2012-01-05 15:19:52 +00:00
reinoud 9e3fb3728b Redo uvm_map_setattr() to never fail and remove the possible panic. The
possibility of failure was a C&P error.
2011-12-22 13:12:50 +00:00
reinoud d131102a3b Add a MAP_NOSYSCALLS flag to mmap. This flag prohibits executing of system
calls from the mapped region. This can be used for emulation perposed or for
extra security in the case of generated code.

Its implemented by adding mapping-attributes to each uvm_map_entry. These can
then be queried when needed.

Currently the MAP_NOSYSCALLS is only implemented for x86 but other
architectures are easy to adapt; see the sys/arch/x86/x86/syscall.c patch.
Port maintainers are encouraged to add them for their processor ports too.
When this feature is not yet implemented for an architecture the
MAP_NOSYSCALLS is simply ignored with virtually no cpu cost..
2011-12-20 15:39:35 +00:00
matt 207bff18bc Forward some UVM from matt-nb5-mips64. Add UVM_KMF_COLORMATCH flag.
When uvm_map gets passed UVM_FLAG_COLORMATCH, the align argument contains
the color of the starting address to be allocated (0..colormask).
When uvm_km_alloc is passed UVM_KMF_COLORMATCH (which can only be used with
UVM_KMF_VAONLY), the align argument contain the color of the starting address
to be allocated.
Change uvm_pagermapin to use this.  When mapping user pages in the kernel,
if colormatch is used with the color of the starting user page then the kernel
mapping will be congruent with the existing user mappings.
2011-09-01 06:40:28 +00:00
christos 262ad41ded Add an optional pglist argument to uvm_obj_wirepages, to be
filled with the list of pages that were wired.
2011-08-27 09:11:52 +00:00
hannken d296304e60 Rename uvm_vnp_zerorange(struct vnode *, off_t, size_t) to
ubc_zerorange(struct uvm_object *, off_t, size_t, int) changing
the first argument to an uvm_object and adding a flags argument.

Modify tmpfs_reg_resize() to zero the backing store (aobj) instead
of the vnode.  Ubc_purge() no longer panics when unmounting tmpfs.

Keep uvm_vnp_zerorange() until the next kernel version bump.
2011-06-16 09:21:02 +00:00
rmind e225b7bd09 Welcome to 5.99.53! Merge rmind-uvmplock branch:
- Reorganize locking in UVM and provide extra serialisation for pmap(9).
  New lock order: [vmpage-owner-lock] -> pmap-lock.

- Simplify locking in some pmap(9) modules by removing P->V locking.

- Use lock object on vmobjlock (and thus vnode_t::v_interlock) to share
  the locks amongst UVM objects where necessary (tmpfs, layerfs, unionfs).

- Rewrite and optimise x86 TLB shootdown code, make it simpler and cleaner.
  Add TLBSTATS option for x86 to collect statistics about TLB shootdowns.

- Unify /dev/mem et al in MI code and provide required locking (removes
  kernel-lock on some ports).  Also, avoid cache-aliasing issues.

Thanks to Andrew Doran and Joerg Sonnenberger, as their initial patches
formed the core changes of this branch.
2011-06-12 03:35:36 +00:00
rmind c22a36981f Replace "malloc" in comments, remove unnecessary header inclusions. 2011-04-23 18:14:12 +00:00
matt 4f38307d62 Add support for cpu-specific uarea allocation routines. Allows different
allocation for user and system lwps.  MIPS will use this to map uareas of
system lwp used direct-mapped addresses (to reduce the overhead of
switching to kernel threads).  ibm4xx could use to map uareas via direct
mapped addresses and avoid the problem of having the kernel stack not in
the TLB.
2011-02-17 19:27:13 +00:00
pooka 22c822c7f3 Make vmapbuf() return success/error and make physio deal with a
failure.
2011-02-10 14:46:44 +00:00
chuck 3ba477b154 udpate license clauses on my code to match the new-style BSD licenses.
based on diff that rmind@ sent me.

no functional change with this commit.
2011-02-02 15:13:33 +00:00
matt 4d8e8a7e36 Add better color matching selecting free pages. KM pages will now allocated
so that VA and PA have the same color.  On a page fault, choose a physical
page that has the same color as the virtual address.

When allocating kernel memory pages, allow the MD to specify a preferred
VM_FREELIST from which to choose pages.  For machines with large amounts
of memory (> 4GB), all kernel memory to come from <4GB to reduce the amount
of bounce buffering needed with 32bit DMA devices.
2011-01-04 08:26:33 +00:00
matt 6a66466f0c Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits.  Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
2010-12-20 00:25:23 +00:00
uebayasi 6d3191d5b6 Hide uvm/uvm_page.h again to ensure its internal structures are MD.
GENERIC or at least one kernel compile tested for:
	acorn26, acorn32, algor, all, alpha, amd64, amiga, amigappc,
	arc, bebox, bighill, cats, cobalt, dreamcast, ews4800mips,
	hp300, hp700, hpcarm, hpcmips, hpcsh, i386, ibmnws,
	integrator, ixm1200, iyonix, landisk, luna68k, mac68k,
	macppc, mipsco, mmeye, mvme68k, mvmeppc, netwinder, news68k,
	newsmips, next68k, obs266a, ofppc, pmax, pmppc, prep,
	rs6000, sandpoint, sbmips, shark, sidebeach, sparc, sparc64,
	sun2, sun3, usermode, vax, x68k, zaurus
2010-11-13 05:52:55 +00:00
uebayasi 3ebf409bf5 Put back uvm_page.h for now. Sorry for mess. 2010-11-12 12:02:35 +00:00
uebayasi 186b58eb54 Abstraction fix; don't pull in physical segment/page definitions
in UVM external API, uvm_extern.h.  Because most users care only
virtual memory.

Device drivers use bus_dma(9) to manage physical memory.  Device
drivers pull in bus_dma(9) API, bus_dma.h.  bus_dma(9) implementations
pull in UVM internal API, uvm.h.

Tested By:	Compiling i386 ALL kernel
2010-11-12 02:36:02 +00:00
rmind 5f0ac9a4fa - Merge sched_pstats() and uvm_meter()/uvm_loadav(). Avoids double loop
through all LWPs and duplicate locking overhead.

- Move sched_pstats() from soft-interrupt context to process 0 main loop.
  Avoids blocking effect on real-time threads.  Mostly fixes PR/38792.

Note: it might be worth to move the loop above PRI_PGDAEMON.  Also,
sched_pstats() might be cleaned-up slightly.
2010-04-16 03:21:49 +00:00
joerg d621e29eca Remove separate mb_map. The nmbclusters is computed at boot time based
on the amount of physical memory and limited by NMBCLUSTERS if present.
Architectures without direct mapping also limit it based on the kmem_map
size, which is used as backing store. On i386 and ARM, the maximum KVA
used for mbuf clusters is limited to 64MB by default.

The old default limits and limits based on GATEWAY have been removed.
key_registered_sb_max is hard-wired to a value derived from 2048
clusters.
2010-02-08 19:02:25 +00:00
rmind 7255a0d9d4 Add uvm_lwp_getuarea() and uvm_lwp_setuarea(). OK matt@. 2009-11-21 17:45:02 +00:00
rmind 40cf6f3659 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>.
2009-10-21 21:11:57 +00:00
yamt f97310f398 whitespace fixes. no functional changes. 2009-08-18 02:43:49 +00:00
haad b760fc6e71 Add uvm_reclaim_hooks support for reclaiming kernel KVA space and memory.
This is used only by zfs where uvm_reclaim hook is added from arc cache.

Oked ad@.
2009-08-10 23:17:29 +00:00
pooka 1252aada83 kill uvm_aio_biodone1(). only user was lfs and that uses nestiobuf now. 2009-08-05 14:11:32 +00:00
pooka 5bd015d57e add some advice symbols we'll eventually need 2009-08-05 14:10:33 +00:00
rmind 5c68e5d0ee Ephemeral mapping (emap) implementation. Concept is based on the idea that
activity of other threads will perform the TLB flush for the processes using
emap as a side effect.  To track that, global and per-CPU generation numbers
are used.  This idea was suggested by Andrew Doran; various improvements to
it by me.  Notes:

- For now, zero-copy on pipe is not yet enabled.
- TCP socket code would likely need more work.
- Additional UVM loaning improvements are needed.

Proposed on <tech-kern>, silence there.
Quickly reviewed by <ad>.
2009-06-28 15:18:50 +00:00
yamt cccbca027b g/c uvm_aiobuf_pool. 2009-03-30 16:36:36 +00:00
mrg fcc023545e - add new RLIMIT_AS (aka RLIMIT_VMEM) resource that limits the total
address space available to processes.  this limit exists in most other
modern unix variants, and like most of them, our defaults are unlimited.
remove the old mmap / rlimit.datasize hack.

- adds the VMCMD_STACK flag to all the stack-creation vmcmd callers.
it is currently unused, but was added a few years ago.

- add a pair of new process size values to kinfo_proc2{}. one is the
total size of the process memory map, and the other is the total size
adjusted for unused stack space (since most processes have a lot of
this...)

- patch sh, and csh to notice RLIMIT_AS.  (in some cases, the alias
RLIMIT_VMEM was already present and used if availble.)

- patch ps, top and systat to notice the new k_vm_vsize member of
kinfo_proc2{}.

- update irix, svr4, svr4_32, linux and osf1 emulations to support
this information.  (freebsd could be done, but that it's best left
as part of the full-update of compat/freebsd.)


this addresses PR 7897.  it also gives correct memory usage values,
which have never been entirely correct (since mmap), and have been
very incorrect since jemalloc() was enabled.

tested on i386 and sparc64, build tested on several other platforms.

thanks to many folks for feedback and testing but most espcially
chuq and yamt for critical suggestions that lead to this patch not
having a special ugliness i wasn't happy with anyway :-)
2009-03-29 01:02:48 +00:00
abs fbcfe9c7af Clarify free_list usage in uvm_page_physload() regarding faster/slower RAM.
Slower RAM should be assigned a higher free_list id.
No functional change to code, just comments and manpage
2009-03-12 12:55:16 +00:00
yamt 62abd426b4 make some functions static. 2009-02-18 13:16:58 +00:00
pooka b4099c3e1d Rototill all remaining file systems to use ubc_uiomove() instead
of the ubc_alloc() - uiomove() - ubc_release() dance.
2008-11-26 20:17:33 +00:00
christos 2a274197af - allocate 8 pointers on the stack to avoid stack overflow in nfs.
- make that 8 a constant
- remove bogus panic
2008-10-31 20:42:41 +00:00