Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752771AbdLEIwM (ORCPT ); Tue, 5 Dec 2017 03:52:12 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:51182 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751840AbdLEIwK (ORCPT ); Tue, 5 Dec 2017 03:52:10 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="30725596" From: Chao Fan To: , , , , , , , CC: , , , Chao Fan Subject: [PATCH v3 0/4] kaslr: add new parameter immovable_mem=nn[KMG]@ss[KMG] to make memory hotplug work well with kaslr Date: Tue, 5 Dec 2017 16:51:56 +0800 Message-ID: <20171205085200.9528-1-fanc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 Content-Type: text/plain X-yoursite-MailScanner-ID: DA9FE486A769.AE9C1 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: fanc.fnst@cn.fujitsu.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2876 Lines: 66 Here is a problem: Here is a machine with several NUMA nodes and some of them are hot-pluggable. It's not good for kernel to be extracted in the memory region of movable node. But in current code, I print the address chosen by kaslr and found it may be placed in movable node sometimes. To solve this problem, it's better to limit the memory region chosen by kaslr to immovable node in kaslr.c. But the memory information about if it's hot-pluggable is stored in ACPI SRAT table, which is parsed after kernel is extracted. So we can't get the detail memory information before extracting kernel. So add the new parameter immovable_mem=nn@ss, in which nn means the size of memory in *immovable* node, and ss means the start position of this memory region. Then limit kaslr choose memory in these regions. There are two policies: 1. Specify the memory region in *movable* node to avoid: Then we can use the existing mem_avoid to handle. But if the memory on movable node was separated by memory hole or different movable nodes are discontinuous, we don't know how many regions need to avoid. OTOH, we must avoid all of the movable memory, otherwise, kaslr may choose the wrong place. 2. Specify the memory region in *immovable* node to select: Only support 4 regions in this parameter. Then user can use two nodes at least for kaslr to choose, it's enough for the kernel to extract. At the same time, because we need only 4 new mem_vector, the usage of memory here is not too big. So I think this way is better, and this patchset is based on this policy. PATCH 1/4 parse the new parameter immovable_mem=nn[KMG]@ss[KMG], then store the memory regions. PATCH 2/4 select the memory region in immovable node when process memmap. PATCH 3/4 skip mirror feature if movable_node or immovable_mem specified. PATCH 4/4 add document. v1->v2: Follow Dou Liyang's suggestion: - Add the parse for movable_node=nn[KMG] without @ss[KMG] - Fix the bug for more than one "movable_node=" specified - Drop useless variables and use mem_vector region directely - Add more comments. v2->v3: Follow Baoquan He's suggestion: - Change names of several functions. - Add a new parameter "immovable_mem" instead of extending mvoable_node - Use the clamp to calculate the memory intersecting, which makes logical more clear. - Disable memory mirror if movable_node specified Chao Fan (4): kaslr: add immovable_mem=nn[KMG]@ss[KMG] to specify extracting memory kaslr: calculate the memory region in immovable node kaslr: disable memory mirror feature when movable_node specified document: change the document for immovable_mem Documentation/admin-guide/kernel-parameters.txt | 9 ++ arch/x86/boot/compressed/kaslr.c | 154 +++++++++++++++++++++--- 2 files changed, 147 insertions(+), 16 deletions(-) -- 2.14.3