From: Marco Schlumpp Date: Thu, 16 Feb 2023 13:37:42 +0000 (+0100) Subject: PR #610.1: Various fixes for firecracker networking X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=e76e29c60cace4cd7b86c99d2e6cfc76e9771396;p=unikraft%2Funikraft.git PR #610.1: Various fixes for firecracker networking * There were some incorrect offsets in the orginal PR * The feature negotiation did not work for the virtqueue --- diff --git a/plat/drivers/virtio/virtio_mmio.c b/plat/drivers/virtio/virtio_mmio.c index e0f72573a..f3ad107e3 100644 --- a/plat/drivers/virtio/virtio_mmio.c +++ b/plat/drivers/virtio/virtio_mmio.c @@ -114,7 +114,7 @@ static void vm_set_features(struct virtio_dev *vdev, struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev); /* Give virtio_ring a chance to accept features. */ - virtqueue_feature_negotiate(features); + features = virtqueue_feature_negotiate(features); /* Make sure there are no mixed devices */ if (vm_dev->version == 2 && diff --git a/plat/drivers/virtio/virtio_net.c b/plat/drivers/virtio/virtio_net.c index 01f4fbf59..74c032260 100644 --- a/plat/drivers/virtio/virtio_net.c +++ b/plat/drivers/virtio/virtio_net.c @@ -340,7 +340,7 @@ static int virtio_netdev_xmit(struct uk_netdev *dev, struct virtio_net_device *vndev; struct virtio_net_hdr *vhdr; struct virtio_net_hdr_padded *padded_hdr; - int16_t header_sz = sizeof(*padded_hdr); + int16_t header_sz; int rc = 0; int status = 0x0; size_t total_len = 0; @@ -351,6 +351,9 @@ static int virtio_netdev_xmit(struct uk_netdev *dev, UK_ASSERT(pkt && queue); vndev = to_virtionetdev(dev); + + header_sz = vndev->modern ? VIRTIO_HDR_LEN : sizeof(*vhdr); + /** * We are reclaiming the free descriptors from buffers. The function is * not protected by means of locks. We need to be careful if there are @@ -363,7 +366,7 @@ static int virtio_netdev_xmit(struct uk_netdev *dev, /** * Use the preallocated header space for the virtio header. */ - rc = uk_netbuf_header(pkt, VIRTIO_HDR_LEN); + rc = uk_netbuf_header(pkt, vndev->modern ? VIRTIO_HDR_LEN : sizeof(*padded_hdr)); if (unlikely(rc != 1)) { uk_pr_err("Failed to prepend virtio header\n"); rc = -ENOSPC; @@ -384,11 +387,11 @@ static int virtio_netdev_xmit(struct uk_netdev *dev, * to `uk_sglist_append_netbuf()`. However, a netbuf * chain can only once have set the PARTIAL_CSUM flag. */ - memset(vhdr, 0, VIRTIO_HDR_LEN); + memset(vhdr, 0, header_sz); if (pkt->flags & UK_NETBUF_F_PARTIAL_CSUM) { vhdr->flags |= VIRTIO_NET_HDR_F_NEEDS_CSUM; /* `csum_start` is without header size */ - vhdr->csum_start = pkt->csum_start - header_sz; + vhdr->csum_start = pkt->csum_start - (vndev->modern ? VIRTIO_HDR_LEN : sizeof(*padded_hdr)); vhdr->csum_offset = pkt->csum_offset; } if (pkt->flags & UK_NETBUF_F_GSO_TCPV4) { diff --git a/plat/drivers/virtio/virtio_ring.c b/plat/drivers/virtio/virtio_ring.c index 5f748b542..3e0e35e37 100644 --- a/plat/drivers/virtio/virtio_ring.c +++ b/plat/drivers/virtio/virtio_ring.c @@ -253,6 +253,8 @@ __u64 virtqueue_feature_negotiate(__u64 feature_set) { __u64 feature = (1ULL << VIRTIO_TRANSPORT_F_START) - 1; + /* Allow version 1 flag */ + feature |= 1ULL << VIRTIO_F_VERSION_1; /* Allow event index feature */ feature |= 1ULL << VIRTIO_F_EVENT_IDX;