Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp358592imm; Wed, 11 Jul 2018 03:52:09 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcqfy4uKnj8MmqPWyxqnzQ+cUoWJwyBVqPkQvW4j7UzqfDgCPAiVouuokmtELYx0EtdyUHW X-Received: by 2002:a65:5c83:: with SMTP id a3-v6mr26277464pgt.164.1531306329421; Wed, 11 Jul 2018 03:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531306329; cv=none; d=google.com; s=arc-20160816; b=SQEjeJBYby52Zk9oGLUv+L6//EyTJq3SwgvbDDD2qtNnq/lIGG7pmWAaGWAe8ROKXt GcI6j84bOjxO8ypRnnT56s0sm12jSMVz4BCnaKaLYEo3E8q1iGX9hDN2M9ZhJbtAf8GT zHdDZwA7Tatlelh6wu/bviFLvudXC2mYjP5/MvZi0IJo0ZeCAL8d6yp1NxO0O/lbNFCl H2BfxSdSBZHDZVKzELr4okQny16lhsHzFYEUyseANgxgt8zFFIoTmfsoojHDt8pQYAO2 H7Fn+/GmRLo8YfGE+OVq8BzAEHiewACfM6WB4NDWQajdzrdrkRAesaOp4Pz2dZ6NxrtV 5g8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=MHfhWA8wg2MLzJfNsPQhKBRhyPHkvtK5K5rPRrVRNSs=; b=hD8Lc7tT+ruuBcUAncYONo1ZSd6lfHtVqubp18CRP3KS7gjKIUv9bE8yofzc6LK1g/ 7WSeg7lOPTz+OCr3MN/AIvQxXDVEl05x4ePUfCG2GqC1snhaAMfhjp5odo9bV/yR1cVa 0txGpGcaOA+OgHduI0EhZFYfwM2OGIq+eR2zDlUXqk2j2z/Y0KhOXz1PVuZcK21e/sr0 C0/5pwrSQm/pyYHyMqtZbPw1P0n+3pL51WtlHLbqiNw2YLCYk+qcZfjCMFI5uNVsut43 9KloJOk7BiHPfm22KWhRtXBS3pAwS7aw3FVbEr2koGtqvoVWtxM/Qg+xO5iS3QurN4Kh mQYQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8-v6si19425888plm.202.2018.07.11.03.51.54; Wed, 11 Jul 2018 03:52:09 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732486AbeGKKxc (ORCPT + 99 others); Wed, 11 Jul 2018 06:53:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41038 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726487AbeGKKxc (ORCPT ); Wed, 11 Jul 2018 06:53:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C91A401CDA7; Wed, 11 Jul 2018 10:49:47 +0000 (UTC) Received: from localhost (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D90C3213ED6A; Wed, 11 Jul 2018 10:49:46 +0000 (UTC) Date: Wed, 11 Jul 2018 18:49:44 +0800 From: Baoquan He To: Chao Fan , akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, yasu.isimatu@gmail.com, keescook@chromium.org, indou.takao@jp.fujitsu.com, caoj.fnst@cn.fujitsu.com, douly.fnst@cn.fujitsu.com, mhocko@suse.com, vbabka@suse.cz, mgorman@techsingularity.net Subject: Re: Bug report about KASLR and ZONE_MOVABLE Message-ID: <20180711104944.GG1969@MiWiFi-R3L-srv> References: <20180711094244.GA2019@localhost.localdomain> <20180711104158.GE2070@MiWiFi-R3L-srv> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180711104158.GE2070@MiWiFi-R3L-srv> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 11 Jul 2018 10:49:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 11 Jul 2018 10:49:47 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'bhe@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/11/18 at 06:41pm, Baoquan He wrote: > Hmm, it's an issue, worth fixing it. Otherwise the size of > movable area will be smaller than we expect when add "kernel_core=" > or "movable_core=". > > Add a check in find_zone_movable_pfns_for_nodes(), and use min() to get > the starting address of movable area between aligned '_etext' > and start_pfn. It will go to label 'restart' to calculate the 2nd round > if not satisfiled. > > Hi Chao, > > Could you check if below patch works for you? > > > From ab6e47c6a78d1a4ccb577b995b7b386f3149732f Mon Sep 17 00:00:00 2001 > From: Baoquan He > Date: Wed, 11 Jul 2018 18:30:04 +0800 > Subject: [PATCH] mm, page_alloc: find movable zone after kernel text > > In find_zone_movable_pfns_for_nodes(), when try to find the starting > PFN movable zone begins in each node, kernel text position is not > considered. KASLR may put kernel after which movable zone begins. > > Fix it by finding movable zone after kernel text. > > Signed-off-by: Baoquan He > --- > mm/page_alloc.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 1521100..fe346b4 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -6678,6 +6678,8 @@ static void __init find_zone_movable_pfns_for_nodes(void) > unsigned long size_pages; > > start_pfn = max(start_pfn, zone_movable_pfn[nid]); > + /* KASLR may put kernel after 'start_pfn', start after kernel */ > + start_pfn = max(start_pfn, PAGE_ALIGN(_etext)); Sorry, I used wrong function. Please try this one: From 005435407a331ecf2803e5ebfdc44b8f5f8f9748 Mon Sep 17 00:00:00 2001 From: Baoquan He Date: Wed, 11 Jul 2018 18:30:04 +0800 Subject: [PATCH v2] mm, page_alloc: find movable zone after kernel text In find_zone_movable_pfns_for_nodes(), when try to find the starting PFN movable zone begins in each node, kernel text position is not considered. KASLR may put kernel after which movable zone begins. Fix it by finding movable zone after kernel text. Signed-off-by: Baoquan He --- mm/page_alloc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 1521100..17584cc 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6678,6 +6678,8 @@ static void __init find_zone_movable_pfns_for_nodes(void) unsigned long size_pages; start_pfn = max(start_pfn, zone_movable_pfn[nid]); + /* KASLR may put kernel after 'start_pfn', start after kernel */ + start_pfn = max(start_pfn, PFN_UP(_etext)); if (start_pfn >= end_pfn) continue; -- 2.1.0