Some small fixes to tst-pipe.cc

tst-pipe.cc read a buffer after freeing it, which could have theoretically
caused segfaults (it didn't in practice, but better fix this oversight).

Also, it forgot to return a return code, so it doesn't play nicely in
a test framework like testrunner.so. I'm surprised the C++ compiler wasn't
bothered by an int main() not returning an int.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Revert "Add tests into tst-fs-link.so to check vnode duplicity"

This reverts commit bdd99c7b2d3a6852c5422852449d1e5c7e9a77d3.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Revert "vfs: Fix duplicate in-memory vnodes"

This reverts commit e4aad1baabc326d11eebb05622832563d616cb60.

It causes tst-vfs.so to just hang.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Reindent fs/vfs/main.cc

main.cc was still using tab characters instead of spaces as our coding
conventions dictate. Reindent it, using Eclipse's ctrl-I.
This patch doesn't change anything else.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mmu: don't bail out on huge page failure

Addressing that FIXME, as part of my memory reclamation series. But this
is ready to go already. The goal is to retry to serve the allocation if a
huge page allocation fails, and fill the range with the 4k pages.

The simplest and most robust way I've found to do that was to propagate the
error up until we reach operate(). Being there, all we need to do is to
re-walk the range with 4k pages instead of 2Mb.

We could theoretically just bail out on huge pages and move hp_end, but,
specially when we have reclaim, it is likely that one operation will fail while
the upcoming ones may succeed.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
[ penberg: s/NULL/nullptr/ ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: Test huge page allocation failure.

Our implementation of operate() will try to fill as much as the address space
as possible with huge pages. If that fails, we should be able to fill the range
with small pages instead of failing. This test should make sure that in such
scenarios, the resulting mapping looks sane.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio: Add vring::used_ring_can_gc() helper

It is useful to test if we can do gc on the used ring.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio-blk: Do not call queue->get_buf_gc() with wait_until

When I hacked use_indirect() to always use indirect buffer, I saw this
assertion when running:

   $scripts/run.py  -e "/tests/tst-bdev-write.so vblk1"

   VFS: mounting devfs at /dev
   51.671 Mb/s
   Assertion failed: _status.load() == status::running
   (/home/asias/src/cloudius-systems/osv/core/sched.cc: prepare_wait: 655) Aborted

It turned out that we are making a waiting thread waiting again. get_buf_gc()
calls free which might make the thread in waiting state again.

Suggested-by: Dor Laor <dor@cloudius-systems.com>
Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio-rng: Do not call queue->get_buf_gc() with wait_until

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
loader.py: Make 'osv info threads' not fail when all frames are blacklisted

When all resolved frames are blacklisted we try to print the oldest
resolved frame.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
loader.py: Skip inlined frames in 'osv info threads'

GDB python API does not handle inlined functions as nicely as regular
'backtrace' command does. Part of the frame attributes point to
the inlined function (variables, symtab) and part point to the caller.

For example frame.function() returns the nearest non-inlined function.

This breaks code which prints thread joining information.
The code thinks it's in "sched::thread::join()" when actually it's in
sched::schedule() context which does not have 'this' variable.

This solution skips inlined functions when considering print
candidates.  The printed information would be confusing anyway: file
and line number would be of the inlined function but printed function
name would belong to the caller. Finally we will reach the non-inlined
caller and print the call site properly.

Fixes #124.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc/mount: Change umount2 and add umount

umount2 should call sys_umount2 instead.  Add umount that calls sys_umount.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Implement mknod()

I tried using a test which called mknod() (to create an empty regular file).
Despite us having an mknod() implementation, it didn't work, and failed on
lookup of the symbol __xmknod.

Turns out that in glibc, mknod() is source-only, and converted to the ABI
function which is __xmknod, whose first parameter is a version number
_MKNOD_VER_LINUX (0 on x86-64 Linux).

So this patch implements __xmknod, and now mknod() works.

Note we already had the same kind of trick for __xstat(), needed so that
stat() would work.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
runtime: fix prio_find_thread() ignoring missing threads

prio_find_thread() is not checking correctly for missing threads, and
may return nulls to the caller.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
build: Fix some debug build errors

Add -Wno-maybe-uninitialized to compilation flags when mode=debug to
avoid bogus compilation errors.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mmu: support MAP_UNINITIALIZED flag

When seeing this flag, pages fault in should not be filled with zeroes or any
other patterns, and should rather be just left alone in whatever state we find
them at.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: Add munmap validation

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: Add munmap tests into tst-mmap-file

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mman: Fix errno handling in mmap and munmap

Nadav Har'El explains:

  Traditionally, functions which succeed do NOT set errno to zero, but
  rather leave it unchanged (errno(3) on Linux says, for example, that
  "errno is never set to zero by any system call or library function.").

Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
rcu: forward declare preempt_enable() to avoid #include hell

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>