Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Skip the second half of get_branch_snapshot in vm

VMs running on upstream 5.12+ 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 <songliubraving@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211007050231.728496-1-songliubraving@fb.com

authored by

Song Liu and committed by
Andrii Nakryiko
aa67fdb4 0eb4ef88

+34
+34
tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
··· 6 6 static int *pfd_array; 7 7 static int cpu_cnt; 8 8 9 + static bool is_hypervisor(void) 10 + { 11 + char *line = NULL; 12 + bool ret = false; 13 + size_t len; 14 + FILE *fp; 15 + 16 + fp = fopen("/proc/cpuinfo", "r"); 17 + if (!fp) 18 + return false; 19 + 20 + while (getline(&line, &len, fp) != -1) { 21 + if (!strncmp(line, "flags", 5)) { 22 + if (strstr(line, "hypervisor") != NULL) 23 + ret = true; 24 + break; 25 + } 26 + } 27 + 28 + free(line); 29 + fclose(fp); 30 + return ret; 31 + } 32 + 9 33 static int create_perf_events(void) 10 34 { 11 35 struct perf_event_attr attr = {0}; ··· 103 79 104 80 if (skel->bss->total_entries < 16) { 105 81 /* too few entries for the hit/waste test */ 82 + test__skip(); 83 + goto cleanup; 84 + } 85 + 86 + if (is_hypervisor()) { 87 + /* As of today, LBR in hypervisor cannot be stopped before 88 + * too many entries are flushed. Skip the hit/waste test 89 + * for now in hypervisor until we optimize the LBR in 90 + * hypervisor. 91 + */ 106 92 test__skip(); 107 93 goto cleanup; 108 94 }