From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.135 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796414516; b=nMcuQpxyFpAzJMqr4Q7Tj4TnvtmVGLZ/5EpH/oJgThL55USj1AEJoRV/FHOdy0EfaWHk vWQ/sgm+Ok6OPBWqlXBV/+6CAs+XGaRyNk1rO9Gl4ZfiRrGvIxMOvvoTrRx+HJhXivKTQ 0mONOc6WPP/j79GrjPFU4dkaY201t1YxrzrnCLhKv6LNoma6bHIPuik2RjOnuOVbgjp5W t4WeXxv3aBM9NmhBRB/BVQ7LhBf/APCx+w4z1scUZi5twumaq5RgYS/VdyEPc0SavMYNh Rox38/Lq2k4Sg2yYsYJGPF/k29eRwg4OQuuvk4vXkgo+3lR61hwVzm6M/zVIKvvSh6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796414516; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:Message-ID:In-Reply-To:References:From:Subject:To:Cc: MIME-Version:Content-Type:Content-Disposition:User-Agent; bh=CAfod/wXTcCObLUUKhevp/WA8FkEBmzDf4lky8T9UHE=; b=OfIArwYAB4bQ8Pbn9DLARDoT6PJTm/iZF8GdEHaNVfBsGzYKBcbtJ3wEFWwqtpTcZ2d6 odu6KNgkop22NxsuqzBkQ8rdkXmtEOELlHm979ghZueAwVSXKFKDld3TwMX0rZ3u4n8zj 3wBdYwvTiTo4bZpNFtq08I1Ky5/b/Zsd3hy7WOb5+GMkw/KDBwrTwzAVOC0699QqbR1Wj N5iuvpObaNxK86foO1nAEgsm6YCYXmxWky9xRp/HIjfBIWfI2SohJs+4TpOcZGTZv08G4 cDPdsiY7vsLXJCRD08ZNj0MER5dfEoB9QHLCtFlPGEjJMbEtM3vOZTQ7kXAydgD7q0Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass header.d=chrisdown.name header.i=@chrisdown.name header.a=rsa-sha256 header.s=google header.b=UQ+CM9z1; arc=none smtp.remote-ip=74.125.224.135 Received: from mail-yx2-f7.google.com (mail-yx2-f7.google.com [74.125.224.135]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F126606A685 for ; Fri, 4 Dec 2026 20:01:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3F126606A685 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.a=rsa-sha256 header.s=google header.b=UQ+CM9z1 Received: by mail-yx2-f7.google.com with SMTP id 956f58d0204a3-67a1a96329cso460805d50.1 for ; Fri, 04 Dec 2026 12:01:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1796414514; x=1797019314; darn=vger.kernel.org; h=user-agent:content-disposition:content-type:mime-version:cc:to :subject:from:references:in-reply-to:message-id:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=CAfod/wXTcCObLUUKhevp/WA8FkEBmzDf4lky8T9UHE=; b=UQ+CM9z1UvEj51TFv65fsRyB4uAXRQACit7g8RM5dSXzZe3UNoRv8rmH/Nr89jpK8P 5PY4L0gNZLcgl6/5eaNXNb/oWZy+5bKhVFQCfv0sJjxawT55HfrxV1RioDotuwOcL28w ZDqCVvNV2Z1kV33OgYL27wgY4bamy6zS2rcUU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796414514; x=1797019314; h=user-agent:content-disposition:content-type:mime-version:cc:to :subject:from:references:in-reply-to:message-id:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CAfod/wXTcCObLUUKhevp/WA8FkEBmzDf4lky8T9UHE=; b=0CAUXjWia3bf5Rj3eIAavwDZLrNYVfHzHFQ5BKFCPnYqAsEYQteh57TAlZJS1Tw/EX 7kk3LYLWJXIPzGaFyqeJTfuHOGoKhCcmQSe4G77soDYo61d4NDMttTz6+MPtWKApt2BX /z6pRyYePqodYe6+I5kGvnH8zOoqvOT3tEDrmkhhzeaG0xqvj6kJS7VHF8zda+VAKP0e C0jiFP00fX3jKskNelREAMH53bviGbdYutPUiqF5qE0RStgPA+QugsrL9OBKpbYFlPeS E95pYU23HiqKDfC5L7iE9PzCAEK1Tkp3rGbOKrQ4Uj70q+XC0VhGB5VNi3+6tGKU/aY8 6NRQ== X-Forwarded-Encrypted: i=1; AL+hErGS9PNwbmt2B6y06+mkNYJT+ohjtQ4HgOdJor5mypbznGxTXG/WSChfV+GotFc6/2dSB6Mxh2K71MX9Egs=@vger.kernel.org X-Gm-Message-State: AB4q+uHuTQh9Jnms1OUr3BLzVUVFyV6Ed+Elmyh265wtceLeKH721Fnj ARIOkk6srS0jpoqAG8fQ6FiwVaVyCjRDFHtVBeCYvJisj6ExNd32K0eHC1Mppu6yCkc= X-Gm-Gg: AZFdTZfAYwukpvoZtP15a2V3c3V0RG35GcaT+QHx8xKZBNiLskctrGC6eLku5qZnTST 3fElV9n/xQHndHM2XuEkLOLefm0uvdAGDV+KNZXSTn8I4v4mi6at1BDKNOCcqlgizXjyI9jhhhL ENPe0x2FyyuHNq6uFfDfHtFbwovwllOYTgpUKR9XhaEfzXLvxtuHA4kHWSwCOCUKnckZtqTC4Fa U1z9WhUF0v2wSjhRINTaz4veFwb5H7QbB772Bm0j94h4AlFLPvnShkcekGl78rtWiE6N2DM7nMH zxLJju1DnN0MLNxUdbCfzo0FuhodKrS+m2zi4wVXruTkVuwIGGZD2RvgGP8MgBuFv4iYTmCh4sS f5QbciY7CLcZkqdzluzKURCMXA76LNfKVPBwHKIY2ux1TKSQt4WxPSAIxTFU5nWSPGcOwcD4a7h 5hS+EeBQP3M3/6pOJJj9OizVF9NAgUSzw7t8nsGhwyyRUaOD2pBdB7p6KkuWciO6zaS/B5oPLeG 4Fvow3ESTPSLEXaQmR8q8k3vCQW7+7iINqUI8ajd3CeOq6MwdELBS3HQaPf7Ic7+2pqNrcMOXmF Xu0mgrdbBKgDFBxjni1Xq96BIbM1TcLlSgYememESwtCvDK7tA4zHBh1Cyup2viqvZXNGYoIt0+ +40FeltK+Ron3A0fUfteW9J/A6/V4+xLnz5cAvJwEg0zm4dYnmLAW+Zhl73qy3wLCzeacbgpQ3G cifKKQU5m7ARSfJH5nHYq/AldIbZBsF9w2/iPjHrQuv652tM7FFGPYLGg2O5A9eOlINv0Id2x5F K5/hQMqeePEDu8cS+9rf6I= X-Received: by 2002:a05:690e:d4d:b0:67d:821f:5c56 with SMTP id 956f58d0204a3-67f7242506emr1007392d50.62.1796414514009; Fri, 04 Dec 2026 12:01:54 -0800 (PST) Received: from [172.18.0.2] (c-73-207-185-9.hsd1.ga.comcast.net. [73.207.185.9]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67f0cd1e19asm1431153d50.18.2026.12.04.12.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 12:01:53 -0800 (PST) Date: Fri, 04 Dec 2026 12:01:51 -0800 Message-ID: <17873a1a6af2e6523697df22d83bb0a25b5298bc.1796410817.git.chris@chrisdown.name> In-Reply-To: References: From: Chris Down Subject: [PATCH 1/2] netconsole: give the console of each target a unique name To: Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Shuah Khan , Shuah Khan , Gustavo Luiz Duarte , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, pmladek@suse.com, john.ogness@linutronix.de, printk@lists.linux.dev, kernel-team@meta.com X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/2.4.3 (cc9e3943) (2026-10-09) Since commit 0d97bae9abbe ("netconsole: register one console per target") the console of a target is called netcons_. Only 15 characters of that fit in the name of a console and a target made through configfs always has index 0, so targets whose names start with the same seven characters get consoles with the same name and index. For example, with targets called target_alpha and target_beta: # grep netcons /proc/consoles netcons_target_0 -W- (E N ) netcons_target_0 -W- (E N ) The targets which netcons_torture.sh creates all register as netcons_netcons0 in the same way. A target called cmdline5 which was not set up by netconsole= is cut to netcons_cmdline0 as well, and that is already the console of the first target from the command line. That commit said that names could collide, and on its own all this means is that /proc/consoles can't tell these consoles apart. It becomes a real problem once something is keyed by the name. The per-console loglevel series [0] adds /sys/class/console/ for each console, which is also where the replay trigger for netconsole is expected to go [1]. With that series applied on top, enabling target_beta above prints a stack trace with sysfs: cannot create duplicate filename '/devices/virtual/console/netcons_target_0' and the target is left without a directory in /sys/class/console, so there is no way to set its loglevel. To fix this, let's give a new target the lowest index which no other target with the same console name has. The targets above become netcons_target_0 and netcons_target_1. A console name shorter than 15 characters, like netcons_foo, can only belong to one target, so target foo keeps index 0 and is still netcons_foo0. The index is chosen when the target is created, and not when its console is registered, so that the console keeps its name while the target is disabled and enabled again. Choosing it means looking at every other target. A target is on target_list or target_cleanup_list, except while process_resume_target() has taken it off both, which it does with dynamic_netconsole_mutex held. make_netconsole_target() thus takes that mutex and target_cleanup_list_lock as well as target_list_lock. Numbering all the consoles from one counter would be simpler, but then target foo is no longer always netcons_foo0, and target a with index 10 would show up under the same name as target a1 with index 0. I ran into this while testing the per-console loglevel series on top of net-next, with the two targets above. With this patch they get different names in /proc/consoles and, with that series applied, a directory each in /sys/class/console. The netconsole selftests still pass. [0]: https://lore.kernel.org/r/84b8d91693e56f6026271bc40553bcb6657ab24d.1764272407.git.chris@chrisdown.name [1]: https://lore.kernel.org/r/at84qygscue8crQi@gmail.com Fixes: 0d97bae9abbe ("netconsole: register one console per target") Signed-off-by: Chris Down --- drivers/net/netconsole.c | 43 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 4b546194f717..713f7735b062 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1850,6 +1850,40 @@ static struct netconsole_target *find_cmdline_target(const char *name) return ret; } +static bool console_index_in_use(struct list_head *targets, const char *name, + short index) +{ + struct netconsole_target *nt; + + list_for_each_entry(nt, targets, list) { + if (nt->console.index == index && + !strcmp(nt->console.name, name)) + return true; + } + + return false; +} + +/* Return the lowest index that no target uses together with the console name + * @name. A target is on target_list or on target_cleanup_list, unless + * process_resume_target() is resuming it under dynamic_netconsole_mutex, so + * the caller holds that mutex and the locks of both lists. + */ +static short netconsole_free_console_index(const char *name) +{ + short index = 0; + + lockdep_assert_held(&dynamic_netconsole_mutex); + lockdep_assert_held(&target_cleanup_list_lock); + lockdep_assert_held(&target_list_lock); + + while (console_index_in_use(&target_list, name, index) || + console_index_in_use(&target_cleanup_list, name, index)) + index++; + + return index; +} + /* * Group operations and type for netconsole_subsys. */ @@ -1879,14 +1913,21 @@ static struct config_group *make_netconsole_target(struct config_group *group, /* Initialize the config_group member */ init_target_config_group(nt, name); - /* The index stays 0, printk shows the console as netcons_0 */ snprintf(nt->console.name, sizeof(nt->console.name), "netcons_%s", name); /* Adding, but it is disabled */ + dynamic_netconsole_mutex_lock(); + mutex_lock(&target_cleanup_list_lock); spin_lock_irqsave(&target_list_lock, flags); + /* netcons_ is cut to fit, so targets can share it. printk shows + * the index after the name, which is 0 unless the name is taken. + */ + nt->console.index = netconsole_free_console_index(nt->console.name); list_add(&nt->list, &target_list); spin_unlock_irqrestore(&target_list_lock, flags); + mutex_unlock(&target_cleanup_list_lock); + dynamic_netconsole_mutex_unlock(); return &nt->group; } -- 2.56.1