From patchwork Wed Jul 11 10:49:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 10519313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9746B6028E for ; Wed, 11 Jul 2018 10:49:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 782D0288A2 for ; Wed, 11 Jul 2018 10:49:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A62428CA7; Wed, 11 Jul 2018 10:49:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF96528938 for ; Wed, 11 Jul 2018 10:49:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 163596B026B; Wed, 11 Jul 2018 06:49:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0EC926B026C; Wed, 11 Jul 2018 06:49:49 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF75D6B026D; Wed, 11 Jul 2018 06:49:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f197.google.com (mail-qk0-f197.google.com [209.85.220.197]) by kanga.kvack.org (Postfix) with ESMTP id C54A46B026B for ; Wed, 11 Jul 2018 06:49:48 -0400 (EDT) Received: by mail-qk0-f197.google.com with SMTP id b185-v6so30689121qkg.19 for ; Wed, 11 Jul 2018 03:49:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:message-id:references:mime-version:content-disposition :in-reply-to:user-agent; bh=MHfhWA8wg2MLzJfNsPQhKBRhyPHkvtK5K5rPRrVRNSs=; b=jbqDQfvhhV5A7fFkXLnuFXzsaX4SGyysD4lABmTBrth6eyuxyAosykxpVdxsV1ReYd 8Kj1LKtAAGJ5i2RbwB/e4b6smAWyeL2Ib4MZi9XozNpSl2Dt1BruVuPwYlhhOP27NLkh z8G+ncnLpT/k2AxdwHmWPagPXrNpxPm4IPv7e81AtPUgw3WS2I5UrkmYXbMk/4FsTKCy TIHRBdskTogBqnlr3ysHZjqsrR6zqHFG1ZHedZ1ogF8LEKGU1ivH8Lxh977cOZ3HTDsb nNpZcfUfO6y9M04fBh2vwbxHydQaIc3xeHqxpjoFRxOytYaV7lrw70LyEnTP0EaJ5r65 xH3w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of bhe@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APt69E0txvKZJgp9yNDaLSmEzwCNwb/LfLwlFHkyC0xyss1SmsollvBr sr+j3/Orz4/+R51maZQ5hM14rh2h82yDYwZHfoKitnU/bI3SXxexk/gG7m/bt3u3dDSFbG34/z6 0cg1+3smy79giT5u6ZEDcNzWg/IPoFHsVySmknE52gm4QGRW1sD/Hm8sIZ4txMyaumA== X-Received: by 2002:a37:1f53:: with SMTP id f80-v6mr24132085qkf.1.1531306188616; Wed, 11 Jul 2018 03:49:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdTJdElpuzzyauWoEB3ahARD7cx17VbwLooEgfT3swzihf8CI0zZHn3mpXRKxKw1ZTwvqKW X-Received: by 2002:a37:1f53:: with SMTP id f80-v6mr24132067qkf.1.1531306188115; Wed, 11 Jul 2018 03:49:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531306188; cv=none; d=google.com; s=arc-20160816; b=l9xBlmmKEgpVCmFnbIF9OzL9EWLoxqJWstXhWgbKYYVnGdLe4Slw+7A8hJSg4EcjLD 5WfNmHx1DR/rjSXJ54Q+FoM2bUZW1KY1KXmxUr1LjTMNB/VbqOhDBM4pFzUyrOC4IMZ7 1ki27iubWL++WRyyUv7cM+qI0ckWyUjXD9Lr4iaNs9ibfSbiJRLVqf6S1XAUovhLNu87 yihxUkhpyPf3vHtsLGZ4CEwjft/2WsJzIWB4x8coPgk1r5/r07Fv6PU1dZRVSrZCACQB tq6K3XKFHm/tO4bznj/k+ELXEEy3TmMr/qZahPZexXQDDF9Bixsh6EfT1pjL+cx4yjSH /e4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:arc-authentication-results; bh=MHfhWA8wg2MLzJfNsPQhKBRhyPHkvtK5K5rPRrVRNSs=; b=cYEkE2JXjqJTUEoQU1aevxue/6mgCbelqC9DlKqJWMYVZivOfGBggVczWu/LEyx8dH iFPlzpLVE98ql7/P0+hWnAu7d48gEGkOpxFcxUVFaBah+URrTom9yv5L0xLAigtXdHkB K1F4Pc61zhRsN+4Qew5Go0RLfcBwuZKpZlUi+Ka6hcV/VnwWgrv+XPDkOr2opNERFGTz X5yJjsQRJa8XM+m5hm+t4zHYIOwVHs7wB9NXlUpJgCMSg0GxtcDoVbQhWtKXqo1c1yze m55Qrc4/Hu6kw3pyCaQ7J6EajQvsWFbgMYUnXehp/QZiUwDV6srkQ7Sff2qjKiXcsSb1 5QMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of bhe@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id j23-v6si18580514qtj.7.2018.07.11.03.49.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 03:49:48 -0700 (PDT) Received-SPF: pass (google.com: domain of bhe@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of bhe@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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-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:'' X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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;