From nobody Sat Feb 7 18:28:39 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 69D6C125A0; Fri, 6 Feb 2026 12:50:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770382225; cv=none; b=sKx9oBb3UslYKRd8XmnP/tfrH4i2UeW1I8HQYLNA01fb7v7G9WxxX95ZIuh48YbADabqUTl2vUI3vjWucQLFSN0w1YooHJ2HEIVwamfK/kxpMSqNWkSh6ieHvQ9YrRauJbLvT6CDr+lrijgXG2RJm2LOl6/zyeaea2qcjNJF3oI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770382225; c=relaxed/simple; bh=mblUlqMee7xPrbQSyHQAbH5cmW73s7eVaewpLfeIYIo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H6JOGbYapiLDEWVhuu+9b7omW+OpPOW6KsyRXGY3tuqXV7NLvgjH1MuGpOatb+yf5BP1enT/fFDpn1eCy/jppNHhCAVxWmfWlWZ7CSzQQRjPjE6dhAzIMRXEC2Ep1oUT8EUdTzcCF38qyUgJC3Iqi19Q6wc6kXX8VuhY3hlUbi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=nUTFbKv5; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="nUTFbKv5" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=F46+BVh5qJcmfs//UilDsQzQbvMrlIR7aX+CON5P7Z4=; b=nUTFbKv5+fAhNSykgimI1/dJ7p BLA7zOMl8G/NU6+2HPmUKcFRE5H1jxuZ8ocgR9kcVkSmCtVskB1PSWPdrOC9yIILDV0w+fXNCb7Mw zD6DAVm1ta+5P/mJSY8PzYEISpgrSwD01HUJDnoARtJNk7T4IrYJtDxqq76tpFryAMKsUj5VfcMN+ xQxILUcQV49E6of9L7LvXbHRRSXOYSRvQgSAV7aMxTpV4eRpyVuWSc+QvozyAusmFbYxjutT0DE4k 8a7QIoe1LDDS7TX0yZdU8ZIWcXwsGnC2HITTiUcULk588F+rC3sXcErZIFPa85XpZ2MojEjiwTZv9 ePgd+3pw==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1voLHs-007Ac4-EW; Fri, 06 Feb 2026 12:50:16 +0000 From: Breno Leitao Date: Fri, 06 Feb 2026 04:45:29 -0800 Subject: [PATCH net-next v7 1/4] printk: Add execution context (task name/CPU) to printk_info Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260206-nbcon-v7-1-62bda69b1b41@debian.org> References: <20260206-nbcon-v7-0-62bda69b1b41@debian.org> In-Reply-To: <20260206-nbcon-v7-0-62bda69b1b41@debian.org> To: Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , pmladek@suse.com, john.ogness@linutronix.de Cc: Greg Kroah-Hartman , Steven Rostedt , Sergey Senozhatsky , Andrew Morton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, asantostc@gmail.com, efault@gmx.de, gustavold@gmail.com, calvin@wbinvd.org, jv@jvosburgh.net, mpdesouza@suse.com, kernel-team@meta.com X-Mailer: b4 0.15-dev-f4305 X-Developer-Signature: v=1; a=openpgp-sha256; l=9035; i=leitao@debian.org; h=from:subject:message-id; bh=mblUlqMee7xPrbQSyHQAbH5cmW73s7eVaewpLfeIYIo=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpheN8qL11WrYKDbzDv/jlnMGRIF58kAocXDThB /VVf2qwXQ+JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaYXjfAAKCRA1o5Of/Hh3 bZTdD/97FiaaVVLzYQjkfk/4HDYI+Ndu1q6S30I88Qg/1Z8/07N7zJlN06CQ/5EwTVHCi2/o3uc ifeqD90i5iWPZLUYEukRSqmI7S9l+UlJOjTeNSQ31N/6xUjhPhuZ3s399xcrvXB1Bd1oAF43/Xj 9pAAePhYyBPkNN0k29q8E6HPr7cnqJQpXI0UGMTNkskHiTbct3JMTIbqxKscenVvMgA/5Y/pDK/ eqTLb0uhFrInfICyr9h229bM3ipUEme3bDnYfE+36aD+PCtuySzbsQhT0ThAs2tVq2bSPTVRCrp UXmNqhNr29hxOPRa3BRjcW+04/qc+56ZKXF5mcS92X7YlhGrBO28bJjwd1CIBCCWMTH3Zm+Ktyh dYZ/cjxQ7f70CDM+WLlySZjgEIJKRCjQSlkCA5EaOG04jWz5If7U/JtB52Y9c5K30rsG3rQ5fBH vik2LABAKNHr5TIg6jgSVP9wbce0fVtHm0n/6Vkz5Zwid4dF06B7zBbScI9k9XMXAOEZW8FB3+k EcAMXiE3ZTDwL2CnnBNZjUDT7CIa/bA89co/Psw+9/5MZ5u9pb19vmmIKW56nFxCkGSyeyuNoY0 aPaysowFA19ibHi1S941qzLvvNXJqS3rTpT+GUQkBtbgDC192EVxsYrX6VL7GqFjD6+Kmly/MNw NV9k8xS0gxKw/Pg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Extend struct printk_info to include the task name, pid, and CPU number where printk messages originate. This information is captured at vprintk_store() time and propagated through printk_message to nbcon_write_context, making it available to nbcon console drivers. This is useful for consoles like netconsole that want to include execution context in their output, allowing correlation of messages with specific tasks and CPUs regardless of where the console driver actually runs. The feature is controlled by CONFIG_PRINTK_EXECUTION_CTX, which is automatically selected by CONFIG_NETCONSOLE_DYNAMIC. When disabled, the helper functions compile to no-ops with no overhead. Suggested-by: John Ogness Signed-off-by: Petr Mladek Reviewed-by: Petr Mladek Signed-off-by: Breno Leitao Reviewed-by: John Ogness --- drivers/net/Kconfig | 1 + include/linux/console.h | 8 ++++++ kernel/printk/internal.h | 8 ++++++ kernel/printk/nbcon.c | 16 ++++++++++++ kernel/printk/printk.c | 54 +++++++++++++++++++++++++++++++++++= +++- kernel/printk/printk_ringbuffer.h | 5 ++++ lib/Kconfig.debug | 12 +++++++++ 7 files changed, 103 insertions(+), 1 deletion(-) diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 9c7953f8e6377..7e9becad91dfb 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -341,6 +341,7 @@ config NETCONSOLE_DYNAMIC bool "Dynamic reconfiguration of logging targets" depends on NETCONSOLE && SYSFS && CONFIGFS_FS && \ !(NETCONSOLE=3Dy && CONFIGFS_FS=3Dm) + select PRINTK_EXECUTION_CTX help This option enables the ability to dynamically reconfigure target parameters (interface, IP addresses, port numbers, MAC addresses) diff --git a/include/linux/console.h b/include/linux/console.h index fc9f5c5c1b04c..cc5dc3bf58b60 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -298,12 +298,20 @@ struct nbcon_context { * @outbuf: Pointer to the text buffer for output * @len: Length to write * @unsafe_takeover: If a hostile takeover in an unsafe state has occurred + * @cpu: CPU on which the message was generated + * @pid: PID of the task that generated the message + * @comm: Name of the task that generated the message */ struct nbcon_write_context { struct nbcon_context __private ctxt; char *outbuf; unsigned int len; bool unsafe_takeover; +#ifdef CONFIG_PRINTK_EXECUTION_CTX + int cpu; + pid_t pid; + char comm[TASK_COMM_LEN]; +#endif }; =20 /** diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 5f5f626f42794..5fdea56827564 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -281,12 +281,20 @@ struct printk_buffers { * nothing to output and this record should be skipped. * @seq: The sequence number of the record used for @pbufs->outbuf. * @dropped: The number of dropped records from reading @seq. + * @cpu: CPU on which the message was generated. + * @pid: PID of the task that generated the message + * @comm: Name of the task that generated the message. */ struct printk_message { struct printk_buffers *pbufs; unsigned int outbuf_len; u64 seq; unsigned long dropped; +#ifdef CONFIG_PRINTK_EXECUTION_CTX + int cpu; + pid_t pid; + char comm[TASK_COMM_LEN]; +#endif }; =20 bool printk_get_next_message(struct printk_message *pmsg, u64 seq, diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 32fc12e536752..f6d22510fdc3a 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -946,6 +946,20 @@ void nbcon_reacquire_nobuf(struct nbcon_write_context = *wctxt) } EXPORT_SYMBOL_GPL(nbcon_reacquire_nobuf); =20 +#ifdef CONFIG_PRINTK_EXECUTION_CTX +static void wctxt_load_execution_ctx(struct nbcon_write_context *wctxt, + struct printk_message *pmsg) +{ + wctxt->cpu =3D pmsg->cpu; + wctxt->pid =3D pmsg->pid; + memcpy(wctxt->comm, pmsg->comm, sizeof(wctxt->comm)); + static_assert(sizeof(wctxt->comm) =3D=3D sizeof(pmsg->comm)); +} +#else +static void wctxt_load_execution_ctx(struct nbcon_write_context *wctxt, + struct printk_message *pmsg) {} +#endif + /** * nbcon_emit_next_record - Emit a record in the acquired context * @wctxt: The write context that will be handed to the write function @@ -1048,6 +1062,8 @@ static bool nbcon_emit_next_record(struct nbcon_write= _context *wctxt, bool use_a /* Initialize the write context for driver callbacks. */ nbcon_write_context_set_buf(wctxt, &pmsg.pbufs->outbuf[0], pmsg.outbuf_le= n); =20 + wctxt_load_execution_ctx(wctxt, &pmsg); + if (use_atomic) con->write_atomic(con, wctxt); else diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 1d765ad242b82..cf6b528610366 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2131,11 +2131,39 @@ static inline void printk_delay(int level) } } =20 +#define CALLER_ID_MASK 0x80000000 + static inline u32 printk_caller_id(void) { return in_task() ? task_pid_nr(current) : - 0x80000000 + smp_processor_id(); + CALLER_ID_MASK + smp_processor_id(); +} + +#ifdef CONFIG_PRINTK_EXECUTION_CTX +/* Store the opposite info than caller_id. */ +static u32 printk_caller_id2(void) +{ + return !in_task() ? task_pid_nr(current) : + CALLER_ID_MASK + smp_processor_id(); +} + +static pid_t printk_info_get_pid(const struct printk_info *info) +{ + u32 caller_id =3D info->caller_id; + u32 caller_id2 =3D info->caller_id2; + + return caller_id & CALLER_ID_MASK ? caller_id2 : caller_id; +} + +static int printk_info_get_cpu(const struct printk_info *info) +{ + u32 caller_id =3D info->caller_id; + u32 caller_id2 =3D info->caller_id2; + + return ((caller_id & CALLER_ID_MASK ? + caller_id : caller_id2) & ~CALLER_ID_MASK); } +#endif =20 /** * printk_parse_prefix - Parse level and control flags. @@ -2213,6 +2241,28 @@ static u16 printk_sprint(char *text, u16 size, int f= acility, return text_len; } =20 +#ifdef CONFIG_PRINTK_EXECUTION_CTX +static void printk_store_execution_ctx(struct printk_info *info) +{ + info->caller_id2 =3D printk_caller_id2(); + get_task_comm(info->comm, current); +} + +static void pmsg_load_execution_ctx(struct printk_message *pmsg, + const struct printk_info *info) +{ + pmsg->cpu =3D printk_info_get_cpu(info); + pmsg->pid =3D printk_info_get_pid(info); + memcpy(pmsg->comm, info->comm, sizeof(pmsg->comm)); + static_assert(sizeof(pmsg->comm) =3D=3D sizeof(info->comm)); +} +#else +static void printk_store_execution_ctx(struct printk_info *info) {} + +static void pmsg_load_execution_ctx(struct printk_message *pmsg, + const struct printk_info *info) {} +#endif + __printf(4, 0) int vprintk_store(int facility, int level, const struct dev_printk_info *dev_info, @@ -2320,6 +2370,7 @@ int vprintk_store(int facility, int level, r.info->caller_id =3D caller_id; if (dev_info) memcpy(&r.info->dev_info, dev_info, sizeof(r.info->dev_info)); + printk_store_execution_ctx(r.info); =20 /* A message without a trailing newline can be continued. */ if (!(flags & LOG_NEWLINE)) @@ -3002,6 +3053,7 @@ bool printk_get_next_message(struct printk_message *p= msg, u64 seq, pmsg->seq =3D r.info->seq; pmsg->dropped =3D r.info->seq - seq; force_con =3D r.info->flags & LOG_FORCE_CON; + pmsg_load_execution_ctx(pmsg, r.info); =20 /* * Skip records that are not forced to be printed on consoles and that diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringb= uffer.h index 4ef81349d9fbe..1651b53ece34f 100644 --- a/kernel/printk/printk_ringbuffer.h +++ b/kernel/printk/printk_ringbuffer.h @@ -23,6 +23,11 @@ struct printk_info { u8 flags:5; /* internal record flags */ u8 level:3; /* syslog level */ u32 caller_id; /* thread id or processor id */ +#ifdef CONFIG_PRINTK_EXECUTION_CTX + u32 caller_id2; /* caller_id complement */ + /* name of the task that generated the message */ + char comm[TASK_COMM_LEN]; +#endif =20 struct dev_printk_info dev_info; }; diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index ba36939fda79b..938d967ae3bf8 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -35,6 +35,18 @@ config PRINTK_CALLER no option to enable/disable at the kernel command line parameter or sysfs interface. =20 +config PRINTK_EXECUTION_CTX + bool + depends on PRINTK + help + This option extends struct printk_info to include extra execution + context in printk, such as task name and CPU number from where the + message originated. This is useful for correlating printk messages + with specific execution contexts. + + This is automatically enabled when a console driver that supports + execution context is selected. + config STACKTRACE_BUILD_ID bool "Show build ID information in stacktraces" depends on PRINTK --=20 2.47.3 From nobody Sat Feb 7 18:28:39 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 675CA125A0; Fri, 6 Feb 2026 12:50:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770382231; cv=none; b=qyEIU4RfYH6SMvJP5yqBuMg5/g1vA6l74Zb6vdGYzjVoYiS1c5rOoUJoUBcHm7DG+X/Fztasrle5gIMvBS86Z55E6MdCtENK0a3h5VVN5uJ9PKZt6oeGqQqNyiJpNFdYgZHuECvFDVYTgUd8PeXtmM23rYtHEnYnIOK3iNI62rQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770382231; c=relaxed/simple; bh=fIda/bwvjdKiEcurZB7NMHmZxg40yG9eI3grk0yk8oU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KuzDg9rf/CJfVkJQrEtFz8e4qOtOEbRdTvvrZkIcM44h947/HPVap+86W+xtk6Gk6SmNm0qKLhlnqTn8vgF415Gb4fo/Vjqy/W6xAEKHGT92iNXSxbjD3vfStVq0Tmp6fhARHXzr1iSrivTv2CPpKDsCa0chdGQAoQD7bzVWVKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=nXM7to+z; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="nXM7to+z" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=MENmtyopKyio3Fbzyv4qcPtKKWl29QukHQsDDkeHm08=; b=nXM7to+znHGvt38RyZVNbt+LjG 0tatvIVaT0v1wiR3ZPQXrIUE9xbN6ZV4UCnGSkzBnrDMLnsv5BbUmdEWQ+S3w8nkRr9BKNSo5ZyHw xOW1K9NPCywZyQBEIL+WrLslq9vwx40NTobn/yaxk3qeg0FSgH13HFy9mXsDk/hAbsOey2hS7moRH J3y9cPVuokVw2LPA6+F8Juq3I+qFdKAGA8Dw/fAQMy/K9LC19bASpvOhulR4ereBkXXxdK6dBsA/j 8xqijMnZBpqMMl2hiI6glsXKEUlhlx0kEHB7cwAK8m6lQM2qIqPYxAGk1+r7df3JCR0UyavOF+51U WrxA9mLQ==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1voLHy-007AcQ-31; Fri, 06 Feb 2026 12:50:22 +0000 From: Breno Leitao Date: Fri, 06 Feb 2026 04:45:30 -0800 Subject: [PATCH net-next v7 2/4] netconsole: extract message fragmentation into send_msg_udp() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260206-nbcon-v7-2-62bda69b1b41@debian.org> References: <20260206-nbcon-v7-0-62bda69b1b41@debian.org> In-Reply-To: <20260206-nbcon-v7-0-62bda69b1b41@debian.org> To: Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , pmladek@suse.com, john.ogness@linutronix.de Cc: Greg Kroah-Hartman , Steven Rostedt , Sergey Senozhatsky , Andrew Morton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, asantostc@gmail.com, efault@gmx.de, gustavold@gmail.com, calvin@wbinvd.org, jv@jvosburgh.net, mpdesouza@suse.com, kernel-team@meta.com, Simon Horman X-Mailer: b4 0.15-dev-f4305 X-Developer-Signature: v=1; a=openpgp-sha256; l=2151; i=leitao@debian.org; h=from:subject:message-id; bh=fIda/bwvjdKiEcurZB7NMHmZxg40yG9eI3grk0yk8oU=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpheN8y1yFgWEaQH8zjPuFi3FUuGzg8RxgeHLXb mw0Bu/k6SGJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaYXjfAAKCRA1o5Of/Hh3 bZt4D/0aZu78pmJ/d09TnR+2Gnj3xX85wO3dwCq///U7PkmyAPapuGZH4+CzYXZO808xtwHO4Uj RMu+THsG51hZeQAdFgw5oqPBXMy3iTI0IBg4Hsj1ei2O6AtxFI/TC3pS4XWPh5I0LtqgP4J/tIl ZWbein3maYj4LsdBUQ82OKPq6cj3NknAdmUUQSm+k9rl75vrKmn/TiFWi/jYz2EHQvHAiPzqdx7 ybtmLW5ATOlckr6E50G8n/RK7LKd/7bdgpjzwx93QIZ/nVCjr2lzJBU7Ei/j5EukrQVcKfCR1jF ETzwfqWl2Ze+wEOAS92n7zT8mHnuIItzxslPRxXuh3j3ZXehItM+Ece3KmYEyOR8IPK6q6GoniS SQkI/DfIGLLOwn3ccORjP+a8n9mgypxvEl30QyFCJczdMCiI6yo0F78vqUxEQ8we40+vj5C8881 tXRI0+an3+dUIe/1ne82Nwov0+SubMsdRsdhkGawEbiBqtZY0oN4EGXVFfc4ao6VTw+Co/BKbGh rvNIPK8dHt6keCWsad8695Ve6jNS8BscoKhHsxwEfCxwM2ceTsh3y5mi3Ll+ZH/InZMPjVsXITc W2V2UYM3kEhaeHou9+RrlzTaTRvKZZ2b0OsmBQZSLlATnlnJfRgZXWUQeozIXciNHLjsTicN39G kF5vL5netSpm2+w== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Extract the message fragmentation logic from write_msg() into a dedicated send_msg_udp() function. This improves code readability and prepares for future enhancements. The new send_msg_udp() function handles splitting messages that exceed MAX_PRINT_CHUNK into smaller fragments and sending them sequentially. This function is placed before send_ext_msg_udp() to maintain a logical ordering of related functions. No functional changes - this is purely a refactoring commit. Reviewed-by: Petr Mladek Reviewed-by: Simon Horman Reviewed-by: John Ogness Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 82c232f9ede24..e37250bf495fa 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1876,12 +1876,24 @@ static void write_ext_msg(struct console *con, cons= t char *msg, spin_unlock_irqrestore(&target_list_lock, flags); } =20 +static void send_msg_udp(struct netconsole_target *nt, const char *msg, + unsigned int len) +{ + const char *tmp =3D msg; + int frag, left =3D len; + + while (left > 0) { + frag =3D min(left, MAX_PRINT_CHUNK); + send_udp(nt, tmp, frag); + tmp +=3D frag; + left -=3D frag; + } +} + static void write_msg(struct console *con, const char *msg, unsigned int l= en) { - int frag, left; unsigned long flags; struct netconsole_target *nt; - const char *tmp; =20 if (oops_only && !oops_in_progress) return; @@ -1899,13 +1911,7 @@ static void write_msg(struct console *con, const cha= r *msg, unsigned int len) * at least one target if we die inside here, instead * of unnecessarily keeping all targets in lock-step. */ - tmp =3D msg; - for (left =3D len; left;) { - frag =3D min(left, MAX_PRINT_CHUNK); - send_udp(nt, tmp, frag); - tmp +=3D frag; - left -=3D frag; - } + send_msg_udp(nt, msg, len); } } spin_unlock_irqrestore(&target_list_lock, flags); --=20 2.47.3 From nobody Sat Feb 7 18:28:39 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 60A303D646B; Fri, 6 Feb 2026 12:50:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770382235; cv=none; b=LfTo+44q26vFKb/hCxQvGcCiZr5piNelwrsBX6d4ImkFTXIkfhxB1yBXMS1EMnnVbT/eJun27OoAc+Sj/mUqzNEBFCJxUQi9dWr6oqpsDWlbhMMs0ln1hKmhuhTQvqtQewatVXUrPizn7uKJ8uKFw7rz4pIhEG8z6oJO2Mt5wTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770382235; c=relaxed/simple; bh=LqN9na1qd1i+ro0yk4N3s39b6Cz9o+HafVLFwLUiQMc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fl4seVTJxDdBSFH9k9/4nwniewAoWmg0q6gAeUaVEsJTM5oyJPBkWnYiYmHE10Sr8swMTFCOHg8ToNFMRifp2qGQGgvnDtacn4Lxu31+8oNWORarb9FKyovHGO8hNV4+YAvvHUSJZ3RwMqeNv2ZnWzA1BX4j//X6WZKnPTqWns4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=On5zbwfN; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="On5zbwfN" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=YB9D715bAwbjNab2XlaCMy48nfwohP5BzppeRgyMIQw=; b=On5zbwfNC4wumEsQBTkRyQf+el 1lxUZ7WGr5rmr6tgQkmNAx7atRDGhDOj2KiSJcvw+m/HPezXWiClPAnZZf6BsxrRSA1dwFZC1d6qo eMYwrwpXl5l9wS4d2+kEjO95NGPHnPf+IroT/o1lodUYItCCTWlXlKf8Ln9ZEUqmO+xEEdZpMQyb9 wpsKLYDVZR+95BJRzpCzwp/wwoJH+lCb9kbZp7yEoEbWL+G31xplwfy1+rxnibgXEasm8f+DNhixw hZYgF/O3Kf0GVLUojX3MdWEVh/Kil87dYgGIL6E5mk8EkU7lV6BUJNTwrGc3BSk+XqM+kPkOpP5yB BtKDSKLA==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1voLI3-007Acp-92; Fri, 06 Feb 2026 12:50:27 +0000 From: Breno Leitao Date: Fri, 06 Feb 2026 04:45:31 -0800 Subject: [PATCH net-next v7 3/4] netconsole: convert to NBCON console infrastructure Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260206-nbcon-v7-3-62bda69b1b41@debian.org> References: <20260206-nbcon-v7-0-62bda69b1b41@debian.org> In-Reply-To: <20260206-nbcon-v7-0-62bda69b1b41@debian.org> To: Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , pmladek@suse.com, john.ogness@linutronix.de Cc: Greg Kroah-Hartman , Steven Rostedt , Sergey Senozhatsky , Andrew Morton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, asantostc@gmail.com, efault@gmx.de, gustavold@gmail.com, calvin@wbinvd.org, jv@jvosburgh.net, mpdesouza@suse.com, kernel-team@meta.com X-Mailer: b4 0.15-dev-f4305 X-Developer-Signature: v=1; a=openpgp-sha256; l=5682; i=leitao@debian.org; h=from:subject:message-id; bh=LqN9na1qd1i+ro0yk4N3s39b6Cz9o+HafVLFwLUiQMc=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpheN8RcRstgAjFITUfmQtS6Rfn25M49gcvgC1o EmlD+BaNDCJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaYXjfAAKCRA1o5Of/Hh3 bbN8D/4l2k+XpXaVclZzF1pDyFG+cDQWqpZHlcIB1eqfIIjNArME1b0jix5Mio3RpNRaWol/EuG NDMdyuG9Xg4xDVJIAp1QVFUCtyP6H71HvsfkN7KhjG1L1RKLtRFYpfstMjhf5UGexBrD6LvNp0I Vg/8pdqqUdbPx3cQhEE7tdAgYvbbMvaS97gxGTzV/42YH1NBOXNFeU8BN5glBvMSot2seKzmJo9 +F+LvqS2VMgnlM6lt7SyPG/d40uD/nVlb6+2EOvRYpoWhUwo9ytWLgGtpNhmLGa93BmtQMzqamw PsrYDnTkiMQDC+t2xt31kdgFMLH53a5k03qlKJSdbyUP5jiNunWi1h9zLtlPOwLno45Z3MUNHUS +pI+MTDLYLIel+gZ0AyeK9W1+BuCjXu2Z+dLFOZo50xXs1btE6fm36wzs7DRJJST7WUPSEpHvyK NooCPkBSJVi5WMiLmEKY5hB6klTBOJEVifdPy4ejkKf+zmPRfBQi2ZGkPC81aNPtWyNYlO0jrO+ 2rycH0LRApMdAg1LMzbOEklKSgVrvB6F96lXOmW+zBd5CVoQ2UqPxNtOZL6MlrjZbkLc2CYPsGV rPqpaRpA5zOllJPEmcTS7pbiwfpAuEXohJ5giFedqo++KzedfNdcbMRxpEbYcvFEeX/xq4AxUBk jzpIHSRz9Uge6ag== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Convert netconsole from the legacy console API to the NBCON framework. NBCON provides threaded printing which unblocks printk()s and flushes in a thread, decoupling network TX from printk() when netconsole is in use. Since netconsole relies on the network stack which cannot safely operate from all atomic contexts, mark both consoles with CON_NBCON_ATOMIC_UNSAFE. (See discussion in [1]) CON_NBCON_ATOMIC_UNSAFE restricts write_atomic() usage to emergency scenarios (panic) where regular messages are sent in threaded mode. Implementation changes: - Unify write_ext_msg() and write_msg() into netconsole_write() - Add device_lock/device_unlock callbacks to manage target_list_lock - Use nbcon_enter_unsafe()/nbcon_exit_unsafe() around network operations. - If nbcon_enter_unsafe() fails, just return given netconsole lost the ownership of the console. - Set write_thread and write_atomic callbacks (both use same function) Link: https://lore.kernel.org/all/b2qps3uywhmjaym4mht2wpxul4yqtuuayeoq4iv4k= 3zf5wdgh3@tocu6c7mj4lt/ [1] Reviewed-by: John Ogness Reviewed-by: Petr Mladek Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 101 +++++++++++++++++++++++++++++--------------= ---- 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index e37250bf495fa..ec000f477c2a8 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1859,23 +1859,6 @@ static void send_ext_msg_udp(struct netconsole_targe= t *nt, const char *msg, sysdata_len); } =20 -static void write_ext_msg(struct console *con, const char *msg, - unsigned int len) -{ - struct netconsole_target *nt; - unsigned long flags; - - if ((oops_only && !oops_in_progress) || list_empty(&target_list)) - return; - - spin_lock_irqsave(&target_list_lock, flags); - list_for_each_entry(nt, &target_list, list) - if (nt->extended && nt->state =3D=3D STATE_ENABLED && - netif_running(nt->np.dev)) - send_ext_msg_udp(nt, msg, len); - spin_unlock_irqrestore(&target_list_lock, flags); -} - static void send_msg_udp(struct netconsole_target *nt, const char *msg, unsigned int len) { @@ -1890,30 +1873,64 @@ static void send_msg_udp(struct netconsole_target *= nt, const char *msg, } } =20 -static void write_msg(struct console *con, const char *msg, unsigned int l= en) +/** + * netconsole_write - Generic function to send a msg to all targets + * @wctxt: nbcon write context + * @extended: "true" for extended console mode + * + * Given an nbcon write context, send the message to the netconsole targets + */ +static void netconsole_write(struct nbcon_write_context *wctxt, bool exten= ded) { - unsigned long flags; struct netconsole_target *nt; =20 if (oops_only && !oops_in_progress) return; - /* Avoid taking lock and disabling interrupts unnecessarily */ - if (list_empty(&target_list)) - return; =20 - spin_lock_irqsave(&target_list_lock, flags); list_for_each_entry(nt, &target_list, list) { - if (!nt->extended && nt->state =3D=3D STATE_ENABLED && - netif_running(nt->np.dev)) { - /* - * We nest this inside the for-each-target loop above - * so that we're able to get as much logging out to - * at least one target if we die inside here, instead - * of unnecessarily keeping all targets in lock-step. - */ - send_msg_udp(nt, msg, len); - } + if (nt->extended !=3D extended || nt->state !=3D STATE_ENABLED || + !netif_running(nt->np.dev)) + continue; + + /* If nbcon_enter_unsafe() fails, just return given netconsole + * lost the ownership, and iterating over the targets will not + * be able to re-acquire. + */ + if (!nbcon_enter_unsafe(wctxt)) + return; + + if (extended) + send_ext_msg_udp(nt, wctxt->outbuf, wctxt->len); + else + send_msg_udp(nt, wctxt->outbuf, wctxt->len); + + nbcon_exit_unsafe(wctxt); } +} + +static void netconsole_write_ext(struct console *con __always_unused, + struct nbcon_write_context *wctxt) +{ + netconsole_write(wctxt, true); +} + +static void netconsole_write_basic(struct console *con __always_unused, + struct nbcon_write_context *wctxt) +{ + netconsole_write(wctxt, false); +} + +static void netconsole_device_lock(struct console *con __always_unused, + unsigned long *flags) +__acquires(&target_list_lock) +{ + spin_lock_irqsave(&target_list_lock, *flags); +} + +static void netconsole_device_unlock(struct console *con __always_unused, + unsigned long flags) +__releases(&target_list_lock) +{ spin_unlock_irqrestore(&target_list_lock, flags); } =20 @@ -2077,15 +2094,21 @@ static void free_param_target(struct netconsole_tar= get *nt) } =20 static struct console netconsole_ext =3D { - .name =3D "netcon_ext", - .flags =3D CON_ENABLED | CON_EXTENDED, - .write =3D write_ext_msg, + .name =3D "netcon_ext", + .flags =3D CON_ENABLED | CON_EXTENDED | CON_NBCON | CON_NBCON_ATOMIC_UNSA= FE, + .write_thread =3D netconsole_write_ext, + .write_atomic =3D netconsole_write_ext, + .device_lock =3D netconsole_device_lock, + .device_unlock =3D netconsole_device_unlock, }; =20 static struct console netconsole =3D { - .name =3D "netcon", - .flags =3D CON_ENABLED, - .write =3D write_msg, + .name =3D "netcon", + .flags =3D CON_ENABLED | CON_NBCON | CON_NBCON_ATOMIC_UNSAFE, + .write_thread =3D netconsole_write_basic, + .write_atomic =3D netconsole_write_basic, + .device_lock =3D netconsole_device_lock, + .device_unlock =3D netconsole_device_unlock, }; =20 static int __init init_netconsole(void) --=20 2.47.3 From nobody Sat Feb 7 18:28:39 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 E670C35BDDE; Fri, 6 Feb 2026 12:50:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770382241; cv=none; b=isgat5yY1X5UrRFQqZzexc0AZuzQYaj/sWNuUaDqoBUzWcwm2fF/VvWdCiCJFZmSw9ir1P9qvpXu8oEWw55ZbyVz5o+GKNoOljiByVOaZVUA0z8enKoHl8UBrsgjRhZg42MeBGi+EM2sYCN2ZjxtG5L/O4CNlRVkFRINtPzrMDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770382241; c=relaxed/simple; bh=OmeG44rKgyBKxyORuh8V0/p6i8lhDoFG7ZQ9oEafjoE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uezVSAW6M1v8+pQPCtHX4ychhL1dCRUKE9RAyALxDwHFL/cw9VFmN2PDqyeuuGC1kUQXCVbkXHL7m4MmQ4wVJovY8MTdiLmjR4QV9stZJnf7XgQnir/TIvvojOQUR0KiZJ+Bm/yD7OyWT0w+MFACtkjlm2/Nt6Ndo7Lm/xmG8JY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=Pd2l5PQP; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="Pd2l5PQP" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=NOP0zvwBDzRaeuaCcbKzyT5NMRYIeO5b3qJSQLlYOAE=; b=Pd2l5PQPr+DLIvf9CySP88MprJ 0ZpFLpeIUaqEYb8YxdFG6fXL2B9A0mLv1LoFXFu+G/8NEtdeyW2jemiZO0TvrAkJ4l7QCxi50YLQB 0C52SDIHhxbtpshWtoWYubegB7lLs17V1/AeigA5Mp+7PXks0aD+sNyvSeKZ1SnPFeTfqHwT9DNdB zCmbMuhp2YEhsBB00YWjN1R4en1pyeCJrokG4VOf37nWnQoYL0hKGFXbjiCW8tX+tuD8Lpl5+IkBa GsaXxG9L3+gnps92zIC/4j8B4qoAof3DcdjfcypOqAZNdv75FfHl2zB7avyv+7eaGAZtv6/UiPJRW h2jTZmHg==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1voLI8-007AdB-IP; Fri, 06 Feb 2026 12:50:32 +0000 From: Breno Leitao Date: Fri, 06 Feb 2026 04:45:32 -0800 Subject: [PATCH net-next v7 4/4] netconsole: Use printk context for CPU and task information Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260206-nbcon-v7-4-62bda69b1b41@debian.org> References: <20260206-nbcon-v7-0-62bda69b1b41@debian.org> In-Reply-To: <20260206-nbcon-v7-0-62bda69b1b41@debian.org> To: Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , pmladek@suse.com, john.ogness@linutronix.de Cc: Greg Kroah-Hartman , Steven Rostedt , Sergey Senozhatsky , Andrew Morton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, asantostc@gmail.com, efault@gmx.de, gustavold@gmail.com, calvin@wbinvd.org, jv@jvosburgh.net, mpdesouza@suse.com, kernel-team@meta.com X-Mailer: b4 0.15-dev-f4305 X-Developer-Signature: v=1; a=openpgp-sha256; l=4958; i=leitao@debian.org; h=from:subject:message-id; bh=OmeG44rKgyBKxyORuh8V0/p6i8lhDoFG7ZQ9oEafjoE=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpheN8tzCk6dq7Hu4fNvIPZJtSDTh6GpqzNwf0b qrg91yvR9+JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaYXjfAAKCRA1o5Of/Hh3 bRHQEACjfdZ7jsWY4c5w5ouj0bILGcOc734My4XF1hLXkx1DRlkbj7lhfCvtwvGuvzOk8jGRBSe 2ggOs8pIKe+kWtTrJBh6sW344kEBAG2BO1IiT66v0MM8VKRtOcIWHU6NJNibLs+YDun4w1HQz7V v4TqHNRUDslcUTfYKdyOx0qe8TC5A6FSqNuPw//+PZmiSmsBEJGWMumM9Jc++iGe2e9gymbIahj eCRZoS+zog+fvMI3+hyK5tL5KG95SeRAF14VvHj5WWiwoLhXf4trpbHjdOFJz2RQE6nJeJ3Kaw3 81Z4JHsRohwMjtMtEyW0ZTe5ct8QzWjAvSDTJ3B9unpdtNhEVZNvI6QlT2FHKJpf5mhxP/1UUaV flfTAUxXdSkCV1uH2bjxyGjsR4F51TOPNVS7l/JhbrMpsLO4XkeJFObMPE3Xp4zibmVbSaOeP3x YWL4j/7EOGNVHqvMR34ka9PH6GzWm8h2QLQqIwTx1C0mjl0J2g98OWN6KIab7rF491/X6jACGCr j+06KuuEqc+YAWQZJyADHRte9poBfP8y1FMPdXoJrqgs3Qwo8LfzQyvRwVro836kw2gCeUVtH60 0MnTv6juXTpstZG4D/KuR8yOtdi9WqfuSCUFuXjs9Zp1bVoWBzgCuTHytkm8E6LMZWuldMUEWl6 JkpoHGQrU9HyT+w== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Use the CPU and task name captured at printk() time from nbcon_write_context instead of querying the current execution context. This provides accurate information about where the message originated, rather than where netconsole happens to be running. For CPU, use wctxt->cpu instead of raw_smp_processor_id(). For taskname, use wctxt->comm directly which contains the task name captured at printk time. This change ensures netconsole outputs reflect the actual context that generated the log message, which is especially important when the console driver runs asynchronously in a dedicated thread. Reviewed-by: John Ogness Reviewed-by: Petr Mladek Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index ec000f477c2a8..0f44ce5ccc0ab 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1490,18 +1490,20 @@ static void populate_configfs_item(struct netconsol= e_target *nt, init_target_config_group(nt, target_name); } =20 -static int sysdata_append_cpu_nr(struct netconsole_target *nt, int offset) +static int sysdata_append_cpu_nr(struct netconsole_target *nt, int offset, + struct nbcon_write_context *wctxt) { return scnprintf(&nt->sysdata[offset], MAX_EXTRADATA_ENTRY_LEN, " cpu=3D%u\n", - raw_smp_processor_id()); + wctxt->cpu); } =20 -static int sysdata_append_taskname(struct netconsole_target *nt, int offse= t) +static int sysdata_append_taskname(struct netconsole_target *nt, int offse= t, + struct nbcon_write_context *wctxt) { return scnprintf(&nt->sysdata[offset], MAX_EXTRADATA_ENTRY_LEN, " taskname=3D%s\n", - current->comm); + wctxt->comm); } =20 static int sysdata_append_release(struct netconsole_target *nt, int offset) @@ -1522,8 +1524,10 @@ static int sysdata_append_msgid(struct netconsole_ta= rget *nt, int offset) /* * prepare_sysdata - append sysdata in runtime * @nt: target to send message to + * @wctxt: nbcon write context containing message metadata */ -static int prepare_sysdata(struct netconsole_target *nt) +static int prepare_sysdata(struct netconsole_target *nt, + struct nbcon_write_context *wctxt) { int sysdata_len =3D 0; =20 @@ -1531,9 +1535,9 @@ static int prepare_sysdata(struct netconsole_target *= nt) goto out; =20 if (nt->sysdata_fields & SYSDATA_CPU_NR) - sysdata_len +=3D sysdata_append_cpu_nr(nt, sysdata_len); + sysdata_len +=3D sysdata_append_cpu_nr(nt, sysdata_len, wctxt); if (nt->sysdata_fields & SYSDATA_TASKNAME) - sysdata_len +=3D sysdata_append_taskname(nt, sysdata_len); + sysdata_len +=3D sysdata_append_taskname(nt, sysdata_len, wctxt); if (nt->sysdata_fields & SYSDATA_RELEASE) sysdata_len +=3D sysdata_append_release(nt, sysdata_len); if (nt->sysdata_fields & SYSDATA_MSGID) @@ -1831,31 +1835,33 @@ static void send_msg_fragmented(struct netconsole_t= arget *nt, /** * send_ext_msg_udp - send extended log message to target * @nt: target to send message to - * @msg: extended log message to send - * @msg_len: length of message + * @wctxt: nbcon write context containing message and metadata * - * Transfer extended log @msg to @nt. If @msg is longer than + * Transfer extended log message to @nt. If message is longer than * MAX_PRINT_CHUNK, it'll be split and transmitted in multiple chunks with * ncfrag header field added to identify them. */ -static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, - int msg_len) +static void send_ext_msg_udp(struct netconsole_target *nt, + struct nbcon_write_context *wctxt) { int userdata_len =3D 0; int release_len =3D 0; int sysdata_len =3D 0; + int len; =20 #ifdef CONFIG_NETCONSOLE_DYNAMIC - sysdata_len =3D prepare_sysdata(nt); + sysdata_len =3D prepare_sysdata(nt, wctxt); userdata_len =3D nt->userdata_length; #endif if (nt->release) release_len =3D strlen(init_utsname()->release) + 1; =20 - if (msg_len + release_len + sysdata_len + userdata_len <=3D MAX_PRINT_CHU= NK) - return send_msg_no_fragmentation(nt, msg, msg_len, release_len); + len =3D wctxt->len + release_len + sysdata_len + userdata_len; + if (len <=3D MAX_PRINT_CHUNK) + return send_msg_no_fragmentation(nt, wctxt->outbuf, + wctxt->len, release_len); =20 - return send_msg_fragmented(nt, msg, msg_len, release_len, + return send_msg_fragmented(nt, wctxt->outbuf, wctxt->len, release_len, sysdata_len); } =20 @@ -1900,7 +1906,7 @@ static void netconsole_write(struct nbcon_write_conte= xt *wctxt, bool extended) return; =20 if (extended) - send_ext_msg_udp(nt, wctxt->outbuf, wctxt->len); + send_ext_msg_udp(nt, wctxt); else send_msg_udp(nt, wctxt->outbuf, wctxt->len); =20 --=20 2.47.3