mmu: separate lock for vpopulate and friends

When the debug allocator is active, it will call vpopulate() to manage the
page table.  This causes a deadlock, as vpopulate() takes vma_list_mutex,
while other operations that hold vma_list_mutex may allocate memory.

Fix by using a separate mutex for the debug range.  This is safe since the
page table root is pre-allocated, and any lower page tables will be either
in the vma list range, or the debug range, but not both.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
virtio: fix virtio-blk under debug allocator

The debug allocator can allocate non-contiguous memory for large requests,
but since b7de9871b31 it uses only one sg entry for the entire buffer.

One possible fix is to allocate contiguous memory even under the debug
allocator, but in the future we may wish to allow discontiguous allocation
when not enough contiguous space is available.  So instead we implement
a virt_to_phys() variant that takes a range, and outputs the physical
segments that make it up, and use that to construct a minimal sg list
depending on the input.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Merge tag 'v2p-debug-v1' of https://github.com/avikivity/osv

This patchset fixes bad interaction between the debug allocator and virtio.

After this patchset, 'make check' still fails, but this is due to genuine
use-after-free problems in the vfs, so will be fixed later.

Fixes #240.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
vfs: leak: Release refcnts hold by main_task structure on shutdown

Whenever you change the working directory through either fchdir or chdir,
a file structure holding refcnts to the underlying mount point is set to
the field t_cwdfp of main_task. If t_cwdfp was previously set, then the
older data will be freed and replaced by the newer one.
The problem exists because these refcnts are never released afterwards.

Changes introduced by this patch:
1) Create a function and use lambda to reuse as much code as possible
(Suggested by Glauber Costa).

2) Create vfs_exit that will use the function previously created to
free up main_task resources, and call unmount_rootfs afterwards.
Needless to say, vfs_exit replaces the function unmount_rootfs at the
shutdown procedure.

After applying the changes described above, the refcnt leaks on the root
mount point are gone.

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>
trace: implement __lt__ for Trace

Python3 no longer supports __cmp__, we need to define __lt__ to make
the objects comparable. This fixes `trace extract` on GDB linked with
python3.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
runtime: implement getgrnam function

Enhance our runtime with the getgrnam function. Although we have no groups,
we will recognize group "nobody" for compatibility and return that as group
0

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libtsm: Add scroll callback

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vga: hw scroll support

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vga: rename private members

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