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 4FCAE606A32C for ; Thu, 3 Dec 2026 01:11:16 +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=f7EqTJBx; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=UlZ/bCqh 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-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=O71O3/7kVwrypvhob9HTDM0860zKVLIXWypzNBkj0hw=; b=f7EqTJBxtYAlI/ fVbe8vJWk/GPx1avSGWfDiASxNNHpxeZb00zR48Jl9HYQFIWxFMkkQOJVXi023/6P9S8duVZNBOx/ hYt1alqMBXrWAAkD1iy6rp5LFkPT0iepnMs96WRwLaz7BXgNPGaBVq7L+tWiH8CEpSK2jKRkldp+v QQPiKEButpLy2AA7ZPKoMN2JTQUyBkE6SyLErTcATM+gjenImvGsG9sbOTxHB3hz4WuIShhtyHU6+ BzGc1mBQxvVsU6w6lfF+8Ip9eM4ScklAjTXTyLNlRyKZqzoqhL9teMRjLZhOpU8LSN0nyef8uIF1t ncGXyPZgqHC8clQpiVCg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYvLq-0000000D7BY-16HH; Thu, 03 Dec 2026 01:11:10 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYvLo-0000000D7BB-0BR9 for linux-arm-kernel@lists.infradead.org; Thu, 03 Dec 2026 01:11:09 +0000 Received: from localhost (unknown [4.194.122.162]) by linux.microsoft.com (Postfix) with ESMTPSA id CDF3C20B7166; Wed, 2 Dec 2026 17:10:52 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CDF3C20B7166 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1796260265; bh=O71O3/7kVwrypvhob9HTDM0860zKVLIXWypzNBkj0hw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=UlZ/bCqh0b37etmY4ZcXCh6ATiUju1Vzrb43vw8hrZfp6JQP/vf+r8SB9S5NVrevF fP0I4hM5DRkCYw3iZeeEFInH159xgW9rSQgq4U9mI+w+IuW3SJO7axJd06A5c9mTxT HW4S2jH2SeEAB9kvlpJkhzDarj+qlgmlJzTpO8b8= Date: Wed, 2 Dec 2026 17:10:49 -0800 From: Jacob Pan To: "Aneesh Kumar K.V (Arm)" Cc: linux-coco@lists.linux.dev, Alex Williamson , Alexey Kardashevskiy , Bjorn Helgaas , Catalin Marinas , 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, jacob.pan@linux.microsoft.com Subject: Re: [PATCH v10 14/18] iommufd/viommu: Identify physical IOMMU backing with a tag Message-ID: <20261202171049.00005214@linux.microsoft.com> In-Reply-To: <20261125081121.379481-15-aneesh.kumar@kernel.org> References: <20261125081121.379481-1-aneesh.kumar@kernel.org> <20261125081121.379481-15-aneesh.kumar@kernel.org> Organization: LSG X-Mailer: Claws Mail 4.4.0 (GTK 3.24.51; x86_64-w64-mingw32) X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-17.4 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,USER_AGENT_SANE_2 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_171108_111985_24EFC91A X-CRM114-Status: GOOD ( 21.53 ) X-Spam-Score: -4.4 (----) 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" Hi Aneesh, On Wed, 25 Nov 2026 13:41:17 +0530 "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; > + } > } > 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; > + } > } > > mutex_lock(&idev->igroup->lock); > diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h > index 5f5c67b24134..192d46b8ccfd 100644 > --- a/include/linux/iommufd.h > +++ b/include/linux/iommufd.h > @@ -98,9 +98,14 @@ void iommufd_access_detach(struct iommufd_access > *access); > void iommufd_ctx_get(struct iommufd_ctx *ictx); > > +enum iommufd_viommu_backing { > + IOMMUFD_VIOMMU_BACKING_IOMMU, > +}; > + > struct iommufd_viommu { > struct iommufd_object obj; > struct iommufd_ctx *ictx; > + enum iommufd_viommu_backing backing; > struct iommu_device *iommu_dev; > struct iommufd_hwpt_paging *hwpt; > struct file *kvm_file; Reviewed-by: Jacob Pan FYI, for MSHV/hypervisor external attachment viommu usage, I am considering a hypervisor-managed backing which does not require viommu->iommu_dev.