All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] vsock/virtio: enable VQs early on probe
@ 2022-03-22 10:38 ` Stefano Garzarella
  0 siblings, 0 replies; 10+ messages in thread
From: Stefano Garzarella @ 2022-03-22 10:38 UTC (permalink / raw)
  To: netdev
  Cc: virtualization, Stefano Garzarella, Asias He, David S. Miller,
	Jakub Kicinski, Stefan Hajnoczi, kvm, linux-kernel, Paolo Abeni,
	Michael S. Tsirkin

virtio spec requires drivers to set DRIVER_OK before using VQs.
This is set automatically after probe returns, but virtio-vsock
driver uses VQs in the probe function to fill rx and event VQs
with new buffers.

Let's fix this, calling virtio_device_ready() before using VQs
in the probe function.

Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko")
Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 5afc194a58bb..b1962f8cd502 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -622,6 +622,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
 	INIT_WORK(&vsock->event_work, virtio_transport_event_work);
 	INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
 
+	virtio_device_ready(vdev);
+
 	mutex_lock(&vsock->tx_lock);
 	vsock->tx_run = true;
 	mutex_unlock(&vsock->tx_lock);
-- 
2.35.1


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

* [PATCH net] vsock/virtio: enable VQs early on probe
@ 2022-03-22 10:38 ` Stefano Garzarella
  0 siblings, 0 replies; 10+ messages in thread
From: Stefano Garzarella @ 2022-03-22 10:38 UTC (permalink / raw)
  To: netdev
  Cc: kvm, Michael S. Tsirkin, linux-kernel, virtualization,
	Stefan Hajnoczi, Jakub Kicinski, Asias He, Paolo Abeni,
	David S. Miller

virtio spec requires drivers to set DRIVER_OK before using VQs.
This is set automatically after probe returns, but virtio-vsock
driver uses VQs in the probe function to fill rx and event VQs
with new buffers.

Let's fix this, calling virtio_device_ready() before using VQs
in the probe function.

Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko")
Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 5afc194a58bb..b1962f8cd502 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -622,6 +622,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
 	INIT_WORK(&vsock->event_work, virtio_transport_event_work);
 	INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
 
+	virtio_device_ready(vdev);
+
 	mutex_lock(&vsock->tx_lock);
 	vsock->tx_run = true;
 	mutex_unlock(&vsock->tx_lock);
-- 
2.35.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH net] vsock/virtio: enable VQs early on probe
  2022-03-22 10:38 ` Stefano Garzarella
@ 2022-03-22 13:36   ` Michael S. Tsirkin
  -1 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2022-03-22 13:36 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: netdev, virtualization, Asias He, David S. Miller,
	Jakub Kicinski, Stefan Hajnoczi, kvm, linux-kernel, Paolo Abeni

On Tue, Mar 22, 2022 at 11:38:23AM +0100, Stefano Garzarella wrote:
> virtio spec requires drivers to set DRIVER_OK before using VQs.
> This is set automatically after probe returns, but virtio-vsock
> driver uses VQs in the probe function to fill rx and event VQs
> with new buffers.


So this is a spec violation. absolutely.

> Let's fix this, calling virtio_device_ready() before using VQs
> in the probe function.
> 
> Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko")
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 5afc194a58bb..b1962f8cd502 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -622,6 +622,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>  	INIT_WORK(&vsock->event_work, virtio_transport_event_work);
>  	INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
>  
> +	virtio_device_ready(vdev);
> +
>  	mutex_lock(&vsock->tx_lock);
>  	vsock->tx_run = true;
>  	mutex_unlock(&vsock->tx_lock);

Here's the whole code snippet:


        mutex_lock(&vsock->tx_lock);
        vsock->tx_run = true;
        mutex_unlock(&vsock->tx_lock);

        mutex_lock(&vsock->rx_lock);
        virtio_vsock_rx_fill(vsock);
        vsock->rx_run = true;
        mutex_unlock(&vsock->rx_lock);

        mutex_lock(&vsock->event_lock);
        virtio_vsock_event_fill(vsock);
        vsock->event_run = true;
        mutex_unlock(&vsock->event_lock);

        if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET))
                vsock->seqpacket_allow = true;

        vdev->priv = vsock;
        rcu_assign_pointer(the_virtio_vsock, vsock);

        mutex_unlock(&the_virtio_vsock_mutex);


I worry that this is not the only problem here:
seqpacket_allow and setting of vdev->priv at least after
device is active look suspicious.
E.g.:

static void virtio_vsock_event_done(struct virtqueue *vq)
{
        struct virtio_vsock *vsock = vq->vdev->priv;

        if (!vsock)
                return;
        queue_work(virtio_vsock_workqueue, &vsock->event_work);
}

looks like it will miss events now they will be reported earlier.
One might say that since vq has been kicked it might send
interrupts earlier too so not a new problem, but
there's a chance device actually waits until DRIVER_OK
to start operating.


> -- 
> 2.35.1


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

* Re: [PATCH net] vsock/virtio: enable VQs early on probe
@ 2022-03-22 13:36   ` Michael S. Tsirkin
  0 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2022-03-22 13:36 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: kvm, netdev, linux-kernel, virtualization, Stefan Hajnoczi,
	Jakub Kicinski, Asias He, Paolo Abeni, David S. Miller

On Tue, Mar 22, 2022 at 11:38:23AM +0100, Stefano Garzarella wrote:
> virtio spec requires drivers to set DRIVER_OK before using VQs.
> This is set automatically after probe returns, but virtio-vsock
> driver uses VQs in the probe function to fill rx and event VQs
> with new buffers.


So this is a spec violation. absolutely.

> Let's fix this, calling virtio_device_ready() before using VQs
> in the probe function.
> 
> Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko")
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 5afc194a58bb..b1962f8cd502 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -622,6 +622,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>  	INIT_WORK(&vsock->event_work, virtio_transport_event_work);
>  	INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
>  
> +	virtio_device_ready(vdev);
> +
>  	mutex_lock(&vsock->tx_lock);
>  	vsock->tx_run = true;
>  	mutex_unlock(&vsock->tx_lock);

Here's the whole code snippet:


        mutex_lock(&vsock->tx_lock);
        vsock->tx_run = true;
        mutex_unlock(&vsock->tx_lock);

        mutex_lock(&vsock->rx_lock);
        virtio_vsock_rx_fill(vsock);
        vsock->rx_run = true;
        mutex_unlock(&vsock->rx_lock);

        mutex_lock(&vsock->event_lock);
        virtio_vsock_event_fill(vsock);
        vsock->event_run = true;
        mutex_unlock(&vsock->event_lock);

        if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET))
                vsock->seqpacket_allow = true;

        vdev->priv = vsock;
        rcu_assign_pointer(the_virtio_vsock, vsock);

        mutex_unlock(&the_virtio_vsock_mutex);


I worry that this is not the only problem here:
seqpacket_allow and setting of vdev->priv at least after
device is active look suspicious.
E.g.:

static void virtio_vsock_event_done(struct virtqueue *vq)
{
        struct virtio_vsock *vsock = vq->vdev->priv;

        if (!vsock)
                return;
        queue_work(virtio_vsock_workqueue, &vsock->event_work);
}

looks like it will miss events now they will be reported earlier.
One might say that since vq has been kicked it might send
interrupts earlier too so not a new problem, but
there's a chance device actually waits until DRIVER_OK
to start operating.


> -- 
> 2.35.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH net] vsock/virtio: enable VQs early on probe
  2022-03-22 13:36   ` Michael S. Tsirkin
@ 2022-03-22 14:05     ` Stefano Garzarella
  -1 siblings, 0 replies; 10+ messages in thread
From: Stefano Garzarella @ 2022-03-22 14:05 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: kvm, netdev, linux-kernel, virtualization, Stefan Hajnoczi,
	Jakub Kicinski, Paolo Abeni, David S. Miller

On Tue, Mar 22, 2022 at 09:36:14AM -0400, Michael S. Tsirkin wrote:
>On Tue, Mar 22, 2022 at 11:38:23AM +0100, Stefano Garzarella wrote:
>> virtio spec requires drivers to set DRIVER_OK before using VQs.
>> This is set automatically after probe returns, but virtio-vsock
>> driver uses VQs in the probe function to fill rx and event VQs
>> with new buffers.
>
>
>So this is a spec violation. absolutely.
>
>> Let's fix this, calling virtio_device_ready() before using VQs
>> in the probe function.
>>
>> Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko")
>> Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 5afc194a58bb..b1962f8cd502 100644
>> --- a/net/vmw_vsock/virtio_transport.c
>> +++ b/net/vmw_vsock/virtio_transport.c
>> @@ -622,6 +622,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>>  	INIT_WORK(&vsock->event_work, virtio_transport_event_work);
>>  	INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
>>
>> +	virtio_device_ready(vdev);
>> +
>>  	mutex_lock(&vsock->tx_lock);
>>  	vsock->tx_run = true;
>>  	mutex_unlock(&vsock->tx_lock);
>
>Here's the whole code snippet:
>
>
>        mutex_lock(&vsock->tx_lock);
>        vsock->tx_run = true;
>        mutex_unlock(&vsock->tx_lock);
>
>        mutex_lock(&vsock->rx_lock);
>        virtio_vsock_rx_fill(vsock);
>        vsock->rx_run = true;
>        mutex_unlock(&vsock->rx_lock);
>
>        mutex_lock(&vsock->event_lock);
>        virtio_vsock_event_fill(vsock);
>        vsock->event_run = true;
>        mutex_unlock(&vsock->event_lock);
>
>        if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET))
>                vsock->seqpacket_allow = true;
>
>        vdev->priv = vsock;
>        rcu_assign_pointer(the_virtio_vsock, vsock);
>
>        mutex_unlock(&the_virtio_vsock_mutex);
>
>
>I worry that this is not the only problem here:
>seqpacket_allow and setting of vdev->priv at least after
>device is active look suspicious.

Right, so if you agree I'll move these before virtio_device_ready().

>E.g.:
>
>static void virtio_vsock_event_done(struct virtqueue *vq)
>{
>        struct virtio_vsock *vsock = vq->vdev->priv;
>
>        if (!vsock)
>                return;
>        queue_work(virtio_vsock_workqueue, &vsock->event_work);
>}
>
>looks like it will miss events now they will be reported earlier.
>One might say that since vq has been kicked it might send
>interrupts earlier too so not a new problem, but
>there's a chance device actually waits until DRIVER_OK
>to start operating.

Yes I see, should I break into 2 patches (one where I move the code 
already present and this one)?

Maybe a single patch is fine since it's the complete solution.

Thank you for the detailed explanation,
Stefano

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH net] vsock/virtio: enable VQs early on probe
@ 2022-03-22 14:05     ` Stefano Garzarella
  0 siblings, 0 replies; 10+ messages in thread
From: Stefano Garzarella @ 2022-03-22 14:05 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: netdev, virtualization, David S. Miller, Jakub Kicinski,
	Stefan Hajnoczi, kvm, linux-kernel, Paolo Abeni

On Tue, Mar 22, 2022 at 09:36:14AM -0400, Michael S. Tsirkin wrote:
>On Tue, Mar 22, 2022 at 11:38:23AM +0100, Stefano Garzarella wrote:
>> virtio spec requires drivers to set DRIVER_OK before using VQs.
>> This is set automatically after probe returns, but virtio-vsock
>> driver uses VQs in the probe function to fill rx and event VQs
>> with new buffers.
>
>
>So this is a spec violation. absolutely.
>
>> Let's fix this, calling virtio_device_ready() before using VQs
>> in the probe function.
>>
>> Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko")
>> Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 5afc194a58bb..b1962f8cd502 100644
>> --- a/net/vmw_vsock/virtio_transport.c
>> +++ b/net/vmw_vsock/virtio_transport.c
>> @@ -622,6 +622,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>>  	INIT_WORK(&vsock->event_work, virtio_transport_event_work);
>>  	INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
>>
>> +	virtio_device_ready(vdev);
>> +
>>  	mutex_lock(&vsock->tx_lock);
>>  	vsock->tx_run = true;
>>  	mutex_unlock(&vsock->tx_lock);
>
>Here's the whole code snippet:
>
>
>        mutex_lock(&vsock->tx_lock);
>        vsock->tx_run = true;
>        mutex_unlock(&vsock->tx_lock);
>
>        mutex_lock(&vsock->rx_lock);
>        virtio_vsock_rx_fill(vsock);
>        vsock->rx_run = true;
>        mutex_unlock(&vsock->rx_lock);
>
>        mutex_lock(&vsock->event_lock);
>        virtio_vsock_event_fill(vsock);
>        vsock->event_run = true;
>        mutex_unlock(&vsock->event_lock);
>
>        if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET))
>                vsock->seqpacket_allow = true;
>
>        vdev->priv = vsock;
>        rcu_assign_pointer(the_virtio_vsock, vsock);
>
>        mutex_unlock(&the_virtio_vsock_mutex);
>
>
>I worry that this is not the only problem here:
>seqpacket_allow and setting of vdev->priv at least after
>device is active look suspicious.

Right, so if you agree I'll move these before virtio_device_ready().

>E.g.:
>
>static void virtio_vsock_event_done(struct virtqueue *vq)
>{
>        struct virtio_vsock *vsock = vq->vdev->priv;
>
>        if (!vsock)
>                return;
>        queue_work(virtio_vsock_workqueue, &vsock->event_work);
>}
>
>looks like it will miss events now they will be reported earlier.
>One might say that since vq has been kicked it might send
>interrupts earlier too so not a new problem, but
>there's a chance device actually waits until DRIVER_OK
>to start operating.

Yes I see, should I break into 2 patches (one where I move the code 
already present and this one)?

Maybe a single patch is fine since it's the complete solution.

Thank you for the detailed explanation,
Stefano


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

* Re: [PATCH net] vsock/virtio: enable VQs early on probe
  2022-03-22 14:05     ` Stefano Garzarella
@ 2022-03-22 14:09       ` Michael S. Tsirkin
  -1 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2022-03-22 14:09 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: netdev, virtualization, David S. Miller, Jakub Kicinski,
	Stefan Hajnoczi, kvm, linux-kernel, Paolo Abeni

On Tue, Mar 22, 2022 at 03:05:00PM +0100, Stefano Garzarella wrote:
> On Tue, Mar 22, 2022 at 09:36:14AM -0400, Michael S. Tsirkin wrote:
> > On Tue, Mar 22, 2022 at 11:38:23AM +0100, Stefano Garzarella wrote:
> > > virtio spec requires drivers to set DRIVER_OK before using VQs.
> > > This is set automatically after probe returns, but virtio-vsock
> > > driver uses VQs in the probe function to fill rx and event VQs
> > > with new buffers.
> > 
> > 
> > So this is a spec violation. absolutely.
> > 
> > > Let's fix this, calling virtio_device_ready() before using VQs
> > > in the probe function.
> > > 
> > > Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko")
> > > Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 5afc194a58bb..b1962f8cd502 100644
> > > --- a/net/vmw_vsock/virtio_transport.c
> > > +++ b/net/vmw_vsock/virtio_transport.c
> > > @@ -622,6 +622,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
> > >  	INIT_WORK(&vsock->event_work, virtio_transport_event_work);
> > >  	INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
> > > 
> > > +	virtio_device_ready(vdev);
> > > +
> > >  	mutex_lock(&vsock->tx_lock);
> > >  	vsock->tx_run = true;
> > >  	mutex_unlock(&vsock->tx_lock);
> > 
> > Here's the whole code snippet:
> > 
> > 
> >        mutex_lock(&vsock->tx_lock);
> >        vsock->tx_run = true;
> >        mutex_unlock(&vsock->tx_lock);
> > 
> >        mutex_lock(&vsock->rx_lock);
> >        virtio_vsock_rx_fill(vsock);
> >        vsock->rx_run = true;
> >        mutex_unlock(&vsock->rx_lock);
> > 
> >        mutex_lock(&vsock->event_lock);
> >        virtio_vsock_event_fill(vsock);
> >        vsock->event_run = true;
> >        mutex_unlock(&vsock->event_lock);
> > 
> >        if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET))
> >                vsock->seqpacket_allow = true;
> > 
> >        vdev->priv = vsock;
> >        rcu_assign_pointer(the_virtio_vsock, vsock);
> > 
> >        mutex_unlock(&the_virtio_vsock_mutex);
> > 
> > 
> > I worry that this is not the only problem here:
> > seqpacket_allow and setting of vdev->priv at least after
> > device is active look suspicious.
> 
> Right, so if you agree I'll move these before virtio_device_ready().
> 
> > E.g.:
> > 
> > static void virtio_vsock_event_done(struct virtqueue *vq)
> > {
> >        struct virtio_vsock *vsock = vq->vdev->priv;
> > 
> >        if (!vsock)
> >                return;
> >        queue_work(virtio_vsock_workqueue, &vsock->event_work);
> > }
> > 
> > looks like it will miss events now they will be reported earlier.
> > One might say that since vq has been kicked it might send
> > interrupts earlier too so not a new problem, but
> > there's a chance device actually waits until DRIVER_OK
> > to start operating.
> 
> Yes I see, should I break into 2 patches (one where I move the code already
> present and this one)?
> 
> Maybe a single patch is fine since it's the complete solution.
> 
> Thank you for the detailed explanation,
> Stefano

Two I think since movement can be backported to before the hardening
effort.

-- 
MST


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

* Re: [PATCH net] vsock/virtio: enable VQs early on probe
@ 2022-03-22 14:09       ` Michael S. Tsirkin
  0 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2022-03-22 14:09 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: kvm, netdev, linux-kernel, virtualization, Stefan Hajnoczi,
	Jakub Kicinski, Paolo Abeni, David S. Miller

On Tue, Mar 22, 2022 at 03:05:00PM +0100, Stefano Garzarella wrote:
> On Tue, Mar 22, 2022 at 09:36:14AM -0400, Michael S. Tsirkin wrote:
> > On Tue, Mar 22, 2022 at 11:38:23AM +0100, Stefano Garzarella wrote:
> > > virtio spec requires drivers to set DRIVER_OK before using VQs.
> > > This is set automatically after probe returns, but virtio-vsock
> > > driver uses VQs in the probe function to fill rx and event VQs
> > > with new buffers.
> > 
> > 
> > So this is a spec violation. absolutely.
> > 
> > > Let's fix this, calling virtio_device_ready() before using VQs
> > > in the probe function.
> > > 
> > > Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko")
> > > Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 5afc194a58bb..b1962f8cd502 100644
> > > --- a/net/vmw_vsock/virtio_transport.c
> > > +++ b/net/vmw_vsock/virtio_transport.c
> > > @@ -622,6 +622,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
> > >  	INIT_WORK(&vsock->event_work, virtio_transport_event_work);
> > >  	INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
> > > 
> > > +	virtio_device_ready(vdev);
> > > +
> > >  	mutex_lock(&vsock->tx_lock);
> > >  	vsock->tx_run = true;
> > >  	mutex_unlock(&vsock->tx_lock);
> > 
> > Here's the whole code snippet:
> > 
> > 
> >        mutex_lock(&vsock->tx_lock);
> >        vsock->tx_run = true;
> >        mutex_unlock(&vsock->tx_lock);
> > 
> >        mutex_lock(&vsock->rx_lock);
> >        virtio_vsock_rx_fill(vsock);
> >        vsock->rx_run = true;
> >        mutex_unlock(&vsock->rx_lock);
> > 
> >        mutex_lock(&vsock->event_lock);
> >        virtio_vsock_event_fill(vsock);
> >        vsock->event_run = true;
> >        mutex_unlock(&vsock->event_lock);
> > 
> >        if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET))
> >                vsock->seqpacket_allow = true;
> > 
> >        vdev->priv = vsock;
> >        rcu_assign_pointer(the_virtio_vsock, vsock);
> > 
> >        mutex_unlock(&the_virtio_vsock_mutex);
> > 
> > 
> > I worry that this is not the only problem here:
> > seqpacket_allow and setting of vdev->priv at least after
> > device is active look suspicious.
> 
> Right, so if you agree I'll move these before virtio_device_ready().
> 
> > E.g.:
> > 
> > static void virtio_vsock_event_done(struct virtqueue *vq)
> > {
> >        struct virtio_vsock *vsock = vq->vdev->priv;
> > 
> >        if (!vsock)
> >                return;
> >        queue_work(virtio_vsock_workqueue, &vsock->event_work);
> > }
> > 
> > looks like it will miss events now they will be reported earlier.
> > One might say that since vq has been kicked it might send
> > interrupts earlier too so not a new problem, but
> > there's a chance device actually waits until DRIVER_OK
> > to start operating.
> 
> Yes I see, should I break into 2 patches (one where I move the code already
> present and this one)?
> 
> Maybe a single patch is fine since it's the complete solution.
> 
> Thank you for the detailed explanation,
> Stefano

Two I think since movement can be backported to before the hardening
effort.

-- 
MST

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH net] vsock/virtio: enable VQs early on probe
  2022-03-22 14:09       ` Michael S. Tsirkin
@ 2022-03-22 14:36         ` Stefano Garzarella
  -1 siblings, 0 replies; 10+ messages in thread
From: Stefano Garzarella @ 2022-03-22 14:36 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: netdev, virtualization, David S. Miller, Jakub Kicinski,
	Stefan Hajnoczi, kvm, linux-kernel, Paolo Abeni

On Tue, Mar 22, 2022 at 10:09:06AM -0400, Michael S. Tsirkin wrote:
>On Tue, Mar 22, 2022 at 03:05:00PM +0100, Stefano Garzarella wrote:
>> On Tue, Mar 22, 2022 at 09:36:14AM -0400, Michael S. Tsirkin wrote:
>> > On Tue, Mar 22, 2022 at 11:38:23AM +0100, Stefano Garzarella wrote:
>> > > virtio spec requires drivers to set DRIVER_OK before using VQs.
>> > > This is set automatically after probe returns, but virtio-vsock
>> > > driver uses VQs in the probe function to fill rx and event VQs
>> > > with new buffers.
>> >
>> >
>> > So this is a spec violation. absolutely.
>> >
>> > > Let's fix this, calling virtio_device_ready() before using VQs
>> > > in the probe function.
>> > >
>> > > Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko")
>> > > Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 5afc194a58bb..b1962f8cd502 100644
>> > > --- a/net/vmw_vsock/virtio_transport.c
>> > > +++ b/net/vmw_vsock/virtio_transport.c
>> > > @@ -622,6 +622,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>> > >  	INIT_WORK(&vsock->event_work, virtio_transport_event_work);
>> > >  	INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
>> > >
>> > > +	virtio_device_ready(vdev);
>> > > +
>> > >  	mutex_lock(&vsock->tx_lock);
>> > >  	vsock->tx_run = true;
>> > >  	mutex_unlock(&vsock->tx_lock);
>> >
>> > Here's the whole code snippet:
>> >
>> >
>> >        mutex_lock(&vsock->tx_lock);
>> >        vsock->tx_run = true;
>> >        mutex_unlock(&vsock->tx_lock);
>> >
>> >        mutex_lock(&vsock->rx_lock);
>> >        virtio_vsock_rx_fill(vsock);
>> >        vsock->rx_run = true;
>> >        mutex_unlock(&vsock->rx_lock);
>> >
>> >        mutex_lock(&vsock->event_lock);
>> >        virtio_vsock_event_fill(vsock);
>> >        vsock->event_run = true;
>> >        mutex_unlock(&vsock->event_lock);
>> >
>> >        if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET))
>> >                vsock->seqpacket_allow = true;
>> >
>> >        vdev->priv = vsock;
>> >        rcu_assign_pointer(the_virtio_vsock, vsock);
>> >
>> >        mutex_unlock(&the_virtio_vsock_mutex);
>> >
>> >
>> > I worry that this is not the only problem here:
>> > seqpacket_allow and setting of vdev->priv at least after
>> > device is active look suspicious.
>>
>> Right, so if you agree I'll move these before virtio_device_ready().
>>
>> > E.g.:
>> >
>> > static void virtio_vsock_event_done(struct virtqueue *vq)
>> > {
>> >        struct virtio_vsock *vsock = vq->vdev->priv;
>> >
>> >        if (!vsock)
>> >                return;
>> >        queue_work(virtio_vsock_workqueue, &vsock->event_work);
>> > }
>> >
>> > looks like it will miss events now they will be reported earlier.
>> > One might say that since vq has been kicked it might send
>> > interrupts earlier too so not a new problem, but
>> > there's a chance device actually waits until DRIVER_OK
>> > to start operating.
>>
>> Yes I see, should I break into 2 patches (one where I move the code already
>> present and this one)?
>>
>> Maybe a single patch is fine since it's the complete solution.
>>
>> Thank you for the detailed explanation,
>> Stefano
>
>Two I think since movement can be backported to before the hardening
>effort.

Yep, maybe 3 since seqpacket was added later.

Thanks,
Stefano


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

* Re: [PATCH net] vsock/virtio: enable VQs early on probe
@ 2022-03-22 14:36         ` Stefano Garzarella
  0 siblings, 0 replies; 10+ messages in thread
From: Stefano Garzarella @ 2022-03-22 14:36 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: kvm, netdev, linux-kernel, virtualization, Stefan Hajnoczi,
	Jakub Kicinski, Paolo Abeni, David S. Miller

On Tue, Mar 22, 2022 at 10:09:06AM -0400, Michael S. Tsirkin wrote:
>On Tue, Mar 22, 2022 at 03:05:00PM +0100, Stefano Garzarella wrote:
>> On Tue, Mar 22, 2022 at 09:36:14AM -0400, Michael S. Tsirkin wrote:
>> > On Tue, Mar 22, 2022 at 11:38:23AM +0100, Stefano Garzarella wrote:
>> > > virtio spec requires drivers to set DRIVER_OK before using VQs.
>> > > This is set automatically after probe returns, but virtio-vsock
>> > > driver uses VQs in the probe function to fill rx and event VQs
>> > > with new buffers.
>> >
>> >
>> > So this is a spec violation. absolutely.
>> >
>> > > Let's fix this, calling virtio_device_ready() before using VQs
>> > > in the probe function.
>> > >
>> > > Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko")
>> > > Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 5afc194a58bb..b1962f8cd502 100644
>> > > --- a/net/vmw_vsock/virtio_transport.c
>> > > +++ b/net/vmw_vsock/virtio_transport.c
>> > > @@ -622,6 +622,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>> > >  	INIT_WORK(&vsock->event_work, virtio_transport_event_work);
>> > >  	INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
>> > >
>> > > +	virtio_device_ready(vdev);
>> > > +
>> > >  	mutex_lock(&vsock->tx_lock);
>> > >  	vsock->tx_run = true;
>> > >  	mutex_unlock(&vsock->tx_lock);
>> >
>> > Here's the whole code snippet:
>> >
>> >
>> >        mutex_lock(&vsock->tx_lock);
>> >        vsock->tx_run = true;
>> >        mutex_unlock(&vsock->tx_lock);
>> >
>> >        mutex_lock(&vsock->rx_lock);
>> >        virtio_vsock_rx_fill(vsock);
>> >        vsock->rx_run = true;
>> >        mutex_unlock(&vsock->rx_lock);
>> >
>> >        mutex_lock(&vsock->event_lock);
>> >        virtio_vsock_event_fill(vsock);
>> >        vsock->event_run = true;
>> >        mutex_unlock(&vsock->event_lock);
>> >
>> >        if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET))
>> >                vsock->seqpacket_allow = true;
>> >
>> >        vdev->priv = vsock;
>> >        rcu_assign_pointer(the_virtio_vsock, vsock);
>> >
>> >        mutex_unlock(&the_virtio_vsock_mutex);
>> >
>> >
>> > I worry that this is not the only problem here:
>> > seqpacket_allow and setting of vdev->priv at least after
>> > device is active look suspicious.
>>
>> Right, so if you agree I'll move these before virtio_device_ready().
>>
>> > E.g.:
>> >
>> > static void virtio_vsock_event_done(struct virtqueue *vq)
>> > {
>> >        struct virtio_vsock *vsock = vq->vdev->priv;
>> >
>> >        if (!vsock)
>> >                return;
>> >        queue_work(virtio_vsock_workqueue, &vsock->event_work);
>> > }
>> >
>> > looks like it will miss events now they will be reported earlier.
>> > One might say that since vq has been kicked it might send
>> > interrupts earlier too so not a new problem, but
>> > there's a chance device actually waits until DRIVER_OK
>> > to start operating.
>>
>> Yes I see, should I break into 2 patches (one where I move the code already
>> present and this one)?
>>
>> Maybe a single patch is fine since it's the complete solution.
>>
>> Thank you for the detailed explanation,
>> Stefano
>
>Two I think since movement can be backported to before the hardening
>effort.

Yep, maybe 3 since seqpacket was added later.

Thanks,
Stefano

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

end of thread, other threads:[~2022-03-22 14:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-22 10:38 [PATCH net] vsock/virtio: enable VQs early on probe Stefano Garzarella
2022-03-22 10:38 ` Stefano Garzarella
2022-03-22 13:36 ` Michael S. Tsirkin
2022-03-22 13:36   ` Michael S. Tsirkin
2022-03-22 14:05   ` Stefano Garzarella
2022-03-22 14:05     ` Stefano Garzarella
2022-03-22 14:09     ` Michael S. Tsirkin
2022-03-22 14:09       ` Michael S. Tsirkin
2022-03-22 14:36       ` Stefano Garzarella
2022-03-22 14:36         ` Stefano Garzarella

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.