Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2787995imm; Wed, 16 May 2018 20:27:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoPfsmukDqzJRZU5Tvl4a+1ZEUFFlcB5paKTRPcNTHHHjx2W3CraliIvCDbMUUNPEoKgRnI X-Received: by 2002:a17:902:3381:: with SMTP id b1-v6mr3556443plc.248.1526527660713; Wed, 16 May 2018 20:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526527660; cv=none; d=google.com; s=arc-20160816; b=qhItAjeS/D0MOCCpY53U3fxGw6jpkV3/Fju4kJqBFS4861MbofAAeaT810twvba4ge wyoaQg97ynoZywv6ZkRpqfbkNwcm7ex2sO7R1Fp216PHhvVFtCzyOBPHz7f1BHSzV/vl /8dEuj+XR0dqoocollfl8hS0RWaU2sC2mOc18gy55P7SE/bb2TAmevFZWSCaP0HiTo8n KXZ58MSXu7Ov7v4wplIibOUWi0kH3YozjtTuaUFPyqsdchxZowRgqmsEPMyap9vg4ewH 7V2po9wgIgB64bzLKo1mIEoe/6okCEcAnuq+Sclp8Ch9cTGmh7juTrtEzT++7+E76Je4 5oRQ== 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=MmqdEZ5Kdv3/toa5uwidF1ga/2EPDt1HP98Ll0vdvFI=; b=fsrbGp/VsfbFe65S9fA0ymqrEm8DVD7IFH1nD8C/VxSbYWfVBL3nJQAMQQkL+zr8WH dPm/H/0WRpY6zkG8icxxVPEZJEWAsk08gYxIogij3UOBEpj3vhDD/QYXlIBUegN6aoPA yQYrPH7EvIzskazohK8CKL2z6nR2YVRA7RIogAvkjYqf1zCelgLi67m7r6IAazM39b1s c6eCH+Nk7pIM5dln3CWN+XzJd9QbKzCv8IaVmE7uG21HDIJ5vEEjVn5aLmtAOje4weq7 9mB+nx0qa7OIVgmmYmZVlPNFtURiom81KSZJsSWKvgjeQ6qXzfyqLqpU5/b83pRc4CLB TBgg== 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 v16-v6si3983656pfm.151.2018.05.16.20.27.23; Wed, 16 May 2018 20:27:40 -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 S1751619AbeEQD1N (ORCPT + 99 others); Wed, 16 May 2018 23:27:13 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:40684 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751457AbeEQD1M (ORCPT ); Wed, 16 May 2018 23:27:12 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="40023199" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 17 May 2018 11:27:11 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 611814B3EF17; Thu, 17 May 2018 11:27:08 +0800 (CST) Received: from localhost.localdomain (10.167.225.56) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.399.0; Thu, 17 May 2018 11:27:13 +0800 Date: Thu, 17 May 2018 11:27:02 +0800 From: Chao Fan To: Baoquan He CC: , , , , , , , , , Subject: Re: [PATCH 1/2] x86/boot/KASLR: Add two functions for 1GB huge pages handling Message-ID: <20180517032702.GA6521@localhost.localdomain> 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.9.5 (2018-04-13) X-Originating-IP: [10.167.225.56] X-yoursite-MailScanner-ID: 611814B3EF17.A954E X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: fanc.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 Baoquan, I have reviewed the patch, I think the caculation of address has no problem. But maybe I miss something, so I have several questions. On Wed, May 16, 2018 at 06:05:31PM +0800, 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); >+ } >+} >+ >+ > 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--; The global variable 'max_gb_huge_pages' means how many huge pages user specified when you get it from command line. But here, everytime we find a position which is good for huge page allocation, the 'max_gdb_huge_page' decreased. So in my understanding, it is used to store how many huge pages that we still need to search memory for good slots to filter out, right? If it's right, maybe the name 'max_gb_huge_pages' is not very suitable. If my understanding is wrong, please tell me. >+ i++; >+ } >+ >+ if (!i) { >+ store_slot_info(region, image_size); >+ return; >+ } >+ >+ /* Process the remaining regions after filtering out. */ >+ This line may be unusable. >+ 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); >+ } I have another question not related to kaslr. Here you try to avoid the memory from addr to (addr + i * PUD_SIZE), but I wonder if after walking all memory regions, 'max_gb_huge_pages' is still more than 0, which means there isn't enough memory slots for huge page, what will happen? Thanks, Chao Fan >+} >+ > static unsigned long slots_fetch_random(void) > { > unsigned long slot; >-- >2.13.6 > > >