From patchwork Wed Aug 14 23:57:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JP Kobryn X-Patchwork-Id: 13764257 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 B46BF14900E for ; Wed, 14 Aug 2024 23:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723679905; cv=none; b=Ru51yf2Zc6O/jLtZmh3ugr5DTKGEW1DgLxLfNbzKT8S8bkF4A3G/7pTCj3t8Z6TsHslLG3OMkA9yYaYlqptGy9zbCYffL4ggTTyR+WKEorJWTqqL7NBBl4z5zqDZ+a4b7I2innsYXJ9sZLyfzVDgUTaVnUzooDnnu80W/c31Nhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723679905; c=relaxed/simple; bh=jQVq3+JODnwQq+1vCUCouWsaExJWOQU+qoJGU59S+HE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dk69mJd9xtaqXgaNW/ict4KX/YUna5XDEbIGHQ2T9rjNSflOa/JdOir6qUwV+wypOMjOZ7puF1mWYEjhEJgqBCBbNVbRlnNxXMqmW+0V/XEQXY7cs3D76F28I9jfg+fCcQwV2suzQvqk/814fX3lldjzVMASvSA3dOwGEA/uNEc= 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=OORHX8CY; arc=none smtp.client-ip=209.85.210.173 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="OORHX8CY" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-7105043330aso355069b3a.0 for ; Wed, 14 Aug 2024 16:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723679903; x=1724284703; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=JOjB6qYi8GFcmeLMpnH15K96KfMPCaC+ZzbKMjqCJMo=; b=OORHX8CYFFULMMjkvcX/i0zfJMFDg6h5LMgIWp/vAfA/2adwhzSFru92cOUdiqhW/2 EmYCMrnE3zV2aa6sQ60byXHZfLSUs4H/olt7JvPH+ShsxYYreuUg884IKM3EyEhmm20T RsSSLSTEONgBSWb3aMkFBVmsy7S5VHZD64ZI/gjVstuUGP+Y/oacJCX/mD8X7P+I0QNw wqRs88KQ8jIPefoTSPzqeKclcNKXc8Vxu26fJ/WHkiepxUj0q0E4FrVaLtbrJmHIWzIa kKzSnpbYSDXUmBMSAFnLZnITdj8DLJPu6sX9/QpC3zO9+xRG0Gmrlkr8fV3xs8wAgVtI A7NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723679903; x=1724284703; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JOjB6qYi8GFcmeLMpnH15K96KfMPCaC+ZzbKMjqCJMo=; b=WxZhHmkmg1GXEpLC1l5SvAozYZddGNEfSJ2mSS0Rn++WQ+ZOz2PvI0k33xjSfim3DO 0dLBQWAIDJ6RsLaCPWFfPMLPJqEStko2+ndxL1XT+l3jVvoxirVj9xVreU06kQ96WAcH 1R3ZkGFNzmDZ+60NAGdQnEcQV2pxpY0KT/1LVCKWh6qVOtebwLXpXsOl0GSJc+lmjktq RdmwI9My3dm7R2pt7fYH3bM5z0FNsZ//L9INXeKZSTe7cWJxGfyrEVN41Z2lLoJHNVt1 SMKEuDhWUUYs3lvQ5Ba343u4uVCGF62VYEV1NXbgBbzhOdGV2Kmv+y+BJH0owyIq5Ik3 DOkQ== X-Forwarded-Encrypted: i=1; AJvYcCXbwo+8manBGEKQLqx8wzLvhDhVaYG7jstEh3gfT9f+9nCNHPtgMzcbnD58KSBbDGqQMCU=@vger.kernel.org X-Gm-Message-State: AOJu0YwhT/PLALzwiHQ4euyeyRAp76ruqJyTajrtIc4fmCW236x9t44E 5IJhazI34nCUEWnlDfNQMv4ncx4vn7EZMp5WMvzjPx71Ga8ruRFX X-Google-Smtp-Source: AGHT+IEiJtSZHUID81oZSYuyf6kSTlATV8sJw6m6HQ6JzYoGmglZl5UyN6ZA/CMCV+6oeusTWVKp0Q== X-Received: by 2002:a05:6a20:c91b:b0:1c6:ba9c:5d7b with SMTP id adf61e73a8af0-1c8eaeaf7b7mr5820527637.23.1723679902904; Wed, 14 Aug 2024 16:58:22 -0700 (PDT) Received: from saturn.. (c-67-188-127-15.hsd1.ca.comcast.net. [67.188.127.15]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127aef5229sm127264b3a.107.2024.08.14.16.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 16:58:22 -0700 (PDT) From: JP Kobryn To: andrii@kernel.org, ast@kernel.org, eddyz87@gmail.com, bpf@vger.kernel.org Subject: [PATCH bpf-next 1/2] bpf/selftests: coverage for calling kfuncs within tracepoint Date: Wed, 14 Aug 2024 16:57:59 -0700 Message-ID: <20240814235800.15253-2-inwardvessel@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814235800.15253-1-inwardvessel@gmail.com> References: <20240814235800.15253-1-inwardvessel@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 This test exposes the issue of being unable to call kfuncs within a normal tracepoint program. The program will be rejected by the verifier as not allowed. Signed-off-by: JP Kobryn --- .../selftests/bpf/prog_tests/kfunc_in_tp.c | 34 ++++++++++++++++++ .../selftests/bpf/progs/test_kfunc_in_tp.c | 35 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c create mode 100644 tools/testing/selftests/bpf/progs/test_kfunc_in_tp.c diff --git a/tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c b/tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c new file mode 100644 index 000000000000..bef1d192fc00 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */ + +#include +#include +#include + +#include "test_kfunc_in_tp.skel.h" +#include "test_progs.h" + +static void run_tp(void) +{ + (void)syscall(__NR_getpid); +} + +void test_kfunc_in_tp(void) +{ + struct test_kfunc_in_tp *skel; + int err; + + skel = test_kfunc_in_tp__open(); + ASSERT_OK_PTR(skel, "test_kfunc_in_tp__open"); + + err = test_kfunc_in_tp__load(skel); + ASSERT_OK(err, "test_kfunc_in_tp__load"); + + err = test_kfunc_in_tp__attach(skel); + ASSERT_OK(err, "test_kfunc_in_tp__attach"); + + run_tp(); + ASSERT_OK(skel->data->result, "complete"); + + test_kfunc_in_tp__destroy(skel); +} diff --git a/tools/testing/selftests/bpf/progs/test_kfunc_in_tp.c b/tools/testing/selftests/bpf/progs/test_kfunc_in_tp.c new file mode 100644 index 000000000000..5a3f1ff930af --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_kfunc_in_tp.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */ + +#include "vmlinux.h" +#include + +char _license[] SEC("license") = "GPL"; + +extern struct bpf_cpumask *bpf_cpumask_create(void) __ksym; +extern void bpf_cpumask_set_cpu(u32 cpu, struct bpf_cpumask *cpumask) __ksym; +extern bool bpf_cpumask_test_cpu(u32 cpu, const struct cpumask *cpumask) __ksym; +extern void bpf_cpumask_release(struct bpf_cpumask *cpumask) __ksym; + +int result = -1; + +/* call arbitrary kfuncs within a tracepoint program */ +SEC("tp/syscalls/sys_enter_getpid") +int handle_tp(struct trace_event_raw_ipi_send_cpumask *ctx) +{ + struct bpf_cpumask *cpumask; + const u32 cpu = bpf_get_smp_processor_id(); + + cpumask = bpf_cpumask_create(); + if (!cpumask) + return 0; + + bpf_cpumask_set_cpu(cpu, cpumask); + if (bpf_cpumask_test_cpu(cpu, (struct cpumask *)cpumask)) + bpf_printk("match\n"); + + bpf_cpumask_release(cpumask); + result = 0; + + return 0; +} From patchwork Wed Aug 14 23:58:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JP Kobryn X-Patchwork-Id: 13764258 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 B3B8114F9D9 for ; Wed, 14 Aug 2024 23:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723679907; cv=none; b=pqq4gHS5S1fHHQ9XHPOkDDMTNACbti0JOH9yu83P9e8BLQKD/RrIVWpZe54JM8LI9/UiLGgNKsRPXzM15+/CZG7ywjKzbwZlCDO017Ptl0vNIZH0wav2iwQoD9KWnpKOOroRgOBZ/cJxvuGHf0FufYgV1/VG2GIKjpbiAP4yKmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723679907; c=relaxed/simple; bh=2HTaOT0VsRh8V+1IZg+6G3ZQvChBDY9unY4ZmDn/x+I=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UiZH0H68snLKpBOQHsm0OpqQtypyjvenAuiql2VZBEH6jrE3uFhYbdJpk+P29/RngPcvIO5E5v0HbGrkPmMbPoVoVYQG0TDzOOtgGiOncNkym36/YmlpF3Ik7XiUWwwV7whVSDahup918P3tTpKbXODMRVzPgZK49NaMrHy/6jY= 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=l/faR22m; arc=none smtp.client-ip=209.85.215.172 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="l/faR22m" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7c6b4222fe3so199407a12.3 for ; Wed, 14 Aug 2024 16:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723679905; x=1724284705; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=BRJokMTcs64VJHknYnsxDilDKSbjJnDAhgxAir1bugs=; b=l/faR22m6njyWmT41hVOLNxsedWqz+ovJgImaOH3oJbA6XObTqXbdcc2XKKc9kEiWL yez9/+OtzXdpsU5BIN2DewiIyEsGZ6Oy5ea0bVNgWG5qJw3uE1NUbQB7vWmufVSgVN5e YgYXKhOu9MPW3jzz8663KOC7P4MStWCkNvKr9DbAxfcJaPKhBx35ircsseoH3EtBYWsZ LN4lZ8YERKk2ZJYV9BTZpQOd3UO3hjxkmmh3pIiWpsuSlUhPm8bw5TYV1PXahdoeIks3 Ah8FZoGZi2c/w1zPvf13dQlOlWFJjqmN0KzEQ/ZjtjDVQYn1RyXj6EyJSZ8ogLPInRgx neZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723679905; x=1724284705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BRJokMTcs64VJHknYnsxDilDKSbjJnDAhgxAir1bugs=; b=DEjL01fO3ePW6Q9aVt9x0IFz0dpELkrEe2yHKaQw2FrtFXBz8pp09pdRhz0svL9Os4 Lm3lh4Eu7VBZjpPA/4Y4MdDno0Fbh5olAo4SiZLBIqHCGBVkod2FYtIEx4Dp57VJXaGI dDW/cKW+wc4r/3hrwakIX4bvkLWvdqbfebWbX0VVS3NhV94b7DHr1zt/T8DCvUHQdkeP Q0XesUCkg8NP7IrNoVlq0Foe6B2GuhuUNsEWVV0l4mvgeK1reaWxnJaKpVGHJjOL5hDg +ru0/Wj4fYIbErOFGjrNTXhnYJZN69oXAlGJ+zLOBk7Zu0E8LorT/dsy2EA3TlG+Sbj0 ookA== X-Forwarded-Encrypted: i=1; AJvYcCVHqCAfS82mlvM4Kh0vsCVvwi1EskEv9jBZw7U33t7t+hGjmndPHZqPGAojH1dk45BQQCc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1bftxMwzPzAQVqkdaEsH9gCWhR4M7UUeIWvHrfB5hkmDzOirB 2MaZYs2yPtnEVrLy1PsSf50zCjATaahn8Z9OrJq0WPgQE7X8lIch X-Google-Smtp-Source: AGHT+IGcbXezCLOxbSzPwH6TWzOstpqaP+H34QpjDVtKrZFQIVk73qnnbeS04VEkf3UWHYiU0tCMUA== X-Received: by 2002:a05:6a20:c78e:b0:1c0:ed80:6e69 with SMTP id adf61e73a8af0-1c8eaf5f205mr6338304637.39.1723679904156; Wed, 14 Aug 2024 16:58:24 -0700 (PDT) Received: from saturn.. (c-67-188-127-15.hsd1.ca.comcast.net. [67.188.127.15]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127aef5229sm127264b3a.107.2024.08.14.16.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 16:58:23 -0700 (PDT) From: JP Kobryn To: andrii@kernel.org, ast@kernel.org, eddyz87@gmail.com, bpf@vger.kernel.org Subject: [PATCH bpf-next 2/2] bpf: allow kfuncs within normal tracepoint programs Date: Wed, 14 Aug 2024 16:58:00 -0700 Message-ID: <20240814235800.15253-3-inwardvessel@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814235800.15253-1-inwardvessel@gmail.com> References: <20240814235800.15253-1-inwardvessel@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 Account for normal tracepoint programs by associating them with the kfunc tracing hook. This allows kfuncs to be called within tracepoint programs. Signed-off-by: JP Kobryn --- kernel/bpf/btf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 520f49f422fe..8b844d6fd041 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -8303,6 +8303,7 @@ static int bpf_prog_type_to_kfunc_hook(enum bpf_prog_type prog_type) return BTF_KFUNC_HOOK_TC; case BPF_PROG_TYPE_STRUCT_OPS: return BTF_KFUNC_HOOK_STRUCT_OPS; + case BPF_PROG_TYPE_TRACEPOINT: case BPF_PROG_TYPE_TRACING: case BPF_PROG_TYPE_LSM: return BTF_KFUNC_HOOK_TRACING;