Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7187737rwp; Tue, 18 Jul 2023 11:17:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlFBP7ESPToXLZa8CeQBV5P3kkiJ2KX9TktPRJrNxqT+tq6YFwUuWhIDGajCZZNXKrf8o2OP X-Received: by 2002:a05:6402:40c5:b0:51a:4d46:4026 with SMTP id z5-20020a05640240c500b0051a4d464026mr596025edb.0.1689704267985; Tue, 18 Jul 2023 11:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689704267; cv=none; d=google.com; s=arc-20160816; b=PwZRTzYA21ablrhM0S1M95l3e+InYQllG+9LLIp0QcHnRjLiZRhBr4d8d566EvF+Kq RMgAH5N+TwqvYAX0G+dcReNgeTsX3vC+hqifC3YIlQ8YnGC3EXEan/PIWyZEVRyJ1aY/ eT4HaFhYr1Ow4VfyvqcTw7qr3Ehdz/Gy5mk6JLjzcMsuV+mWzhW/rJuCQVkXih747F30 hBuFlA1M/ZGVvRrBedWqF5ZRJWNFThG42WvDce7/HkcTPCiQf8IjGGQhwBWhDo8TW2xG faQJ7W5CBFhgnwE4oskTlnt8uscOaRMDOloh+XGxKhnL+fnEt+M4ZWRluvPmJHT82wQV nMlw== 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=tkRDIjgwoi7c8HuFjXoUTj2zb+RizwwV2GwfLVc5LoM=; fh=IiLlUAYZQ4hWuQbi3V9KE00VdjFsw4tg4Y6JCUFRLn0=; b=K2I5rTELhmIB/eqkPeepAFmLEe2k8kaMk8rQDRG2HljNraagunlE82o96qU2PNxYvK SZW8EUhY+5QcfqT0OqClDGWCsAQAk6lx2lW+jRQEYVq1a1goGUUhOpRLnSOx6iJ05JUP g3hE+Kwc3+4sCSKOhJMUPmP1tuRpsNCvzNxE4QTMJ++myzws5e7oaPBwAR/vszPiEqwi wy+kE+aXly3fmLpSbxCWctvuhq4wHqXTWyWYdkzEu9BYJ5d47Of/2gHvX8sKVtP+PWrN 013gPRVZ+DPRBGbkNGRmyRLBEhmmhbQ582q20vEH/1f8u4igdiGud/xb+lsvdhVTY68r FHjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=Mmo1l+fK; 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 v10-20020aa7d9ca000000b0051df91e0b95si1609952eds.253.2023.07.18.11.17.23; Tue, 18 Jul 2023 11:17:47 -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=Mmo1l+fK; 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 S232942AbjGRSIf (ORCPT + 99 others); Tue, 18 Jul 2023 14:08:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232692AbjGRSI0 (ORCPT ); Tue, 18 Jul 2023 14:08:26 -0400 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB7991733; Tue, 18 Jul 2023 11:08:22 -0700 (PDT) Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 6845612005D; Tue, 18 Jul 2023 21:08:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 6845612005D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1689703698; bh=tkRDIjgwoi7c8HuFjXoUTj2zb+RizwwV2GwfLVc5LoM=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=Mmo1l+fK/0woxIqGezL0OflmOtkdmUafpFBEg3/9bvYgCR7Fp4ZhhkFtIUyv+/pRe mvuvuj26b29QPvvpXlg7xa27Yw6OdcS1L8MzFCLqNWKBCWuGSTdnviaWl7XSSoi/0g 0bT1hAUvJ7F6hWyPb80Cj4g608o+tmuIBrUeSe3kRHulnQIj6tkehQKtiBenhQFVmh qQHhC3Tf/C/rRfDWhLh77fruHotLzGYCMAFIkoTPZz+lVn1f4hMav0Rer+a3emR4Of Q5uY2BqL76CPyb9Ro3zL2wBFlR6xUQmdnnAT2mCk+nUMuP32qNhx6nS4iYYVzefZvg AIgucssW0R1Yg== 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; Tue, 18 Jul 2023 21:08:18 +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; Tue, 18 Jul 2023 21:08:17 +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: [PATCH net-next v2 2/4] vsock/virtio: support to send non-linear skb Date: Tue, 18 Jul 2023 21:02:35 +0300 Message-ID: <20230718180237.3248179-3-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230718180237.3248179-1-AVKrasnov@sberdevices.ru> References: <20230718180237.3248179-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-m02.sberdevices.ru (172.16.192.103) 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: 178700 [Jul 18 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: 524 524 9753033d6953787301affc41bead8ed49c47b39d, {Tracking_from_domain_doesnt_match_to}, 100.64.160.123:7.1.2;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;p-i-exch-sc-m01.sberdevices.ru:7.1.1,5.0.1;127.0.0.199:7.1.2;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/18 13:44:00 #21634370 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,RCVD_IN_DNSWL_BLOCKED, 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 Reviewed-by: Stefano Garzarella --- 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