Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1798772pxa; Thu, 6 Aug 2020 16:40:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQkUS362OntyO0X3oQbOTM6WXmgxtT0HAZaH8i/dqFR7yjNj6gyOkgmaKwgJBQ4SZP/jti X-Received: by 2002:a17:906:6bc9:: with SMTP id t9mr6552531ejs.372.1596757234313; Thu, 06 Aug 2020 16:40:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596757234; cv=none; d=google.com; s=arc-20160816; b=mf7k97cOUs6ugejdj8gt4QSctU/xQpNlMtLQsnCZtvl5t68yICGCxPz0LzvvL8YU52 cbwCc+LID483xWOcEeFZ/SsHHMt6ccSfWki7B0PhfWuRSq+SK0jk5MOu1RDlgIBbZa50 InJMR9dPJcf/lpmvQJg8+cPJSmCKhDEj+WyM8uVOYqmXdNb3+jFQ6MOLwGvbV3gU+ZIq 9aTAX5o73/FoLlY9JcpVqsHxi4s8CrCj0rDhOg1iWsTlWZ1UV/GjrA4hxdB2Tqu0pxiY f497tEJStMGrrQpkUQouGapWIDKeh0YV90Nha3UhthlamIsGUoplI71lMwKh3rP9bkC5 ZXnA== 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=l4S3pVhMKh2t0G9uw4IYK8KX+fkH+eaym+tHkM+R+FA=; b=ecy+qFvRMDbzaeCczBRJgt4POUy1kSWBBjd9gIrmPvMCFHpHM7WuuwWHvKk8zmzPm9 lMyglxI/FqVK/I8bHke2x3vQzd/18Le/E3pFMxifctxYAk2ftz9L9Vuas0w10rWNBWIm XsKN5EAB1VtXMZt6PgVpD8SIvHb0F2sp7G9FcM63MZUe21iMSOZo2JFuBA5vuh8RmuwO lSmQXGdZNbh0S01BZkiigqWL+iZrk/ifRMa1xacRVeplQGXom5OK+xnhXsB/11oBhd9T 9nqay40s1ByNpZBQ7lkhoS5qQvlHiOBTOPwcPGwv0S/Qtvr83ez/8bNteQYzNnwsk/qL EKCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=aU09s6H9; dkim=neutral (no key) header.i=@vger.kernel.org header.s=2020e; 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 q19si4111230eja.613.2020.08.06.16.40.11; Thu, 06 Aug 2020 16:40:34 -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=aU09s6H9; dkim=neutral (no key) header.i=@vger.kernel.org header.s=2020e; 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 S1726826AbgHFXjN (ORCPT + 99 others); Thu, 6 Aug 2020 19:39:13 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:60972 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726615AbgHFXjA (ORCPT ); Thu, 6 Aug 2020 19:39:00 -0400 Date: Thu, 06 Aug 2020 23:38:58 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1596757138; 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=l4S3pVhMKh2t0G9uw4IYK8KX+fkH+eaym+tHkM+R+FA=; b=aU09s6H9NvZ/+JZOi7zcmRhOkZraNuGzvZF0ZJzjBkV4v8tOZDMUxiHpjn6zajEnYDQCEA +oDiq+jSSqCaIaDqD4v7t40i8essFlgdo5Tozyif//nSn594jrKD3oT2517RVaRlQwFzp7 EHY2ujcntNJFYYZzQJNwSYc+12yDHbulb1QGGK7OzThL0TlIkQMgUXnJ1vzC2N9z1BzoBH CUbg54DKYt3mHx+zNBCF9l0BR4OQ16lXEZtEdanz+73KlCfmg+mVRxxQ3rx+ujNTnzVCdk Ui5t2b0cGUS6SFJ3ChzH1Wdev4qFF7hdtw3Ga32gexZz0jiRB4HILT4W1w7ZVQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1596757138; 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=l4S3pVhMKh2t0G9uw4IYK8KX+fkH+eaym+tHkM+R+FA=; b=7dQBnQcW4XCUYMP4v0jwK0F56nfaplP+qeBwi7MPemX/0nVpKdcf4nPNkEth0gqQvj6R1K rMBjJQraivjHp1DQ== 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: Drop some redundant checks from __process_mem_region() Cc: Arvind Sankar , Ingo Molnar , x86 , LKML In-Reply-To: <20200728225722.67457-10-nivedita@alum.mit.edu> References: <20200728225722.67457-10-nivedita@alum.mit.edu> MIME-Version: 1.0 Message-ID: <159675713825.3192.5330235874355690213.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: bf457be1548eee6d106daf9604e029b36fed2b11 Gitweb: https://git.kernel.org/tip/bf457be1548eee6d106daf9604e029b36fed2b11 Author: Arvind Sankar AuthorDate: Tue, 28 Jul 2020 18:57:10 -04:00 Committer: Ingo Molnar CommitterDate: Fri, 31 Jul 2020 11:08:17 +02:00 x86/kaslr: Drop some redundant checks from __process_mem_region() Clip the start and end of the region to minimum and mem_limit prior to the loop. region.start can only increase during the loop, so raising it to minimum before the loop is enough. A region that becomes empty due to this will get checked in the first iteration of the loop. Drop the check for overlap extending beyond the end of the region. This will get checked in the next loop iteration anyway. Rename end to region_end for symmetry with region.start. Signed-off-by: Arvind Sankar Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20200728225722.67457-10-nivedita@alum.mit.edu --- arch/x86/boot/compressed/kaslr.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index 8cc47fa..d074986 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -623,34 +623,23 @@ static void __process_mem_region(struct mem_vector *entry, unsigned long image_size) { struct mem_vector region, overlap; - unsigned long end; + unsigned long region_end; - /* Ignore entries entirely below our minimum. */ - if (entry->start + entry->size < minimum) - return; - - /* Ignore entries above memory limit */ - end = min(entry->size + entry->start, mem_limit); - if (entry->start >= end) - return; - - region.start = entry->start; + /* Enforce minimum and memory limit. */ + region.start = max_t(unsigned long long, entry->start, minimum); + region_end = min(entry->start + entry->size, mem_limit); /* Give up if slot area array is full. */ while (slot_area_index < MAX_SLOT_AREA) { - /* Potentially raise address to minimum location. */ - if (region.start < minimum) - region.start = minimum; - /* Potentially raise address to meet alignment needs. */ region.start = ALIGN(region.start, CONFIG_PHYSICAL_ALIGN); /* Did we raise the address above the passed in memory entry? */ - if (region.start > end) + if (region.start > region_end) return; /* Reduce size by any delta from the original address. */ - region.size = end - region.start; + region.size = region_end - region.start; /* Return if region can't contain decompressed kernel */ if (region.size < image_size) @@ -668,10 +657,6 @@ static void __process_mem_region(struct mem_vector *entry, process_gb_huge_pages(®ion, image_size); } - /* Return if overlap extends to or past end of region. */ - if (overlap.start + overlap.size >= region.start + region.size) - return; - /* Clip off the overlapping region and start over. */ region.start = overlap.start + overlap.size; }