From 34d086e3e67827f0496b838d5d05a9964aa1346c Mon Sep 17 00:00:00 2001 From: Sakethan R Kotta Date: Thu, 10 May 2018 04:27:37 -0500 Subject: untrusted SBE reserved memory region to Rsvd Mem Trace Buf Section Opens an untrusted SBE reserved memory region with read-only permissions to the Rsvd Mem Trace Buf Section.so that tools/debug can come in and read those traces in secure mode. Establishes the window across -all- chips. Change-Id: Ied9852455d7c412915871328976a9204e1f5247f RTC:191303 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/58637 Reviewed-by: Prachi Gupta Reviewed-by: Daniel M. Crowell Tested-by: Daniel M. Crowell --- src/include/usr/runtime/runtime.H | 11 ++++ src/usr/runtime/populate_hbruntime.C | 107 +++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/src/include/usr/runtime/runtime.H b/src/include/usr/runtime/runtime.H index e8605676b..5ae784b74 100644 --- a/src/include/usr/runtime/runtime.H +++ b/src/include/usr/runtime/runtime.H @@ -357,6 +357,17 @@ void findHdatLocation(uint64_t payloadBase_va, uint64_t& o_hdat_offset, size_t& o_hdat_size); +/** + * @brief Finds the Rsvd Mem Trace Buffer section and returns the address and + * size of the section + * + * @param[out] o_RsvdMemAddress - tarting address of the Rsvd Mem Trace Buffer section + * @param[out] o_size - Size of the Rsvd Mem Trace Buffer section + * @return errlHndl_t Returns nullptr on success; otherwise errlog + */ +errlHndl_t getRsvdMemTraceBuf(uint64_t& o_RsvdMemAddress, uint64_t& o_size); + } #endif + diff --git a/src/usr/runtime/populate_hbruntime.C b/src/usr/runtime/populate_hbruntime.C index 008db2f7b..f36851b7d 100644 --- a/src/usr/runtime/populate_hbruntime.C +++ b/src/usr/runtime/populate_hbruntime.C @@ -3463,6 +3463,40 @@ errlHndl_t openUntrustedSpCommArea(const uint64_t i_commBase) } } + // Open Unsecure Memory Region for HBRT Rsvd Mem Trace Section + uint64_t l_RsvdMemRtTraceAddr = 0; + uint64_t l_RsvdMemRtTraceSize = 0; + + //get the HBRT Rsvd Mem Trace Section addr and size + l_err = getRsvdMemTraceBuf(l_RsvdMemRtTraceAddr,l_RsvdMemRtTraceSize); + + if(l_err) + { + TRACFCOMP( g_trac_runtime, ERR_MRK "openUntrustedSpCommArea(): getRsvdMemTraceBuf() failed proc = 0x%X", + l_id); + + break; + } + + if((l_RsvdMemRtTraceAddr != 0) && (l_RsvdMemRtTraceSize != 0)) + { + // Open Unsecure Memory Region for HBRT Rsvd Mem Trace Section + l_err = SBEIO::openUnsecureMemRegion(l_RsvdMemRtTraceAddr, + l_RsvdMemRtTraceSize, + false, //Read-Only + l_procChip); + if(l_err) + { + TRACFCOMP( g_trac_runtime, ERR_MRK "openUntrustedSpCommArea(): openUnsecureMemRegion() failed proc = 0x%X addr = 0x%016llx size = 0x%X", + l_id, + l_RsvdMemRtTraceAddr, + l_RsvdMemRtTraceSize); + + break; + } + + } + } if(l_err) { @@ -3483,5 +3517,78 @@ void setPayloadBaseAddress(uint64_t i_payloadAddress) sys->setAttr(i_payloadAddress); } +errlHndl_t getRsvdMemTraceBuf(uint64_t& o_RsvdMemAddress, uint64_t& o_size) +{ + errlHndl_t l_elog = nullptr; + uint64_t l_rsvMemDataAddr = 0; + uint64_t l_rsvMemDataSize = 0; + hdatMsVpdRhbAddrRange_t* l_rngPtr = nullptr; + Util::hbrtTableOfContents_t * l_hbTOC = nullptr; + + do{ + // We have only one HBRT_MEM_LABEL_TRACEBUF section across the system. + // Loop through all RESERVED_MEM sections in the system (of all nodes), + // and find out the section with label HBRT_MEM_LABEL_TRACEBUF + uint64_t l_StartInstance = 0; //start from 0 + uint64_t l_EndInstance = 0; + + l_elog = RUNTIME::get_instance_count(RUNTIME::RESERVED_MEM,l_EndInstance); + if(l_elog != nullptr) + { + TRACFCOMP( g_trac_runtime, + "getRsvdMemTraceBuf() fail get_instance_count"); + break; + } + + + for (uint64_t l_instance = l_StartInstance ; l_instance < l_EndInstance; l_instance++) + { + + // Get the address of the section + l_elog = RUNTIME::get_host_data_section( RUNTIME::RESERVED_MEM, + l_instance, + l_rsvMemDataAddr, + l_rsvMemDataSize ); + if(l_elog != nullptr) + { + TRACFCOMP( g_trac_runtime, + "getRsvdMemTraceBuf fail get_host_data_section instance = %d", + l_instance); + break; + } + + l_rngPtr = reinterpret_cast(l_rsvMemDataAddr); + + assert(l_rngPtr != nullptr, "get_host_data_section returned nullptr"); + + const char* l_region = reinterpret_cast(l_rngPtr->hdatRhbLabelString); + + if (strcmp(l_region,"HBRT_RSVD_MEM__DATA")== 0) + { + TRACFCOMP( g_trac_runtime, + "getRsvdMemTraceBuf() Found HBRT_RSVD_MEM__DATA section"); + + l_hbTOC = reinterpret_cast( + l_rngPtr->hdatRhbAddrRngStrAddr); + o_RsvdMemAddress = Util::hb_find_rsvd_mem_label(Util::HBRT_MEM_LABEL_TRACEBUF, + l_hbTOC, + o_size); + if((o_RsvdMemAddress != 0) && (o_size != 0)) + { + TRACFCOMP( g_trac_runtime, + "getRsvdMemTraceBuf() Found HBRT_MEM_LABEL_TRACEBUF section 0x%016llx size = 0x%X", + o_RsvdMemAddress,o_size); + break; + } + } + + } + + }while(0); + + return l_elog; + +} + } //namespace RUNTIME -- cgit v1.2.1