Skip to content

Commit 5266b8e

Browse files
jgross1Boris Ostrovsky
authored andcommitted
xen: fix booting ballooned down hvm guest
Commit 96edd61 ("xen/balloon: don't online new memory initially") introduced a regression when booting a HVM domain with memory less than mem-max: instead of ballooning down immediately the system would try to use the memory up to mem-max resulting in Xen crashing the domain. For HVM domains the current size will be reflected in Xenstore node memory/static-max instead of memory/target. Additionally we have to trigger the ballooning process at once. Cc: <[email protected]> # 4.13 Fixes: 96edd61 ("xen/balloon: don't online new memory initially") Reported-by: Simon Gaiser <[email protected]> Suggested-by: Boris Ostrovsky <[email protected]> Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Boris Ostrovsky <[email protected]> Signed-off-by: Boris Ostrovsky <[email protected]>
1 parent 298d275 commit 5266b8e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

drivers/xen/xen-balloon.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static int register_balloon(struct device *dev);
5757
static void watch_target(struct xenbus_watch *watch,
5858
const char *path, const char *token)
5959
{
60-
unsigned long long new_target;
60+
unsigned long long new_target, static_max;
6161
int err;
6262
static bool watch_fired;
6363
static long target_diff;
@@ -72,13 +72,20 @@ static void watch_target(struct xenbus_watch *watch,
7272
* pages. PAGE_SHIFT converts bytes to pages, hence PAGE_SHIFT - 10.
7373
*/
7474
new_target >>= PAGE_SHIFT - 10;
75-
if (watch_fired) {
76-
balloon_set_new_target(new_target - target_diff);
77-
return;
75+
76+
if (!watch_fired) {
77+
watch_fired = true;
78+
err = xenbus_scanf(XBT_NIL, "memory", "static-max", "%llu",
79+
&static_max);
80+
if (err != 1)
81+
static_max = new_target;
82+
else
83+
static_max >>= PAGE_SHIFT - 10;
84+
target_diff = xen_pv_domain() ? 0
85+
: static_max - balloon_stats.target_pages;
7886
}
7987

80-
watch_fired = true;
81-
target_diff = new_target - balloon_stats.target_pages;
88+
balloon_set_new_target(new_target - target_diff);
8289
}
8390
static struct xenbus_watch target_watch = {
8491
.node = "memory/target",

0 commit comments

Comments
 (0)