Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4093833iog; Tue, 28 Jun 2022 08:51:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1saarQ5Ph/Lb9RAaMJrFLozRW4QhYZZASedDBvR271pSvUhMdmC1F8TeuGr7NIt+GKmWcMm X-Received: by 2002:a05:6a00:2295:b0:525:72fa:658c with SMTP id f21-20020a056a00229500b0052572fa658cmr5364792pfe.42.1656431490699; Tue, 28 Jun 2022 08:51:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656431490; cv=none; d=google.com; s=arc-20160816; b=iOxTwNnZE/H3UnnPImyrq3fHEbFy50vzk2EzPIB6L9HCNlHH4E+CtmQ32un5QMXDdH YqJCsiPW23TgIY/2gE4pAPhC02XzZO31BJv80nEO86nga35Xs8+gHeHmgkfS40UcJS9H FnhldzxfRj5F/vZH0rV3wM+QBZuZq16NAFmfRtUngbWLugtkUBC+KMk2F+wxfmPI59cu 76GCN108k5a+vZMa/nz44hErkD5/qj0NgWI8jnsFtL7wSPDDDJ9KpAducNKZR+IyQbQv QZhB4Epgn94iXyKL+drJN7heJ7BzsJcK2nZwDZS7Bl3vJa0rC1RckGxCKCqy3ncxJDz6 jUiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8kVNWHrBL0GiaNqy7pXs9TTaPLwVW5aeut18uIqtgkc=; b=LoYDToEBOiBTleFbxGkBxuM7yF5qfm/ld0cvAII/ueSTipc8IEufnUfBka+mtL2t2h aqFG5Jf0oipXG132MYGyo388WFo5mp7UWV2z3k3qVn/qfN2OEYjFhXDQ2wWV96ZCAjU/ nhGY71SJpxeNuvEvnrZHlhOdcg5e6KNaxGGSV9DC/OFsNrlkJzJhjUKl83DzcYGHZcIc 88mO6D6ibbT1o7Pp8RV9JkrxHpusm/pdro8W1BgBHXBqce03yZSgpOJWAtJLhTR11EJg W2SzWHFel0OlfLZarcSGTsvScDAtup9NPibLMI/4Pyu4ZFQacx4QqzeyJ/ZEo8MkMhDV o5XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Lur6rtWd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a170902e0c300b0016a108577cdsi16712141pla.575.2022.06.28.08.51.16; Tue, 28 Jun 2022 08:51:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Lur6rtWd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348169AbiF1PQD (ORCPT + 99 others); Tue, 28 Jun 2022 11:16:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348161AbiF1PP2 (ORCPT ); Tue, 28 Jun 2022 11:15:28 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1778432053 for ; Tue, 28 Jun 2022 08:15:19 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id i25so12661090wrc.13 for ; Tue, 28 Jun 2022 08:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8kVNWHrBL0GiaNqy7pXs9TTaPLwVW5aeut18uIqtgkc=; b=Lur6rtWdWtsnC+SAMWRIoyGTCnfrArnoVRT/JoKQA1MBFjN7wKpLHEMLSnukDEMMHU Ay8mffu3ExD+WOLzoMZ+p+JZ0ihbmQHBW6GWjmYKXBoeoe0FBG0XJ7G9Gj7v5Haq+GO3 Q4N96g0vvP7TUEYJcVhsixklEsMkotlZak7Lw+VD8LfCJ+ePdug2NU13uZZa4uLEPlGY R1LHApvvD7Xx1zetSoSWWfwOIYLhCIdnAERf7Bj6mgMQXZar+tZqeEOkuMD/O/XWIa7q K+OFjxGLNiNhPL9R9aMgdJuBzRu/VIrMkviyPILGE1JV+wYAVrZ32Z/g1Y0yuXXmJN41 0Myw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8kVNWHrBL0GiaNqy7pXs9TTaPLwVW5aeut18uIqtgkc=; b=XsymbFzg/pMONQ974KXUS+FVjf2kD5RcFGPVujBLM72wxxrJjaygEghON1EHvBUpnW g6Ts+X4o5VTRWThP7nnJYzZrIhtJ0mR0Dpu0TS4xyf7k87gN1EEjsNAamxxfIycYP2kb U24WqftLX3f6MSEH8fhrmmhUBs2dQvPaQW99f0Ztq6ZmNSQKt0pkqHj/F6pWWob7uwX+ aeijSob7gls0VC6xzlWainytVD5ksttra77AagDrjGk2Fxe3rTt4he+1+rfilaAQxS7N LWKbgl3eqd0H2Rp9KgLyEPTRXJOpNquCpRhThsDiiMWgeR4HXbaLP9HIhtcnL+j4zA6J CXuw== X-Gm-Message-State: AJIora90YNLcgKQgPAKhccMVVvQcDVQpQJHFLIW/aUEEGCWERhDTFEUt w6BCo5m17OJAnVtMa9gKgBNHeEPBbBW/cMqBrQ3fZw== X-Received: by 2002:a5d:544c:0:b0:21b:a288:f98c with SMTP id w12-20020a5d544c000000b0021ba288f98cmr17779907wrv.300.1656429317400; Tue, 28 Jun 2022 08:15:17 -0700 (PDT) MIME-Version: 1.0 References: <20220614014714.1407239-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Tue, 28 Jun 2022 08:15:04 -0700 Message-ID: Subject: Re: [PATCH] perf bpf: 8 byte align bpil data To: olsajiri@gmail.com Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Dave Marchevsky , Quentin Monnet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Stephane Eranian Content-Type: text/plain; charset="UTF-8" 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, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 On Tue, Jun 28, 2022 at 1:41 AM wrote: > > On Mon, Jun 13, 2022 at 06:47:14PM -0700, Ian Rogers wrote: > > bpil data is accessed assuming 64-bit alignment resulting in undefined > > behavior as the data is just byte aligned. With an -fsanitize=undefined > > build the following errors are observed: > > I need to add -w to get the clean build with that, do you see that as well? > > $ make EXTRA_CFLAGS='-fsanitize=undefined -w' I don't recall needing this, but I was stacking fixes which may explain it. > > > > $ sudo perf record -a sleep 1 > > util/bpf-event.c:310:22: runtime error: load of misaligned address 0x55f61084520f for type '__u64', which requires 8 byte alignment > > 0x55f61084520f: note: pointer points here > > a8 fe ff ff 3c 51 d3 c0 ff ff ff ff 04 84 d3 c0 ff ff ff ff d8 aa d3 c0 ff ff ff ff a4 c0 d3 c0 > > ^ > > util/bpf-event.c:311:20: runtime error: load of misaligned address 0x55f61084522f for type '__u32', which requires 4 byte alignment > > 0x55f61084522f: note: pointer points here > > ff ff ff ff c7 17 00 00 f1 02 00 00 1f 04 00 00 58 04 00 00 00 00 00 00 0f 00 00 00 63 02 00 00 > > ^ > > util/bpf-event.c:198:33: runtime error: member access within misaligned address 0x55f61084523f for type 'const struct bpf_func_info', which requires 4 byte alignment > > 0x55f61084523f: note: pointer points here > > 58 04 00 00 00 00 00 00 0f 00 00 00 63 02 00 00 3b 00 00 00 ab 02 00 00 44 00 00 00 14 03 00 00 > > > and I'm also getting another error in: > > [root@krava perf]# ./perf record -a sleep 1 > util/synthetic-events.c:1202:11: runtime error: member access within misaligned address 0x00000286f7ea for type 'struct perf_record_record_cpu_map', which requires 8 byte alignment > 0x00000286f7ea: note: pointer points here > 20 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > ^ > util/synthetic-events.c:1203:18: runtime error: member access within misaligned address 0x00000286f7ea for type 'struct perf_record_record_cpu_map', which requires 8 byte alignment > 0x00000286f7ea: note: pointer points here > 20 00 01 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > ^ > util/synthetic-events.c:1206:46: runtime error: member access within misaligned address 0x00000286f7ea for type 'struct perf_record_record_cpu_map', which requires 8 byte alignment > 0x00000286f7ea: note: pointer points here > 20 00 01 00 01 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > ^ > /home/jolsa/kernel/linux-perf/tools/include/asm-generic/bitops/atomic.h:10:29: runtime error: load of misaligned address 0x00000286f7f2 for type 'long unsigned int', which requires 8 byte alignment > 0x00000286f7f2: note: pointer points here > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 51 00 00 00 00 00 > ^ > > are you going to address this one as well? > > > the reason for this one is that 'data' in struct perf_record_cpu_map_data > is not alligned(8), so that's why I raised the question in my other reply ;-) > > I wonder we should mark all tools/lib/perf/include/perf/event.h types > as packed to prevent any compiler padding I already sent out a fix and some improvements related to this: https://lore.kernel.org/lkml/20220614143353.1559597-1-irogers@google.com/ Could you take a look? I'm not sure about aligned and packed. I tried to minimize it in the change above. The issue is that taking the address of a variable in a packed struct results in an unaligned pointer. To address this in the fix above I changed the functions to pass pointers to the whole struct. Thanks, Ian > thanks, > jirka