From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54C9938D400; Fri, 29 May 2026 08:28:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780043321; cv=none; b=ehoQjjmffWo0Kw9kIl/vBMUdM/beVjPwANWSKkMvQD2uHy+4VZcrbKwuhlF8ACkNZ6qSt/L8GGfrUnzVaR+1bQwSgmyII1DJHXsSY3kx/aQ2y0LvmmQdXc8kE9N6c6+7DF/RnnFz8oXTTDyn2m1V5UWunHuyrS5QO0FI6hsRP+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780043321; c=relaxed/simple; bh=HxDE/v275kzieWm+smiZqa4yjNgD7FuY1p40zCPFJh8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UtPiEe0Wfn9qboK7iNm8pdql3luZWgIKjalrTVzRkmC7g3aIqhqHkzIBSIgvp1uuD8vRmLyo9U4RY4Yo0XjVN1jphR6OOFhlhMfACaZK/EwydpYoIO6AuIZURUXnm5YFaSMtn0dZWgSv7pCWyeWdu9wh8OnMcvYSf94oUZ7w7OY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=XYY9kB9G; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="XYY9kB9G" 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 A19FE201B; Fri, 29 May 2026 01:28:33 -0700 (PDT) Received: from [10.57.91.162] (unknown [10.57.91.162]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 51F163F632; Fri, 29 May 2026 01:28:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1780043318; bh=HxDE/v275kzieWm+smiZqa4yjNgD7FuY1p40zCPFJh8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=XYY9kB9GX0DEWsQN+Oj7ZxBosVWDp3/KI3Y5O5DSe8+4geNHXgkk8LulhMaD4MsWA Nccb5VsdP0UL8JIjPxBgRordOXz3Gl/86u7LQqEBCbv412ByXijVU4uD+broFZMSHy cGpZhrwOcstLiYiLOi2GfzJ7aoGgzXegNpL7uRks= Message-ID: <87ed7239-1622-4cb3-af04-2390f2b549e3@arm.com> Date: Fri, 29 May 2026 10:28:31 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 10/15] arm64: mm: Don't abuse memblock NOMAP to check for overlaps To: Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, Ard Biesheuvel , Ryan Roberts , Anshuman Khandual , Liz Prucka , Seth Jenkins , Kees Cook , Mike Rapoport , David Hildenbrand , Andrew Morton , Jann Horn , linux-mm@kvack.org, linux-hardening@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-sh@vger.kernel.org References: <20260526175846.2694125-17-ardb+git@google.com> <20260526175846.2694125-27-ardb+git@google.com> From: Kevin Brodsky Content-Language: en-GB In-Reply-To: <20260526175846.2694125-27-ardb+git@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 26/05/2026 19:58, Ard Biesheuvel wrote: > From: Ard Biesheuvel > > Now that the linear region mapping routines respect existing table > mappings and contiguous block and page mappings, it is no longer needed > to fiddle with the memblock tables to set and clear the NOMAP attribute > in order to omit text and rodata when creating the linear map. > > Instead, map the kernel text and rodata alias first with the desired > initial attributes and granularity, so that the loop iterating over the > memblocks will not remap it in a manner that prevents it from being > remapped with updated attributes later. > > Signed-off-by: Ard Biesheuvel > --- > arch/arm64/mm/mmu.c | 23 ++++++-------------- > 1 file changed, 7 insertions(+), 16 deletions(-) > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index 04cc579c7a15..b20c76b8381d 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -1164,12 +1164,14 @@ static void __init map_mem(void) > flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; > > /* > - * Take care not to create a writable alias for the > - * read-only text and rodata sections of the kernel image. > - * So temporarily mark them as NOMAP to skip mappings in > - * the following for-loop > + * Map the linear alias of the [_text, __init_begin) interval > + * as non-executable now, and remove the write permission in > + * mark_linear_text_alias_ro() above (which will be called after > + * alternative patching has completed). This makes the contents > + * of the region accessible to subsystems such as hibernate, > + * but protects it from inadvertent modification or execution. > */ > - memblock_mark_nomap(kernel_start, kernel_end - kernel_start); > + __map_memblock(kernel_start, kernel_end, PAGE_KERNEL, flags); Isn't the loop going to remap the range as pgprot_tagged(PAGE_KERNEL)? Maybe better to use that here as well just to make it look more consistent. If my understanding is correct, we should also amend the comment to avoid implying that the permissions we're passing to __map_memblock() here matter - the linear alias is going to be non-executable regardless because of the loop below mapping everything RW. - Kevin > > /* map all the memory banks */ > for_each_mem_range(i, &start, &end) { > @@ -1181,17 +1183,6 @@ static void __init map_mem(void) > __map_memblock(start, end, pgprot_tagged(PAGE_KERNEL), > flags); > } > - > - /* > - * Map the linear alias of the [_text, __init_begin) interval > - * as non-executable now, and remove the write permission in > - * mark_linear_text_alias_ro() below (which will be called after > - * alternative patching has completed). This makes the contents > - * of the region accessible to subsystems such as hibernate, > - * but protects it from inadvertent modification or execution. > - */ > - __map_memblock(kernel_start, kernel_end, PAGE_KERNEL, 0); > - memblock_clear_nomap(kernel_start, kernel_end - kernel_start); > } > > void mark_rodata_ro(void)