From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 932B2C4338F for ; Tue, 24 Aug 2021 10:44:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 51F9F60FD7 for ; Tue, 24 Aug 2021 10:44:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 51F9F60FD7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lAo2S1Az9qKSOUY8rmbEFCfT5NOXnoGEZZcjUtMHvTg=; b=1eTcgh7zVOaVe9 Cvd9BLLaMPumJRqvXwc+vyuIHkQ4s1GTq+cQUL8rk6idrfnMk0jIY6vVayLFIYvWlwvuHpNBcbby8 flcnjvEZrzBgoEWr4/YdD3bnbM5m5CQ3b9gPRkmfWDhZMmfQwsM3ylme/sNQhaYfaYdTEXAd8dY5S GXyHc8s2bLU6C2+4f+Waebeug/GQl3qaXmc5ku+/1eYYvEo2mFsko/fDvbqlaraG0aOFY44xOi3NM i7813TI8mh5IY2At9ttXESIciGcEe3PUG865XC13cefcv0i528zx+mMpQNgHNJG+0JSHRESVj+wdd /+35LGjE3PODmfNDGeGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mITtE-002ZI4-RQ; Tue, 24 Aug 2021 10:42:44 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mITtB-002ZHL-2R for linux-arm-kernel@lists.infradead.org; Tue, 24 Aug 2021 10:42:42 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0769E60FD7; Tue, 24 Aug 2021 10:42:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629801760; bh=dzMalCfJkDrJCdi0pNqtJZyBVDdJx8O7iegTeoa0P0c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JlW/hlG7tJeOnsCyxLZmJz+tPIjRceK2YW9PaiWxqdfTcmg7nLrmfRh+sL2E7o0lp 44DVRmHX/hs3WbWrJDjJ28vkQ292tm/j2iXohY/oQQpSqDn6bKD7SSOgtbUJ3ft7vP c5QNkzeR1wQxzdNjkrSYNl+w4HQ/Zu4rAIHAVzTptBBADfuknVozmvbQwk+jpGUlPa Oj9Gn8f12lBXA6an1pwnzPhjEA5adYJV5gq0XoF4FcpoSt8rZo+F5sF4drHbBQnptv r+WvvLlnLY578WQqG2m2pK6gBnAdO0i199OmUuQdd02d+xVgTxVXHzoa3m0UEIThh9 jf3P8lQVKpSQw== Date: Tue, 24 Aug 2021 11:42:35 +0100 From: Will Deacon To: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, anshuman.khandual@arm.com, ard.biesheuvel@linaro.org, catalin.marinas@arm.com, steve.capper@arm.com Subject: Re: [PATCH v2] arm64: head: avoid over-mapping in map_memory Message-ID: <20210824104234.GA22752@willie-the-truck> References: <20210823101253.55567-1-mark.rutland@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210823101253.55567-1-mark.rutland@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210824_034241_177237_5B619D2A X-CRM114-Status: GOOD ( 21.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Aug 23, 2021 at 11:12:53AM +0100, Mark Rutland wrote: > The `compute_indices` and `populate_entries` macros operate on inclusive > bounds, and thus the `map_memory` macro which uses them also operates > on inclusive bounds. > > We pass `_end` and `_idmap_text_end` to `map_memory`, but these are > exclusive bounds, and if one of these is sufficiently aligned (as a > result of kernel configuration, physical placement, and KASLR), then: > > * In `compute_indices`, the computed `iend` will be in the page/block *after* > the final byte of the intended mapping. > > * In `populate_entries`, an unnecessary entry will be created at the end > of each level of table. At the leaf level, this entry will map up to > SWAPPER_BLOCK_SIZE bytes of physical addresses that we did not intend > to map. > > As we may map up to SWAPPER_BLOCK_SIZE bytes more than intended, we may > violate the boot protocol and map physical address past the 2MiB-aligned > end address we are permitted to map. As we map these with Normal memory > attributes, this may result in further problems depending on what these > physical addresses correspond to. > > The final entry at each level may require an additional table at that > level. As EARLY_ENTRIES() calculates an inclusive bound, we allocate > enough memory for this. > > Avoid the extraneous mapping by having map_memory convert the exclusive > end address to an inclusive end address by subtracting one, and do > likewise in EARLY_ENTRIES() when calculating the number of required > tables. For clarity, comments are updated to more clearly document which > boundaries the macros operate on. For consistency with the other > macros, the comments in map_memory are also updated to describe `vstart` > and `vend` as virtual addresses. > > Fixes: 0370b31e48454d8c ("arm64: Extend early page table code to allow for larger kernel") > Signed-off-by: Mark Rutland > Cc: Anshuman Khandual > Cc: Ard Biesheuvel > Cc: Catalin Marinas > Cc: Steve Capper > Cc: Will Deacon > --- > arch/arm64/include/asm/kernel-pgtable.h | 4 ++-- > arch/arm64/kernel/head.S | 11 ++++++----- > 2 files changed, 8 insertions(+), 7 deletions(-) Acked-by: Will Deacon Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel