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=1796397137; b=SXVJKuZttE5lSBb+IpaeQiuYxwAjWfWfRy8hA07QEQl4gfoeogIP0mvY7emfz9myY2t1 ghiHbAOwKKigdehCn/SBuZsIF/zanUHavRL1S6ydu4c/ZJRS31FINWbazwx/HnUL32QMF 4xa2wadFAsVPvHFHB8qV/aMTbITlyRgCJu+9sSh6FReund1+CZPJefPQBv1CXC6RYEET9 b29GQBuGlfsLc7TbhS8Jcjdqdo6RY/RygRJdoRw2j2Aqos+rhUpvGhNZ/rH6LPjgBhjb0 Qf6Rd0VvQYuMRdi2nnMWKlx4Y3G7/rt4fppQ3DPQkzItzLM7so12zCTzGQ6IMI/BsaQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796397137; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=70PWd0J3nT7s54tBPC7TWXKbU89kGLxTVt7hQ3aAJbY=; b=MpCeZmAA2ecOYaZhUhOweAqDl3jmjUZORbXrpWjm4hUnBWPE3azsIUShsyMdNkgHOUW8 L5GwqjzRRLgGBfeNYRItXF7M+e+a8vw99nAUzkaYxHwyYlXYwHmeywYd87fzTOmL4G/OY YTuvoLyY3Hm5qLvp+AWhGs+wq7U8fwBoKxlmYFp1m8XNZCgIhcgrhOi0tEpTr3sitkcxE MU9ppXdboQ79uncPXzLeqxLmyPngPjbMtvJaz7wycEnNv9J9cVjG470AC+tPn3UuxjdBs NLbggVuaoj7nBaq6p2vunRwz07ryLowGAKiENx5q8levitjuNwedhnQBiMWlEo1pLgA== 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="GAHO/cFK"; 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 15FD5606A32C for ; Fri, 4 Dec 2026 15:12:17 +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=GAHO/cFK Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABFCF1F00934; Fri, 4 Dec 2026 15:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796397136; bh=70PWd0J3nT7s54tBPC7TWXKbU89kGLxTVt7hQ3aAJbY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=GAHO/cFKDAnmq5/CGvKMBOtJ5mg0C7HWbgdKlnF6QcLYot5y0X1Y8UfwlMnMEy4YC pcrY0Z67HxM697h5DdJAvmmXbrB3qu8Qr9Phg+e25COyf6fOX6huCOLjcyQcTW0fZn B2CF6d5Apu3ammoWem0YXdUkWHrCUcLUZsa9Wx4LFuh8X7TSbi9yRIGXFyadbnayFb l6+rn402X3Skr5u37BgNo6i1i/xLAHf+xvBWjX461N1Se6TPiUA9rzqmvPeRTlkH2U wT70EG6VxvrVFWQoR1S0aoIOxH9R7VbV4kyEI15ehnRBnfUS0uKzgkIrdbGLY8t++h CLdU5OcfrYU1g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/3] iommu: sva: allow SVA without PASID 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-2-svens@linux.ibm.com> References: <20261204144529.960326-1-svens@linux.ibm.com> <20261204144529.960326-2-svens@linux.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 15:12:16 +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 3 potential issues to consider: - [Medium] iommu: unlocked dev->iommu dereference races with iommu_init_device() - [Medium] iommu/sva: IOMMU_SVA stays under IOMMU_SUPPORT without selecting IOMMU_API - [Low] iommu/sva: misleading kernel-doc in iommu_sva_bind_device_no_iommu() -- commit 8cca46e12185238c9aeda86bc1c45d0a7bb8e5f9 Author: Arnd Bergmann iommu: sva: allow SVA without PASID This commit adds iommu_sva_bind_device_no_iommu() so devices without an IOMMU can install an iommu_mm_data object and allocate a global PASID on an mm_struct, and updates iommu_alloc_mm_data() and iommu_alloc_global_pasid() to handle a NULL dev->iommu. > diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c > index 9827cb8043635..b444f3483f6df 100644 > --- a/drivers/iommu/iommu-sva.c > +++ b/drivers/iommu/iommu-sva.c [ ... ] > @@ -156,6 +156,35 @@ struct iommu_sva *iommu_sva_bind_device(struct devic= e *dev, struct mm_struct *mm > } > EXPORT_SYMBOL_GPL(iommu_sva_bind_device); > =20 > +/** > + * iommu_sva_bind_device_no_iommu() - Bind a process address space to a = device without iommu > + * @dev: the device > + * @mm: the mm to bind, caller must hold a reference to mm_users > + * > + * Allow the use of shared virtual addressing on devices that transparen= tly > + * use the CPU's page table instead of an IOMMU. A global PASID is alloc= ated > + * in case the same process uses another device with an IOMMU later. > + * > + * The reference is held until the mm_struct is destroyed. [Severity: Low] Is "The reference is held until the mm_struct is destroyed" accurate? iommu_sva_bind_device_no_iommu() takes no reference on mm or dev and allocates no iommu_sva handle; only mm->iommu_mm and its global PASID remain allocated until mm_pasid_drop() runs in __mmdrop(). Describing the lifetime of mm->iommu_mm and that no explicit unbind is needed would avoid misleading callers. [ ... ] > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index b486b8bbd1fcd..1470bb9c1ca89 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -3827,17 +3827,24 @@ EXPORT_SYMBOL_GPL(iommu_detach_device_pasid); > ioasid_t iommu_alloc_global_pasid(struct device *dev) > { > int ret; > + unsigned int max_pasid; > =20 > - /* max_pasids =3D=3D 0 means that the device does not support PASID */ > - if (!dev->iommu->max_pasids) > + if (!dev->iommu) { > + /* no IOMMU but capable of enqcmd/st64bv0: pick any PASID */ > + max_pasid =3D IOMMU_PASID_INVALID - 1; > + } else if (dev->iommu->max_pasids) { > + /* > + * max_pasids is set up by vendor driver based on number of > + * PASID bits supported but the IDA allocation is inclusive. > + */ > + max_pasid =3D dev->iommu->max_pasids - 1; > + } else { > + /* max_pasids =3D=3D 0 means that the device does not support PASID */ > return IOMMU_PASID_INVALID; > + } [Severity: Medium] Can reading and dereferencing dev->iommu here without iommu_probe_device_lock race with iommu_init_device()? Previously, iommu_alloc_mm_data() and iommu_alloc_global_pasid() were only reached when dev->iommu_group was non-NULL, so __iommu_probe_device() returned early without touching dev->iommu. When iommu_sva_bind_device_no_iommu() runs with dev->iommu_group =3D=3D NULL, a concurrent iommu_device_register() scan via bus_iommu_probe() calls iommu_init_device(dev), which transiently allocates dev->iommu with max_pasids =3D=3D 0 and then frees it with kfree() in dev_iommu_free() under iommu_probe_device_lock: CPU0 CPU1 iommu_sva_bind_device_no_iommu() iommu_device_register() mutex_lock(&iommu_sva_lock) ... -> __iommu_probe_device() iommu_alloc_mm_data() lock(&iommu_probe_device_lock) iommu_alloc_global_pasid() iommu_init_device() dev_iommu_get(dev) dev->iommu =3D param if (!dev->iommu) /* non-NULL */ dev_iommu_free(dev) dev->iommu =3D NULL kfree(param) else if (dev->iommu->max_pasids) <-- use-after-free Depending on whether the compiler caches or reloads dev->iommu, this can cause a slab use-after-free read, a NULL pointer dereference, or a spurious -ENOSPC/-EOVERFLOW if transient max_pasids =3D=3D 0 is observed before kfree(). iommu_alloc_mm_data() has the same unlocked dev->iommu dereference, and iommu_sva_bind_device_no_iommu() also checks dev->iommu_group without iommu_probe_device_lock. [ ... ] > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index ef5043752a365..131595da295f7 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -1663,6 +1663,8 @@ static inline u32 mm_get_enqcmd_pasid(struct mm_str= uct *mm) > void mm_pasid_drop(struct mm_struct *mm); > struct iommu_sva *iommu_sva_bind_device(struct device *dev, > struct mm_struct *mm); > +int iommu_sva_bind_device_no_iommu(struct device *dev, > + struct mm_struct *mm); [Severity: Medium] Does selecting IOMMU_SVA from a no-IOMMU driver break the build when CONFIG_IOMMU_SUPPORT=3Dn? In drivers/iommu/Kconfig, config IOMMU_SVA stays nested inside if IOMMU_SUPPORT and selects IOMMU_MM_DATA without selecting IOMMU_API. When a no-IOMMU driver (such as commit "drivers: firmware: add ARM on s390 accelerator driver") selects IOMMU_SVA with CONFIG_IOMMU_SUPPORT=3Dn and nothing else enabling CONFIG_IOMMU_API, Kconfig warns about the unmet IOMMU_SUPPORT dependency and enables CONFIG_IOMMU_SVA and CONFIG_IOMMU_MM_DATA while CONFIG_IOMMU_API stays disabled. In that configuration, drivers/iommu/Makefile builds iommu-sva.o without iommu.o, while struct iommu_mm_data, struct dev_iommu, and the real iommu_alloc_global_pasid() remain inside #ifdef CONFIG_IOMMU_API in include/linux/iommu.h, causing compilation failures in mm_get_enqcmd_pasid() and iommu-sva.c. Moving config IOMMU_SVA outside if IOMMU_SUPPORT and adding select IOMMU_API (or factoring global PASID and iommu_mm_data out of CONFIG_IOMMU_API) would prevent both the warning and the build failure. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204144529.9603= 26-1-svens@linux.ibm.com?part=3D1