public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: Zhu Yanjun <yanjun.zhu@linux.dev>,
	jgg@ziepe.ca, leon@kernel.org, zyjzyj2000@gmail.com,
	linux-rdma@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 3/4] RDMA/rxe: Add net namespace support for IPv4/IPv6 sockets
Date: Fri, 6 Mar 2026 18:10:35 -0700	[thread overview]
Message-ID: <03ece7a0-7fe7-45bd-9baf-d88d689bc578@kernel.org> (raw)
In-Reply-To: <20260306082452.1822-4-yanjun.zhu@linux.dev>

On 3/6/26 1:24 AM, Zhu Yanjun wrote:
> diff --git a/drivers/infiniband/sw/rxe/rxe_ns.c b/drivers/infiniband/sw/rxe/rxe_ns.c
> new file mode 100644
> index 000000000000..29d08899dcda
> --- /dev/null
> +++ b/drivers/infiniband/sw/rxe/rxe_ns.c
> @@ -0,0 +1,134 @@
> +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
> +/*
> + * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
> + * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
> + */
> +
> +#include <net/sock.h>
> +#include <net/netns/generic.h>
> +#include <net/net_namespace.h>
> +#include <linux/module.h>
> +#include <linux/skbuff.h>
> +#include <linux/pid_namespace.h>
> +#include <net/udp_tunnel.h>
> +
> +#include "rxe_ns.h"
> +
> +/*
> + * Per network namespace data
> + */
> +struct rxe_ns_sock {
> +	struct sock __rcu *rxe_sk4;
> +	struct sock __rcu *rxe_sk6;
> +};
> +
> +/*
> + * Index to store custom data for each network namespace.
> + */
> +static unsigned int rxe_pernet_id;
> +
> +/*
> + * Called for every existing and added network namespaces
> + */
> +static int __net_init rxe_ns_init(struct net *net)
> +{
> +	/*
> +	 * create (if not present) and access data item in network namespace
> +	 * (net) using the id (net_id)
> +	 */

this comment is not needed; does not really convey anything useful. I
would like this function to have the comment from my patch:

	/* defer socket create in the namespace to the first
	 * device create.
	 */

this makes it clear why init and exit are not symmetrical.

> +	struct rxe_ns_sock *ns_sk = net_generic(net, rxe_pernet_id);
> +
> +	rcu_assign_pointer(ns_sk->rxe_sk4, NULL); /* initialize sock 4 socket */
> +	rcu_assign_pointer(ns_sk->rxe_sk6, NULL); /* initialize sock 6 socket */
> +	synchronize_rcu();

I believe the core network namespace code ensures the memory is
initialized, so this is not needed.

> +
> +	return 0;
> +}
> +
> +static void __net_exit rxe_ns_exit(struct net *net)
> +{
> +	/*
> +	 * called when the network namespace is removed
> +	 */
> +	struct rxe_ns_sock *ns_sk = net_generic(net, rxe_pernet_id);
> +	struct sock *rxe_sk4 = NULL;
> +	struct sock *rxe_sk6 = NULL;

initialization is not needed since both are set before use.

> +
> +	rcu_read_lock();
> +	rxe_sk4 = rcu_dereference(ns_sk->rxe_sk4);
> +	rxe_sk6 = rcu_dereference(ns_sk->rxe_sk6);
> +	rcu_read_unlock();
> +
> +	/* close socket */
> +	if (rxe_sk4 && rxe_sk4->sk_socket) {

how can rxe_sk4 be non-NULL and yet sk_socket become NULL?

> +		udp_tunnel_sock_release(rxe_sk4->sk_socket);
> +		rcu_assign_pointer(ns_sk->rxe_sk4, NULL);

if you flip the order

		rcu_assign_pointer(ns_sk->rxe_sk4, NULL);
		/* udp_tunnel_sock_release calls synchronize_rcu */
		udp_tunnel_sock_release(rxe_sk4->sk_socket);


you should be able to drop the synchronize_rcu here:

> +		synchronize_rcu();

> +	}
> +
> +	if (rxe_sk6 && rxe_sk6->sk_socket) {

same here.

> +		udp_tunnel_sock_release(rxe_sk6->sk_socket);
> +		rcu_assign_pointer(ns_sk->rxe_sk6, NULL);
> +		synchronize_rcu();> +	}
> +}
> +


  reply	other threads:[~2026-03-07  1:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-06  8:24 [PATCH 0/4] RDMA/rxe: Add the support that rxe can work in net namespace Zhu Yanjun
2026-03-06  8:24 ` [PATCH 1/4] RDMA/rxe: Add testcase for net namespace rxe Zhu Yanjun
2026-03-07  1:10   ` David Ahern
2026-03-06  8:24 ` [PATCH 2/4] RDMA/nldev: Add dellink function pointer Zhu Yanjun
2026-03-06  8:24 ` [PATCH 3/4] RDMA/rxe: Add net namespace support for IPv4/IPv6 sockets Zhu Yanjun
2026-03-07  1:10   ` David Ahern [this message]
2026-03-07  8:00     ` Zhu Yanjun
2026-03-06  8:24 ` [PATCH 4/4] RDMA/rxe: Support RDMA link creation and destruction per net namespace Zhu Yanjun
2026-03-07  1:10   ` David Ahern
2026-03-07  8:00     ` Zhu Yanjun
2026-03-07  1:12   ` yanjun.zhu
2026-03-06  8:27 ` [PATCH 0/4] RDMA/rxe: Add the support that rxe can work in " Zhu Yanjun

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=03ece7a0-7fe7-45bd-9baf-d88d689bc578@kernel.org \
    --to=dsahern@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=yanjun.zhu@linux.dev \
    --cc=zyjzyj2000@gmail.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