Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp409848rdb; Thu, 5 Oct 2023 09:17:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGNbhSmvGtqMvMoHeR0k9n3FZEwaRhne6Q98lrqMy3hOLB4vMCyfDSYFWPmGjd78HcRW0jB X-Received: by 2002:a17:902:a417:b0:1c6:1679:e035 with SMTP id p23-20020a170902a41700b001c61679e035mr4227341plq.21.1696522621533; Thu, 05 Oct 2023 09:17:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696522621; cv=none; d=google.com; s=arc-20160816; b=BgRZoK4mGFDN+qoQd5yGkzBXY0HywR0J5Ym2ySGl7cjZpBoaZPqFYyrMMQiPTjwczD 5BIsMzJI3uAUKL799tPdpPYRZXvQxOVwL3RwsY5auUk63I5eOjJQutrD6PiuRtN36KK4 rW+qirC2RUrJV7WvIgKHi+FJx7eCL3O7cavafO/qq9XdEnmuyT9vUv2r+AQNsVKsnKjc 5TQ6p5Ej/T+Ep7tWLD0jTAjY1eXcXvmf7uCbYH2GAzAMUuj/XLlDKxLgWvrQl/3PjkRf A5lPBmsUguhmEwyxA0Fvmffuw/5Xf0cmXfHukHPpaRv7FytuMMsRCHRuYCYibQYYZMQ9 uHQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Ab1RWq/q/7xQ1yVOIIQTt0NzzLhBI+PnkiYu9FpqEBk=; fh=/tLgnQQtlIDlVLnIiO029O4jQxqd2PExTlHXqkMkYRY=; b=cB+SuZY37b4stmQZ3DsyA1uLYEj/zd8s146mBC5UEbGaIb0b4DXuNFsm3/rJ78IJoo E1F90cls6UIVPACEvjV0w2eJAigbxng8aSM61UKNoSKFf7uA2Lk/4MiBUo3tw1cXJNGI mh3U+tTWlx7Alse8tj7Ds+AzTViSZ6BDd2nfz7V9DDmNneOR3WUBkH32z45aTkw4njoj eLRI3ijvPZLlGq5h/w0PdVSdL9cI9s7EHIfqzId1N0vhePSoVITxVh2SKQB3v87wxHI/ tQRjAC9qTCluuPArXc6b9HzDD0P+7085sUCdbojRxPQXJ0RiKdxg4TOsO/opcJeJH9qU LAEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ikWAsPEm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id kn6-20020a170903078600b001c41515c4c7si1728669plb.115.2023.10.05.09.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:17:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ikWAsPEm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 214BA80713ED; Thu, 5 Oct 2023 09:15:38 -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 S241736AbjJEQOm (ORCPT + 99 others); Thu, 5 Oct 2023 12:14:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239398AbjJEQMa (ORCPT ); Thu, 5 Oct 2023 12:12:30 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 151D05AE0C for ; Thu, 5 Oct 2023 08:48:59 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50348c54439so4810e87.1 for ; Thu, 05 Oct 2023 08:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696520937; x=1697125737; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Ab1RWq/q/7xQ1yVOIIQTt0NzzLhBI+PnkiYu9FpqEBk=; b=ikWAsPEmJOKqFxewntwjtRFelMFr/pZ12c7WhFLQJ5AYWxNI8Asc8tdQDyRePz89Dq k5dCK2KsqNtQ+tqHcCZ5wHaoerX6GN2evBFgWaxKPd7IX9jwWcq9f7S1eIeJWE7tgeyl Njzf3K46r+PEcKkTuNxhcFHQ8zwi6QQdVKG34jZqj2nPqwzuKuQp2PsR5/FyV9bVv7Oy d1cdk84X2hizgALPdSwJ94jwKJcb1esKfIMTN81kTkQ8MrhkUT4w0fLakzwp7HNqfJR9 hhKjQNqYOY1e0eruljFZM4OO+2u+GYUZED9xzYJApAeGlpaEMS/ELE5U99459Ybex2Vs eKRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696520937; x=1697125737; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ab1RWq/q/7xQ1yVOIIQTt0NzzLhBI+PnkiYu9FpqEBk=; b=qpJmFu4Dzfrnx6IXZDfiw9BGy+g2DZtHjTgtxlJGImgOZyW07jTLlkuK0E1uUMFIcl B1EB2x8ME2Qeewj8rVtYGcU6EaBsXli+GnsIuj5uo3kQfu1KJj3grLehpsCHZ9iADN28 Ih5MPKIi37YJy2woSwomtxKycoNBSZb6KAQywLBX1wJYjihygGWUHJ/NhEhLX7y4MYsg rQznTf5jacEDZCKYT72BfNcUP5QnSok0+q+7YFyzhdZhYFs5xPEXPmzVm7EqyvJj1f5Z p1UI42MIjnJbGeOHPw4GSb40ot/ka5XUa+C95VLwtdZkOShhtYWfBxtasonI4m+DEWlt fhGA== X-Gm-Message-State: AOJu0YzjgDOimCdSv/WEB4VmgrMvNMkwODaWadayDWnvokEuliPKVsn8 VLlSITgkY4S0Ehn+Bswn5dyv4Zg32Oo6nMbjz2YMTQ== X-Received: by 2002:ac2:42d1:0:b0:502:932e:2e36 with SMTP id n17-20020ac242d1000000b00502932e2e36mr49426lfl.2.1696520937110; Thu, 05 Oct 2023 08:48:57 -0700 (PDT) MIME-Version: 1.0 References: <20231002221909.2958708-1-irogers@google.com> In-Reply-To: <20231002221909.2958708-1-irogers@google.com> From: Ian Rogers Date: Thu, 5 Oct 2023 08:48:45 -0700 Message-ID: Subject: Re: [PATCH v1] perf intel-pt: pkt-decoder: Fix alignment issues To: Adrian Hunter Cc: Alexander Shishkin , Ingo Molnar , Arnaldo Carvalho de Melo , Peter Zijlstra , Jiri Olsa , Miguel Ojeda , Liam Howlett , Namhyung Kim , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 09:15:38 -0700 (PDT) On Mon, Oct 2, 2023 at 3:19=E2=80=AFPM Ian Rogers wrot= e: > > The byte aligned buffer is cast to large types and dereferenced > causing misaligned pointer warnings from undefined behavior sanitizer. > Fix the alignment issues with memcpy which may require the > introduction of temporaries. > > Signed-off-by: Ian Rogers > --- This is a relatively small change that fixes building with -fsanitize=3Dalignment -fsanitize-undefined-trap-on-error. Adrian, as this is Intel-PT could you take a look? Thanks, Ian > .../intel-pt-decoder/intel-pt-pkt-decoder.c | 21 ++++++++++++------- > 1 file changed, 14 insertions(+), 7 deletions(-) > > diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/to= ols/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c > index af9710622a1f..28659874d84e 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 > @@ -83,7 +83,7 @@ static int intel_pt_get_long_tnt(const unsigned char *b= uf, size_t len, > if (len < 8) > return INTEL_PT_NEED_MORE_BYTES; > > - payload =3D le64_to_cpu(*(uint64_t *)buf); > + memcpy_le64(&payload, buf, sizeof(payload)); > > for (count =3D 47; count; count--) { > if (payload & BIT63) > @@ -220,6 +220,8 @@ static int intel_pt_get_3byte(const unsigned char *bu= f, size_t len, > static int intel_pt_get_ptwrite(const unsigned char *buf, size_t len, > struct intel_pt_pkt *packet) > { > + uint32_t tmp; > + > packet->count =3D (buf[1] >> 5) & 0x3; > packet->type =3D buf[1] & BIT(7) ? INTEL_PT_PTWRITE_IP : > INTEL_PT_PTWRITE; > @@ -228,12 +230,13 @@ 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)); > + memcpy(&tmp, buf + 2, sizeof(tmp)); > + packet->payload =3D le32_to_cpu(tmp); > return 6; > case 1: > if (len < 10) > return INTEL_PT_NEED_MORE_BYTES; > - packet->payload =3D le64_to_cpu(*(uint64_t *)(buf + 2)); > + memcpy_le64(&packet->payload, buf + 2, sizeof(packet->pay= load)); > return 10; > default: > return INTEL_PT_BAD_PACKET; > @@ -258,7 +261,7 @@ static int intel_pt_get_mwait(const unsigned char *bu= f, 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)); > + memcpy_le64(&packet->payload, buf + 2, sizeof(packet->payload)); > return 10; > } > > @@ -454,6 +457,8 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type typ= e, unsigned int byte, > struct intel_pt_pkt *packet) > { > int ip_len; > + uint16_t tmp16; > + uint32_t tmp32; > > packet->count =3D byte >> 5; > > @@ -465,13 +470,15 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type t= ype, 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)); > + memcpy(&tmp16, buf + 1, sizeof(tmp16)); > + packet->payload =3D le16_to_cpu(tmp16); > 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)); > + memcpy(&tmp32, buf + 1, sizeof(tmp32)); > + packet->payload =3D le32_to_cpu(tmp32); > break; > case 3: > case 4: > @@ -484,7 +491,7 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type typ= e, 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)); > + memcpy_le64(&packet->payload, buf + 1, sizeof(packet->pay= load)); > break; > default: > return INTEL_PT_BAD_PACKET; > -- > 2.42.0.582.g8ccd20d70d-goog >