Skip to content

Commit

Permalink
lkl-arm: Fixes and quirks to get virtio_net_raspi working
Browse files Browse the repository at this point in the history
- Prevent deadlocks when polling for network I/O
- Remove calls to lkl_sys_close to prevent crashes
- Fix incorrect buffer offset
  • Loading branch information
midchildan committed Feb 28, 2019
1 parent 955c503 commit 50107f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tools/lkl/lib/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ int lkl_if_up(int ifindex)
err = lkl_sys_ioctl(sock, LKL_SIOCSIFFLAGS, (long)&ifr);
}

// XXX: Workaround to avoid crashes in raspi
#ifndef LKL_HOST_CONFIG_VIRTIO_NET_RASPI
lkl_sys_close(sock);
#endif

return err;
}
Expand Down Expand Up @@ -596,7 +599,10 @@ static int ipaddr_modify(int cmd, int flags, int ifindex, int af, void *addr,

err = rtnl_talk(fd, &req.n);

// XXX: Workaround to avoid crashes in raspi
#ifndef LKL_HOST_CONFIG_VIRTIO_NET_RASPI
lkl_sys_close(fd);
#endif
return err;
}

Expand Down
19 changes: 18 additions & 1 deletion tools/lkl/lib/virtio_net_raspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ static inline size_t min(size_t a, size_t b)
return (a > b) ? b : a;
}

static inline void platform_sleep(void)
{
typedef int64_t time_t;
struct __platform_timespec { time_t tv_sec; long tv_nsec; };
extern int __platform_clock_nanosleep(int clock_id, int flags,
const struct timespec *request,
struct timespec *remain);

struct __platform_timespec sl = {0, 0};

__platform_clock_nanosleep(3 /* == CLOCK_MONOTONIC */, 0, &sl, NULL);
}

static int net_tx(struct lkl_netdev *nd, struct iovec *iov, int cnt)
{
struct lkl_netdev_raspi *nd_raspi =
Expand All @@ -37,8 +50,8 @@ static int net_tx(struct lkl_netdev *nd, struct iovec *iov, int cnt)
else if (len == 0)
continue;

sent += to_send;
memcpy(buffer + sent, iov[seg].iov_base, to_send);
sent += to_send;
}

if (sent > 0) {
Expand Down Expand Up @@ -83,6 +96,9 @@ static int net_poll(struct lkl_netdev *nd)
if (nd_raspi->is_closed)
return LKL_DEV_NET_POLL_HUP;

// XXX: Necessary to avoid deadlocks
platform_sleep();

return LKL_DEV_NET_POLL_RX | LKL_DEV_NET_POLL_TX;
}

Expand Down Expand Up @@ -120,5 +136,6 @@ struct lkl_netdev *lkl_netdev_raspi_create(void)

nd->is_closed = 0;
nd->dev.ops = &raspi_net_ops;
nd->dev.has_vnet_hdr = 0;
return nd;
}

0 comments on commit 50107f4

Please sign in to comment.