Skip to content

Commit

Permalink
virtio_ring: document alignment requirements
Browse files Browse the repository at this point in the history
Host needs to know vring element alignment requirements:
simply doing alignof on structures doesn't work reliably: on some
platforms gcc has alignof(uint32_t) == 2.

Add macros for alignment as specified in virtio 1.0 cs01,
export them to userspace as well.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
Michael S. Tsirkin committed Dec 29, 2014
1 parent b7392d2 commit b28e050
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/uapi/linux/virtio_ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ struct vring {
struct vring_used *used;
};

/* Alignment requirements for vring elements.
* When using pre-virtio 1.0 layout, these fall out naturally.
*/
#define VRING_AVAIL_ALIGN_SIZE 2
#define VRING_USED_ALIGN_SIZE 4
#define VRING_DESC_ALIGN_SIZE 16

/* The standard layout for the ring is a continuous chunk of memory which looks
* like this. We assume num is a power of 2.
*
Expand Down

0 comments on commit b28e050

Please sign in to comment.