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=-4.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 9C517C4338F for ; Wed, 11 Aug 2021 10:11:20 +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 58C7A601FD for ; Wed, 11 Aug 2021 10:11:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 58C7A601FD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com 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=RVJtswcnbsfu/rvMocm0u0e5ZhMgxRoidzYkhVV3AtM=; b=ZdJ4RKNadxKkZi dwyOACAzq4aCZO9jXCrAcu+UYf0E1xl2Gy9CFRgtKsHB4p+dCxrfD3jF+t0IK/lwIcRBFz+n3XnxA /RsWQV7hptxAPjJu+TEQbIBFC5sx+vtZDbvmQVSNWu7OuH/gA5Bv4hgvj1DKo7MGEzm5BDMN/sC61 aZLpal2L9Z7pXVEezsrftabzBTtJq98WaL3C2vInQmuMQwOKElKHytzT9WI56AQ7yOXPhvK3Jr2HH j/HWyg2C8IgQ8X8cXlqPa7mXAfisoz7xIW2hAR6ShK9r4s1++qR9nrLj1cIQA5OnMiwTgAquiueyI rOcsajBFr5IyXxs1lHrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mDlBJ-006YNb-64; Wed, 11 Aug 2021 10:09:53 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mDlBB-006YME-C6 for linux-arm-kernel@lists.infradead.org; Wed, 11 Aug 2021 10:09:47 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CF217106F; Wed, 11 Aug 2021 03:09:43 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.41.79]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4AD2E3F70D; Wed, 11 Aug 2021 03:09:42 -0700 (PDT) Date: Wed, 11 Aug 2021 11:09:31 +0100 From: Mark Rutland To: Will Deacon 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] arm64: head: avoid over-mapping in map_memory Message-ID: <20210811100905.GA72303@C02TD0UTHF1T.local> References: <20210810152756.23903-1-mark.rutland@arm.com> <20210811094457.GA4426@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210811094457.GA4426@willie-the-truck> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210811_030945_523205_C0A2BD62 X-CRM114-Status: GOOD ( 26.37 ) 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 Wed, Aug 11, 2021 at 10:44:58AM +0100, Will Deacon wrote: > Hi Mark, > > On Tue, Aug 10, 2021 at 04:27:56PM +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. > > > > Fix this by subtracting one from the end address in both cases, such > > that we always use inclusive bounds. For clarity, comments are updated > > to more clearly document that the macros expect inclusive bounds. > > I think the comments are already clear for populate_entries and map_memory, > so just adding something to compute_indices should suffice. As-is, your > patch leaves populate_entries inconsistent with the others. Sorry, I'd left that in a separate patch that also renamed index/eindex to istart/iend for consistency with compute_indices. I should have folded that change in. > That aside, I don't think any amount of comments will help because it's > just plain weird for vend to be inclusive for map_memory, no? I guess; I have no strong feeling either way. > Given that both (all) callers got this wrong, I'd be inclined to say > that map_memory should take an exclusive 'vend' as you'd normally > expect and it can adjust it before using the helper macros (which > should perhaps have 'inclusive' in their names). Sure, I'm also happy with that. > Although we currently preserve 'vend' in map_memory, that doesn't > appear to be necessary so we can just move it to the list of clobbers > in the comment nobody reads. Works for me. Thanks, Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel