Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7826972ybl; Thu, 16 Jan 2020 06:17:58 -0800 (PST) X-Google-Smtp-Source: APXvYqyMO/SI2T8j6w2X+LKRs6pmzxYkJP2f5MfUqQ60GgtRlBIgNfhSSnSyF/45xlytuyfA+E6M X-Received: by 2002:a05:6830:9a:: with SMTP id a26mr2186223oto.131.1579184278544; Thu, 16 Jan 2020 06:17:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579184278; cv=none; d=google.com; s=arc-20160816; b=SXNucCFothzu0pWuaGBk7FNTQTexNbTM617Bmk0cxORVVBWkHaoKR0aMIwWmZXf3U0 Z0ZLDrrV+jZ1cXsF7apfmvQ+16Dvi3dFCnpdbM7TxsDWYR1q+1yXBVq0M4CHwJ9CdAfq m4UZPbHj3pF/5ew42nZ2+QxFbh+uZJrTfT9gpyN3AguGE04c0khtxenGJmnq+rWsk2FV y9Kvlx7YR1uZmdg+78F3V3RdNhaP6FY5UTMsZ9tfz+WQgm/tYxKKMEV/axepDWVa0ge7 zUQseqHklFb2Q+HJTty2YDaG2fBcfiK1bt5d9Vrwt61Zk+OYaHkHokaYS5o+iHLIv5MF WEnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Eu4Tz2PSHJmrgZ6GXoLAyXHUq4EjuOki9XQQRKCo8U0=; b=kDUTWmq+2cwsc7KWQJ1hu+N/6ZaEaWeyH5vgKfsD017KGUgU4dVcnI86UmpeIr2gDt 2ysKQ6ATkk+Lj+gdq9WYXLmOYt/2p5EOPpifCR1elvNq0TvAKUErxcTxapAlcY+k60EB 9u9gYsnTuqrhk3bbENm//WybTPp6X30UHzZpXZjW8a2d2exqWb/AElNLH2X6foXxtIyn HJZHe+XDL1gi+cWiULrRtE3WVJSy8XfwhXPNLUFuIsp6RR3ihaICkxW8j6khz3mN494d y+9IZlK+8UVaj730jLbP0oXXps1yGYdyc23UKAEf6c9huKYKBFgH00yE14hNeXAxNdH+ ViPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fulQtMWe; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x186si11283226oig.209.2020.01.16.06.17.46; Thu, 16 Jan 2020 06:17:58 -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=@gmail.com header.s=20161025 header.b=fulQtMWe; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726876AbgAPOQJ (ORCPT + 99 others); Thu, 16 Jan 2020 09:16:09 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46881 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbgAPOQJ (ORCPT ); Thu, 16 Jan 2020 09:16:09 -0500 Received: by mail-pg1-f195.google.com with SMTP id z124so9937975pgb.13; Thu, 16 Jan 2020 06:16:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Eu4Tz2PSHJmrgZ6GXoLAyXHUq4EjuOki9XQQRKCo8U0=; b=fulQtMWeJzJQoeci+lVO3hnPUXUa8ii7kCvabmXiar4NzJDT43mfCse0/Cq5/HJ00b nVZp7FyBkFWK6cMr0yEj/v7iVyBuqPq/VXo7wPZApgeDIKRUAbpNGEw2m5nYsB9r9Kwf O6rpbddcdhUzK17ns5jmEKoD28JwZB2ONzrKXY6XN10dFY2XIa/s48lfZJeFXaICKtX0 fEBMCQv47qv4SHazvM7oUANXT/pMqGf5247ick38zrO8s5lISUVmIDd+6Ec+J2EqBppF WjTdSQ/LQw6jTrddr36hXXBqvmajfwIz0+1G8rusdMdg4ZbHofql3yd2vpNKYZOCus0x 1XKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Eu4Tz2PSHJmrgZ6GXoLAyXHUq4EjuOki9XQQRKCo8U0=; b=lP4cSXE8GwaYuH5/eGVhHI+8+DMtAYeBj8px+CVME8mg5zdPrmXEen4N4Xhsru5XGt KyBYV8JCMF77zRRRmaNm+zHLC746rRgl9xFv8ejWJA1qeXf1iU8bMQNeq9e3isV3rP7e W24vd2myd6AlJ5JIaUpIIDCllcqhTt+u39xRiccus5jkvtGO0OFy3OPPaA92UKkR0q8R 4RnJA6px1/3ifCwH7Smb8ZxprHuYmfZP7fdGZU+m8oPkuZYuVy9QFGSap/G/zdnBNwfV IQRRIRs6k8+T0SfM3CMGoWzVdYzYK32Euf8Z3udETo8IhdqMitnjBqUfxe0/LhQHB1MA 7FGA== X-Gm-Message-State: APjAAAVI8Np7Q9LOAbIQ0/UpW/k8yoRo/pM9GilQJm364d5tC400m1Iz KQ6P03ACtrAdaHdy6+KHbHk= X-Received: by 2002:a63:bc01:: with SMTP id q1mr41620570pge.442.1579184168288; Thu, 16 Jan 2020 06:16:08 -0800 (PST) Received: from localhost.corp.microsoft.com ([167.220.255.5]) by smtp.googlemail.com with ESMTPSA id j7sm27576502pgn.0.2020.01.16.06.16.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 Jan 2020 06:16:07 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, sashal@kernel.org, michael.h.kelley@microsoft.com Cc: Tianyu Lan , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, vkuznets@redhat.com, stable@vger.kernel.org Subject: [PATCH V2] x86/Hyper-V: Balloon up according to request page number Date: Thu, 16 Jan 2020 22:16:00 +0800 Message-Id: <20200116141600.23391-1-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tianyu Lan 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 Signed-off-by: Tianyu Lan --- Change since v2: - Change logic of switching alloc_unit from 2MB to 4KB in the balloon_up() to avoid redundant iteration when handle non-aligned page request. - Remove 2MB alignment operation and comment in balloon_up() --- drivers/hv/hv_balloon.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 7f3e7ab22d5d..536807efbc35 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -1684,7 +1684,7 @@ static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm, 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; @@ -1722,7 +1722,7 @@ static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm, } - return num_pages; + return i * alloc_unit; } static void balloon_up(union dm_msg_info *msg_info) @@ -1737,9 +1737,6 @@ static void balloon_up(union dm_msg_info *msg_info) 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. @@ -1749,14 +1746,13 @@ static void balloon_up(union dm_msg_info *msg_info) 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) { @@ -1770,7 +1766,7 @@ static void balloon_up(union dm_msg_info *msg_info) num_ballooned = alloc_balloon_pages(&dm_device, num_pages, bl_resp, alloc_unit); - if (alloc_unit != 1 && num_ballooned == 0) { + if (alloc_unit != 1 && num_ballooned != num_pages) { alloc_unit = 1; continue; } -- 2.14.5