From: Marc Zyngier <maz@kernel.org>
To: Yicong Yang <yangyccccc@gmail.com>
Cc: Marek Vasut <marek.vasut@mailbox.org>,
Marek Vasut <marek.vasut+renesas@mailbox.org>,
linux-arm-kernel@lists.infradead.org,
Anshuman Khandual <anshuman.khandual@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Ryan Roberts <ryan.roberts@arm.com>,
Will Deacon <will@kernel.org>,
Yicong Yang <yangyicong@hisilicon.com>,
linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH] arm64: guard AMU register access with ARM64_HAS_AMU_EXTN
Date: Thu, 23 Oct 2025 15:21:55 +0100 [thread overview]
Message-ID: <87wm4l3dh8.wl-maz@kernel.org> (raw)
In-Reply-To: <632d6afe-40d3-4632-99c7-b098967bd649@gmail.com>
On Thu, 23 Oct 2025 13:01:52 +0100,
Yicong Yang <yangyccccc@gmail.com> wrote:
>
> On 2025/10/22 22:33, Marek Vasut wrote:
> > On 10/22/25 4:20 PM, Marc Zyngier wrote:
> >> On Wed, 22 Oct 2025 14:35:28 +0100,
> >> Marek Vasut <marek.vasut+renesas@mailbox.org> wrote:
> >>>
> >>> The AMU configuration register access may fault and prevent successful
> >>> kernel boot. This can occur for example in case the firmware does not
> >>> allow AMU counter access from EL1. Guard the AMU configuration register
> >>> access with ARM64_HAS_AMU_EXTN to prevent this fault if ARM64_HAS_AMU_EXTN
> >>> Kconfig option is explicitly disabled. Other interaction with the AMU is
> >>> already guarded by similar ifdeffery.
> >>>
> >>> Fixes: 87a1f063464a ("arm64: trap to EL1 accesses to AMU counters from EL0")
> >>> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
> >>> ---
> >>> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> >>> Cc: Catalin Marinas <catalin.marinas@arm.com>
> >>> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> >>> Cc: Marc Zyngier <maz@kernel.org>
> >>> Cc: Ryan Roberts <ryan.roberts@arm.com>
> >>> Cc: Will Deacon <will@kernel.org>
> >>> Cc: Yicong Yang <yangyicong@hisilicon.com>
> >>> Cc: linux-arm-kernel@lists.infradead.org
> >>> Cc: linux-renesas-soc@vger.kernel.org
> >>> ---
> >>> arch/arm64/mm/proc.S | 4 ++++
> >>> 1 file changed, 4 insertions(+)
> >>>
> >>> diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
> >>> index 86818511962b6..123538ffeda6b 100644
> >>> --- a/arch/arm64/mm/proc.S
> >>> +++ b/arch/arm64/mm/proc.S
> >>> @@ -145,7 +145,9 @@ SYM_FUNC_START(cpu_do_resume)
> >>> ubfx x11, x11, #1, #1
> >>> msr oslar_el1, x11
> >>> reset_pmuserenr_el0 x0 // Disable PMU access from EL0
> >>> +alternative_if ARM64_HAS_AMU_EXTN
> >>> reset_amuserenr_el0 x0 // Disable AMU access from EL0
> >>> +alternative_else_nop_endif
> >>
> >> Why?
> >>
> >> We ensure that the AMU is available in the macro itself by checking
> >> for ID_AA64PFR0_EL1.AMU. If the AMu isn't present on this CPU, we skip
> >> the offending sysreg access. This is similar to what we do for the
> >> PMU.
> >>
> >> Does your HW advertise an AMU, but doesn't actually have one?
> > The hardware does have AMU, but it is currently blocked in old TFA version and access to this AMU register here causes a fault. That's why I have to disable ARM64_HAS_AMU_EXTN until the TFA is updated and the AMU access is made available on this hardware. But even if I do disable ARM64_HAS_AMU_EXTN=n , I get a fault.
> >
> > This patch is mainly meant to prevent a surprise in case someone does set ARM64_HAS_AMU_EXTN=n , and the system still faults on AMU register access.
> >
>
> then I think it's more proper to guard it with CONFIG_ARM64_AMU_EXTN
> (I think you mean this above?) rathter than the cpu cap. then with
> the patch kernel won't touch the AMU registers here if the kconfig
> is disabled on you AMU supported hardware and AMU unsupported
> firmware.
No. Not preventing EL0 from accessing the register is a data leak to
userspace. This must be acted upon irrespective of the kernel being
AMU-enabled or not.
M.
--
Jazz isn't dead. It just smells funny.
next prev parent reply other threads:[~2025-10-23 14:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-22 13:35 [PATCH] arm64: guard AMU register access with ARM64_HAS_AMU_EXTN Marek Vasut
2025-10-22 14:20 ` Marc Zyngier
2025-10-22 14:33 ` Marek Vasut
2025-10-22 15:02 ` Marc Zyngier
2025-10-22 15:19 ` Catalin Marinas
2025-10-22 15:31 ` Marek Vasut
2025-10-22 15:29 ` Marek Vasut
2025-10-23 14:19 ` Marc Zyngier
2025-10-23 15:58 ` Marek Vasut
2025-10-24 9:27 ` Marc Zyngier
2025-12-30 2:00 ` Marek Vasut
2025-10-23 12:01 ` Yicong Yang
2025-10-23 13:16 ` Marek Vasut
2025-10-23 14:21 ` Marc Zyngier [this message]
2025-10-23 14:44 ` Yicong Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wm4l3dh8.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=anshuman.khandual@arm.com \
--cc=catalin.marinas@arm.com \
--cc=geert+renesas@glider.be \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=marek.vasut+renesas@mailbox.org \
--cc=marek.vasut@mailbox.org \
--cc=ryan.roberts@arm.com \
--cc=will@kernel.org \
--cc=yangyccccc@gmail.com \
--cc=yangyicong@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.