Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp842182pxb; Fri, 22 Apr 2022 12:21:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZGvcl7rw+/+eDpiprh6E972d9dXs+JOWPZRIstaVMAnzJMh/q8KsRFAsn1TT+mAevYquB X-Received: by 2002:a17:902:7c8c:b0:156:5651:1d51 with SMTP id y12-20020a1709027c8c00b0015656511d51mr6097752pll.107.1650655264298; Fri, 22 Apr 2022 12:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650655264; cv=none; d=google.com; s=arc-20160816; b=aHvwkOWU7lsZm7eNZz/NHCPA0pF7C9+8lxCG757cQJQuzfXtNBF/LBMnd12I4X51F0 D6hRiD5dk6vGR5G87i5FW/NwPrvBPnO+DMwQBW4SXhu6oH8USSQri45ZzmWZhczKxN5x 6uI39pLe2o3cZwgcau2TkKWw3sXGxjyZhSFPU+W3KIlooGCo/fhYIzrZqy2Odf061oTq R1j0IcnOezkSnh9H6Acy8vh0RMyxRjyJI0y/OY1poZB6ZkHJEaE/Z+NQxWI5nLRddNt7 78vQUEcWIHP0+i5me1F7PDlePfXSQsZfOIRXmsz4wAr0zJIu66TTKl5dmSY3JnKza0Xn ACkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:reply-to:cc :from:to:dkim-signature:date; bh=ieYkeey10FAhoCbWrOd1isttftjkFsISmPppYe5m5sM=; b=g8h3cAKog5miXQ6kJ9FvLmiJM7qSM5uk5opbIASbSo5OImAeLqxzRCwNmuZ33B0Pw0 Wgt7uKERoZqgzD3u8xgi0d9pVbd5pmOBE+yQ20FmrbRCh189RdHG6BqUKkzIidw1YGtm KNp2benkEQgiuhYDJ/40bNsiwyrtTVoyvQOHNBmoieyJEqUJsmkQ5bJzAcEbsfpTJ6kc 6hdKTa4DvnT0SorzMH4XwJvGMCStQeeb/EizPRfHPiC0Uv4xaTiXQxhlW/gdmakGOnQL usbO2RIYXBlz6H3E2ihSY1j8W6+B27GLbGEebLM786EQUSLqI/lSa8JvMmITuiSmfKxB nN5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail2 header.b=hGIu1Muj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 126-20020a630484000000b003a8c6e17289si9104628pge.842.2022.04.22.12.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:21:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail2 header.b=hGIu1Muj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1AE911581FA; Fri, 22 Apr 2022 11:34:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383460AbiDUAll (ORCPT + 99 others); Wed, 20 Apr 2022 20:41:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383447AbiDUAlh (ORCPT ); Wed, 20 Apr 2022 20:41:37 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F00481FCDA for ; Wed, 20 Apr 2022 17:38:49 -0700 (PDT) Date: Thu, 21 Apr 2022 00:38:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1650501528; bh=ieYkeey10FAhoCbWrOd1isttftjkFsISmPppYe5m5sM=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:Feedback-ID:From:To:Cc:Date:Subject:Reply-To: Feedback-ID:Message-ID; b=hGIu1MujrFCCpRDxpmF8ugG8/VtqzXXj2hTW0lqgEu/pD4OBH65i2iXXJbcVS8c0+ VVNIJXEOJyZaF3/4rH3OmWMbvhT68ti9JsvLjFpoPzUguuLp5jsIosFJqsuW0SO8Qu OOPyBfe58wvB/pc9fLlhkXC8h4uThZFq0n5rWWw3XJWONZSGlEdQPyDN91Kd33jUFM jDKcD0YZNm+b1AENqdkC1HIMoeOR5w5T31xBj/W+J0lMIOFrn25DDGpj25/3jwF6fu 9PDia2fmA8HM5jTmXPlG4STMdDjaRk3xEcjSDbs1MvwL+UQGPfBQ6hATa32xmO1sA3 9oHwpaxvQ0BuA== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Alexander Lobakin , Maciej Fijalkowski , Song Liu , Kumar Kartikeya Dwivedi , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH v2 bpf 01/11] bpftool: use a local copy of perf_event to fix accessing ::bpf_cookie Message-ID: <20220421003152.339542-2-alobakin@pm.me> In-Reply-To: <20220421003152.339542-1-alobakin@pm.me> References: <20220421003152.339542-1-alobakin@pm.me> Feedback-ID: 22809121:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no 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 When CONFIG_PERF_EVENTS is not set, struct perf_event remains empty. However, the structure is being used by bpftool indirectly via BTF. This leads to: skeleton/pid_iter.bpf.c:49:30: error: no member named 'bpf_cookie' in 'stru= ct perf_event' return BPF_CORE_READ(event, bpf_cookie); ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~ ... skeleton/pid_iter.bpf.c:49:9: error: returning 'void' from a function with = incompatible result type '__u64' (aka 'unsigned long long') return BPF_CORE_READ(event, bpf_cookie); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tools and samples can't use any CONFIG_ definitions, so the fields used there should always be present. Define struct perf_event___local with the `preserve_access_index` attribute inside the pid_iter BPF prog to allow compiling on any configs. CO-RE will substitute it with the real struct perf_event accesses later on. Fixes: cbdaf71f7e65 ("bpftool: Add bpf_cookie to link output") Suggested-by: Andrii Nakryiko Signed-off-by: Alexander Lobakin --- tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c b/tools/bpf/bpftool/= skeleton/pid_iter.bpf.c index eb05ea53afb1..e2af8e5fb29e 100644 --- a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c +++ b/tools/bpf/bpftool/skeleton/pid_iter.bpf.c @@ -15,6 +15,10 @@ enum bpf_obj_type { =09BPF_OBJ_BTF, }; +struct perf_event___local { +=09u64 bpf_cookie; +} __attribute__((preserve_access_index)); + extern const void bpf_link_fops __ksym; extern const void bpf_map_fops __ksym; extern const void bpf_prog_fops __ksym; @@ -41,8 +45,8 @@ static __always_inline __u32 get_obj_id(void *ent, enum b= pf_obj_type type) /* could be used only with BPF_LINK_TYPE_PERF_EVENT links */ static __u64 get_bpf_cookie(struct bpf_link *link) { +=09struct perf_event___local *event; =09struct bpf_perf_link *perf_link; -=09struct perf_event *event; =09perf_link =3D container_of(link, struct bpf_perf_link, link); =09event =3D BPF_CORE_READ(perf_link, perf_file, private_data); -- 2.36.0