Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp11614896rwd; Thu, 22 Jun 2023 16:14:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4obcumLFRCvoN33IISbjPJhJeg5jbYMUgZ+X53ozYahSxY/lBn3sO7lZdoQdIFN8IIa0QY X-Received: by 2002:a05:6a20:549e:b0:104:35ec:c25c with SMTP id i30-20020a056a20549e00b0010435ecc25cmr10595203pzk.41.1687475649624; Thu, 22 Jun 2023 16:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687475649; cv=none; d=google.com; s=arc-20160816; b=HRZxkqMxYlImAdA8n+1lqIG334R5zrUbkLDNvT5MTDK0YfZfixkRzU07+M55gkecAS QrQWkzOjuZ0yOj1iKuixsfXJDoMqiOl6j7QB12/oI/FZf0OZwhNceVrYtwkolnlMfclM f3ppnThiuwntMKsVPhWHSOT8C+/cBITiG1g5hms1ktVjgQVZrPCRdZCaT6DnZfW30KiI gVHTyqQgRQD5XSfQKQlmrFSdrQvA3+32M7TSTf5yqNyc5vCEcIkf9vsBc2+gqib5Z/6A DWgVH3IQgJEkuUFrCq9I/enW4DBvP/RUAjCbGiQUxXNQhIV+SXOfKqyAvsnKkCgZGzok RK+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WHjYmH8s3fnZQ0PvCppw8g8ikfZuwN8TA2ENp2THW84=; b=d4uf5MZh4XTUIZIC4wuUZaG5uEP2KbXjBha+APKkZjT+Lq01OIlmdc9JOQRTekK+CF T1maIHgNtsStFLiQXh17ijbEMQRje1edO+QCWdlOxyXTGioFMuOtQRJc5OgQAG5PwBm7 DlkRteLIEkPW+WdBjuEsDu8NgQuzUn4WFGiU9vhnEZ+T2zrVS2BlDN/+ksoAWiy+X4vW E7Yg1PlyDy3e3ywIKhToqa1qH5Dkcd6y5WdGtuzdoWHpcM7WsIr7JAArduRePOJPkqjs xul/+C9jYGVWq/r7tHAFdSL2/ck2IDTTlQ+pLRqqTN2Xi0IP0ncKqZ3kxYi99huZZzux OAFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=eAOEFgW+; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a67-20020a624d46000000b00668b881d698si6551700pfb.75.2023.06.22.16.13.56; Thu, 22 Jun 2023 16:14:09 -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=@gmail.com header.s=20221208 header.b=eAOEFgW+; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231175AbjFVXFs (ORCPT + 99 others); Thu, 22 Jun 2023 19:05:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230255AbjFVXFq (ORCPT ); Thu, 22 Jun 2023 19:05:46 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 651591FE8; Thu, 22 Jun 2023 16:05:45 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1b520c77de0so40402295ad.0; Thu, 22 Jun 2023 16:05:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687475145; x=1690067145; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=WHjYmH8s3fnZQ0PvCppw8g8ikfZuwN8TA2ENp2THW84=; b=eAOEFgW+SUOOsIZUBQ5ZgE642tNDIfwXJ6L4oP9aXgrupTZ1tUgw7T0wogkuR24dZQ YFv4qDDUtKFDzXgwpz1fBj0VnBv+ua+QMCHH/FmLIMYBZiY1SujXyo18j+gk7DO+UpYe jEfIz4q185Eyvv8vqBZjM1Fb1jfadiNxqXY6WkoD/qqUBwdWrF+T2RfxoWQNcrPlEiuv Ey4NNNHOK7dFmiNLCjQxd5nglDKSPPgTN6ROFRiMditQ/WwzXLrekvEjfZgDzjk921jd pwV94ilLj89ws35BYNAwLkVelhZEpdI+ZhjKudLjojGPWoHxGtNheCFh3WMOK4KP7cvs 8UdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687475145; x=1690067145; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WHjYmH8s3fnZQ0PvCppw8g8ikfZuwN8TA2ENp2THW84=; b=BFC1MFC1vyBvGIXBMOf/a+0MyNOIyHWQu7C5fWst+hOLxxkB+MAQNc9juKnlot9J1+ L92xKYkCBHrdBXiOqLW1YN6xuSHz1tUIpKMj0bq9IhYoER0CbsYkzFhuIuyA2qIfGNlr qj6ohaMr/jJ8NktLioxXKoHAqiWTXnVDzKPF1/ztv6yseY+68Xp2q58dODkWSFw0PVzf zKIU5yUVjX4XbrQv+z7m/wMuuoRB589bHhTI8Vu8uQ58BLItdmtU2SFZ2ZNYcxt1I7xz 4EZg+pXgWx+IIl3Ax5LmyiVBFQRtuUFDUqOFhGdwzjweKxjx6124LFtuu6UfsQRIBwi1 0+Sg== X-Gm-Message-State: AC+VfDwM3DWLYRncYhmd0CmPZKzVMzzx0UuQGNTqKPLglDXa3bdX6lb7 04DQCGhe8D/wQ7kM9WY4nYY= X-Received: by 2002:a17:90a:748f:b0:256:991a:19e with SMTP id p15-20020a17090a748f00b00256991a019emr9368441pjk.9.1687475144704; Thu, 22 Jun 2023 16:05:44 -0700 (PDT) Received: from localhost (ec2-54-67-115-33.us-west-1.compute.amazonaws.com. [54.67.115.33]) by smtp.gmail.com with ESMTPSA id bv7-20020a17090af18700b0025edb720cc1sm235782pjb.22.2023.06.22.16.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 16:05:44 -0700 (PDT) Date: Thu, 22 Jun 2023 23:05:43 +0000 From: Bobby Eshleman To: Stefano Garzarella Cc: Bobby Eshleman , Stefan Hajnoczi , "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 , 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 Subject: Re: [PATCH RFC net-next v4 4/8] vsock: make vsock bind reusable Message-ID: References: <20230413-b4-vsock-dgram-v4-0-0cebbb2ae899@bytedance.com> <20230413-b4-vsock-dgram-v4-4-0cebbb2ae899@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Thu, Jun 22, 2023 at 05:25:55PM +0200, Stefano Garzarella wrote: > On Sat, Jun 10, 2023 at 12:58:31AM +0000, Bobby Eshleman wrote: > > This commit makes the bind table management functions in vsock usable > > for different bind tables. For use by datagrams in a future patch. > > > > Signed-off-by: Bobby Eshleman > > --- > > net/vmw_vsock/af_vsock.c | 33 ++++++++++++++++++++++++++------- > > 1 file changed, 26 insertions(+), 7 deletions(-) > > > > diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c > > index ef86765f3765..7a3ca4270446 100644 > > --- a/net/vmw_vsock/af_vsock.c > > +++ b/net/vmw_vsock/af_vsock.c > > @@ -230,11 +230,12 @@ static void __vsock_remove_connected(struct vsock_sock *vsk) > > sock_put(&vsk->sk); > > } > > > > -static struct sock *__vsock_find_bound_socket(struct sockaddr_vm *addr) > > +struct sock *vsock_find_bound_socket_common(struct sockaddr_vm *addr, > > + struct list_head *bind_table) > > { > > struct vsock_sock *vsk; > > > > - list_for_each_entry(vsk, vsock_bound_sockets(addr), bound_table) { > > + list_for_each_entry(vsk, bind_table, bound_table) { > > if (vsock_addr_equals_addr(addr, &vsk->local_addr)) > > return sk_vsock(vsk); > > > > @@ -247,6 +248,11 @@ static struct sock *__vsock_find_bound_socket(struct sockaddr_vm *addr) > > return NULL; > > } > > > > +static struct sock *__vsock_find_bound_socket(struct sockaddr_vm *addr) > > +{ > > + return vsock_find_bound_socket_common(addr, vsock_bound_sockets(addr)); > > +} > > + > > static struct sock *__vsock_find_connected_socket(struct sockaddr_vm *src, > > struct sockaddr_vm *dst) > > { > > @@ -646,12 +652,17 @@ static void vsock_pending_work(struct work_struct *work) > > > > /**** SOCKET OPERATIONS ****/ > > > > -static int __vsock_bind_connectible(struct vsock_sock *vsk, > > - struct sockaddr_vm *addr) > > +static int vsock_bind_common(struct vsock_sock *vsk, > > + struct sockaddr_vm *addr, > > + struct list_head *bind_table, > > + size_t table_size) > > { > > static u32 port; > > struct sockaddr_vm new_addr; > > > > + if (table_size < VSOCK_HASH_SIZE) > > + return -1; > > Why we need this check now? > If the table_size is not at least VSOCK_HASH_SIZE then the VSOCK_HASH(addr) used later could overflow the table. Maybe this really deserves a WARN() and a comment? > > + > > if (!port) > > port = get_random_u32_above(LAST_RESERVED_PORT); > > > > @@ -667,7 +678,8 @@ static int __vsock_bind_connectible(struct vsock_sock *vsk, > > > > new_addr.svm_port = port++; > > > > - if (!__vsock_find_bound_socket(&new_addr)) { > > + if (!vsock_find_bound_socket_common(&new_addr, > > + &bind_table[VSOCK_HASH(addr)])) { > > found = true; > > break; > > } > > @@ -684,7 +696,8 @@ static int __vsock_bind_connectible(struct vsock_sock *vsk, > > return -EACCES; > > } > > > > - if (__vsock_find_bound_socket(&new_addr)) > > + if (vsock_find_bound_socket_common(&new_addr, > > + &bind_table[VSOCK_HASH(addr)])) > > return -EADDRINUSE; > > } > > > > @@ -696,11 +709,17 @@ static int __vsock_bind_connectible(struct vsock_sock *vsk, > > * by AF_UNIX. > > */ > > __vsock_remove_bound(vsk); > > - __vsock_insert_bound(vsock_bound_sockets(&vsk->local_addr), vsk); > > + __vsock_insert_bound(&bind_table[VSOCK_HASH(&vsk->local_addr)], vsk); > > > > return 0; > > } > > > > +static int __vsock_bind_connectible(struct vsock_sock *vsk, > > + struct sockaddr_vm *addr) > > +{ > > + return vsock_bind_common(vsk, addr, vsock_bind_table, VSOCK_HASH_SIZE + 1); > > +} > > + > > static int __vsock_bind_dgram(struct vsock_sock *vsk, > > struct sockaddr_vm *addr) > > { > > > > -- > > 2.30.2 > > > > The rest seems okay to me, but I agree with Simon's suggestion. > > Stefano > Thanks, Bobby