On Thu, Jun 18, 2026 at 11:59 AM Yichong Chen <[email protected]> wrote:
>
> vhost_net_test builds virtio_ring.c in userspace.
>
> Recent virtio headers pull in new helper headers.
>
> They also use new allocation helpers and a DMA attribute.
>
> Add the missing compat definitions.
>
I'm all in with this patch but it still misses some headers, could you
check again with latest master?
$ make vhost_net_test
cc -g -O2 -Werror -Wno-maybe-uninitialized -Wall -I. -I../include/ -I
../../usr/include/ -Wno-pointer-sign -fno-strict-overflow
-fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -include
../../include/linux/kconfig.h -mfunction-return=thunk
-fcf-protection=none -mindirect-branch-register -pthread -c -o
virtio_ring.o ../../drivers/virtio/virtio_ring.c
In file included from ./linux/compiler.h:7,
from ./linux/kernel.h:12,
from ./linux/scatterlist.h:4,
from ./../../include/linux/virtio.h:7,
from ./linux/virtio.h:1,
from ../../drivers/virtio/virtio_ring.c:6:
./linux/../../../include/linux/compiler_types.h:638:10: fatal error:
asm/percpu_types.h: No such file or directory
638 | #include <asm/percpu_types.h>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: virtio_ring.o] Error 1
> Signed-off-by: Yichong Chen <[email protected]>
> ---
> tools/virtio/linux/completion.h | 9 +++++
> tools/virtio/linux/device.h | 1 +
> tools/virtio/linux/dma-mapping.h | 1 +
> tools/virtio/linux/mod_devicetable.h | 14 +++++++
> tools/virtio/linux/slab.h | 4 ++
> tools/virtio/linux/virtio_features.h | 56 ++++++++++++++++++++++++++++
> 6 files changed, 85 insertions(+)
> create mode 100644 tools/virtio/linux/completion.h
> create mode 100644 tools/virtio/linux/mod_devicetable.h
> create mode 100644 tools/virtio/linux/virtio_features.h
>
> diff --git a/tools/virtio/linux/completion.h b/tools/virtio/linux/completion.h
> new file mode 100644
> index 000000000000..5e54b679721b
> --- /dev/null
> +++ b/tools/virtio/linux/completion.h
> @@ -0,0 +1,9 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _LINUX_COMPLETION_H
> +#define _LINUX_COMPLETION_H
> +
> +struct completion {
> + unsigned int done;
> +};
> +
> +#endif /* _LINUX_COMPLETION_H */
> diff --git a/tools/virtio/linux/device.h b/tools/virtio/linux/device.h
> index 075c2140d975..abf100cb0023 100644
> --- a/tools/virtio/linux/device.h
> +++ b/tools/virtio/linux/device.h
> @@ -1,4 +1,5 @@
> #ifndef LINUX_DEVICE_H
> +#define LINUX_DEVICE_H
>
> struct device {
> void *parent;
> diff --git a/tools/virtio/linux/dma-mapping.h
> b/tools/virtio/linux/dma-mapping.h
> index fddfa2fbb276..65e2974b3908 100644
> --- a/tools/virtio/linux/dma-mapping.h
> +++ b/tools/virtio/linux/dma-mapping.h
> @@ -59,5 +59,6 @@ enum dma_data_direction {
> * instead.
> */
> #define DMA_MAPPING_ERROR (~(dma_addr_t)0)
> +#define DMA_ATTR_DEBUGGING_IGNORE_CACHELINES 0
>
> #endif
> diff --git a/tools/virtio/linux/mod_devicetable.h
> b/tools/virtio/linux/mod_devicetable.h
> new file mode 100644
> index 000000000000..3ba594b8229d
> --- /dev/null
> +++ b/tools/virtio/linux/mod_devicetable.h
> @@ -0,0 +1,14 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _LINUX_MOD_DEVICETABLE_H
> +#define _LINUX_MOD_DEVICETABLE_H
> +
> +#include <linux/types.h>
> +
> +struct virtio_device_id {
> + __u32 device;
> + __u32 vendor;
> +};
> +
> +#define VIRTIO_DEV_ANY_ID 0xffffffff
> +
> +#endif /* _LINUX_MOD_DEVICETABLE_H */
> diff --git a/tools/virtio/linux/slab.h b/tools/virtio/linux/slab.h
> index 319dcaa07755..13d94c6f663c 100644
> --- a/tools/virtio/linux/slab.h
> +++ b/tools/virtio/linux/slab.h
> @@ -4,4 +4,8 @@
> #define GFP_ATOMIC 0
> #define __GFP_NOWARN 0
> #define __GFP_ZERO 0
> +#define kmalloc_obj(VAR_OR_TYPE, ...) \
> + kmalloc(sizeof(VAR_OR_TYPE), GFP_KERNEL)
> +#define kmalloc_objs(VAR_OR_TYPE, COUNT, ...) \
> + kmalloc_array((COUNT), sizeof(VAR_OR_TYPE), GFP_KERNEL)
> #endif
> diff --git a/tools/virtio/linux/virtio_features.h
> b/tools/virtio/linux/virtio_features.h
> new file mode 100644
> index 000000000000..18c56610e209
> --- /dev/null
> +++ b/tools/virtio/linux/virtio_features.h
> @@ -0,0 +1,56 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _LINUX_VIRTIO_FEATURES_H
> +#define _LINUX_VIRTIO_FEATURES_H
> +
> +#include <linux/bug.h>
> +#include <linux/string.h>
> +#include <linux/types.h>
> +
> +#define VIRTIO_FEATURES_U64S 2
> +#define VIRTIO_FEATURES_BITS (VIRTIO_FEATURES_U64S * 64)
> +
> +#define VIRTIO_BIT(b) (1ULL << ((b) & 0x3f))
> +#define VIRTIO_U64(b) ((b) >> 6)
> +
> +#define VIRTIO_DECLARE_FEATURES(name) \
> + union { \
> + u64 name; \
> + u64 name##_array[VIRTIO_FEATURES_U64S]; \
> + }
> +
> +static inline bool virtio_features_chk_bit(unsigned int bit)
> +{
> + return bit < VIRTIO_FEATURES_BITS;
> +}
> +
> +static inline bool virtio_features_test_bit(const u64 *features,
> + unsigned int bit)
> +{
> + return virtio_features_chk_bit(bit) &&
> + !!(features[VIRTIO_U64(bit)] & VIRTIO_BIT(bit));
> +}
> +
> +static inline void virtio_features_set_bit(u64 *features, unsigned int bit)
> +{
> + if (virtio_features_chk_bit(bit))
> + features[VIRTIO_U64(bit)] |= VIRTIO_BIT(bit);
> +}
> +
> +static inline void virtio_features_clear_bit(u64 *features, unsigned int bit)
> +{
> + if (virtio_features_chk_bit(bit))
> + features[VIRTIO_U64(bit)] &= ~VIRTIO_BIT(bit);
> +}
> +
> +static inline void virtio_features_zero(u64 *features)
> +{
> + memset(features, 0, sizeof(features[0]) * VIRTIO_FEATURES_U64S);
> +}
> +
> +static inline void virtio_features_from_u64(u64 *features, u64 from)
> +{
> + virtio_features_zero(features);
> + features[0] = from;
> +}
> +
> +#endif /* _LINUX_VIRTIO_FEATURES_H */
> --
> 2.51.0
>