aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/virtio/virtio_balloon.c13
-rw-r--r--include/linux/virtio_balloon.h3
2 files changed, 14 insertions, 2 deletions
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 62eab43152d..59268266b79 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -56,6 +56,15 @@ static struct virtio_device_id id_table[] = {
56 { 0 }, 56 { 0 },
57}; 57};
58 58
59static u32 page_to_balloon_pfn(struct page *page)
60{
61 unsigned long pfn = page_to_pfn(page);
62
63 BUILD_BUG_ON(PAGE_SHIFT < VIRTIO_BALLOON_PFN_SHIFT);
64 /* Convert pfn from Linux page size to balloon page size. */
65 return pfn >> (PAGE_SHIFT - VIRTIO_BALLOON_PFN_SHIFT);
66}
67
59static void balloon_ack(struct virtqueue *vq) 68static void balloon_ack(struct virtqueue *vq)
60{ 69{
61 struct virtio_balloon *vb; 70 struct virtio_balloon *vb;
@@ -99,7 +108,7 @@ static void fill_balloon(struct virtio_balloon *vb, size_t num)
99 msleep(200); 108 msleep(200);
100 break; 109 break;
101 } 110 }
102 vb->pfns[vb->num_pfns] = page_to_pfn(page); 111 vb->pfns[vb->num_pfns] = page_to_balloon_pfn(page);
103 totalram_pages--; 112 totalram_pages--;
104 vb->num_pages++; 113 vb->num_pages++;
105 list_add(&page->lru, &vb->pages); 114 list_add(&page->lru, &vb->pages);
@@ -132,7 +141,7 @@ static void leak_balloon(struct virtio_balloon *vb, size_t num)
132 for (vb->num_pfns = 0; vb->num_pfns < num; vb->num_pfns++) { 141 for (vb->num_pfns = 0; vb->num_pfns < num; vb->num_pfns++) {
133 page = list_first_entry(&vb->pages, struct page, lru); 142 page = list_first_entry(&vb->pages, struct page, lru);
134 list_del(&page->lru); 143 list_del(&page->lru);
135 vb->pfns[vb->num_pfns] = page_to_pfn(page); 144 vb->pfns[vb->num_pfns] = page_to_balloon_pfn(page);
136 vb->num_pages--; 145 vb->num_pages--;
137 } 146 }
138 147
diff --git a/include/linux/virtio_balloon.h b/include/linux/virtio_balloon.h
index c30c7bfbf39..8726ff77763 100644
--- a/include/linux/virtio_balloon.h
+++ b/include/linux/virtio_balloon.h
@@ -10,6 +10,9 @@
10/* The feature bitmap for virtio balloon */ 10/* The feature bitmap for virtio balloon */
11#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */ 11#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
12 12
13/* Size of a PFN in the balloon interface. */
14#define VIRTIO_BALLOON_PFN_SHIFT 12
15
13struct virtio_balloon_config 16struct virtio_balloon_config
14{ 17{
15 /* Number of pages host wants Guest to give up. */ 18 /* Number of pages host wants Guest to give up. */