Message ID | 20221111161729.915233-1-linux@rasmusvillemoes.dk |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp840070wru; Fri, 11 Nov 2022 08:23:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf6WlV6BWPtlvXew+cksMLxfaH96YUC7bheZ+d9eyl+QpVZ7elNvsipuDmOBRQDxWbKWpqQD X-Received: by 2002:a17:902:6941:b0:17f:5810:e9e3 with SMTP id k1-20020a170902694100b0017f5810e9e3mr3314279plt.11.1668183818307; Fri, 11 Nov 2022 08:23:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668183818; cv=none; d=google.com; s=arc-20160816; b=sfTJaqdQB8gNOulJvERTFuECZQQnXzh0eYZBTdBM2WCJoQswUHkDWI+iSHnkj+33gy PWNQHS9beaoOI7CajAhXqx8zbyBwx1tAfGmwdgo2rAooZPyESd9bPwKvrk1Xv1Uj170c MWhezjN3thYHMfGE/pXB5risIvPm1ltVoAKtWPbcasDdSRmgG9IukCF+/nodR7TTfzIF MnPD501uwO20op80lHDJDsxCxC3IZmDDKLVjQiKLzUETB76RkXHSeE9ivpnTKm92GLIk oW5vpfPiRarAfdvi/aUd3ZtB7yeufBaHmPwKCs86mmAt5TMN7De5EHxYXk/jiFYCr+rS 8SCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=PPFK299nWfDr/V9J7p74DjQEhALYVf51OEuCFpbYSbM=; b=fg+geHHqbGpIJoIKDD2cQzLlqUXOsDXuKHV1bklLyX12+r+1j71tnnWspcokPZPmAb g9LVA2Ro6xP4AwHoPn19wtymyR7ob3o0Bfnb0uiDeXQuxjSjoRJBZcnTrqhQXGkRT5rs F+xCyfYKxeYaltzR9Sj+u9+bId6iX+k+EwfDtrXXwB+Jajm/nIrJFTCtgAOe+VzhOqEi oTIIcRQmlXPI/YtjHF2VQntFeJAT5+WMJOWJFfZmjkGRldL9TnRupjGrf3+NDq9VaRNQ sydx+FrlC6lmNkGZvuvQ/FUP/VEWHMeWUeV4shII6wAaw3SrjNKjTaoogz9d1mSs1K5H g3BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=KBU+AAvw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n21-20020aa78a55000000b0056ec4a6babasi2313109pfa.381.2022.11.11.08.23.24; Fri, 11 Nov 2022 08:23:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=KBU+AAvw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233651AbiKKQRl (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Fri, 11 Nov 2022 11:17:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233688AbiKKQRk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 11 Nov 2022 11:17:40 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54341658C for <linux-kernel@vger.kernel.org>; Fri, 11 Nov 2022 08:17:38 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id i21so8243292edj.10 for <linux-kernel@vger.kernel.org>; Fri, 11 Nov 2022 08:17:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PPFK299nWfDr/V9J7p74DjQEhALYVf51OEuCFpbYSbM=; b=KBU+AAvwge0Xr3lQE8QmWKlPSunFws73fRLUrfKBI3t0C7DwjZNxz9x1Rs/CD8AOg7 aACR3Djshp/4SGNH1bl3rM8whcVgrQwz8IpxNGkznbL+XM9X+u05meAx3yOmRGlMyEoe bXMuNxJrrrdXPC6j9kBN7+DChSccZwvS1fHmE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PPFK299nWfDr/V9J7p74DjQEhALYVf51OEuCFpbYSbM=; b=sJtv8NM4auKGtdB03/9UPjN62Lmf77oR7d1bPs0nIQW0lKYMB+rkpLwg4ZYqUkS2bb xsB9eQhiDFtpJcMsi6Jxz3GW/1N1CGpI+LPJqObm5AT6YI9d5eWUZPeXoS/Q4fxExZ/r 5ThgCUoesW6lJSd7BuCB5Tt3MChGO4QDiRy1s8gI5+kt56XVNcADr0EasgEkWywyaHDl dMgJJAf6uAzlMNo2ob/UnurS1VgYxDeO/uGO9bPSAyiM4XEtNarRjJWNgba52daQan2P qpiOKBX9By7leni/ZQEaKesyAoR9sOIqSdJsvUqJgXtcqa0WVyaOPaCxOSqtFkIDQs/d 3jRQ== X-Gm-Message-State: ANoB5pnFPzKz75pGHjnpA1ThYjUd3TB3lQqAwPtDKGafyZC327LAkzW1 bNvAoX8/qn77HH9yBIDrRte2pA== X-Received: by 2002:aa7:d4d3:0:b0:45f:b80f:1fe8 with SMTP id t19-20020aa7d4d3000000b0045fb80f1fe8mr2064057edr.118.1668183456903; Fri, 11 Nov 2022 08:17:36 -0800 (PST) Received: from prevas-ravi.tritech.se ([80.208.71.65]) by smtp.gmail.com with ESMTPSA id v2-20020a170906292200b007aacfce2a91sm1038990ejd.27.2022.11.11.08.17.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 08:17:35 -0800 (PST) From: Rasmus Villemoes <linux@rasmusvillemoes.dk> To: Andrew Lunn <andrew@lunn.ch>, Vivien Didelot <vivien.didelot@gmail.com>, Florian Fainelli <f.fainelli@gmail.com>, Vladimir Oltean <olteanv@gmail.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net: dsa: use NET_NAME_PREDICTABLE for user ports with name given in DT Date: Fri, 11 Nov 2022 17:17:28 +0100 Message-Id: <20221111161729.915233-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749217515602222898?= X-GMAIL-MSGID: =?utf-8?q?1749217515602222898?= |
Series |
net: dsa: use NET_NAME_PREDICTABLE for user ports with name given in DT
|
|
Commit Message
Rasmus Villemoes
Nov. 11, 2022, 4:17 p.m. UTC
When a user port has a label in device tree, the corresponding
netdevice is "predictably named by the kernel".
Expose that information properly for the benefit of userspace tools
that make decisions based on the name_assign_type attribute,
e.g. a systemd-udev rule with "kernel" in NamePolicy.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
net/dsa/dsa2.c | 3 ---
net/dsa/slave.c | 13 +++++++++++--
2 files changed, 11 insertions(+), 5 deletions(-)
Comments
> diff --git a/net/dsa/slave.c b/net/dsa/slave.c > index a9fde48cffd4..dfefcc4a9ccf 100644 > --- a/net/dsa/slave.c > +++ b/net/dsa/slave.c > @@ -2374,16 +2374,25 @@ int dsa_slave_create(struct dsa_port *port) > { > struct net_device *master = dsa_port_to_master(port); > struct dsa_switch *ds = port->ds; > - const char *name = port->name; > struct net_device *slave_dev; > struct dsa_slave_priv *p; > + const char *name; > + int assign_type; > int ret; > > if (!ds->num_tx_queues) > ds->num_tx_queues = 1; > > + if (port->name) { > + name = port->name; > + assign_type = NET_NAME_PREDICTABLE; > + } else { > + name = "eth%d"; > + assign_type = NET_NAME_UNKNOWN; > + } I know it is a change in behaviour, but it seems like NET_NAME_ENUM should be used, not NET_NAME_UNKNOWN. alloc_etherdev_mqs() uses NET_NAME_ENUM. https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/netdevice.h#L42 says that NET_NAME_UNKNOWN does not get passed to user space, but i assume NET_NAME_ENUM does. So maybe changing it would be an ABI change? Humm, i don't know what the right thing is... Andrew
On 11/11/2022 18.10, Andrew Lunn wrote: >> diff --git a/net/dsa/slave.c b/net/dsa/slave.c >> index a9fde48cffd4..dfefcc4a9ccf 100644 >> --- a/net/dsa/slave.c >> +++ b/net/dsa/slave.c >> @@ -2374,16 +2374,25 @@ int dsa_slave_create(struct dsa_port *port) >> { >> struct net_device *master = dsa_port_to_master(port); >> struct dsa_switch *ds = port->ds; >> - const char *name = port->name; >> struct net_device *slave_dev; >> struct dsa_slave_priv *p; >> + const char *name; >> + int assign_type; >> int ret; >> >> if (!ds->num_tx_queues) >> ds->num_tx_queues = 1; >> >> + if (port->name) { >> + name = port->name; >> + assign_type = NET_NAME_PREDICTABLE; >> + } else { >> + name = "eth%d"; >> + assign_type = NET_NAME_UNKNOWN; >> + } > > I know it is a change in behaviour, but it seems like NET_NAME_ENUM > should be used, not NET_NAME_UNKNOWN. alloc_etherdev_mqs() uses > NET_NAME_ENUM. I don't really have any strong opinion on the case where we fall back to eth%d, as its not relevant to any board I've worked on. > https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/netdevice.h#L42 > says that NET_NAME_UNKNOWN does not get passed to user space, but i > assume NET_NAME_ENUM does. So maybe changing it would be an ABI > change? Well, the name_assign_type ABI is kind of silly. I mean, userspace knows that when one gets EINVAL trying to read the value, that really means that the value is NET_NAME_UNKNOWN. But I won't propose changing that. However, what I do propose here is obviously already an ABI change; I _want_ to expose more proper information in the case where the port has a label, and just kept the NET_NAME_UNKNOWN for the eth%d case to make the minimal change. But if people want to change that to NET_NAME_ENUM while we're here, I can certainly do that. I can't think of any real scenario where NET_NAME_ENUM would be treated differently than NET_NAME_UNKNOWN - in both cases, userspace don't know that the name can be trusted to be predictable. Rasmus
On Sun, 13 Nov 2022 21:03:52 +0100 Rasmus Villemoes wrote: > > I know it is a change in behaviour, but it seems like NET_NAME_ENUM > > should be used, not NET_NAME_UNKNOWN. alloc_etherdev_mqs() uses > > NET_NAME_ENUM. > > I don't really have any strong opinion on the case where we fall back to > eth%d, as its not relevant to any board I've worked on. > > > https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/netdevice.h#L42 > > says that NET_NAME_UNKNOWN does not get passed to user space, but i > > assume NET_NAME_ENUM does. So maybe changing it would be an ABI > > change? > > Well, the name_assign_type ABI is kind of silly. I mean, userspace knows > that when one gets EINVAL trying to read the value, that really means > that the value is NET_NAME_UNKNOWN. But I won't propose changing that. > > However, what I do propose here is obviously already an ABI change; I > _want_ to expose more proper information in the case where the port has > a label, and just kept the NET_NAME_UNKNOWN for the eth%d case to make > the minimal change. But if people want to change that to NET_NAME_ENUM > while we're here, I can certainly do that. I can't think of any real > scenario where NET_NAME_ENUM would be treated differently than > NET_NAME_UNKNOWN - in both cases, userspace don't know that the name can > be trusted to be predictable. Apparently there may be a reason, see commit e9f656b7a214 ("net: ethernet: set default assignment identifier to NET_NAME_ENUM") so let's switch to ENUM while at it.
> Apparently there may be a reason, see commit e9f656b7a214 ("net: > ethernet: set default assignment identifier to NET_NAME_ENUM") > so let's switch to ENUM while at it. I would recommend two patches, making it easier to revert if we find something in userspace breaks. Andrew
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index e504a18fc125..522fc1b6e8c6 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1364,9 +1364,6 @@ static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index) static int dsa_port_parse_user(struct dsa_port *dp, const char *name) { - if (!name) - name = "eth%d"; - dp->type = DSA_PORT_TYPE_USER; dp->name = name; diff --git a/net/dsa/slave.c b/net/dsa/slave.c index a9fde48cffd4..dfefcc4a9ccf 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -2374,16 +2374,25 @@ int dsa_slave_create(struct dsa_port *port) { struct net_device *master = dsa_port_to_master(port); struct dsa_switch *ds = port->ds; - const char *name = port->name; struct net_device *slave_dev; struct dsa_slave_priv *p; + const char *name; + int assign_type; int ret; if (!ds->num_tx_queues) ds->num_tx_queues = 1; + if (port->name) { + name = port->name; + assign_type = NET_NAME_PREDICTABLE; + } else { + name = "eth%d"; + assign_type = NET_NAME_UNKNOWN; + } + slave_dev = alloc_netdev_mqs(sizeof(struct dsa_slave_priv), name, - NET_NAME_UNKNOWN, ether_setup, + assign_type, ether_setup, ds->num_tx_queues, 1); if (slave_dev == NULL) return -ENOMEM;