Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1624526imm; Wed, 1 Aug 2018 20:48:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfmJO40S6nJULd2DeflWstowX6Yo5C+cZm6XKTmvPYM2jwI4jQ8G0sm+9GtZWr6vA/4S1ye X-Received: by 2002:a17:902:b205:: with SMTP id t5-v6mr871440plr.220.1533181705820; Wed, 01 Aug 2018 20:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533181705; cv=none; d=google.com; s=arc-20160816; b=IMdXQoSJpE+mHl3Qk/Z9WW4aHXXmDHqanpp3wkBHREc32LU6NV+aVPzmCRWm0QW/2L JAjEzNRqQ6C7M6f5i7Vfsyv1hZFLyq3szFdGR2DKgrlBEttaoykdQhE32LZwm9ScfLem ODyzv05Ap6BY1sMmGNOIDmxBQ0JZeQQRAq7rtXKrUmLIONdn1Tn1PBcmH4uUKpHUwM+C sBxd1BqgU0AburJjy443zfyyWI2lwg5JokibtHIV0fPKL9Z2v+LBmHrK+S4tsTVavBhc uyLlGmzKJlkUoAPTIWy+ctoTRqzvjykVHJhiktGO9gv9rpMHLb21l60YhLWKwbgz6NI4 W4wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=Ay/34j7xTtuG/OSyJYjdp91GC6jjDBXF/JSOrXvskEQ=; b=acWALqWcBqDepFmMr04eWRvOLUwDcyQRCQl3dgXMc5IASqipDjDIsiuTb8r3gYMCzP iRErIksO6Uj9koRXZdhvBHOtzlOBTR7W34Nq+r2rl9q8RvvIeSZYobaFCaEkttnSgVIF zHC4b+DVKUMXOViDra4rzAejIzuzipl8sB7x86H20vX1/IRRFRjzYbEp/JCdNz8AGhfw ob47Jx5FPc3kIwlE5M92eMqFGCl5C93JvZfJN8eenHJPdKyoEMqbLRThphpwLvHm0yTl uRFFk9DQyZqIrusUGT3fUyVXjB6Evnn4Ryr5heZcKe2ofHrpvqMYdSWe8sf0YCbAbns9 /RVg== 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 87-v6si877710pfi.60.2018.08.01.20.48.10; Wed, 01 Aug 2018 20:48:25 -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 S1726631AbeHBFg0 (ORCPT + 99 others); Thu, 2 Aug 2018 01:36:26 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:5043 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726042AbeHBFgZ (ORCPT ); Thu, 2 Aug 2018 01:36:25 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="42966782" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 02 Aug 2018 11:47:16 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id D3ABA4B6ADE1; Thu, 2 Aug 2018 11:47:14 +0800 (CST) Received: from localhost.localdomain (10.167.226.106) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.399.0; Thu, 2 Aug 2018 11:47:16 +0800 Subject: Re: [PATCH v4 3/4] x86/boot/KASLR: Walk srat tables to filter immovable memory To: Chao Fan , , , , , , , , CC: , References: <20180723092908.32656-1-fanc.fnst@cn.fujitsu.com> <20180723092908.32656-4-fanc.fnst@cn.fujitsu.com> From: Dou Liyang Message-ID: <18d27595-43d8-d2a0-bfdf-bd731b77d1b9@cn.fujitsu.com> Date: Thu, 2 Aug 2018 11:47:13 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20180723092908.32656-4-fanc.fnst@cn.fujitsu.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.167.226.106] X-yoursite-MailScanner-ID: D3ABA4B6ADE1.AE3B9 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: douly.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 Hi Fan, At 07/23/2018 05:29 PM, Chao Fan wrote: > If 'CONFIG_MEMORY_HOTREMOVE' specified, walk the acpi srat memory > tables, store the immovable memory regions, so that kaslr can get > the information abouth where can be selected or not. > If 'CONFIG_MEMORY_HOTREMOVE' not specified, go on the old code. > > Signed-off-by: Chao Fan > --- > arch/x86/boot/compressed/kaslr.c | 55 ++++++++++++++++++++++++++++++++ > 1 file changed, 55 insertions(+) > > diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c > index 531c9876f573..4705682caf1f 100644 > --- a/arch/x86/boot/compressed/kaslr.c > +++ b/arch/x86/boot/compressed/kaslr.c > @@ -31,6 +31,7 @@ > > #include "misc.h" > #include "error.h" > +#include "acpitb.h" > #include "../string.h" > > #include > @@ -104,6 +105,14 @@ static bool memmap_too_large; > /* Store memory limit specified by "mem=nn[KMG]" or "memmap=nn[KMG]" */ > unsigned long long mem_limit = ULLONG_MAX; > > +#ifdef CONFIG_MEMORY_HOTREMOVE > +/* Store the immovable memory regions */ > +struct mem_vector immovable_mem[]; > + > +/* Store the amount of immovable memory regions */ > +static int num_immovable_mem; > +#endif > + > > enum mem_avoid_index { > MEM_AVOID_ZO_RANGE = 0, > @@ -298,6 +307,47 @@ static int handle_mem_options(void) > return 0; > } > > +#ifdef CONFIG_MEMORY_HOTREMOVE > +/* > + * According to ACPI table, filter the immvoable memory regions > + * and store them in immovable_mem[]. > + */ > +static void handle_immovable_mem(void) > +{ > + struct acpi_table_header *table_header; > + struct acpi_subtable_header *table; > + struct acpi_srat_mem_affinity *ma; > + unsigned long table_size; > + unsigned long table_end; > + int i = 0; > + > + table_header = get_acpi_srat_table(); > + > + if (!table_header) > + return; > + > + table_end = (unsigned long)table_header + table_header->length; > + > + table = (struct acpi_subtable_header *) > + ((unsigned long)table_header + sizeof(struct acpi_table_srat)); > + > + table_size = sizeof(struct acpi_subtable_header); table_size isn't used, can be remove. > + while (((unsigned long)table) + table->length < table_end) { > + if (table->type == 1) { > + ma = (struct acpi_srat_mem_affinity *)table; > + if (!(ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)) { > + immovable_mem[i].start = ma->base_address; > + immovable_mem[i].size = ma->length; > + i++; need a check(i < MAX_NUMNODES*2) before doing that in case of __IndexOutOfBoundsException__ even if it may be impossible in ACPI. Thanks, dou > + } > + } > + table = (struct acpi_subtable_header *) > + ((unsigned long)table + table->length); > + } > + num_immovable_mem = i; > +} > +#endif > + > /* > * In theory, KASLR can put the kernel anywhere in the range of [16M, 64T). > * The mem_avoid array is used to store the ranges that need to be avoided > @@ -421,6 +471,11 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size, > /* Mark the memmap regions we need to avoid */ > handle_mem_options(); > > +#ifdef CONFIG_MEMORY_HOTREMOVE > + /* Mark the immovable regions we need to choose */ > + handle_immovable_mem(); > +#endif > + > #ifdef CONFIG_X86_VERBOSE_BOOTUP > /* Make sure video RAM can be used. */ > add_identity_map(0, PMD_SIZE); >