Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1799290pxa; Thu, 6 Aug 2020 16:41:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjxoB1Wc/GeT+NC6JiJFXPJpDNXMzbPfwQHuMB0moj7imV+dGUVrTmrplnjKlB33G0vuW8 X-Received: by 2002:a17:906:7857:: with SMTP id p23mr6715432ejm.260.1596757290592; Thu, 06 Aug 2020 16:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596757290; cv=none; d=google.com; s=arc-20160816; b=W+5ftx/axhP7sso8GDQWMgppxyazsscsSf680mGc4+ib0ccArUPNJ7q46nBggL0dZ/ FiDE7u9JpY69RIVQDLT7wJ35Tr24TsSlo53BmBjcxwJx/E++UhLamwSccY0dxstdQpog k1B63RpBi8etVqM4qyd7eRZN1Zj6QHtcDleXoEZHWmFad/tcEu3wQSu1FtlLBJaXkzoq TPNzjv2WdjwF5b3MGA8+BSqdRw1khcYpnwzupej8r2kuqs3hXp+eF8bjP+8zx6haQGLH yJhjCVOht7iWIZiUpb8ISVkmDfuHN2wJJXHI7UVsjSTf97hu2BZWuPSaGC2DHRNA9EtZ dpbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:dkim-signature :dkim-signature:date; bh=INTq0XLsB267sE8Ey06szv6/TkBzi3zrOmLj6qcppWs=; b=cCalcAsWbzHH5AKVA4BBZGrHV9IrQfc6YQViogW1P+1mJGej/sAC/EaN0iDqVWedAt Rvb53mxLj7+PCZ+eDEve++5ic4hQD9HERiAbM0Yhz74Dw5H2Ha6zCcCbHpuAFTy89emL zTZ1vH+DFK6V6a4TQ3JnLnbzR3QYA98eXhL+1tHZ6n40vf/M4yL8qXQ2tYLzMhCFKdAJ tbDbHBHkKqwG2GjEqTl2QXNLHZe0tYlwh+nJCWoeXMwafNf2pEUqq9VPV49DnFZHhpub 0OOdPGBJa1BNuKneyCxo1Z2jU7Ndq08ngSfNkbf2Xgtf4p7doZb9ZKiIp9B3ihQ4JZER dvhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=v+KIdBQS; dkim=neutral (no key) header.i=@vger.kernel.org; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq22si4036443edb.609.2020.08.06.16.41.07; Thu, 06 Aug 2020 16:41:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=v+KIdBQS; dkim=neutral (no key) header.i=@vger.kernel.org; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727016AbgHFXj5 (ORCPT + 99 others); Thu, 6 Aug 2020 19:39:57 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:60936 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726595AbgHFXi7 (ORCPT ); Thu, 6 Aug 2020 19:38:59 -0400 Date: Thu, 06 Aug 2020 23:38:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1596757137; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=INTq0XLsB267sE8Ey06szv6/TkBzi3zrOmLj6qcppWs=; b=v+KIdBQSCRWqk34IF/6S/HxLXs57UwGXHbH7eeepVMhoWGhBCYGyw+yX5TsrxWZ0CatWLe 7tGOpUw121hSbJr8Rcy1cliemNwqmMqIV/ZLDRtUN49avonGpv+2lCuD24BSGVSIGJpc70 uBLmZQK88tBhRxeEgjujPjihgof/lA9Vrvfl+dGLlk+L8PdR7N8homLaA0e6ehhocYCsx4 lmQvK1RaGN70JSb5x6zmF5NMtSgpcufiBfHA06ZUCo8SRuL5l9mBScVXWFV4bE83lvHG3u g7bMcSt9UWkjaZ1UndvVodQhgq0e92yW15fSpsSBKpvsCi8/gXhABeGr1IJgqQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1596757137; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=INTq0XLsB267sE8Ey06szv6/TkBzi3zrOmLj6qcppWs=; b=orYR0jLZwgAVhC5m4tqayPKUDbHBxAySbdwf0DbuIUErgUo8RnZCcXA7w5CiR0SIKsSZig WB1PCQqm3p0lmmDQ== From: "tip-bot2 for Arvind Sankar" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/kaslr] x86/kaslr: Simplify process_gb_huge_pages() Cc: Arvind Sankar , Ingo Molnar , x86 , LKML In-Reply-To: <20200728225722.67457-13-nivedita@alum.mit.edu> References: <20200728225722.67457-13-nivedita@alum.mit.edu> MIME-Version: 1.0 Message-ID: <159675713636.3192.8550558633124756003.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/kaslr branch of tip: Commit-ID: be9e8d9541a95bdfac1c13d112cc032ea7fc745f Gitweb: https://git.kernel.org/tip/be9e8d9541a95bdfac1c13d112cc032ea7fc745f Author: Arvind Sankar AuthorDate: Tue, 28 Jul 2020 18:57:13 -04:00 Committer: Ingo Molnar CommitterDate: Fri, 31 Jul 2020 11:08:17 +02:00 x86/kaslr: Simplify process_gb_huge_pages() Replace the loop to determine the number of 1Gb pages with arithmetic. Signed-off-by: Arvind Sankar Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20200728225722.67457-13-nivedita@alum.mit.edu --- arch/x86/boot/compressed/kaslr.c | 47 +++++++++++++------------------ 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index 3727e97..00ef84b 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -547,49 +547,44 @@ static void store_slot_info(struct mem_vector *region, unsigned long image_size) static void process_gb_huge_pages(struct mem_vector *region, unsigned long image_size) { - unsigned long addr, size = 0; + unsigned long pud_start, pud_end, gb_huge_pages; struct mem_vector tmp; - int i = 0; if (!IS_ENABLED(CONFIG_X86_64) || !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++; - } + /* Are there any 1GB pages in the region? */ + pud_start = ALIGN(region->start, PUD_SIZE); + pud_end = ALIGN_DOWN(region->start + region->size, PUD_SIZE); /* No good 1GB huge pages found: */ - if (!i) { + if (pud_start >= pud_end) { 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) { + /* Check if the head part of the region is usable. */ + if (pud_start >= region->start + image_size) { tmp.start = region->start; - tmp.size = addr - region->start; + tmp.size = pud_start - 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; + /* Skip the good 1GB pages. */ + gb_huge_pages = (pud_end - pud_start) >> PUD_SHIFT; + if (gb_huge_pages > max_gb_huge_pages) { + pud_end = pud_start + (max_gb_huge_pages << PUD_SHIFT); + max_gb_huge_pages = 0; + } else { + max_gb_huge_pages -= gb_huge_pages; + } + + /* Check if the tail part of the region is usable. */ + if (region->start + region->size >= pud_end + image_size) { + tmp.start = pud_end; + tmp.size = region->start + region->size - pud_end; store_slot_info(&tmp, image_size); } }