From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 81A0220E6E7 for ; Thu, 12 Dec 2024 09:27:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733995676; cv=none; b=gYOqMCUIIAMWtqD4wNrnPrrflQhgTReh8xDsTP+g9gVmE3Ci5RZRVaB8jJ21mzrMFhpjDnSL33aKb3Gl9emy8V1Vuj8PBNDNnN/lqEnnTBStmAJRqNoHhDsg4U1Q2P4sZCHswTLJs+TXB2sCpsmQKwyt7CXB3Vy4KQONilhd2/A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733995676; c=relaxed/simple; bh=b9cdBCl6i8/Pg9BidsE6MaRf0sy/S53LsQhJ0yDDCcE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=k9RJI9IgzHHyn+dJrp/NnLnQ66AG3x04JWwFGPI9vwaCC77LMNb5X8vGn+QX6YORT4vE7ONZ2OydzbukW/Q+4wheq5lXp/+VTcg919re7eqK6Gdi3Q03p4vLv3wWhwq84iQp1GatEiPfHmrjLFM0ZV6YpG3C8GRQRcLvqi61/DE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=c87EtkV6; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c87EtkV6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733995673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YQDLEldT18Fc0IWLf1h2y9YzeGe3KbZy7EnSjmgH5Ac=; b=c87EtkV6eYaUI8u387TMDiiFfhEPpYXq+7Js0ftv7XrrdVSAewFJozVdeBZipmXtche6+F lxsaMfZizWIo4ZpPWuLhJAcFhK37BMzxZ8vXmyeMC+Kvs5pqFJbsmOh13vs0vZxH2kXCWi M8Ns+xqwNWwAPX8HuKvFjRktYTnBV9Q= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-HzcGERNDNSuT8VwD2Tuzdg-1; Thu, 12 Dec 2024 04:27:52 -0500 X-MC-Unique: HzcGERNDNSuT8VwD2Tuzdg-1 X-Mimecast-MFC-AGG-ID: HzcGERNDNSuT8VwD2Tuzdg Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4361efc9dc6so2285315e9.3 for ; Thu, 12 Dec 2024 01:27:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733995671; x=1734600471; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YQDLEldT18Fc0IWLf1h2y9YzeGe3KbZy7EnSjmgH5Ac=; b=rlUSi6d/TvkC30ZqIKSwLUhq8Dqy4xLNuIJmRWveZFIXu2t+PzqVAww4or/FuB2sB0 PhHYOsdTytTv7PQhwvBovQRgSuvBxElDn4H/fdW3Lv9zln2rz7tV3mKrSYlHPtujoEmP Fcqozp3gIIa6ioIFUn7fSJsI7ch5tW0b9VrnJP+bYRc7S5fRLNFJnEAyFWYd0tHoaWBh K7XlNteCB4KICaGGYqDX8huc4X/sg5rzVH+tSk/aMcKxqqD6fQFxux627bnh371tfdgH 924PKOKQTfXEdCbu/3h6KtD5zuGdyiFgCurjT3sMA1TBuf3EvM1nIZxRjHSs79N71bPX tQlg== X-Forwarded-Encrypted: i=1; AJvYcCXia1D6t0UipWLWYuQe19ItMTqqzs21BjCIsT7dRDbxhVfJjhuXZGisjq0nc/EUodengu8lNDv5kMw=@vger.kernel.org X-Gm-Message-State: AOJu0YwNDhQG0kAmrYNyMM52lIGRtct9QCzzgJvMEPuSR6OPlWbdFbZ8 xaBgQrnTmCPPCSRw0DKYOmSTaT0hNZQKl9nWcFJ81LGHMtyPUnlFMqE1CtzQOfnw01c1bVySPYa sAtKe/hDyYz5+i/BK3OB1clPvb39ggBCDAWXZw5g9W2fTxrQ0dN1QuzUmuA== X-Gm-Gg: ASbGncspIEgEKIw6W+JATuitG6HDRg9TONnI8FVDsq4MlcHkcOCn96s8nFp2D0eVijm A0t3BP9NxtKKBwmtZbvt58bHoDT3F0yIGZAqLnIH1Y2MdyA/pad5vi8DLo8lmoIfUJq5rs2Qznp BJH2vwyExFzeG+V/aj5KURr5dlZBU49gCQFBm5k5yG+q+QLHpnAn1wfxFnsUX1TEYWutrnwje8M HkZH6hP3fxyEFXqzuxIH0SXbJ1fk3Hjs4Gw2x9dQkW17ddhXA8IvCuwukOSYUlu1CINZDOh3sBr qrICDHM= X-Received: by 2002:a05:600c:548a:b0:434:f609:1afa with SMTP id 5b1f17b1804b1-43622823a9bmr23142175e9.4.1733995671102; Thu, 12 Dec 2024 01:27:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfecq/fvmxWbZmLr9mwKSJq21xM6RVRZ1wSoCEsNQjvNePz0TX5CuMdaiXcW+mTqnLDcuA8w== X-Received: by 2002:a05:600c:548a:b0:434:f609:1afa with SMTP id 5b1f17b1804b1-43622823a9bmr23141765e9.4.1733995670687; Thu, 12 Dec 2024 01:27:50 -0800 (PST) Received: from [192.168.88.24] (146-241-48-67.dyn.eolo.it. [146.241.48.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436256b42a3sm10746345e9.28.2024.12.12.01.27.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Dec 2024 01:27:50 -0800 (PST) Message-ID: <2b89667d-ccd6-40b7-b355-1c71e159d14f@redhat.com> Date: Thu, 12 Dec 2024 10:27:48 +0100 Precedence: bulk X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v5 3/5] rtnetlink: Decouple net namespaces in rtnl_newlink_create() To: Xiao Liang , netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org References: <20241209140151.231257-1-shaw.leon@gmail.com> <20241209140151.231257-4-shaw.leon@gmail.com> Content-Language: en-US From: Paolo Abeni In-Reply-To: <20241209140151.231257-4-shaw.leon@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/9/24 15:01, Xiao Liang wrote: > There are 4 net namespaces involved when creating links: > > - source netns - where the netlink socket resides, > - target netns - where to put the device being created, > - link netns - netns associated with the device (backend), > - peer netns - netns of peer device. > > Currently, two nets are passed to newlink() callback - "src_net" > parameter and "dev_net" (implicitly in net_device). They are set as > follows, depending on netlink attributes. > > +------------+-------------------+---------+---------+ > | peer netns | IFLA_LINK_NETNSID | src_net | dev_net | > +------------+-------------------+---------+---------+ > | | absent | source | target | > | absent +-------------------+---------+---------+ > | | present | link | link | > +------------+-------------------+---------+---------+ > | | absent | peer | target | > | present +-------------------+---------+---------+ > | | present | peer | link | > +------------+-------------------+---------+---------+ > > When IFLA_LINK_NETNSID is present, the device is created in link netns > first. This has some side effects, including extra ifindex allocation, > ifname validation and link notifications. There's also an extra step to > move the device to target netns. These could be avoided if we create it > in target netns at the beginning. > > On the other hand, the meaning of src_net is ambiguous. It varies > depending on how parameters are passed. It is the effective link or peer > netns by design, but some drivers ignore it and use dev_net instead. > > This patch refactors netns handling by packing newlink() parameters into > a struct, and passing source, link and peer netns as is through this > struct. Fallback logic is implemented in helper functions - > rtnl_newlink_link_net() and rtnl_newlink_peer_net(). If is not set, peer > netns falls back to link netns, and link netns falls back to source netns. > rtnl_newlink_create() now creates devices in target netns directly, > so dev_net is always target netns. > > For drivers that use dev_net as fallback of link_netns, current behavior > is kept for compatibility. > > Signed-off-by: Xiao Liang I must admit this patch is way too huge for me to allow any reasonable review except that this has the potential of breaking a lot of things. I think you should be splitted to make it more palatable; i.e. - a patch just add the params struct with no semantic changes. - a patch making the dev_change_net_namespace() conditional on net != tge_net[1] - many per-device patches creating directly the device in the target namespace. - a patch reverting [1] Other may have different opinions, I'd love to hear them. > diff --git a/drivers/net/amt.c b/drivers/net/amt.c > index 98c6205ed19f..2f7bf50e05d2 100644 > --- a/drivers/net/amt.c > +++ b/drivers/net/amt.c > @@ -3161,14 +3161,17 @@ static int amt_validate(struct nlattr *tb[], struct nlattr *data[], > return 0; > } > > -static int amt_newlink(struct net *net, struct net_device *dev, > - struct nlattr *tb[], struct nlattr *data[], > - struct netlink_ext_ack *extack) > +static int amt_newlink(struct rtnl_newlink_params *params) > { > + struct net_device *dev = params->dev; > + struct nlattr **tb = params->tb; > + struct nlattr **data = params->data; > + struct netlink_ext_ack *extack = params->extack; > + struct net *link_net = rtnl_newlink_link_net(params); > struct amt_dev *amt = netdev_priv(dev); > int err = -EINVAL; Minor nit: here and and many other places, please respect the reverse xmas tree order. Thanks, Paolo