Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3205677iog; Mon, 27 Jun 2022 11:23:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sVMojMM/82nnUh81GHSWlh0rvIBSakdKGYLn348tIIqD0sp+M2NVypYbR+Ol4sIrqXMnn8 X-Received: by 2002:a17:907:6e17:b0:726:2b3c:d373 with SMTP id sd23-20020a1709076e1700b007262b3cd373mr13886886ejc.357.1656354192092; Mon, 27 Jun 2022 11:23:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656354192; cv=none; d=google.com; s=arc-20160816; b=WUWn4IPaCir/Hwrl7wiW6DSUu+q0sOorSHn+tq4F7qQAZt3aqCnVMlgRQhFh74g49f 9uOaAhI+bFR5wnsVzED2WFzhIJq7WlCfZfC5kD+5U6ubuPyCs39Vq6CS8J/RX1d2df4C ompl/H6Stin6XVmXdwiQPpyf3AxnvL2rwNyGUDgwWABf2E7GRmXmhXJu5tF3kZUtWVyN HlF5GA9BYESUEDly9zTTeu84hgINvTYk9b+R+W/JpsR/FRtzECBP3FuwpgCmx3ruv4KC XgccZtgu84EuSU/jeZR9Fb9eMUfpli89rSzsIE2jpVOuSGFZyt7neWqedwz4dFkSnxH2 oasg== 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=Rx9f3FFpQHBCbk0ON6Xh6VW45WNeEZB24W/hAUNIOhc=; b=LKhS9wwVj2lXlqxmveB3BfaqEVTufa7HTCx398pQ4BzxBfQGYZas+sKQ0b63Ebd/DV EkZldWesZ7lhWP8yAmgWpJNl5nBzYhAHdVAOcGFAlyb0I/jhxTi24vC+07WtG31Pb+/l Au6tTowX/SCw+2k8cWnh4s+hkSiflQRAoV5k2sFBRVXq+MK+Xhn7jsbiEX0OORqJ4JMj 8uwvZjCDwLBPTc440tm4fo7zuCzsrBQGt9dIYPEoVMLTBxq4Lx9hzCgoj9VSGTh7Hc5l pu1J9iIg2zI4fHSU5bxdFYYh/EYsKMxo8Sppp2KxESX3IT2miMo6A3TjyCP3jCXosihg v4yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=G+D6o8B0; 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 dt13-20020a170907728d00b00726be208896si2322060ejc.973.2022.06.27.11.22.47; Mon, 27 Jun 2022 11:23:12 -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=G+D6o8B0; 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 S239926AbiF0RSL (ORCPT + 99 others); Mon, 27 Jun 2022 13:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235968AbiF0RSJ (ORCPT ); Mon, 27 Jun 2022 13:18:09 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63C41137 for ; Mon, 27 Jun 2022 10:18:07 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id i1so9521602wrb.11 for ; Mon, 27 Jun 2022 10:18:07 -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=Rx9f3FFpQHBCbk0ON6Xh6VW45WNeEZB24W/hAUNIOhc=; b=G+D6o8B0JVucQW6+PhCQ5L2XRwfWedIWe5iLwmsIKnP8l2kIPE3ln4/ME0/NvRV+UI IRq3HZNljewherNlCxkZNHbPRyhOKbLAJsPLf/122Lc0zDeUZ3DSYptMKEcEzzE5M49v K7z5/G6X58efTmpm/XecTLJdA7JzogWXZL37jfBfaiP12a4vZimKbpMNVbZqbhlrQndn amVSil4XRxHxN3Czg+9XDVPJzWWjWA1lGbD0M6Gf9a4KCdlQI4edBbYRGLimeSp7uaaN pvrRhrhKcOF/RRlK5ucxsSdCE8jF8RFh7BplqDvHDLsP9MUYF1Emg8N/f0LtedmrcKxn UcoQ== 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=Rx9f3FFpQHBCbk0ON6Xh6VW45WNeEZB24W/hAUNIOhc=; b=hMvcH9LORbZtgKLkJlJVydM25th/ik2f+eaidsLoea27qx3sSH7BPssCC6dy2KHx/z 0QM7M1aJICfPfcCRT8uzK8+gN4O7rw6HngkU5b5jFkaAU+/XFyaQh9Ho50YNO9INGlEZ rRdph4YCJt2TAQGw3oGjnhS9vv1BgT7NPihpwVUZw3zKbRtipws8PqiFsVY+QTii59sd VxC9yQdaTwi44ydUczcvDyqekFQm1BmV5n+0hB87YPGBEwtIP+tuLCeB6qUyRvz+GuIy yZu4zk86zhI89L5hutyObJ4gcz+FaeobuGEzBXXXrS2BMRpCY7+p3ENg4zifRP0FREsy 2uQw== X-Gm-Message-State: AJIora/fIk38XAo9yzqXVgBbvpAgBY+xdCUsaIGQ6CN2qL2Mm9UBGn4o jRhcMM85rVYjtGI6EHQaAx4kHC1QuuAvYk7IyIivEw== X-Received: by 2002:a5d:6b91:0:b0:21b:bc0b:7282 with SMTP id n17-20020a5d6b91000000b0021bbc0b7282mr13477019wrx.375.1656350285740; Mon, 27 Jun 2022 10:18:05 -0700 (PDT) MIME-Version: 1.0 References: <20220614014714.1407239-1-irogers@google.com> In-Reply-To: <20220614014714.1407239-1-irogers@google.com> From: Ian Rogers Date: Mon, 27 Jun 2022 10:17:51 -0700 Message-ID: Subject: Re: [PATCH] perf bpf: 8 byte align bpil data To: Dave Marchevsky Cc: Stephane Eranian , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Song Liu , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Yonghong Song , John Fastabend , KP Singh , Quentin Monnet 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=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 On Mon, Jun 13, 2022 at 6:47 PM 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: > > $ 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 > > Correct this by rouding up the data sizes and aligning the pointers. Happy Monday, polite ping! Thanks, Ian > Signed-off-by: Ian Rogers > --- > tools/perf/util/bpf-utils.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/tools/perf/util/bpf-utils.c b/tools/perf/util/bpf-utils.c > index e271e05e51bc..80b1d2b3729b 100644 > --- a/tools/perf/util/bpf-utils.c > +++ b/tools/perf/util/bpf-utils.c > @@ -149,11 +149,10 @@ get_bpf_prog_info_linear(int fd, __u64 arrays) > count = bpf_prog_info_read_offset_u32(&info, desc->count_offset); > size = bpf_prog_info_read_offset_u32(&info, desc->size_offset); > > - data_len += count * size; > + data_len += roundup(count * size, sizeof(__u64)); > } > > /* step 3: allocate continuous memory */ > - data_len = roundup(data_len, sizeof(__u64)); > info_linear = malloc(sizeof(struct perf_bpil) + data_len); > if (!info_linear) > return ERR_PTR(-ENOMEM); > @@ -180,7 +179,7 @@ get_bpf_prog_info_linear(int fd, __u64 arrays) > bpf_prog_info_set_offset_u64(&info_linear->info, > desc->array_offset, > ptr_to_u64(ptr)); > - ptr += count * size; > + ptr += roundup(count * size, sizeof(__u64)); > } > > /* step 5: call syscall again to get required arrays */ > -- > 2.36.1.476.g0c4daa206d-goog >