Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp20006ybl; Tue, 7 Jan 2020 13:15:38 -0800 (PST) X-Google-Smtp-Source: APXvYqwWKZNIJdtsbE0sR0uUPVI83YDgooBvoqi9bCA5mRY8B9Kpa901BhXj4aA+P0lT6Pzw3oDQ X-Received: by 2002:aca:1a06:: with SMTP id a6mr343237oia.148.1578431738473; Tue, 07 Jan 2020 13:15:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578431738; cv=none; d=google.com; s=arc-20160816; b=xrbg3x4dPY7JXn8hcJcGIUZgzNG+4h8mKsjHoRRmoYRtmAYeCVBz/IhV/0GsfMDiR5 LIcNmKab0c7Hqon2WovedP8u7OYFSE3H2j6VM+y5DxWUsmJjJHsEE2zwvXtgKinXM8BO 4bwwRQAIlrxq+0OIbJJlt8CSWRsZfwYWI+eduRwGAUHLPAQCXV2/ZG1QjeT8e9soDH3a NDXuWYEl+eOWVsloFQkB4f28ZezC0pKOexNPGD6Q4+lPwG83tzYen5K6D2fDNy+yngsb thf721pbCy7xjotZEzO5Ek0KTrEFOMYzK6AleJyOis0M/Aigk93WW+95UsJDcZoIhPtA BdNw== 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=z+M2gAltS7gwZ+JAplghIxakAxEHKjjn/xY5iWd5BVU=; b=FgkBzGpCoR22Y35hHb5ZU0F14cu2g43e6S+onQiO8Y5F+lYbweeoBcOR97qvb/LPMt nUavN6vxcOUJmcuCdJjIFIUmsK9v/4V0+1zOT2lSHK6xCOS4uONVLaftSbKfwdus2mot nYZSa7Nqz9wfHO2uSM4TqUX0sX6n9mTVxSolFF6kbowFUBO7Ka4hOITLoQyfw8noADjQ Ev4LfqHnv8dCm4i97hwB9TQw6a6bN2sKrJR/xsgZUWDAGD2iBaOw5Or+dnze70bAS1yD v+tJegvWppcbeezG1fUUH7x8HlWEPPcBjrrpXxXcsTibXGpz7VMGvmjL9EWuW2QJWWOg c8yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dI5chXwr; 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 v6si609142ota.19.2020.01.07.13.15.24; Tue, 07 Jan 2020 13:15:38 -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=dI5chXwr; 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 S1730078AbgAGVOo (ORCPT + 99 others); Tue, 7 Jan 2020 16:14:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:34080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729782AbgAGVJG (ORCPT ); Tue, 7 Jan 2020 16:09:06 -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 B2B572077B; Tue, 7 Jan 2020 21:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578431345; bh=PzOiKsjF1/umswGqVpZDzDrBAh8I1IAG4egqRoftmpc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dI5chXwr3JsE1n4OYWl64VrmI+BtlS41iLREMjPoikPOoZSU+29bZNEvJOiYltCP+ h5TKhcFZGFOGsw4kiTcUw+6XhLg34FYfSujHC8epcqoOTaEyv5rrnu1r5Nl0a3AoMC W2E0P4qjCsrp0NWFXHgcVHBhqoAyRNV4x+JFiG4w= 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.14 19/74] PM / hibernate: memory_bm_find_bit(): Tighten node optimisation Date: Tue, 7 Jan 2020 21:54:44 +0100 Message-Id: <20200107205148.756441076@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200107205135.369001641@linuxfoundation.org> References: <20200107205135.369001641@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: 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 0972a8e09d08..ff2aabb70de9 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -734,8 +734,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