From nobody Sat Jan 3 02:07:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71FF0E92729 for ; Thu, 5 Oct 2023 19:06:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230081AbjJETGh (ORCPT ); Thu, 5 Oct 2023 15:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229939AbjJETGf (ORCPT ); Thu, 5 Oct 2023 15:06:35 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B644FEA; Thu, 5 Oct 2023 12:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696532794; x=1728068794; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dx4bgn3zzTZ9xOLzFW1eBj7lM2vIsla8X5xiYClbPKg=; b=GcXzKhMsdO3FDl35O3GpDpY1GlBXi2Bl2Rl1Mh9wUIB9hAsgBxOJbRHi 0nRfqICQ/fOKoxdu4iwEQFfe6dQ0CY9pM9xSZSqANgUsamLIuFhrT2mbv LsPvTb3PngKBOMLxKhuSDPbIGVQC+gQBIIVlOBBRa7JOf3i6DV1jdKpf0 VmUfeBbtb+sagL+uwE66C/FfmUI+jVNIzfGEmWP1s1Cjz+5OIqETm8XDg 5WXGt1uYDYxc8kK3sS9CvwEuF/1+kxUbCIY9pBgFcnXZwUTj20RRZDGYG pqqnwl/IZmA6JpjQyPF3LwWQ70tnbBL9t6paqFGP3RkQqIBntMzUqlT86 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="383488228" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="383488228" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:05:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="999055088" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="999055088" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.249.35.8]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:05:10 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH 1/5] perf tools: Add get_unaligned_leNN() Date: Thu, 5 Oct 2023 22:04:47 +0300 Message-Id: <20231005190451.175568-2-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231005190451.175568-1-adrian.hunter@intel.com> References: <20231005190451.175568-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same as include/asm-generic/unaligned.h. Use diagnostic pragmas to ignore -Wpacked used by perf build. Signed-off-by: Adrian Hunter Suggested-by, ok? --- tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-gene= ric/unaligned.h index 47387c607035..9140bb4e16c6 100644 --- a/tools/include/asm-generic/unaligned.h +++ b/tools/include/asm-generic/unaligned.h @@ -6,6 +6,9 @@ #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H =20 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpacked" + #define __get_unaligned_t(type, ptr) ({ \ const struct { type x; } __packed *__pptr =3D (typeof(__pptr))(ptr); \ __pptr->x; \ @@ -19,5 +22,22 @@ #define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr)) #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (= ptr)) =20 +static inline u16 get_unaligned_le16(const void *p) +{ + return le16_to_cpu(__get_unaligned_t(__le16, p)); +} + +static inline u32 get_unaligned_le32(const void *p) +{ + return le32_to_cpu(__get_unaligned_t(__le32, p)); +} + +static inline u64 get_unaligned_le64(const void *p) +{ + return le64_to_cpu(__get_unaligned_t(__le64, p)); +} + +#pragma GCC diagnostic pop + #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */ =20 --=20 2.34.1 From nobody Sat Jan 3 02:07:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC818E92728 for ; Thu, 5 Oct 2023 19:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230442AbjJETGl (ORCPT ); Thu, 5 Oct 2023 15:06:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229781AbjJETGg (ORCPT ); Thu, 5 Oct 2023 15:06:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D88AEEB; Thu, 5 Oct 2023 12:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696532794; x=1728068794; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/M0BXFayBhHOB8YBHRkLZxRHjkjjHcYFaqoHoxPtxBQ=; b=J+r21PKZg31aA1D3j2yjmnf2dI5vC479k4oUjpSD4XIf/QaeySprDkfX nE1CWAcuk0BDBOK3T7XQmpBJyVLK1yb462D07g0Pef8BvhBdbcsHsczkJ BhSpUkJs4O5r7PxxGVPvG+kLvBg/V61LPiZAiZOgJKPW2yxKoCgI4iCdC ELdoAWjOEc1mDz1afz9812v5AIP6lwv7bJdRX+lyJltarEg9dOy6ycxDA /3Uup9+Y57fSr0BDIgRrr6DwQJm3YISXR0/EvjhzQnGT9dfiEtQaACwQP qm5kkfpwfSu/wRo3r8ZfNkO5om/PgfP6uznx42/anIdi6T3umfEpvrbE/ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="383488235" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="383488235" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:05:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="999055112" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="999055112" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.249.35.8]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:05:12 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH 2/5] perf intel-pt: Simplify intel_pt_get_vmcs() Date: Thu, 5 Oct 2023 22:04:48 +0300 Message-Id: <20231005190451.175568-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231005190451.175568-1-adrian.hunter@intel.com> References: <20231005190451.175568-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Simplify and remove unnecessary constant expressions. Signed-off-by: Adrian Hunter --- .../util/intel-pt-decoder/intel-pt-pkt-decoder.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tool= s/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c index af9710622a1f..249610cc9284 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c @@ -131,19 +131,14 @@ static int intel_pt_get_cbr(const unsigned char *buf,= size_t len, static int intel_pt_get_vmcs(const unsigned char *buf, size_t len, struct intel_pt_pkt *packet) { - unsigned int count =3D (52 - 5) >> 3; - - if (count < 1 || count > 7) - return INTEL_PT_BAD_PACKET; - - if (len < count + 2) + if (len < 7) return INTEL_PT_NEED_MORE_BYTES; =20 packet->type =3D INTEL_PT_VMCS; - packet->count =3D count; - memcpy_le64(&packet->payload, buf + 2, count); + packet->count =3D 5; + memcpy_le64(&packet->payload, buf + 2, 5); =20 - return count + 2; + return 7; } =20 static int intel_pt_get_ovf(struct intel_pt_pkt *packet) --=20 2.34.1 From nobody Sat Jan 3 02:07:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27A40E92728 for ; Thu, 5 Oct 2023 19:06:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230406AbjJETGt (ORCPT ); Thu, 5 Oct 2023 15:06:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbjJETGh (ORCPT ); Thu, 5 Oct 2023 15:06:37 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6F4ADB; Thu, 5 Oct 2023 12:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696532795; x=1728068795; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qtF8zRHNP255BfSQ+DVT/RKn8FRUesePocVsXbPofQc=; b=QoDHwYG6p4azHfsI7MeXDqAdWFsA3Udnh6EirWfssBMDUrb8gibTBdoq 1dEIgG09RlWEhPDSH7L/Hf21lNulqJ1h0wGQ1TlgjOL6xV1lhtmBg81li VRpRQ96KlHavBd0GpFbz+iwQrQOH9nT1GMiQB/HX4l8gxvapibMWqTL4R QgME3JYQ06IWBtpIRAcZZ1v6ADTaPjovX3jIUn47SdximacJzsPdbdbPw 8DBPtj81V6Y7I/3WQCtKhSI18bkyQ1Ux9YC53uja/s0JLNV/LPnpDgf7I GnjKuK65IJ6XKafTqDjzpGvhm81qhI20vwgbDjO5JbYS0fPFpwSNNgCtO Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="383488244" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="383488244" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:05:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="999055151" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="999055151" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.249.35.8]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:05:14 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH 3/5] perf intel-pt: Use existing definitions of le16_to_cpu() etc Date: Thu, 5 Oct 2023 22:04:49 +0300 Message-Id: <20231005190451.175568-4-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231005190451.175568-1-adrian.hunter@intel.com> References: <20231005190451.175568-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use definitions from tools/include/linux/kernel.h Signed-off-by: Adrian Hunter --- tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tool= s/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c index 249610cc9284..ffd0d647473c 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c @@ -8,6 +8,7 @@ #include #include #include +#include #include =20 #include "intel-pt-pkt-decoder.h" @@ -17,17 +18,11 @@ #define BIT63 ((uint64_t)1 << 63) =20 #if __BYTE_ORDER__ =3D=3D __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) =3D le64_to_cpu(*(d)); \ } while (0) #else -#define le16_to_cpu -#define le32_to_cpu -#define le64_to_cpu #define memcpy_le64 memcpy #endif =20 --=20 2.34.1 From nobody Sat Jan 3 02:07:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EE11E92728 for ; Thu, 5 Oct 2023 19:06:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231156AbjJETGp (ORCPT ); Thu, 5 Oct 2023 15:06:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230112AbjJETGh (ORCPT ); Thu, 5 Oct 2023 15:06:37 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE64DDE; Thu, 5 Oct 2023 12:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696532795; x=1728068795; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U76zY0O5kmHJh4OzAqNOSoPGSwZlGkT5ypjB3gSNylc=; b=l2p0CPXi33NIXnsbOBW8NrUe9MlJhYAT5TAL6uYZUDOvFyrTAx3iS5iE EVlNVBV8KtXc0jRKCBrFolm8o+wJyH36I0BllWgwNvrzmJQ7CNWZTNI/m X5eLJdwh+aozs+RRMste/j0URZLmtZTkEqiMNHCVkHzsxcbJjvqpCXZhG GNT/1xdqRBeXopiMTa+RZWNQHwiRXxQh6vPTiI5IidhqByaShpVZc2psi 4YtCZO8jWI58LTVYN6sPVtynbHlkecnhrAPCzE4uxy5lNf/DIlOecI0MK N5xeclbU61KyPFol5kGL6ZnG04xCtWvClRAdR6YB+rQNGfTAZJsIqfZqD g==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="383488254" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="383488254" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:05:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="999055177" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="999055177" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.249.35.8]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:05:16 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH 4/5] perf intel-pt: Use get_unaligned_le16() etc Date: Thu, 5 Oct 2023 22:04:50 +0300 Message-Id: <20231005190451.175568-5-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231005190451.175568-1-adrian.hunter@intel.com> References: <20231005190451.175568-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Avoid unaligned access by using get_unaligned_le16(), get_unaligned_le32() and get_unaligned_le64(). Signed-off-by: Adrian Hunter --- .../intel-pt-decoder/intel-pt-pkt-decoder.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tool= s/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c index ffd0d647473c..7a90218aecb1 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 #include "intel-pt-pkt-decoder.h" =20 @@ -78,7 +79,7 @@ static int intel_pt_get_long_tnt(const unsigned char *buf= , size_t len, if (len < 8) return INTEL_PT_NEED_MORE_BYTES; =20 - payload =3D le64_to_cpu(*(uint64_t *)buf); + payload =3D get_unaligned_le64(buf); =20 for (count =3D 47; count; count--) { if (payload & BIT63) @@ -119,7 +120,7 @@ static int intel_pt_get_cbr(const unsigned char *buf, s= ize_t len, if (len < 4) return INTEL_PT_NEED_MORE_BYTES; packet->type =3D INTEL_PT_CBR; - packet->payload =3D le16_to_cpu(*(uint16_t *)(buf + 2)); + packet->payload =3D get_unaligned_le16(buf + 2); return 4; } =20 @@ -218,12 +219,12 @@ static int intel_pt_get_ptwrite(const unsigned char *= buf, size_t len, case 0: if (len < 6) return INTEL_PT_NEED_MORE_BYTES; - packet->payload =3D le32_to_cpu(*(uint32_t *)(buf + 2)); + packet->payload =3D get_unaligned_le32(buf + 2); return 6; case 1: if (len < 10) return INTEL_PT_NEED_MORE_BYTES; - packet->payload =3D le64_to_cpu(*(uint64_t *)(buf + 2)); + packet->payload =3D get_unaligned_le64(buf + 2); return 10; default: return INTEL_PT_BAD_PACKET; @@ -248,7 +249,7 @@ static int intel_pt_get_mwait(const unsigned char *buf,= size_t len, if (len < 10) return INTEL_PT_NEED_MORE_BYTES; packet->type =3D INTEL_PT_MWAIT; - packet->payload =3D le64_to_cpu(*(uint64_t *)(buf + 2)); + packet->payload =3D get_unaligned_le64(buf + 2); return 10; } =20 @@ -455,13 +456,13 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type typ= e, unsigned int byte, if (len < 3) return INTEL_PT_NEED_MORE_BYTES; ip_len =3D 2; - packet->payload =3D le16_to_cpu(*(uint16_t *)(buf + 1)); + packet->payload =3D get_unaligned_le16(buf + 1); break; case 2: if (len < 5) return INTEL_PT_NEED_MORE_BYTES; ip_len =3D 4; - packet->payload =3D le32_to_cpu(*(uint32_t *)(buf + 1)); + packet->payload =3D get_unaligned_le32(buf + 1); break; case 3: case 4: @@ -474,7 +475,7 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type type,= unsigned int byte, if (len < 9) return INTEL_PT_NEED_MORE_BYTES; ip_len =3D 8; - packet->payload =3D le64_to_cpu(*(uint64_t *)(buf + 1)); + packet->payload =3D get_unaligned_le64(buf + 1); break; default: return INTEL_PT_BAD_PACKET; --=20 2.34.1 From nobody Sat Jan 3 02:07:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03232E92728 for ; Thu, 5 Oct 2023 19:06:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231551AbjJETGy (ORCPT ); Thu, 5 Oct 2023 15:06:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231142AbjJETGn (ORCPT ); Thu, 5 Oct 2023 15:06:43 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E54BD9; Thu, 5 Oct 2023 12:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696532797; x=1728068797; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Idg8ltgyFZaayjhZqPMjxwfK9UI2JApxxyIZyfMjKUk=; b=GYLfpluDeVMuZW+WyB0/L2uLMqRzIBuF1ZFpTVxE5tkVQOeL+7p0Np0c AevmLnwWksu0eQkMUfHZDwnfsPBCJs4bTCe9SPOqpo1jlPjHt0erl98dH msyDgRGdnVT3UwLXDhvcly8JjJ9ZR+vaADaIcvl5EdH4XC0Y6V+9KxAiP z4Zh9KHKQkjj7X8gMijCDzw8jAC8Rn5ubP50bnhRFuHbAsdek89CB68Fs CQHR9tpb6KtgH54+Q0PyevGUVFLiCRGxZ1eLYS/1olVRoVI1kaFNM26f2 ZqvqxjEwA7M+lITBSgY96S3d53Ppl0fIpo9nUV0/2aJgAjW4ppHwgaAnx A==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="383488268" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="383488268" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:05:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="999055209" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="999055209" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.249.35.8]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:05:18 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH 5/5] perf intel-pt: Prefer get_unaligned_le64 to memcpy_le64 Date: Thu, 5 Oct 2023 22:04:51 +0300 Message-Id: <20231005190451.175568-6-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231005190451.175568-1-adrian.hunter@intel.com> References: <20231005190451.175568-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use get_unaligned_le64() instead of memcpy_le64(..., 8) because it produces simpler code. Signed-off-by: Adrian Hunter --- tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tool= s/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c index 7a90218aecb1..bccb988a7a44 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c @@ -190,7 +190,7 @@ static int intel_pt_get_mnt(const unsigned char *buf, s= ize_t len, if (len < 11) return INTEL_PT_NEED_MORE_BYTES; packet->type =3D INTEL_PT_MNT; - memcpy_le64(&packet->payload, buf + 3, 8); + packet->payload =3D get_unaligned_le64(buf + 3); return 11; } =20 @@ -302,7 +302,7 @@ static int intel_pt_get_bip_8(const unsigned char *buf,= size_t len, return INTEL_PT_NEED_MORE_BYTES; packet->type =3D INTEL_PT_BIP; packet->count =3D buf[0] >> 3; - memcpy_le64(&packet->payload, buf + 1, 8); + packet->payload =3D get_unaligned_le64(buf + 1); return 9; } =20 @@ -341,7 +341,7 @@ static int intel_pt_get_evd(const unsigned char *buf, s= ize_t len, packet->type =3D INTEL_PT_EVD; packet->count =3D buf[2] & 0x3f; packet->payload =3D buf[3]; - memcpy_le64(&packet->payload, buf + 3, 8); + packet->payload =3D get_unaligned_le64(buf + 3); return 11; } =20 --=20 2.34.1 From nobody Sat Jan 3 02:07:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 517BDCD8C8E for ; Tue, 10 Oct 2023 14:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232884AbjJJOWu (ORCPT ); Tue, 10 Oct 2023 10:22:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232200AbjJJOWs (ORCPT ); Tue, 10 Oct 2023 10:22:48 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38FC191; Tue, 10 Oct 2023 07:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696947767; x=1728483767; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QuUaC9YOuX87JW2J8slurScV01GdxJIdY83DI5FquNY=; b=GK+YQS2hvDmQGFZ70CGVEBY4pTuFMx08phhs7aPrmdBHTNSjKK1xgOjz Dh5mNGgA7Q7m7whJ62Yt6j1OxdEQPV9PZ+Rlc/IeMHhh8Q53oAnd5HVlR fJX8wZy4wR/1Hj00qfKgpowGbY7rctIw+P6AFdB/RWj8vihJGTqWcTIzb dtKp/soLbL8xjIOSOPKtGukBa6IWrnF6vsLqpFTv1TiioJk1aFPziWm/K bgKiRec1heZrd4gPSsvrMInn8MD3DZ66uK14XxH6MOEhH7SzdE4NK7ymN z6CYvSSTUUXUmzVR92OWLXJqrzBfGevoNbcXekaA5qWVkB+I97mCCSnli Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="381665076" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="381665076" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 07:22:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="823794124" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="823794124" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.249.36.106]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 07:22:44 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH] perf tools: Add unaligned.h to check-headers.sh Date: Tue, 10 Oct 2023 17:22:34 +0300 Message-Id: <20231010142234.20061-1-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231005190451.175568-1-adrian.hunter@intel.com> References: <20231005190451.175568-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add include/asm-generic/unaligned.h to check-headers.sh bringing tools/include/asm-generic/unaligned.h up to date so that the kernel and tools versions match. Signed-off-by: Adrian Hunter Reviewed-by: Ian Rogers --- Based on top of 5 patch set "perf intel-pt: Use of get_unaligned_le16() etc" tools/include/asm-generic/unaligned.h | 129 ++++++++++++++++++++++++-- tools/perf/check-headers.sh | 1 + 2 files changed, 122 insertions(+), 8 deletions(-) diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-gene= ric/unaligned.h index 9140bb4e16c6..156743d399ae 100644 --- a/tools/include/asm-generic/unaligned.h +++ b/tools/include/asm-generic/unaligned.h @@ -1,11 +1,11 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_GENERIC_UNALIGNED_H +#define __ASM_GENERIC_UNALIGNED_H + /* - * Copied from the kernel sources to tools/perf/: + * This is the most generic implementation of unaligned accesses + * and should work almost anywhere. */ - -#ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H -#define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H - #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpacked" =20 @@ -37,7 +37,120 @@ static inline u64 get_unaligned_le64(const void *p) return le64_to_cpu(__get_unaligned_t(__le64, p)); } =20 -#pragma GCC diagnostic pop +static inline void put_unaligned_le16(u16 val, void *p) +{ + __put_unaligned_t(__le16, cpu_to_le16(val), p); +} + +static inline void put_unaligned_le32(u32 val, void *p) +{ + __put_unaligned_t(__le32, cpu_to_le32(val), p); +} + +static inline void put_unaligned_le64(u64 val, void *p) +{ + __put_unaligned_t(__le64, cpu_to_le64(val), p); +} + +static inline u16 get_unaligned_be16(const void *p) +{ + return be16_to_cpu(__get_unaligned_t(__be16, p)); +} + +static inline u32 get_unaligned_be32(const void *p) +{ + return be32_to_cpu(__get_unaligned_t(__be32, p)); +} + +static inline u64 get_unaligned_be64(const void *p) +{ + return be64_to_cpu(__get_unaligned_t(__be64, p)); +} + +static inline void put_unaligned_be16(u16 val, void *p) +{ + __put_unaligned_t(__be16, cpu_to_be16(val), p); +} + +static inline void put_unaligned_be32(u32 val, void *p) +{ + __put_unaligned_t(__be32, cpu_to_be32(val), p); +} + +static inline void put_unaligned_be64(u64 val, void *p) +{ + __put_unaligned_t(__be64, cpu_to_be64(val), p); +} + +static inline u32 __get_unaligned_be24(const u8 *p) +{ + return p[0] << 16 | p[1] << 8 | p[2]; +} =20 -#endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */ +static inline u32 get_unaligned_be24(const void *p) +{ + return __get_unaligned_be24(p); +} + +static inline u32 __get_unaligned_le24(const u8 *p) +{ + return p[0] | p[1] << 8 | p[2] << 16; +} + +static inline u32 get_unaligned_le24(const void *p) +{ + return __get_unaligned_le24(p); +} + +static inline void __put_unaligned_be24(const u32 val, u8 *p) +{ + *p++ =3D val >> 16; + *p++ =3D val >> 8; + *p++ =3D val; +} + +static inline void put_unaligned_be24(const u32 val, void *p) +{ + __put_unaligned_be24(val, p); +} + +static inline void __put_unaligned_le24(const u32 val, u8 *p) +{ + *p++ =3D val; + *p++ =3D val >> 8; + *p++ =3D val >> 16; +} + +static inline void put_unaligned_le24(const u32 val, void *p) +{ + __put_unaligned_le24(val, p); +} + +static inline void __put_unaligned_be48(const u64 val, u8 *p) +{ + *p++ =3D val >> 40; + *p++ =3D val >> 32; + *p++ =3D val >> 24; + *p++ =3D val >> 16; + *p++ =3D val >> 8; + *p++ =3D val; +} + +static inline void put_unaligned_be48(const u64 val, void *p) +{ + __put_unaligned_be48(val, p); +} + +static inline u64 __get_unaligned_be48(const u8 *p) +{ + return (u64)p[0] << 40 | (u64)p[1] << 32 | (u64)p[2] << 24 | + p[3] << 16 | p[4] << 8 | p[5]; +} + +static inline u64 get_unaligned_be48(const void *p) +{ + return __get_unaligned_be48(p); +} +#pragma GCC diagnostic pop =20 +#endif /* __ASM_GENERIC_UNALIGNED_H */ diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh index 4314c9197850..d09c3d46f08f 100755 --- a/tools/perf/check-headers.sh +++ b/tools/perf/check-headers.sh @@ -161,6 +161,7 @@ check arch/x86/lib/memcpy_64.S '-I "^EXPORT_SYMB= OL" -I "^#include " -I"^SYM_FUNC_START\(_LOCAL\)*(memset_\(erms\|orig\))"' check arch/x86/include/asm/amd-ibs.h '-I "^#include [<\"]\(asm/\)*msr-ind= ex.h"' check arch/arm64/include/asm/cputype.h '-I "^#include [<\"]\(asm/\)*sysreg= .h"' +check include/asm-generic/unaligned.h '-I "^#include " -I "^#include " -I "^#pragma GCC diagnostic"' check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generi= c/mman-common\(-tools\)*.h>"' check include/uapi/linux/mman.h '-I "^#include <\(uapi/\)*asm/mman.h= >"' check include/linux/build_bug.h '-I "^#\(ifndef\|endif\)\( \/\/\)* s= tatic_assert$"' --=20 2.34.1