Fix bug in readv() and fread()

readv() takes a pointer to *const* iovecs, meaning it isn't allowed to change
them. Unfortunately, our internal read implementation did modify the iovecs,
zeroing their length field. It turns out that this non-conformity with the
standard also breaks our fread() implementation, which uses readv() and
assumes it doesn't touch the iovec's lengths, so without this patch fread()
with large enough lengths will return garbage.

Interestingly, the compiler should have warned us about writing to a const
field, except we had an explicit cast (!) removing the constness. Yuck.

The solution is to copy the iovecs in sys_read (the new vector is allocated
on the heap). Interestingly, the existing code already used a silly function
"copyinuio" which allocated the "uio" structure on the heap, which we didn't
need to do, and forgot to copy the iovec, which it needed to. So use correct
inline code instead of the useless copyinuio().

Fixes #354.

In separate patches I will provide a test case for this bug, and also the same
patch for writev() and perhaps other users of copyinuio().

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Merge branch 'master' of https://github.com/cloudius-systems/osv
zfs: align vdev_label_t buffer to page boundary

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
xen: align grant table to page boundary

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
vmxnet3: Fix TSO support on VMware Player/Workstation/Fusion

There's a report that TSO support on VMware Player/Workstation/Fusion was broken on upstream OS of this driver(FreeBSD):
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=185849
This patch is backported from the fix on FreeBSD:
http://svnweb.freebsd.org/base?view=revision&revision=267253

fixed #340

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Reviewed-by: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Remove dead code

Remove copyinuio() function. Not needed any more, and shouldn't be needed
in the future (there is no reason to allocate a uio on the heap, and there's
a reason to copy the iovecs, which this function didn't).

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Remove double include

Signed-off-by: KANATSU Minoru <icc.pot.tyew272@gmail.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tcp: trim mbuf to IP packet length in the net channel path

Fixes #342.

According to RFC894 the minimum ethernet frame size is 60 bytes. When
the packet is smaller than that it should be padded. Looks like vmxnet
in constrast to virtio-net respects this rule and pads small packets
with zeros.

FreeBSD's stack is prepared for this, the mbuf is trimmed in
ip_preprocess_packet() which is called from ip_input(). However our
net channel fast path did not have this logic. This patch adds the
missing processing to tcp_net_channel_packet().

Reported-by: Lyor Goldstein <lgoldstein@vmware.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Test readv() and fread()

This test confirms bug issue #354, and verifies its fix.

It demonstrates that readv() wrongly modified its const parameter, and
fread() returned garbage data (compared to the correct data returned by
getc() and read()), and that after this bug's fix, both readv() and
fread() work correctly.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Fix writev() as well

This patch fixes a bug in writev() identical to the one we already fixed
in readv() - it illegally modified its const argument.

The patch also adds to tests/tst-uio.cc a test for this bug.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
elf: warn when using unsupported combination of PIE and TLS

As explained in issue #352, a PIE (position-independent executable) using
TLS (thread-local storage) does not currently work correctly. Fixing this
case is not easy, but until we do, it is dangerous to allow this case to
be ignored, as it causes reading and writing to wrong positions in memory
whenever TLS is used in the PIE.

So this patch adds a warning printout (to stdout) whenever one attempts to
load a PIE which has any TLS variables.

This is, of course, just a temporary measure. The real solution is to fix
object load and not just warn.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
dhcp: add handling of option 121 "Classless Static Route"

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mgmt: update

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
modules: add the osvinit module

This adds the osvinit module to the image.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mgmt: update

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
aarch64: entry.S: do not treat all sync aborts as page faults

not all sync aborts are made equal: do not treat everything
as translation faults. For everything else, for now just
put the interesting values in X21..X24 and halt, so that
we can easily debug what happened.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
aarch64: libc: remove unnecessary AARCH64_PORT_STUB

The stub implementation is not necessary anymore,
we have mmu and page faults now.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
async: remove unused include directive

also remove the AARCH64_PORT_STUB which becomes useless.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build.mk: fix info message broken by previous commits

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Use osv::run in run_elf()

In run_elf(), our JNI function for running an executable (used, for example
in the shell's "run" command), use osv::run instead of reimplementing it.
osv::run has recently acquired more steps, namely copying the arguments
to be consecutive in memory, and in the future might get even more complex,
e.g., treat executables differently from shared objects. So let's use
osv::run when we can.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>