Re: [PATCH 0/6] virtio_balloon: virtio 1 support

2015-03-31 Thread Cornelia Huck
On Mon, 30 Mar 2015 19:37:08 +0200
Michael S. Tsirkin m...@redhat.com wrote:

 Virtio 1.0 doesn't include a modern balloon device.
 At some point we'll likely define an incompatible interface with a different
 ID.  But for now, it's not a big change to support a transitional balloon
 device: this has the advantage of supporting existing drivers, transparently.

This is needed to support a ballooner on transports that don't support
mixing legacy and 1.0, right?

 
 The only issue is with the stats buffer, which has misaligned fields.
 Seems easy to fix by prepending a 6 byte reserved field.

I assume you also define the stats fields to be le for 1.0?

 
 I'll post spec patch and qemu patches shortly.

I'll defer review until then.

 
 Michael S. Tsirkin (6):
   virtio_balloon: transitional interface
   virtio: balloon might not be a legacy device
   virtio_ccw: support non-legacy balloon devices
   virtio_mmio: support non-legacy balloon devices
   virtio_pci: support non-legacy balloon devices
   virtio: drop virtio_device_is_legacy_only
 
  include/linux/virtio.h  |  2 --
  include/uapi/linux/virtio_balloon.h |  6 ++
  drivers/s390/kvm/virtio_ccw.c   | 10 +++---
  drivers/virtio/virtio.c |  6 --
  drivers/virtio/virtio_balloon.c |  8 ++--
  drivers/virtio/virtio_mmio.c|  8 
  drivers/virtio/virtio_pci_modern.c  |  3 ---
  7 files changed, 15 insertions(+), 28 deletions(-)
 

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH] virtio: drop a useless config read

2015-03-31 Thread Michael S. Tsirkin
commit d71de9ec6ba806104439d3a669befda84757b5af
virtio: core support for config generation
fixed reading up 64 bit values, adding generation
checks for such reads.

By mistake, it left an explicit get call in place
as well. the result is that the value is read twice,
the first result is discarded.

Not a big deal since this only happens with virtio
blk and only on boot ATM, so performance isn't
affected, but let's clean it up.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/linux/virtio_config.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index ca3ed78..ed1e0d5 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -374,7 +374,6 @@ static inline u64 virtio_cread64(struct virtio_device *vdev,
 unsigned int offset)
 {
u64 ret;
-   vdev-config-get(vdev, offset, ret, sizeof(ret));
__virtio_cread_many(vdev, offset, ret, 1, sizeof(ret));
return virtio64_to_cpu(vdev, (__force __virtio64)ret);
 }
-- 
MST
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH 0/6] virtio_balloon: virtio 1 support

2015-03-31 Thread Michael S. Tsirkin
On Tue, Mar 31, 2015 at 10:46:18AM +0200, Cornelia Huck wrote:
 On Mon, 30 Mar 2015 19:37:08 +0200
 Michael S. Tsirkin m...@redhat.com wrote:
 
  Virtio 1.0 doesn't include a modern balloon device.
  At some point we'll likely define an incompatible interface with a different
  ID.  But for now, it's not a big change to support a transitional balloon
  device: this has the advantage of supporting existing drivers, 
  transparently.
 
 This is needed to support a ballooner on transports that don't support
 mixing legacy and 1.0, right?

That too. But it's also useful if you don't know whether your guest
supports virtio 1 or not - which is the point of using
a transitional device.

  
  The only issue is with the stats buffer, which has misaligned fields.
  Seems easy to fix by prepending a 6 byte reserved field.
 
 I assume you also define the stats fields to be le for 1.0?

They were always le for the balloon.

  
  I'll post spec patch and qemu patches shortly.
 
 I'll defer review until then.
 
  
  Michael S. Tsirkin (6):
virtio_balloon: transitional interface
virtio: balloon might not be a legacy device
virtio_ccw: support non-legacy balloon devices
virtio_mmio: support non-legacy balloon devices
virtio_pci: support non-legacy balloon devices
virtio: drop virtio_device_is_legacy_only
  
   include/linux/virtio.h  |  2 --
   include/uapi/linux/virtio_balloon.h |  6 ++
   drivers/s390/kvm/virtio_ccw.c   | 10 +++---
   drivers/virtio/virtio.c |  6 --
   drivers/virtio/virtio_balloon.c |  8 ++--
   drivers/virtio/virtio_mmio.c|  8 
   drivers/virtio/virtio_pci_modern.c  |  3 ---
   7 files changed, 15 insertions(+), 28 deletions(-)
  
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH] virtio: drop a useless config read

2015-03-31 Thread Cornelia Huck
On Tue, 31 Mar 2015 13:55:42 +0200
Michael S. Tsirkin m...@redhat.com wrote:

 commit d71de9ec6ba806104439d3a669befda84757b5af
 virtio: core support for config generation
 fixed reading up 64 bit values, adding generation
 checks for such reads.
 
 By mistake, it left an explicit get call in place
 as well. the result is that the value is read twice,
 the first result is discarded.
 
 Not a big deal since this only happens with virtio
 blk and only on boot ATM, so performance isn't
 affected, but let's clean it up.
 
 Signed-off-by: Michael S. Tsirkin m...@redhat.com
 ---
  include/linux/virtio_config.h | 1 -
  1 file changed, 1 deletion(-)

Reviewed-by: Cornelia Huck cornelia.h...@de.ibm.com

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH 4/6] virtio_mmio: support non-legacy balloon devices

2015-03-31 Thread Pawel Moll
On Mon, 2015-03-30 at 18:37 +0100, Michael S. Tsirkin wrote:
 virtio_device_is_legacy_only is always false now,
 drop the test from virtio mmio.
 
 Signed-off-by: Michael S. Tsirkin m...@redhat.com

Slightly ironic ack ;-) after all the battle you fought for this:

Acked-by: Pawel Moll pawel.m...@arm.com

Thanks!

Pawel

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH] virtio: drop a useless config read

2015-03-31 Thread Rusty Russell
Cornelia Huck cornelia.h...@de.ibm.com writes:
 On Tue, 31 Mar 2015 13:55:42 +0200
 Michael S. Tsirkin m...@redhat.com wrote:

 commit d71de9ec6ba806104439d3a669befda84757b5af
 virtio: core support for config generation
 fixed reading up 64 bit values, adding generation
 checks for such reads.
 
 By mistake, it left an explicit get call in place
 as well. the result is that the value is read twice,
 the first result is discarded.
 
 Not a big deal since this only happens with virtio
 blk and only on boot ATM, so performance isn't
 affected, but let's clean it up.
 
 Signed-off-by: Michael S. Tsirkin m...@redhat.com
 ---
  include/linux/virtio_config.h | 1 -
  1 file changed, 1 deletion(-)

 Reviewed-by: Cornelia Huck cornelia.h...@de.ibm.com

Applied.

Thanks!
Rusty.
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH v2 1/6] virtio_balloon: transitional interface

2015-03-31 Thread Rusty Russell
Michael S. Tsirkin m...@redhat.com writes:
 Virtio 1.0 doesn't include a modern balloon device.
 But it's not a big change to support a transitional
 balloon device: this has the advantage of supporting
 existing drivers, transparently.

You decided to fix the packed struct...

 diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
 index 6a356e3..574267f 100644
 --- a/drivers/virtio/virtio_balloon.c
 +++ b/drivers/virtio/virtio_balloon.c
 @@ -77,7 +77,7 @@ struct virtio_balloon {
  
   /* Memory statistics */
   int need_stats_update;
 - struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR];
 + struct virtio_balloon_stat_modern stats[VIRTIO_BALLOON_S_NR];
  
   /* To register callback in oom notifier call chain */
   struct notifier_block nb;
 @@ -269,7 +269,11 @@ static void stats_handle_request(struct virtio_balloon 
 *vb)
   vq = vb-stats_vq;
   if (!virtqueue_get_buf(vq, len))
   return;
 - sg_init_one(sg, vb-stats, sizeof(vb-stats));
 + if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1))
 + sg_init_one(sg, vb-stats, sizeof(vb-stats));
 + else
 + sg_init_one(sg, vb-stats-tag, sizeof(vb-stats) -
 + offsetof(typeof(*vb-stats, tag);

This makes it compile, but definitely won't work.

   virtqueue_add_outbuf(vq, sg, 1, vb, GFP_KERNEL);
   virtqueue_kick(vq);
  }
 @@ -283,21 +287,30 @@ static void virtballoon_changed(struct virtio_device 
 *vdev)
  
  static inline s64 towards_target(struct virtio_balloon *vb)
  {
 - __le32 v;
   s64 target;
 + u32 num_pages;
  
 - virtio_cread(vb-vdev, struct virtio_balloon_config, num_pages, v);
 + virtio_cread(vb-vdev, struct virtio_balloon_config,
 +  num_pages, num_pages);
  
 - target = le32_to_cpu(v);
 + /* Legacy balloon config space is LE, unlike all other devices. */
 + if (!virtio_has_feature(vb-vdev, VIRTIO_F_VERSION_1))
 + num_pages = le32_to_cpu((__force le32)num_pages);
 +
 + target = num_pages;
   return target - vb-num_pages;
  }
  
  static void update_balloon_size(struct virtio_balloon *vb)
  {
 - __le32 actual = cpu_to_le32(vb-num_pages);
 + u32 actual = vb-num_pages;
 +
 + /* Legacy balloon config space is LE, unlike all other devices. */
 + if (!virtio_has_feature(vb-vdev, VIRTIO_F_VERSION_1))
 + actual = (__force u32)cpu_to_le32(num_pages);
  
 - virtio_cwrite(vb-vdev, struct virtio_balloon_config, actual,
 -   actual);
 + virtio_cwrite(vb-vdev, struct virtio_balloon_config,
 +   actual, actual);
  }

Final line is gratitous reformatting.

I would leave the device *exactly* as is, ugly structure packing and
all.

Cheers,
Rusty.
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH] virtio_config: reorder functions

2015-03-31 Thread Michael S. Tsirkin
This simply reorders functions in virtio_config
so width access wrapper helpers are all together.
Drops an extra empty line while we are at it.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/linux/virtio_config.h | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index ed1e0d5..1e306f7 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -298,13 +298,6 @@ static inline __virtio64 cpu_to_virtio64(struct 
virtio_device *vdev, u64 val)
}   \
} while(0)
 
-static inline u8 virtio_cread8(struct virtio_device *vdev, unsigned int offset)
-{
-   u8 ret;
-   vdev-config-get(vdev, offset, ret, sizeof(ret));
-   return ret;
-}
-
 /* Read @count fields, @bytes each. */
 static inline void __virtio_cread_many(struct virtio_device *vdev,
   unsigned int offset,
@@ -326,7 +319,6 @@ static inline void __virtio_cread_many(struct virtio_device 
*vdev,
} while (gen != old);
 }
 
-
 static inline void virtio_cread_bytes(struct virtio_device *vdev,
  unsigned int offset,
  void *buf, size_t len)
@@ -334,6 +326,13 @@ static inline void virtio_cread_bytes(struct virtio_device 
*vdev,
__virtio_cread_many(vdev, offset, buf, len, 1);
 }
 
+static inline u8 virtio_cread8(struct virtio_device *vdev, unsigned int offset)
+{
+   u8 ret;
+   vdev-config-get(vdev, offset, ret, sizeof(ret));
+   return ret;
+}
+
 static inline void virtio_cwrite8(struct virtio_device *vdev,
  unsigned int offset, u8 val)
 {
-- 
MST
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v2 5/6] virtio_pci: support non-legacy balloon devices

2015-03-31 Thread Michael S. Tsirkin
virtio_device_is_legacy_only is always false now,
drop the test from virtio pci.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 drivers/virtio/virtio_pci_modern.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 2aa38e5..dfea17a 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -577,9 +577,6 @@ int virtio_pci_modern_probe(struct virtio_pci_device 
*vp_dev)
}
vp_dev-vdev.id.vendor = pci_dev-subsystem_vendor;
 
-   if (virtio_device_is_legacy_only(vp_dev-vdev.id))
-   return -ENODEV;
-
/* check for a common config: if not, use legacy mode (bar 0). */
common = virtio_pci_find_capability(pci_dev, VIRTIO_PCI_CAP_COMMON_CFG,
IORESOURCE_IO | IORESOURCE_MEM);
-- 
MST

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v2 4/6] virtio_mmio: support non-legacy balloon devices

2015-03-31 Thread Michael S. Tsirkin
virtio_device_is_legacy_only is always false now,
drop the test from virtio mmio.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
Acked-by: Pawel Moll pawel.m...@arm.com
---
 drivers/virtio/virtio_mmio.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 6010d7e..7a5e60d 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -581,14 +581,6 @@ static int virtio_mmio_probe(struct platform_device *pdev)
}
vm_dev-vdev.id.vendor = readl(vm_dev-base + VIRTIO_MMIO_VENDOR_ID);
 
-   /* Reject legacy-only IDs for version 2 devices */
-   if (vm_dev-version == 2 
-   virtio_device_is_legacy_only(vm_dev-vdev.id)) {
-   dev_err(pdev-dev, Version 2 not supported for devices %u!\n,
-   vm_dev-vdev.id.device);
-   return -ENODEV;
-   }
-
if (vm_dev-version == 1)
writel(PAGE_SIZE, vm_dev-base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
 
-- 
MST

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH 4/6] virtio_mmio: support non-legacy balloon devices

2015-03-31 Thread Michael S. Tsirkin
On Tue, Mar 31, 2015 at 01:31:35PM +0100, Pawel Moll wrote:
 On Mon, 2015-03-30 at 18:37 +0100, Michael S. Tsirkin wrote:
  virtio_device_is_legacy_only is always false now,
  drop the test from virtio mmio.
  
  Signed-off-by: Michael S. Tsirkin m...@redhat.com
 
 Slightly ironic ack ;-) after all the battle you fought for this:

In hindsight, the time might have been better spent working on this
patchset instead, that's true.

 Acked-by: Pawel Moll pawel.m...@arm.com
 
 Thanks!
 
 Pawel
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v2 1/6] virtio_balloon: transitional interface

2015-03-31 Thread Michael S. Tsirkin
Virtio 1.0 doesn't include a modern balloon device.
But it's not a big change to support a transitional
balloon device: this has the advantage of supporting
existing drivers, transparently.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/uapi/linux/virtio_balloon.h | 11 +--
 drivers/virtio/virtio_balloon.c | 29 +
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/include/uapi/linux/virtio_balloon.h 
b/include/uapi/linux/virtio_balloon.h
index 4b0488f..71ef93b 100644
--- a/include/uapi/linux/virtio_balloon.h
+++ b/include/uapi/linux/virtio_balloon.h
@@ -38,9 +38,9 @@
 
 struct virtio_balloon_config {
/* Number of pages host wants Guest to give up. */
-   __le32 num_pages;
+   __u32 num_pages;
/* Number of pages we've actually got in balloon. */
-   __le32 actual;
+   __u32 actual;
 };
 
 #define VIRTIO_BALLOON_S_SWAP_IN  0   /* Amount of memory swapped in */
@@ -51,9 +51,16 @@ struct virtio_balloon_config {
 #define VIRTIO_BALLOON_S_MEMTOT   5   /* Total amount of memory */
 #define VIRTIO_BALLOON_S_NR   6
 
+/* Legacy stat structure. We keep it around to avoid breaking old userspace. */
 struct virtio_balloon_stat {
__u16 tag;
__u64 val;
 } __attribute__((packed));
 
+struct virtio_balloon_stat_modern {
+   __u8 reserved[6];
+   __virtio16 tag;
+   __virtio64 val;
+};
+
 #endif /* _LINUX_VIRTIO_BALLOON_H */
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 6a356e3..574267f 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -77,7 +77,7 @@ struct virtio_balloon {
 
/* Memory statistics */
int need_stats_update;
-   struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR];
+   struct virtio_balloon_stat_modern stats[VIRTIO_BALLOON_S_NR];
 
/* To register callback in oom notifier call chain */
struct notifier_block nb;
@@ -269,7 +269,11 @@ static void stats_handle_request(struct virtio_balloon *vb)
vq = vb-stats_vq;
if (!virtqueue_get_buf(vq, len))
return;
-   sg_init_one(sg, vb-stats, sizeof(vb-stats));
+   if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1))
+   sg_init_one(sg, vb-stats, sizeof(vb-stats));
+   else
+   sg_init_one(sg, vb-stats-tag, sizeof(vb-stats) -
+   offsetof(typeof(*vb-stats, tag);
virtqueue_add_outbuf(vq, sg, 1, vb, GFP_KERNEL);
virtqueue_kick(vq);
 }
@@ -283,21 +287,30 @@ static void virtballoon_changed(struct virtio_device 
*vdev)
 
 static inline s64 towards_target(struct virtio_balloon *vb)
 {
-   __le32 v;
s64 target;
+   u32 num_pages;
 
-   virtio_cread(vb-vdev, struct virtio_balloon_config, num_pages, v);
+   virtio_cread(vb-vdev, struct virtio_balloon_config,
+num_pages, num_pages);
 
-   target = le32_to_cpu(v);
+   /* Legacy balloon config space is LE, unlike all other devices. */
+   if (!virtio_has_feature(vb-vdev, VIRTIO_F_VERSION_1))
+   num_pages = le32_to_cpu((__force le32)num_pages);
+
+   target = num_pages;
return target - vb-num_pages;
 }
 
 static void update_balloon_size(struct virtio_balloon *vb)
 {
-   __le32 actual = cpu_to_le32(vb-num_pages);
+   u32 actual = vb-num_pages;
+
+   /* Legacy balloon config space is LE, unlike all other devices. */
+   if (!virtio_has_feature(vb-vdev, VIRTIO_F_VERSION_1))
+   actual = (__force u32)cpu_to_le32(num_pages);
 
-   virtio_cwrite(vb-vdev, struct virtio_balloon_config, actual,
- actual);
+   virtio_cwrite(vb-vdev, struct virtio_balloon_config,
+ actual, actual);
 }
 
 /*
-- 
MST

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v2 2/6] virtio: balloon might not be a legacy device

2015-03-31 Thread Michael S. Tsirkin
We added transitional device support to balloon driver,
so we don't need to black-list it in core anymore.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 drivers/virtio/virtio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 5ce2aa4..5fa67b5 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -280,7 +280,7 @@ static struct bus_type virtio_bus = {
 
 bool virtio_device_is_legacy_only(struct virtio_device_id id)
 {
-   return id.device == VIRTIO_ID_BALLOON;
+   return false;
 }
 EXPORT_SYMBOL_GPL(virtio_device_is_legacy_only);
 
-- 
MST

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH] add generic callbacks into compaction

2015-03-31 Thread Gioh Kim
I sent a patch about page allocation for less fragmentation.
http://permalink.gmane.org/gmane.linux.kernel.mm/130599

It proposes a page allocator allocates pages in the same pageblock
for the drivers to move their unmovable pages. Some drivers which comsumes many 
pages
and increases system fragmentation use the allocator to move their pages to
decrease fragmentation.

I think I can try another approach.
There is a compaction code for balloon pages.
But the compaction code cannot migrate pages of other drivers.
If there is a generic migration framework applicable to any drivers,
drivers can register their migration functions.
And the compaction can migrate movable pages and also driver's pages.

I'm not familiar with virtualization so I couldn't test this patch yet.
But if mm developers agree with this approach, I will complete this patch.

I would do appreciate any feedback.

Signed-off-by: Gioh Kim gioh@lge.com
---
 drivers/virtio/virtio_balloon.c|2 ++
 include/linux/balloon_compaction.h |   23 +---
 include/linux/fs.h |3 ++
 include/linux/pagemap.h|   26 ++
 mm/balloon_compaction.c|   68 ++--
 mm/compaction.c|7 ++--
 mm/migrate.c   |   24 ++---
 7 files changed, 129 insertions(+), 24 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 0413157..cd9b8e4 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -486,6 +486,8 @@ static int virtballoon_probe(struct virtio_device *vdev)
 
balloon_devinfo_init(vb-vb_dev_info);
 #ifdef CONFIG_BALLOON_COMPACTION
+   vb-vb_dev_info.mapping = balloon_mapping_alloc(vb-vb_dev_info,
+   balloon_aops);
vb-vb_dev_info.migratepage = virtballoon_migratepage;
 #endif
 
diff --git a/include/linux/balloon_compaction.h 
b/include/linux/balloon_compaction.h
index 9b0a15d..0af32b3 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -62,6 +62,7 @@ struct balloon_dev_info {
struct list_head pages; /* Pages enqueued  handled to Host */
int (*migratepage)(struct balloon_dev_info *, struct page *newpage,
struct page *page, enum migrate_mode mode);
+   struct address_space *mapping;
 };
 
 extern struct page *balloon_page_enqueue(struct balloon_dev_info *b_dev_info);
@@ -76,10 +77,22 @@ static inline void balloon_devinfo_init(struct 
balloon_dev_info *balloon)
 }
 
 #ifdef CONFIG_BALLOON_COMPACTION
-extern bool balloon_page_isolate(struct page *page);
-extern void balloon_page_putback(struct page *page);
-extern int balloon_page_migrate(struct page *newpage,
-   struct page *page, enum migrate_mode mode);
+extern const struct address_space_operations balloon_aops;
+extern int balloon_page_isolate(struct page *page);
+extern int balloon_page_putback(struct page *page);
+extern int balloon_page_migrate(struct address_space *mapping,
+   struct page *newpage,
+   struct page *page,
+   enum migrate_mode mode);
+
+extern struct address_space
+*balloon_mapping_alloc(struct balloon_dev_info *b_dev_info,
+  const struct address_space_operations *a_ops);
+
+static inline void balloon_mapping_free(struct address_space *balloon_mapping)
+{
+   kfree(balloon_mapping);
+}
 
 /*
  * __is_movable_balloon_page - helper to perform @page PageBalloon tests
@@ -123,6 +136,7 @@ static inline bool isolated_balloon_page(struct page *page)
 static inline void balloon_page_insert(struct balloon_dev_info *balloon,
   struct page *page)
 {
+   page-mapping = balloon-mapping;
__SetPageBalloon(page);
SetPagePrivate(page);
set_page_private(page, (unsigned long)balloon);
@@ -139,6 +153,7 @@ static inline void balloon_page_insert(struct 
balloon_dev_info *balloon,
  */
 static inline void balloon_page_delete(struct page *page)
 {
+   page-mapping = NULL;
__ClearPageBalloon(page);
set_page_private(page, 0);
if (PagePrivate(page)) {
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b4d71b5..de463b9 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -368,6 +368,9 @@ struct address_space_operations {
 */
int (*migratepage) (struct address_space *,
struct page *, struct page *, enum migrate_mode);
+   int (*isolatepage)(struct page *);
+   int (*putbackpage)(struct page *);
+
int (*launder_page) (struct page *);
int (*is_partially_uptodate) (struct page *, unsigned long,
unsigned long);
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 4b3736f..715b5b2 100644
---