Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp422162imm; Wed, 11 Jul 2018 05:02:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdFEysqw4iNunuO2gSkHDjhLY4UHdmFLdUy7f24eHvYL5PEP288rv5IkTGqnGf6stOsXaQI X-Received: by 2002:a65:5144:: with SMTP id g4-v6mr26367030pgq.21.1531310548651; Wed, 11 Jul 2018 05:02:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531310548; cv=none; d=google.com; s=arc-20160816; b=dOHX6M4qpVwCUl8eqevQ3Pqbowc7ogOOXt40AlZuciIYA814bD0D6/7GUoIiI3P4X2 QooabPCOLfbkBVs/XhD3ascbbGx6Q2kAO96RYeIEJzr2TQgh+WAw4JV2Pbpm0tzjqLH6 G7FeaI6bpSkHXw6q3eUMkrRmiAryVymxh6Qh/4qBeo1Cws+f18wqkvWmyEl4i1R3dcXF 6lgans8/oqqlz5I9m8qJRw4W52ljG8lto2hMjVXK4RmoLu4LEYv6HyOXw4VBqU2Bj348 eKxvqX9pgYd89rpnWEjGqg0pYn3AOTD6i5f95qZvmkFdhA3Qu3fJpwwTKp4eVV9YHyow JVrQ== 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=AH6CRCvdcbyIBd5BkPG2M/5DX6lQUtJFWfdhv54vv90=; b=gjTCS5I6uCuX8UhFeXGux00pTm0bE7czVUd7w9GAfxitgyfjHlDRag5yvKzm64ExaY wlBUFZ1On5jZhGcsP3DV5W64pTfuj9Jbmw0H1P1rD41OvIQ4oocQwrmaCZ7WfQuhONtE NCezOrDR4fzapGePnzcXOvWkW2Uk7Do2ViovNMfBraWZiTW2RpnPsz5ZoCA415lnAoHR 1Ny8EjxWmgr87fX9V8osyWEWvXTi2XU4CXXeEwL5f0+uCo2fe6dAftSUxJ96DtcNh+cN PoUDicuuHNnJWsxDI1g8YTQJ6vIXjAjuFGZpb+ugO2EwpaUbr2Bloir2hw/BJbEd41PY QUEg== 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 v4-v6si20226853pfk.116.2018.07.11.05.02.13; Wed, 11 Jul 2018 05:02:28 -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 S1726698AbeGKKWL (ORCPT + 99 others); Wed, 11 Jul 2018 06:22:11 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:27934 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726464AbeGKKWK (ORCPT ); Wed, 11 Jul 2018 06:22:10 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="42116184" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 11 Jul 2018 18:18:33 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 18DE74B473E0; Wed, 11 Jul 2018 18:18:33 +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; Wed, 11 Jul 2018 18:18:28 +0800 Date: Wed, 11 Jul 2018 18:16:57 +0800 From: Chao Fan To: , , , CC: , , , , Subject: Re: Bug report about KASLR and ZONE_MOVABLE Message-ID: <20180711101657.GB6742@localhost.localdomain> References: <20180711094244.GA2019@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20180711094244.GA2019@localhost.localdomain> User-Agent: Mutt/1.10.0 (2018-05-17) X-Originating-IP: [10.167.225.56] X-yoursite-MailScanner-ID: 18DE74B473E0.A7629 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: fanc.fnst@cn.fujitsu.com X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org More explanation: If there is a machine with 10 nodes, and memory size in each node is 20G. Then 'kernelcore=100G' will set last 10G memory in each node as ZONE_MOVABLE. But if KASLR put kernel to 19G position of first node, the regions can not be offlined. So we should set the last 1G of first kernel and last 11G as ZONE_MOVABLE of other 9 nodes as ZONE_MOVABLE. Thanks, Chao Fan On Wed, Jul 11, 2018 at 05:42:44PM +0800, Chao Fan wrote: >Hi all, > >I found there is a BUG about KASLR and ZONE_MOVABLE. > >When users use 'kernelcore=' parameter without 'movable_node', >movable memory is evenly distributed to all nodes. The size of >ZONE_MOVABLE depends on the kernel parameter 'kernelcore=' and >'movablecore='. >But sometiomes, KASLR may put the uncompressed kernel to the >tail position of a node, which will cause the kernel memory >set as ZONE_MOVABLE. This region can not be offlined. > >Here is a very simple test in my qemu-kvm machine, there is >only one node: > >The command line: >[root@localhost ~]# cat /proc/cmdline >BOOT_IMAGE=/vmlinuz-4.18.0-rc3+ root=/dev/mapper/fedora_localhost--live-root >ro resume=/dev/mapper/fedora_localhost--live-swap >rd.lvm.lv=fedora_localhost-live/root rd.lvm.lv=fedora_localhost-live/swap >console=ttyS0 earlyprintk=ttyS0,115200n8 memblock=debug kernelcore=50% > >I use 'kernelcore=50%' here. > >Here is my early print result, I print the random_addr after KASLR chooses >physical memory: >early console in extract_kernel >input_data: 0x000000000266b3b1 >input_len: 0x00000000007d8802 >output: 0x0000000001000000 >output_len: 0x0000000001e15698 >kernel_total_size: 0x0000000001a8b000 >trampoline_32bit: 0x000000000009d000 >booted via startup_32() >Physical KASLR using RDRAND RDTSC... >random_addr: 0x000000012f000000 >Virtual KASLR using RDRAND RDTSC... > >The address for kernel is 0x000000012f000000 > >Here is the log of ZONE: >[ 0.000000] Zone ranges: >[ 0.000000] DMA [mem 0x0000000000001000-0x0000000000ffffff] >[ 0.000000] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] >[ 0.000000] Normal [mem 0x0000000100000000-0x00000001f57fffff] >[ 0.000000] Device empty >[ 0.000000] Movable zone start for each node >[ 0.000000] Node 0: 0x000000011b000000 >[ 0.000000] Early memory node ranges >[ 0.000000] node 0: [mem 0x0000000000001000-0x000000000009efff] >[ 0.000000] node 0: [mem 0x0000000000100000-0x00000000bffd6fff] >[ 0.000000] node 0: [mem 0x0000000100000000-0x00000001f57fffff] >[ 0.000000] Initmem setup node 0 [mem >0x0000000000001000-0x00000001f57fffff] > >Only one node in my machine, ZONE_MOVABLE begins from 0x000000011b000000, >which is lower than 0x000000012f000000. >So KASLR put the kernel to the ZONE_MOVABLE. >Try to solve this problem, I think there should be a new tactic in function >find_zone_movable_pfns_for_nodes() of mm/page_alloc.c. If kernel is uncompressed >in a tail position, then just set the memory after the kernel as ZONE_MOVABLE, >at the same time, memory in other nodes will be set as ZONE_MOVABLE. > >If there is something wrong, pleas let me know. And any comments will be welcome. > >Thanks, >Chao Fan