Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arnd Bergmann" <arnd@kernel.org>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
	"Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v3 3/4] arm64: add HWCAP3_LS64_ACCDATA
Date: Thu, 03 Dec 2026 10:19:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-247564@kernel.org> (raw)
In-Reply-To: <20261203095703.655796-4-arnd@kernel.org>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Critical] arm64: NULL mm dereference in ls64_accdata_thread_switch()
  on task exit
- [Medium] arm64: HWCAP3_LS64_ACCDATA advertised without
  CONFIG_ARM64_LS64_ACCDATA
- [Low] arm64: elf_hwcaps.rst overstates SIGBUS scope and uses >=
  convention
- [Low] arm64: elf_hwcaps.rst unconfirmed st64bv0 bits 31:0 overwrite
  claim
--

commit f0a6f157224e6ac0c0f369c507739103758e5747
Author: Arnd Bergmann <arnd@arndb.de>

arm64: add HWCAP3_LS64_ACCDATA

This commit exposes FEAT_LS64_ACCDATA to userspace via HWCAP3_LS64_ACCDATA
and /proc/cpuinfo, and documents its semantics in elf_hwcaps.rst.

Link: https://www.kernel.org/doc/html/v7.3/arch/x86/sva.html#enqcmd

> diff --git a/Documentation/arch/arm64/elf_hwcaps.rst b/Documentation/arch/arm64/elf_hwcaps.rst
> index f60ca5612daa4..f56b38e4349b6 100644
> --- a/Documentation/arch/arm64/elf_hwcaps.rst
> +++ b/Documentation/arch/arm64/elf_hwcaps.rst
> @@ -478,6 +478,17 @@ HWCAP3_SVE_LUT6
>      Functionality implied by ID_AA64PFR0_EL1.SVE == 0b0001 and
>      ID_AA64ISAR2_EL1.LUT == 0b0010.
>  
> +HWCAP3_LS64_ACCDATA
> +    Functionality implied by ID_AA64ISAR1_EL1.LS64 >= 0b0011.
> +    Note that the function of instruction st64bv0 requires support
> +    by CPU, system and target (device) memory location and a matching
> +    device driver.  HWCAP3_LS64_ACCDATA implies the support of CPU only.
> +    The kernel uses ACCDATA_EL1 to supply the Process Address Space ID
> +    (PASID) of the calling process. The CPU replaces bits [31:0] of the
> +    64-byte store data with this value. st64bv0 can only be used after

[Severity: Low]
This rests on an arm64 architectural detail that could not be confirmed
from the kernel source: does st64bv0 transmit ACCDATA_EL1[31:0] as
separate transaction metadata alongside the 64-byte store payload rather
than overwriting bits [31:0] of the 64-byte store data?

If so, this documentation would mislead userspace about how to lay out
its 64-byte st64bv0 work descriptors.

> +    a device driver has bound the process address space to a device that
> +    supports this instruction.  Any other I/O access raises SIGBUS with
> +    si_code == BUS_OBJERR.

[Severity: Low]
Does this overstate when SIGBUS with si_code == BUS_OBJERR is raised?

Only trapped st64bv0 instructions inject SIGBUS/BUS_OBJERR in
do_el0_other(), not general I/O accesses.  Furthermore, once
try_enable_st64bv0() sets SCTLR_EL1_EnAS0 for a thread, it is not
cleared on iommu_sva_unbind_device(), so later st64bv0 accesses by that
thread to unbound or unsupported mappings no longer trap to
do_el0_other() and are not guaranteed to raise SIGBUS.

Also, ID_AA64ISAR1_EL1.LS64 >= 0b0011 is the only entry in this file
using >= instead of the idreg.field == val convention described in
Section 2.

[ ... ]

> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
> index 866385b490eb7..8f874e344e52d 100644
> --- a/arch/arm64/kernel/cpufeature.c
> +++ b/arch/arm64/kernel/cpufeature.c
> @@ -3223,6 +3223,7 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = {
>  	HWCAP_CAP(ID_AA64ISAR1_EL1, DGH, IMP, CAP_HWCAP, KERNEL_HWCAP_DGH),
>  	HWCAP_CAP(ID_AA64ISAR1_EL1, I8MM, IMP, CAP_HWCAP, KERNEL_HWCAP_I8MM),
>  	HWCAP_CAP(ID_AA64ISAR1_EL1, LS64, LS64, CAP_HWCAP, KERNEL_HWCAP_LS64),
> +	HWCAP_CAP(ID_AA64ISAR1_EL1, LS64, LS64_ACCDATA, CAP_HWCAP, KERNEL_HWCAP_LS64_ACCDATA),

[Severity: Medium]
As reported by Catalin Marinas on v2 [1], should this entry and
system_supports_ls64_accdata() be gated on CONFIG_ARM64_LS64_ACCDATA?

With CONFIG_IOMMU_SVA=y and CONFIG_ARM64_LS64_ACCDATA=n, in-tree SVA
drivers such as uacce still bind via iommu_sva_bind_device() without
checking CONFIG_ARM64_LS64_ACCDATA, while userspace sees
HWCAP3_LS64_ACCDATA set with no way to tell that kernel ACCDATA_EL1
support is compiled out.  Issuing st64bv0 then unconditionally fails
with SIGBUS (BUS_OBJERR) in try_enable_st64bv0().

Guarding both the arm64_elf_hwcaps[] entry with #ifdef
CONFIG_ARM64_LS64_ACCDATA and system_supports_ls64_accdata() with
IS_ENABLED(CONFIG_ARM64_LS64_ACCDATA) would match the other
Kconfig-gated EL0 features in this table.

[Severity: Critical]
Once userspace discovers HWCAP3_LS64_ACCDATA and executes st64bv0, can
ls64_accdata_thread_switch() dereference a NULL next->mm on task exit?

In commit "arm64: dynamically enable st64bv0 for SVA",
try_enable_st64bv0() sets SCTLR_EL1_EnAS0 in current->thread.sctlr_user,
which is never cleared on exit.  During do_exit(), exit_mm() sets
current->mm = NULL before sleepable teardown steps such as exit_files().
If the exiting task sleeps or is preempted and later scheduled back in,
__switch_to() calls ls64_accdata_thread_switch():

arch/arm64/kernel/process.c:ls64_accdata_thread_switch() {
	if (!(next->thread.sctlr_user & SCTLR_EL1_EnAS0))
		return;

	pasid = mm_get_enqcmd_pasid(next->mm);
	if (pasid != IOMMU_PASID_INVALID)
		write_sysreg_s(pasid, SYS_ACCDATA_EL1);
}

mm_get_enqcmd_pasid() unconditionally dereferences mm->iommu_mm, causing
a kernel NULL pointer dereference inside __switch_to() with interrupts
disabled and the runqueue lock held.  Any unprivileged user with access to
an SVA device can panic the kernel by running st64bv0 and exiting.

Similarly, ls64_accdata_suspend_exit() in arch/arm64/kernel/suspend.c
passes current->mm to mm_get_enqcmd_pasid() without checking for NULL,
and writes the result to SYS_ACCDATA_EL1 without checking for
IOMMU_PASID_INVALID.

[1] https://lore.kernel.org/r/aw26TP1HH-oo1kjf@arm.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203095703.655796-1-arnd@kernel.org?part=3

  reply	other threads:[~2026-12-03 10:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  9:56 [PATCH v3 0/4] st64bv0 support in iommu-sva Arnd Bergmann
2026-12-03  9:57 ` [PATCH v3 1/4] arm64: kvm: save and restore ACCDATA_EL1 if used by host Arnd Bergmann
2026-12-03 10:16   ` sashiko-bot
2026-12-03  9:57 ` [PATCH v3 2/4] arm64: dynamically enable st64bv0 for SVA Arnd Bergmann
2026-12-03 10:26   ` sashiko-bot
2026-12-03  9:57 ` [PATCH v3 3/4] arm64: add HWCAP3_LS64_ACCDATA Arnd Bergmann
2026-12-03 10:19   ` sashiko-bot [this message]
2026-12-03  9:57 ` [PATCH v3 4/4] kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA Arnd Bergmann
2026-12-03 10:14   ` sashiko-bot

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=sashiko-outbox-247564@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arnd@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox