public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Breno Leitao <leitao@debian.org>,
	Breno Leitao <leitao@debian.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	pmladek@suse.com
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	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
Subject: Re: [PATCH net-next v4 1/5] printk: Add execution context (task name/CPU) to printk_info
Date: Tue, 27 Jan 2026 21:49:25 +0106	[thread overview]
Message-ID: <87ldhi7pn6.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <20260123-nbcon-v4-1-46a5cf567926@debian.org>

On 2026-01-23, Breno Leitao <leitao@debian.org> wrote:
> diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
> index 32fc12e536752..391a58be0c5b3 100644
> --- a/kernel/printk/nbcon.c
> +++ b/kernel/printk/nbcon.c
> @@ -946,6 +946,19 @@ void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt)
>  }
>  EXPORT_SYMBOL_GPL(nbcon_reacquire_nobuf);
>  
> +#ifdef CONFIG_PRINTK_EXECUTION_CTX
> +static void wctxt_load_execution_ctx(struct nbcon_write_context *wctxt,
> +				     struct printk_message *pmsg)
> +{
> +	wctxt->cpu = pmsg->cpu;
> +	wctxt->pid = pmsg->pid;
> +	memcpy(wctxt->comm, pmsg->comm, TASK_COMM_LEN);

Perhaps using sizeof() instead?

	memcpy(wctxt->comm, pmsg->comm, sizeof(wctxt->comm));

And adding a static assert that the sizes match?

	static_assert(sizeof(wctxt->comm) == sizeof(pmsg->comm));

> +}

[...]

> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 1d765ad242b82..7daaa27705339 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2131,12 +2131,37 @@ static inline void printk_delay(int level)
>  	}
>  }
>  
> +#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 = info->caller_id;
> +	u32 caller_id2 = info->caller_id2;
> +
> +	return caller_id & CALLER_ID_MASK ? caller_id2 : caller_id;
> +}
> +
> +static int printk_info_get_cpu(const struct printk_info *info)
> +{
> +	return ((info->caller_id & CALLER_ID_MASK ?
> +		 info->caller_id : info->caller_id2) & ~CALLER_ID_MASK);
> +}

It is a bit odd that printk_info_get_pid() uses local variables and
printk_info_get_cpu() does not. I could understand if things evolve that
way over time, but it is odd to use the two different styles from the
beginning.

I would prefer the local variable variant. But mostly I would prefer
that they are the same style.

> +#endif
> +
>  /**
>   * printk_parse_prefix - Parse level and control flags.
>   *
> @@ -2213,6 +2238,27 @@ static u16 printk_sprint(char *text, u16 size, int facility,
>  	return text_len;
>  }
>  
> +#ifdef CONFIG_PRINTK_EXECUTION_CTX
> +static void printk_store_execution_ctx(struct printk_info *info)
> +{
> +	info->caller_id2 = 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 = printk_info_get_cpu(info);
> +	pmsg->pid = printk_info_get_pid(info);
> +	memcpy(pmsg->comm, info->comm, TASK_COMM_LEN);

Here I also suggest using sizeof() and static_assert():

	memcpy(pmsg->comm, info->comm, sizeof(pmsg->comm));
	static_assert(sizeof(pmsg->comm) == sizeof(info->comm));

John Ogness

  parent reply	other threads:[~2026-01-27 20:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-23 12:17 [PATCH net-next v4 0/5] net: netconsole: convert to NBCON console infrastructure Breno Leitao
2026-01-23 12:17 ` [PATCH net-next v4 1/5] printk: Add execution context (task name/CPU) to printk_info Breno Leitao
2026-01-27 14:58   ` Paolo Abeni
2026-01-27 20:43   ` John Ogness [this message]
2026-01-28 10:52     ` Breno Leitao
2026-01-23 12:17 ` [PATCH net-next v4 2/5] netconsole: extract message fragmentation into send_msg_udp() Breno Leitao
2026-01-23 12:17 ` [PATCH net-next v4 3/5] netconsole: convert to NBCON console infrastructure Breno Leitao
2026-01-23 12:17 ` [PATCH net-next v4 4/5] netconsole: Use printk context for CPU and task information Breno Leitao
2026-01-23 12:17 ` [PATCH net-next v4 5/5] netconsole: pass wctxt to send_msg_udp() for consistency Breno Leitao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ldhi7pn6.fsf@jogness.linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=akpm@linux-foundation.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=asantostc@gmail.com \
    --cc=calvin@wbinvd.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=efault@gmx.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavold@gmail.com \
    --cc=jv@jvosburgh.net \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpdesouza@suse.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox