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

Segmentation fault on Apple M2 #1253

Open
steffenvongrabau opened this issue Jan 7, 2025 · 9 comments
Open

Segmentation fault on Apple M2 #1253

steffenvongrabau opened this issue Jan 7, 2025 · 9 comments

Comments

@steffenvongrabau
Copy link

I've stumbled upon this issue while trying to run Niri and it instantly segfaulted.
Using GDB I generated the following backtrace, which shows: Segmentation fault.
init_from_sysinfo_ehdr () at src/backend/linux_raw/vdso.rs:187
gdb.txt

I cloned this git repository and ran cargo test --features=all-apis --no-fail-fast which showed multiple tests failing.
cargo_test.txt

tests/time/main.rs segfaults with no further error message, so I manually ran target/debug/deps/time-ebc378475d0c4529 with rust-gdb to generate this backtrace:
gdb_time.txt
Like the Niri backtrace it also shows: Segmentation fault.
rustix::backend::vdso::init_from_sysinfo_ehdr () at src/backend/linux_raw/vdso.rs:187

System Information

  • Gentoo aarch64
    • KernelPageSize: 16KB
    • MMUPageSize: 16KB
  • CPU: Apple M2
  • rustix version: 0.38.35
@steffenvongrabau
Copy link
Author

I reran cargo test on a rk3588 (Radxa Rock 5b 8G, also aarch64 but 4KB pagesize) to see if the issue persists or is specific to the Apple M2 SoC.

3 targets failing on M2 passed on rk3588:
--test fs
--test mm
--test pipe

2 targets still failed:
--test thread
--test time (segfault)

cargo_test_rk3588.txt

@sunfishcode
Copy link
Member

Thanks for the report! I don't have an Apple M2 myself, but going by the backtrace you provided, I have a guess of at least part of what's going on. Would you be able to test the patch in #1254?

If you're able to, I'd also be curious to know if you could run tests such as the vdso_test_gettimeofday.c test in https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/vDSO/. If your vDSO is missing a DT_HASH section, that test should fail as well.

@steffenvongrabau
Copy link
Author

Thanks a lot for the quick response! I've tested the patch in #1254 and tests/time/main.rs passed but test backend::vdso::test:vdso fails now.
cargo_test_patch1254.txt

vdso_test_gettimeofday outputs Could not find __kernel_gettimeofday
Please let me know if there's anything else I can do.

@sunfishcode
Copy link
Member

Cool, thanks for testing!

I will land the patch (after fixing some unrelated CI breakage). I may disable that test_vdso test disabled on aarch64, unless I learn more about what's causing this issue.

Also, it appears your Linux kernel's vDSO is lacking a DT_HASH entry, which means that even Linux's own reference vDSO parser can't parse it. The downside of this (besides hitting this rustix bug) is that you may be missing out on the fast clock_gettime, and potentially other optimizations as well, in rustix, but possibly also in your libc. I would suggest reporting this as a bug with your Linux upstream.

@sunfishcode
Copy link
Member

This may be caused by torvalds/linux@48f6430, in which case it's not a bug. It appears the changes to Linux's reference parser haven't landed yet, but it looks like https://lore.kernel.org/lkml/[email protected]/T/#r3166a373d53e9beb19a33abcbd3eb131dcdcc107 is the needed change.

@steffenvongrabau
Copy link
Author

I've added the patch and ran the tests again. vdso_test_gettimeofday now outputs the correct time

@sunfishcode
Copy link
Member

I've now released rustix 0.38.43 with the fix for the segmentation fault. For now if there's no DT_HASH section it'll just forego the vDSO. I'll implement the DT_GNU_HASH algorithm in a separate PR.

@sunfishcode
Copy link
Member

I've now submitted #1259 implementing DT_GNU_HASH support, and re-enabling the test_vdso test.

@steffenvongrabau Would you by change be able to test out the patch in #1259?

@steffenvongrabau
Copy link
Author

steffenvongrabau commented Jan 8, 2025

With the patch in #1259 test backend::vdso::test_vdso passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants