Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp692341ybp; Fri, 11 Oct 2019 02:50:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgIEu6+E0yMTsAf1dIznZewETtCkWJGPcQgeWG5aJDiWFpSURGQU5KK+2XxFuzuqM8oxrr X-Received: by 2002:a17:906:4d95:: with SMTP id s21mr12711563eju.175.1570787410410; Fri, 11 Oct 2019 02:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570787410; cv=none; d=google.com; s=arc-20160816; b=bKvs4Io65bZezPBUGKEyEWIDj33MbuVTNygYRl16NtftT++cSkXISM5wJy3QzHxgFa UQ7XRXGtQMTt4KP5iD3C6ezMp8B0npvA/H3FUmxhUalKCDHRr5yOB4ZUiM/oQPUWSVd7 wm+73u4xCcsvssa1b2i97Q8GWtF0xx7oO0/qL9dN+qJMCP1jlW6c/t4sU0evJZ9OOSTA 2kFDeBb92wN6sMz5smkJYrvCz7GR7X1Wh1ssefL4eF3eo8fZO21hMYWIxDGd760RJRt8 prNJkKNUYukBpL6Blq2l2JXZ3EjYjDA3hHemoM2sswzSnQEcG0vrbkgAsI1d8Wgl5NqP lZBA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=zYdRWXf1ivTrS8iERqjBRqvGtZhk6TLnTKfc6dMjmDM=; b=uBfUk09Ws4WtjEVTeWG7FPFYjj94dczeHDrFAKPqwQLBAIqldDkZrxENNYkHTQhAIB k4iDdu02af/LvViB1XfkUFlTv/+VDcGR/r8EJfFp/6SB17rHUcbJf8kwG95L/lulIpXp rCESTcaUNkEMrZzjiq3Eb5w0UdfGxieJPltvuFR0nVOLi4E4yQNG5tLyLBwIKdT1YG81 Xvi5YAvRFP3aFlvHZhyNaXVHdekBflcCaBFcyP0z3KaM38LKzgAXL9qdXn6dEutV2xSU 24rcOJXgPVjaI8JzQmVJpi0ZAGUmJhu8QNXDCofmsGJpeqgC9GjBKnWuqrvoHdLayhIC boPQ== ARC-Authentication-Results: i=1; mx.google.com; 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 f21si5024004ejc.159.2019.10.11.02.49.47; Fri, 11 Oct 2019 02:50:10 -0700 (PDT) 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; 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 S1727668AbfJKJtb (ORCPT + 99 others); Fri, 11 Oct 2019 05:49:31 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:56409 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726585AbfJKJtb (ORCPT ); Fri, 11 Oct 2019 05:49:31 -0400 Received: from 79.184.255.36.ipv4.supernova.orange.pl (79.184.255.36) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.292) id 1b220ecebb2d0121; Fri, 11 Oct 2019 11:49:29 +0200 From: "Rafael J. Wysocki" To: Andy Whitcroft Cc: linux-pm@vger.kernel.org, Len Brown , Pavel Machek , Andrea Righi , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] PM / hibernate: memory_bm_find_bit -- tighten node optimisation Date: Fri, 11 Oct 2019 11:49:29 +0200 Message-ID: <2167643.HFCj9E3NaD@kreacher> In-Reply-To: <20190925143912.22593-1-apw@canonical.com> References: <20190925143912.22593-1-apw@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday, September 25, 2019 4:39:12 PM CEST Andy Whitcroft wrote: > 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 > --- > 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 83105874f255..26b9168321e7 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; > Applying as 5.5 material, thanks!