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: 13129378 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBAD9C636D3 for ; Mon, 6 Feb 2023 06:59:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229829AbjBFG72 (ORCPT ); Mon, 6 Feb 2023 01:59:28 -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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC 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(-) 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;