2018-06-20 06:00:29 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2010-04-24 00:18:08 +07:00
|
|
|
/*
|
|
|
|
* VMware Balloon driver.
|
|
|
|
*
|
2018-06-20 06:00:29 +07:00
|
|
|
* Copyright (C) 2000-2018, VMware, Inc. All Rights Reserved.
|
2010-04-24 00:18:08 +07:00
|
|
|
*
|
|
|
|
* This is VMware physical memory management driver for Linux. The driver
|
|
|
|
* acts like a "balloon" that can be inflated to reclaim physical pages by
|
|
|
|
* reserving them in the guest and invalidating them in the monitor,
|
|
|
|
* freeing up the underlying machine pages so they can be allocated to
|
|
|
|
* other guests. The balloon can also be deflated to allow the guest to
|
|
|
|
* use more physical memory. Higher level policies can control the sizes
|
|
|
|
* of balloons in VMs in order to manage physical memory resources.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//#define DEBUG
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
2015-08-07 05:17:58 +07:00
|
|
|
#include <linux/vmalloc.h>
|
2010-04-24 00:18:08 +07:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include <linux/seq_file.h>
|
2015-08-07 05:18:01 +07:00
|
|
|
#include <linux/vmw_vmci_defs.h>
|
|
|
|
#include <linux/vmw_vmci_api.h>
|
2010-05-09 15:13:42 +07:00
|
|
|
#include <asm/hypervisor.h>
|
2010-04-24 00:18:08 +07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("VMware, Inc.");
|
|
|
|
MODULE_DESCRIPTION("VMware Memory Control (Balloon) Driver");
|
2015-08-07 05:18:01 +07:00
|
|
|
MODULE_VERSION("1.5.0.0-k");
|
2010-04-24 00:18:08 +07:00
|
|
|
MODULE_ALIAS("dmi:*:svnVMware*:*");
|
|
|
|
MODULE_ALIAS("vmware_vmmemctl");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/*
|
2018-09-21 00:30:11 +07:00
|
|
|
* Use __GFP_HIGHMEM to allow pages from HIGHMEM zone. We don't allow wait
|
|
|
|
* (__GFP_RECLAIM) for huge page allocations. Use __GFP_NOWARN, to suppress page
|
|
|
|
* allocation failure warnings. Disallow access to emergency low-memory pools.
|
2010-04-24 00:18:08 +07:00
|
|
|
*/
|
2018-09-21 00:30:11 +07:00
|
|
|
#define VMW_HUGE_PAGE_ALLOC_FLAGS (__GFP_HIGHMEM|__GFP_NOWARN| \
|
|
|
|
__GFP_NOMEMALLOC)
|
2010-04-24 00:18:08 +07:00
|
|
|
|
|
|
|
/*
|
2018-09-21 00:30:11 +07:00
|
|
|
* Use __GFP_HIGHMEM to allow pages from HIGHMEM zone. We allow lightweight
|
|
|
|
* reclamation (__GFP_NORETRY). Use __GFP_NOWARN, to suppress page allocation
|
|
|
|
* failure warnings. Disallow access to emergency low-memory pools.
|
2010-04-24 00:18:08 +07:00
|
|
|
*/
|
2018-09-21 00:30:11 +07:00
|
|
|
#define VMW_PAGE_ALLOC_FLAGS (__GFP_HIGHMEM|__GFP_NOWARN| \
|
|
|
|
__GFP_NOMEMALLOC|__GFP_NORETRY)
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2010-06-05 04:14:52 +07:00
|
|
|
/* Maximum number of refused pages we accumulate during inflation cycle */
|
|
|
|
#define VMW_BALLOON_MAX_REFUSED 16
|
2010-04-24 00:18:08 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hypervisor communication port definitions.
|
|
|
|
*/
|
|
|
|
#define VMW_BALLOON_HV_PORT 0x5670
|
|
|
|
#define VMW_BALLOON_HV_MAGIC 0x456c6d6f
|
|
|
|
#define VMW_BALLOON_GUEST_ID 1 /* Linux */
|
|
|
|
|
2015-06-13 01:43:23 +07:00
|
|
|
enum vmwballoon_capabilities {
|
|
|
|
/*
|
|
|
|
* Bit 0 is reserved and not associated to any capability.
|
|
|
|
*/
|
2015-08-07 05:18:01 +07:00
|
|
|
VMW_BALLOON_BASIC_CMDS = (1 << 1),
|
|
|
|
VMW_BALLOON_BATCHED_CMDS = (1 << 2),
|
|
|
|
VMW_BALLOON_BATCHED_2M_CMDS = (1 << 3),
|
|
|
|
VMW_BALLOON_SIGNALLED_WAKEUP_CMD = (1 << 4),
|
2015-06-13 01:43:23 +07:00
|
|
|
};
|
|
|
|
|
2015-08-07 05:17:58 +07:00
|
|
|
#define VMW_BALLOON_CAPABILITIES (VMW_BALLOON_BASIC_CMDS \
|
2015-08-07 05:18:01 +07:00
|
|
|
| VMW_BALLOON_BATCHED_CMDS \
|
2015-08-07 05:18:01 +07:00
|
|
|
| VMW_BALLOON_BATCHED_2M_CMDS \
|
|
|
|
| VMW_BALLOON_SIGNALLED_WAKEUP_CMD)
|
2015-08-07 05:18:01 +07:00
|
|
|
|
2018-09-21 00:30:14 +07:00
|
|
|
#define VMW_BALLOON_2M_ORDER (PMD_SHIFT - PAGE_SHIFT)
|
2015-08-07 05:18:01 +07:00
|
|
|
#define VMW_BALLOON_NUM_PAGE_SIZES (2)
|
2015-06-13 01:43:23 +07:00
|
|
|
|
2015-08-07 05:17:58 +07:00
|
|
|
/*
|
|
|
|
* Backdoor commands availability:
|
|
|
|
*
|
|
|
|
* START, GET_TARGET and GUEST_ID are always available,
|
|
|
|
*
|
|
|
|
* VMW_BALLOON_BASIC_CMDS:
|
|
|
|
* LOCK and UNLOCK commands,
|
|
|
|
* VMW_BALLOON_BATCHED_CMDS:
|
|
|
|
* BATCHED_LOCK and BATCHED_UNLOCK commands.
|
2015-08-07 05:18:01 +07:00
|
|
|
* VMW BALLOON_BATCHED_2M_CMDS:
|
2015-08-07 05:18:01 +07:00
|
|
|
* BATCHED_2M_LOCK and BATCHED_2M_UNLOCK commands,
|
|
|
|
* VMW VMW_BALLOON_SIGNALLED_WAKEUP_CMD:
|
|
|
|
* VMW_BALLOON_CMD_VMCI_DOORBELL_SET command.
|
2015-08-07 05:17:58 +07:00
|
|
|
*/
|
2015-08-07 05:18:01 +07:00
|
|
|
#define VMW_BALLOON_CMD_START 0
|
|
|
|
#define VMW_BALLOON_CMD_GET_TARGET 1
|
|
|
|
#define VMW_BALLOON_CMD_LOCK 2
|
|
|
|
#define VMW_BALLOON_CMD_UNLOCK 3
|
|
|
|
#define VMW_BALLOON_CMD_GUEST_ID 4
|
|
|
|
#define VMW_BALLOON_CMD_BATCHED_LOCK 6
|
|
|
|
#define VMW_BALLOON_CMD_BATCHED_UNLOCK 7
|
|
|
|
#define VMW_BALLOON_CMD_BATCHED_2M_LOCK 8
|
|
|
|
#define VMW_BALLOON_CMD_BATCHED_2M_UNLOCK 9
|
2015-08-07 05:18:01 +07:00
|
|
|
#define VMW_BALLOON_CMD_VMCI_DOORBELL_SET 10
|
2015-08-07 05:18:01 +07:00
|
|
|
|
2018-09-21 00:30:08 +07:00
|
|
|
#define VMW_BALLOON_CMD_NUM 11
|
2010-04-24 00:18:08 +07:00
|
|
|
|
|
|
|
/* error codes */
|
2015-06-13 01:43:23 +07:00
|
|
|
#define VMW_BALLOON_SUCCESS 0
|
|
|
|
#define VMW_BALLOON_FAILURE -1
|
|
|
|
#define VMW_BALLOON_ERROR_CMD_INVALID 1
|
|
|
|
#define VMW_BALLOON_ERROR_PPN_INVALID 2
|
|
|
|
#define VMW_BALLOON_ERROR_PPN_LOCKED 3
|
|
|
|
#define VMW_BALLOON_ERROR_PPN_UNLOCKED 4
|
|
|
|
#define VMW_BALLOON_ERROR_PPN_PINNED 5
|
|
|
|
#define VMW_BALLOON_ERROR_PPN_NOTNEEDED 6
|
|
|
|
#define VMW_BALLOON_ERROR_RESET 7
|
|
|
|
#define VMW_BALLOON_ERROR_BUSY 8
|
|
|
|
|
|
|
|
#define VMW_BALLOON_SUCCESS_WITH_CAPABILITIES (0x03000000)
|
|
|
|
|
2018-09-21 00:30:07 +07:00
|
|
|
#define VMW_BALLOON_CMD_WITH_TARGET_MASK \
|
|
|
|
((1UL << VMW_BALLOON_CMD_GET_TARGET) | \
|
|
|
|
(1UL << VMW_BALLOON_CMD_LOCK) | \
|
|
|
|
(1UL << VMW_BALLOON_CMD_UNLOCK) | \
|
|
|
|
(1UL << VMW_BALLOON_CMD_BATCHED_LOCK) | \
|
|
|
|
(1UL << VMW_BALLOON_CMD_BATCHED_UNLOCK) | \
|
|
|
|
(1UL << VMW_BALLOON_CMD_BATCHED_2M_LOCK) | \
|
|
|
|
(1UL << VMW_BALLOON_CMD_BATCHED_2M_UNLOCK))
|
|
|
|
|
2018-09-21 00:30:08 +07:00
|
|
|
static const char * const vmballoon_cmd_names[] = {
|
|
|
|
[VMW_BALLOON_CMD_START] = "start",
|
|
|
|
[VMW_BALLOON_CMD_GET_TARGET] = "target",
|
|
|
|
[VMW_BALLOON_CMD_LOCK] = "lock",
|
|
|
|
[VMW_BALLOON_CMD_UNLOCK] = "unlock",
|
|
|
|
[VMW_BALLOON_CMD_GUEST_ID] = "guestType",
|
|
|
|
[VMW_BALLOON_CMD_BATCHED_LOCK] = "batchLock",
|
|
|
|
[VMW_BALLOON_CMD_BATCHED_UNLOCK] = "batchUnlock",
|
|
|
|
[VMW_BALLOON_CMD_BATCHED_2M_LOCK] = "2m-lock",
|
|
|
|
[VMW_BALLOON_CMD_BATCHED_2M_UNLOCK] = "2m-unlock",
|
|
|
|
[VMW_BALLOON_CMD_VMCI_DOORBELL_SET] = "doorbellSet"
|
|
|
|
};
|
|
|
|
|
2010-04-24 00:18:08 +07:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
struct vmballoon_stats {
|
|
|
|
unsigned int timer;
|
2015-08-07 05:18:01 +07:00
|
|
|
unsigned int doorbell;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2011-11-03 03:40:07 +07:00
|
|
|
/* allocation statistics */
|
2015-08-07 05:18:01 +07:00
|
|
|
unsigned int alloc[VMW_BALLOON_NUM_PAGE_SIZES];
|
|
|
|
unsigned int alloc_fail[VMW_BALLOON_NUM_PAGE_SIZES];
|
|
|
|
unsigned int refused_alloc[VMW_BALLOON_NUM_PAGE_SIZES];
|
|
|
|
unsigned int refused_free[VMW_BALLOON_NUM_PAGE_SIZES];
|
|
|
|
unsigned int free[VMW_BALLOON_NUM_PAGE_SIZES];
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2018-09-21 00:30:08 +07:00
|
|
|
/* Monitor operations. */
|
|
|
|
unsigned long ops[VMW_BALLOON_CMD_NUM];
|
|
|
|
unsigned long ops_fail[VMW_BALLOON_CMD_NUM];
|
2010-04-24 00:18:08 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define STATS_INC(stat) (stat)++
|
|
|
|
#else
|
|
|
|
#define STATS_INC(stat)
|
|
|
|
#endif
|
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
static DEFINE_STATIC_KEY_TRUE(vmw_balloon_batching);
|
2015-08-07 05:17:58 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
struct vmballoon_page_size {
|
2010-04-24 00:18:08 +07:00
|
|
|
/* list of reserved physical pages */
|
|
|
|
struct list_head pages;
|
|
|
|
|
|
|
|
/* transient list of non-balloonable pages */
|
|
|
|
struct list_head refused_pages;
|
2010-06-05 04:14:52 +07:00
|
|
|
unsigned int n_refused_pages;
|
2015-08-07 05:18:01 +07:00
|
|
|
};
|
|
|
|
|
2018-09-21 00:30:10 +07:00
|
|
|
/**
|
|
|
|
* struct vmballoon_batch_entry - a batch entry for lock or unlock.
|
|
|
|
*
|
|
|
|
* @status: the status of the operation, which is written by the hypervisor.
|
|
|
|
* @reserved: reserved for future use. Must be set to zero.
|
|
|
|
* @pfn: the physical frame number of the page to be locked or unlocked.
|
|
|
|
*/
|
|
|
|
struct vmballoon_batch_entry {
|
|
|
|
u64 status : 5;
|
|
|
|
u64 reserved : PAGE_SHIFT - 5;
|
|
|
|
u64 pfn : 52;
|
|
|
|
} __packed;
|
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
struct vmballoon {
|
|
|
|
struct vmballoon_page_size page_sizes[VMW_BALLOON_NUM_PAGE_SIZES];
|
|
|
|
|
|
|
|
/* supported page sizes. 1 == 4k pages only, 2 == 4k and 2m pages */
|
|
|
|
unsigned supported_page_sizes;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
|
|
|
/* balloon size in pages */
|
|
|
|
unsigned int size;
|
|
|
|
unsigned int target;
|
|
|
|
|
|
|
|
/* reset flag */
|
|
|
|
bool reset_required;
|
|
|
|
|
2015-08-07 05:17:58 +07:00
|
|
|
unsigned long capabilities;
|
|
|
|
|
2018-09-21 00:30:10 +07:00
|
|
|
/**
|
|
|
|
* @batch_page: pointer to communication batch page.
|
|
|
|
*
|
|
|
|
* When batching is used, batch_page points to a page, which holds up to
|
|
|
|
* %VMW_BALLOON_BATCH_MAX_PAGES entries for locking or unlocking.
|
|
|
|
*/
|
|
|
|
struct vmballoon_batch_entry *batch_page;
|
|
|
|
|
2015-08-07 05:17:58 +07:00
|
|
|
unsigned int batch_max_pages;
|
|
|
|
struct page *page;
|
|
|
|
|
2010-04-24 00:18:08 +07:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
/* statistics */
|
|
|
|
struct vmballoon_stats stats;
|
|
|
|
|
|
|
|
/* debugfs file exporting statistics */
|
|
|
|
struct dentry *dbg_entry;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct sysinfo sysinfo;
|
|
|
|
|
|
|
|
struct delayed_work dwork;
|
2015-08-07 05:18:01 +07:00
|
|
|
|
|
|
|
struct vmci_handle vmci_doorbell;
|
2010-04-24 00:18:08 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct vmballoon balloon;
|
|
|
|
|
2018-09-21 00:30:07 +07:00
|
|
|
static inline unsigned long
|
|
|
|
__vmballoon_cmd(struct vmballoon *b, unsigned long cmd, unsigned long arg1,
|
|
|
|
unsigned long arg2, unsigned long *result)
|
|
|
|
{
|
|
|
|
unsigned long status, dummy1, dummy2, dummy3, local_result;
|
|
|
|
|
2018-09-21 00:30:08 +07:00
|
|
|
STATS_INC(b->stats.ops[cmd]);
|
|
|
|
|
2018-09-21 00:30:07 +07:00
|
|
|
asm volatile ("inl %%dx" :
|
|
|
|
"=a"(status),
|
|
|
|
"=c"(dummy1),
|
|
|
|
"=d"(dummy2),
|
|
|
|
"=b"(local_result),
|
|
|
|
"=S"(dummy3) :
|
|
|
|
"0"(VMW_BALLOON_HV_MAGIC),
|
|
|
|
"1"(cmd),
|
|
|
|
"2"(VMW_BALLOON_HV_PORT),
|
|
|
|
"3"(arg1),
|
|
|
|
"4"(arg2) :
|
|
|
|
"memory");
|
|
|
|
|
|
|
|
/* update the result if needed */
|
|
|
|
if (result)
|
|
|
|
*result = (cmd == VMW_BALLOON_CMD_START) ? dummy1 :
|
|
|
|
local_result;
|
|
|
|
|
|
|
|
/* update target when applicable */
|
|
|
|
if (status == VMW_BALLOON_SUCCESS &&
|
|
|
|
((1ul << cmd) & VMW_BALLOON_CMD_WITH_TARGET_MASK))
|
|
|
|
b->target = local_result;
|
|
|
|
|
2018-09-21 00:30:08 +07:00
|
|
|
if (status != VMW_BALLOON_SUCCESS &&
|
|
|
|
status != VMW_BALLOON_SUCCESS_WITH_CAPABILITIES) {
|
|
|
|
STATS_INC(b->stats.ops_fail[cmd]);
|
|
|
|
pr_debug("%s: %s [0x%lx,0x%lx) failed, returned %ld\n",
|
|
|
|
__func__, vmballoon_cmd_names[cmd], arg1, arg2,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:30:07 +07:00
|
|
|
/* mark reset required accordingly */
|
|
|
|
if (status == VMW_BALLOON_ERROR_RESET)
|
|
|
|
b->reset_required = true;
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline unsigned long
|
|
|
|
vmballoon_cmd(struct vmballoon *b, unsigned long cmd, unsigned long arg1,
|
|
|
|
unsigned long arg2)
|
|
|
|
{
|
|
|
|
unsigned long dummy;
|
|
|
|
|
|
|
|
return __vmballoon_cmd(b, cmd, arg1, arg2, &dummy);
|
|
|
|
}
|
|
|
|
|
2010-04-24 00:18:08 +07:00
|
|
|
/*
|
|
|
|
* Send "start" command to the host, communicating supported version
|
|
|
|
* of the protocol.
|
|
|
|
*/
|
2015-08-07 05:17:58 +07:00
|
|
|
static bool vmballoon_send_start(struct vmballoon *b, unsigned long req_caps)
|
2010-04-24 00:18:08 +07:00
|
|
|
{
|
2018-09-21 00:30:07 +07:00
|
|
|
unsigned long status, capabilities;
|
2015-08-07 05:18:01 +07:00
|
|
|
bool success;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2018-09-21 00:30:07 +07:00
|
|
|
status = __vmballoon_cmd(b, VMW_BALLOON_CMD_START, req_caps, 0,
|
|
|
|
&capabilities);
|
2015-08-07 05:17:58 +07:00
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case VMW_BALLOON_SUCCESS_WITH_CAPABILITIES:
|
|
|
|
b->capabilities = capabilities;
|
2015-08-07 05:18:01 +07:00
|
|
|
success = true;
|
|
|
|
break;
|
2015-08-07 05:17:58 +07:00
|
|
|
case VMW_BALLOON_SUCCESS:
|
|
|
|
b->capabilities = VMW_BALLOON_BASIC_CMDS;
|
2015-08-07 05:18:01 +07:00
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
success = false;
|
2015-08-07 05:17:58 +07:00
|
|
|
}
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2018-06-20 06:00:25 +07:00
|
|
|
/*
|
|
|
|
* 2MB pages are only supported with batching. If batching is for some
|
|
|
|
* reason disabled, do not use 2MB pages, since otherwise the legacy
|
|
|
|
* mechanism is used with 2MB pages, causing a failure.
|
|
|
|
*/
|
|
|
|
if ((b->capabilities & VMW_BALLOON_BATCHED_2M_CMDS) &&
|
|
|
|
(b->capabilities & VMW_BALLOON_BATCHED_CMDS))
|
2015-08-07 05:18:01 +07:00
|
|
|
b->supported_page_sizes = 2;
|
|
|
|
else
|
|
|
|
b->supported_page_sizes = 1;
|
|
|
|
|
|
|
|
return success;
|
2010-04-24 00:18:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Communicate guest type to the host so that it can adjust ballooning
|
|
|
|
* algorithm to the one most appropriate for the guest. This command
|
|
|
|
* is normally issued after sending "start" command and is part of
|
|
|
|
* standard reset sequence.
|
|
|
|
*/
|
|
|
|
static bool vmballoon_send_guest_id(struct vmballoon *b)
|
|
|
|
{
|
2018-09-21 00:30:07 +07:00
|
|
|
unsigned long status;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2018-09-21 00:30:07 +07:00
|
|
|
status = vmballoon_cmd(b, VMW_BALLOON_CMD_GUEST_ID,
|
|
|
|
VMW_BALLOON_GUEST_ID, 0);
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2018-09-21 00:30:07 +07:00
|
|
|
if (status == VMW_BALLOON_SUCCESS)
|
2010-04-24 00:18:08 +07:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
static u16 vmballoon_page_size(bool is_2m_page)
|
|
|
|
{
|
|
|
|
if (is_2m_page)
|
2018-09-21 00:30:14 +07:00
|
|
|
return 1 << VMW_BALLOON_2M_ORDER;
|
2015-08-07 05:18:01 +07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-04-24 00:18:08 +07:00
|
|
|
/*
|
|
|
|
* Retrieve desired balloon size from the host.
|
|
|
|
*/
|
2018-09-21 00:30:07 +07:00
|
|
|
static bool vmballoon_send_get_target(struct vmballoon *b)
|
2010-04-24 00:18:08 +07:00
|
|
|
{
|
|
|
|
unsigned long status;
|
|
|
|
unsigned long limit;
|
|
|
|
u32 limit32;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* si_meminfo() is cheap. Moreover, we want to provide dynamic
|
|
|
|
* max balloon size later. So let us call si_meminfo() every
|
|
|
|
* iteration.
|
|
|
|
*/
|
|
|
|
si_meminfo(&b->sysinfo);
|
|
|
|
limit = b->sysinfo.totalram;
|
|
|
|
|
|
|
|
/* Ensure limit fits in 32-bits */
|
|
|
|
limit32 = (u32)limit;
|
|
|
|
if (limit != limit32)
|
|
|
|
return false;
|
|
|
|
|
2018-09-21 00:30:07 +07:00
|
|
|
status = vmballoon_cmd(b, VMW_BALLOON_CMD_GET_TARGET, limit, 0);
|
|
|
|
|
|
|
|
if (status == VMW_BALLOON_SUCCESS)
|
2010-04-24 00:18:08 +07:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:30:11 +07:00
|
|
|
static struct page *vmballoon_alloc_page(bool is_2m_page)
|
2015-08-07 05:18:01 +07:00
|
|
|
{
|
|
|
|
if (is_2m_page)
|
2018-09-21 00:30:11 +07:00
|
|
|
return alloc_pages(VMW_HUGE_PAGE_ALLOC_FLAGS,
|
2018-09-21 00:30:14 +07:00
|
|
|
VMW_BALLOON_2M_ORDER);
|
2015-08-07 05:18:01 +07:00
|
|
|
|
2018-09-21 00:30:11 +07:00
|
|
|
return alloc_page(VMW_PAGE_ALLOC_FLAGS);
|
2015-08-07 05:18:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vmballoon_free_page(struct page *page, bool is_2m_page)
|
|
|
|
{
|
|
|
|
if (is_2m_page)
|
2018-09-21 00:30:14 +07:00
|
|
|
__free_pages(page, VMW_BALLOON_2M_ORDER);
|
2015-08-07 05:18:01 +07:00
|
|
|
else
|
|
|
|
__free_page(page);
|
|
|
|
}
|
|
|
|
|
2010-04-24 00:18:08 +07:00
|
|
|
/*
|
|
|
|
* Quickly release all pages allocated for the balloon. This function is
|
|
|
|
* called when host decides to "reset" balloon for one reason or another.
|
|
|
|
* Unlike normal "deflate" we do not (shall not) notify host of the pages
|
|
|
|
* being released.
|
|
|
|
*/
|
|
|
|
static void vmballoon_pop(struct vmballoon *b)
|
|
|
|
{
|
|
|
|
struct page *page, *next;
|
2015-08-07 05:18:01 +07:00
|
|
|
unsigned is_2m_pages;
|
|
|
|
|
|
|
|
for (is_2m_pages = 0; is_2m_pages < VMW_BALLOON_NUM_PAGE_SIZES;
|
|
|
|
is_2m_pages++) {
|
|
|
|
struct vmballoon_page_size *page_size =
|
|
|
|
&b->page_sizes[is_2m_pages];
|
|
|
|
u16 size_per_page = vmballoon_page_size(is_2m_pages);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(page, next, &page_size->pages, lru) {
|
|
|
|
list_del(&page->lru);
|
|
|
|
vmballoon_free_page(page, is_2m_pages);
|
|
|
|
STATS_INC(b->stats.free[is_2m_pages]);
|
|
|
|
b->size -= size_per_page;
|
|
|
|
cond_resched();
|
|
|
|
}
|
2010-04-24 00:18:08 +07:00
|
|
|
}
|
|
|
|
|
vmw_balloon: fixing double free when batching mode is off
The balloon.page field is used for two different purposes if batching is
on or off. If batching is on, the field point to the page which is used
to communicate with with the hypervisor. If it is off, balloon.page
points to the page that is about to be (un)locked.
Unfortunately, this dual-purpose of the field introduced a bug: when the
balloon is popped (e.g., when the machine is reset or the balloon driver
is explicitly removed), the balloon driver frees, unconditionally, the
page that is held in balloon.page. As a result, if batching is
disabled, this leads to double freeing the last page that is sent to the
hypervisor.
The following error occurs during rmmod when kernel checkers are on, and
the balloon is not empty:
[ 42.307653] ------------[ cut here ]------------
[ 42.307657] Kernel BUG at ffffffffba1e4b28 [verbose debug info unavailable]
[ 42.307720] invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC
[ 42.312512] Modules linked in: vmw_vsock_vmci_transport vsock ppdev joydev vmw_balloon(-) input_leds serio_raw vmw_vmci parport_pc shpchp parport i2c_piix4 nfit mac_hid autofs4 vmwgfx drm_kms_helper hid_generic syscopyarea sysfillrect usbhid sysimgblt fb_sys_fops hid ttm mptspi scsi_transport_spi ahci mptscsih drm psmouse vmxnet3 libahci mptbase pata_acpi
[ 42.312766] CPU: 10 PID: 1527 Comm: rmmod Not tainted 4.12.0+ #5
[ 42.312803] Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 09/30/2016
[ 42.313042] task: ffff9bf9680f8000 task.stack: ffffbfefc1638000
[ 42.313290] RIP: 0010:__free_pages+0x38/0x40
[ 42.313510] RSP: 0018:ffffbfefc163be98 EFLAGS: 00010246
[ 42.313731] RAX: 000000000000003e RBX: ffffffffc02b9720 RCX: 0000000000000006
[ 42.313972] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff9bf97e08e0a0
[ 42.314201] RBP: ffffbfefc163be98 R08: 0000000000000000 R09: 0000000000000000
[ 42.314435] R10: 0000000000000000 R11: 0000000000000000 R12: ffffffffc02b97e4
[ 42.314505] R13: ffffffffc02b9748 R14: ffffffffc02b9728 R15: 0000000000000200
[ 42.314550] FS: 00007f3af5fec700(0000) GS:ffff9bf97e080000(0000) knlGS:0000000000000000
[ 42.314599] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 42.314635] CR2: 00007f44f6f4ab24 CR3: 00000003a7d12000 CR4: 00000000000006e0
[ 42.314864] Call Trace:
[ 42.315774] vmballoon_pop+0x102/0x130 [vmw_balloon]
[ 42.315816] vmballoon_exit+0x42/0xd64 [vmw_balloon]
[ 42.315853] SyS_delete_module+0x1e2/0x250
[ 42.315891] entry_SYSCALL_64_fastpath+0x23/0xc2
[ 42.315924] RIP: 0033:0x7f3af5b0e8e7
[ 42.315949] RSP: 002b:00007fffe6ce0148 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0
[ 42.315996] RAX: ffffffffffffffda RBX: 000055be676401e0 RCX: 00007f3af5b0e8e7
[ 42.316951] RDX: 000000000000000a RSI: 0000000000000800 RDI: 000055be67640248
[ 42.317887] RBP: 0000000000000003 R08: 0000000000000000 R09: 1999999999999999
[ 42.318845] R10: 0000000000000883 R11: 0000000000000206 R12: 00007fffe6cdf130
[ 42.319755] R13: 0000000000000000 R14: 0000000000000000 R15: 000055be676401e0
[ 42.320606] Code: c0 74 1c f0 ff 4f 1c 74 02 5d c3 85 f6 74 07 e8 0f d8 ff ff 5d c3 31 f6 e8 c6 fb ff ff 5d c3 48 c7 c6 c8 0f c5 ba e8 58 be 02 00 <0f> 0b 66 0f 1f 44 00 00 66 66 66 66 90 48 85 ff 75 01 c3 55 48
[ 42.323462] RIP: __free_pages+0x38/0x40 RSP: ffffbfefc163be98
[ 42.325735] ---[ end trace 872e008e33f81508 ]---
To solve the bug, we eliminate the dual purpose of balloon.page.
Fixes: f220a80f0c2e ("VMware balloon: add batching to the vmw_balloon.")
Cc: stable@vger.kernel.org
Reported-by: Oleksandr Natalenko <onatalen@redhat.com>
Signed-off-by: Gil Kupfer <gilkup@gmail.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Tested-by: Oleksandr Natalenko <oleksandr@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-06-01 14:47:47 +07:00
|
|
|
/* Clearing the batch_page unconditionally has no adverse effect */
|
|
|
|
free_page((unsigned long)b->batch_page);
|
|
|
|
b->batch_page = NULL;
|
2010-04-24 00:18:08 +07:00
|
|
|
}
|
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
/**
|
|
|
|
* vmballoon_status_page - returns the status of (un)lock operation
|
|
|
|
*
|
|
|
|
* @b: pointer to the balloon.
|
|
|
|
* @idx: index for the page for which the operation is performed.
|
|
|
|
* @p: pointer to where the page struct is returned.
|
|
|
|
*
|
|
|
|
* Following a lock or unlock operation, returns the status of the operation for
|
|
|
|
* an individual page. Provides the page that the operation was performed on on
|
|
|
|
* the @page argument.
|
|
|
|
*
|
|
|
|
* Returns: The status of a lock or unlock operation for an individual page.
|
2010-04-24 00:18:08 +07:00
|
|
|
*/
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
static unsigned long vmballoon_status_page(struct vmballoon *b, int idx,
|
|
|
|
struct page **p)
|
2010-04-24 00:18:08 +07:00
|
|
|
{
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
if (static_branch_likely(&vmw_balloon_batching)) {
|
|
|
|
/* batching mode */
|
|
|
|
*p = pfn_to_page(b->batch_page[idx].pfn);
|
|
|
|
return b->batch_page[idx].status;
|
|
|
|
}
|
2018-09-21 00:30:07 +07:00
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
/* non-batching mode */
|
|
|
|
*p = b->page;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
/*
|
|
|
|
* If a failure occurs, the indication will be provided in the status
|
|
|
|
* of the entire operation, which is considered before the individual
|
|
|
|
* page status. So for non-batching mode, the indication is always of
|
|
|
|
* success.
|
|
|
|
*/
|
|
|
|
return VMW_BALLOON_SUCCESS;
|
|
|
|
}
|
2010-04-24 00:18:08 +07:00
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
/**
|
|
|
|
* vmballoon_lock_op - notifies the host about inflated/deflated pages.
|
|
|
|
* @b: pointer to the balloon.
|
|
|
|
* @num_pages: number of inflated/deflated pages.
|
|
|
|
* @is_2m_pages: whether the page(s) are 2M (or 4k).
|
|
|
|
* @lock: whether the operation is lock (or unlock).
|
|
|
|
*
|
|
|
|
* Notify the host about page(s) that were ballooned (or removed from the
|
|
|
|
* balloon) so that host can use it without fear that guest will need it (or
|
|
|
|
* stop using them since the VM does). Host may reject some pages, we need to
|
|
|
|
* check the return value and maybe submit a different page. The pages that are
|
|
|
|
* inflated/deflated are pointed by @b->page.
|
|
|
|
*
|
|
|
|
* Return: result as provided by the hypervisor.
|
|
|
|
*/
|
|
|
|
static unsigned long vmballoon_lock_op(struct vmballoon *b,
|
|
|
|
unsigned int num_pages,
|
|
|
|
bool is_2m_pages, bool lock)
|
|
|
|
{
|
|
|
|
unsigned long cmd, pfn;
|
|
|
|
|
|
|
|
if (static_branch_likely(&vmw_balloon_batching)) {
|
|
|
|
if (lock)
|
|
|
|
cmd = is_2m_pages ? VMW_BALLOON_CMD_BATCHED_2M_LOCK :
|
|
|
|
VMW_BALLOON_CMD_BATCHED_LOCK;
|
|
|
|
else
|
|
|
|
cmd = is_2m_pages ? VMW_BALLOON_CMD_BATCHED_2M_UNLOCK :
|
|
|
|
VMW_BALLOON_CMD_BATCHED_UNLOCK;
|
|
|
|
|
|
|
|
pfn = PHYS_PFN(virt_to_phys(b->batch_page));
|
|
|
|
} else {
|
|
|
|
cmd = lock ? VMW_BALLOON_CMD_LOCK : VMW_BALLOON_CMD_UNLOCK;
|
|
|
|
pfn = page_to_pfn(b->page);
|
|
|
|
|
|
|
|
/* In non-batching mode, PFNs must fit in 32-bit */
|
|
|
|
if (unlikely(pfn != (u32)pfn))
|
|
|
|
return VMW_BALLOON_ERROR_PPN_INVALID;
|
2015-06-13 01:43:22 +07:00
|
|
|
}
|
2010-04-24 00:18:08 +07:00
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
return vmballoon_cmd(b, cmd, pfn, num_pages);
|
2010-04-24 00:18:08 +07:00
|
|
|
}
|
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
static int vmballoon_lock(struct vmballoon *b, unsigned int num_pages,
|
|
|
|
bool is_2m_pages)
|
2015-08-07 05:17:58 +07:00
|
|
|
{
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
unsigned long batch_status;
|
|
|
|
int i;
|
2015-08-07 05:18:01 +07:00
|
|
|
u16 size_per_page = vmballoon_page_size(is_2m_pages);
|
2015-08-07 05:17:58 +07:00
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
batch_status = vmballoon_lock_op(b, num_pages, is_2m_pages, true);
|
2015-08-07 05:17:58 +07:00
|
|
|
|
|
|
|
for (i = 0; i < num_pages; i++) {
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
unsigned long status;
|
|
|
|
struct page *p;
|
2015-08-07 05:18:01 +07:00
|
|
|
struct vmballoon_page_size *page_size =
|
|
|
|
&b->page_sizes[is_2m_pages];
|
2015-08-07 05:17:58 +07:00
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
status = vmballoon_status_page(b, i, &p);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Failure of the whole batch overrides a single operation
|
|
|
|
* results.
|
|
|
|
*/
|
|
|
|
if (batch_status != VMW_BALLOON_SUCCESS)
|
|
|
|
status = batch_status;
|
2015-08-07 05:17:58 +07:00
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
if (status == VMW_BALLOON_SUCCESS) {
|
|
|
|
/* track allocated page */
|
2015-08-07 05:18:01 +07:00
|
|
|
list_add(&p->lru, &page_size->pages);
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
|
|
|
|
/* update balloon size */
|
2015-08-07 05:18:01 +07:00
|
|
|
b->size += size_per_page;
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Error occurred */
|
|
|
|
STATS_INC(b->stats.refused_alloc[is_2m_pages]);
|
|
|
|
|
2018-09-21 00:30:13 +07:00
|
|
|
/*
|
|
|
|
* Place page on the list of non-balloonable pages
|
|
|
|
* and retry allocation, unless we already accumulated
|
|
|
|
* too many of them, in which case take a breather.
|
|
|
|
*/
|
|
|
|
list_add(&p->lru, &page_size->refused_pages);
|
|
|
|
page_size->n_refused_pages++;
|
2015-08-07 05:17:58 +07:00
|
|
|
}
|
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
return batch_status == VMW_BALLOON_SUCCESS ? 0 : -EIO;
|
2015-08-07 05:17:58 +07:00
|
|
|
}
|
|
|
|
|
2010-04-24 00:18:08 +07:00
|
|
|
/*
|
|
|
|
* Release the page allocated for the balloon. Note that we first notify
|
|
|
|
* the host so it can make sure the page will be available for the guest
|
|
|
|
* to use, if needed.
|
|
|
|
*/
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
static int vmballoon_unlock(struct vmballoon *b, unsigned int num_pages,
|
|
|
|
bool is_2m_pages)
|
2010-04-24 00:18:08 +07:00
|
|
|
{
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
int i;
|
|
|
|
unsigned long batch_status;
|
2015-08-07 05:18:01 +07:00
|
|
|
u16 size_per_page = vmballoon_page_size(is_2m_pages);
|
2015-08-07 05:17:58 +07:00
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
batch_status = vmballoon_lock_op(b, num_pages, is_2m_pages, false);
|
2015-08-07 05:17:58 +07:00
|
|
|
|
|
|
|
for (i = 0; i < num_pages; i++) {
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
struct vmballoon_page_size *page_size;
|
|
|
|
unsigned long status;
|
|
|
|
struct page *p;
|
|
|
|
|
|
|
|
status = vmballoon_status_page(b, i, &p);
|
|
|
|
page_size = &b->page_sizes[is_2m_pages];
|
2015-08-07 05:17:58 +07:00
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
/*
|
|
|
|
* Failure of the whole batch overrides a single operation
|
|
|
|
* results.
|
|
|
|
*/
|
|
|
|
if (batch_status != VMW_BALLOON_SUCCESS)
|
|
|
|
status = batch_status;
|
|
|
|
|
|
|
|
if (status != VMW_BALLOON_SUCCESS) {
|
2015-08-07 05:17:58 +07:00
|
|
|
/*
|
|
|
|
* That page wasn't successfully unlocked by the
|
|
|
|
* hypervisor, re-add it to the list of pages owned by
|
|
|
|
* the balloon driver.
|
|
|
|
*/
|
2015-08-07 05:18:01 +07:00
|
|
|
list_add(&p->lru, &page_size->pages);
|
2015-08-07 05:17:58 +07:00
|
|
|
} else {
|
|
|
|
/* deallocate page */
|
2015-08-07 05:18:01 +07:00
|
|
|
vmballoon_free_page(p, is_2m_pages);
|
|
|
|
STATS_INC(b->stats.free[is_2m_pages]);
|
2015-08-07 05:17:58 +07:00
|
|
|
|
|
|
|
/* update balloon size */
|
2015-08-07 05:18:01 +07:00
|
|
|
b->size -= size_per_page;
|
2015-08-07 05:17:58 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
return batch_status == VMW_BALLOON_SUCCESS ? 0 : -EIO;
|
2015-08-07 05:17:58 +07:00
|
|
|
}
|
|
|
|
|
2010-04-24 00:18:08 +07:00
|
|
|
/*
|
|
|
|
* Release pages that were allocated while attempting to inflate the
|
|
|
|
* balloon but were refused by the host for one reason or another.
|
|
|
|
*/
|
2015-08-07 05:18:01 +07:00
|
|
|
static void vmballoon_release_refused_pages(struct vmballoon *b,
|
|
|
|
bool is_2m_pages)
|
2010-04-24 00:18:08 +07:00
|
|
|
{
|
|
|
|
struct page *page, *next;
|
2015-08-07 05:18:01 +07:00
|
|
|
struct vmballoon_page_size *page_size =
|
|
|
|
&b->page_sizes[is_2m_pages];
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
list_for_each_entry_safe(page, next, &page_size->refused_pages, lru) {
|
2010-04-24 00:18:08 +07:00
|
|
|
list_del(&page->lru);
|
2015-08-07 05:18:01 +07:00
|
|
|
vmballoon_free_page(page, is_2m_pages);
|
|
|
|
STATS_INC(b->stats.refused_free[is_2m_pages]);
|
2010-04-24 00:18:08 +07:00
|
|
|
}
|
2010-06-05 04:14:52 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
page_size->n_refused_pages = 0;
|
2010-04-24 00:18:08 +07:00
|
|
|
}
|
|
|
|
|
2015-08-07 05:17:58 +07:00
|
|
|
static void vmballoon_add_page(struct vmballoon *b, int idx, struct page *p)
|
|
|
|
{
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
if (static_branch_likely(&vmw_balloon_batching))
|
|
|
|
b->batch_page[idx] = (struct vmballoon_batch_entry)
|
2018-09-21 00:30:10 +07:00
|
|
|
{ .pfn = page_to_pfn(p) };
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
else
|
|
|
|
b->page = p;
|
2015-08-07 05:17:58 +07:00
|
|
|
}
|
|
|
|
|
2010-04-24 00:18:08 +07:00
|
|
|
/*
|
|
|
|
* Inflate the balloon towards its target size. Note that we try to limit
|
|
|
|
* the rate of allocation to make sure we are not choking the rest of the
|
|
|
|
* system.
|
|
|
|
*/
|
|
|
|
static void vmballoon_inflate(struct vmballoon *b)
|
|
|
|
{
|
2015-08-07 05:17:58 +07:00
|
|
|
unsigned int num_pages = 0;
|
2010-04-24 00:18:08 +07:00
|
|
|
int error = 0;
|
2015-08-07 05:18:01 +07:00
|
|
|
bool is_2m_pages;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
|
|
|
pr_debug("%s - size: %d, target %d\n", __func__, b->size, b->target);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First try NOSLEEP page allocations to inflate balloon.
|
|
|
|
*
|
|
|
|
* If we do not throttle nosleep allocations, we can drain all
|
|
|
|
* free pages in the guest quickly (if the balloon target is high).
|
|
|
|
* As a side-effect, draining free pages helps to inform (force)
|
|
|
|
* the guest to start swapping if balloon target is not met yet,
|
|
|
|
* which is a desired behavior. However, balloon driver can consume
|
|
|
|
* all available CPU cycles if too many pages are allocated in a
|
|
|
|
* second. Therefore, we throttle nosleep allocations even when
|
|
|
|
* the guest is not under memory pressure. OTOH, if we have already
|
|
|
|
* predicted that the guest is under memory pressure, then we
|
|
|
|
* slowdown page allocations considerably.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start with no sleep allocation rate which may be higher
|
|
|
|
* than sleeping allocation rate.
|
|
|
|
*/
|
2018-06-20 06:00:28 +07:00
|
|
|
is_2m_pages = b->supported_page_sizes == VMW_BALLOON_NUM_PAGE_SIZES;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2018-06-20 06:00:28 +07:00
|
|
|
pr_debug("%s - goal: %d", __func__, b->target - b->size);
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
while (!b->reset_required &&
|
2015-08-07 05:18:01 +07:00
|
|
|
b->size + num_pages * vmballoon_page_size(is_2m_pages)
|
|
|
|
< b->target) {
|
2015-08-07 05:17:59 +07:00
|
|
|
struct page *page;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2018-09-21 00:30:11 +07:00
|
|
|
STATS_INC(b->stats.alloc[is_2m_pages]);
|
|
|
|
page = vmballoon_alloc_page(is_2m_pages);
|
2015-06-13 01:43:22 +07:00
|
|
|
if (!page) {
|
2015-08-07 05:18:01 +07:00
|
|
|
STATS_INC(b->stats.alloc_fail[is_2m_pages]);
|
|
|
|
if (is_2m_pages) {
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
vmballoon_lock(b, num_pages, true);
|
2015-08-07 05:18:01 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ignore errors from locking as we now switch
|
|
|
|
* to 4k pages and we might get different
|
|
|
|
* errors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
num_pages = 0;
|
|
|
|
is_2m_pages = false;
|
|
|
|
continue;
|
|
|
|
}
|
2018-09-21 00:30:11 +07:00
|
|
|
break;
|
2010-04-24 00:18:08 +07:00
|
|
|
}
|
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
vmballoon_add_page(b, num_pages++, page);
|
2015-08-07 05:17:58 +07:00
|
|
|
if (num_pages == b->batch_max_pages) {
|
2018-09-21 00:30:13 +07:00
|
|
|
struct vmballoon_page_size *page_size =
|
|
|
|
&b->page_sizes[is_2m_pages];
|
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
error = vmballoon_lock(b, num_pages, is_2m_pages);
|
2018-09-21 00:30:07 +07:00
|
|
|
|
2015-08-07 05:17:58 +07:00
|
|
|
num_pages = 0;
|
2018-09-21 00:30:13 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop allocating this page size if we already
|
|
|
|
* accumulated too many pages that the hypervisor
|
|
|
|
* refused.
|
|
|
|
*/
|
|
|
|
if (page_size->n_refused_pages >=
|
|
|
|
VMW_BALLOON_MAX_REFUSED) {
|
|
|
|
if (!is_2m_pages)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the refused pages as we move to 4k
|
|
|
|
* pages.
|
|
|
|
*/
|
|
|
|
vmballoon_release_refused_pages(b, true);
|
|
|
|
is_2m_pages = true;
|
|
|
|
}
|
|
|
|
|
2015-08-07 05:17:58 +07:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
2015-06-13 01:43:22 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
cond_resched();
|
2010-04-24 00:18:08 +07:00
|
|
|
}
|
|
|
|
|
2015-08-07 05:17:58 +07:00
|
|
|
if (num_pages > 0)
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
vmballoon_lock(b, num_pages, is_2m_pages);
|
2015-08-07 05:17:58 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
vmballoon_release_refused_pages(b, true);
|
|
|
|
vmballoon_release_refused_pages(b, false);
|
2010-04-24 00:18:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decrease the size of the balloon allowing guest to use more memory.
|
|
|
|
*/
|
|
|
|
static void vmballoon_deflate(struct vmballoon *b)
|
|
|
|
{
|
2015-08-07 05:18:01 +07:00
|
|
|
unsigned is_2m_pages;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
pr_debug("%s - size: %d, target %d\n", __func__, b->size, b->target);
|
2010-04-24 00:18:08 +07:00
|
|
|
|
|
|
|
/* free pages to reach target */
|
2015-08-07 05:18:01 +07:00
|
|
|
for (is_2m_pages = 0; is_2m_pages < b->supported_page_sizes;
|
|
|
|
is_2m_pages++) {
|
|
|
|
struct page *page, *next;
|
|
|
|
unsigned int num_pages = 0;
|
|
|
|
struct vmballoon_page_size *page_size =
|
|
|
|
&b->page_sizes[is_2m_pages];
|
|
|
|
|
|
|
|
list_for_each_entry_safe(page, next, &page_size->pages, lru) {
|
|
|
|
if (b->reset_required ||
|
|
|
|
(b->target > 0 &&
|
|
|
|
b->size - num_pages
|
|
|
|
* vmballoon_page_size(is_2m_pages)
|
|
|
|
< b->target + vmballoon_page_size(true)))
|
|
|
|
break;
|
2015-08-07 05:17:58 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
list_del(&page->lru);
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
vmballoon_add_page(b, num_pages++, page);
|
2015-08-07 05:18:01 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
if (num_pages == b->batch_max_pages) {
|
|
|
|
int error;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
error = vmballoon_unlock(b, num_pages,
|
2018-09-21 00:30:07 +07:00
|
|
|
is_2m_pages);
|
2015-08-07 05:18:01 +07:00
|
|
|
num_pages = 0;
|
|
|
|
if (error)
|
|
|
|
return;
|
|
|
|
}
|
2015-08-07 05:18:01 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
cond_resched();
|
|
|
|
}
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
if (num_pages > 0)
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
vmballoon_unlock(b, num_pages, is_2m_pages);
|
2015-08-07 05:18:01 +07:00
|
|
|
}
|
2015-08-07 05:17:58 +07:00
|
|
|
}
|
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
/**
|
|
|
|
* vmballoon_deinit_batching - disables batching mode.
|
|
|
|
*
|
|
|
|
* @b: pointer to &struct vmballoon.
|
|
|
|
*
|
|
|
|
* Disables batching, by deallocating the page for communication with the
|
|
|
|
* hypervisor and disabling the static key to indicate that batching is off.
|
|
|
|
*/
|
|
|
|
static void vmballoon_deinit_batching(struct vmballoon *b)
|
|
|
|
{
|
|
|
|
free_page((unsigned long)b->batch_page);
|
|
|
|
b->batch_page = NULL;
|
|
|
|
static_branch_disable(&vmw_balloon_batching);
|
|
|
|
b->batch_max_pages = 1;
|
|
|
|
}
|
2015-08-07 05:17:58 +07:00
|
|
|
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
/**
|
|
|
|
* vmballoon_init_batching - enable batching mode.
|
|
|
|
*
|
|
|
|
* @b: pointer to &struct vmballoon.
|
|
|
|
*
|
|
|
|
* Enables batching, by allocating a page for communication with the hypervisor
|
|
|
|
* and enabling the static_key to use batching.
|
|
|
|
*
|
|
|
|
* Return: zero on success or an appropriate error-code.
|
|
|
|
*/
|
|
|
|
static int vmballoon_init_batching(struct vmballoon *b)
|
2015-08-07 05:17:58 +07:00
|
|
|
{
|
vmw_balloon: fixing double free when batching mode is off
The balloon.page field is used for two different purposes if batching is
on or off. If batching is on, the field point to the page which is used
to communicate with with the hypervisor. If it is off, balloon.page
points to the page that is about to be (un)locked.
Unfortunately, this dual-purpose of the field introduced a bug: when the
balloon is popped (e.g., when the machine is reset or the balloon driver
is explicitly removed), the balloon driver frees, unconditionally, the
page that is held in balloon.page. As a result, if batching is
disabled, this leads to double freeing the last page that is sent to the
hypervisor.
The following error occurs during rmmod when kernel checkers are on, and
the balloon is not empty:
[ 42.307653] ------------[ cut here ]------------
[ 42.307657] Kernel BUG at ffffffffba1e4b28 [verbose debug info unavailable]
[ 42.307720] invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC
[ 42.312512] Modules linked in: vmw_vsock_vmci_transport vsock ppdev joydev vmw_balloon(-) input_leds serio_raw vmw_vmci parport_pc shpchp parport i2c_piix4 nfit mac_hid autofs4 vmwgfx drm_kms_helper hid_generic syscopyarea sysfillrect usbhid sysimgblt fb_sys_fops hid ttm mptspi scsi_transport_spi ahci mptscsih drm psmouse vmxnet3 libahci mptbase pata_acpi
[ 42.312766] CPU: 10 PID: 1527 Comm: rmmod Not tainted 4.12.0+ #5
[ 42.312803] Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 09/30/2016
[ 42.313042] task: ffff9bf9680f8000 task.stack: ffffbfefc1638000
[ 42.313290] RIP: 0010:__free_pages+0x38/0x40
[ 42.313510] RSP: 0018:ffffbfefc163be98 EFLAGS: 00010246
[ 42.313731] RAX: 000000000000003e RBX: ffffffffc02b9720 RCX: 0000000000000006
[ 42.313972] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff9bf97e08e0a0
[ 42.314201] RBP: ffffbfefc163be98 R08: 0000000000000000 R09: 0000000000000000
[ 42.314435] R10: 0000000000000000 R11: 0000000000000000 R12: ffffffffc02b97e4
[ 42.314505] R13: ffffffffc02b9748 R14: ffffffffc02b9728 R15: 0000000000000200
[ 42.314550] FS: 00007f3af5fec700(0000) GS:ffff9bf97e080000(0000) knlGS:0000000000000000
[ 42.314599] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 42.314635] CR2: 00007f44f6f4ab24 CR3: 00000003a7d12000 CR4: 00000000000006e0
[ 42.314864] Call Trace:
[ 42.315774] vmballoon_pop+0x102/0x130 [vmw_balloon]
[ 42.315816] vmballoon_exit+0x42/0xd64 [vmw_balloon]
[ 42.315853] SyS_delete_module+0x1e2/0x250
[ 42.315891] entry_SYSCALL_64_fastpath+0x23/0xc2
[ 42.315924] RIP: 0033:0x7f3af5b0e8e7
[ 42.315949] RSP: 002b:00007fffe6ce0148 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0
[ 42.315996] RAX: ffffffffffffffda RBX: 000055be676401e0 RCX: 00007f3af5b0e8e7
[ 42.316951] RDX: 000000000000000a RSI: 0000000000000800 RDI: 000055be67640248
[ 42.317887] RBP: 0000000000000003 R08: 0000000000000000 R09: 1999999999999999
[ 42.318845] R10: 0000000000000883 R11: 0000000000000206 R12: 00007fffe6cdf130
[ 42.319755] R13: 0000000000000000 R14: 0000000000000000 R15: 000055be676401e0
[ 42.320606] Code: c0 74 1c f0 ff 4f 1c 74 02 5d c3 85 f6 74 07 e8 0f d8 ff ff 5d c3 31 f6 e8 c6 fb ff ff 5d c3 48 c7 c6 c8 0f c5 ba e8 58 be 02 00 <0f> 0b 66 0f 1f 44 00 00 66 66 66 66 90 48 85 ff 75 01 c3 55 48
[ 42.323462] RIP: __free_pages+0x38/0x40 RSP: ffffbfefc163be98
[ 42.325735] ---[ end trace 872e008e33f81508 ]---
To solve the bug, we eliminate the dual purpose of balloon.page.
Fixes: f220a80f0c2e ("VMware balloon: add batching to the vmw_balloon.")
Cc: stable@vger.kernel.org
Reported-by: Oleksandr Natalenko <onatalen@redhat.com>
Signed-off-by: Gil Kupfer <gilkup@gmail.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Tested-by: Oleksandr Natalenko <oleksandr@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-06-01 14:47:47 +07:00
|
|
|
struct page *page;
|
2015-08-07 05:17:58 +07:00
|
|
|
|
vmw_balloon: fixing double free when batching mode is off
The balloon.page field is used for two different purposes if batching is
on or off. If batching is on, the field point to the page which is used
to communicate with with the hypervisor. If it is off, balloon.page
points to the page that is about to be (un)locked.
Unfortunately, this dual-purpose of the field introduced a bug: when the
balloon is popped (e.g., when the machine is reset or the balloon driver
is explicitly removed), the balloon driver frees, unconditionally, the
page that is held in balloon.page. As a result, if batching is
disabled, this leads to double freeing the last page that is sent to the
hypervisor.
The following error occurs during rmmod when kernel checkers are on, and
the balloon is not empty:
[ 42.307653] ------------[ cut here ]------------
[ 42.307657] Kernel BUG at ffffffffba1e4b28 [verbose debug info unavailable]
[ 42.307720] invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC
[ 42.312512] Modules linked in: vmw_vsock_vmci_transport vsock ppdev joydev vmw_balloon(-) input_leds serio_raw vmw_vmci parport_pc shpchp parport i2c_piix4 nfit mac_hid autofs4 vmwgfx drm_kms_helper hid_generic syscopyarea sysfillrect usbhid sysimgblt fb_sys_fops hid ttm mptspi scsi_transport_spi ahci mptscsih drm psmouse vmxnet3 libahci mptbase pata_acpi
[ 42.312766] CPU: 10 PID: 1527 Comm: rmmod Not tainted 4.12.0+ #5
[ 42.312803] Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 09/30/2016
[ 42.313042] task: ffff9bf9680f8000 task.stack: ffffbfefc1638000
[ 42.313290] RIP: 0010:__free_pages+0x38/0x40
[ 42.313510] RSP: 0018:ffffbfefc163be98 EFLAGS: 00010246
[ 42.313731] RAX: 000000000000003e RBX: ffffffffc02b9720 RCX: 0000000000000006
[ 42.313972] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff9bf97e08e0a0
[ 42.314201] RBP: ffffbfefc163be98 R08: 0000000000000000 R09: 0000000000000000
[ 42.314435] R10: 0000000000000000 R11: 0000000000000000 R12: ffffffffc02b97e4
[ 42.314505] R13: ffffffffc02b9748 R14: ffffffffc02b9728 R15: 0000000000000200
[ 42.314550] FS: 00007f3af5fec700(0000) GS:ffff9bf97e080000(0000) knlGS:0000000000000000
[ 42.314599] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 42.314635] CR2: 00007f44f6f4ab24 CR3: 00000003a7d12000 CR4: 00000000000006e0
[ 42.314864] Call Trace:
[ 42.315774] vmballoon_pop+0x102/0x130 [vmw_balloon]
[ 42.315816] vmballoon_exit+0x42/0xd64 [vmw_balloon]
[ 42.315853] SyS_delete_module+0x1e2/0x250
[ 42.315891] entry_SYSCALL_64_fastpath+0x23/0xc2
[ 42.315924] RIP: 0033:0x7f3af5b0e8e7
[ 42.315949] RSP: 002b:00007fffe6ce0148 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0
[ 42.315996] RAX: ffffffffffffffda RBX: 000055be676401e0 RCX: 00007f3af5b0e8e7
[ 42.316951] RDX: 000000000000000a RSI: 0000000000000800 RDI: 000055be67640248
[ 42.317887] RBP: 0000000000000003 R08: 0000000000000000 R09: 1999999999999999
[ 42.318845] R10: 0000000000000883 R11: 0000000000000206 R12: 00007fffe6cdf130
[ 42.319755] R13: 0000000000000000 R14: 0000000000000000 R15: 000055be676401e0
[ 42.320606] Code: c0 74 1c f0 ff 4f 1c 74 02 5d c3 85 f6 74 07 e8 0f d8 ff ff 5d c3 31 f6 e8 c6 fb ff ff 5d c3 48 c7 c6 c8 0f c5 ba e8 58 be 02 00 <0f> 0b 66 0f 1f 44 00 00 66 66 66 66 90 48 85 ff 75 01 c3 55 48
[ 42.323462] RIP: __free_pages+0x38/0x40 RSP: ffffbfefc163be98
[ 42.325735] ---[ end trace 872e008e33f81508 ]---
To solve the bug, we eliminate the dual purpose of balloon.page.
Fixes: f220a80f0c2e ("VMware balloon: add batching to the vmw_balloon.")
Cc: stable@vger.kernel.org
Reported-by: Oleksandr Natalenko <onatalen@redhat.com>
Signed-off-by: Gil Kupfer <gilkup@gmail.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Tested-by: Oleksandr Natalenko <oleksandr@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-06-01 14:47:47 +07:00
|
|
|
page = alloc_page(GFP_KERNEL | __GFP_ZERO);
|
|
|
|
if (!page)
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
return -ENOMEM;
|
2015-08-07 05:17:58 +07:00
|
|
|
|
vmw_balloon: fixing double free when batching mode is off
The balloon.page field is used for two different purposes if batching is
on or off. If batching is on, the field point to the page which is used
to communicate with with the hypervisor. If it is off, balloon.page
points to the page that is about to be (un)locked.
Unfortunately, this dual-purpose of the field introduced a bug: when the
balloon is popped (e.g., when the machine is reset or the balloon driver
is explicitly removed), the balloon driver frees, unconditionally, the
page that is held in balloon.page. As a result, if batching is
disabled, this leads to double freeing the last page that is sent to the
hypervisor.
The following error occurs during rmmod when kernel checkers are on, and
the balloon is not empty:
[ 42.307653] ------------[ cut here ]------------
[ 42.307657] Kernel BUG at ffffffffba1e4b28 [verbose debug info unavailable]
[ 42.307720] invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC
[ 42.312512] Modules linked in: vmw_vsock_vmci_transport vsock ppdev joydev vmw_balloon(-) input_leds serio_raw vmw_vmci parport_pc shpchp parport i2c_piix4 nfit mac_hid autofs4 vmwgfx drm_kms_helper hid_generic syscopyarea sysfillrect usbhid sysimgblt fb_sys_fops hid ttm mptspi scsi_transport_spi ahci mptscsih drm psmouse vmxnet3 libahci mptbase pata_acpi
[ 42.312766] CPU: 10 PID: 1527 Comm: rmmod Not tainted 4.12.0+ #5
[ 42.312803] Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 09/30/2016
[ 42.313042] task: ffff9bf9680f8000 task.stack: ffffbfefc1638000
[ 42.313290] RIP: 0010:__free_pages+0x38/0x40
[ 42.313510] RSP: 0018:ffffbfefc163be98 EFLAGS: 00010246
[ 42.313731] RAX: 000000000000003e RBX: ffffffffc02b9720 RCX: 0000000000000006
[ 42.313972] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff9bf97e08e0a0
[ 42.314201] RBP: ffffbfefc163be98 R08: 0000000000000000 R09: 0000000000000000
[ 42.314435] R10: 0000000000000000 R11: 0000000000000000 R12: ffffffffc02b97e4
[ 42.314505] R13: ffffffffc02b9748 R14: ffffffffc02b9728 R15: 0000000000000200
[ 42.314550] FS: 00007f3af5fec700(0000) GS:ffff9bf97e080000(0000) knlGS:0000000000000000
[ 42.314599] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 42.314635] CR2: 00007f44f6f4ab24 CR3: 00000003a7d12000 CR4: 00000000000006e0
[ 42.314864] Call Trace:
[ 42.315774] vmballoon_pop+0x102/0x130 [vmw_balloon]
[ 42.315816] vmballoon_exit+0x42/0xd64 [vmw_balloon]
[ 42.315853] SyS_delete_module+0x1e2/0x250
[ 42.315891] entry_SYSCALL_64_fastpath+0x23/0xc2
[ 42.315924] RIP: 0033:0x7f3af5b0e8e7
[ 42.315949] RSP: 002b:00007fffe6ce0148 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0
[ 42.315996] RAX: ffffffffffffffda RBX: 000055be676401e0 RCX: 00007f3af5b0e8e7
[ 42.316951] RDX: 000000000000000a RSI: 0000000000000800 RDI: 000055be67640248
[ 42.317887] RBP: 0000000000000003 R08: 0000000000000000 R09: 1999999999999999
[ 42.318845] R10: 0000000000000883 R11: 0000000000000206 R12: 00007fffe6cdf130
[ 42.319755] R13: 0000000000000000 R14: 0000000000000000 R15: 000055be676401e0
[ 42.320606] Code: c0 74 1c f0 ff 4f 1c 74 02 5d c3 85 f6 74 07 e8 0f d8 ff ff 5d c3 31 f6 e8 c6 fb ff ff 5d c3 48 c7 c6 c8 0f c5 ba e8 58 be 02 00 <0f> 0b 66 0f 1f 44 00 00 66 66 66 66 90 48 85 ff 75 01 c3 55 48
[ 42.323462] RIP: __free_pages+0x38/0x40 RSP: ffffbfefc163be98
[ 42.325735] ---[ end trace 872e008e33f81508 ]---
To solve the bug, we eliminate the dual purpose of balloon.page.
Fixes: f220a80f0c2e ("VMware balloon: add batching to the vmw_balloon.")
Cc: stable@vger.kernel.org
Reported-by: Oleksandr Natalenko <onatalen@redhat.com>
Signed-off-by: Gil Kupfer <gilkup@gmail.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Tested-by: Oleksandr Natalenko <oleksandr@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-06-01 14:47:47 +07:00
|
|
|
b->batch_page = page_address(page);
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
b->batch_max_pages = PAGE_SIZE / sizeof(struct vmballoon_batch_entry);
|
|
|
|
|
|
|
|
static_branch_enable(&vmw_balloon_batching);
|
|
|
|
|
|
|
|
return 0;
|
2015-08-07 05:17:58 +07:00
|
|
|
}
|
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
/*
|
|
|
|
* Receive notification and resize balloon
|
|
|
|
*/
|
|
|
|
static void vmballoon_doorbell(void *client_data)
|
|
|
|
{
|
|
|
|
struct vmballoon *b = client_data;
|
|
|
|
|
|
|
|
STATS_INC(b->stats.doorbell);
|
|
|
|
|
|
|
|
mod_delayed_work(system_freezable_wq, &b->dwork, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up vmci doorbell
|
|
|
|
*/
|
|
|
|
static void vmballoon_vmci_cleanup(struct vmballoon *b)
|
|
|
|
{
|
2018-09-21 00:30:07 +07:00
|
|
|
vmballoon_cmd(b, VMW_BALLOON_CMD_VMCI_DOORBELL_SET,
|
|
|
|
VMCI_INVALID_ID, VMCI_INVALID_ID);
|
2015-08-07 05:18:01 +07:00
|
|
|
|
|
|
|
if (!vmci_handle_is_invalid(b->vmci_doorbell)) {
|
|
|
|
vmci_doorbell_destroy(b->vmci_doorbell);
|
|
|
|
b->vmci_doorbell = VMCI_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize vmci doorbell, to get notified as soon as balloon changes
|
|
|
|
*/
|
|
|
|
static int vmballoon_vmci_init(struct vmballoon *b)
|
|
|
|
{
|
2018-09-21 00:30:07 +07:00
|
|
|
unsigned long error;
|
2015-08-07 05:18:01 +07:00
|
|
|
|
2018-06-20 06:00:26 +07:00
|
|
|
if ((b->capabilities & VMW_BALLOON_SIGNALLED_WAKEUP_CMD) == 0)
|
|
|
|
return 0;
|
2015-08-07 05:18:01 +07:00
|
|
|
|
2018-06-20 06:00:26 +07:00
|
|
|
error = vmci_doorbell_create(&b->vmci_doorbell, VMCI_FLAG_DELAYED_CB,
|
|
|
|
VMCI_PRIVILEGE_FLAG_RESTRICTED,
|
|
|
|
vmballoon_doorbell, b);
|
2015-08-07 05:18:01 +07:00
|
|
|
|
2018-06-20 06:00:26 +07:00
|
|
|
if (error != VMCI_SUCCESS)
|
|
|
|
goto fail;
|
|
|
|
|
2018-09-21 00:30:07 +07:00
|
|
|
error = __vmballoon_cmd(b, VMW_BALLOON_CMD_VMCI_DOORBELL_SET,
|
|
|
|
b->vmci_doorbell.context,
|
|
|
|
b->vmci_doorbell.resource, NULL);
|
2018-06-20 06:00:26 +07:00
|
|
|
|
|
|
|
if (error != VMW_BALLOON_SUCCESS)
|
|
|
|
goto fail;
|
2015-08-07 05:18:01 +07:00
|
|
|
|
|
|
|
return 0;
|
2018-06-20 06:00:26 +07:00
|
|
|
fail:
|
|
|
|
vmballoon_vmci_cleanup(b);
|
|
|
|
return -EIO;
|
2015-08-07 05:18:01 +07:00
|
|
|
}
|
|
|
|
|
2015-08-07 05:17:58 +07:00
|
|
|
/*
|
|
|
|
* Perform standard reset sequence by popping the balloon (in case it
|
|
|
|
* is not empty) and then restarting protocol. This operation normally
|
|
|
|
* happens when host responds with VMW_BALLOON_ERROR_RESET to a command.
|
|
|
|
*/
|
|
|
|
static void vmballoon_reset(struct vmballoon *b)
|
|
|
|
{
|
2015-08-07 05:18:01 +07:00
|
|
|
int error;
|
|
|
|
|
|
|
|
vmballoon_vmci_cleanup(b);
|
|
|
|
|
2015-08-07 05:17:58 +07:00
|
|
|
/* free all pages, skipping monitor unlock */
|
|
|
|
vmballoon_pop(b);
|
|
|
|
|
|
|
|
if (!vmballoon_send_start(b, VMW_BALLOON_CAPABILITIES))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((b->capabilities & VMW_BALLOON_BATCHED_CMDS) != 0) {
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
if (vmballoon_init_batching(b)) {
|
2015-08-07 05:17:58 +07:00
|
|
|
/*
|
|
|
|
* We failed to initialize batching, inform the monitor
|
|
|
|
* about it by sending a null capability.
|
|
|
|
*
|
|
|
|
* The guest will retry in one second.
|
|
|
|
*/
|
|
|
|
vmballoon_send_start(b, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if ((b->capabilities & VMW_BALLOON_BASIC_CMDS) != 0) {
|
vmw_balloon: change batch/single lock abstractions
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).
The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.
Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.
To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.
Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.
Reviewed-by: Xavier Deguillard <xdeguillard@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-21 00:30:12 +07:00
|
|
|
vmballoon_deinit_batching(b);
|
2015-08-07 05:17:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
b->reset_required = false;
|
2015-08-07 05:18:01 +07:00
|
|
|
|
|
|
|
error = vmballoon_vmci_init(b);
|
|
|
|
if (error)
|
|
|
|
pr_err("failed to initialize vmci doorbell\n");
|
|
|
|
|
2015-08-07 05:17:58 +07:00
|
|
|
if (!vmballoon_send_guest_id(b))
|
|
|
|
pr_err("failed to send guest ID to the host\n");
|
2010-04-24 00:18:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Balloon work function: reset protocol, if needed, get the new size and
|
|
|
|
* adjust balloon as needed. Repeat in 1 sec.
|
|
|
|
*/
|
|
|
|
static void vmballoon_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct delayed_work *dwork = to_delayed_work(work);
|
|
|
|
struct vmballoon *b = container_of(dwork, struct vmballoon, dwork);
|
|
|
|
|
|
|
|
STATS_INC(b->stats.timer);
|
|
|
|
|
|
|
|
if (b->reset_required)
|
|
|
|
vmballoon_reset(b);
|
|
|
|
|
2018-09-21 00:30:07 +07:00
|
|
|
if (!b->reset_required && vmballoon_send_get_target(b)) {
|
|
|
|
unsigned long target = b->target;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2018-09-21 00:30:07 +07:00
|
|
|
/* update target, adjust size */
|
2010-04-24 00:18:08 +07:00
|
|
|
if (b->size < target)
|
|
|
|
vmballoon_inflate(b);
|
2015-08-07 05:18:01 +07:00
|
|
|
else if (target == 0 ||
|
|
|
|
b->size > target + vmballoon_page_size(true))
|
2010-04-24 00:18:08 +07:00
|
|
|
vmballoon_deflate(b);
|
|
|
|
}
|
|
|
|
|
2011-07-27 06:08:56 +07:00
|
|
|
/*
|
|
|
|
* We are using a freezable workqueue so that balloon operations are
|
|
|
|
* stopped while the system transitions to/from sleep/hibernation.
|
|
|
|
*/
|
|
|
|
queue_delayed_work(system_freezable_wq,
|
|
|
|
dwork, round_jiffies_relative(HZ));
|
2010-04-24 00:18:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DEBUGFS Interface
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
|
|
|
|
static int vmballoon_debug_show(struct seq_file *f, void *offset)
|
|
|
|
{
|
|
|
|
struct vmballoon *b = f->private;
|
|
|
|
struct vmballoon_stats *stats = &b->stats;
|
2018-09-21 00:30:08 +07:00
|
|
|
int i;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2015-08-07 05:18:00 +07:00
|
|
|
/* format capabilities info */
|
|
|
|
seq_printf(f,
|
|
|
|
"balloon capabilities: %#4x\n"
|
2015-08-07 05:18:01 +07:00
|
|
|
"used capabilities: %#4lx\n"
|
|
|
|
"is resetting: %c\n",
|
|
|
|
VMW_BALLOON_CAPABILITIES, b->capabilities,
|
|
|
|
b->reset_required ? 'y' : 'n');
|
2015-08-07 05:18:00 +07:00
|
|
|
|
2010-04-24 00:18:08 +07:00
|
|
|
/* format size info */
|
|
|
|
seq_printf(f,
|
|
|
|
"target: %8d pages\n"
|
|
|
|
"current: %8d pages\n",
|
|
|
|
b->target, b->size);
|
|
|
|
|
2018-09-21 00:30:08 +07:00
|
|
|
for (i = 0; i < VMW_BALLOON_CMD_NUM; i++) {
|
|
|
|
if (vmballoon_cmd_names[i] == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
seq_printf(f, "%-22s: %16lu (%lu failed)\n",
|
|
|
|
vmballoon_cmd_names[i], stats->ops[i],
|
|
|
|
stats->ops_fail[i]);
|
|
|
|
}
|
|
|
|
|
2010-04-24 00:18:08 +07:00
|
|
|
seq_printf(f,
|
|
|
|
"\n"
|
|
|
|
"timer: %8u\n"
|
2015-08-07 05:18:01 +07:00
|
|
|
"doorbell: %8u\n"
|
2015-08-07 05:18:01 +07:00
|
|
|
"prim2mAlloc: %8u (%4u failed)\n"
|
2018-09-21 00:30:11 +07:00
|
|
|
"prim4kAlloc: %8u (%4u failed)\n"
|
2015-08-07 05:18:01 +07:00
|
|
|
"prim2mFree: %8u\n"
|
2010-04-24 00:18:08 +07:00
|
|
|
"primFree: %8u\n"
|
2015-08-07 05:18:01 +07:00
|
|
|
"err2mAlloc: %8u\n"
|
2010-04-24 00:18:08 +07:00
|
|
|
"errAlloc: %8u\n"
|
2015-08-07 05:18:01 +07:00
|
|
|
"err2mFree: %8u\n"
|
2018-09-21 00:30:08 +07:00
|
|
|
"errFree: %8u\n",
|
2010-04-24 00:18:08 +07:00
|
|
|
stats->timer,
|
2015-08-07 05:18:01 +07:00
|
|
|
stats->doorbell,
|
2015-08-07 05:18:01 +07:00
|
|
|
stats->alloc[true], stats->alloc_fail[true],
|
|
|
|
stats->alloc[false], stats->alloc_fail[false],
|
|
|
|
stats->free[true],
|
|
|
|
stats->free[false],
|
|
|
|
stats->refused_alloc[true], stats->refused_alloc[false],
|
2018-09-21 00:30:08 +07:00
|
|
|
stats->refused_free[true], stats->refused_free[false]);
|
2010-04-24 00:18:08 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vmballoon_debug_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, vmballoon_debug_show, inode->i_private);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations vmballoon_debug_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = vmballoon_debug_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init vmballoon_debugfs_init(struct vmballoon *b)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
b->dbg_entry = debugfs_create_file("vmmemctl", S_IRUGO, NULL, b,
|
|
|
|
&vmballoon_debug_fops);
|
|
|
|
if (IS_ERR(b->dbg_entry)) {
|
|
|
|
error = PTR_ERR(b->dbg_entry);
|
|
|
|
pr_err("failed to create debugfs entry, error: %d\n", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit vmballoon_debugfs_exit(struct vmballoon *b)
|
|
|
|
{
|
|
|
|
debugfs_remove(b->dbg_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static inline int vmballoon_debugfs_init(struct vmballoon *b)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void vmballoon_debugfs_exit(struct vmballoon *b)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_DEBUG_FS */
|
|
|
|
|
|
|
|
static int __init vmballoon_init(void)
|
|
|
|
{
|
|
|
|
int error;
|
2015-08-07 05:18:01 +07:00
|
|
|
unsigned is_2m_pages;
|
2010-04-24 00:18:08 +07:00
|
|
|
/*
|
|
|
|
* Check if we are running on VMware's hypervisor and bail out
|
|
|
|
* if we are not.
|
|
|
|
*/
|
2017-11-09 20:27:36 +07:00
|
|
|
if (x86_hyper_type != X86_HYPER_VMWARE)
|
2010-04-24 00:18:08 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
for (is_2m_pages = 0; is_2m_pages < VMW_BALLOON_NUM_PAGE_SIZES;
|
|
|
|
is_2m_pages++) {
|
|
|
|
INIT_LIST_HEAD(&balloon.page_sizes[is_2m_pages].pages);
|
|
|
|
INIT_LIST_HEAD(&balloon.page_sizes[is_2m_pages].refused_pages);
|
|
|
|
}
|
2010-04-24 00:18:08 +07:00
|
|
|
|
|
|
|
INIT_DELAYED_WORK(&balloon.dwork, vmballoon_work);
|
|
|
|
|
|
|
|
error = vmballoon_debugfs_init(&balloon);
|
|
|
|
if (error)
|
2011-07-27 06:08:56 +07:00
|
|
|
return error;
|
2010-04-24 00:18:08 +07:00
|
|
|
|
2015-08-07 05:18:01 +07:00
|
|
|
balloon.vmci_doorbell = VMCI_INVALID_HANDLE;
|
2015-08-07 05:18:01 +07:00
|
|
|
balloon.batch_page = NULL;
|
|
|
|
balloon.page = NULL;
|
|
|
|
balloon.reset_required = true;
|
|
|
|
|
2011-07-27 06:08:56 +07:00
|
|
|
queue_delayed_work(system_freezable_wq, &balloon.dwork, 0);
|
2010-04-24 00:18:08 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-06-20 06:00:27 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Using late_initcall() instead of module_init() allows the balloon to use the
|
|
|
|
* VMCI doorbell even when the balloon is built into the kernel. Otherwise the
|
|
|
|
* VMCI is probed only after the balloon is initialized. If the balloon is used
|
|
|
|
* as a module, late_initcall() is equivalent to module_init().
|
|
|
|
*/
|
|
|
|
late_initcall(vmballoon_init);
|
2010-04-24 00:18:08 +07:00
|
|
|
|
|
|
|
static void __exit vmballoon_exit(void)
|
|
|
|
{
|
2015-08-07 05:18:01 +07:00
|
|
|
vmballoon_vmci_cleanup(&balloon);
|
2010-04-24 00:18:08 +07:00
|
|
|
cancel_delayed_work_sync(&balloon.dwork);
|
|
|
|
|
|
|
|
vmballoon_debugfs_exit(&balloon);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deallocate all reserved memory, and reset connection with monitor.
|
|
|
|
* Reset connection before deallocating memory to avoid potential for
|
|
|
|
* additional spurious resets from guest touching deallocated pages.
|
|
|
|
*/
|
2015-08-07 05:18:01 +07:00
|
|
|
vmballoon_send_start(&balloon, 0);
|
2010-04-24 00:18:08 +07:00
|
|
|
vmballoon_pop(&balloon);
|
|
|
|
}
|
|
|
|
module_exit(vmballoon_exit);
|