From patchwork Mon Feb 6 06:59:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 53032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2089025wrn; Sun, 5 Feb 2023 23:00:58 -0800 (PST) X-Google-Smtp-Source: AK7set9tTpZQkt0hneNlJ6xJ0gjrrgHZIK1W6ekPVZZ336+OnGYGTQzacWvo6I/2ZTnaL54HIgtP X-Received: by 2002:a17:90b:3a90:b0:22c:19e4:a66f with SMTP id om16-20020a17090b3a9000b0022c19e4a66fmr20476318pjb.12.1675666858093; Sun, 05 Feb 2023 23:00:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675666858; cv=none; d=google.com; s=arc-20160816; b=HhTq2ziJJEezYA/b8L9TbgwUZmlIqmXqb1jqrtH7ri0V9eam2gd8eD4wsuLx2XB1hW bGNpXjqX4pg1m4kdHGfhnh/4ZZiXbgP50cvbyp6cwLfGvBV6kcJ1YVMZqfncbapfhMbD /QPsHECnMeW8Ny653Ol0ht4ZU9r16yvD59Ac/HUWh86dInmWKaJeTFpq2s6n9cGfbige zoR/PFgOtcpWPQXuo3cmfA9MHM8GFvMcPaDHHTsnJzjDCvxpZ4Oc7+VJZAQKY8dca0WH JOPz+l7Zbeh2ewPNaECIkj1SFQJEpmHg++doLtwZWmc2V+CL85AGOcEGTU9Yd8XHfq0C bJOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=iyACDNtFEIsHltnXG+ySQX2fasSDQiF7Yuq0gz9yqsQ=; b=WQCSuIw2Zyv3DmCkILmsZxeZHh7x1pwKpz8CJ9wUoFL11BUfuypzYuuJvJWFsU0nCY zliHmMwW3DInh+j6Avsa/Cd5sLczhagbNX+IqM1m+8R/8fbiGVsApLAv839v8tyAVPUu N18VTDzHaZ3IajH2XpM/qqkdV+j8FzjDMR0g84/eoOcEe8mNHttAvDTUzxzybzDzHO+y dJ44z6q1MYfDhS6yxY9b7323e+ZWHvWP0WmOIUa/+mqYQFsY44MzVS+TG0VI6POfBXu7 cLp6GZ9ackNXjvmI2JJQGQwp/bdBoxW+/wPCsCVN/De8RXcUiAH82xfI8kXy+xb8XxK5 ba5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=d6MsAvAT; 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 b12-20020a17090ae38c00b0022c5524d76dsi5441268pjz.24.2023.02.05.23.00.44; Sun, 05 Feb 2023 23:00:58 -0800 (PST) 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=d6MsAvAT; 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 S229826AbjBFG73 (ORCPT + 99 others); Mon, 6 Feb 2023 01:59:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229745AbjBFG71 (ORCPT ); Mon, 6 Feb 2023 01:59:27 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BFB130F0; Sun, 5 Feb 2023 22:59:23 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 934FF5FD03; Mon, 6 Feb 2023 09:59:21 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1675666761; bh=iyACDNtFEIsHltnXG+ySQX2fasSDQiF7Yuq0gz9yqsQ=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=d6MsAvATUavP20XbY45f8BnjkeT4HelwAa47K+EmXLQJBgIPLkEBtTxBabq9Wb49O CkAwduOWqsKVrRISbwq9xq1bI0hhhsrhmkX3Syapz6xLLI0Nj+JbXDD8e/JmhMqWOu BdjD/ZS58bZ3gFSGhn1MpjkSG2pN+WlC81X4zGqtisXSGQVgg+7mNSaxX9KJdRxQlX dVRNc5GTARksDDgyJG/FubDwmAeZ7qgOBtiq25zWRRHy8YiASBw0/IcsXSLb9q6fWH EP/qq0QIST6Pg+gjES8znN4UGtS/PxEUwUnVuH/q/AMnuEARRt/hKbMdH4/S8mOS07 GSq8FB6ac6cmg== Received: from S-MS-EXCH02.sberdevices.ru (S-MS-EXCH02.sberdevices.ru [172.16.1.5]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 6 Feb 2023 09:59:21 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Arseniy Krasnov , "Krasnov Arseniy" CC: "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , kernel Subject: [RFC PATCH v1 06/12] vsock/virtio: non-linear skb handling for TAP dev Thread-Topic: [RFC PATCH v1 06/12] vsock/virtio: non-linear skb handling for TAP dev Thread-Index: AQHZOfiJxMkNoIhc8E+iz5K/W09Rxg== Date: Mon, 6 Feb 2023 06:59:21 +0000 Message-ID: In-Reply-To: <0e7c6fc4-b4a6-a27b-36e9-359597bba2b5@sberdevices.ru> Accept-Language: en-US, ru-RU Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.1.12] Content-ID: <7A34F74EA281224884E6A4D1F6C61275@sberdevices.ru> MIME-Version: 1.0 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/02/06 01:18:00 #20834045 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_PASS 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?1757064051716131880?= X-GMAIL-MSGID: =?utf-8?q?1757064051716131880?= For TAP device new skb is created and data from the current skb is copied to it. This adds copying data from non-linear skb to new the skb. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 43 +++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) -- 2.25.1 diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index a1581c77cf84..05ce97b967ad 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -101,6 +101,39 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info, return NULL; } +static void virtio_transport_copy_nonlinear_skb(struct sk_buff *skb, + void *dst, + size_t len) +{ + size_t rest_len = len; + + while (rest_len && virtio_vsock_skb_has_frags(skb)) { + struct bio_vec *curr_vec; + size_t curr_vec_end; + size_t to_copy; + int curr_frag; + int curr_offs; + + curr_frag = VIRTIO_VSOCK_SKB_CB(skb)->curr_frag; + curr_offs = VIRTIO_VSOCK_SKB_CB(skb)->frag_off; + curr_vec = &skb_shinfo(skb)->frags[curr_frag]; + + curr_vec_end = curr_vec->bv_offset + curr_vec->bv_len; + to_copy = min(rest_len, (size_t)(curr_vec_end - curr_offs)); + + memcpy(dst, page_to_virt(curr_vec->bv_page) + curr_offs, + to_copy); + + rest_len -= to_copy; + VIRTIO_VSOCK_SKB_CB(skb)->frag_off += to_copy; + + if (VIRTIO_VSOCK_SKB_CB(skb)->frag_off == (curr_vec_end)) { + VIRTIO_VSOCK_SKB_CB(skb)->curr_frag++; + VIRTIO_VSOCK_SKB_CB(skb)->frag_off = 0; + } + } +} + /* Packet capture */ static struct sk_buff *virtio_transport_build_skb(void *opaque) { @@ -109,7 +142,6 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque) struct af_vsockmon_hdr *hdr; struct sk_buff *skb; size_t payload_len; - void *payload_buf; /* A packet could be split to fit the RX buffer, so we can retrieve * the payload length from the header and the buffer pointer taking @@ -117,7 +149,6 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque) */ pkt_hdr = virtio_vsock_hdr(pkt); payload_len = pkt->len; - payload_buf = pkt->data; skb = alloc_skb(sizeof(*hdr) + sizeof(*pkt_hdr) + payload_len, GFP_ATOMIC); @@ -160,7 +191,13 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque) skb_put_data(skb, pkt_hdr, sizeof(*pkt_hdr)); if (payload_len) { - skb_put_data(skb, payload_buf, payload_len); + if (skb_is_nonlinear(skb)) { + void *data = skb_put(skb, payload_len); + + virtio_transport_copy_nonlinear_skb(skb, data, payload_len); + } else { + skb_put_data(skb, pkt->data, payload_len); + } } return skb;