From patchwork Sun Jun 18 06:24:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 109571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2318929vqr; Sat, 17 Jun 2023 23:33:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5HBhWvHg9fn/y8+QP5M3feNdH3NHCVnZGDHL4GclXZ1vreMo/2MBafpr15EESg+kMLMP2j X-Received: by 2002:a05:6808:10c3:b0:398:560c:a4c5 with SMTP id s3-20020a05680810c300b00398560ca4c5mr10333822ois.55.1687070026073; Sat, 17 Jun 2023 23:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687070026; cv=none; d=google.com; s=arc-20160816; b=NxNrw4j2nlkIcM87DyPBr1feodmnplC5tphzZcX1dmVdmBgaa7LFpxeT9mnGBoiBkU oy2AlxAt3GCUTLS83bHCnIvbW8cEhRuKeBGB2vNrjNmyua5qDb15/1nBNiigfzsA3aMT WQArSZEoFdTaoKM/OBOOPP4Q1rhz9Taw3VsAXiLVm+1z+gvMiNiddg3oh+5NNh87iMCc 6qtx3kimPUi0UGf3qAeJv2ngaioZkWzgEXdpx0LKcqHYGnrbHBLvX6/vy6ErEIOK1PjL DV/sOLhY1bXoJJ+Jd8l1zOTmX74SC+p04JbJPWLUZFEzxEjrPN08i8kmo6DRwMK9dBd4 ncxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4XeoB7uPdy2JNi6czfBT5EehboC5nIlTIqZ7j5KzL3A=; b=aDCBzjPOTYsvtkv4uBYI61TnHZF/yr8hKwBeZROyc9ljasPz4ApyOAfRge5K9QGXI5 bw43EmZEUfUmuIwFsg+e3f0zy10pJUZigSewDBCMNVf3LeDlAbNcW6jxtlwtyjghd02V bWcvqZPIOpnZEh4Ul9/bIUGFhbZTY9DwXSZrpVz6atajaJT9eVXsLFwLn4JwR6cseo7v g1hWIAFSltMyGXFVPS4J2QXaAnG2wvh5tjs8GTWgieeAqdd1UkkwkqVnxOtes4vkqreo NytGS/Erb0icePmsKpsec5HMLQhdxT1+qVTVdQn2P3qfAyGFuy0q8GGbEYr36YwLy5SO dacA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=Aq8WrdxG; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a170902e55100b001b548730447si2487385plf.414.2023.06.17.23.33.32; Sat, 17 Jun 2023 23:33:46 -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=@sberdevices.ru header.s=mail header.b=Aq8WrdxG; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229619AbjFRGaO (ORCPT + 99 others); Sun, 18 Jun 2023 02:30:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229579AbjFRGaM (ORCPT ); Sun, 18 Jun 2023 02:30:12 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 703AC1719; Sat, 17 Jun 2023 23:30:06 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 529DE5FD24; Sun, 18 Jun 2023 09:30:02 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1687069802; bh=4XeoB7uPdy2JNi6czfBT5EehboC5nIlTIqZ7j5KzL3A=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Aq8WrdxGMlS1oZqdbVFXPRwGxTmxyQZvKzGkLtBRjN8QJLa1ZSxUnqn+2tnPZN0Uv P8UUJyNycKTAXUfHX9ba5Shg4Zcb1wfCcF0Qf1s45NE/QeGJ3On1Ql/WU2CPh8NbdZ IQrwxjQ6Fix4/zHUJz5Ox/sOuO96pU1T8q/5ibBL3N+8HyaSt6B+Hb3ba8G8ZhtYmX vmsrwKGxX/xTfn2vY1tWronMN3aOyKhzMpmTTwFVjz2+q2rJFKnXVl6MYdDt0teW5v yYvF4trBxsgSro5y1+YYImgLOTuJGK2ZMafoGfnnW/7unfWbJqfCIMiu7L+8waB2qp Jmazh8ElzIyJw== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 18 Jun 2023 09:30:02 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v1 1/4] virtio/vsock: rework MSG_PEEK for SOCK_STREAM Date: Sun, 18 Jun 2023 09:24:48 +0300 Message-ID: <20230618062451.79980-2-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230618062451.79980-1-AVKrasnov@sberdevices.ru> References: <20230618062451.79980-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/18 01:53:00 #21507494 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769021139305267908?= X-GMAIL-MSGID: =?utf-8?q?1769021139305267908?= 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 Reviewed-by: Bobby Eshleman --- 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);