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

[llvm-exegesis] Use correct rseq struct size #100804

Merged

Conversation

boomanaiden154
Copy link
Contributor

Glibc v2.40 changes the definition of __rseq_size to the usable area of the struct rather than the actual size of the struct to accommodate users trying to figure out what features can be used. This change breaks llvm-exegesis trying to disable rseq as the size registered in the kernel is no longer equal to __rseq_size. This patch adds a check to see if __rseq_size is less than 32 bytes and uses 32 as a value if it is given alignment requirements.

Fixes #100791.

Glibc v2.40 changes the definition of __rseq_size to the usable area of
the struct rather than the actual size of the struct to accommodate
users trying to figure out what features can be used. This change breaks
llvm-exegesis trying to disable rseq as the size registered in the
kernel is no longer equal to __rseq_size. This patch adds a check to see
if __rseq_size is less than 32 bytes and uses 32 as a value if it is
given alignment requirements.

Fixes llvm#100791.
@llvmbot
Copy link
Member

llvmbot commented Jul 26, 2024

@llvm/pr-subscribers-tools-llvm-exegesis

Author: Aiden Grossman (boomanaiden154)

Changes

Glibc v2.40 changes the definition of __rseq_size to the usable area of the struct rather than the actual size of the struct to accommodate users trying to figure out what features can be used. This change breaks llvm-exegesis trying to disable rseq as the size registered in the kernel is no longer equal to __rseq_size. This patch adds a check to see if __rseq_size is less than 32 bytes and uses 32 as a value if it is given alignment requirements.

Fixes #100791.


Full diff: https://github.com/llvm/llvm-project/pull/100804.diff

1 Files Affected:

  • (modified) llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (+12-1)
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index ed53f8fabb175..adee869967d98 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -466,9 +466,20 @@ class SubProcessFunctionExecutorImpl
 // segfaults in the program. Unregister the rseq region so that we can safely
 // unmap it later
 #ifdef GLIBC_INITS_RSEQ
+    unsigned int RseqStructSize = __rseq_size;
+
+    // Glibc v2.40 (the change is also expected to be backported to v2.35)
+    // changes the definition of __rseq_size to be the usable area of the struct
+    // rather than the actual size of the struct. v2.35 uses only 20 bytes of
+    // the 32 byte struct. For now, it should be safe to assume that if the
+    // usable size is less than 32, the actual size of the struct will be 32
+    // bytes given alignment requirements.
+    if (__rseq_size < 32)
+      RseqStructSize = 32;
+
     long RseqDisableOutput =
         syscall(SYS_rseq, (intptr_t)__builtin_thread_pointer() + __rseq_offset,
-                __rseq_size, RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
+                RseqStructSize, RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
     if (RseqDisableOutput != 0)
       exit(ChildProcessExitCodeE::RSeqDisableFailed);
 #endif // GLIBC_INITS_RSEQ

@boomanaiden154
Copy link
Contributor Author

@mgorny Can you apply this locally and test that this fixes the issue that you saw? I don't have glibc 2.40 on a machine with perf counters available to test.

@mgorny
Copy link
Member

mgorny commented Jul 26, 2024

Sure, will do, but probably tomorrow.

Copy link
Member

@mgorny mgorny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This fixes the issue for me.

@boomanaiden154 boomanaiden154 merged commit 1e8df9e into llvm:main Jul 27, 2024
9 checks passed
@boomanaiden154 boomanaiden154 deleted the exegesis-glibc-v240-rseq-size branch July 27, 2024 17:53
@boomanaiden154 boomanaiden154 added this to the LLVM 19.X Release milestone Jul 27, 2024
@boomanaiden154
Copy link
Contributor Author

/cherry-pick 1e8df9e

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 27, 2024
Glibc v2.40 changes the definition of __rseq_size to the usable area of
the struct rather than the actual size of the struct to accommodate
users trying to figure out what features can be used. This change breaks
llvm-exegesis trying to disable rseq as the size registered in the
kernel is no longer equal to __rseq_size. This patch adds a check to see
if __rseq_size is less than 32 bytes and uses 32 as a value if it is
given alignment requirements.

Fixes llvm#100791.

(cherry picked from commit 1e8df9e)
@llvmbot
Copy link
Member

llvmbot commented Jul 27, 2024

/pull-request #100885

@llvmbot
Copy link
Member

llvmbot commented Jul 27, 2024

Failed to create pull request for issue100804 https://github.com/llvm/llvm-project/actions/runs/10125556000

@boomanaiden154
Copy link
Contributor Author

/cherry-pick 1e8df9e

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 27, 2024
Glibc v2.40 changes the definition of __rseq_size to the usable area of
the struct rather than the actual size of the struct to accommodate
users trying to figure out what features can be used. This change breaks
llvm-exegesis trying to disable rseq as the size registered in the
kernel is no longer equal to __rseq_size. This patch adds a check to see
if __rseq_size is less than 32 bytes and uses 32 as a value if it is
given alignment requirements.

Fixes llvm#100791.

(cherry picked from commit 1e8df9e)
@llvmbot
Copy link
Member

llvmbot commented Jul 27, 2024

/pull-request #100896

tru pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 29, 2024
Glibc v2.40 changes the definition of __rseq_size to the usable area of
the struct rather than the actual size of the struct to accommodate
users trying to figure out what features can be used. This change breaks
llvm-exegesis trying to disable rseq as the size registered in the
kernel is no longer equal to __rseq_size. This patch adds a check to see
if __rseq_size is less than 32 bytes and uses 32 as a value if it is
given alignment requirements.

Fixes llvm#100791.

(cherry picked from commit 1e8df9e)
Ma27 added a commit to Ma27/nixpkgs that referenced this pull request Sep 15, 2024
See llvm/llvm-project#100804 for further
context.

Tests for LLVM 12 to 16 pass fine without this change (the entire
section of the test doesn't exist there), our LLVM 19 already has the
patch applied.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

tools/llvm-exegesis/X86/latency tests fail with glibc 2.40
3 participants