From patchwork Thu Jul 12 01:19:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Fan X-Patchwork-Id: 10520771 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 037CA603D7 for ; Thu, 12 Jul 2018 01:22:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF46E2942A for ; Thu, 12 Jul 2018 01:22:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D339229430; Thu, 12 Jul 2018 01:22:42 +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=unavailable 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 651E529433 for ; Thu, 12 Jul 2018 01:22:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 628136B0003; Wed, 11 Jul 2018 21:22:41 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5AF216B0006; Wed, 11 Jul 2018 21:22:41 -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 451C16B0007; Wed, 11 Jul 2018 21:22:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f71.google.com (mail-oi0-f71.google.com [209.85.218.71]) by kanga.kvack.org (Postfix) with ESMTP id 16A8C6B0003 for ; Wed, 11 Jul 2018 21:22:41 -0400 (EDT) Received: by mail-oi0-f71.google.com with SMTP id r186-v6so37636390oie.16 for ; Wed, 11 Jul 2018 18:22:41 -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=in5MCASlk9xeI/nMwtGcywbmvnuWcvrHalEnCruoyj8=; b=b9MnnDOa0nVtl0fw1auvVVf7EbR9etzqJtbeS3mNN93cfCn65+3e9xsi7Nt+EK0c4x iabJuWxQnhoZ7VgCO3Ovx/nOPpx8ZhGUmoPzFpG9UbXjyo79AeapvJQ0BGKCEVvFXsCS JU1JuchhBFRdOVlUQnOfYUiocAjcjuNDkeus7npDDAbmEFhgNh8MBaIPo3ioDZJLDemh lEn/SLL94VW3/Uq3ErNmYlgAdYjh3Ip4T/RCQP1HlUo2Nj2FvlpLxQaNY1EIyibq8Zvc 1g0dkBQjPBNpG5PK0JTUyTBEZxzsu0YGZ7dHE2YqN8hgGLcnzg9YX5JS0wcQ77D+lXRQ oRng== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of fanc.fnst@cn.fujitsu.com designates 183.91.158.132 as permitted sender) smtp.mailfrom=fanc.fnst@cn.fujitsu.com X-Gm-Message-State: AOUpUlH5pnKk5mBAiNZy0NdUDVy9nrrQqJijj37g24FApkDq+Yypustd CAgWoUE9myAG0Gpp4udsUjzsBiRRdek9vGFvhaM2xlJPLgFjb1+d2uRf36CBPwhNv8Sr/NWRKHq Z1nWW1KqcNTuwDAX57t6180JJFU7Fi4QFEcqZwiHwLXeKzchOPIxl3HiUYFMeIHFvqg== X-Received: by 2002:aca:c585:: with SMTP id v127-v6mr223139oif.348.1531358560851; Wed, 11 Jul 2018 18:22:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdzj75qnGj6k/iONzl8uksLRG3iTwijZoRrfbUzyG7t+zvXi9elyiEOf2SXHWDaIfPFZopj X-Received: by 2002:aca:c585:: with SMTP id v127-v6mr223055oif.348.1531358559304; Wed, 11 Jul 2018 18:22:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531358559; cv=none; d=google.com; s=arc-20160816; b=E5i41H1JWJeB4iK1ZfoX95qZxQohQR4c1PyR9ZhSmpwU41LX/52/WtSxdNkb6LBPnL 4+FiMoR/QMCdLVL3Z/gdeCGJU05agF25IS59fNkJ2gnd+LxN8Z5a4FozvFK+ViH9bpAu MAwaDRFpcdjPDyq37N05ntUmNSgN9pDxD2lW8yHpID2q2s+1i765A6LBCjk1QrDWpeqO ZBnVQq8l8Z5GNNrXlBO2rMJAHSqGtOF8FqKHmeg99mQ65aq6JWJAQe6ZQSwzbvwpgsxr SiZjaWDgy14RaHVh73HgSQBkFHCKvTkvyHD3VG8XVEn+U1SpOwykIWqYIwwPYPWd7PQv 2OAw== 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=in5MCASlk9xeI/nMwtGcywbmvnuWcvrHalEnCruoyj8=; b=Lq7kyH92RPlE2b2Z5/vkQ1IOoFiVKFHsKx2ZNac05naS8akVXe+2xWE3Mvbd6l+VZn HmmITBBccNxNz8U4dGUfxBYOViPU1UCDOkTyB98eme8reed7PKsVNtq2VHUGYSSfeilj qVDuyr+cnMMQI5enSfnJk6JhGHHDMDe/YsTwbDToO6dy4KVJq59SbDh7XB6NavXaPfTC +0sKwagBJPmx/u9zmUS/KKZkgOng1cw7kBt1DTybGhqS9fsNRj8vhhFX/4LHDy0DkU7C feBrFJTo8ccFd39LY5M65MG98ZyWdP+0OKI5s7k45WG6+ODboMAbLGbE1AklcQujbm2Z hdcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of fanc.fnst@cn.fujitsu.com designates 183.91.158.132 as permitted sender) smtp.mailfrom=fanc.fnst@cn.fujitsu.com Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com. [183.91.158.132]) by mx.google.com with ESMTP id e194-v6si13224808oic.415.2018.07.11.18.22.37 for ; Wed, 11 Jul 2018 18:22:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of fanc.fnst@cn.fujitsu.com designates 183.91.158.132 as permitted sender) client-ip=183.91.158.132; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of fanc.fnst@cn.fujitsu.com designates 183.91.158.132 as permitted sender) smtp.mailfrom=fanc.fnst@cn.fujitsu.com X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="42141154" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 Jul 2018 09:21:38 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 50C0E4B43D51; Thu, 12 Jul 2018 09:21:32 +0800 (CST) Received: from localhost.localdomain (10.167.225.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.399.0; Thu, 12 Jul 2018 09:21:37 +0800 Date: Thu, 12 Jul 2018 09:19:54 +0800 From: Chao Fan To: Baoquan He CC: , , , , , , , , , , , , Subject: Re: Bug report about KASLR and ZONE_MOVABLE Message-ID: <20180712011954.GC6742@localhost.localdomain> References: <20180711094244.GA2019@localhost.localdomain> <20180711104158.GE2070@MiWiFi-R3L-srv> <20180711104944.GG1969@MiWiFi-R3L-srv> <20180711124008.GF2070@MiWiFi-R3L-srv> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180711124008.GF2070@MiWiFi-R3L-srv> User-Agent: Mutt/1.10.0 (2018-05-17) X-Originating-IP: [10.167.225.56] X-yoursite-MailScanner-ID: 50C0E4B43D51.AB2E5 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: fanc.fnst@cn.fujitsu.com 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 Wed, Jul 11, 2018 at 08:40:08PM +0800, Baoquan He wrote: >Please try this v3 patch: > >From 9850d3de9c02e570dc7572069a9749a8add4c4c7 Mon Sep 17 00:00:00 2001 >From: Baoquan He >Date: Wed, 11 Jul 2018 20:31:51 +0800 >Subject: [PATCH v3] 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 on that node. > >Signed-off-by: Baoquan He >--- > mm/page_alloc.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > >diff --git a/mm/page_alloc.c b/mm/page_alloc.c >index 1521100..390eb35 100644 >--- a/mm/page_alloc.c >+++ b/mm/page_alloc.c >@@ -6547,7 +6547,7 @@ static unsigned long __init early_calculate_totalpages(void) > static void __init find_zone_movable_pfns_for_nodes(void) > { > int i, nid; >- unsigned long usable_startpfn; >+ unsigned long usable_startpfn, real_startpfn; > unsigned long kernelcore_node, kernelcore_remaining; > /* save the state before borrow the nodemask */ > nodemask_t saved_node_state = node_states[N_MEMORY]; >@@ -6681,10 +6681,20 @@ static void __init find_zone_movable_pfns_for_nodes(void) > if (start_pfn >= end_pfn) > continue; Hi Baoquan, Thanks for your quick reply and PATCH. I think it can work well after reviewing the code. But I think the new variable 'real_startpfn' is unnecessary. How about this: I think the logic of these two method are the same, and this method change less code. If I am wrong, please let me know. Thanks, Chao Fan > >+ /* >+ * KASLR may put kernel near tail of node memory, >+ * start after kernel on that node to find PFN >+ * which zone begins. >+ */ >+ if (pfn_to_nid(PFN_UP(_etext)) == i) >+ real_startpfn = max(usable_startpfn, >+ PFN_UP(_etext)) >+ else >+ real_startpfn = usable_startpfn; > /* Account for what is only usable for kernelcore */ >- if (start_pfn < usable_startpfn) { >+ if (start_pfn < real_startpfn) { > unsigned long kernel_pages; >- kernel_pages = min(end_pfn, usable_startpfn) >+ kernel_pages = min(end_pfn, real_startpfn) > - start_pfn; > > kernelcore_remaining -= min(kernel_pages, >@@ -6693,7 +6703,7 @@ static void __init find_zone_movable_pfns_for_nodes(void) > required_kernelcore); > > /* Continue if range is now fully accounted */ >- if (end_pfn <= usable_startpfn) { >+ if (end_pfn <= real_startpfn) { > > /* > * Push zone_movable_pfn to the end so >@@ -6704,7 +6714,7 @@ static void __init find_zone_movable_pfns_for_nodes(void) > zone_movable_pfn[nid] = end_pfn; > continue; > } >- start_pfn = usable_startpfn; >+ start_pfn = real_startpfn; > } > > /* >-- >2.1.0 > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 6d00f746c2fd..0fc9c4283947 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6492,6 +6492,10 @@ static void __init find_zone_movable_pfns_for_nodes(void) if (start_pfn >= end_pfn) continue; + if (pfn_to_nid(PFN_UP(_etext)) == i) + usable_startpfn = max(usable_startpfn, + PFN_UP(_etext)); + /* Account for what is only usable for kernelcore */ if (start_pfn < usable_startpfn) { unsigned long kernel_pages;