Re: [PATCH rdma-next 1/3] RDMA/core: Share driver structure size with core

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jan 28, 2019 at 05:53:35AM -0700, Leon Romanovsky wrote:
> On Sun, Jan 27, 2019 at 08:56:07PM +0200, Leon Romanovsky wrote:
> > From: Leon Romanovsky <leonro@xxxxxxxxxxxx>
> >
> > Add new macros to be used in drivers while registering ops structure
> > and IB/core while calling allocation routines, so drivers won't need
> > to perform kzalloc/kfree in their paths.
> >
> > The change in allocation stage allows us to initialize common fields
> > prior to calling to drivers (e.g. restrack).
> >
> > Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx>
> >  drivers/infiniband/core/device.c | 2 ++
> >  include/rdma/ib_verbs.h          | 8 ++++++++
> >  2 files changed, 10 insertions(+)
> >
> > diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
> > index d13491b416dc..c332398376fc 100644
> > +++ b/drivers/infiniband/core/device.c
> > @@ -1221,6 +1221,8 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
> >  				(ptr)->name = ops->name;                       \
> >  	} while (0)
> >
> > +#define SET_OBJ_SIZE(ptr, name) SET_DEVICE_OP(ptr, size_##name)
> > +
> >  	SET_DEVICE_OP(dev_ops, add_gid);
> >  	SET_DEVICE_OP(dev_ops, advise_mr);
> >  	SET_DEVICE_OP(dev_ops, alloc_dm);
> > diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
> > index d54c87640f89..a1f097fa33f2 100644
> > +++ b/include/rdma/ib_verbs.h
> > @@ -2264,6 +2264,14 @@ struct ib_counters_read_attr {
> >
> >  struct uverbs_attr_bundle;
> >
> > +#define INIT_RDMA_DRIVER_SIZE(ib_struct, drv_struct, member)                   \
> > +	.size_##ib_struct =                                                    \
> > +		(sizeof(struct drv_struct) +                                   \
> > +		 BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)))
> > +
> > +#define RDMA_DRIVER_SIZE(_ib_dev, ib_struct) (_ib_dev->ops.size_##ib_struct)
> > +#define DECLARE_RDMA_DRIVER_SIZE(ib_struct) size_t size_##ib_struct
> > +
> 
> I finally found how to write variant of this macro that will ensure that
> first embedded field has the same type as requested.
> 
> Please use this fixup.
> 
> diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
> index 02cde5e10712..bbacf30e9443 100644
> +++ b/include/rdma/ib_verbs.h
> @@ -2267,7 +2267,10 @@ struct uverbs_attr_bundle;
>  #define INIT_RDMA_DRIVER_SIZE(ib_struct, drv_struct, member)                   \
>  	.size_##ib_struct =                                                    \
>  		(sizeof(struct drv_struct) +                                   \
> -		 BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)))
> +		 BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)) +      \
> +		 BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(              \
> +			 typeof(((struct drv_struct *)NULL)->member),          \
> +			 struct ib_struct)))

This should also just be container of..

#define INIT_RDMA_DRIVER_SIZE(ib_struct, drv_struct, member)                   \
	.size_##ib_struct =                                                    \
		(sizeof(*container_of((struct ib_struct *)NULL,                \
				      struct drv_struct, member)) +            \
		 BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)))

Jason




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux