[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250729172621.00006344@huawei.com>
Date: Tue, 29 Jul 2025 17:26:21 +0100
From: Jonathan Cameron <Jonathan.Cameron@...wei.com>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@...nel.org>
CC: <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>, Jason Gunthorpe <jgg@...pe.ca>, "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 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?
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?
> + fput(filp);
> + return rc;
> +}
> +
> +static void viommu_put_kvm(struct iommufd_viommu *viommu)
> +{
> + fput(viommu->kvm_filp);
> + viommu->kvm_filp = NULL;
> +}
> +#endif
Powered by blists - more mailing lists