[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250729231630.GI26511@ziepe.ca>
Date: Tue, 29 Jul 2025 20:16:30 -0300
From: Jason Gunthorpe <jgg@...pe.ca>
To: Jonathan Cameron <Jonathan.Cameron@...wei.com>
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@...nel.org>,
linux-coco@...ts.linux.dev, kvmarm@...ts.linux.dev,
linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
aik@....com, lukas@...ner.de, Samuel Ortiz <sameo@...osinc.com>,
Xu Yilun <yilun.xu@...ux.intel.com>,
Suzuki K Poulose <Suzuki.Poulose@....com>,
Steven Price <steven.price@....com>,
Catalin Marinas <catalin.marinas@....com>,
Marc Zyngier <maz@...nel.org>, Will Deacon <will@...nel.org>,
Oliver Upton <oliver.upton@...ux.dev>
Subject: Re: [RFC PATCH v1 07/38] iommufd/viommu: Add support to associate
viommu with kvm instance
On Tue, Jul 29, 2025 at 05:26:21PM +0100, Jonathan Cameron wrote:
> On Mon, 28 Jul 2025 19:21:44 +0530
> "Aneesh Kumar K.V (Arm)" <aneesh.kumar@...nel.org> wrote:
>
> > The associated kvm instance will be used in later patch by iommufd to
> > bind a tdi to kvm.
> >
> > Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@...nel.org>
> > ---
> > drivers/iommu/iommufd/viommu.c | 45 +++++++++++++++++++++++++++++++++-
> > include/linux/iommufd.h | 3 +++
> > include/uapi/linux/iommufd.h | 12 +++++++++
> > 3 files changed, 59 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
> > index 2ca5809b238b..59f1e1176f7f 100644
> > --- a/drivers/iommu/iommufd/viommu.c
> > +++ b/drivers/iommu/iommufd/viommu.c
> > @@ -2,6 +2,36 @@
> > /* Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES
> > */
> > #include "iommufd_private.h"
> > +#include "linux/tsm.h"
> > +
> > +#if IS_ENABLED(CONFIG_KVM)
> > +#include <linux/kvm_host.h>
> > +
> > +static int viommu_get_kvm(struct iommufd_viommu *viommu, int kvm_vm_fd)
> > +{
> > + int rc = -EBADF;
> > + struct file *filp;
> > +
> > + filp = fget(kvm_vm_fd);
> > +
> > + if (!file_is_kvm(filp))
> > + goto err_out;
> > +
> > + /* hold the kvm reference via file descriptor */
> > + viommu->kvm_filp = filp;
> > + return 0;
> > +err_out:
> > + viommu->kvm_filp = NULL;
>
> Is this to undo side effects from this function on error?
>
> kvm_filp is only set after all error paths so maybe this isn't
> needed?
Looks like you are right to me
> If this isn't needed then use __free(fput) and no_free_ptr() to
> deal with filp more simply and in teh erorr path can just return -EBADF
> directly rather than the goto.
>
> Or are we avoiding that stuff in iommufd?
Nope, gentle obvious use is fine :)
Jason
Powered by blists - more mailing lists