vfs: add dentry_ref, a smart pointer for dentrys

Makes managing references easier.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
vfs: convert file::f_dentry to dentry_ref

Fixes possible leak in sys_open() and vfs_file::close() error cases.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
vfs: make error class build in C code

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
vfs: add C++ namei()

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
vfs: covert sys_stat, sys_statfs to C++ namei

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
x64: add lfence accessor

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
pvclock: add LFENCE before reading the time stamp counter

The RDTSC instruction is unordered, ensure that the processor orders it
with an LFENCE instruction.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tests: add monotonic clock test case

Ensure the clock doesn't go backwards.

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

"Add dentry_ref, a cousin to fileref, an automatic reference counted smart
pointer for dentries, and start using it."

Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
random: save needlessly entropy waste during OSv build process

entropy is being needlessly wasted while building OSv, let's avoid
that.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
aarch64: gic: do not abort on cpumask read as zero

When on uniprocessor, the register is Read As Zero,
and all interrupts are assumed to target the only processor.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
kvmclock: ensure _boot_systemtime is set only once.

Eeach vCPU is executing kvmclock::setup_cpu() which modifies a shared
variable kvmclock::_boot_systemtime, which is used as a base for
osv::clock::uptime. This race was causing osv::clock::uptime to
appear as moving backwards during boot time when _boot_systemtime
was bumped up by another CPU when it was initializing its clock.

This patch also ensures proper memory ordering between _smp_init and
_boot_system_time.

This is (apparently) making this assertion failure go away:
[backtrace]
0x00000000003b54ae <sched::timer_list::fired()+1054>
0x000000000036de66 <interrupt_descriptor_table::invoke_interrupt(unsigned int)+166>
0x000000000036df59 <interrupt+41>
0x000000000036cb4c <interrupt_entry_common+34>
0x000000000038df3a <AcpiPsCreateOp+218>
0x000000000038d81d <AcpiPsParseLoop+349>
0x000000000038eb97 <AcpiPsParseAml+567>
0x00000000003762ff <AcpiDmParseDeferredOps+927>
0x0000000000376490 <AcpiDsGetRegionArguments+64>
0x0000000000388d3b <AcpiNsExecModuleCodeList+875>
0x000000000038ba50 <AcpiNsWalkNamespace+288>
0x000000000038c155 <AcpiWalkNamespace+165>
0x0000000000388ed1 <AcpiNsInitializeObjects+65>
0x00000000003989c4 <AcpiInitializeObjects+100>
0x000000000035ace5 <acpi::init()+21>
0x0000000000210346 <main_cont(int, char**)+326>
0x00000000003b7faa <thread_main_c+26>
0x000000000036cb75 <thread_main+7>
0x0000000000d19f4f <workman::_duty+2566>

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
vfs: Fix isatty on console file descriptors

file descriptors 0, 1 and 2 aren't vfs files,
thus isatty cannot rely on a vnode to determine
whether or not the device underlying the file
is tty.

Avi suggested adding a new file subclass and using
dynamic_cast to avoid introcucing a new file type
to specifically address this problem.

According to Gilad, this bug was preventing lua
from starting in interactive mode.

Reported-by: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>