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>