Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/virtio.c
/*- | /*- | ||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | ||||
* | * | ||||
* Copyright (c) 2013 Chris Torek <torek @ torek net> | * Copyright (c) 2013 Chris Torek <torek @ torek net> | ||||
* All rights reserved. | * All rights reserved. | ||||
* Copyright (c) 2019 Joyent, Inc. | |||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
Show All 13 Lines | |||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/uio.h> | #include <sys/uio.h> | ||||
#include <machine/atomic.h> | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <pthread_np.h> | #include <pthread_np.h> | ||||
#include "bhyverun.h" | #include "bhyverun.h" | ||||
kib: Usually machine/ comes after sys/, before userspace headers. | |||||
Done Inline ActionsThere was some inconsistency in the other bhyve examples for that which lead me astray. Will fix. pmooney_pfmooney.com: There was some inconsistency in the other bhyve examples for that which lead me astray. Will… | |||||
#include "pci_emul.h" | #include "pci_emul.h" | ||||
#include "virtio.h" | #include "virtio.h" | ||||
/* | /* | ||||
* Functions for dealing with generalized "virtual devices" as | * Functions for dealing with generalized "virtual devices" as | ||||
* defined by <https://www.google.com/#output=search&q=virtio+spec> | * defined by <https://www.google.com/#output=search&q=virtio+spec> | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 368 Lines • ▼ Show 20 Lines | vq_relchain(struct vqueue_info *vq, uint16_t idx, uint32_t iolen) | ||||
*/ | */ | ||||
mask = vq->vq_qsize - 1; | mask = vq->vq_qsize - 1; | ||||
vuh = vq->vq_used; | vuh = vq->vq_used; | ||||
uidx = vuh->vu_idx; | uidx = vuh->vu_idx; | ||||
vue = &vuh->vu_ring[uidx++ & mask]; | vue = &vuh->vu_ring[uidx++ & mask]; | ||||
vue->vu_idx = idx; | vue->vu_idx = idx; | ||||
vue->vu_tlen = iolen; | vue->vu_tlen = iolen; | ||||
/* | |||||
rgrimesUnsubmitted Not Done Inline Actionsjhb: blank line before block comments. rgrimes: jhb: blank line before block comments. | |||||
* Ensure the used descriptor is visible before updating the index. | |||||
* This is necessary on ISAs with memory ordering less strict than x86. | |||||
*/ | |||||
atomic_thread_fence_rel(); | |||||
Done Inline ActionsThis should be substituted by atomic_thread_fence_rel(), indeed. kib: This should be substituted by atomic_thread_fence_rel(), indeed. | |||||
vuh->vu_idx = uidx; | vuh->vu_idx = uidx; | ||||
} | } | ||||
/* | /* | ||||
* Driver has finished processing "available" chains and calling | * Driver has finished processing "available" chains and calling | ||||
* vq_relchain on each one. If driver used all the available | * vq_relchain on each one. If driver used all the available | ||||
* chains, used_all should be set. | * chains, used_all should be set. | ||||
* | * | ||||
Show All 21 Lines | vq_endchains(struct vqueue_info *vq, int used_all_avail) | ||||
* but suppressed by VRING_AVAIL_F_NO_INTERRUPT. | * but suppressed by VRING_AVAIL_F_NO_INTERRUPT. | ||||
* | * | ||||
* In any case, though, if NOTIFY_ON_EMPTY is set and the | * In any case, though, if NOTIFY_ON_EMPTY is set and the | ||||
* entire avail was processed, we need to interrupt always. | * entire avail was processed, we need to interrupt always. | ||||
*/ | */ | ||||
vs = vq->vq_vs; | vs = vq->vq_vs; | ||||
old_idx = vq->vq_save_used; | old_idx = vq->vq_save_used; | ||||
vq->vq_save_used = new_idx = vq->vq_used->vu_idx; | vq->vq_save_used = new_idx = vq->vq_used->vu_idx; | ||||
/* | |||||
rgrimesUnsubmitted Not Done Inline ActionsBlank line before block comment rgrimes: Blank line before block comment | |||||
* Use full memory barrier between vu_idx store from preceding | |||||
* vq_relchain() call and the loads from VQ_USED_EVENT_IDX() or | |||||
* va_flags below. | |||||
*/ | |||||
atomic_thread_fence_seq_cst(); | |||||
Done Inline ActionsThis should be atomic_thread_fence_seq_cst(). Atomic_thread_fence_acq_rel() does not order reads after writes, it is a mechanical combination of acq and rel. kib: This should be atomic_thread_fence_seq_cst(). Atomic_thread_fence_acq_rel() does not order… | |||||
if (used_all_avail && | if (used_all_avail && | ||||
(vs->vs_negotiated_caps & VIRTIO_F_NOTIFY_ON_EMPTY)) | (vs->vs_negotiated_caps & VIRTIO_F_NOTIFY_ON_EMPTY)) | ||||
intr = 1; | intr = 1; | ||||
else if (vs->vs_negotiated_caps & VIRTIO_RING_F_EVENT_IDX) { | else if (vs->vs_negotiated_caps & VIRTIO_RING_F_EVENT_IDX) { | ||||
event_idx = VQ_USED_EVENT_IDX(vq); | event_idx = VQ_USED_EVENT_IDX(vq); | ||||
/* | /* | ||||
* This calculation is per docs and the kernel | * This calculation is per docs and the kernel | ||||
* (see src/sys/dev/virtio/virtio_ring.h). | * (see src/sys/dev/virtio/virtio_ring.h). | ||||
▲ Show 20 Lines • Show All 310 Lines • Show Last 20 Lines |
Usually machine/ comes after sys/, before userspace headers.