Skip to content

Commit 48e3d66

Browse files
Philip P. Moltmanngregkh
authored andcommitted
VMware balloon: Enable notification via VMCI
Get notified immediately when a balloon target is set, instead of waiting for up to one second. The up-to 1 second gap could be long enough to cause swapping inside of the VM that receives the VM. Acked-by: Andy King <[email protected]> Signed-off-by: Xavier Deguillard <[email protected]> Tested-by: Siva Sankar Reddy B <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d7568c1 commit 48e3d66

File tree

2 files changed

+97
-10
lines changed

2 files changed

+97
-10
lines changed

drivers/misc/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ config TI_DAC7512
414414

415415
config VMWARE_BALLOON
416416
tristate "VMware Balloon Driver"
417-
depends on X86 && HYPERVISOR_GUEST
417+
depends on VMWARE_VMCI && X86 && HYPERVISOR_GUEST
418418
help
419419
This is VMware physical memory management driver which acts
420420
like a "balloon" that can be inflated to reclaim physical pages

drivers/misc/vmw_balloon.c

Lines changed: 96 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* VMware Balloon driver.
33
*
4-
* Copyright (C) 2000-2013, VMware, Inc. All Rights Reserved.
4+
* Copyright (C) 2000-2014, VMware, Inc. All Rights Reserved.
55
*
66
* This program is free software; you can redistribute it and/or modify it
77
* under the terms of the GNU General Public License as published by the
@@ -43,11 +43,13 @@
4343
#include <linux/workqueue.h>
4444
#include <linux/debugfs.h>
4545
#include <linux/seq_file.h>
46+
#include <linux/vmw_vmci_defs.h>
47+
#include <linux/vmw_vmci_api.h>
4648
#include <asm/hypervisor.h>
4749

4850
MODULE_AUTHOR("VMware, Inc.");
4951
MODULE_DESCRIPTION("VMware Memory Control (Balloon) Driver");
50-
MODULE_VERSION("1.4.1.0-k");
52+
MODULE_VERSION("1.5.0.0-k");
5153
MODULE_ALIAS("dmi:*:svnVMware*:*");
5254
MODULE_ALIAS("vmware_vmmemctl");
5355
MODULE_LICENSE("GPL");
@@ -101,14 +103,16 @@ enum vmwballoon_capabilities {
101103
/*
102104
* Bit 0 is reserved and not associated to any capability.
103105
*/
104-
VMW_BALLOON_BASIC_CMDS = (1 << 1),
105-
VMW_BALLOON_BATCHED_CMDS = (1 << 2),
106-
VMW_BALLOON_BATCHED_2M_CMDS = (1 << 3),
106+
VMW_BALLOON_BASIC_CMDS = (1 << 1),
107+
VMW_BALLOON_BATCHED_CMDS = (1 << 2),
108+
VMW_BALLOON_BATCHED_2M_CMDS = (1 << 3),
109+
VMW_BALLOON_SIGNALLED_WAKEUP_CMD = (1 << 4),
107110
};
108111

109112
#define VMW_BALLOON_CAPABILITIES (VMW_BALLOON_BASIC_CMDS \
110113
| VMW_BALLOON_BATCHED_CMDS \
111-
| VMW_BALLOON_BATCHED_2M_CMDS)
114+
| VMW_BALLOON_BATCHED_2M_CMDS \
115+
| VMW_BALLOON_SIGNALLED_WAKEUP_CMD)
112116

113117
#define VMW_BALLOON_2M_SHIFT (9)
114118
#define VMW_BALLOON_NUM_PAGE_SIZES (2)
@@ -123,7 +127,9 @@ enum vmwballoon_capabilities {
123127
* VMW_BALLOON_BATCHED_CMDS:
124128
* BATCHED_LOCK and BATCHED_UNLOCK commands.
125129
* VMW BALLOON_BATCHED_2M_CMDS:
126-
* BATCHED_2M_LOCK and BATCHED_2M_UNLOCK commands.
130+
* BATCHED_2M_LOCK and BATCHED_2M_UNLOCK commands,
131+
* VMW VMW_BALLOON_SIGNALLED_WAKEUP_CMD:
132+
* VMW_BALLOON_CMD_VMCI_DOORBELL_SET command.
127133
*/
128134
#define VMW_BALLOON_CMD_START 0
129135
#define VMW_BALLOON_CMD_GET_TARGET 1
@@ -134,6 +140,7 @@ enum vmwballoon_capabilities {
134140
#define VMW_BALLOON_CMD_BATCHED_UNLOCK 7
135141
#define VMW_BALLOON_CMD_BATCHED_2M_LOCK 8
136142
#define VMW_BALLOON_CMD_BATCHED_2M_UNLOCK 9
143+
#define VMW_BALLOON_CMD_VMCI_DOORBELL_SET 10
137144

138145

139146
/* error codes */
@@ -214,6 +221,7 @@ static void vmballoon_batch_set_pa(struct vmballoon_batch_page *batch, int idx,
214221
#ifdef CONFIG_DEBUG_FS
215222
struct vmballoon_stats {
216223
unsigned int timer;
224+
unsigned int doorbell;
217225

218226
/* allocation statistics */
219227
unsigned int alloc[VMW_BALLOON_NUM_PAGE_SIZES];
@@ -235,6 +243,8 @@ struct vmballoon_stats {
235243
unsigned int start_fail;
236244
unsigned int guest_type;
237245
unsigned int guest_type_fail;
246+
unsigned int doorbell_set;
247+
unsigned int doorbell_unset;
238248
};
239249

240250
#define STATS_INC(stat) (stat)++
@@ -299,6 +309,8 @@ struct vmballoon {
299309
struct sysinfo sysinfo;
300310

301311
struct delayed_work dwork;
312+
313+
struct vmci_handle vmci_doorbell;
302314
};
303315

304316
static struct vmballoon balloon;
@@ -992,13 +1004,76 @@ static bool vmballoon_init_batching(struct vmballoon *b)
9921004
return true;
9931005
}
9941006

1007+
/*
1008+
* Receive notification and resize balloon
1009+
*/
1010+
static void vmballoon_doorbell(void *client_data)
1011+
{
1012+
struct vmballoon *b = client_data;
1013+
1014+
STATS_INC(b->stats.doorbell);
1015+
1016+
mod_delayed_work(system_freezable_wq, &b->dwork, 0);
1017+
}
1018+
1019+
/*
1020+
* Clean up vmci doorbell
1021+
*/
1022+
static void vmballoon_vmci_cleanup(struct vmballoon *b)
1023+
{
1024+
int error;
1025+
1026+
VMWARE_BALLOON_CMD(VMCI_DOORBELL_SET, VMCI_INVALID_ID,
1027+
VMCI_INVALID_ID, error);
1028+
STATS_INC(b->stats.doorbell_unset);
1029+
1030+
if (!vmci_handle_is_invalid(b->vmci_doorbell)) {
1031+
vmci_doorbell_destroy(b->vmci_doorbell);
1032+
b->vmci_doorbell = VMCI_INVALID_HANDLE;
1033+
}
1034+
}
1035+
1036+
/*
1037+
* Initialize vmci doorbell, to get notified as soon as balloon changes
1038+
*/
1039+
static int vmballoon_vmci_init(struct vmballoon *b)
1040+
{
1041+
int error = 0;
1042+
1043+
if ((b->capabilities & VMW_BALLOON_SIGNALLED_WAKEUP_CMD) != 0) {
1044+
error = vmci_doorbell_create(&b->vmci_doorbell,
1045+
VMCI_FLAG_DELAYED_CB,
1046+
VMCI_PRIVILEGE_FLAG_RESTRICTED,
1047+
vmballoon_doorbell, b);
1048+
1049+
if (error == VMCI_SUCCESS) {
1050+
VMWARE_BALLOON_CMD(VMCI_DOORBELL_SET,
1051+
b->vmci_doorbell.context,
1052+
b->vmci_doorbell.resource, error);
1053+
STATS_INC(b->stats.doorbell_set);
1054+
}
1055+
}
1056+
1057+
if (error != 0) {
1058+
vmballoon_vmci_cleanup(b);
1059+
1060+
return -EIO;
1061+
}
1062+
1063+
return 0;
1064+
}
1065+
9951066
/*
9961067
* Perform standard reset sequence by popping the balloon (in case it
9971068
* is not empty) and then restarting protocol. This operation normally
9981069
* happens when host responds with VMW_BALLOON_ERROR_RESET to a command.
9991070
*/
10001071
static void vmballoon_reset(struct vmballoon *b)
10011072
{
1073+
int error;
1074+
1075+
vmballoon_vmci_cleanup(b);
1076+
10021077
/* free all pages, skipping monitor unlock */
10031078
vmballoon_pop(b);
10041079

@@ -1024,6 +1099,11 @@ static void vmballoon_reset(struct vmballoon *b)
10241099
}
10251100

10261101
b->reset_required = false;
1102+
1103+
error = vmballoon_vmci_init(b);
1104+
if (error)
1105+
pr_err("failed to initialize vmci doorbell\n");
1106+
10271107
if (!vmballoon_send_guest_id(b))
10281108
pr_err("failed to send guest ID to the host\n");
10291109
}
@@ -1097,6 +1177,7 @@ static int vmballoon_debug_show(struct seq_file *f, void *offset)
10971177
seq_printf(f,
10981178
"\n"
10991179
"timer: %8u\n"
1180+
"doorbell: %8u\n"
11001181
"start: %8u (%4u failed)\n"
11011182
"guestType: %8u (%4u failed)\n"
11021183
"2m-lock: %8u (%4u failed)\n"
@@ -1112,8 +1193,11 @@ static int vmballoon_debug_show(struct seq_file *f, void *offset)
11121193
"err2mAlloc: %8u\n"
11131194
"errAlloc: %8u\n"
11141195
"err2mFree: %8u\n"
1115-
"errFree: %8u\n",
1196+
"errFree: %8u\n"
1197+
"doorbellSet: %8u\n"
1198+
"doorbellUnset: %8u\n",
11161199
stats->timer,
1200+
stats->doorbell,
11171201
stats->start, stats->start_fail,
11181202
stats->guest_type, stats->guest_type_fail,
11191203
stats->lock[true], stats->lock_fail[true],
@@ -1127,7 +1211,8 @@ static int vmballoon_debug_show(struct seq_file *f, void *offset)
11271211
stats->free[true],
11281212
stats->free[false],
11291213
stats->refused_alloc[true], stats->refused_alloc[false],
1130-
stats->refused_free[true], stats->refused_free[false]);
1214+
stats->refused_free[true], stats->refused_free[false],
1215+
stats->doorbell_set, stats->doorbell_unset);
11311216

11321217
return 0;
11331218
}
@@ -1204,6 +1289,7 @@ static int __init vmballoon_init(void)
12041289
if (error)
12051290
return error;
12061291

1292+
balloon.vmci_doorbell = VMCI_INVALID_HANDLE;
12071293
balloon.batch_page = NULL;
12081294
balloon.page = NULL;
12091295
balloon.reset_required = true;
@@ -1216,6 +1302,7 @@ module_init(vmballoon_init);
12161302

12171303
static void __exit vmballoon_exit(void)
12181304
{
1305+
vmballoon_vmci_cleanup(&balloon);
12191306
cancel_delayed_work_sync(&balloon.dwork);
12201307

12211308
vmballoon_debugfs_exit(&balloon);

0 commit comments

Comments
 (0)