Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/virtio: fix build caused by virtio_ring changes

Fix the build dependency for virtio_test. The virtio_ring that is used from
the test requires container_of_const(). Change to use container_of.h kernel
header directly and adapt related codes.

Signed-off-by: Shunsuke Mie <mie@igel.co.jp>
Message-Id: <20230417022037.917668-2-mie@igel.co.jp>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Shunsuke Mie and committed by
Michael S. Tsirkin
e9c4962c 38fc29ea

+10 -13
+5
tools/include/linux/types.h
··· 49 49 #endif 50 50 51 51 #define __force 52 + /* This is defined in linux/compiler_types.h and is left for backward 53 + * compatibility. 54 + */ 55 + #ifndef __user 52 56 #define __user 57 + #endif 53 58 #define __must_check 54 59 #define __cold 55 60
+2
tools/virtio/linux/compiler.h
··· 2 2 #ifndef LINUX_COMPILER_H 3 3 #define LINUX_COMPILER_H 4 4 5 + #include "../../../include/linux/compiler_types.h" 6 + 5 7 #define WRITE_ONCE(var, val) \ 6 8 (*((volatile typeof(val) *)(&(var))) = (val)) 7 9
+1 -4
tools/virtio/linux/kernel.h
··· 10 10 #include <stdarg.h> 11 11 12 12 #include <linux/compiler.h> 13 + #include "../../../include/linux/container_of.h" 13 14 #include <linux/log2.h> 14 15 #include <linux/types.h> 15 16 #include <linux/overflow.h> ··· 107 106 { 108 107 free((void *)addr); 109 108 } 110 - 111 - #define container_of(ptr, type, member) ({ \ 112 - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 113 - (type *)( (char *)__mptr - offsetof(type,member) );}) 114 109 115 110 # ifndef likely 116 111 # define likely(x) (__builtin_expect(!!(x), 1))
+2 -9
tools/virtio/linux/uaccess.h
··· 6 6 7 7 extern void *__user_addr_min, *__user_addr_max; 8 8 9 - static inline void __chk_user_ptr(const volatile void *p, size_t size) 10 - { 11 - assert(p >= __user_addr_min && p + size <= __user_addr_max); 12 - } 13 - 14 9 #define put_user(x, ptr) \ 15 10 ({ \ 16 11 typeof(ptr) __pu_ptr = (ptr); \ 17 - __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \ 12 + __chk_user_ptr(__pu_ptr); \ 18 13 WRITE_ONCE(*(__pu_ptr), x); \ 19 14 0; \ 20 15 }) ··· 17 22 #define get_user(x, ptr) \ 18 23 ({ \ 19 24 typeof(ptr) __pu_ptr = (ptr); \ 20 - __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \ 25 + __chk_user_ptr(__pu_ptr); \ 21 26 x = READ_ONCE(*(__pu_ptr)); \ 22 27 0; \ 23 28 }) ··· 32 37 static inline int copy_from_user(void *to, const void __user volatile *from, 33 38 unsigned long n) 34 39 { 35 - __chk_user_ptr(from, n); 36 40 volatile_memcpy(to, from, n); 37 41 return 0; 38 42 } ··· 39 45 static inline int copy_to_user(void __user volatile *to, const void *from, 40 46 unsigned long n) 41 47 { 42 - __chk_user_ptr(to, n); 43 48 volatile_memcpy(to, from, n); 44 49 return 0; 45 50 }