Skip to content

Commit 319933a

Browse files
committed
xen/balloon: fix cancelled balloon action
In case a ballooning action is cancelled the new kernel thread handling the ballooning might end up in a busy loop. Fix that by handling the cancelled action gracefully. While at it introduce a short wait for the BP_WAIT case. Cc: [email protected] Fixes: 8480ed9 ("xen/balloon: use a kernel thread instead a workqueue") Reported-by: Marek Marczykowski-Górecki <[email protected]> Signed-off-by: Juergen Gross <[email protected]> Tested-by: Jason Andryuk <[email protected]> Reviewed-by: Boris Ostrovsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Juergen Gross <[email protected]>
1 parent 9c11112 commit 319933a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

drivers/xen/balloon.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,12 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
491491
}
492492

493493
/*
494-
* Stop waiting if either state is not BP_EAGAIN and ballooning action is
495-
* needed, or if the credit has changed while state is BP_EAGAIN.
494+
* Stop waiting if either state is BP_DONE and ballooning action is
495+
* needed, or if the credit has changed while state is not BP_DONE.
496496
*/
497497
static bool balloon_thread_cond(enum bp_state state, long credit)
498498
{
499-
if (state != BP_EAGAIN)
499+
if (state == BP_DONE)
500500
credit = 0;
501501

502502
return current_credit() != credit || kthread_should_stop();
@@ -516,10 +516,19 @@ static int balloon_thread(void *unused)
516516

517517
set_freezable();
518518
for (;;) {
519-
if (state == BP_EAGAIN)
520-
timeout = balloon_stats.schedule_delay * HZ;
521-
else
519+
switch (state) {
520+
case BP_DONE:
521+
case BP_ECANCELED:
522522
timeout = 3600 * HZ;
523+
break;
524+
case BP_EAGAIN:
525+
timeout = balloon_stats.schedule_delay * HZ;
526+
break;
527+
case BP_WAIT:
528+
timeout = HZ;
529+
break;
530+
}
531+
523532
credit = current_credit();
524533

525534
wait_event_freezable_timeout(balloon_thread_wq,

0 commit comments

Comments
 (0)