Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754650AbdLFJ2L (ORCPT ); Wed, 6 Dec 2017 04:28:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59354 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754239AbdLFJ2G (ORCPT ); Wed, 6 Dec 2017 04:28:06 -0500 Date: Wed, 6 Dec 2017 17:28:00 +0800 From: Baoquan He To: Kees Cook Cc: Chao Fan , LKML , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , yasu.isimatu@gmail.com, indou.takao@jp.fujitsu.com, caoj.fnst@cn.fujitsu.com, Dou Liyang Subject: Re: [PATCH v3 2/4] kaslr: calculate the memory region in immovable node Message-ID: <20171206092800.GK15074@x1> References: <20171205085200.9528-1-fanc.fnst@cn.fujitsu.com> <20171205085200.9528-3-fanc.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.0 (2016-08-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 06 Dec 2017 09:28:06 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3260 Lines: 94 On 12/05/17 at 11:40am, Kees Cook wrote: > On Tue, Dec 5, 2017 at 12:51 AM, Chao Fan wrote: > > If there is no immovable memory region specified, go on the old code. > > There are several conditons: > > 1. CONFIG_MEMORY_HOTPLUG is not specified to y. > > 2. immovable_mem= is not specified. > > > > Otherwise, calculate the intersecting between memmap entry and > > immovable memory. > > Instead of copy/pasting code between process_efi_entries() and > process_e820_entries(), I'd rather that process_mem_region() is > modified to deal with immovable regions. If put it into process_mem_region(), one level of loop is added. How about changing it like below. If no immovable_mem, just process the region in process_immovable_mem(). This we don't need to touch process_mem_region(). >From 9ae3f5ab0e2f129757495af2412bd52dcf86aa46 Mon Sep 17 00:00:00 2001 From: Baoquan He Date: Wed, 6 Dec 2017 17:24:55 +0800 Subject: [PATCH] KASLR: change code Signed-off-by: Baoquan He --- arch/x86/boot/compressed/kaslr.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index 13d26b859c69..73b1562a7439 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -638,13 +638,23 @@ static bool process_immovable_mem(struct mem_vector region, unsigned long long minimum, unsigned long long image_size) { - int i; + /* If no immovable_mem stored, use region directly */ + if (num_immovable_region == 0) { + process_mem_region(&entry, minimum, image_size); + + if (slot_area_index == MAX_SLOT_AREA) { + debug_putstr("Aborted memmap scan (slot_areas full)!\n"); + return 1; + } + + return 0; + } /* * Walk all immovable regions, and filter the intersection * to process_mem_region. */ - for (i = 0; i < num_immovable_region; i++) { + for (int i = 0; i < num_immovable_region; i++) { struct mem_vector entry; unsigned long long start, end, entry_end; @@ -738,14 +748,7 @@ process_efi_entries(unsigned long minimum, unsigned long image_size) region.start = md->phys_addr; region.size = md->num_pages << EFI_PAGE_SHIFT; - /* If no immovable_mem stored, use region directly */ - if (num_immovable_region == 0) { - process_mem_region(®ion, minimum, image_size); - if (slot_area_index == MAX_SLOT_AREA) { - debug_putstr("Aborted memmap scan (slot_areas full)!\n"); - break; - } - } else if (process_immovable_mem(region, minimum, image_size)) + if (process_immovable_mem(region, minimum, image_size)) break; } return true; @@ -774,14 +777,7 @@ static void process_e820_entries(unsigned long minimum, region.start = entry->addr; region.size = entry->size; - /* If no immovable_mem stored, use region directly */ - if (num_immovable_region == 0) { - process_mem_region(®ion, minimum, image_size); - if (slot_area_index == MAX_SLOT_AREA) { - debug_putstr("Aborted memmap scan (slot_areas full)!\n"); - break; - } - } else if (process_immovable_mem(region, minimum, image_size)) + if (process_immovable_mem(region, minimum, image_size)) break; } } -- 2.5.5