Module Name: src Committed By: riastradh Date: Fri Aug 12 10:49:58 UTC 2022
Modified Files: src/sys/dev/pci: virtio.c Log Message: virtio(4): Membar and bus_dmamap_sync audit. - Don't use membar_* for DMA. - Sync only the header and payload of the rings separately as needed. If we bounce, this avoids large memcpy when we only care about the header. - Sync uring with PREREAD before triggering anything that will return data in it. => Move uring PREREAD in virtio_enqueue_commit to _before_ updating vq->vq_avail->idx, which is the pointat which the DMA read is triggered in the `device' (host). => Omit needless membar_consumer in virtio_enqueue_commit -- may not work with DMA memory, and even if it does, redundant with bus_dmamap_sync uring PREREAD here. => XXX Does the device/host ever return unsolicited entries in the queue, or only solicited ones? If only solicited ones, the PREREAD in virtio_init_vq is redundant. - Sync uring with POSTREAD before we read from it. This way the DMA read into our buffer has finished before we read from the buffer. => Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of vq->vq_used_idx and return to caller, so that the caller can safely use virtio_dequeue. => Add missing uring POSTREADs in virtio_start_vq_intr: . between entry from caller and the read of vq->vq_used_idx . between the read of vq->vq_used_idx and return to caller, so that the caller can safely use virtio_dequeue, just like virtio_vq_is_enqueued => Move uring POSTREADs in virtio_enqueue_commit to _before_ reading vq->vq_used->flags or *vq->vq_avail_event, not after. - After we write to aring, sync it with PREWRITE. This way we finish writing to our buffer before the DMA write from it. => Omit needless PREWRITE in virtio_init_vq -- we do the appropriate PREWRITE in virtio_enqueue_commit now. => Convert membar_producer to bus_dmamap_sync PREWRITE in virtio_enqueue_commit. => Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need because the DMA write may not have completed yet at this point, and we already do a POSTWRITE in virtio_vq_is_enqueued. => Omit needless membar_producer in virtio_postpone_intr -- may not work with DMA memory, and even if it does, redundant with bus_dmamap_sync PREWRITE here. - After xfers to aring have completed, sync it with POSTWRITE. => Add missing aring POSTWRITE in virtio_free_vq, in case there are paths from virtio_enqueue_commit to here that don't go through virtio_is_enqueued. (If there are no such paths, then maybe we should KASSERT(vq->vq_queued == 0) in virtio_free_vq.) To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/sys/dev/pci/virtio.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.