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 4/4] kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA
Date: Thu, 03 Dec 2026 10:14:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-247532@kernel.org> (raw)
In-Reply-To: <20261203095703.655796-5-arnd@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Critical] arm64: NULL dereference of next->mm in
  ls64_accdata_thread_switch() on exit
- [Low] kselftest/arm64: ls64_accdata_sigill() never verifies SIGBUS or
  BUS_OBJERR
--

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

kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA

This commit adds a HWCAP3_LS64_ACCDATA selftest to the arm64 ABI hwcap
test, issuing st64bv0 on a stack buffer to verify the instruction does not
raise SIGILL when the feature is reported.

Link: https://lore.kernel.org/all/20241202135504.14252-4-yangyicong@huawei.com/

> diff --git a/tools/testing/selftests/arm64/abi/hwcap.c b/tools/testing/selftests/arm64/abi/hwcap.c
> index 19fca95f7c228..4c89a897837db 100644
> --- a/tools/testing/selftests/arm64/abi/hwcap.c
> +++ b/tools/testing/selftests/arm64/abi/hwcap.c
> @@ -693,6 +693,48 @@ static void ls64_sigill(void)

[ ... ]

> +static void ls64_accdata_sigill(void)
> +{
> +	struct sigaction ign, old;
> +	char dst[64] __aligned(64);
> +
> +	/*
> +	 * Like LS64, LS64_ACCDATA requires both the feature to be
> +	 * available in hardware, and the address to be on a device
> +	 * capable of the transaction.
> +	 * In addition, the device driver that has mapped the device
> +	 * must have created a PASID that can be used as ACCDATA.
> +	 *
> +	 * For testing the ABI, check only that st64bv0 on a user
> +	 * address gives the expected SIGBUS error when the instruction
> +	 * is not enabled for this thread. If it was enabled, the
> +	 * error status would be reported in 'st' instead of a signal,
> +	 * but that can only be tested if a PASID is set for this thread.
> +	 */
> +	ign.sa_sigaction = ignore_signal;
> +	ign.sa_flags = SA_SIGINFO | SA_RESTART;
> +	sigemptyset(&ign.sa_mask);
> +	sigaction(SIGBUS, &ign, &old);

[Severity: Low]
Does ls64_accdata_sigill() actually verify that SIGBUS with BUS_OBJERR is
delivered?

The comment states that the test checks for the expected SIGBUS error when
st64bv0 is not enabled for the thread, matching the ABI in
Documentation/arch/arm64/elf_hwcaps.rst.  However, ignore_signal() only
advances uc->uc_mcontext.pc without recording SIGBUS delivery or checking
info->si_code == BUS_OBJERR, and the hwcaps[] entry leaves .sigbus_fn
NULL.

If a kernel bug left SCTLR_EL1.EnAS0 enabled for threads without a PASID,
st64bv0 would execute without raising SIGILL or SIGBUS and the test would
silently pass.  Either verify SIGBUS with BUS_OBJERR when
HWCAP3_LS64_ACCDATA is set, or update the comment to state that only the
absence of SIGILL is checked.

[ ... ]

> @@ -1300,6 +1342,14 @@ static const struct hwcap_data {
>  		.sigill_fn = ls64_sigill,
>  		.sigill_reliable = true,
>  	},
> +	{
> +		.name = "LS64_ACCDATA",
> +		.at_hwcap = AT_HWCAP3,
> +		.hwcap_bit = HWCAP3_LS64_ACCDATA,
> +		.cpuinfo = "ls64accdata",
> +		.sigill_fn = ls64_accdata_sigill,
> +		.sigill_reliable = true,
> +	},
>  };

[Severity: Critical]
In earlier commit "arm64: dynamically enable st64bv0 for SVA" from this
series, can ls64_accdata_thread_switch() dereference a NULL next->mm when
an exiting task is scheduled back in?

Once a thread enables st64bv0 via do_el0_other() -> try_enable_st64bv0(),
SCTLR_EL1_EnAS0 remains set in thread.sctlr_user across exit_mm(), which
sets current->mm = NULL.  If the exiting task sleeps or is preempted
during teardown (for example in mmput() or exit_files()), __switch_to()
calls ls64_accdata_thread_switch() with next->mm == NULL:

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);
    ...
}

mm_get_enqcmd_pasid() unconditionally reads mm->iommu_mm, causing a
deterministic kernel NULL pointer dereference panic when any local process
that used st64bv0 exits.

In the same commit, ls64_accdata_suspend_exit() in
arch/arm64/kernel/suspend.c also calls mm_get_enqcmd_pasid(current->mm)
without checking current->mm != NULL, and writes the returned pasid to
SYS_ACCDATA_EL1 without checking pasid != IOMMU_PASID_INVALID (which can
write IOMMU_PASID_INVALID if the SVA device was unbound before suspend).

Clearing SCTLR_EL1_EnAS0 on exit, or checking for a NULL mm and
IOMMU_PASID_INVALID before programming SYS_ACCDATA_EL1, avoids both
issues.

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

      reply	other threads:[~2026-12-03 10:14 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
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 [this message]

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-247532@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