From patchwork Tue Apr 1 16:54:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mykyta Yatsenko X-Patchwork-Id: 14035175 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30BC720D517 for ; Tue, 1 Apr 2025 16:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743526466; cv=none; b=pB4U8ih4wDkAHX24dsAPfImynUn9qU8DGztf7MedqwGtoR8tmWoIs0xy3bAGTxW+sfYdRG27bstLO0er3lpGLpp0ZzxBgOeZGHLmxUyAEZ1z4lSzWf//SU4wfa3iwshGczsjff+d3dhZFKyXwfWjvlt9zYUTMSgPd7URQo6xsnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743526466; c=relaxed/simple; bh=KWaY+/cOB1D+dX+j2sLnWloyPm85RyrhH4tNk0LCeSo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FXD/pCUIRctDdMJQHpT8g28DtrtPZFYMlXNcAkX65zWWPGi3SBfOWSo4SrGK9UON+9rF9dpza9lJ0tNOWHe2QWahW1tfGQF9jvMHsYEKe/i+aPZDJtltQCYqhlRD3tazNa80kVpFlVwsoJjDt2VsSZVfSmr2G/YsszsdxeceWF8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bkWg7mDl; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bkWg7mDl" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-43cf680d351so150635e9.0 for ; Tue, 01 Apr 2025 09:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743526463; x=1744131263; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0xIBmhW+FIJLCI1Rfo8vhwrALknx8oL9oRsgu3k5kgw=; b=bkWg7mDlImGmi65HHnTVEIxWSg4yI5VD0/oPP3OR9IKVMWofRmiRQFcrZSnGK6Fr6F mM8vtur3VUDppO0CTZQBwM/ClwpGQY6heA3Vy21bBzEe2F9DHWrpBmtTI5WjfspE0dwm xUsl2tHX3NGbXCQOHLbB2SC5yqRxrBW5OTa1a0MElPVZSEJK6Dwn+FRF+/2gfmOJbv9m X4D0rcIQtJAMQIQxw/QZ/S71311VeuXaVh4hqey/Uhc4OJCVAE+06Vm6n50M35xmGf9K elvzXwVePNTFNtDIPLCAG1o2Zz85mtJkJFuxcO5//3EdlRyE0Eob1HfUO3B779UU5jC9 aUMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743526463; x=1744131263; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0xIBmhW+FIJLCI1Rfo8vhwrALknx8oL9oRsgu3k5kgw=; b=hlos9PioGOwncCK2rZDYGu6JBjENe/LQdGGrbv6DLVrL5lfhZynyBXTHr4Ed0Lk32O ASVs9VKi4Oo9kzPXKXiW5w4e/3UK8QT8rJ7kyzxeyeCNo6wLbcbiO/fMUwkMqv0CV0DF hKYImNNlDLTkrTDqLAEuMqwtuWw5wFSJz/Lnj6dDxFETdRPribzQEpbzZ2/BewFhkqf7 d5veqQStyvMagWg8rePseVLOu/W7DzePLHcgkGHXYsbYKqCXpiO7x9zVJWYxHgZaWntt 6o5YNB7RphUmzU55X8ZwHmeiXrxlTJDjP0L9qzNWqR09A+ve7aOeQpODcbSSA7PTMj3A GiWA== X-Gm-Message-State: AOJu0YwwyIt/h+HmEXD59MvxxqSFDbq0xCpEcXUi69YxCCGQ4EOm7uz1 sqres4zEPJYWKEYABxmqqvslp2K6nY4PALH6yLWt0YMAzPS4z2EY3kp11A== X-Gm-Gg: ASbGncuGxU80Tc54EwjyjPRwX9Pp7uOtybYg9p/HePY2OoPjTnqQddOpoLOp6inGx1M LRidVxGJ1j6bakNm4Rin64exK9FrtSfg9aBI/katRoV1GOf7BogCHhcrf2ifXIJzpXtGSY1hjRe ISLBWyPJyya8G0/0vkP6joLi5JlZr8c/Rc+V17PPk83eIATZB7rMqmM39mw4h3chxTewnlWgw6n slhzdebBcUGe5kr/1ga9ZVGswFxUfAXyTrf+tXFaGqrJYIIn0Q7+x8923TlaJRzkHHPUTOPRAEB Md+1gjfQKBYhHC87Gw/dVwjdUv/MeRCc9ULq9sqGRdUUVhw1U/SjBBnJQLF+/Rc= X-Google-Smtp-Source: AGHT+IF0bYVEcwALmkJk0ZIKKaD2JGjTxPdVjOcTCzhiNPlEftMLWPNgIHJda4pXgIOU6I4FM0Rkqw== X-Received: by 2002:a05:600c:1d0f:b0:439:9737:675b with SMTP id 5b1f17b1804b1-43eb0579d9cmr8497455e9.7.1743526463340; Tue, 01 Apr 2025 09:54:23 -0700 (PDT) Received: from msi-laptop.mynet ([2a01:4b00:bf28:2e00:ff96:2dac:a39:3e10]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d84632ffcsm201397215e9.31.2025.04.01.09.54.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:54:22 -0700 (PDT) From: Mykyta Yatsenko To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, kafai@meta.com, kernel-team@meta.com, eddyz87@gmail.com Cc: Mykyta Yatsenko Subject: [PATCH bpf-next v3 1/2] libbpf: add getters for BTF.ext func and line info Date: Tue, 1 Apr 2025 17:54:16 +0100 Message-ID: <20250401165417.170632-2-mykyta.yatsenko5@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401165417.170632-1-mykyta.yatsenko5@gmail.com> References: <20250401165417.170632-1-mykyta.yatsenko5@gmail.com> 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 From: Mykyta Yatsenko Introducing new libbpf API getters for BTF.ext func and line info, namely: bpf_program__func_info bpf_program__func_info_cnt bpf_program__line_info bpf_program__line_info_cnt This change enables scenarios, when user needs to load bpf_program directly using `bpf_prog_load`, instead of higher-level `bpf_object__load`. Line and func info are required for checking BTF info in verifier; verification may fail without these fields if, for example, program calls `bpf_obj_new`. Signed-off-by: Mykyta Yatsenko --- tools/lib/bpf/libbpf.c | 24 ++++++++++++++++++++++++ tools/lib/bpf/libbpf.h | 6 ++++++ tools/lib/bpf/libbpf.map | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 6b85060f07b3..551a8514dc7d 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9455,6 +9455,30 @@ int bpf_program__set_log_buf(struct bpf_program *prog, char *log_buf, size_t log return 0; } +struct bpf_func_info *bpf_program__func_info(const struct bpf_program *prog) +{ + if (prog->func_info_rec_size != sizeof(struct bpf_func_info)) + return libbpf_err_ptr(-EOPNOTSUPP); + return prog->func_info; +} + +__u32 bpf_program__func_info_cnt(const struct bpf_program *prog) +{ + return prog->func_info_cnt; +} + +struct bpf_line_info *bpf_program__line_info(const struct bpf_program *prog) +{ + if (prog->line_info_rec_size != sizeof(struct bpf_line_info)) + return libbpf_err_ptr(-EOPNOTSUPP); + return prog->line_info; +} + +__u32 bpf_program__line_info_cnt(const struct bpf_program *prog) +{ + return prog->line_info_cnt; +} + #define SEC_DEF(sec_pfx, ptype, atype, flags, ...) { \ .sec = (char *)sec_pfx, \ .prog_type = BPF_PROG_TYPE_##ptype, \ diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index e0605403f977..d39f19c8396d 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -940,6 +940,12 @@ LIBBPF_API int bpf_program__set_log_level(struct bpf_program *prog, __u32 log_le LIBBPF_API const char *bpf_program__log_buf(const struct bpf_program *prog, size_t *log_size); LIBBPF_API int bpf_program__set_log_buf(struct bpf_program *prog, char *log_buf, size_t log_size); +LIBBPF_API struct bpf_func_info *bpf_program__func_info(const struct bpf_program *prog); +LIBBPF_API __u32 bpf_program__func_info_cnt(const struct bpf_program *prog); + +LIBBPF_API struct bpf_line_info *bpf_program__line_info(const struct bpf_program *prog); +LIBBPF_API __u32 bpf_program__line_info_cnt(const struct bpf_program *prog); + /** * @brief **bpf_program__set_attach_target()** sets BTF-based attach target * for supported BPF program types: diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index d8b71f22f197..1205f9a4fe04 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -437,6 +437,10 @@ LIBBPF_1.6.0 { bpf_linker__add_fd; bpf_linker__new_fd; bpf_object__prepare; + bpf_program__func_info; + bpf_program__func_info_cnt; + bpf_program__line_info; + bpf_program__line_info_cnt; btf__add_decl_attr; btf__add_type_attr; } LIBBPF_1.5.0; From patchwork Tue Apr 1 16:54:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mykyta Yatsenko X-Patchwork-Id: 14035176 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0F7A20D517 for ; Tue, 1 Apr 2025 16:54:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743526469; cv=none; b=VnhtRGfy1nNpE/h+Yv7HaBhkImwlIyXDu8tuLaj7jyQ/PkRVyKgGtFnTQ3ee9hAAwbUIkI+64mMjvsu5GNSpOybeVmkG9msgk93pDP1ZCFQBOR7Ge7Ybs3HsfcjgQzVsJiWAKWY9bo8gQlUD/7P/wfk/rgCgUMzfZWShzCZnUPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743526469; c=relaxed/simple; bh=rKbNtV4bprcIu+3GaX2HKmJxlle8CjeVPheOuwR85bk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cSlTaXsvBwRYroIg4lbM24O+xuJi+Q5dgnUbbI93HJuFlK/+eaa7OEPdhumJtUXcWNB7VqkgjiFdneXqOWLeYFr09x8g9ghZg2yxnExjJzGnkjA5VqiLG5H1okesJWUu7rltppnbIRYMOVzFEII4Z2zZI0k1Rg8fpFuTRIB0LjM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FOixcVvG; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FOixcVvG" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-43d07ca6a80so30878865e9.1 for ; Tue, 01 Apr 2025 09:54:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743526466; x=1744131266; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ojALwK1S+wEOV139aLxoflByFcNtM/5VELMW7+vehr0=; b=FOixcVvGZxLxrLrfoX44cEkKSWfvDjdwcqQZ2R5xUTHYkXYXh7qGw+yM/M07hIQuv5 X1scmeURd851wE59D9jBsH8vRsgWA5NbqZC2QoLs3FNP1EBVGvJEYe2IrxVthtfQ0WXY 7tWWQ2PlsaOib9HOL1MBimRvcXx7SnSeEWiUDse69HTYmLLwqKZOhc7UnzZ+MHmgX+92 1WD/6ojpyYzwhmUIVr3io9iPz9D2jBrj8Cd2187eYGOM7YM+dfWddDyN2IcMSlz0fWm+ RPpDtWMguEM9IrtXuwN/NIECPbJf+NCXEZgWpNiZy4hULUA6eYiudWAR38Gt+bhQdCYm VIUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743526466; x=1744131266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ojALwK1S+wEOV139aLxoflByFcNtM/5VELMW7+vehr0=; b=sAEoFijh/bTP+4FmoCdnYkmDRx3BftXOzgiIb0mq8q3Q5ZTKvfhCisq2st906kIDo8 jE7LTy61L2rtlLxCNGD4B0ZSX4dcDxcu4s50E5ioIaTXvfhLFBsIHBHP4T+J4DciO/IP tFn+3x2ZW2FAxVkl9bmRCZ/yhpkuUoL137XGXVt0CsLzdXvVTWIYczc9p7hsOWFsCWQw oYTTa2mxWnEkdDKiKuk1gDwLjON5jeXtj2ZTFVVqgDt4zTWj1BDfN0077qRtEslQoMjD T47YSU0WVGOkYoeCjMxeeU8MKVSccBmCqdKqm4AfDbBXMBUpON+ztSPV6XVBZjTpcqow v3ng== X-Gm-Message-State: AOJu0Yyv4+/YsTimoop3EotXYs88dkHml5n5dedGzo0YYE3bypLuNkqC lJClgyUgVkqtprf8s7mUP1C2GeV1FIO8WjgDSrdOifZH+dLmD9sdx/o9FA== X-Gm-Gg: ASbGncvIK4SG49M/MYtb6BWudVvqADdyIMC/3E33e0PcR7nMx7xVV/CvuqI3rvw1XME gSWKKglt70d51gg0M7+C1JyRBmzJoqYpnllygVVz0p6zZpt4McL4WKVu73P8tUViZ6w/+PT9HZ3 h9XjDGCOOeey2pAoVCmUqbbtzFBIw2VJatoQs8JzG7gdEkatum0d4Ww9CGw6v4TkBNJ3jstP0zc DB+sl6nuC7yhRo0eFgb29X3g96Xrhsms/x3N0MeDFP28nkpR4NtNcZlRmfnAMdAxjwFOLahsXEV EtU90rSGCAhLoPGK4xDD8qamSpONKmqjp74YHRNI6IxCuzjjpjz+9gqLtdfsIj6AmYnNUarLtg= = X-Google-Smtp-Source: AGHT+IGbLD8FLv2/6Y23zd+qMiuzXYImcT88eRHiRoV0o3tBzytGgdZTy+LVHoN9EvANgL8f0hTUfA== X-Received: by 2002:a05:600c:229a:b0:43d:fa58:8377 with SMTP id 5b1f17b1804b1-43dfa588414mr82112715e9.32.1743526466019; Tue, 01 Apr 2025 09:54:26 -0700 (PDT) Received: from msi-laptop.mynet ([2a01:4b00:bf28:2e00:ff96:2dac:a39:3e10]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d84632ffcsm201397215e9.31.2025.04.01.09.54.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:54:24 -0700 (PDT) From: Mykyta Yatsenko To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, kafai@meta.com, kernel-team@meta.com, eddyz87@gmail.com Cc: Mykyta Yatsenko Subject: [PATCH bpf-next v3 2/2] selftests/bpf: add .BTF.ext line/func info getter tests Date: Tue, 1 Apr 2025 17:54:17 +0100 Message-ID: <20250401165417.170632-3-mykyta.yatsenko5@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401165417.170632-1-mykyta.yatsenko5@gmail.com> References: <20250401165417.170632-1-mykyta.yatsenko5@gmail.com> 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 From: Mykyta Yatsenko Add selftests checking that line and func info retrieved by newly added libbpf APIs are the same as returned by kernel via bpf_prog_get_info_by_fd. Signed-off-by: Mykyta Yatsenko --- .../selftests/bpf/prog_tests/test_btf_ext.c | 111 ++++++++++++++++++ .../selftests/bpf/progs/test_btf_ext.c | 21 ++++ 2 files changed, 132 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/test_btf_ext.c create mode 100644 tools/testing/selftests/bpf/progs/test_btf_ext.c diff --git a/tools/testing/selftests/bpf/prog_tests/test_btf_ext.c b/tools/testing/selftests/bpf/prog_tests/test_btf_ext.c new file mode 100644 index 000000000000..00aeebc8f863 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/test_btf_ext.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2020 Facebook */ +#include +#include "test_btf_ext.skel.h" +#include "btf_helpers.h" + +static void subtest_line_info(void) +{ + struct test_btf_ext *skel; + struct bpf_prog_info info; + struct bpf_line_info line_info[1024], *libbpf_line_info; + __u32 info_len = sizeof(info), libbbpf_line_info_cnt; + int err, fd, i; + + skel = test_btf_ext__open(); + if (!ASSERT_OK_PTR(skel, "skel_open")) + return; + + bpf_program__set_autoload(skel->progs.global_func, true); + + err = test_btf_ext__load(skel); + if (!ASSERT_OK(err, "skel_load")) + goto out; + + fd = bpf_program__fd(skel->progs.global_func); + + memset(&info, 0, sizeof(info)); + info.line_info = ptr_to_u64(&line_info); + info.nr_line_info = sizeof(line_info); + info.line_info_rec_size = sizeof(*line_info); + err = bpf_prog_get_info_by_fd(fd, &info, &info_len); + if (!ASSERT_OK(err, "prog_info")) + goto out; + + libbpf_line_info = bpf_program__line_info(skel->progs.global_func); + libbbpf_line_info_cnt = bpf_program__line_info_cnt(skel->progs.global_func); + + if (!ASSERT_OK_PTR(libbpf_line_info, "bpf_program__line_info")) + goto out; + if (!ASSERT_GT(libbbpf_line_info_cnt, 0, "line_info_cnt>0")) + goto out; + if (!ASSERT_EQ(libbbpf_line_info_cnt, info.nr_line_info, "line_info_cnt")) + goto out; + + for (i = 0; i < libbbpf_line_info_cnt; ++i) { + int eq = memcmp(libbpf_line_info + i, line_info + i, sizeof(*line_info)); + + if (!ASSERT_EQ(eq, 0, "line_info")) + goto out; + } + +out: + test_btf_ext__destroy(skel); +} + +static void subtest_func_info(void) +{ + struct test_btf_ext *skel; + struct bpf_prog_info info; + struct bpf_func_info func_info[1024], *libbpf_func_info; + __u32 info_len = sizeof(info), libbbpf_func_info_cnt; + int err, fd, i; + + skel = test_btf_ext__open(); + if (!ASSERT_OK_PTR(skel, "skel_open")) + return; + + bpf_program__set_autoload(skel->progs.global_func, true); + + err = test_btf_ext__load(skel); + if (!ASSERT_OK(err, "skel_load")) + goto out; + + fd = bpf_program__fd(skel->progs.global_func); + + memset(&info, 0, sizeof(info)); + info.func_info = ptr_to_u64(&func_info); + info.nr_func_info = sizeof(func_info); + info.func_info_rec_size = sizeof(*func_info); + err = bpf_prog_get_info_by_fd(fd, &info, &info_len); + if (!ASSERT_OK(err, "prog_info")) + goto out; + + libbpf_func_info = bpf_program__func_info(skel->progs.global_func); + libbbpf_func_info_cnt = bpf_program__func_info_cnt(skel->progs.global_func); + + if (!ASSERT_OK_PTR(libbpf_func_info, "bpf_program__func_info")) + goto out; + if (!ASSERT_GT(libbbpf_func_info_cnt, 0, "func_info_cnt>0")) + goto out; + if (!ASSERT_EQ(libbbpf_func_info_cnt, info.nr_func_info, "func_info_cnt")) + goto out; + + for (i = 0; i < libbbpf_func_info_cnt; ++i) { + int eq = memcmp(libbpf_func_info + i, func_info + i, sizeof(*func_info)); + + if (!ASSERT_EQ(eq, 0, "func_info")) + goto out; + } + +out: + test_btf_ext__destroy(skel); +} + +void test_btf_ext(void) +{ + if (test__start_subtest("func_info")) + subtest_func_info(); + if (test__start_subtest("line_info")) + subtest_line_info(); +} diff --git a/tools/testing/selftests/bpf/progs/test_btf_ext.c b/tools/testing/selftests/bpf/progs/test_btf_ext.c new file mode 100644 index 000000000000..be92e445a988 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_btf_ext.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2025 Meta Platforms Inc. */ + +#include +#include + +const volatile int val = 3; + +static __attribute__ ((noinline)) +int f0(int var) +{ + int retval = var + val; + + return retval; +} + +SEC("tc") +int global_func(struct __sk_buff *skb) +{ + return f0(skb->len); +}