From patchwork Wed May 31 00:35:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bobby Eshleman X-Patchwork-Id: 101168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2555165vqr; Tue, 30 May 2023 17:41:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42/iuemaWn21d6muwFBpIPGmX8rKlXv534UmoWZ4gilSVu47yf1X/TmN0CY+kJqqSw0190 X-Received: by 2002:a05:6a20:258a:b0:10f:7abd:fe5e with SMTP id k10-20020a056a20258a00b0010f7abdfe5emr4431713pzd.40.1685493662435; Tue, 30 May 2023 17:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685493662; cv=none; d=google.com; s=arc-20160816; b=yi7+jjA0O2IE6pNKmBPeAo60EuGYXIxRy4Tqs+mT3ivsHxz88icd6tWZL91kau0rYO mggSXUN011i92EGtHr5SFbWqiSoqZgq3NyyIuTTKodV0lOXSoHjLdOC5wZ3+9jh+eMdn vI6MeJFrtQjniVZ/iD3HCeaqkM7cmAAH02hXGMbNLK4LZZ2wR3ZRqk1YcvLvK+/tfUbI oI9pKS5c9vzhiYH0OE77WLI3LhLzK6e0B3kCBWqEe13f8Ctt4nOcK6taiw0LQyZ1Kr9q UJqfdDyBlLNpNkhJ0Nf55kOyHpEE2RDVtbrjVNPt1NCQ+49AeODuBDOculpcGt1Z1dcx gFbw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y5-20020aa79e05000000b0062dbc05a323si2565107pfq.298.2023.05.30.17.40.46; Tue, 30 May 2023 17:41:02 -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 S233617AbjEaAgX (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767368202710118779?= X-GMAIL-MSGID: =?utf-8?q?1767368202710118779?= 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;