rcu: allow initializing with a pointer

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
rcu: add a Disposer template parameter so an rcu_ptr<> can own its resource

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
bsd: convert netport.c to C++

Allows making ifnet a C++ class.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
bsd: reconcile sys/param.h with system header

Include the system header and remove duplicate definitions.

Change some solaris imports to use _GNU_SOURCE to make rlim64_t defined
consistently.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: add ntoh()/hton() for in_addr

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: add comparison operator for in_addr

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: enable ifnet constructor/destructor

This allows placing C++ objects in ifnet.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: fix sblock()

sblock() takes sb_rwlock for reading, and is the only such locker, so it
clearly has no effect.

Change it to acquire the lock for writing, so it serializes access to the
socket buffer as intended.

Bug introduced in 6296cbabf89f10b.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: replace sockbuf::sb_rwlock with a waitqueue

sb_rwlock is used to serialize concurrent writers (or readers) to the same
socket buffer, but is quite expensive as it requires 4 atomic operations
per transaction, even if there is no contention.

Replace it with a waitqueue, and use the sockbuf::sb_mtx for serialization.
This still has exactly the same cost, but we can later move sblock() and
sbunlock() into contexts where the sockbuf::sb_mtx is already acquired.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: optimize sblock(), sbunlock()

Instead of acquiring sockbuf::sb_mtx inside sblock() and sbunlock(), rely
on the caller to take the lock for us.  Expand existing lock hold regions
in callers to make it so.  This reduces acquisitions of sb_mtx.

As a side effect, copies to and from userspace are done under the lock.
This can affect MSG_NOWAIT with demand paging major faults, but these are
screwed anyway.

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