From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EC08C282DD for ; Tue, 7 Jan 2020 21:18:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 024112081E for ; Tue, 7 Jan 2020 21:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578431916; bh=AVKSpfvqyb4cVq0WXRc4SdruK0gYvLsJhYeVw4lm340=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=rfTpnoXbeqDUP7n0/2+/KRGnQ4Lkcnmbqz8UirgZS6tdz7QEHd2gkWbtegLxXA78A 2HQm8aycVYNoHoJIwFJoaL59TekuXqCI/jPkoWJgxy0MotSAST7K4sWjpzXAQ4m+U6 LIVPZzo1LbZBipxaJ2bZ9iHc7a57PpC3wnfyipn0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728591AbgAGVFF (ORCPT ); Tue, 7 Jan 2020 16:05:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:50812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729179AbgAGVFF (ORCPT ); Tue, 7 Jan 2020 16:05:05 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 3AC5020880; Tue, 7 Jan 2020 21:05:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578431104; bh=AVKSpfvqyb4cVq0WXRc4SdruK0gYvLsJhYeVw4lm340=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y5y9T3aX0FVM+AUTj6Sj5toV6/qqGs1UHyz8gOzDQwNk3e9vOQYsN7T5FgXwz8YZA KtgcZoDf0X1lDPf6RBCjLTad8VwPtIue9pKSRr189smVZkJz1Y5bgVRVx8uPNYsUgI ZOgzmAMLJBq3cxX6g5I0hxZ6rcbhV5YLqNGP2WqM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrea Righi , Andy Whitcroft , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 4.19 034/115] PM / hibernate: memory_bm_find_bit(): Tighten node optimisation Date: Tue, 7 Jan 2020 21:54:04 +0100 Message-Id: <20200107205301.374584557@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200107205240.283674026@linuxfoundation.org> References: <20200107205240.283674026@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Andy Whitcroft [ Upstream commit da6043fe85eb5ec621e34a92540735dcebbea134 ] When looking for a bit by number we make use of the cached result from the preceding lookup to speed up operation. Firstly we check if the requested pfn is within the cached zone and if not lookup the new zone. We then check if the offset for that pfn falls within the existing cached node. This happens regardless of whether the node is within the zone we are now scanning. With certain memory layouts it is possible for this to false trigger creating a temporary alias for the pfn to a different bit. This leads the hibernation code to free memory which it was never allocated with the expected fallout. Ensure the zone we are scanning matches the cached zone before considering the cached node. Deep thanks go to Andrea for many, many, many hours of hacking and testing that went into cornering this bug. Reported-by: Andrea Righi Tested-by: Andrea Righi Signed-off-by: Andy Whitcroft Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- kernel/power/snapshot.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 3d37c279c090..f2635fc751d9 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -736,8 +736,15 @@ static int memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn, * We have found the zone. Now walk the radix tree to find the leaf node * for our PFN. */ + + /* + * If the zone we wish to scan is the the current zone and the + * pfn falls into the current node then we do not need to walk + * the tree. + */ node = bm->cur.node; - if (((pfn - zone->start_pfn) & ~BM_BLOCK_MASK) == bm->cur.node_pfn) + if (zone == bm->cur.zone && + ((pfn - zone->start_pfn) & ~BM_BLOCK_MASK) == bm->cur.node_pfn) goto node_found; node = zone->rtree; -- 2.20.1