aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Di Biagio <andrea.dibiagio@sony.com>2021-04-20 12:57:20 +0100
committerAndrea Di Biagio <andrea.dibiagio@sony.com>2021-04-20 13:30:45 +0100
commit2226d21896d6d30d51e13385361ea0706ee9d9fb (patch)
tree5526f532a01eeb067e280f4211943485e858dabb
parent[PowerPC] Canonicalize shuffles on big endian targets as well (diff)
downloadllvm-project-2226d21896d6d30d51e13385361ea0706ee9d9fb.tar.gz
llvm-project-2226d21896d6d30d51e13385361ea0706ee9d9fb.tar.bz2
llvm-project-2226d21896d6d30d51e13385361ea0706ee9d9fb.zip
[MCA][LSUnit] Fix a potential use after free in the logic that updates memory groups.
Make sure that the `CriticalMemoryInstruction` of a memory group is invalidated if it references an already executed instruction. This avoids a potential use-after-free if the critical memory info becomes stale, and the value is read after the instruction has executed.
-rw-r--r--llvm/include/llvm/MCA/HardwareUnits/LSUnit.h7
-rw-r--r--llvm/lib/MCA/HardwareUnits/LSUnit.cpp2
2 files changed, 7 insertions, 2 deletions
diff --git a/llvm/include/llvm/MCA/HardwareUnits/LSUnit.h b/llvm/include/llvm/MCA/HardwareUnits/LSUnit.h
index 0f1fac55af4f..7eddd067aa0c 100644
--- a/llvm/include/llvm/MCA/HardwareUnits/LSUnit.h
+++ b/llvm/include/llvm/MCA/HardwareUnits/LSUnit.h
@@ -160,11 +160,16 @@ public:
MG->onGroupIssued(CriticalMemoryInstruction, true);
}
- void onInstructionExecuted() {
+ void onInstructionExecuted(const InstRef &IR) {
assert(isReady() && !isExecuted() && "Invalid internal state!");
--NumExecuting;
++NumExecuted;
+ if (CriticalMemoryInstruction &&
+ CriticalMemoryInstruction.getSourceIndex() == IR.getSourceIndex()) {
+ CriticalMemoryInstruction.invalidate();
+ }
+
if (!isExecuted())
return;
diff --git a/llvm/lib/MCA/HardwareUnits/LSUnit.cpp b/llvm/lib/MCA/HardwareUnits/LSUnit.cpp
index 4594368fc0e9..07be7b077bc9 100644
--- a/llvm/lib/MCA/HardwareUnits/LSUnit.cpp
+++ b/llvm/lib/MCA/HardwareUnits/LSUnit.cpp
@@ -205,7 +205,7 @@ void LSUnitBase::onInstructionExecuted(const InstRef &IR) {
unsigned GroupID = IR.getInstruction()->getLSUTokenID();
auto It = Groups.find(GroupID);
assert(It != Groups.end() && "Instruction not dispatched to the LS unit");
- It->second->onInstructionExecuted();
+ It->second->onInstructionExecuted(IR);
if (It->second->isExecuted())
Groups.erase(It);
}