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=WkWHiwZX; 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 6F8445A061A for ; Tue, 26 Nov 2024 15:11:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732630290; 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=zQ4fHGNy8NetkAjM2vrdec4zp29KteGCfIgktbNqOWk=; b=WkWHiwZXpVpubqKdhhWHneEKSUPzvh06cHbvn6GZ6y7lwtFxPPCHrJtIBiOMMNm30HRp4f b5oEX/TG1U/uyoKF0qKc8YY4o1sSxZLujv6iiqxdAzeQxDzC9WMx8LvgnIGxNufvyxUaME yzNFzKSN8ORo+QOB4fru3AW/My+OIOY= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-aLPPqdWaPPSzD74P9vc6og-1; Tue, 26 Nov 2024 09:11:28 -0500 X-MC-Unique: aLPPqdWaPPSzD74P9vc6og-1 X-Mimecast-MFC-AGG-ID: aLPPqdWaPPSzD74P9vc6og Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7b67a9aea08so7157685a.2 for ; Tue, 26 Nov 2024 06:11:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732630288; x=1733235088; 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=zQ4fHGNy8NetkAjM2vrdec4zp29KteGCfIgktbNqOWk=; b=EAWdoiITyEPHWFPzouW8YIh5WIuqfMqeDElRY21eA8bQ6pIbvDqodpp2v0Nn05h4Lb VAxPnK7BZ6VMmyXJ1jGWT/tuocw2ZsbnUgN22OdjzI+635ZNfE8i7AD32jdDqMyWmXmF X/zsgh6U5Hduxwso6tS9DE0LhiHkelmLWHHXUc3pdV5brSjIEs9gX9AyZymZ+rMS9riO p7BWbtIJQSmoY2yAUo5pcU1tWPVxgz8cvuU/+cJDJi/C3zkTWIkmIRrCQiPcPeCwFVYE loNRZG976yaftnf0p6XB4HntdD+Pukrx9zgUi8Ji2wdl8C1IDyTZR5/dH7lDSqybn6aM i5Qg== X-Gm-Message-State: AOJu0YxJ5iBMYmCvicji+6LcoCWGRAK0buYi+tc06eKN3D8dcHxKofuD O8LaHuE2cudvx9JHskbgaQKtIfIzxFei2iMVUjx9ab33jnjcbDqdbBLDK2y8oWMa7b2nV3oa3b5 jDsjG+dPpewA5kWXpyEC77NqI9dfl2gVbEgFsLop+d2YszW41uQ== X-Gm-Gg: ASbGncuhG7NL7Y8576otgRaaYkh1pCVdPFI6MITGw2nRIqYr4qdCnBeyEQqzKUZtUwg QczBZIoWjKz9+RmlAdjorMDMixcGV7FQL8DfNT0X9leKTqd4DMhSkc59Cy+sTDg4TqsEjDODXKN 9eZ7KZK6+PX+ZivNQaaGvocfHA/pbJIUwYad5jOZ1HmGtoNQ8wG+IkJhaFxhmNg0HE1q0lMRe3q KGbvSmMPNwZfq6EyvRBngN56yh3bWXgPktzLsCfcapjpTHtarMkB+T2MDZzuVq1RjEqMh8vPqp9 LkAAw+OhmMCZ X-Received: by 2002:a05:620a:1985:b0:7b1:5424:e998 with SMTP id af79cd13be357-7b51451faa6mr2100316385a.22.1732630288441; Tue, 26 Nov 2024 06:11:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPAG553gaalZvTaq2wNsKKZuvSzTk2oZX8wESMKc3wgja41Aa0RNYtauk4hc4A2h58IFEPCg== X-Received: by 2002:a05:620a:1985:b0:7b1:5424:e998 with SMTP id af79cd13be357-7b51451faa6mr2100312885a.22.1732630288063; Tue, 26 Nov 2024 06:11:28 -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 af79cd13be357-7b675abc6a3sm73185185a.7.2024.11.26.06.11.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Nov 2024 06:11:27 -0800 (PST) Message-ID: <50e95450-620c-47b3-bc70-168d1659fdb5@redhat.com> Date: Tue, 26 Nov 2024 15:11:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v14 7/9] vhost-user: add vhost-user To: Stefano Brivio References: <20241122164337.3377854-1-lvivier@redhat.com> <20241122164337.3377854-8-lvivier@redhat.com> <20241126061443.3287f86d@elisabeth> <20241126145334.13d2301b@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+91a6tnqfyPcMbduxyB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XEYRWdiCxN7ca5iPml5gLtuvhJMSy36gl U6IW9kn30IWuSoBpTkgV7rLUEhh9Ms82VWW/h2TxL8enfx40PrfbDtWwqRID3WY8jLrjKfTd R3LW8BnUDNkG+c4FzvvGUs8AvuqxxyHbXAfDx9o/jXfPHVRmJVhSmd+hC3mcQ+4iX5bBPBPM oDqSoLt5w9GoQQ6gDVP2ZjTWqwSRMLzNr37rJjZ1pt0DCMMTbiYIUcrhX8eveCJtY7NGWNyx FCRkhxRuGcpwPmRVDwOl39MB3iTsRighiMnijkbLXiKoJ5CDVvX5yicNqYJPKh5MFXN1bvsB kmYiStMRbrD0HoY1kx5/VozBtc70OU0EB8Wrv9hZD+Ofp0T3KOr1RUHvCZoLURfFhSQ= In-Reply-To: <20241126145334.13d2301b@elisabeth> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: MjO1rlrpMa1EqtpYQf01XqH600jJIKT_r6G0biPeDl8_1732630288 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: KX34WSGO6WNTPPMOCXMHCG5KBE4OCYGI X-Message-ID-Hash: KX34WSGO6WNTPPMOCXMHCG5KBE4OCYGI 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 26/11/2024 14:53, Stefano Brivio wrote: > On Tue, 26 Nov 2024 06:14:43 +0100 > Stefano Brivio wrote: > >> On Fri, 22 Nov 2024 17:43:34 +0100 >> Laurent Vivier 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); >>> + size_t fillsize, hdrlen; >>> + int v6 = CONN_V6(conn); >>> + uint32_t already_sent; >>> + const uint16_t *check; >>> + int i, iov_cnt; >>> + ssize_t len; >>> + >>> + if (!vu_queue_enabled(vq) || !vu_queue_started(vq)) { >>> + debug("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 (tcp_set_peek_offset(conn->sock, 0)) { >>> + tcp_rst(c, conn); >>> + return -1; >>> + } >>> + } >>> + >>> + 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 - already_sent; >>> + >>> + /* collect the buffers from vhost-user and fill them with the >>> + * data from the socket >>> + */ >>> + len = tcp_vu_sock_recv(c, conn, v6, already_sent, fillsize, &iov_cnt); >>> + if (len < 0) { >>> + if (len != -EAGAIN && len != -EWOULDBLOCK) { >>> + tcp_rst(c, conn); >>> + return len; >>> + } >>> + return 0; >>> + } >>> + >>> + if (!len) { >>> + if (already_sent) { >>> + conn_flag(c, conn, STALLED); >>> + } else if ((conn->events & (SOCK_FIN_RCVD | TAP_FIN_SENT)) == >>> + SOCK_FIN_RCVD) { >>> + int ret = tcp_vu_send_flag(c, conn, FIN | ACK); >>> + if (ret) { >>> + tcp_rst(c, conn); >>> + return ret; >>> + } >>> + >>> + conn_event(c, conn, TAP_FIN_SENT); >>> + } >>> + >>> + return 0; >>> + } >>> + >>> + conn_flag(c, conn, ~STALLED); >>> + >>> + /* Likely, some new data was acked too. */ >>> + tcp_update_seqack_wnd(c, conn, false, NULL); >>> + >>> + /* initialize headers */ >>> + /* 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 >>> + */ >>> + >>> + hdrlen = tcp_vu_hdrlen(v6); >>> + for (i = 0, check = NULL; i < head_cnt; i++) { >>> + struct iovec *iov = &elem[head[i]].in_sg[0]; >>> + int buf_cnt = head[i + 1] - head[i]; >>> + int dlen = iov_size(iov, buf_cnt) - hdrlen; >> >> Unless I'm missing something, to me this looks like a false positive, >> but Coverity now reports, for this line: >> >> (17) Event function_return: Function "iov_size(iov, buf_cnt)" returns 0. >> (18) Event overflow_const: Expression "iov_size(iov, buf_cnt) - hdrlen", which is equal to 18446744073709551550, where "iov_size(iov, buf_cnt)" is known to be equal to 0, and "hdrlen" is known to be equal to 66, underflows the type that receives it, an unsigned integer 64 bits wide. >> >> ...I don't think iov_size() can ever return 0 if we reach this point, >> but I would try to cover this by either, in order of preference: >> >> 1. not sending this frame if iov_size(iov, buf_cnt) < hdrlen >> >> 2. an ASSERT(iov_size(iov, buf_cnt) >= hdrlen) >> >> It can be a follow-up patch, there's no need to re-post the whole thing >> (at least not just for this), unless you see something that actually >> needs to be fixed. > > ...nothing to be fixed in your opinion, I suppose? > There is an ASSERT() in tcp_vu_sock_recv() that ensure size of the first iovec of segment is at least hdrlen. Thanks, Laurent