elf: Make lookup_addr() respect symbol size

This makes lookup_addr() to check that "addr" is within the bounds of
the "best" symbol symbol we found.

This should clean up backtraces such as the following that have
obviously bogus symbols (with very large offsets):

  [backtrace]
  0x000000000032282f <mmu::jvm_balloon_vma::split(unsigned long)+367>
  0x0000000000323632 <mmu::vm_fault(unsigned long, exception_frame*)+146>
  0x000000000036f939 <page_fault+105>
  0x000000000036e826 <ex_pf+34>
  0x0000100004400898 <main+80>
  0x00000000003d32db <osv::run(std::string, int, char**, int*)+507>
  0x0000100004007930 <run_elf(int, char**, int*)+128>
  0x0000100004007c0c <Java_com_cloudius_util_Exec_run+172>
  0x00002000006134b5 <???+6370485>
  0x00002000006061d3 <???+6316499>
  0x000020000060050a <???+6292746>
  0x00001000011ef168 <AsyncGetCallTrace+919944>
  0x00001000011eebc7 <AsyncGetCallTrace+918503>
  0x000010000144b6e7 <JVM_handle_linux_signal+463895>
  0x000010000144c837 <JVM_handle_linux_signal+468327>
  0x000010000123c542 <JVM_InvokeMethod+402>

Fixes #263.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
pci: Add VGA classcode

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vga: use PCI classcode on probe function

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
pci: Add AHCI classcodes

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
ahci: use PCI classcode on probe function

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
random: init and deinit live entropy sources

The functions intended to initialize and uninitialize
live entropy sources aren't being called.
Their role is to initialize and destroy a static global
mutex, respectively. Therefore, I would say that the lack
of calls hasn't prevented any CSPRNG functionality from
working as desired.

FreeBSD relies on SYS_INIT and SYSUNINIT to get those
functions called, respectively.
For OSv, let's simply remove their static modifiers such
that they will be properly called from the outside.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
zfs: Fix spa import procedure for multi-vdev pools

This patch is fixing a bug when using a ZFS pool with more than
a single vdev, i.e. blk device. In other words, it will allow
us to use a ZFS pool with multiple devices, and even add more
devices to an existent pool on-the-fly.

The root:
OSv-specific spa_import_rootpool and spa_generate_rootconf functions
are limited to a single vdev, therefore spa_root_vdev, a structure
keeping root vdev information, would not be aware of additional vdevs
available in the underlying pool.

The problem happens when vdev_mirror_map_alloc asks spa_root_vdev
for these additional vdevs.
It does so by using the function vdev_lookup_top that is intended to
return the requested vdev from spa_root_vdev, however, it will return
NULL when spa_root_vdev isn't aware of the requested vdev.
Consequently, a NULL dereference will always happen, when using a pool
with more than one vdev.

Example:
page fault outside application, addr: 0x0000000000000000
[backtrace]
...
0x00000000002f599b <vdev_config_sync+2427>
...

After investigation, I discovered that spa_import_rootpool and
spa_generate_rootconf should be fixed to generate proper information
about all the vdevs associated with the pool being imported.

Solution was to use FreeBSD-specific procedures for importing the root
pool, then all the vdev children information will be properly added into
the SPA namespace, and pools with more than a single vdev will start
working as expected.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mkfs: Automatic detection and insertion of additional vblk devices

mkfs code is changed to detect additional vblk devices, and insert
them into the vblk devices argument list for the pool creation.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
timer-set: make the assertion in expire() more verbose

This is to help us a bit in diagnosing what's happening when that
assertion fails.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Add missing backtrace line

As explained in issue #380, too often our backtrace results are bogus.

One of the problems was that very often the function itself in which the
crash happened was missing from the backtrace. It turns out that
print_backtrace() function always assumed it should ignore two frames,
for abort() which calls abort("Aborted."). However, when abort(message)
was called directly, and this was often the case, we unnecessarily
ignored one interesting frame.

So in this patch we ignore just the first frame (abort(const char*)),
and later ignore an abort() frame, but only if there is one.

Note that there are still bogus backtrace problems - this is only a
partial solution.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
sched: fix allocation in interruptible wait_until

wait_until<interruptible> throws an exception when it is interrupt, and
as the runtime allocates memory for this, we need to re-enable preemption
before this happens.

Found with --leak and netperf, though not directly related.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Revert "net: use rcu_hashtable in net channel classifier"

This reverts commit dea7624a757177160c1f663918005a5a063fbc54 as it causes
regressions everywhere.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
httpserver: fix rule for swagger-ui

The path is wrong.

Fixes #384.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server Testing: Adding test for thread API

This test check that the thread API timestamp progress and that the
thread idle time cpu_ms counter progress.

The test itself calls the thread API twice with 2s time difference,
it look for the idle thread and check that it has the same id and that
its cpu_ms was changed.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: add EC2 metadata service simulator

Run it like this:

  $ sudo scripts/ec2-simulator.py

The tool starts HTTP server which can be reached via standard cloud
meta-data service IP (169.254.169.254).

It needs to modify NAT rules and insert an IP address so it needs to be
run with "sudo".

You can set user data via command line arguments, eg:

  $ sudo scripts/ec2-simulator.py -f user-data.yaml

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio: fix missed notification

In virtio::vring::kick(), we read avail_event (which is written by the host)
in order to see if we need to notify the host about our last write.  However,
the processor may speculate this read, moving it before the avail_idx write
(in virtio::vring::add_buf()), in which case we will see a stale value.

Insert a memory fence in order to ensure we read a fresh value.

The fixes throughput issues in request/repsonse benchmarks, esp. netperf
TCP_RR.

Fixed #383.

Reviewed-by: Dor Laor <dor@cloudius-systems.com>
Reviewed-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build: teach osv-version.sh not to pick up random tags

Otherwise the build blows up when some regex doesn't match.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tests: fix tst-dlfcn

info.dli_sname can be null; account for it.

Suggested by Nadav.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tests: reduce rcu hashtable test running time

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
EC2 simulator: Add metadata API for Cassandra autoconfig

This adds more metadata APIs that are needed by Cassandra's EC2 cluster
auto-configuration service called Datastax Reflector.

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>