Changeset 417aaafb in mainline


Ignore:
Timestamp:
2018-06-25T21:37:48Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e3107e2
Parents:
ea6840d
Message:

Protect the virtqueue with a mutex

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/virtio-net/virtio-net.c

    rea6840d r417aaafb  
    155155    uint16_t *head)
    156156{
     157        virtq_t *q = &vdev->queues[num];
     158        fibril_mutex_lock(&q->lock);
    157159        uint16_t descno = *head;
    158160        if (descno != (uint16_t) -1U)
    159161                *head = virtio_virtq_desc_get_next(vdev, num, descno);
     162        fibril_mutex_unlock(&q->lock);
    160163        return descno;
    161164}
     
    171174    uint16_t *head, uint16_t descno)
    172175{
     176        virtq_t *q = &vdev->queues[num];
     177        fibril_mutex_lock(&q->lock);
    173178        virtio_virtq_desc_set(vdev, num, descno, 0, 0, VIRTQ_DESC_F_NEXT,
    174179            *head);
    175180        *head = descno;
     181        fibril_mutex_unlock(&q->lock);
    176182}
    177183
  • uspace/lib/virtio/virtio-pci.h

    rea6840d r417aaafb  
    3636#include <pci_dev_iface.h>
    3737#include <ddi.h>
     38#include <fibril_synch.h>
    3839
    3940#define VIRTIO_PCI_CAP_CAP_LEN(c)       ((c) + 2)
     
    131132        size_t size;
    132133
     134        /** Mutex protecting access to this virtqueue */
     135        fibril_mutex_t lock;
     136
    133137        /**
    134138         * Size of the queue which determines the number of descriptors and
  • uspace/lib/virtio/virtio.c

    rea6840d r417aaafb  
    6363        virtq_t *q = &vdev->queues[num];
    6464
     65        fibril_mutex_lock(&q->lock);
    6566        uint16_t idx = pio_read_le16(&q->avail->idx);
    6667        pio_write_le16(&q->avail->ring[idx % q->queue_size], descno);
     
    6970        write_barrier();
    7071        pio_write_le16(q->notify, num);
     72        fibril_mutex_unlock(&q->lock);
    7173}
    7274
     
    7678        virtq_t *q = &vdev->queues[num];
    7779
     80        fibril_mutex_lock(&q->lock);
    7881        uint16_t last_idx = q->used_last_idx % q->queue_size;
    79         if (last_idx == (pio_read_le16(&q->used->idx) % q->queue_size))
     82        if (last_idx == (pio_read_le16(&q->used->idx) % q->queue_size)) {
     83                fibril_mutex_unlock(&q->lock);
    8084                return false;
     85        }
    8186
    8287        *descno = (uint16_t) pio_read_le32(&q->used->ring[last_idx].id);
     
    8489
    8590        q->used_last_idx++;
     91        fibril_mutex_unlock(&q->lock);
    8692
    8793        return true;
     
    132138        }
    133139
     140        fibril_mutex_initialize(&q->lock);
     141
    134142        q->size = mem_size;
    135143        q->queue_size = size;
Note: See TracChangeset for help on using the changeset viewer.