2 * Virtio balloon implementation, inspired by Dor Laor and Marcelo
3 * Tosatti's implementations.
5 * Copyright 2008 Rusty Russell IBM Corporation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <linux/virtio.h>
23 #include <linux/virtio_balloon.h>
24 #include <linux/swap.h>
25 #include <linux/workqueue.h>
26 #include <linux/delay.h>
27 #include <linux/slab.h>
28 #include <linux/module.h>
29 #include <linux/balloon_compaction.h>
30 #include <linux/wait.h>
32 #include <linux/mount.h>
33 #include <linux/magic.h>
36 * Balloon device works in 4K page units. So each page is pointed to by
37 * multiple balloon pages. All memory counters in this driver are in balloon
40 #define VIRTIO_BALLOON_PAGES_PER_PAGE (unsigned)(PAGE_SIZE >> VIRTIO_BALLOON_PFN_SHIFT)
41 #define VIRTIO_BALLOON_ARRAY_PFNS_MAX 256
42 #define VIRTBALLOON_OOM_NOTIFY_PRIORITY 80
44 #ifdef CONFIG_BALLOON_COMPACTION
45 static struct vfsmount
*balloon_mnt
;
48 struct virtio_balloon
{
49 struct virtio_device
*vdev
;
50 struct virtqueue
*inflate_vq
, *deflate_vq
, *stats_vq
;
52 /* The balloon servicing is delegated to a freezable workqueue. */
53 struct work_struct update_balloon_stats_work
;
54 struct work_struct update_balloon_size_work
;
56 /* Prevent updating balloon when it is being canceled. */
57 spinlock_t stop_update_lock
;
60 /* Waiting for host to ack the pages we released. */
61 wait_queue_head_t acked
;
63 /* Number of balloon pages we've told the Host we're not using. */
64 unsigned int num_pages
;
66 * The pages we've told the Host we're not using are enqueued
67 * at vb_dev_info->pages list.
68 * Each page on this list adds VIRTIO_BALLOON_PAGES_PER_PAGE
71 struct balloon_dev_info vb_dev_info
;
73 /* Synchronize access/update to this struct virtio_balloon elements */
74 struct mutex balloon_lock
;
76 /* The array of pfns we tell the Host about. */
77 unsigned int num_pfns
;
78 __virtio32 pfns
[VIRTIO_BALLOON_ARRAY_PFNS_MAX
];
80 /* Memory statistics */
81 struct virtio_balloon_stat stats
[VIRTIO_BALLOON_S_NR
];
83 /* To register a shrinker to shrink memory upon memory pressure */
84 struct shrinker shrinker
;
87 static struct virtio_device_id id_table
[] = {
88 { VIRTIO_ID_BALLOON
, VIRTIO_DEV_ANY_ID
},
92 static u32
page_to_balloon_pfn(struct page
*page
)
94 unsigned long pfn
= page_to_pfn(page
);
96 BUILD_BUG_ON(PAGE_SHIFT
< VIRTIO_BALLOON_PFN_SHIFT
);
97 /* Convert pfn from Linux page size to balloon page size. */
98 return pfn
* VIRTIO_BALLOON_PAGES_PER_PAGE
;
101 static void balloon_ack(struct virtqueue
*vq
)
103 struct virtio_balloon
*vb
= vq
->vdev
->priv
;
108 static void tell_host(struct virtio_balloon
*vb
, struct virtqueue
*vq
)
110 struct scatterlist sg
;
113 sg_init_one(&sg
, vb
->pfns
, sizeof(vb
->pfns
[0]) * vb
->num_pfns
);
115 /* We should always be able to add one buffer to an empty queue. */
116 virtqueue_add_outbuf(vq
, &sg
, 1, vb
, GFP_KERNEL
);
119 /* When host has read buffer, this completes via balloon_ack */
120 wait_event(vb
->acked
, virtqueue_get_buf(vq
, &len
));
124 static void set_page_pfns(struct virtio_balloon
*vb
,
125 __virtio32 pfns
[], struct page
*page
)
130 * Set balloon pfns pointing at this page.
131 * Note that the first pfn points at start of the page.
133 for (i
= 0; i
< VIRTIO_BALLOON_PAGES_PER_PAGE
; i
++)
134 pfns
[i
] = cpu_to_virtio32(vb
->vdev
,
135 page_to_balloon_pfn(page
) + i
);
138 static unsigned fill_balloon(struct virtio_balloon
*vb
, size_t num
)
140 unsigned num_allocated_pages
;
145 /* We can only do one array worth at a time. */
146 num
= min(num
, ARRAY_SIZE(vb
->pfns
));
148 for (num_pfns
= 0; num_pfns
< num
;
149 num_pfns
+= VIRTIO_BALLOON_PAGES_PER_PAGE
) {
150 struct page
*page
= balloon_page_alloc();
153 dev_info_ratelimited(&vb
->vdev
->dev
,
154 "Out of puff! Can't get %u pages\n",
155 VIRTIO_BALLOON_PAGES_PER_PAGE
);
156 /* Sleep for at least 1/5 of a second before retry. */
161 balloon_page_push(&pages
, page
);
164 mutex_lock(&vb
->balloon_lock
);
168 while ((page
= balloon_page_pop(&pages
))) {
169 balloon_page_enqueue(&vb
->vb_dev_info
, page
);
171 set_page_pfns(vb
, vb
->pfns
+ vb
->num_pfns
, page
);
172 vb
->num_pages
+= VIRTIO_BALLOON_PAGES_PER_PAGE
;
173 if (!virtio_has_feature(vb
->vdev
,
174 VIRTIO_BALLOON_F_DEFLATE_ON_OOM
))
175 adjust_managed_page_count(page
, -1);
176 vb
->num_pfns
+= VIRTIO_BALLOON_PAGES_PER_PAGE
;
179 num_allocated_pages
= vb
->num_pfns
;
180 /* Did we get any? */
181 if (vb
->num_pfns
!= 0)
182 tell_host(vb
, vb
->inflate_vq
);
183 mutex_unlock(&vb
->balloon_lock
);
185 return num_allocated_pages
;
188 static void release_pages_balloon(struct virtio_balloon
*vb
,
189 struct list_head
*pages
)
191 struct page
*page
, *next
;
193 list_for_each_entry_safe(page
, next
, pages
, lru
) {
194 if (!virtio_has_feature(vb
->vdev
,
195 VIRTIO_BALLOON_F_DEFLATE_ON_OOM
))
196 adjust_managed_page_count(page
, 1);
197 list_del(&page
->lru
);
198 put_page(page
); /* balloon reference */
202 static unsigned leak_balloon(struct virtio_balloon
*vb
, size_t num
)
204 unsigned num_freed_pages
;
206 struct balloon_dev_info
*vb_dev_info
= &vb
->vb_dev_info
;
209 /* We can only do one array worth at a time. */
210 num
= min(num
, ARRAY_SIZE(vb
->pfns
));
212 mutex_lock(&vb
->balloon_lock
);
213 /* We can't release more pages than taken */
214 num
= min(num
, (size_t)vb
->num_pages
);
215 for (vb
->num_pfns
= 0; vb
->num_pfns
< num
;
216 vb
->num_pfns
+= VIRTIO_BALLOON_PAGES_PER_PAGE
) {
217 page
= balloon_page_dequeue(vb_dev_info
);
220 set_page_pfns(vb
, vb
->pfns
+ vb
->num_pfns
, page
);
221 list_add(&page
->lru
, &pages
);
222 vb
->num_pages
-= VIRTIO_BALLOON_PAGES_PER_PAGE
;
225 num_freed_pages
= vb
->num_pfns
;
228 * virtio_has_feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST);
229 * is true, we *have* to do it in this order
231 if (vb
->num_pfns
!= 0)
232 tell_host(vb
, vb
->deflate_vq
);
233 release_pages_balloon(vb
, &pages
);
234 mutex_unlock(&vb
->balloon_lock
);
235 return num_freed_pages
;
238 static inline void update_stat(struct virtio_balloon
*vb
, int idx
,
241 BUG_ON(idx
>= VIRTIO_BALLOON_S_NR
);
242 vb
->stats
[idx
].tag
= cpu_to_virtio16(vb
->vdev
, tag
);
243 vb
->stats
[idx
].val
= cpu_to_virtio64(vb
->vdev
, val
);
246 #define pages_to_bytes(x) ((u64)(x) << PAGE_SHIFT)
248 static unsigned int update_balloon_stats(struct virtio_balloon
*vb
)
250 unsigned long events
[NR_VM_EVENT_ITEMS
];
252 unsigned int idx
= 0;
254 unsigned long caches
;
256 all_vm_events(events
);
259 available
= si_mem_available();
260 caches
= global_node_page_state(NR_FILE_PAGES
);
262 #ifdef CONFIG_VM_EVENT_COUNTERS
263 update_stat(vb
, idx
++, VIRTIO_BALLOON_S_SWAP_IN
,
264 pages_to_bytes(events
[PSWPIN
]));
265 update_stat(vb
, idx
++, VIRTIO_BALLOON_S_SWAP_OUT
,
266 pages_to_bytes(events
[PSWPOUT
]));
267 update_stat(vb
, idx
++, VIRTIO_BALLOON_S_MAJFLT
, events
[PGMAJFAULT
]);
268 update_stat(vb
, idx
++, VIRTIO_BALLOON_S_MINFLT
, events
[PGFAULT
]);
269 #ifdef CONFIG_HUGETLB_PAGE
270 update_stat(vb
, idx
++, VIRTIO_BALLOON_S_HTLB_PGALLOC
,
271 events
[HTLB_BUDDY_PGALLOC
]);
272 update_stat(vb
, idx
++, VIRTIO_BALLOON_S_HTLB_PGFAIL
,
273 events
[HTLB_BUDDY_PGALLOC_FAIL
]);
276 update_stat(vb
, idx
++, VIRTIO_BALLOON_S_MEMFREE
,
277 pages_to_bytes(i
.freeram
));
278 update_stat(vb
, idx
++, VIRTIO_BALLOON_S_MEMTOT
,
279 pages_to_bytes(i
.totalram
));
280 update_stat(vb
, idx
++, VIRTIO_BALLOON_S_AVAIL
,
281 pages_to_bytes(available
));
282 update_stat(vb
, idx
++, VIRTIO_BALLOON_S_CACHES
,
283 pages_to_bytes(caches
));
289 * While most virtqueues communicate guest-initiated requests to the hypervisor,
290 * the stats queue operates in reverse. The driver initializes the virtqueue
291 * with a single buffer. From that point forward, all conversations consist of
292 * a hypervisor request (a call to this function) which directs us to refill
293 * the virtqueue with a fresh stats buffer. Since stats collection can sleep,
294 * we delegate the job to a freezable workqueue that will do the actual work via
295 * stats_handle_request().
297 static void stats_request(struct virtqueue
*vq
)
299 struct virtio_balloon
*vb
= vq
->vdev
->priv
;
301 spin_lock(&vb
->stop_update_lock
);
302 if (!vb
->stop_update
)
303 queue_work(system_freezable_wq
, &vb
->update_balloon_stats_work
);
304 spin_unlock(&vb
->stop_update_lock
);
307 static void stats_handle_request(struct virtio_balloon
*vb
)
309 struct virtqueue
*vq
;
310 struct scatterlist sg
;
311 unsigned int len
, num_stats
;
313 num_stats
= update_balloon_stats(vb
);
316 if (!virtqueue_get_buf(vq
, &len
))
318 sg_init_one(&sg
, vb
->stats
, sizeof(vb
->stats
[0]) * num_stats
);
319 virtqueue_add_outbuf(vq
, &sg
, 1, vb
, GFP_KERNEL
);
323 static void virtballoon_changed(struct virtio_device
*vdev
)
325 struct virtio_balloon
*vb
= vdev
->priv
;
328 spin_lock_irqsave(&vb
->stop_update_lock
, flags
);
329 if (!vb
->stop_update
)
330 queue_work(system_freezable_wq
, &vb
->update_balloon_size_work
);
331 spin_unlock_irqrestore(&vb
->stop_update_lock
, flags
);
334 static inline s64
towards_target(struct virtio_balloon
*vb
)
339 virtio_cread(vb
->vdev
, struct virtio_balloon_config
, num_pages
,
342 /* Legacy balloon config space is LE, unlike all other devices. */
343 if (!virtio_has_feature(vb
->vdev
, VIRTIO_F_VERSION_1
))
344 num_pages
= le32_to_cpu((__force __le32
)num_pages
);
347 return target
- vb
->num_pages
;
350 static void update_balloon_size(struct virtio_balloon
*vb
)
352 u32 actual
= vb
->num_pages
;
354 /* Legacy balloon config space is LE, unlike all other devices. */
355 if (!virtio_has_feature(vb
->vdev
, VIRTIO_F_VERSION_1
))
356 actual
= (__force u32
)cpu_to_le32(actual
);
358 virtio_cwrite(vb
->vdev
, struct virtio_balloon_config
, actual
,
362 static void update_balloon_stats_func(struct work_struct
*work
)
364 struct virtio_balloon
*vb
;
366 vb
= container_of(work
, struct virtio_balloon
,
367 update_balloon_stats_work
);
368 stats_handle_request(vb
);
371 static void update_balloon_size_func(struct work_struct
*work
)
373 struct virtio_balloon
*vb
;
376 vb
= container_of(work
, struct virtio_balloon
,
377 update_balloon_size_work
);
378 diff
= towards_target(vb
);
381 diff
-= fill_balloon(vb
, diff
);
383 diff
+= leak_balloon(vb
, -diff
);
384 update_balloon_size(vb
);
387 queue_work(system_freezable_wq
, work
);
390 static int init_vqs(struct virtio_balloon
*vb
)
392 struct virtqueue
*vqs
[3];
393 vq_callback_t
*callbacks
[] = { balloon_ack
, balloon_ack
, stats_request
};
394 static const char * const names
[] = { "inflate", "deflate", "stats" };
398 * We expect two virtqueues: inflate and deflate, and
401 nvqs
= virtio_has_feature(vb
->vdev
, VIRTIO_BALLOON_F_STATS_VQ
) ? 3 : 2;
402 err
= virtio_find_vqs(vb
->vdev
, nvqs
, vqs
, callbacks
, names
, NULL
);
406 vb
->inflate_vq
= vqs
[0];
407 vb
->deflate_vq
= vqs
[1];
408 if (virtio_has_feature(vb
->vdev
, VIRTIO_BALLOON_F_STATS_VQ
)) {
409 struct scatterlist sg
;
410 unsigned int num_stats
;
411 vb
->stats_vq
= vqs
[2];
414 * Prime this virtqueue with one buffer so the hypervisor can
415 * use it to signal us later (it can't be broken yet!).
417 num_stats
= update_balloon_stats(vb
);
419 sg_init_one(&sg
, vb
->stats
, sizeof(vb
->stats
[0]) * num_stats
);
420 err
= virtqueue_add_outbuf(vb
->stats_vq
, &sg
, 1, vb
,
423 dev_warn(&vb
->vdev
->dev
, "%s: add stat_vq failed\n",
427 virtqueue_kick(vb
->stats_vq
);
432 #ifdef CONFIG_BALLOON_COMPACTION
434 * virtballoon_migratepage - perform the balloon page migration on behalf of
435 * a compation thread. (called under page lock)
436 * @vb_dev_info: the balloon device
437 * @newpage: page that will replace the isolated page after migration finishes.
438 * @page : the isolated (old) page that is about to be migrated to newpage.
439 * @mode : compaction mode -- not used for balloon page migration.
441 * After a ballooned page gets isolated by compaction procedures, this is the
442 * function that performs the page migration on behalf of a compaction thread
443 * The page migration for virtio balloon is done in a simple swap fashion which
444 * follows these two macro steps:
445 * 1) insert newpage into vb->pages list and update the host about it;
446 * 2) update the host about the old page removed from vb->pages list;
448 * This function preforms the balloon page migration task.
449 * Called through balloon_mapping->a_ops->migratepage
451 static int virtballoon_migratepage(struct balloon_dev_info
*vb_dev_info
,
452 struct page
*newpage
, struct page
*page
, enum migrate_mode mode
)
454 struct virtio_balloon
*vb
= container_of(vb_dev_info
,
455 struct virtio_balloon
, vb_dev_info
);
459 * In order to avoid lock contention while migrating pages concurrently
460 * to leak_balloon() or fill_balloon() we just give up the balloon_lock
461 * this turn, as it is easier to retry the page migration later.
462 * This also prevents fill_balloon() getting stuck into a mutex
463 * recursion in the case it ends up triggering memory compaction
464 * while it is attempting to inflate the ballon.
466 if (!mutex_trylock(&vb
->balloon_lock
))
469 get_page(newpage
); /* balloon reference */
471 /* balloon's page migration 1st step -- inflate "newpage" */
472 spin_lock_irqsave(&vb_dev_info
->pages_lock
, flags
);
473 balloon_page_insert(vb_dev_info
, newpage
);
474 vb_dev_info
->isolated_pages
--;
475 __count_vm_event(BALLOON_MIGRATE
);
476 spin_unlock_irqrestore(&vb_dev_info
->pages_lock
, flags
);
477 vb
->num_pfns
= VIRTIO_BALLOON_PAGES_PER_PAGE
;
478 set_page_pfns(vb
, vb
->pfns
, newpage
);
479 tell_host(vb
, vb
->inflate_vq
);
481 /* balloon's page migration 2nd step -- deflate "page" */
482 spin_lock_irqsave(&vb_dev_info
->pages_lock
, flags
);
483 balloon_page_delete(page
);
484 spin_unlock_irqrestore(&vb_dev_info
->pages_lock
, flags
);
485 vb
->num_pfns
= VIRTIO_BALLOON_PAGES_PER_PAGE
;
486 set_page_pfns(vb
, vb
->pfns
, page
);
487 tell_host(vb
, vb
->deflate_vq
);
489 mutex_unlock(&vb
->balloon_lock
);
491 put_page(page
); /* balloon reference */
493 return MIGRATEPAGE_SUCCESS
;
496 static struct dentry
*balloon_mount(struct file_system_type
*fs_type
,
497 int flags
, const char *dev_name
, void *data
)
499 static const struct dentry_operations ops
= {
500 .d_dname
= simple_dname
,
503 return mount_pseudo(fs_type
, "balloon-kvm:", NULL
, &ops
,
507 static struct file_system_type balloon_fs
= {
508 .name
= "balloon-kvm",
509 .mount
= balloon_mount
,
510 .kill_sb
= kill_anon_super
,
513 #endif /* CONFIG_BALLOON_COMPACTION */
515 static unsigned long virtio_balloon_shrinker_scan(struct shrinker
*shrinker
,
516 struct shrink_control
*sc
)
518 unsigned long pages_to_free
, pages_freed
= 0;
519 struct virtio_balloon
*vb
= container_of(shrinker
,
520 struct virtio_balloon
, shrinker
);
522 pages_to_free
= sc
->nr_to_scan
* VIRTIO_BALLOON_PAGES_PER_PAGE
;
525 * One invocation of leak_balloon can deflate at most
526 * VIRTIO_BALLOON_ARRAY_PFNS_MAX balloon pages, so we call it
527 * multiple times to deflate pages till reaching pages_to_free.
529 while (vb
->num_pages
&& pages_to_free
) {
530 pages_to_free
-= pages_freed
;
531 pages_freed
+= leak_balloon(vb
, pages_to_free
);
533 update_balloon_size(vb
);
535 return pages_freed
/ VIRTIO_BALLOON_PAGES_PER_PAGE
;
538 static unsigned long virtio_balloon_shrinker_count(struct shrinker
*shrinker
,
539 struct shrink_control
*sc
)
541 struct virtio_balloon
*vb
= container_of(shrinker
,
542 struct virtio_balloon
, shrinker
);
544 return vb
->num_pages
/ VIRTIO_BALLOON_PAGES_PER_PAGE
;
547 static void virtio_balloon_unregister_shrinker(struct virtio_balloon
*vb
)
549 unregister_shrinker(&vb
->shrinker
);
552 static int virtio_balloon_register_shrinker(struct virtio_balloon
*vb
)
554 vb
->shrinker
.scan_objects
= virtio_balloon_shrinker_scan
;
555 vb
->shrinker
.count_objects
= virtio_balloon_shrinker_count
;
556 vb
->shrinker
.seeks
= DEFAULT_SEEKS
;
558 return register_shrinker(&vb
->shrinker
);
561 static int virtballoon_probe(struct virtio_device
*vdev
)
563 struct virtio_balloon
*vb
;
566 if (!vdev
->config
->get
) {
567 dev_err(&vdev
->dev
, "%s failure: config access disabled\n",
572 vdev
->priv
= vb
= kzalloc(sizeof(*vb
), GFP_KERNEL
);
578 INIT_WORK(&vb
->update_balloon_stats_work
, update_balloon_stats_func
);
579 INIT_WORK(&vb
->update_balloon_size_work
, update_balloon_size_func
);
580 spin_lock_init(&vb
->stop_update_lock
);
581 mutex_init(&vb
->balloon_lock
);
582 init_waitqueue_head(&vb
->acked
);
585 balloon_devinfo_init(&vb
->vb_dev_info
);
591 #ifdef CONFIG_BALLOON_COMPACTION
592 balloon_mnt
= kern_mount(&balloon_fs
);
593 if (IS_ERR(balloon_mnt
)) {
594 err
= PTR_ERR(balloon_mnt
);
598 vb
->vb_dev_info
.migratepage
= virtballoon_migratepage
;
599 vb
->vb_dev_info
.inode
= alloc_anon_inode(balloon_mnt
->mnt_sb
);
600 if (IS_ERR(vb
->vb_dev_info
.inode
)) {
601 err
= PTR_ERR(vb
->vb_dev_info
.inode
);
602 kern_unmount(balloon_mnt
);
605 vb
->vb_dev_info
.inode
->i_mapping
->a_ops
= &balloon_aops
;
608 * We continue to use VIRTIO_BALLOON_F_DEFLATE_ON_OOM to decide if a
609 * shrinker needs to be registered to relieve memory pressure.
611 if (virtio_has_feature(vb
->vdev
, VIRTIO_BALLOON_F_DEFLATE_ON_OOM
)) {
612 err
= virtio_balloon_register_shrinker(vb
);
616 virtio_device_ready(vdev
);
618 if (towards_target(vb
))
619 virtballoon_changed(vdev
);
623 vdev
->config
->del_vqs(vdev
);
630 static void remove_common(struct virtio_balloon
*vb
)
632 /* There might be pages left in the balloon: free them. */
633 while (vb
->num_pages
)
634 leak_balloon(vb
, vb
->num_pages
);
635 update_balloon_size(vb
);
637 /* Now we reset the device so we can clean up the queues. */
638 vb
->vdev
->config
->reset(vb
->vdev
);
640 vb
->vdev
->config
->del_vqs(vb
->vdev
);
643 static void virtballoon_remove(struct virtio_device
*vdev
)
645 struct virtio_balloon
*vb
= vdev
->priv
;
647 if (virtio_has_feature(vb
->vdev
, VIRTIO_BALLOON_F_DEFLATE_ON_OOM
))
648 virtio_balloon_unregister_shrinker(vb
);
649 spin_lock_irq(&vb
->stop_update_lock
);
650 vb
->stop_update
= true;
651 spin_unlock_irq(&vb
->stop_update_lock
);
652 cancel_work_sync(&vb
->update_balloon_size_work
);
653 cancel_work_sync(&vb
->update_balloon_stats_work
);
656 #ifdef CONFIG_BALLOON_COMPACTION
657 if (vb
->vb_dev_info
.inode
)
658 iput(vb
->vb_dev_info
.inode
);
660 kern_unmount(balloon_mnt
);
665 #ifdef CONFIG_PM_SLEEP
666 static int virtballoon_freeze(struct virtio_device
*vdev
)
668 struct virtio_balloon
*vb
= vdev
->priv
;
671 * The workqueue is already frozen by the PM core before this
672 * function is called.
678 static int virtballoon_restore(struct virtio_device
*vdev
)
680 struct virtio_balloon
*vb
= vdev
->priv
;
683 ret
= init_vqs(vdev
->priv
);
687 virtio_device_ready(vdev
);
689 if (towards_target(vb
))
690 virtballoon_changed(vdev
);
691 update_balloon_size(vb
);
696 static int virtballoon_validate(struct virtio_device
*vdev
)
698 __virtio_clear_bit(vdev
, VIRTIO_F_IOMMU_PLATFORM
);
702 static unsigned int features
[] = {
703 VIRTIO_BALLOON_F_MUST_TELL_HOST
,
704 VIRTIO_BALLOON_F_STATS_VQ
,
705 VIRTIO_BALLOON_F_DEFLATE_ON_OOM
,
708 static struct virtio_driver virtio_balloon_driver
= {
709 .feature_table
= features
,
710 .feature_table_size
= ARRAY_SIZE(features
),
711 .driver
.name
= KBUILD_MODNAME
,
712 .driver
.owner
= THIS_MODULE
,
713 .id_table
= id_table
,
714 .validate
= virtballoon_validate
,
715 .probe
= virtballoon_probe
,
716 .remove
= virtballoon_remove
,
717 .config_changed
= virtballoon_changed
,
718 #ifdef CONFIG_PM_SLEEP
719 .freeze
= virtballoon_freeze
,
720 .restore
= virtballoon_restore
,
724 module_virtio_driver(virtio_balloon_driver
);
725 MODULE_DEVICE_TABLE(virtio
, id_table
);
726 MODULE_DESCRIPTION("Virtio balloon driver");
727 MODULE_LICENSE("GPL");