Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3745531iog; Tue, 28 Jun 2022 01:42:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vBKBXQgBLRiQk+Is1mph9NtVupRUzVFEYgzo9M5pVK3H3KgTxXLgQvrw7Zv/c/v4be4cvQ X-Received: by 2002:a17:907:7e8b:b0:726:2c51:b06e with SMTP id qb11-20020a1709077e8b00b007262c51b06emr16380265ejc.129.1656405748691; Tue, 28 Jun 2022 01:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656405748; cv=none; d=google.com; s=arc-20160816; b=zCfLXh0GCW7yOHpMZxySCdgnfkUlgubzwm51/DFkwJPphfnCgOZN7HGyohjx6lruvR yoce0xwFKbXMoieP6T2vVU8F3XKFUZYKBlnlid+Qv1Nqkz+U7nAKd8kPd2zkFQwOrSI+ yShSYQVaS0oJklUnx3mHYzlDtD/HhrMDSHq3ytTxW1l7NSfFXftma9FcppSfE/7EMszz AYK3qVIJQEBSVYp8ec7878F1NmFSmJkV1aZpYnJiRhNpLKxliKTzEiqwDXmX/xEkRl4o N2H6kHfMPuNiU7oyB7kGz0w9wmVbGHxh0/tGI2Pa2dJHo2HXpRH5vsUeZIvxVviSyhlc om6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=fTVgseVNgqo9Ivwwv2PAZ0MNjl+Ewk+f4XoldCtkS7k=; b=Vk7MnHXFuCA685qH3JFQrTP1qE72MI4eeDbfvNYEroVWt80TmkV/t74IRMgBtGFYs6 nktY+lQSVblkeclO5W7n+R9qYpyyw5VWSLlfHklb3a2ZW5JagYIniKLq60+5gTOQrgX3 /hzMPI+8aliufvJGJJHDS81MIW0Ei5trdrVUPJjW69c5Okc4HQefdYR7lGbfInZNIbKC tsXwZ44HZxDEyqv+ZWGQM2bTeJfCfAUMR1YUkMCUp68na419F7Dgc7AsF8cJZoPnX4Op IwU2E6iHofOH3aDMlhZ9Lv9X3xvvkWop7p1jH8Y8/UQsDdk+mgiQ+cd8bNMXT5VLGVsI 15gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=I59z5R3I; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg8-20020a170907a40800b00726c0da22dfsi3744240ejc.774.2022.06.28.01.42.00; Tue, 28 Jun 2022 01:42:28 -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=@gmail.com header.s=20210112 header.b=I59z5R3I; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244370AbiF1IQG (ORCPT + 99 others); Tue, 28 Jun 2022 04:16:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244273AbiF1IPj (ORCPT ); Tue, 28 Jun 2022 04:15:39 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E18982DD4D; Tue, 28 Jun 2022 01:14:58 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id u12-20020a05600c210c00b003a02b16d2b8so7068186wml.2; Tue, 28 Jun 2022 01:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fTVgseVNgqo9Ivwwv2PAZ0MNjl+Ewk+f4XoldCtkS7k=; b=I59z5R3IxjeTR4zj7ruq4/SbCv3uBEBD094l7mpGuxilr5kfRI3ZACUGAU5IZN8y8B BfSV9A1mR3Rx5E/OTpm6NGAmO+Nk7hxmkTvnSHgjOyclMxvRwvq/4zlX73em4tIUpwmu i8KrZ6TDibLG0X2kg26gWHv0PjSdnu5zGtVkC0JOcWoovkBanhw7JLE4u8aWL4fzWEsP zNTJ/otGInEahf12+Ps09mAd6b7q9dgp2M5JwsQy5JfShadJLHvYn2h96BTlszgo4V8q BBksVJh+vBC8ywMYSQu/m1eJEDoGb6nZL5I+a2/vDs0GI6K7sWyEBhsazHJxwiSvPXGi qaog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fTVgseVNgqo9Ivwwv2PAZ0MNjl+Ewk+f4XoldCtkS7k=; b=MgD7aWjONreRkeIsgTMVFrTgSEQyyaTliX7DpN8sTCwif80m2GB5o17DvmBj07ZihJ VDWBkhigQSqJUVIvStYToZvSyE2C/HPYswFo29e35a22iEockqd0Qpf6F7KCuJbcWdTh eDdb++5OY0xFYbuUSjhtGVylJDH4GrGkudHVXRcVqt4j7qC6wKKOazb4O9Qxh0NHGSYG rh72Ormcg+558f0AaWycJco/ykVzq77mi0C/Tkyjzk8cHyije3hojDJk/J4Ypn2jxAy9 goX3SjuU5B0zsX1M/xinFaH7Qvn6BHwuPXQEWm+U2pewyoPkPUwZZ3tk5cNApZhwycBT 2HAg== X-Gm-Message-State: AJIora8KaGn4C9Nbzjb6VByNX/fvLRa9aKGm8IQNZsQbkrdkpsLyHQS7 chsIgZdwinuu1NgiwpCvR38= X-Received: by 2002:a05:600c:3508:b0:39c:8240:5538 with SMTP id h8-20020a05600c350800b0039c82405538mr25878322wmq.165.1656404096701; Tue, 28 Jun 2022 01:14:56 -0700 (PDT) Received: from krava (net-109-116-206-47.cust.vodafonedsl.it. [109.116.206.47]) by smtp.gmail.com with ESMTPSA id j10-20020a5d448a000000b0021b8c99860asm12958055wrq.115.2022.06.28.01.14.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 01:14:56 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Tue, 28 Jun 2022 10:14:52 +0200 To: Ian Rogers 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 Subject: Re: [PATCH] perf bpf: 8 byte align bpil data Message-ID: References: <20220614014714.1407239-1-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220614014714.1407239-1-irogers@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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: > > $ 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. > > 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)); this one depends on info_linear->data being alligned(8), right? should we make sure it's allways the case like in the patch below, or it's superfluous? thanks, jirka --- diff --git a/tools/perf/util/bpf-utils.h b/tools/perf/util/bpf-utils.h index 86a5055cdfad..1aba76c44116 100644 --- a/tools/perf/util/bpf-utils.h +++ b/tools/perf/util/bpf-utils.h @@ -60,7 +60,7 @@ struct perf_bpil { /* which arrays are included in data */ __u64 arrays; struct bpf_prog_info info; - __u8 data[]; + __u8 data[] __attribute__((aligned(8))); }; struct perf_bpil *