From patchwork Wed Jul 11 12:40:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 10519691 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 DF9FF6028E for ; Wed, 11 Jul 2018 12:40:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C546428CA7 for ; Wed, 11 Jul 2018 12:40:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B950F28E19; Wed, 11 Jul 2018 12:40:21 +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 652CD28CA7 for ; Wed, 11 Jul 2018 12:40:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B51F6B026C; Wed, 11 Jul 2018 08:40:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 664E56B026D; Wed, 11 Jul 2018 08:40:20 -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 57A956B026E; Wed, 11 Jul 2018 08:40:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f199.google.com (mail-qk0-f199.google.com [209.85.220.199]) by kanga.kvack.org (Postfix) with ESMTP id 2D82D6B026C for ; Wed, 11 Jul 2018 08:40:20 -0400 (EDT) Received: by mail-qk0-f199.google.com with SMTP id c27-v6so29160565qkj.3 for ; Wed, 11 Jul 2018 05:40:20 -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=595iEy55U/QI1DHEYIJbmTEMSrWaMmAPZHPXX5797DY=; b=Pe03UaxD6Y09tNmBK3B0MWmhvSu0od5tOJg1c4JgFycVGmqHIihNaqQnj6aAFFz2/A cvPRqpZfk8ibg330wg7IUngCZzi4HIo6ET/otXnOeaNiXdmSevuG0RENTw4scIYiXxLl Fi1dZWMxAGN65znhAPo9gNjQORHYB4C2+F5JyhzVjQFeIBBkdb0ZkIRZVGQdpgYPdkjJ iqxQpONRXHPhfc1i9rr/xiVBTLG+Z088mQ/wkbFvOufPgc2/MmI3APe2rAsz53zNHU6w lm6UhJl6sFoo/Ie5zf291vo6caOEBcQKZz++Y37LHqqvm8PJJZx0FsR6kHNgOcQNG5Vo 4AQA== 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: APt69E33TWZ0eFxnUElDgLMmGwvDdCu68L4EHZZGaMs2P+rOp+HaFpSB Hpwc7RyRkWnWqsEKVpnhEHbKRZTOzboZz7/mz+dr5o8qcAH8pAqmFSkHOXGHBctfsgUl6EbljZS nTdZoz9JYqpD3R5LzIV4958rhrxtFIeYC/LHNKN+tQDFcILtJuJMRg8wRJ7FmBIdQfw== X-Received: by 2002:a37:dd4:: with SMTP id 203-v6mr25949972qkn.14.1531312819920; Wed, 11 Jul 2018 05:40:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdJTLVt3QtcPbvfYpjX6GFUk5U0eUGb7CJhTkciRMqIgSU2zQTp66j0F890IM1HmtVNTlqF X-Received: by 2002:a37:dd4:: with SMTP id 203-v6mr25949576qkn.14.1531312814213; Wed, 11 Jul 2018 05:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531312814; cv=none; d=google.com; s=arc-20160816; b=LwKb2kyPv3/7SdTVtoxqrxC/KEuXemxgq12TCxX2haxt9+GLAWxuHPnfPNMvVJamws DJWJI+UDfG+ZK3vOw06iHNp4JbKo07g6cbGPoImB3tp/QU6sr8uB2nX/1IPZZEL1vaEb AY678/2VG8myQV0Zeoh8VzM6LzmO5T/SmZdHki6Qbbiez/cBPl2jHIvX48XuDY3lMVJI yaHVyz+58dYBpBic0o7jD1P9YZQi3qFATZxAX5llYM5NnLFOnh7u4pj5JcstnW6VfvT1 3/4mxmxAiqfGOeptHTeqhKgGOGeQclqNFiRkh2gaD1huGpGqiyZbFR6llOt2cfGFgDm1 fZ7A== 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=595iEy55U/QI1DHEYIJbmTEMSrWaMmAPZHPXX5797DY=; b=JmamMvcRomiwQqQHK8N89mlPSuHYp6oPHwaKx3BUX3tdIkY4NEumyZXtGEeaOKzWL3 AsaypmcH8D3n9MTjfeicuQpArTEaZCsj4ZUGkFKOnxKE8x10On4r2XVp7F9ybH73fpOx mB87009WiULbQZAQ6gDNakhv1/cyRCz0bC9RreU20zcujXyp2F3xQO3BsSPMtxMtANv9 YGW5hhMXTMzh/SSZyBcD9NXMkYWjtgciZgE/WGjmx5pcmBl0NTTsjWNLQ7duq7l6wtE3 mWCPJh8HgWqwNJvCOtyMjUARr59/AHm6HUam+njl1oExmChe1kemKFHrS1dgXC0xdnlQ z/Pw== 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 t185-v6si5831207qkh.71.2018.07.11.05.40.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 05:40:14 -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-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A96747A7F0; Wed, 11 Jul 2018 12:40:13 +0000 (UTC) Received: from localhost (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7F1322026D6B; Wed, 11 Jul 2018 12:40:12 +0000 (UTC) Date: Wed, 11 Jul 2018 20:40:08 +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: <20180711124008.GF2070@MiWiFi-R3L-srv> References: <20180711094244.GA2019@localhost.localdomain> <20180711104158.GE2070@MiWiFi-R3L-srv> <20180711104944.GG1969@MiWiFi-R3L-srv> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180711104944.GG1969@MiWiFi-R3L-srv> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 11 Jul 2018 12:40:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 11 Jul 2018 12:40:13 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 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; + /* + * 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; } /*