[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aBngorZeIASsJEvY@arm.com>
Date: Tue, 6 May 2025 11:12:50 +0100
From: Catalin Marinas <catalin.marinas@....com>
To: Yeoreum Yun <yeoreum.yun@....com>
Cc: Ryan Roberts <ryan.roberts@....com>, will@...nel.org, nathan@...nel.org,
nick.desaulniers+lkml@...il.com, morbo@...gle.com,
justinstitt@...gle.com, broonie@...nel.org, maz@...nel.org,
oliver.upton@...ux.dev, joey.gouly@....com,
shameerali.kolothum.thodi@...wei.com, james.morse@....com,
hardevsinh.palaniya@...iconsignals.io, ardb@...nel.org,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
llvm@...ts.linux.dev, stable@...r.kernel.org
Subject: Re: [PATCH v2] arm64/cpufeature: annotate arm64_use_ng_mappings with
ro_after_init to prevent wrong idmap generation
On Tue, May 06, 2025 at 09:53:57AM +0100, Yeoreum Yun wrote:
> > >>>> On Sat, May 03, 2025 at 11:16:12AM +0100, Catalin Marinas wrote:
> > >>>>> On Fri, 02 May 2025 19:04:12 +0100, Yeoreum Yun wrote:
> > >>>>>> create_init_idmap() could be called before .bss section initialization
> > >>>>>> which is done in early_map_kernel().
> > >>>>>> Therefore, data/test_prot could be set incorrectly by PTE_MAYBE_NG macro.
> > >>>>>>
> > >>>>>> PTE_MAYBE_NG macro set NG bit according to value of "arm64_use_ng_mappings".
> > >>>>>> and this variable places in .bss section.
> > >>>>>>
> > >>>>>> [...]
> > >>>>>
> > >>>>> Applied to arm64 (for-next/fixes), with some slight tweaking of the
> > >>>>> comment, thanks!
> > >>>>>
> > >>>>> [1/1] arm64/cpufeature: annotate arm64_use_ng_mappings with ro_after_init to prevent wrong idmap generation
> > >>>>> https://git.kernel.org/arm64/c/12657bcd1835
> > >>>>
> > >>>> I'm going to drop this for now. The kernel compiled with a clang 19.1.5
> > >>>> version I have around (Debian sid) fails to boot, gets stuck early on:
[...]
> Personally, I don't believe this because the create_init_idmap()
> maps the the .rodata section with PAGE_KERNEL pgprot
> from __initdata_begin to _end.
>
> and at the mark_readonly() the pgprot is changed to PAGE_KERNEL_RO
> But, arm64_use_ng_mappings is accessed with write before mark_readonly()
> only via smp_cpus_done().
>
> JFYI here is map information:
>
> // mark_readlonly() changes to ro perm below ranges:
> ffff800081b30000 g .rodata 0000000000000000 __start_rodata
> ffff800082560000 g .rodata.text 0000000000000000 __init_begin
>
> // create_init_idmap() maps below range with PAGE_KERNEL.
> ffff8000826d0000 g .altinstructions 0000000000000000 __initdata_begin
> ffff800082eb0000 g .bss 0000000000000000 _end
>
> ffff8000824596d0 g O .rodata 0000000000000001 arm64_use_ng_mappings
So arm64_use_ng_mappings is mapped as read-only since .rodata is before
__initdata_begin.
--
Catalin
Powered by blists - more mailing lists