From: Amery Hung <ameryhung@gmail.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: stefanha@redhat.com, mst@redhat.com, jasowang@redhat.com,
xuanzhuo@linux.alibaba.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com, bryantan@vmware.com, vdasa@vmware.com,
pv-drivers@vmware.com, dan.carpenter@linaro.org,
simon.horman@corigine.com, oxffffaa@gmail.com,
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@bytedance.com, jiang.wang@bytedance.com,
amery.hung@bytedance.com, xiyou.wangcong@gmail.com
Subject: Re: [RFC PATCH net-next v6 04/14] af_vsock: generalize bind table functions
Date: Tue, 30 Jul 2024 10:56:46 -0700 [thread overview]
Message-ID: <CAMB2axPfz0kOFau0tX2=87e=2EPSLxX1AXHPpsv3QyaLYaBvoA@mail.gmail.com> (raw)
In-Reply-To: <ba2hivznnjcyeftr7ch7gvrwjvkimx5u2t2anv7wv7n7yb3j36@dbagnaylvu6o>
On Tue, Jul 30, 2024 at 1:00 AM Stefano Garzarella <sgarzare@redhat.com> wrote:
>
> On Sun, Jul 28, 2024 at 11:52:54AM GMT, Amery Hung wrote:
> >On Tue, Jul 23, 2024 at 7:40 AM Stefano Garzarella <sgarzare@redhat.com> wrote:
> >>
> >> On Wed, Jul 10, 2024 at 09:25:45PM GMT, Amery Hung wrote:
> >> >From: Bobby Eshleman <bobby.eshleman@bytedance.com>
> >> >
> >> >This commit makes the bind table management functions in vsock usable
> >> >for different bind tables. Future work will introduce a new table for
> >> >datagrams to avoid address collisions, and these functions will be used
> >> >there.
> >> >
> >> >Signed-off-by: Bobby Eshleman <bobby.eshleman@bytedance.com>
> >> >---
> >> > net/vmw_vsock/af_vsock.c | 34 +++++++++++++++++++++++++++-------
> >> > 1 file changed, 27 insertions(+), 7 deletions(-)
> >> >
> >> >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> >> >index acc15e11700c..d571be9cdbf0 100644
> >> >--- a/net/vmw_vsock/af_vsock.c
> >> >+++ b/net/vmw_vsock/af_vsock.c
> >> >@@ -232,11 +232,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)
> >> >+static 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);
> >> >
> >> >@@ -249,6 +250,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)
> >> > {
> >> >@@ -671,12 +677,18 @@ 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 (WARN_ONCE(table_size < VSOCK_HASH_SIZE,
> >> >+ "table size too small, may cause overflow"))
> >> >+ return -EINVAL;
> >> >+
> >>
> >> I'd add this in another commit.
> >>
> >> > if (!port)
> >> > port = get_random_u32_above(LAST_RESERVED_PORT);
> >> >
> >> >@@ -692,7 +704,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)])) {
> >>
> >> Can we add a macro for `&bind_table[VSOCK_HASH(addr)])` ?
> >>
> >
> >Definitely. I will add the following macro:
> >
> >#define vsock_bound_sockets_in_table(bind_table, addr) \
> > (&bind_table[VSOCK_HASH(addr)])
>
> yeah.
>
> >
> >> > found = true;
> >> > break;
> >> > }
> >> >@@ -709,7 +722,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;
> >> > }
> >> >
> >> >@@ -721,11 +735,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);
> >>
> >> What about using ARRAY_SIZE(x) ?
> >>
> >> BTW we are using that size just to check it, but all the arrays we use
> >> are statically allocated, so what about a compile time check like
> >> BUILD_BUG_ON()?
> >>
> >
> >I will remove the table_size check you mentioned earlier and the
> >argument here as the arrays are allocated statically like you
> >mentioned.
> >
> >If you think this check may be a good addition, I can add a
> >BUILD_BUG_ON() in the new vsock_bound_sockets_in_table() macro.
>
> If you want to add it, we need to do it in a separate commit. But since
> we already have so many changes and both arrays are statically allocated
> in the same file, IMHO we can avoid the check.
>
> Stefano
>
Okay. I will not add the check.
Thanks,
Amery
next prev parent reply other threads:[~2024-07-30 17:56 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-10 21:25 [RFC PATCH net-next v6 00/14] virtio/vsock: support datagrams Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 01/14] af_vsock: generalize vsock_dgram_recvmsg() to all transports Amery Hung
2024-07-15 8:02 ` Luigi Leonardi
2024-07-15 23:39 ` Amery Hung
2024-07-29 19:25 ` Arseniy Krasnov
2024-07-10 21:25 ` [RFC PATCH net-next v6 02/14] af_vsock: refactor transport lookup code Amery Hung
2024-07-25 6:29 ` Arseniy Krasnov
2024-07-28 22:10 ` Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 03/14] af_vsock: support multi-transport datagrams Amery Hung
2024-07-15 8:13 ` Arseniy Krasnov
2024-07-15 17:41 ` Amery Hung
2024-07-28 20:28 ` Arseniy Krasnov
2024-07-28 21:53 ` Amery Hung
2024-07-29 5:12 ` Arseniy Krasnov
2024-07-10 21:25 ` [RFC PATCH net-next v6 04/14] af_vsock: generalize bind table functions Amery Hung
2024-07-23 14:39 ` Stefano Garzarella
2024-07-28 18:52 ` Amery Hung
2024-07-30 8:00 ` Stefano Garzarella
2024-07-30 17:56 ` Amery Hung [this message]
2024-07-10 21:25 ` [RFC PATCH net-next v6 05/14] af_vsock: use a separate dgram bind table Amery Hung
2024-07-23 14:41 ` Stefano Garzarella
2024-07-28 21:37 ` Amery Hung
2024-07-30 8:05 ` Stefano Garzarella
2024-07-10 21:25 ` [RFC PATCH net-next v6 06/14] virtio/vsock: add VIRTIO_VSOCK_TYPE_DGRAM Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 07/14] virtio/vsock: add common datagram send path Amery Hung
2024-07-23 14:42 ` Stefano Garzarella
2024-07-26 23:22 ` Amery Hung
2024-07-30 8:22 ` Stefano Garzarella
2024-07-29 20:00 ` Arseniy Krasnov
2024-07-29 22:51 ` Amery Hung
2024-07-30 5:09 ` Arseniy Krasnov
2024-07-10 21:25 ` [RFC PATCH net-next v6 08/14] af_vsock: add vsock_find_bound_dgram_socket() Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 09/14] virtio/vsock: add common datagram recv path Amery Hung
2024-07-23 14:42 ` Stefano Garzarella
2024-07-30 0:35 ` Amery Hung
2024-07-30 8:32 ` Stefano Garzarella
2024-07-10 21:25 ` [RFC PATCH net-next v6 10/14] virtio/vsock: add VIRTIO_VSOCK_F_DGRAM feature bit Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 11/14] vhost/vsock: implement datagram support Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 12/14] vsock/loopback: " Amery Hung
2024-08-01 12:18 ` Luigi Leonardi
2024-07-10 21:25 ` [RFC PATCH net-next v6 13/14] virtio/vsock: " Amery Hung
2024-07-11 23:02 ` Luigi Leonardi
2024-07-11 23:07 ` Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 14/14] test/vsock: add vsock dgram tests Amery Hung
2024-07-20 19:58 ` Arseniy Krasnov
2024-07-23 14:43 ` Stefano Garzarella
2024-07-28 22:06 ` Amery Hung
2024-07-23 14:38 ` [RFC PATCH net-next v6 00/14] virtio/vsock: support datagrams Stefano Garzarella
2025-07-22 14:35 ` Stefano Garzarella
2025-07-26 5:53 ` Amery Hung
2025-07-29 12:40 ` Stefano Garzarella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMB2axPfz0kOFau0tX2=87e=2EPSLxX1AXHPpsv3QyaLYaBvoA@mail.gmail.com' \
--to=ameryhung@gmail.com \
--cc=amery.hung@bytedance.com \
--cc=bobby.eshleman@bytedance.com \
--cc=bpf@vger.kernel.org \
--cc=bryantan@vmware.com \
--cc=dan.carpenter@linaro.org \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=edumazet@google.com \
--cc=haiyangz@microsoft.com \
--cc=jasowang@redhat.com \
--cc=jiang.wang@bytedance.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=oxffffaa@gmail.com \
--cc=pabeni@redhat.com \
--cc=pv-drivers@vmware.com \
--cc=sgarzare@redhat.com \
--cc=simon.horman@corigine.com \
--cc=stefanha@redhat.com \
--cc=vdasa@vmware.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=wei.liu@kernel.org \
--cc=xiyou.wangcong@gmail.com \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).