Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2855553imm; Wed, 16 May 2018 22:13:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr60AriX/prwXeS9ccU3RyWdNscmjZfHeGaDWmOuGG6MbgEdtkklOlvvJ7F0bdV35zE30RH X-Received: by 2002:a17:902:6006:: with SMTP id r6-v6mr3753025plj.70.1526533982267; Wed, 16 May 2018 22:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526533982; cv=none; d=google.com; s=arc-20160816; b=h4D8VwaWpUzgjLsekE/qWWrUtQ7NQatycQtJ+sd4oHOMdk9YqKr0Xzvf7eya+iDU5T V0oqRJpQyzbcG4dfkcEO9R7T6sPmiNvi7ZTU0NHw/lbfkiE9LTKWo55rfk3RaSHibf7b 6WtEvcgVkKaF1kCSwJlmJIpJ42wN2XhJV+fo9v3OSwPr6yoCgYTXq1Dj61ERJ11lJN86 t9pTs1SY6eqQj212S/WOrVmciYI6z+oyB7jjug6yaNwHDpNl3tTCeAJa1CokZVLnufol d4eursyuYws4lriMgx6h6rQvm9J6Z6hApnHtiiPCQoqYLX1xU+rEEiM1mTmAq2BieAok XXrg== 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:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=LrFX3EfpanpcvpTCxwv23JlvauqGkdN2aN+BWyxOaRI=; b=YY+mNq2rBSaz8nkBuwi1ZifVO+aR5CpV8ojoQBeruo5k7Y1/aNHCwuEhoKt5USeknx GMSxcsJrePylEYqzzddxQjrX9+lMSbRRqpZcparqfF0g+QGb00wtKdXzuZ1QmZMLaGhP IparBGt47bwazL8FHPRpatoUcUu+0Nol9JX38IiMyfKHACHcTcTdi5s2vNnLBs7gTB6f rmvxmaik+i25b7k3UqKoZvJhz1G5ychd9oKJ3F33P014qjDp8zuNNPLpsbxs3RsM4a/m Da1btxCJolk17sn4wH4w2rOsjYwTDPlYwQ/OWwUEWRsUtTOm9Ya7aD1V0brZPdMHTs51 Wt4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@icloud.com header.s=04042017 header.b=MB7wVMt/; 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=pass (p=NONE sp=NONE dis=NONE) header.from=icloud.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1-v6si4212170plb.8.2018.05.16.22.12.47; Wed, 16 May 2018 22:13:02 -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; dkim=pass header.i=@icloud.com header.s=04042017 header.b=MB7wVMt/; 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=pass (p=NONE sp=NONE dis=NONE) header.from=icloud.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751395AbeEQFMh (ORCPT + 99 others); Thu, 17 May 2018 01:12:37 -0400 Received: from ms11p00im-qufv17100601.me.com ([17.58.37.33]:34786 "EHLO ms11p00im-qufv17100601.me.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750727AbeEQFMg (ORCPT ); Thu, 17 May 2018 01:12:36 -0400 Received: from process-dkim-sign-daemon.ms11p00im-qufv17100601.me.com by ms11p00im-qufv17100601.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) id <0P8U00N00SAXOJ00@ms11p00im-qufv17100601.me.com> for linux-kernel@vger.kernel.org; Thu, 17 May 2018 05:12:35 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=04042017; t=1526533955; bh=LrFX3EfpanpcvpTCxwv23JlvauqGkdN2aN+BWyxOaRI=; h=Date:From:To:Subject:Message-id:MIME-version:Content-type; b=MB7wVMt/TynSdUXFyDEkoNLa3W1+p6Gx4FvSo6oOJKu5tgNyyGAfTNnpBoRIrRfaO Q+qDbC7P3Vkwupw1eUouFliYfBYf8KPFdqpwRqC1Dk5pk+W3x7OBbwZ5xtthXp4jrS RKVUSwp10YSSyI5ZQv0OcEWTpwXMWW0iN/0UfK+RQmcqYIrkDK1/sS9V1IHP4TR5F1 hJSNvZelwBDMpO+ZwOPHtDiagw4eOLu/59MDIA7MqSadVsjY0cUyj2Sg9qS13cSgC8 PwgYqsenV09eg0shL/rHKm0clUck9LMW402gFGrPnhVVFm1XepXBUFd6P5VprnODL1 xEcnAmhzU4Yvw== Received: from icloud.com ([127.0.0.1]) by ms11p00im-qufv17100601.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) with ESMTPSA id <0P8U003MAX4Q3W10@ms11p00im-qufv17100601.me.com>; Thu, 17 May 2018 05:12:34 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-05-17_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1011 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1805170049 Date: Thu, 17 May 2018 07:12:26 +0200 From: damian To: Baoquan He 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: <20180517051225.GA2361@zrhn9910b> Mail-followup-to: Baoquan He , 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 References: <20180516100532.14083-1-bhe@redhat.com> <20180516100532.14083-2-bhe@redhat.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-disposition: inline In-reply-to: <20180516100532.14083-2-bhe@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ? regards Damian > + > + > 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 >