Received: by 10.223.176.46 with SMTP id f43csp357565wra; Thu, 18 Jan 2018 18:39:57 -0800 (PST) X-Google-Smtp-Source: ACJfBossW5NIxXsD8ba9TGSDIyJDCMr+ydnt81livDkEPdcgcOU4SrtAUk8aMXBCQyV5yZpmAOBm X-Received: by 10.99.123.91 with SMTP id k27mr27671821pgn.179.1516329596996; Thu, 18 Jan 2018 18:39:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516329596; cv=none; d=google.com; s=arc-20160816; b=ZW5nptNvtYk3RK1iaAXXWXdQ8QYSSmU2prQoKSP59hFbGf3tm1HpaIUk/v5O9hcR9A 0fL/Sf7Vme0LcWVWG7L2kQZvpE++uH/hDbqk+Yb8A0yB4dTXU7dY0Uf9+r7ozwj23rh4 eimJnxBsXW+ZuJOs8zdJ+AORzASq4WxzvfpQxMcFmn6oxrbubbL3H3jy0zOAWWHtl582 OjwysHW8+6nmIAo2UZVH78vxRFuZLBcxRMR0slBelIL9GtzygDa3IkpG7Diqnyyw+tAo mc6XdMshnbGqqzwivixCcZODcnaoXRWXWkx2EQ/A2wnLHADkWPnUv5uUNCfxkk4cn0Tl QMMQ== 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=+Ab7uSXqi8Z9ZcyWnyQ7rAIvoobPQmcVxNs5I7CdwI0=; b=EDbxPSOax/fr/hPHnUG4mVSlX477u/hNwZjC3oV9r/g+9Tr4+SSY2Y+DUE+Y9ode2h 3ywLkPw+Qee0XvrD2Ws13vHXiktovgz9gjTum3CRHvEeMrpcF8tInUFlqcGwUz2jqBLr a924Wo3gLZ4wC63AeBxRfGi0hufxBU3nNrG2pMOcHIq7LeZWKHUMpLQS2fswHDCRbXky pW5Cz9vdyv6OlrrZc2deKdUGe6iQLCqOfDF+JUGttV1fFgQkuLSAWRusZeGLT73lP4HV 5ZeGLmxD3DxzZm2OsU3dLJf8Q6lhojE9BBh1jkv1RY7lGZ8tTlBt8jHFRQY5lyXD7CKx CT0Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9-v6si431494pln.716.2018.01.18.18.39.42; Thu, 18 Jan 2018 18:39:56 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755122AbeASCjN (ORCPT + 99 others); Thu, 18 Jan 2018 21:39:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39828 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752855AbeASCjI (ORCPT ); Thu, 18 Jan 2018 21:39:08 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 868B58046E; Fri, 19 Jan 2018 02:39:08 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C927F600C0; Fri, 19 Jan 2018 02:39:05 +0000 (UTC) Date: Fri, 19 Jan 2018 10:39:03 +0800 From: Baoquan He To: Chao Fan Cc: linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, tglx@linutronix.de, mingo@redhat.com, keescook@chromium.org, yasu.isimatu@gmail.com, indou.takao@jp.fujitsu.com, lcapitulino@redhat.com Subject: Re: [PATCH v7 2/5] x86/KASLR: Handle the memory regions specified in kaslr_mem Message-ID: <20180119023903.GB1753@localhost.localdomain> References: <20180117105351.12226-1-fanc.fnst@cn.fujitsu.com> <20180117105351.12226-3-fanc.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180117105351.12226-3-fanc.fnst@cn.fujitsu.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 19 Jan 2018 02:39:08 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/17/18 at 06:53pm, Chao Fan wrote: > If no 'kaslr_mem=' specified, just handle the e820/efi entries directly > as before. Otherwise, limit kernel to memory regions specified in > 'kaslr_mem=' commandline. > > Rename process_mem_region to slots_count to match > slots_fetch_random, and name new function as process_mem_region. > > Signed-off-by: Chao Fan > --- > arch/x86/boot/compressed/kaslr.c | 64 +++++++++++++++++++++++++++++++++------- > 1 file changed, 53 insertions(+), 11 deletions(-) > > diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c > index b21741135673..b200a7ceafc1 100644 > --- a/arch/x86/boot/compressed/kaslr.c > +++ b/arch/x86/boot/compressed/kaslr.c > @@ -548,9 +548,9 @@ static unsigned long slots_fetch_random(void) > return 0; > } Looks good, ack. Acked-by: Baoquan He > > -static void process_mem_region(struct mem_vector *entry, > - unsigned long minimum, > - unsigned long image_size) > +static void slots_count(struct mem_vector *entry, > + unsigned long minimum, > + unsigned long image_size) > { > struct mem_vector region, overlap; > struct slot_area slot_area; > @@ -627,6 +627,52 @@ static void process_mem_region(struct mem_vector *entry, > } > } > > +static bool process_mem_region(struct mem_vector region, > + unsigned long long minimum, > + unsigned long long image_size) > +{ > + /* > + * If kaslr_mem= specified, walk all the regions, and > + * filter the intersection to slots_count. > + */ > + if (num_usable_region > 0) { > + int i; > + > + for (i = 0; i < num_usable_region; i++) { > + struct mem_vector entry; > + unsigned long long start, end, entry_end, region_end; > + > + start = mem_usable[i].start; > + end = start + mem_usable[i].size; > + region_end = region.start + region.size; > + > + entry.start = clamp(region.start, start, end); > + entry_end = clamp(region_end, start, end); > + > + if (entry.start < entry_end) { > + entry.size = entry_end - entry.start; > + slots_count(&entry, minimum, image_size); > + } > + > + if (slot_area_index == MAX_SLOT_AREA) { > + debug_putstr("Aborted e820/efi memmap scan (slot_areas full)!\n"); > + return 1; > + } > + } > + return 0; > + } > + > + /* > + * If no kaslr_mem stored, use region directly > + */ > + slots_count(®ion, minimum, image_size); > + if (slot_area_index == MAX_SLOT_AREA) { > + debug_putstr("Aborted e820/efi memmap scan (slot_areas full)!\n"); > + return 1; > + } > + return 0; > +} > + > #ifdef CONFIG_EFI > /* > * Returns true if mirror region found (and must have been processed > @@ -692,11 +738,9 @@ process_efi_entries(unsigned long minimum, unsigned long image_size) > > region.start = md->phys_addr; > region.size = md->num_pages << EFI_PAGE_SHIFT; > - process_mem_region(®ion, minimum, image_size); > - if (slot_area_index == MAX_SLOT_AREA) { > - debug_putstr("Aborted EFI scan (slot_areas full)!\n"); > + > + if (process_mem_region(region, minimum, image_size)) > break; > - } > } > return true; > } > @@ -723,11 +767,9 @@ static void process_e820_entries(unsigned long minimum, > continue; > region.start = entry->addr; > region.size = entry->size; > - process_mem_region(®ion, minimum, image_size); > - if (slot_area_index == MAX_SLOT_AREA) { > - debug_putstr("Aborted e820 scan (slot_areas full)!\n"); > + > + if (process_mem_region(region, minimum, image_size)) > break; > - } > } > } > > -- > 2.14.3 > > >