linux/drivers/misc/vmw_balloon.c
<<
>>
Prefs
   1/*
   2 * VMware Balloon driver.
   3 *
   4 * Copyright (C) 2000-2014, VMware, Inc. All Rights Reserved.
   5 *
   6 * This program is free software; you can redistribute it and/or modify it
   7 * under the terms of the GNU General Public License as published by the
   8 * Free Software Foundation; version 2 of the License and no later version.
   9 *
  10 * This program is distributed in the hope that it will be useful, but
  11 * WITHOUT ANY WARRANTY; without even the implied warranty of
  12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  13 * NON INFRINGEMENT.  See the GNU General Public License for more
  14 * details.
  15 *
  16 * You should have received a copy of the GNU General Public License
  17 * along with this program; if not, write to the Free Software
  18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19 *
  20 * Maintained by:       Xavier Deguillard <xdeguillard@vmware.com>
  21 *                      Philip Moltmann <moltmann@vmware.com>
  22 */
  23
  24/*
  25 * This is VMware physical memory management driver for Linux. The driver
  26 * acts like a "balloon" that can be inflated to reclaim physical pages by
  27 * reserving them in the guest and invalidating them in the monitor,
  28 * freeing up the underlying machine pages so they can be allocated to
  29 * other guests.  The balloon can also be deflated to allow the guest to
  30 * use more physical memory. Higher level policies can control the sizes
  31 * of balloons in VMs in order to manage physical memory resources.
  32 */
  33
  34//#define DEBUG
  35#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  36
  37#include <linux/types.h>
  38#include <linux/io.h>
  39#include <linux/kernel.h>
  40#include <linux/mm.h>
  41#include <linux/vmalloc.h>
  42#include <linux/sched.h>
  43#include <linux/module.h>
  44#include <linux/workqueue.h>
  45#include <linux/debugfs.h>
  46#include <linux/seq_file.h>
  47#include <linux/vmw_vmci_defs.h>
  48#include <linux/vmw_vmci_api.h>
  49#include <asm/hypervisor.h>
  50
  51MODULE_AUTHOR("VMware, Inc.");
  52MODULE_DESCRIPTION("VMware Memory Control (Balloon) Driver");
  53MODULE_VERSION("1.5.0.0-k");
  54MODULE_ALIAS("dmi:*:svnVMware*:*");
  55MODULE_ALIAS("vmware_vmmemctl");
  56MODULE_LICENSE("GPL");
  57
  58/*
  59 * Various constants controlling rate of inflaint/deflating balloon,
  60 * measured in pages.
  61 */
  62
  63/*
  64 * Rates of memory allocaton when guest experiences memory pressure
  65 * (driver performs sleeping allocations).
  66 */
  67#define VMW_BALLOON_RATE_ALLOC_MIN      512U
  68#define VMW_BALLOON_RATE_ALLOC_MAX      2048U
  69#define VMW_BALLOON_RATE_ALLOC_INC      16U
  70
  71/*
  72 * When guest is under memory pressure, use a reduced page allocation
  73 * rate for next several cycles.
  74 */
  75#define VMW_BALLOON_SLOW_CYCLES         4
  76
  77/*
  78 * Use __GFP_HIGHMEM to allow pages from HIGHMEM zone. We don't
  79 * allow wait (__GFP_RECLAIM) for NOSLEEP page allocations. Use
  80 * __GFP_NOWARN, to suppress page allocation failure warnings.
  81 */
  82#define VMW_PAGE_ALLOC_NOSLEEP          (__GFP_HIGHMEM|__GFP_NOWARN)
  83
  84/*
  85 * Use GFP_HIGHUSER when executing in a separate kernel thread
  86 * context and allocation can sleep.  This is less stressful to
  87 * the guest memory system, since it allows the thread to block
  88 * while memory is reclaimed, and won't take pages from emergency
  89 * low-memory pools.
  90 */
  91#define VMW_PAGE_ALLOC_CANSLEEP         (GFP_HIGHUSER)
  92
  93/* Maximum number of refused pages we accumulate during inflation cycle */
  94#define VMW_BALLOON_MAX_REFUSED         16
  95
  96/*
  97 * Hypervisor communication port definitions.
  98 */
  99#define VMW_BALLOON_HV_PORT             0x5670
 100#define VMW_BALLOON_HV_MAGIC            0x456c6d6f
 101#define VMW_BALLOON_GUEST_ID            1       /* Linux */
 102
 103enum vmwballoon_capabilities {
 104        /*
 105         * Bit 0 is reserved and not associated to any capability.
 106         */
 107        VMW_BALLOON_BASIC_CMDS                  = (1 << 1),
 108        VMW_BALLOON_BATCHED_CMDS                = (1 << 2),
 109        VMW_BALLOON_BATCHED_2M_CMDS             = (1 << 3),
 110        VMW_BALLOON_SIGNALLED_WAKEUP_CMD        = (1 << 4),
 111};
 112
 113#define VMW_BALLOON_CAPABILITIES        (VMW_BALLOON_BASIC_CMDS \
 114                                        | VMW_BALLOON_BATCHED_CMDS \
 115                                        | VMW_BALLOON_BATCHED_2M_CMDS \
 116                                        | VMW_BALLOON_SIGNALLED_WAKEUP_CMD)
 117
 118#define VMW_BALLOON_2M_SHIFT            (9)
 119#define VMW_BALLOON_NUM_PAGE_SIZES      (2)
 120
 121/*
 122 * Backdoor commands availability:
 123 *
 124 * START, GET_TARGET and GUEST_ID are always available,
 125 *
 126 * VMW_BALLOON_BASIC_CMDS:
 127 *      LOCK and UNLOCK commands,
 128 * VMW_BALLOON_BATCHED_CMDS:
 129 *      BATCHED_LOCK and BATCHED_UNLOCK commands.
 130 * VMW BALLOON_BATCHED_2M_CMDS:
 131 *      BATCHED_2M_LOCK and BATCHED_2M_UNLOCK commands,
 132 * VMW VMW_BALLOON_SIGNALLED_WAKEUP_CMD:
 133 *      VMW_BALLOON_CMD_VMCI_DOORBELL_SET command.
 134 */
 135#define VMW_BALLOON_CMD_START                   0
 136#define VMW_BALLOON_CMD_GET_TARGET              1
 137#define VMW_BALLOON_CMD_LOCK                    2
 138#define VMW_BALLOON_CMD_UNLOCK                  3
 139#define VMW_BALLOON_CMD_GUEST_ID                4
 140#define VMW_BALLOON_CMD_BATCHED_LOCK            6
 141#define VMW_BALLOON_CMD_BATCHED_UNLOCK          7
 142#define VMW_BALLOON_CMD_BATCHED_2M_LOCK         8
 143#define VMW_BALLOON_CMD_BATCHED_2M_UNLOCK       9
 144#define VMW_BALLOON_CMD_VMCI_DOORBELL_SET       10
 145
 146
 147/* error codes */
 148#define VMW_BALLOON_SUCCESS                     0
 149#define VMW_BALLOON_FAILURE                     -1
 150#define VMW_BALLOON_ERROR_CMD_INVALID           1
 151#define VMW_BALLOON_ERROR_PPN_INVALID           2
 152#define VMW_BALLOON_ERROR_PPN_LOCKED            3
 153#define VMW_BALLOON_ERROR_PPN_UNLOCKED          4
 154#define VMW_BALLOON_ERROR_PPN_PINNED            5
 155#define VMW_BALLOON_ERROR_PPN_NOTNEEDED         6
 156#define VMW_BALLOON_ERROR_RESET                 7
 157#define VMW_BALLOON_ERROR_BUSY                  8
 158
 159#define VMW_BALLOON_SUCCESS_WITH_CAPABILITIES   (0x03000000)
 160
 161/* Batch page description */
 162
 163/*
 164 * Layout of a page in the batch page:
 165 *
 166 * +-------------+----------+--------+
 167 * |             |          |        |
 168 * | Page number | Reserved | Status |
 169 * |             |          |        |
 170 * +-------------+----------+--------+
 171 * 64  PAGE_SHIFT          6         0
 172 *
 173 * The reserved field should be set to 0.
 174 */
 175#define VMW_BALLOON_BATCH_MAX_PAGES     (PAGE_SIZE / sizeof(u64))
 176#define VMW_BALLOON_BATCH_STATUS_MASK   ((1UL << 5) - 1)
 177#define VMW_BALLOON_BATCH_PAGE_MASK     (~((1UL << PAGE_SHIFT) - 1))
 178
 179struct vmballoon_batch_page {
 180        u64 pages[VMW_BALLOON_BATCH_MAX_PAGES];
 181};
 182
 183static u64 vmballoon_batch_get_pa(struct vmballoon_batch_page *batch, int idx)
 184{
 185        return batch->pages[idx] & VMW_BALLOON_BATCH_PAGE_MASK;
 186}
 187
 188static int vmballoon_batch_get_status(struct vmballoon_batch_page *batch,
 189                                int idx)
 190{
 191        return (int)(batch->pages[idx] & VMW_BALLOON_BATCH_STATUS_MASK);
 192}
 193
 194static void vmballoon_batch_set_pa(struct vmballoon_batch_page *batch, int idx,
 195                                u64 pa)
 196{
 197        batch->pages[idx] = pa;
 198}
 199
 200
 201#define VMWARE_BALLOON_CMD(cmd, arg1, arg2, result)             \
 202({                                                              \
 203        unsigned long __status, __dummy1, __dummy2, __dummy3;   \
 204        __asm__ __volatile__ ("inl %%dx" :                      \
 205                "=a"(__status),                                 \
 206                "=c"(__dummy1),                                 \
 207                "=d"(__dummy2),                                 \
 208                "=b"(result),                                   \
 209                "=S" (__dummy3) :                               \
 210                "0"(VMW_BALLOON_HV_MAGIC),                      \
 211                "1"(VMW_BALLOON_CMD_##cmd),                     \
 212                "2"(VMW_BALLOON_HV_PORT),                       \
 213                "3"(arg1),                                      \
 214                "4" (arg2) :                                    \
 215                "memory");                                      \
 216        if (VMW_BALLOON_CMD_##cmd == VMW_BALLOON_CMD_START)     \
 217                result = __dummy1;                              \
 218        result &= -1UL;                                         \
 219        __status & -1UL;                                        \
 220})
 221
 222#ifdef CONFIG_DEBUG_FS
 223struct vmballoon_stats {
 224        unsigned int timer;
 225        unsigned int doorbell;
 226
 227        /* allocation statistics */
 228        unsigned int alloc[VMW_BALLOON_NUM_PAGE_SIZES];
 229        unsigned int alloc_fail[VMW_BALLOON_NUM_PAGE_SIZES];
 230        unsigned int sleep_alloc;
 231        unsigned int sleep_alloc_fail;
 232        unsigned int refused_alloc[VMW_BALLOON_NUM_PAGE_SIZES];
 233        unsigned int refused_free[VMW_BALLOON_NUM_PAGE_SIZES];
 234        unsigned int free[VMW_BALLOON_NUM_PAGE_SIZES];
 235
 236        /* monitor operations */
 237        unsigned int lock[VMW_BALLOON_NUM_PAGE_SIZES];
 238        unsigned int lock_fail[VMW_BALLOON_NUM_PAGE_SIZES];
 239        unsigned int unlock[VMW_BALLOON_NUM_PAGE_SIZES];
 240        unsigned int unlock_fail[VMW_BALLOON_NUM_PAGE_SIZES];
 241        unsigned int target;
 242        unsigned int target_fail;
 243        unsigned int start;
 244        unsigned int start_fail;
 245        unsigned int guest_type;
 246        unsigned int guest_type_fail;
 247        unsigned int doorbell_set;
 248        unsigned int doorbell_unset;
 249};
 250
 251#define STATS_INC(stat) (stat)++
 252#else
 253#define STATS_INC(stat)
 254#endif
 255
 256struct vmballoon;
 257
 258struct vmballoon_ops {
 259        void (*add_page)(struct vmballoon *b, int idx, struct page *p);
 260        int (*lock)(struct vmballoon *b, unsigned int num_pages,
 261                        bool is_2m_pages, unsigned int *target);
 262        int (*unlock)(struct vmballoon *b, unsigned int num_pages,
 263                        bool is_2m_pages, unsigned int *target);
 264};
 265
 266struct vmballoon_page_size {
 267        /* list of reserved physical pages */
 268        struct list_head pages;
 269
 270        /* transient list of non-balloonable pages */
 271        struct list_head refused_pages;
 272        unsigned int n_refused_pages;
 273};
 274
 275struct vmballoon {
 276        struct vmballoon_page_size page_sizes[VMW_BALLOON_NUM_PAGE_SIZES];
 277
 278        /* supported page sizes. 1 == 4k pages only, 2 == 4k and 2m pages */
 279        unsigned supported_page_sizes;
 280
 281        /* balloon size in pages */
 282        unsigned int size;
 283        unsigned int target;
 284
 285        /* reset flag */
 286        bool reset_required;
 287
 288        /* adjustment rates (pages per second) */
 289        unsigned int rate_alloc;
 290
 291        /* slowdown page allocations for next few cycles */
 292        unsigned int slow_allocation_cycles;
 293
 294        unsigned long capabilities;
 295
 296        struct vmballoon_batch_page *batch_page;
 297        unsigned int batch_max_pages;
 298        struct page *page;
 299
 300        const struct vmballoon_ops *ops;
 301
 302#ifdef CONFIG_DEBUG_FS
 303        /* statistics */
 304        struct vmballoon_stats stats;
 305
 306        /* debugfs file exporting statistics */
 307        struct dentry *dbg_entry;
 308#endif
 309
 310        struct sysinfo sysinfo;
 311
 312        struct delayed_work dwork;
 313
 314        struct vmci_handle vmci_doorbell;
 315};
 316
 317static struct vmballoon balloon;
 318
 319/*
 320 * Send "start" command to the host, communicating supported version
 321 * of the protocol.
 322 */
 323static bool vmballoon_send_start(struct vmballoon *b, unsigned long req_caps)
 324{
 325        unsigned long status, capabilities, dummy = 0;
 326        bool success;
 327
 328        STATS_INC(b->stats.start);
 329
 330        status = VMWARE_BALLOON_CMD(START, req_caps, dummy, capabilities);
 331
 332        switch (status) {
 333        case VMW_BALLOON_SUCCESS_WITH_CAPABILITIES:
 334                b->capabilities = capabilities;
 335                success = true;
 336                break;
 337        case VMW_BALLOON_SUCCESS:
 338                b->capabilities = VMW_BALLOON_BASIC_CMDS;
 339                success = true;
 340                break;
 341        default:
 342                success = false;
 343        }
 344
 345        if (b->capabilities & VMW_BALLOON_BATCHED_2M_CMDS)
 346                b->supported_page_sizes = 2;
 347        else
 348                b->supported_page_sizes = 1;
 349
 350        if (!success) {
 351                pr_debug("%s - failed, hv returns %ld\n", __func__, status);
 352                STATS_INC(b->stats.start_fail);
 353        }
 354        return success;
 355}
 356
 357static bool vmballoon_check_status(struct vmballoon *b, unsigned long status)
 358{
 359        switch (status) {
 360        case VMW_BALLOON_SUCCESS:
 361                return true;
 362
 363        case VMW_BALLOON_ERROR_RESET:
 364                b->reset_required = true;
 365                /* fall through */
 366
 367        default:
 368                return false;
 369        }
 370}
 371
 372/*
 373 * Communicate guest type to the host so that it can adjust ballooning
 374 * algorithm to the one most appropriate for the guest. This command
 375 * is normally issued after sending "start" command and is part of
 376 * standard reset sequence.
 377 */
 378static bool vmballoon_send_guest_id(struct vmballoon *b)
 379{
 380        unsigned long status, dummy = 0;
 381
 382        status = VMWARE_BALLOON_CMD(GUEST_ID, VMW_BALLOON_GUEST_ID, dummy,
 383                                dummy);
 384
 385        STATS_INC(b->stats.guest_type);
 386
 387        if (vmballoon_check_status(b, status))
 388                return true;
 389
 390        pr_debug("%s - failed, hv returns %ld\n", __func__, status);
 391        STATS_INC(b->stats.guest_type_fail);
 392        return false;
 393}
 394
 395static u16 vmballoon_page_size(bool is_2m_page)
 396{
 397        if (is_2m_page)
 398                return 1 << VMW_BALLOON_2M_SHIFT;
 399
 400        return 1;
 401}
 402
 403/*
 404 * Retrieve desired balloon size from the host.
 405 */
 406static bool vmballoon_send_get_target(struct vmballoon *b, u32 *new_target)
 407{
 408        unsigned long status;
 409        unsigned long target;
 410        unsigned long limit;
 411        unsigned long dummy = 0;
 412        u32 limit32;
 413
 414        /*
 415         * si_meminfo() is cheap. Moreover, we want to provide dynamic
 416         * max balloon size later. So let us call si_meminfo() every
 417         * iteration.
 418         */
 419        si_meminfo(&b->sysinfo);
 420        limit = b->sysinfo.totalram;
 421
 422        /* Ensure limit fits in 32-bits */
 423        limit32 = (u32)limit;
 424        if (limit != limit32)
 425                return false;
 426
 427        /* update stats */
 428        STATS_INC(b->stats.target);
 429
 430        status = VMWARE_BALLOON_CMD(GET_TARGET, limit, dummy, target);
 431        if (vmballoon_check_status(b, status)) {
 432                *new_target = target;
 433                return true;
 434        }
 435
 436        pr_debug("%s - failed, hv returns %ld\n", __func__, status);
 437        STATS_INC(b->stats.target_fail);
 438        return false;
 439}
 440
 441/*
 442 * Notify the host about allocated page so that host can use it without
 443 * fear that guest will need it. Host may reject some pages, we need to
 444 * check the return value and maybe submit a different page.
 445 */
 446static int vmballoon_send_lock_page(struct vmballoon *b, unsigned long pfn,
 447                                unsigned int *hv_status, unsigned int *target)
 448{
 449        unsigned long status, dummy = 0;
 450        u32 pfn32;
 451
 452        pfn32 = (u32)pfn;
 453        if (pfn32 != pfn)
 454                return -1;
 455
 456        STATS_INC(b->stats.lock[false]);
 457
 458        *hv_status = status = VMWARE_BALLOON_CMD(LOCK, pfn, dummy, *target);
 459        if (vmballoon_check_status(b, status))
 460                return 0;
 461
 462        pr_debug("%s - ppn %lx, hv returns %ld\n", __func__, pfn, status);
 463        STATS_INC(b->stats.lock_fail[false]);
 464        return 1;
 465}
 466
 467static int vmballoon_send_batched_lock(struct vmballoon *b,
 468                unsigned int num_pages, bool is_2m_pages, unsigned int *target)
 469{
 470        unsigned long status;
 471        unsigned long pfn = PHYS_PFN(virt_to_phys(b->batch_page));
 472
 473        STATS_INC(b->stats.lock[is_2m_pages]);
 474
 475        if (is_2m_pages)
 476                status = VMWARE_BALLOON_CMD(BATCHED_2M_LOCK, pfn, num_pages,
 477                                *target);
 478        else
 479                status = VMWARE_BALLOON_CMD(BATCHED_LOCK, pfn, num_pages,
 480                                *target);
 481
 482        if (vmballoon_check_status(b, status))
 483                return 0;
 484
 485        pr_debug("%s - batch ppn %lx, hv returns %ld\n", __func__, pfn, status);
 486        STATS_INC(b->stats.lock_fail[is_2m_pages]);
 487        return 1;
 488}
 489
 490/*
 491 * Notify the host that guest intends to release given page back into
 492 * the pool of available (to the guest) pages.
 493 */
 494static bool vmballoon_send_unlock_page(struct vmballoon *b, unsigned long pfn,
 495                                                        unsigned int *target)
 496{
 497        unsigned long status, dummy = 0;
 498        u32 pfn32;
 499
 500        pfn32 = (u32)pfn;
 501        if (pfn32 != pfn)
 502                return false;
 503
 504        STATS_INC(b->stats.unlock[false]);
 505
 506        status = VMWARE_BALLOON_CMD(UNLOCK, pfn, dummy, *target);
 507        if (vmballoon_check_status(b, status))
 508                return true;
 509
 510        pr_debug("%s - ppn %lx, hv returns %ld\n", __func__, pfn, status);
 511        STATS_INC(b->stats.unlock_fail[false]);
 512        return false;
 513}
 514
 515static bool vmballoon_send_batched_unlock(struct vmballoon *b,
 516                unsigned int num_pages, bool is_2m_pages, unsigned int *target)
 517{
 518        unsigned long status;
 519        unsigned long pfn = PHYS_PFN(virt_to_phys(b->batch_page));
 520
 521        STATS_INC(b->stats.unlock[is_2m_pages]);
 522
 523        if (is_2m_pages)
 524                status = VMWARE_BALLOON_CMD(BATCHED_2M_UNLOCK, pfn, num_pages,
 525                                *target);
 526        else
 527                status = VMWARE_BALLOON_CMD(BATCHED_UNLOCK, pfn, num_pages,
 528                                *target);
 529
 530        if (vmballoon_check_status(b, status))
 531                return true;
 532
 533        pr_debug("%s - batch ppn %lx, hv returns %ld\n", __func__, pfn, status);
 534        STATS_INC(b->stats.unlock_fail[is_2m_pages]);
 535        return false;
 536}
 537
 538static struct page *vmballoon_alloc_page(gfp_t flags, bool is_2m_page)
 539{
 540        if (is_2m_page)
 541                return alloc_pages(flags, VMW_BALLOON_2M_SHIFT);
 542
 543        return alloc_page(flags);
 544}
 545
 546static void vmballoon_free_page(struct page *page, bool is_2m_page)
 547{
 548        if (is_2m_page)
 549                __free_pages(page, VMW_BALLOON_2M_SHIFT);
 550        else
 551                __free_page(page);
 552}
 553
 554/*
 555 * Quickly release all pages allocated for the balloon. This function is
 556 * called when host decides to "reset" balloon for one reason or another.
 557 * Unlike normal "deflate" we do not (shall not) notify host of the pages
 558 * being released.
 559 */
 560static void vmballoon_pop(struct vmballoon *b)
 561{
 562        struct page *page, *next;
 563        unsigned is_2m_pages;
 564
 565        for (is_2m_pages = 0; is_2m_pages < VMW_BALLOON_NUM_PAGE_SIZES;
 566                        is_2m_pages++) {
 567                struct vmballoon_page_size *page_size =
 568                                &b->page_sizes[is_2m_pages];
 569                u16 size_per_page = vmballoon_page_size(is_2m_pages);
 570
 571                list_for_each_entry_safe(page, next, &page_size->pages, lru) {
 572                        list_del(&page->lru);
 573                        vmballoon_free_page(page, is_2m_pages);
 574                        STATS_INC(b->stats.free[is_2m_pages]);
 575                        b->size -= size_per_page;
 576                        cond_resched();
 577                }
 578        }
 579
 580        /* Clearing the batch_page unconditionally has no adverse effect */
 581        free_page((unsigned long)b->batch_page);
 582        b->batch_page = NULL;
 583}
 584
 585/*
 586 * Notify the host of a ballooned page. If host rejects the page put it on the
 587 * refuse list, those refused page are then released at the end of the
 588 * inflation cycle.
 589 */
 590static int vmballoon_lock_page(struct vmballoon *b, unsigned int num_pages,
 591                                bool is_2m_pages, unsigned int *target)
 592{
 593        int locked, hv_status;
 594        struct page *page = b->page;
 595        struct vmballoon_page_size *page_size = &b->page_sizes[false];
 596
 597        /* is_2m_pages can never happen as 2m pages support implies batching */
 598
 599        locked = vmballoon_send_lock_page(b, page_to_pfn(page), &hv_status,
 600                                                                target);
 601        if (locked > 0) {
 602                STATS_INC(b->stats.refused_alloc[false]);
 603
 604                if (hv_status == VMW_BALLOON_ERROR_RESET ||
 605                                hv_status == VMW_BALLOON_ERROR_PPN_NOTNEEDED) {
 606                        vmballoon_free_page(page, false);
 607                        return -EIO;
 608                }
 609
 610                /*
 611                 * Place page on the list of non-balloonable pages
 612                 * and retry allocation, unless we already accumulated
 613                 * too many of them, in which case take a breather.
 614                 */
 615                if (page_size->n_refused_pages < VMW_BALLOON_MAX_REFUSED) {
 616                        page_size->n_refused_pages++;
 617                        list_add(&page->lru, &page_size->refused_pages);
 618                } else {
 619                        vmballoon_free_page(page, false);
 620                }
 621                return -EIO;
 622        }
 623
 624        /* track allocated page */
 625        list_add(&page->lru, &page_size->pages);
 626
 627        /* update balloon size */
 628        b->size++;
 629
 630        return 0;
 631}
 632
 633static int vmballoon_lock_batched_page(struct vmballoon *b,
 634                unsigned int num_pages, bool is_2m_pages, unsigned int *target)
 635{
 636        int locked, i;
 637        u16 size_per_page = vmballoon_page_size(is_2m_pages);
 638
 639        locked = vmballoon_send_batched_lock(b, num_pages, is_2m_pages,
 640                        target);
 641        if (locked > 0) {
 642                for (i = 0; i < num_pages; i++) {
 643                        u64 pa = vmballoon_batch_get_pa(b->batch_page, i);
 644                        struct page *p = pfn_to_page(pa >> PAGE_SHIFT);
 645
 646                        vmballoon_free_page(p, is_2m_pages);
 647                }
 648
 649                return -EIO;
 650        }
 651
 652        for (i = 0; i < num_pages; i++) {
 653                u64 pa = vmballoon_batch_get_pa(b->batch_page, i);
 654                struct page *p = pfn_to_page(pa >> PAGE_SHIFT);
 655                struct vmballoon_page_size *page_size =
 656                                &b->page_sizes[is_2m_pages];
 657
 658                locked = vmballoon_batch_get_status(b->batch_page, i);
 659
 660                switch (locked) {
 661                case VMW_BALLOON_SUCCESS:
 662                        list_add(&p->lru, &page_size->pages);
 663                        b->size += size_per_page;
 664                        break;
 665                case VMW_BALLOON_ERROR_PPN_PINNED:
 666                case VMW_BALLOON_ERROR_PPN_INVALID:
 667                        if (page_size->n_refused_pages
 668                                        < VMW_BALLOON_MAX_REFUSED) {
 669                                list_add(&p->lru, &page_size->refused_pages);
 670                                page_size->n_refused_pages++;
 671                                break;
 672                        }
 673                        /* Fallthrough */
 674                case VMW_BALLOON_ERROR_RESET:
 675                case VMW_BALLOON_ERROR_PPN_NOTNEEDED:
 676                        vmballoon_free_page(p, is_2m_pages);
 677                        break;
 678                default:
 679                        /* This should never happen */
 680                        WARN_ON_ONCE(true);
 681                }
 682        }
 683
 684        return 0;
 685}
 686
 687/*
 688 * Release the page allocated for the balloon. Note that we first notify
 689 * the host so it can make sure the page will be available for the guest
 690 * to use, if needed.
 691 */
 692static int vmballoon_unlock_page(struct vmballoon *b, unsigned int num_pages,
 693                bool is_2m_pages, unsigned int *target)
 694{
 695        struct page *page = b->page;
 696        struct vmballoon_page_size *page_size = &b->page_sizes[false];
 697
 698        /* is_2m_pages can never happen as 2m pages support implies batching */
 699
 700        if (!vmballoon_send_unlock_page(b, page_to_pfn(page), target)) {
 701                list_add(&page->lru, &page_size->pages);
 702                return -EIO;
 703        }
 704
 705        /* deallocate page */
 706        vmballoon_free_page(page, false);
 707        STATS_INC(b->stats.free[false]);
 708
 709        /* update balloon size */
 710        b->size--;
 711
 712        return 0;
 713}
 714
 715static int vmballoon_unlock_batched_page(struct vmballoon *b,
 716                                unsigned int num_pages, bool is_2m_pages,
 717                                unsigned int *target)
 718{
 719        int locked, i, ret = 0;
 720        bool hv_success;
 721        u16 size_per_page = vmballoon_page_size(is_2m_pages);
 722
 723        hv_success = vmballoon_send_batched_unlock(b, num_pages, is_2m_pages,
 724                        target);
 725        if (!hv_success)
 726                ret = -EIO;
 727
 728        for (i = 0; i < num_pages; i++) {
 729                u64 pa = vmballoon_batch_get_pa(b->batch_page, i);
 730                struct page *p = pfn_to_page(pa >> PAGE_SHIFT);
 731                struct vmballoon_page_size *page_size =
 732                                &b->page_sizes[is_2m_pages];
 733
 734                locked = vmballoon_batch_get_status(b->batch_page, i);
 735                if (!hv_success || locked != VMW_BALLOON_SUCCESS) {
 736                        /*
 737                         * That page wasn't successfully unlocked by the
 738                         * hypervisor, re-add it to the list of pages owned by
 739                         * the balloon driver.
 740                         */
 741                        list_add(&p->lru, &page_size->pages);
 742                } else {
 743                        /* deallocate page */
 744                        vmballoon_free_page(p, is_2m_pages);
 745                        STATS_INC(b->stats.free[is_2m_pages]);
 746
 747                        /* update balloon size */
 748                        b->size -= size_per_page;
 749                }
 750        }
 751
 752        return ret;
 753}
 754
 755/*
 756 * Release pages that were allocated while attempting to inflate the
 757 * balloon but were refused by the host for one reason or another.
 758 */
 759static void vmballoon_release_refused_pages(struct vmballoon *b,
 760                bool is_2m_pages)
 761{
 762        struct page *page, *next;
 763        struct vmballoon_page_size *page_size =
 764                        &b->page_sizes[is_2m_pages];
 765
 766        list_for_each_entry_safe(page, next, &page_size->refused_pages, lru) {
 767                list_del(&page->lru);
 768                vmballoon_free_page(page, is_2m_pages);
 769                STATS_INC(b->stats.refused_free[is_2m_pages]);
 770        }
 771
 772        page_size->n_refused_pages = 0;
 773}
 774
 775static void vmballoon_add_page(struct vmballoon *b, int idx, struct page *p)
 776{
 777        b->page = p;
 778}
 779
 780static void vmballoon_add_batched_page(struct vmballoon *b, int idx,
 781                                struct page *p)
 782{
 783        vmballoon_batch_set_pa(b->batch_page, idx,
 784                        (u64)page_to_pfn(p) << PAGE_SHIFT);
 785}
 786
 787/*
 788 * Inflate the balloon towards its target size. Note that we try to limit
 789 * the rate of allocation to make sure we are not choking the rest of the
 790 * system.
 791 */
 792static void vmballoon_inflate(struct vmballoon *b)
 793{
 794        unsigned rate;
 795        unsigned int allocations = 0;
 796        unsigned int num_pages = 0;
 797        int error = 0;
 798        gfp_t flags = VMW_PAGE_ALLOC_NOSLEEP;
 799        bool is_2m_pages;
 800
 801        pr_debug("%s - size: %d, target %d\n", __func__, b->size, b->target);
 802
 803        /*
 804         * First try NOSLEEP page allocations to inflate balloon.
 805         *
 806         * If we do not throttle nosleep allocations, we can drain all
 807         * free pages in the guest quickly (if the balloon target is high).
 808         * As a side-effect, draining free pages helps to inform (force)
 809         * the guest to start swapping if balloon target is not met yet,
 810         * which is a desired behavior. However, balloon driver can consume
 811         * all available CPU cycles if too many pages are allocated in a
 812         * second. Therefore, we throttle nosleep allocations even when
 813         * the guest is not under memory pressure. OTOH, if we have already
 814         * predicted that the guest is under memory pressure, then we
 815         * slowdown page allocations considerably.
 816         */
 817
 818        /*
 819         * Start with no sleep allocation rate which may be higher
 820         * than sleeping allocation rate.
 821         */
 822        if (b->slow_allocation_cycles) {
 823                rate = b->rate_alloc;
 824                is_2m_pages = false;
 825        } else {
 826                rate = UINT_MAX;
 827                is_2m_pages =
 828                        b->supported_page_sizes == VMW_BALLOON_NUM_PAGE_SIZES;
 829        }
 830
 831        pr_debug("%s - goal: %d, no-sleep rate: %u, sleep rate: %d\n",
 832                 __func__, b->target - b->size, rate, b->rate_alloc);
 833
 834        while (!b->reset_required &&
 835                b->size + num_pages * vmballoon_page_size(is_2m_pages)
 836                < b->target) {
 837                struct page *page;
 838
 839                if (flags == VMW_PAGE_ALLOC_NOSLEEP)
 840                        STATS_INC(b->stats.alloc[is_2m_pages]);
 841                else
 842                        STATS_INC(b->stats.sleep_alloc);
 843
 844                page = vmballoon_alloc_page(flags, is_2m_pages);
 845                if (!page) {
 846                        STATS_INC(b->stats.alloc_fail[is_2m_pages]);
 847
 848                        if (is_2m_pages) {
 849                                b->ops->lock(b, num_pages, true, &b->target);
 850
 851                                /*
 852                                 * ignore errors from locking as we now switch
 853                                 * to 4k pages and we might get different
 854                                 * errors.
 855                                 */
 856
 857                                num_pages = 0;
 858                                is_2m_pages = false;
 859                                continue;
 860                        }
 861
 862                        if (flags == VMW_PAGE_ALLOC_CANSLEEP) {
 863                                /*
 864                                 * CANSLEEP page allocation failed, so guest
 865                                 * is under severe memory pressure. Quickly
 866                                 * decrease allocation rate.
 867                                 */
 868                                b->rate_alloc = max(b->rate_alloc / 2,
 869                                                    VMW_BALLOON_RATE_ALLOC_MIN);
 870                                STATS_INC(b->stats.sleep_alloc_fail);
 871                                break;
 872                        }
 873
 874                        /*
 875                         * NOSLEEP page allocation failed, so the guest is
 876                         * under memory pressure. Let us slow down page
 877                         * allocations for next few cycles so that the guest
 878                         * gets out of memory pressure. Also, if we already
 879                         * allocated b->rate_alloc pages, let's pause,
 880                         * otherwise switch to sleeping allocations.
 881                         */
 882                        b->slow_allocation_cycles = VMW_BALLOON_SLOW_CYCLES;
 883
 884                        if (allocations >= b->rate_alloc)
 885                                break;
 886
 887                        flags = VMW_PAGE_ALLOC_CANSLEEP;
 888                        /* Lower rate for sleeping allocations. */
 889                        rate = b->rate_alloc;
 890                        continue;
 891                }
 892
 893                b->ops->add_page(b, num_pages++, page);
 894                if (num_pages == b->batch_max_pages) {
 895                        error = b->ops->lock(b, num_pages, is_2m_pages,
 896                                        &b->target);
 897                        num_pages = 0;
 898                        if (error)
 899                                break;
 900                }
 901
 902                cond_resched();
 903
 904                if (allocations >= rate) {
 905                        /* We allocated enough pages, let's take a break. */
 906                        break;
 907                }
 908        }
 909
 910        if (num_pages > 0)
 911                b->ops->lock(b, num_pages, is_2m_pages, &b->target);
 912
 913        /*
 914         * We reached our goal without failures so try increasing
 915         * allocation rate.
 916         */
 917        if (error == 0 && allocations >= b->rate_alloc) {
 918                unsigned int mult = allocations / b->rate_alloc;
 919
 920                b->rate_alloc =
 921                        min(b->rate_alloc + mult * VMW_BALLOON_RATE_ALLOC_INC,
 922                            VMW_BALLOON_RATE_ALLOC_MAX);
 923        }
 924
 925        vmballoon_release_refused_pages(b, true);
 926        vmballoon_release_refused_pages(b, false);
 927}
 928
 929/*
 930 * Decrease the size of the balloon allowing guest to use more memory.
 931 */
 932static void vmballoon_deflate(struct vmballoon *b)
 933{
 934        unsigned is_2m_pages;
 935
 936        pr_debug("%s - size: %d, target %d\n", __func__, b->size, b->target);
 937
 938        /* free pages to reach target */
 939        for (is_2m_pages = 0; is_2m_pages < b->supported_page_sizes;
 940                        is_2m_pages++) {
 941                struct page *page, *next;
 942                unsigned int num_pages = 0;
 943                struct vmballoon_page_size *page_size =
 944                                &b->page_sizes[is_2m_pages];
 945
 946                list_for_each_entry_safe(page, next, &page_size->pages, lru) {
 947                        if (b->reset_required ||
 948                                (b->target > 0 &&
 949                                        b->size - num_pages
 950                                        * vmballoon_page_size(is_2m_pages)
 951                                < b->target + vmballoon_page_size(true)))
 952                                break;
 953
 954                        list_del(&page->lru);
 955                        b->ops->add_page(b, num_pages++, page);
 956
 957                        if (num_pages == b->batch_max_pages) {
 958                                int error;
 959
 960                                error = b->ops->unlock(b, num_pages,
 961                                                is_2m_pages, &b->target);
 962                                num_pages = 0;
 963                                if (error)
 964                                        return;
 965                        }
 966
 967                        cond_resched();
 968                }
 969
 970                if (num_pages > 0)
 971                        b->ops->unlock(b, num_pages, is_2m_pages, &b->target);
 972        }
 973}
 974
 975static const struct vmballoon_ops vmballoon_basic_ops = {
 976        .add_page = vmballoon_add_page,
 977        .lock = vmballoon_lock_page,
 978        .unlock = vmballoon_unlock_page
 979};
 980
 981static const struct vmballoon_ops vmballoon_batched_ops = {
 982        .add_page = vmballoon_add_batched_page,
 983        .lock = vmballoon_lock_batched_page,
 984        .unlock = vmballoon_unlock_batched_page
 985};
 986
 987static bool vmballoon_init_batching(struct vmballoon *b)
 988{
 989        struct page *page;
 990
 991        page = alloc_page(GFP_KERNEL | __GFP_ZERO);
 992        if (!page)
 993                return false;
 994
 995        b->batch_page = page_address(page);
 996        return true;
 997}
 998
 999/*
1000 * Receive notification and resize balloon
1001 */
1002static void vmballoon_doorbell(void *client_data)
1003{
1004        struct vmballoon *b = client_data;
1005
1006        STATS_INC(b->stats.doorbell);
1007
1008        mod_delayed_work(system_freezable_wq, &b->dwork, 0);
1009}
1010
1011/*
1012 * Clean up vmci doorbell
1013 */
1014static void vmballoon_vmci_cleanup(struct vmballoon *b)
1015{
1016        int error;
1017
1018        VMWARE_BALLOON_CMD(VMCI_DOORBELL_SET, VMCI_INVALID_ID,
1019                        VMCI_INVALID_ID, error);
1020        STATS_INC(b->stats.doorbell_unset);
1021
1022        if (!vmci_handle_is_invalid(b->vmci_doorbell)) {
1023                vmci_doorbell_destroy(b->vmci_doorbell);
1024                b->vmci_doorbell = VMCI_INVALID_HANDLE;
1025        }
1026}
1027
1028/*
1029 * Initialize vmci doorbell, to get notified as soon as balloon changes
1030 */
1031static int vmballoon_vmci_init(struct vmballoon *b)
1032{
1033        int error = 0;
1034
1035        if ((b->capabilities & VMW_BALLOON_SIGNALLED_WAKEUP_CMD) != 0) {
1036                error = vmci_doorbell_create(&b->vmci_doorbell,
1037                                VMCI_FLAG_DELAYED_CB,
1038                                VMCI_PRIVILEGE_FLAG_RESTRICTED,
1039                                vmballoon_doorbell, b);
1040
1041                if (error == VMCI_SUCCESS) {
1042                        VMWARE_BALLOON_CMD(VMCI_DOORBELL_SET,
1043                                        b->vmci_doorbell.context,
1044                                        b->vmci_doorbell.resource, error);
1045                        STATS_INC(b->stats.doorbell_set);
1046                }
1047        }
1048
1049        if (error != 0) {
1050                vmballoon_vmci_cleanup(b);
1051
1052                return -EIO;
1053        }
1054
1055        return 0;
1056}
1057
1058/*
1059 * Perform standard reset sequence by popping the balloon (in case it
1060 * is not  empty) and then restarting protocol. This operation normally
1061 * happens when host responds with VMW_BALLOON_ERROR_RESET to a command.
1062 */
1063static void vmballoon_reset(struct vmballoon *b)
1064{
1065        int error;
1066
1067        vmballoon_vmci_cleanup(b);
1068
1069        /* free all pages, skipping monitor unlock */
1070        vmballoon_pop(b);
1071
1072        if (!vmballoon_send_start(b, VMW_BALLOON_CAPABILITIES))
1073                return;
1074
1075        if ((b->capabilities & VMW_BALLOON_BATCHED_CMDS) != 0) {
1076                b->ops = &vmballoon_batched_ops;
1077                b->batch_max_pages = VMW_BALLOON_BATCH_MAX_PAGES;
1078                if (!vmballoon_init_batching(b)) {
1079                        /*
1080                         * We failed to initialize batching, inform the monitor
1081                         * about it by sending a null capability.
1082                         *
1083                         * The guest will retry in one second.
1084                         */
1085                        vmballoon_send_start(b, 0);
1086                        return;
1087                }
1088        } else if ((b->capabilities & VMW_BALLOON_BASIC_CMDS) != 0) {
1089                b->ops = &vmballoon_basic_ops;
1090                b->batch_max_pages = 1;
1091        }
1092
1093        b->reset_required = false;
1094
1095        error = vmballoon_vmci_init(b);
1096        if (error)
1097                pr_err("failed to initialize vmci doorbell\n");
1098
1099        if (!vmballoon_send_guest_id(b))
1100                pr_err("failed to send guest ID to the host\n");
1101}
1102
1103/*
1104 * Balloon work function: reset protocol, if needed, get the new size and
1105 * adjust balloon as needed. Repeat in 1 sec.
1106 */
1107static void vmballoon_work(struct work_struct *work)
1108{
1109        struct delayed_work *dwork = to_delayed_work(work);
1110        struct vmballoon *b = container_of(dwork, struct vmballoon, dwork);
1111        unsigned int target;
1112
1113        STATS_INC(b->stats.timer);
1114
1115        if (b->reset_required)
1116                vmballoon_reset(b);
1117
1118        if (b->slow_allocation_cycles > 0)
1119                b->slow_allocation_cycles--;
1120
1121        if (!b->reset_required && vmballoon_send_get_target(b, &target)) {
1122                /* update target, adjust size */
1123                b->target = target;
1124
1125                if (b->size < target)
1126                        vmballoon_inflate(b);
1127                else if (target == 0 ||
1128                                b->size > target + vmballoon_page_size(true))
1129                        vmballoon_deflate(b);
1130        }
1131
1132        /*
1133         * We are using a freezable workqueue so that balloon operations are
1134         * stopped while the system transitions to/from sleep/hibernation.
1135         */
1136        queue_delayed_work(system_freezable_wq,
1137                           dwork, round_jiffies_relative(HZ));
1138}
1139
1140/*
1141 * DEBUGFS Interface
1142 */
1143#ifdef CONFIG_DEBUG_FS
1144
1145static int vmballoon_debug_show(struct seq_file *f, void *offset)
1146{
1147        struct vmballoon *b = f->private;
1148        struct vmballoon_stats *stats = &b->stats;
1149
1150        /* format capabilities info */
1151        seq_printf(f,
1152                   "balloon capabilities:   %#4x\n"
1153                   "used capabilities:      %#4lx\n"
1154                   "is resetting:           %c\n",
1155                   VMW_BALLOON_CAPABILITIES, b->capabilities,
1156                   b->reset_required ? 'y' : 'n');
1157
1158        /* format size info */
1159        seq_printf(f,
1160                   "target:             %8d pages\n"
1161                   "current:            %8d pages\n",
1162                   b->target, b->size);
1163
1164        /* format rate info */
1165        seq_printf(f,
1166                   "rateSleepAlloc:     %8d pages/sec\n",
1167                   b->rate_alloc);
1168
1169        seq_printf(f,
1170                   "\n"
1171                   "timer:              %8u\n"
1172                   "doorbell:           %8u\n"
1173                   "start:              %8u (%4u failed)\n"
1174                   "guestType:          %8u (%4u failed)\n"
1175                   "2m-lock:            %8u (%4u failed)\n"
1176                   "lock:               %8u (%4u failed)\n"
1177                   "2m-unlock:          %8u (%4u failed)\n"
1178                   "unlock:             %8u (%4u failed)\n"
1179                   "target:             %8u (%4u failed)\n"
1180                   "prim2mAlloc:        %8u (%4u failed)\n"
1181                   "primNoSleepAlloc:   %8u (%4u failed)\n"
1182                   "primCanSleepAlloc:  %8u (%4u failed)\n"
1183                   "prim2mFree:         %8u\n"
1184                   "primFree:           %8u\n"
1185                   "err2mAlloc:         %8u\n"
1186                   "errAlloc:           %8u\n"
1187                   "err2mFree:          %8u\n"
1188                   "errFree:            %8u\n"
1189                   "doorbellSet:        %8u\n"
1190                   "doorbellUnset:      %8u\n",
1191                   stats->timer,
1192                   stats->doorbell,
1193                   stats->start, stats->start_fail,
1194                   stats->guest_type, stats->guest_type_fail,
1195                   stats->lock[true],  stats->lock_fail[true],
1196                   stats->lock[false],  stats->lock_fail[false],
1197                   stats->unlock[true], stats->unlock_fail[true],
1198                   stats->unlock[false], stats->unlock_fail[false],
1199                   stats->target, stats->target_fail,
1200                   stats->alloc[true], stats->alloc_fail[true],
1201                   stats->alloc[false], stats->alloc_fail[false],
1202                   stats->sleep_alloc, stats->sleep_alloc_fail,
1203                   stats->free[true],
1204                   stats->free[false],
1205                   stats->refused_alloc[true], stats->refused_alloc[false],
1206                   stats->refused_free[true], stats->refused_free[false],
1207                   stats->doorbell_set, stats->doorbell_unset);
1208
1209        return 0;
1210}
1211
1212static int vmballoon_debug_open(struct inode *inode, struct file *file)
1213{
1214        return single_open(file, vmballoon_debug_show, inode->i_private);
1215}
1216
1217static const struct file_operations vmballoon_debug_fops = {
1218        .owner          = THIS_MODULE,
1219        .open           = vmballoon_debug_open,
1220        .read           = seq_read,
1221        .llseek         = seq_lseek,
1222        .release        = single_release,
1223};
1224
1225static int __init vmballoon_debugfs_init(struct vmballoon *b)
1226{
1227        int error;
1228
1229        b->dbg_entry = debugfs_create_file("vmmemctl", S_IRUGO, NULL, b,
1230                                           &vmballoon_debug_fops);
1231        if (IS_ERR(b->dbg_entry)) {
1232                error = PTR_ERR(b->dbg_entry);
1233                pr_err("failed to create debugfs entry, error: %d\n", error);
1234                return error;
1235        }
1236
1237        return 0;
1238}
1239
1240static void __exit vmballoon_debugfs_exit(struct vmballoon *b)
1241{
1242        debugfs_remove(b->dbg_entry);
1243}
1244
1245#else
1246
1247static inline int vmballoon_debugfs_init(struct vmballoon *b)
1248{
1249        return 0;
1250}
1251
1252static inline void vmballoon_debugfs_exit(struct vmballoon *b)
1253{
1254}
1255
1256#endif  /* CONFIG_DEBUG_FS */
1257
1258static int __init vmballoon_init(void)
1259{
1260        int error;
1261        unsigned is_2m_pages;
1262        /*
1263         * Check if we are running on VMware's hypervisor and bail out
1264         * if we are not.
1265         */
1266        if (x86_hyper_type != X86_HYPER_VMWARE)
1267                return -ENODEV;
1268
1269        for (is_2m_pages = 0; is_2m_pages < VMW_BALLOON_NUM_PAGE_SIZES;
1270                        is_2m_pages++) {
1271                INIT_LIST_HEAD(&balloon.page_sizes[is_2m_pages].pages);
1272                INIT_LIST_HEAD(&balloon.page_sizes[is_2m_pages].refused_pages);
1273        }
1274
1275        /* initialize rates */
1276        balloon.rate_alloc = VMW_BALLOON_RATE_ALLOC_MAX;
1277
1278        INIT_DELAYED_WORK(&balloon.dwork, vmballoon_work);
1279
1280        error = vmballoon_debugfs_init(&balloon);
1281        if (error)
1282                return error;
1283
1284        balloon.vmci_doorbell = VMCI_INVALID_HANDLE;
1285        balloon.batch_page = NULL;
1286        balloon.page = NULL;
1287        balloon.reset_required = true;
1288
1289        queue_delayed_work(system_freezable_wq, &balloon.dwork, 0);
1290
1291        return 0;
1292}
1293module_init(vmballoon_init);
1294
1295static void __exit vmballoon_exit(void)
1296{
1297        vmballoon_vmci_cleanup(&balloon);
1298        cancel_delayed_work_sync(&balloon.dwork);
1299
1300        vmballoon_debugfs_exit(&balloon);
1301
1302        /*
1303         * Deallocate all reserved memory, and reset connection with monitor.
1304         * Reset connection before deallocating memory to avoid potential for
1305         * additional spurious resets from guest touching deallocated pages.
1306         */
1307        vmballoon_send_start(&balloon, 0);
1308        vmballoon_pop(&balloon);
1309}
1310module_exit(vmballoon_exit);
1311