elf: add functions to read the section table and section table entry names

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
elf: populate segments if ".note.osv-mlock" section is present

This allows shared objects that disable preemption to work correctly,
since faulting in executable pages with preemption disabled is not supported.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
elf: fix bad indents

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
rcu: destroy callback after executing it

The callback's destructor may refer to dynamically linked sections; destroy
it after executing it to prevent the destructor firing in the next pass and
referencing deallocated memory.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
rcu: add rcu_flush()

Add a callback to force all currently queued callbacks to execute.

This is useful for global state changes, such as removing a loaded module,
and for unit tests.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
elf: flush all rcu callbacks before unloading a module

An rcu callback may refer to the text or data section of a loaded module;
prevent access to unmapped memory by forcing all rcu callbacks to complete
before removing the module.

Fixes #231.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
rcu: introduce an rcu list type

This is a singly-linked list, suitable for building an rcu hash table.

Only a minimal interface is implemented so far.  The list itself exposes
two list-like interfaces, one for a mutating owner, the other for read-only
rcu access.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
memory: support for larger-than-page alignment

Our existing implementation of posix_memalign() and the C11 aligned_alloc()
used our regular malloc(), so it only work worked up to alignment of 4096
bytes - and crashed when it failed to achieve a higher desired alignment.

Some applications do ask for higher alignment - for example MongoDB allocates
a large buffer at 8192 byte alignment, and accordingly crashes half of the
times, when the desired alignment is not achieved (half of the time, it is
achieved by chance).

This patch makes our support for alignment better organized, and fixes
the alignment > 4096 case:

The alignment is no longer available only to the outer function like
posix_memalign(). Rather, it is passed down to lower-level allocation
functions like malloc_large() which allocates whole pages - and this
function now knows how to pick pages which start at a properly aligned
boundary.

This patch does not improve the wastefulness of our malloc_large(), so
an overhaul of it would still be welcome. Case in point, malloc_large()
always adds a full page to any allocation larger than half a page.
Multiple allocations with posix_memalign(8192, 8192), rather than being
tightly packed, each take 3 pages and are separated by a free page.
This page is not wasted, but causes fragmentation of the heap.

Note that after this patch, we still have one other bug in
posix_memalign(size, align) - for small sizes and large alignments.
For small sizes, we use a pool allocator with "size" alignment, and
may not achieve the desired alignment (so causing an assertion failure).
This bug can also be fixed, but is unrelated to this patch.

This patch also adds a test for posix_memalign(), checking all alignments
including large alignments which are the topic of this patch.
The tests for small *sizes*, which as explained above are still buggy,
are commented out, because they fail.

Fixes #266.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@avi.cloudius>
tests: add rcu list test

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Merge branch 'rcu-list'

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
zfsarc: temporarily disable ARC mappings

The fix will take time. Just disable it entirely while we cook up a solution.

Acked-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: extract testing framework

This refactoring will allow to create more complex tests which are not
limited to running only one command inside the guest, but can also
perform actions and validations which are external to the guest. Such
test cases are managed by the common test runner (scripts/test.py) and
use the same guest-management infrastructure, error detection,
etc. The common code is extracted to testing.py module. This was in
done with intent to write tests which involve external TCP
communication.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: use singular form of a noun when count is one

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: introduce --test option

This option allows to run a single test using the test runner.

Example:

 scripts/test.py --test tst-async.so

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: add test for closing TCP connection with pending packets

The test is supposed to trigger the problem from issue #259. I was not
able to trigger the problem using guest-local communication, hence the
client is external to the guest.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: Add upload script for standalone images

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: Rename Capstan release upload script

Rename the script to "upload-capstan-release" to match the naming
convention of "upload-standalone-release".

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
x64: Switch to "-msse2" GCC option

VirtualBox, for example, does not enable SSE 4.1 by default and Avi
tells me QEMU does not do that either.

To make OSv always bootable, switch to SSE2 which is guaranteed to be
present on x86-64.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
limits: provide alias for *limit64 functions

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
x64: make .fixup section writable

The content of .fixup section is sorted during boot. Moreover, since
.fixup contains pointers to locations in .text section it requires
R_X86_64_RELATIVE relocations.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pawel Dziepak <pdziepak@quarnos.org>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>