Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3708310ybv; Mon, 10 Feb 2020 05:05:48 -0800 (PST) X-Google-Smtp-Source: APXvYqydBF4/5WHiXPD2lLs1o8XFpDyeYq5cOdaIPB9JFdAmnYORLI1+LckwAcZWG4C2wbyb+Qxq X-Received: by 2002:a9d:7851:: with SMTP id c17mr1033726otm.58.1581339948571; Mon, 10 Feb 2020 05:05:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339948; cv=none; d=google.com; s=arc-20160816; b=YvNK0hExjFm+KDy7GIH/mEPBZxde//YMQOcEOsDTIcMTKI/ja76SwG5AZP+xQq7aY6 xyuszR3pHjhCc+/IfA7UHEePvAidPdNB1wq9hcECwjES6+frmVNvO3SVDnCMKwJAAN6m 8r8PSUno6vK+jfVkRbKaHZAnczgEi15SHS0VI944dZQgqpINPqE8zpfiTylM3SLNYW79 tNSaTtpijU9VGfHaZCiwi2uqHFd/1LZ8xuFo+EZhAjFBKXQdlYSsugKi8mgsM8xdeMN0 1cly+Hnc0blzww6D7sNSrlh1EnA64HTNxh6/pNhk3o0WMS20MNIOMW5rCPgXsVVis/vV nmPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Cyz0poD+tpyZrvTFH1T9SNstFy8glRnrwUfrUTYhIB8=; b=jZPcnG9LMPEkY5gUkEp8zi4OhVoT0qktPeKJ8Hm1Aef40UVWUj3ko9SMPOKYj18ryh LIFydW5HheVBGL3/YgRhngvZqkzi1BXXuT2+k4COMXG9wjFsPh5QmTkxRgUQdP81xChd RnZVwFa+c6qCod41nRgStNUXR3XVa7v9LkQwhHIxd+sjYZ8zCTba2xHnQnyy014BncJi OOWHRi6Fagtpmz2ta0QnT785oS+I6lh2RxlUIvVzq6rOo1k0bTklDKflYZfcdz3VnYCd 3lbePjMt2wAozqZHp9AaHpHXdaZsQ18Huk5vB9XKW3sUvrGdkgOdPJ+nVOYQjEX4vS7d RaiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mPmUOgsi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x26si150071otk.325.2020.02.10.05.05.36; Mon, 10 Feb 2020 05:05:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mPmUOgsi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730791AbgBJNFI (ORCPT + 99 others); Mon, 10 Feb 2020 08:05:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:39438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729623AbgBJMkH (ORCPT ); Mon, 10 Feb 2020 07:40:07 -0500 Received: from localhost (unknown [209.37.97.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 104FE24672; Mon, 10 Feb 2020 12:40:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338407; bh=SuRrPA4tdvUoCTfsC4/L91gX2RFmWCvvWteqkENkFwU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mPmUOgsioKwrIeZFcfoxgs6ktt+UytIwFcjNrbTvOt8ax59x/Fuh1eUog4acLQumv pEwI/oAPPq+kMhzqzo7is0FH13ysoIeQoZBbd5OfyAxNQAohzlrC5X8VY1C9kKrW2n wRAY5TKZBIa6DwVpMnJEw67ZOysklsbRwj2YLJkM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Kuznetsov , Tianyu Lan , Michael Kelley , Sasha Levin Subject: [PATCH 5.5 110/367] hv_balloon: Balloon up according to request page number Date: Mon, 10 Feb 2020 04:30:23 -0800 Message-Id: <20200210122434.627765704@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tianyu Lan commit d33c240d47dab4fd15123d9e73fc8810cbc6ed6a upstream. Current code has assumption that balloon request memory size aligns with 2MB. But actually Hyper-V doesn't guarantee such alignment. When balloon driver receives non-aligned balloon request, it produces warning and balloon up more memory than requested in order to keep 2MB alignment. Remove the warning and balloon up memory according to actual requested memory size. Fixes: f6712238471a ("hv: hv_balloon: avoid memory leak on alloc_error of 2MB memory block") Cc: stable@vger.kernel.org Reviewed-by: Vitaly Kuznetsov Signed-off-by: Tianyu Lan Reviewed-by: Michael Kelley Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/hv/hv_balloon.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -1217,10 +1217,7 @@ static unsigned int alloc_balloon_pages( unsigned int i, j; struct page *pg; - if (num_pages < alloc_unit) - return 0; - - for (i = 0; (i * alloc_unit) < num_pages; i++) { + for (i = 0; i < num_pages / alloc_unit; i++) { if (bl_resp->hdr.size + sizeof(union dm_mem_page_range) > HV_HYP_PAGE_SIZE) return i * alloc_unit; @@ -1258,7 +1255,7 @@ static unsigned int alloc_balloon_pages( } - return num_pages; + return i * alloc_unit; } static void balloon_up(struct work_struct *dummy) @@ -1273,9 +1270,6 @@ static void balloon_up(struct work_struc long avail_pages; unsigned long floor; - /* The host balloons pages in 2M granularity. */ - WARN_ON_ONCE(num_pages % PAGES_IN_2M != 0); - /* * We will attempt 2M allocations. However, if we fail to * allocate 2M chunks, we will go back to PAGE_SIZE allocations. @@ -1285,14 +1279,13 @@ static void balloon_up(struct work_struc avail_pages = si_mem_available(); floor = compute_balloon_floor(); - /* Refuse to balloon below the floor, keep the 2M granularity. */ + /* Refuse to balloon below the floor. */ if (avail_pages < num_pages || avail_pages - num_pages < floor) { pr_warn("Balloon request will be partially fulfilled. %s\n", avail_pages < num_pages ? "Not enough memory." : "Balloon floor reached."); num_pages = avail_pages > floor ? (avail_pages - floor) : 0; - num_pages -= num_pages % PAGES_IN_2M; } while (!done) {