Skip to content

Commit e9c4962

Browse files
ShunsukeMiemstsirkin
authored andcommitted
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>
1 parent 38fc29e commit e9c4962

4 files changed

Lines changed: 10 additions & 13 deletions

File tree

tools/include/linux/types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ typedef __s8 s8;
4949
#endif
5050

5151
#define __force
52+
/* This is defined in linux/compiler_types.h and is left for backward
53+
* compatibility.
54+
*/
55+
#ifndef __user
5256
#define __user
57+
#endif
5358
#define __must_check
5459
#define __cold
5560

tools/virtio/linux/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#ifndef LINUX_COMPILER_H
33
#define LINUX_COMPILER_H
44

5+
#include "../../../include/linux/compiler_types.h"
6+
57
#define WRITE_ONCE(var, val) \
68
(*((volatile typeof(val) *)(&(var))) = (val))
79

tools/virtio/linux/kernel.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <stdarg.h>
1111

1212
#include <linux/compiler.h>
13+
#include "../../../include/linux/container_of.h"
1314
#include <linux/log2.h>
1415
#include <linux/types.h>
1516
#include <linux/overflow.h>
@@ -107,10 +108,6 @@ static inline void free_page(unsigned long addr)
107108
free((void *)addr);
108109
}
109110

110-
#define container_of(ptr, type, member) ({ \
111-
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
112-
(type *)( (char *)__mptr - offsetof(type,member) );})
113-
114111
# ifndef likely
115112
# define likely(x) (__builtin_expect(!!(x), 1))
116113
# endif

tools/virtio/linux/uaccess.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,18 @@
66

77
extern void *__user_addr_min, *__user_addr_max;
88

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-
149
#define put_user(x, ptr) \
1510
({ \
1611
typeof(ptr) __pu_ptr = (ptr); \
17-
__chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
12+
__chk_user_ptr(__pu_ptr); \
1813
WRITE_ONCE(*(__pu_ptr), x); \
1914
0; \
2015
})
2116

2217
#define get_user(x, ptr) \
2318
({ \
2419
typeof(ptr) __pu_ptr = (ptr); \
25-
__chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
20+
__chk_user_ptr(__pu_ptr); \
2621
x = READ_ONCE(*(__pu_ptr)); \
2722
0; \
2823
})
@@ -37,15 +32,13 @@ static void volatile_memcpy(volatile char *to, const volatile char *from,
3732
static inline int copy_from_user(void *to, const void __user volatile *from,
3833
unsigned long n)
3934
{
40-
__chk_user_ptr(from, n);
4135
volatile_memcpy(to, from, n);
4236
return 0;
4337
}
4438

4539
static inline int copy_to_user(void __user volatile *to, const void *from,
4640
unsigned long n)
4741
{
48-
__chk_user_ptr(to, n);
4942
volatile_memcpy(to, from, n);
5043
return 0;
5144
}

0 commit comments

Comments
 (0)