From patchwork Sat Jun 10 00:58:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bobby Eshleman X-Patchwork-Id: 105863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1279430vqr; Fri, 9 Jun 2023 17:59:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gmIalB1kf6SOe92AawHIBsZLiPRoZqlqmppj8I17f5E2mQ9tlppkzfoIQN4vKCMmaM1+T X-Received: by 2002:a17:90b:3909:b0:255:54ce:c3a9 with SMTP id ob9-20020a17090b390900b0025554cec3a9mr2145016pjb.24.1686358793163; Fri, 09 Jun 2023 17:59:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686358793; cv=none; d=google.com; s=arc-20160816; b=weZWtHYNOiQMw02A4jI5jEpIqTAjMidIRElxxTRVKCR+nVkhzdEyRhphrMk6yh5WTf Npl53DTt/I1wToV+EXfOR9c5FeHuN1DBUnHLoN0NEHkuPvQmeEbZ037z7pvESifdN14H g7UIMYweS9z2m91BRrnOlX1DzrqX40VAqTJ9OqiHXoSd/779Pa428P169F9sEc/3KcCQ jO1Vn2t6GXF3hLrRvREcQqJBxYkEY3uFqLyjYKYKbYc7tPegsSuMSFU/V+7ph5ZTqiRd uHHd26tzHC+Zjej4lsXqBnVHIQSON4Duat8j7XxJk8n5BbZIjm6H+JCrHMiKRnthlrgi o7NA== 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=EPbFW7iZxMvtqbmK4J1z/miwrV0fMapcvT6vEzi4BQ0=; b=ZJpmYhlf0clmZk4ExOf80grQLo1T93Lhfd3uplpi6HeSYjo3KJX5eVDX86IrahpiIy lEzBmphDO9ITbqQ+QszHx68FsCOYdZp01/0YPOe+qFNowZRaH2jA+uaLlVcidRVTtcU7 xUZbb6qk3IAFH2SMcAwwK3mLADyciaYWkgpNYRQKPtgQVGHc6Hs6dZij8y+ODUBok90s cqRkkISTEkak8t/sKOZ9AZSDsjt8HtV4JC+m2x9Jv0azB5BItHyOqnbWI7gxeHPIvp0j AjkjJSmsBmbNTLM+a99ZF1kDjOlT9tIz3X94jZGHAMfGOFWBMVy9zqPIiDO5YEz8YZcD Zzsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=eHIaq50n; 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 mm22-20020a17090b359600b0025693afd311si5148004pjb.43.2023.06.09.17.59.40; Fri, 09 Jun 2023 17:59:53 -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=eHIaq50n; 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 S232531AbjFJA6w (ORCPT + 99 others); Fri, 9 Jun 2023 20:58:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230044AbjFJA6u (ORCPT ); Fri, 9 Jun 2023 20:58:50 -0400 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2737E3583 for ; Fri, 9 Jun 2023 17:58:47 -0700 (PDT) Received: by mail-qt1-x82c.google.com with SMTP id d75a77b69052e-3f9b5ec058aso20959551cf.0 for ; Fri, 09 Jun 2023 17:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1686358726; x=1688950726; 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=EPbFW7iZxMvtqbmK4J1z/miwrV0fMapcvT6vEzi4BQ0=; b=eHIaq50noFLOTfklzASCj2kkioU8QAZElobxZznaqVwCR+W0ZXU3bcPNgvc+WQtA4V ZPh99Ldk0TcosIYZJPhQcTKxuga8iR/gP2SlRfSF/FXq8qouuVLQEsvyDEM1zPWWBJkx hn7nWcxMz2c+xwvGdDgizok4EVHbTFiyq5QCVqNCKK6jxRyu1TMqWnnTzsKU8WOvy3+s SctSa77Chu2Ul63vM3KhNb3YEXgAXN6A4L0LtRz+e/cWMr+oRB4J33cwIds5xkVmkNCR 6MA/4rN3clrZtTnCTJSBUyzkmkGrwcx3x3L6DJl/fPcZ089lMjkv3tCg+HkV4kISDjXE WTDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686358726; x=1688950726; 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=EPbFW7iZxMvtqbmK4J1z/miwrV0fMapcvT6vEzi4BQ0=; b=OzCudKAJM942o6GCS8RNrvrpsexws28z2bZpHZG4O8loKZjxcvM2helh0CM8JKWSPc 71nUvdW3EuUSF0pfTNcWfnwCIJYDXlT8TLc6L7dpdJ9Nv4ryrpWtxTac6qAfEzk+KnW9 v8ntIYPeTAjgd6XGT7zVhEF04juCw2oaXhUHslRnMMRzi3+uN4Hn+ty8o14WiUdYinNs pX2JmV+nYu5dHuZYG2mcnl6P9CtC5nfuQ8whvD2F98TJVEG08m2ZGrRD+UT/JTEEjlUC 9L3VXiZrJX2pMbu4b04mlDxOdLR5AxrbB3MNcwgH+Dv+ah0NPf8pBC7t8JAu9a4l6QWB G+BQ== X-Gm-Message-State: AC+VfDxDf/OZdnfh+3IeCeWjheoTTjDU/TIyfGyuGp6NWW62TpPBsomH hlV0B0hGNj+1oJdQaIbc+5mFjQ== X-Received: by 2002:a05:6214:509b:b0:625:b3a2:f655 with SMTP id kk27-20020a056214509b00b00625b3a2f655mr3585747qvb.30.1686358726197; Fri, 09 Jun 2023 17:58:46 -0700 (PDT) Received: from [172.17.0.4] ([130.44.212.126]) by smtp.gmail.com with ESMTPSA id x17-20020a0ce251000000b00606750abaf9sm1504075qvl.136.2023.06.09.17.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 17:58:45 -0700 (PDT) From: Bobby Eshleman Date: Sat, 10 Jun 2023 00:58:29 +0000 Subject: [PATCH RFC net-next v4 2/8] vsock: refactor transport lookup code MIME-Version: 1.0 Message-Id: <20230413-b4-vsock-dgram-v4-2-0cebbb2ae899@bytedance.com> References: <20230413-b4-vsock-dgram-v4-0-0cebbb2ae899@bytedance.com> In-Reply-To: <20230413-b4-vsock-dgram-v4-0-0cebbb2ae899@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_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768275357489104420?= X-GMAIL-MSGID: =?utf-8?q?1768275357489104420?= Introduce new reusable function vsock_connectible_lookup_transport() that performs the transport lookup logic. No functional change intended. Signed-off-by: Bobby Eshleman Reviewed-by: Stefano Garzarella --- net/vmw_vsock/af_vsock.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index ffb4dd8b6ea7..74358f0b47fa 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -422,6 +422,22 @@ static void vsock_deassign_transport(struct vsock_sock *vsk) vsk->transport = NULL; } +static const struct vsock_transport * +vsock_connectible_lookup_transport(unsigned int cid, __u8 flags) +{ + const struct vsock_transport *transport; + + if (vsock_use_local_transport(cid)) + transport = transport_local; + else if (cid <= VMADDR_CID_HOST || !transport_h2g || + (flags & VMADDR_FLAG_TO_HOST)) + transport = transport_g2h; + else + transport = transport_h2g; + + return transport; +} + /* Assign a transport to a socket and call the .init transport callback. * * Note: for connection oriented socket this must be called when vsk->remote_addr @@ -462,13 +478,8 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk) break; case SOCK_STREAM: case SOCK_SEQPACKET: - if (vsock_use_local_transport(remote_cid)) - new_transport = transport_local; - else if (remote_cid <= VMADDR_CID_HOST || !transport_h2g || - (remote_flags & VMADDR_FLAG_TO_HOST)) - new_transport = transport_g2h; - else - new_transport = transport_h2g; + new_transport = vsock_connectible_lookup_transport(remote_cid, + remote_flags); break; default: return -ESOCKTNOSUPPORT;