Commit graph

97 commits

Author SHA1 Message Date
David van Moolenbroek 29346ab043 PM: add support for wait4(2)
This patch adds support for the wait4 system call, and with that the
wait3 call as well.  The implementation is absolutely minimal: only
user and system times of the exited child are returned (with all other
rusage fields left zero), and there is no support for tracers.  Still,
this should cover the main use cases of wait4.

Change-Id: I7a04589a8423a23990ab39aa38e85d535556743a
2015-09-29 18:15:28 +00:00
David van Moolenbroek bc2d75fa05 Rework getrusage(2) infrastructure
- the userland call is now made to PM only, and PM relays the call to
  other servers as appropriate; this is an ABI change that will
  ultimately allow us to add proper support for wait3() and the like;
  for the moment there is backward compatibility;
- the getrusage-specific kernel subcall has been removed, as it
  provided only redundant functionality, and did not provide the means
  to be extended correctly in the future - namely, allowing the kernel
  to return different values depending on whether resource usage of
  the caller (self) or its children was requested;
- VM is now told whether resource usage of the caller (self) or its
  children is requested, and it refrains from filling in wrong values
  for information it does not have;
- VM now uses the correct unit for the ru_maxrss values;
- VFS is cut out of the loop entirely, since it does not provide any
  values at the moment; a comment explains how it should be readded.

Change-Id: I27b0f488437dec3d8e784721c67b03f2f853120f
2015-09-28 14:06:59 +00:00
David van Moolenbroek cd27b2627a getrusage(2): zero out ru_i[xds]rss fields
The current values were both inaccurate (especially for dynamically
linked executables) and using the wrong unit (bytes, instead of
kilobytes times ticks-of-execution).  For now we are better off not
populating these fields at all.

Change-Id: I195a8fa8db909e64a833eec25f59c9ee0b89bdc5
2015-09-28 14:06:58 +00:00
David van Moolenbroek 0f5c95a00b PM: make child time accumulation POSIX compliant
POSIX states that times() and getrusage() should only return child
user and system times of terminated children for which wait*() has
returned their PIDs.

Change-Id: I38e19ad71543a3b91e944bef8e4e1bd903de51bf
2015-09-28 14:06:57 +00:00
Lionel Sambuc 81b1f87117 Fix noassert builds
Change-Id: I5626950ffa29afe7a0fb9e9144839b311824da92
2015-09-25 15:47:43 -07:00
David van Moolenbroek 20054ae93f Kernel: separate userland ABI on kernel page
Currently, the userland ABI uses a single field ('user_sp') far
into the very large 'kinfo' structure on the shared kernel
information page.  This precludes us from modifying or getting
rid of 'kinfo' in the future without breaking userland.  This
patch adds a separate 'kuserinfo' structure to the kernel
information page, with only information that is part of the
userland ABI, in an extensible manner.  Userland now uses this
field if it is present, and falls back to the old field if not.

Change-Id: Ib7b24b53a440f40a2edc28cdfa48447ac2179288
2015-09-23 12:01:15 +00:00
David van Moolenbroek d91f738bd8 Kernel: export clock information on kernel page
Please note that this information is for use by system services only!
The clock facility is not ready to be used directly by userland, and
thus, this kernel page extension is NOT part of the userland ABI.

For service programmers' convenience, change the prototype of the
getticks(3) to return the uptime clock value directly, since the call
can no longer fail.

Correct the sys_times(2) reply message to use the right field type
for the boot time.

Restructure the kernel internals a bit so as to have all the clock
stuff closer together.

Change-Id: Ifc050b7bd253aecbe46e3bd7d7cc75bd86e45555
2015-09-23 12:00:46 +00:00
David van Moolenbroek 594df55e53 Abstract away minix_kerninfo access
Instead of importing an external _minix_kerninfo variable, any code
using the shared kernel page should now call get_minix_kerninfo(3).
Since this is the only logical name for such a function, rename the
previous get_minix_kerninfo call to ipc_minix_kerninfo.

Change-Id: I2e424b6fb55aa55d3da850187f1f7a0b7cbbf910
2015-09-21 15:09:04 +00:00
David van Moolenbroek e4d99eb9b0 Basic live rerandomization infrastructure
This commits adds a basic infrastructure to support Address Space
Randomization (ASR).  In a nutshell, using the already imported ASR
LLVM pass, multiple versions can be generated for the same system
service, each with a randomized, different address space layout.
Combined with the magic instrumentation for state transfer, a system
service can be live updated into another ASR-randomized version at
runtime, thus providing live rerandomization.

Since MINIX3 is not yet capable of running LLVM linker passes, the
ASR-randomized service binaries have to be pregenerated during
crosscompilation.  These pregenerated binaries can then be cycled
through at runtime.  This patch provides the basic proof-of-concept
infrastructure for both these parts.

In order to support pregeneration, the clientctl host script has
been extended with a "buildasr" command.  It is to be used after
building the entire system with bitcode and magic support, and will
produce a given number of ASR-randomized versions of all system
services.  These services are placed in /usr/service/asr in the
image that is generated as final step by the "buildasr" command.

In order to support runtime updating, a new update_asr(8) command
has been added to MINIX3.  This command attempts to live-update the
running system services into their next ASR-randomized versions.
For now, this command is not run automatically, and thus must be
invoked manually.

Technical notes:

- For various reasons, magic instrumentation is x86-only for now,
  and ASR functionality is therefore to be used on x86 only as well.
- The ASR-randomized binaries are placed in numbered subdirectories
  so as not to have to change their actual program names, which are
  assumed to be static in various places (system.conf, procfs).
- The root partition is typically too small to contain all the
  produced binaries, which is why we introduce /usr/service.  There
  is a symlink from /service/asr to /usr/service/asr for no other
  reason than to let userland continue to assume that all services
  are reachable through /service.
- The ASR count field (r_asr_count/ASRcount) maintained by RS is not
  used within RS in any way; it is only passed through procfs to
  userland in order to allow update_asr(8) to keep track of which
  version is currently loaded without having to maintain own state.
- Ideally, pre-instrumentation linking of a service would remove all
  its randomized versions.  Currently, the user is assumed not to
  perform ASR instrumentation and then recompile system services
  without performing ASR instrumentation again, as the randomized
  binaries included in the image would then be stale.  This aspect
  has to be improved later.
- Various other issues are flagged in the comments of the various
  parts of this patch.

Change-Id: I093ad57f31c18305591f64b2d491272288aa0937
2015-09-17 17:15:03 +00:00
David van Moolenbroek fbbf2570b4 VM: hide harmless ACL warning for RS at startup
Change-Id: Ied8167bc44ffc336b4ab2478f11586b7d6ae0016
2015-09-17 17:14:58 +00:00
David van Moolenbroek ef52a26bab VFS/libblockdriver: enlarge threads stacks for ASR
Change-Id: If4e858bc2dbb2c69850cd265ff612bd5a6119bd3
2015-09-17 17:14:53 +00:00
David van Moolenbroek 65c4b82f02 VM: align frame buffer
Lack of alignment causes minix_stack_fill to produce an incorrect
frame layout, subsequently resulting in a crash of the started
process.  For now, we assume that the other callers of
minix_stack_fill do get an aligned buffer through sbrk(3), but this
may have to be changed later as well.

Change-Id: I1575bd62b050749d1a1aae7417310c91713462c3
2015-09-17 17:14:38 +00:00
David van Moolenbroek 5ba2e6e6e8 VM/VFS: align ELF header buffer
The libexec ELF parser expects to be given a word-aligned buffer,
but the ASR pass may cause VM and VFS to pass it an arbitrarily
aligned buffer, causing libexec to refuse loading the executable.
This patch aligns the buffers explicitly.

Change-Id: Ic2d5fd3a8f204c3e4f000cffdb7ac71c8339257a
2015-09-17 17:14:29 +00:00
David van Moolenbroek 728b0e5b34 VFS: suspend threads for live update
- do not allow live update for request and protocol free states if
  there are any worker threads that have pending or active work;
- destroy all worker threads before such live updates and recreate
  them afterwards, because transferring (the contents of) the
  thread stacks is not an option at this time;
- recreate worker threads in the new instance only if they were
  shut down before the state transfer, by letting RS provide the
  original preparation state as initialization information.

Change-Id: I846225f5b7281f19e69175485f2c88a4b4891dc2
2015-09-17 17:13:46 +00:00
David van Moolenbroek 129adfeb53 Annotations and tweaks for live update
This change is necessary for instrumentation-aided state transfer.

Change-Id: I24be938009f02e302a15083f9a7a11824975e42b
2015-09-17 17:13:38 +00:00
David van Moolenbroek 23369f9c9e DS: workaround for weak symbol issue
The bitcode file given to the instrumentation pass does not include
certain weak symbols, in particular regcomp and regfree, which are
required to be visible to the magic pass for state transfer to work
correctly.  This patch forces DS to make the calls using their actual
symbol names (with leading underscore), thus resolving the issue, but
this issue should really be solved in a cleaner and more generic way.

Change-Id: Iebee4341cc30ddabcf7593afb5c49d41c0839863
2015-09-17 17:13:28 +00:00
David van Moolenbroek c0df94ec22 RS: remove support for unsafe updates
This feature should no longer be necessary.

Change-Id: I9bff628be020cf1741bffaeb3bb97e3660a54aea
2015-09-17 14:09:47 +00:00
David van Moolenbroek 4506a0eebf VM: allocate cache pages in mmap region
That way, these pages are transferred during live update, as they
should.  This resolves a mfs crash after a number of live updates.

Change-Id: Ia53bec2692b2114c29b96a453beb0f915f56453a
2015-09-17 14:09:06 +00:00
David van Moolenbroek 76b68f9f99 Disable malloc instrumentation for VM (#1)
This patch changes the VM makefile to specify that the magic pass is
to skip memory function instrumentation, and to transfer the data
variables of the malloc code (thus overriding the exception we made
for all other system services).  We add two magic pass flags to
achieve this.  Since the magic pass is a big bowl of spaghetti code,
ignoring whitespace changes while viewing this patch is recommended.

Change-Id: I5ab83b23d8437b37c44dea99537bc202469c9df6
2015-09-17 14:05:14 +00:00
David van Moolenbroek abf8a7e7b3 RS/VM: proper preparation for multi-VM live update
Due to changed VM internals, more elaborate preparation is required
before a live update with multiple components including VM can take
place.  This patch adds the essential preparation infrastructure to
VM and adapts RS to make use of it.  As a side effect, it is no
longer necessary to supply RS as the last component (if at all)
during the set-up of a multicomponent live update operation.

Change-Id: If069fd3f93f96f9d5433998e4615f861465ef448
2015-09-17 14:01:06 +00:00
David van Moolenbroek 5a4672e300 VM: undo actions after live-update rollback
During live update, the new instance of VM may make changes that,
after a rollback, have to be undone by the old instance of VM, in
particular because both instances share (read-write) all dynamically
allocated pages.

Change-Id: I2bcfa8e627ca6084b1991e0af7cccecc683894a2
2015-09-17 14:00:32 +00:00
David van Moolenbroek 95cb93971a VM: fix mmap region transfer range bug
A missing check to see whether the range being transferred is sane
(with a starting address lower than an ending address) caused extra
memory to be marked erroneously as copy-on-write for some processes,
ultimately resulting in pagefaults on the stack during live update
rollback.

Change-Id: I1516b509b485379606d8df05b8a0f514896a0f19
2015-09-17 13:44:55 +00:00
Dirk Vogt a6db4d0a62 VM: live update - check for regions above stack
If the stack is not mapped at the VM_DATATOP (e.g. booted with
ac_layout = 1), there might be some more regions hiding above
the stack.  We also have to transfer those.

Change-Id: Idf3b94a36fcec8a10ace2f6dffe816faf0a88f60
2015-09-17 13:44:30 +00:00
Ben Gras 8f4f859b35 RS: synchronize priv from kernel after swap
. make sure the priv id etc is maintained so
	  future privctl talk about the right thing
	. solves broken IPC after update

Change-Id: I17ed0212c22d634e6db1e80f8dcb2fb8bffe82c6
2015-09-17 13:43:49 +00:00
David van Moolenbroek 2867e60add SEF: query VM about holes during state transfer
The 'memory' service has holes in its data section, which causes
problems during state transfer.  Since VM cannot handle page faults
during a multicomponent-with-VM live update, the state transfer must
ensure that no page faults occur during copying.  Therefore, we now
query VM about the regions to copy, thus skipping holes.  While the
solution is not ideal, it is sufficiently generic that it can be used
for the data section state transfer of all processes, and possibly
for state transfer of other regions in the future as well.

Change-Id: I2a71383a18643ebd36956c396fbd22c8fd137202
2015-09-17 13:43:06 +00:00
Ben Gras 683f1fcab3 vm: restartability improvements (#2)
also allocate vm pagetables dynamic-only.

further improves restart survivability.

Change-Id: Iac44845d9bd434408b23755274fa890a7b851373
2015-09-17 13:42:18 +00:00
Ben Gras 10e6ba68d2 vm: restartability improvements (#1)
Two bugs fixed wrt vm restartability.

	. make sure pagetable data is only allocated
	  using dynamic data instead of static spare pages
	  (bootstrap pages). They are needed for bootstrap
	  but now repeat some of the initialization so only
	  dynamic data remains. This solves the problem of
	  physical addresses changing (as static pages are
	  re-allocated for the new instance) after update.
	. pt_ptalloc has to be specified in bytes instead of
	  pde slot numbers. leaving pt_pt NULL causes mapping
	  transfers to fail because NULL happens to be mapped in
	  then and updates then happen there.
	. added some sanity checks against the above happening.

The new state is that VM can update many times, but the system
isn't fully reliable afterwards yet.

Change-Id: I7313602c740cdae8590589132291116ed921aed7
2015-09-17 13:41:26 +00:00
Cristiano Giuffrida 36f477c20e vm: Allow in-band metadata for cache blocks
Allow extra space for in-band metadata when allocating cache blocks.

Edited by David van Moolenbroek: since this effectively halves the
potential size of the typical file system cache, do this only when
compiling with instrumentation.

Change-Id: I0840af6420899ede2d5bb7539e79c0a456b5128d
2015-09-17 13:40:39 +00:00
Cristiano Giuffrida 3f82ac6a4e services: Selectively enable stateful restart.
Change-Id: Ibf6afa3041013ca714e28b673abb1329cd72d2d5
2015-09-17 13:36:01 +00:00
Cristiano Giuffrida dc76d7e9da rs: Update recovery policies for sched and mfs.
Edited by David van Moolenbroek.

Change-Id: I7bbe543e2349dca3856a17abddc8366d1f19fe10
2015-09-17 13:34:59 +00:00
Cristiano Giuffrida 3837bb5c0b rs: Add support for RS_FI.
Change-Id: Id8663859accfc4e3587db35dec7000059860fd49
2015-09-17 13:29:47 +00:00
Cristiano Giuffrida eacaa8290b vm: Fix heap preallocation.
Change-Id: I5b7f6473b9bbff69eae6ab26c889ad8ed902ff3a
2015-09-17 13:28:17 +00:00
Cristiano Giuffrida 0be084004f vm: Fix vm cloning.
Change-Id: I996410ab1b9628cde797d9e5dd73ed07f13a884b
2015-09-17 13:27:24 +00:00
David van Moolenbroek 37489f8a24 Resolve boot-time VM/RS deadlock
VM used to call sendrec to send a boot-time RS_INIT reply to RS, but
RS could run into a pagefault at the same time, thus spawning a
message to VM, resulting in a deadlock.  We resolve this situation by
making VM acknowledge RS_INIT asynchronously at boot time, while
retaining the synchronous sendrec for subsequent RS_INIT responses.

Change-Id: I3cb72d7f8d6b9bfdc59a85958ada739c37fa3bde
2015-09-17 13:27:05 +00:00
Cristiano Giuffrida 0e78c0166c Switch to stateful restart.
The following services have been updated to support stateful restarts:
 - Drivers: tty
 - Filesystems: isofs, mfs, pfs, libvtreefs-based file servers
 - System servers: tty, ds, pm, vfs, vm

Change-Id: Ie84baa3ba1774047b3ae519808fe4116928edabb
2015-09-17 13:26:22 +00:00
Cristiano Giuffrida 2b641b28b1 ds: Add live update extensions.
Change-Id: I093c462ddad4a5e9b3dc39140f45f0e25e83bb55
2015-09-17 13:26:09 +00:00
Cristiano Giuffrida 50b7f13f9f Add live update-friendly annotations.
Change-Id: I7d7d79893836a20799ca548a350f3288e92581f0
2015-09-17 13:25:38 +00:00
Cristiano Giuffrida 162b8995bb vm: Let SEF know about special mmapped regions.
Change-Id: I742529a6747ddd181937aa1a45264b87677c01c8
2015-09-16 15:31:40 +00:00
David van Moolenbroek e3f3566e33 RS: clean up dead services during shutdown
Previously, RS would clean up dead services only when it is idle.
During shutdown, all services are marked with the 'exiting' flag,
and these flags lead RS to conclude it is not idle.  Therefore, at
shutdown time, no services were cleaned up anymore, leading to
deadlock situations.  For example, VFS could end up waiting for a
service that was already dead, or one driver could end up waiting
for an interrupt on a line shared with another dead driver.

While it may be possible to ignore RS_EXITING when checking idle
status, other flags may have the same ultimate effect.  Therefore,
this patch skips the idle check altogether when in shutdown mode.

Change-Id: I071fa9545da1d43c5e5c2e0bc2b6c173e3bb57c3
2015-09-16 15:31:29 +00:00
David van Moolenbroek 1aa4eb6a85 RS: reset heartbeat status after rollback
While in a multicomponent live update that includes RS, the new RS
instance may receive heartbeat replies which, after a rollback, the
old RS instance will then never see.  As a result, the rolled-back
RS instance may end up killing well-behaving services.

Change-Id: I0f0af283c33502d5d55b27e353b62aec2e301285
2015-09-16 15:31:19 +00:00
David van Moolenbroek f16b761d2a RS: use IPC filters to do a timed receive
Change-Id: I28df9920d8a65b47f3cf974ed9c5eb3174479d8a
2015-09-16 15:31:10 +00:00
Cristiano Giuffrida fb6bd596bf rs: New RS.
Change-Id: I46e335d5dac49104028d7cb0706b3e85de752bfe
2015-09-16 15:30:48 +00:00
Cristiano Giuffrida d196e2c333 sef: Extensions for new RS.
Change-Id: I89b6f8015b1f9c46bf98694450bdaa80b7777940
2015-09-16 15:30:34 +00:00
Cristiano Giuffrida 65b4b95259 vm: Allow VM to make self calls when needed.
Change-Id: I7aada24adad3dc6bfe5b0bd4a50b5005c79ff887
2015-09-16 11:06:51 +00:00
Cristiano Giuffrida 63483e02e6 vm: Improve live update support.
Change-Id: I02da3ea32cd05c4ed84a6e199236e5df6e25cb60
2015-09-16 11:06:41 +00:00
Cristiano Giuffrida 53398d733f vm: Separate mmap regions.
Add support for compact address layout.  This feature can be enabled
through the ac_layout=1 boot option.

Change-Id: Ie20b808fce32b5c54d0a7e7210e0084a540e9613
2015-09-16 11:06:17 +00:00
Cristiano Giuffrida 48f446ecd5 vm: Extend the vm_memctl() interface.
Change-Id: I87b7c188bd1fc54a3ec943e7ff1d05c6f4c8a56a
2015-09-16 11:04:09 +00:00
Cristiano Giuffrida 7f439d4656 rs: Ditch dead code to munmap zero pages.
Change-Id: Ib184839e3b607986716fc48aec5ebd8ee796a065
2015-09-16 11:03:52 +00:00
Cristiano Giuffrida a1760b573b kernel: Extend the {sys,vm}_update() interfaces.
Change-Id: I9ada3c04c08d219b198e9081f4e1942b11c722f6
2015-09-16 11:01:47 +00:00
Cristiano Giuffrida 606626c691 include: Add sys flags definitions.
Change-Id: I8ecbe636641467efea058a9527416fc25d954daf
2015-09-16 10:59:34 +00:00