Skip to content

Commit

Permalink
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/gi…
Browse files Browse the repository at this point in the history
…t/mst/vhost

Pull virtio tests and fixes from Michael Tsirkin:
 "This fixes existing tests broken by barrier rework, and adds some new
  tests.

  Plus, there's a fix for an old bug in virtio-pci"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
  tools/virtio: add ringtest utilities
  sh: fix smp_store_mb for !SMP
  tools/virtio: use virt_xxx barriers
  virtio_pci: fix use after free on release
  • Loading branch information
torvalds committed Jan 27, 2016
2 parents 075356c + 481eaec commit 03c21cb
Show file tree
Hide file tree
Showing 13 changed files with 1,148 additions and 10 deletions.
1 change: 0 additions & 1 deletion arch/sh/include/asm/barrier.h
Expand Up @@ -33,7 +33,6 @@
#endif

#define __smp_store_mb(var, value) do { (void)xchg(&var, value); } while (0)
#define smp_store_mb(var, value) __smp_store_mb(var, value)

#include <asm-generic/barrier.h>

Expand Down
2 changes: 2 additions & 0 deletions drivers/virtio/virtio_pci_common.c
Expand Up @@ -545,6 +545,7 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
static void virtio_pci_remove(struct pci_dev *pci_dev)
{
struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
struct device *dev = get_device(&vp_dev->vdev.dev);

unregister_virtio_device(&vp_dev->vdev);

Expand All @@ -554,6 +555,7 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
virtio_pci_modern_remove(vp_dev);

pci_disable_device(pci_dev);
put_device(dev);
}

static struct pci_driver virtio_pci_driver = {
Expand Down
22 changes: 13 additions & 9 deletions tools/virtio/asm/barrier.h
@@ -1,15 +1,19 @@
#if defined(__i386__) || defined(__x86_64__)
#define barrier() asm volatile("" ::: "memory")
#define mb() __sync_synchronize()

#define smp_mb() mb()
# define dma_rmb() barrier()
# define dma_wmb() barrier()
# define smp_rmb() barrier()
# define smp_wmb() barrier()
#define virt_mb() __sync_synchronize()
#define virt_rmb() barrier()
#define virt_wmb() barrier()
/* Atomic store should be enough, but gcc generates worse code in that case. */
#define virt_store_mb(var, value) do { \
typeof(var) virt_store_mb_value = (value); \
__atomic_exchange(&(var), &virt_store_mb_value, &virt_store_mb_value, \
__ATOMIC_SEQ_CST); \
barrier(); \
} while (0);
/* Weak barriers should be used. If not - it's a bug */
# define rmb() abort()
# define wmb() abort()
# define mb() abort()
# define rmb() abort()
# define wmb() abort()
#else
#error Please fill in barrier macros
#endif
Expand Down
9 changes: 9 additions & 0 deletions tools/virtio/linux/compiler.h
@@ -0,0 +1,9 @@
#ifndef LINUX_COMPILER_H
#define LINUX_COMPILER_H

#define WRITE_ONCE(var, val) \
(*((volatile typeof(val) *)(&(var))) = (val))

#define READ_ONCE(var) (*((volatile typeof(val) *)(&(var))))

#endif
1 change: 1 addition & 0 deletions tools/virtio/linux/kernel.h
Expand Up @@ -8,6 +8,7 @@
#include <assert.h>
#include <stdarg.h>

#include <linux/compiler.h>
#include <linux/types.h>
#include <linux/printk.h>
#include <linux/bug.h>
Expand Down
22 changes: 22 additions & 0 deletions tools/virtio/ringtest/Makefile
@@ -0,0 +1,22 @@
all:

all: ring virtio_ring_0_9 virtio_ring_poll

CFLAGS += -Wall
CFLAGS += -pthread -O2 -ggdb
LDFLAGS += -pthread -O2 -ggdb

main.o: main.c main.h
ring.o: ring.c main.h
virtio_ring_0_9.o: virtio_ring_0_9.c main.h
virtio_ring_poll.o: virtio_ring_poll.c virtio_ring_0_9.c main.h
ring: ring.o main.o
virtio_ring_0_9: virtio_ring_0_9.o main.o
virtio_ring_poll: virtio_ring_poll.o main.o
clean:
-rm main.o
-rm ring.o ring
-rm virtio_ring_0_9.o virtio_ring_0_9
-rm virtio_ring_poll.o virtio_ring_poll

.PHONY: all clean
2 changes: 2 additions & 0 deletions tools/virtio/ringtest/README
@@ -0,0 +1,2 @@
Partial implementation of various ring layouts, useful to tune virtio design.
Uses shared memory heavily.

0 comments on commit 03c21cb

Please sign in to comment.