History log of /net/9p/trans_virtio.c
Revision Date Author Comments
0b36f1adcb5adace6d45ca4d9a0f00860e60d012 20-Mar-2013 Rusty Russell <rusty@rustcorp.com.au> 9p/trans_virtio.c: use virtio_add_sgs[]

virtio_add_buf() is going away, replaced with virtio_add_sgs() which
takes multiple terminated scatterlists.

Cc: Eric Van Hensbergen <ericvh@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
dc893e19b5800d7743fb58235877bfa9091805ff 08-Mar-2013 Arnd Bergmann <arnd@arndb.de> Revert parts of "hlist: drop the node parameter from iterators"

Commit b67bfe0d42ca ("hlist: drop the node parameter from iterators")
did a lot of nice changes but also contains two small hunks that seem to
have slipped in accidentally and have no apparent connection to the
intent of the patch.

This reverts the two extraneous changes.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Peter Senna Tschudin <peter.senna@gmail.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
b67bfe0d42cac56c512dd5da4b1b347a23f4b70a 28-Feb-2013 Sasha Levin <sasha.levin@oracle.com> hlist: drop the node parameter from iterators

I'm not sure why, but the hlist for each entry iterators were conceived

list_for_each_entry(pos, head, member)

The hlist ones were greedy and wanted an extra parameter:

hlist_for_each_entry(tpos, pos, head, member)

Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.

Besides the semantic patch, there was some manual work required:

- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.

The semantic patch which is mostly the work of Peter Senna Tschudin is here:

@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;

type T;
expression a,c,d,e;
identifier b;
statement S;
@@

-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>

[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
7293bfba03e8283e29558c20aee279642f619c43 23-Feb-2013 Zhang Yanfei <zhangyanfei@cn.fujitsu.com> net: change type of virtio_chan->p9_max_pages

This member of struct virtio_chan is calculated from nr_free_buffer_pages
so change its type to unsigned long in case of overflow.

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Cc: David Miller <davem@davemloft.net>
Cc: Eric Van Hensbergen <ericvh@gmail.com>
Cc: Ron Minnich <rminnich@sandia.gov>
Cc: Latchesar Ionkov <lucho@ionkov.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
b9cdc88df8e63e81c723b82c286fc97f5d0dc325 19-Oct-2012 Will Deacon <will.deacon@arm.com> virtio: 9p: correctly pass physical address to userspace for high pages

When using a virtio transport, the 9p net device may pass the physical
address of a kernel buffer to userspace via a scatterlist inside a
virtqueue. If the kernel buffer is mapped outside of the linear mapping
(e.g. highmem), then virt_to_page will return a bogus value and we will
populate the scatterlist with junk.

This patch uses kmap_to_page when populating the page array for a kernel
buffer.

Cc: stable@kernel.org
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2c53040f018b6c36a46eec75b9b937aaa5f78e6d 10-Jul-2012 Ben Hutchings <bhutchings@solarflare.com> net: Fix (nearly-)kernel-doc comments for various functions

Fix incorrect start markers, wrapped summary lines, missing section
breaks, incorrect separators, and some name mismatches.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
5fcb08befaf57faa1b00e514915c1660252b8c26 11-Jun-2012 Sasha Levin <levinsasha928@gmail.com> 9p: BUG before corrupting memory

The BUG_ON() in pack_sg_list() would get triggered only one time after we've
corrupted some memory by sg_set_buf() into an invalid sg buffer.

I'm still working on figuring out why I manage to trigger that bug...

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
991ad9ec39bd3ecaf08cfb7ea3ef7ae9148e5068 13-Apr-2012 Sasha Levin <levinsasha928@gmail.com> 9p: disconnect channel when PCI device is removed

When a virtio_9p pci device is being removed, we should close down any
active channels and free up resources, we're not supposed to BUG() if there's
still an open channel since it's a valid case when removing the PCI device.

Otherwise, removing the PCI device with an open channel would cause the
following BUG():

[ 1184.671416] ------------[ cut here ]------------
[ 1184.672057] kernel BUG at net/9p/trans_virtio.c:618!
[ 1184.672057] invalid opcode: 0000 [#1] PREEMPT SMP
[ 1184.672057] CPU 3
[ 1184.672057] Pid: 5, comm: kworker/u:0 Tainted: G W 3.4.0-rc2-next-20120413-sasha-dirty #76
[ 1184.672057] RIP: 0010:[<ffffffff825c9116>] [<ffffffff825c9116>] p9_virtio_remove+0x16/0x90
[ 1184.672057] RSP: 0018:ffff88000d653ac0 EFLAGS: 00010202
[ 1184.672057] RAX: ffffffff836bfb40 RBX: ffff88000c9b2148 RCX: ffff88000d658978
[ 1184.672057] RDX: 0000000000000006 RSI: 0000000000000000 RDI: ffff880028868000
[ 1184.672057] RBP: ffff88000d653ad0 R08: 0000000000000000 R09: 0000000000000000
[ 1184.672057] R10: 0000000000000000 R11: 0000000000000001 R12: ffff880028868000
[ 1184.672057] R13: ffffffff835aa7c0 R14: ffff880041630000 R15: ffff88000d653da0
[ 1184.672057] FS: 0000000000000000(0000) GS:ffff880035a00000(0000) knlGS:0000000000000000
[ 1184.672057] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[ 1184.672057] CR2: 0000000001181000 CR3: 000000000eba1000 CR4: 00000000000406e0
[ 1184.672057] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
x000000000117a190 *[ 1184.672057] DR3: 00000000000000**
00 DR6: 00000000ffff0ff0 DR7: 0000000000000400
[ 1184.672057] Process kworker/u:0 (pid: 5, threadinfo ffff88000d652000, task ffff88000d658000)
[ 1184.672057] Stack:
[ 1184.672057] ffff880028868000 ffffffff836bfb40 ffff88000d653af0 ffffffff8193661b
[ 1184.672057] ffff880028868008 ffffffff836bfb40 ffff88000d653b10 ffffffff81af1c81
[ 1184.672057] ffff880028868068 ffff880028868008 ffff88000d653b30 ffffffff81af257a
[ 1184.795301] Call Trace:
[ 1184.795301] [<ffffffff8193661b>] virtio_dev_remove+0x1b/0x60
[ 1184.795301] [<ffffffff81af1c81>] __device_release_driver+0x81/0xd0
[ 1184.795301] [<ffffffff81af257a>] device_release_driver+0x2a/0x40
[ 1184.795301] [<ffffffff81af0d48>] bus_remove_device+0x138/0x150
[ 1184.795301] [<ffffffff81aef08d>] device_del+0x14d/0x1b0
[ 1184.795301] [<ffffffff81aef138>] device_unregister+0x48/0x60
[ 1184.795301] [<ffffffff8193694d>] unregister_virtio_device+0xd/0x10
[ 1184.795301] [<ffffffff8265fc74>] virtio_pci_remove+0x2a/0x6c
[ 1184.795301] [<ffffffff818a95ad>] pci_device_remove+0x4d/0x110
[ 1184.795301] [<ffffffff81af1c81>] __device_release_driver+0x81/0xd0
[ 1184.795301] [<ffffffff81af257a>] device_release_driver+0x2a/0x40
[ 1184.795301] [<ffffffff81af0d48>] bus_remove_device+0x138/0x150
[ 1184.795301] [<ffffffff81aef08d>] device_del+0x14d/0x1b0
[ 1184.795301] [<ffffffff81aef138>] device_unregister+0x48/0x60
[ 1184.795301] [<ffffffff818a36fa>] pci_stop_bus_device+0x6a/0x90
[ 1184.795301] [<ffffffff818a3791>] pci_stop_and_remove_bus_device+0x11/0x20
[ 1184.795301] [<ffffffff818c21d9>] remove_callback+0x9/0x10
[ 1184.795301] [<ffffffff81252d91>] sysfs_schedule_callback_work+0x21/0x60
[ 1184.795301] [<ffffffff810cb1a1>] process_one_work+0x281/0x430
[ 1184.795301] [<ffffffff810cb140>] ? process_one_work+0x220/0x430
[ 1184.795301] [<ffffffff81252d70>] ? sysfs_read_file+0x1c0/0x1c0
[ 1184.795301] [<ffffffff810cc613>] worker_thread+0x1f3/0x320
[ 1184.795301] [<ffffffff810cc420>] ? manage_workers.clone.13+0x130/0x130
[ 1184.795301] [<ffffffff810d30b2>] kthread+0xb2/0xc0
[ 1184.795301] [<ffffffff826783f4>] kernel_thread_helper+0x4/0x10
[ 1184.795301] [<ffffffff810deb18>] ? finish_task_switch+0x78/0xf0
[ 1184.795301] [<ffffffff82676574>] ? retint_restore_args+0x13/0x13
[ 1184.795301] [<ffffffff810d3000>] ? kthread_flush_work_fn+0x10/0x10
[ 1184.795301] [<ffffffff826783f0>] ? gs_change+0x13/0x13
[ 1184.795301] Code: c1 9e 0a 00 48 83 c4 08 5b c9 c3 66 2e 0f 1f 84 00 00 00 00 00 55 48 89 e5 41 54 49 89 fc 53 48 8b 9f a8 04 00 00 80 3b 00 74 0a <0f> 0b 0f 1f 84 00 00 00 00 00 48 8b 87 88 04 00 00 ff 50 30 31
[ 1184.795301] RIP [<ffffffff825c9116>] p9_virtio_remove+0x16/0x90
[ 1184.795301] RSP <ffff88000d653ac0>
[ 1184.952618] ---[ end trace a307b3ed40206b4c ]---

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
f96fde41f7f9af6cf20f6a1919f5d9670f84d574 12-Jan-2012 Rusty Russell <rusty@rustcorp.com.au> virtio: rename virtqueue_add_buf_gfp to virtqueue_add_buf

Remove wrapper functions. This makes the allocation type explicit in
all callers; I used GPF_KERNEL where it seemed obvious, left it at
GFP_ATOMIC otherwise.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Christoph Hellwig <hch@lst.de>
5d3851530d6d68564e4e0ce04d0547d4d106fc72 28-Nov-2011 Joe Perches <joe@perches.com> 9p: Reduce object size with CONFIG_NET_9P_DEBUG

Reduce object size by deduplicating formats.

Use vsprintf extension %pV.
Rename P9_DPRINTK uses to p9_debug, align arguments.
Add function for _p9_debug and macro to add __func__.
Add missing "\n"s to p9_debug uses.
Remove embedded function names as p9_debug adds it.
Remove P9_EPRINTK macro and convert use to pr_<level>.
Add and use pr_fmt and pr_<level>.

$ size fs/9p/built-in.o*
text data bss dec hex filename
62133 984 16000 79117 1350d fs/9p/built-in.o.new
67342 984 16928 85254 14d06 fs/9p/built-in.o.old
$ size net/9p/built-in.o*
text data bss dec hex filename
88792 4148 22024 114964 1c114 net/9p/built-in.o.new
94072 4148 23232 121452 1da6c net/9p/built-in.o.old

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
abfa034e4b8ed0046fa589769e9840af645bc4ba 16-Aug-2011 Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> fs/9p: Update zero-copy implementation in 9p

* remove lot of update to different data structure
* add a seperate callback for zero copy request.
* above makes non zero copy code path simpler
* remove conditionalizing TREAD/TREADDIR/TWRITE in the zero copy path
* Fix the dotu p9_check_errors with zero copy. Add sufficient doc around
* Add support for both in and output buffers in zero copy callback
* pin and unpin pages in the same context
* use helpers instead of defining page offset and rest of page ourself
* Fix mem leak in p9_check_errors
* Remove 'E' and 'F' in p9pdu_vwritef

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
b49d8b5d7007a673796f3f99688b46931293873e 17-Aug-2011 Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> net/9p: Fix kernel crash with msize 512K

With msize equal to 512K (PAGE_SIZE * VIRTQUEUE_NUM), we hit multiple
crashes. This patch fix those.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
7f781679dd596c8abde8336b4d0d166d6a4aad04 01-Jul-2011 jvrao <jvrao@linux.vnet.ibm.com> VirtIO can transfer VIRTQUEUE_NUM of pages.

Signed-off-by: Venkateswararao Jujjuri "<jvrao@linux.vnet.ibm.com>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
114e6f3a5ede73d5b56e145f04680c61c3dd67c4 01-Jul-2011 jvrao <jvrao@linux.vnet.ibm.com> Fix the size of receive buffer packing onto VirtIO ring.

Signed-off-by: Venkateswararao Jujjuri "<jvrao@linux.vnet.ibm.com>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
bd8c8ade6b6f109bc3dce14a8d12013f27f2a590 24-Mar-2011 Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> 9p: Fix sparse error

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
68da9ba4eeadae86ad42e52b80822fbd56971267 18-Mar-2011 Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com> [net/9p]: Introduce basic flow-control for VirtIO transport.

Recent zerocopy work in the 9P VirtIO transport maps and pins
user buffers into kernel memory for the server to work on them.
Since the user process can initiate this kind of pinning with a simple
read/write call, thousands of IO threads initiated by the user process can
hog the system resources and could result into denial of service.

This patch introduces flow control to avoid that extreme scenario.

The ceiling limit to avoid denial of service attacks is set to relatively
high (nr_free_pagecache_pages()/4) so that it won't interfere with
regular usage, but can step in extreme cases to limit the total system
hang. Since we don't have a global structure to accommodate this variable,
I choose the virtio_chan as the home for this.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Reviewed-by: Badari Pulavarty <pbadari@us.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
316ad5501c2098cb2a2a25ed77a0421f1671411c 14-Mar-2011 Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com> [net/9p] Don't re-pin pages on retrying virtqueue_add_buf().

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
a01a984035ea799b14aa5e874dcaeb122f09c4b4 14-Mar-2011 Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com> [net/9p] Set the condition just before waking up.

Given that the sprious wake-ups are common, we need to move the
condition setting right next to the wake_up(). After setting the condition
to req->status = REQ_STATUS_RCVD, sprious wakeups may cause the
virtqueue back on the free list for someone else to use.
This may result in kernel panic while relasing the pinned pages
in p9_release_req_pages().

Also rearranged the while loop in req_done() for better redability.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
53bda3e5b4e91763224ecb7d05dab94d281fd41d 09-Mar-2011 Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com> [net/9p] unconditional wake_up to proc waiting for space on VirtIO ring

Process may wait to get space on VirtIO ring to send a transaction to
VirtFS server. Current code just does a conditional wake_up() which
means only one process will be woken up even if multiple processes
are waiting.

This fix makes the wake_up unconditional. Hence we won't have any
processes waiting for-ever.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
6f69c395cefb26ebba2c9bb725296a3a4a9200ec 06-Feb-2011 Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com> [net/9p] Add preferences to transport layer.

This patch adds preferences field to the p9_trans_module.
Through this, now transport layer can express its preference about the
payload. i.e if payload neds to be part of the PDU or it prefers it
to be sent sepearetly so that the transport layer can handle it in
a better way.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
4038866dab4e461e0ef144458bad9d70ce0c98c1 29-Jan-2011 Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com> [net/9p] Add gup/zero_copy support to VirtIO transport layer.

Modify p9_virtio_request() and req_done() functions to support
additional payload sent down to the transport layer through
tc->pubuf and tc->pkbuf.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
52f44e0d08ff1a065bf06615483c608163575cb1 30-Sep-2010 Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com> net/9p: Add waitq to VirtIO transport.

If there is not enough space for the PDU on the VirtIO ring, current
code returns -EIO propagating the error to user.

This patch introduced a wqit_queue on the channel, and lets the process
wait on this queue until VirtIO ring frees up.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
419b39561e698d73a42f8010655d22e0134486da 30-Sep-2010 Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com> [net/9p]Serialize virtqueue operations to make VirtIO transport SMP safe.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
0b20406cda621c2495d10baab1e87127ceb43337 28-Sep-2010 Sven Eckelmann <sven.eckelmann@gmx.de> net/9p: Mount only matching virtio channels

p9_virtio_create will only compare the the channel's tag characters
against the device name till the end of the channel's tag but not till
the end of the device name. This means that if a user defines channels
with the tags foo and foobar then he would mount foo when he requested
foonot and may mount foo when he requested foobar.

Thus it is necessary to check both string lengths against each other in
case of a successful partial string match.

Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
dc3f5e68f846eec38fb31d78f0b6e83633ad375e 13-Apr-2010 Michael S. Tsirkin <mst@redhat.com> trans_virtio: use virtqueue_xxx wrappers

Switch trans_virtio to new virtqueue_xxx wrappers.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5a0e3ad6af8660be21ca98a971cd00f331318c05 24-Mar-2010 Tejun Heo <tj@kernel.org> include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h

percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.

percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.

http://userweb.kernel.org/~tj/misc/slabh-sweep.py

The script does the followings.

* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.

* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.

* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.

The conversion was done in the following steps.

1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.

2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.

3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.

4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.

5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.

6. percpu.h was updated not to include slab.h.

7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).

* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig

8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.

Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.

Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
86c8437383acd85c05ec7c9a004f59fe7ac9821a 06-Mar-2010 Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> net/9p: Add sysfs mount_tag file for virtio 9P device

This adds a new file for virtio 9P device. The file
contain details of the mount device name that should
be used to mount the 9P file system.

Ex: /sys/devices/virtio-pci/virtio1/mount_tag file now
contian the tag name to be used to mount the 9P file system.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
97ee9b0257402f4731b55dfea42f24d26d793ddf 06-Mar-2010 Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> net/9p: Use the tag name in the config space for identifying mount point

This patch use the tag name in the config space to identify the
mount device. The the virtio device name depend on the enumeration
order of the device and may not remain the same across multiple boots
So we use the tag name which is set via qemu option to uniquely identify
the mount device

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
c1a7c2262035e83a8f70ebe1328b3451702cf51b 15-Feb-2010 Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> net/9p: Handle mount errors correctly.

With this patch we have

# mount -t 9p -o trans=virtio virtio2 /mnt/
# mount -t 9p -o trans=virtio virtio2 /mnt/
mount: virtio2 already mounted or /mnt/ busy
mount: according to mtab, virtio2 is already mounted on /mnt
# mount -t 9p -o trans=virtio virtio3 /mnt/ -o debug=0xfff
mount: special device virtio3 does not exist

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
37c1209d413242d9560e343c040777049a8dd869 15-Feb-2010 Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> net/9p: Remove MAX_9P_CHAN limit

Use a list to track the channel instead of statically
allocated array

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
f75580c4afb72c156746b3fc1ec977b1a85d3dee 15-Feb-2010 Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> net/9p: Add multi channel support.

This is needed for supporting multiple mount points.

We can find out the device names to be used with mount by checking

/sys/devices/virtio-pci/virtio*/device file

if the device file have value 9 then the specific virtio device can
be used for mounting.

ex:
#cat /sys/devices/virtio-pci/virtio1/device
9

now we can mount using
# mount -t 9p -o trans=virtio virtio1 /mnt/

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
fb786100f7c75e154e63d0f5a2982e6d46dfb602 08-Feb-2010 Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> 9p: Fix the kernel crash on a failed mount

The patch fix the crash repoted below

[ 15.149907] BUG: unable to handle kernel NULL pointer dereference at 00000001
[ 15.150806] IP: [<c140b886>] p9_virtio_close+0x18/0x24
.....
....
[ 15.150806] Call Trace:
[ 15.150806] [<c1408e78>] ? p9_client_destroy+0x3f/0x163
[ 15.150806] [<c1409342>] ? p9_client_create+0x25f/0x270
[ 15.150806] [<c1063b72>] ? trace_hardirqs_on+0xb/0xd
[ 15.150806] [<c11ed4e8>] ? match_token+0x64/0x164
[ 15.150806] [<c1175e8d>] ? v9fs_session_init+0x2f1/0x3c8
[ 15.150806] [<c109cfc9>] ? kmem_cache_alloc+0x98/0xb8
[ 15.150806] [<c1063b72>] ? trace_hardirqs_on+0xb/0xd
[ 15.150806] [<c1173dd1>] ? v9fs_get_sb+0x47/0x1e8
[ 15.150806] [<c1173dea>] ? v9fs_get_sb+0x60/0x1e8
[ 15.150806] [<c10a2e77>] ? vfs_kern_mount+0x81/0x11a
[ 15.150806] [<c10a2f55>] ? do_kern_mount+0x33/0xbe
[ 15.150806] [<c10b40b9>] ? do_mount+0x654/0x6b3
[ 15.150806] [<c1038949>] ? do_page_fault+0x0/0x284
[ 15.150806] [<c10b28ec>] ? copy_mount_options+0x73/0xd2
[ 15.150806] [<c10b4179>] ? sys_mount+0x61/0x94
[ 15.150806] [<c14284e9>] ? syscall_call+0x7/0xb
....
[ 15.203562] ---[ end trace 1dd159357709eb4b ]---
[

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
562ada612058133a5483c68a73605f3c5f42fffe 16-Jan-2010 Eric Van Hensbergen <ericvh@gmail.com> net/9p: fix virtio transport to correctly update status on connect

The 9p virtio transport was not updating its connection status correctly
preventing it from being able to mount the server.

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
e95646c3ec33c8ec0693992da4332a6b32eb7e31 30-Sep-2009 Christian Borntraeger <borntraeger@de.ibm.com> virtio: let header files include virtio_ids.h

Rusty,

commit 3ca4f5ca73057a617f9444a91022d7127041970a
virtio: add virtio IDs file
moved all device IDs into a single file. While the change itself is
a very good one, it can break userspace applications. For example
if a userspace tool wanted to get the ID of virtio_net it used to
include virtio_net.h. This does no longer work, since virtio_net.h
does not include virtio_ids.h.
This patch moves all "#include <linux/virtio_ids.h>" from the C
files into the header files, making the header files compatible with
the old ones.

In addition, this patch exports virtio_ids.h to userspace.

CC: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3ca4f5ca73057a617f9444a91022d7127041970a 31-Jul-2009 Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp> virtio: add virtio IDs file

Virtio IDs are spread all over the tree which makes assigning new IDs
bothersome. Putting them together should make the process less error-prone.

Signed-off-by: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3a20210dc26bbfff3bbb48bb22d2846240b71d8f 30-Jul-2009 Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp> virtio: get rid of redundant VIRTIO_ID_9P definition

VIRTIO_ID_9P is already defined in include/linux/virtio_9p.h
so use that definition instead.

Signed-off-by: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Eric Van Hensbergen <ericvh@gmail.com>
3c1b27d5043086a485f8526353ae9fe37bfa1065 24-Sep-2009 Rusty Russell <rusty@rustcorp.com.au> virtio: make add_buf return capacity remaining

This API change means that virtio_net can tell how much capacity
remains for buffers. It's necessarily fuzzy, since
VIRTIO_RING_F_INDIRECT_DESC means we can fit any number of descriptors
in one, *if* we can kmalloc.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Dinesh Subhraveti <dineshs@us.ibm.com>
0e15597ebfe00e28857185f46aba00f400480ffe 19-Jul-2009 Abhishek Kulkarni <adkulkar@umail.iu.edu> 9p: minor comment fixes

Fix the comments -- mostly the improper and/or missing descriptions
of function parameters.

Signed-off-by: Abhishek Kulkarni <adkulkar@umail.iu.edu>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
d2a7ddda9ffb1c8961abff6714b0f1eb925c120f 13-Jun-2009 Michael S. Tsirkin <mst@redhat.com> virtio: find_vqs/del_vqs virtio operations

This replaces find_vq/del_vq with find_vqs/del_vqs virtio operations,
and updates all drivers. This is needed for MSI support, because MSI
needs to know the total number of vectors upfront.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (+ lguest/9p compile fixes)
9499f5e7ed5224c40706f0cec6542a9916bc7606 13-Jun-2009 Rusty Russell <rusty@rustcorp.com.au> virtio: add names to virtqueue struct, mapping from devices to queues.

Add a linked list of all virtqueues for a virtio device: this helps for
debugging and is also needed for upcoming interface change.

Also, add a "name" field for clearer debug messages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1bab88b2310998de18b32529a27ea835d164254a 05-Apr-2009 Latchesar Ionkov <lucho@ionkov.net> net/9p: handle correctly interrupted 9P requests

Currently the 9p code crashes when a operation is interrupted, i.e. for
example when the user presses ^C while reading from a file.

This patch fixes the code that is responsible for interruption and flushing
of 9P operations.

Signed-off-by: Latchesar Ionkov <lucho@ionkov.net>
91b8534fa8f5e01f249b1bf8df0a2540053549ad 14-Oct-2008 Eric Van Hensbergen <ericvh@gmail.com> 9p: make rpc code common and rework flush code

This code moves the rpc function to the common client base,
reorganizes the flush code to be more simple and stable, and
makes the necessary adjustments to the underlying transports
to adapt to the new structure.

This reduces the overall amount of code duplication between the
transports and should make adding new transports more straightforward.

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
673d62cdaac6ffbce980a349d3174b3929ceb9e5 14-Oct-2008 Eric Van Hensbergen <ericvh@gmail.com> 9p: apply common request code to trans_fd

Apply the now common p9_req_t structure to the fd transport.

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
fea511a644fb0fb938309c6ab286725ac31b87e2 14-Oct-2008 Eric Van Hensbergen <ericvh@gmail.com> 9p: move request management to client code

The virtio transport uses a simplified request management system
that I want to use for all transports. This patch adapts and moves the
exisiting code for managing requests to the client common code.
Later patches will apply these mechanisms to the other transports.

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
8b81ef589ad1483dd977ef47fe00d4ce4d91a0ab 14-Oct-2008 Eric Van Hensbergen <ericvh@ericvh-desktop.austin.ibm.com> 9p: consolidate transport structure

Right now there is a transport module structure which provides per-transport
type functions and data and a transport structure which contains per-instance
public data as well as function pointers to instance specific functions.

This patch moves public transport visible instance data to the client
structure (which in some cases had duplicate data) and consolidates the
functions into the transport module structure.

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
72029fe85d8d060b3f966f2dbc36b3c75b5a6532 24-Sep-2008 Tejun Heo <tj@kernel.org> 9p: implement proper trans module refcounting and unregistration

9p trans modules aren't refcounted nor were they unregistered
properly. Fix it.

* Add 9p_trans_module->owner and reference the module on each trans
instance creation and put it on destruction.

* Protect v9fs_trans_list with a spinlock. This isn't strictly
necessary as the list is manipulated only during module loading /
unloading but it's a good idea to make the API safe.

* Unregister trans modules when the corresponding module is being
unloaded.

* While at it, kill unnecessary EXPORT_SYMBOL on p9_trans_fd_init().

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
d0c447180bfcb1db8d59e6ddb10f0346bd7d29e9 04-May-2008 Steven Rostedt <rostedt@goodmis.org> 9p: fix flags length in net

Some files in the net/9p directory uses "int" for flags. This can
cause hard to find bugs on some architectures. This patch converts the
flags to use "long" instead.

This bug was discovered by doing an allyesconfig make on the -rt kernel
where checks are done to ensure all flags are of size sizeof(long).

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Acked-by: Eric Van Hensbergen <ericvh@gmail.com>
c1549497e903a1ffa1c5808337a987180e480e7a 07-Mar-2008 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> 9p: use struct mutex instead of struct semaphore

Replace semaphores protecting use flags with a mutex.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Acked-by: Eric Van Hensbergen <ericvh@gmail.com>
ee443996a35c1e04f210cafd43d5a98d41e46085 05-Mar-2008 Eric Van Hensbergen <ericvh@ericvh-desktop.(none)> 9p: Documentation updates

The kernel-doc comments of much of the 9p system have been in disarray since
reorganization. This patch fixes those problems, adds additional documentation
and a template book which collects the 9p information.

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
15e29b8b0542f28fc0feed2d60e0377b39a45c4f 20-Feb-2008 Adrian Bunk <bunk@kernel.org> net/9p/trans_virtio.c: kmalloc() enough memory

The Coverity checker spotted that less memory than required was
allocated.

Signed-off-by: Adrian Bunk <bunk@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
d6584f3a08055688b2344eb26379fb2f3147ce91 18-Feb-2008 Julia Lawall <julia@diku.dk> net/9p/trans_virtio.c: Use BUG_ON

if (...) BUG(); should be replaced with BUG_ON(...) when the test has no
side-effects to allow a definition of BUG_ON that drops the code completely.

The semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@ disable unlikely @ expression E,f; @@

(
if (<... f(...) ...>) { BUG(); }
|
- if (unlikely(E)) { BUG(); }
+ BUG_ON(E);
)

@@ expression E,f; @@

(
if (<... f(...) ...>) { BUG(); }
|
- if (E) { BUG(); }
+ BUG_ON(E);
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: David S. Miller <davem@davemloft.net>
8a0dc95fd976a052e5e799ef33e6c8e3141b5dff 07-Feb-2008 Eric Van Hensbergen <ericvh@opteron.homeip.net> 9p: transport API reorganization

This merges the mux.c (including the connection interface) with trans_fd
in preparation for transport API changes. Ultimately, trans_fd will need
to be rewritten to clean it up and simplify the implementation, but this
reorganization is viewed as the first step.

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
f39335453fe79f4e12e263e7c6387dc9fb86bfff 07-Feb-2008 Eric Van Hensbergen <ericvh@ericvh-desktop.(none)> 9p: add remove function to trans_virtio

Request from rusty:
Just cleaning up patches for 2.6.25 merge, and noticed that
net/9p/trans_virtio.c doesn't have a remove function. This will crash when
removing the module (console doesn't have one because it can't really be
removed).

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
7c7d90f2dda6daec5a6aaf8f97aacc10ee4deb77 07-Feb-2008 Eric Van Hensbergen <ericvh@opteron.homeip.net> 9p: Fix soft lockup in virtio transport

This fixes a poorly placed spinlock which could result in a
soft lockup condition.

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
e2735b7720320b68590ca2b32b78ca91213931b2 07-Feb-2008 Eric Van Hensbergen <ericvh@gmail.com> 9p: block-based virtio client

This replaces the console-based virto client with a block-based
client using a single request queue.

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
18445c4d501b9ab4336f66ef46b092661ddaf336 05-Feb-2008 Rusty Russell <rusty@rustcorp.com.au> virtio: explicit enable_cb/disable_cb rather than callback return.

It seems that virtio_net wants to disable callbacks (interrupts) before
calling netif_rx_schedule(), so we can't use the return value to do so.

Rename "restart" to "cb_enable" and introduce "cb_disable" hook: callback
now returns void, rather than a boolean.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
a586d4f6016f7139d8c26df0e6927131168d3b5b 05-Feb-2008 Rusty Russell <rusty@rustcorp.com.au> virtio: simplify config mechanism.

Previously we used a type/len pair within the config space, but this
seems overkill. We now simply define a structure which represents the
layout in the config space: the config space can now only be extended
at the end.

The main driver-visible changes:
1) We indicate what fields are present with an explicit feature bit.
2) Virtqueues are explicitly numbered, and not in the config space.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
b530cc794024be227876a089e66fb17b7b512763 23-Oct-2007 Eric Van Hensbergen <ericvh@gmail.com> 9p: add virtio transport

This adds a transport to 9p for communicating between guests and a host
using a virtio based transport.

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>