From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AHBUnxBf; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 9C4C55A004E for ; Fri, 15 Nov 2024 09:30:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731659449; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=WjMkwT/icLPqamo9KOf3xKTqIX9vqtiv0P1yZsyfX6w=; b=AHBUnxBfHiC4FMuUZZ86r+R4VW+yOua0qT4jrLT5gm7Tum6tAyBh3I8qzlCwzrPdro5Bw4 GGp3UrC0yycrFnMLteC4TRjbJbwy/H1Bocb+BBiIGZiCxKSrFErXUNt6SQ9CC7n99OSLvg tTMB6LUuy3R6f5ZIkNKD0KTuhDQVmzE= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-580-foRNta_yNGGo9ssvr5Bjyw-1; Fri, 15 Nov 2024 03:30:47 -0500 X-MC-Unique: foRNta_yNGGo9ssvr5Bjyw-1 X-Mimecast-MFC-AGG-ID: foRNta_yNGGo9ssvr5Bjyw Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4314a22ed8bso3306635e9.1 for ; Fri, 15 Nov 2024 00:30:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731659446; x=1732264246; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WjMkwT/icLPqamo9KOf3xKTqIX9vqtiv0P1yZsyfX6w=; b=R9UioteKotjp5ljpmhRN0Y5eZBQgO1ym6fndI1PE9+YEsgcxWnQuqqYRzdTUDe+hYt x9eOmwsIkFRfOTuUXxZEyPohkBsgyZy+M+2G52BknCJCQj7cx7ofX//TmPTUcfzrsPgl /7zUGSDE6Nj62P5s2rINoECpuSOazY5eLGMp/lkfmAi7oqukJ0JTE8r759QP0gB4xvkm 6N/YU1aWfoQd14Qy6MgO9NcW6dxzyPjl6ige4yeQWY/ukqwJ9H35vsxurXIE+2DjqVB4 a6vuIBW3Ywt3arjYQcx56D63WT50D9gYmUzmyPsdehzj1o4WjYT3o1oMFybEQCLzbPrG KPeg== X-Gm-Message-State: AOJu0YwnM2MFCfXhkA47VVwgRHSIXUSYDtCFI8eAditXTzSj5Y4AWOYf RSiZESlOzznbNPPpY2HtOrcUtHRoLYMW9zIIcvANPgyzS4mg9+DW0d3eKLER73y4FLLtg6ftWEb FoEJwXhZ2zKAZdVs53xINIaUZt4HgjMzHJPhBI5uNKcwzS/RzmQ== X-Received: by 2002:a05:600c:314d:b0:432:b38e:a048 with SMTP id 5b1f17b1804b1-432df72c95fmr15069265e9.12.1731659446520; Fri, 15 Nov 2024 00:30:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkNQoXO19TUpRGRysy5C3iaIYZd5WFUwHybkvvDi1uGlPQXXVS9EtLS3AJqpqit1m8NHKXrw== X-Received: by 2002:a05:600c:314d:b0:432:b38e:a048 with SMTP id 5b1f17b1804b1-432df72c95fmr15068965e9.12.1731659446082; Fri, 15 Nov 2024 00:30:46 -0800 (PST) Received: from ?IPV6:2a01:e0a:e10:ef90:343a:68f:2e91:95c? ([2a01:e0a:e10:ef90:343a:68f:2e91:95c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432daafc6b3sm48044535e9.0.2024.11.15.00.30.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 Nov 2024 00:30:45 -0800 (PST) Message-ID: <03986996-a879-4109-8a7c-cc68c1c00464@redhat.com> Date: Fri, 15 Nov 2024 09:30:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8 7/8] vhost-user: add vhost-user To: Stefano Brivio References: <20241010122903.1188992-1-lvivier@redhat.com> <20241010122903.1188992-8-lvivier@redhat.com> <20241017021034.437f3757@elisabeth> <81955149-fc8f-47ef-b6fb-ce284e8e8b1b@redhat.com> <20241114152316.6843a427@elisabeth> From: Laurent Vivier Autocrypt: addr=lvivier@redhat.com; keydata= xsFNBFYFJhkBEAC2me7w2+RizYOKZM+vZCx69GTewOwqzHrrHSG07MUAxJ6AY29/+HYf6EY2 WoeuLWDmXE7A3oJoIsRecD6BXHTb0OYS20lS608anr3B0xn5g0BX7es9Mw+hV/pL+63EOCVm SUVTEQwbGQN62guOKnJJJfphbbv82glIC/Ei4Ky8BwZkUuXd7d5NFJKC9/GDrbWdj75cDNQx UZ9XXbXEKY9MHX83Uy7JFoiFDMOVHn55HnncflUncO0zDzY7CxFeQFwYRbsCXOUL9yBtqLer Ky8/yjBskIlNrp0uQSt9LMoMsdSjYLYhvk1StsNPg74+s4u0Q6z45+l8RAsgLw5OLtTa+ePM JyS7OIGNYxAX6eZk1+91a6tnqfyPcMbduxyBaYXn94HUG162BeuyBkbNoIDkB7pCByed1A7q q9/FbuTDwgVGVLYthYSfTtN0Y60OgNkWCMtFwKxRaXt1WFA5ceqinN/XkgA+vf2Ch72zBkJL RBIhfOPFv5f2Hkkj0MvsUXpOWaOjatiu0fpPo6Hw14UEpywke1zN4NKubApQOlNKZZC4hu6/ 8pv2t4HRi7s0K88jQYBRPObjrN5+owtI51xMaYzvPitHQ2053LmgsOdN9EKOqZeHAYG2SmRW LOxYW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Nyx FCRkhxRuGcpwPmRVDwOl39MB3iTsRighiMnijkbLXiKoJ5CDVvX5yicNqYJPKh5MFXN1bvsB kmYiStMRbrD0HoY1kx5/VozBtc70OU0EB8Wrv9hZD+Ofp0T3KOr1RUHvCZoLURfFhSQ= In-Reply-To: <20241114152316.6843a427@elisabeth> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: iIAKxbfKnbu8qQhgLHgEmD3EcWf0LDlgyH5a5b85ufA_1731659447 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: ELLCDEI7N74752S4SH4KT46GEY5SVTT5 X-Message-ID-Hash: ELLCDEI7N74752S4SH4KT46GEY5SVTT5 X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 14/11/2024 15:23, Stefano Brivio wrote: > On Thu, 14 Nov 2024 11:23:11 +0100 > Laurent Vivier wrote: > >> On 17/10/2024 02:10, Stefano Brivio wrote: >>>> +/** >>>> + * tcp_vu_data_from_sock() - Handle new data from socket, queue to vhost-user, >>>> + * in window >>>> + * @c: Execution context >>>> + * @conn: Connection pointer >>>> + * >>>> + * Return: Negative on connection reset, 0 otherwise >>>> + */ >>>> +int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) >>>> +{ >>>> + uint32_t wnd_scaled = conn->wnd_from_tap << conn->ws_from_tap; >>>> + struct vu_dev *vdev = c->vdev; >>>> + struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; >>>> + const struct flowside *tapside = TAPFLOW(conn); >>>> + uint16_t mss = MSS_GET(conn); >>>> + size_t l2_hdrlen, fillsize; >>>> + int i, iov_cnt, iov_used; >>>> + int v4 = CONN_V4(conn); >>>> + uint32_t already_sent = 0; >>>> + const uint16_t *check; >>>> + struct iovec *first; >>>> + int frame_size; >>>> + int num_buffers; >>>> + ssize_t len; >>>> + >>>> + if (!vu_queue_enabled(vq) || !vu_queue_started(vq)) { >>>> + flow_err(conn, >>>> + "Got packet, but RX virtqueue not usable yet"); >>>> + return 0; >>>> + } >>>> + >>>> + already_sent = conn->seq_to_tap - conn->seq_ack_from_tap; >>>> + >>>> + if (SEQ_LT(already_sent, 0)) { >>>> + /* RFC 761, section 2.1. */ >>>> + flow_trace(conn, "ACK sequence gap: ACK for %u, sent: %u", >>>> + conn->seq_ack_from_tap, conn->seq_to_tap); >>>> + conn->seq_to_tap = conn->seq_ack_from_tap; >>>> + already_sent = 0; >>>> + } >>>> + >>>> + if (!wnd_scaled || already_sent >= wnd_scaled) { >>>> + conn_flag(c, conn, STALLED); >>>> + conn_flag(c, conn, ACK_FROM_TAP_DUE); >>>> + return 0; >>>> + } >>>> + >>>> + /* Set up buffer descriptors we'll fill completely and partially. */ >>>> + >>>> + fillsize = wnd_scaled; >>>> + >>>> + if (peek_offset_cap) >>>> + already_sent = 0; >>>> + >>>> + iov_vu[0].iov_base = tcp_buf_discard; >>>> + iov_vu[0].iov_len = already_sent; >>>> + fillsize -= already_sent; >>>> + >>>> + /* collect the buffers from vhost-user and fill them with the >>>> + * data from the socket >>>> + */ >>>> + iov_cnt = tcp_vu_sock_recv(c, conn, v4, fillsize, &len); >>>> + if (iov_cnt <= 0) >>>> + return iov_cnt; >>>> + >>>> + len -= already_sent; >>>> + if (len <= 0) { >>>> + conn_flag(c, conn, STALLED); >>>> + vu_queue_rewind(vq, iov_cnt); >>>> + return 0; >>>> + } >>>> + >>>> + conn_flag(c, conn, ~STALLED); >>>> + >>>> + /* Likely, some new data was acked too. */ >>>> + tcp_update_seqack_wnd(c, conn, 0, NULL); >>>> + >>>> + /* initialize headers */ >>>> + l2_hdrlen = tcp_vu_l2_hdrlen(!v4); >>>> + iov_used = 0; >>>> + num_buffers = 0; >>>> + check = NULL; >>>> + frame_size = 0; >>>> + >>>> + /* iov_vu is an array of buffers and the buffer size can be >>>> + * smaller than the frame size we want to use but with >>>> + * num_buffer we can merge several virtio iov buffers in one packet >>>> + * we need only to set the packet headers in the first iov and >>>> + * num_buffer to the number of iov entries >>> ...this part is clear to me, what I don't understand is if we still >>> have a way to guarantee that the sum of several buffers is big enough >>> to fit frame_size bytes. >> >> We don't have this garantee. But I think it's the same for the socket version? > > Well, there we do: > > fill_bufs = DIV_ROUND_UP(wnd_scaled - already_sent, mss); > if (fill_bufs > TCP_FRAMES) { > fill_bufs = TCP_FRAMES; > > and we don't fetch more data than that from the socket (in one pass). > > Is this implicit in the i < iov_cnt loop condition here? That's the part > I don't understand: how do we limit the amount of data we can dequeue > from a socket in one single pass. > In the loop "i < iov_cnt" is the number of available buffers collected previously. Usually the size of one buffer is 1536 bytes. We join the buffers here (when VIRTIO_NET_F_MRG_RXBUF is avaialble) to create frame with a size of "mss". iov_cnt is computed in tcp_vu_sock_recv(): this is the number of buffers we have collected from the queue to have enough space to store fillsize bytes. But if we don't have enough buffers in the queue ioc_cnt will be lower and the size of the data we will collect will be truncated. Thanks, Laurent