[PATCH net-next 3/5] netconsole: append msgid to sysdata

Gustavo Luiz Duarte posted 5 patches 4 months ago
There is a newer version of this series
[PATCH net-next 3/5] netconsole: append msgid to sysdata
Posted by Gustavo Luiz Duarte 4 months ago
Add msgcounter to the netconsole_target struct to generate message IDs.
If the msgid_enabled attribute is true, increment msgcounter and append
msgid=<msgcounter> to sysdata buffer before sending the message.

Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
---
 drivers/net/netconsole.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 813f50abaf9f..34b61e299eeb 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -155,6 +155,8 @@ struct netconsole_target {
 	size_t			userdata_length;
 	/* bit-wise with sysdata_feature bits */
 	u32			sysdata_fields;
+	/* protected by target_list_lock */
+	u32			msgcounter;
 #endif
 	struct netconsole_target_stats stats;
 	bool			enabled;
@@ -1345,13 +1347,21 @@ static int sysdata_append_release(struct netconsole_target *nt, int offset)
 			 init_utsname()->release);
 }
 
+static int sysdata_append_msgid(struct netconsole_target *nt, int offset)
+{
+	nt->msgcounter++;
+	return scnprintf(&nt->extradata_complete[offset],
+			 MAX_EXTRADATA_ENTRY_LEN, " msgid=%u\n",
+			 nt->msgcounter);
+}
+
 /*
  * prepare_extradata - append sysdata at extradata_complete in runtime
  * @nt: target to send message to
  */
 static int prepare_extradata(struct netconsole_target *nt)
 {
-	u32 fields = SYSDATA_CPU_NR | SYSDATA_TASKNAME;
+	u32 fields = SYSDATA_CPU_NR | SYSDATA_TASKNAME | SYSDATA_MSGID;
 	int extradata_len;
 
 	/* userdata was appended when configfs write helper was called
@@ -1368,6 +1378,8 @@ static int prepare_extradata(struct netconsole_target *nt)
 		extradata_len += sysdata_append_taskname(nt, extradata_len);
 	if (nt->sysdata_fields & SYSDATA_RELEASE)
 		extradata_len += sysdata_append_release(nt, extradata_len);
+	if (nt->sysdata_fields & SYSDATA_MSGID)
+		extradata_len += sysdata_append_msgid(nt, extradata_len);
 
 	WARN_ON_ONCE(extradata_len >
 		     MAX_EXTRADATA_ENTRY_LEN * MAX_EXTRADATA_ITEMS);

-- 
2.47.1
Re: [PATCH net-next 3/5] netconsole: append msgid to sysdata
Posted by Breno Leitao 4 months ago
On Wed, Jun 11, 2025 at 07:36:05AM -0700, Gustavo Luiz Duarte wrote:
> Add msgcounter to the netconsole_target struct to generate message IDs.
> If the msgid_enabled attribute is true, increment msgcounter and append
> msgid=<msgcounter> to sysdata buffer before sending the message.
> 
> Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
> ---
>  drivers/net/netconsole.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index 813f50abaf9f..34b61e299eeb 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -155,6 +155,8 @@ struct netconsole_target {
>  	size_t			userdata_length;
>  	/* bit-wise with sysdata_feature bits */
>  	u32			sysdata_fields;
> +	/* protected by target_list_lock */
> +	u32			msgcounter;
>  #endif
>  	struct netconsole_target_stats stats;
>  	bool			enabled;
> @@ -1345,13 +1347,21 @@ static int sysdata_append_release(struct netconsole_target *nt, int offset)
>  			 init_utsname()->release);
>  }
>  
> +static int sysdata_append_msgid(struct netconsole_target *nt, int offset)
> +{
> +	nt->msgcounter++;

This will eventually wrap. I am wondering if you should use the
overflow.h helpers to avoid warnings in UBSAN and friends.

Quick glanced over that filed, I found:

	/**
	* wrapping_add() - Intentionally perform a wrapping addition
	* @type: type for result of calculation
	* @a: first addend
	* @b: second addend
	*
	* Return the potentially wrapped-around addition without
	* tripping any wrap-around sanitizers that may be enabled.
	*/

> +	return scnprintf(&nt->extradata_complete[offset],
> +			 MAX_EXTRADATA_ENTRY_LEN, " msgid=%u\n",
> +			 nt->msgcounter);
> +}
> +
>  /*
>   * prepare_extradata - append sysdata at extradata_complete in runtime
>   * @nt: target to send message to
>   */
>  static int prepare_extradata(struct netconsole_target *nt)
>  {
> -	u32 fields = SYSDATA_CPU_NR | SYSDATA_TASKNAME;
> +	u32 fields = SYSDATA_CPU_NR | SYSDATA_TASKNAME | SYSDATA_MSGID;

This might be gone now, according to your last patch.,

LGTM.
Re: [PATCH net-next 3/5] netconsole: append msgid to sysdata
Posted by Gustavo Luiz Duarte 4 months ago
On Wed, Jun 11, 2025 at 4:30 PM Breno Leitao <leitao@debian.org> wrote:
>
> On Wed, Jun 11, 2025 at 07:36:05AM -0700, Gustavo Luiz Duarte wrote:
> > Add msgcounter to the netconsole_target struct to generate message IDs.
> > If the msgid_enabled attribute is true, increment msgcounter and append
> > msgid=<msgcounter> to sysdata buffer before sending the message.
> >
> > Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
> > ---
> >  drivers/net/netconsole.c | 14 +++++++++++++-
> >  1 file changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> > index 813f50abaf9f..34b61e299eeb 100644
> > --- a/drivers/net/netconsole.c
> > +++ b/drivers/net/netconsole.c
> > @@ -155,6 +155,8 @@ struct netconsole_target {
> >       size_t                  userdata_length;
> >       /* bit-wise with sysdata_feature bits */
> >       u32                     sysdata_fields;
> > +     /* protected by target_list_lock */
> > +     u32                     msgcounter;
> >  #endif
> >       struct netconsole_target_stats stats;
> >       bool                    enabled;
> > @@ -1345,13 +1347,21 @@ static int sysdata_append_release(struct netconsole_target *nt, int offset)
> >                        init_utsname()->release);
> >  }
> >
> > +static int sysdata_append_msgid(struct netconsole_target *nt, int offset)
> > +{
> > +     nt->msgcounter++;
>
> This will eventually wrap. I am wondering if you should use the
> overflow.h helpers to avoid warnings in UBSAN and friends.

Good point. I will send v2 using one of the overflow safe macros.
Thanks for reviewing!

>
> Quick glanced over that filed, I found:
>
>         /**
>         * wrapping_add() - Intentionally perform a wrapping addition
>         * @type: type for result of calculation
>         * @a: first addend
>         * @b: second addend
>         *
>         * Return the potentially wrapped-around addition without
>         * tripping any wrap-around sanitizers that may be enabled.
>         */
>
> > +     return scnprintf(&nt->extradata_complete[offset],
> > +                      MAX_EXTRADATA_ENTRY_LEN, " msgid=%u\n",
> > +                      nt->msgcounter);
> > +}
> > +
> >  /*
> >   * prepare_extradata - append sysdata at extradata_complete in runtime
> >   * @nt: target to send message to
> >   */
> >  static int prepare_extradata(struct netconsole_target *nt)
> >  {
> > -     u32 fields = SYSDATA_CPU_NR | SYSDATA_TASKNAME;
> > +     u32 fields = SYSDATA_CPU_NR | SYSDATA_TASKNAME | SYSDATA_MSGID;
>
> This might be gone now, according to your last patch.,
>
> LGTM.
Re: [PATCH net-next 3/5] netconsole: append msgid to sysdata
Posted by Jakub Kicinski 4 months ago
On Wed, 11 Jun 2025 08:30:11 -0700 Breno Leitao wrote:
> >  static int prepare_extradata(struct netconsole_target *nt)
> >  {
> > -	u32 fields = SYSDATA_CPU_NR | SYSDATA_TASKNAME;
> > +	u32 fields = SYSDATA_CPU_NR | SYSDATA_TASKNAME | SYSDATA_MSGID;  
> 
> This might be gone now, according to your last patch.,

Right, please wait until tomorrow afternoon (Pacific Time), then rebase
and repost. We will merge the net tree into net-next after we send the
pending fixes to Linus. Otherwise by the time we try to merge this it
will no longer apply..