linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Jason Xing <kerneljasonxing@gmail.com>
Cc: axboe@kernel.dk, rostedt@goodmis.org, mhiramat@kernel.org,
	mathieu.desnoyers@efficios.com, linux-kernel@vger.kernel.org,
	linux-block@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	Jason Xing <kernelxing@tencent.com>,
	Yushan Zhou <katrinzhou@tencent.com>
Subject: Re: [PATCH v1 2/5] relayfs: introduce dump of relayfs statistics function
Date: Mon, 12 May 2025 17:51:56 -0700	[thread overview]
Message-ID: <20250512175156.7d3d4db53d40c7a34c1f68d6@linux-foundation.org> (raw)
In-Reply-To: <20250512024935.64704-3-kerneljasonxing@gmail.com>

On Mon, 12 May 2025 10:49:32 +0800 Jason Xing <kerneljasonxing@gmail.com> wrote:

> From: Jason Xing <kernelxing@tencent.com>
> 
> In this version, only support dumping the counter for buffer full and
> implement the framework of how it works. Users MUST pass a valid @buf
> with a valid @len that is required to be larger than RELAY_DUMP_BUF_MAX_LEN
> to acquire which information indicated by @flags to dump.
> 
> RELAY_DUMP_BUF_MAX_LEN shows the maximum len of the buffer if users
> choose to dump all the values.
> 
> Users can use this buffer to do whatever they expect in their own kernel
> module, say, print to console/dmesg or write them into the relay buffer.
> 
> ...
>  
> +/**
> + *	relay_dump - dump statistics of the specified channel buffer
> + *	@chan: the channel
> + *	@buf: buf to store statistics
> + *	@len: len of buf to check
> + *	@flags: select particular information to dump
> + */
> +void relay_dump(struct rchan *chan, char *buf, int len, int flags)

`size_t' is probably a more appropriate type for `len'.

> +{
> +	unsigned int i, full_counter = 0;
> +	struct rchan_buf *rbuf;
> +	int offset = 0;
> +
> +	if (!chan || !buf || flags & ~RELAY_DUMP_MASK)
> +		return;
> +
> +	if (len < RELAY_DUMP_BUF_MAX_LEN)
> +		return;

So we left the memory at *buf uninitialized but failed to tell the
caller this.  The caller will then proceed to use uninitialized memory.

It's a programming error, so simply going BUG seems OK.

> +	if (chan->is_global) {
> +		rbuf = *per_cpu_ptr(chan->buf, 0);
> +		full_counter = rbuf->stats.full;
> +	} else {
> +		for_each_possible_cpu(i) {

I'm thinking that at this stage in the patch series, this should be
for_each_online_cpu(), then adjust that in patch [5/5].

> +			if ((rbuf = *per_cpu_ptr(chan->buf, i)))
> +				full_counter += rbuf->stats.full;
> +	}
> +
> +	if (flags & RELAY_DUMP_BUF_FULL)
> +		offset += snprintf(buf, sizeof(unsigned int), "%u", full_counter);

This seems strange.  sizeof(unsigned int) has nothing to do with the
number of characters which are consumed by expansion of "%u"?

> +
> +	snprintf(buf + offset, 1, "\n");
> +}
> +EXPORT_SYMBOL_GPL(relay_dump);
> +
>  /**
>   *	relay_file_open - open file op for relay files
>   *	@inode: the inode


  reply	other threads:[~2025-05-13  0:51 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12  2:49 [PATCH v1 0/5] relayfs: misc changes Jason Xing
2025-05-12  2:49 ` [PATCH v1 1/5] relayfs: support a counter tracking if per-cpu buffers is full Jason Xing
2025-05-13  0:51   ` Andrew Morton
2025-05-13  1:37     ` Jason Xing
2025-05-12  2:49 ` [PATCH v1 2/5] relayfs: introduce dump of relayfs statistics function Jason Xing
2025-05-13  0:51   ` Andrew Morton [this message]
2025-05-13  1:48     ` Jason Xing
2025-05-13  2:04       ` Andrew Morton
2025-05-13  2:26         ` Jason Xing
2025-05-13  3:41           ` Andrew Morton
2025-05-13  3:48             ` Jason Xing
2025-05-13  9:58   ` Masami Hiramatsu
2025-05-13 10:32     ` Jason Xing
2025-05-13 13:22       ` Masami Hiramatsu
2025-05-13 13:46         ` Jason Xing
2025-05-14  1:29           ` Masami Hiramatsu
2025-05-14  2:06             ` Jason Xing
2025-05-12  2:49 ` [PATCH v1 3/5] blktrace: use rbuf->stats.full as a drop indicator in relayfs Jason Xing
2025-05-12  2:49 ` [PATCH v1 4/5] relayfs: support a counter tracking if data is too big to write Jason Xing
2025-05-12  2:49 ` [PATCH v1 5/5] relayfs: uniformally use possible cpu iteration Jason Xing
2025-05-13  0:52   ` Andrew Morton
2025-05-13  2:03     ` Jason Xing
2025-05-13  3:21       ` Andrew Morton
2025-05-13  3:25         ` Jason Xing
2025-05-13  5:52     ` Jason Xing

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=20250512175156.7d3d4db53d40c7a34c1f68d6@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=katrinzhou@tencent.com \
    --cc=kerneljasonxing@gmail.com \
    --cc=kernelxing@tencent.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).