Thread (2 messages) flat view 2 messages, 2 authors, 2021-10-08
STALE1773d LANDED

Landed in mainline as aa67fdb46436 on 2021-10-08.

[PATCH bpf-next v2] selftests/bpf: skip the second half of get_branch_snapshot in vm

From: Song Liu <hidden>
Date: 2021-10-07 05:02:46
Also in: bpf
Subsystem: bpf [general] (safe dynamic programs and tools), bpf [selftests] (test runners & infrastructure), kernel selftest framework, the rest · Maintainers: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi, Shuah Khan, Shuah Khan, Linus Torvalds

VMs running on latest kernel support LBR. However, bpf_get_branch_snapshot
couldn't stop the LBR before too many entries are flushed. Skip the
hit/waste test for VMs before we find a proper fix for LBR in VM.

Fixes: 025bd7c753aa ("selftests/bpf: Add test for bpf_get_branch_snapshot")
Signed-off-by: Song Liu <redacted>

---
Changes v1 => v2:
1. Move the is_hypervisor() check to later in the test, so that we still
   Run the first half of the test in vm
2. Use strncmp instead of strstr. (Andrii)
3. Fix the Fixes tag. (Andrii)
---
 .../bpf/prog_tests/get_branch_snapshot.c      | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
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 67e86f8d86775..e4f92feb7b32c 100644
--- a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
+++ b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
@@ -6,6 +6,30 @@
 static int *pfd_array;
 static int cpu_cnt;
 
+static bool is_hypervisor(void)
+{
+	char *line = NULL;
+	bool ret = false;
+	size_t len;
+	FILE *fp;
+
+	fp = fopen("/proc/cpuinfo", "r");
+	if (!fp)
+		return false;
+
+	while (getline(&line, &len, fp) != -1) {
+		if (!strncmp(line, "flags", 5)) {
+			if (strstr(line, "hypervisor") != NULL)
+				ret = true;
+			break;
+		}
+	}
+
+	free(line);
+	fclose(fp);
+	return ret;
+}
+
 static int create_perf_events(void)
 {
 	struct perf_event_attr attr = {0};
@@ -83,6 +107,16 @@ void test_get_branch_snapshot(void)
 		goto cleanup;
 	}
 
+	if (is_hypervisor()) {
+		/* As of today, LBR in hypervisor cannot be stopped before
+		 * too many entries are flushed. Skip the hit/waste test
+		 * for now in hypervisor until we optimize the LBR in
+		 * hypervisor.
+		 */
+		test__skip();
+		goto cleanup;
+	}
+
 	ASSERT_GT(skel->bss->test1_hits, 6, "find_looptest_in_lbr");
 
 	/* Given we stop LBR in software, we will waste a few entries.
-- 
2.30.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help