提交 64ec45bf 编写于 作者: L Linus Torvalds

Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost

Pull virtio fixes from Michael S Tsirkin:
 "virtio 1.0 related fixes

  Most importantly, this fixes using virtio_pci as a module.

  Further, the big virtio 1.0 conversion missed a couple of places.
  This fixes them up.

  This isn't 100% sparse-clean yet because on many architectures
  get_user triggers sparse warnings when used with __bitwise tag (when
  same tag is on both pointer and value read).

  I posted a patchset to fix it up by adding __force on all arches that
  don't already have it (many do), when that's merged these warnings
  will go away"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
  virtio_pci: restore module attributes
  mic/host: fix up virtio 1.0 APIs
  vringh: update for virtio 1.0 APIs
  vringh: 64 bit features
  tools/virtio: add virtio 1.0 in vringh_test
  tools/virtio: add virtio 1.0 in virtio_test
  tools/virtio: enable -Werror
  tools/virtio: 64 bit features
  tools/virtio: fix vringh test
  tools/virtio: more stubs
  virtio: core support for config generation
  virtio_pci: add VIRTIO_PCI_NO_LEGACY
  virtio_pci: move probe to common file
  virtio_pci_common.h: drop VIRTIO_PCI_NO_LEGACY
  virtio_config: fix virtio_cread_bytes
  virtio: set VIRTIO_CONFIG_S_FEATURES_OK on restore
...@@ -326,21 +326,27 @@ static int mic_vdev_info_show(struct seq_file *s, void *unused) ...@@ -326,21 +326,27 @@ static int mic_vdev_info_show(struct seq_file *s, void *unused)
} }
avail = vrh->vring.avail; avail = vrh->vring.avail;
seq_printf(s, "avail flags 0x%x idx %d\n", seq_printf(s, "avail flags 0x%x idx %d\n",
avail->flags, avail->idx & (num - 1)); vringh16_to_cpu(vrh, avail->flags),
vringh16_to_cpu(vrh, avail->idx) & (num - 1));
seq_printf(s, "avail flags 0x%x idx %d\n", seq_printf(s, "avail flags 0x%x idx %d\n",
avail->flags, avail->idx); vringh16_to_cpu(vrh, avail->flags),
vringh16_to_cpu(vrh, avail->idx));
for (j = 0; j < num; j++) for (j = 0; j < num; j++)
seq_printf(s, "avail ring[%d] %d\n", seq_printf(s, "avail ring[%d] %d\n",
j, avail->ring[j]); j, avail->ring[j]);
used = vrh->vring.used; used = vrh->vring.used;
seq_printf(s, "used flags 0x%x idx %d\n", seq_printf(s, "used flags 0x%x idx %d\n",
used->flags, used->idx & (num - 1)); vringh16_to_cpu(vrh, used->flags),
vringh16_to_cpu(vrh, used->idx) & (num - 1));
seq_printf(s, "used flags 0x%x idx %d\n", seq_printf(s, "used flags 0x%x idx %d\n",
used->flags, used->idx); vringh16_to_cpu(vrh, used->flags),
vringh16_to_cpu(vrh, used->idx));
for (j = 0; j < num; j++) for (j = 0; j < num; j++)
seq_printf(s, "used ring[%d] id %d len %d\n", seq_printf(s, "used ring[%d] id %d len %d\n",
j, used->ring[j].id, j, vringh32_to_cpu(vrh,
used->ring[j].len); used->ring[j].id),
vringh32_to_cpu(vrh,
used->ring[j].len));
} }
} }
mutex_unlock(&mdev->mic_mutex); mutex_unlock(&mdev->mic_mutex);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/export.h> #include <linux/export.h>
#include <uapi/linux/virtio_config.h>
static __printf(1,2) __cold void vringh_bad(const char *fmt, ...) static __printf(1,2) __cold void vringh_bad(const char *fmt, ...)
{ {
...@@ -28,13 +29,14 @@ static __printf(1,2) __cold void vringh_bad(const char *fmt, ...) ...@@ -28,13 +29,14 @@ static __printf(1,2) __cold void vringh_bad(const char *fmt, ...)
/* Returns vring->num if empty, -ve on error. */ /* Returns vring->num if empty, -ve on error. */
static inline int __vringh_get_head(const struct vringh *vrh, static inline int __vringh_get_head(const struct vringh *vrh,
int (*getu16)(u16 *val, const u16 *p), int (*getu16)(const struct vringh *vrh,
u16 *val, const __virtio16 *p),
u16 *last_avail_idx) u16 *last_avail_idx)
{ {
u16 avail_idx, i, head; u16 avail_idx, i, head;
int err; int err;
err = getu16(&avail_idx, &vrh->vring.avail->idx); err = getu16(vrh, &avail_idx, &vrh->vring.avail->idx);
if (err) { if (err) {
vringh_bad("Failed to access avail idx at %p", vringh_bad("Failed to access avail idx at %p",
&vrh->vring.avail->idx); &vrh->vring.avail->idx);
...@@ -49,7 +51,7 @@ static inline int __vringh_get_head(const struct vringh *vrh, ...@@ -49,7 +51,7 @@ static inline int __vringh_get_head(const struct vringh *vrh,
i = *last_avail_idx & (vrh->vring.num - 1); i = *last_avail_idx & (vrh->vring.num - 1);
err = getu16(&head, &vrh->vring.avail->ring[i]); err = getu16(vrh, &head, &vrh->vring.avail->ring[i]);
if (err) { if (err) {
vringh_bad("Failed to read head: idx %d address %p", vringh_bad("Failed to read head: idx %d address %p",
*last_avail_idx, &vrh->vring.avail->ring[i]); *last_avail_idx, &vrh->vring.avail->ring[i]);
...@@ -144,28 +146,32 @@ static inline bool no_range_check(struct vringh *vrh, u64 addr, size_t *len, ...@@ -144,28 +146,32 @@ static inline bool no_range_check(struct vringh *vrh, u64 addr, size_t *len,
} }
/* No reason for this code to be inline. */ /* No reason for this code to be inline. */
static int move_to_indirect(int *up_next, u16 *i, void *addr, static int move_to_indirect(const struct vringh *vrh,
int *up_next, u16 *i, void *addr,
const struct vring_desc *desc, const struct vring_desc *desc,
struct vring_desc **descs, int *desc_max) struct vring_desc **descs, int *desc_max)
{ {
u32 len;
/* Indirect tables can't have indirect. */ /* Indirect tables can't have indirect. */
if (*up_next != -1) { if (*up_next != -1) {
vringh_bad("Multilevel indirect %u->%u", *up_next, *i); vringh_bad("Multilevel indirect %u->%u", *up_next, *i);
return -EINVAL; return -EINVAL;
} }
if (unlikely(desc->len % sizeof(struct vring_desc))) { len = vringh32_to_cpu(vrh, desc->len);
if (unlikely(len % sizeof(struct vring_desc))) {
vringh_bad("Strange indirect len %u", desc->len); vringh_bad("Strange indirect len %u", desc->len);
return -EINVAL; return -EINVAL;
} }
/* We will check this when we follow it! */ /* We will check this when we follow it! */
if (desc->flags & VRING_DESC_F_NEXT) if (desc->flags & cpu_to_vringh16(vrh, VRING_DESC_F_NEXT))
*up_next = desc->next; *up_next = vringh16_to_cpu(vrh, desc->next);
else else
*up_next = -2; *up_next = -2;
*descs = addr; *descs = addr;
*desc_max = desc->len / sizeof(struct vring_desc); *desc_max = len / sizeof(struct vring_desc);
/* Now, start at the first indirect. */ /* Now, start at the first indirect. */
*i = 0; *i = 0;
...@@ -287,22 +293,25 @@ __vringh_iov(struct vringh *vrh, u16 i, ...@@ -287,22 +293,25 @@ __vringh_iov(struct vringh *vrh, u16 i,
if (unlikely(err)) if (unlikely(err))
goto fail; goto fail;
if (unlikely(desc.flags & VRING_DESC_F_INDIRECT)) { if (unlikely(desc.flags &
cpu_to_vringh16(vrh, VRING_DESC_F_INDIRECT))) {
u64 a = vringh64_to_cpu(vrh, desc.addr);
/* Make sure it's OK, and get offset. */ /* Make sure it's OK, and get offset. */
len = desc.len; len = vringh32_to_cpu(vrh, desc.len);
if (!rcheck(vrh, desc.addr, &len, &range, getrange)) { if (!rcheck(vrh, a, &len, &range, getrange)) {
err = -EINVAL; err = -EINVAL;
goto fail; goto fail;
} }
if (unlikely(len != desc.len)) { if (unlikely(len != vringh32_to_cpu(vrh, desc.len))) {
slow = true; slow = true;
/* We need to save this range to use offset */ /* We need to save this range to use offset */
slowrange = range; slowrange = range;
} }
addr = (void *)(long)(desc.addr + range.offset); addr = (void *)(long)(a + range.offset);
err = move_to_indirect(&up_next, &i, addr, &desc, err = move_to_indirect(vrh, &up_next, &i, addr, &desc,
&descs, &desc_max); &descs, &desc_max);
if (err) if (err)
goto fail; goto fail;
...@@ -315,7 +324,7 @@ __vringh_iov(struct vringh *vrh, u16 i, ...@@ -315,7 +324,7 @@ __vringh_iov(struct vringh *vrh, u16 i,
goto fail; goto fail;
} }
if (desc.flags & VRING_DESC_F_WRITE) if (desc.flags & cpu_to_vringh16(vrh, VRING_DESC_F_WRITE))
iov = wiov; iov = wiov;
else { else {
iov = riov; iov = riov;
...@@ -336,12 +345,14 @@ __vringh_iov(struct vringh *vrh, u16 i, ...@@ -336,12 +345,14 @@ __vringh_iov(struct vringh *vrh, u16 i,
again: again:
/* Make sure it's OK, and get offset. */ /* Make sure it's OK, and get offset. */
len = desc.len; len = vringh32_to_cpu(vrh, desc.len);
if (!rcheck(vrh, desc.addr, &len, &range, getrange)) { if (!rcheck(vrh, vringh64_to_cpu(vrh, desc.addr), &len, &range,
getrange)) {
err = -EINVAL; err = -EINVAL;
goto fail; goto fail;
} }
addr = (void *)(unsigned long)(desc.addr + range.offset); addr = (void *)(unsigned long)(vringh64_to_cpu(vrh, desc.addr) +
range.offset);
if (unlikely(iov->used == (iov->max_num & ~VRINGH_IOV_ALLOCATED))) { if (unlikely(iov->used == (iov->max_num & ~VRINGH_IOV_ALLOCATED))) {
err = resize_iovec(iov, gfp); err = resize_iovec(iov, gfp);
...@@ -353,14 +364,16 @@ __vringh_iov(struct vringh *vrh, u16 i, ...@@ -353,14 +364,16 @@ __vringh_iov(struct vringh *vrh, u16 i,
iov->iov[iov->used].iov_len = len; iov->iov[iov->used].iov_len = len;
iov->used++; iov->used++;
if (unlikely(len != desc.len)) { if (unlikely(len != vringh32_to_cpu(vrh, desc.len))) {
desc.len -= len; desc.len = cpu_to_vringh32(vrh,
desc.addr += len; vringh32_to_cpu(vrh, desc.len) - len);
desc.addr = cpu_to_vringh64(vrh,
vringh64_to_cpu(vrh, desc.addr) + len);
goto again; goto again;
} }
if (desc.flags & VRING_DESC_F_NEXT) { if (desc.flags & cpu_to_vringh16(vrh, VRING_DESC_F_NEXT)) {
i = desc.next; i = vringh16_to_cpu(vrh, desc.next);
} else { } else {
/* Just in case we need to finish traversing above. */ /* Just in case we need to finish traversing above. */
if (unlikely(up_next > 0)) { if (unlikely(up_next > 0)) {
...@@ -387,7 +400,8 @@ __vringh_iov(struct vringh *vrh, u16 i, ...@@ -387,7 +400,8 @@ __vringh_iov(struct vringh *vrh, u16 i,
static inline int __vringh_complete(struct vringh *vrh, static inline int __vringh_complete(struct vringh *vrh,
const struct vring_used_elem *used, const struct vring_used_elem *used,
unsigned int num_used, unsigned int num_used,
int (*putu16)(u16 *p, u16 val), int (*putu16)(const struct vringh *vrh,
__virtio16 *p, u16 val),
int (*putused)(struct vring_used_elem *dst, int (*putused)(struct vring_used_elem *dst,
const struct vring_used_elem const struct vring_used_elem
*src, unsigned num)) *src, unsigned num))
...@@ -420,7 +434,7 @@ static inline int __vringh_complete(struct vringh *vrh, ...@@ -420,7 +434,7 @@ static inline int __vringh_complete(struct vringh *vrh,
/* Make sure buffer is written before we update index. */ /* Make sure buffer is written before we update index. */
virtio_wmb(vrh->weak_barriers); virtio_wmb(vrh->weak_barriers);
err = putu16(&vrh->vring.used->idx, used_idx + num_used); err = putu16(vrh, &vrh->vring.used->idx, used_idx + num_used);
if (err) { if (err) {
vringh_bad("Failed to update used index at %p", vringh_bad("Failed to update used index at %p",
&vrh->vring.used->idx); &vrh->vring.used->idx);
...@@ -433,7 +447,9 @@ static inline int __vringh_complete(struct vringh *vrh, ...@@ -433,7 +447,9 @@ static inline int __vringh_complete(struct vringh *vrh,
static inline int __vringh_need_notify(struct vringh *vrh, static inline int __vringh_need_notify(struct vringh *vrh,
int (*getu16)(u16 *val, const u16 *p)) int (*getu16)(const struct vringh *vrh,
u16 *val,
const __virtio16 *p))
{ {
bool notify; bool notify;
u16 used_event; u16 used_event;
...@@ -447,7 +463,7 @@ static inline int __vringh_need_notify(struct vringh *vrh, ...@@ -447,7 +463,7 @@ static inline int __vringh_need_notify(struct vringh *vrh,
/* Old-style, without event indices. */ /* Old-style, without event indices. */
if (!vrh->event_indices) { if (!vrh->event_indices) {
u16 flags; u16 flags;
err = getu16(&flags, &vrh->vring.avail->flags); err = getu16(vrh, &flags, &vrh->vring.avail->flags);
if (err) { if (err) {
vringh_bad("Failed to get flags at %p", vringh_bad("Failed to get flags at %p",
&vrh->vring.avail->flags); &vrh->vring.avail->flags);
...@@ -457,7 +473,7 @@ static inline int __vringh_need_notify(struct vringh *vrh, ...@@ -457,7 +473,7 @@ static inline int __vringh_need_notify(struct vringh *vrh,
} }
/* Modern: we know when other side wants to know. */ /* Modern: we know when other side wants to know. */
err = getu16(&used_event, &vring_used_event(&vrh->vring)); err = getu16(vrh, &used_event, &vring_used_event(&vrh->vring));
if (err) { if (err) {
vringh_bad("Failed to get used event idx at %p", vringh_bad("Failed to get used event idx at %p",
&vring_used_event(&vrh->vring)); &vring_used_event(&vrh->vring));
...@@ -478,20 +494,22 @@ static inline int __vringh_need_notify(struct vringh *vrh, ...@@ -478,20 +494,22 @@ static inline int __vringh_need_notify(struct vringh *vrh,
} }
static inline bool __vringh_notify_enable(struct vringh *vrh, static inline bool __vringh_notify_enable(struct vringh *vrh,
int (*getu16)(u16 *val, const u16 *p), int (*getu16)(const struct vringh *vrh,
int (*putu16)(u16 *p, u16 val)) u16 *val, const __virtio16 *p),
int (*putu16)(const struct vringh *vrh,
__virtio16 *p, u16 val))
{ {
u16 avail; u16 avail;
if (!vrh->event_indices) { if (!vrh->event_indices) {
/* Old-school; update flags. */ /* Old-school; update flags. */
if (putu16(&vrh->vring.used->flags, 0) != 0) { if (putu16(vrh, &vrh->vring.used->flags, 0) != 0) {
vringh_bad("Clearing used flags %p", vringh_bad("Clearing used flags %p",
&vrh->vring.used->flags); &vrh->vring.used->flags);
return true; return true;
} }
} else { } else {
if (putu16(&vring_avail_event(&vrh->vring), if (putu16(vrh, &vring_avail_event(&vrh->vring),
vrh->last_avail_idx) != 0) { vrh->last_avail_idx) != 0) {
vringh_bad("Updating avail event index %p", vringh_bad("Updating avail event index %p",
&vring_avail_event(&vrh->vring)); &vring_avail_event(&vrh->vring));
...@@ -503,7 +521,7 @@ static inline bool __vringh_notify_enable(struct vringh *vrh, ...@@ -503,7 +521,7 @@ static inline bool __vringh_notify_enable(struct vringh *vrh,
* sure it's written, then check again. */ * sure it's written, then check again. */
virtio_mb(vrh->weak_barriers); virtio_mb(vrh->weak_barriers);
if (getu16(&avail, &vrh->vring.avail->idx) != 0) { if (getu16(vrh, &avail, &vrh->vring.avail->idx) != 0) {
vringh_bad("Failed to check avail idx at %p", vringh_bad("Failed to check avail idx at %p",
&vrh->vring.avail->idx); &vrh->vring.avail->idx);
return true; return true;
...@@ -516,11 +534,13 @@ static inline bool __vringh_notify_enable(struct vringh *vrh, ...@@ -516,11 +534,13 @@ static inline bool __vringh_notify_enable(struct vringh *vrh,
} }
static inline void __vringh_notify_disable(struct vringh *vrh, static inline void __vringh_notify_disable(struct vringh *vrh,
int (*putu16)(u16 *p, u16 val)) int (*putu16)(const struct vringh *vrh,
__virtio16 *p, u16 val))
{ {
if (!vrh->event_indices) { if (!vrh->event_indices) {
/* Old-school; update flags. */ /* Old-school; update flags. */
if (putu16(&vrh->vring.used->flags, VRING_USED_F_NO_NOTIFY)) { if (putu16(vrh, &vrh->vring.used->flags,
VRING_USED_F_NO_NOTIFY)) {
vringh_bad("Setting used flags %p", vringh_bad("Setting used flags %p",
&vrh->vring.used->flags); &vrh->vring.used->flags);
} }
...@@ -528,14 +548,18 @@ static inline void __vringh_notify_disable(struct vringh *vrh, ...@@ -528,14 +548,18 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
} }
/* Userspace access helpers: in this case, addresses are really userspace. */ /* Userspace access helpers: in this case, addresses are really userspace. */
static inline int getu16_user(u16 *val, const u16 *p) static inline int getu16_user(const struct vringh *vrh, u16 *val, const __virtio16 *p)
{ {
return get_user(*val, (__force u16 __user *)p); __virtio16 v = 0;
int rc = get_user(v, (__force __virtio16 __user *)p);
*val = vringh16_to_cpu(vrh, v);
return rc;
} }
static inline int putu16_user(u16 *p, u16 val) static inline int putu16_user(const struct vringh *vrh, __virtio16 *p, u16 val)
{ {
return put_user(val, (__force u16 __user *)p); __virtio16 v = cpu_to_vringh16(vrh, val);
return put_user(v, (__force __virtio16 __user *)p);
} }
static inline int copydesc_user(void *dst, const void *src, size_t len) static inline int copydesc_user(void *dst, const void *src, size_t len)
...@@ -577,7 +601,7 @@ static inline int xfer_to_user(void *dst, void *src, size_t len) ...@@ -577,7 +601,7 @@ static inline int xfer_to_user(void *dst, void *src, size_t len)
* Returns an error if num is invalid: you should check pointers * Returns an error if num is invalid: you should check pointers
* yourself! * yourself!
*/ */
int vringh_init_user(struct vringh *vrh, u32 features, int vringh_init_user(struct vringh *vrh, u64 features,
unsigned int num, bool weak_barriers, unsigned int num, bool weak_barriers,
struct vring_desc __user *desc, struct vring_desc __user *desc,
struct vring_avail __user *avail, struct vring_avail __user *avail,
...@@ -589,6 +613,7 @@ int vringh_init_user(struct vringh *vrh, u32 features, ...@@ -589,6 +613,7 @@ int vringh_init_user(struct vringh *vrh, u32 features,
return -EINVAL; return -EINVAL;
} }
vrh->little_endian = (features & (1ULL << VIRTIO_F_VERSION_1));
vrh->event_indices = (features & (1 << VIRTIO_RING_F_EVENT_IDX)); vrh->event_indices = (features & (1 << VIRTIO_RING_F_EVENT_IDX));
vrh->weak_barriers = weak_barriers; vrh->weak_barriers = weak_barriers;
vrh->completed = 0; vrh->completed = 0;
...@@ -729,8 +754,8 @@ int vringh_complete_user(struct vringh *vrh, u16 head, u32 len) ...@@ -729,8 +754,8 @@ int vringh_complete_user(struct vringh *vrh, u16 head, u32 len)
{ {
struct vring_used_elem used; struct vring_used_elem used;
used.id = head; used.id = cpu_to_vringh32(vrh, head);
used.len = len; used.len = cpu_to_vringh32(vrh, len);
return __vringh_complete(vrh, &used, 1, putu16_user, putused_user); return __vringh_complete(vrh, &used, 1, putu16_user, putused_user);
} }
EXPORT_SYMBOL(vringh_complete_user); EXPORT_SYMBOL(vringh_complete_user);
...@@ -792,15 +817,16 @@ int vringh_need_notify_user(struct vringh *vrh) ...@@ -792,15 +817,16 @@ int vringh_need_notify_user(struct vringh *vrh)
EXPORT_SYMBOL(vringh_need_notify_user); EXPORT_SYMBOL(vringh_need_notify_user);
/* Kernelspace access helpers. */ /* Kernelspace access helpers. */
static inline int getu16_kern(u16 *val, const u16 *p) static inline int getu16_kern(const struct vringh *vrh,
u16 *val, const __virtio16 *p)
{ {
*val = ACCESS_ONCE(*p); *val = vringh16_to_cpu(vrh, ACCESS_ONCE(*p));
return 0; return 0;
} }
static inline int putu16_kern(u16 *p, u16 val) static inline int putu16_kern(const struct vringh *vrh, __virtio16 *p, u16 val)
{ {
ACCESS_ONCE(*p) = val; ACCESS_ONCE(*p) = cpu_to_vringh16(vrh, val);
return 0; return 0;
} }
...@@ -836,7 +862,7 @@ static inline int xfer_kern(void *src, void *dst, size_t len) ...@@ -836,7 +862,7 @@ static inline int xfer_kern(void *src, void *dst, size_t len)
* *
* Returns an error if num is invalid. * Returns an error if num is invalid.
*/ */
int vringh_init_kern(struct vringh *vrh, u32 features, int vringh_init_kern(struct vringh *vrh, u64 features,
unsigned int num, bool weak_barriers, unsigned int num, bool weak_barriers,
struct vring_desc *desc, struct vring_desc *desc,
struct vring_avail *avail, struct vring_avail *avail,
...@@ -848,6 +874,7 @@ int vringh_init_kern(struct vringh *vrh, u32 features, ...@@ -848,6 +874,7 @@ int vringh_init_kern(struct vringh *vrh, u32 features,
return -EINVAL; return -EINVAL;
} }
vrh->little_endian = (features & (1ULL << VIRTIO_F_VERSION_1));
vrh->event_indices = (features & (1 << VIRTIO_RING_F_EVENT_IDX)); vrh->event_indices = (features & (1 << VIRTIO_RING_F_EVENT_IDX));
vrh->weak_barriers = weak_barriers; vrh->weak_barriers = weak_barriers;
vrh->completed = 0; vrh->completed = 0;
...@@ -962,8 +989,8 @@ int vringh_complete_kern(struct vringh *vrh, u16 head, u32 len) ...@@ -962,8 +989,8 @@ int vringh_complete_kern(struct vringh *vrh, u16 head, u32 len)
{ {
struct vring_used_elem used; struct vring_used_elem used;
used.id = head; used.id = cpu_to_vringh32(vrh, head);
used.len = len; used.len = cpu_to_vringh32(vrh, len);
return __vringh_complete(vrh, &used, 1, putu16_kern, putused_kern); return __vringh_complete(vrh, &used, 1, putu16_kern, putused_kern);
} }
......
...@@ -162,6 +162,27 @@ static void virtio_config_enable(struct virtio_device *dev) ...@@ -162,6 +162,27 @@ static void virtio_config_enable(struct virtio_device *dev)
spin_unlock_irq(&dev->config_lock); spin_unlock_irq(&dev->config_lock);
} }
static int virtio_finalize_features(struct virtio_device *dev)
{
int ret = dev->config->finalize_features(dev);
unsigned status;
if (ret)
return ret;
if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1))
return 0;
add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
status = dev->config->get_status(dev);
if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {
dev_err(&dev->dev, "virtio: device refuses features: %x\n",
status);
return -ENODEV;
}
return 0;
}
static int virtio_dev_probe(struct device *_d) static int virtio_dev_probe(struct device *_d)
{ {
int err, i; int err, i;
...@@ -170,7 +191,6 @@ static int virtio_dev_probe(struct device *_d) ...@@ -170,7 +191,6 @@ static int virtio_dev_probe(struct device *_d)
u64 device_features; u64 device_features;
u64 driver_features; u64 driver_features;
u64 driver_features_legacy; u64 driver_features_legacy;
unsigned status;
/* We have a driver! */ /* We have a driver! */
add_status(dev, VIRTIO_CONFIG_S_DRIVER); add_status(dev, VIRTIO_CONFIG_S_DRIVER);
...@@ -208,21 +228,10 @@ static int virtio_dev_probe(struct device *_d) ...@@ -208,21 +228,10 @@ static int virtio_dev_probe(struct device *_d)
if (device_features & (1ULL << i)) if (device_features & (1ULL << i))
__virtio_set_bit(dev, i); __virtio_set_bit(dev, i);
err = dev->config->finalize_features(dev); err = virtio_finalize_features(dev);
if (err) if (err)
goto err; goto err;
if (virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
status = dev->config->get_status(dev);
if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {
dev_err(_d, "virtio: device refuses features: %x\n",
status);
err = -ENODEV;
goto err;
}
}
err = drv->probe(dev); err = drv->probe(dev);
if (err) if (err)
goto err; goto err;
...@@ -372,7 +381,7 @@ int virtio_device_restore(struct virtio_device *dev) ...@@ -372,7 +381,7 @@ int virtio_device_restore(struct virtio_device *dev)
/* We have a driver! */ /* We have a driver! */
add_status(dev, VIRTIO_CONFIG_S_DRIVER); add_status(dev, VIRTIO_CONFIG_S_DRIVER);
ret = dev->config->finalize_features(dev); ret = virtio_finalize_features(dev);
if (ret) if (ret)
goto err; goto err;
......
...@@ -458,7 +458,44 @@ static int virtio_pci_restore(struct device *dev) ...@@ -458,7 +458,44 @@ static int virtio_pci_restore(struct device *dev)
return virtio_device_restore(&vp_dev->vdev); return virtio_device_restore(&vp_dev->vdev);
} }
const struct dev_pm_ops virtio_pci_pm_ops = { static const struct dev_pm_ops virtio_pci_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(virtio_pci_freeze, virtio_pci_restore) SET_SYSTEM_SLEEP_PM_OPS(virtio_pci_freeze, virtio_pci_restore)
}; };
#endif #endif
/* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */
static const struct pci_device_id virtio_pci_id_table[] = {
{ PCI_DEVICE(0x1af4, PCI_ANY_ID) },
{ 0 }
};
MODULE_DEVICE_TABLE(pci, virtio_pci_id_table);
static int virtio_pci_probe(struct pci_dev *pci_dev,
const struct pci_device_id *id)
{
return virtio_pci_legacy_probe(pci_dev, id);
}
static void virtio_pci_remove(struct pci_dev *pci_dev)
{
virtio_pci_legacy_remove(pci_dev);
}
static struct pci_driver virtio_pci_driver = {
.name = "virtio-pci",
.id_table = virtio_pci_id_table,
.probe = virtio_pci_probe,
.remove = virtio_pci_remove,
#ifdef CONFIG_PM_SLEEP
.driver.pm = &virtio_pci_pm_ops,
#endif
};
module_pci_driver(virtio_pci_driver);
MODULE_AUTHOR("Anthony Liguori <aliguori@us.ibm.com>");
MODULE_DESCRIPTION("virtio-pci");
MODULE_LICENSE("GPL");
MODULE_VERSION("1");
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include <linux/virtio.h> #include <linux/virtio.h>
#include <linux/virtio_config.h> #include <linux/virtio_config.h>
#include <linux/virtio_ring.h> #include <linux/virtio_ring.h>
#define VIRTIO_PCI_NO_LEGACY
#include <linux/virtio_pci.h> #include <linux/virtio_pci.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
...@@ -129,8 +128,8 @@ const char *vp_bus_name(struct virtio_device *vdev); ...@@ -129,8 +128,8 @@ const char *vp_bus_name(struct virtio_device *vdev);
int vp_set_vq_affinity(struct virtqueue *vq, int cpu); int vp_set_vq_affinity(struct virtqueue *vq, int cpu);
void virtio_pci_release_dev(struct device *); void virtio_pci_release_dev(struct device *);
#ifdef CONFIG_PM_SLEEP int virtio_pci_legacy_probe(struct pci_dev *pci_dev,
extern const struct dev_pm_ops virtio_pci_pm_ops; const struct pci_device_id *id);
#endif void virtio_pci_legacy_remove(struct pci_dev *pci_dev);
#endif #endif
...@@ -19,14 +19,6 @@ ...@@ -19,14 +19,6 @@
#include "virtio_pci_common.h" #include "virtio_pci_common.h"
/* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */
static const struct pci_device_id virtio_pci_id_table[] = {
{ PCI_DEVICE(0x1af4, PCI_ANY_ID) },
{ 0 }
};
MODULE_DEVICE_TABLE(pci, virtio_pci_id_table);
/* virtio config->get_features() implementation */ /* virtio config->get_features() implementation */
static u64 vp_get_features(struct virtio_device *vdev) static u64 vp_get_features(struct virtio_device *vdev)
{ {
...@@ -220,7 +212,7 @@ static const struct virtio_config_ops virtio_pci_config_ops = { ...@@ -220,7 +212,7 @@ static const struct virtio_config_ops virtio_pci_config_ops = {
}; };
/* the PCI probing function */ /* the PCI probing function */
static int virtio_pci_probe(struct pci_dev *pci_dev, int virtio_pci_legacy_probe(struct pci_dev *pci_dev,
const struct pci_device_id *id) const struct pci_device_id *id)
{ {
struct virtio_pci_device *vp_dev; struct virtio_pci_device *vp_dev;
...@@ -300,7 +292,7 @@ static int virtio_pci_probe(struct pci_dev *pci_dev, ...@@ -300,7 +292,7 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
return err; return err;
} }
static void virtio_pci_remove(struct pci_dev *pci_dev) void virtio_pci_legacy_remove(struct pci_dev *pci_dev)
{ {
struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
...@@ -312,15 +304,3 @@ static void virtio_pci_remove(struct pci_dev *pci_dev) ...@@ -312,15 +304,3 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
pci_disable_device(pci_dev); pci_disable_device(pci_dev);
kfree(vp_dev); kfree(vp_dev);
} }
static struct pci_driver virtio_pci_driver = {
.name = "virtio-pci",
.id_table = virtio_pci_id_table,
.probe = virtio_pci_probe,
.remove = virtio_pci_remove,
#ifdef CONFIG_PM_SLEEP
.driver.pm = &virtio_pci_pm_ops,
#endif
};
module_pci_driver(virtio_pci_driver);
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
* offset: the offset of the configuration field * offset: the offset of the configuration field
* buf: the buffer to read the field value from. * buf: the buffer to read the field value from.
* len: the length of the buffer * len: the length of the buffer
* @generation: config generation counter
* vdev: the virtio_device
* Returns the config generation counter
* @get_status: read the status byte * @get_status: read the status byte
* vdev: the virtio_device * vdev: the virtio_device
* Returns the status byte * Returns the status byte
...@@ -60,6 +63,7 @@ struct virtio_config_ops { ...@@ -60,6 +63,7 @@ struct virtio_config_ops {
void *buf, unsigned len); void *buf, unsigned len);
void (*set)(struct virtio_device *vdev, unsigned offset, void (*set)(struct virtio_device *vdev, unsigned offset,
const void *buf, unsigned len); const void *buf, unsigned len);
u32 (*generation)(struct virtio_device *vdev);
u8 (*get_status)(struct virtio_device *vdev); u8 (*get_status)(struct virtio_device *vdev);
void (*set_status)(struct virtio_device *vdev, u8 status); void (*set_status)(struct virtio_device *vdev, u8 status);
void (*reset)(struct virtio_device *vdev); void (*reset)(struct virtio_device *vdev);
...@@ -301,11 +305,33 @@ static inline u8 virtio_cread8(struct virtio_device *vdev, unsigned int offset) ...@@ -301,11 +305,33 @@ static inline u8 virtio_cread8(struct virtio_device *vdev, unsigned int offset)
return ret; return ret;
} }
/* Read @count fields, @bytes each. */
static inline void __virtio_cread_many(struct virtio_device *vdev,
unsigned int offset,
void *buf, size_t count, size_t bytes)
{
u32 old, gen = vdev->config->generation ?
vdev->config->generation(vdev) : 0;
int i;
do {
old = gen;
for (i = 0; i < count; i++)
vdev->config->get(vdev, offset + bytes * i,
buf + i * bytes, bytes);
gen = vdev->config->generation ?
vdev->config->generation(vdev) : 0;
} while (gen != old);
}
static inline void virtio_cread_bytes(struct virtio_device *vdev, static inline void virtio_cread_bytes(struct virtio_device *vdev,
unsigned int offset, unsigned int offset,
void *buf, size_t len) void *buf, size_t len)
{ {
vdev->config->get(vdev, offset, buf, len); __virtio_cread_many(vdev, offset, buf, len, 1);
} }
static inline void virtio_cwrite8(struct virtio_device *vdev, static inline void virtio_cwrite8(struct virtio_device *vdev,
...@@ -349,6 +375,7 @@ static inline u64 virtio_cread64(struct virtio_device *vdev, ...@@ -349,6 +375,7 @@ static inline u64 virtio_cread64(struct virtio_device *vdev,
{ {
u64 ret; u64 ret;
vdev->config->get(vdev, offset, &ret, sizeof(ret)); vdev->config->get(vdev, offset, &ret, sizeof(ret));
__virtio_cread_many(vdev, offset, &ret, 1, sizeof(ret));
return virtio64_to_cpu(vdev, (__force __virtio64)ret); return virtio64_to_cpu(vdev, (__force __virtio64)ret);
} }
......
...@@ -24,12 +24,16 @@ ...@@ -24,12 +24,16 @@
#ifndef _LINUX_VRINGH_H #ifndef _LINUX_VRINGH_H
#define _LINUX_VRINGH_H #define _LINUX_VRINGH_H
#include <uapi/linux/virtio_ring.h> #include <uapi/linux/virtio_ring.h>
#include <linux/virtio_byteorder.h>
#include <linux/uio.h> #include <linux/uio.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <asm/barrier.h> #include <asm/barrier.h>
/* virtio_ring with information needed for host access. */ /* virtio_ring with information needed for host access. */
struct vringh { struct vringh {
/* Everything is little endian */
bool little_endian;
/* Guest publishes used event idx (note: we always do). */ /* Guest publishes used event idx (note: we always do). */
bool event_indices; bool event_indices;
...@@ -105,7 +109,7 @@ struct vringh_kiov { ...@@ -105,7 +109,7 @@ struct vringh_kiov {
#define VRINGH_IOV_ALLOCATED 0x8000000 #define VRINGH_IOV_ALLOCATED 0x8000000
/* Helpers for userspace vrings. */ /* Helpers for userspace vrings. */
int vringh_init_user(struct vringh *vrh, u32 features, int vringh_init_user(struct vringh *vrh, u64 features,
unsigned int num, bool weak_barriers, unsigned int num, bool weak_barriers,
struct vring_desc __user *desc, struct vring_desc __user *desc,
struct vring_avail __user *avail, struct vring_avail __user *avail,
...@@ -167,7 +171,7 @@ bool vringh_notify_enable_user(struct vringh *vrh); ...@@ -167,7 +171,7 @@ bool vringh_notify_enable_user(struct vringh *vrh);
void vringh_notify_disable_user(struct vringh *vrh); void vringh_notify_disable_user(struct vringh *vrh);
/* Helpers for kernelspace vrings. */ /* Helpers for kernelspace vrings. */
int vringh_init_kern(struct vringh *vrh, u32 features, int vringh_init_kern(struct vringh *vrh, u64 features,
unsigned int num, bool weak_barriers, unsigned int num, bool weak_barriers,
struct vring_desc *desc, struct vring_desc *desc,
struct vring_avail *avail, struct vring_avail *avail,
...@@ -222,4 +226,33 @@ static inline void vringh_notify(struct vringh *vrh) ...@@ -222,4 +226,33 @@ static inline void vringh_notify(struct vringh *vrh)
vrh->notify(vrh); vrh->notify(vrh);
} }
static inline u16 vringh16_to_cpu(const struct vringh *vrh, __virtio16 val)
{
return __virtio16_to_cpu(vrh->little_endian, val);
}
static inline __virtio16 cpu_to_vringh16(const struct vringh *vrh, u16 val)
{
return __cpu_to_virtio16(vrh->little_endian, val);
}
static inline u32 vringh32_to_cpu(const struct vringh *vrh, __virtio32 val)
{
return __virtio32_to_cpu(vrh->little_endian, val);
}
static inline __virtio32 cpu_to_vringh32(const struct vringh *vrh, u32 val)
{
return __cpu_to_virtio32(vrh->little_endian, val);
}
static inline u64 vringh64_to_cpu(const struct vringh *vrh, __virtio64 val)
{
return __virtio64_to_cpu(vrh->little_endian, val);
}
static inline __virtio64 cpu_to_vringh64(const struct vringh *vrh, u64 val)
{
return __cpu_to_virtio64(vrh->little_endian, val);
}
#endif /* _LINUX_VRINGH_H */ #endif /* _LINUX_VRINGH_H */
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#include <linux/virtio_config.h> #include <linux/virtio_config.h>
#ifndef VIRTIO_PCI_NO_LEGACY
/* A 32-bit r/o bitmask of the features supported by the host */ /* A 32-bit r/o bitmask of the features supported by the host */
#define VIRTIO_PCI_HOST_FEATURES 0 #define VIRTIO_PCI_HOST_FEATURES 0
...@@ -67,16 +69,11 @@ ...@@ -67,16 +69,11 @@
* a read-and-acknowledge. */ * a read-and-acknowledge. */
#define VIRTIO_PCI_ISR 19 #define VIRTIO_PCI_ISR 19
/* The bit of the ISR which indicates a device configuration change. */
#define VIRTIO_PCI_ISR_CONFIG 0x2
/* MSI-X registers: only enabled if MSI-X is enabled. */ /* MSI-X registers: only enabled if MSI-X is enabled. */
/* A 16-bit vector for configuration changes. */ /* A 16-bit vector for configuration changes. */
#define VIRTIO_MSI_CONFIG_VECTOR 20 #define VIRTIO_MSI_CONFIG_VECTOR 20
/* A 16-bit vector for selected queue notifications. */ /* A 16-bit vector for selected queue notifications. */
#define VIRTIO_MSI_QUEUE_VECTOR 22 #define VIRTIO_MSI_QUEUE_VECTOR 22
/* Vector value used to disable MSI for queue */
#define VIRTIO_MSI_NO_VECTOR 0xffff
/* The remaining space is defined by each driver as the per-driver /* The remaining space is defined by each driver as the per-driver
* configuration space */ * configuration space */
...@@ -94,4 +91,12 @@ ...@@ -94,4 +91,12 @@
/* The alignment to use between consumer and producer parts of vring. /* The alignment to use between consumer and producer parts of vring.
* x86 pagesize again. */ * x86 pagesize again. */
#define VIRTIO_PCI_VRING_ALIGN 4096 #define VIRTIO_PCI_VRING_ALIGN 4096
#endif /* VIRTIO_PCI_NO_LEGACY */
/* The bit of the ISR which indicates a device configuration change. */
#define VIRTIO_PCI_ISR_CONFIG 0x2
/* Vector value used to disable MSI for queue */
#define VIRTIO_MSI_NO_VECTOR 0xffff
#endif #endif
...@@ -3,7 +3,7 @@ test: virtio_test vringh_test ...@@ -3,7 +3,7 @@ test: virtio_test vringh_test
virtio_test: virtio_ring.o virtio_test.o virtio_test: virtio_ring.o virtio_test.o
vringh_test: vringh_test.o vringh.o virtio_ring.o vringh_test: vringh_test.o vringh.o virtio_ring.o
CFLAGS += -g -O2 -Wall -I. -I../include/ -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE CFLAGS += -g -O2 -Werror -Wall -I. -I../include/ -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE
vpath %.c ../../drivers/virtio ../../drivers/vhost vpath %.c ../../drivers/virtio ../../drivers/vhost
mod: mod:
${MAKE} -C `pwd`/../.. M=`pwd`/vhost_test ${MAKE} -C `pwd`/../.. M=`pwd`/vhost_test
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
/* TODO: empty stubs for now. Broken but enough for virtio_ring.c */ /* TODO: empty stubs for now. Broken but enough for virtio_ring.c */
#define list_add_tail(a, b) do {} while (0) #define list_add_tail(a, b) do {} while (0)
#define list_del(a) do {} while (0) #define list_del(a) do {} while (0)
#define list_for_each_entry(a, b, c) while (0)
/* end of stubs */ /* end of stubs */
struct virtio_device { struct virtio_device {
......
#ifndef _LINUX_VIRTIO_BYTEORDER_STUB_H
#define _LINUX_VIRTIO_BYTEORDER_STUB_H
#include <asm/byteorder.h>
#include "../../include/linux/byteorder/generic.h"
#include "../../include/linux/virtio_byteorder.h"
#endif
#define VIRTIO_TRANSPORT_F_START 28 #include <linux/virtio_byteorder.h>
#define VIRTIO_TRANSPORT_F_END 32 #include <linux/virtio.h>
#include <uapi/linux/virtio_config.h>
/*
* __virtio_test_bit - helper to test feature bits. For use by transports.
* Devices should normally use virtio_has_feature,
* which includes more checks.
* @vdev: the device
* @fbit: the feature bit
*/
static inline bool __virtio_test_bit(const struct virtio_device *vdev,
unsigned int fbit)
{
return vdev->features & (1ULL << fbit);
}
/**
* __virtio_set_bit - helper to set feature bits. For use by transports.
* @vdev: the device
* @fbit: the feature bit
*/
static inline void __virtio_set_bit(struct virtio_device *vdev,
unsigned int fbit)
{
vdev->features |= (1ULL << fbit);
}
/**
* __virtio_clear_bit - helper to clear feature bits. For use by transports.
* @vdev: the device
* @fbit: the feature bit
*/
static inline void __virtio_clear_bit(struct virtio_device *vdev,
unsigned int fbit)
{
vdev->features &= ~(1ULL << fbit);
}
#define virtio_has_feature(dev, feature) \ #define virtio_has_feature(dev, feature) \
(__virtio_test_bit((dev), feature)) (__virtio_test_bit((dev), feature))
static inline u16 virtio16_to_cpu(struct virtio_device *vdev, __virtio16 val)
{
return __virtio16_to_cpu(virtio_has_feature(vdev, VIRTIO_F_VERSION_1), val);
}
static inline __virtio16 cpu_to_virtio16(struct virtio_device *vdev, u16 val)
{
return __cpu_to_virtio16(virtio_has_feature(vdev, VIRTIO_F_VERSION_1), val);
}
static inline u32 virtio32_to_cpu(struct virtio_device *vdev, __virtio32 val)
{
return __virtio32_to_cpu(virtio_has_feature(vdev, VIRTIO_F_VERSION_1), val);
}
static inline __virtio32 cpu_to_virtio32(struct virtio_device *vdev, u32 val)
{
return __cpu_to_virtio32(virtio_has_feature(vdev, VIRTIO_F_VERSION_1), val);
}
static inline u64 virtio64_to_cpu(struct virtio_device *vdev, __virtio64 val)
{
return __virtio64_to_cpu(virtio_has_feature(vdev, VIRTIO_F_VERSION_1), val);
}
static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
{
return __cpu_to_virtio64(virtio_has_feature(vdev, VIRTIO_F_VERSION_1), val);
}
#include "../../include/uapi/linux/virtio_types.h"
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdbool.h> #include <stdbool.h>
#include <linux/virtio_types.h>
#include <linux/vhost.h> #include <linux/vhost.h>
#include <linux/virtio.h> #include <linux/virtio.h>
#include <linux/virtio_ring.h> #include <linux/virtio_ring.h>
...@@ -226,6 +227,14 @@ const struct option longopts[] = { ...@@ -226,6 +227,14 @@ const struct option longopts[] = {
.name = "no-indirect", .name = "no-indirect",
.val = 'i', .val = 'i',
}, },
{
.name = "virtio-1",
.val = '1',
},
{
.name = "no-virtio-1",
.val = '0',
},
{ {
.name = "delayed-interrupt", .name = "delayed-interrupt",
.val = 'D', .val = 'D',
...@@ -243,6 +252,7 @@ static void help(void) ...@@ -243,6 +252,7 @@ static void help(void)
fprintf(stderr, "Usage: virtio_test [--help]" fprintf(stderr, "Usage: virtio_test [--help]"
" [--no-indirect]" " [--no-indirect]"
" [--no-event-idx]" " [--no-event-idx]"
" [--no-virtio-1]"
" [--delayed-interrupt]" " [--delayed-interrupt]"
"\n"); "\n");
} }
...@@ -251,7 +261,7 @@ int main(int argc, char **argv) ...@@ -251,7 +261,7 @@ int main(int argc, char **argv)
{ {
struct vdev_info dev; struct vdev_info dev;
unsigned long long features = (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | unsigned long long features = (1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
(1ULL << VIRTIO_RING_F_EVENT_IDX); (1ULL << VIRTIO_RING_F_EVENT_IDX) | (1ULL << VIRTIO_F_VERSION_1);
int o; int o;
bool delayed = false; bool delayed = false;
...@@ -272,6 +282,9 @@ int main(int argc, char **argv) ...@@ -272,6 +282,9 @@ int main(int argc, char **argv)
case 'i': case 'i':
features &= ~(1ULL << VIRTIO_RING_F_INDIRECT_DESC); features &= ~(1ULL << VIRTIO_RING_F_INDIRECT_DESC);
break; break;
case '0':
features &= ~(1ULL << VIRTIO_F_VERSION_1);
break;
case 'D': case 'D':
delayed = true; delayed = true;
break; break;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <linux/virtio.h> #include <linux/virtio.h>
#include <linux/vringh.h> #include <linux/vringh.h>
#include <linux/virtio_ring.h> #include <linux/virtio_ring.h>
#include <linux/virtio_config.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -131,7 +132,7 @@ static inline int vringh_get_head(struct vringh *vrh, u16 *head) ...@@ -131,7 +132,7 @@ static inline int vringh_get_head(struct vringh *vrh, u16 *head)
return 1; return 1;
} }
static int parallel_test(unsigned long features, static int parallel_test(u64 features,
bool (*getrange)(struct vringh *vrh, bool (*getrange)(struct vringh *vrh,
u64 addr, struct vringh_range *r), u64 addr, struct vringh_range *r),
bool fast_vringh) bool fast_vringh)
...@@ -456,6 +457,8 @@ int main(int argc, char *argv[]) ...@@ -456,6 +457,8 @@ int main(int argc, char *argv[])
__virtio_set_bit(&vdev, VIRTIO_RING_F_INDIRECT_DESC); __virtio_set_bit(&vdev, VIRTIO_RING_F_INDIRECT_DESC);
else if (strcmp(argv[1], "--eventidx") == 0) else if (strcmp(argv[1], "--eventidx") == 0)
__virtio_set_bit(&vdev, VIRTIO_RING_F_EVENT_IDX); __virtio_set_bit(&vdev, VIRTIO_RING_F_EVENT_IDX);
else if (strcmp(argv[1], "--virtio-1") == 0)
__virtio_set_bit(&vdev, VIRTIO_F_VERSION_1);
else if (strcmp(argv[1], "--slow-range") == 0) else if (strcmp(argv[1], "--slow-range") == 0)
getrange = getrange_slow; getrange = getrange_slow;
else if (strcmp(argv[1], "--fast-vringh") == 0) else if (strcmp(argv[1], "--fast-vringh") == 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册