Commit Graph
300 Commits
Author SHA1 Message Date
Dmitrii Kuvaiskii a72662ffb2 [LibOS] Refactor and simplify ioctl() emulation 2020-11-23 14:04:24 -08:00
Stefan Berger a01b8743f8 [LibOS] Move CRASH_PROCESS from BUG() into arch-specific header 2020-11-23 22:14:49 +01:00
borysp f1c8512a5e [LibOS] Rename shim_signal_handles to shim_signal_dispositions 2020-11-19 18:35:27 +01:00
borysp 2a95cd5f25 [LibOS] Rework threads implementation
Most important differences from the old version:
- strip global process information from the thread struct into a
  dedicated one,
- a parent is informed about the child death when the whole process
  (the last thread) dies (not on each thread exit),
- all threads have the same parent (spawning thread is NOT the parent of
  the spawned thread),
- a thread is able to wait on children created by another thread,
- a process is able to wait for exited children after execve,
- rewritten `waitid` implementation (no more gotos, supports __WCLONE
  and friends flags),
- added option for syscall restarting, for now used only in `waitid`.

Additionally various bugfixes, cleanups and missing locks added.
2020-11-19 18:35:27 +01:00
borysp 5b4c747edf [LibOS] Allow for stopping IPC helper thread
Sometimes we need to temporarily stop IPC helper thread from receiving
more messages, e.g. when doing execve just before migrating exited (but
not yet waited for) children list.
2020-11-19 18:23:26 +01:00
Paweł Marczewski 883ae10de1 [Pal,LibOS] Clean up includes
* Make sure "stat.h" and "perm.h" are directly included where
  necessary.
* Don't include "perm.h" inside "stat.h" but require it to be
  included separately.
* Remove workarounds with __KERNEL__, __GLIBC__, defining pid_t
  directly, and reversed include order (system headers before local
  ones).
2020-11-19 14:27:06 +01:00
Paweł Marczewski 1b3de7203e [Pal,LibOS] Introduce stat.h
Keep our own copy of S_* macros.
2020-11-19 14:24:59 +01:00
Paweł Marczewski 38bf50c4c5 [Pal,LibOS] Fix loader.debug_type = file
Logging to file was broken, because the PAL file write operation
required the user to provide an absolute offset, and LibOS always
provided an offset of 0. This worked when logging to stdout, but
in case of a regular file, it kept overwriting the beginning of
file.

To fix that, we introduce a a special DkDebugLog call. This is a
better solution than tracking the file offset manually, because
the offset would need to be synchronized across different threads
and processes, and debug logs should be as simple as possible. At
the same time, we don't want PAL to provide a generic "append to
a file" mechanism, because it makes I/O less deterministic.
2020-11-17 23:56:28 +01:00
borysp b11184534f [LibOS] Always clear SIGSTOP and SIGKILL from signals mask 2020-11-17 02:24:03 +01:00
Dmitrii Kuvaiskii 8eee4a4742 [LibOS,Pal,Examples,GSC,Docs] Move manifest parsing to TOML
The manifest syntax stays exactly the same, including 0 and 1
integers to denote boolean values (this is done for ease of porting
and can be fixed in future commits). The only visible change is
surrounding strings in the manifest with quotes (requirement of
TOML). All manifests and Makefiles of our tests and example apps are
ported to the new TOML syntax. Documentation is updated.
2020-11-12 05:45:07 -08:00
Paweł Marczewski a353f54296 [LibOS] Fix fcntl(F_DUPFD) hang
The operation loops indefinitely on error. Instead, it should find
the first free FD, and then try allocating it.

In addition, the right error after exceeding the limit is EMFILE
(however, dup2() is still supposed to return EBADF if asking for
an out-of-range value, as checked by the dup201 LTP test).
2020-11-12 11:55:52 +01:00
borysp 514180bc22 [LibOS] Fix *_event functions
They all lacked error checking and `wait_event` was completely broken:
it was reading from non-blocking pipe and treating EAGAIN as
successfully waited-for event.
2020-11-09 22:46:57 +01:00
Vijay DhanrajandGary 3fa93cc86f [LibOS,Pal] Add sched_setaffinity/sched_getaffinity syscall support
This patch adds syscall support for setting/getting cpu affinity
of threads.

Co-authored-by: Gary <gordon.king@intel.com>
2020-11-06 22:28:32 +01:00
Dmitrii Kuvaiskii 54ab669ecd [LibOS] Remove unused IPC port types
Previously, IPC_PORT_SERVER meant "listening port", and the actual
communication ports had several types. Only two of these types were
used for differentiation during IPC broadcast (direct-child and
direct-parent types). All other types denoted who is the remote party
this port connects to, but this info is superfluous. So this commit
replaces all these types with a generic IPC_PORT_CONNECTION, and
renames IPC_PORT_SERVER to a more familiar IPC_PORT_LISTENING.
2020-11-05 22:13:46 +01:00
borysp 3014a0dd1c Miscelaneous inline asm fixes
Mostly adds missing "memory" clobber which caused some nasty bugs - gcc
optimized those inline asms and assumed values returned by them never
change.
2020-11-05 13:48:41 +01:00
Dmitrii Kuvaiskii 9b91693497 [LibOS] Remove create_{dir,file,handle}() and refactor create_pipe() 2020-10-31 03:11:22 +01:00
Dmitrii Kuvaiskii 3b02bdc80f [LibOS] Add XSAVE area handling and save/restore it on child thread creation
Previously, LibOS (shim) layer of Graphene didn't support XSAVE area.
The XSAVE area stores FP, XMM, YMM, ZMM, etc. registers and control
states and is handled via FXSAVE/XSAVE and FXRSTOR/XRSTOR x86-64
instructions. This commit is the first step towards adding full-
fledged XSAVE support to LibOS. It adds XSAVE related structs and
functions to LibOS code, and propagates XSAVE regs/states from
parent to child on thread creation via clone() (though not really
correctly). New test `fp_multithread` is added to LibOS regression.

Future commits will add correct XSAVE handling on syscall transitions
and arriving signals.
2020-10-29 07:56:31 -07:00
Li, Xun ea49007aa0 [LibOS] Enhance /dev/null stat
glibc function daemon() checks st_rdev field in struct stat of
/dev/null, which wasn't previously properly filled.
2020-10-27 00:58:43 +01:00
borysp b2f03e0d47 [LibOS] Remove IPC LEASETYPE and accompanying fields
Some structures had a field `lease` which was passed to IPC code, which
shuffled it left and right, but never actually used.
2020-10-22 01:27:38 -07:00
borysp 2c85c91c24 [LibOS] Remove exit code from ipc_port_with_child_fini
If a remote ipc port gets disconnected we assume that remote process
died unexpectedly and mark it as killed with SIGKILL, so it makes no
sense to also keep the exit code.
2020-10-21 21:53:01 +02:00
borysp fffd703b74 [LibOS] Clean up clone and fork implementations
On Linux fork and vfork are just specific cases of clone. This commit
does small cleanup of clone code and deduplicates proces copying code by
always using clone.
2020-10-20 20:40:30 +02:00
borysp 4305f667e1 [LibOS] Remove unneeded tid field of shim_tcb
This field was just cached `tcb->tp->tid`. It was not really needed and
annoying to keep in sync.
2020-10-20 12:59:18 +02:00
borysp 1dc11a6f84 [LibOS] Move locking from shim_internal.h to a dedicated header 2020-10-20 12:59:18 +02:00
borysp 36edd357fa [LibOS] Remove unused functions in shim_internal.h and shim_init.c
Removed:
- `message_confirm` - not used anywhere (and probably won't ever be),
- `SYS_PRINTF` - this was just synonym of `debug` or `warn` (depending
   on the context),
- all other functions that were used only by the two above.
2020-10-16 18:06:22 +02:00
borysp 05a258c95b [LibOS] Consolidate and remove unused code in thread checkpointing 2020-10-15 00:03:44 +02:00
Michał Kowalczyk 70590b8222 [LibOS] Implement madvise syscall 2020-10-14 20:01:13 +02:00
Michał Kowalczyk e4d228d4b9 [LibOS+Pal] Clean up file comments
I don't know any reason why would stating the file name we're in be
helpful for anything. Moreover, this information was incorrect in a few
cases (copy-paste bugs, probably).

Additionally, a few minor type/formatting fixes included.
2020-10-14 20:01:13 +02:00
borysp ff1bbe7308 [LibOS] Remove unused exit_code in shim_process_ipc_info 2020-10-14 16:10:41 +02:00
borysp e1aee92542 [LibOS] Rename shim_process to shim_process_ipc_info 2020-10-14 16:10:41 +02:00
Juro Bystricky fbb9a5b581 [LibOS] Use correct v5.8 x86 syscall numbers
When compiling against v5.8 (or later) kernel headers, we encounter
compilation errors such as:

  In file included from /usr/include/asm/unistd.h:13,
                   from shim_parser.c:11:
  shim_parser.c:408:10: error: array index in initializer exceeds array bounds
           [__NR_io_uring_setup]    = {.slow = 0, .parser = {NULL}},

The remedy is to extend `syscall_parser_table` by modyfing the
definition of LIBOS_SYSCALL_BOUND so the offending system calls fit in
the table.

While at it, also fix the actual values for syscall numbers in
"shim_syscalls.h" (the numbers are not sequential, there is an
intentional gap between the numers).
2020-10-13 03:18:51 +02:00
Dmitrii Kuvaiskii 70c7264f03 [Pal/Linux-SGX] Add manifest option loader.pal_internal_mem_size
Previously, Graphene preallocated 64MB for PAL internal metadata
like trusted/protected files metadata, handles metadata, etc.
If this limit was depleted, Graphene loudly failed, and the user
had no option but to change constant in source code and rebuild
Graphene. This commit adds the manifest option
`loader.pal_internal_mem_size` to allow increasing this limit.
2020-09-30 08:14:38 -07:00
borysp 5dd0c5a64b [LibOS] Unify logic of counting handles in epoll 2020-09-29 15:52:32 +02:00
Michał Kowalczyk 0c951dbe9d [LibOS] Implement getrandom syscall 2020-09-25 09:29:52 +02:00
Michał Kowalczyk 6b6bdb28b2 [LibOS] Update x64 syscall list to Linux v5.8 2020-09-25 09:29:52 +02:00
Paweł Marczewski cbb3bc2958 [LibOS] Implement waitid syscall
For now it supports only WEXITED and WNOWAIT (no WSTOPPED and
WCONTINUED) and P_ALL, P_PID and P_PGID, but not P_PIDFD.
2020-09-23 18:22:42 +02:00
Michał Kowalczyk 471eb8ec60 [LibOS] Remove unused code
This commit removes some unused code from LibOS, the biggest part of
which being the support for "inline" binaries linked directly against
LibOS.

This allows us to remove e.g. POINTER_TYPE() macro, which was supposed
to check if a type is a pointer type, but implemented the check based
only on the first 2 characters of the type name (?!?).
2020-09-18 19:48:37 +02:00
Michał Kowalczyk e6e46a9e5a [LibOS] Remove unused md5 implementation 2020-09-15 02:00:54 +02:00
Michał Kowalczyk ad477ec7bf Reformat repository to our C formatting rules (final iteration) 2020-09-15 02:00:54 +02:00
Paweł Marczewski 3388229dc5 [LibOS] Remove stack allocation from dentry_get_path()
Instead, require the user to always provide a big enough buffer.

This is because inlined alloca() doesn't work in clang, see
https://github.com/oscarlab/graphene/issues/1794.

- Create a convenience "into qstr" wrapper
- Eliminate the only instances where the function was called with
  on_stack == false (they were leaking memory)
- Remove a few null checks that are impossible now
- Fix possible overflow in unix_copy_addr() (truncate the address
  instead)
2020-09-09 21:05:21 +02:00
Paweł Marczewski d8930fb4ac [LibOS] Get rid of qstrtostr()
Used in one place. Needed to remove non-standard use of alloca.
2020-09-07 17:12:16 +00:00
Paweł Marczewski f883d05317 [LibOS] Get rid of alloca in debug_setbuf()
This use of alloca is non-standard and fails to retain the memory
when compiling code with clang (even though the function is still
inlined).
2020-09-07 17:12:16 +00:00
borysp 9024e2cf50 [LibOS] Add readlinkat syscall implementation 2020-09-05 00:47:45 +02:00
borysp c9fc06b9f5 [LibOS] Rework sending memory content in checkpoints
Previously memory content was sent inside a checkpoint and counted
towards the checkpoint size in the child process, but not in the parent
process. The child allocated the checkpoint at the same address as in
the parent, but it had a different size, so it could colide with another
memory mapping. This commmit fixes it by making checkpointing code
receive the memory directly to destination addresses (which additionally
saves an unnecessary copy).
2020-09-03 01:11:07 +02:00
Dmitrii Kuvaiskii 78d870dd1b [LibOS] Refactor IPC subsystem's PID, SYS-V, and range logic
This commit contains the following changes:
- Removing macros like CONCAT, NS_SEND, NS_CALLBACK and replacing
  with actual function/symbol names.
- Removing distinction between PID and SYS-V namespaces and their
  corresponding leaders: all range requests for both namespaces
  now go through the same logic and are served by the same set of
  functions like ipc_lease_send/ipc_lease_callback, etc.
- Removing unnecessary IPC header files, by consolidating all
  declarations in shim_ipc.h.
- Moving logic from shim_ipc_ns.h and shim_ipc_nsimpl.h to a new
  shim_ipc_ranges.c -- responsible for alloc/dealloc of ranges.
2020-09-02 20:49:13 +00:00
Dmitrii Kuvaiskii d0a34dd645 [LibOS,Pal/lib] Partially refactor slabmgr and memmgr in Pal/lib
In particular, this commit:
- Removes SLAB_DEBUG macros and corresponding code.
- Fixes memory leak in memmgr's enlarge_mem_mgr() by removing
  __set_free_mem_area() call.
- Fixes bug of double-free of the very first memmgr area in
  destroy_mem_mgr().
- De-duplicates "get new memory object" code by changing
  get_mem_obj_from_mgr() to call get_mem_obj_from_mgr_enlarge().
- Simplifies and improves performance of free_mem_obj_to_mgr() since
  there is no need to double-check that the object belongs to one of
  the memmgr's areas because we already check memory_migrated().
- Fixes bug of free of wrong object in slabmgr's destroy_slab_mgr().
2020-08-28 08:43:24 -07:00
borysp d80192147c [LibOS] Fix epoll closing and epoll_item ref-counting and checkpointing 2020-08-19 15:13:36 +02:00
borysp e5ed68f76a [LibOS] Remove useless pal_handles and maxfds from shim_epoll_handle
This additionally fixes a stale PAL pointers (to pal_handles and event)
being migrated at fork/execve.
2020-08-19 15:13:36 +02:00
Dmitrii Kuvaiskii 707b62e3cf [LibOS] Allow but ignore MSG_DONTWAIT flag in recvfrom/sendto
This commit also adds checks for supported flags in sendto/sendmsg
and allows only MSG_DONTWAIT and MSG_NOSIGNAL.
2020-08-18 09:19:46 -07:00
borysp 91682a3306 Fix a bug introduced in '[LibOS] Fix setting O_NONBLOCK flag in pipe2' 2020-08-12 19:38:26 +02:00
borysp 2abb2f325e [LibOS] Fix setting O_NONBLOCK flag in pipe2
Specifying O_NONBLOCK flag in the call to pipe2 applied it only to one
end of the pipe.
2020-08-12 01:20:43 +02:00