Skip to content

Commit d0870ff

Browse files
lakshayk-nvIanWood1
authored andcommitted
[llvm-exegesis][AArch64] Disable pauth and ldgm as unsupported instructions fixed (llvm#136868)
[llvm-exegesis][AArch64] Recommit: Disable pauth and ldgm as unsupported instructions. Skipping AUT and LDGM opcode variants which currently throws "illegal instruction". Last pull request [llvm#132346](llvm#132346) got reviewed and merged but builder bot got failed. This was due to undefined `PR_PAC_SET_ENABLED_KEYS` utilized were not defined in x86 arch, resulting in build failure. This is followup to merge the changes with following changes to fixup the build failure. Changes: - Fixed up the problem with arch specific check for `prctl` library import - Defining `PR_PAC_SET_ENABLED_KEYS` if undefined.
1 parent 8429b64 commit d0870ff

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
llvm/test/tools/llvm-exegesis/AArch64/skip_unsupported_instructions.s
2+
3+
# REQUIRES: aarch64-registered-target
4+
5+
# Check for skipping of illegal instruction errors (AUT and LDGM)
6+
# RUN: llvm-exegesis -mcpu=neoverse-v2 -mode=latency --opcode-name=AUTIA --benchmark-phase=assemble-measured-code 2>&1 | FileCheck %s --check-prefix=CHECK-AUTIA
7+
# CHECK-AUTIA-NOT: snippet crashed while running: Illegal instruction
8+
9+
# RUN: llvm-exegesis -mcpu=neoverse-v2 -mode=latency --opcode-name=LDGM --benchmark-phase=assemble-measured-code 2>&1 | FileCheck %s --check-prefix=CHECK-LDGM
10+
# CHECK-LDGM: LDGM: Unsupported opcode: load tag multiple

llvm/tools/llvm-exegesis/lib/AArch64/Target.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,64 @@
99
#include "AArch64.h"
1010
#include "AArch64RegisterInfo.h"
1111

12+
#if defined(__aarch64__) && defined(__linux__)
13+
#include <linux/prctl.h> // For PR_PAC_* constants
14+
#include <sys/prctl.h>
15+
#ifndef PR_PAC_SET_ENABLED_KEYS
16+
#define PR_PAC_SET_ENABLED_KEYS 60
17+
#endif
18+
#ifndef PR_PAC_GET_ENABLED_KEYS
19+
#define PR_PAC_GET_ENABLED_KEYS 61
20+
#endif
21+
#endif
22+
1223
#define GET_AVAILABLE_OPCODE_CHECKER
1324
#include "AArch64GenInstrInfo.inc"
1425

1526
namespace llvm {
1627
namespace exegesis {
1728

29+
bool isPointerAuth(unsigned Opcode) {
30+
switch (Opcode) {
31+
default:
32+
return false;
33+
34+
// FIXME: Pointer Authentication instructions.
35+
// We would like to measure these instructions, but they can behave
36+
// differently on different platforms, and maybe the snippets need to look
37+
// different for these instructions,
38+
// Platform-specific handling: On Linux, we disable authentication, may
39+
// interfere with measurements. On non-Linux platforms, disable opcodes for
40+
// now.
41+
case AArch64::AUTDA:
42+
case AArch64::AUTDB:
43+
case AArch64::AUTDZA:
44+
case AArch64::AUTDZB:
45+
case AArch64::AUTIA:
46+
case AArch64::AUTIA1716:
47+
case AArch64::AUTIASP:
48+
case AArch64::AUTIAZ:
49+
case AArch64::AUTIB:
50+
case AArch64::AUTIB1716:
51+
case AArch64::AUTIBSP:
52+
case AArch64::AUTIBZ:
53+
case AArch64::AUTIZA:
54+
case AArch64::AUTIZB:
55+
return true;
56+
}
57+
}
58+
59+
bool isLoadTagMultiple(unsigned Opcode) {
60+
switch (Opcode) {
61+
default:
62+
return false;
63+
64+
// Load tag multiple instruction
65+
case AArch64::LDGM:
66+
return true;
67+
}
68+
}
69+
1870
static unsigned getLoadImmediateOpcode(unsigned RegBitWidth) {
1971
switch (RegBitWidth) {
2072
case 32:
@@ -134,6 +186,35 @@ class ExegesisAArch64Target : public ExegesisTarget {
134186
// Function return is a pseudo-instruction that needs to be expanded
135187
PM.add(createAArch64ExpandPseudoPass());
136188
}
189+
190+
const char *getIgnoredOpcodeReasonOrNull(const LLVMState &State,
191+
unsigned Opcode) const override {
192+
if (const char *Reason =
193+
ExegesisTarget::getIgnoredOpcodeReasonOrNull(State, Opcode))
194+
return Reason;
195+
196+
if (isPointerAuth(Opcode)) {
197+
#if defined(__aarch64__) && defined(__linux__)
198+
// Disable all PAC keys. Note that while we expect the measurements to
199+
// be the same with PAC keys disabled, they could potentially be lower
200+
// since authentication checks are bypassed.
201+
if (prctl(PR_PAC_SET_ENABLED_KEYS,
202+
PR_PAC_APIAKEY | PR_PAC_APIBKEY | PR_PAC_APDAKEY |
203+
PR_PAC_APDBKEY, // all keys
204+
0, // disable all
205+
0, 0) < 0) {
206+
return "Failed to disable PAC keys";
207+
}
208+
#else
209+
return "Unsupported opcode: isPointerAuth";
210+
#endif
211+
}
212+
213+
if (isLoadTagMultiple(Opcode))
214+
return "Unsupported opcode: load tag multiple";
215+
216+
return nullptr;
217+
}
137218
};
138219

139220
} // namespace

0 commit comments

Comments
 (0)