From: sashiko-bot@kernel.org
To: "Sven Schnelle" <svens@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver
Date: Fri, 04 Dec 2026 15:45:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-250126@kernel.org> (raw)
In-Reply-To: <20261204144529.960326-4-svens@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] firmware: platform-accel: AB-BA deadlock in
platform_accel_mmap()
- [High] firmware: platform-accel: missing VM_SHARED check allows
MAP_PRIVATE MMIO COW
- [Medium] firmware: platform-accel: missing IOMMU_SUPPORT dependency in
Kconfig
- [Medium] firmware: platform-accel: missing CONFIG_ARM64_LS64_ACCDATA
check
- [Medium] firmware: platform-accel: missing PAGE_SIZE alignment check
on MMIO resource
- [Medium] firmware: platform-accel: missing VMA revocation in
platform_accel_remove()
- [Medium] firmware: platform-accel: missing VM_DONTCOPY leaks unbound
MMIO across fork()
- [Low] firmware: platform-accel: unused kernel ioremap in probe
--
commit 7b5f761f498fd31a0537f5d7386952caeaaf03c4
Author: Sven Schnelle <svens@linux.ibm.com>
drivers: firmware: add ARM on s390 accelerator driver
This commit adds a platform driver for arm64 s390 KVM guests that exposes
accelerator MMIO regions via misc devices so userspace can mmap() them and
use st64bv0.
> diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
> index 43e2e2a645945..bc90aa19b5d38 100644
> --- a/drivers/firmware/Kconfig
> +++ b/drivers/firmware/Kconfig
> @@ -299,6 +299,16 @@ config TURRIS_MOX_RWTM_KEYCTL
>
> endif # TURRIS_MOX_RWTM
>
> +config PLATFORM_ACCEL
> + tristate "Acceleration driver for arm64"
> + depends on ARM64
> + select IOMMU_SVA
[Severity: Medium]
Can selecting IOMMU_SVA without depending on IOMMU_SUPPORT break the build
when CONFIG_IOMMU_SUPPORT is disabled?
IOMMU_SVA lives inside "if IOMMU_SUPPORT" in drivers/iommu/Kconfig. When
CONFIG_IOMMU_SUPPORT=n, selecting IOMMU_SVA emits an unmet dependency
warning and compiles drivers/iommu/iommu-sva.c without CONFIG_IOMMU_API,
failing on undefined struct dev_iommu fields and missing
iommu_attach_handle_get().
Adding "depends on IOMMU_SUPPORT" ensures IOMMU_API is enabled alongside
IOMMU_SVA.
[ ... ]
> diff --git a/drivers/firmware/platform-accel.c b/drivers/firmware/platform-accel.c
> new file mode 100644
> index 0000000000000..0e77a8243d038
> --- /dev/null
> +++ b/drivers/firmware/platform-accel.c
[ ... ]
> +static int platform_accel_mmap(struct file *filep, struct vm_area_struct *vma)
> +{
> + struct miscdevice *misc = filep->private_data;
> + struct platform_accel *dev = container_of(misc, struct platform_accel, misc);
> + int ret = -ENODEV;
> +
> + mutex_lock(&dev->lock);
> + if (!dev->present)
> + goto out;
> +
> + ret = iommu_sva_bind_device_no_iommu(&dev->pdev->dev, current->mm);
> + if (ret)
> + goto out;
[Severity: High]
Can calling iommu_sva_bind_device_no_iommu() from platform_accel_mmap()
cause an ABBA deadlock between mm->mmap_lock and iommu_sva_lock?
vm_mmap_pgoff() holds current->mm->mmap_lock for writing across
f_op->mmap(), so platform_accel_mmap() acquires iommu_sva_lock inside
mm->mmap_lock. Meanwhile, iommu_sva_bind_device() acquires iommu_sva_lock
before calling arm_smmu_sva_domain_alloc() -> mmu_notifier_register(),
which takes mmap_write_lock(mm):
CPU0 CPU1
---- ----
lock(&mm->mmap_lock)
lock(&iommu_sva_lock)
lock(&iommu_sva_lock)
lock(&mm->mmap_lock)
*** DEADLOCK ***
CPU0: vm_mmap_pgoff() -> ... -> platform_accel_mmap()
-> iommu_sva_bind_device_no_iommu()
CPU1: iommu_sva_bind_device() -> iommu_sva_domain_alloc()
-> arm_smmu_sva_domain_alloc() -> mmu_notifier_register()
Binding SVA before vm_iomap_memory() also permanently allocates a global
PASID on current->mm even if vm_iomap_memory() fails with -EINVAL.
Performing SVA binding outside mmap_lock (for example in f_op->open(),
without nesting dev->lock across misc_mtx) avoids both problems.
> + vma->vm_page_prot = pgprot_device(vma->vm_page_prot);
> + ret = vm_iomap_memory(vma, dev->phys_base, dev->phys_size);
[Severity: High]
Should platform_accel_mmap() reject MAP_PRIVATE mappings by checking
VM_SHARED?
Because the device is mode 0666, any unprivileged user can mmap it with
MAP_PRIVATE and write to it. do_wp_page() -> wp_page_copy() then executes
kernel reads directly from the Device-nGnRE MMIO window in
__wp_page_copy_user(), hitting WARN_ON_ONCE(1) if normal loads fail.
wp_page_copy() also maps the newly allocated normal RAM folio with
vma->vm_page_prot (MT_DEVICE_nGnRE), creating a mismatched memory-attribute
alias with the MT_NORMAL kernel linear map on arm64.
[Severity: Medium]
Should platform_accel_mmap() set VM_DONTCOPY on vma?
Without VM_DONTCOPY, fork() copies the Device-nGnRE MMIO PTEs into the
child even though mm_pasid_init() clears child->mm->iommu_mm and
copy_thread_ls64_accdata() clears SCTLR_EL1_EnAS0. Executing st64bv0 in
the child then traps with SIGBUS, while regular accesses still reach MMIO.
[ ... ]
> +static int platform_accel_do_platform_probe(struct platform_device *pdev)
> +{
> + struct platform_accel *dev = platform_get_drvdata(pdev);
> + struct resource *r;
> + void __iomem *ret;
> +
> + ret = devm_platform_get_and_ioremap_resource(pdev, 0, &r);
> + if (IS_ERR(ret))
> + return PTR_ERR(ret);
[Severity: Low]
Is the kernel ioremap mapping created by
devm_platform_get_and_ioremap_resource() needed here?
The returned pointer is never used because the driver only exposes the
physical range to userspace via vm_iomap_memory(). Using
platform_get_resource() with devm_request_mem_region() avoids allocating
unused kernel virtual address space and page-table entries.
> + dev_info(&pdev->dev, "mmio at %pR\n", r);
> + dev->phys_base = r->start;
> + dev->phys_size = resource_size(r);
[Severity: Medium]
Should r->start and resource_size(r) be checked for PAGE_SIZE alignment?
If firmware provides a 4 KiB-aligned resource on a 16 KiB or 64 KiB page
arm64 kernel, __simple_ioremap_prep() silently rounds the base down and
size up to PAGE_SIZE boundaries. That exposes adjacent physical address
space to unprivileged userspace and shifts offset 0 of the mapping.
[ ... ]
> +static int platform_accel_probe(struct platform_device *pdev)
> +{
> + struct platform_accel *dev;
> + int err;
> +
> + if (!system_supports_ls64_accdata())
> + return -ENODEV;
[Severity: Medium]
Does platform_accel_probe() still succeed when CONFIG_ARM64_LS64_ACCDATA
is disabled?
system_supports_ls64_accdata() only checks the hardware CPU capability, so
the driver still creates the misc devices when CONFIG_ARM64_LS64_ACCDATA=n.
Userspace executing st64bv0 then hits try_enable_st64bv0(), which returns
false and delivers SIGBUS.
Checking IS_ENABLED(CONFIG_ARM64_LS64_ACCDATA) here, or depending on
ARM64_LS64_ACCDATA in Kconfig, prevents exposing unusable devices.
[ ... ]
> +static void platform_accel_remove(struct platform_device *pdev)
> +{
> + struct platform_accel *dev = platform_get_drvdata(pdev);
> +
> + mutex_lock(&dev->lock);
> + misc_deregister(&dev->misc);
> + dev->present = false;
> + platform_set_drvdata(pdev, NULL);
> + dev->pdev = NULL;
> + mutex_unlock(&dev->lock);
> +}
[Severity: Medium]
Can userspace retain live MMIO PTEs after platform_accel_remove() releases
the memory region?
misc_deregister() does not zap existing userspace VMAs, so after devres
releases the IORESOURCE_MEM region on unbind or hot-remove, processes with
an active mmap() keep writable VM_IO | VM_PFNMAP mappings pointing to the
released physical range.
Recording the inode mapping and calling unmap_mapping_range() during
removal (as uacce_remove() does) would revoke active mappings before
releasing the resource.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204144529.960326-1-svens@linux.ibm.com?part=3
next prev parent reply other threads:[~2026-12-04 15:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 14:45 [PATCH 0/3] Add arm on s390 accelerator driver Sven Schnelle
2026-12-04 14:45 ` [PATCH 1/3] iommu: sva: allow SVA without PASID Sven Schnelle
2026-12-04 15:12 ` sashiko-bot
2026-12-04 14:45 ` [PATCH 2/3] dt-bindings: firmware: platform-accel: add yaml documentation Sven Schnelle
2026-12-04 15:22 ` sashiko-bot
2026-12-05 13:18 ` Krzysztof Kozlowski
2026-12-04 14:45 ` [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver Sven Schnelle
2026-12-04 15:28 ` Arnd Bergmann
2026-12-04 15:45 ` sashiko-bot [this message]
2026-12-05 9:47 ` Uwe Kleine-König
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-250126@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=svens@linux.ibm.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.