x64: fix exception stack restoring

Exiting from the second exception (exception_depth == 2) should restore
the exception stack to percpu_exception_stack[0], which was the value
used before the second exception happened.

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>
x64: Fix nested exception support

Commit 89464d6a037dd06ac5ca37f0c70a65786193866a added support for
nested exceptions. One of the reason these are needed are when using
tracepoints keeping backtraces using backtrace_safe(). If the tracepoint
happens while handling an exception, the call to backtrace_safe() might
itself cause an exception, and while handling *that* nested exception
on the per-cpu nested exception stack, we need a second nested exception
stack (that second stack will only ever be used to print a "nested too deep"
error).

However, the existing code had an off-by-one error in its test, and
actually aborted on the nested exception, when exception_depth=1,
rather than setting the exception stack to precpu_exception_stack[1]
as it should, and only aborting when exception_depth reaches 2.

So despite the aforementioned commit, we did not actually support nested
exceptions.  Turning on malloc tracing with backtraces, with the kernel
arguments "--trace=memory_malloc --trace-backtrace", quickly resulted in an
abort. With this patch, that tracing no longer aborts.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
dhcp: Fix dhcp issue on VBOX

I've seen OSv can not get dhcp address in Virtual Box.

On Linux, the dhcp client sends dhcp options in both DISCOVER and
REQUEST packets. However, OSv only sends the options in DISCOVER
packet.

Fix the issue by making OSv behave the same with Linux dhcp client.

Though other people (Vlad) did not this issue, it won't hurt to send
options in both packets.

This patch fixes the dhcp issue for me.

Reviewed-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
build: fix building in directories containing the string 'debug'

An unrestrained grep ate the gcc include directory.

Fix by grepping for the right things.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
pci: Fix header type check

Header Type is 8-bit. The bit 7 is used to identify a multi-function
device. The lower bit 1 and bit 0 are used to identify the header type.

   00b is defined for Normal devices
   01b is defined for PCI-to-PCI bridges
   10b is defined for PC Card Standard

Fix the check by masking the lower 2 bits only.

This patch fixes the device probe on VMware Workstation.

Signed-off-by: Asias He <asias@cloudius-systems.com>
scsi: Introduce scsi-common

Split the common scsi code from virtio-scsi.cc to scsi-common.cc. This way, we can share
code with other scsi driver, e.g., vmw-pvscsi.

Tested on local kvm and GCE.

Signed-off-by: Asias He <asias@cloudius-systems.com>
vmw-pvscsi: Initial support

This driver is for VMware's pvscsi disk. It has better performance than
using AHCI device in VMware. This driver uses the common scsi code in
scsi-common.

This driver is written from scratch. QEMU and Linux pvscsi drivers were
used as reference as there's no specification available.

Tested on QEMU's pvscsi implementation and VMware Workstation.

Signed-off-by: Asias He <asias@cloudius-systems.com>
virtio-scsi: Do not assert on response in req_done

req->response can be not zero when in some cases, for instance, when the
REPORT LUNS command send to a target which does not exist. Pass the
handling of req->response to command handling.

This allows us to probe multiple targets.

Signed-off-by: Asias He <asias@cloudius-systems.com>
scsi: Introduce config.max_target

Use this to limit max number of target to scan.

Signed-off-by: Asias He <asias@cloudius-systems.com>
scsi: Enable multiple target scan

Since we can handle non-exist target correctly now, we can enable
multiple target scan.

Signed-off-by: Asias He <asias@cloudius-systems.com>
vmw-pvscsi: Limit max number of LUNs per target to 1.

VMware supports only 1 lun per target. Limit the max_lun to speed up
probe.

Signed-off-by: Asias He <asias@cloudius-systems.com>
scsi: Add scsi_common::handle_bio helper

This eliminates duplicated code in make_request() of scsi driver.

Signed-off-by: Asias He <asias@cloudius-systems.com>
scsi: Specify virtual keyword for the virtual functions

Avi suggested to add the virtual keyword to reduce possible confusion.

Signed-off-by: Asias He <asias@cloudius-systems.com>