--- /dev/null
+From fcb8996728fb59eddf84678df7cb213b2c9a2e26 Mon Sep 17 00:00:00 2001
+From: Ben Hutchings <ben@decadent.org.uk>
+Date: Tue, 31 Jul 2012 16:45:02 -0700
+Subject: mm: add kmap_to_page()
+
+From: Ben Hutchings <ben@decadent.org.uk>
+
+commit fcb8996728fb59eddf84678df7cb213b2c9a2e26 upstream.
+
+This is extracted from Mel Gorman's commit 5a178119b0fb ('mm: add
+support for direct_IO to highmem pages') upstream.
+
+Required to backport commit b9cdc88df8e6 ('virtio: 9p: correctly pass
+physical address to userspace for high pages').
+
+Cc: Mel Gorman <mgorman@suse.de>
+Cc: Rik van Riel <riel@redhat.com>
+Cc: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
+Cc: Yijing Wang <wangyijing@huawei.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ include/linux/highmem.h | 7 +++++++
+ mm/highmem.c | 12 ++++++++++++
+ 2 files changed, 19 insertions(+)
+
+--- a/include/linux/highmem.h
++++ b/include/linux/highmem.h
+@@ -39,10 +39,17 @@ extern unsigned long totalhigh_pages;
+
+ void kmap_flush_unused(void);
+
++struct page *kmap_to_page(void *addr);
++
+ #else /* CONFIG_HIGHMEM */
+
+ static inline unsigned int nr_free_highpages(void) { return 0; }
+
++static inline struct page *kmap_to_page(void *addr)
++{
++ return virt_to_page(addr);
++}
++
+ #define totalhigh_pages 0UL
+
+ #ifndef ARCH_HAS_KMAP
+--- a/mm/highmem.c
++++ b/mm/highmem.c
+@@ -94,6 +94,18 @@ static DECLARE_WAIT_QUEUE_HEAD(pkmap_map
+ do { spin_unlock(&kmap_lock); (void)(flags); } while (0)
+ #endif
+
++struct page *kmap_to_page(void *vaddr)
++{
++ unsigned long addr = (unsigned long)vaddr;
++
++ if (addr >= PKMAP_ADDR(0) && addr <= PKMAP_ADDR(LAST_PKMAP)) {
++ int i = (addr - PKMAP_ADDR(0)) >> PAGE_SHIFT;
++ return pte_page(pkmap_page_table[i]);
++ }
++
++ return virt_to_page(addr);
++}
++
+ static void flush_all_zero_pkmaps(void)
+ {
+ int i;
--- /dev/null
+From 8bc528cece6bc1adf4524eaab7bb82aa66438c4a Mon Sep 17 00:00:00 2001
+From: Will Deacon <will.deacon@arm.com>
+Date: Fri, 19 Oct 2012 14:03:31 +0100
+Subject: mm: highmem: export kmap_to_page for modules
+
+From: Will Deacon <will.deacon@arm.com>
+
+commit f0263d2d222e9e25f2587e51a9dc58c6fb2a9352 upstream.
+
+Some virtio device drivers (9p) need to translate high virtual addresses
+to physical addresses, which are inserted into the virtqueue for
+processing by userspace.
+
+This patch exports the kmap_to_page symbol, so that the affected drivers
+can be compiled as modules.
+
+Signed-off-by: Will Deacon <will.deacon@arm.com>
+Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
+Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
+Cc: Yijing Wang <wangyijing@huawei.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ mm/highmem.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/mm/highmem.c
++++ b/mm/highmem.c
+@@ -105,6 +105,7 @@ struct page *kmap_to_page(void *vaddr)
+
+ return virt_to_page(addr);
+ }
++EXPORT_SYMBOL(kmap_to_page);
+
+ static void flush_all_zero_pkmaps(void)
+ {
virtio-blk-fix-hot-unplug-race-in-remove-method.patch
virtio-blk-call-del_gendisk-before-disable-guest-kick.patch
virtio-blk-reset-device-after-blk_cleanup_queue.patch
+mm-add-kmap_to_page.patch
+mm-highmem-export-kmap_to_page-for-modules.patch
+virtio-9p-correctly-pass-physical-address-to-userspace-for-high-pages.patch
+virtio-blk-don-t-free-ida-when-disk-is-in-use.patch
+virtio_console-fix-uapi-header.patch
+virtio-console-rename-cvq_lock-to-c_ivq_lock.patch
+virtio-console-add-locking-around-c_ovq-operations.patch
--- /dev/null
+From 30d395b124c51db66d9f3ba0611cd62021afc392 Mon Sep 17 00:00:00 2001
+From: Will Deacon <will.deacon@arm.com>
+Date: Fri, 19 Oct 2012 14:03:32 +0100
+Subject: virtio: 9p: correctly pass physical address to userspace for high pages
+
+From: Will Deacon <will.deacon@arm.com>
+
+commit 30d395b124c51db66d9f3ba0611cd62021afc392 upstream.
+
+commit b9cdc88df8e63e81c723b82c286fc97f5d0dc325 upstream.
+
+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: Sasha Levin <levinsasha928@gmail.com>
+Signed-off-by: Will Deacon <will.deacon@arm.com>
+Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
+Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
+Cc: Yijing Wang <wangyijing@huawei.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/9p/trans_virtio.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+--- a/net/9p/trans_virtio.c
++++ b/net/9p/trans_virtio.c
+@@ -39,6 +39,7 @@
+ #include <linux/inet.h>
+ #include <linux/idr.h>
+ #include <linux/file.h>
++#include <linux/highmem.h>
+ #include <linux/slab.h>
+ #include <net/9p/9p.h>
+ #include <linux/parser.h>
+@@ -325,7 +326,7 @@ static int p9_get_mapped_pages(struct vi
+ int count = nr_pages;
+ while (nr_pages) {
+ s = rest_of_page(data);
+- pages[index++] = virt_to_page(data);
++ pages[index++] = kmap_to_page(data);
+ data += s;
+ nr_pages--;
+ }
--- /dev/null
+From 63dddb4936fa86057e7f94a0bd10cb8ac25bc7f3 Mon Sep 17 00:00:00 2001
+From: Alexander Graf <agraf@suse.de>
+Date: Wed, 2 Jan 2013 15:37:17 +1030
+Subject: virtio-blk: Don't free ida when disk is in use
+
+From: Alexander Graf <agraf@suse.de>
+
+commit f4953fe6c4aeada2d5cafd78aa97587a46d2d8f9 upstream.
+
+When a file system is mounted on a virtio-blk disk, we then remove it
+and then reattach it, the reattached disk gets the same disk name and
+ids as the hot removed one.
+
+This leads to very nasty effects - mostly rendering the newly attached
+device completely unusable.
+
+Trying what happens when I do the same thing with a USB device, I saw
+that the sd node simply doesn't get free'd when a device gets forcefully
+removed.
+
+Imitate the same behavior for vd devices. This way broken vd devices
+simply are never free'd and newly attached ones keep working just fine.
+
+Signed-off-by: Alexander Graf <agraf@suse.de>
+Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
+Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
+Cc: Yijing Wang <wangyijing@huawei.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/block/virtio_blk.c | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+--- a/drivers/block/virtio_blk.c
++++ b/drivers/block/virtio_blk.c
+@@ -573,6 +573,7 @@ static void __devexit virtblk_remove(str
+ {
+ struct virtio_blk *vblk = vdev->priv;
+ int index = vblk->index;
++ int refc;
+
+ /* Prevent config work handler from accessing the device. */
+ mutex_lock(&vblk->config_lock);
+@@ -587,11 +588,15 @@ static void __devexit virtblk_remove(str
+
+ flush_work(&vblk->config_work);
+
++ refc = atomic_read(&disk_to_dev(vblk->disk)->kobj.kref.refcount);
+ put_disk(vblk->disk);
+ mempool_destroy(vblk->pool);
+ vdev->config->del_vqs(vdev);
+ kfree(vblk);
+- ida_simple_remove(&vd_index_ida, index);
++
++ /* Only free device id if we don't have any users */
++ if (refc == 1)
++ ida_simple_remove(&vd_index_ida, index);
+ }
+
+ #ifdef CONFIG_PM
--- /dev/null
+From 9ba5c80b1aea8648a3efe5f22dc1f7cacdfbeeb8 Mon Sep 17 00:00:00 2001
+From: Amit Shah <amit.shah@redhat.com>
+Date: Fri, 29 Mar 2013 16:30:08 +0530
+Subject: virtio: console: add locking around c_ovq operations
+
+From: Amit Shah <amit.shah@redhat.com>
+
+commit 9ba5c80b1aea8648a3efe5f22dc1f7cacdfbeeb8 upstream.
+
+When multiple ovq operations are being performed (lots of open/close
+operations on virtio_console fds), the __send_control_msg() function can
+get confused without locking.
+
+A simple recipe to cause badness is:
+* create a QEMU VM with two virtio-serial ports
+* in the guest, do
+ while true;do echo abc >/dev/vport0p1;done
+ while true;do echo edf >/dev/vport0p2;done
+
+In one run, this caused a panic in __send_control_msg(). In another, I
+got
+
+ virtio_console virtio0: control-o:id 0 is not a head!
+
+This also results repeated messages similar to these on the host:
+
+ qemu-kvm: virtio-serial-bus: Unexpected port id 478762112 for device virtio-serial-bus.0
+ qemu-kvm: virtio-serial-bus: Unexpected port id 478762368 for device virtio-serial-bus.0
+
+Reported-by: FuXiangChun <xfu@redhat.com>
+Signed-off-by: Amit Shah <amit.shah@redhat.com>
+Reviewed-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
+Reviewed-by: Asias He <asias@redhat.com>
+Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
+[bwh: Backported to 3.2: adjust context]
+Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
+[wyj: Backported to 3.4: adjust context]
+Signed-off-by: Yijing Wang <wangyijing@huawei.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/char/virtio_console.c | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+--- a/drivers/char/virtio_console.c
++++ b/drivers/char/virtio_console.c
+@@ -132,6 +132,7 @@ struct ports_device {
+
+ /* To protect the vq operations for the control channel */
+ spinlock_t c_ivq_lock;
++ spinlock_t c_ovq_lock;
+
+ /* The current config space is stored here */
+ struct virtio_console_config config;
+@@ -460,11 +461,14 @@ static ssize_t __send_control_msg(struct
+ vq = portdev->c_ovq;
+
+ sg_init_one(sg, &cpkt, sizeof(cpkt));
++
++ spin_lock(&portdev->c_ovq_lock);
+ if (virtqueue_add_buf(vq, sg, 1, 0, &cpkt, GFP_ATOMIC) >= 0) {
+ virtqueue_kick(vq);
+ while (!virtqueue_get_buf(vq, &len))
+ cpu_relax();
+ }
++ spin_unlock(&portdev->c_ovq_lock);
+ return 0;
+ }
+
+@@ -1752,6 +1756,7 @@ static int __devinit virtcons_probe(stru
+ unsigned int nr_added_bufs;
+
+ spin_lock_init(&portdev->c_ivq_lock);
++ spin_lock_init(&portdev->c_ovq_lock);
+ INIT_WORK(&portdev->control_work, &control_work_handler);
+
+ nr_added_bufs = fill_queue(portdev->c_ivq,
--- /dev/null
+From 165b1b8bbc17c9469b053bab78b11b7cbce6d161 Mon Sep 17 00:00:00 2001
+From: Amit Shah <amit.shah@redhat.com>
+Date: Fri, 29 Mar 2013 16:30:07 +0530
+Subject: virtio: console: rename cvq_lock to c_ivq_lock
+
+From: Amit Shah <amit.shah@redhat.com>
+
+commit 165b1b8bbc17c9469b053bab78b11b7cbce6d161 upstream.
+
+The cvq_lock was taken for the c_ivq. Rename the lock to make that
+obvious.
+
+We'll also add a lock around the c_ovq in the next commit, so there's no
+ambiguity.
+
+Signed-off-by: Amit Shah <amit.shah@redhat.com>
+Reviewed-by: Asias He <asias@redhat.com>
+Reviewed-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
+Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
+[bwh: Backported to 3.2:
+ - Adjust context
+ - Drop change to virtcons_restore()]
+Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
+[wyj: Backported to 3.4:
+ - pick change to virtcons_restore() from upsteam patch]
+Signed-off-by: Yijing Wang <wangyijing@huawei.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/char/virtio_console.c | 17 +++++++++--------
+ 1 file changed, 9 insertions(+), 8 deletions(-)
+
+--- a/drivers/char/virtio_console.c
++++ b/drivers/char/virtio_console.c
+@@ -131,7 +131,7 @@ struct ports_device {
+ spinlock_t ports_lock;
+
+ /* To protect the vq operations for the control channel */
+- spinlock_t cvq_lock;
++ spinlock_t c_ivq_lock;
+
+ /* The current config space is stored here */
+ struct virtio_console_config config;
+@@ -1474,23 +1474,23 @@ static void control_work_handler(struct
+ portdev = container_of(work, struct ports_device, control_work);
+ vq = portdev->c_ivq;
+
+- spin_lock(&portdev->cvq_lock);
++ spin_lock(&portdev->c_ivq_lock);
+ while ((buf = virtqueue_get_buf(vq, &len))) {
+- spin_unlock(&portdev->cvq_lock);
++ spin_unlock(&portdev->c_ivq_lock);
+
+ buf->len = len;
+ buf->offset = 0;
+
+ handle_control_message(portdev, buf);
+
+- spin_lock(&portdev->cvq_lock);
++ spin_lock(&portdev->c_ivq_lock);
+ if (add_inbuf(portdev->c_ivq, buf) < 0) {
+ dev_warn(&portdev->vdev->dev,
+ "Error adding buffer to queue\n");
+ free_buf(buf);
+ }
+ }
+- spin_unlock(&portdev->cvq_lock);
++ spin_unlock(&portdev->c_ivq_lock);
+ }
+
+ static void out_intr(struct virtqueue *vq)
+@@ -1751,10 +1751,11 @@ static int __devinit virtcons_probe(stru
+ if (multiport) {
+ unsigned int nr_added_bufs;
+
+- spin_lock_init(&portdev->cvq_lock);
++ spin_lock_init(&portdev->c_ivq_lock);
+ INIT_WORK(&portdev->control_work, &control_work_handler);
+
+- nr_added_bufs = fill_queue(portdev->c_ivq, &portdev->cvq_lock);
++ nr_added_bufs = fill_queue(portdev->c_ivq,
++ &portdev->c_ivq_lock);
+ if (!nr_added_bufs) {
+ dev_err(&vdev->dev,
+ "Error allocating buffers for control queue\n");
+@@ -1895,7 +1896,7 @@ static int virtcons_restore(struct virti
+ return ret;
+
+ if (use_multiport(portdev))
+- fill_queue(portdev->c_ivq, &portdev->cvq_lock);
++ fill_queue(portdev->c_ivq, &portdev->c_ivq_lock);
+
+ list_for_each_entry(port, &portdev->ports, list) {
+ port->in_vq = portdev->in_vqs[port->id];
--- /dev/null
+From 0cbb6f3def0ceedcbef5af335c756cd427d9e8cc Mon Sep 17 00:00:00 2001
+From: "Michael S. Tsirkin" <mst@redhat.com>
+Date: Fri, 17 May 2013 10:44:15 +0930
+Subject: virtio_console: fix uapi header
+
+From: "Michael S. Tsirkin" <mst@redhat.com>
+
+commit 6407d75afd08545f2252bb39806ffd3f10c7faac upstream.
+
+uapi should use __u32 not u32.
+Fix a macro in virtio_console.h which uses u32.
+
+Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
+Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
+[bwh: Backported to 3.2: adjust filename]
+Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
+Cc: Yijing Wang <wangyijing@huawei.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ include/linux/virtio_console.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/include/linux/virtio_console.h
++++ b/include/linux/virtio_console.h
+@@ -39,7 +39,7 @@
+ #define VIRTIO_CONSOLE_F_SIZE 0 /* Does host provide console size? */
+ #define VIRTIO_CONSOLE_F_MULTIPORT 1 /* Does host provide multiple ports? */
+
+-#define VIRTIO_CONSOLE_BAD_ID (~(u32)0)
++#define VIRTIO_CONSOLE_BAD_ID (~(__u32)0)
+
+ struct virtio_console_config {
+ /* colums of the screens */