virtio: uapi: avoid usage of libc types
PATCH 1/1 virtio: uapi: avoid usage of libc types
Using libc types and headers from the UAPI headers is problematic as it introduces a dependency on a full C toolchain.
On Linux 'unsigned long' works as a replacement for 'uintptr_t' and does not depend on libc.
--- include/uapi/linux/virtio_ring.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
include/uapi/linux/virtio_ring.h +1 -4
@@ -31,9 +31,6 @@* SUCH DAMAGE. * * Copyright Rusty Russell IBM Corporation 2007. */ -#ifndef __KERNEL__ -#include <stdint.h> -#endif #include <linux/types.h> #include <linux/virtio_types.h>
@@ -202,7 +199,7 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p, vr->num = num; vr->desc = p; vr->avail = (struct vring_avail *)((char *)p + num *sizeof (struct vring_desc )); - vr->used = (void *)(((uintptr_t )&vr->avail->ring[num] +sizeof (__virtio16) + vr->used = (void *)(((unsigned long )&vr->avail->ring[num] +sizeof (__virtio16) + align-1 ) & ~(align -1 )); }
---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251222-uapi-virtio-d208b915ca1d
Best regards,
Signature · 1 line
Thomas Weißschuh <[email protected]>
Michael S. Tsirkin
maintainerQuoted 7 lines · Thomas Weißschuh
Using libc types and headers from the UAPI headers is problematic as it introduces a dependency on a full C toolchain.
On Linux 'unsigned long' works as a replacement for '
uintptr_t' and does not depend on libc.Signed-off-by Thomas Weißschuh <[email protected]>
are you fixing other uses of uintptr_t ?
Quoted 35 lines
--- include/uapi/linux/virtio_ring.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)include/uapi/linux/virtio_ring.h +1
-5@@ -31,9 +31,6 @@* SUCH DAMAGE. * * Copyright Rusty Russell IBM Corporation 2007. */ -#ifndef __KERNEL__ -#include <stdint.h> -#endif #include <linux/types.h> #include <linux/virtio_types.h> @@ -202,7 +199,7 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p, vr->num = num; vr->desc = p; vr->avail = (struct vring_avail *)((char *)p + num *sizeof (struct vring_desc )); - vr->used = (void *)(((uintptr_t )&vr->avail->ring[num] +sizeof (__virtio16) + vr->used = (void *)(((unsigned long )&vr->avail->ring[num] +sizeof (__virtio16) + align-1 ) & ~(align -1 )); } ---base-commit:
8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251222-uapi-virtio-d208b915ca1dBest regards,
Signature · 1 line
Thomas Weißschuh <[email protected]>
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Thomas Weißschuh
Using libc types and headers from the UAPI headers is problematic as it introduces a dependency on a full C toolchain.
On Linux 'unsigned long' works as a replacement for '
uintptr_t' and does not depend on libc.Signed-off-by Thomas Weißschuh <[email protected]>are you fixing other uses of
uintptr_t?
I am focussing on UAPI headers which include libc headers. virtio_ring.h seems to be the only such header which uses uintptr_t. There are a few other UAPI headers which reference uintptr_t, but only in comments or macros.
uintptr_t in regular kernel code is out of scope for me. While it is iffy, it doesn't actually hurt.
Thomas
Michael S. Tsirkin
maintainerQuoted 18 lines · Thomas Weißschuh
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Thomas Weißschuh
Using libc types and headers from the UAPI headers is problematic as it introduces a dependency on a full C toolchain.
On Linux 'unsigned long' works as a replacement for '
uintptr_t' and does not depend on libc.Signed-off-by Thomas Weißschuh <[email protected]>are you fixing other uses of
uintptr_t?I am focussing on UAPI headers which include libc headers.
virtio_ring.hseems to be the only such header which usesuintptr_t. There are a few other UAPI headers which referenceuintptr_t, but only in comments or macros.
Quoted 5 lines
uintptr_tin regular kernel code is out of scope for me. While it is iffy, it doesn't actually hurt.Thomas
And other uses of stdint.h?
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Thomas Weißschuh
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Thomas Weißschuh
Using libc types and headers from the UAPI headers is problematic as it introduces a dependency on a full C toolchain.
On Linux 'unsigned long' works as a replacement for '
uintptr_t' and does not depend on libc.Signed-off-by Thomas Weißschuh <[email protected]>are you fixing other uses of
uintptr_t?I am focussing on UAPI headers which include libc headers.
virtio_ring.hseems to be the only such header which usesuintptr_t. There are a few other UAPI headers which referenceuintptr_t, but only in comments or macros.
Quoted 7 lines
Quoted 5 lines
uintptr_tin regular kernel code is out of scope for me. While it is iffy, it doesn't actually hurt.Thomas
And other uses of
stdint.h?
If they are in UAPI headers I will look at them.
I also have a series prepared to prevent new users from creeping in.
Michael S. Tsirkin
maintainerQuoted 24 lines · Thomas Weißschuh
Quoted 23 lines · Michael S. Tsirkin
Quoted 22 lines · Thomas Weißschuh
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Thomas Weißschuh
Using libc types and headers from the UAPI headers is problematic as it introduces a dependency on a full C toolchain.
On Linux 'unsigned long' works as a replacement for '
uintptr_t' and does not depend on libc.Signed-off-by Thomas Weißschuh <[email protected]>are you fixing other uses of
uintptr_t?I am focussing on UAPI headers which include libc headers.
virtio_ring.hseems to be the only such header which usesuintptr_t. There are a few other UAPI headers which referenceuintptr_t, but only in comments or macros.
uintptr_tin regular kernel code is out of scope for me. While it is iffy, it doesn't actually hurt.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Thomas
And other uses of
stdint.h?If they are in UAPI headers I will look at them.
I also have a series prepared to prevent new users from creeping in.
I don't mind picking this but I'm just curious what's driving all this effort.
Signature · 1 line
MST
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Thomas Weißschuh
Quoted 25 lines · Michael S. Tsirkin
Quoted 23 lines · Thomas Weißschuh
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Thomas Weißschuh
Using libc types and headers from the UAPI headers is problematic as it introduces a dependency on a full C toolchain.
On Linux 'unsigned long' works as a replacement for '
uintptr_t' and does not depend on libc.Signed-off-by Thomas Weißschuh <[email protected]>are you fixing other uses of
uintptr_t?I am focussing on UAPI headers which include libc headers.
virtio_ring.hseems to be the only such header which usesuintptr_t. There are a few other UAPI headers which referenceuintptr_t, but only in comments or macros.
uintptr_tin regular kernel code is out of scope for me. While it is iffy, it doesn't actually hurt.Thomas
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
And other uses of
stdint.h?If they are in UAPI headers I will look at them.
I also have a series prepared to prevent new users from creeping in.I don't mind picking this but I'm just curious what's driving all this effort.
It started with a recent change to an UAPI header which introduced a dependency on libc that broke some things I was doing. See the fix and background in [0]. So I looked into catching such issues earlier, which resulted in [1]. Fortunately there are not many problematic headers [2] in general, so I am now also fixing those, so the new check can validate more headers and prevent more regressions.
[0] https://lore.kernel.org/lkml/[email protected]/
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
Thomas
Quoted 7 lines · Thomas Weißschuh
Using libc types and headers from the UAPI headers is problematic as it introduces a dependency on a full C toolchain.
On Linux 'unsigned long' works as a replacement for '
uintptr_t' and does not depend on libc.Signed-off-by Thomas Weißschuh <[email protected]>