From nobody Thu Apr 9 01:45:26 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9A01C4332F for ; Wed, 2 Nov 2022 00:25:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229912AbiKBAZk (ORCPT ); Tue, 1 Nov 2022 20:25:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbiKBAZf (ORCPT ); Tue, 1 Nov 2022 20:25:35 -0400 Received: from mx0a-003ede02.pphosted.com (mx0a-003ede02.pphosted.com [205.220.169.153]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E17AA60CE for ; Tue, 1 Nov 2022 17:25:34 -0700 (PDT) Received: from pps.filterd (m0286617.ppops.net [127.0.0.1]) by mx0b-003ede02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2A20PYqx003058 for ; Tue, 1 Nov 2022 17:25:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getcruise.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=ppemail; bh=HNeH6fQKWa/SXTqsQ3ku21U4ths4w0Cni02GfQkvwJU=; b=FE8RKg2bNnCCSEFEk3OlkHJjN1j1IGYZSGSzi2TfDF5gM2yBTz/QzMWGS4fzGqW4dhW8 36S26gPwrUw/VYuLaPIUP+sOQjQwAggWQgIU7Z7WTaSyepHZzajyBljVo1RSAQtLYx7j EL2ruIwpE/uWh5EXtaJOTjaYdMqb6/vaBfPffzfu3Tn6vA9tsJhthLE3S7If2tE7Dkwm dshOPa47bnTTtAPR93JeIPkNtWm/ItGd5pgE25u0fcqTXWIbEcQsT6krI9KPQ7XOWdzF e0nJYJ1gxecsi07PTBByHvaeZhxkdgWzg3vWv5D2a6+DSsvzLqcC2p0BL1Em7d1xfo7E Yw== Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by mx0b-003ede02.pphosted.com (PPS) with ESMTPS id 3kh0k60wrg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 01 Nov 2022 17:25:34 -0700 Received: by mail-pg1-f197.google.com with SMTP id t4-20020a635344000000b0045fe7baa222so8567540pgl.13 for ; Tue, 01 Nov 2022 17:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getcruise.com; 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=HNeH6fQKWa/SXTqsQ3ku21U4ths4w0Cni02GfQkvwJU=; b=gZMI7qdmcGdQieYwM6F86KvCUS5dNynbkKH1Hqmbl0z5g0i8Yv83PyUoGB+4LIPIkc lPIg3ew2iLvBySJ7Jlt1XSpu4FNrd5qwG57XDkz3EOLkesy55IP5Qb+0VpO3tslKEZXU RUjxe7FFjE+OjZp8OWFVkKSLqeWsEX6lrmExhM5KRTIPDPbe4pg7OAt3OAhlWsqNGhRk 9hZt7wportbubjzEbSUoVqTJAIVNA2dzX5EhKJQgv9hQMSfYb3m+j1ekt7I2vmGcX09a 19L/3Wg5UPLqkpeuGJplhecfnNdnpItPBq51BdDpRc/WhV3ETUBfS7L3B9TFNwSNBBJ0 PB+A== 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=HNeH6fQKWa/SXTqsQ3ku21U4ths4w0Cni02GfQkvwJU=; b=XHVZXTmssHFDZqVOFuwB2IyUFpI1FcbwwEF4s3F1d0IDnVj96RghVe75051PYD3LMW S7H9CG3iTGItn81zLAq2Y+gwC5LxxOPjq6nhnlz8wvEOa5J2hcAjuowS+jgTudhfJqDn SdguZA41/9IVMdHYIoTPWygbflTOlAnPkUOxf/RGKGdFUudiU9/axY0XlwkHYQ4dlohH LnYBV/cyuxntG3EEfBoZd1pfp1rYQJaZ0irQHzJ2+6voZlpvm5vyCqrMEzCYEUO0MtYr ad7I+cJr19TsBgtDwtjCZVFVmfU60v8XZBoniFJvnIAz6bQdixd5P7hljTsDj0APD74Q TkoQ== X-Gm-Message-State: ACrzQf2sN5c/g07oIbFKvRIxnQI5Y7EM8hEpk3JLknqfX/oMei+xWFLB /yj4KkAeLApbnfHEl51r/wmEVMvrUaUUvh7vCxnXDCBDKs3+IXPCA7BgYCfg6K5NN5OIDjuHKTT 3f3EQbQvgxuKdA4DbBfi3RdU= X-Received: by 2002:a17:902:6bc5:b0:183:4bef:1b20 with SMTP id m5-20020a1709026bc500b001834bef1b20mr21661896plt.158.1667348733542; Tue, 01 Nov 2022 17:25:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/YWdmRuUsmso5eR0Fo7r6dQnDUFcvn5En4f2d0BIxI8IYV1nnrOD0fnF5ySDdIKGo+FLgDg== X-Received: by 2002:a17:902:6bc5:b0:183:4bef:1b20 with SMTP id m5-20020a1709026bc500b001834bef1b20mr21661869plt.158.1667348733233; Tue, 01 Nov 2022 17:25:33 -0700 (PDT) Received: from 4VPLMR2-DT.corp.robot.car ([199.73.125.241]) by smtp.gmail.com with ESMTPSA id x20-20020a17090a531400b001fe39bda429sm98272pjh.38.2022.11.01.17.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 17:25:32 -0700 (PDT) From: Andy Ren To: netdev@vger.kernel.org Cc: richardbgobert@gmail.com, davem@davemloft.net, wsa+renesas@sang-engineering.com, edumazet@google.com, petrm@nvidia.com, kuba@kernel.org, pabeni@redhat.com, corbet@lwn.net, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, roman.gushchin@linux.dev, Andy Ren Subject: [PATCH net-next v2] netconsole: Enable live renaming for network interfaces used by netconsole Date: Tue, 1 Nov 2022 17:24:20 -0700 Message-Id: <20221102002420.2613004-1-andy.ren@getcruise.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: WOtgLV98bJ8wvtghYxWsdgSeYtDtON3r X-Proofpoint-ORIG-GUID: WOtgLV98bJ8wvtghYxWsdgSeYtDtON3r X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-01_11,2022-11-01_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211010163 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch enables support for live renaming of network interfaces initialized by netconsole. This resolves an issue seen when netconsole is configured to boot as a built-in kernel module with a kernel boot argument. As stated in the kernel man page - As a built-in, netconsole initializes immediately after NIC cards and will bring up the specified interface as soon as possible. Consequently, the renaming of specified interfaces will fail and return EBUSY. This is because by default, the kernel disallows live renaming unless the device explicitly sets a priv_flags bit (e.g: IFF_LIVE_RENAME_OK or IFF_LIVE_ADDR_CHANGE), and so renaming after a network interface is up returns EBUSY. The changes to the kernel are as of following: - Addition of a iface_live_renaming boolean flag to the netpoll struct, used to enable/disable interface live renaming. False by default - Changes to check for the aforementioned flag in network and ethernet driver interface renaming code - Adds a new optional "*" parameter to the netconsole configuration string that enables interface live renaming when included (e.g. netconsole=3D+*....). When this optional parameter is included, "iface_live_renaming" is set to true Signed-off-by: Andy Ren --- Documentation/networking/netconsole.rst | 7 ++++--- drivers/net/netconsole.c | 5 +++++ include/linux/netpoll.h | 3 +++ net/core/dev.c | 3 ++- net/core/netpoll.c | 15 +++++++++++++++ net/ethernet/eth.c | 5 ++++- 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Documentation/networking/netconsole.rst b/Documentation/networ= king/netconsole.rst index 1f5c4a04027c..01a45f38ce3f 100644 --- a/Documentation/networking/netconsole.rst +++ b/Documentation/networking/netconsole.rst @@ -34,10 +34,11 @@ Sender and receiver configuration: It takes a string configuration parameter "netconsole" in the following format:: =20 - netconsole=3D[+][src-port]@[src-ip]/[],[tgt-port]@/[tgt-maca= ddr] + netconsole=3D[+][*][src-port]@[src-ip]/[],[tgt-port]@/[tgt-m= acaddr] =20 where + if present, enable extended console support + * if present, allow runtime network interface renaming src-port source for UDP packets (defaults to 6665) src-ip source IP to use (interface address) dev network interface (eth0) @@ -47,7 +48,7 @@ following format:: =20 Examples:: =20 - linux netconsole=3D4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc + linux netconsole=3D*4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc =20 or:: =20 @@ -158,7 +159,7 @@ If '+' is prefixed to the configuration line or "extend= ed" config file is set to 1, extended console support is enabled. An example boot param follows:: =20 - linux netconsole=3D+4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc + linux netconsole=3D+*4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc =20 Log messages are transmitted with extended metadata header in the following format which is the same as /dev/kmsg:: diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index bdff9ac5056d..dea5b783744f 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -188,6 +188,11 @@ static struct netconsole_target *alloc_param_target(ch= ar *target_config) target_config++; } =20 + if (*target_config =3D=3D '*') { + nt->np.iface_live_renaming =3D true; + target_config++; + } + /* Parse parameters and setup netpoll */ err =3D netpoll_parse_options(&nt->np, target_config); if (err) diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h index bd19c4b91e31..f2ebdabf0959 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h @@ -32,6 +32,7 @@ struct netpoll { bool ipv6; u16 local_port, remote_port; u8 remote_mac[ETH_ALEN]; + bool iface_live_renaming; }; =20 struct netpoll_info { @@ -51,9 +52,11 @@ struct netpoll_info { void netpoll_poll_dev(struct net_device *dev); void netpoll_poll_disable(struct net_device *dev); void netpoll_poll_enable(struct net_device *dev); +bool netpoll_live_renaming_enabled(struct net_device *dev); #else static inline void netpoll_poll_disable(struct net_device *dev) { return; } static inline void netpoll_poll_enable(struct net_device *dev) { return; } +static inline bool netpoll_live_renaming_enabled(struct net_device *dev) {= return false; } #endif =20 void netpoll_send_udp(struct netpoll *np, const char *msg, int len); diff --git a/net/core/dev.c b/net/core/dev.c index 2e4f1c97b59e..90e6870d38d0 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1176,7 +1176,8 @@ int dev_change_name(struct net_device *dev, const cha= r *newname) * directly. */ if (dev->flags & IFF_UP && - likely(!(dev->priv_flags & IFF_LIVE_RENAME_OK))) + likely(!(dev->priv_flags & IFF_LIVE_RENAME_OK) && + !netpoll_live_renaming_enabled(dev))) return -EBUSY; =20 down_write(&devnet_rename_sem); diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 9be762e1d042..a22319676667 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -224,6 +224,21 @@ void netpoll_poll_enable(struct net_device *dev) } EXPORT_SYMBOL(netpoll_poll_enable); =20 +bool netpoll_live_renaming_enabled(struct net_device *dev) +{ + struct netpoll_info *ni; + bool live_renaming_enabled =3D false; + + rcu_read_lock(); + ni =3D rcu_dereference(dev->npinfo); + if (ni && ni->netpoll->iface_live_renaming) + live_renaming_enabled =3D true; + rcu_read_unlock(); + + return live_renaming_enabled; +} +EXPORT_SYMBOL(netpoll_live_renaming_enabled); + static void refill_skbs(void) { struct sk_buff *skb; diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index e02daa74e833..bb341acfcf05 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -62,6 +62,7 @@ #include #include #include +#include =20 /** * eth_header - create the Ethernet header @@ -288,8 +289,10 @@ int eth_prepare_mac_addr_change(struct net_device *dev= , void *p) { struct sockaddr *addr =3D p; =20 - if (!(dev->priv_flags & IFF_LIVE_ADDR_CHANGE) && netif_running(dev)) + if (!(dev->priv_flags & IFF_LIVE_ADDR_CHANGE) && netif_running(dev) && + !netpoll_live_renaming_enabled(dev)) return -EBUSY; + if (!is_valid_ether_addr(addr->sa_data)) return -EADDRNOTAVAIL; return 0; --=20 2.38.1