Skip to content

Commit 8f0cbed

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio fixes from Michael Tsirkin: "Just a bunch of fixes, mostly trivial ones in tools/virtio" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vhost/vsock: improve RCU read sections around vhost_vsock_get() tools/virtio: add device, device_driver stubs tools/virtio: fix up oot build virtio_features: make it self-contained tools/virtio: switch to kernel's virtio_config.h tools/virtio: stub might_sleep and synchronize_rcu tools/virtio: add struct cpumask to cpumask.h tools/virtio: pass KCFLAGS to module build tools/virtio: add ucopysize.h stub tools/virtio: add dev_WARN_ONCE and is_vmalloc_addr stubs tools/virtio: stub DMA mapping functions tools/virtio: add struct module forward declaration tools/virtio: use kernel's virtio.h virtio: make it self-contained tools/virtio: fix up compiler.h stub
2 parents e2cc644 + d8ee3cf commit 8f0cbed

14 files changed

Lines changed: 93 additions & 180 deletions

File tree

drivers/vhost/vsock.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ static u32 vhost_transport_get_local_cid(void)
6666
return VHOST_VSOCK_DEFAULT_HOST_CID;
6767
}
6868

69-
/* Callers that dereference the return value must hold vhost_vsock_mutex or the
70-
* RCU read lock.
69+
/* Callers must be in an RCU read section or hold the vhost_vsock_mutex.
70+
* The return value can only be dereferenced while within the section.
7171
*/
7272
static struct vhost_vsock *vhost_vsock_get(u32 guest_cid)
7373
{
7474
struct vhost_vsock *vsock;
7575

76-
hash_for_each_possible_rcu(vhost_vsock_hash, vsock, hash, guest_cid) {
76+
hash_for_each_possible_rcu(vhost_vsock_hash, vsock, hash, guest_cid,
77+
lockdep_is_held(&vhost_vsock_mutex)) {
7778
u32 other_cid = vsock->guest_cid;
7879

7980
/* Skip instances that have no CID yet */
@@ -709,9 +710,15 @@ static void vhost_vsock_reset_orphans(struct sock *sk)
709710
* executing.
710711
*/
711712

713+
rcu_read_lock();
714+
712715
/* If the peer is still valid, no need to reset connection */
713-
if (vhost_vsock_get(vsk->remote_addr.svm_cid))
716+
if (vhost_vsock_get(vsk->remote_addr.svm_cid)) {
717+
rcu_read_unlock();
714718
return;
719+
}
720+
721+
rcu_read_unlock();
715722

716723
/* If the close timeout is pending, let it expire. This avoids races
717724
* with the timeout callback.

include/linux/virtio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <linux/completion.h>
1414
#include <linux/virtio_features.h>
1515

16+
struct module;
17+
1618
/**
1719
* struct virtqueue - a queue to register buffers for sending or receiving.
1820
* @list: the chain of virtqueues for this device

include/linux/virtio_features.h

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

55
#include <linux/bits.h>
6+
#include <linux/bug.h>
7+
#include <linux/string.h>
68

79
#define VIRTIO_FEATURES_U64S 2
810
#define VIRTIO_FEATURES_BITS (VIRTIO_FEATURES_U64S * 64)

tools/virtio/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ CFLAGS += -g -O2 -Werror -Wno-maybe-uninitialized -Wall -I. -I../include/ -I ../
2020
CFLAGS += -pthread
2121
LDFLAGS += -pthread
2222
vpath %.c ../../drivers/virtio ../../drivers/vhost
23+
BUILD=KCFLAGS="-I "`pwd`/../../drivers/vhost ${MAKE} -C `pwd`/../.. V=${V}
2324
mod:
24-
${MAKE} -C `pwd`/../.. M=`pwd`/vhost_test V=${V}
25+
${BUILD} M=`pwd`/vhost_test
2526

2627
#oot: build vhost as an out of tree module for a distro kernel
2728
#no effort is taken to make it actually build or work, but tends to mostly work
@@ -37,8 +38,9 @@ OOT_CONFIGS=\
3738
CONFIG_VHOST_NET=n \
3839
CONFIG_VHOST_SCSI=n \
3940
CONFIG_VHOST_VSOCK=n \
40-
CONFIG_VHOST_RING=n
41-
OOT_BUILD=KCFLAGS="-I "${OOT_VHOST} ${MAKE} -C ${OOT_KSRC} V=${V}
41+
CONFIG_VHOST_RING=n \
42+
CONFIG_VHOST_VDPA=n
43+
OOT_BUILD=KCFLAGS="-include "`pwd`"/oot-stubs.h -I "${OOT_VHOST} ${MAKE} -C ${OOT_KSRC} V=${V}
4244
oot-build:
4345
echo "UNSUPPORTED! Don't use the resulting modules in production!"
4446
${OOT_BUILD} M=`pwd`/vhost_test

tools/virtio/linux/compiler.h

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

5+
/* Avoid redefinition warnings */
6+
#undef __user
57
#include "../../../include/linux/compiler_types.h"
8+
#undef __user
9+
#define __user
610

711
#define WRITE_ONCE(var, val) \
812
(*((volatile typeof(val) *)(&(var))) = (val))
@@ -35,4 +39,6 @@
3539
__v; \
3640
})
3741

42+
#define __must_check
43+
3844
#endif

tools/virtio/linux/cpumask.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44

55
#include <linux/kernel.h>
66

7+
struct cpumask {
8+
unsigned long bits[1];
9+
};
10+
711
#endif /* _LINUX_CPUMASK_H */

tools/virtio/linux/device.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
#ifndef LINUX_DEVICE_H
2+
3+
struct device {
4+
void *parent;
5+
};
6+
7+
struct device_driver {
8+
const char *name;
9+
};
210
#endif

tools/virtio/linux/dma-mapping.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ enum dma_data_direction {
2222
#define dma_free_coherent(d, s, p, h) kfree(p)
2323

2424
#define dma_map_page(d, p, o, s, dir) (page_to_phys(p) + (o))
25+
#define dma_map_page_attrs(d, p, o, s, dir, a) (page_to_phys(p) + (o))
2526

2627
#define dma_map_single(d, p, s, dir) (virt_to_phys(p))
2728
#define dma_map_single_attrs(d, p, s, dir, a) (virt_to_phys(p))
2829
#define dma_mapping_error(...) (0)
2930

3031
#define dma_unmap_single(d, a, s, r) do { (void)(d); (void)(a); (void)(s); (void)(r); } while (0)
3132
#define dma_unmap_page(d, a, s, r) do { (void)(d); (void)(a); (void)(s); (void)(r); } while (0)
33+
#define dma_unmap_page_attrs(d, a, s, r, t) do { \
34+
(void)(d); (void)(a); (void)(s); (void)(r); (void)(t); \
35+
} while (0)
3236

3337
#define sg_dma_address(sg) (0)
3438
#define sg_dma_len(sg) (0)

tools/virtio/linux/kernel.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/log2.h>
1515
#include <linux/types.h>
1616
#include <linux/overflow.h>
17+
#include <linux/limits.h>
1718
#include <linux/list.h>
1819
#include <linux/printk.h>
1920
#include <linux/bug.h>
@@ -135,6 +136,21 @@ static inline void *krealloc_array(void *p, size_t new_n, size_t new_size, gfp_t
135136
#define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
136137
#define dev_warn_once(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
137138

139+
#define dev_WARN_ONCE(dev, condition, format...) \
140+
WARN_ONCE(condition, format)
141+
142+
static inline bool is_vmalloc_addr(const void *x)
143+
{
144+
return false;
145+
}
146+
147+
#define might_sleep() do { } while (0)
148+
149+
static inline void synchronize_rcu(void)
150+
{
151+
assert(0);
152+
}
153+
138154
#define min(x, y) ({ \
139155
typeof(x) _min1 = (x); \
140156
typeof(y) _min2 = (y); \

tools/virtio/linux/module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#include <linux/export.h>
33

4+
struct module;
5+
46
#define MODULE_LICENSE(__MODULE_LICENSE_value) \
57
static __attribute__((unused)) const char *__MODULE_LICENSE_name = \
68
__MODULE_LICENSE_value

0 commit comments

Comments
 (0)