Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4600761pxb; Tue, 5 Oct 2021 06:36:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywdBGSeypLyUy3QkPJvMnxKWUNAv0kueP5EVg6MeMY9N2A9K8Mh/bIR5xlNB4TL+Y6EaTS X-Received: by 2002:a05:6a00:c8c:b0:447:bddb:c83 with SMTP id a12-20020a056a000c8c00b00447bddb0c83mr32020462pfv.1.1633440962187; Tue, 05 Oct 2021 06:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633440962; cv=none; d=google.com; s=arc-20160816; b=UzSvQ9s03YqKcwQtEBENEd9nSZagj06xHxeI93GgewZ0rbtzZLV7mX3AwY26iyR7eF MJLjxFojcm5H2/58dBtnWwk6nDNNzW3fn/4APmjmn/BgHhryL48JjBuJbavIKi5Ph3D9 7Dlod6LPQySHkY1lbszfD7+cO2vuijkKweghWHgrUqArt16C/m4BCxYR+gKNLWXSughR wLOozJjcr66HN6o8v2U4u0stZSFT42T6heBk1BPkqhXWfEG71f9mrLJLYcMqW6lgwGXH SDmGjpBS6P6p3M5l95G/fHrNlbwntPQmNoek0fqUMsoa4DtRcJ8saZ1COX3pCupbEoWi 8CdA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=muVpN94mowz5PNDdbHLdWMwCxQCzzIFQLh6tPGkXOCw=; b=BUQsmC2lcFAo7r5sukVm12cSmEUPdTKgj7ZYHMZxu+g7BbLpXiiQhZCQoqXTo+5B4+ 39MwHDRvciOwhxvPxvspXD3suViwyHR1SXzQfnXMNyBgy2kJEo2UG5tk7GqD2lk/0Wvf xa9Mu2ERdwO6HLqBClhFHaYRx0nTTGdtrWm4mxNv1EYkj74DhtAxLbfpDpvShkGD1svb J01D41JXW/EbHnG1ivfKiyIWxaciDpEhkynr7MU57WG/427STWrHf8lFOuuOOjkYvBZB 2rEDwIWNjX8LRxiZcpYbZNrEvKM0lmUqn0YSc+RPshxlVr8Hslf5fTnh76MTicAe0JLs efHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=WB084CpV; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s73si21968152pgs.611.2021.10.05.06.35.45; Tue, 05 Oct 2021 06:36:02 -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=@suse.com header.s=susede1 header.b=WB084CpV; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235015AbhJENg2 (ORCPT + 99 others); Tue, 5 Oct 2021 09:36:28 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:41132 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234103AbhJENg1 (ORCPT ); Tue, 5 Oct 2021 09:36:27 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9BBDF20028; Tue, 5 Oct 2021 13:34:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1633440875; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=muVpN94mowz5PNDdbHLdWMwCxQCzzIFQLh6tPGkXOCw=; b=WB084CpVgo7IVkufWcK3GX0mN37NTIXQAwwmpfy8mfvZjcDCTnJJph90jEaoPJ8gs6E5BO s7Z+YiKqhftnBIOnEtwSjw6L/5HUFyKN3dBids+HBSzO8WlZAQPyLKQ8bJBkW6WBWRx9Qa iO4ZxJ64g3GTX589cF6hqBGZ96qyPzc= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6487D13C35; Tue, 5 Oct 2021 13:34:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id a1xEF2tUXGHnDwAAMHmgww (envelope-from ); Tue, 05 Oct 2021 13:34:35 +0000 From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , stable@vger.kernel.org, =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Subject: [PATCH] xen/balloon: fix cancelled balloon action Date: Tue, 5 Oct 2021 15:34:33 +0200 Message-Id: <20211005133433.32008-1-jgross@suse.com> X-Mailer: git-send-email 2.26.2 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 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 --- drivers/xen/balloon.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 43ebfe36ac27..3a50f097ed3e 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -491,12 +491,12 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) } /* - * 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(); @@ -516,10 +516,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, -- 2.26.2