LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] vsock/virtio: set vsock frontend ready in virtio_vsock_probe()
@ 2021-07-20  7:13 Xianting Tian
  2021-07-20  7:54 ` Jason Wang
  2021-07-20 10:23 ` Stefan Hajnoczi
  0 siblings, 2 replies; 8+ messages in thread
From: Xianting Tian @ 2021-07-20  7:13 UTC (permalink / raw)
  To: stefanha, sgarzare, davem, kuba, jasowang
  Cc: kvm, netdev, linux-kernel, Xianting Tian

Add the missed virtio_device_ready() to set vsock frontend ready.

Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
---
 net/vmw_vsock/virtio_transport.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index e0c2c992a..dc834b8fd 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -639,6 +639,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
 
 	mutex_unlock(&the_virtio_vsock_mutex);
 
+	virtio_device_ready(vdev);
+
 	return 0;
 
 out:
-- 
2.17.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] vsock/virtio: set vsock frontend ready in virtio_vsock_probe()
  2021-07-20  7:13 [PATCH v2] vsock/virtio: set vsock frontend ready in virtio_vsock_probe() Xianting Tian
@ 2021-07-20  7:54 ` Jason Wang
  2021-07-20  8:36   ` Xianting Tian
  2021-07-20 10:23 ` Stefan Hajnoczi
  1 sibling, 1 reply; 8+ messages in thread
From: Jason Wang @ 2021-07-20  7:54 UTC (permalink / raw)
  To: Xianting Tian, stefanha, sgarzare, davem, kuba; +Cc: kvm, netdev, linux-kernel


在 2021/7/20 下午3:13, Xianting Tian 写道:
> Add the missed virtio_device_ready() to set vsock frontend ready.
>
> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
> ---
>   net/vmw_vsock/virtio_transport.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
> index e0c2c992a..dc834b8fd 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -639,6 +639,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>   
>   	mutex_unlock(&the_virtio_vsock_mutex);
>   
> +	virtio_device_ready(vdev);
> +
>   	return 0;
>   
>   out:


Just notice this:

commit 5b40a7daf51812b35cf05d1601a779a7043f8414
Author: Rusty Russell <rusty@rustcorp.com.au>
Date:   Tue Feb 17 16:12:44 2015 +1030

     virtio: don't set VIRTIO_CONFIG_S_DRIVER_OK twice.

     I noticed this with the console device.  It's not *wrong*, just a bit
     weird.

     Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index b9f70dfc4751..5ce2aa48fc6e 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -236,7 +236,10 @@ static int virtio_dev_probe(struct device *_d)
         if (err)
                 goto err;

-       add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
+       /* If probe didn't do it, mark device DRIVER_OK ourselves. */
+       if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
+               virtio_device_ready(dev);
+
         if (drv->scan)
                 drv->scan(dev);

So I think we need to be consistent: switch to use virtio_device_ready() 
for all the drivers, and then we can remove this step and warn if 
(DRIVER_OK) is not set.

Thanks


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] vsock/virtio: set vsock frontend ready in virtio_vsock_probe()
  2021-07-20  7:54 ` Jason Wang
@ 2021-07-20  8:36   ` Xianting Tian
  0 siblings, 0 replies; 8+ messages in thread
From: Xianting Tian @ 2021-07-20  8:36 UTC (permalink / raw)
  To: Jason Wang, stefanha, sgarzare, davem, kuba; +Cc: kvm, netdev, linux-kernel

thanks for the findings.

Let me make furture patches to make consistent.

在 2021/7/20 下午3:54, Jason Wang 写道:
>
> 在 2021/7/20 下午3:13, Xianting Tian 写道:
>> Add the missed virtio_device_ready() to set vsock frontend ready.
>>
>> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
>> ---
>>   net/vmw_vsock/virtio_transport.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/net/vmw_vsock/virtio_transport.c 
>> b/net/vmw_vsock/virtio_transport.c
>> index e0c2c992a..dc834b8fd 100644
>> --- a/net/vmw_vsock/virtio_transport.c
>> +++ b/net/vmw_vsock/virtio_transport.c
>> @@ -639,6 +639,8 @@ static int virtio_vsock_probe(struct 
>> virtio_device *vdev)
>>         mutex_unlock(&the_virtio_vsock_mutex);
>>   +    virtio_device_ready(vdev);
>> +
>>       return 0;
>>     out:
>
>
> Just notice this:
>
> commit 5b40a7daf51812b35cf05d1601a779a7043f8414
> Author: Rusty Russell <rusty@rustcorp.com.au>
> Date:   Tue Feb 17 16:12:44 2015 +1030
>
>     virtio: don't set VIRTIO_CONFIG_S_DRIVER_OK twice.
>
>     I noticed this with the console device.  It's not *wrong*, just a bit
>     weird.
>
>     Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
>
> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> index b9f70dfc4751..5ce2aa48fc6e 100644
> --- a/drivers/virtio/virtio.c
> +++ b/drivers/virtio/virtio.c
> @@ -236,7 +236,10 @@ static int virtio_dev_probe(struct device *_d)
>         if (err)
>                 goto err;
>
> -       add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
> +       /* If probe didn't do it, mark device DRIVER_OK ourselves. */
> +       if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
> +               virtio_device_ready(dev);
> +
>         if (drv->scan)
>                 drv->scan(dev);
>
> So I think we need to be consistent: switch to use 
> virtio_device_ready() for all the drivers, and then we can remove this 
> step and warn if (DRIVER_OK) is not set.
>
> Thanks

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] vsock/virtio: set vsock frontend ready in virtio_vsock_probe()
  2021-07-20  7:13 [PATCH v2] vsock/virtio: set vsock frontend ready in virtio_vsock_probe() Xianting Tian
  2021-07-20  7:54 ` Jason Wang
@ 2021-07-20 10:23 ` Stefan Hajnoczi
  2021-07-20 10:56   ` Xianting Tian
  2021-07-20 11:05   ` Xianting Tian
  1 sibling, 2 replies; 8+ messages in thread
From: Stefan Hajnoczi @ 2021-07-20 10:23 UTC (permalink / raw)
  To: Xianting Tian; +Cc: sgarzare, davem, kuba, jasowang, kvm, netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1161 bytes --]

On Tue, Jul 20, 2021 at 03:13:37PM +0800, Xianting Tian wrote:
> Add the missed virtio_device_ready() to set vsock frontend ready.
> 
> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
> ---
>  net/vmw_vsock/virtio_transport.c | 2 ++
>  1 file changed, 2 insertions(+)

Please include a changelog when you send v2, v3, etc patches.

> 
> diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
> index e0c2c992a..dc834b8fd 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -639,6 +639,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>  
>  	mutex_unlock(&the_virtio_vsock_mutex);
>  
> +	virtio_device_ready(vdev);

Why is this patch necessary?

The core virtio_dev_probe() code already calls virtio_device_ready for
us:

  static int virtio_dev_probe(struct device *_d)
  {
      ...
      err = drv->probe(dev);
      if (err)
          goto err;
  
      /* If probe didn't do it, mark device DRIVER_OK ourselves. */
      if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
          virtio_device_ready(dev);

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] vsock/virtio: set vsock frontend ready in virtio_vsock_probe()
  2021-07-20 10:23 ` Stefan Hajnoczi
@ 2021-07-20 10:56   ` Xianting Tian
  2021-07-20 11:05   ` Xianting Tian
  1 sibling, 0 replies; 8+ messages in thread
From: Xianting Tian @ 2021-07-20 10:56 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: sgarzare, davem, kuba, jasowang, kvm, netdev, linux-kernel

OK,

thanks

在 2021/7/20 下午6:23, Stefan Hajnoczi 写道:
> On Tue, Jul 20, 2021 at 03:13:37PM +0800, Xianting Tian wrote:
>> Add the missed virtio_device_ready() to set vsock frontend ready.
>>
>> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
>> ---
>>   net/vmw_vsock/virtio_transport.c | 2 ++
>>   1 file changed, 2 insertions(+)
> Please include a changelog when you send v2, v3, etc patches.
>
>> diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
>> index e0c2c992a..dc834b8fd 100644
>> --- a/net/vmw_vsock/virtio_transport.c
>> +++ b/net/vmw_vsock/virtio_transport.c
>> @@ -639,6 +639,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>>   
>>   	mutex_unlock(&the_virtio_vsock_mutex);
>>   
>> +	virtio_device_ready(vdev);
> Why is this patch necessary?
>
> The core virtio_dev_probe() code already calls virtio_device_ready for
> us:
>
>    static int virtio_dev_probe(struct device *_d)
>    {
>        ...
>        err = drv->probe(dev);
>        if (err)
>            goto err;
>    
>        /* If probe didn't do it, mark device DRIVER_OK ourselves. */
>        if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
>            virtio_device_ready(dev);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] vsock/virtio: set vsock frontend ready in virtio_vsock_probe()
  2021-07-20 10:23 ` Stefan Hajnoczi
  2021-07-20 10:56   ` Xianting Tian
@ 2021-07-20 11:05   ` Xianting Tian
  2021-07-20 13:12     ` Stefan Hajnoczi
  1 sibling, 1 reply; 8+ messages in thread
From: Xianting Tian @ 2021-07-20 11:05 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: sgarzare, davem, kuba, jasowang, kvm, netdev, linux-kernel


在 2021/7/20 下午6:23, Stefan Hajnoczi 写道:
> On Tue, Jul 20, 2021 at 03:13:37PM +0800, Xianting Tian wrote:
>> Add the missed virtio_device_ready() to set vsock frontend ready.
>>
>> Signed-off-by: Xianting Tian<xianting.tian@linux.alibaba.com>
>> ---
>>   net/vmw_vsock/virtio_transport.c | 2 ++
>>   1 file changed, 2 insertions(+)
> Please include a changelog when you send v2, v3, etc patches.
OK, thanks.
>> diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
>> index e0c2c992a..dc834b8fd 100644
>> --- a/net/vmw_vsock/virtio_transport.c
>> +++ b/net/vmw_vsock/virtio_transport.c
>> @@ -639,6 +639,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>>   
>>   	mutex_unlock(&the_virtio_vsock_mutex);
>>   
>> +	virtio_device_ready(vdev);
> Why is this patch necessary?

Sorry, I didn't notice the check in virtio_dev_probe(),

As Jason comment,  I alsoe think we need to be consistent: switch to use 
virtio_device_ready() for all the drivers. What's opinion about this?

> The core virtio_dev_probe() code already calls virtio_device_ready for
> us:
>
>    static int virtio_dev_probe(struct device *_d)
>    {
>        ...
>        err = drv->probe(dev);
>        if (err)
>            goto err;
>    
>        /* If probe didn't do it, mark device DRIVER_OK ourselves. */
>        if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
>            virtio_device_ready(dev);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] vsock/virtio: set vsock frontend ready in virtio_vsock_probe()
  2021-07-20 11:05   ` Xianting Tian
@ 2021-07-20 13:12     ` Stefan Hajnoczi
  2021-07-21  1:30       ` Xianting Tian
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Hajnoczi @ 2021-07-20 13:12 UTC (permalink / raw)
  To: Xianting Tian; +Cc: sgarzare, davem, kuba, jasowang, kvm, netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2099 bytes --]

On Tue, Jul 20, 2021 at 07:05:39PM +0800, Xianting Tian wrote:
> 
> 在 2021/7/20 下午6:23, Stefan Hajnoczi 写道:
> > On Tue, Jul 20, 2021 at 03:13:37PM +0800, Xianting Tian wrote:
> > > Add the missed virtio_device_ready() to set vsock frontend ready.
> > > 
> > > Signed-off-by: Xianting Tian<xianting.tian@linux.alibaba.com>
> > > ---
> > >   net/vmw_vsock/virtio_transport.c | 2 ++
> > >   1 file changed, 2 insertions(+)
> > Please include a changelog when you send v2, v3, etc patches.
> OK, thanks.
> > > diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
> > > index e0c2c992a..dc834b8fd 100644
> > > --- a/net/vmw_vsock/virtio_transport.c
> > > +++ b/net/vmw_vsock/virtio_transport.c
> > > @@ -639,6 +639,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
> > >   	mutex_unlock(&the_virtio_vsock_mutex);
> > > +	virtio_device_ready(vdev);
> > Why is this patch necessary?
> 
> Sorry, I didn't notice the check in virtio_dev_probe(),
> 
> As Jason comment,  I alsoe think we need to be consistent: switch to use
> virtio_device_ready() for all the drivers. What's opinion about this?

According to the documentation the virtio_device_read() API is optional:

  /**
   * virtio_device_ready - enable vq use in probe function
   * @vdev: the device
   *
   * Driver must call this to use vqs in the probe function.
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   *
   * Note: vqs are enabled automatically after probe returns.
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   */

Many drivers do not use vqs during the ->probe() function. They don't
need to call virtio_device_ready(). That's why the virtio_vsock driver
doesn't call it.

But if a ->probe() function needs to send virtqueue buffers, e.g. to
query the device or activate some device feature, then the driver will
need to call it explicitly.

The documentation is clear and this design is less error-prone than
relying on all drivers to call it manually. I suggest leaving things
unchanged.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] vsock/virtio: set vsock frontend ready in virtio_vsock_probe()
  2021-07-20 13:12     ` Stefan Hajnoczi
@ 2021-07-21  1:30       ` Xianting Tian
  0 siblings, 0 replies; 8+ messages in thread
From: Xianting Tian @ 2021-07-21  1:30 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: sgarzare, davem, kuba, jasowang, kvm, netdev, linux-kernel

Got it.

thanks for the comments,


在 2021/7/20 下午9:12, Stefan Hajnoczi 写道:
> On Tue, Jul 20, 2021 at 07:05:39PM +0800, Xianting Tian wrote:
>> 在 2021/7/20 下午6:23, Stefan Hajnoczi 写道:
>>> On Tue, Jul 20, 2021 at 03:13:37PM +0800, Xianting Tian wrote:
>>>> Add the missed virtio_device_ready() to set vsock frontend ready.
>>>>
>>>> Signed-off-by: Xianting Tian<xianting.tian@linux.alibaba.com>
>>>> ---
>>>>    net/vmw_vsock/virtio_transport.c | 2 ++
>>>>    1 file changed, 2 insertions(+)
>>> Please include a changelog when you send v2, v3, etc patches.
>> OK, thanks.
>>>> diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
>>>> index e0c2c992a..dc834b8fd 100644
>>>> --- a/net/vmw_vsock/virtio_transport.c
>>>> +++ b/net/vmw_vsock/virtio_transport.c
>>>> @@ -639,6 +639,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>>>>    	mutex_unlock(&the_virtio_vsock_mutex);
>>>> +	virtio_device_ready(vdev);
>>> Why is this patch necessary?
>> Sorry, I didn't notice the check in virtio_dev_probe(),
>>
>> As Jason comment,  I alsoe think we need to be consistent: switch to use
>> virtio_device_ready() for all the drivers. What's opinion about this?
> According to the documentation the virtio_device_read() API is optional:
>
>    /**
>     * virtio_device_ready - enable vq use in probe function
>     * @vdev: the device
>     *
>     * Driver must call this to use vqs in the probe function.
>       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     *
>     * Note: vqs are enabled automatically after probe returns.
>       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     */
>
> Many drivers do not use vqs during the ->probe() function. They don't
> need to call virtio_device_ready(). That's why the virtio_vsock driver
> doesn't call it.
>
> But if a ->probe() function needs to send virtqueue buffers, e.g. to
> query the device or activate some device feature, then the driver will
> need to call it explicitly.
>
> The documentation is clear and this design is less error-prone than
> relying on all drivers to call it manually. I suggest leaving things
> unchanged.
>
> Stefan

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-07-21  1:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-20  7:13 [PATCH v2] vsock/virtio: set vsock frontend ready in virtio_vsock_probe() Xianting Tian
2021-07-20  7:54 ` Jason Wang
2021-07-20  8:36   ` Xianting Tian
2021-07-20 10:23 ` Stefan Hajnoczi
2021-07-20 10:56   ` Xianting Tian
2021-07-20 11:05   ` Xianting Tian
2021-07-20 13:12     ` Stefan Hajnoczi
2021-07-21  1:30       ` Xianting Tian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).