From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752554AbcEAAmq (ORCPT ); Sat, 30 Apr 2016 20:42:46 -0400 Received: from p3plsmtps2ded01.prod.phx3.secureserver.net ([208.109.80.58]:47619 "EHLO p3plsmtps2ded01.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752250AbcEAAmS (ORCPT ); Sat, 30 Apr 2016 20:42:18 -0400 x-originating-ip: 72.167.245.219 From: "K. Y. Srinivasan" To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, jasowang@redhat.com Cc: "K. Y. Srinivasan" Subject: [PATCH RESEND 3/5] Drivers: hv: balloon: don't crash when memory is added in non-sorted order Date: Sat, 30 Apr 2016 19:21:35 -0700 Message-Id: <1462069297-11033-3-git-send-email-kys@microsoft.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1462069297-11033-1-git-send-email-kys@microsoft.com> References: <1462069204-10989-1-git-send-email-kys@microsoft.com> <1462069297-11033-1-git-send-email-kys@microsoft.com> X-CMAE-Envelope: MS4wfMYfEtOgA/YKOPXPu19Oqv3auylr3ocBEEqLKAOS/vUIkj+3iKCMTf3gwrRmpsdPOxhBsZwFfdaz3rP4qz7vIa/qEx7dnlZXXYMXCmMTIMHRPEB75SCD rOBFOLSORRU5MaYBRuEnZJtmPiYrbXdC03sTgdwt2aQOJRoeUBP5RVbzMVeMCE4c3/Rxygpa0Ik8miEl3neXJQMw7YxZevk0BE6gf78Si8MthjGhuzxHRMcz xXVUkl8+BB+YuyUBz2RltjhY0EOqHl8IuDhgKjHDsje/0vg9jfSzjD7WEPXoUbvcro5AJvqxfwQarUpYDV+aKF98z63w0laQsTK28sLo3HSbZlVNDO39Kye8 TU9Qzvip0cpe4aJNM6AtwKSti3THlLVdrvKjeh+O4dyVxMkwbonXKa2EXlixiAJjFK7wcQmk Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vitaly Kuznetsov When we iterate through all HA regions in handle_pg_range() we have an assumption that all these regions are sorted in the list and the 'start_pfn >= has->end_pfn' check is enough to find the proper region. Unfortunately it's not the case with WS2016 where host can hot-add regions in a different order. We end up modifying the wrong HA region and crashing later on pages online. Modify the check to make sure we found the region we were searching for while iterating. Fix the same check in pfn_covered() as well. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan --- drivers/hv/hv_balloon.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index b853b4b..43af913 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -714,7 +714,7 @@ static bool pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt) * If the pfn range we are dealing with is not in the current * "hot add block", move on. */ - if ((start_pfn >= has->end_pfn)) + if (start_pfn < has->start_pfn || start_pfn >= has->end_pfn) continue; /* * If the current hot add-request extends beyond @@ -768,7 +768,7 @@ static unsigned long handle_pg_range(unsigned long pg_start, * If the pfn range we are dealing with is not in the current * "hot add block", move on. */ - if ((start_pfn >= has->end_pfn)) + if (start_pfn < has->start_pfn || start_pfn >= has->end_pfn) continue; old_covered_state = has->covered_end_pfn; -- 1.7.4.1