From patchwork Fri Jun 3 05:41:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 12868588 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 A03A9C43334 for ; Fri, 3 Jun 2022 05:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241245AbiFCFlk (ORCPT ); Fri, 3 Jun 2022 01:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235472AbiFCFli (ORCPT ); Fri, 3 Jun 2022 01:41:38 -0400 Received: from mail.sberdevices.ru (mail.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B04736E00; Thu, 2 Jun 2022 22:41:36 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mail.sberdevices.ru (Postfix) with ESMTP id 540745FD02; Fri, 3 Jun 2022 08:41:34 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1654234894; bh=7SQwZfSXoKBQPVHv3x8ggArLeuvotFhF1XdrXYyomo8=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=pfpY1GpGZpjUI7/Yy8OekTKh7rv7qGUQ1Us2G65PTuuCs1MeULhER0U/782zFvMxw 445IvEgRuuvR9yqHkkc7NE0MM4s9oUVMfqOvfGyxpN8OiRxtG7zcWYYwWSEYwSEYRj OPinC+ZJCuifVAa4b+cAbB8fGUPgoP/udhhK3VQtimAZaQppi4smDZk+chbnyQs6Ud N7mcZSi0KGgtG6EC7lqt6D71VxGylOJTmKthe2TvwR+0UAyRR0ETxf9Ls/bANUitut l8Go0XPzeHedM2n6H65Nw9EdtXg6ooNRr0FgI5alCdYL+uVivhEXuPzZhnGwehrPX+ kDRr/2lMOtL5g== Received: from S-MS-EXCH02.sberdevices.ru (S-MS-EXCH02.sberdevices.ru [172.16.1.5]) by mail.sberdevices.ru (Postfix) with ESMTP; Fri, 3 Jun 2022 08:41:34 +0300 (MSK) From: Arseniy Krasnov To: Stefano Garzarella , Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Paolo Abeni , Jakub Kicinski CC: "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , kernel , Krasnov Arseniy , Arseniy Krasnov Subject: [RFC PATCH v2 6/8] virtio/vsock: enable zerocopy callback Thread-Topic: [RFC PATCH v2 6/8] virtio/vsock: enable zerocopy callback Thread-Index: AQHYdwyFKI2EahWo0ki3hG6/uJhhrg== Date: Fri, 3 Jun 2022 05:41:07 +0000 Message-ID: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.1.12] Content-ID: 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: 2022/06/03 01:19:00 #19656765 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This adds zerocopy callback for virtio transport. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport.c | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index 19909c1e9ba3..2e05b01caa94 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -64,6 +64,7 @@ struct virtio_vsock { u32 guest_cid; bool seqpacket_allow; + bool zerocopy_rx_on; }; static u32 virtio_transport_get_local_cid(void) @@ -455,6 +456,45 @@ static void virtio_vsock_rx_done(struct virtqueue *vq) static bool virtio_transport_seqpacket_allow(u32 remote_cid); +static int +virtio_transport_zerocopy_set(struct vsock_sock *vsk, bool enable) +{ + struct virtio_vsock *vsock; + + rcu_read_lock(); + vsock = rcu_dereference(the_virtio_vsock); + + if (!vsock) { + rcu_read_unlock(); + return -ENODEV; + } + + vsock->zerocopy_rx_on = enable; + rcu_read_unlock(); + + return 0; +} + +static int +virtio_transport_zerocopy_get(struct vsock_sock *vsk) +{ + struct virtio_vsock *vsock; + bool res; + + rcu_read_lock(); + vsock = rcu_dereference(the_virtio_vsock); + + if (!vsock) { + rcu_read_unlock(); + return -ENODEV; + } + + res = vsock->zerocopy_rx_on; + rcu_read_unlock(); + + return res; +} + static struct virtio_transport virtio_transport = { .transport = { .module = THIS_MODULE, @@ -480,6 +520,9 @@ static struct virtio_transport virtio_transport = { .stream_rcvhiwat = virtio_transport_stream_rcvhiwat, .stream_is_active = virtio_transport_stream_is_active, .stream_allow = virtio_transport_stream_allow, + .zerocopy_dequeue = virtio_transport_zerocopy_dequeue, + .rx_zerocopy_set = virtio_transport_zerocopy_set, + .rx_zerocopy_get = virtio_transport_zerocopy_get, .seqpacket_dequeue = virtio_transport_seqpacket_dequeue, .seqpacket_enqueue = virtio_transport_seqpacket_enqueue,