From patchwork Thu Feb 1 17:20:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13541484 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DE565B036 for ; Thu, 1 Feb 2024 17:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808072; cv=none; b=T5ITV6HuIiYwrZBuTc2A6k3KvtX01G1HtBVmWyCIExMVaUgTzEXYxpSe/SC9EtNDHauMOGOKoQDv3ghTXODIsBhged1g00LnZMVlHnwRSc3R1sexnlqbfuOfOvDfNXnSjVcLfDiQ+smc5L356RpSECBk1ZLXKr5XuFYcRTCqYHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808072; c=relaxed/simple; bh=Z8jg+TiWfdlbJURhufvnuM+daxABoZjXXHNRN58Q0Hc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GDHDyJ4c6aF0+NBj0QNXbbl5t0ISVZ/GXL3xUXmh6/9spmw+SvrLbF7Ig/O1fFSJhgD12E1Vx+8Zke2h/wsb1AA32g1qEOXlTo/QQ8ZSi254EA4bIOv6QPIMQaPurmqfSKNGkHtZaJH2oDS1nY3Qkcgo54nMRjA/7X6cJCRH3M0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HEMHIeJM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HEMHIeJM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47F54C433C7; Thu, 1 Feb 2024 17:21:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706808072; bh=Z8jg+TiWfdlbJURhufvnuM+daxABoZjXXHNRN58Q0Hc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HEMHIeJMyJlcGpusOHljwCvuM65qSBKKfufH8ZDUO6s2PjrkNwVnKToDrKzRRdQh8 FQDrzvBbJmHM11GXm+9+k4KWaueHqtsqdhkAUAL9k1r7Q/LpIxuRdTJnjZ4ZlVJe0B 9YaajRqZhn/Uxjl2SF5BwiwzRLBK2e9w+4xvViBy8qgpZFjZ/RwJG/nRWmEmGVRQWv RTRwFByG6f1oMBNGgl68pRYz7uwSof7t9Nj1NhxJGUuH1tcssFoZSbPUqNF+DTGkEy CgtWYO7l1apchgUben5WVI/lXob0NsOJ3ETKMeyVxH/vcDzJNiP23i0J+KwYFRXI4l f2xkjky6pBmEg== From: Andrii Nakryiko To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, martin.lau@kernel.org Cc: andrii@kernel.org, kernel-team@meta.com Subject: [PATCH v2 bpf-next 1/5] libbpf: call memfd_create() syscall directly Date: Thu, 1 Feb 2024 09:20:23 -0800 Message-Id: <20240201172027.604869-2-andrii@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201172027.604869-1-andrii@kernel.org> References: <20240201172027.604869-1-andrii@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Some versions of Android do not implement memfd_create() wrapper in their libc implementation, leading to build failures ([0]). On the other hand, memfd_create() is available as a syscall on quite old kernels (3.17+, while bpf() syscall itself is available since 3.18+), so it is ok to assume that syscall availability and call into it with syscall() helper to avoid Android-specific workarounds. Validated in libbpf-bootstrap's CI ([1]). [0] https://github.com/libbpf/libbpf-bootstrap/actions/runs/7701003207/job/20986080319#step:5:83 [1] https://github.com/libbpf/libbpf-bootstrap/actions/runs/7715988887/job/21031767212?pr=253 Signed-off-by: Andrii Nakryiko --- tools/lib/bpf/libbpf.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index f6953d7faff1..6932f2c4ddfd 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1525,11 +1525,20 @@ static Elf64_Sym *find_elf_var_sym(const struct bpf_object *obj, const char *nam return ERR_PTR(-ENOENT); } +/* Some versions of Android don't provide memfd_create() in their libc + * implementation, so avoid complications and just go straight to Linux + * syscall. + */ +static int sys_memfd_create(const char *name, unsigned flags) +{ + return syscall(__NR_memfd_create, name, flags); +} + static int create_placeholder_fd(void) { int fd; - fd = ensure_good_fd(memfd_create("libbpf-placeholder-fd", MFD_CLOEXEC)); + fd = ensure_good_fd(sys_memfd_create("libbpf-placeholder-fd", MFD_CLOEXEC)); if (fd < 0) return -errno; return fd; From patchwork Thu Feb 1 17:20:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13541485 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEA545B036 for ; Thu, 1 Feb 2024 17:21:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808075; cv=none; b=smvfJ0YqBe1PMHpIvSLEiAx1p9B804GSvjl1Rv54Tk982iS8Ll+LLdP/OvA/innGjuYQyfsX1aw2pZzrdLAoJU/9ixgioIe+OWunY6MksVeGwKftLCQal8ZaQxeCCjdFFkZ7T/y5vmw41zYCxxJFSEhjbf1CpgOAMGfxophi0VI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808075; c=relaxed/simple; bh=L+eZFxcUFuMBBvoa3ThQWD/xOVAWLnTTYQNuKJHiaaI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n3xa6jGk2yBf1L4kL7i4WKjwNN8JncXMasETHRe0jZPASwm1GMF2iW7RejtamJtCB3OCOQSSWeBHqgGe3BYgduBUzXCnB7z4aLHPNNp4Blev1qVuZE3Atfmy6flk7BxZ39hPY2K50l0RfILzeE96JL93tKjLAVSxxnwMKvPYPKg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dP2t6ZUA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dP2t6ZUA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C82CC433F1; Thu, 1 Feb 2024 17:21:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706808075; bh=L+eZFxcUFuMBBvoa3ThQWD/xOVAWLnTTYQNuKJHiaaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dP2t6ZUAXbsK/8dxbE94DP92Zwh8o9Rmmx9fhcNACe7fESuy8Ot0R0Cdz5lv+itI2 JhKmGdT2obS70F6d/JpdgaxNDkK6g3soYujX73BGx7U37ZA7btc+sMumgKTNRwl5ho A93PDDVdR3EphhIkdo9mlzF4Ir+pzwIXXyMk43+p8F3iYOcAnFNzoXMGmieo+hSgBc sg3+87c1TsWfKBXEJfuIM2wbfLwM0MaDH23MyLtI0oG5WR1IewdI5mSkViH5hT9Q7Z lqzyAZUphJ6AHhWjL87pnCgJNe6O4b3ndRCVn8cGJB63FtvfiRNMlcxnG3UlebG9e1 6AixeFrDf9/iA== From: Andrii Nakryiko To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, martin.lau@kernel.org Cc: andrii@kernel.org, kernel-team@meta.com Subject: [PATCH v2 bpf-next 2/5] libbpf: add missing LIBBPF_API annotation to libbpf_set_memlock_rlim API Date: Thu, 1 Feb 2024 09:20:24 -0800 Message-Id: <20240201172027.604869-3-andrii@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201172027.604869-1-andrii@kernel.org> References: <20240201172027.604869-1-andrii@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net LIBBPF_API annotation seems missing on libbpf_set_memlock_rlim API, so add it to make this API callable from libbpf's shared library version. Fixes: e542f2c4cd16 ("libbpf: Auto-bump RLIMIT_MEMLOCK if kernel needs it for BPF") Fixes: ab9a5a05dc48 ("libbpf: fix up few libbpf.map problems") Signed-off-by: Andrii Nakryiko --- tools/lib/bpf/bpf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 1441f642c563..f866e98b2436 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -35,7 +35,7 @@ extern "C" { #endif -int libbpf_set_memlock_rlim(size_t memlock_bytes); +LIBBPF_API int libbpf_set_memlock_rlim(size_t memlock_bytes); struct bpf_map_create_opts { size_t sz; /* size of this struct for forward/backward compatibility */ From patchwork Thu Feb 1 17:20:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13541486 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFA525B046 for ; Thu, 1 Feb 2024 17:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808079; cv=none; b=nVm1/59YDmY/r9ibgPQThYyLqu1cLqzxHHl38JPVyBs2ZH764e9YAtClziNk6S87bqMCMh0RsDNDsYrRawcQHFuomt0PF1F1q6M5H+sdCZs8Wfo7NROdcDywdUsGLfPt6lRvskx8VOXoPdBmI15eDL26d+KYIz93LYpq1LSPdtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808079; c=relaxed/simple; bh=rftYcHmlmMv34x7ss8O92q4W1IC5dTwHXDosWC6JSvA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jcAd3yezljEaUxIHEN5IP0yCmpl4SatwazDCeX8ClKzKRSYDfvz3b+Mp7ZtqGJntJFvBv20eSxgl2Qy8jvs/0ATsDlcJbeGBMmPax358u6dkf2LVyZ6/dWVNtYLjeVgASZYT4Sxa789vNWb79zC3je8Iui4uTGNwkbZTD5+jbz8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c2qzAs0F; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c2qzAs0F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A94A0C433C7; Thu, 1 Feb 2024 17:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706808078; bh=rftYcHmlmMv34x7ss8O92q4W1IC5dTwHXDosWC6JSvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c2qzAs0FNNY5Us1BHvBh4AXl/EZXVuVGtwKGy5Q77dMWWu0JcK8sA1DNJ+OFD+f/E yplcnUtl7X04Ju1dg0a0A4lyVoqLoNZtbTsgEC5OLcfDGdo8A2dHoEx9n7LR7QAvAj v+oSUz6gDQg2qHzvAvPg+cSYVjQCmWZP+8JxPjmfd2T4kH4Du6i8kj0hcGfjFSiOZ/ /PI5QogGlJG9Dp4Jk01SdukgxxLhWjuzCNGpymlveijYAug1cOxiaUymUy8XEzMfq0 9ePJ7h9n+r3q6/wYlmaVlisZ5ldHjhSJN/kgIaOE85qqJSruNjhbawv3xdehUCFob0 8XPWrAYnLuk/g== From: Andrii Nakryiko To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, martin.lau@kernel.org Cc: andrii@kernel.org, kernel-team@meta.com Subject: [PATCH v2 bpf-next 3/5] libbpf: add btf__new_split() API that was declared but not implemented Date: Thu, 1 Feb 2024 09:20:25 -0800 Message-Id: <20240201172027.604869-4-andrii@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201172027.604869-1-andrii@kernel.org> References: <20240201172027.604869-1-andrii@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Seems like original commit adding split BTF support intended to add btf__new_split() API, and even declared it in libbpf.map, but never added (trivial) implementation. Fix this. Fixes: ba451366bf44 ("libbpf: Implement basic split BTF support") Signed-off-by: Andrii Nakryiko --- tools/lib/bpf/btf.c | 5 +++++ tools/lib/bpf/libbpf.map | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 95db88b36cf3..845034d15420 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -1079,6 +1079,11 @@ struct btf *btf__new(const void *data, __u32 size) return libbpf_ptr(btf_new(data, size, NULL)); } +struct btf *btf__new_split(const void *data, __u32 size, struct btf *base_btf) +{ + return libbpf_ptr(btf_new(data, size, base_btf)); +} + static struct btf *btf_parse_elf(const char *path, struct btf *base_btf, struct btf_ext **btf_ext) { diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index d9e1f57534fa..386964f572a8 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -245,7 +245,6 @@ LIBBPF_0.3.0 { btf__parse_raw_split; btf__parse_split; btf__new_empty_split; - btf__new_split; ring_buffer__epoll_fd; } LIBBPF_0.2.0; @@ -411,5 +410,7 @@ LIBBPF_1.3.0 { } LIBBPF_1.2.0; LIBBPF_1.4.0 { + global: bpf_token_create; + btf__new_split; } LIBBPF_1.3.0; From patchwork Thu Feb 1 17:20:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13541487 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 255235B038 for ; Thu, 1 Feb 2024 17:21:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808082; cv=none; b=MbOKUb7OP2/pJi7DZwjkwN69if693VL77sGtY8Pu2LWorUFy5gm2GP5/lvy2Bx4qVbPgfo4uR+y21hEULEK/VKjvfgY93LuMrDkStVdtxN4QcANy5bvgEzhFFWSx3YY8Q9GuBxWP523iDhm8ghwIWRoe5GlkLUt+vARJkf6mE1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808082; c=relaxed/simple; bh=0IqmjUKDIAH+n/U558cKShOSrC+VrizWFbQILbOrWwE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D+vutEP/EPwwhMnjWz595gK6xxYLsBFdhLVk0EDXKGqjbbEqMA2tp0Jw6gIPsNLzeqWNbbrm4WV/aOAsGdz32JpEMqHnDOZTfmRMpjM72ZV9QdOUjh3BF3NrN0SAtimooL8Hyrkaf3/TVZr061y5X2hGuRnQQ1+q1q8nFEgJSmg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ivd7LbpY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ivd7LbpY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB1BBC433C7; Thu, 1 Feb 2024 17:21:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706808082; bh=0IqmjUKDIAH+n/U558cKShOSrC+VrizWFbQILbOrWwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ivd7LbpYcthADgLuhDZFmgxcr4dO67euZ3JIwdJlUHTKgdZKSHf3Es6BnsYPocDuW xoKA4W3k5J4sHxuktAcxT5/fM2ASAyiPCjKPXTUvWpey3jibVFTJCR3h9JeDIF1t3v nMeAikHxiTqGqQ0FBRuebNBAVVrwfEuv2LxvhXIfCnpAm8rx2dQ5g/LvZIhhwpZMNq CqTcQhelVFtrF2mxUkJrvuECQKxbh79+tftGbKSDzs9Ii9gqJ86SBg17YkPrQsWSi8 FikqqTHc3rPmhFyl6tVu0p3+HHz/9iR+OL4123jR56jw/f89qkRLR4M1ubviEGOrsr ahLtFfk6bPJKQ== From: Andrii Nakryiko To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, martin.lau@kernel.org Cc: andrii@kernel.org, kernel-team@meta.com Subject: [PATCH v2 bpf-next 4/5] libbpf: add missed btf_ext__raw_data() API Date: Thu, 1 Feb 2024 09:20:26 -0800 Message-Id: <20240201172027.604869-5-andrii@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201172027.604869-1-andrii@kernel.org> References: <20240201172027.604869-1-andrii@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Another API that was declared in libbpf.map but actual implementation was missing. btf_ext__get_raw_data() was intended as a discouraged alias to consistently-named btf_ext__raw_data(), so make this an actuality. Fixes: 20eccf29e297 ("libbpf: hide and discourage inconsistently named getters") Signed-off-by: Andrii Nakryiko --- tools/lib/bpf/btf.c | 6 +++++- tools/lib/bpf/libbpf.map | 2 +- tools/lib/bpf/linker.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 845034d15420..a17b4c9c4213 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -3050,12 +3050,16 @@ struct btf_ext *btf_ext__new(const __u8 *data, __u32 size) return btf_ext; } -const void *btf_ext__get_raw_data(const struct btf_ext *btf_ext, __u32 *size) +const void *btf_ext__raw_data(const struct btf_ext *btf_ext, __u32 *size) { *size = btf_ext->data_size; return btf_ext->data; } +__attribute__((alias("btf_ext__raw_data"))) +const void *btf_ext__get_raw_data(const struct btf_ext *btf_ext, __u32 *size); + + struct btf_dedup; static struct btf_dedup *btf_dedup_new(struct btf *btf, const struct btf_dedup_opts *opts); diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 386964f572a8..86804fd90dd1 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -325,7 +325,6 @@ LIBBPF_0.7.0 { bpf_xdp_detach; bpf_xdp_query; bpf_xdp_query_id; - btf_ext__raw_data; libbpf_probe_bpf_helper; libbpf_probe_bpf_map_type; libbpf_probe_bpf_prog_type; @@ -413,4 +412,5 @@ LIBBPF_1.4.0 { global: bpf_token_create; btf__new_split; + btf_ext__raw_data; } LIBBPF_1.3.0; diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c index 16bca56002ab..0d4be829551b 100644 --- a/tools/lib/bpf/linker.c +++ b/tools/lib/bpf/linker.c @@ -2732,7 +2732,7 @@ static int finalize_btf(struct bpf_linker *linker) /* Emit .BTF.ext section */ if (linker->btf_ext) { - raw_data = btf_ext__get_raw_data(linker->btf_ext, &raw_sz); + raw_data = btf_ext__raw_data(linker->btf_ext, &raw_sz); if (!raw_data) return -ENOMEM; From patchwork Thu Feb 1 17:20:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13541488 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 555635B05A for ; Thu, 1 Feb 2024 17:21:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808085; cv=none; b=URokx/uN8B+lmQeR8vTPqzqeHwHGjTh310D59nKrX1jW1THiZaO8pAPpdGiexiog5XrRp3sBzmSXjz64ixhFGlre767DvL64+ma5K55hXaksA5MCUTjkJK51OkX8YMG/YGsqfJfCQPIFcsg3dm164f+iXWTB32+Yke7vIg4N46w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808085; c=relaxed/simple; bh=PEZPMSUWObczLBAgu3L3JjgC+2IewAJjzvR6UrgZYAE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ptBg6WaHxgM9pO1+gU/msHItOkWxTCGdMLe88h+jtNtONXCHPo+S7Du0g9F8QJta+YHF0V2ejOgJMTD7PuhfZhRtK8d7MeG7r987wxHgauRODLvjhJpVrLlawO08EFNakiDeB+IdbqUaAxWYUoRhzlLjpyU6N+Y2B8kzD9r86dI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YxK1Iee7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YxK1Iee7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08C6DC43390; Thu, 1 Feb 2024 17:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706808085; bh=PEZPMSUWObczLBAgu3L3JjgC+2IewAJjzvR6UrgZYAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YxK1Iee7u8aGR3p1ap6lcmM1BIkzBsLinF6ysDyXLlBsbL0SjYjg7EZuEZq0p4ux2 rFFgxGQ2jWMNFELCLG6t7Nf3GIlQt/yrgldeXR2zOLbQbKqZKp3Y1awE/QLo9Ywl48 QMT3XbZxVVkGcYytWEXL4eEdOX070OYrz9JpL5nRkLdnZczdW1BP0boItpswRC/BOe 0PCfYE2/nv7NfLdeH2tL87oq06oZP2GFYLdQp6XjxlPlr7cgWgCwy4WpJ3a3XsbTyt DOrL6BDuDPZ+v+QxHMfv0OSuJl899g27XyT8JchPJaFpZapJLGF/7kA5k2V8OpgGs1 BzT3djnwZvOug== From: Andrii Nakryiko To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, martin.lau@kernel.org Cc: andrii@kernel.org, kernel-team@meta.com Subject: [PATCH v2 bpf-next 5/5] selftests/bpf: fix bench runner SIGSEGV Date: Thu, 1 Feb 2024 09:20:27 -0800 Message-Id: <20240201172027.604869-6-andrii@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201172027.604869-1-andrii@kernel.org> References: <20240201172027.604869-1-andrii@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Some benchmarks don't have either "consumer" or "producer" sides. For example, trig-tp and other BPF triggering benchmarks don't have consumers, as they only do "producing" by calling into syscall or predefined uproes. As such it's valid for some benchmarks to have zero consumers or producers. So allows to specify `-c0` explicitly. This triggers another problem. If benchmark doesn't support either consumer or producer side, consumer_thread/producer_thread callback will be NULL, but benchmark runner will attempt to use those NULL callback to create threads anyways. So instead of crashing with SIGSEGV in case of misconfigured benchmark, detect the condition and report error. Signed-off-by: Andrii Nakryiko --- tools/testing/selftests/bpf/bench.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/bench.c b/tools/testing/selftests/bpf/bench.c index 73ce11b0547d..1724d50ba942 100644 --- a/tools/testing/selftests/bpf/bench.c +++ b/tools/testing/selftests/bpf/bench.c @@ -323,14 +323,14 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) break; case 'p': env.producer_cnt = strtol(arg, NULL, 10); - if (env.producer_cnt <= 0) { + if (env.producer_cnt < 0) { fprintf(stderr, "Invalid producer count: %s\n", arg); argp_usage(state); } break; case 'c': env.consumer_cnt = strtol(arg, NULL, 10); - if (env.consumer_cnt <= 0) { + if (env.consumer_cnt < 0) { fprintf(stderr, "Invalid consumer count: %s\n", arg); argp_usage(state); } @@ -607,6 +607,10 @@ static void setup_benchmark(void) bench->setup(); for (i = 0; i < env.consumer_cnt; i++) { + if (!bench->consumer_thread) { + fprintf(stderr, "benchmark doesn't support consumers!\n"); + exit(1); + } err = pthread_create(&state.consumers[i], NULL, bench->consumer_thread, (void *)(long)i); if (err) { @@ -626,6 +630,10 @@ static void setup_benchmark(void) env.prod_cpus.next_cpu = env.cons_cpus.next_cpu; for (i = 0; i < env.producer_cnt; i++) { + if (!bench->producer_thread) { + fprintf(stderr, "benchmark doesn't support producers!\n"); + exit(1); + } err = pthread_create(&state.producers[i], NULL, bench->producer_thread, (void *)(long)i); if (err) {