* [PATCH v1] perf arm-spe: Unaligned pointer work around
@ 2024-05-14 5:24 Ian Rogers
2024-05-14 15:39 ` Ian Rogers
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ian Rogers @ 2024-05-14 5:24 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Kan Liang, linux-perf-users,
linux-kernel
Use get_unaligned_leXX instead of leXX_to_cpu to handle unaligned
pointers. Such pointers occur with libFuzzer testing.
A similar change for intel-pt was done in:
https://lore.kernel.org/r/20231005190451.175568-6-adrian.hunter@intel.com
Signed-off-by: Ian Rogers <irogers@google.com>
---
.../arm-spe-decoder/arm-spe-pkt-decoder.c | 23 ++++---------------
1 file changed, 5 insertions(+), 18 deletions(-)
diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
index a454c6737563..7bf607d0f6d8 100644
--- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
+++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
@@ -10,24 +10,11 @@
#include <byteswap.h>
#include <linux/bitops.h>
#include <stdarg.h>
+#include <linux/kernel.h>
+#include <asm-generic/unaligned.h>
#include "arm-spe-pkt-decoder.h"
-#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-#define le16_to_cpu bswap_16
-#define le32_to_cpu bswap_32
-#define le64_to_cpu bswap_64
-#define memcpy_le64(d, s, n) do { \
- memcpy((d), (s), (n)); \
- *(d) = le64_to_cpu(*(d)); \
-} while (0)
-#else
-#define le16_to_cpu
-#define le32_to_cpu
-#define le64_to_cpu
-#define memcpy_le64 memcpy
-#endif
-
static const char * const arm_spe_packet_name[] = {
[ARM_SPE_PAD] = "PAD",
[ARM_SPE_END] = "END",
@@ -70,9 +57,9 @@ static int arm_spe_get_payload(const unsigned char *buf, size_t len,
switch (payload_len) {
case 1: packet->payload = *(uint8_t *)buf; break;
- case 2: packet->payload = le16_to_cpu(*(uint16_t *)buf); break;
- case 4: packet->payload = le32_to_cpu(*(uint32_t *)buf); break;
- case 8: packet->payload = le64_to_cpu(*(uint64_t *)buf); break;
+ case 2: packet->payload = get_unaligned_le16(buf); break;
+ case 4: packet->payload = get_unaligned_le32(buf); break;
+ case 8: packet->payload = get_unaligned_le64(buf); break;
default: return ARM_SPE_BAD_PACKET;
}
--
2.45.0.rc1.225.g2a3ae87e7f-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v1] perf arm-spe: Unaligned pointer work around
2024-05-14 5:24 [PATCH v1] perf arm-spe: Unaligned pointer work around Ian Rogers
@ 2024-05-14 15:39 ` Ian Rogers
2024-05-15 15:38 ` James Clark
2024-05-29 19:25 ` Namhyung Kim
2 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2024-05-14 15:39 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Kan Liang, linux-perf-users,
linux-kernel, Leo Yan, James Clark
On Mon, May 13, 2024 at 10:24 PM Ian Rogers <irogers@google.com> wrote:
>
> Use get_unaligned_leXX instead of leXX_to_cpu to handle unaligned
> pointers. Such pointers occur with libFuzzer testing.
>
> A similar change for intel-pt was done in:
> https://lore.kernel.org/r/20231005190451.175568-6-adrian.hunter@intel.com
>
> Signed-off-by: Ian Rogers <irogers@google.com>
+Leo Yan +James Clark surprisingly missed by get_maintainer.pl.
Thanks,
Ian
> ---
> .../arm-spe-decoder/arm-spe-pkt-decoder.c | 23 ++++---------------
> 1 file changed, 5 insertions(+), 18 deletions(-)
>
> diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> index a454c6737563..7bf607d0f6d8 100644
> --- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> +++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> @@ -10,24 +10,11 @@
> #include <byteswap.h>
> #include <linux/bitops.h>
> #include <stdarg.h>
> +#include <linux/kernel.h>
> +#include <asm-generic/unaligned.h>
>
> #include "arm-spe-pkt-decoder.h"
>
> -#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> -#define le16_to_cpu bswap_16
> -#define le32_to_cpu bswap_32
> -#define le64_to_cpu bswap_64
> -#define memcpy_le64(d, s, n) do { \
> - memcpy((d), (s), (n)); \
> - *(d) = le64_to_cpu(*(d)); \
> -} while (0)
> -#else
> -#define le16_to_cpu
> -#define le32_to_cpu
> -#define le64_to_cpu
> -#define memcpy_le64 memcpy
> -#endif
> -
> static const char * const arm_spe_packet_name[] = {
> [ARM_SPE_PAD] = "PAD",
> [ARM_SPE_END] = "END",
> @@ -70,9 +57,9 @@ static int arm_spe_get_payload(const unsigned char *buf, size_t len,
>
> switch (payload_len) {
> case 1: packet->payload = *(uint8_t *)buf; break;
> - case 2: packet->payload = le16_to_cpu(*(uint16_t *)buf); break;
> - case 4: packet->payload = le32_to_cpu(*(uint32_t *)buf); break;
> - case 8: packet->payload = le64_to_cpu(*(uint64_t *)buf); break;
> + case 2: packet->payload = get_unaligned_le16(buf); break;
> + case 4: packet->payload = get_unaligned_le32(buf); break;
> + case 8: packet->payload = get_unaligned_le64(buf); break;
> default: return ARM_SPE_BAD_PACKET;
> }
>
> --
> 2.45.0.rc1.225.g2a3ae87e7f-goog
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v1] perf arm-spe: Unaligned pointer work around
2024-05-14 5:24 [PATCH v1] perf arm-spe: Unaligned pointer work around Ian Rogers
2024-05-14 15:39 ` Ian Rogers
@ 2024-05-15 15:38 ` James Clark
2024-05-29 19:25 ` Namhyung Kim
2 siblings, 0 replies; 4+ messages in thread
From: James Clark @ 2024-05-15 15:38 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Adrian Hunter, Kan Liang, linux-perf-users, linux-kernel
On 14/05/2024 07:24, Ian Rogers wrote:
> Use get_unaligned_leXX instead of leXX_to_cpu to handle unaligned
> pointers. Such pointers occur with libFuzzer testing.
>
> A similar change for intel-pt was done in:
> https://lore.kernel.org/r/20231005190451.175568-6-adrian.hunter@intel.com
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
Reviewed-by: James Clark <james.clark@arm.com>
> .../arm-spe-decoder/arm-spe-pkt-decoder.c | 23 ++++---------------
> 1 file changed, 5 insertions(+), 18 deletions(-)
>
> diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> index a454c6737563..7bf607d0f6d8 100644
> --- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> +++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> @@ -10,24 +10,11 @@
> #include <byteswap.h>
> #include <linux/bitops.h>
> #include <stdarg.h>
> +#include <linux/kernel.h>
> +#include <asm-generic/unaligned.h>
>
> #include "arm-spe-pkt-decoder.h"
>
> -#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> -#define le16_to_cpu bswap_16
> -#define le32_to_cpu bswap_32
> -#define le64_to_cpu bswap_64
> -#define memcpy_le64(d, s, n) do { \
> - memcpy((d), (s), (n)); \
> - *(d) = le64_to_cpu(*(d)); \
> -} while (0)
> -#else
> -#define le16_to_cpu
> -#define le32_to_cpu
> -#define le64_to_cpu
> -#define memcpy_le64 memcpy
> -#endif
> -
> static const char * const arm_spe_packet_name[] = {
> [ARM_SPE_PAD] = "PAD",
> [ARM_SPE_END] = "END",
> @@ -70,9 +57,9 @@ static int arm_spe_get_payload(const unsigned char *buf, size_t len,
>
> switch (payload_len) {
> case 1: packet->payload = *(uint8_t *)buf; break;
> - case 2: packet->payload = le16_to_cpu(*(uint16_t *)buf); break;
> - case 4: packet->payload = le32_to_cpu(*(uint32_t *)buf); break;
> - case 8: packet->payload = le64_to_cpu(*(uint64_t *)buf); break;
> + case 2: packet->payload = get_unaligned_le16(buf); break;
> + case 4: packet->payload = get_unaligned_le32(buf); break;
> + case 8: packet->payload = get_unaligned_le64(buf); break;
> default: return ARM_SPE_BAD_PACKET;
> }
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v1] perf arm-spe: Unaligned pointer work around
2024-05-14 5:24 [PATCH v1] perf arm-spe: Unaligned pointer work around Ian Rogers
2024-05-14 15:39 ` Ian Rogers
2024-05-15 15:38 ` James Clark
@ 2024-05-29 19:25 ` Namhyung Kim
2 siblings, 0 replies; 4+ messages in thread
From: Namhyung Kim @ 2024-05-29 19:25 UTC (permalink / raw)
To: linux-kernel, Alexander Shishkin, Ian Rogers, Mark Rutland,
Peter Zijlstra, Jiri Olsa, Arnaldo Carvalho de Melo,
linux-perf-users, Adrian Hunter, Ingo Molnar, Kan Liang
On Mon, 13 May 2024 22:24:02 -0700, Ian Rogers wrote:
> Use get_unaligned_leXX instead of leXX_to_cpu to handle unaligned
> pointers. Such pointers occur with libFuzzer testing.
>
> A similar change for intel-pt was done in:
> https://lore.kernel.org/r/20231005190451.175568-6-adrian.hunter@intel.com
>
>
> [...]
Applied to perf-tools-next, thanks!
Best regards,
--
Namhyung Kim <namhyung@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-29 19:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-14 5:24 [PATCH v1] perf arm-spe: Unaligned pointer work around Ian Rogers
2024-05-14 15:39 ` Ian Rogers
2024-05-15 15:38 ` James Clark
2024-05-29 19:25 ` Namhyung Kim
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).