On 2011年08月29日 10:53, Rusty Russell wrote: > On Sat, 27 Aug 2011 17:52:02 +0800, Wang Sheng-Hui <shhuiw@xxxxxxxxx> wrote: >> On 2011年08月27日 17:34, Wang Sheng-Hui wrote: >> diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h >> index 4a32cb6..300af76 100644 >> --- a/include/linux/virtio_ring.h >> +++ b/include/linux/virtio_ring.h >> @@ -135,13 +135,13 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p, >> vr->num = num; >> vr->desc = p; >> vr->avail = p + num*sizeof(struct vring_desc); >> - vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + align-1) >> - & ~(align - 1)); >> + vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + 16 >> + + align-1) & ~(align - 1)); >> } > > This + 16 should be + sizeof(__u16), right? It's just the > used_event_idx which has been added: > > * __u16 available[num]; > * __u16 used_event_idx; > * > * // Padding to the next align boundary. > * char pad[]; > * > * [USED] > >> static inline unsigned vring_size(unsigned int num, unsigned long align) >> { >> - return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (2 + num) >> + return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (3 + num) >> + align - 1) & ~(align - 1)) >> + sizeof(__u16) * 3 + sizeof(struct vring_used_elem) * num; > > This is correct. > > And, yes, since align is always 4096, it's currently just a cleanup, but > it makes things much less confusing! > > Thanks, > Rusty. Patch regerated to use sizeof(__u16) instead of 16 in vring_init. Please check it. [PATCH] virtio: modify vring_init and vring_size to take account of the layout containing *_event_idx The patch is against 3.1-rc3. Based on the layout description in the comments, take account of the *_event_idx in functions vring_init and vring_size. Signed-off-by: Wang Sheng-Hui <shhuiw@xxxxxxxxx> --- include/linux/virtio_ring.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h index 4a32cb6..2a731bd 100644 --- a/include/linux/virtio_ring.h +++ b/include/linux/virtio_ring.h @@ -135,13 +135,13 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p, vr->num = num; vr->desc = p; vr->avail = p + num*sizeof(struct vring_desc); - vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + align-1) - & ~(align - 1)); + vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__16) + + align-1) & ~(align - 1)); } static inline unsigned vring_size(unsigned int num, unsigned long align) { - return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (2 + num) + return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (3 + num) + align - 1) & ~(align - 1)) + sizeof(__u16) * 3 + sizeof(struct vring_used_elem) * num; } -- 1.7.1 _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linux-foundation.org/mailman/listinfo/virtualization