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=gTgkNvyc; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id D39BC5A0626 for ; Thu, 14 Nov 2024 15:23:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731594201; 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; bh=A+4tK4uvW5g9gwuIYIj/j2101bWYCobIAdk0MgQzSaY=; b=gTgkNvycr9aqrznfn3UVfw+oyMOAHlNttTj6cxP4V6eklwhRqGZ0fiZR3PQ4ykDbskcYUS WeMWZ3sn3bFVcf2vQqnfavGEdK2vLOzCl4//n96YMZJ9QP8+5i4v61iGlhcZGI+GaPCRXC eoujOD72G5FHSNoOIo9kGLMuX/Ub5VM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-203-wrf27vpKOHeUj3qYDUDoTw-1; Thu, 14 Nov 2024 09:23:20 -0500 X-MC-Unique: wrf27vpKOHeUj3qYDUDoTw-1 X-Mimecast-MFC-AGG-ID: wrf27vpKOHeUj3qYDUDoTw Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4315eaa3189so6733795e9.1 for ; Thu, 14 Nov 2024 06:23:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731594199; x=1732198999; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=A+4tK4uvW5g9gwuIYIj/j2101bWYCobIAdk0MgQzSaY=; b=rwNCSEaHzhIBRlaQBFMHofWxpOKoCxDBAVP3igmnxqP/dZPOmgPgVAsfnojAuTInhD L3NsADzJb+NbBEkmUeLO+l9ZTLf+5Q3rWfcwtt9ed24OZeI+UulMGJM+Ve5xovEl0ctC ihc1rf3oOgQyvrwkq8c1XwQvIlOHb09Np/eaLDEgzrWGW5XCS4IkGXwNZJWMPUZ2IDKM EUy7zZXa6iL062MEkS1YFOnjrx6UyV07G9WquP7V+8gPBcqvNUKSZBMqCN8Rq7lxqPpR f1cidHMBPhDV6FeOZ+wcuYVd5drO2HBotcowAVZ5ifYhH9+yIF/N+AB+921ky+bgSyiE xFeQ== X-Gm-Message-State: AOJu0YyPQnwFUXPK9ub/r/lsOO35GM4eT8cBFu7U313icIZLYp5GyHfj tiUwwlyExQ4C6UcfGaqflaLUA1VI6ToxwOz8uFtT9KEDgJjgZc+sBffvCL8nw5XH2jGGA+k45nU FFSJMt1md1jelO2TIVxJmLaYXPcjQKHeLzteLdeZUBYjzR4BCUTANp+Avza2QEi78gyvBixUA6X /lLiXyjgWSOmwSKtzVAtwkNxG9zaheXq7R X-Received: by 2002:a05:600c:4f83:b0:432:d735:cc71 with SMTP id 5b1f17b1804b1-432da7cbc0cmr26172945e9.25.1731594198841; Thu, 14 Nov 2024 06:23:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRjh6cZY7QfTQYY3fswE4J84WXQ0KXxrmFucaEethsi+/chwOcrP4dOEEly8OaTjpVzeijjA== X-Received: by 2002:a05:600c:4f83:b0:432:d735:cc71 with SMTP id 5b1f17b1804b1-432da7cbc0cmr26172595e9.25.1731594198424; Thu, 14 Nov 2024 06:23:18 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dac1fb7asm22226235e9.42.2024.11.14.06.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 06:23:17 -0800 (PST) Date: Thu, 14 Nov 2024 15:23:16 +0100 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v8 7/8] vhost-user: add vhost-user Message-ID: <20241114152316.6843a427@elisabeth> In-Reply-To: <81955149-fc8f-47ef-b6fb-ce284e8e8b1b@redhat.com> References: <20241010122903.1188992-1-lvivier@redhat.com> <20241010122903.1188992-8-lvivier@redhat.com> <20241017021034.437f3757@elisabeth> <81955149-fc8f-47ef-b6fb-ce284e8e8b1b@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zTGDpwmeFiPelh0CqFTmI0rZzZUWsDEUsJyx11ScmeQ_1731594199 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 4PNG4ES5I52GTI6AN4V7USDYKAEAOVCQ X-Message-ID-Hash: 4PNG4ES5I52GTI6AN4V7USDYKAEAOVCQ X-MailFrom: sbrivio@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 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. -- Stefano