Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp159962rwd; Tue, 30 May 2023 18:02:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5G+/+y0T7lOZ4cGvydTHrWbP0wQICmw/5c0+BgE+ywNpRJNw0i2yYR5o4NmWacp+gZvx4c X-Received: by 2002:a05:6a21:797:b0:10f:702a:189b with SMTP id mg23-20020a056a21079700b0010f702a189bmr4152322pzb.24.1685494923047; Tue, 30 May 2023 18:02:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685494923; cv=none; d=google.com; s=arc-20160816; b=WezXMReMCBsvrO/gaoGIZ8hT9EaICL0CqOVyi5m0x/rTzxnWP00Toe/sseFNmSr1th Up4h8ZKwbtrqh8DVBwnrhhvWR1h1uK+gw6i10B+0v9FAoNT1WQBteHLDmtApakD4sdUs hhz1E5KdIxCIz+2sYYBYycP1lomAxLRRbJ1pwpclNjxvKRZRIkfcCVeQZzDzRRj6vq7b 1zYGJ3wN6aBctJvZWuH1XFq6PPO9PjqYFY7IuT0iASj/L8CU6Lq0jmsqWf/pqFMgvxVW I272HYb6Rglijq/7cRnIYdCtTPty9OaeEpgS0AgvU6qoenX6RaRracWPKgpq89k/Kd0j cNxA== 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=2mLaP7sR8YQ85tKDJtrowu0OZeTDnTVHBsPa3lq9ex0=; b=amoaGDsehj0AwsRiJe03vgtFHteinoh9UuycxWmczq28iuqr4WH70XoxzKSwTsoLHL r7Fe9RWGXeGqF8/CWBiYajPs9qw4RaPUev5h7cPb2mtXwmM4Ak368B2iFxzOqV+AenJh uiYpyuTriTAcibphTfOZnTauoouljLHE6d4B8LcNHSgkQ9+Hb7Z/bX2YW3CT1+EdV7Oh SHdJRgU2UerKw435UDb2e+innl/S19hfI36oPKjAZRSJdqtPbuw00SdpVWTz4Rcf86vt qp5VxNo7oY4dZAFM+xwixGAJuFCgHT5A4dDiimzDHsqg/lqZUaUSYalzRTPOoqcv48fA DzBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=F3LYU0KC; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i185-20020a6254c2000000b0063b652ff9cdsi2544610pfb.404.2023.05.30.18.01.47; Tue, 30 May 2023 18:02:03 -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=F3LYU0KC; 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 S233702AbjEaAgX (ORCPT + 99 others); Tue, 30 May 2023 20:36:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233628AbjEaAgR (ORCPT ); Tue, 30 May 2023 20:36:17 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E00FE5D for ; Tue, 30 May 2023 17:35:23 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-64d2c865e4eso3897954b3a.0 for ; Tue, 30 May 2023 17:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1685493311; x=1688085311; 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=2mLaP7sR8YQ85tKDJtrowu0OZeTDnTVHBsPa3lq9ex0=; b=F3LYU0KCEVEyeO73qa8kNcgsEFHTjyCBUlVuylZXzqwEuCuD/5VVkg13vBR70tcOex xiXxOgLEUJDpbUkWKrcLTM2Y0HNCZHAXjow5BEyXJIKKQcM6GUHy1jobrJzUJV0CCV7B e3tER2nkLtU3O2jBKudUvOTH6D092x2dF0x+YYHrG65yFT7cr/la1D/zKxL2p8oJJNSP t2HhOFBEZPLV0mx8OzH394a0vczH9HjTWwnezAQjbQR+Inru6jr/6xYWqJPaSwl4L0O0 pYMT8+XdL40SC3W6P5RHpzYkdym14DqA6MCEiwt7psFOs7DepiLs7Ir/Wv38VOPkFPBK r0jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685493311; x=1688085311; 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=2mLaP7sR8YQ85tKDJtrowu0OZeTDnTVHBsPa3lq9ex0=; b=RGgant/gjzPdG/NjY1D07eDFwVjmwIy5sBknUz0tnUR+xjEGRMw175u56bR52OzGxj EAAixH3i8s1g/oKrh0cIH0NuwqrB0rGu3D+n4FhLPP+XHBTYZcW1CRwp61EtDGpKHx6Z GUVNWjVJjjwAfXk8Sk7zHxcS6xmYFVqwTb9UWnoL1XsFptRJxpL4L/vH98aziIN+u1Zf UZ0ysVyjhrrq2aQv8121Z/vT8aFz8ZVsjPXrocj4gGhleVAAKC1+dAgFeRgKcXmy514d o/4f1cM2sWs+468X3LgnWTdd9wbw6/JSB9JvfvNpQQ43WHKxduTwT9m+tDx/HYWLvOJJ sv6w== X-Gm-Message-State: AC+VfDwys3eFkKAqQLr9RoLUMdmiIFkjIfUW0iZEpgphJgKlNTEbnKB/ RtifdLUDPUbVBZHw5sQy+xc8ZQ== X-Received: by 2002:a05:6a00:2d04:b0:64d:88b:a342 with SMTP id fa4-20020a056a002d0400b0064d088ba342mr4177965pfb.30.1685493310847; Tue, 30 May 2023 17:35:10 -0700 (PDT) Received: from [172.17.0.2] (c-67-170-131-147.hsd1.wa.comcast.net. [67.170.131.147]) by smtp.gmail.com with ESMTPSA id j12-20020a62b60c000000b0064cb0845c77sm2151340pff.122.2023.05.30.17.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 17:35:10 -0700 (PDT) From: Bobby Eshleman Date: Wed, 31 May 2023 00:35:06 +0000 Subject: [PATCH RFC net-next v3 2/8] vsock: refactor transport lookup code MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230413-b4-vsock-dgram-v3-2-c2414413ef6a@bytedance.com> References: <20230413-b4-vsock-dgram-v3-0-c2414413ef6a@bytedance.com> In-Reply-To: <20230413-b4-vsock-dgram-v3-0-c2414413ef6a@bytedance.com> To: Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , "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: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@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 Introduce new reusable function vsock_connectible_lookup_transport() that performs the transport lookup logic. No functional change intended. Signed-off-by: Bobby Eshleman --- 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 7ec0659c6ae5..67dd9d78272d 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; -- 2.30.2