Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arm64: bpf: Fix branch offset in JIT #75

Closed
wants to merge 2 commits into from

Conversation

kernel-patches-bot
Copy link

Pull request for series with
subject: arm64: bpf: Fix branch offset in JIT
version: 3
url: https://patchwork.ozlabs.org/project/netdev/list/?series=202354

@kernel-patches-bot
Copy link
Author

@kernel-patches-bot
Copy link
Author

@kernel-patches-bot
Copy link
Author

@kernel-patches-bot
Copy link
Author

kernel-patches-bot and others added 2 commits September 21, 2020 12:27
[ 6525.735488] Unexpected kernel BRK exception at EL1
[ 6525.735502] Internal error: ptrace BRK handler: f2000100 [#1] SMP
[ 6525.741609] Modules linked in: nls_utf8 cifs libdes libarc4 dns_resolver fscache binfmt_misc nls_ascii nls_cp437 vfat fat aes_ce_blk crypto_simd cryptd aes_ce_cipher ghash_ce gf128mul efi_pstore sha2_ce sha256_arm64 sha1_ce evdev efivars efivarfs ip_tables x_tables autofs4 btrfs blake2b_generic xor xor_neon zstd_compress raid6_pq libcrc32c crc32c_generic ahci xhci_pci libahci xhci_hcd igb libata i2c_algo_bit nvme realtek usbcore nvme_core scsi_mod t10_pi netsec mdio_devres of_mdio gpio_keys fixed_phy libphy gpio_mb86s7x
[ 6525.787760] CPU: 3 PID: 7881 Comm: test_verifier Tainted: G        W         5.9.0-rc1+ #47
[ 6525.796111] Hardware name: Socionext SynQuacer E-series DeveloperBox, BIOS build #1 Jun  6 2020
[ 6525.804812] pstate: 20000005 (nzCv daif -PAN -UAO BTYPE=--)
[ 6525.810390] pc : bpf_prog_c3d01833289b6311_F+0xc8/0x9f4
[ 6525.815613] lr : bpf_prog_d53bb52e3f4483f9_F+0x38/0xc8c
[ 6525.820832] sp : ffff8000130cbb80
[ 6525.824141] x29: ffff8000130cbbb0 x28: 0000000000000000
[ 6525.829451] x27: 000005ef6fcbf39b x26: 0000000000000000
[ 6525.834759] x25: ffff8000130cbb80 x24: ffff800011dc7038
[ 6525.840067] x23: ffff8000130cbd00 x22: ffff0008f624d080
[ 6525.845375] x21: 0000000000000001 x20: ffff800011dc7000
[ 6525.850682] x19: 0000000000000000 x18: 0000000000000000
[ 6525.855990] x17: 0000000000000000 x16: 0000000000000000
[ 6525.861298] x15: 0000000000000000 x14: 0000000000000000
[ 6525.866606] x13: 0000000000000000 x12: 0000000000000000
[ 6525.871913] x11: 0000000000000001 x10: ffff8000000a660c
[ 6525.877220] x9 : ffff800010951810 x8 : ffff8000130cbc38
[ 6525.882528] x7 : 0000000000000000 x6 : 0000009864cfa881
[ 6525.887836] x5 : 00ffffffffffffff x4 : 002880ba1a0b3e9f
[ 6525.893144] x3 : 0000000000000018 x2 : ffff8000000a4374
[ 6525.898452] x1 : 000000000000000a x0 : 0000000000000009
[ 6525.903760] Call trace:
[ 6525.906202]  bpf_prog_c3d01833289b6311_F+0xc8/0x9f4
[ 6525.911076]  bpf_prog_d53bb52e3f4483f9_F+0x38/0xc8c
[ 6525.915957]  bpf_dispatcher_xdp_func+0x14/0x20
[ 6525.920398]  bpf_test_run+0x70/0x1b0
[ 6525.923969]  bpf_prog_test_run_xdp+0xec/0x190
[ 6525.928326]  __do_sys_bpf+0xc88/0x1b28
[ 6525.932072]  __arm64_sys_bpf+0x24/0x30
[ 6525.935820]  el0_svc_common.constprop.0+0x70/0x168
[ 6525.940607]  do_el0_svc+0x28/0x88
[ 6525.943920]  el0_sync_handler+0x88/0x190
[ 6525.947838]  el0_sync+0x140/0x180
[ 6525.951154] Code: d4202000 d4202000 d4202000 d4202000 (d4202000)
[ 6525.957249] ---[ end trace cecc3f93b14927e2 ]---

The reason is the offset[] creation and later usage, while building
the eBPF body. The code currently omits the first instruction, since
build_insn() will increase our ctx->idx before saving it.
That was fine up until bounded eBPF loops were introduced. After that
introduction, offset[0] must be the offset of the end of prologue which
is the start of the 1st insn while, offset[n] holds the
offset of the end of n-th insn.

When "taken loop with back jump to 1st insn" test runs, it will
eventually call bpf2a64_offset(-1, 2, ctx). Since negative indexing is
permitted, the current outcome depends on the value stored in
ctx->offset[-1], which has nothing to do with our array.
If the value happens to be 0 the tests will work. If not this error
triggers.

commit 7c2e988 ("bpf: fix x64 JIT code generation for jmp to 1st insn")
fixed an indentical bug on x86 when eBPF bounded loops were introduced.

So let's fix it by creating the ctx->offset[] differently. Track the
beginning of instruction and account for the extra instruction while
calculating the arm instruction offsets.

Fixes: 2589726 ("bpf: introduce bounded loops")
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Reported-by: Jiri Olsa <jolsa@kernel.org>
Co-developed-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Co-developed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
Changes since v1:
 - Added Co-developed-by, Reported-by and Fixes tags correctly
 - Describe the expected context of ctx->offset[] in comments
Changes since v2:
 - Drop the change of behavior for 16-byte eBPF instructions. This won't
 currently cause any problems and can go in on a different patch
 - simplify bpf2a64_offset()

 arch/arm64/net/bpf_jit_comp.c | 43 +++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 12 deletions(-)
@kernel-patches-bot
Copy link
Author

@kernel-patches-bot
Copy link
Author

At least one diff in series https://patchwork.ozlabs.org/project/netdev/list/?series=202354 expired. Closing PR.

@kernel-patches-bot kernel-patches-bot deleted the series/201615=>bpf-next branch September 30, 2020 16:12
kernel-patches-bot pushed a commit that referenced this pull request Jan 29, 2021
…abled

When booting a kernel which has been built with CONFIG_AMD_MEM_ENCRYPT
enabled as a Xen pv guest a warning is issued for each processor:

[    5.964347] ------------[ cut here ]------------
[    5.968314] WARNING: CPU: 0 PID: 1 at /home/gross/linux/head/arch/x86/xen/enlighten_pv.c:660 get_trap_addr+0x59/0x90
[    5.972321] Modules linked in:
[    5.976313] CPU: 0 PID: 1 Comm: swapper/0 Tainted: G        W         5.11.0-rc5-default #75
[    5.980313] Hardware name: Dell Inc. OptiPlex 9020/0PC5F7, BIOS A05 12/05/2013
[    5.984313] RIP: e030:get_trap_addr+0x59/0x90
[    5.988313] Code: 42 10 83 f0 01 85 f6 74 04 84 c0 75 1d b8 01 00 00 00 c3 48 3d 00 80 83 82 72 08 48 3d 20 81 83 82 72 0c b8 01 00 00 00 eb db <0f> 0b 31 c0 c3 48 2d 00 80 83 82 48 ba 72 1c c7 71 1c c7 71 1c 48
[    5.992313] RSP: e02b:ffffc90040033d38 EFLAGS: 00010202
[    5.996313] RAX: 0000000000000001 RBX: ffffffff82a141d0 RCX: ffffffff8222ec38
[    6.000312] RDX: ffffffff8222ec38 RSI: 0000000000000005 RDI: ffffc90040033d40
[    6.004313] RBP: ffff8881003984a0 R08: 0000000000000007 R09: ffff888100398000
[    6.008312] R10: 0000000000000007 R11: ffffc90040246000 R12: ffff8884082182a8
[    6.012313] R13: 0000000000000100 R14: 000000000000001d R15: ffff8881003982d0
[    6.016316] FS:  0000000000000000(0000) GS:ffff888408200000(0000) knlGS:0000000000000000
[    6.020313] CS:  e030 DS: 0000 ES: 0000 CR0: 0000000080050033
[    6.024313] CR2: ffffc900020ef000 CR3: 000000000220a000 CR4: 0000000000050660
[    6.028314] Call Trace:
[    6.032313]  cvt_gate_to_trap.part.7+0x3f/0x90
[    6.036313]  ? asm_exc_double_fault+0x30/0x30
[    6.040313]  xen_convert_trap_info+0x87/0xd0
[    6.044313]  xen_pv_cpu_up+0x17a/0x450
[    6.048313]  bringup_cpu+0x2b/0xc0
[    6.052313]  ? cpus_read_trylock+0x50/0x50
[    6.056313]  cpuhp_invoke_callback+0x80/0x4c0
[    6.060313]  _cpu_up+0xa7/0x140
[    6.064313]  cpu_up+0x98/0xd0
[    6.068313]  bringup_nonboot_cpus+0x4f/0x60
[    6.072313]  smp_init+0x26/0x79
[    6.076313]  kernel_init_freeable+0x103/0x258
[    6.080313]  ? rest_init+0xd0/0xd0
[    6.084313]  kernel_init+0xa/0x110
[    6.088313]  ret_from_fork+0x1f/0x30
[    6.092313] ---[ end trace be9ecf17dceeb4f3 ]---

Reason is that there is no Xen pv trap entry for X86_TRAP_VC.

Fix that by adding a generic trap handler for unknown traps and wire all
unknown bare metal handlers to this generic handler, which will just
crash the system in case such a trap will ever happen.

Fixes: 0786138 ("x86/sev-es: Add a Runtime #VC Exception Handler")
Cc: <stable@vger.kernel.org> # v5.10
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
kernel-patches-bot pushed a commit that referenced this pull request Nov 15, 2021
Branch data available to bpf programs can be very useful to get
stack traces out of userspace applications.

Commit fff7b64 ("bpf: Add bpf_read_branch_records() helper")
added bpf support to capture branch records in x86. Enable this feature
for powerpc as well.

Commit 67306f8 ("selftests/bpf: Add bpf_read_branch_records()
selftest") adds selftest corresponding to bpf branch read
function bpf_read_branch_records(). Used this selftest to
test bpf support, for reading branch records in powerpc.

Selftest result in power9 box before this patch changes:

[command]# ./test_progs -t perf_branches
Failed to load bpf_testmod.ko into the kernel: -8
WARNING! Selftests relying on bpf_testmod.ko will be skipped.
test_perf_branches_common:PASS:test_perf_branches_load 0 nsec
test_perf_branches_common:PASS:attach_perf_event 0 nsec
test_perf_branches_common:PASS:set_affinity 0 nsec
check_good_sample:PASS:output not valid 0 nsec
check_good_sample:FAIL:read_branches_size err -2
check_good_sample:FAIL:read_branches_stack err -2
check_good_sample:FAIL:read_branches_stack stack bytes written=-2
not multiple of struct size=24
check_good_sample:FAIL:read_branches_global err -2
check_good_sample:FAIL:read_branches_global global bytes written=-2
not multiple of struct size=24
check_good_sample:PASS:read_branches_size 0 nsec
 #75/1 perf_branches_hw:FAIL
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:FAIL
Summary: 0/1 PASSED, 0 SKIPPED, 2 FAILED

Selftest result in power9 box after this patch changes:

[command]#: ./test_progs -t perf_branches
 #75/1 perf_branches_hw:OK
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Kajol Jain<kjain@linux.ibm.com>
kernel-patches-bot pushed a commit that referenced this pull request Nov 15, 2021
Branch data available to bpf programs can be very useful to get
stack traces out of userspace applications.

Commit fff7b64 ("bpf: Add bpf_read_branch_records() helper")
added bpf support to capture branch records in x86. Enable this feature
for powerpc as well.

Commit 67306f8 ("selftests/bpf: Add bpf_read_branch_records()
selftest") adds selftest corresponding to bpf branch read
function bpf_read_branch_records(). Used this selftest to
test bpf support, for reading branch records in powerpc.

Selftest result in power9 box before this patch changes:

[command]# ./test_progs -t perf_branches
Failed to load bpf_testmod.ko into the kernel: -8
WARNING! Selftests relying on bpf_testmod.ko will be skipped.
test_perf_branches_common:PASS:test_perf_branches_load 0 nsec
test_perf_branches_common:PASS:attach_perf_event 0 nsec
test_perf_branches_common:PASS:set_affinity 0 nsec
check_good_sample:PASS:output not valid 0 nsec
check_good_sample:FAIL:read_branches_size err -2
check_good_sample:FAIL:read_branches_stack err -2
check_good_sample:FAIL:read_branches_stack stack bytes written=-2
not multiple of struct size=24
check_good_sample:FAIL:read_branches_global err -2
check_good_sample:FAIL:read_branches_global global bytes written=-2
not multiple of struct size=24
check_good_sample:PASS:read_branches_size 0 nsec
 #75/1 perf_branches_hw:FAIL
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:FAIL
Summary: 0/1 PASSED, 0 SKIPPED, 2 FAILED

Selftest result in power9 box after this patch changes:

[command]#: ./test_progs -t perf_branches
 #75/1 perf_branches_hw:OK
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Kajol Jain<kjain@linux.ibm.com>
kernel-patches-bot pushed a commit that referenced this pull request Nov 15, 2021
Branch data available to bpf programs can be very useful to get
stack traces out of userspace applications.

Commit fff7b64 ("bpf: Add bpf_read_branch_records() helper")
added bpf support to capture branch records in x86. Enable this feature
for powerpc as well.

Commit 67306f8 ("selftests/bpf: Add bpf_read_branch_records()
selftest") adds selftest corresponding to bpf branch read
function bpf_read_branch_records(). Used this selftest to
test bpf support, for reading branch records in powerpc.

Selftest result in power9 box before this patch changes:

[command]# ./test_progs -t perf_branches
Failed to load bpf_testmod.ko into the kernel: -8
WARNING! Selftests relying on bpf_testmod.ko will be skipped.
test_perf_branches_common:PASS:test_perf_branches_load 0 nsec
test_perf_branches_common:PASS:attach_perf_event 0 nsec
test_perf_branches_common:PASS:set_affinity 0 nsec
check_good_sample:PASS:output not valid 0 nsec
check_good_sample:FAIL:read_branches_size err -2
check_good_sample:FAIL:read_branches_stack err -2
check_good_sample:FAIL:read_branches_stack stack bytes written=-2
not multiple of struct size=24
check_good_sample:FAIL:read_branches_global err -2
check_good_sample:FAIL:read_branches_global global bytes written=-2
not multiple of struct size=24
check_good_sample:PASS:read_branches_size 0 nsec
 #75/1 perf_branches_hw:FAIL
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:FAIL
Summary: 0/1 PASSED, 0 SKIPPED, 2 FAILED

Selftest result in power9 box after this patch changes:

[command]#: ./test_progs -t perf_branches
 #75/1 perf_branches_hw:OK
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Kajol Jain<kjain@linux.ibm.com>
kernel-patches-bot pushed a commit that referenced this pull request Nov 15, 2021
Branch data available to bpf programs can be very useful to get
stack traces out of userspace applications.

Commit fff7b64 ("bpf: Add bpf_read_branch_records() helper")
added bpf support to capture branch records in x86. Enable this feature
for powerpc as well.

Commit 67306f8 ("selftests/bpf: Add bpf_read_branch_records()
selftest") adds selftest corresponding to bpf branch read
function bpf_read_branch_records(). Used this selftest to
test bpf support, for reading branch records in powerpc.

Selftest result in power9 box before this patch changes:

[command]# ./test_progs -t perf_branches
Failed to load bpf_testmod.ko into the kernel: -8
WARNING! Selftests relying on bpf_testmod.ko will be skipped.
test_perf_branches_common:PASS:test_perf_branches_load 0 nsec
test_perf_branches_common:PASS:attach_perf_event 0 nsec
test_perf_branches_common:PASS:set_affinity 0 nsec
check_good_sample:PASS:output not valid 0 nsec
check_good_sample:FAIL:read_branches_size err -2
check_good_sample:FAIL:read_branches_stack err -2
check_good_sample:FAIL:read_branches_stack stack bytes written=-2
not multiple of struct size=24
check_good_sample:FAIL:read_branches_global err -2
check_good_sample:FAIL:read_branches_global global bytes written=-2
not multiple of struct size=24
check_good_sample:PASS:read_branches_size 0 nsec
 #75/1 perf_branches_hw:FAIL
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:FAIL
Summary: 0/1 PASSED, 0 SKIPPED, 2 FAILED

Selftest result in power9 box after this patch changes:

[command]#: ./test_progs -t perf_branches
 #75/1 perf_branches_hw:OK
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Kajol Jain<kjain@linux.ibm.com>
kernel-patches-bot pushed a commit that referenced this pull request Nov 16, 2021
Branch data available to bpf programs can be very useful to get
stack traces out of userspace applications.

Commit fff7b64 ("bpf: Add bpf_read_branch_records() helper")
added bpf support to capture branch records in x86. Enable this feature
for powerpc as well.

Commit 67306f8 ("selftests/bpf: Add bpf_read_branch_records()
selftest") adds selftest corresponding to bpf branch read
function bpf_read_branch_records(). Used this selftest to
test bpf support, for reading branch records in powerpc.

Selftest result in power9 box before this patch changes:

[command]# ./test_progs -t perf_branches
Failed to load bpf_testmod.ko into the kernel: -8
WARNING! Selftests relying on bpf_testmod.ko will be skipped.
test_perf_branches_common:PASS:test_perf_branches_load 0 nsec
test_perf_branches_common:PASS:attach_perf_event 0 nsec
test_perf_branches_common:PASS:set_affinity 0 nsec
check_good_sample:PASS:output not valid 0 nsec
check_good_sample:FAIL:read_branches_size err -2
check_good_sample:FAIL:read_branches_stack err -2
check_good_sample:FAIL:read_branches_stack stack bytes written=-2
not multiple of struct size=24
check_good_sample:FAIL:read_branches_global err -2
check_good_sample:FAIL:read_branches_global global bytes written=-2
not multiple of struct size=24
check_good_sample:PASS:read_branches_size 0 nsec
 #75/1 perf_branches_hw:FAIL
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:FAIL
Summary: 0/1 PASSED, 0 SKIPPED, 2 FAILED

Selftest result in power9 box after this patch changes:

[command]#: ./test_progs -t perf_branches
 #75/1 perf_branches_hw:OK
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Kajol Jain<kjain@linux.ibm.com>
kernel-patches-bot pushed a commit that referenced this pull request Nov 16, 2021
Branch data available to bpf programs can be very useful to get
stack traces out of userspace applications.

Commit fff7b64 ("bpf: Add bpf_read_branch_records() helper")
added bpf support to capture branch records in x86. Enable this feature
for powerpc as well.

Commit 67306f8 ("selftests/bpf: Add bpf_read_branch_records()
selftest") adds selftest corresponding to bpf branch read
function bpf_read_branch_records(). Used this selftest to
test bpf support, for reading branch records in powerpc.

Selftest result in power9 box before this patch changes:

[command]# ./test_progs -t perf_branches
Failed to load bpf_testmod.ko into the kernel: -8
WARNING! Selftests relying on bpf_testmod.ko will be skipped.
test_perf_branches_common:PASS:test_perf_branches_load 0 nsec
test_perf_branches_common:PASS:attach_perf_event 0 nsec
test_perf_branches_common:PASS:set_affinity 0 nsec
check_good_sample:PASS:output not valid 0 nsec
check_good_sample:FAIL:read_branches_size err -2
check_good_sample:FAIL:read_branches_stack err -2
check_good_sample:FAIL:read_branches_stack stack bytes written=-2
not multiple of struct size=24
check_good_sample:FAIL:read_branches_global err -2
check_good_sample:FAIL:read_branches_global global bytes written=-2
not multiple of struct size=24
check_good_sample:PASS:read_branches_size 0 nsec
 #75/1 perf_branches_hw:FAIL
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:FAIL
Summary: 0/1 PASSED, 0 SKIPPED, 2 FAILED

Selftest result in power9 box after this patch changes:

[command]#: ./test_progs -t perf_branches
 #75/1 perf_branches_hw:OK
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Kajol Jain<kjain@linux.ibm.com>
kernel-patches-bot pushed a commit that referenced this pull request Nov 16, 2021
Branch data available to bpf programs can be very useful to get
stack traces out of userspace applications.

Commit fff7b64 ("bpf: Add bpf_read_branch_records() helper")
added bpf support to capture branch records in x86. Enable this feature
for powerpc as well.

Commit 67306f8 ("selftests/bpf: Add bpf_read_branch_records()
selftest") adds selftest corresponding to bpf branch read
function bpf_read_branch_records(). Used this selftest to
test bpf support, for reading branch records in powerpc.

Selftest result in power9 box before this patch changes:

[command]# ./test_progs -t perf_branches
Failed to load bpf_testmod.ko into the kernel: -8
WARNING! Selftests relying on bpf_testmod.ko will be skipped.
test_perf_branches_common:PASS:test_perf_branches_load 0 nsec
test_perf_branches_common:PASS:attach_perf_event 0 nsec
test_perf_branches_common:PASS:set_affinity 0 nsec
check_good_sample:PASS:output not valid 0 nsec
check_good_sample:FAIL:read_branches_size err -2
check_good_sample:FAIL:read_branches_stack err -2
check_good_sample:FAIL:read_branches_stack stack bytes written=-2
not multiple of struct size=24
check_good_sample:FAIL:read_branches_global err -2
check_good_sample:FAIL:read_branches_global global bytes written=-2
not multiple of struct size=24
check_good_sample:PASS:read_branches_size 0 nsec
 #75/1 perf_branches_hw:FAIL
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:FAIL
Summary: 0/1 PASSED, 0 SKIPPED, 2 FAILED

Selftest result in power9 box after this patch changes:

[command]#: ./test_progs -t perf_branches
 #75/1 perf_branches_hw:OK
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Kajol Jain<kjain@linux.ibm.com>
kernel-patches-bot pushed a commit that referenced this pull request Nov 16, 2021
Branch data available to bpf programs can be very useful to get
stack traces out of userspace applications.

Commit fff7b64 ("bpf: Add bpf_read_branch_records() helper")
added bpf support to capture branch records in x86. Enable this feature
for powerpc as well.

Commit 67306f8 ("selftests/bpf: Add bpf_read_branch_records()
selftest") adds selftest corresponding to bpf branch read
function bpf_read_branch_records(). Used this selftest to
test bpf support, for reading branch records in powerpc.

Selftest result in power9 box before this patch changes:

[command]# ./test_progs -t perf_branches
Failed to load bpf_testmod.ko into the kernel: -8
WARNING! Selftests relying on bpf_testmod.ko will be skipped.
test_perf_branches_common:PASS:test_perf_branches_load 0 nsec
test_perf_branches_common:PASS:attach_perf_event 0 nsec
test_perf_branches_common:PASS:set_affinity 0 nsec
check_good_sample:PASS:output not valid 0 nsec
check_good_sample:FAIL:read_branches_size err -2
check_good_sample:FAIL:read_branches_stack err -2
check_good_sample:FAIL:read_branches_stack stack bytes written=-2
not multiple of struct size=24
check_good_sample:FAIL:read_branches_global err -2
check_good_sample:FAIL:read_branches_global global bytes written=-2
not multiple of struct size=24
check_good_sample:PASS:read_branches_size 0 nsec
 #75/1 perf_branches_hw:FAIL
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:FAIL
Summary: 0/1 PASSED, 0 SKIPPED, 2 FAILED

Selftest result in power9 box after this patch changes:

[command]#: ./test_progs -t perf_branches
 #75/1 perf_branches_hw:OK
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Kajol Jain<kjain@linux.ibm.com>
kernel-patches-bot pushed a commit that referenced this pull request Dec 9, 2021
…fails

Check for a valid hv_vp_index array prior to derefencing hv_vp_index when
setting Hyper-V's TSC change callback.  If Hyper-V setup failed in
hyperv_init(), the kernel will still report that it's running under
Hyper-V, but will have silently disabled nearly all functionality.

  BUG: kernel NULL pointer dereference, address: 0000000000000010
  #PF: supervisor read access in kernel mode
  #PF: error_code(0x0000) - not-present page
  PGD 0 P4D 0
  Oops: 0000 [#1] SMP
  CPU: 4 PID: 1 Comm: swapper/0 Not tainted 5.15.0-rc2+ #75
  Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015
  RIP: 0010:set_hv_tscchange_cb+0x15/0xa0
  Code: <8b> 04 82 8b 15 12 17 85 01 48 c1 e0 20 48 0d ee 00 01 00 f6 c6 08
  ...
  Call Trace:
   kvm_arch_init+0x17c/0x280
   kvm_init+0x31/0x330
   vmx_init+0xba/0x13a
   do_one_initcall+0x41/0x1c0
   kernel_init_freeable+0x1f2/0x23b
   kernel_init+0x16/0x120
   ret_from_fork+0x22/0x30

Fixes: 9328626 ("x86/hyperv: Reenlightenment notifications support")
Cc: stable@vger.kernel.org
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Link: https://lore.kernel.org/r/20211104182239.1302956-2-seanjc@google.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Aug 26, 2023
With latest clang18, I hit test_progs failures for the following test:
  #13/2    bpf_cookie/multi_kprobe_link_api:FAIL
  #13/3    bpf_cookie/multi_kprobe_attach_api:FAIL
  #13      bpf_cookie:FAIL
  #75      fentry_fexit:FAIL
  #76/1    fentry_test/fentry:FAIL
  #76      fentry_test:FAIL
  #80/1    fexit_test/fexit:FAIL
  #80      fexit_test:FAIL
  #110/1   kprobe_multi_test/skel_api:FAIL
  #110/2   kprobe_multi_test/link_api_addrs:FAIL
  #110/3   kprobe_multi_test/link_api_syms:FAIL
  #110/4   kprobe_multi_test/attach_api_pattern:FAIL
  #110/5   kprobe_multi_test/attach_api_addrs:FAIL
  #110/6   kprobe_multi_test/attach_api_syms:FAIL
  #110     kprobe_multi_test:FAIL

For example, for #13/2, the error messages are
  ...
  kprobe_multi_test_run:FAIL:kprobe_test7_result unexpected kprobe_test7_result: actual 0 != expected 1
  ...
  kprobe_multi_test_run:FAIL:kretprobe_test7_result unexpected kretprobe_test7_result: actual 0 != expected 1

clang17 does not have this issue.

Further investigation shows that kernel func bpf_fentry_test7(), used
in the above tests, is inlined by the compiler although it is
marked as noinline.

  int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
  {
        return (long)arg;
  }

It is known that for simple functions like the above (e.g. just returning
a constant or an input argument), the clang compiler may still do inlining
for a noinline function. Adding 'asm volatile ("")' in the beginning of the
bpf_fentry_test7() can prevent inlining.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Aug 27, 2023
With latest clang18, I hit test_progs failures for the following test:
  #13/2    bpf_cookie/multi_kprobe_link_api:FAIL
  #13/3    bpf_cookie/multi_kprobe_attach_api:FAIL
  #13      bpf_cookie:FAIL
  #75      fentry_fexit:FAIL
  #76/1    fentry_test/fentry:FAIL
  #76      fentry_test:FAIL
  #80/1    fexit_test/fexit:FAIL
  #80      fexit_test:FAIL
  #110/1   kprobe_multi_test/skel_api:FAIL
  #110/2   kprobe_multi_test/link_api_addrs:FAIL
  #110/3   kprobe_multi_test/link_api_syms:FAIL
  #110/4   kprobe_multi_test/attach_api_pattern:FAIL
  #110/5   kprobe_multi_test/attach_api_addrs:FAIL
  #110/6   kprobe_multi_test/attach_api_syms:FAIL
  #110     kprobe_multi_test:FAIL

For example, for #13/2, the error messages are
  ...
  kprobe_multi_test_run:FAIL:kprobe_test7_result unexpected kprobe_test7_result: actual 0 != expected 1
  ...
  kprobe_multi_test_run:FAIL:kretprobe_test7_result unexpected kretprobe_test7_result: actual 0 != expected 1

clang17 does not have this issue.

Further investigation shows that kernel func bpf_fentry_test7(), used
in the above tests, is inlined by the compiler although it is
marked as noinline.

  int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
  {
        return (long)arg;
  }

It is known that for simple functions like the above (e.g. just returning
a constant or an input argument), the clang compiler may still do inlining
for a noinline function. Adding 'asm volatile ("")' in the beginning of the
bpf_fentry_test7() can prevent inlining.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Aug 28, 2023
With latest clang18, I hit test_progs failures for the following test:
  #13/2    bpf_cookie/multi_kprobe_link_api:FAIL
  #13/3    bpf_cookie/multi_kprobe_attach_api:FAIL
  #13      bpf_cookie:FAIL
  #75      fentry_fexit:FAIL
  #76/1    fentry_test/fentry:FAIL
  #76      fentry_test:FAIL
  #80/1    fexit_test/fexit:FAIL
  #80      fexit_test:FAIL
  #110/1   kprobe_multi_test/skel_api:FAIL
  #110/2   kprobe_multi_test/link_api_addrs:FAIL
  #110/3   kprobe_multi_test/link_api_syms:FAIL
  #110/4   kprobe_multi_test/attach_api_pattern:FAIL
  #110/5   kprobe_multi_test/attach_api_addrs:FAIL
  #110/6   kprobe_multi_test/attach_api_syms:FAIL
  #110     kprobe_multi_test:FAIL

For example, for #13/2, the error messages are
  ...
  kprobe_multi_test_run:FAIL:kprobe_test7_result unexpected kprobe_test7_result: actual 0 != expected 1
  ...
  kprobe_multi_test_run:FAIL:kretprobe_test7_result unexpected kretprobe_test7_result: actual 0 != expected 1

clang17 does not have this issue.

Further investigation shows that kernel func bpf_fentry_test7(), used
in the above tests, is inlined by the compiler although it is
marked as noinline.

  int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
  {
        return (long)arg;
  }

It is known that for simple functions like the above (e.g. just returning
a constant or an input argument), the clang compiler may still do inlining
for a noinline function. Adding 'asm volatile ("")' in the beginning of the
bpf_fentry_test7() can prevent inlining.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Tested-by: Eduard Zingerman <eddyz87@gmail.com>
eddyz87 pushed a commit to eddyz87/bpf that referenced this pull request Aug 28, 2023
With latest clang18, I hit test_progs failures for the following test:
  kernel-patches#13/2    bpf_cookie/multi_kprobe_link_api:FAIL
  kernel-patches#13/3    bpf_cookie/multi_kprobe_attach_api:FAIL
  kernel-patches#13      bpf_cookie:FAIL
  kernel-patches#75      fentry_fexit:FAIL
  kernel-patches#76/1    fentry_test/fentry:FAIL
  kernel-patches#76      fentry_test:FAIL
  kernel-patches#80/1    fexit_test/fexit:FAIL
  kernel-patches#80      fexit_test:FAIL
  kernel-patches#110/1   kprobe_multi_test/skel_api:FAIL
  kernel-patches#110/2   kprobe_multi_test/link_api_addrs:FAIL
  kernel-patches#110/3   kprobe_multi_test/link_api_syms:FAIL
  kernel-patches#110/4   kprobe_multi_test/attach_api_pattern:FAIL
  kernel-patches#110/5   kprobe_multi_test/attach_api_addrs:FAIL
  kernel-patches#110/6   kprobe_multi_test/attach_api_syms:FAIL
  kernel-patches#110     kprobe_multi_test:FAIL

For example, for kernel-patches#13/2, the error messages are
  ...
  kprobe_multi_test_run:FAIL:kprobe_test7_result unexpected kprobe_test7_result: actual 0 != expected 1
  ...
  kprobe_multi_test_run:FAIL:kretprobe_test7_result unexpected kretprobe_test7_result: actual 0 != expected 1

clang17 does not have this issue.

Further investigation shows that kernel func bpf_fentry_test7(), used
in the above tests, is inlined by the compiler although it is
marked as noinline.

  int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
  {
        return (long)arg;
  }

It is known that for simple functions like the above (e.g. just returning
a constant or an input argument), the clang compiler may still do inlining
for a noinline function. Adding 'asm volatile ("")' in the beginning of the
bpf_fentry_test7() can prevent inlining.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Aug 30, 2023
With latest clang18, I hit test_progs failures for the following test:

  #13/2    bpf_cookie/multi_kprobe_link_api:FAIL
  #13/3    bpf_cookie/multi_kprobe_attach_api:FAIL
  #13      bpf_cookie:FAIL
  #75      fentry_fexit:FAIL
  #76/1    fentry_test/fentry:FAIL
  #76      fentry_test:FAIL
  #80/1    fexit_test/fexit:FAIL
  #80      fexit_test:FAIL
  #110/1   kprobe_multi_test/skel_api:FAIL
  #110/2   kprobe_multi_test/link_api_addrs:FAIL
  #110/3   kprobe_multi_test/link_api_syms:FAIL
  #110/4   kprobe_multi_test/attach_api_pattern:FAIL
  #110/5   kprobe_multi_test/attach_api_addrs:FAIL
  #110/6   kprobe_multi_test/attach_api_syms:FAIL
  #110     kprobe_multi_test:FAIL

For example, for #13/2, the error messages are:

  [...]
  kprobe_multi_test_run:FAIL:kprobe_test7_result unexpected kprobe_test7_result: actual 0 != expected 1
  [...]
  kprobe_multi_test_run:FAIL:kretprobe_test7_result unexpected kretprobe_test7_result: actual 0 != expected 1

clang17 does not have this issue.

Further investigation shows that kernel func bpf_fentry_test7(), used in
the above tests, is inlined by the compiler although it is marked as
noinline.

  int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
  {
        return (long)arg;
  }

It is known that for simple functions like the above (e.g. just returning
a constant or an input argument), the clang compiler may still do inlining
for a noinline function. Adding 'asm volatile ("")' in the beginning of the
bpf_fentry_test7() can prevent inlining.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/20230826200843.2210074-1-yonghong.song@linux.dev
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Aug 30, 2023
With latest clang18, I hit test_progs failures for the following test:
  #13/2    bpf_cookie/multi_kprobe_link_api:FAIL
  #13/3    bpf_cookie/multi_kprobe_attach_api:FAIL
  #13      bpf_cookie:FAIL
  #75      fentry_fexit:FAIL
  #76/1    fentry_test/fentry:FAIL
  #76      fentry_test:FAIL
  #80/1    fexit_test/fexit:FAIL
  #80      fexit_test:FAIL
  #110/1   kprobe_multi_test/skel_api:FAIL
  #110/2   kprobe_multi_test/link_api_addrs:FAIL
  #110/3   kprobe_multi_test/link_api_syms:FAIL
  #110/4   kprobe_multi_test/attach_api_pattern:FAIL
  #110/5   kprobe_multi_test/attach_api_addrs:FAIL
  #110/6   kprobe_multi_test/attach_api_syms:FAIL
  #110     kprobe_multi_test:FAIL

For example, for #13/2, the error messages are
  ...
  kprobe_multi_test_run:FAIL:kprobe_test7_result unexpected kprobe_test7_result: actual 0 != expected 1
  ...
  kprobe_multi_test_run:FAIL:kretprobe_test7_result unexpected kretprobe_test7_result: actual 0 != expected 1

clang17 does not have this issue.

Further investigation shows that kernel func bpf_fentry_test7(), used
in the above tests, is inlined by the compiler although it is
marked as noinline.

  int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
  {
        return (long)arg;
  }

It is known that for simple functions like the above (e.g. just returning
a constant or an input argument), the clang compiler may still do inlining
for a noinline function. Adding 'asm volatile ("")' in the beginning of the
bpf_fentry_test7() can prevent inlining.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Tested-by: Eduard Zingerman <eddyz87@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants