From patchwork Thu Apr 14 22:44:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12814090 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35C26C433EF for ; Thu, 14 Apr 2022 22:45:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347140AbiDNWr0 (ORCPT ); Thu, 14 Apr 2022 18:47:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347163AbiDNWrY (ORCPT ); Thu, 14 Apr 2022 18:47:24 -0400 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E3A0AFACB; Thu, 14 Apr 2022 15:44:57 -0700 (PDT) Date: Thu, 14 Apr 2022 22:44:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976293; bh=m39CgK5yAeTLeYnreGilY1UHwXX8icQa6tZk1rsB5Sc=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=TkUjN83LOR7KPiP6/BtDcJy9T5A0SCRrwKRt1UzFAetbS3c2v+4YvxILXankuuXKA 4HY05YFja8QYjbogtEz/s3wWHsySjkzwMmMmTQe/GZkAKHlTVVzgr2BOFKMUlYdunH rlfQ0yZrJiUMxNdi/r5H9DIqgAc5zLN8ybeswQmgTg7NUzgVx050NOn/FYpLVcfwaf POZh9VZIGI9C+ZjD+HeOg87Gpvtxhol39CYLQ9cTVYgA+ymIpw0NTL02KXjOxWRu3j V2oO+f4NaEvXJWVWqIMY7N935zYLBKulFFf/y0Q9/PDR1Pc6f/JDUGJcRR8dSV0C9U bTqx92pK+L0rg== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 01/11] bpf, perf: fix bpftool compilation with !CONFIG_PERF_EVENTS Message-ID: <20220414223704.341028-2-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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 'struct 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. Move CONFIG_BPF_SYSCALL block out of the CONFIG_PERF_EVENTS block to make it available unconditionally. Fixes: cbdaf71f7e65 ("bpftool: Add bpf_cookie to link output") Signed-off-by: Alexander Lobakin --- include/linux/perf_event.h | 2 ++ 1 file changed, 2 insertions(+) -- 2.35.2 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index af97dd427501..b1d5715b8b34 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -762,12 +762,14 @@ struct perf_event { u64 (*clock)(void); perf_overflow_handler_t overflow_handler; void *overflow_handler_context; +#endif /* CONFIG_PERF_EVENTS */ #ifdef CONFIG_BPF_SYSCALL perf_overflow_handler_t orig_overflow_handler; struct bpf_prog *prog; u64 bpf_cookie; #endif +#ifdef CONFIG_PERF_EVENTS #ifdef CONFIG_EVENT_TRACING struct trace_event_call *tp_event; struct event_filter *filter; From patchwork Thu Apr 14 22:45:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12814091 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33C83C4332F for ; Thu, 14 Apr 2022 22:45:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347172AbiDNWrl (ORCPT ); Thu, 14 Apr 2022 18:47:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347153AbiDNWrj (ORCPT ); Thu, 14 Apr 2022 18:47:39 -0400 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6B2FC559B; Thu, 14 Apr 2022 15:45:13 -0700 (PDT) Date: Thu, 14 Apr 2022 22:45:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976310; bh=uv61apQIeQt8drF2A52PZrs8AoOA0Lvm41y6dOx4zW4=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=dWY+JprLs4JIrIWoJF/Ubs58DGuvqgzq0bbgkJbERbj+vlcFLFU4rLtZoy/LqcBem j5UIXLMFErTLjO5XpUmTD1bJor/Sv45lvgS54UbUxhe4TFAvY2KbYulb1Bc6QfZ7YY GEluu1k5+/WyknMrfSSIHY3WTmzhoGSpwCUZ/dwyv/lZGHRo3ell+m8rxkxWI34P0t zg2nC6c1GBM5nxedFuxOziSD0uwPAUxoWlzIYpkXqeG1VlJpQ+eowVW9yrtjgdiWVJ +zQtLu/qJJaA85eYPNHDmu6+wcUeI06oX1xMr9mrHwF3zuEkxafI4uQ2aEkxqHe7xu InZyBMxrBp/Gg== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 02/11] bpf: always emit struct bpf_perf_link BTF Message-ID: <20220414223704.341028-3-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net When building bpftool with !CONFIG_PERF_EVENTS: skeleton/pid_iter.bpf.c:47:14: error: incomplete definition of type 'struct bpf_perf_link' perf_link = container_of(link, struct bpf_perf_link, link); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helpers.h:74:22: note: expanded from macro 'container_of' ((type *)(__mptr - offsetof(type, member))); \ ^~~~~~~~~~~~~~~~~~~~~~ tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helpers.h:68:60: note: expanded from macro 'offsetof' #define offsetof(TYPE, MEMBER) ((unsigned long)&((TYPE *)0)->MEMBER) ~~~~~~~~~~~^ skeleton/pid_iter.bpf.c:44:9: note: forward declaration of 'struct bpf_perf_link' struct bpf_perf_link *perf_link; ^ &bpf_perf_link is being defined and used only under the ifdef. Move it out of the block and explicitly emit a BTF to fix compilation. Fixes: cbdaf71f7e65 ("bpftool: Add bpf_cookie to link output") Signed-off-by: Alexander Lobakin --- kernel/bpf/syscall.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.35.2 diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index e9621cfa09f2..34fdf27d14cf 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2952,12 +2952,12 @@ static const struct bpf_link_ops bpf_raw_tp_link_lops = { .fill_link_info = bpf_raw_tp_link_fill_link_info, }; -#ifdef CONFIG_PERF_EVENTS struct bpf_perf_link { struct bpf_link link; struct file *perf_file; }; +#ifdef CONFIG_PERF_EVENTS static void bpf_perf_link_release(struct bpf_link *link) { struct bpf_perf_link *perf_link = container_of(link, struct bpf_perf_link, link); @@ -4333,6 +4333,7 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) #endif case BPF_PROG_TYPE_PERF_EVENT: case BPF_PROG_TYPE_TRACEPOINT: + BTF_TYPE_EMIT(struct bpf_perf_link); ret = bpf_perf_link_attach(attr, prog); break; case BPF_PROG_TYPE_KPROBE: From patchwork Thu Apr 14 22:45:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12814092 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 464B3C4332F for ; Thu, 14 Apr 2022 22:45:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347196AbiDNWrz (ORCPT ); Thu, 14 Apr 2022 18:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347153AbiDNWrx (ORCPT ); Thu, 14 Apr 2022 18:47:53 -0400 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7110BC6B77 for ; Thu, 14 Apr 2022 15:45:27 -0700 (PDT) Date: Thu, 14 Apr 2022 22:45:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976323; bh=Jjx4TEjThTwWL8bj+lhR5ya+aOGQp9+e5cNVbMKzJbU=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=n1JYQEqnS0UycH2UG6rdRF0NDW9N472WSec3ZYaZEP3WdQJe6sEY8fOYa6pQDOBdN n8KwoW1Q61coy1P8wCY8gGLszNUHTwKDvm15696xiuA8j78ApsqvDyfkMtgZ16Emsr qFgZpsBF6piz0VCrrmuPaYznPT8dig9fPkTg9vphSHENpc3o3X51MeHt3Z8UuaPibu dBKc0hQoG/Q2AVm6EWq3QzG2b5A3fa3WbRKOTPt1VVTl/7k+9vfWIBxus5+8owcR+B xU2HYkr/S5czp89OwOV035PGE7HAeeZcuNkP9UoLJWEaE3NimsNNbjEJlF0n7asDZa 5+VuryUcvrAiQ== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 03/11] tools, bpf: fix bpftool build with !CONFIG_BPF_EVENTS Message-ID: <20220414223704.341028-4-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Fix the following error when building bpftool: CLANG profiler.bpf.o CLANG pid_iter.bpf.o skeleton/profiler.bpf.c:18:21: error: invalid application of 'sizeof' to an incomplete type 'struct bpf_perf_event_value' __uint(value_size, sizeof(struct bpf_perf_event_value)); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helpers.h:13:39: note: expanded from macro '__uint' ^~~ tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helper_defs.h:7:8: note: forward declaration of 'struct bpf_perf_event_value' struct bpf_perf_event_value; ^ struct bpf_perf_event_value is being used in the kernel only when CONFIG_BPF_EVENTS is enabled, so it misses a BTF entry then. Emit the type unconditionally to fix the problem. Fixes: 47c09d6a9f67 ("bpftool: Introduce "prog profile" command") Signed-off-by: Alexander Lobakin Acked-by: Song Liu --- kernel/bpf/syscall.c | 1 + 1 file changed, 1 insertion(+) -- 2.35.2 diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 34fdf27d14cf..dd8284a60a8e 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -4286,6 +4286,7 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) goto out; case BPF_PROG_TYPE_PERF_EVENT: case BPF_PROG_TYPE_TRACEPOINT: + BTF_TYPE_EMIT(struct bpf_perf_event_value); if (attr->link_create.attach_type != BPF_PERF_EVENT) { ret = -EINVAL; goto out; From patchwork Thu Apr 14 22:45:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12814093 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4EC4C433FE for ; Thu, 14 Apr 2022 22:45:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347190AbiDNWsQ (ORCPT ); Thu, 14 Apr 2022 18:48:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241321AbiDNWsO (ORCPT ); Thu, 14 Apr 2022 18:48:14 -0400 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 683F4C6B76; Thu, 14 Apr 2022 15:45:47 -0700 (PDT) Date: Thu, 14 Apr 2022 22:45:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976343; bh=N1CwAcVop9zqLRsxrEXTkTy/S/preizWU4aYyhoZHhM=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=A22Iq2lQ4+bvKuiiH5ymI5leLRm2NdvbTRbCKTbTSPbG9FrsxL4lhq+6lvrKqyYVX f+jqjmtNimSu19D0n3qDygcmD1jdvQp+kYlfG4OE2s1GwAZu6kcwmnJpwpHSULv6+v YkJ5usrs7vsKBaD8n69R3nMgGX9KrJaF6R7iOUOKjdFww7hAJvnC1d9tJpqlb9w7w0 RTW+fAuYbwCvz+VXBdIHc/UwvFj62SsB67Zxs+5vY9lCY5WUkeQCMLmyZhuRgubjMN /7zWr9JFt/FO+dtUcBPTOTDQ8qvU4HV/xO4vF3lssWb3vjzIWPUYjhNE8V6O1LHI/T SDUZPwx38pcAw== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 04/11] samples: bpf: add 'asm/mach-generic' include path for every MIPS Message-ID: <20220414223704.341028-5-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Fix the following: In file included from samples/bpf/tracex2_kern.c:7: In file included from ./include/linux/skbuff.h:13: In file included from ./include/linux/kernel.h:22: In file included from ./include/linux/bitops.h:33: In file included from ./arch/mips/include/asm/bitops.h:20: In file included from ./arch/mips/include/asm/barrier.h:11: ./arch/mips/include/asm/addrspace.h:13:10: fatal error: 'spaces.h' file not found #include ^~~~~~~~~~ 'arch/mips/include/asm/mach-generic' should always be included as many other MIPS include files rely on this. Move it from under CONFIG_MACH_LOONGSON64 to let it be included for every MIPS. Fixes: 058107abafc7 ("samples/bpf: Add include dir for MIPS Loongson64 to fix build errors") Signed-off-by: Alexander Lobakin Acked-by: Song Liu --- samples/bpf/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.35.2 diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 8fff5ad3444b..97203c0de252 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -193,8 +193,8 @@ ifeq ($(ARCH), mips) TPROGS_CFLAGS += -D__SANE_USERSPACE_TYPES__ ifdef CONFIG_MACH_LOONGSON64 BPF_EXTRA_CFLAGS += -I$(srctree)/arch/mips/include/asm/mach-loongson64 -BPF_EXTRA_CFLAGS += -I$(srctree)/arch/mips/include/asm/mach-generic endif +BPF_EXTRA_CFLAGS += -I$(srctree)/arch/mips/include/asm/mach-generic endif TPROGS_CFLAGS += -Wall -O2 From patchwork Thu Apr 14 22:45:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12814094 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0346C433EF for ; Thu, 14 Apr 2022 22:46:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347238AbiDNWsf (ORCPT ); Thu, 14 Apr 2022 18:48:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347253AbiDNWsa (ORCPT ); Thu, 14 Apr 2022 18:48:30 -0400 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4BEAC6EF0; Thu, 14 Apr 2022 15:45:59 -0700 (PDT) Date: Thu, 14 Apr 2022 22:45:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976355; bh=4UBxbz5wf4h5VLr17g7++AvyCOaKrTuecaQ7HkJeJ4c=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=MooR0+CEAV4XbA72GQZXTEX0qrP/7bHt4An7MuN15EsMiCeJbogR0SuNVdOa0OE6z i5+DpHyyLJJ93Op7sWb/op+qLU0EmssLRgsQvozEzp9XCuYj6OxIshSNSU9RqC/0Oh rUaMn5VIHKUuG4Vr7yn/ye0MEfT3ZHK0QwLU+Z3HP7UjnJLtV8rbSCsNs2o9lknyl3 zDaxvV7foY/Do1y9UGcYfDuYlthxRsfNMA15DpXT7vIEl4izRnpnOpeCivqxQ1q0Ma f68vfMrSc7K+gHtcmWUFMHgeMGPcdlBaL1OiaRrmvwFuNffHMfOdFLnVH4nCscDzqr +qg809I6lI6qQ== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 05/11] samples: bpf: use host bpftool to generate vmlinux.h, not target Message-ID: <20220414223704.341028-6-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Use the host build of bpftool (bootstrap) instead of the target one to generate vmlinux.h/skeletons for the BPF samples. Otherwise, when host != target, samples compilation fails with: /bin/sh: line 1: samples/bpf/bpftool/bpftool: failed to exec: Exec format error Fixes: 384b6b3bbf0d ("samples: bpf: Add vmlinux.h generation support") Signed-off-by: Alexander Lobakin Acked-by: Kumar Kartikeya Dwivedi Acked-by: Song Liu --- samples/bpf/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.35.2 diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 97203c0de252..02f999a8ef84 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -291,12 +291,13 @@ $(LIBBPF): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool BPFTOOL_OUTPUT := $(abspath $(BPF_SAMPLES_PATH))/bpftool -BPFTOOL := $(BPFTOOL_OUTPUT)/bpftool +BPFTOOL := $(BPFTOOL_OUTPUT)/bootstrap/bpftool $(BPFTOOL): $(LIBBPF) $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT) $(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../ \ OUTPUT=$(BPFTOOL_OUTPUT)/ \ LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/ \ - LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/ + LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/ \ + bootstrap $(LIBBPF_OUTPUT) $(BPFTOOL_OUTPUT): $(call msg,MKDIR,$@) From patchwork Thu Apr 14 22:46:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12814095 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC5B3C433F5 for ; Thu, 14 Apr 2022 22:46:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347274AbiDNWsq (ORCPT ); Thu, 14 Apr 2022 18:48:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235898AbiDNWsl (ORCPT ); Thu, 14 Apr 2022 18:48:41 -0400 X-Greylist: delayed 92 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 14 Apr 2022 15:46:15 PDT Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50E9DC6B76; Thu, 14 Apr 2022 15:46:15 -0700 (PDT) Date: Thu, 14 Apr 2022 22:46:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976373; bh=+DkRIXJc5M3gz3F1I0xigPA/k06QlcMXGhroeUqQePw=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=HQiMjgfKOjR3X8TVweXIVyu1t4Gd2yBQvkpZ6YSQzI+fFkGQoNk7nXgVD2uZ4EXNT eo3BJ/Xd/bWnrp/ClkfhLYLMO2GoXnTWE9gvTnCv6qf8ceUb6jJE1+lKhJ1LONCpxy ELnrljzwRInDfLKRtetJn7/Y4YBka9BOd4B5EeDJaDIM+mtxVHHBQO7D/933Hj9Z91 Ea7hngMlNPpGn4g4EizCKziBbiPYdnbdv/YiIR7zzgV3hk4zo0v0HEOyUquzjzIO+O 8d7ZdZLYnTtFuHzvzi+WsZx8plerCzOqB6eqW30tVoPH8mDFimIu7dBPyyjVb8uYFo 4me2Zigwe515w== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 06/11] tools, bpf: fix fcntl.h include in bpftool Message-ID: <20220414223704.341028-7-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Fix the following (on some libc implementations): CC tracelog.o In file included from tracelog.c:12: include/sys/fcntl.h:1:2: warning: #warning redirecting incorrect #include to [-Wcpp] 1 | #warning redirecting incorrect #include to | ^~~~~~~ is anyway just a wrapper over (backcomp stuff). Fixes: 30da46b5dc3a ("tools: bpftool: add a command to dump the trace pipe") Signed-off-by: Alexander Lobakin Acked-by: Song Liu --- tools/bpf/bpftool/tracelog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.35.2 diff --git a/tools/bpf/bpftool/tracelog.c b/tools/bpf/bpftool/tracelog.c index e80a5c79b38f..bf1f02212797 100644 --- a/tools/bpf/bpftool/tracelog.c +++ b/tools/bpf/bpftool/tracelog.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include "main.h" From patchwork Thu Apr 14 22:46:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12814096 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3712BC4332F for ; Thu, 14 Apr 2022 22:46:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347296AbiDNWtD (ORCPT ); Thu, 14 Apr 2022 18:49:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347277AbiDNWs7 (ORCPT ); Thu, 14 Apr 2022 18:48:59 -0400 Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86956C6F00; Thu, 14 Apr 2022 15:46:32 -0700 (PDT) Date: Thu, 14 Apr 2022 22:46:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976390; bh=LiFwMTDd2fdSlZNNJT9AWOWlwaivKQ5qk8KaEcQEfrs=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=fiN8lGwSeXi6yQVq95169CY5q0fzkvN7gW6UYs2Gv4qL+WDStjwwjCQh0hCFYvksU KnswdJkdUtU5G9GqL5Gxkii4Kk5V4ypSMXwAFRhB8ERjsorTeeAsUqVoT+zdEMMnjf oJiycRhG9r7gmPG8gH0louf++DYLLAv75knuCVPX+ca7M2uTv/1VQdT18IzG6xzs/a 6g4MF5ZXxirNHeYPobCikPiutt8fL50asp7vfCzUqKz1WsQRnWgrgFEHA5NMdKI4K0 ZaO3DghoEjFcnwImnLGE3V49hSOiewYZfIPHt/9yi4wVZ+k81z8SzXwdnbzSqnD24V tQqte9gKKFnUQ== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 07/11] samples: bpf: fix uin64_t format literals Message-ID: <20220414223704.341028-8-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net There's a couple places where uin64_t is being passed as an %ld format argument, which is incorrect (should be %lld). Fix them. Fixes: 51570a5ab2b7 ("A Sample of using socket cookie and uid for traffic monitoring") Fixes: 00f660eaf378 ("Sample program using SO_COOKIE") Signed-off-by: Alexander Lobakin --- samples/bpf/cookie_uid_helper_example.c | 12 ++++++------ samples/bpf/lwt_len_hist_user.c | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) -- 2.35.2 diff --git a/samples/bpf/cookie_uid_helper_example.c b/samples/bpf/cookie_uid_helper_example.c index f0df3dda4b1f..1b98debb6019 100644 --- a/samples/bpf/cookie_uid_helper_example.c +++ b/samples/bpf/cookie_uid_helper_example.c @@ -207,9 +207,9 @@ static void print_table(void) error(1, errno, "fail to get entry value of Key: %u\n", curN); } else { - printf("cookie: %u, uid: 0x%x, Packet Count: %lu," - " Bytes Count: %lu\n", curN, curEntry.uid, - curEntry.packets, curEntry.bytes); + printf("cookie: %u, uid: 0x%x, Packet Count: %llu, Bytes Count: %llu\n", + curN, curEntry.uid, curEntry.packets, + curEntry.bytes); } } } @@ -265,9 +265,9 @@ static void udp_client(void) if (res < 0) error(1, errno, "lookup sk stat failed, cookie: %lu\n", cookie); - printf("cookie: %lu, uid: 0x%x, Packet Count: %lu," - " Bytes Count: %lu\n\n", cookie, dataEntry.uid, - dataEntry.packets, dataEntry.bytes); + printf("cookie: %llu, uid: 0x%x, Packet Count: %llu, Bytes Count: %llu\n\n", + cookie, dataEntry.uid, dataEntry.packets, + dataEntry.bytes); } close(s_send); close(s_rcv); diff --git a/samples/bpf/lwt_len_hist_user.c b/samples/bpf/lwt_len_hist_user.c index 430a4b7e353e..4ef22571aa67 100644 --- a/samples/bpf/lwt_len_hist_user.c +++ b/samples/bpf/lwt_len_hist_user.c @@ -44,7 +44,7 @@ int main(int argc, char **argv) while (bpf_map_get_next_key(map_fd, &key, &next_key) == 0) { if (next_key >= MAX_INDEX) { - fprintf(stderr, "Key %lu out of bounds\n", next_key); + fprintf(stderr, "Key %llu out of bounds\n", next_key); continue; } @@ -66,7 +66,7 @@ int main(int argc, char **argv) for (i = 1; i <= max_key + 1; i++) { stars(starstr, data[i - 1], max_value, MAX_STARS); - printf("%8ld -> %-8ld : %-8ld |%-*s|\n", + printf("%8ld -> %-8ld : %-8lld |%-*s|\n", (1l << i) >> 1, (1l << i) - 1, data[i - 1], MAX_STARS, starstr); } From patchwork Thu Apr 14 22:46:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12814097 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43E83C433FE for ; Thu, 14 Apr 2022 22:46:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347301AbiDNWtT (ORCPT ); Thu, 14 Apr 2022 18:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347288AbiDNWtR (ORCPT ); Thu, 14 Apr 2022 18:49:17 -0400 X-Greylist: delayed 98 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 14 Apr 2022 15:46:49 PDT Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54D74C6F32; Thu, 14 Apr 2022 15:46:49 -0700 (PDT) Date: Thu, 14 Apr 2022 22:46:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976407; bh=gD40bE7CA3nEbFCC4RvOWqz3pW6a2RcS6zm8BhERlxo=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=C1aVC6ihmrjtj8lQuyquB9RBqnf8GaT44/TGR+XaxR8nMZ6x6GWtkAvp8QODJgNz8 vAJmQjrWys4Iqn092ieJH35uZoJF5SgB4ShAOb5Wk/eHnQ3gyj9uwuyxK2+Oyygvkt DtJvm1Cscy0q8/NH2foPjX32AXJIIN+clYH+TL/n4wLU6NUng5qdiKwFFVhmrhlxDE YzrkoThbgG/wTXEJm6NoxJ7B6CVsgDl9P8LXzlU8dmjKuD6TXAPVgPFPiwdrtcp/kO 7RPD+732T0+G/q+rw91CjFDWYvqbPLM80ceEDcuL/Qm2Yw8HUVPPmYEb6WnbcwPiyI RmmdX98keMNzA== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 08/11] samples: bpf: fix shifting unsigned long by 32 positions Message-ID: <20220414223704.341028-9-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net On 32 bit systems, shifting an unsigned long by 32 positions yields the following warning: samples/bpf/tracex2_kern.c:60:23: warning: shift count >= width of type [-Wshift-count-overflow] unsigned int hi = v >> 32; ^ ~~ The usual way to avoid this is to shift by 16 two times (see upper_32_bits() macro in the kernel). Use it across the BPF sample code as well. Fixes: d822a1926849 ("samples/bpf: Add counting example for kfree_skb() function calls and the write() syscall") Fixes: 0fb1170ee68a ("bpf: BPF based latency tracing") Fixes: f74599f7c530 ("bpf: Add tests and samples for LWT-BPF") Signed-off-by: Alexander Lobakin Acked-by: Song Liu --- samples/bpf/lathist_kern.c | 2 +- samples/bpf/lwt_len_hist_kern.c | 2 +- samples/bpf/tracex2_kern.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) -- 2.35.2 diff --git a/samples/bpf/lathist_kern.c b/samples/bpf/lathist_kern.c index 4adfcbbe6ef4..9744ed547abe 100644 --- a/samples/bpf/lathist_kern.c +++ b/samples/bpf/lathist_kern.c @@ -53,7 +53,7 @@ static unsigned int log2(unsigned int v) static unsigned int log2l(unsigned long v) { - unsigned int hi = v >> 32; + unsigned int hi = (v >> 16) >> 16; if (hi) return log2(hi) + 32; diff --git a/samples/bpf/lwt_len_hist_kern.c b/samples/bpf/lwt_len_hist_kern.c index 1fa14c54963a..bf32fa04c91f 100644 --- a/samples/bpf/lwt_len_hist_kern.c +++ b/samples/bpf/lwt_len_hist_kern.c @@ -49,7 +49,7 @@ static unsigned int log2(unsigned int v) static unsigned int log2l(unsigned long v) { - unsigned int hi = v >> 32; + unsigned int hi = (v >> 16) >> 16; if (hi) return log2(hi) + 32; else diff --git a/samples/bpf/tracex2_kern.c b/samples/bpf/tracex2_kern.c index 5bc696bac27d..6bf22056ff95 100644 --- a/samples/bpf/tracex2_kern.c +++ b/samples/bpf/tracex2_kern.c @@ -57,7 +57,7 @@ static unsigned int log2(unsigned int v) static unsigned int log2l(unsigned long v) { - unsigned int hi = v >> 32; + unsigned int hi = (v >> 16) >> 16; if (hi) return log2(hi) + 32; else From patchwork Thu Apr 14 22:46:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12814098 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 341CCC433EF for ; Thu, 14 Apr 2022 22:47:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347345AbiDNWtl (ORCPT ); Thu, 14 Apr 2022 18:49:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345500AbiDNWtb (ORCPT ); Thu, 14 Apr 2022 18:49:31 -0400 Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 236C5C8BFD; Thu, 14 Apr 2022 15:47:02 -0700 (PDT) Date: Thu, 14 Apr 2022 22:46:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976420; bh=PEDAO2gdSiFRYDFQPzekiNHelP6dYcLV8W7h2o7bylk=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=QHoSlbFjf/Kt42k1QML0xtJ8oejvL8X+tAEFv/nsHe8Ff3PQZtHTi++9Iq/59YmQS 1hDTnY12ldGaBakqr4D2UDRXQF7k6Z2xQC1OKyyExd2OINI7yc3czb+qPnHfpc/y1K jtMmDIyGRHjNUjk0UCdJQWl5TbEQ66u8D48Y585iGQ7ub2ue37KezYbyTwTYxyoYOb Dtj8qPuqHXVW6bsioTlJMuxWbUdxSIo6kyKln9JaBA4i/A9nuvFLOty4a/IpeUxrfG YuIroPBF0Jn9brL75ErSOdvivLhH2gHzVDyXFJSg/4vUUufqjTWCGOcgT6PE4Eb1Qw Xg8wGvE7ccFzg== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 09/11] samples: bpf: fix include order for non-Glibc environments Message-ID: <20220414223704.341028-10-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Some standard C library implementations, e.g. Musl, ship the UAPI definitions themselves to not be dependent on the UAPI headers and their versions. Their kernel UAPI counterparts are usually guarded with some definitions which the formers set in order to avoid duplicate definitions. In such cases, include order matters. Change it in two samples: in the first, kernel UAPI ioctl definitions should go before the libc ones, and the opposite story with the second, where the kernel includes should go later to avoid struct redefinitions. Fixes: b4b8faa1ded7 ("samples/bpf: sample application and documentation for AF_XDP sockets") Fixes: e55190f26f92 ("samples/bpf: Fix build for task_fd_query_user.c") Signed-off-by: Alexander Lobakin Acked-by: Song Liu --- samples/bpf/task_fd_query_user.c | 2 +- samples/bpf/xdpsock_user.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) -- 2.35.2 diff --git a/samples/bpf/task_fd_query_user.c b/samples/bpf/task_fd_query_user.c index 424718c0872c..5d3a60547f9f 100644 --- a/samples/bpf/task_fd_query_user.c +++ b/samples/bpf/task_fd_query_user.c @@ -9,10 +9,10 @@ #include #include #include +#include #include #include #include -#include #include #include diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c index be7d2572e3e6..399b999fcec2 100644 --- a/samples/bpf/xdpsock_user.c +++ b/samples/bpf/xdpsock_user.c @@ -7,14 +7,15 @@ #include #include #include -#include #include #include +#include #include #include #include #include #include +#include #include #include #include From patchwork Thu Apr 14 22:47:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12814099 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D034DC433EF for ; Thu, 14 Apr 2022 22:47:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347332AbiDNWtt (ORCPT ); Thu, 14 Apr 2022 18:49:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347310AbiDNWtl (ORCPT ); Thu, 14 Apr 2022 18:49:41 -0400 Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00F51C8BF1 for ; Thu, 14 Apr 2022 15:47:14 -0700 (PDT) Date: Thu, 14 Apr 2022 22:47:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976433; bh=THMmkXXMS2lPNNZpAKvu3GAAetFAVRpTegVE6Ot/KkU=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=OXkMtj7iaWudLwGUwWTU7oX0NF7hArQWxhthVlcg3TIgPYTx8RSG42gqGiU0Cve2y BYUA9IRlAcKYpB5XNnNj4k722gX0u+C8vCyNGLg7RNfRkuQHvESq2c5D/kPWDzUDYX A/XxycqH1wvrAZuxlVmH94RVwUOQpoiaEIwfXOhor/M9wvCZfKI2z6k1RuLbsF7P8Q PwsttRM3exP3+TixGhFGgbb4dIM1Y7iyQ+f3v9LpeadgCzMQ+EDKRN71eUoZA+PsFQ DH7TZBmw8kyGraPfnf+/a1OXNifL7FRvUSS78NRqVmrT2SuuXgab8WjmEUww+SeRvE iiARFXOmOeWiw== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 10/11] samples: bpf: fix -Wsequence-point Message-ID: <20220414223704.341028-11-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net In some libc implementations, CPU_SET() may utilize its first argument several times. When combined with a post-increment, it leads to: samples/bpf/test_lru_dist.c:233:36: warning: operation on 'next_to_try' may be undefined [-Wsequence-point] 233 | CPU_SET(next_to_try++, &cpuset); | ^ Split the sentence into two standalone operations to fix this. Fixes: 5db58faf989f ("bpf: Add tests for the LRU bpf_htab") Signed-off-by: Alexander Lobakin Acked-by: Song Liu --- samples/bpf/test_lru_dist.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.35.2 diff --git a/samples/bpf/test_lru_dist.c b/samples/bpf/test_lru_dist.c index be98ccb4952f..191643ec501e 100644 --- a/samples/bpf/test_lru_dist.c +++ b/samples/bpf/test_lru_dist.c @@ -229,7 +229,8 @@ static int sched_next_online(int pid, int next_to_try) while (next_to_try < nr_cpus) { CPU_ZERO(&cpuset); - CPU_SET(next_to_try++, &cpuset); + CPU_SET(next_to_try, &cpuset); + next_to_try++; if (!sched_setaffinity(pid, sizeof(cpuset), &cpuset)) break; } From patchwork Thu Apr 14 22:47:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12814100 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 655CDC4332F for ; Thu, 14 Apr 2022 22:47:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347361AbiDNWuO (ORCPT ); Thu, 14 Apr 2022 18:50:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347356AbiDNWuB (ORCPT ); Thu, 14 Apr 2022 18:50:01 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C84C74A4; Thu, 14 Apr 2022 15:47:33 -0700 (PDT) Date: Thu, 14 Apr 2022 22:47:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976451; bh=wBk9JjddsWdkPL3+TnZwqvhbFqPlgDryFkVFtACVs5s=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=nOwFrCMQqgdnT5ACg0miHsryQvMGaVe1VVs6T+wkBBVk40W6TE0Oxjlsqbiiqtd4i IL3o3iY4Fmhszf3elBnEFfupsT+BLDg2f0H4qXtRtsemsQkLk8jIQ9ZubVi6/8Mj0C WSO0kpOQNupTzmMubOERMBBZKtgMtH9nko71yWrOKqgqTgLI6YoUgUiUMxyn77ZNzn B4gmE8cw6m7FaO8iBFxmb5lmu/zAbxSCDY+JMXFJ2mue0BKKsVwYAGHThryC4JPvB7 hqVfIWqC1Bv4OFOZY6FypF77uCtCS32X6gX/aV7jChafN1KUc8WV9PUzrVlWlFTDd0 50OCb5uCi1WOQ== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 11/11] samples: bpf: xdpsock: fix -Wmaybe-uninitialized Message-ID: <20220414223704.341028-12-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Fix two sort-of-false-positives in the xdpsock userspace part: samples/bpf/xdpsock_user.c: In function 'main': samples/bpf/xdpsock_user.c:1531:47: warning: 'tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized] 1531 | pktgen_hdr->tv_usec = htonl(tv_usec); | ^~~~~~~~~~~~~~ samples/bpf/xdpsock_user.c:1500:26: note: 'tv_usec' was declared here 1500 | u32 idx, tv_sec, tv_usec; | ^~~~~~~ samples/bpf/xdpsock_user.c:1530:46: warning: 'tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized] 1530 | pktgen_hdr->tv_sec = htonl(tv_sec); | ^~~~~~~~~~~~~ samples/bpf/xdpsock_user.c:1500:18: note: 'tv_sec' was declared here 1500 | u32 idx, tv_sec, tv_usec; | ^~~~~~ Both variables are always initialized when @opt_tstamp == true and they're being used also only when @opt_tstamp == true. However, that variable comes from the BSS and is being toggled from another function. They can't be executed simultaneously to actually trigger undefined behaviour, but purely technically it is a correct warning. Just initialize them with zeroes. Fixes: eb68db45b747 ("samples/bpf: xdpsock: Add timestamp for Tx-only operation") Signed-off-by: Alexander Lobakin Acked-by: Maciej Fijalkowski Acked-by: Song Liu --- samples/bpf/xdpsock_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.35.2 diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c index 399b999fcec2..1dc7ad5dbef4 100644 --- a/samples/bpf/xdpsock_user.c +++ b/samples/bpf/xdpsock_user.c @@ -1496,7 +1496,7 @@ static void rx_drop_all(void) static int tx_only(struct xsk_socket_info *xsk, u32 *frame_nb, int batch_size, unsigned long tx_ns) { - u32 idx, tv_sec, tv_usec; + u32 idx, tv_sec = 0, tv_usec = 0; unsigned int i; while (xsk_ring_prod__reserve(&xsk->tx, batch_size, &idx) <