diff options
author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-11-12 11:13:31 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-11-12 11:13:31 -0800 |
commit | 05f3f415894d061f7d3e77e3d46caeb4c184b005 (patch) | |
tree | d49254d7ae4759ab85a2944843f73adaa6865e0a /include/linux | |
parent | e697b8d13ede3893724898d983eff3f8c9183643 (diff) | |
parent | 42b36cc0ce717deeb10030141a43dede763a3ebe (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-virtio
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-virtio:
virtio: Force use of power-of-two for descriptor ring sizes
lguest: Fix lguest virtio-blk backend size computation
virtio: Fix used_idx wrap-around
virtio: more fallout from scatterlist changes.
virtio: fix vring_init for 64 bits
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/virtio_ring.h | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h index ac69e7bb5a1..1a4ed49f647 100644 --- a/include/linux/virtio_ring.h +++ b/include/linux/virtio_ring.h @@ -67,7 +67,7 @@ struct vring { }; /* The standard layout for the ring is a continuous chunk of memory which looks - * like this. The used fields will be aligned to a "num+1" boundary. + * like this. We assume num is a power of 2. * * struct vring * { @@ -79,8 +79,8 @@ struct vring { * __u16 avail_idx; * __u16 available[num]; * - * // Padding so a correctly-chosen num value will cache-align used_idx. - * char pad[sizeof(struct vring_desc) - sizeof(avail_flags)]; + * // Padding to the next page boundary. + * char pad[]; * * // A ring of used descriptor heads with free-running index. * __u16 used_flags; @@ -88,18 +88,21 @@ struct vring { * struct vring_used_elem used[num]; * }; */ -static inline void vring_init(struct vring *vr, unsigned int num, void *p) +static inline void vring_init(struct vring *vr, unsigned int num, void *p, + unsigned int pagesize) { vr->num = num; vr->desc = p; - vr->avail = p + num*sizeof(struct vring); - vr->used = p + (num+1)*(sizeof(struct vring) + sizeof(__u16)); + vr->avail = p + num*sizeof(struct vring_desc); + vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + pagesize-1) + & ~(pagesize - 1)); } -static inline unsigned vring_size(unsigned int num) +static inline unsigned vring_size(unsigned int num, unsigned int pagesize) { - return (num + 1) * (sizeof(struct vring_desc) + sizeof(__u16)) - + sizeof(__u32) + num * sizeof(struct vring_used_elem); + return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (2 + num) + + pagesize - 1) & ~(pagesize - 1)) + + sizeof(__u16) * 2 + sizeof(struct vring_used_elem) * num; } #ifdef __KERNEL__ |