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 0EBDACA6007 for ; Thu, 8 Oct 2026 06:01:37 +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: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=q++wsWtVbwXkEf71+CgUoMe/MxicdoF4EDB7F0Rp1rg=; b=o81ZYB0M3ojho+2ru70xil9RNh 2BgW/m6WyluKKTsZ27yYOmlCE5rkbTmv/clm6ItCUA8uLdQcszG/l+TaSRVEd4UF1LqtuAply1ETy Qh+eDNB0DyKt+enVD3LtjUZ2d6YEV7ulS+ezhCzyDS+509i++G31+DuvFHgmuv2itaPhI9Ky0VqL6 PsVyd7GsXjKSx83h1cGnwZGlMaOSx5UnSUavnkyVKHd2js/fCSCuTZ0tpY+Mm6Xn3P+iFdAYmsyW5 Bis1MoWcUSuZ7otlyb6MnuJZJ3TPNb+N/uvyWh8jyHZ7+FMS4q5ROelzr3ZvPeB3F8+WfPzraeDrE /PDFtWow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xEhC6-00000003aox-3Wl6; Thu, 08 Oct 2026 06:01:30 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xEhC5-00000003aoS-3HT2 for linux-arm-kernel@lists.infradead.org; Thu, 08 Oct 2026 06:01:29 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 3F3D9601EF; Thu, 8 Oct 2026 06:01:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF8361F0089A; Thu, 8 Oct 2026 06:01:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791439289; bh=q++wsWtVbwXkEf71+CgUoMe/MxicdoF4EDB7F0Rp1rg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KRAhwlSAONJX2U/yDNASgdvntqtI3qacT3zhQQ0xU0IpW4Mbz8Ev7QzdzVkdfXLhM gW3N8z97HqXtyeiMCr6SG9IVpz/iNGz+HGPFk/tMxK0HPuVFdlySwrtOqo8xb85/R3 rZdwnRtHkPIZ4GxrYwYJ0zugeg2LjA9Q4lGRPvrrNbLhuxYQ5yDT1ekT0h4FBr0roE ay+lXJf1FbwKMAOOEzrZQj3QVHtmqno/lp8DpE9kCrVKlpU1axPjUKddVl9VlS1Js/ /qEPSj0cmFEkXus4NaQvI0zuXpGxZgORArPtPRvsqeXLeLkf24A+eqh4u1uksESTDA XT4mDbzyq62cw== From: "Aneesh Kumar K.V (Arm)" To: iommu@lists.linux.dev Cc: "Aneesh Kumar K.V (Arm)" , 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 , 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 Subject: [PATCH v7 08/16] iommufd/viommu: Keep a reference to the KVM file Date: Thu, 8 Oct 2026 11:29:47 +0530 Message-ID: <20261008055955.4014342-9-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261008055955.4014342-1-aneesh.kumar@kernel.org> References: <20261008055955.4014342-1-aneesh.kumar@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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); 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; -- 2.43.0