From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796399101; b=BIh9Uq9dDiA2I5nN5g19R6ymyylxxPgwS0E17Wxy1EMUQDfv9cvLq+OzLjBhluJgxdbF y9hJYddtKgs62dmkFIgJiP8JTF5qAK2xN1PMKFrwo8owye37YQf9sHae92cbJRTWIyZEf ReSxvTcvXJHMhERXrL1zoJ7ukjKE8miXVxURvme91p3qoXnPamn/ALRWmQv43n6tD9F5X 8HkzHBb+pV0x6plgq5WZDekYEqMjHdxoaQE4Zh0blK5KZ2ney52yKRL3z12Mf0Iis5IC5 zUc4ple5HYCpwLyjnlYf5d+gq/JQBxXNonpg+C29HVBg1UOrzWhMCir3bZG3iOVZ+RA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796399101; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=g5toDgkUv1SgbVqWlnnT903Uwk1frd5ksnvSwBSwLug=; b=FT9qBqTrwP2Em7rl98CFGBqYCZZUWFIDIedvfkkdo2NW8BPYRIxiKNjpFfFSVXc8bF4h S6ifaAShpMgt5W8FRp5I0QljioR6XpgjMBoj0uEufWjdSlqt6hH4n0BrOnou59loalK7r YVwPCceV96qUXwSAvNMhVThn7r6S1O/n8jB54CSiVASLhokeg/+B+krcjXVuEEe+137OK Nh4QD7RTip31XetOP5rZQxzkpDVbGW38BDwySXHauTy9dh2EhKrF2+bYo0s+1Rn3bjTIg T3BSLqIop5hlQ1cuCwRCypQoTbDSf3JHnGl0CevmZpQ2yi3sTqclUNDzNHZ9F+GIHCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ir0PPCQ7; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5358606A322 for ; Fri, 4 Dec 2026 15:45:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ir0PPCQ7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 316241F00A09; Fri, 4 Dec 2026 15:45:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796399101; bh=g5toDgkUv1SgbVqWlnnT903Uwk1frd5ksnvSwBSwLug=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ir0PPCQ7GLAL6PikLkNNRmDqVMGcz/kLACJGwPjpcU/YKdNASSCbZ5KCfCyNjp16L y59VYjSK65SHFzgbwzZXkjvP8YVVhD5plpIzUp5Xkw2hoy8IpUAOpV+XiuaPdBD17P KYFmXOQxay5XgUPAsjxdyyAco3am2CT7UZsrWiULldq5eFUrXeZdMd59d5KikejNJJ En6suzMqqvSla7HV0BMEiRYM0UUtrKS6WSB6FgRGY1390+TzJbYbb/+P6hiVw+/8c0 vQlfrZihsDCs7ROeoB41C9s5frZzLE0jEaPNL/kbeAXUSvfrHO7HJMhtQ4tY9DffgB W7wX1ZeZFCBWw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver Reply-To: sashiko-reviews@lists.linux.dev To: "Sven Schnelle" Cc: linux-s390@vger.kernel.org, "Heiko Carstens" , "Vasily Gorbik" , "Alexander Gordeev" , "Christian Borntraeger" In-Reply-To: <20261204144529.960326-4-svens@linux.ibm.com> References: <20261204144529.960326-1-svens@linux.ibm.com> <20261204144529.960326-4-svens@linux.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 15:45:00 +0000 X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 > =20 > endif # TURRIS_MOX_RWTM > =20 > +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=3Dn, 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/platfor= m-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 =3D filep->private_data; > + struct platform_accel *dev =3D container_of(misc, struct platform_accel= , misc); > + int ret =3D -ENODEV; > + > + mutex_lock(&dev->lock); > + if (!dev->present) > + goto out; > + > + ret =3D 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 =3D pgprot_device(vma->vm_page_prot); > + ret =3D 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 =3D platform_get_drvdata(pdev); > + struct resource *r; > + void __iomem *ret; > + > + ret =3D 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 =3D r->start; > + dev->phys_size =3D 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=3D= 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 =3D platform_get_drvdata(pdev); > + > + mutex_lock(&dev->lock); > + misc_deregister(&dev->misc); > + dev->present =3D false; > + platform_set_drvdata(pdev, NULL); > + dev->pdev =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204144529.9603= 26-1-svens@linux.ibm.com?part=3D3