From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Namhyung Kim <namhyung@kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2] perf tools: Avoid unaligned pointer operations
Date: Thu, 28 Nov 2024 09:59:51 -0500 [thread overview]
Message-ID: <d40c6d0e-3755-4cfa-bb9e-e2aa520edb0f@linux.intel.com> (raw)
In-Reply-To: <20241128010325.946897-1-namhyung@kernel.org>
On 2024-11-27 8:03 p.m., Namhyung Kim wrote:
> The sample data is 64-bit aligned basically but raw data starts with
> 32-bit length field and data follows. In perf_event__synthesize_sample
> it treats the sample data as a 64-bit array. And it needs some trick
> to update the raw data properly.
>
> But it seems some compilers are not happy with this and the program dies
> siliently. I found the sample parsing test failed without any messages
> on affected systems.
>
> Let's update the code to use a 32-bit pointer directly and make sure the
> result is 64-bit aligned again. No functional changes intended.
>
> Reviewed-by: Ian Rogers <irogers@google.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Thanks,
Kan
> ---
> v2) use '%' instead of '/' to check alignment
>
> tools/perf/util/synthetic-events.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> index a58444c4aed1f1ea..6923b0d5efede4a7 100644
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c
> @@ -1686,12 +1686,16 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo
> }
>
> if (type & PERF_SAMPLE_RAW) {
> - u.val32[0] = sample->raw_size;
> - *array = u.val64;
> - array = (void *)array + sizeof(u32);
> + u32 *array32 = (void *)array;
> +
> + *array32 = sample->raw_size;
> + array32++;
> +
> + memcpy(array32, sample->raw_data, sample->raw_size);
> + array = (void *)(array32 + (sample->raw_size / sizeof(u32)));
>
> - memcpy(array, sample->raw_data, sample->raw_size);
> - array = (void *)array + sample->raw_size;
> + /* make sure the array is 64-bit aligned */
> + BUG_ON(((long)array) % sizeof(u64));
> }
>
> if (type & PERF_SAMPLE_BRANCH_STACK) {
next prev parent reply other threads:[~2024-11-28 14:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-28 1:03 [PATCH v2] perf tools: Avoid unaligned pointer operations Namhyung Kim
2024-11-28 14:59 ` Liang, Kan [this message]
2024-12-13 20:57 ` Ian Rogers
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=d40c6d0e-3755-4cfa-bb9e-e2aa520edb0f@linux.intel.com \
--to=kan.liang@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.