Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18049971rwd; Tue, 27 Jun 2023 10:53:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6IVH0mmPXj4IonCjY1OUCR+lSj0XSKN+4+SpTySik0grHnDwznhJ1x2sJgW6yGPdB2n9Fa X-Received: by 2002:a17:907:1c06:b0:992:e1:93c with SMTP id nc6-20020a1709071c0600b0099200e1093cmr3530312ejc.37.1687888382825; Tue, 27 Jun 2023 10:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687888382; cv=none; d=google.com; s=arc-20160816; b=gVuDVDWDgbmM/NSCSzCQMhdMqWHMlbqTZDXM78gP+qlgdIV7FCt458EbodMHik/KQu nDDArkOq4VxbIh5V8k9qBpQc/wd2emWxR/Wv+rdtzHermKPV5MTI5BnUuNJK7wTH89dU eYaEa+U091zP83AofCb84U6GkuudSioy2KUF/HNxhwE9PEfjU2k1pGUumxP3DiGMxqOw Z0B5ni4Sgc38IoAFxLZOeOM74As52V3ALA/UbVjZgjZzxLY7NNm9e29qz4qwgtBmDRs9 E/jhFRVNlWX1LnfHLFFi9+wHjNJQS7qfGPLomQ6VDcZJdO9gzjOfI8vmSUTfziOuuJAM 9uxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9jrnt+MmJKUYvCt2TBQZCoAXPj+BR7ObJDIcBWoLltM=; fh=gIf5LuFLpOdUf1GBsTuwThIGsioNEz+4x9cRrY2Gdic=; b=GPMmMJj/9vbtsy5CUJyACoiZ6mncAN5oMG8PQVb9Y0fqr1i+60j3Qna51Opm2P/XJy ZeZdDTRaHFi6tXRMBcmS7sqnM43g2fE/2pgf40di60+l77TUXdblX/5rZMaB41ltYjvP yZibXNuSy96qTGGP86LO4BGKoCEjhAz/kPnQKQDt8b/bhtpSMS96xlKgqC2VW2yyQVn6 qlUrvX8T2RBb4H8V6+qYfYmgVogHrRBylVMtlOB0vtKaoCMR2UyVdUR8qzJZEkXQ9gPz EP+5+YgQf5z4YnBkhXoK1V0KWh2pPFrc7DSIV7xGYhotUopcbfVJLmtP+D0CYI3zdle3 Va7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fMVqxpqF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l24-20020a1709060e1800b00977cc27c42esi4407069eji.579.2023.06.27.10.52.36; Tue, 27 Jun 2023 10:53:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fMVqxpqF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231722AbjF0RhU (ORCPT + 99 others); Tue, 27 Jun 2023 13:37:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231651AbjF0RhM (ORCPT ); Tue, 27 Jun 2023 13:37:12 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 556DD272D; Tue, 27 Jun 2023 10:37:11 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1b7db2e162cso19065735ad.1; Tue, 27 Jun 2023 10:37:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687887431; x=1690479431; 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=9jrnt+MmJKUYvCt2TBQZCoAXPj+BR7ObJDIcBWoLltM=; b=fMVqxpqFDIZeWw2s+njNjftXa7SeHIKEqOXAF1O1i/CkGCjB5kgjVRxXKk7hUHbFwa HjcGS/m0mm9WAANhdhb+nz4SMAQ3mN+rChiIsxP8mr/8z0KsP8QgMYTVgdjZ7PvOSXBz GzRHMlXleSZ6y80j63vAdmqx9eJAm5jQoBOxypiIq5A9dzj10nB9hrF5xSdsHxIxNJ9F VOuQBbTb1qAL/09MH+WPgynqhZbmr6k7aoc9gHyuQmGiF3EEu5hbFyuBqMG0f78+hTDF 61zB+FW6VQ4Sxz4hk8SiDNuimg879WL1xiI8dyuRurzC/jozDWXVF3c/9Krav/WJz9w0 Pxdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687887431; x=1690479431; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9jrnt+MmJKUYvCt2TBQZCoAXPj+BR7ObJDIcBWoLltM=; b=O1JeZ1N5C+DGkskpVfdFTFPuT4g+ASykIY9LUB4wsaQykg//tZXzJVWi3CuPeRwlM1 8VBEsL+LQx0+uvK+r6mdWQ9LNPK0s0nElXrp1l9x3uqntYp+XPQCvCUxLJ0zzrxoXyLm cOUIXeaGsiMAEqpSRBX5Z1iSWLbssj59xBHN6hbQdNal7vSeFFLAgtN90DWj0Ia4YeQl qRsv6LWFqbXrUr4v8Bf1MDvBljyGlcKy0c41CIlxI2Zj75wIyMH7VyDkMdrbJbZYALFg oYHkxlTOb25paKKGqFKDIKWOaG4EYj6fd/9ou7ek44zYc1MWsomeKLUx2MFdVh4CE25i oSXw== X-Gm-Message-State: AC+VfDzvyemX33+9eRypmWoCHIKi+pZO/C+H/C2xVDzvYOKCGc9oCQRj xn0g1T/LBGw2Lr1XWgocu1g= X-Received: by 2002:a17:902:9341:b0:1b8:b51:694e with SMTP id g1-20020a170902934100b001b80b51694emr4195898plp.62.1687887430751; Tue, 27 Jun 2023 10:37:10 -0700 (PDT) Received: from localhost (ec2-54-67-115-33.us-west-1.compute.amazonaws.com. [54.67.115.33]) by smtp.gmail.com with ESMTPSA id b8-20020a170902a9c800b001b5247cac3dsm6245649plr.110.2023.06.27.10.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 10:37:10 -0700 (PDT) Date: Tue, 27 Jun 2023 01:32:37 +0000 From: Bobby Eshleman To: Arseniy Krasnov Cc: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@sberdevices.ru, oxffffaa@gmail.com Subject: Re: [RFC PATCH v1 1/4] virtio/vsock: rework MSG_PEEK for SOCK_STREAM Message-ID: References: <20230618062451.79980-1-AVKrasnov@sberdevices.ru> <20230618062451.79980-2-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230618062451.79980-2-AVKrasnov@sberdevices.ru> X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DATE_IN_PAST_12_24, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jun 18, 2023 at 09:24:48AM +0300, Arseniy Krasnov wrote: > This reworks current implementation of MSG_PEEK logic: > 1) Replaces 'skb_queue_walk_safe()' with 'skb_queue_walk()'. There is > no need in the first one, as there are no removes of skb in loop. > 2) Removes nested while loop - MSG_PEEK logic could be implemented > without it: just iterate over skbs without removing it and copy > data from each until destination buffer is not full. > > Signed-off-by: Arseniy Krasnov > --- > net/vmw_vsock/virtio_transport_common.c | 41 ++++++++++++------------- > 1 file changed, 19 insertions(+), 22 deletions(-) > > diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c > index b769fc258931..2ee40574c339 100644 > --- a/net/vmw_vsock/virtio_transport_common.c > +++ b/net/vmw_vsock/virtio_transport_common.c > @@ -348,37 +348,34 @@ virtio_transport_stream_do_peek(struct vsock_sock *vsk, > size_t len) > { > struct virtio_vsock_sock *vvs = vsk->trans; > - size_t bytes, total = 0, off; > - struct sk_buff *skb, *tmp; > - int err = -EFAULT; > + struct sk_buff *skb; > + size_t total = 0; > + int err; > > spin_lock_bh(&vvs->rx_lock); > > - skb_queue_walk_safe(&vvs->rx_queue, skb, tmp) { > - off = 0; > + skb_queue_walk(&vvs->rx_queue, skb) { > + size_t bytes; > > - if (total == len) > - break; > + bytes = len - total; > + if (bytes > skb->len) > + bytes = skb->len; > > - while (total < len && off < skb->len) { > - bytes = len - total; > - if (bytes > skb->len - off) > - bytes = skb->len - off; > + spin_unlock_bh(&vvs->rx_lock); > > - /* sk_lock is held by caller so no one else can dequeue. > - * Unlock rx_lock since memcpy_to_msg() may sleep. > - */ > - spin_unlock_bh(&vvs->rx_lock); > + /* sk_lock is held by caller so no one else can dequeue. > + * Unlock rx_lock since memcpy_to_msg() may sleep. > + */ > + err = memcpy_to_msg(msg, skb->data, bytes); > + if (err) > + goto out; > > - err = memcpy_to_msg(msg, skb->data + off, bytes); > - if (err) > - goto out; > + total += bytes; > > - spin_lock_bh(&vvs->rx_lock); > + spin_lock_bh(&vvs->rx_lock); > > - total += bytes; > - off += bytes; > - } > + if (total == len) > + break; > } > > spin_unlock_bh(&vvs->rx_lock); > -- > 2.25.1 > That cleans up nicely! LGTM. Reviewed-by: Bobby Eshleman