[2/6] uio_hv_generic: Query the ringbuffer size for device

Message ID 1708193020-14740-3-git-send-email-ssengar@linux.microsoft.com
State New
Headers
Series Low speed Hyper-V devices support |

Commit Message

Saurabh Singh Sengar Feb. 17, 2024, 6:03 p.m. UTC
  Query the ring buffer size from pre defined table per device.
Keep the size as is if the device doesn't have any preferred
ring size.

Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
---
 drivers/uio/uio_hv_generic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Comments

Greg KH Feb. 19, 2024, 8:50 a.m. UTC | #1
On Sat, Feb 17, 2024 at 10:03:36AM -0800, Saurabh Sengar wrote:
> Query the ring buffer size from pre defined table per device.
> Keep the size as is if the device doesn't have any preferred
> ring size.

What is the "as is" size?

> 
> Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
> ---
>  drivers/uio/uio_hv_generic.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
> index 20d9762331bd..4bda6b52e49e 100644
> --- a/drivers/uio/uio_hv_generic.c
> +++ b/drivers/uio/uio_hv_generic.c
> @@ -238,6 +238,7 @@ hv_uio_probe(struct hv_device *dev,
>  	struct hv_uio_private_data *pdata;
>  	void *ring_buffer;
>  	int ret;
> +	size_t ring_size = hv_dev_ring_size(channel);
>  
>  	/* Communicating with host has to be via shared memory not hypercall */
>  	if (!channel->offermsg.monitor_allocated) {
> @@ -245,12 +246,14 @@ hv_uio_probe(struct hv_device *dev,
>  		return -ENOTSUPP;
>  	}
>  
> +	if (!ring_size)
> +		ring_size = HV_RING_SIZE * PAGE_SIZE;

Why the magic * PAGE_SIZE here?

Where is it documented that ring_size is in pages?

And what happens when PAGE_SIZE is changed?  Why are you relying on that
arbritrary value to dictate your buffer sizes to a device that has
no relationship with PAGE_SIZE?

Yes, I know you are copying what was there today, but you have the
chance to rethink and most importantly, DOCUMENT this decision properly
now.

thanks,

greg k-h
  
Saurabh Singh Sengar Feb. 19, 2024, 9:40 a.m. UTC | #2
On Mon, Feb 19, 2024 at 09:50:54AM +0100, Greg KH wrote:
> On Sat, Feb 17, 2024 at 10:03:36AM -0800, Saurabh Sengar wrote:
> > Query the ring buffer size from pre defined table per device.
> > Keep the size as is if the device doesn't have any preferred
> > ring size.
> 
> What is the "as is" size?

I will elaborate more here.

> 
> > 
> > Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
> > ---
> >  drivers/uio/uio_hv_generic.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
> > index 20d9762331bd..4bda6b52e49e 100644
> > --- a/drivers/uio/uio_hv_generic.c
> > +++ b/drivers/uio/uio_hv_generic.c
> > @@ -238,6 +238,7 @@ hv_uio_probe(struct hv_device *dev,
> >  	struct hv_uio_private_data *pdata;
> >  	void *ring_buffer;
> >  	int ret;
> > +	size_t ring_size = hv_dev_ring_size(channel);
> >  
> >  	/* Communicating with host has to be via shared memory not hypercall */
> >  	if (!channel->offermsg.monitor_allocated) {
> > @@ -245,12 +246,14 @@ hv_uio_probe(struct hv_device *dev,
> >  		return -ENOTSUPP;
> >  	}
> >  
> > +	if (!ring_size)
> > +		ring_size = HV_RING_SIZE * PAGE_SIZE;
> 
> Why the magic * PAGE_SIZE here?
> 
> Where is it documented that ring_size is in pages?
> 
> And what happens when PAGE_SIZE is changed?  Why are you relying on that
> arbritrary value to dictate your buffer sizes to a device that has
> no relationship with PAGE_SIZE?
> 
> Yes, I know you are copying what was there today, but you have the
> chance to rethink and most importantly, DOCUMENT this decision properly
> now.

I agree PAGE_SIZE is not accurate here and we should use HV_HYP_PAGE_SIZE.
This can be further improved by using VMBUS_RING_SIZE macro.

However, I propose addressing this improvement in a separate patch, given
the are significant changes already present in this series.

- Saurabh


> 
> thanks,
> 
> greg k-h
  
Greg KH Feb. 19, 2024, 10:02 a.m. UTC | #3
On Mon, Feb 19, 2024 at 01:40:23AM -0800, Saurabh Singh Sengar wrote:
> On Mon, Feb 19, 2024 at 09:50:54AM +0100, Greg KH wrote:
> > On Sat, Feb 17, 2024 at 10:03:36AM -0800, Saurabh Sengar wrote:
> > > Query the ring buffer size from pre defined table per device.
> > > Keep the size as is if the device doesn't have any preferred
> > > ring size.
> > 
> > What is the "as is" size?
> 
> I will elaborate more here.
> 
> > 
> > > 
> > > Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
> > > ---
> > >  drivers/uio/uio_hv_generic.c | 7 +++++--
> > >  1 file changed, 5 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
> > > index 20d9762331bd..4bda6b52e49e 100644
> > > --- a/drivers/uio/uio_hv_generic.c
> > > +++ b/drivers/uio/uio_hv_generic.c
> > > @@ -238,6 +238,7 @@ hv_uio_probe(struct hv_device *dev,
> > >  	struct hv_uio_private_data *pdata;
> > >  	void *ring_buffer;
> > >  	int ret;
> > > +	size_t ring_size = hv_dev_ring_size(channel);
> > >  
> > >  	/* Communicating with host has to be via shared memory not hypercall */
> > >  	if (!channel->offermsg.monitor_allocated) {
> > > @@ -245,12 +246,14 @@ hv_uio_probe(struct hv_device *dev,
> > >  		return -ENOTSUPP;
> > >  	}
> > >  
> > > +	if (!ring_size)
> > > +		ring_size = HV_RING_SIZE * PAGE_SIZE;
> > 
> > Why the magic * PAGE_SIZE here?
> > 
> > Where is it documented that ring_size is in pages?
> > 
> > And what happens when PAGE_SIZE is changed?  Why are you relying on that
> > arbritrary value to dictate your buffer sizes to a device that has
> > no relationship with PAGE_SIZE?
> > 
> > Yes, I know you are copying what was there today, but you have the
> > chance to rethink and most importantly, DOCUMENT this decision properly
> > now.
> 
> I agree PAGE_SIZE is not accurate here and we should use HV_HYP_PAGE_SIZE.
> This can be further improved by using VMBUS_RING_SIZE macro.
> 
> However, I propose addressing this improvement in a separate patch, given
> the are significant changes already present in this series.

Add it as a new patch to the series makes sense, thanks!

greg k-h
  
Saurabh Singh Sengar Feb. 19, 2024, 10:21 a.m. UTC | #4
On Mon, Feb 19, 2024 at 11:02:54AM +0100, Greg KH wrote:
> On Mon, Feb 19, 2024 at 01:40:23AM -0800, Saurabh Singh Sengar wrote:
> > On Mon, Feb 19, 2024 at 09:50:54AM +0100, Greg KH wrote:
> > > On Sat, Feb 17, 2024 at 10:03:36AM -0800, Saurabh Sengar wrote:
> > > > Query the ring buffer size from pre defined table per device.
> > > > Keep the size as is if the device doesn't have any preferred
> > > > ring size.
> > > 
> > > What is the "as is" size?
> > 
> > I will elaborate more here.
> > 
> > > 
> > > > 
> > > > Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
> > > > ---
> > > >  drivers/uio/uio_hv_generic.c | 7 +++++--
> > > >  1 file changed, 5 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
> > > > index 20d9762331bd..4bda6b52e49e 100644
> > > > --- a/drivers/uio/uio_hv_generic.c
> > > > +++ b/drivers/uio/uio_hv_generic.c
> > > > @@ -238,6 +238,7 @@ hv_uio_probe(struct hv_device *dev,
> > > >  	struct hv_uio_private_data *pdata;
> > > >  	void *ring_buffer;
> > > >  	int ret;
> > > > +	size_t ring_size = hv_dev_ring_size(channel);
> > > >  
> > > >  	/* Communicating with host has to be via shared memory not hypercall */
> > > >  	if (!channel->offermsg.monitor_allocated) {
> > > > @@ -245,12 +246,14 @@ hv_uio_probe(struct hv_device *dev,
> > > >  		return -ENOTSUPP;
> > > >  	}
> > > >  
> > > > +	if (!ring_size)
> > > > +		ring_size = HV_RING_SIZE * PAGE_SIZE;
> > > 
> > > Why the magic * PAGE_SIZE here?
> > > 
> > > Where is it documented that ring_size is in pages?
> > > 
> > > And what happens when PAGE_SIZE is changed?  Why are you relying on that
> > > arbritrary value to dictate your buffer sizes to a device that has
> > > no relationship with PAGE_SIZE?
> > > 
> > > Yes, I know you are copying what was there today, but you have the
> > > chance to rethink and most importantly, DOCUMENT this decision properly
> > > now.
> > 
> > I agree PAGE_SIZE is not accurate here and we should use HV_HYP_PAGE_SIZE.
> > This can be further improved by using VMBUS_RING_SIZE macro.
> > 
> > However, I propose addressing this improvement in a separate patch, given
> > the are significant changes already present in this series.
> 
> Add it as a new patch to the series makes sense, thanks!

Sure, will add in V2.

- Saurabh

> 
> greg k-h
  

Patch

diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
index 20d9762331bd..4bda6b52e49e 100644
--- a/drivers/uio/uio_hv_generic.c
+++ b/drivers/uio/uio_hv_generic.c
@@ -238,6 +238,7 @@  hv_uio_probe(struct hv_device *dev,
 	struct hv_uio_private_data *pdata;
 	void *ring_buffer;
 	int ret;
+	size_t ring_size = hv_dev_ring_size(channel);
 
 	/* Communicating with host has to be via shared memory not hypercall */
 	if (!channel->offermsg.monitor_allocated) {
@@ -245,12 +246,14 @@  hv_uio_probe(struct hv_device *dev,
 		return -ENOTSUPP;
 	}
 
+	if (!ring_size)
+		ring_size = HV_RING_SIZE * PAGE_SIZE;
+
 	pdata = devm_kzalloc(&dev->device, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
 		return -ENOMEM;
 
-	ret = vmbus_alloc_ring(channel, HV_RING_SIZE * PAGE_SIZE,
-			       HV_RING_SIZE * PAGE_SIZE);
+	ret = vmbus_alloc_ring(channel, ring_size, ring_size);
 	if (ret)
 		return ret;