Skip to content

Commit 559540d

Browse files
authored
[llvm-exegesis][AArch64] Disable pauth and ldgm as unsupported instructions (#132346)
[llvm-exegesis][AArch64] Disable pauth and ldgm as unsupported instructions. Skipping AUT and LDGM opcode variants which currently throws "illegal instruction". - Checking opcodes specifically for LDGM and AUT opcode instruction variants. - Gracefully exiting with " : Unsupported opcode: isPointerAuth/isUncheckedAccess" - Added corresponding test cases to check exit message.
1 parent 50e218a commit 559540d

File tree

2 files changed

+83
-0
lines changed

2 files changed

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

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

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

12+
#ifdef __linux__
13+
#include <linux/prctl.h> // For PR_PAC_* constants
14+
#include <sys/prctl.h>
15+
#endif
16+
1217
#define GET_AVAILABLE_OPCODE_CHECKER
1318
#include "AArch64GenInstrInfo.inc"
1419

1520
namespace llvm {
1621
namespace exegesis {
1722

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

139214
} // namespace

0 commit comments

Comments
 (0)