Received: by 2002:a05:6520:1682:b0:147:d1a0:b502 with SMTP id ck2csp5595930lkb; Mon, 11 Oct 2021 09:38:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8BT0jGs/DX6KKtkcI+/aY+7equhgemnG96Vky0XLN6rqEyvYHc0xcRvdoQQx223gInKKG X-Received: by 2002:a63:ba58:: with SMTP id l24mr19201838pgu.184.1633970297020; Mon, 11 Oct 2021 09:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633970297; cv=none; d=google.com; s=arc-20160816; b=fXEYfo9+sjDQR1GDEZQbq0Q934uSJgyGqSnkqki9GuR0aDgnDVepXy+MJRWCVvcRS8 9XZKgrA4G6oE7w9RJbYz9Skgwx+AkZL+JXHlVSljY6ePCxu365X6g1ehEcqjNPp8yvnR VApGpCOgPSquQ64eVMFWkfhQHS01WoNuBUfehA0NEmiV71dmPbgz88D2YFTXMx7s2m40 FS850fkj1X8tjgW5QUG3G3iCzcJGK92nbosN0AVa62PnaHgTP2qBLZELGVOBIOQznTjm PRHFyQWJWd/nTEPnPNqUqEJLkLNqN/amOyc90CBZUaD9RwBiT3yNiYdeispib69cE+Zm NB1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/v6xA7nqCmPr5sMDutevkC4hT6E6QzDulGIsO3lFYFc=; b=biFGY7dqBx0Jl3Asx/U5k74hVw0YrlQnSgJFXC01ePeOhbEcALsmbQmAksCtbntZ6s EP59T2iRYMnxQwIwMlT/r+zw1NT8q0pAIVdsu799wbkBggqXrXeiNssDULhecwQ2KHGx Lp8w6GPh0jsSTMdpt4L776G160hXofmdC9aR+ltJ/A9pCz914vQlEQZTIbla+JSWziRu QQgSkRp6ObWzSm3eSJ1jNwp/SKfVwxqlyCmXNs3wO5VjltLhJTo1cF4twJv2VvHuWdnK wAQhme3otmE+1xjsWpPFLa8fdUWf4zgKeT5XFA5RtlZ8RKJPkK5HnFjkd/AJba/lWWyK nr1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D+7gufID; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f9si13587pjs.10.2021.10.11.09.38.02; Mon, 11 Oct 2021 09:38:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D+7gufID; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242632AbhJKORd (ORCPT + 99 others); Mon, 11 Oct 2021 10:17:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:35058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243835AbhJKOOx (ORCPT ); Mon, 11 Oct 2021 10:14:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F3BE261354; Mon, 11 Oct 2021 14:04:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633961096; bh=VhVdJO++/fA/CrMBT1l2MTIpN+N+tBrIikvMt4s0sPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D+7gufIDmE30GEirV3/iRZ09GxZoL0DTsjm3DgyXIF5ha/TC3YGBcLRxPfx2BvuBQ RqKRtkzPWT64a7XFpew7Vh+7IWzj7nqVtGIQPePiDU4mmUZOKaKFZnnWusiJh0Sjys AhZKlLWW26EiP2l9Z/gSdnsV9wVwuIoEYhCeBeZU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Juergen Gross , Jason Andryuk , Boris Ostrovsky Subject: [PATCH 4.19 07/28] xen/balloon: fix cancelled balloon action Date: Mon, 11 Oct 2021 15:46:57 +0200 Message-Id: <20211011134640.946996802@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134640.711218469@linuxfoundation.org> References: <20211011134640.711218469@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juergen Gross commit 319933a80fd4f07122466a77f93e5019d71be74c upstream. 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: stable@vger.kernel.org Fixes: 8480ed9c2bbd56 ("xen/balloon: use a kernel thread instead a workqueue") Reported-by: Marek Marczykowski-Górecki Signed-off-by: Juergen Gross Tested-by: Jason Andryuk Reviewed-by: Boris Ostrovsky Link: https://lore.kernel.org/r/20211005133433.32008-1-jgross@suse.com Signed-off-by: Juergen Gross Signed-off-by: Greg Kroah-Hartman --- drivers/xen/balloon.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -508,12 +508,12 @@ static enum bp_state decrease_reservatio } /* - * Stop waiting if either state is not BP_EAGAIN and ballooning action is - * needed, or if the credit has changed while state is BP_EAGAIN. + * Stop waiting if either state is BP_DONE and ballooning action is + * needed, or if the credit has changed while state is not BP_DONE. */ static bool balloon_thread_cond(enum bp_state state, long credit) { - if (state != BP_EAGAIN) + if (state == BP_DONE) credit = 0; return current_credit() != credit || kthread_should_stop(); @@ -533,10 +533,19 @@ static int balloon_thread(void *unused) set_freezable(); for (;;) { - if (state == BP_EAGAIN) - timeout = balloon_stats.schedule_delay * HZ; - else + switch (state) { + case BP_DONE: + case BP_ECANCELED: timeout = 3600 * HZ; + break; + case BP_EAGAIN: + timeout = balloon_stats.schedule_delay * HZ; + break; + case BP_WAIT: + timeout = HZ; + break; + } + credit = current_credit(); wait_event_freezable_timeout(balloon_thread_wq,