From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 734E7CA5A for ; Sat, 7 Mar 2026 08:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772870466; cv=none; b=GR0GO1K0D1yknkHWPrDDbxjUBRViZ1WdtBFvwmiPwxWF2tNbxuyEX0C6305QvxQLogA188LdusOykhsqw0AKD69v9uuM9ubj8V5RmhJvIqZttYEqz3ZcOiXfB1WeIUB0LrShQCBy11rj+i7JzoFKgixGbP8vmfZMqWP8QZOYB9Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772870466; c=relaxed/simple; bh=amTi6mhncQFgZhdX+ghT4i9cJ+tUuHa1bTB59MtKUmc=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=ANF1Ec5fplQSvlSV5S1S+ZvJd2iMW8UsTXpMu222P3lK0ck8rYPdaKM5qbUO60tuuZ1Peee1gI2olmkiunuJ6X2gIygNbtIDBb5m6ErMffi8GC9Y6dP5dpge0yp39s1wmDbbqPLYb3I/B1B4D8xjzKH5rSMc4b4b4iGfPraMbWY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=V8VpVYha; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="V8VpVYha" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772870453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XinBd3kl2KEQLcCa959/LqwGyRy8pHn8Guj+4yi4ETE=; b=V8VpVYhaFO1c9IVYU3Q6WN0RNnXVGyanTE2F2bhkjgYlQxzILKuHdOBO9/g4xX6Ourzo4J DuwTEdQxkN2edT9N+FJm9WjyXFZ0/uPlHm8PNWVncwyrYYzhxpTVgjA/0r9xaIlh9PXkKO TgSzNgmhc85grXBh1CnH65OhghKEkv4= Date: Sat, 7 Mar 2026 00:00:49 -0800 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH 3/4] RDMA/rxe: Add net namespace support for IPv4/IPv6 sockets To: David Ahern , jgg@ziepe.ca, leon@kernel.org, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org, linux-kselftest@vger.kernel.org, "yanjun.zhu@linux.dev" References: <20260306082452.1822-1-yanjun.zhu@linux.dev> <20260306082452.1822-4-yanjun.zhu@linux.dev> <03ece7a0-7fe7-45bd-9baf-d88d689bc578@kernel.org> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Zhu Yanjun In-Reply-To: <03ece7a0-7fe7-45bd-9baf-d88d689bc578@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 在 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 >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#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