Thomas Huth
2015-Jul-02 07:21 UTC
[PATCH RESEND] virtio: Fix typecast of pointer in vring_init()
The virtio_ring.h header is used in userspace programs (ie. QEMU), too. Here we can not assume that sizeof(pointer) is the same as sizeof(long), e.g. when compiling for Windows, so the typecast in vring_init() should be done with (uintptr_t) instead of (unsigned long). Signed-off-by: Thomas Huth <thuth at redhat.com> --- include/uapi/linux/virtio_ring.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/linux/virtio_ring.h b/include/uapi/linux/virtio_ring.h index 915980a..8682551 100644 --- a/include/uapi/linux/virtio_ring.h +++ b/include/uapi/linux/virtio_ring.h @@ -143,7 +143,7 @@ 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] + sizeof(__virtio16) + vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(__virtio16) + align-1) & ~(align - 1)); } -- 1.8.3.1
Michael S. Tsirkin
2015-Jul-05 10:58 UTC
[PATCH RESEND] virtio: Fix typecast of pointer in vring_init()
On Thu, Jul 02, 2015 at 09:21:22AM +0200, Thomas Huth wrote:> The virtio_ring.h header is used in userspace programs (ie. QEMU), > too. Here we can not assume that sizeof(pointer) is the same as > sizeof(long), e.g. when compiling for Windows, so the typecast in > vring_init() should be done with (uintptr_t) instead of (unsigned long). > > Signed-off-by: Thomas Huth <thuth at redhat.com>This seems to break some userspace too: INSTALL usr/include/linux/ (413 files) CHECK usr/include/linux/ (413 files) HOSTCC Documentation/accounting/getdelays HOSTCC Documentation/connector/ucon HOSTCC Documentation/mic/mpssd/mpssd.o In file included from Documentation/mic/mpssd/mpssd.c:36:0: ./usr/include/linux/virtio_ring.h: In function ?vring_init?: ./usr/include/linux/virtio_ring.h:146:24: error: ?uintptr_t? undeclared (first use in this function) vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(__virtio16) ^ ./usr/include/linux/virtio_ring.h:146:24: note: each undeclared identifier is reported only once for each function it appears in scripts/Makefile.host:108: recipe for target 'Documentation/mic/mpssd/mpssd.o' failed make[3]: *** [Documentation/mic/mpssd/mpssd.o] Error 1 scripts/Makefile.build:403: recipe for target 'Documentation/mic/mpssd' failed make[2]: *** [Documentation/mic/mpssd] Error 2 scripts/Makefile.build:403: recipe for target 'Documentation/mic' failed make[1]: *** [Documentation/mic] Error 2 E.g. fuse.h has this code: #ifdef __KERNEL__ #include <linux/types.h> #else #include <stdint.h> #endif Maybe we need something similar.> --- > include/uapi/linux/virtio_ring.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/uapi/linux/virtio_ring.h b/include/uapi/linux/virtio_ring.h > index 915980a..8682551 100644 > --- a/include/uapi/linux/virtio_ring.h > +++ b/include/uapi/linux/virtio_ring.h > @@ -143,7 +143,7 @@ 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] + sizeof(__virtio16) > + vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(__virtio16) > + align-1) & ~(align - 1)); > } > > -- > 1.8.3.1
Michael S. Tsirkin
2015-Jul-05 12:59 UTC
[PATCH RESEND] virtio: Fix typecast of pointer in vring_init()
On Sun, Jul 05, 2015 at 12:58:53PM +0200, Michael S. Tsirkin wrote:> On Thu, Jul 02, 2015 at 09:21:22AM +0200, Thomas Huth wrote: > > The virtio_ring.h header is used in userspace programs (ie. QEMU), > > too. Here we can not assume that sizeof(pointer) is the same as > > sizeof(long), e.g. when compiling for Windows, so the typecast in > > vring_init() should be done with (uintptr_t) instead of (unsigned long). > > > > Signed-off-by: Thomas Huth <thuth at redhat.com> > > This seems to break some userspace too: > > INSTALL usr/include/linux/ (413 files) > CHECK usr/include/linux/ (413 files) > HOSTCC Documentation/accounting/getdelays > HOSTCC Documentation/connector/ucon > HOSTCC Documentation/mic/mpssd/mpssd.o > In file included from Documentation/mic/mpssd/mpssd.c:36:0: > ./usr/include/linux/virtio_ring.h: In function ?vring_init?: > ./usr/include/linux/virtio_ring.h:146:24: error: ?uintptr_t? undeclared > (first use in this function) > vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + > sizeof(__virtio16) > ^ > ./usr/include/linux/virtio_ring.h:146:24: note: each undeclared > identifier is reported only once for each function it appears in > scripts/Makefile.host:108: recipe for target > 'Documentation/mic/mpssd/mpssd.o' failed > make[3]: *** [Documentation/mic/mpssd/mpssd.o] Error 1 > scripts/Makefile.build:403: recipe for target 'Documentation/mic/mpssd' > failed > make[2]: *** [Documentation/mic/mpssd] Error 2 > scripts/Makefile.build:403: recipe for target 'Documentation/mic' failed > make[1]: *** [Documentation/mic] Error 2 > > > E.g. fuse.h has this code: > #ifdef __KERNEL__ > #include <linux/types.h> > #else > #include <stdint.h> > #endif > > Maybe we need something similar.The following seems to help. Does it help the windows build? --- include/uapi/linux/virtio_ring.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/uapi/linux/virtio_ring.h b/include/uapi/linux/virtio_ring.h index 8682551..c072959 100644 --- a/include/uapi/linux/virtio_ring.h +++ b/include/uapi/linux/virtio_ring.h @@ -31,6 +31,9 @@ * SUCH DAMAGE. * * Copyright Rusty Russell IBM Corporation 2007. */ +#ifndef __KERNEL__ +#include <stdint.h> +#endif #include <linux/types.h> #include <linux/virtio_types.h> -- MST
Seemingly Similar Threads
- [PATCH RESEND] virtio: Fix typecast of pointer in vring_init()
- [PATCH RESEND] virtio: Fix typecast of pointer in vring_init()
- [PATCH RESEND] virtio: Fix typecast of pointer in vring_init()
- [PATCH RESEND] virtio: Fix typecast of pointer in vring_init()
- [PATCH RESEND] virtio: Fix typecast of pointer in vring_init()