epoll: fix up lock ordering issues

epoll suffers from a basic lock ordering issue: epoll_ctl() needs to
protect against concurrent adds, so it needs an epoll-wide lock to be held
during these operations, which also involve the polled file's lock.  On the
other hand, when a polled file has an event, already holding its own lock,
it wants to enqueue it to all epollers, it needs the epoll's lock to protect
the _activity data structure.

Fix by splitting epoll_file::f_lock into two: f_lock is used to protected
epoll_file::map (used for epoll_ctl), while a new _activity_lock is used
to protect _activity and the rest of the notification side.

This simplifies a lot of code and prevents some races, and allows us to fix
up the close() path.

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
musl: clean up more libc/math/ files

Clean up all remaining libc/math/ files which we can take from musl.
Some of these files we didn't modify at all (just took a slightly
different version), and some we modified to avoid unjustified warnings.

Now, instead of modifying the musl files to avoid errors (unused variable,
and false "maybe uninitialized" errors), I added in libc/build.mk explicit
"-Wno-error" directives to warn, not stop compilation, when the known
issues happen on the known files (e.g., maybe-uninitialized on lgammar_r.c).
Hopefully this won't be necessary in newer version of musl.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
xmitter: move xmitter_functor to driver indipendent header

Another drivers will use it, better to move them to percpu_xmit.hh.

Reviewed-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vmxnet3: implement xmitter

Reviewed-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vmxnet3: move slice_memory to header

Reviewed-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vmxnet3: rename enums

Reviewed-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vmxnet3: move vmxnet3 RX methods to vmxnet3_rxqueue

Reviewed-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vmxnet3: move vmxnet3 TX methods to vmxnet3_txqueue

Reviewed-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vmxnet3: Switch to vmxnet3_rx/txqueue::enable/disable_interrupt()

Reviewed-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vmxnet3: drop error packet on receiver

Reviewed-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Merge branch 'vmxnet3'
musl: more cleanups in stdio/

Remove 4 files that were identical to the musl originals except the
include of <stdio.h> was replaced by either "stdio.h" or "stdio_impl.h".

It is working well with <stdio.h>, so we can use the unmodified musl
files.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: _chk versions for memset and memmove

The needed check should be pretty trivial, it is just a matter of ensuring the
size is respected. To move towards a more common implementation, I am bringing
in here a new function _chk_fail, that can be called when the check fails. I am
not converting any users, but I can do that, if we agree upon this approach. In
any case, because I abort on _chk_fail, the current behavior should be consistent
with existing checks.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc/time: Migrate to upstream musl

Migrate all identical files under libc/time to upstream musl.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc/temp: Migrate to upstream musl

Migrate all identical files under libc/temp to upstream musl.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc/network: Migrate to upstream musl

Migrate all identical files under libc/network to upstream musl.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
musl: clean more files from libc/stdio

A few files only added "#define _GNU_SOURCE" to the original musl code,
supposedly to make this work together with glibc headers. Since we no
longer use glibc headers in our compilation (and haven't done so in a
very long time), this different is no longer relevant, and can be dropped.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: add the new memory files to the build

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
musl: more stdio files from musl

libc/stdio/stdio_ext.h is identical to include/api/stdio_ext.h, so can
be removed. ext.c's only change was from <stdio_ext.h> to "stdio_ext.h"
so it can be removed too.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
musl: remove libc/stdio/stdio.h

Remove libc/stdio/stdio.h, which was an unnecessary slightly-modified copy
of include/api/stdio.h. Musl doesn't have a stdio/stdio.h file either.
In a few places that included "stdio.h" and similar, include <stdio.h> instead.

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