From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01F8FCC6B1A for ; Wed, 14 Oct 2026 17:59:44 +0000 (UTC) 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-Owner; bh=w+LHJC/NB4yRzWoWwokMMEzOhdTsVA9ERhh/Ya3fyko=; b=ZQXmtySpdZqpqpgyeO53pUL0Si aWtnTHjjJM5Z2jWkkbqI+Q6JUo2H98Yd42zXZujWGmlB2O9DNobTj641w+kqycOfwTx0uT6BXXFGK CHwU8kOeoFbRf9EPeylnf56JzdP+KpVgoMQgKsh8PCXKpMGanscafxJBbPz7CU4HwwxvbJaQRw0Xu LA48/uivBFJFd+rmI6m3cJsYbSBRD7CF0OxQHNNraJ2ti8K446JW3X6egcbf5JisQI76MCtOhTix9 HOnryt7MhiqVBUmLPuoUEttFdRSMKdSgx/FtsACCKEBuYp72DqCaP+mKNS9ZTi8HdtL+1LU+lbmDs iNGW5ipQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xH3GH-0000000G7aQ-1LXM; Wed, 14 Oct 2026 17:59:33 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xH3GF-0000000G7Zq-0o8h for linux-arm-kernel@lists.infradead.org; Wed, 14 Oct 2026 17:59:32 +0000 Received: from localhost (unknown [4.194.122.144]) by linux.microsoft.com (Postfix) with ESMTPSA id BE38B20B7166; Wed, 14 Oct 2026 10:59:13 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BE38B20B7166 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1792000765; bh=w+LHJC/NB4yRzWoWwokMMEzOhdTsVA9ERhh/Ya3fyko=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=axoF8r+6w476cU0VGnnpnAmwmzXLi4bAV8TsfQtae96LkE3UE0UZC6O3c5c/ntdql eYvWFE3Uu7XqgcwhPPlZBwc4Nr6xACMFBQ+1papQUDT8vJHb9XQBWWus4QC50y/B7E w0dvyC+VBWj+UHjxKlTKAyFWiS0KwTtKwKFICy9c= Date: Wed, 14 Oct 2026 10:59:13 -0700 From: Jacob Pan To: "Aneesh Kumar K.V (Arm)" Cc: iommu@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 , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org, jacob.pan@linux.microsoft.com Subject: Re: [PATCH v7 08/16] iommufd/viommu: Keep a reference to the KVM file Message-ID: <20261014105913.00001217@linux.microsoft.com> In-Reply-To: <20261008055955.4014342-9-aneesh.kumar@kernel.org> References: <20261008055955.4014342-1-aneesh.kumar@kernel.org> <20261008055955.4014342-9-aneesh.kumar@kernel.org> Organization: LSG X-Mailer: Claws Mail 3.21.0 (GTK+ 2.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261014_105931_263636_6F401789 X-CRM114-Status: GOOD ( 22.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Aneesh, On Thu, 8 Oct 2026 11:29:47 +0530 "Aneesh Kumar K.V (Arm)" wrote: > From: Nicolin Chen > > The TSM vDevice operations need access to the KVM associated with the > device's vIOMMU. Save the device's KVM file in the iommufd_viommu > when the vIOMMU is allocated, and take a file reference so it remains > valid for the lifetime of the vIOMMU. > > Release the reference when the vIOMMU is destroyed. > > Based on an original patch by > Shameer Kolothum > > [nicolinc: hold kvm's users_count] > Signed-off-by: Nicolin Chen > [aneesh.kumar: Switch to use kvm_file] > Cc: jgg@ziepe.ca > Cc: kevin.tian@intel.com > Cc: joro@8bytes.org > Cc: will@kernel.org > Cc: robin.murphy@arm.com > Signed-off-by: Aneesh Kumar K.V (Arm) > --- > drivers/iommu/iommufd/viommu.c | 5 +++++ > include/linux/iommufd.h | 1 + > 2 files changed, 6 insertions(+) > > diff --git a/drivers/iommu/iommufd/viommu.c > b/drivers/iommu/iommufd/viommu.c index f7951057a1e5..b7489ed259bd > 100644 --- a/drivers/iommu/iommufd/viommu.c > +++ b/drivers/iommu/iommufd/viommu.c > @@ -1,6 +1,7 @@ > // SPDX-License-Identifier: GPL-2.0-only > /* Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES > */ > +#include > #include "iommufd_private.h" > > void iommufd_viommu_destroy(struct iommufd_object *obj) > @@ -11,6 +12,8 @@ void iommufd_viommu_destroy(struct iommufd_object > *obj) if (viommu->ops && viommu->ops->destroy) > viommu->ops->destroy(viommu); > refcount_dec(&viommu->hwpt->common.obj.users); > + if (viommu->kvm_file) > + fput(viommu->kvm_file); > xa_destroy(&viommu->vdevs); > } > > @@ -82,6 +85,8 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd > *ucmd) } > > xa_init(&viommu->vdevs); > + if (idev->kvm_file) > + viommu->kvm_file = get_file(idev->kvm_file); So kvm_file will persist inside viommu even when no more vdevice exists under the viommu. In that case, don't we need to check idev->kvm_file matches viommu->kvm_file during vdevice allocation? Otherwise, it appears possible to associate a device belonging to a different KVM VM with the existing vIOMMU, no? > viommu->type = cmd->type; > viommu->ictx = ucmd->ictx; > viommu->hwpt = hwpt_paging; > diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h > index 0a0bb4abfbd2..3267717f676d 100644 > --- a/include/linux/iommufd.h > +++ b/include/linux/iommufd.h > @@ -103,6 +103,7 @@ struct iommufd_viommu { > struct iommufd_ctx *ictx; > struct iommu_device *iommu_dev; > struct iommufd_hwpt_paging *hwpt; > + struct file *kvm_file; > > const struct iommufd_viommu_ops *ops; >