From patchwork Thu Oct 5 19:04:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 148994 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp508545vqb; Thu, 5 Oct 2023 12:06:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPzDcCD1fLDlxwH+bTNnHM5+SA9E0SRzD8jjdYDqGIEwLT1xoxMr6zlo5yZYqr8x83Kp1t X-Received: by 2002:a05:6358:2611:b0:142:e357:e777 with SMTP id l17-20020a056358261100b00142e357e777mr6705353rwc.25.1696532817995; Thu, 05 Oct 2023 12:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696532817; cv=none; d=google.com; s=arc-20160816; b=J64JDHcrUKyusJmACm4Bqxtlm3TwSgZ7/vVf/c8vncn7jcZi7WVOqpHvLltjc3TtnL IthFTzx3qKeZx537PnpaFtLtv/OBdi64tOpQSos2E+/hIV8vsxvEtISF2moWfeLolKlr guq6eqB26ASBCHTrueijWI1X+LigtAX+vy1CluykmT2M3w+jsNr8j4eET9OYqa9zqPO3 uHfSO6JKFL6sTyTDHcsqEl5mCQwI0/7G/7YeXVh8nQyi9X+zIDQ5e14t8pROIsDZ/gGo OIPPMe3D9vatfJkc3sAzoTC94oUdcJk5GRiwnOwqKvIOiBg4k1oBJL07G7aJ0uait7jF dcVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z1ermOgdCtdHkTS1bJ4MgHACEg7KimCWvy62QZUReTQ=; fh=7ueK1huCq2Lf3LMjc8i3Ob70zhQl+8ZRdqYzG6swRYY=; b=LD+SWPIy7tICcZxulmjiVe/f7lMZBt/3Rok81EoxS61r2UYmeZNSAwQWUuMAdTIEPo tK1VP1ZbP7mLcfjQHkg0T5i33LNv8TDluRlB85ges7cc07SJ6apLF9iQMhjFH8VUScI6 lrGupexXKNBR2HlSdTOU25DP58LibpvaNeGKrtF3HKzq/e/CW5D9vzM82WlmVRDyHt0g SoZrLw1EKSoHn2EP1JcJZyimsHXvbrEmyRxQtq2cSoD4j3KizipYjI+oZ5cSrgm72YBH cCFBAIc34ynN4MOdKhc4vunWe0qIDajPKi+MIv2UjCQyHeXL8YqDZM8zL6EASFh+BLQ/ ++4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l2p0CPXi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id hk8-20020a17090b224800b00274c6997c25si2399072pjb.110.2023.10.05.12.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 12:06:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l2p0CPXi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id AAC77835C23A; Thu, 5 Oct 2023 12:06:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230055AbjJETGo (ORCPT + 18 others); Thu, 5 Oct 2023 15:06:44 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 05 Oct 2023 12:06:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778943596266979663 X-GMAIL-MSGID: 1778943596266979663 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/tools/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 #include "intel-pt-pkt-decoder.h" @@ -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; - payload = le64_to_cpu(*(uint64_t *)buf); + payload = get_unaligned_le64(buf); for (count = 47; count; count--) { if (payload & BIT63) @@ -119,7 +120,7 @@ static int intel_pt_get_cbr(const unsigned char *buf, size_t len, if (len < 4) return INTEL_PT_NEED_MORE_BYTES; packet->type = INTEL_PT_CBR; - packet->payload = le16_to_cpu(*(uint16_t *)(buf + 2)); + packet->payload = get_unaligned_le16(buf + 2); return 4; } @@ -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 = le32_to_cpu(*(uint32_t *)(buf + 2)); + packet->payload = get_unaligned_le32(buf + 2); return 6; case 1: if (len < 10) return INTEL_PT_NEED_MORE_BYTES; - packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2)); + packet->payload = 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 = INTEL_PT_MWAIT; - packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2)); + packet->payload = get_unaligned_le64(buf + 2); return 10; } @@ -455,13 +456,13 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type type, unsigned int byte, if (len < 3) return INTEL_PT_NEED_MORE_BYTES; ip_len = 2; - packet->payload = le16_to_cpu(*(uint16_t *)(buf + 1)); + packet->payload = get_unaligned_le16(buf + 1); break; case 2: if (len < 5) return INTEL_PT_NEED_MORE_BYTES; ip_len = 4; - packet->payload = le32_to_cpu(*(uint32_t *)(buf + 1)); + packet->payload = 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 = 8; - packet->payload = le64_to_cpu(*(uint64_t *)(buf + 1)); + packet->payload = get_unaligned_le64(buf + 1); break; default: return INTEL_PT_BAD_PACKET;