Skip to content

Commit 3a24df9

Browse files
committed
[ARM] Pass for Cortex-A57 and Cortex-A72 Fused AES Erratum
This adds a late Machine Pass to work around a Cortex CPU Erratum affecting Cortex-A57 and Cortex-A72: - Cortex-A57 Erratum 1742098 - Cortex-A72 Erratum 1655431 The pass inserts instructions to make the inputs to the fused AES instruction pairs no longer trigger the erratum. Here the pass errs on the side of caution, inserting the instructions wherever we cannot prove that the inputs came from a safe instruction. The pass is used: - for Cortex-A57 and Cortex-A72, - for "generic" cores (which are used when using `-march=`), - when the user specifies `-mfix-cortex-a57-aes-1742098` or `mfix-cortex-a72-aes-1655431` in the command-line arguments to clang. Reviewed By: dmgreen, simon_tatham Differential Revision: https://reviews.llvm.org/D119720
1 parent 7deed49 commit 3a24df9

File tree

10 files changed

+627
-3
lines changed

10 files changed

+627
-3
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,6 +3451,20 @@ def mfix_cmse_cve_2021_35465 : Flag<["-"], "mfix-cmse-cve-2021-35465">,
34513451
def mno_fix_cmse_cve_2021_35465 : Flag<["-"], "mno-fix-cmse-cve-2021-35465">,
34523452
Group<m_arm_Features_Group>,
34533453
HelpText<"Don't work around VLLDM erratum CVE-2021-35465 (ARM only)">;
3454+
def mfix_cortex_a57_aes_1742098 : Flag<["-"], "mfix-cortex-a57-aes-1742098">,
3455+
Group<m_arm_Features_Group>,
3456+
HelpText<"Work around Cortex-A57 Erratum 1742098 (ARM only)">;
3457+
def mno_fix_cortex_a57_aes_1742098 : Flag<["-"], "mno-fix-cortex-a57-aes-1742098">,
3458+
Group<m_arm_Features_Group>,
3459+
HelpText<"Don't work around Cortex-A57 Erratum 1742098 (ARM only)">;
3460+
def mfix_cortex_a72_aes_1655431 : Flag<["-"], "mfix-cortex-a72-aes-1655431">,
3461+
Group<m_arm_Features_Group>,
3462+
HelpText<"Work around Cortex-A72 Erratum 1655431 (ARM only)">,
3463+
Alias<mfix_cortex_a57_aes_1742098>;
3464+
def mno_fix_cortex_a72_aes_1655431 : Flag<["-"], "mno-fix-cortex-a72-aes-1655431">,
3465+
Group<m_arm_Features_Group>,
3466+
HelpText<"Don't work around Cortex-A72 Erratum 1655431 (ARM only)">,
3467+
Alias<mno_fix_cortex_a57_aes_1742098>;
34543468
def mfix_cortex_a53_835769 : Flag<["-"], "mfix-cortex-a53-835769">,
34553469
Group<m_aarch64_Features_Group>,
34563470
HelpText<"Workaround Cortex-A53 erratum 835769 (AArch64 only)">;

clang/lib/Driver/ToolChains/Arch/ARM.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,16 @@ void arm::getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple,
733733
Features.push_back("-fix-cmse-cve-2021-35465");
734734
}
735735

736+
// This also handles the -m(no-)fix-cortex-a72-1655431 arguments via aliases.
737+
if (Arg *A = Args.getLastArg(options::OPT_mfix_cortex_a57_aes_1742098,
738+
options::OPT_mno_fix_cortex_a57_aes_1742098)) {
739+
if (A->getOption().matches(options::OPT_mfix_cortex_a57_aes_1742098)) {
740+
Features.push_back("+fix-cortex-a57-aes-1742098");
741+
} else {
742+
Features.push_back("-fix-cortex-a57-aes-1742098");
743+
}
744+
}
745+
736746
// Look for the last occurrence of -mlong-calls or -mno-long-calls. If
737747
// neither options are specified, see if we are compiling for kernel/kext and
738748
// decide whether to pass "+long-calls" based on the OS and its version.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clang -### %s -target arm-none-none-eabi -march=armv8a -mfix-cortex-a57-aes-1742098 2>&1 | FileCheck %s --check-prefix=FIX
2+
// RUN: %clang -### %s -target arm-none-none-eabi -march=armv8a -mno-fix-cortex-a57-aes-1742098 2>&1 | FileCheck %s --check-prefix=NO-FIX
3+
4+
// RUN: %clang -### %s -target arm-none-none-eabi -march=armv8a -mfix-cortex-a72-aes-1655431 2>&1 | FileCheck %s --check-prefix=FIX
5+
// RUN: %clang -### %s -target arm-none-none-eabi -march=armv8a -mno-fix-cortex-a72-aes-1655431 2>&1 | FileCheck %s --check-prefix=NO-FIX
6+
7+
// RUN: %clang -### %s -target arm-none-none-eabi -march=armv8a 2>&1 | FileCheck %s --check-prefix=UNSPEC
8+
// RUN: %clang -### %s -target arm-none-none-eabi -march=armv8a 2>&1 | FileCheck %s --check-prefix=UNSPEC
9+
10+
// This test checks that "-m(no-)fix-cortex-a57-aes-1742098" and
11+
// "-m(no-)fix-cortex-a72-aes-1655431" cause the "fix-cortex-a57-aes-1742098"
12+
// target feature to be passed to `clang -cc1`.
13+
//
14+
// This feature is also enabled in the backend for the two affected CPUs and the
15+
// "generic" cpu (used when only specifying -march), but that won't show up on
16+
// the `clang -cc1` command line.
17+
//
18+
// We do not check whether this option is correctly specified for the CPU: users
19+
// can specify the "-mfix-cortex-a57-aes-1742098" option with "-mcpu=cortex-a72"
20+
// and vice-versa, and will still get the fix, as the target feature and the fix
21+
// is the same in both cases.
22+
23+
// FIX: "-target-feature" "+fix-cortex-a57-aes-1742098"
24+
// NO-FIX: "-target-feature" "-fix-cortex-a57-aes-1742098"
25+
// UNSPEC-NOT: "-target-feature" "{[+-]}fix-cortex-a57-aes-1742098"

llvm/lib/Target/ARM/ARM.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Pass *createMVEGatherScatterLoweringPass();
5757
FunctionPass *createARMSLSHardeningPass();
5858
FunctionPass *createARMIndirectThunks();
5959
Pass *createMVELaneInterleavingPass();
60+
FunctionPass *createARMFixCortexA57AES1742098Pass();
6061

6162
void LowerARMMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI,
6263
ARMAsmPrinter &AP);
@@ -77,6 +78,7 @@ void initializeMVETailPredicationPass(PassRegistry &);
7778
void initializeMVEGatherScatterLoweringPass(PassRegistry &);
7879
void initializeARMSLSHardeningPass(PassRegistry &);
7980
void initializeMVELaneInterleavingPass(PassRegistry &);
81+
void initializeARMFixCortexA57AES1742098Pass(PassRegistry &);
8082

8183
} // end namespace llvm
8284

llvm/lib/Target/ARM/ARM.td

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ def FeatureNoBTIAtReturnTwice : SubtargetFeature<"no-bti-at-return-twice",
542542
"Don't place a BTI instruction "
543543
"after a return-twice">;
544544

545+
def FeatureFixCortexA57AES1742098 : SubtargetFeature<"fix-cortex-a57-aes-1742098",
546+
"FixCortexA57AES1742098", "true",
547+
"Work around Cortex-A57 Erratum 1742098 / Cortex-A72 Erratum 1655431 (AES)">;
548+
545549
//===----------------------------------------------------------------------===//
546550
// ARM architecture class
547551
//
@@ -1157,7 +1161,7 @@ include "ARMScheduleM7.td"
11571161
// ARM processors
11581162
//
11591163
// Dummy CPU, used to target architectures
1160-
def : ProcessorModel<"generic", CortexA8Model, []>;
1164+
def : ProcessorModel<"generic", CortexA8Model, [FeatureFixCortexA57AES1742098]>;
11611165

11621166
// FIXME: Several processors below are not using their own scheduler
11631167
// model, but one of similar/previous processor. These should be fixed.
@@ -1467,13 +1471,15 @@ def : ProcessorModel<"cortex-a57", CortexA57Model, [ARMv8a, ProcA57,
14671471
FeatureCRC,
14681472
FeatureFPAO,
14691473
FeatureAvoidPartialCPSR,
1470-
FeatureCheapPredicableCPSR]>;
1474+
FeatureCheapPredicableCPSR,
1475+
FeatureFixCortexA57AES1742098]>;
14711476

14721477
def : ProcessorModel<"cortex-a72", CortexA57Model, [ARMv8a, ProcA72,
14731478
FeatureHWDivThumb,
14741479
FeatureHWDivARM,
14751480
FeatureCrypto,
1476-
FeatureCRC]>;
1481+
FeatureCRC,
1482+
FeatureFixCortexA57AES1742098]>;
14771483

14781484
def : ProcNoItin<"cortex-a73", [ARMv8a, ProcA73,
14791485
FeatureHWDivThumb,

0 commit comments

Comments
 (0)