Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2873384imm; Wed, 16 May 2018 22:39:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoJPBkMqK/2+guT421pu+1VYNUh7DxhbEGbYJ/LP1GNZmYxJSeXV6w1gc/OG8tdpf+G+OYF X-Received: by 2002:a17:902:581:: with SMTP id f1-v6mr3935583plf.48.1526535568495; Wed, 16 May 2018 22:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526535568; cv=none; d=google.com; s=arc-20160816; b=cP2t3ZjmwAgHHaUUDpBDwOcN6Vi2VvQl+4r3vS6U/lQkfAbuIhqyGZTQtxoR/hh4gW 4d9JxqQfAb5YSt19maDEQjOlHMxmosDDOzPq3aAvaqbUMC1IpNiZ8JbUtjBuuCW8HxQa 6+2WR2idgYwdwq7Fw2MJBT5XbmuBWAzx98wMLoNqKV6tjnXfO227xz0JHoQXZx1NEb5R RocwgcfSpUvraBbvdpDQ0s1wmr5t0lmBEQEzQaMsma+0xTb0Qb09l1pCz8zqyXmVK/Vc RcNaDq1wgQ1G1WQN51X6EvCDy3jrKqbLE1pma+0d8p4K1md9zyBbj70/04WD5KsS/fsa NvdA== 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=+fgPnyw3jGLS4Pc2fV68oVK33O4rbV3fsSA7edmBBBE=; b=sAe7VZxqSw7UKoUSyeWgWUDFzXDW7k1bo6gvTk0Jztsw/kVAYSyPAmg03LgwL3LCnM TBkdQB2KNxKrce9XNjFZd5ErYQEW9M7DMD9ZBlywI1vr69xyzpDMfEg4WTPKQLuwfIxO dP+EK/IQ9YRDyweRXH/apyS1uWdRtucr2azRmYd92BtP+jHrrVZXWCjpg4+FuQZrMk+n MZ07OsKIrdKbEyMkvG/weBdjBWpMn7PTUjDhCCVZN83bRI5Nyt03CCIRFI1F9UuODpBx Xz8DSiK8JEWFOPX5e99O3/0kwHXqO/0qtUNcOVAGQLBhso4HX9Nqjx33fGl4F+3x75gD 5AZA== 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 d17-v6si3977305pll.590.2018.05.16.22.39.12; Wed, 16 May 2018 22:39: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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751061AbeEQFjC (ORCPT + 99 others); Thu, 17 May 2018 01:39:02 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35726 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750727AbeEQFjB (ORCPT ); Thu, 17 May 2018 01:39:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 212977A082; Thu, 17 May 2018 05:39:01 +0000 (UTC) Received: from localhost (ovpn-8-20.pek2.redhat.com [10.72.8.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47755100295A; Thu, 17 May 2018 05:38:57 +0000 (UTC) Date: Thu, 17 May 2018 13:38:55 +0800 From: Baoquan He To: linux_dti@icloud.com Cc: linux-kernel@vger.kernel.org, mingo@kernel.org, lcapitulino@redhat.com, keescook@chromium.org, tglx@linutronix.de, x86@kernel.org, hpa@zytor.com, fanc.fnst@cn.fujitsu.com, yasu.isimatu@gmail.com, indou.takao@jp.fujitsu.com, douly.fnst@cn.fujitsu.com Subject: Re: [PATCH 1/2] x86/boot/KASLR: Add two functions for 1GB huge pages handling Message-ID: <20180517053228.GM24627@MiWiFi-R3L-srv> References: <20180516100532.14083-1-bhe@redhat.com> <20180516100532.14083-2-bhe@redhat.com> <20180517051225.GA2361@zrhn9910b> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180517051225.GA2361@zrhn9910b> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 05:39:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 05:39:01 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'bhe@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/17/18 at 07:12am, damian wrote: > On Wed, 16. May 18:05, Baoquan He wrote: > > Functions parse_gb_huge_pages() and process_gb_huge_page() are introduced to > > handle conflict between KASLR and huge pages, will be used in the next patch. > > > > Function parse_gb_huge_pages() is used to parse kernel command-line to get > > how many 1GB huge pages have been specified. A static global variable > > 'max_gb_huge_pages' is added to store the number. > > > > And process_gb_huge_page() is used to skip as many 1GB huge pages as possible > > from the passed in memory region according to the specified number. > > > > Signed-off-by: Baoquan He > > --- > > arch/x86/boot/compressed/kaslr.c | 71 ++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 71 insertions(+) > > > > diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c > > index a0a50b91ecef..13bd879cdc5d 100644 > > --- a/arch/x86/boot/compressed/kaslr.c > > +++ b/arch/x86/boot/compressed/kaslr.c > > @@ -215,6 +215,32 @@ static void mem_avoid_memmap(char *str) > > memmap_too_large = true; > > } > > > > +/* Store the number of 1GB huge pages which user specified.*/ > > +static unsigned long max_gb_huge_pages; > > + > > +static int parse_gb_huge_pages(char *param, char* val) > > +{ > > + char *p; > > + u64 mem_size; > > + static bool gbpage_sz = false; > > + > > + if (!strcmp(param, "hugepagesz")) { > > + p = val; > > + mem_size = memparse(p, &p); > > + if (mem_size == PUD_SIZE) { > > + if (gbpage_sz) > > + warn("Repeadly set hugeTLB page size of 1G!\n"); > > + gbpage_sz = true; > > + } else > > + gbpage_sz = false; > > + } else if (!strcmp(param, "hugepages") && gbpage_sz) { > > + p = val; > > + max_gb_huge_pages = simple_strtoull(p, &p, 0); > > + debug_putaddr(max_gb_huge_pages); > > + } > > +} > Hello, > > the return value is missing for the function or not ? Thanks, very good catch. It should be 'static void ', no return value since we didn't check it. Will update when repost. > > > + > > + > > static int handle_mem_memmap(void) > > { > > char *args = (char *)get_cmd_line_ptr(); > > @@ -466,6 +492,51 @@ static void store_slot_info(struct mem_vector *region, unsigned long image_size) > > } > > } > > > > +/* Skip as many 1GB huge pages as possible in the passed region. */ > > +static void process_gb_huge_page(struct mem_vector *region, unsigned long image_size) > > +{ > > + int i = 0; > > + unsigned long addr, size; > > + struct mem_vector tmp; > > + > > + if (!max_gb_huge_pages) { > > + store_slot_info(region, image_size); > > + return; > > + } > > + > > + addr = ALIGN(region->start, PUD_SIZE); > > + /* If Did we raise the address above the passed in memory entry? */ > > + if (addr < region->start + region->size) > > + size = region->size - (addr - region->start); > > + > > + /* Check how many 1GB huge pages can be filtered out*/ > > + while (size > PUD_SIZE && max_gb_huge_pages) { > > + size -= PUD_SIZE; > > + max_gb_huge_pages--; > > + i++; > > + } > > + > > + if (!i) { > > + store_slot_info(region, image_size); > > + return; > > + } > > + > > + /* Process the remaining regions after filtering out. */ > > + > > + if (addr >= region->start + image_size) { > > + tmp.start = region->start; > > + tmp.size = addr - region->start; > > + store_slot_info(&tmp, image_size); > > + } > > + > > + size = region->size - (addr - region->start) - i * PUD_SIZE; > > + if (size >= image_size) { > > + tmp.start = addr + i*PUD_SIZE; > > + tmp.size = size; > > + store_slot_info(&tmp, image_size); > > + } > > +} > > + > > static unsigned long slots_fetch_random(void) > > { > > unsigned long slot; > > -- > > 2.13.6 > >