mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: Vasant Hegde <vasant.hegde@amd.com>,
	linux-coco@lists.linux.dev, iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Jason Gunthorpe <jgg@ziepe.ca>,
	Alexey Kardashevskiy <aik@amd.com>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Joerg Roedel <joro@8bytes.org>,
	Jonathan Cameron <jic23@kernel.org>,
	Kevin Tian <kevin.tian@intel.com>,
	Nicolin Chen <nicolinc@nvidia.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Steven Price <steven.price@arm.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Will Deacon <will@kernel.org>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [RFC PATCH v6 04/11] iommufd/viommu: Keep a reference to the KVM file
Date: Fri, 02 Oct 2026 10:56:03 +0530	[thread overview]
Message-ID: <yq5ay0cgu104.fsf@kernel.org> (raw)
In-Reply-To: <76d51545-47d3-4ef7-bb10-551c898c0968@amd.com>

Vasant Hegde <vasant.hegde@amd.com> writes:

> On 9/17/2026 7:31 PM, Aneesh Kumar K.V (Arm) wrote:
>> From: Nicolin Chen <nicolinc@nvidia.com>
>> 
>> 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 <shameerali.kolothum.thodi@huawei.com>
>> 
>> [nicolinc: hold kvm's users_count]
>> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
>> [aneesh.kumar: Switch to use kvm_file]
>> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
>> ---
>>  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 4081deda9b33..bf5d58d55939 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 <linux/file.h>
>>  #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);
>>  }
>>  
>> @@ -76,6 +79,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);
>
> Nice! This is needed for AMD IOMMU as well!
>
> Minor nit. You have to add fput() in error path.

The error path is handled by iommufd_viommu_destroy().
iommufd_fops_ioctl() calls either destroy or finalize, as required.

-aneesh

  reply	other threads:[~2026-10-02  5:26 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 14:01 [RFC PATCH v6 00/11] iommufd: Infrastructure for vIOMMU creation for confidential guests and guest TSM requests Aneesh Kumar K.V (Arm)
2026-09-17 14:01 ` [RFC PATCH v6 01/11] vfio: cache KVM VM file references instead of raw struct kvm pointers Aneesh Kumar K.V (Arm)
2026-09-24 19:41   ` Jason Gunthorpe
2026-09-30  7:19     ` Aneesh Kumar K.V
2026-09-17 14:01 ` [RFC PATCH v6 02/11] vfio: cdev: Reject duplicate bind before updating KVM file Aneesh Kumar K.V (Arm)
2026-09-24  7:53   ` Tian, Kevin
2026-09-25  5:49     ` Aneesh Kumar K.V
2026-09-17 14:01 ` [RFC PATCH v6 03/11] iommufd/device: Associate KVM file pointer with iommufd_device Aneesh Kumar K.V (Arm)
2026-09-17 14:01 ` [RFC PATCH v6 04/11] iommufd/viommu: Keep a reference to the KVM file Aneesh Kumar K.V (Arm)
2026-09-30 13:28   ` Vasant Hegde
2026-10-02  5:26     ` Aneesh Kumar K.V [this message]
2026-09-17 14:01 ` [RFC PATCH v6 05/11] iommu: Add a helper to validate a vIOMMU parent Aneesh Kumar K.V (Arm)
2026-09-24 19:41   ` Jason Gunthorpe
2026-09-25  5:48     ` Aneesh Kumar K.V
2026-09-25 12:23       ` Jason Gunthorpe
2026-09-28 10:36         ` Aneesh Kumar K.V
2026-09-28 12:11           ` Jason Gunthorpe
2026-09-28 15:39             ` Aneesh Kumar K.V
2026-09-28 16:17               ` Jason Gunthorpe
2026-09-28 18:08                 ` Jacob Pan
2026-09-28 18:20                   ` Jason Gunthorpe
2026-09-28 22:24                     ` Jacob Pan
2026-09-28 23:03                       ` Jason Gunthorpe
2026-09-29  5:55                         ` Jacob Pan
2026-09-29 12:30                           ` Jason Gunthorpe
2026-09-29 23:15                             ` Jacob Pan
2026-09-29 23:30                               ` Jason Gunthorpe
2026-09-17 14:01 ` [RFC PATCH v6 06/11] iommu: Add a helper to query vIOMMU hardware parameters Aneesh Kumar K.V (Arm)
2026-09-24 19:41   ` Jason Gunthorpe
2026-09-25  5:59     ` Aneesh Kumar K.V
2026-09-25 12:29       ` Jason Gunthorpe
2026-09-17 14:01 ` [RFC PATCH v6 07/11] coco: tsm: Expose active-user lifetime references Aneesh Kumar K.V (Arm)
2026-09-17 14:01 ` [RFC PATCH v6 08/11] iommufd: Add vIOMMU provider support Aneesh Kumar K.V (Arm)
2026-09-24 19:41   ` Jason Gunthorpe
2026-09-25  6:08     ` Aneesh Kumar K.V
2026-09-25 12:39       ` Jason Gunthorpe
2026-09-28  3:41         ` Tian, Kevin
2026-09-29  6:14           ` Aneesh Kumar K.V
2026-09-29 12:17             ` Jason Gunthorpe
2026-09-29 12:45               ` Aneesh Kumar K.V
2026-09-29 13:06                 ` Jason Gunthorpe
2026-09-29 15:58                   ` Aneesh Kumar K.V
2026-09-29 19:10                     ` Jason Gunthorpe
2026-09-28 10:51         ` Aneesh Kumar K.V
2026-09-17 14:01 ` [RFC PATCH v6 09/11] iommufd: Add the vdevice TSM request ioctl Aneesh Kumar K.V (Arm)
2026-09-18 13:09   ` Alexey Kardashevskiy
2026-09-18 13:13     ` Jason Gunthorpe
2026-09-24 19:41   ` Jason Gunthorpe
2026-09-30  8:03     ` Aneesh Kumar K.V
2026-09-30 13:26       ` Vasant Hegde
2026-09-30 14:03         ` Jason Gunthorpe
2026-09-30 14:08       ` Jason Gunthorpe
2026-09-17 14:01 ` [RFC PATCH v6 10/11] PCI/TSM: Remove the legacy guest request interface Aneesh Kumar K.V (Arm)
2026-09-17 14:01 ` [RFC PATCH v6 11/11] PCI/TSM: Add reference-counted contexts for vdevice providers Aneesh Kumar K.V (Arm)
2026-09-24  8:17   ` Tian, Kevin
2026-09-24 19:41   ` Jason Gunthorpe
2026-09-25  8:15     ` Aneesh Kumar K.V
2026-09-28 18:47   ` Sonang Patel
2026-09-28 23:08     ` Jason Gunthorpe
2026-10-02  6:14       ` Aneesh Kumar K.V
2026-09-17 14:17 ` [RFC PATCH v6 00/11] iommufd: Infrastructure for vIOMMU creation for confidential guests and guest TSM requests Aneesh Kumar K.V
2026-09-24  7:48 ` Tian, Kevin
2026-09-24 19:20   ` Jason Gunthorpe
2026-09-28  3:35     ` Tian, Kevin
2026-09-28 13:08       ` Jason Gunthorpe
2026-09-25  8:29   ` Aneesh Kumar K.V
2026-09-28  3:41     ` Tian, Kevin
2026-09-28  3:55       ` Tian, Kevin
2026-09-24 19:09 ` Jason Gunthorpe
2026-09-25  6:46   ` Aneesh Kumar K.V
2026-09-25 12:45     ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yq5ay0cgu104.fsf@kernel.org \
    --to=aneesh.kumar@kernel.org \
    --cc=Suzuki.Poulose@arm.com \
    --cc=aik@amd.com \
    --cc=helgaas@kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=jic23@kernel.org \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=pbonzini@redhat.com \
    --cc=sameo@rivosinc.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=steven.price@arm.com \
    --cc=vasant.hegde@amd.com \
    --cc=will@kernel.org \
    --cc=yilun.xu@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®