diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2016-05-17 06:31:18 -0400 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2016-05-22 12:44:13 -0400 |
commit | 87c9403b0d1de4676b0bd273eea68fcf6de68e68 (patch) | |
tree | 18793d3de167ca35dd04e45f8a33a777da37256d /drivers/virtio | |
parent | ce10c1b95095c652461616a3f887f6412ab6e1cc (diff) |
virtio_balloon: fix PFN format for virtio-1
Everything should be LE when using virtio-1, but
the linux balloon driver does not seem to care about that.
Reported-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Diffstat (limited to 'drivers/virtio')
-rw-r--r-- | drivers/virtio/virtio_balloon.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 7b6d74f0c72f..476c0e3a7150 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c | |||
@@ -75,7 +75,7 @@ struct virtio_balloon { | |||
75 | 75 | ||
76 | /* The array of pfns we tell the Host about. */ | 76 | /* The array of pfns we tell the Host about. */ |
77 | unsigned int num_pfns; | 77 | unsigned int num_pfns; |
78 | u32 pfns[VIRTIO_BALLOON_ARRAY_PFNS_MAX]; | 78 | __virtio32 pfns[VIRTIO_BALLOON_ARRAY_PFNS_MAX]; |
79 | 79 | ||
80 | /* Memory statistics */ | 80 | /* Memory statistics */ |
81 | struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR]; | 81 | struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR]; |
@@ -127,14 +127,16 @@ static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) | |||
127 | 127 | ||
128 | } | 128 | } |
129 | 129 | ||
130 | static void set_page_pfns(u32 pfns[], struct page *page) | 130 | static void set_page_pfns(struct virtio_balloon *vb, |
131 | __virtio32 pfns[], struct page *page) | ||
131 | { | 132 | { |
132 | unsigned int i; | 133 | unsigned int i; |
133 | 134 | ||
134 | /* Set balloon pfns pointing at this page. | 135 | /* Set balloon pfns pointing at this page. |
135 | * Note that the first pfn points at start of the page. */ | 136 | * Note that the first pfn points at start of the page. */ |
136 | for (i = 0; i < VIRTIO_BALLOON_PAGES_PER_PAGE; i++) | 137 | for (i = 0; i < VIRTIO_BALLOON_PAGES_PER_PAGE; i++) |
137 | pfns[i] = page_to_balloon_pfn(page) + i; | 138 | pfns[i] = cpu_to_virtio32(vb->vdev, |
139 | page_to_balloon_pfn(page) + i); | ||
138 | } | 140 | } |
139 | 141 | ||
140 | static unsigned fill_balloon(struct virtio_balloon *vb, size_t num) | 142 | static unsigned fill_balloon(struct virtio_balloon *vb, size_t num) |
@@ -158,7 +160,7 @@ static unsigned fill_balloon(struct virtio_balloon *vb, size_t num) | |||
158 | msleep(200); | 160 | msleep(200); |
159 | break; | 161 | break; |
160 | } | 162 | } |
161 | set_page_pfns(vb->pfns + vb->num_pfns, page); | 163 | set_page_pfns(vb, vb->pfns + vb->num_pfns, page); |
162 | vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE; | 164 | vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE; |
163 | if (!virtio_has_feature(vb->vdev, | 165 | if (!virtio_has_feature(vb->vdev, |
164 | VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) | 166 | VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) |
@@ -177,10 +179,12 @@ static unsigned fill_balloon(struct virtio_balloon *vb, size_t num) | |||
177 | static void release_pages_balloon(struct virtio_balloon *vb) | 179 | static void release_pages_balloon(struct virtio_balloon *vb) |
178 | { | 180 | { |
179 | unsigned int i; | 181 | unsigned int i; |
182 | struct page *page; | ||
180 | 183 | ||
181 | /* Find pfns pointing at start of each page, get pages and free them. */ | 184 | /* Find pfns pointing at start of each page, get pages and free them. */ |
182 | for (i = 0; i < vb->num_pfns; i += VIRTIO_BALLOON_PAGES_PER_PAGE) { | 185 | for (i = 0; i < vb->num_pfns; i += VIRTIO_BALLOON_PAGES_PER_PAGE) { |
183 | struct page *page = balloon_pfn_to_page(vb->pfns[i]); | 186 | page = balloon_pfn_to_page(virtio32_to_cpu(vb->vdev, |
187 | vb->pfns[i])); | ||
184 | if (!virtio_has_feature(vb->vdev, | 188 | if (!virtio_has_feature(vb->vdev, |
185 | VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) | 189 | VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) |
186 | adjust_managed_page_count(page, 1); | 190 | adjust_managed_page_count(page, 1); |
@@ -203,7 +207,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, size_t num) | |||
203 | page = balloon_page_dequeue(vb_dev_info); | 207 | page = balloon_page_dequeue(vb_dev_info); |
204 | if (!page) | 208 | if (!page) |
205 | break; | 209 | break; |
206 | set_page_pfns(vb->pfns + vb->num_pfns, page); | 210 | set_page_pfns(vb, vb->pfns + vb->num_pfns, page); |
207 | vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE; | 211 | vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE; |
208 | } | 212 | } |
209 | 213 | ||
@@ -471,13 +475,13 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info, | |||
471 | __count_vm_event(BALLOON_MIGRATE); | 475 | __count_vm_event(BALLOON_MIGRATE); |
472 | spin_unlock_irqrestore(&vb_dev_info->pages_lock, flags); | 476 | spin_unlock_irqrestore(&vb_dev_info->pages_lock, flags); |
473 | vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE; | 477 | vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE; |
474 | set_page_pfns(vb->pfns, newpage); | 478 | set_page_pfns(vb, vb->pfns, newpage); |
475 | tell_host(vb, vb->inflate_vq); | 479 | tell_host(vb, vb->inflate_vq); |
476 | 480 | ||
477 | /* balloon's page migration 2nd step -- deflate "page" */ | 481 | /* balloon's page migration 2nd step -- deflate "page" */ |
478 | balloon_page_delete(page); | 482 | balloon_page_delete(page); |
479 | vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE; | 483 | vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE; |
480 | set_page_pfns(vb->pfns, page); | 484 | set_page_pfns(vb, vb->pfns, page); |
481 | tell_host(vb, vb->deflate_vq); | 485 | tell_host(vb, vb->deflate_vq); |
482 | 486 | ||
483 | mutex_unlock(&vb->balloon_lock); | 487 | mutex_unlock(&vb->balloon_lock); |