29 Commits

Author SHA1 Message Date
Alan 77f6ea83ae uip: finish off the changes for connect()
A connect that fails is now echoed back to the guest with a valid RST frame
so that the client user sees "connection refused" not a long timeout and
failure.
2015-07-15 02:01:50 +01:00
Arjan van de Ven fccb7a1553 Skip ethernet header in the packet, with this DHCP works 2015-07-15 02:01:50 +01:00
Alan 2ce27503a0 dhcp: Possible fix
This should hopefully fix the problem by walking the options, however clear
has committed suicide so its untested
2015-07-15 02:01:50 +01:00
Arjan van de Ven b3d7cd0539 Reduce console spam
remove left over debug printf
2015-07-15 02:01:50 +01:00
Alan 93454e8983 tools/kvm: fix assumption of no IP options 2015-07-15 01:57:26 +01:00
Will Deacon 6d6cc14b76 kvm tools: net: don't propagate error codes from tx/rx operations
Currently, if a ->tx or ->rx callback into the net_dev_operations
encounters an error, it returns -1 to the virtio-net code, which in turn
treats this as an unsigned (size_t) size describing the data available.
The resulting memcpy operation then quickly explodes with a SEGV.

This patch detects the error code from the low-level callbacks and
exits the thread dealing with the erroneous queue.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:54 +01:00
Marc Zyngier 5f3aaf2281 kvm tools: plug race between uip_init and virtio_net_rx_thread
When fa7226f (kvm tools: init network devices only when the virtio
driver is ready to go) was introduced, a tiny detail was overlooked:

- Initialization of the uip layer is now coming in very late (only
  when the guest driver says it is ready).
- In parallel, the rx thread is created quite early (as soon as the
  queues are allocated).

This cause the rx thread to call uip_rx, which calls uip_buf_get_used,
which starts to use buf_lock mutex/the buf_used_cond, which haven't
been initialized yet. Tears and devastation follow, not to mention a
certain lack of network connectivity for the unsuspecting guest.

The (not so pretty) fix is to split uip_init:
- uip_static_init: initialize the lists, mutexes and conditions,
  called from virtio_net__init_one.
- uip_init: perform the dynamic memory allocations, called from
  notify_status.

This allows the network to be safely initialized.

Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:54 +01:00
Sasha Levin 7668c3a677 kvm tools: virtio-net mergable rx buffers
Support mergable rx buffers for virtio-net. This helps reduce the amount
of memory the guest kernel has to allocate per rx vq.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:54 +01:00
Sasha Levin 7200d3a15c kvm tools: use iovec functions in uip_rx
Simplifies the code a lot.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:54 +01:00
Sasha Levin 643f6c0857 kvm tools: pass virtio header size to uip_init
We want to make the size of the virtio net header opaque to
uip.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:54 +01:00
Sasha Levin d3476f7d3b kvm tools: use mutex abstraction instead of pthread mutex
We already have something to wrap pthread with mutex_[init,lock,unlock]
calls. This patch creates a new struct mutex abstraction and moves
everything to work with it.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:53 +01:00
Sasha Levin a4d8c55eb2 kvm tools: Specify names for VM internal threads
Give threads a meaningful name. This makes debugging much easier, and
everything else much prettier.

Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
[ penberg@kernel.org: specify vcpu names ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:53 +01:00
Asias He 3909f9b57b kvm tools: Respect guest tcp window size
Respect guest tcp window size and stop sending tcp segments to guest
if guest's receive window is closed.

This fixes the TCP hang I'm seeing where guest and host are transferring
big chuck of data.

This problem was not triggered when guest and external host
communicates, probably because guest to external host communication
walks through real network and is much slower than guest and host
communication. Thus, guest's receive window has little chance to be
closed.

v2: use pthread_cond_wait to wait

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He 195544b78f kvm tools: Make tcp between guest/host virtual ip work in UIP mode
This pach makes tcp between 'guest ip' and 'host virtual ip' work in UIP mode.
(The defulat guest ip is 192.168.33.15, host virtual ip is 192.168.33.1)

  guest$ wget http://192.168.33.1/file
  guest$ ssh 192.168.33.1

Without this patch, user has to figure out the ip address of host's
interface (e.g. eth0) and use that ip address to access host.

With this patch, user can simply use the virtual host ip.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman a7b946b905 kvm tools: Fix crash when /etc/resolv.conf doesn't exist
In uip_dhcp_get_dns() we try to open /etc/resolv.conf. If we fail to
open it we then SEGV trying to fclose() it.

Fix the code to just return directly if we can't open it.

Acked-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He 5943c3cbbc kvm tools: Fix a vertical indentation for net/uip/udp.c
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Asias He 7b0155fed9 kvm tools: Use macro in uip_tx_do_ipv4()
Use marcro instead of magic number in uip_tx_do_ipv4()

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 575a9e3f31 kvm tools: Use kernel dhcp for network autoconfiguration
This patch removes the manual/usermode dhcp client configuration and instead
uses the DHCP client built within the kernel.

Since this client is tightly integrated with NFS (if NFS config is set), we
will add a specific NFS root addr in our DHCP offer to point it to a non
existent address so that we won't hang trying to poke it for our root.

Acked-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:47 +01:00
Asias He 41b13f6a1c kvm tools: Handle DHCP package in gernal UDP processing path
DHCP packages are handled by the hypervisor, they are not sent to remote
servers. In contrast, all other non-DHCP UDP packages are sent to remote
servers.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Asias He 80f43f64dd kvm tools: Get DNS information from host in uip_init()
Use uip_dhcp_get_dns() in uip_init() to get DNS information from host
for DHCP.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Asias He bcd315db17 kvm tools: Introduce uip_tx_do_ipv4_udp_dhcp()
uip_tx_do_ipv4_udp_dhcp() is used to handle DHCP packages from guest.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Asias He 155c7f336c kvm tools: Introduce uip_dhcp_make_pkg()
This patch cooks a DHCP package.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Asias He ab8d80a615 kvm tools: Fill all DHCP options
The following DHCP options are filled.

   - MSG_TYPE

   - SERVER_ID

   - LEASE_TIME

   - SUBMASK

   - ROUTER

   - DNS_SERVER

   - DOMAIN_NAME

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Asias He 32a44aaf03 kvm tools: Fill DHCP options with domain name and DNS server IP
Domain name and DNS server IP address are filled.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Asias He bdcc9e40df kvm tools: Get domain name and nameserver from host
This patch get domain name and nameserver information from host config
file /etc/resolv.conf.

Guest can obtain DNS information through DHCP.

Signed-off-by: Asias He <asias.hejun@gmail.com>
[ penberg@kernel.org: check fscanf() for errors ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Asias He 8f5f2f958f kvm tools: Add helpers to tell the type of a DHCP message
If DHCP DISCOVER or DHCP REQUEST is found, reply with DHCP OFFER or DHCP
ACK respectively.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Asias He 0c4bfcac1c kvm tools: Add helper to tell if a UDP package is a DHCP package
This patch checks:

   - sport and dport

   - magic cookie

to detemine whether a UDP package is a DHCP package.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Asias He d9da915bb5 kvm tools: Introduce uip_udp_make_pkg()
This helper cooks a ethernet package and virtio header for UDP.
This patch also makes uip_udp_socket_thread() shorter.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Asias He 42a6c572af kvm tools: Move uip to net directory
This mirrors what the kernel already has.

Suggested-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00