From patchwork Wed Jul 19 00:50:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bobby Eshleman X-Patchwork-Id: 122336 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2111772vqt; Tue, 18 Jul 2023 17:52:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlFrua9dtRWubU0s+cj5nnsh0rgSwIsVE2ivFZcd04YljeOZQ1pR+aMTwPL/uMS2Asoy8ZlF X-Received: by 2002:a17:90a:d915:b0:263:e122:1bc7 with SMTP id c21-20020a17090ad91500b00263e1221bc7mr750064pjv.23.1689727977639; Tue, 18 Jul 2023 17:52:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689727977; cv=none; d=google.com; s=arc-20160816; b=rREBqUdkh00Oa6rbCymPXrt1G5ntbLe5n6A7cHuHVedP7yIL5SL2ho0ZzczDoOF4sd P/ETfjDaXX/v+JnwruhRGM83MQfsHkBy6TB842qkEueihV+qlv6IfYfB1p/c0L15pcwH wujDlwVSvaJoyrXs+dMKQKAc2yPAmCmLI1BWOTBcmOMnelggXbXN14S1APx9BrP67a6N AoXwysWz7oYwd7hK6GNJN/ru1MQ/SpCh/BCnMK/dk86ts2VLWnkHIW1iy4+uEI9fGdqh rmmd49rCFf/kCW7S7Ia1+a6vwPv2oalQtNBWFPbCl3LtLQ2SO8s/lFyubbvwWyrEeMXT 4WZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=2jDdPbzH4onHNW5mQ+nHZzIsBXIDVnlx9OcaE5Mwsjc=; fh=jejeGpHkr9vVlEyvdVBCSLFut92eNP6vAI+O1tx9vp4=; b=YoT1nI6K32BTW94Jl6uFv4n02VbTq9ITYjtRdDA9g9aL+A4YH3wJfOkhfF7n+b7S8V hpTdnHy2lirdTnb+fFkGBUGtcwrkcvK/xayaH5sYJsAUffvm02N/4n67/JS3TTqhWYFY cCREv95efCDaQpUDDAduBRI3acWnaEQQWBdPUaDKHRNZhPrFMBvvdLxpuyS5plPfUBBF sQi/ihncep7+8rkZJw3FUSBHWS4RE8BpRfxohksTMNSjz2HnZ487xNJJj6mAD7TN0BKe n0XSJnu9QOqc5dzGjGPSdV7YRpPlwfFBug/B11qiMl5f+yZ5hw5zi06N6tDEMp49FPTA vcHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=eepobj0V; 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=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a2-20020a17090ad80200b00259a3c7fb52si343316pjv.27.2023.07.18.17.52.44; Tue, 18 Jul 2023 17:52:57 -0700 (PDT) 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=@bytedance.com header.s=google header.b=eepobj0V; 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=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229689AbjGSAvW (ORCPT + 99 others); Tue, 18 Jul 2023 20:51:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230144AbjGSAvB (ORCPT ); Tue, 18 Jul 2023 20:51:01 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A8C01A8 for ; Tue, 18 Jul 2023 17:50:17 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-76571dae5feso589566385a.1 for ; Tue, 18 Jul 2023 17:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689727816; x=1692319816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2jDdPbzH4onHNW5mQ+nHZzIsBXIDVnlx9OcaE5Mwsjc=; b=eepobj0Vc1efSCz7ybajZtwpgJ5AghKHP5/txHgJFHHyY4FHoRmuQTm5LGfIesiqT/ PD2ZTDjYtuPJ8w+SRAsKlf9SW1Ib1pYpdFc84jBiO4Y0y16uLALHKiYXgvuGWkyfqOw2 oljI0n/oJhPluX28Ya2d//kILPfh1ZUF/MMYgawk3dKZjJ9oe5nOBGUQyNi8SIIIm7c0 DTD5w9IYzqxsaAfBozvvoYSNWWlOsx0KjrDpjNiA32/Tivs28ml9xEjAwGuMBfpc3bKv z6IhJoR+YcKaXykod/FSL6o2Y+i/IWqmY0UulvwuRxY56EXpN3w9sHfLd323IuK7M8Tu AOgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689727816; x=1692319816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2jDdPbzH4onHNW5mQ+nHZzIsBXIDVnlx9OcaE5Mwsjc=; b=SNzEwskg9rPm/Bl9CH1HSdwC26W7b8w8Nt0ZFgPA82knQu3f+MAf3F/RxW7BIXkdGr 1MTflwjNjyATClkawcGaZBVupWno5KstbXT1dkw6f7bliSJ9xfWEMrLFOA8qoc8sw+35 WAKn9a3VHP4NajC+exEjW0yBnr9MxkpH7T5emsmsLHzTOaUgcJqw7ywOjDn/56LRVeyY vken5GjOGWqk2QZCUsFjdTViMdkN5fpcCmXxsFef+iMNxKYAKWd371X1Y0PI8XCufR2X WTKFEPlosfPpdGbG/uREY8rJHE2XYJqEtXyiGn4HahIxgqIWEhS2nEBtJtVwgn3P9HN4 KCkw== X-Gm-Message-State: ABy/qLbFQS/FXP7CcGATSwUfONm1uLJzneJN3YRlVUtnLLN5VYBGEKEA hnQuQ5c9kVHdVqjKUp2GzLd+rA== X-Received: by 2002:a05:620a:3998:b0:767:2f4a:e07a with SMTP id ro24-20020a05620a399800b007672f4ae07amr1182364qkn.68.1689727816119; Tue, 18 Jul 2023 17:50:16 -0700 (PDT) Received: from [172.17.0.7] ([130.44.212.112]) by smtp.gmail.com with ESMTPSA id c5-20020a05620a11a500b0076738337cd1sm968696qkk.1.2023.07.18.17.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 17:50:15 -0700 (PDT) From: Bobby Eshleman Date: Wed, 19 Jul 2023 00:50:12 +0000 Subject: [PATCH RFC net-next v5 08/14] af_vsock: add vsock_find_bound_dgram_socket() MIME-Version: 1.0 Message-Id: <20230413-b4-vsock-dgram-v5-8-581bd37fdb26@bytedance.com> References: <20230413-b4-vsock-dgram-v5-0-581bd37fdb26@bytedance.com> In-Reply-To: <20230413-b4-vsock-dgram-v5-0-581bd37fdb26@bytedance.com> To: Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Bryan Tan , Vishnu Dasa , VMware PV-Drivers Reviewers Cc: Dan Carpenter , Simon Horman , Krasnov Arseniy , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, bpf@vger.kernel.org, Bobby Eshleman X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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: INBOX X-GMAIL-THRID: 1771808203905383095 X-GMAIL-MSGID: 1771808203905383095 This commit adds vsock_find_bound_dgram_socket() which allows transports to find bound dgram sockets in the global dgram bind table. It is intended to be used for "routing" incoming packets to the correct sockets if the transport uses the global bind table. Signed-off-by: Bobby Eshleman --- include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index f6a0ca9d7c3e..ae6b6cdf6a4d 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h @@ -215,6 +215,7 @@ void vsock_for_each_connected_socket(struct vsock_transport *transport, void (*fn)(struct sock *sk)); int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk); bool vsock_find_cid(unsigned int cid); +struct sock *vsock_find_bound_dgram_socket(struct sockaddr_vm *addr); /**** TAP ****/ diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 0895f4c1d340..e73f3b2c52f1 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -264,6 +264,22 @@ static struct sock *vsock_find_bound_socket_common(struct sockaddr_vm *addr, return NULL; } +struct sock * +vsock_find_bound_dgram_socket(struct sockaddr_vm *addr) +{ + struct sock *sk; + + spin_lock_bh(&vsock_dgram_table_lock); + sk = vsock_find_bound_socket_common(addr, vsock_bound_dgram_sockets(addr)); + if (sk) + sock_hold(sk); + + spin_unlock_bh(&vsock_dgram_table_lock); + + return sk; +} +EXPORT_SYMBOL_GPL(vsock_find_bound_dgram_socket); + static struct sock *__vsock_find_bound_socket(struct sockaddr_vm *addr) { return vsock_find_bound_socket_common(addr, vsock_bound_sockets(addr));