-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
MDEV-34815 SIGILL error when executing mariadbd compiled for RISC-V with Clang #3661
MDEV-34815 SIGILL error when executing mariadbd compiled for RISC-V with Clang #3661
Conversation
On clang we use __builtin_readcyclecounter(), except for AARCH64. | ||
On clang we use __builtin_readcyclecounter(), except for AARCH64 and RISC-V. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to see a justification for these exceptions, such as links to clang bug reports. I found that the RISC-V implementation was added in https://reviews.llvm.org/D64125 but I found no bug report about this. Can you please file one?
For ARMv8 there already is a bug report llvm/llvm-project#43652 where it is suggested that the instruction could work depending on the operating system kernel configuration.
These optionally privileged instructions could be usable if on the affected ISA we made my_timer_cycles()
a function pointer. An initialization function could try to run the instruction under a SIGILL wrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite right, was thinking the same. Clang isn't just for kernels and root processes. I did compiler export the latest version and the behaviour is still there.
include/my_rdtsc.h
Outdated
@@ -152,7 +152,7 @@ C_MODE_START | |||
*/ | |||
static inline ulonglong my_timer_cycles(void) | |||
{ | |||
# if __has_builtin(__builtin_readcyclecounter) && !defined (__aarch64__) | |||
# if __has_builtin(__builtin_readcyclecounter) && !defined (__aarch64__) && !defined(__riscv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be gated on linux, other operating systems such as FreeBSD don't make this inaccessible. Quite surprising to see that x86 rdtsc is permitted but the aarch64 counters are not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, adjusted. Seems the Aarch64 was removed for performance reasons instead rather than Kernel limitation. Oops mea cupla. It was previous (<14.0.0) clang mapping of __builltin_readcycle counter that mapped to PMCCNTR_EL0 resulting in SIGILL - MDEV-23249).
…ith Clang RISC-V and Clang produce rdcycle for __builtin_readcyclecounter. Since Linux kernel 6.6 this is a privileged instruction not available to userspace programs. The use of __builtin_readcyclecounter is excluded from RISCV falling back to the rdtime/rdtimeh instructions provided in MDEV-33435. Thanks Alexander Richardson for noting it should be linux only in the code and noting FreeBSD RISC-V permits rdcycle. Author: BINSZ on JIRA
1e0434a
to
1d1520b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks, Daniel
Description
RISC-V and Clang produce rdcycle for __builtin_readcyclecounter.
Since Linux kernel 6.6 this is a privileged instruction not available to userspace programs.
The use of __builtin_readcyclecounter is excluded from RISCV falling back to the rdtime/rdtimeh instructions provided in MDEV-33435.
Author: BINSZ on JIRA
Release Notes
Correct SIGILL on RISC-V for Linux kernels 6.6+ when compiled with clang.
How can this PR be tested?
Environment as above.
Basing the PR against the correct MariaDB version
main
branch.PR quality check