diff mbox series

[RFC,net-next,v1,1/3] vfio/mdev: Inherit dma masks of parent device

Message ID 1552082876-60228-2-git-send-email-parav@mellanox.com (mailing list archive)
State New, archived
Headers show
Series Support mlx5 mediated devices in host | expand

Commit Message

Parav Pandit March 8, 2019, 10:07 p.m. UTC
Inherit dma mask of parent device in child mdev devices, so that
protocol stack can use right dma mask while doing dma mappings.

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 drivers/vfio/mdev/mdev_core.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Alex Williamson March 8, 2019, 10:32 p.m. UTC | #1
On Fri,  8 Mar 2019 16:07:54 -0600
Parav Pandit <parav@mellanox.com> wrote:

> Inherit dma mask of parent device in child mdev devices, so that
> protocol stack can use right dma mask while doing dma mappings.
> 
> Signed-off-by: Parav Pandit <parav@mellanox.com>
> ---
>  drivers/vfio/mdev/mdev_core.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
> index 0212f0e..9b8bdc9 100644
> --- a/drivers/vfio/mdev/mdev_core.c
> +++ b/drivers/vfio/mdev/mdev_core.c
> @@ -315,6 +315,10 @@ int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid)
>  	mdev->dev.parent  = dev;
>  	mdev->dev.bus     = &mdev_bus_type;
>  	mdev->dev.release = mdev_device_release;
> +	mdev->dev.dma_mask = dev->dma_mask;
> +	mdev->dev.dma_parms = dev->dma_parms;
> +	mdev->dev.coherent_dma_mask = dev->coherent_dma_mask;
> +
>  	dev_set_name(&mdev->dev, "%pUl", uuid.b);
>  
>  	ret = device_register(&mdev->dev);

This seems like a rather large assumption and none of the existing mdev
drivers even make use of DMA ops.  Why shouldn't this be done in
mdev_parent_ops.create?  Thanks,

Alex
Parav Pandit March 9, 2019, 3:55 a.m. UTC | #2
> -----Original Message-----
> From: Alex Williamson <alex.williamson@redhat.com>
> Sent: Friday, March 8, 2019 4:33 PM
> To: Parav Pandit <parav@mellanox.com>
> Cc: netdev@vger.kernel.org; linux-kernel@vger.kernel.org;
> michal.lkml@markovi.net; davem@davemloft.net;
> gregkh@linuxfoundation.org; Jiri Pirko <jiri@mellanox.com>;
> kwankhede@nvidia.com; Vu Pham <vuhuong@mellanox.com>; Yuval Avnery
> <yuvalav@mellanox.com>; jakub.kicinski@netronome.com;
> kvm@vger.kernel.org
> Subject: Re: [RFC net-next v1 1/3] vfio/mdev: Inherit dma masks of parent
> device
> 
> On Fri,  8 Mar 2019 16:07:54 -0600
> Parav Pandit <parav@mellanox.com> wrote:
> 
> > Inherit dma mask of parent device in child mdev devices, so that
> > protocol stack can use right dma mask while doing dma mappings.
> >
> > Signed-off-by: Parav Pandit <parav@mellanox.com>
> > ---
> >  drivers/vfio/mdev/mdev_core.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/vfio/mdev/mdev_core.c
> > b/drivers/vfio/mdev/mdev_core.c index 0212f0e..9b8bdc9 100644
> > --- a/drivers/vfio/mdev/mdev_core.c
> > +++ b/drivers/vfio/mdev/mdev_core.c
> > @@ -315,6 +315,10 @@ int mdev_device_create(struct kobject *kobj,
> struct device *dev, uuid_le uuid)
> >  	mdev->dev.parent  = dev;
> >  	mdev->dev.bus     = &mdev_bus_type;
> >  	mdev->dev.release = mdev_device_release;
> > +	mdev->dev.dma_mask = dev->dma_mask;
> > +	mdev->dev.dma_parms = dev->dma_parms;
> > +	mdev->dev.coherent_dma_mask = dev->coherent_dma_mask;
> > +
> >  	dev_set_name(&mdev->dev, "%pUl", uuid.b);
> >
> >  	ret = device_register(&mdev->dev);
> 
> This seems like a rather large assumption and none of the existing mdev
> drivers even make use of DMA ops.
So its non-harmful anyway.

> Why shouldn't this be done in mdev_parent_ops.create?  Thanks,
> 
Struct device should be setup correctly before calling device_register().
That is the sane way to access device_register() API.
Doing this under mdev_parent_ops.create() will do it after device_register().
If you want to make it optional, mdev_register_device() can pass a bool flag to setup dma params or not which can be applied conditionally in mdev_device_create() before device_register().
diff mbox series

Patch

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 0212f0e..9b8bdc9 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -315,6 +315,10 @@  int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid)
 	mdev->dev.parent  = dev;
 	mdev->dev.bus     = &mdev_bus_type;
 	mdev->dev.release = mdev_device_release;
+	mdev->dev.dma_mask = dev->dma_mask;
+	mdev->dev.dma_parms = dev->dma_parms;
+	mdev->dev.coherent_dma_mask = dev->coherent_dma_mask;
+
 	dev_set_name(&mdev->dev, "%pUl", uuid.b);
 
 	ret = device_register(&mdev->dev);