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 84B42346AF1 for ; Wed, 24 Jun 2026 07:46:47 +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=1782287210; cv=none; b=DLku/zTMhRBqZBKE+1SWU+C0BNOD8NEZAU94CtEoHv1T3zkztIKqpZKphzyfqId/Ni0iHlyC2KwWuj5iP/TcSYjl5Hk0KHAfW+oFrBjhe0+uVa5DXebEJ9zjhnMM9JhqxPLYY4+6b6MWrXQG0b6vHA6OFYjHoA0i+4zu8+qJEzo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782287210; c=relaxed/simple; bh=sbdMZ7z3OdjetPqNLVMjiXhZ3+C66lUfyXUflKzbfqk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LsK8LRB825nziRLOwidSnHiZ+wWqG5bLfOJ+p1B6urmW7pNSCY2Rh08Rh3bVisJApRoPY0woghW6gCecSXrNM22Ny/HZ55qDeFqz8vNh/iFwuLMEIVR54Dv2Juw8Ljx9g+oNyGI8Ox+vfAHO87Cn8sEYRBsJf/4RPEIJsXOBEdI= 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=cHP+Jdgb; 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="cHP+Jdgb" 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 612D4263D; Wed, 24 Jun 2026 00:46:41 -0700 (PDT) Received: from [10.57.80.25] (unknown [10.57.80.25]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D40803F632; Wed, 24 Jun 2026 00:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1782287205; bh=sbdMZ7z3OdjetPqNLVMjiXhZ3+C66lUfyXUflKzbfqk=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=cHP+JdgbxoHxo09iik7ypg7Z8zF6wUkdxsssBPzBpiXtUJFP0fwGxiYRD1I+QQYNQ wmmzN40Z63gvg90cmGYzkCZ+stFAvxczeDN7EkVWydaZoKerSTLISBQShcnWp/j8+f 1CIwtUXlqlaGlMUvQup+A7eZtr4aRcoxEI1gJFgY= Message-ID: <0708554c-54dd-4bd0-a147-b565733b5e4e@arm.com> Date: Wed, 24 Jun 2026 09:46:36 +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 v2] 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: <20260623202817.2225495-2-ardb+git@google.com> From: Kevin Brodsky Content-Language: en-GB In-Reply-To: <20260623202817.2225495-2-ardb+git@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 23/06/2026 22:28, Ard Biesheuvel wrote: > From: Ard Biesheuvel > > Since commit > > f2ba877402e5 ("arm64: mm: Map the kernel data/bss read-only in the linear map") > > the linear alias of the .data and .bss regions is remapped read-only > early during the boot. (Note that a subsequent patch to unmap this > region entirely was reverted just before the v7.2 merge window, and will > be brought back in an improved form for the v7.3 cycle) > > 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. > > Fixes: f2ba877402e5 ("arm64: mm: Map the kernel data/bss read-only in the linear map") > Reviewed-by: Fuad Tabba > Tested-by: Fuad Tabba < fuad.tabba@linux.dev> > Signed-off-by: Ard Biesheuvel Thanks for expanding the commit message! Reviewed-by: Kevin Brodsky > --- > v2: improve changelog, add Fuad's R-b > > 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); > } > > static void __init declare_vma(struct vm_struct *vma,