virtio-net: fix debug build due to missing try_lock_running()

The lock has been pushed down to a helper class and cannot be accessed here,
so remove the assert.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
sched: add barrier() to migrate_disable/migrate_enable()

These functions are used to demark a critical section and should
follow a contract which says that no operation inside the critical
section should be moved before migrate_disable() and after
migrate_enable(). These functions are declared inline and the compiler
could theoretically move instructions across these.

Spotted during code contemplation.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
x64: arch-switch: remove unused stack_trampoline code

Signed-off-by: Jani Kokkonen <jani.kokkonen@huawei.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
ring_spsc: put proper memory barriers when reading and storing _begin

Proper memory ordering should be implied to loads and stores of _begin
field. Otherwise they may be reordered with the appropriate stores and
loads to/from the _ring array and in a corner case when the ring is full
it may lead to ring data corruption.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Reported-by: Nadav Har'el <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
sched: relax migration lock barriers

Instead of forcing a reload (and a flush) of all variables in memory,
use the minimum required barrier via std::atomic_signal_fence().

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
sched: simplify load_balance() determination of pinned threads

Take the migration lock for pinned threads instead of a separate
check whether they are pinned or not.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
virtio-net: fix spelling in comments

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
sched: strengthen the fence in migrate_disable()

memory_order_acquire does not prevent previous stores from moving past
the barrier so if the _migration_lock_counter incrementation is split
into two accesses, this is eligible:

tmp = _migration_lock_counter;
atomic_signal_fence(std::memory_order_acquire); // load-load, load-store
<critical instructions here>
_migration_lock_counter = tmp + 1; // was moved past the barrier

To prevent this, we need to order previous stores with future
loads and stores, which is given only by std::memory_order_seq_cst.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mmu: make flush_tlb_all() migration-safe

If a thread which invokes flush_tlb_all() is migrated between the
call to flush_tlb_local() and send_allbutself(), the CPU onto which it
was migrated would not get its TLB flushed.

Spotted during code inspection.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
java: Don't throw exceptions at user when the main class is not found

Fixes https://github.com/cloudius-systems/mgmt/issues/33

If a user runs 'java xyz', instead of throwing the stacktrace, a simple
message informing the user about the missing class, should suffice.

Signed-off-by: Jaspal Singh Dhillon <jaspal.iiith@gmail.com>
Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
aarch64: bsd: atomic.h: use STLR for atomic_store_rel_int

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Cc: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
rework OSV_SYM macro

As Nadav pointed out during review, this macro could use a bit more work, to
use a single parameter instead of one. That is what is done in this patch.
Unfortunately just pasting __COUNTER__ doesn't work because of preprocessor
rules, and we need some indirection to get it working. Also, visibility
"hidden" can go because that is already implied by "static". The problem then
becomes the fact that gcc does not really like unreferenced static variables,
which is solved by the "used" attribute. From gcc docs about "used":

   "This attribute, attached to a variable with the static storage, means that
    the variable must be emitted even if it appears that the variable is not
    referenced."

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
README: Add Debian stable description

Linked to wiki page.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
build.mk: introduce *_env variables to make system

According to http://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html,
the versions of standard libraries have a strong matchup with versions
of compilers, so linkage errors occur when using libstdc++ in *external*
submodule when using GCC 4.9.0.

As there is such a mixup in the build system, the environments of
standard libraries in link time should be switchable to support GCC
whose version doesn't match up with external's.

*_env variables are introduced. To build a image with standard libraries
in the host, run `make build_env=host'. For fine-grained settings, use
gcc_lib_env and cxx_lib_env.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Boqun Feng <boqun.feng@linux.vnet.ibm.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: initial malloc benchmark

Currently covering three cases: 1 thread allocation, n threads allocation,
and n threads allocations with frees in a different cpu. We should improve
with more cases.

This test was designed to run on Linux as well. Let's keep it this way.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vfs: enable support for DEBUG_VFS

At the moment, defining DEBUG_VFS fails OSv compilation. The patch
ensures OSv compiles and correct debug logs are emitted.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mmu, x64: get maximum supported phys/virt bits from cpuid

Later patches will use reserved bit, so we want to be sure that it is
available.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mmu, x64: fix getting/setting address in a pte

Currently address we get from pte includes reserved bits and setting
zeroes available and reserved bits.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mmu, x64: optimize detection of PROT_NONE mem region using PT reserved bit

Java uses accesses to PROT_NONE region to stop threads sometimes, so it
worthwhile to be able to catch this as fast as possible without taking
vma_list_mutex. The patch does it by setting reserved bit on all ptes in
PROT_NONE VMA which causes RSVD bit to be set in a page fault error code.
It is enough to check it to know that access is to a valid VMA, but
permission is lacking.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mmu: rename intermediate_page() to intermediate_page_post()

The function should be called intermediate_page_post(), otherwise it is
never called.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>