diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-18 23:50:30 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-18 23:50:30 -0500 |
| commit | 64ec45bff6b3dade2643ed4c0f688a15ecf46ea2 (patch) | |
| tree | 29816f500d80a64c84455778918d94ff3ddf02e4 /include/linux | |
| parent | c0f486fde3f353232c1cc2fd4d62783ac782a467 (diff) | |
| parent | 5ff16110c637726111662c1df41afd9df7ef36bd (diff) | |
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio fixes from Michael S Tsirkin:
"virtio 1.0 related fixes
Most importantly, this fixes using virtio_pci as a module.
Further, the big virtio 1.0 conversion missed a couple of places.
This fixes them up.
This isn't 100% sparse-clean yet because on many architectures
get_user triggers sparse warnings when used with __bitwise tag (when
same tag is on both pointer and value read).
I posted a patchset to fix it up by adding __force on all arches that
don't already have it (many do), when that's merged these warnings
will go away"
* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
virtio_pci: restore module attributes
mic/host: fix up virtio 1.0 APIs
vringh: update for virtio 1.0 APIs
vringh: 64 bit features
tools/virtio: add virtio 1.0 in vringh_test
tools/virtio: add virtio 1.0 in virtio_test
tools/virtio: enable -Werror
tools/virtio: 64 bit features
tools/virtio: fix vringh test
tools/virtio: more stubs
virtio: core support for config generation
virtio_pci: add VIRTIO_PCI_NO_LEGACY
virtio_pci: move probe to common file
virtio_pci_common.h: drop VIRTIO_PCI_NO_LEGACY
virtio_config: fix virtio_cread_bytes
virtio: set VIRTIO_CONFIG_S_FEATURES_OK on restore
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/virtio_config.h | 29 | ||||
| -rw-r--r-- | include/linux/vringh.h | 37 |
2 files changed, 63 insertions, 3 deletions
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 7979f850e7ac..ca3ed78e5ec7 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h | |||
| @@ -19,6 +19,9 @@ | |||
| 19 | * offset: the offset of the configuration field | 19 | * offset: the offset of the configuration field |
| 20 | * buf: the buffer to read the field value from. | 20 | * buf: the buffer to read the field value from. |
| 21 | * len: the length of the buffer | 21 | * len: the length of the buffer |
| 22 | * @generation: config generation counter | ||
| 23 | * vdev: the virtio_device | ||
| 24 | * Returns the config generation counter | ||
| 22 | * @get_status: read the status byte | 25 | * @get_status: read the status byte |
| 23 | * vdev: the virtio_device | 26 | * vdev: the virtio_device |
| 24 | * Returns the status byte | 27 | * Returns the status byte |
| @@ -60,6 +63,7 @@ struct virtio_config_ops { | |||
| 60 | void *buf, unsigned len); | 63 | void *buf, unsigned len); |
| 61 | void (*set)(struct virtio_device *vdev, unsigned offset, | 64 | void (*set)(struct virtio_device *vdev, unsigned offset, |
| 62 | const void *buf, unsigned len); | 65 | const void *buf, unsigned len); |
| 66 | u32 (*generation)(struct virtio_device *vdev); | ||
| 63 | u8 (*get_status)(struct virtio_device *vdev); | 67 | u8 (*get_status)(struct virtio_device *vdev); |
| 64 | void (*set_status)(struct virtio_device *vdev, u8 status); | 68 | void (*set_status)(struct virtio_device *vdev, u8 status); |
| 65 | void (*reset)(struct virtio_device *vdev); | 69 | void (*reset)(struct virtio_device *vdev); |
| @@ -301,11 +305,33 @@ static inline u8 virtio_cread8(struct virtio_device *vdev, unsigned int offset) | |||
| 301 | return ret; | 305 | return ret; |
| 302 | } | 306 | } |
| 303 | 307 | ||
| 308 | /* Read @count fields, @bytes each. */ | ||
| 309 | static inline void __virtio_cread_many(struct virtio_device *vdev, | ||
| 310 | unsigned int offset, | ||
| 311 | void *buf, size_t count, size_t bytes) | ||
| 312 | { | ||
| 313 | u32 old, gen = vdev->config->generation ? | ||
| 314 | vdev->config->generation(vdev) : 0; | ||
| 315 | int i; | ||
| 316 | |||
| 317 | do { | ||
| 318 | old = gen; | ||
| 319 | |||
| 320 | for (i = 0; i < count; i++) | ||
| 321 | vdev->config->get(vdev, offset + bytes * i, | ||
| 322 | buf + i * bytes, bytes); | ||
| 323 | |||
| 324 | gen = vdev->config->generation ? | ||
| 325 | vdev->config->generation(vdev) : 0; | ||
| 326 | } while (gen != old); | ||
| 327 | } | ||
| 328 | |||
| 329 | |||
| 304 | static inline void virtio_cread_bytes(struct virtio_device *vdev, | 330 | static inline void virtio_cread_bytes(struct virtio_device *vdev, |
| 305 | unsigned int offset, | 331 | unsigned int offset, |
| 306 | void *buf, size_t len) | 332 | void *buf, size_t len) |
| 307 | { | 333 | { |
| 308 | vdev->config->get(vdev, offset, buf, len); | 334 | __virtio_cread_many(vdev, offset, buf, len, 1); |
| 309 | } | 335 | } |
| 310 | 336 | ||
| 311 | static inline void virtio_cwrite8(struct virtio_device *vdev, | 337 | static inline void virtio_cwrite8(struct virtio_device *vdev, |
| @@ -349,6 +375,7 @@ static inline u64 virtio_cread64(struct virtio_device *vdev, | |||
| 349 | { | 375 | { |
| 350 | u64 ret; | 376 | u64 ret; |
| 351 | vdev->config->get(vdev, offset, &ret, sizeof(ret)); | 377 | vdev->config->get(vdev, offset, &ret, sizeof(ret)); |
| 378 | __virtio_cread_many(vdev, offset, &ret, 1, sizeof(ret)); | ||
| 352 | return virtio64_to_cpu(vdev, (__force __virtio64)ret); | 379 | return virtio64_to_cpu(vdev, (__force __virtio64)ret); |
| 353 | } | 380 | } |
| 354 | 381 | ||
diff --git a/include/linux/vringh.h b/include/linux/vringh.h index 749cde28728b..a3fa537e717a 100644 --- a/include/linux/vringh.h +++ b/include/linux/vringh.h | |||
| @@ -24,12 +24,16 @@ | |||
| 24 | #ifndef _LINUX_VRINGH_H | 24 | #ifndef _LINUX_VRINGH_H |
| 25 | #define _LINUX_VRINGH_H | 25 | #define _LINUX_VRINGH_H |
| 26 | #include <uapi/linux/virtio_ring.h> | 26 | #include <uapi/linux/virtio_ring.h> |
| 27 | #include <linux/virtio_byteorder.h> | ||
| 27 | #include <linux/uio.h> | 28 | #include <linux/uio.h> |
| 28 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
| 29 | #include <asm/barrier.h> | 30 | #include <asm/barrier.h> |
| 30 | 31 | ||
| 31 | /* virtio_ring with information needed for host access. */ | 32 | /* virtio_ring with information needed for host access. */ |
| 32 | struct vringh { | 33 | struct vringh { |
| 34 | /* Everything is little endian */ | ||
| 35 | bool little_endian; | ||
| 36 | |||
| 33 | /* Guest publishes used event idx (note: we always do). */ | 37 | /* Guest publishes used event idx (note: we always do). */ |
| 34 | bool event_indices; | 38 | bool event_indices; |
| 35 | 39 | ||
| @@ -105,7 +109,7 @@ struct vringh_kiov { | |||
| 105 | #define VRINGH_IOV_ALLOCATED 0x8000000 | 109 | #define VRINGH_IOV_ALLOCATED 0x8000000 |
| 106 | 110 | ||
| 107 | /* Helpers for userspace vrings. */ | 111 | /* Helpers for userspace vrings. */ |
| 108 | int vringh_init_user(struct vringh *vrh, u32 features, | 112 | int vringh_init_user(struct vringh *vrh, u64 features, |
| 109 | unsigned int num, bool weak_barriers, | 113 | unsigned int num, bool weak_barriers, |
| 110 | struct vring_desc __user *desc, | 114 | struct vring_desc __user *desc, |
| 111 | struct vring_avail __user *avail, | 115 | struct vring_avail __user *avail, |
| @@ -167,7 +171,7 @@ bool vringh_notify_enable_user(struct vringh *vrh); | |||
| 167 | void vringh_notify_disable_user(struct vringh *vrh); | 171 | void vringh_notify_disable_user(struct vringh *vrh); |
| 168 | 172 | ||
| 169 | /* Helpers for kernelspace vrings. */ | 173 | /* Helpers for kernelspace vrings. */ |
| 170 | int vringh_init_kern(struct vringh *vrh, u32 features, | 174 | int vringh_init_kern(struct vringh *vrh, u64 features, |
| 171 | unsigned int num, bool weak_barriers, | 175 | unsigned int num, bool weak_barriers, |
| 172 | struct vring_desc *desc, | 176 | struct vring_desc *desc, |
| 173 | struct vring_avail *avail, | 177 | struct vring_avail *avail, |
| @@ -222,4 +226,33 @@ static inline void vringh_notify(struct vringh *vrh) | |||
| 222 | vrh->notify(vrh); | 226 | vrh->notify(vrh); |
| 223 | } | 227 | } |
| 224 | 228 | ||
| 229 | static inline u16 vringh16_to_cpu(const struct vringh *vrh, __virtio16 val) | ||
| 230 | { | ||
| 231 | return __virtio16_to_cpu(vrh->little_endian, val); | ||
| 232 | } | ||
| 233 | |||
| 234 | static inline __virtio16 cpu_to_vringh16(const struct vringh *vrh, u16 val) | ||
| 235 | { | ||
| 236 | return __cpu_to_virtio16(vrh->little_endian, val); | ||
| 237 | } | ||
| 238 | |||
| 239 | static inline u32 vringh32_to_cpu(const struct vringh *vrh, __virtio32 val) | ||
| 240 | { | ||
| 241 | return __virtio32_to_cpu(vrh->little_endian, val); | ||
| 242 | } | ||
| 243 | |||
| 244 | static inline __virtio32 cpu_to_vringh32(const struct vringh *vrh, u32 val) | ||
| 245 | { | ||
| 246 | return __cpu_to_virtio32(vrh->little_endian, val); | ||
| 247 | } | ||
| 248 | |||
| 249 | static inline u64 vringh64_to_cpu(const struct vringh *vrh, __virtio64 val) | ||
| 250 | { | ||
| 251 | return __virtio64_to_cpu(vrh->little_endian, val); | ||
| 252 | } | ||
| 253 | |||
| 254 | static inline __virtio64 cpu_to_vringh64(const struct vringh *vrh, u64 val) | ||
| 255 | { | ||
| 256 | return __cpu_to_virtio64(vrh->little_endian, val); | ||
| 257 | } | ||
| 225 | #endif /* _LINUX_VRINGH_H */ | 258 | #endif /* _LINUX_VRINGH_H */ |
