From patchwork Fri Jun 3 05:39:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 12868542 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 3CC26C43334 for ; Fri, 3 Jun 2022 05:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238175AbiFCFkM (ORCPT ); Fri, 3 Jun 2022 01:40:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241226AbiFCFjy (ORCPT ); Fri, 3 Jun 2022 01:39:54 -0400 Received: from mail.sberdevices.ru (mail.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22B68396AE; Thu, 2 Jun 2022 22:39:52 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mail.sberdevices.ru (Postfix) with ESMTP id 632305FD02; Fri, 3 Jun 2022 08:39:50 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1654234790; bh=lK6cao0uju2hrt5cbvoIe3JQzXNM+1hhRQxVtKooXw8=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=UNN5T8IYi3P36krQSPsocMZEVkk1kXmwNnIC+0HZHzG9ZPXNy+YBwCrFK1yu+aQKE S+O3eUEwTCM385w+UFrS3xOkkNX9WNzrAhQwJ38CyXUlOm4/xPvvy4OlqgpF7OducO y9Ibhd/FIz5EDFELcILtVQmU+JJ3urdQnhKNm36yno6Dj51Za9JOLhoC+NbXuW9LnF TPB4fMZvarF0ZoJch4RFXj+3MZQsHkWjH7af99lI5kwhBTpPghbwIyhXxGeuI0uioi krCJeBV0yb/EgPx2Qn9NRb+MS5D4ilUUbDFJOKEjWdbtdbEyuzTXYR1m5j4vE4hJh8 4X0w9BNA/nmsA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mail.sberdevices.ru (Postfix) with ESMTP; Fri, 3 Jun 2022 08:39:49 +0300 (MSK) From: Arseniy Krasnov To: Stefano Garzarella , Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , "Jakub Kicinski" , Paolo Abeni 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 5/8] vhost/vsock: enable zerocopy callback Thread-Topic: [RFC PATCH v2 5/8] vhost/vsock: enable zerocopy callback Thread-Index: AQHYdwxHDqmhK66rm0GOZ6CooDdkrg== Date: Fri, 3 Jun 2022 05:39:23 +0000 Message-ID: <04c01c03-647c-49c2-bfa3-23fd995ce5bf@sberdevices.ru> 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: netdev@vger.kernel.org X-Patchwork-State: RFC This adds zerocopy callback to vhost transport. Signed-off-by: Arseniy Krasnov --- drivers/vhost/vsock.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 0dc2229f18f7..dcb8182f5ac9 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -481,6 +481,43 @@ static bool vhost_vsock_more_replies(struct vhost_vsock *vsock) return val < vq->num; } +static int vhost_transport_zerocopy_set(struct vsock_sock *vsk, bool enable) +{ + struct vhost_vsock *vsock; + + rcu_read_lock(); + vsock = vhost_vsock_get(vsk->remote_addr.svm_cid); + + if (!vsock) { + rcu_read_unlock(); + return -ENODEV; + } + + vsock->zerocopy_rx_on = enable; + rcu_read_unlock(); + + return 0; +} + +static int vhost_transport_zerocopy_get(struct vsock_sock *vsk) +{ + struct vhost_vsock *vsock; + bool res; + + rcu_read_lock(); + vsock = vhost_vsock_get(vsk->remote_addr.svm_cid); + + if (!vsock) { + rcu_read_unlock(); + return -ENODEV; + } + + res = vsock->zerocopy_rx_on; + rcu_read_unlock(); + + return res; +} + static bool vhost_transport_seqpacket_allow(u32 remote_cid); static struct virtio_transport vhost_transport = { @@ -508,6 +545,9 @@ static struct virtio_transport vhost_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 = vhost_transport_zerocopy_set, + .rx_zerocopy_get = vhost_transport_zerocopy_get, .seqpacket_dequeue = virtio_transport_seqpacket_dequeue, .seqpacket_enqueue = virtio_transport_seqpacket_enqueue,