From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (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 69456325720 for ; Fri, 9 Jan 2026 15:37:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767973057; cv=none; b=uSpBcgPlR9VTBbgPhzmEzutkNDy0QqlYcMrnfH19/XTrw6r7v63mfujeeQQVJ7hgzNE5yA9lTCPpIEaBtpz9bA5gW4TsrS+PQP3yq9dg5pzSj2fyjT+Y2fNfdewjGhfk+1SPQjQn0i7mX1PBWT4FL0adfwF15u4lZLlyCe3K7wQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767973057; c=relaxed/simple; bh=olXGm4lhKZ/DUlPJ4xDJl2D4L2YZF2AiKKcbPFW+qYo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mrxFtC8yiXIDhTUkpFEcomdOW9YKSKEteaII0sI6oUA+oTI6XsWBrneozsvOCpT1ek8Xnjuz8Zjr6u9D6O9POGqJQj2O1s6DrNBM3J3MWUPcpJLRTZfSv+m60h4CCkP1iSUqeUxXu/ZkgHvbxgfLgIZ2mZaBfcU3wHSTchroVMk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Mm1147DI; arc=none smtp.client-ip=95.215.58.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Mm1147DI" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767973053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zGmQZRRwHlrtsRbft3WSiOCAz3aFQwD5zodc3tv48HM=; b=Mm1147DIHhLW7zP2EauxyHdsXI9RKxz3GC3qUwmoLQ4yuNjCPdidgxYYT9PcDapwg/HC7B MIvVhpXMv5LqUDNM6kDVe2b6YwJnRCuX5+WfKrlJoHQ8IOb6UHl2QQHnDRVNPXoNFbNqIf R0eRMuWuubcK/ROndIFPVPTrdcatV40= From: Leon Hwang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S . Miller" , David Ahern , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Matt Bobrowski , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Shuah Khan , Leon Hwang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-patches-bot@fb.com Subject: [PATCH bpf-next 3/3] selftests/bpf: Add BPF_BRANCH_SNAPSHOT_F_COPY test Date: Fri, 9 Jan 2026 23:34:20 +0800 Message-ID: <20260109153420.32181-4-leon.hwang@linux.dev> In-Reply-To: <20260109153420.32181-1-leon.hwang@linux.dev> References: <20260109153420.32181-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Add test for BPF_BRANCH_SNAPSHOT_F_COPY flag by adding flag to the callsite of bpf_get_branch_snapshot helper. Signed-off-by: Leon Hwang --- .../bpf/prog_tests/get_branch_snapshot.c | 26 ++++++++++++++++--- .../selftests/bpf/progs/get_branch_snapshot.c | 3 ++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c index 0394a1156d99..6b8ab1655ab0 100644 --- a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c +++ b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c @@ -73,7 +73,7 @@ static void close_perf_events(void) free(pfd_array); } -void serial_test_get_branch_snapshot(void) +static void test_branch_snapshot(int flags) { struct get_branch_snapshot *skel = NULL; int err; @@ -89,8 +89,14 @@ void serial_test_get_branch_snapshot(void) goto cleanup; } - skel = get_branch_snapshot__open_and_load(); - if (!ASSERT_OK_PTR(skel, "get_branch_snapshot__open_and_load")) + skel = get_branch_snapshot__open(); + if (!ASSERT_OK_PTR(skel, "get_branch_snapshot__open")) + goto cleanup; + + skel->rodata->flags = flags; + + err = get_branch_snapshot__load(skel); + if (!ASSERT_OK(err, "get_branch_snapshot__load")) goto cleanup; err = kallsyms_find("bpf_testmod_loop_test", &skel->bss->address_low); @@ -128,3 +134,17 @@ void serial_test_get_branch_snapshot(void) get_branch_snapshot__destroy(skel); close_perf_events(); } + +void serial_test_get_branch_snapshot(void) +{ + test_branch_snapshot(0); +} + +enum { + BPF_BRANCH_SNAPSHOT_F_COPY = 1, /* Copy branch snapshot from bpf_branch_snapshot. */ +}; + +void serial_test_copy_branch_snapshot(void) +{ + test_branch_snapshot(BPF_BRANCH_SNAPSHOT_F_COPY); +} diff --git a/tools/testing/selftests/bpf/progs/get_branch_snapshot.c b/tools/testing/selftests/bpf/progs/get_branch_snapshot.c index 511ac634eef0..47a1984bdf46 100644 --- a/tools/testing/selftests/bpf/progs/get_branch_snapshot.c +++ b/tools/testing/selftests/bpf/progs/get_branch_snapshot.c @@ -6,6 +6,7 @@ char _license[] SEC("license") = "GPL"; +volatile const int flags = 0; __u64 test1_hits = 0; __u64 address_low = 0; __u64 address_high = 0; @@ -25,7 +26,7 @@ int BPF_PROG(test1, int n, int ret) { long i; - total_entries = bpf_get_branch_snapshot(entries, sizeof(entries), 0); + total_entries = bpf_get_branch_snapshot(entries, sizeof(entries), flags); total_entries /= sizeof(struct perf_branch_entry); for (i = 0; i < ENTRY_CNT; i++) { -- 2.52.0