Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Zhu Yanjun <yanjun.zhu@linux.dev>
To: David Ahern <dsahern@kernel.org>,
	jgg@ziepe.ca, leon@kernel.org, zyjzyj2000@gmail.com,
	linux-rdma@vger.kernel.org, linux-kselftest@vger.kernel.org,
	"yanjun.zhu@linux.dev" <yanjun.zhu@linux.dev>
Subject: Re: [PATCH 3/4] RDMA/rxe: Add net namespace support for IPv4/IPv6 sockets
Date: Sat, 7 Mar 2026 00:00:49 -0800	[thread overview]
Message-ID: <b90e3a90-7a88-449b-915a-83a662656c90@linux.dev> (raw)
In-Reply-To: <03ece7a0-7fe7-45bd-9baf-d88d689bc578@kernel.org>


在 2026/3/6 17:10, David Ahern 写道:
> 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.

All the mentioned problems are fix in the latest commit.

Zhu Yanjun

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

-- 
Best Regards,
Yanjun.Zhu


  reply	other threads:[~2026-03-07  8:01 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
2026-03-07  8:00     ` Zhu Yanjun [this message]
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=b90e3a90-7a88-449b-915a-83a662656c90@linux.dev \
    --to=yanjun.zhu@linux.dev \
    --cc=dsahern@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --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