Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp23371511rwd; Sat, 1 Jul 2023 00:14:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlHJihn3RgMoXQxIlngkK6sVOBaI8RW6snAp8au2116FpEPYaoCWFR8t/T7GgtN9bUzEJrEo X-Received: by 2002:a81:a547:0:b0:576:a603:e733 with SMTP id v7-20020a81a547000000b00576a603e733mr4787783ywg.22.1688195689478; Sat, 01 Jul 2023 00:14:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688195689; cv=none; d=google.com; s=arc-20160816; b=bZB5Jtvv7wAAz+scBsZtkYrAV6h4kiHMIs9sWtnHmoAz2riTcPeSp4CbqfhPf128XD uv3T3Rt8z7gesCOfTiUhIgySMAoYUJbqR6KcXMWqRBZrHiAgMlBu8vxgJ6iL66fL+404 98F3oxB3x/dy1Z6guk7FaP+gOy82djdWiBMCi+Y4GdmgmM00ffS6Mqn1UrS8Qoh9JC3+ V7WE/b/710Ey8o1jZCuLlmf3938ZzW+xLSJjI2m60GPrTDjTwKEZ30QPVvQcwq673iR2 ezSy/kaWy8h+jowzbpXGhxFp1cRW1OIOKqebNayH54HgXjhGf+W+AfyMYDhSZv58H40D DOAA== 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:dkim-filter; bh=HVWROl+BBXUa2BfH+uJoxZPqiGPfyFPGa1/4nNCI6t8=; fh=PzWIi6JmlJNekYqVy23433fKO6OE4+V62ucRx731HUI=; b=JVK+308CcMYrYtCXMYAr6+LzFaI/Y6HzFR6QkAx3/gJo42tfSYeZUuKx5I0Mh8Xd1e 1kD3UyqHrWIO0BcqDCb/mPGY/4w21uFmkibsJETuB+wRZJoftv0/OJNFQEI9+TnAYlgA /RVA1iMw7ceilQpC7d2385FBomzMYWxAVpmo2wYyo5JRmdFpIM33IJNnsPlSy0IQOm6D b70DGGOl+ee/v4GgW2k8FRfEQQLmSqsQiCBygfmZVN6ScVikQMGMvjHsLR+sTUMiqOYx FnUnYPBZRPNLZ4aTbDHXQ17MMHuaB1IqbHaXTwoC82YkPYUHyOSqKjhugoSv6BZQg01D mAHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=B6Fb9tGo; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 72-20020a63004b000000b0054fd1c6d242si14050111pga.878.2023.07.01.00.14.35; Sat, 01 Jul 2023 00:14:49 -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=B6Fb9tGo; 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 S229693AbjGAGwx (ORCPT + 99 others); Sat, 1 Jul 2023 02:52:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbjGAGvc (ORCPT ); Sat, 1 Jul 2023 02:51:32 -0400 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4624729F; Fri, 30 Jun 2023 23:45:22 -0700 (PDT) Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 96FB9120007; Sat, 1 Jul 2023 09:45:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 96FB9120007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1688193905; bh=HVWROl+BBXUa2BfH+uJoxZPqiGPfyFPGa1/4nNCI6t8=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=B6Fb9tGoVllp9JkEbm0HlxqDD8/SjBZN1CW51FediVNLUcWRYfqIWY7+R0O1PDGU3 pU5Ct+Zw2Ht2Zjyn3n4FEGKW6lNrWC+Y5eyhRfE1fEMnn3XIjOTSRqk27KQu+2PPUX a6nI5NENN1QPj4a9MUZWNLmzlUN5tWDQDNepJfe7tULqhexQ4TmePIu5TuoydPAz0l WSsQfqa0eFIAYFlrHbj3v9FK2Fn9qvVSonsTIM/e+E7f+9czWJapY62yPgoYO9EYem 0S/gb/6jibtO/8vxlBmGrWyt9180jp5Ik3LPDh5YiYn49M1FiI2jR8UsrsbtGgFAIl m/GdItXsLIyXg== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Sat, 1 Jul 2023 09:45:04 +0300 (MSK) Received: from localhost.localdomain (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Sat, 1 Jul 2023 09:44:44 +0300 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 v5 03/17] vsock/virtio: support to send non-linear skb Date: Sat, 1 Jul 2023 09:39:33 +0300 Message-ID: <20230701063947.3422088-4-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230701063947.3422088-1-AVKrasnov@sberdevices.ru> References: <20230701063947.3422088-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 178380 [Jun 30 2023] X-KSMG-AntiSpam-Version: 5.9.59.0 X-KSMG-AntiSpam-Envelope-From: AVKrasnov@sberdevices.ru X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 517 517 b0056c19d8e10afbb16cb7aad7258dedb0179a79, {Tracking_from_domain_doesnt_match_to}, sberdevices.ru:7.1.1,5.0.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;127.0.0.199:7.1.2;100.64.160.123:7.1.2;p-i-exch-sc-m01.sberdevices.ru:7.1.1,5.0.1, FromAlignment: s, {Tracking_white_helo}, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2023/07/01 04:02:00 #21597763 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,URIBL_BLOCKED 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 For non-linear skb use its pages from fragment array as buffers in virtio tx queue. These pages are already pinned by 'get_user_pages()' during such skb creation. Signed-off-by: Arseniy Krasnov --- Changelog: v4 -> v5: * Use 'out_sgs' variable to index 'bufs', not only 'sgs'. * Move smaller branch above, see 'if (!skb_is_nonlinear(skb)'). * Remove blank line. * R-b from Bobby Eshleman removed due to patch update. net/vmw_vsock/virtio_transport.c | 40 +++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index e95df847176b..6cbb45bb12d2 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -100,7 +100,9 @@ virtio_transport_send_pkt_work(struct work_struct *work) vq = vsock->vqs[VSOCK_VQ_TX]; for (;;) { - struct scatterlist hdr, buf, *sgs[2]; + /* +1 is for packet header. */ + struct scatterlist *sgs[MAX_SKB_FRAGS + 1]; + struct scatterlist bufs[MAX_SKB_FRAGS + 1]; int ret, in_sg = 0, out_sg = 0; struct sk_buff *skb; bool reply; @@ -111,12 +113,38 @@ virtio_transport_send_pkt_work(struct work_struct *work) virtio_transport_deliver_tap_pkt(skb); reply = virtio_vsock_skb_reply(skb); + sg_init_one(&bufs[out_sg], virtio_vsock_hdr(skb), + sizeof(*virtio_vsock_hdr(skb))); + sgs[out_sg] = &bufs[out_sg]; + out_sg++; + + if (!skb_is_nonlinear(skb)) { + if (skb->len > 0) { + sg_init_one(&bufs[out_sg], skb->data, skb->len); + sgs[out_sg] = &bufs[out_sg]; + out_sg++; + } + } else { + struct skb_shared_info *si; + int i; + + si = skb_shinfo(skb); + + for (i = 0; i < si->nr_frags; i++) { + skb_frag_t *skb_frag = &si->frags[i]; + void *va = page_to_virt(skb_frag->bv_page); - sg_init_one(&hdr, virtio_vsock_hdr(skb), sizeof(*virtio_vsock_hdr(skb))); - sgs[out_sg++] = &hdr; - if (skb->len > 0) { - sg_init_one(&buf, skb->data, skb->len); - sgs[out_sg++] = &buf; + /* We will use 'page_to_virt()' for userspace page here, + * because virtio layer will call 'virt_to_phys()' later + * to fill buffer descriptor. We don't touch memory at + * "virtual" address of this page. + */ + sg_init_one(&bufs[out_sg], + va + skb_frag->bv_offset, + skb_frag->bv_len); + sgs[out_sg] = &bufs[out_sg]; + out_sg++; + } } ret = virtqueue_add_sgs(vq, sgs, out_sg, in_sg, skb, GFP_KERNEL); -- 2.25.1