lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241017163359.GB3559746@nvidia.com>
Date: Thu, 17 Oct 2024 13:33:59 -0300
From: Jason Gunthorpe <jgg@...dia.com>
To: Nicolin Chen <nicolinc@...dia.com>
Cc: kevin.tian@...el.com, will@...nel.org, joro@...tes.org,
	suravee.suthikulpanit@....com, robin.murphy@....com,
	dwmw2@...radead.org, baolu.lu@...ux.intel.com, shuah@...nel.org,
	linux-kernel@...r.kernel.org, iommu@...ts.linux.dev,
	linux-arm-kernel@...ts.infradead.org,
	linux-kselftest@...r.kernel.org, eric.auger@...hat.com,
	jean-philippe@...aro.org, mdf@...nel.org, mshavit@...gle.com,
	shameerali.kolothum.thodi@...wei.com, smostafa@...gle.com,
	yi.l.liu@...el.com, aik@....com, patches@...ts.linux.dev
Subject: Re: [PATCH v3 03/11] iommufd: Introduce IOMMUFD_OBJ_VIOMMU and its
 related struct

On Wed, Oct 09, 2024 at 09:38:03AM -0700, Nicolin Chen wrote:
> +	struct iommufd_viommu *(*viommu_alloc)(struct iommu_device *iommu_dev,
> +					       struct iommu_domain *domain,

Let's call this parent_domain ie nesting parent

> +/*
> + * Helpers for IOMMU driver to allocate driver structures that will be freed by
> + * the iommufd core. Yet, a driver is responsible for its own
> struct cleanup.

'own struct cleanup via the free callback'

> diff --git a/drivers/iommu/iommufd/viommu_api.c b/drivers/iommu/iommufd/viommu_api.c
> new file mode 100644
> index 000000000000..c1731f080d6b
> --- /dev/null
> +++ b/drivers/iommu/iommufd/viommu_api.c

Let's call this file driver.c to match CONFIG_IOMMUFD_DRIVER

> +struct iommufd_viommu *
> +__iommufd_viommu_alloc(struct iommufd_ctx *ictx, size_t size,
> +		       const struct iommufd_viommu_ops *ops)
> +{
> +	struct iommufd_viommu *viommu;
> +	struct iommufd_object *obj;
> +
> +	if (WARN_ON(size < sizeof(*viommu)))
> +		return ERR_PTR(-EINVAL);

The macro does this already

> +	obj = iommufd_object_alloc_elm(ictx, size, IOMMUFD_OBJ_VIOMMU);
> +	if (IS_ERR(obj))
> +		return ERR_CAST(obj);
> +	viommu = container_of(obj, struct iommufd_viommu, obj);

And this too..

> +	if (ops)
> +		viommu->ops = ops;

No need for an if...

It could just be in the macro which is a bit appealing given we want
this linked into the drivers..

/*
 * Helpers for IOMMU driver to allocate driver structures that will be freed by
 * the iommufd core. The free op will be called prior to freeing the memory.
 */
#define iommufd_viommu_alloc(ictx, drv_struct, member, viommu_ops)            \
	({                                                                    \
		struct drv_struct *ret;                                       \
                                                                              \
		static_assert(                                                \
			__same_type(struct iommufd_viommu,                    \
				    ((struct drv_struct *)NULL)->member));    \
		static_assert(offsetof(struct drv_struct, member.obj) == 0);  \
		ret = (struct drv_struct *)iommufd_object_alloc_elm(          \
			ictx, sizeof(struct drv_struct), IOMMUFD_OBJ_VIOMMU); \
		ret->member.ops = viommu_ops;                                 \
		ret;                                                          \
	})

Jason

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ