Commit Graph
1049 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
Paweł Marczewski 6c8321b1ca [LibOS] test/regression: Fix exit_group test
The exit code of the test was a random number between 0 and 4,
which gave no guarantee that the right code from exit() will
actually reach the user.

Instead of testing a race between threads, make it possible to
call exit() in a chosen thread, and verify that it always works.

In addition, propagate the exit code from a forked process. That
use case was broken recently and has been fixed in the commit
titled 'Rework threads implementation'.
2020-11-20 16:35:16 +01:00
borysp 8ff79072f5 [LTP] Enable passing tests 2020-11-19 18:35:27 +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
Li, Xun 673785bfe0 [LibOS] Fix sendfile to return EINVAL when out_fd has O_APPEND flag
Linux errors out if output fd has the O_APPEND flag set.

Also fixes non-matching get_handle/put_handle in shim_do_sendfile().
2020-11-19 15:52:01 +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 b063a2ba1b [Pal,LibOS] Introduce human-readable PERM_* macros
Instead of using S_I* flags, or hardcoded octal literals, use
helpers such as PERM_rwxrwxr_x. These are proposed in a Linux patch
by Ingo Molnar: https://lwn.net/Articles/696231/
2020-11-19 14:24:59 +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
Dmitrii Kuvaiskii c06e72288e Fix ref counting bug in shim_do_poll()
During poll/select emulation, Graphene incremented refcount of polled
handles, but forgot to decrement it in case poll timed out or failed.
2020-11-18 07:33:43 -05:00
Paweł Marczewski e5988071ba [Pal,LibOS] tests: Remove unnecessary usage of get_manifest() 2020-11-18 00:29:43 +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
Paweł Marczewski 1d25612006 [CI] Enable pylint unconditionally, fix violations
Pylint output was filtered so that many files with existing pylint
violations were allowed to stay broken.

I made sure all files pass pylint, but whitelisted some rules that
we commonly disable:

* missing docstrings: most of the code is tests/internal anyway
* invalid-name: too many violations, and we commonly use one- or
  two-character names (like "a, b" or "t1, t2") which is
  disallowed by this rule; we could tweak it and then fix
  remaining violations such as camel-case or lowercase constants
* fixme: we leave TODOs as a matter of practice, same as in C
* high-level style rules like too-few-* and too-many-*,
  no-self-use

Hopefully that will make using pylint less annoying, while also
catching serious issues (such as unused variables or imports).
2020-11-17 13:45:09 -08:00
aneessahib a7a1160c48 [LibOS] Move from linked list to AVL trees for managing futexes
This greatly improves performance on futex-heavy workloads.
2020-11-17 21:28:47 +01:00
Paweł Marczewski 5ba470800d [CI] Add back gitignore-test to all configurations
Removed by mistake in "[LibOS] test/ltp: Upgrade LTP to 20200930".

Also add two files that have been merged without gitignore in the
meantime.
2020-11-17 05:28:56 -08:00
Stefan Berger 6e03e599de [LibOS] Preserve type checking when copying equivalent structures
Get rid of a few memcpy's to preserve the type checking when copying
structures around.
2020-11-16 23:27:29 -08:00
borysp 3330238e7f [LibOS] Fix SA_RESETHAND semantics
Restore the signal action to the default when `SA_RESETHAND` is set only
if a signal handler is called.
2020-11-17 02:24:03 +01:00
borysp b11184534f [LibOS] Always clear SIGSTOP and SIGKILL from signals mask 2020-11-17 02:24:03 +01:00
Dmitrii Kuvaiskii 0a76c12c29 [LibOS] Gracefully exit with message on duplicate mounts in manifest
Sometimes users may try to add `/dev` or root (`/`) mounts to the
manifest file, but these paths are already automatically mounted by
Graphene on startup. Previously, Graphene failed on assert in such
cases, now it prints a meaningful error message.
2020-11-16 10:40:47 -08:00
Dmitrii Kuvaiskii c5f010b9e0 [Pal/{Linux,Linux-SGX}] Refactor "device" PAL handles 2020-11-16 01:08:13 -08: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
Paweł Marczewski 193978193c [LibOS] test/ltp: Show all tests with make regression V=1 2020-11-12 11:55:52 +01:00
Paweł Marczewski a1f1cc4c50 [LibOS] Fix sethostname()/setdomainname()
The functions incorrectly pad the char array with zeroes.
2020-11-12 11:55:52 +01:00
Paweł Marczewski b8da38b945 [LibOS] Fix readv() on zero-length data 2020-11-12 11:55:52 +01:00
Paweł Marczewski 616816244e [LibOS] Fix truncate()/ftruncate() with negative lengths
There was no error checking before the value ultimately got passed
to an unsigned argument deep inside PAL.
2020-11-12 11:55:52 +01:00
Paweł Marczewski ebe7715d3a [LibOS] Fix execve() corner cases
- Return EACCES if the file has no execute permission
- Return ENOEXEC if the file is not recognized as either ELF or
  shebang script
2020-11-12 11:55:52 +01:00
Paweł Marczewski 7ef9601501 [LibOS] Fix clock corner cases
- return EINVAL for invalid clock type
- for clock_getres: allow null pointer as argument
- for nanosleep/clock_nanosleep: check timespec
2020-11-12 11:55:52 +01:00
Stefan Berger 6eff7da03e [LibOS] regression: Remove unnecessary asm from pthread_set_get_affinity 2020-11-09 23:46:39 -08: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 Dhanraj 96e8b05a64 [LibOS] Fix type field in dirent struct
Currently in Graphene, the type field in dirent struct is only updated
for parent directory and is set to DT_UNKNOWN type for its children.
But APIs like `sysconf(_SC_NPROCESSORS_CONF)` rely on type field to
identify the number of processors on the host by reading the number of
cpuX directories and ensuring their type is set to DT_DIR. This commit
addresses the issue by updating the dirent type appropriately even for
child directories or files.
2020-11-08 23:26:53 -08: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
Vijay Dhanraj 41a87ad2c8 [Pal,LibOS] Add physical id and fix cpu cores in /proc/cpuinfo
Applications tend to use `/proc/cpuinfo` to get the `cpu cores`
and `physical id` for computing number of physical cores in a
socket. Currently `cpu cores` field is incorrectly implemented as
it is set to number of logical processors online and `physical id`
isn't implemented. This patch addresses both of these issues.
2020-11-06 00:25:03 +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
Vijay Dhanraj cadcb2a6ee [LibOS] Fix absolute path handling in *at() syscalls
As per linux man-pages, dirfd can be ignored if an absolute path is
provided when invoking *at() calls. But in Graphene many of the *at()
calls require a valid dirfd even when an absolute path is provided. If
not, the call fails. This commit fixes the issue by ignoring dirfd if
absolute filepath is provided.
2020-11-05 18:20:00 +01:00
Dmitrii Kuvaiskii 186690efef [Pal/Linux-SGX] Do not downgrade IPC plaintext after checkpoint
Previously, process communication (channel between parent and newly
created child) was protected via TLS only during send/receive of the
checkpoint; after that the channel was downgraded from TLS to
plaintext. The reason for this downgrade is historical (IPC was
complicated, and we wanted to have at least some TLS at the time).
This commit fixes this issue: Graphene now always uses TLS on IPC.
2020-11-05 07:56:33 -08: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 eb0e726625 [Pal/Linux-SGX] Allow EPID attestation even with DCAP SGX driver
Previously, Graphene assumed that if it was built with the DCAP
SGX driver or in-kernel SGX driver, then it should use DCAP/ECDSA
based attestation. In fact, the SGX driver has nothing to do with
the attestation scheme. This commit allows to use EPID based
attestation even when Graphene is built with the DCAP SGX driver.
2020-11-03 06:24:02 -08:00
Paweł Marczewski eeda995edc [LibOS] test/ltp: Update tests after LTP upgrade 2020-11-03 01:41:33 +01:00
Paweł Marczewski c581dc3248 [LibOS] test/ltp: Print number of passed tests
The XML output doesn't contain this information, but it's useful
for the user.
2020-11-03 01:41:33 +01:00
Paweł Marczewski 4873550097 [LibOS] test/ltp: Remove outdated tests from configuration 2020-11-03 01:41:33 +01:00
Paweł Marczewski abe3d77552 [LibOS] test/ltp: Upgrade LTP to 20200930
- Remove old LTP bug workaround from Jenkins files
- Add pkg-config as an explicit dependency (it wasn't installed on
  Ubuntu 16 and LTP won't build without it)
2020-11-03 01:41:33 +01:00
Dmitrii Kuvaiskii 9b91693497 [LibOS] Remove create_{dir,file,handle}() and refactor create_pipe() 2020-10-31 03:11:22 +01:00
Paweł Marczewski b6b9a35f23 [LibOS] ltp: Document scripts in contrib/ 2020-10-29 17:52:28 +01:00
Paweł Marczewski 0d81e26b8f [LibOS] test/ltp: Document debugging the tests 2020-10-29 17:52:28 +01:00
Paweł Marczewski 3b14680da0 [LibOS] test/ltp: Partial cleanup of the test list
- Add short comments to tests that I've had time to investigate
- Collapse some test groups where we simply do not support the
  feature being tested (e.g. a syscall) using a wildcard. Until we
  implement it, we will not care about any new tests, and having
  all the tests separately is just noise.
- Unskip some tests that seem to pass now
2020-10-29 17:52:24 +01:00
Paweł Marczewski e972b45f35 [LibOS] test/ltp: Reduce ltp-sgx.cfg
Keep only sections that differ from ltp.cfg, so that the file is
easier to maintain. Done automatically using
contrib/conf_subtract.py.

(As far as I can tell, there are no tests disabled in Linux and
enabled in Linux-SGX, only the other way around).
2020-10-29 17:51:45 +01:00
Paweł Marczewski bfbcdd1bd2 [LibOS] test/ltp: Detect duplicate configuration sections 2020-10-29 17:51:45 +01:00