From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA390606A32D for ; Fri, 4 Dec 2026 06:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=4E+JB+ZI; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DZ3TMb+6 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=yMAFaiSmKJZoNcrXcbt0TbR8BkQBz7nXnsYno4SNEag=; b=4E+JB+ZITorMEalXWGL2CD2kYr G9rw8/6jgZdOkGHyEayAagPWt4u+qVw2F9/wOJKhaSiwhqfI4Fosmpaoi98cl/PcEiP5juOuP+crL uBSLITuUmHHvadSPSwKpNEZ/v+n6vlujz/fWXeURILTYzlujul50BwC5vUwzCSOsQoVHLQyxhoX97 y6oiRldHZ5sZugex9M5J10SXIx+750YRwjbAn5mn0lZq01T+/ZbOO3onWo5GUSRQA/uQYNhz7MKgb 3lTfJW6lQzuJVu7zKKuoyS6WpsscIKj9bPZmw0lCFEi5N7eV0F9tYEXViMqVab4iRH9uteuVXvbyR 0vWVsu/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZNGO-0000000Gri8-0TOB; Fri, 04 Dec 2026 06:59:39 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZNGB-0000000GrgM-0zya for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 06:59:21 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id ADC9240DF9; Fri, 4 Dec 2026 06:59:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61AB01F000C2; Fri, 4 Dec 2026 06:59:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796367550; bh=yMAFaiSmKJZoNcrXcbt0TbR8BkQBz7nXnsYno4SNEag=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=DZ3TMb+6pS+U88of+9LRwcjUc+oqirIOHJIXi8lCfglYFqwXOWqJCU3GlhkTZkBg/ MkKG2brh5jBjimzEAh1jsL+5AOLbd+VcN7wjc1MO2FtQvdy0Hww4krjC+1xrCRHGKC aQrK42CwFNgO98MTW8puZeXwFrwWU0GytydxGh9qNnUpMaU8MJdm1k++kqdC4D7MWJ R4J/3lIe4palAEzABbhRBFjIzvzmH1hYoEVjOjL/oJiWxo+F/QoBJr5MXbQEBeQjnd iBNKwI8Y7mM9fiT0kGdH3B9q8b7BE+onRkM3V5e/Ddx8oHRqExINk7+xGBJZvB6vUe ymqKwjxsxmxGQ== X-Mailer: emacs 31.1 (via feedmail 11-beta-1 I) From: Aneesh Kumar K.V To: Baolu Lu , linux-coco@lists.linux.dev Cc: baolu.lu@linux.intel.com, Alex Williamson , Alexey Kardashevskiy , Bjorn Helgaas , Catalin Marinas , Jacob Pan , Jason Gunthorpe , Joerg Roedel , Jonathan Cameron , Jonathan Hunter , Kevin Tian , Krishna Reddy , Lukas Wunner , Nicolin Chen , Robin Murphy , Samuel Ortiz , Shameer Kolothum , Steven Price , Suravee Suthikulpanit , Suzuki K Poulose , Thierry Reding , Vasant Hegde , Will Deacon , Xu Yilun , Ashish Kalra , Herbert Xu , Jonathan Cameron , Tom Lendacky , kvm@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH v10 14/18] iommufd/viommu: Identify physical IOMMU backing with a tag In-Reply-To: References: <20261125081121.379481-1-aneesh.kumar@kernel.org> <20261125081121.379481-15-aneesh.kumar@kernel.org> <9517555a-ca6f-4a6e-afcb-4414729ade5a@linux.intel.com> Date: Fri, 04 Dec 2026 12:28:57 +0530 Message-ID: X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-16.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Aneesh Kumar K.V writes: > Baolu Lu writes: > >> On 11/25/2026 4:11 PM, Aneesh Kumar K.V (Arm) wrote: >>> When allocating a vDEVICE or nested HWPT, IOMMUFD checks that the device >>> and its vIOMMU use the same physical IOMMU. >>> >>> The next patch adds vIOMMUs implemented by a TSM. These store a TSM >>> pointer instead of a physical IOMMU pointer, so the same comparison >>> cannot be used. >>> >>> Add a backing field to identify vIOMMUs that use a physical IOMMU, and >>> perform the comparison only for those vIOMMUs. All existing vIOMMUs >>> select that value, so their behavior is unchanged. >>> >>> Signed-off-by: Aneesh Kumar K.V (Arm) >>> --- >>> drivers/iommu/iommufd/hw_pagetable.c | 10 ++++++---- >>> drivers/iommu/iommufd/viommu.c | 11 +++++++---- >>> include/linux/iommufd.h | 5 +++++ >>> 3 files changed, 18 insertions(+), 8 deletions(-) >>> >>> diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c >>> index ae62db50885c..859eadf05f1d 100644 >>> --- a/drivers/iommu/iommufd/hw_pagetable.c >>> +++ b/drivers/iommu/iommufd/hw_pagetable.c >>> @@ -404,10 +404,12 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd) >>> struct iommufd_viommu *viommu; >>> >>> viommu = container_of(pt_obj, struct iommufd_viommu, obj); >>> - iommu_dev = iommufd_device_get_iommu_dev(idev); >>> - if (!iommu_dev || viommu->iommu_dev != iommu_dev) { >>> - rc = -EINVAL; >>> - goto out_unlock; >>> + if (viommu->backing == IOMMUFD_VIOMMU_BACKING_IOMMU) { >>> + iommu_dev = iommufd_device_get_iommu_dev(idev); >>> + if (!iommu_dev || viommu->iommu_dev != iommu_dev) { >>> + rc = -EINVAL; >>> + goto out_unlock; >>> + } >> >> What happens when viommu->backing != IOMMUFD_VIOMMU_BACKING_IOMMU? A >> nested hwpt is not valid for such a viommu, but this code skips the >> check and still calls iommufd_viommu_alloc_hwpt_nested(). That function >> dereferences viommu->iommu_dev->ops, which after the next patch aliases >> tsm_dev. How about rejecting it explicitly: >> >> if (viommu->backing != IOMMUFD_VIOMMU_BACKING_IOMMU) { >> rc = -EOPNOTSUPP; >> goto out_unlock; >> } >> > > I add a similar check in PATCH 16 https://patch.msgid.link/20261125081121.379481-17-aneesh.kumar@kernel.org > I can move that check into this patch. > >> >> iommu_dev = iommufd_device_get_iommu_dev(idev); >> if (!iommu_dev || viommu->iommu_dev != iommu_dev) { >> rc = -EINVAL; >> goto out_unlock; >> } >> >>> } >>> hwpt_nested = iommufd_viommu_alloc_hwpt_nested( >>> viommu, cmd->flags, &user_data); >>> diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c >>> index 472381b96a8e..dab499d24c45 100644 >>> --- a/drivers/iommu/iommufd/viommu.c >>> +++ b/drivers/iommu/iommufd/viommu.c >>> @@ -105,6 +105,7 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) >>> * pluggable IOMMU instance (if exists) is responsible for refcounting >>> * on its own. >>> */ >>> + viommu->backing = IOMMUFD_VIOMMU_BACKING_IOMMU; >>> viommu->iommu_dev = iommu_dev; >>> >>> rc = ops->viommu_init(viommu, idev->dev, >>> @@ -218,10 +219,12 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd) >>> goto out_put_idev; >>> } >>> >>> - iommu_dev = iommufd_device_get_iommu_dev(idev); >>> - if (!iommu_dev || viommu->iommu_dev != iommu_dev) { >>> - rc = -EINVAL; >>> - goto out_put_idev; >>> + if (viommu->backing == IOMMUFD_VIOMMU_BACKING_IOMMU) { >>> + iommu_dev = iommufd_device_get_iommu_dev(idev); >>> + if (!iommu_dev || viommu->iommu_dev != iommu_dev) { >>> + rc = -EINVAL; >>> + goto out_put_idev; >>> + } >> >> Similar concern here, although a tsm-backed viommu does need vdevices, >> so this path can't simply be rejected. Skipping the check means the core >> accepts any idev for a tsm viommu, without verifying that the device is >> managed by viommu->tsm_dev. >> > > > cca_vdevice_init() performs the required check. This keeps the vIOMMU > backing validation close to where it is used. I can add a comment here > stating that vdevice_init() must validate the vIOMMU backing tag. > something like modified drivers/iommu/iommufd/hw_pagetable.c @@ -306,6 +306,10 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu *viommu, u32 flags, return ERR_PTR(-EOPNOTSUPP); if (!user_data->len) return ERR_PTR(-EOPNOTSUPP); + + if (viommu->backing != IOMMUFD_VIOMMU_BACKING_IOMMU) + return ERR_PTR(-EOPNOTSUPP); + if (!viommu->ops || !viommu->ops->alloc_domain_nested) return ERR_PTR(-EOPNOTSUPP); modified drivers/iommu/iommufd/viommu.c @@ -227,6 +227,11 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd) } } + /* + * vdevice_init() performs any additional device compatibility + * checks required by the vIOMMU backing. + */ + mutex_lock(&idev->igroup->lock); if (idev->destroying) { rc = -ENOENT;