From a39dda53f59e50a1edf6bca10cd05202b032bdba Mon Sep 17 00:00:00 2001 From: CHUNSEOK LEE Date: Wed, 20 Sep 2017 20:26:44 +0900 Subject: Disable-VSD-Stub-Kind-Prediction, secure-delegate-bug Change-Id: I2d37cbe3145bc2ba2ae9d5acce531408ff3737cf Signed-off-by: CHUNSEOK LEE --- ...rt-to-2.0.0-Fix-ARM32-secure-delegate-bug.patch | 60 ++++++++++++ ...-Stub-Kind-Prediction-on-H-W-Exception-14.patch | 106 +++++++++++++++++++++ packaging/coreclr.spec | 6 +- 3 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 packaging/0031-Port-to-2.0.0-Fix-ARM32-secure-delegate-bug.patch create mode 100644 packaging/0032-Disable-VSD-Stub-Kind-Prediction-on-H-W-Exception-14.patch diff --git a/packaging/0031-Port-to-2.0.0-Fix-ARM32-secure-delegate-bug.patch b/packaging/0031-Port-to-2.0.0-Fix-ARM32-secure-delegate-bug.patch new file mode 100644 index 0000000000..71c07441d5 --- /dev/null +++ b/packaging/0031-Port-to-2.0.0-Fix-ARM32-secure-delegate-bug.patch @@ -0,0 +1,60 @@ +From d1a968702e2fec725255ec77de254293104b191f Mon Sep 17 00:00:00 2001 +From: Jan Vorlicek +Date: Wed, 13 Sep 2017 08:16:39 -0700 +Subject: [PATCH] Port to 2.0.0 - Fix ARM32 secure delegate bug + +This change fixes a bug that causes crashes when secure delegate is +invoked on ARM32 with legacy codegen. Register R4 was loaded with +indirection slot address and immediatelly marked as trashed, so the JIT +compiler reused it before the call that was supposed to have that value +in R4. +The fix was to move the reg trashing after the call. +There was also an incorrect marking of that address as EA_PTRSIZE +while it should be EA_BYREF, so I've fixed that too. +--- + src/jit/codegenlegacy.cpp | 17 ++++++++++++++++- + 1 file changed, 16 insertions(+), 1 deletion(-) + +diff --git a/src/jit/codegenlegacy.cpp b/src/jit/codegenlegacy.cpp +index d653511..b8a239a 100644 +--- a/src/jit/codegenlegacy.cpp ++++ b/src/jit/codegenlegacy.cpp +@@ -18632,12 +18632,20 @@ regMaskTP CodeGen::genCodeForCall(GenTreeCall* call, bool valUsed) + firstTgtOffs = pInfo->offsetOfDelegateFirstTarget; + + #ifdef _TARGET_ARM_ ++ // Ensure that we don't trash any of these registers if we have to load ++ // the helper call target into a register to invoke it. ++ regMaskTP regsUsed = 0; ++ + if ((call->gtCallMoreFlags & GTF_CALL_M_SECURE_DELEGATE_INV)) + { +- getEmitter()->emitIns_R_R_I(INS_add, EA_PTRSIZE, REG_VIRTUAL_STUB_PARAM, regThis, ++ getEmitter()->emitIns_R_R_I(INS_add, EA_BYREF, REG_VIRTUAL_STUB_PARAM, regThis, + pInfo->offsetOfSecureDelegateIndirectCell); + regTracker.rsTrackRegTrash(REG_VIRTUAL_STUB_PARAM); ++ ++ // Ensure that the virtual stub param info register doesn't get reused before the call is taken ++ regSet.rsLockReg(RBM_VIRTUAL_STUB_PARAM, ®sUsed); + } ++ + #endif // _TARGET_ARM_ + + // Grab an available register to use for the CALL indirection +@@ -18661,6 +18669,13 @@ regMaskTP CodeGen::genCodeForCall(GenTreeCall* call, bool valUsed) + INDEBUG_LDISASM_COMMA(sigInfo) NULL, // addr + args, retSize, gcInfo.gcVarPtrSetCur, gcInfo.gcRegGCrefSetCur, + gcInfo.gcRegByrefSetCur, ilOffset, indCallReg); ++ ++#ifdef _TARGET_ARM_ ++ if ((call->gtCallMoreFlags & GTF_CALL_M_SECURE_DELEGATE_INV)) ++ { ++ regSet.rsUnlockReg(RBM_VIRTUAL_STUB_PARAM, regsUsed); ++ } ++#endif // _TARGET_ARM_ + } + else + +-- +2.7.4 + diff --git a/packaging/0032-Disable-VSD-Stub-Kind-Prediction-on-H-W-Exception-14.patch b/packaging/0032-Disable-VSD-Stub-Kind-Prediction-on-H-W-Exception-14.patch new file mode 100644 index 0000000000..7dbc6eb07c --- /dev/null +++ b/packaging/0032-Disable-VSD-Stub-Kind-Prediction-on-H-W-Exception-14.patch @@ -0,0 +1,106 @@ +From d768ef837a0a4f13cec786f0d8aa7278abf10bdb Mon Sep 17 00:00:00 2001 +From: Jonghyun Park +Date: Tue, 19 Sep 2017 17:17:10 +0900 +Subject: [PATCH] Disable VSD Stub Kind Prediction on H/W Exception (#14051) + +* Disable VSD Stub Kind Prediction on H/W Exception + +* Add a comment on a false argument + +* Use BOOL (instead of bool) for consistency + +* Replace remaining bool/true/false with BOOL/TRUE/FALSE +--- + src/vm/exceptionhandling.cpp | 2 +- + src/vm/virtualcallstub.cpp | 8 ++++---- + src/vm/virtualcallstub.h | 7 ++++--- + 3 files changed, 9 insertions(+), 8 deletions(-) + +diff --git a/src/vm/exceptionhandling.cpp b/src/vm/exceptionhandling.cpp +index abea194..2802f73 100644 +--- a/src/vm/exceptionhandling.cpp ++++ b/src/vm/exceptionhandling.cpp +@@ -5146,7 +5146,7 @@ static BOOL IsIPinVirtualStub(PCODE f_IP) + } + + VirtualCallStubManager::StubKind sk; +- VirtualCallStubManager::FindStubManager(f_IP, &sk); ++ VirtualCallStubManager::FindStubManager(f_IP, &sk, FALSE /* usePredictStubKind */); + + if (sk == VirtualCallStubManager::SK_DISPATCH) + { +diff --git a/src/vm/virtualcallstub.cpp b/src/vm/virtualcallstub.cpp +index e753860..e659e35 100644 +--- a/src/vm/virtualcallstub.cpp ++++ b/src/vm/virtualcallstub.cpp +@@ -970,7 +970,7 @@ void VirtualCallStubManager::Reclaim() + + //---------------------------------------------------------------------------- + /* static */ +-VirtualCallStubManager *VirtualCallStubManager::FindStubManager(PCODE stubAddress, StubKind* wbStubKind) ++VirtualCallStubManager *VirtualCallStubManager::FindStubManager(PCODE stubAddress, StubKind* wbStubKind, BOOL usePredictStubKind) + { + CONTRACTL { + NOTHROW; +@@ -995,7 +995,7 @@ VirtualCallStubManager *VirtualCallStubManager::FindStubManager(PCODE stubAddres + // VirtualCallStubManager::isDispatchingStub + // + CONTRACT_VIOLATION(SOToleranceViolation); +- kind = pCur->getStubKind(stubAddress); ++ kind = pCur->getStubKind(stubAddress, usePredictStubKind); + if (kind != SK_UNKNOWN) + { + if (wbStubKind) +@@ -1007,7 +1007,7 @@ VirtualCallStubManager *VirtualCallStubManager::FindStubManager(PCODE stubAddres + // See if we are managed by the shared domain + // + pCur = SharedDomain::GetDomain()->GetLoaderAllocator()->GetVirtualCallStubManager(); +- kind = pCur->getStubKind(stubAddress); ++ kind = pCur->getStubKind(stubAddress, usePredictStubKind); + if (kind != SK_UNKNOWN) + { + if (wbStubKind) +@@ -1022,7 +1022,7 @@ VirtualCallStubManager *VirtualCallStubManager::FindStubManager(PCODE stubAddres + { + _ASSERTE(pCur != NULL); + +- kind = pCur->getStubKind(stubAddress); ++ kind = pCur->getStubKind(stubAddress, usePredictStubKind); + if (kind != SK_UNKNOWN) + { + if (wbStubKind) +diff --git a/src/vm/virtualcallstub.h b/src/vm/virtualcallstub.h +index 7b6fedf..b8984ea 100644 +--- a/src/vm/virtualcallstub.h ++++ b/src/vm/virtualcallstub.h +@@ -317,7 +317,7 @@ public: + /* know thine own stubs. It is possible that when multiple + virtualcallstub managers are built that these may need to become + non-static, and the callers modified accordingly */ +- StubKind getStubKind(PCODE stubStartAddress) ++ StubKind getStubKind(PCODE stubStartAddress, BOOL usePredictStubKind = TRUE) + { + WRAPPER_NO_CONTRACT; + SUPPORTS_DAC; +@@ -329,7 +329,7 @@ public: + + // Rather than calling IsInRange(stubStartAddress) for each possible stub kind + // we can peek at the assembly code and predict which kind of a stub we have +- StubKind predictedKind = predictStubKind(stubStartAddress); ++ StubKind predictedKind = (usePredictStubKind) ? predictStubKind(stubStartAddress) : SK_UNKNOWN; + + if (predictedKind == SK_DISPATCH) + { +@@ -732,7 +732,8 @@ private: + public: + // Given a stub address, find the VCSManager that owns it. + static VirtualCallStubManager *FindStubManager(PCODE addr, +- StubKind* wbStubKind = NULL); ++ StubKind* wbStubKind = NULL, ++ BOOL usePredictStubKind = TRUE); + + #ifndef DACCESS_COMPILE + // insert a linked list of indirection cells at the beginning of m_RecycledIndCellList +-- +2.7.4 + diff --git a/packaging/coreclr.spec b/packaging/coreclr.spec index 5f445bfd60..7aedf9c81a 100644 --- a/packaging/coreclr.spec +++ b/packaging/coreclr.spec @@ -23,7 +23,7 @@ Source1000: downloaded_files.tar.gz Source1001: %{name}.manifest Source1002: libicu.tar.gz Source1003: dep_libs.tar.gz -# Gbp-Ignore-Patches: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +# Gbp-Ignore-Patches: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Patch0: 0001-Add-project.assets.json-files.patch Patch1: 0001-ARM-Linux-Support-unaligned-struct-read-write-11290.patch Patch2: 0002-x86-Linux-Thread-safe-UMThunkMarshInfo-RunTimeInit-1.patch @@ -56,6 +56,8 @@ Patch28: 0027-Include-PAL-headers-instead-of-embedding-it-11705.patch Patch29: 0028-added-DWARF-exprloc-for-static-value-class-fields-11.patch Patch30: 0029-Fix-calculation-of-debuginfo-s-size.-13899.patch Patch31: 0030-Force-O3-build-with-clang3.8.patch +Patch32: 0031-Port-to-2.0.0-Fix-ARM32-secure-delegate-bug.patch +Patch33: 0032-Disable-VSD-Stub-Kind-Prediction-on-H-W-Exception-14.patch ExcludeArch: aarch64 @@ -187,6 +189,8 @@ cp %{SOURCE1001} . %patch29 -p1 %patch30 -p1 %patch31 -p1 +%patch32 -p1 +%patch33 -p1 %if 0%{skipmscorlib} %else -- cgit v1.2.3