From patchwork Thu Oct 10 21:17:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13831150 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 D6BEE19DF61 for ; Thu, 10 Oct 2024 21:17:34 +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=1728595054; cv=none; b=fJF3tBM74T80whvrdczOr0dpsuwcgMwSrppWHAewvwsHqEm6PkmEBHw5ljJfvCMeT6B8VPQwXZyDIle2xF0pgXm0RcL8Q+88fK2HYaiAevt68tWtCBG1FGuTXREn1hY6z6PN+hiuhFl6Quwj8UZbBgOoowk5kh/fIeq+UEHzy0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728595054; c=relaxed/simple; bh=beZjZRLb/GaGdqhxvIMJzpNAodTRhru6C/1wPVsw6SI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=iSoPRjMqNu5ZqQozjUAH9DO4e3ObFZkQ8ATES7xRZNRM72i/PQG1sbvfNPNEFanRcr1fBlezLb27JRJr37TksqxIDjd1UBmNO/jdKI7PncYtjwFWZLGXR2GOu0UbXMj4CwauYOcgxtRVQP6R23gGGYtzdxGatsMI9xVErGbT4uM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=plDo/CUK; 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="plDo/CUK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C192C4CEC5; Thu, 10 Oct 2024 21:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728595054; bh=beZjZRLb/GaGdqhxvIMJzpNAodTRhru6C/1wPVsw6SI=; h=From:To:Cc:Subject:Date:From; b=plDo/CUKR6paRbY03Qw4AYEtzrQTT8ytrWdLvIR7wwWCQJrACpRgHLgzgGER/2MjJ DJ2yb/1a7+ZqMPiS6JPdz9c9/9+I/N9yU5510+EIlQeFwHzbTPE0nmM7bFJx6+h/gq WuFQg7l3VTzPB3AZZSpiOU8kJk8WszcRjkhP0EeEWkFPnwyvvWkOmZuSsScf0hAxVO GLodnZDnk8Tj/ZYStwQKTEfCe4E8yeyC+8+Hw0TqOLybamxwClMAcPo6VZvPYpvB5b p1Heff/jfEOfos9VeoKR58/hngzrTtOEJMOcBaZ7qql26K9OCKj+VbnCsQEwKM9a8n BH1ApkMEbh3Iw== 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 bpf-next 1/2] libbpf: never interpret subprogs in .text as entry programs Date: Thu, 10 Oct 2024 14:17:30 -0700 Message-ID: <20241010211731.4121837-1-andrii@kernel.org> X-Mailer: git-send-email 2.43.5 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 pre-1.0 had a legacy logic of allowing singular non-annotated (i.e., not having explicit SEC() annotation) function to be treated as sole entry BPF program (unless there were other explicit entry programs). This behavior was dropped during libbpf 1.0 transition period (unless LIBBPF_STRICT_SEC_NAME flag was unset in libbpf_mode). When 1.0 was released and all the legacy behavior was removed, the bug slipped through leaving this legacy behavior around. Fix this for good, as it actually causes very confusing behavior if BPF object file only has subprograms, but no entry programs. Fixes: bd054102a8c7 ("libbpf: enforce strict libbpf 1.0 behaviors") Signed-off-by: Andrii Nakryiko --- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 05ad264ff09b..7c40286c3948 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -4417,7 +4417,7 @@ static int bpf_object__collect_externs(struct bpf_object *obj) static bool prog_is_subprog(const struct bpf_object *obj, const struct bpf_program *prog) { - return prog->sec_idx == obj->efile.text_shndx && obj->nr_programs > 1; + return prog->sec_idx == obj->efile.text_shndx; } struct bpf_program * From patchwork Thu Oct 10 21:17:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13831151 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 2606B79D2 for ; Thu, 10 Oct 2024 21:17:37 +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=1728595058; cv=none; b=OCgFwmBI0gRp6ig863zk5XQdyMq9lYq46A+mOUqHfKP/q6O9hsyjTWkXvMFuL6xJwFMCubdd+zIkASJjTGVgZK4icRjxqqFEQFYik5WuCwSQb49tb7DbC7VM4QV+r9SscGclz8tgUnPSlsQBXi6tsYf+OZqjBKKpsgT6rUHhNP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728595058; c=relaxed/simple; bh=taZcxtP09exfathlFfWFsZR1sXmFNmYV1d+3LzOrHkA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r5/CzzjhmTU8KBGOZETokgT7IH7JvVjYWX8PO/IL4nJN748ZWBFot0+UIWYY6meb6PEaKN771TWQkE9gzsDErwRwqLBVWATFX8G1qNa0GacZbQNM1Ukwrltt5PpwF+7xVcTLG7Z0znLiBUr19Gs3J2YGtqsox78Rkwmpe1kGM4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PS0cicmx; 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="PS0cicmx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82765C4CEC5; Thu, 10 Oct 2024 21:17:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728595057; bh=taZcxtP09exfathlFfWFsZR1sXmFNmYV1d+3LzOrHkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PS0cicmxruBZzr3L9b9s2SG5qtGnz0Y7UJYOq2yqlxdbGOWIpn9Bj+GqsrI/im/6n J28uVD3cFRCHbSkg+T7JX1l2aWKPOnDDQKGaVuanC+LjzvAQJl5T5ZmB+uLFy/kAga FrHGB5lVYEwThFIRDH4AyHE03B4xrwAVz6ngbh+uW7M1Cv/Owu12ODwPsEwfaQu79e qeRwkFEF5q1kbXgmAg2Umrd31Bmp+S0+WRIujugluYCRCgzdkPSnSNTa56YsBaXgzW ygpJcMcsyqOv2f/fxhXwZ2ZEf+TbkC/BGwLyamUStLfkPFMfG5uyuTIABIFo0cK2Lt bziUIW4peAQbQ== 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 bpf-next 2/2] selftests/bpf: add subprog to BPF object file with no entry programs Date: Thu, 10 Oct 2024 14:17:31 -0700 Message-ID: <20241010211731.4121837-2-andrii@kernel.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241010211731.4121837-1-andrii@kernel.org> References: <20241010211731.4121837-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 Add a subprogram to BPF object file that otherwise has no entry BPF programs to validate that libbpf can still load this correctly. Until this was fixed, user could expect this very confusing error message: libbpf: prog 'dangling_subprog': missing BPF prog type, check ELF section name '.text' libbpf: prog 'dangling_subprog': failed to load: -22 libbpf: failed to load object 'struct_ops_detach' libbpf: failed to load BPF skeleton 'struct_ops_detach': -22 Signed-off-by: Andrii Nakryiko --- tools/testing/selftests/bpf/progs/struct_ops_detach.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/struct_ops_detach.c b/tools/testing/selftests/bpf/progs/struct_ops_detach.c index 56b787a89876..5222d58592a7 100644 --- a/tools/testing/selftests/bpf/progs/struct_ops_detach.c +++ b/tools/testing/selftests/bpf/progs/struct_ops_detach.c @@ -6,5 +6,11 @@ char _license[] SEC("license") = "GPL"; +int dangling_subprog(void) +{ + /* do nothing, just be here */ + return 0; +} + SEC(".struct_ops.link") struct bpf_testmod_ops testmod_do_detach;