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=1796365731; b=dD84swv5QFI9I5iDb3DbhNWDkW1RgBtkZfycUgJbtmbCgkdFe8+TPwgXLCOq1OFgC9RQ KQb3gdjSS0cS50hD4TL4D0+wFupNGi+ucZrmRjgeZNTmDe3jyU7gsBOAmsul9PPbJgXCq j9FGoxAt/EuWSvOjlA6yR+XTMHpNFFYh/8UXkchjutIXug0609J2yYYfZ6w/fV7jLLWNR 2be4DkHH5IA/uxckEFo2nGmC/aqdIc8hs7EIPOj/rovzuvssAmttDLFdq3geWIoXxsAOX nQYgHk7kNGjT8LD0wMdV57G5GBFYpU1gbW88dYwQRbEZ3Fp3uQa0+GTuWQi4HKvQHtg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796365731; h=Received:DKIM-Signature:X-Mailer:From:To:Cc:Subject:In-Reply-To: References:Date:Message-ID:MIME-Version:Content-Type; bh=VyeP43OD0oLG/6KZ9Xs87uogsCMQus8LEmHXh8B0hZs=; b=np94jboWQKIm34+W0eFmem9dkCuWl0XkRYRsa96q5XafFCosXxBCnLh9QDsovM2ElUvP 3FEY62RYoro2yk3yjhDB1pMbcrb/Pps1U/agCbu9kvqDYgEzX5F8k0cf6XG3SnfFunx9O weyXLmu7kn4ycJ7UOgBxaGXHiyRU9WBCKfBhoDeA15n0Eps9TDyE7vw06bPg3edNUodlk G6o/gTdbfp9mOhHnKY8W5x53JJx6l5PoU+VMTDb02WujeznJFB2mxm2Y5lI3FoK0MBkHm heabsObwZj0SAepVLJTWUzSlHxHg1xMusp1MFMFtY1lPRZPZCg07M+Ss6CqX6FuZFCg== 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="Nsxb/GvD"; 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 17F61606A322; Fri, 4 Dec 2026 06:28:50 +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=Nsxb/GvD Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23DFA1F000CE; Fri, 4 Dec 2026 06:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796365730; bh=VyeP43OD0oLG/6KZ9Xs87uogsCMQus8LEmHXh8B0hZs=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=Nsxb/GvDLSiFfPnZvlk9Hd7bwxqnffQQE3bhQeLy2m0Q0j9l1X/y/Qm7wNV2tg23O AGMp3AsZgqDNJuaOlZdVPAdBea1gUKly99sbgtO9apU3WrmImbXF1B3UakwpaQBfTj K82zZJhodo/A6tk02A7/kl8/UFpSOgpbHvuSUeKi7R8hgzX2hvOH8T4lmnTzPNuDEu XXciNVHQPvV9KRnNDGxRv+QAxg33k02UVsQzGn6TVjtmOR/GgaGwu78f9hvZO/HvLw /Nc94UnPQ3Kfajf2hHSjeU1H8UYmMcXKIh/a+yIzTaKN7pzYZj1cPcykLs+mROwpL3 lzZzIbSLcBFig== 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: <9517555a-ca6f-4a6e-afcb-4414729ade5a@linux.intel.com> 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 11:58:35 +0530 Message-ID: X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain 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. -aneesh