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

Configure Feed

Select the types of activity you want to include in your feed.

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

+93 -180
+11 -4
drivers/vhost/vsock.c
··· 66 66 return VHOST_VSOCK_DEFAULT_HOST_CID; 67 67 } 68 68 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. 71 71 */ 72 72 static struct vhost_vsock *vhost_vsock_get(u32 guest_cid) 73 73 { 74 74 struct vhost_vsock *vsock; 75 75 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)) { 77 78 u32 other_cid = vsock->guest_cid; 78 79 79 80 /* Skip instances that have no CID yet */ ··· 710 709 * executing. 711 710 */ 712 711 712 + rcu_read_lock(); 713 + 713 714 /* If the peer is still valid, no need to reset connection */ 714 - if (vhost_vsock_get(vsk->remote_addr.svm_cid)) 715 + if (vhost_vsock_get(vsk->remote_addr.svm_cid)) { 716 + rcu_read_unlock(); 715 717 return; 718 + } 719 + 720 + rcu_read_unlock(); 716 721 717 722 /* If the close timeout is pending, let it expire. This avoids races 718 723 * with the timeout callback.
+2
include/linux/virtio.h
··· 13 13 #include <linux/completion.h> 14 14 #include <linux/virtio_features.h> 15 15 16 + struct module; 17 + 16 18 /** 17 19 * struct virtqueue - a queue to register buffers for sending or receiving. 18 20 * @list: the chain of virtqueues for this device
+2
include/linux/virtio_features.h
··· 3 3 #define _LINUX_VIRTIO_FEATURES_H 4 4 5 5 #include <linux/bits.h> 6 + #include <linux/bug.h> 7 + #include <linux/string.h> 6 8 7 9 #define VIRTIO_FEATURES_U64S 2 8 10 #define VIRTIO_FEATURES_BITS (VIRTIO_FEATURES_U64S * 64)
+5 -3
tools/virtio/Makefile
··· 20 20 CFLAGS += -pthread 21 21 LDFLAGS += -pthread 22 22 vpath %.c ../../drivers/virtio ../../drivers/vhost 23 + BUILD=KCFLAGS="-I "`pwd`/../../drivers/vhost ${MAKE} -C `pwd`/../.. V=${V} 23 24 mod: 24 - ${MAKE} -C `pwd`/../.. M=`pwd`/vhost_test V=${V} 25 + ${BUILD} M=`pwd`/vhost_test 25 26 26 27 #oot: build vhost as an out of tree module for a distro kernel 27 28 #no effort is taken to make it actually build or work, but tends to mostly work ··· 38 37 CONFIG_VHOST_NET=n \ 39 38 CONFIG_VHOST_SCSI=n \ 40 39 CONFIG_VHOST_VSOCK=n \ 41 - CONFIG_VHOST_RING=n 42 - OOT_BUILD=KCFLAGS="-I "${OOT_VHOST} ${MAKE} -C ${OOT_KSRC} V=${V} 40 + CONFIG_VHOST_RING=n \ 41 + CONFIG_VHOST_VDPA=n 42 + OOT_BUILD=KCFLAGS="-include "`pwd`"/oot-stubs.h -I "${OOT_VHOST} ${MAKE} -C ${OOT_KSRC} V=${V} 43 43 oot-build: 44 44 echo "UNSUPPORTED! Don't use the resulting modules in production!" 45 45 ${OOT_BUILD} M=`pwd`/vhost_test
+6
tools/virtio/linux/compiler.h
··· 2 2 #ifndef LINUX_COMPILER_H 3 3 #define LINUX_COMPILER_H 4 4 5 + /* Avoid redefinition warnings */ 6 + #undef __user 5 7 #include "../../../include/linux/compiler_types.h" 8 + #undef __user 9 + #define __user 6 10 7 11 #define WRITE_ONCE(var, val) \ 8 12 (*((volatile typeof(val) *)(&(var))) = (val)) ··· 38 34 auto __v = (expr); \ 39 35 __v; \ 40 36 }) 37 + 38 + #define __must_check 41 39 42 40 #endif
+4
tools/virtio/linux/cpumask.h
··· 4 4 5 5 #include <linux/kernel.h> 6 6 7 + struct cpumask { 8 + unsigned long bits[1]; 9 + }; 10 + 7 11 #endif /* _LINUX_CPUMASK_H */
+8
tools/virtio/linux/device.h
··· 1 1 #ifndef LINUX_DEVICE_H 2 + 3 + struct device { 4 + void *parent; 5 + }; 6 + 7 + struct device_driver { 8 + const char *name; 9 + }; 2 10 #endif
+4
tools/virtio/linux/dma-mapping.h
··· 22 22 #define dma_free_coherent(d, s, p, h) kfree(p) 23 23 24 24 #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)) 25 26 26 27 #define dma_map_single(d, p, s, dir) (virt_to_phys(p)) 27 28 #define dma_map_single_attrs(d, p, s, dir, a) (virt_to_phys(p)) ··· 30 29 31 30 #define dma_unmap_single(d, a, s, r) do { (void)(d); (void)(a); (void)(s); (void)(r); } while (0) 32 31 #define dma_unmap_page(d, a, s, r) do { (void)(d); (void)(a); (void)(s); (void)(r); } while (0) 32 + #define dma_unmap_page_attrs(d, a, s, r, t) do { \ 33 + (void)(d); (void)(a); (void)(s); (void)(r); (void)(t); \ 34 + } while (0) 33 35 34 36 #define sg_dma_address(sg) (0) 35 37 #define sg_dma_len(sg) (0)
+16
tools/virtio/linux/kernel.h
··· 14 14 #include <linux/log2.h> 15 15 #include <linux/types.h> 16 16 #include <linux/overflow.h> 17 + #include <linux/limits.h> 17 18 #include <linux/list.h> 18 19 #include <linux/printk.h> 19 20 #include <linux/bug.h> ··· 135 134 #define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__) 136 135 #define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__) 137 136 #define dev_warn_once(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__) 137 + 138 + #define dev_WARN_ONCE(dev, condition, format...) \ 139 + WARN_ONCE(condition, format) 140 + 141 + static inline bool is_vmalloc_addr(const void *x) 142 + { 143 + return false; 144 + } 145 + 146 + #define might_sleep() do { } while (0) 147 + 148 + static inline void synchronize_rcu(void) 149 + { 150 + assert(0); 151 + } 138 152 139 153 #define min(x, y) ({ \ 140 154 typeof(x) _min1 = (x); \
+2
tools/virtio/linux/module.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 #include <linux/export.h> 3 3 4 + struct module; 5 + 4 6 #define MODULE_LICENSE(__MODULE_LICENSE_value) \ 5 7 static __attribute__((unused)) const char *__MODULE_LICENSE_name = \ 6 8 __MODULE_LICENSE_value
+21
tools/virtio/linux/ucopysize.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __LINUX_UCOPYSIZE_H__ 3 + #define __LINUX_UCOPYSIZE_H__ 4 + 5 + #include <linux/bug.h> 6 + 7 + static inline void check_object_size(const void *ptr, unsigned long n, 8 + bool to_user) 9 + { } 10 + 11 + static inline void copy_overflow(int size, unsigned long count) 12 + { 13 + } 14 + 15 + static __always_inline __must_check bool 16 + check_copy_size(const void *addr, size_t bytes, bool is_source) 17 + { 18 + return true; 19 + } 20 + 21 + #endif /* __LINUX_UCOPYSIZE_H__ */
+1 -72
tools/virtio/linux/virtio.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef LINUX_VIRTIO_H 3 - #define LINUX_VIRTIO_H 4 - #include <linux/scatterlist.h> 5 - #include <linux/kernel.h> 6 - #include <linux/spinlock.h> 7 - 8 - struct device { 9 - void *parent; 10 - }; 11 - 12 - struct virtio_device { 13 - struct device dev; 14 - u64 features; 15 - struct list_head vqs; 16 - spinlock_t vqs_list_lock; 17 - const struct virtio_config_ops *config; 18 - }; 19 - 20 - struct virtqueue { 21 - struct list_head list; 22 - void (*callback)(struct virtqueue *vq); 23 - const char *name; 24 - struct virtio_device *vdev; 25 - unsigned int index; 26 - unsigned int num_free; 27 - unsigned int num_max; 28 - void *priv; 29 - bool reset; 30 - }; 31 - 32 - /* Interfaces exported by virtio_ring. */ 33 - int virtqueue_add_sgs(struct virtqueue *vq, 34 - struct scatterlist *sgs[], 35 - unsigned int out_sgs, 36 - unsigned int in_sgs, 37 - void *data, 38 - gfp_t gfp); 39 - 40 - int virtqueue_add_outbuf(struct virtqueue *vq, 41 - struct scatterlist sg[], unsigned int num, 42 - void *data, 43 - gfp_t gfp); 44 - 45 - int virtqueue_add_inbuf(struct virtqueue *vq, 46 - struct scatterlist sg[], unsigned int num, 47 - void *data, 48 - gfp_t gfp); 49 - 50 - bool virtqueue_kick(struct virtqueue *vq); 51 - 52 - void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len); 53 - 54 - void virtqueue_disable_cb(struct virtqueue *vq); 55 - 56 - bool virtqueue_enable_cb(struct virtqueue *vq); 57 - bool virtqueue_enable_cb_delayed(struct virtqueue *vq); 58 - 59 - void *virtqueue_detach_unused_buf(struct virtqueue *vq); 60 - struct virtqueue *vring_new_virtqueue(unsigned int index, 61 - unsigned int num, 62 - unsigned int vring_align, 63 - struct virtio_device *vdev, 64 - bool weak_barriers, 65 - bool ctx, 66 - void *pages, 67 - bool (*notify)(struct virtqueue *vq), 68 - void (*callback)(struct virtqueue *vq), 69 - const char *name); 70 - void vring_del_virtqueue(struct virtqueue *vq); 71 - 72 - #endif 1 + #include <../../include/linux/virtio.h>
+1 -101
tools/virtio/linux/virtio_config.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef LINUX_VIRTIO_CONFIG_H 3 - #define LINUX_VIRTIO_CONFIG_H 4 - #include <linux/virtio_byteorder.h> 5 - #include <linux/virtio.h> 6 - #include <uapi/linux/virtio_config.h> 7 - 8 - struct virtio_config_ops { 9 - int (*disable_vq_and_reset)(struct virtqueue *vq); 10 - int (*enable_vq_after_reset)(struct virtqueue *vq); 11 - }; 12 - 13 - /* 14 - * __virtio_test_bit - helper to test feature bits. For use by transports. 15 - * Devices should normally use virtio_has_feature, 16 - * which includes more checks. 17 - * @vdev: the device 18 - * @fbit: the feature bit 19 - */ 20 - static inline bool __virtio_test_bit(const struct virtio_device *vdev, 21 - unsigned int fbit) 22 - { 23 - return vdev->features & (1ULL << fbit); 24 - } 25 - 26 - /** 27 - * __virtio_set_bit - helper to set feature bits. For use by transports. 28 - * @vdev: the device 29 - * @fbit: the feature bit 30 - */ 31 - static inline void __virtio_set_bit(struct virtio_device *vdev, 32 - unsigned int fbit) 33 - { 34 - vdev->features |= (1ULL << fbit); 35 - } 36 - 37 - /** 38 - * __virtio_clear_bit - helper to clear feature bits. For use by transports. 39 - * @vdev: the device 40 - * @fbit: the feature bit 41 - */ 42 - static inline void __virtio_clear_bit(struct virtio_device *vdev, 43 - unsigned int fbit) 44 - { 45 - vdev->features &= ~(1ULL << fbit); 46 - } 47 - 48 - #define virtio_has_feature(dev, feature) \ 49 - (__virtio_test_bit((dev), feature)) 50 - 51 - /** 52 - * virtio_has_dma_quirk - determine whether this device has the DMA quirk 53 - * @vdev: the device 54 - */ 55 - static inline bool virtio_has_dma_quirk(const struct virtio_device *vdev) 56 - { 57 - /* 58 - * Note the reverse polarity of the quirk feature (compared to most 59 - * other features), this is for compatibility with legacy systems. 60 - */ 61 - return !virtio_has_feature(vdev, VIRTIO_F_ACCESS_PLATFORM); 62 - } 63 - 64 - static inline bool virtio_is_little_endian(struct virtio_device *vdev) 65 - { 66 - return virtio_has_feature(vdev, VIRTIO_F_VERSION_1) || 67 - virtio_legacy_is_little_endian(); 68 - } 69 - 70 - /* Memory accessors */ 71 - static inline u16 virtio16_to_cpu(struct virtio_device *vdev, __virtio16 val) 72 - { 73 - return __virtio16_to_cpu(virtio_is_little_endian(vdev), val); 74 - } 75 - 76 - static inline __virtio16 cpu_to_virtio16(struct virtio_device *vdev, u16 val) 77 - { 78 - return __cpu_to_virtio16(virtio_is_little_endian(vdev), val); 79 - } 80 - 81 - static inline u32 virtio32_to_cpu(struct virtio_device *vdev, __virtio32 val) 82 - { 83 - return __virtio32_to_cpu(virtio_is_little_endian(vdev), val); 84 - } 85 - 86 - static inline __virtio32 cpu_to_virtio32(struct virtio_device *vdev, u32 val) 87 - { 88 - return __cpu_to_virtio32(virtio_is_little_endian(vdev), val); 89 - } 90 - 91 - static inline u64 virtio64_to_cpu(struct virtio_device *vdev, __virtio64 val) 92 - { 93 - return __virtio64_to_cpu(virtio_is_little_endian(vdev), val); 94 - } 95 - 96 - static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val) 97 - { 98 - return __cpu_to_virtio64(virtio_is_little_endian(vdev), val); 99 - } 100 - 101 - #endif 1 + #include "../../include/linux/virtio_config.h"
+10
tools/virtio/oot-stubs.h
··· 1 + #include <linux/bug.h> 2 + #include <linux/string.h> 3 + #include <linux/virtio_features.h> 4 + 5 + #ifndef VIRTIO_FEATURES_BITS 6 + #define VIRTIO_FEATURES_BITS 128 7 + #endif 8 + #ifndef VIRTIO_U64 9 + #define VIRTIO_U64(b) ((b) >> 6) 10 + #endif