Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1448174pxb; Thu, 28 Oct 2021 04:02:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEa99zdrEP5BjqmP8M8iK/1ziiK5qWrOG/fF9A9aCIm1hMP6isSXxKolBVo91QiyREj+d6 X-Received: by 2002:a05:6a00:731:b0:44c:7c1b:fe6a with SMTP id 17-20020a056a00073100b0044c7c1bfe6amr3390231pfm.44.1635418927672; Thu, 28 Oct 2021 04:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635418927; cv=none; d=google.com; s=arc-20160816; b=gasdAwDvBcqJ038qezRcW4StrYhH43AU2/tWQcdtDRKJzR54wq9lYMB7hhwU/Vi91R T4W3rt/rZlhYJyiYtJjqnkSgV3PKhFQDlHP7+jc8Y8cfWsrDMime5c92B5N0gbSspw/8 6fSJOBTj+CcycYTWHowc2Au8Mq5ULy1EDATQ8yIiJj5KRcx05HkO+/wiQ3TdDaNDaoSm q9S9JXK2zZoDY0APLEoobVkQCE4Z6+uf4N7j64bv/X5YcvRi2ZPyA0P8McQnhVLNSZ2J XxzWu10FTjaxz0d1HRLTDx/RbmJeyCRUuDnTNCIWJq9qALr8wxokCman4SGBbge+8leH XifA== 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=zbNYXie6Hzu/qw+CQlU1pNMVLlxvFSRFIIQVne0mm/A=; b=PkFumAV7Tg7mbHToh1mOqJ8zH+5w/oC2shBQdB6ggl5n8IuX+2Sv5HIhuQ29rszGCh AG4mZDk3WSscHY1XiFy07Zivm9rKuOBQx4x+ndvVgMdyqnKZ4EDhK4l/V9YSc0dMPHb7 DpLrIU7m1cvo1pJYD6reMqZMzJXqT7sQVemw3Wpl45Dn2B+1S1w+CnIBcz8EWxvbxXUA szUjmKFCnjwy3W4Trl5osxx6i9/aqoBKsuoIggTPUoCV9ObyOkSSsMZeXW3CkpHVgUWD RPR0IDdZQdyGpF+rgqW59fFWJoKYMZkZRdFaplNX5D+GG5a0blOJvHzOK3/Q40PmHHy3 wrvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=bNz1I6ZA; 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 h16si3518310pfv.316.2021.10.28.04.01.54; Thu, 28 Oct 2021 04:02:07 -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=bNz1I6ZA; 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 S230166AbhJ1LCZ (ORCPT + 99 others); Thu, 28 Oct 2021 07:02:25 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:47378 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230093AbhJ1LCY (ORCPT ); Thu, 28 Oct 2021 07:02:24 -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 454D91FD4B; Thu, 28 Oct 2021 10:59:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1635418796; 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=zbNYXie6Hzu/qw+CQlU1pNMVLlxvFSRFIIQVne0mm/A=; b=bNz1I6ZABAMt8Dl4G3Tn26G74FtY89yFKIs9oSYIAdBladlFdguRX8/jVEu3rN725BrO4C aqnV6fskaxOVK3L71kMUr+uMwiA7gKJQBRpXB4MDDNsPpBtRipv/LEPd1uw9yowq6PUP08 2lKgmbDSHONB5ZySGN9l0z4USVQIkKg= 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 07D4713C5C; Thu, 28 Oct 2021 10:59:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id opa6AKyCemGQNgAAMHmgww (envelope-from ); Thu, 28 Oct 2021 10:59:56 +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: add late_initcall_sync() for initial ballooning done Date: Thu, 28 Oct 2021 12:59:52 +0200 Message-Id: <20211028105952.10011-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 When running as PVH or HVM guest with actual memory < max memory the hypervisor is using "populate on demand" in order to allow the guest to balloon down from its maximum memory size. For this to work correctly the guest must not touch more memory pages than its target memory size as otherwise the PoD cache will be exhausted and the guest is crashed as a result of that. In extreme cases ballooning down might not be finished today before the init process is started, which can consume lots of memory. In order to avoid random boot crashes in such cases, add a late init call to wait for ballooning down having finished for PVH/HVM guests. Cc: Reported-by: Marek Marczykowski-Górecki Signed-off-by: Juergen Gross --- drivers/xen/balloon.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 3a50f097ed3e..d19b851c3d3b 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -765,3 +765,23 @@ static int __init balloon_init(void) return 0; } subsys_initcall(balloon_init); + +static int __init balloon_wait_finish(void) +{ + if (!xen_domain()) + return -ENODEV; + + /* PV guests don't need to wait. */ + if (xen_pv_domain() || !current_credit()) + return 0; + + pr_info("Waiting for initial ballooning down having finished.\n"); + + while (current_credit()) + schedule_timeout_interruptible(HZ / 10); + + pr_info("Initial ballooning down finished.\n"); + + return 0; +} +late_initcall_sync(balloon_wait_finish); -- 2.26.2