epoll: make epoll_wait respect concurrent updates

Fixes #331.

The solution is rather a workoaround. It's using an extra pipe file,
which is added to the poll list, to interrupt epoll_wait() upon
updates.

This fix is needed to implement httpserver shutdown.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tests: add test for epoll_ctl concurrent with epoll_wait

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tests: make tst-epoll return non-zero exit code on error

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tests: fix tst-sigwait.cc

I was observing that tst-sigwait was hanging from time to time. As it
turned out, the culprit was concurrent access of non-atomic variable:
siguser2_received. It was set in one thread and read in another like
this:

  while (siguser2_received == 0);

Because this variable is neither volatile nor std::atomic<>, the
compiler can legitimately elide subsequent reads and in fact it checks
the variable only on first access, which leads to infinite loop under
right timing. Here's the assembly for the loop:

    1ec0:   8b 00                   mov    (%rax),%eax
    1ec2:   85 c0                   test   %eax,%eax
    1ec4:   0f 84 e1 01 00 00       je     20ab

    # ... right round, baby, right round
    20ab:   0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)
    20b0:   eb f9                   jmp    20ab

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>
net: simplify inpcb allocation

Remove inpcbinfo::ipi_zone, replacing it by a normal new/delete.  This reduces
indirections and makes it easier to modify the stack.

The call to uma_zone_set_max() is lost, but since it was a no-op, there
is no change in functionality.  If desired, it can be restored using
something like

  -new inpcb(...);
  +new (resticted_allocator) inpcb(...);

where restricted_allocator fails if we overflow the socket limit.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
net: remove unused fields from struct inpcb

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
net: inpcb: replace bzero() with C++ initialization

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
net: remove tcp offload support

Unused and unusable in virt context.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
net: convert inpcbinfo::ipi_lock to a mutex

ipi_lock is now a rwlock, which is expensive and complicated to reason about.
However, everywhere interesting it is taken for write (except for accept()),
so we can convert it into an ordinary mutex without loss of parallelism.

Because rw_assert() is defined as a no-op, some of the asserts are converted
in the same way, to avoid triggering latent bugs.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
net: tcp: remove dead code

Remove ipv6, tcp signature, and ipsec support.  While it will be a pain to
add them back later, it's impossible to maintain them while modifying the
code.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
net: tcp: fix up indentations

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Revert "build: remove .SECONDARY"

This reverts commit 93a520b9665193659edd953021b18c394065328f.  According to
Nadav's analisys, .SECONDARY was not at fault (it was libstatic-thread-local.so
trying to link against itself; fixed by a4b52857d38.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
net: Add fast path in ARP lookups

This patch adds a fast path to arpresolve. A RCU protected ARP cache is
introduced to accelerate arpresolve lookup. IPv4 address and MAC address
are cached. If we hit the cache, no mutexes are taken and we go to the
fast path. If not, we go to the normal slow path. Most of the time will
we hit the fast path, in this case, in a single lookup,
IF_AFDATA_RLOCK(ifp), IF_AFDATA_RUNLOCK(ifp), LLE_RLOCK(lle),
LLE_RUNLOCK(lle) will be saved.

Currently, arpresolve returns a 'struct llentry* lle' which is used in
ether_output. We might hit use-after-free if we do not take the lle lock
in the fast path. However, in ether_output, lle is only used to check if
the lle contains LLE_IFADDR flag. To solve this issue, we return a
is_ifaddr flag instead of lle.

Fixes #300.

Signed-off-by: Asias He <asias@cloudius-systems.com>
[avi: remove debug calls]
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
syscall: Drop #if 0'd sendfile code

Killing it simplifies the sblock/sbunlock code auditing.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
net: Get rid of unnecessary recursive locking

We already get SOCK_LOCK(so) before we call sblock() everywhere. No need
to do recursive locking.

Similarly, we will call SOCK_UNLOCK(so) after we call sbunlock()
everywhere.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Drivers get_name method should be const

There is no point in returning a const object as a name, it is useful to
make the method const.

This patch changes hw_driver from
virtual const std::string get_name() to virtual std::string get_name() const

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
libtools should be added to the image

libtools got its own module and was added as a dependency to the
httpserver model.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Move the get interface logic outside of ifconfig into libtools.lib

Expose the logic of getting the interface outside of ifconfig
implementation and allows other module to use it.

The implementation hide the bsd related details from modules that uses
it.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: Add an API to unset environment variable

This adds an API and a test to unset an environment variable.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
rcu hashtable: add documenation

Add doxygen style documentation.  In addition, add separate helpers
for owner_find() and reader_find() in the special case where the type
of the key is equal to the type of the data element.

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