From patchwork Wed Jul 19 00:50: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: 122333 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2111498vqt; Tue, 18 Jul 2023 17:52:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlFlRhqsDlYRtTOwjIfzo9J9sKhn5/6uLa6w6Y0auCp+PpN5qfR176jfl52h9zfWdEiNRrmx X-Received: by 2002:a05:6808:200e:b0:3a4:2a13:71ca with SMTP id q14-20020a056808200e00b003a42a1371camr22650286oiw.16.1689727928781; Tue, 18 Jul 2023 17:52:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689727928; cv=none; d=google.com; s=arc-20160816; b=cDT060ZLuI1eSCB/rq+DrGn2AQY+2VJkuVBOCuR5Eh7KkAkoHjDVQwMkaBcJ/EMzcI ARGOKriZb5K8KI7vE8FV3dMTyyRnAJ1wrFOiHJyra8I8UbhtPAkrEQEA3zz4Y/fSMawq 90aBsCr3dIejleM9/GaHko8uhjqIZMbZ743wKpHRFzlNX2CSJBTEilLLZjLer0DMDFUa +8h51KRbjVAEIPFTxAHz8k1gyWi9DIoC+ylzQXqmoLI7qUTOz1qgkp4oqS6mdXhEXTl9 awtzqtIguEqOorwagnTWE4ptMjWbXZciWg4FKyoojkpaRY7f1MkgxK6xEMnhOmVug4g7 5zjQ== 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=RRgj32iUYcRPQa7+gTgJIjnpPYuGFjIY/Kz/A8nTowk=; fh=jejeGpHkr9vVlEyvdVBCSLFut92eNP6vAI+O1tx9vp4=; b=mTE3eLA1NNQB93KbHJb+hM3rXsvESsQY7c7KupSGvGURvEqJKf+Bd9/HSd56btskMh zbBrJ2T6ynJfukDN8+XgMGyBKm1uD0uCktk0GngHJVAoon4FtZSygzb++Ii/dun6+ZKL k+No7qiZHR2D/IM5TEME1qDnLRuQrAR3ia+pwc1IEdFOMqOszjJEJHVlFkoafnk2J0FJ xu9qGbl26tGChr6KzpgCkZiTt04oatobpYv5dxyvY1mS6QllRsVLUvuszCK0pqf8y+K1 eZnZKaF4fHDmmC/DsLgHsoyD80hxpQKyc2wPHKaTQEVW1vto9tjz8YI7M2OlnVwT59RV zAzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=IXZ5R7IW; 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 v2-20020a17090a898200b0025960d035c6si327878pjn.138.2023.07.18.17.51.55; Tue, 18 Jul 2023 17:52:08 -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=IXZ5R7IW; 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 S230057AbjGSAup (ORCPT + 99 others); Tue, 18 Jul 2023 20:50:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229809AbjGSAuj (ORCPT ); Tue, 18 Jul 2023 20:50:39 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1289F171A for ; Tue, 18 Jul 2023 17:50:11 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id d75a77b69052e-4039f7e1d3aso51335861cf.0 for ; Tue, 18 Jul 2023 17:50:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689727811; x=1692319811; 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=RRgj32iUYcRPQa7+gTgJIjnpPYuGFjIY/Kz/A8nTowk=; b=IXZ5R7IWCdcvitOGSq8k/EIMLrqwPMUB9D/Zi9EE+9sSo9Ibqe7l8BTzzztEfZzLWg B2G5CHGlUkVio9Re3XZr0aX1lfiEfU0+n5TSJiykLg5DMsjUemmLr97vWvbzPEH6VBPf wc6K6mPxmMC4VBezVPhsbsTL8crTwuA9GenLAUs2GbzMEAAnTjBwClQX40kOCEfno/vD rcs9gwkb9hLLHvZt5yWNJZejItpccGsrQ1MfVasQA+l2WX9ZDxvzqyQ5U2gycVRfZwT+ kyaQKcjHLuSQxTbn52xpRG8wpj3PWrLi+kBY7lEhlwtPa+rBSATIlhwiR2U+jI7y9txa 7ILA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689727811; x=1692319811; 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=RRgj32iUYcRPQa7+gTgJIjnpPYuGFjIY/Kz/A8nTowk=; b=PTIG9LqEhAyuALFd/Sq4QDuFL3aISpVLAwJ+E5FfA1MpHshYooTpErF3ADlTnNmqxg 79/GydUjKf5c4q1qYIAv2ijMZ1GfM1ZLvyyEi8S4KJZu4A6nvQ1ohiY4vPr2DCK3SZIG nMS9QuOeLMSW34qI0iFQjwcpaaB3MCQkO+Mfzen84Ys9VusTR2Syl0R5YvSBnsu7lqUn iFH/oHnTO+0+ISKP7wp05h7bB0jfEOxXFvXB3OSyHx2W5kwMoTrHNh2l/lFWvJqmzE40 V4JwurtRPPeJ5tw+TgIjBHh/H4c3ukfnNS1/A+DnOF8mZsAXYFTw2zOSWLfzdaKAcjnm TlVg== X-Gm-Message-State: ABy/qLbYWIRWgPYtIWWkHyeF2wYbM67uQq3ZZqHYtfGHLiKFBrpopUoL dWZOGbjBixisWYQlKL6NWhr0eg== X-Received: by 2002:a05:622a:1788:b0:403:fe96:7af2 with SMTP id s8-20020a05622a178800b00403fe967af2mr2544945qtk.41.1689727811113; Tue, 18 Jul 2023 17:50:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 17:50:10 -0700 (PDT) From: Bobby Eshleman Date: Wed, 19 Jul 2023 00:50:06 +0000 Subject: [PATCH RFC net-next v5 02/14] af_vsock: refactor transport lookup code MIME-Version: 1.0 Message-Id: <20230413-b4-vsock-dgram-v5-2-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_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: INBOX X-GMAIL-THRID: 1771808152584583607 X-GMAIL-MSGID: 1771808152584583607 Introduce new reusable function vsock_connectible_lookup_transport() that performs the transport lookup logic. No functional change intended. Reviewed-by: Stefano Garzarella 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 ad71e084bf2f..ae5ac5531d96 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -423,6 +423,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 @@ -463,13 +479,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;