Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 530d15b9 authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by Greg Kroah-Hartman
Browse files

Drivers: hv: hv_balloon: refuse to balloon below the floor



When host asks us to balloon up we need to be sure we're not committing suicide
by overballooning. Use already existent 'floor' metric as our lowest possible
value for free ram.

Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 549fd280
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -1138,6 +1138,8 @@ static void balloon_up(struct work_struct *dummy)
	bool alloc_error;
	bool alloc_error;
	bool done = false;
	bool done = false;
	int i;
	int i;
	struct sysinfo val;
	unsigned long floor;


	/* The host balloons pages in 2M granularity. */
	/* The host balloons pages in 2M granularity. */
	WARN_ON_ONCE(num_pages % PAGES_IN_2M != 0);
	WARN_ON_ONCE(num_pages % PAGES_IN_2M != 0);
@@ -1148,6 +1150,15 @@ static void balloon_up(struct work_struct *dummy)
	 */
	 */
	alloc_unit = 512;
	alloc_unit = 512;


	si_meminfo(&val);
	floor = compute_balloon_floor();

	/* Refuse to balloon below the floor, keep the 2M granularity. */
	if (val.freeram - num_pages < floor) {
		num_pages = val.freeram > floor ? (val.freeram - floor) : 0;
		num_pages -= num_pages % PAGES_IN_2M;
	}

	while (!done) {
	while (!done) {
		bl_resp = (struct dm_balloon_response *)send_buffer;
		bl_resp = (struct dm_balloon_response *)send_buffer;
		memset(send_buffer, 0, PAGE_SIZE);
		memset(send_buffer, 0, PAGE_SIZE);