From patchwork Sun Nov 6 19:38:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13033537 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 4600DC43217 for ; Sun, 6 Nov 2022 19:38:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbiKFTih (ORCPT ); Sun, 6 Nov 2022 14:38:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229947AbiKFTig (ORCPT ); Sun, 6 Nov 2022 14:38:36 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC5F52DC0; Sun, 6 Nov 2022 11:38:34 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 2A8055FD04; Sun, 6 Nov 2022 22:38:33 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1667763513; bh=EEoKcv2eN2h4TIogPlImzmkvyAMOSyDfOwiRdxm5/Uc=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=a5pOFkdns/nGHJF2r6nW/22qh5m7oJXUahsvuEBQLu/LxnAIvk1vOItoJewBTKi+M tMAr4D7LOi1HkHOR81DTcrw0U4KexZtPgLBlmM+V1VJj9ZmoFL78xFDQcRKSBQiiMH hGbm53187KsXpDmUsh9JXd9Cx1kZc84y+lXtGjhzlqiM3VLdxnwZIqXt3YR3C8g4Bu HIWDpl75SJ2tN7KJICVcy37rvNnFLNj/EubHp+TQrvME5ZzwvCdp/nLJ1Dp8a1trWt Rd4uIl4wQJVaCJjtOqFVkQ4YXeBLfrjxsK/mW0x3TmhsOXKNRYRnzCOtxVKN2gKh4H qtsK72AbxY27w== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 6 Nov 2022 22:38:32 +0300 (MSK) From: Arseniy Krasnov To: Stefano Garzarella , Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , "edumazet@google.com" , Jakub Kicinski , Paolo Abeni , 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 v3 02/11] virtio/vsock: update, 'virtio_transport_recv_pkt()' Thread-Topic: [RFC PATCH v3 02/11] virtio/vsock: update, 'virtio_transport_recv_pkt()' Thread-Index: AQHY8hdI/Cz9wqLJ60mqLRsUlqPepQ== Date: Sun, 6 Nov 2022 19:38:01 +0000 Message-ID: In-Reply-To: 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: <271160C92372DC4C8A0D7E0DB977117E@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: 2022/11/06 12:52:00 #20573807 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC Pass destination socket to 'virtio_transport_recv_pkt()'. This is needed, because caller may need socket structure, thus to avoid socket extra lookup in connect/bind lists, socket is passed as parameter(if it is NULL, then lookup is performed in the same way as before). Signed-off-by: Arseniy Krasnov --- drivers/vhost/vsock.c | 2 +- include/linux/virtio_vsock.h | 1 + net/vmw_vsock/virtio_transport.c | 2 +- net/vmw_vsock/virtio_transport_common.c | 12 +++++++----- net/vmw_vsock/vsock_loopback.c | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 65475d128a1d..6f3d9f02cc1d 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -548,7 +548,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work) if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid && le64_to_cpu(pkt->hdr.dst_cid) == vhost_transport_get_local_cid()) - virtio_transport_recv_pkt(&vhost_transport, pkt); + virtio_transport_recv_pkt(&vhost_transport, NULL, pkt); else virtio_transport_free_pkt(pkt); diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h index d02cb7aa922f..c1be40f89a89 100644 --- a/include/linux/virtio_vsock.h +++ b/include/linux/virtio_vsock.h @@ -150,6 +150,7 @@ virtio_transport_dgram_enqueue(struct vsock_sock *vsk, void virtio_transport_destruct(struct vsock_sock *vsk); void virtio_transport_recv_pkt(struct virtio_transport *t, + struct sock *sk, struct virtio_vsock_pkt *pkt); void virtio_transport_free_pkt(struct virtio_vsock_pkt *pkt); void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct virtio_vsock_pkt *pkt); diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index 19909c1e9ba3..0305f94c98bb 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -560,7 +560,7 @@ static void virtio_transport_rx_work(struct work_struct *work) pkt->len = len - sizeof(pkt->hdr); virtio_transport_deliver_tap_pkt(pkt); - virtio_transport_recv_pkt(&virtio_transport, pkt); + virtio_transport_recv_pkt(&virtio_transport, NULL, pkt); } } while (!virtqueue_enable_cb(vq)); diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 37e8dbfe2f5d..444764869670 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -1238,11 +1238,11 @@ static bool virtio_transport_valid_type(u16 type) * lock. */ void virtio_transport_recv_pkt(struct virtio_transport *t, + struct sock *sk, struct virtio_vsock_pkt *pkt) { struct sockaddr_vm src, dst; struct vsock_sock *vsk; - struct sock *sk; bool space_available; vsock_addr_init(&src, le64_to_cpu(pkt->hdr.src_cid), @@ -1267,12 +1267,14 @@ void virtio_transport_recv_pkt(struct virtio_transport *t, /* The socket must be in connected or bound table * otherwise send reset back */ - sk = vsock_find_connected_socket(&src, &dst); if (!sk) { - sk = vsock_find_bound_socket(&dst); + sk = vsock_find_connected_socket(&src, &dst); if (!sk) { - (void)virtio_transport_reset_no_sock(t, pkt); - goto free_pkt; + sk = vsock_find_bound_socket(&dst); + if (!sk) { + (void)virtio_transport_reset_no_sock(t, pkt); + goto free_pkt; + } } } diff --git a/net/vmw_vsock/vsock_loopback.c b/net/vmw_vsock/vsock_loopback.c index 169a8cf65b39..37c28bbeafaf 100644 --- a/net/vmw_vsock/vsock_loopback.c +++ b/net/vmw_vsock/vsock_loopback.c @@ -134,7 +134,7 @@ static void vsock_loopback_work(struct work_struct *work) list_del_init(&pkt->list); virtio_transport_deliver_tap_pkt(pkt); - virtio_transport_recv_pkt(&loopback_transport, pkt); + virtio_transport_recv_pkt(&loopback_transport, NULL, pkt); } }