From patchwork Fri Apr 24 15:08:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 11508065 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF8A0112C for ; Fri, 24 Apr 2020 15:08:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 974AB20776 for ; Fri, 24 Apr 2020 15:08:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="H7fa5u3k" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727903AbgDXPI5 (ORCPT ); Fri, 24 Apr 2020 11:08:57 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:23576 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727804AbgDXPI4 (ORCPT ); Fri, 24 Apr 2020 11:08:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587740935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9R6yjveOElwyTut93FZB4NDQJHLkZZ8HkoqOG3/TEPw=; b=H7fa5u3kq0iFqt+1pKZuspjKSk54jXe5JXcnYGxX/Rhxx+ehHdRj2Lf4nGqLnfw40lD6ZS Smvkc6VB0nnnalAclJXEXvFHlGiE1IUqCJ6H0ElI98ZF1AYJYEx6s1jmv9i87I0xJMQ9Ec JUQoqsfZnnbcNI8m98wTAhxQc3ve/do= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-iTW-gitIMiyiT6Du8TpJbg-1; Fri, 24 Apr 2020 11:08:51 -0400 X-MC-Unique: iTW-gitIMiyiT6Du8TpJbg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CBD7E1005510; Fri, 24 Apr 2020 15:08:36 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-114-43.ams2.redhat.com [10.36.114.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71AC55D70C; Fri, 24 Apr 2020 15:08:34 +0000 (UTC) From: Stefano Garzarella To: davem@davemloft.net Cc: Jason Wang , Jakub Kicinski , linux-kernel@vger.kernel.org, Stefano Garzarella , kvm@vger.kernel.org, "Michael S. Tsirkin" , Stefan Hajnoczi , virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH net v2 1/2] vhost/vsock: fix packet delivery order to monitoring devices Date: Fri, 24 Apr 2020 17:08:29 +0200 Message-Id: <20200424150830.183113-2-sgarzare@redhat.com> In-Reply-To: <20200424150830.183113-1-sgarzare@redhat.com> References: <20200424150830.183113-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We want to deliver packets to monitoring devices before it is put in the virtqueue, to avoid that replies can appear in the packet capture before the transmitted packet. Signed-off-by: Stefano Garzarella --- drivers/vhost/vsock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 97669484a3f6..18aff350a405 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -181,14 +181,14 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, break; } - vhost_add_used(vq, head, sizeof(pkt->hdr) + payload_len); - added = true; - - /* Deliver to monitoring devices all correctly transmitted - * packets. + /* Deliver to monitoring devices all packets that we + * will transmit. */ virtio_transport_deliver_tap_pkt(pkt); + vhost_add_used(vq, head, sizeof(pkt->hdr) + payload_len); + added = true; + pkt->off += payload_len; total_len += payload_len; From patchwork Fri Apr 24 15:08:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 11508069 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 124621575 for ; Fri, 24 Apr 2020 15:09:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF13B2075A for ; Fri, 24 Apr 2020 15:09:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DUDJFIWT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727962AbgDXPJB (ORCPT ); Fri, 24 Apr 2020 11:09:01 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:55267 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727781AbgDXPJA (ORCPT ); Fri, 24 Apr 2020 11:09:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587740938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ARp1QaZyc6uSRKz56nM+3cPhl3dHwuu6PrNTP1aVNwk=; b=DUDJFIWT+TNUJwty3YeDIDwMtYBZX22wZwIyjFe/pilQo5Yl7udb4K3oopuOCEi88e/JZR tsxwE4AEM/9A/jXWP5xDHU6wzT6te62Btg6SQY3AS4rs462TW+arHEwLgXOibRlCQQ1fIg 5IAIq/5NXCSWavdj8P+I9BfHCHAwON4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-179-DmiyAjRKOj64EzmUgW8ULQ-1; Fri, 24 Apr 2020 11:08:57 -0400 X-MC-Unique: DmiyAjRKOj64EzmUgW8ULQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F8F3100A8D3; Fri, 24 Apr 2020 15:08:39 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-114-43.ams2.redhat.com [10.36.114.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 324695D750; Fri, 24 Apr 2020 15:08:37 +0000 (UTC) From: Stefano Garzarella To: davem@davemloft.net Cc: Jason Wang , Jakub Kicinski , linux-kernel@vger.kernel.org, Stefano Garzarella , kvm@vger.kernel.org, "Michael S. Tsirkin" , Stefan Hajnoczi , virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH net v2 2/2] vsock/virtio: fix multiple packet delivery to monitoring devices Date: Fri, 24 Apr 2020 17:08:30 +0200 Message-Id: <20200424150830.183113-3-sgarzare@redhat.com> In-Reply-To: <20200424150830.183113-1-sgarzare@redhat.com> References: <20200424150830.183113-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In virtio_transport.c, if the virtqueue is full, the transmitting packet is queued up and it will be sent in the next iteration. This causes the same packet to be delivered multiple times to monitoring devices. We want to continue to deliver packets to monitoring devices before it is put in the virtqueue, to avoid that replies can appear in the packet capture before the transmitted packet. This patch fixes the issue, adding a new flag (tap_delivered) in struct virtio_vsock_pkt, to check if the packet is already delivered to monitoring devices. In vhost/vsock.c, we are splitting packets, so we must set 'tap_delivered' to false when we queue up the same virtio_vsock_pkt to handle the remaining bytes. Signed-off-by: Stefano Garzarella --- drivers/vhost/vsock.c | 6 ++++++ include/linux/virtio_vsock.h | 1 + net/vmw_vsock/virtio_transport_common.c | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 18aff350a405..11f066c76a25 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -196,6 +196,12 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, * to send it with the next available buffer. */ if (pkt->off < pkt->len) { + /* We are queueing the same virtio_vsock_pkt to handle + * the remaining bytes, and we want to deliver it + * to monitoring devices in the next iteration. + */ + pkt->tap_delivered = false; + spin_lock_bh(&vsock->send_pkt_list_lock); list_add(&pkt->list, &vsock->send_pkt_list); spin_unlock_bh(&vsock->send_pkt_list_lock); diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h index 71c81e0dc8f2..dc636b727179 100644 --- a/include/linux/virtio_vsock.h +++ b/include/linux/virtio_vsock.h @@ -48,6 +48,7 @@ struct virtio_vsock_pkt { u32 len; u32 off; bool reply; + bool tap_delivered; }; struct virtio_vsock_pkt_info { diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 709038a4783e..69efc891885f 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -157,7 +157,11 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque) void virtio_transport_deliver_tap_pkt(struct virtio_vsock_pkt *pkt) { + if (pkt->tap_delivered) + return; + vsock_deliver_tap(virtio_transport_build_skb, pkt); + pkt->tap_delivered = true; } EXPORT_SYMBOL_GPL(virtio_transport_deliver_tap_pkt);