Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A1BC314D13 for ; Mon, 22 Jun 2026 15:23:42 +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=1782141826; cv=none; b=jsO10r//nO6zJyPyjeGNzh9qr5DFmiCzFKadlPT+y0UhZSHr1KoPHPlr86f2GeIkk+ZNbH41RE5lDXyaUoateon7XVui89bfwYwpSjitBvfqvGm00xsIh0DeYWkv/MKpM47GQrE/IhB65/EIRB7NGTvXlbJTw8DcHOna42IPY8k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782141826; c=relaxed/simple; bh=yCffkQovzvs4v9GagD78FMN0QtZEotX8qJKYNIKpzL4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=mw6dpNDYjXkfJp6bey90xeyw/rR6/kanwwOrvQvT+RXbY0pYpRO9Fn2Oq30Ha0aMhC42SGNIwh4jij3SmiD+e4Jz4RL/hj4yBG0o8Yo/HvCkhn0r/P8nHr0bOwSXzr0aI7qmLu6A0l5unAl4AG+iXY+ZlsxEf/OAodRIh/Ppx+A= 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=OekL3WjS; 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="OekL3WjS" 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 423921BCB; Mon, 22 Jun 2026 08:23:37 -0700 (PDT) Received: from [10.57.95.184] (unknown [10.57.95.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C95833F62B; Mon, 22 Jun 2026 08:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1782141821; bh=yCffkQovzvs4v9GagD78FMN0QtZEotX8qJKYNIKpzL4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=OekL3WjSP4roVpk0NM4g4AfyI1Mp3kAZfJ4DR5wnNKyB1etrO85W4ZiPertDj+/B2 Dc5Hl3twFRSBVPWwDYxvUz4Td/I0WT6eekJj7FJvdbw7z/Kc/BHAGOJuAD3JKsms9/ KTclsJ1wUwoMh3qhKg9MY83YsxLPH1cdiO0mr4nI= Message-ID: <2deff570-0497-4438-94ba-a9691881a016@arm.com> Date: Mon, 22 Jun 2026 17:23:37 +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] arm64: mm: Defer read-only remap of data/bss linear alias To: Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, Ard Biesheuvel , Fuad Tabba References: <20260619163940.3185308-2-ardb+git@google.com> From: Kevin Brodsky Content-Language: en-GB In-Reply-To: <20260619163940.3185308-2-ardb+git@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 19/06/2026 18:39, Ard Biesheuvel wrote: > From: Ard Biesheuvel > > Fuad reports that in some cases, the KVM init code may apply relocations > to variables that reside in .data, and does so via the linear map. This > means that remapping .data read-only beforehand is a bad idea, and > results in an early boot crash. > > These variables in .data are only present when CONFIG_NVHE_EL2_DEBUG or > CONFIG_NVHE_EL2_TRACING are enabled, which is why it was not spotted in > testing. > > So move the remap to mark_rodata_ro(), which is a reasonable place to > put this, and ensures that it happens much later during the boot. It > also means that rodata=off is now taken into account, and so the linear > alias will remain writable in that case. > > Cc: Fuad Tabba > Fixes: f2ba877402e5 ("arm64: mm: Map the kernel data/bss read-only in the linear map") > Signed-off-by: Ard Biesheuvel > --- > arch/arm64/mm/mmu.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index 9f354971b7e4..1f7eca86b5c1 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -1198,11 +1198,6 @@ static void __init map_mem(void) > __map_memblock(start, end, pgprot_tagged(PAGE_KERNEL), > flags); > } > - > - /* Map the kernel data/bss read-only in the linear map */ > - __map_memblock(init_end, kernel_end, PAGE_KERNEL_RO, flags); > - flush_tlb_kernel_range((unsigned long)lm_alias(__init_end), > - (unsigned long)lm_alias(__bss_stop)); > } > > void mark_rodata_ro(void) > @@ -1221,6 +1216,12 @@ void mark_rodata_ro(void) > update_mapping_prot(__pa_symbol(_text), (unsigned long)_text, > (unsigned long)_stext - (unsigned long)_text, > PAGE_KERNEL_RO); > + > + /* Map the kernel data/bss read-only in the linear map */ > + update_mapping_prot(__pa_symbol(__init_end), > + (unsigned long)lm_alias(__init_end), > + (unsigned long)__bss_stop - (unsigned long)__init_end, > + PAGE_KERNEL_RO); I was rather confused by this patch until I saw in master: f102131c842d Revert "arm64: mm: Unmap kernel data/bss entirely from the linear map" 81479b6888f8 Revert "arm64: mm: Defer remap of linear alias of data/bss" ... which explains the diff, but it looks like there are multiple issues here. Is my understanding correct that these reverts fix kvm_arm_init() because it needs to *read* from the linear map, while this new patch fixes some KVM configurations that need to *write* to the linear map? If so it might be good to give a recap in the commit message, because the reverts are easy to miss. It would also be good to explain why we can't do this in mark_linear_text_alias_ro() (presumably because this is too early). I do agree that honouring rodata=off is a good thing, though. BTW, if only kvm_arm_init() needs to read the data/bss via the linear map, maybe we can still unmap it later? - Kevin