From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DD85C433E0 for ; Mon, 15 Mar 2021 11:16:08 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2D85864E81 for ; Mon, 15 Mar 2021 11:16:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D85864E81 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=virtualization-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id BCDE8605A6; Mon, 15 Mar 2021 11:16:07 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Af-YedB2vslj; Mon, 15 Mar 2021 11:16:06 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTP id 2B9FA6F488; Mon, 15 Mar 2021 11:16:06 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 08625C000A; Mon, 15 Mar 2021 11:16:06 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2EF5EC0001 for ; Mon, 15 Mar 2021 11:16:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 10DC46ED68 for ; Mon, 15 Mar 2021 11:16:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id V2KnlJssERuO for ; Mon, 15 Mar 2021 11:16:04 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 3860D605A6 for ; Mon, 15 Mar 2021 11:16:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615806961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zTCAicjVpAPdaMgz3Js6yfA0Br4haFpS8XvtL+22h/g=; b=h0GnhOauCh8Zdlip+H1F8iwvSOSv9FFKCXRFbQbjFyAsvlEWvG9BnhTAWCdaPeCzDC67+9 ieHw8gju57WSIQlVoGvwJdrb6Yb+vaZJcJs9taoNIc0ZkHO0+/HC119+GzLwJJTIOQFuFh q+ZQ0KRc5xMR6f/3JPWnoPPcG077g3Q= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-553-RrhMqMB-NLiEP3tTJTJPbg-1; Mon, 15 Mar 2021 07:16:00 -0400 X-MC-Unique: RrhMqMB-NLiEP3tTJTJPbg-1 Received: by mail-wm1-f69.google.com with SMTP id i14so8013266wmq.7 for ; Mon, 15 Mar 2021 04:15:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=zTCAicjVpAPdaMgz3Js6yfA0Br4haFpS8XvtL+22h/g=; b=uILzOH2elLudeR89pC87xssSTWAkbBANxgXpAeDtmCcHac/ZSUC7xGskHcMQdtCA30 BLd5hw3SEv0Yca+yHN7ZryFTu1J9SPNQhc1Pv86gN1vAw/APza2w5jAQt5ngJmhGoj7A 1IYasiRAJQvPRqmFc9G+kgVuFtHPLCzDhtSXVAJE2lfPU/eiwzDWp00/HDpA4PrUYbob sD8Mbtlero56VpGjSzKwf3sPsG84rJ22+XiTiwfC4KAZGH72gXObZeU1MlQyJ0KtlkHX lDGz5urQH2SC56cOAP5NQbb9qAr+6VUKNfuranNaxb3CI83mPa1mmpTFGGj7xZctQ5xK T9PQ== X-Gm-Message-State: AOAM532H/zjQxtt73vdfSkXPEezk4DW5SctT8ERoSUAzuqdgoAOwY6qg JGvOaHQ2PKuL2oeI7dlYgT5xXS4XNbqYXec9EKXG8Gbom5jmAsMOyGCZAppK1+FunhpQM/6bIRk ovvWZYp91+j7tGTpKRr0cfRs61nsbvDWYcOAP92sL5Q== X-Received: by 2002:a5d:6a86:: with SMTP id s6mr27930971wru.307.1615806938611; Mon, 15 Mar 2021 04:15:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrXQ6HXQSOKtfo2XLAhaJtEOgAIv8MsWedRGd0O6PHJ2FIe7vMb6i/B9IXA4kIhs96rnRsqA== X-Received: by 2002:a5d:6a86:: with SMTP id s6mr27930940wru.307.1615806938386; Mon, 15 Mar 2021 04:15:38 -0700 (PDT) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id s11sm12731700wme.22.2021.03.15.04.15.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 04:15:38 -0700 (PDT) Date: Mon, 15 Mar 2021 12:15:35 +0100 From: Stefano Garzarella To: Arseny Krasnov Subject: Re: [RFC PATCH v6 13/22] virtio/vsock: add SEQPACKET receive logic Message-ID: <20210315111535.eujoemvhqxcjag2e@steredhat> References: <20210307175722.3464068-1-arseny.krasnov@kaspersky.com> <20210307180253.3466110-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 In-Reply-To: <20210307180253.3466110-1-arseny.krasnov@kaspersky.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=sgarzare@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Cc: Andra Paraschiv , kvm@vger.kernel.org, "Michael S. Tsirkin" , netdev@vger.kernel.org, stsp2@yandex.ru, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, oxffffaa@gmail.com, Norbert Slusarek , Stefan Hajnoczi , Colin Ian King , Jakub Kicinski , "David S. Miller" , Jorgen Hansen X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" On Sun, Mar 07, 2021 at 09:02:50PM +0300, Arseny Krasnov wrote: >This modifies current receive logic for SEQPACKET support: >1) Inserts 'SEQ_BEGIN' packet to socket's rx queue. >2) Inserts 'RW' packet to socket's rx queue, but without merging with > buffer of last packet in queue. >3) Performs check for packet and socket types on receive(if mismatch, > then reset connection). > >Signed-off-by: Arseny Krasnov >--- > net/vmw_vsock/virtio_transport_common.c | 63 +++++++++++++++++-------- > 1 file changed, 44 insertions(+), 19 deletions(-) > >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c >index 6fc78fec41c0..9d86375935ce 100644 >--- a/net/vmw_vsock/virtio_transport_common.c >+++ b/net/vmw_vsock/virtio_transport_common.c >@@ -165,6 +165,14 @@ void virtio_transport_deliver_tap_pkt(struct virtio_vsock_pkt *pkt) > } > EXPORT_SYMBOL_GPL(virtio_transport_deliver_tap_pkt); > >+static u16 virtio_transport_get_type(struct sock *sk) >+{ >+ if (sk->sk_type == SOCK_STREAM) >+ return VIRTIO_VSOCK_TYPE_STREAM; >+ else >+ return VIRTIO_VSOCK_TYPE_SEQPACKET; >+} >+ > /* This function can only be used on connecting/connected sockets, > * since a socket assigned to a transport is required. > * >@@ -1062,25 +1070,27 @@ virtio_transport_recv_enqueue(struct vsock_sock *vsk, > goto out; > } > >- /* Try to copy small packets into the buffer of last packet queued, >- * to avoid wasting memory queueing the entire buffer with a small >- * payload. >- */ >- if (pkt->len <= GOOD_COPY_LEN && !list_empty(&vvs->rx_queue)) { >- struct virtio_vsock_pkt *last_pkt; >+ if (le16_to_cpu(pkt->hdr.type) == VIRTIO_VSOCK_TYPE_STREAM) { >+ /* Try to copy small packets into the buffer of last packet queued, >+ * to avoid wasting memory queueing the entire buffer with a small >+ * payload. >+ */ >+ if (pkt->len <= GOOD_COPY_LEN && !list_empty(&vvs->rx_queue)) { >+ struct virtio_vsock_pkt *last_pkt; > >- last_pkt = list_last_entry(&vvs->rx_queue, >- struct virtio_vsock_pkt, list); >+ last_pkt = list_last_entry(&vvs->rx_queue, >+ struct virtio_vsock_pkt, list); > >- /* If there is space in the last packet queued, we copy the >- * new packet in its buffer. >- */ >- if (pkt->len <= last_pkt->buf_len - last_pkt->len) { >- memcpy(last_pkt->buf + last_pkt->len, pkt->buf, >- pkt->len); >- last_pkt->len += pkt->len; >- free_pkt = true; >- goto out; >+ /* If there is space in the last packet queued, we copy the >+ * new packet in its buffer. >+ */ >+ if (pkt->len <= last_pkt->buf_len - last_pkt->len) { >+ memcpy(last_pkt->buf + last_pkt->len, pkt->buf, >+ pkt->len); >+ last_pkt->len += pkt->len; >+ free_pkt = true; >+ goto out; >+ } > } > } > >@@ -1100,9 +1110,13 @@ virtio_transport_recv_connected(struct sock *sk, > int err = 0; > > switch (le16_to_cpu(pkt->hdr.op)) { >+ case VIRTIO_VSOCK_OP_SEQ_BEGIN: >+ case VIRTIO_VSOCK_OP_SEQ_END: > case VIRTIO_VSOCK_OP_RW: > virtio_transport_recv_enqueue(vsk, pkt); >- sk->sk_data_ready(sk); >+ >+ if (le16_to_cpu(pkt->hdr.op) != VIRTIO_VSOCK_OP_SEQ_BEGIN) >+ sk->sk_data_ready(sk); > return err; > case VIRTIO_VSOCK_OP_CREDIT_UPDATE: > sk->sk_write_space(sk); >@@ -1245,6 +1259,12 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt, > return 0; > } > >+static bool virtio_transport_valid_type(u16 type) >+{ >+ return (type == VIRTIO_VSOCK_TYPE_STREAM) || >+ (type == VIRTIO_VSOCK_TYPE_SEQPACKET); >+} >+ > /* We are under the virtio-vsock's vsock->rx_lock or vhost-vsock's vq->mutex > * lock. > */ >@@ -1270,7 +1290,7 @@ void virtio_transport_recv_pkt(struct virtio_transport *t, > le32_to_cpu(pkt->hdr.buf_alloc), > le32_to_cpu(pkt->hdr.fwd_cnt)); > >- if (le16_to_cpu(pkt->hdr.type) != VIRTIO_VSOCK_TYPE_STREAM) { >+ if (!virtio_transport_valid_type(le16_to_cpu(pkt->hdr.type))) { > (void)virtio_transport_reset_no_sock(t, pkt); > goto free_pkt; > } >@@ -1287,6 +1307,11 @@ void virtio_transport_recv_pkt(struct virtio_transport *t, > } > } > >+ if (virtio_transport_get_type(sk) != le16_to_cpu(pkt->hdr.type)) { >+ (void)virtio_transport_reset_no_sock(t, pkt); We must release the refcnt acquired by vsock_find_connected_socket() or vsock_find_bound_socket(), so we need to add: sock_put(sk); >+ goto free_pkt; >+ } >+ > vsk = vsock_sk(sk); > > lock_sock(sk); >-- >2.25.1 > _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization