LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/2] vhost/vsock: fix used length and cleanup in vhost_vsock_handle_tx_kick()
@ 2021-11-22 16:35 Stefano Garzarella
  2021-11-22 16:35 ` [PATCH 1/2] vhost/vsock: fix incorrect used length reported to the guest Stefano Garzarella
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Stefano Garzarella @ 2021-11-22 16:35 UTC (permalink / raw)
  To: virtualization
  Cc: linux-kernel, Stefano Garzarella, Jason Wang, Stefan Hajnoczi,
	netdev, Halil Pasic, kvm, Asias He, Michael S. Tsirkin

This is a follow-up to Micheal's patch [1] and the discussion with Halil and
Jason [2].

I made two patches, one to fix the problem and one for cleanup. This should
simplify the backport of the fix because we've had the problem since
vhost-vsock was introduced (v4.8) and that part has been touched a bit
recently.

Thanks,
Stefano

[1] https://lore.kernel.org/virtualization/20211122105822.onarsa4sydzxqynu@steredhat/T/#t
[2] https://lore.kernel.org/virtualization/20211027022107.14357-1-jasowang@redhat.com/T/#t

Stefano Garzarella (2):
  vhost/vsock: fix incorrect used length reported to the guest
  vhost/vsock: cleanup removing `len` variable

 drivers/vhost/vsock.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

-- 
2.31.1


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

* [PATCH 1/2] vhost/vsock: fix incorrect used length reported to the guest
  2021-11-22 16:35 [PATCH 0/2] vhost/vsock: fix used length and cleanup in vhost_vsock_handle_tx_kick() Stefano Garzarella
@ 2021-11-22 16:35 ` Stefano Garzarella
  2021-11-23 13:22   ` Halil Pasic
  2021-11-22 16:35 ` [PATCH 2/2] vhost/vsock: cleanup removing `len` variable Stefano Garzarella
  2021-11-23 12:54 ` [PATCH 0/2] vhost/vsock: fix used length and cleanup in vhost_vsock_handle_tx_kick() Stefan Hajnoczi
  2 siblings, 1 reply; 5+ messages in thread
From: Stefano Garzarella @ 2021-11-22 16:35 UTC (permalink / raw)
  To: virtualization
  Cc: linux-kernel, Stefano Garzarella, Jason Wang, Stefan Hajnoczi,
	netdev, Halil Pasic, kvm, Asias He, Michael S. Tsirkin

The "used length" reported by calling vhost_add_used() must be the
number of bytes written by the device (using "in" buffers).

In vhost_vsock_handle_tx_kick() the device only reads the guest
buffers (they are all "out" buffers), without writing anything,
so we must pass 0 as "used length" to comply virtio spec.

Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko")
Cc: stable@vger.kernel.org
Reported-by: Halil Pasic <pasic@linux.ibm.com>
Suggested-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 drivers/vhost/vsock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 938aefbc75ec..4e3b95af7ee4 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -554,7 +554,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
 			virtio_transport_free_pkt(pkt);
 
 		len += sizeof(pkt->hdr);
-		vhost_add_used(vq, head, len);
+		vhost_add_used(vq, head, 0);
 		total_len += len;
 		added = true;
 	} while(likely(!vhost_exceeds_weight(vq, ++pkts, total_len)));
-- 
2.31.1


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

* [PATCH 2/2] vhost/vsock: cleanup removing `len` variable
  2021-11-22 16:35 [PATCH 0/2] vhost/vsock: fix used length and cleanup in vhost_vsock_handle_tx_kick() Stefano Garzarella
  2021-11-22 16:35 ` [PATCH 1/2] vhost/vsock: fix incorrect used length reported to the guest Stefano Garzarella
@ 2021-11-22 16:35 ` Stefano Garzarella
  2021-11-23 12:54 ` [PATCH 0/2] vhost/vsock: fix used length and cleanup in vhost_vsock_handle_tx_kick() Stefan Hajnoczi
  2 siblings, 0 replies; 5+ messages in thread
From: Stefano Garzarella @ 2021-11-22 16:35 UTC (permalink / raw)
  To: virtualization
  Cc: linux-kernel, Stefano Garzarella, Jason Wang, Stefan Hajnoczi,
	netdev, Halil Pasic, kvm, Asias He, Michael S. Tsirkin

We can increment `total_len` directly and remove `len` since it
is no longer used for vhost_add_used().

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 drivers/vhost/vsock.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 4e3b95af7ee4..d6ca1c7ad513 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -511,8 +511,6 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
 
 	vhost_disable_notify(&vsock->dev, vq);
 	do {
-		u32 len;
-
 		if (!vhost_vsock_more_replies(vsock)) {
 			/* Stop tx until the device processes already
 			 * pending replies.  Leave tx virtqueue
@@ -540,7 +538,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
 			continue;
 		}
 
-		len = pkt->len;
+		total_len += sizeof(pkt->hdr) + pkt->len;
 
 		/* Deliver to monitoring devices all received packets */
 		virtio_transport_deliver_tap_pkt(pkt);
@@ -553,9 +551,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
 		else
 			virtio_transport_free_pkt(pkt);
 
-		len += sizeof(pkt->hdr);
 		vhost_add_used(vq, head, 0);
-		total_len += len;
 		added = true;
 	} while(likely(!vhost_exceeds_weight(vq, ++pkts, total_len)));
 
-- 
2.31.1


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

* Re: [PATCH 0/2] vhost/vsock: fix used length and cleanup in vhost_vsock_handle_tx_kick()
  2021-11-22 16:35 [PATCH 0/2] vhost/vsock: fix used length and cleanup in vhost_vsock_handle_tx_kick() Stefano Garzarella
  2021-11-22 16:35 ` [PATCH 1/2] vhost/vsock: fix incorrect used length reported to the guest Stefano Garzarella
  2021-11-22 16:35 ` [PATCH 2/2] vhost/vsock: cleanup removing `len` variable Stefano Garzarella
@ 2021-11-23 12:54 ` Stefan Hajnoczi
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2021-11-23 12:54 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: virtualization, linux-kernel, Jason Wang, netdev, Halil Pasic,
	kvm, Asias He, Michael S. Tsirkin

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

On Mon, Nov 22, 2021 at 05:35:23PM +0100, Stefano Garzarella wrote:
> This is a follow-up to Micheal's patch [1] and the discussion with Halil and
> Jason [2].
> 
> I made two patches, one to fix the problem and one for cleanup. This should
> simplify the backport of the fix because we've had the problem since
> vhost-vsock was introduced (v4.8) and that part has been touched a bit
> recently.
> 
> Thanks,
> Stefano
> 
> [1] https://lore.kernel.org/virtualization/20211122105822.onarsa4sydzxqynu@steredhat/T/#t
> [2] https://lore.kernel.org/virtualization/20211027022107.14357-1-jasowang@redhat.com/T/#t
> 
> Stefano Garzarella (2):
>   vhost/vsock: fix incorrect used length reported to the guest
>   vhost/vsock: cleanup removing `len` variable
> 
>  drivers/vhost/vsock.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> -- 
> 2.31.1
> 

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

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

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

* Re: [PATCH 1/2] vhost/vsock: fix incorrect used length reported to the guest
  2021-11-22 16:35 ` [PATCH 1/2] vhost/vsock: fix incorrect used length reported to the guest Stefano Garzarella
@ 2021-11-23 13:22   ` Halil Pasic
  0 siblings, 0 replies; 5+ messages in thread
From: Halil Pasic @ 2021-11-23 13:22 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: virtualization, linux-kernel, Jason Wang, Stefan Hajnoczi,
	netdev, kvm, Asias He, Michael S. Tsirkin, Halil Pasic

On Mon, 22 Nov 2021 17:35:24 +0100
Stefano Garzarella <sgarzare@redhat.com> wrote:

> The "used length" reported by calling vhost_add_used() must be the
> number of bytes written by the device (using "in" buffers).
> 
> In vhost_vsock_handle_tx_kick() the device only reads the guest
> buffers (they are all "out" buffers), without writing anything,
> so we must pass 0 as "used length" to comply virtio spec.
> 
> Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko")
> Cc: stable@vger.kernel.org
> Reported-by: Halil Pasic <pasic@linux.ibm.com>
> Suggested-by: Jason Wang <jasowang@redhat.com>
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>

Reviewed-by: Halil Pasic <pasic@linux.ibm.com>

> ---
>  drivers/vhost/vsock.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> index 938aefbc75ec..4e3b95af7ee4 100644
> --- a/drivers/vhost/vsock.c
> +++ b/drivers/vhost/vsock.c
> @@ -554,7 +554,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
>  			virtio_transport_free_pkt(pkt);
>  
>  		len += sizeof(pkt->hdr);
> -		vhost_add_used(vq, head, len);
> +		vhost_add_used(vq, head, 0);
>  		total_len += len;
>  		added = true;
>  	} while(likely(!vhost_exceeds_weight(vq, ++pkts, total_len)));


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

end of thread, other threads:[~2021-11-23 13:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 16:35 [PATCH 0/2] vhost/vsock: fix used length and cleanup in vhost_vsock_handle_tx_kick() Stefano Garzarella
2021-11-22 16:35 ` [PATCH 1/2] vhost/vsock: fix incorrect used length reported to the guest Stefano Garzarella
2021-11-23 13:22   ` Halil Pasic
2021-11-22 16:35 ` [PATCH 2/2] vhost/vsock: cleanup removing `len` variable Stefano Garzarella
2021-11-23 12:54 ` [PATCH 0/2] vhost/vsock: fix used length and cleanup in vhost_vsock_handle_tx_kick() Stefan Hajnoczi

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).