* [PATCH] virtio: uapi: avoid usage of libc types
@ 2025-12-22 8:00 Thomas Weißschuh
2025-12-22 8:39 ` Michael S. Tsirkin
2025-12-22 8:46 ` Arnd Bergmann
0 siblings, 2 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2025-12-22 8:00 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Eugenio Pérez
Cc: virtualization, linux-kernel, Arnd Bergmann,
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 <thomas.weissschuh@linutronix.de>
---
include/uapi/linux/virtio_ring.h | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/include/uapi/linux/virtio_ring.h b/include/uapi/linux/virtio_ring.h
index f8c20d3de8da..3c478582a3c2 100644
--- a/include/uapi/linux/virtio_ring.h
+++ b/include/uapi/linux/virtio_ring.h
@@ -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,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio: uapi: avoid usage of libc types
2025-12-22 8:00 [PATCH] virtio: uapi: avoid usage of libc types Thomas Weißschuh
@ 2025-12-22 8:39 ` Michael S. Tsirkin
2025-12-22 10:22 ` Thomas Weißschuh
2025-12-22 8:46 ` Arnd Bergmann
1 sibling, 1 reply; 8+ messages in thread
From: Michael S. Tsirkin @ 2025-12-22 8:39 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Jason Wang, Xuan Zhuo, Eugenio Pérez, virtualization,
linux-kernel, Arnd Bergmann
On Mon, Dec 22, 2025 at 09:00:33AM +0100, Thomas Weißschuh wrote:
> 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 <thomas.weissschuh@linutronix.de>
are you fixing other uses of uintptr_t ?
> ---
> include/uapi/linux/virtio_ring.h | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/include/uapi/linux/virtio_ring.h b/include/uapi/linux/virtio_ring.h
> index f8c20d3de8da..3c478582a3c2 100644
> --- a/include/uapi/linux/virtio_ring.h
> +++ b/include/uapi/linux/virtio_ring.h
> @@ -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,
> --
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio: uapi: avoid usage of libc types
2025-12-22 8:00 [PATCH] virtio: uapi: avoid usage of libc types Thomas Weißschuh
2025-12-22 8:39 ` Michael S. Tsirkin
@ 2025-12-22 8:46 ` Arnd Bergmann
1 sibling, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2025-12-22 8:46 UTC (permalink / raw)
To: Thomas Weißschuh, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez
Cc: virtualization, linux-kernel
On Mon, Dec 22, 2025, at 09:00, Thomas Weißschuh wrote:
> 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 <thomas.weissschuh@linutronix.de>
Acked-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio: uapi: avoid usage of libc types
2025-12-22 8:39 ` Michael S. Tsirkin
@ 2025-12-22 10:22 ` Thomas Weißschuh
2025-12-22 10:28 ` Michael S. Tsirkin
0 siblings, 1 reply; 8+ messages in thread
From: Thomas Weißschuh @ 2025-12-22 10:22 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Jason Wang, Xuan Zhuo, Eugenio Pérez, virtualization,
linux-kernel, Arnd Bergmann
On Mon, Dec 22, 2025 at 03:39:12AM -0500, Michael S. Tsirkin wrote:
> On Mon, Dec 22, 2025 at 09:00:33AM +0100, Thomas Weißschuh wrote:
> > 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 <thomas.weissschuh@linutronix.de>
>
>
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio: uapi: avoid usage of libc types
2025-12-22 10:22 ` Thomas Weißschuh
@ 2025-12-22 10:28 ` Michael S. Tsirkin
2025-12-22 10:43 ` Thomas Weißschuh
0 siblings, 1 reply; 8+ messages in thread
From: Michael S. Tsirkin @ 2025-12-22 10:28 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Jason Wang, Xuan Zhuo, Eugenio Pérez, virtualization,
linux-kernel, Arnd Bergmann
On Mon, Dec 22, 2025 at 11:22:16AM +0100, Thomas Weißschuh wrote:
> On Mon, Dec 22, 2025 at 03:39:12AM -0500, Michael S. Tsirkin wrote:
> > On Mon, Dec 22, 2025 at 09:00:33AM +0100, Thomas Weißschuh wrote:
> > > 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 <thomas.weissschuh@linutronix.de>
> >
> >
> > 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
And other uses of stdint.h?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio: uapi: avoid usage of libc types
2025-12-22 10:28 ` Michael S. Tsirkin
@ 2025-12-22 10:43 ` Thomas Weißschuh
2025-12-22 22:18 ` Michael S. Tsirkin
0 siblings, 1 reply; 8+ messages in thread
From: Thomas Weißschuh @ 2025-12-22 10:43 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Jason Wang, Xuan Zhuo, Eugenio Pérez, virtualization,
linux-kernel, Arnd Bergmann
On Mon, Dec 22, 2025 at 05:28:30AM -0500, Michael S. Tsirkin wrote:
> On Mon, Dec 22, 2025 at 11:22:16AM +0100, Thomas Weißschuh wrote:
> > On Mon, Dec 22, 2025 at 03:39:12AM -0500, Michael S. Tsirkin wrote:
> > > On Mon, Dec 22, 2025 at 09:00:33AM +0100, Thomas Weißschuh wrote:
> > > > 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 <thomas.weissschuh@linutronix.de>
> > >
> > >
> > > 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
>
> 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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio: uapi: avoid usage of libc types
2025-12-22 10:43 ` Thomas Weißschuh
@ 2025-12-22 22:18 ` Michael S. Tsirkin
2025-12-23 7:10 ` Thomas Weißschuh
0 siblings, 1 reply; 8+ messages in thread
From: Michael S. Tsirkin @ 2025-12-22 22:18 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Jason Wang, Xuan Zhuo, Eugenio Pérez, virtualization,
linux-kernel, Arnd Bergmann
On Mon, Dec 22, 2025 at 11:43:52AM +0100, Thomas Weißschuh wrote:
> On Mon, Dec 22, 2025 at 05:28:30AM -0500, Michael S. Tsirkin wrote:
> > On Mon, Dec 22, 2025 at 11:22:16AM +0100, Thomas Weißschuh wrote:
> > > On Mon, Dec 22, 2025 at 03:39:12AM -0500, Michael S. Tsirkin wrote:
> > > > On Mon, Dec 22, 2025 at 09:00:33AM +0100, Thomas Weißschuh wrote:
> > > > > 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 <thomas.weissschuh@linutronix.de>
> > > >
> > > >
> > > > 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
> >
> > 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.
--
MST
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio: uapi: avoid usage of libc types
2025-12-22 22:18 ` Michael S. Tsirkin
@ 2025-12-23 7:10 ` Thomas Weißschuh
0 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2025-12-23 7:10 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Jason Wang, Xuan Zhuo, Eugenio Pérez, virtualization,
linux-kernel, Arnd Bergmann
On Mon, Dec 22, 2025 at 05:18:26PM -0500, Michael S. Tsirkin wrote:
> On Mon, Dec 22, 2025 at 11:43:52AM +0100, Thomas Weißschuh wrote:
> > On Mon, Dec 22, 2025 at 05:28:30AM -0500, Michael S. Tsirkin wrote:
> > > On Mon, Dec 22, 2025 at 11:22:16AM +0100, Thomas Weißschuh wrote:
> > > > On Mon, Dec 22, 2025 at 03:39:12AM -0500, Michael S. Tsirkin wrote:
> > > > > On Mon, Dec 22, 2025 at 09:00:33AM +0100, Thomas Weißschuh wrote:
> > > > > > 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 <thomas.weissschuh@linutronix.de>
> > > > >
> > > > >
> > > > > 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
> > >
> > > 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/20251203-uapi-fcntl-v1-1-490c67bf3425@linutronix.de/
[1] https://lore.kernel.org/lkml/20251223-uapi-nostdinc-v1-0-d91545d794f7@linutronix.de/
[2] https://lore.kernel.org/lkml/20251223-uapi-nostdinc-v1-1-d91545d794f7@linutronix.de/
Thomas
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-12-23 7:10 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-22 8:00 [PATCH] virtio: uapi: avoid usage of libc types Thomas Weißschuh
2025-12-22 8:39 ` Michael S. Tsirkin
2025-12-22 10:22 ` Thomas Weißschuh
2025-12-22 10:28 ` Michael S. Tsirkin
2025-12-22 10:43 ` Thomas Weißschuh
2025-12-22 22:18 ` Michael S. Tsirkin
2025-12-23 7:10 ` Thomas Weißschuh
2025-12-22 8:46 ` Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox