lguest: fix paths in comments

After commit 07fe997, lguest tool has already moved from
Documentation/virtual/lguest/ to tools/lguest/.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
virtio-scsi: use pr_err() instead of printk()

Convert the virtio-scsi driver to use pr_err() instead of printk().

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
virtio-blk: emit udev event when device is resized

When virtio-blk device is resized from host (using block_resize from QEMU) emit
KOBJ_CHANGE uevent to notify guest about such change. This allows user to have
custom udev rules which would take whatever action if such event occurs. As a
proof of concept I've created simple udev rule that automatically resize
filesystem on virtio-blk device.

ACTION=="change", KERNEL=="vd*", \
        ENV{RESIZE}=="1", \
        ENV{ID_FS_TYPE}=="ext[3-4]", \
        RUN+="/sbin/resize2fs /dev/%k"
ACTION=="change", KERNEL=="vd*", \
        ENV{RESIZE}=="1", \
        ENV{ID_FS_TYPE}=="LVM2_member", \
        RUN+="/sbin/pvresize /dev/%k"

Signed-off-by: Milos Vyletel <milos.vyletel@sde.cz>
Tested-by: Asias He <asias@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (minor simplification)
Remove Documentation/virtual/virtio-spec.txt

We haven't been keeping it in sync, so just remove it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
CONFIG_SYMBOL_PREFIX: cleanup.

We have CONFIG_SYMBOL_PREFIX, which three archs define to the string
"_".  But Al Viro broke this in "consolidate cond_syscall and
SYSCALL_ALIAS declarations" (in linux-next), and he's not the first to
do so.

Using CONFIG_SYMBOL_PREFIX is awkward, since we usually just want to
prefix it so something.  So various places define helpers which are
defined to nothing if CONFIG_SYMBOL_PREFIX isn't set:

1) include/asm-generic/unistd.h defines __SYMBOL_PREFIX.
2) include/asm-generic/vmlinux.lds.h defines VMLINUX_SYMBOL(sym)
3) include/linux/export.h defines MODULE_SYMBOL_PREFIX.
4) include/linux/kernel.h defines SYMBOL_PREFIX (which differs from #7)
5) kernel/modsign_certificate.S defines ASM_SYMBOL(sym)
6) scripts/modpost.c defines MODULE_SYMBOL_PREFIX
7) scripts/Makefile.lib defines SYMBOL_PREFIX on the commandline if
   CONFIG_SYMBOL_PREFIX is set, so that we have a non-string version
   for pasting.

(arch/h8300/include/asm/linkage.h defines SYMBOL_NAME(), too).

Let's solve this properly:
1) No more generic prefix, just CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX.
2) Make linux/export.h usable from asm.
3) Define VMLINUX_SYMBOL() and VMLINUX_SYMBOL_STR().
4) Make everyone use them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Tested-by: James Hogan <james.hogan@imgtec.com> (metag)
Merge branch 'virtio-next' into pending-rebases
Merge branch 'modules-next' into pending-rebases
hw_random: free rng_buffer at module exit

At Thu, 14 Mar 2013 17:11:21 +1030,
Rusty Russell wrote:
>
> Satoru Takeuchi <satoru.takeuchi@gmail.com> writes:
> > Hi Rusty,
> >
> > At Tue, 12 Mar 2013 15:43:33 -0700,
> > Greg Kroah-Hartman wrote:
> >> @@ -307,6 +312,14 @@ int hwrng_register(struct hwrng *rng)
> >>
> >>  	mutex_lock(&rng_mutex);
> >>
> >> +	/* kmalloc makes this safe for virt_to_page() in virtio_rng.c */
> >> +	err = -ENOMEM;
> >> +	if (!rng_buffer) {
> >> +		rng_buffer = kmalloc(rng_buffer_size(), GFP_KERNEL);
> >
> > rng_buffer is now kmalloc-ed, but not kfree-ed. Shoudn't it be kfree-ed
> > at hwrng_unregister()? If my suspect is correct, the same problem is
> > in 3.8.3-rc1 and 3.0.69-rc1. I'm OK to make a patch, but it'll be after
> > some hours.
> >
> > Corecct me if I'm wrong.
>
> Yes, it would be nice to free it, but it really makes sense to free it
> in module_cleanup() (which would have to be written, as the module
> currently doesn't have one).
>
> Cheers,
> Rusty.

From: Satoru Takeuchi <satoru.takeuchi@gmail.com>

rng-core module allocates rng_buffer by kmalloc() since commit
f7f154f1246ccc5a0a7e9ce50932627d60a0c878. But this buffer won't be
freed and there is a memory leak possibility at module exit.

Signed-off-by: Satoru Takeuchi <satoru.takeuchi@gmail.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Matt Mackall <mpm@selenic.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
genksyms: pass symbol-prefix instead of arch

Pass symbol-prefix to genksyms instead of arch, so that the decision
what symbol prefix to use is kept in one place.

Basically genksyms used to take a -a $ARCH argument and it used that to
determine whether to add an underscore symbol prefix. It's now changed
to take a -s $SYMBOL_PREFIX argument so that the caller decides whether
a symbol prefix is required. The build system then uses
CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX to determine whether to pass the
argument.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
module: fix symbol versioning with symbol prefixes

Fix symbol versioning on architectures with symbol prefixes. Although
the build was free from warnings the actual modules still wouldn't load
as the ____versions table contained unprefixed symbol names, which were
being compared against the prefixed symbol names when checking the
symbol versions.

This is fixed by modifying modpost to add the symbol prefix to the
____versions table it outputs (Modules.symvers still contains unprefixed
symbol names). The check_modstruct_version() function is also fixed as
it checks the version of the unprefixed "module_layout" symbol which
would no longer work.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jonathan Kliegman <kliegs@chromium.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (use VMLINUX_SYMBOL_STR)
tools/virtio: fix build for 3.8

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tools/virtio: separate headers more.

This makes them a bit more like the kernel headers, so we can include more
real kernel headers in our tests.

In addition this means that we don't break tools/virtio with the next
patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
virtio_ring: expose virtio barriers for use in vringh.

The host side of ring needs this logic too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
vringh: host-side implementation of virtio rings.

	Changes since v1:
	1) Fix for broken race handling with event indexes.
	2) Fix backward vringh_notify_enable_user / vringh_notify_enable_kern.
	3) iovec/kvec iterators mangle iov/kvec so it's always usable.

Getting use of virtio rings correct is tricky, and a recent patch saw
an implementation of in-kernel rings (as separate from userspace).

This abstracts the business of dealing with the virtio ring layout
from the access (userspace or direct); to do this, we use function
pointers, which gcc inlines correctly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
tools/virtio: add vring_test.

	Changes since v1:
	1) --fast-vringh for testing speed of virtqueue (ie. guest) side.
	2) Various uninitialized stuff caught by valgrind.

This is mainly to test the drivers/vhost/vringh.c code, but it also
uses the drivers/virtio/virtio_ring.c code for the guest side.

Usage for testing the basic implementation:

	./vringh_test
	# Test with indirect descriptors
	./vringh_test --indirect
	# Test with indirect descriptors and event indexex
	./vringh_test --indirect --eventidx

You can run a parallel stress test by adding --parallel to any of the
above options.

eg ./vringh_test --parallel:
	Using CPUS 0 and 3
	Guest: notified 10107974, pinged 107970
	Host: notified 108158, pinged 3172148

./vringh_test --indirect --eventidx --parallel:
	Using CPUS 0 and 3
	Guest: notified 156357, pinged 156251
	Host: notified 156251, pinged 78179

Average of 50 times doing ./vringh_test --indirect --eventidx --parallel:
	2.840000-3.040000(2.927292)user

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
vhost: don't use access_ok().

It doesn't do anything useful and it adds a *lot* of code.  Just use
normal accessors which is simpler and safer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
vhost: log whole used ring as used when it changes.

If we change the used ring, simply mark the entire region as used.
This is simpler, we're only talking about a few pages, and logging is
a slow path anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
vhost: update writelog from sg list.

vhost needs to log userspace writes which it does, after it has done
them.  Drivers (ie. vhost_net) currently hand pointers down through
vhost_get_vq_desc, which appends output descriptors to a log array
(which is actually contained in the generic vq struct anyway), which
the driver then hands back to vhost_log_write() once it has written
the output.

Since this is a slow path, it's cleaner to hide these details from the
drivers altogether.  Instead, vhost_get_vq_desc makes a copy of the
output iovec (as the caller tends to mangle the original), and then
use that for logging once the descriptor is completed.

This means mapping the descriptor backwards via the memory array, but
it cleanly separates vring handling from logging.

Before any vhost changes (~50 runs):
	$ ./sock_sink -H 192.168.3.2
	host=192.168.3.2 port=7001 options=[]
	145.741000-170.763000(156.382702) MB/sec
	$ ./sock_source
	port=7001 options=[]
	waiting for connection
	accepted
	137.207000-143.335000(140.480609) MB/sec

After: (~50 runs)
	$ ./sock_sink -H 192.168.3.2
	host=192.168.3.2 port=7001 options=[]
	153.056000-174.741000(159.899128) MB/sec
	$ ./sock_source
	port=7001 options=[]
	waiting for connection
	accepted
	126.161000-142.574000(139.890933) MB/sec

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
drivers/vhost: use vringh for backend.

Only noticable difference for users (net.c and tcm_vhost.c) is that the
ring size is in the vringh structure now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

FIXME: RERUN THESE
Before: (~50 runs)
	$ ./sock_sink -H 192.168.3.2
	host=192.168.3.2 port=7001 options=[]
	153.056000-174.741000(159.899128) MB/sec
	$ ./sock_source
	port=7001 options=[]
	waiting for connection
	accepted
	126.161000-142.574000(139.890933) MB/sec

After: (~50 runs)
	$ ./sock_sink -H 192.168.3.2
	host=192.168.3.2 port=7001 options=[]
	155.905000-160.066000(158.122638) MB/sec

	$ ./sock_source
	port=7001 options=[]
	waiting for connection
	accepted
	111.780000-141.044000(137.704087) MB/sec
drivers/vhost: make vhost_enable_notify() return false on failure.

This makes more sense to me, and it's what the virtqueue() equivalent
does (virtqueue_enable_cb), thus what vringh does.

Reported-by: Sjur Brændeland <sjurbren@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>