From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 378843DEACC for ; Wed, 15 Apr 2026 15:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776267670; cv=none; b=AViSclzTxwwNClHmiLuUJ0SwQ8CMfexUkszlPVA+fWxxAlnuEVA+SffzlimsQeFzzDMxlvZk8GISvnTJCBIm3x6LCToi4F1jbd55sbMxKmtLWP9wWfMkK6FdARMjAXi+hJtz4cH1EcXWaTJ7I4t2xLXCWOOZZXlGxmVPJI/+xOs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776267670; c=relaxed/simple; bh=2SsUYUfpJ6Cn7ENP9SVUB703hjWJHv3onCi+Vq1hxh0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZTl8yJV8Ly+kHXFVF2Qun1ypWHXU/oIAfUeyuDT6TsphPn7+mM02JXwYHVtCMStwI/es7cA5aMcU4R2XxsCfxHKWuJXrWLUbSrMuJ022pCK3VM0wx6+d2or+BZvrzEt+fznaEKDGv1SRyVAi3QKmIplJPzBL88l1pMkrXiySmyI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=f8Zq7DjO; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=KhP1L7EG; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="f8Zq7DjO"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="KhP1L7EG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776267666; 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=Ow5K8hzTuD9W/wj2bq1mSm/2juaMM9qh5FYIv6eXqRM=; b=f8Zq7DjOmYTXBequ3/tmRfUCcwbMgHfny8aAjTmbZhXSNS8AEpGFYjEMzPw3e0Ni32ohtM eayP9CnLIwIIJh238MyNHv8+0nqqvihXJp/qDsQjZLvsVIm2kS3x6OlkG/mZwBvjMHO9Lb 7D0FZgT4rrnPzmspTxAE8od9nJksiVE= 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-5-tgvCVlYYOoyaZvmxPNij4Q-1; Wed, 15 Apr 2026 11:41:04 -0400 X-MC-Unique: tgvCVlYYOoyaZvmxPNij4Q-1 X-Mimecast-MFC-AGG-ID: tgvCVlYYOoyaZvmxPNij4Q_1776267664 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-488e1757205so24671455e9.0 for ; Wed, 15 Apr 2026 08:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776267663; x=1776872463; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Ow5K8hzTuD9W/wj2bq1mSm/2juaMM9qh5FYIv6eXqRM=; b=KhP1L7EGSGj8v7+RertazyvQR/n+mGipRSK9QxpGjQFFK/qBvI9GeunI1mk0/tTtYg LWI0d6OWYUhct8O7r+mRTct6iEsIGYp1Zt8sjjUsEVxcKJzNU5y4COQ/s8Rg6+2oPGc7 25nxsD7QB3G/cqgUCQzyI6mTuanwQ7lQBtzxKx/3eROx1u8Z0LAlsPhE8lc06A7DzIuq 418d4Nnlfd01wzlzOFMjnV741yBJuLYnSQ9yrx++ZwSNgiF+TR9+etFJoUaudbM9E7Ks qmxZ3NaFJpw5kyss4rfavX1+uRa2rk2kAHr5zYE4VQ6cu9pgdQzuzjw4T2FgyoneU5kJ ki5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776267663; x=1776872463; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ow5K8hzTuD9W/wj2bq1mSm/2juaMM9qh5FYIv6eXqRM=; b=ReClBoBAY7oBTnhgCEtZ8Py0DDrCB23Qt93VCORnxR9cmHjcAThbPxxZi/87Psuwml aKQmWSkqVqJqPWuac2QLzx4mN222L4AP49CG3CJIAFvo1JgNIvSaq6ALZlbaupkNKGZc NU790kYdsASp8tRg2CqVjwyZQsPZnCKrCJCvWRaHAR8Vw8TaQHSBMrc2MNOb1nuw6Vpa 42clmfqJyBxbMF6W4wymQgJOTy1bQwEANsF9woZY9uFt/ipnu8JDSXRVJhO/HDlob5Fg eFB2oQVhZiSRPOq/mccJRNECECfUfxPM/dR4zsUgHO373bw8dsP0xQOG+5GL87yksnOR b0Ww== X-Forwarded-Encrypted: i=1; AFNElJ9RZK+fhh+zbE/9PUb+uIDue4i5iiXlvmWbh2vF/on27y6mI7AVYBfBSLDyDIdvMAJuBFHB/iRYFZv+wI0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3NMfjFrlk3gWR91HXslNFjLVD29iUOS5Lelta5GuFMH5LWY9m RwgQS17W2QvUuzChF4a7i5ONr5RvLaqZ5A38s19KLLXck3kWpwfgIdUDtgWYDKdqCrjc3cRdskN zkfKVcPQd0Z5k5MzArpYcLPg7RHGmkvgRwUe+prblNhvJ+PabPSjFjKGVl4JnklV+aA== X-Gm-Gg: AeBDiesutSlRXafk+rNEvvLkMERkQdLsmY0yXiyITyYsFFlc/Vvk+vi7QCw4ge7aqey UGcm9hlQlJi3GR/1i9oxgw6DSMWqOF7JC6rsWpKEYzlUhb3W/EDABuOgCszZt6dneJkMmUF1aPK +LCX4ZdyTpN7LFkd3p3Tk+bO1VGMLbPBw70tvJNqRrtgjSBI/6R0ESDNXSWipaN2nOtltP/EUBt fSLBx2DdnUpGOSRW/YaYFB5CCTOmppUUWAnN5YKeQ3Oq0GoL+ee0Cl6pLAfwnQV+CDH2q1jVMcn IuDAqc/bZTAWGuHpDmY6E0XXI+cIJNObmabKOyxFJULQaINEReR4g880UIXjgTE2WMZ6EVo6gND T2ysRp+QaIz6VKq8wpNmucsCHKEVOggMLVNHEDy68DDza7FNg1wHkok0AW3JOQzgHg6UgpSo6VZ iW1sH0HQ== X-Received: by 2002:a05:600c:a106:b0:486:fbe1:2499 with SMTP id 5b1f17b1804b1-488d685fcf7mr215995685e9.22.1776267663582; Wed, 15 Apr 2026 08:41:03 -0700 (PDT) X-Received: by 2002:a05:600c:a106:b0:486:fbe1:2499 with SMTP id 5b1f17b1804b1-488d685fcf7mr215995085e9.22.1776267662938; Wed, 15 Apr 2026 08:41:02 -0700 (PDT) Received: from sgarzare-redhat (host-87-16-204-83.retail.telecomitalia.it. [87.16.204.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43ead3d5eb4sm6314894f8f.20.2026.04.15.08.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2026 08:41:02 -0700 (PDT) Date: Wed, 15 Apr 2026 17:40:55 +0200 From: Stefano Garzarella To: Luigi Leonardi Cc: Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Arseniy Krasnov , kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net v4 2/3] vsock/test: fix MSG_PEEK handling in recv_buf() Message-ID: References: <20260415-fix_peek-v4-0-8207e872759e@redhat.com> <20260415-fix_peek-v4-2-8207e872759e@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20260415-fix_peek-v4-2-8207e872759e@redhat.com> On Wed, Apr 15, 2026 at 05:09:29PM +0200, Luigi Leonardi wrote: >`recv_buf` does not handle the MSG_PEEK flag correctly: it keeps calling >`recv` until all requested bytes are available or an error occurs. > >The problem is how it calculates the number of bytes read: MSG_PEEK >doesn't consume any bytes and will re-read the same bytes from the buffer >head, so summing the return value every time is wrong. > >Moreover, MSG_PEEK doesn't consume the bytes in the buffer, so if more >bytes are requested than are available, the loop will never terminate, >because `recv` will never return EOF. For this reason, we need to compare >the number of bytes read with the number of bytes expected. > >Add a check: if the MSG_PEEK flag is present, update the byte counter and >break out of the loop only after at least the expected number of bytes >have been received; otherwise, retry after a short delay to avoid >consuming too many CPU cycles. > >This allows us to simplify the `test_stream_credit_update_test` by >reusing `recv_buf`, like some other tests already do. > >Suggested-by: Stefano Garzarella >Signed-off-by: Luigi Leonardi >--- > tools/testing/vsock/util.c | 15 +++++++++++++++ > tools/testing/vsock/vsock_test.c | 13 +------------ > 2 files changed, 16 insertions(+), 12 deletions(-) Reviewed-by: Stefano Garzarella