Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1311466imm; Tue, 3 Jul 2018 08:59:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLT2rnMFn1zXki6sHgZv152pHgxwBSMB6RdAbrqznecHqr4kEKjhtN7PaZdLhuPwhZSjqoN X-Received: by 2002:a63:82c7:: with SMTP id w190-v6mr26134674pgd.253.1530633589545; Tue, 03 Jul 2018 08:59:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530633589; cv=none; d=google.com; s=arc-20160816; b=oaxbSBoKt8lNxU4rNrJlOyZLqhy7c1k6jTvFLfmLsHwItSnOIYluJ/klQvuh7E/Xyp HbJlNXl3yvkh00G7hCsGbO1Ei6cHcT+ydxeK3MuekB47EMwUt6OdyMXbwMBnLsXJ9xbu WUlHmc//0u0Pqg+HRwrV3LljGzr5TQW/RHRroX2UiCmIsWRFFooXar4aS0NoIDzDbSHa sOzpQxldZqN+BsubuvPoSLzINq77E9nj17r/ga5b/XMgucTe3cjR6lW1/DHKzzeYJcDs nEJDE1b8sPgxhSXnfbGcUWCFnsLlLxsRkTKnt5lzBPbQAggKWKjXF3EkMAfYbIXkhCQd g/Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=7Pzy4oAxNV3zWEiICGd7WSq8LgGp6xb3QcgwrCQlzPI=; b=bCMirqssSd/RB/eMDuWMZS9fdmEU1EdwCJRxqwZmAo5ei/ldVJLzJSj+BQu5KwIZjQ guxdMbCqtJzcWh1oqJLR53bRKBE+OQnUB/6XMPqP3WYdh2MQzFn48hwOFCtOpNgfWo9t Lod+JU3eIJDmXfEr+p6cFfgvfoDZUonfaNUrcf5GGkqJ56vZRoXP8RUjopqNWB04giMN fMzj5rpuh/e+als4at+MGvDIJuMpEFoI/0VUjWryClcQcgO0m5cadS7NDF6SExWmmR8B IhuLhIvBnKeIiqh1Br1hc1MLWNxzTW0Zpbjh0rJv1lFiPMG/oJ47IXqR2YYKMQA6uePY zqfA== 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 c17-v6si1206173pgu.583.2018.07.03.08.59.34; Tue, 03 Jul 2018 08:59:49 -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 S932771AbeGCP6m (ORCPT + 99 others); Tue, 3 Jul 2018 11:58:42 -0400 Received: from terminus.zytor.com ([198.137.202.136]:55449 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752905AbeGCP6k (ORCPT ); Tue, 3 Jul 2018 11:58:40 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w63Fw3fX338376 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 3 Jul 2018 08:58:03 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w63Fw37i338373; Tue, 3 Jul 2018 08:58:03 -0700 Date: Tue, 3 Jul 2018 08:58:03 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Baoquan He Message-ID: Cc: tglx@linutronix.de, mingo@kernel.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, hpa@zytor.com, bhe@redhat.com, peterz@infradead.org Reply-To: hpa@zytor.com, bhe@redhat.com, tglx@linutronix.de, mingo@kernel.org, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, peterz@infradead.org In-Reply-To: <20180625031656.12443-2-bhe@redhat.com> References: <20180625031656.12443-2-bhe@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/boot] x86/boot/KASLR: Add two new functions for 1GB huge pages handling Git-Commit-ID: 9b912485e0e74a74e042e4f2dd87f262e46fcdf1 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 9b912485e0e74a74e042e4f2dd87f262e46fcdf1 Gitweb: https://git.kernel.org/tip/9b912485e0e74a74e042e4f2dd87f262e46fcdf1 Author: Baoquan He AuthorDate: Mon, 25 Jun 2018 11:16:55 +0800 Committer: Ingo Molnar CommitDate: Tue, 3 Jul 2018 10:50:12 +0200 x86/boot/KASLR: Add two new functions for 1GB huge pages handling Introduce two new functions: parse_gb_huge_pages() and process_gb_huge_pages(), which handle a conflict between KASLR and huge pages of 1GB. These two functions will be used in the next patch: - 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. - process_gb_huge_pages() 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 Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: douly.fnst@cn.fujitsu.com Cc: fanc.fnst@cn.fujitsu.com Cc: indou.takao@jp.fujitsu.com Cc: keescook@chromium.org Cc: lcapitulino@redhat.com Cc: yasu.isimatu@gmail.com Link: http://lkml.kernel.org/r/20180625031656.12443-2-bhe@redhat.com Signed-off-by: Ingo Molnar --- arch/x86/boot/compressed/kaslr.c | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index b87a7582853d..d97647b5ffb7 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -215,6 +215,35 @@ static void mem_avoid_memmap(char *str) memmap_too_large = true; } +/* Store the number of 1GB huge pages which users specified: */ +static unsigned long max_gb_huge_pages; + +static void parse_gb_huge_pages(char *param, char *val) +{ + static bool gbpage_sz; + char *p; + + if (!strcmp(param, "hugepagesz")) { + p = val; + if (memparse(p, &p) != PUD_SIZE) { + gbpage_sz = false; + return; + } + + if (gbpage_sz) + warn("Repeatedly set hugeTLB page size of 1G!\n"); + gbpage_sz = true; + return; + } + + if (!strcmp(param, "hugepages") && gbpage_sz) { + p = val; + max_gb_huge_pages = simple_strtoull(p, &p, 0); + return; + } +} + + static int handle_mem_memmap(void) { char *args = (char *)get_cmd_line_ptr(); @@ -466,6 +495,60 @@ 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 + * according to the number which users specified: + */ +static void +process_gb_huge_pages(struct mem_vector *region, unsigned long image_size) +{ + unsigned long addr, size = 0; + struct mem_vector tmp; + int i = 0; + + if (!max_gb_huge_pages) { + store_slot_info(region, image_size); + return; + } + + addr = ALIGN(region->start, PUD_SIZE); + /* 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++; + } + + /* No good 1GB huge pages found: */ + if (!i) { + store_slot_info(region, image_size); + return; + } + + /* + * Skip those 'i'*1GB good huge pages, and continue checking and + * processing the remaining head or tail part of the passed region + * if available. + */ + + 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;