diff options
author | Stephen Cprek <smcprek@us.ibm.com> | 2017-10-03 09:36:58 -0500 |
---|---|---|
committer | William G. Hoffa <wghoffa@us.ibm.com> | 2017-10-24 13:58:43 -0400 |
commit | 0ff075bac5d78384a625de70b34b7ef363a25fd6 (patch) | |
tree | 30e1a8e011be3b2bfde6d4e616f8745dde212d28 /src/usr/runtime | |
parent | da12bd653f7eabbc2d97938a3ac25666187e6abb (diff) | |
download | talos-hostboot-0ff075bac5d78384a625de70b34b7ef363a25fd6.tar.gz talos-hostboot-0ff075bac5d78384a625de70b34b7ef363a25fd6.zip |
Create Pre Verified Lid Manager and refactor exisiting implementation
Change-Id: I5417b8e381bf15a1b696cf006940eedd7a1e235c
RTC:125304
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/47110
Reviewed-by: Michael Baiocchi <mbaiocch@us.ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Nicholas E. Bofferding <bofferdn@us.ibm.com>
Reviewed-by: William G. Hoffa <wghoffa@us.ibm.com>
Diffstat (limited to 'src/usr/runtime')
-rw-r--r-- | src/usr/runtime/makefile | 1 | ||||
-rw-r--r-- | src/usr/runtime/populate_hbruntime.C | 181 | ||||
-rw-r--r-- | src/usr/runtime/preverifiedlidmgr.C | 332 | ||||
-rw-r--r-- | src/usr/runtime/test/makefile | 1 | ||||
-rw-r--r-- | src/usr/runtime/test/testpreverifiedlidmgr.H | 123 |
5 files changed, 491 insertions, 147 deletions
diff --git a/src/usr/runtime/makefile b/src/usr/runtime/makefile index bdfa301c3..cc53bb3ae 100644 --- a/src/usr/runtime/makefile +++ b/src/usr/runtime/makefile @@ -40,6 +40,7 @@ OBJS += fakepayload.o OBJS += errlud_hdat.o OBJS += customize_attrs_for_payload.o OBJS += hdatcommonutil.o +OBJS += preverifiedlidmgr.o SUBDIRS += test.d diff --git a/src/usr/runtime/populate_hbruntime.C b/src/usr/runtime/populate_hbruntime.C index 4a838ca15..028f92802 100644 --- a/src/usr/runtime/populate_hbruntime.C +++ b/src/usr/runtime/populate_hbruntime.C @@ -70,11 +70,26 @@ #include <util/utilrsvdmem.H> #include <util/utillidpnor.H> #include <stdio.h> +#include <runtime/populate_hbruntime.H> +#include <runtime/preverifiedlidmgr.H> namespace RUNTIME { +// -- Verified Images +// -- OCC +// -- WOFDATA +// -- HCODE +// -- Non-verified Images +/// -- RINGOVD +const std::vector<PNOR::SectionId> preVerifiedPnorSections { + PNOR::OCC, + PNOR::WOFDATA, + PNOR::HCODE, + PNOR::RINGOVD, +}; + mutex_t g_rhbMutex = MUTEX_INITIALIZER; // used for populating the TPM required bit in HDAT @@ -138,16 +153,8 @@ errlHndl_t getNextRhbAddrRange(hdatMsVpdRhbAddrRange_t* & o_rngPtr) return(l_elog); } - -/** - * @brief Map physical address to virtual - * @param[in] i_addr Physical address - * @param[in] i_size Size of block to be mapped - * @param[out] o_addr Virtual address - * @return Error handle if error - */ errlHndl_t mapPhysAddr(uint64_t i_addr, - uint64_t i_size, + size_t i_size, uint64_t& o_addr) { errlHndl_t l_elog = nullptr; @@ -184,12 +191,6 @@ errlHndl_t mapPhysAddr(uint64_t i_addr, return l_elog; } - -/** - * @brief Unmap virtual address block - * @param[in] i_addr Virtual address - * @return Error handle if error - */ errlHndl_t unmapVirtAddr(uint64_t i_addr) { errlHndl_t l_elog = nullptr; @@ -236,25 +237,12 @@ void traceHbRsvMemRange(hdatMsVpdRhbAddrRange_t* & i_rngPtr ) i_rngPtr->hdatRhbPermission); } -/** - * @brief Get the next Reserved HB memory range and set all member variables - * of struct. Additionally trace out relevant parts of the struct - * @param[in] i_type, Range type - * @param[in] i_rangeId, Range ID - * @param[in] i_startAddr, Range Starting Address - * @param[in] i_size, Size of address space to reserve - * @param[in] i_label, Label String Ptr - * - * @return errlHndl_t, nullptr on success; otherwise errlog - */ errlHndl_t setNextHbRsvMemEntry(const HDAT::hdatMsVpdRhbAddrRangeType i_type, const uint16_t i_rangeId, const uint64_t i_startAddr, const uint64_t i_size, const char* i_label, - const HDAT::hdatRhbPermType i_permission = - HDAT::RHB_READ_WRITE - ) + const HDAT::hdatRhbPermType i_permission) { errlHndl_t l_elog = nullptr; @@ -579,17 +567,12 @@ errlHndl_t fill_RsvMem_hbData(uint64_t & io_start_address, return l_elog; } -errlHndl_t hbResvLoadSecureSection (const PNOR::SectionId i_sec, - const uint64_t i_rangeId, - uint64_t& io_prevAddr, - uint64_t& io_prevSize) +errlHndl_t hbResvLoadSecureSection (const PNOR::SectionId i_sec) { TRACFCOMP( g_trac_runtime,ENTER_MRK"hbResvloadSecureSection() sec %s", PNOR::SectionIdToString(i_sec)); errlHndl_t l_elog = nullptr; - PNOR::SectionInfo_t l_info; - uint64_t l_tmpVaddr = 0; do { @@ -601,7 +584,7 @@ errlHndl_t hbResvLoadSecureSection (const PNOR::SectionId i_sec, break; } - + PNOR::SectionInfo_t l_info; l_elog = PNOR::getSectionInfo( i_sec, l_info ); if(l_elog) { @@ -641,95 +624,13 @@ errlHndl_t hbResvLoadSecureSection (const PNOR::SectionId i_sec, } #endif - // Align size for OPAL - size_t l_imgSizeAligned = ALIGN_X(l_imgSize, HBRT_RSVD_MEM_OPAL_ALIGN); - - // For PHYP we build up starting at the end of the previously allocated - // areas, for OPAL we build downwards from the top of memory - uint64_t l_imgAdd = 0x0; - if(TARGETING::is_phyp_load()) - { - l_imgAdd = io_prevAddr + io_prevSize; - } - else if(TARGETING::is_sapphire_load()) - { - l_imgAdd = io_prevAddr - l_imgSizeAligned; - } - - auto l_lids = Util::getPnorSecLidIds(i_sec); - TRACFCOMP(g_trac_runtime, "hbResvloadSecureSection() getPnorSecLidIds lid = 0x%X, containerLid = 0x%X", - l_lids.lid, l_lids.containerLid); - assert(l_lids.lid != Util::INVALID_LIDID,"Pnor Section = %s not associated with any Lids", PNOR::SectionIdToString(i_sec)); - - // @TODO RTC:178163 enabled when HDAT support is complete for extra HB resv mem entries - // PHYP will use these 2 entries in the future - /* - // Verified Lid - Header Only - char l_containerLidStr [Util::lidIdStrLength]; - snprintf (l_containerLidStr, Util::lidIdStrLength, "%X", - l_lids.containerLid); - l_elog = setNextHbRsvMemEntry(HDAT::RHB_TYPE_VERIFIED_LIDS, - i_rangeId, - l_imgAdd, - l_imgSizeAligned, - l_containerLidStr); + // Load Pnor section into HB reserved memory + l_elog = PreVerifiedLidMgr::loadFromPnor(i_sec, l_pnorVaddr, l_imgSize); if(l_elog) { - TRACFCOMP( g_trac_runtime, ERR_MRK"hbResvloadSecureSection() setNextHbRsvMemEntry Lid header failed"); break; } - // Verified Lid - Content Only - char l_lidStr[Util::lidIdStrLength]; - snprintf (l_lidStr, Util::lidIdStrLength, "%X",l_lids.lid); - l_elog = setNextHbRsvMemEntry(HDAT::RHB_TYPE_VERIFIED_LIDS, - i_rangeId, - l_imgAdd+PAGE_SIZE, - l_imgSizeAligned, - l_lidStr); - if(l_elog) - { - TRACFCOMP( g_trac_runtime, ERR_MRK"hbResvloadSecureSection() setNextHbRsvMemEntry Lid content failed"); - break; - } - */ - // Verified PNOR - Header + Content - l_elog = setNextHbRsvMemEntry(HDAT::RHB_TYPE_VERIFIED_PNOR, - i_rangeId, - l_imgAdd, - l_imgSizeAligned, - PNOR::SectionIdToString(i_sec), - HDAT::RHB_READ_ONLY); - if(l_elog) - { - TRACFCOMP( g_trac_runtime, ERR_MRK"hbResvloadSecureSection() setNextHbRsvMemEntry PNOR content failed"); - break; - } - - io_prevAddr = l_imgAdd; - // Use aligned size for OPAL alignment even if that means there is some - // wasted space. - io_prevSize = l_imgSizeAligned; - - // Load the Verified image into HB resv memory - l_elog = mapPhysAddr(l_imgAdd, l_imgSize, l_tmpVaddr); - if(l_elog) - { - TRACFCOMP( g_trac_runtime, ERR_MRK"hbResvloadSecureSection() mapPhysAddr failed"); - break; - } - - // Include Header page from pnor image. - memcpy(reinterpret_cast<void*>(l_tmpVaddr), - reinterpret_cast<void*>(l_pnorVaddr), - l_imgSize); - - l_elog = unmapVirtAddr(l_tmpVaddr); - if(l_elog) - { - TRACFCOMP( g_trac_runtime, ERR_MRK"hbResvloadSecureSection() unmapVirtAddr failed"); - break; - } } while(0); return l_elog; @@ -1171,38 +1072,24 @@ errlHndl_t populate_HbRsvMem(uint64_t i_nodeId) } } - /////////////////////////////////////////////////// - // -- Verified Images - // -- OCC - // -- WOFDATA - // -- HCODE - // -- Non-verified Images - /// -- RINGOVD - l_elog = hbResvLoadSecureSection(PNOR::OCC, i_nodeId, - l_prevDataAddr, l_prevDataSize); - if (l_elog) - { - break; - } - l_elog = hbResvLoadSecureSection(PNOR::WOFDATA, i_nodeId, - l_prevDataAddr, l_prevDataSize); - if (l_elog) - { - break; - } - l_elog = hbResvLoadSecureSection(PNOR::HCODE, i_nodeId, l_prevDataAddr, - l_prevDataSize); - if (l_elog) + // Initialize Pre-Verified Lid manager + PreVerifiedLidMgr::initLock(l_prevDataAddr, l_prevDataSize, i_nodeId); + + // Handle all Pre verified PNOR sections + for (const auto secId : preVerifiedPnorSections) { - break; + l_elog = hbResvLoadSecureSection(secId); + if (l_elog) + { + break; + } } - // Note: RINGOVD is not a securely signed section. - l_elog = hbResvLoadSecureSection(PNOR::RINGOVD, i_nodeId, - l_prevDataAddr, l_prevDataSize); + PreVerifiedLidMgr::unlock(); if (l_elog) { break; } + } while(0); TRACFCOMP( g_trac_runtime, EXIT_MRK"populate_HbRsvMem> l_elog=%.8X", ERRL_GETRC_SAFE(l_elog) ); @@ -1664,7 +1551,7 @@ errlHndl_t populate_TpmInfoByNode() SECUREBOOT::handleSecurebootFailure(err); - assert(true,"Bug! handleSecurebootFailure shouldn't return!"); + assert(false,"Bug! handleSecurebootFailure shouldn't return!"); } else { diff --git a/src/usr/runtime/preverifiedlidmgr.C b/src/usr/runtime/preverifiedlidmgr.C new file mode 100644 index 000000000..0f3398721 --- /dev/null +++ b/src/usr/runtime/preverifiedlidmgr.C @@ -0,0 +1,332 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/runtime/preverifiedlidmgr.C $ */ +/* */ +/* OpenPOWER HostBoot Project */ +/* */ +/* Contributors Listed Below - COPYRIGHT 2017 */ +/* [+] International Business Machines Corp. */ +/* */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); */ +/* you may not use this file except in compliance with the License. */ +/* You may obtain a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ +/* implied. See the License for the specific language governing */ +/* permissions and limitations under the License. */ +/* */ +/* IBM_PROLOG_END_TAG */ +#include <runtime/preverifiedlidmgr.H> +#include <errl/errlentry.H> +#include <errl/errlmanager.H> +#include <utility> +#include <runtime/populate_hbruntime.H> +#include <util/align.H> +#include <util/utillidmgr.H> +#include <util/utillidpnor.H> +#include <initservice/initserviceif.H> +#include <util/singleton.H> +#include <stdio.h> +#include <arch/ppc.H> + +extern trace_desc_t *g_trac_runtime; + +// Set static variables +TARGETING::PAYLOAD_KIND PreVerifiedLidMgr::cv_payloadKind = TARGETING::PAYLOAD_KIND_NONE; +std::map<uint64_t,bool> PreVerifiedLidMgr::cv_lidsLoaded {}; +bool PreVerifiedLidMgr::cv_phypLidSeen = false; +PreVerifiedLidMgr::ResvMemInfo* PreVerifiedLidMgr::cv_pResvMemInfo = nullptr; +PreVerifiedLidMgr::ResvMemInfo PreVerifiedLidMgr::cv_resvMemInfo {}; +PreVerifiedLidMgr::ResvMemInfo PreVerifiedLidMgr::cv_phypResvMemInfo {}; +mutex_t PreVerifiedLidMgr::cv_mutex = MUTEX_INITIALIZER; +mutex_t PreVerifiedLidMgr::cv_loadImageMutex = MUTEX_INITIALIZER; + +/******************** + Public Methods + ********************/ + +void PreVerifiedLidMgr::initLock(const uint64_t i_prevAddr, + const uint64_t i_prevSize, + const size_t i_rangeId) +{ + Singleton<PreVerifiedLidMgr>::instance()._initLock(i_prevAddr, + i_prevSize, + i_rangeId); +} + +void PreVerifiedLidMgr::unlock() +{ + Singleton<PreVerifiedLidMgr>::instance()._unlock(); +} + + +errlHndl_t PreVerifiedLidMgr::loadFromPnor(const PNOR::SectionId i_sec, + const uint64_t i_addr, + const size_t i_size) +{ + return Singleton<PreVerifiedLidMgr>::instance()._loadFromPnor(i_sec, + i_addr, + i_size); +} + +/******************** + Private Implementations of Static Public Methods + ********************/ + +void PreVerifiedLidMgr::_initLock(const uint64_t i_prevAddr, + const uint64_t i_prevSize, + const size_t i_rangeId) +{ + mutex_lock(&cv_mutex); + + cv_payloadKind = TARGETING::PAYLOAD_KIND_NONE; + cv_phypLidSeen = false; + + // Default Reserved Memory Information + cv_resvMemInfo.rangeId = i_rangeId; + cv_resvMemInfo.curAddr = i_prevAddr; + cv_resvMemInfo.prevSize = i_prevSize; + + // PHYP Reserved Memory Information + cv_phypResvMemInfo.rangeId = i_rangeId; + // PHYP lids loaded at HRMOR - 4K (Header) + // Get Target Service, and the system target. + TARGETING::Target* l_sys = nullptr; + TARGETING::targetService().getTopLevelTarget(l_sys); + assert(l_sys!=nullptr,"Top Level Target is nullptr"); + cv_phypResvMemInfo.curAddr = (l_sys->getAttr<TARGETING::ATTR_PAYLOAD_BASE>() + * MEGABYTE) - PAGE_SIZE; + + // PHYP should be placed starting exactly at HRMOR - 4K, so make prevSize 0 + cv_phypResvMemInfo.prevSize = 0; + + // Refer to default reserved memory + cv_pResvMemInfo = &cv_resvMemInfo; + + // Set variables based on payload Kind + // Note: For PHYP we build up starting at the end of the + // previously allocated HOMER/OCC areas, for OPAL we build + // downwards from the top of memory where the HOMER/OCC + // areas were placed + + // Set default next physical address to simply increment in order + getNextAddress = getNextPhypAddress; + + if(TARGETING::is_phyp_load()) + { + cv_payloadKind = TARGETING::PAYLOAD_KIND_PHYP; + } + else if(TARGETING::is_sapphire_load()) + { + cv_payloadKind = TARGETING::PAYLOAD_KIND_SAPPHIRE; + getNextAddress = getNextOpalAddress; + } +} + +void PreVerifiedLidMgr::_unlock() +{ + TRACFCOMP(g_trac_runtime, "PreVerifiedLidMgr::_unlock"); + mutex_unlock(&cv_mutex); +} + +errlHndl_t PreVerifiedLidMgr::_loadFromPnor(const PNOR::SectionId i_sec, + const uint64_t i_addr, + const size_t i_size) +{ + mutex_lock(&cv_loadImageMutex); + + TRACFCOMP(g_trac_runtime, ENTER_MRK"PreVerifiedLidMgr::_loadFromPnor - sec %s", + PNOR::SectionIdToString(i_sec)); + + errlHndl_t l_errl = nullptr; + + do { + + // Translate Pnor Section Id to Lid + auto l_lids = Util::getPnorSecLidIds(i_sec); + TRACFCOMP( g_trac_runtime, "PreVerifiedLidMgr::loadFromPnor - getPnorSecLidIds lid = 0x%X, containerLid = 0x%X", + l_lids.lid, l_lids.containerLid); + assert(l_lids.lid != Util::INVALID_LIDID,"Pnor Section = %s not associated with any Lids", PNOR::SectionIdToString(i_sec)); + + // Only load if not previously done. + if( isLidLoaded(l_lids.containerLid) && isLidLoaded(l_lids.lid) ) + { + TRACFCOMP( g_trac_runtime, "PreVerifiedLidMgr::loadFromPnor - sec %s already loaded", + PNOR::SectionIdToString(i_sec)); + break; + } + + // Get next available HB resverved memory address + cv_pResvMemInfo->curAddr = getNextAddress(i_size); + + // @TODO RTC:178163 remove need for l_loadImage + bool l_loadImage = false; + if(cv_payloadKind == TARGETING::PAYLOAD_KIND_PHYP) + { + // @TODO RTC:178163 enable when we can Load ALL pre-verfied lids + // There are checks in phyp for ANY hdat entry marked "RHB_TYPE_VERIFIED_LIDS" + // If there are any missing phyp will fail to boot. +/* + l_loadImage = true; + // Verified Lid - Header Only + if ( (l_lids.containerLid != INVALID_LIDID) && + !isLidLoaded(l_lids.containerLid)) + { + char l_containerLidStr [Util::lidIdStrLength] {}; + snprintf (l_containerLidStr, Util::lidIdStrLength, "%08X", + l_lids.containerLid); + l_errl = RUNTIME::setNextHbRsvMemEntry(HDAT::RHB_TYPE_VERIFIED_LIDS, + cv_pResvMemInfo->rangeId, + cv_pResvMemInfo->curAddr, + getAlignedSize(PAGE_SIZE), + l_containerLidStr); + if(l_errl) + { + TRACFCOMP( g_trac_runtime, ERR_MRK"PreVerifiedLidMgr::loadFromPnor - setNextHbRsvMemEntry Lid header failed"); + break; + } + } + + // Verified Lid - Content Only + if ( (l_lids.lid != INVALID_LIDID) && + !isLidLoaded(l_lids.lid)) + { + char l_lidStr[Util::lidIdStrLength] {}; + snprintf (l_lidStr, Util::lidIdStrLength, "%08X",l_lids.lid); + l_errl = RUNTIME::setNextHbRsvMemEntry(HDAT::RHB_TYPE_VERIFIED_LIDS, + cv_pResvMemInfo->rangeId, + cv_pResvMemInfo->curAddr+PAGE_SIZE, + getAlignedSize(i_size), + l_lidStr); + if(l_errl) + { + TRACFCOMP( g_trac_runtime, ERR_MRK"PreVerifiedLidMgr::loadFromPnor - setNextHbRsvMemEntry Lid content failed"); + break; + } + } +*/ + } + else if(cv_payloadKind == TARGETING::PAYLOAD_KIND_SAPPHIRE) + { + l_loadImage = true; + // Verified PNOR - Header + Content + l_errl = RUNTIME::setNextHbRsvMemEntry(HDAT::RHB_TYPE_VERIFIED_PNOR, + cv_pResvMemInfo->rangeId, + cv_pResvMemInfo->curAddr, + getAlignedSize(i_size), + PNOR::SectionIdToString(i_sec), + HDAT::RHB_READ_ONLY); + if(l_errl) + { + TRACFCOMP( g_trac_runtime, ERR_MRK"PreVerifiedLidMgr::loadFromPnor - setNextHbRsvMemEntry PNOR content failed"); + break; + } + } + + if (l_loadImage) + { + // Load image into HB reserved memory + l_errl = loadImage(i_addr, i_size); + if(l_errl) + { + TRACFCOMP( g_trac_runtime, ERR_MRK"PreVerifiedLidMgr::loadFromPnor - setNextHbRsvMemEntry PNOR content failed"); + break; + } + } + + // Indicate the full PNOR section has been loaded. + // Include both the header and content lids + cv_lidsLoaded.insert(std::make_pair(l_lids.containerLid, true)); + cv_lidsLoaded.insert(std::make_pair(l_lids.lid, true)); + + } while(0); + + TRACFCOMP( g_trac_runtime, EXIT_MRK"PreVerifiedLidMgr::_loadFromPnor"); + + mutex_unlock(&cv_loadImageMutex); + + return l_errl; +} + +/******************** + Private/Protected Methods + ********************/ + +PreVerifiedLidMgr& PreVerifiedLidMgr::getInstance() +{ + return Singleton<PreVerifiedLidMgr>::instance(); +} + +uint64_t PreVerifiedLidMgr::getAlignedSize(const size_t i_imgSize) +{ + return ALIGN_X(i_imgSize, HBRT_RSVD_MEM_OPAL_ALIGN); +} + +uint64_t PreVerifiedLidMgr::getNextPhypAddress(const size_t i_prevSize) +{ + return cv_pResvMemInfo->curAddr + cv_pResvMemInfo->prevSize; +} + +uint64_t PreVerifiedLidMgr::getNextOpalAddress(const size_t i_curSize) +{ + return cv_pResvMemInfo->curAddr - getAlignedSize(i_curSize); +} + +bool PreVerifiedLidMgr::isLidLoaded(uint32_t i_lidId) +{ + bool l_loaded = false; + + if (cv_lidsLoaded.count(i_lidId) > 0) + { + l_loaded = true; + } + + return l_loaded; +} + +errlHndl_t PreVerifiedLidMgr::loadImage(const uint64_t i_imgAddr, + const size_t i_imgSize) +{ + TRACFCOMP( g_trac_runtime, ENTER_MRK"PreVerifiedLidMgr::loadImage"); + + errlHndl_t l_errl = nullptr; + + do { + + uint64_t l_tmpVaddr = 0; + // Load the Verified image into HB resv memory + l_errl = RUNTIME::mapPhysAddr(cv_pResvMemInfo->curAddr, i_imgSize, l_tmpVaddr); + if(l_errl) + { + TRACFCOMP( g_trac_runtime, ERR_MRK"PreVerifiedLidMgr::loadImage - mapPhysAddr failed"); + break; + } + + // Include Header page from pnor image. + memcpy(reinterpret_cast<void*>(l_tmpVaddr), + reinterpret_cast<void*>(i_imgAddr), + i_imgSize); + + l_errl = RUNTIME::unmapVirtAddr(l_tmpVaddr); + if(l_errl) + { + TRACFCOMP( g_trac_runtime, ERR_MRK"PreVerifiedLidMgr::loadImage - unmapVirtAddr failed"); + break; + } + + // Update previous size using aligned size for OPAL alignment even if that + // means there is some wasted space. + cv_pResvMemInfo->prevSize = getAlignedSize(i_imgSize); + + } while(0); + + TRACFCOMP( g_trac_runtime, EXIT_MRK"PreVerifiedLidMgr::loadImage"); + + return l_errl; +}
\ No newline at end of file diff --git a/src/usr/runtime/test/makefile b/src/usr/runtime/test/makefile index e307302f2..92715cf83 100644 --- a/src/usr/runtime/test/makefile +++ b/src/usr/runtime/test/makefile @@ -25,6 +25,7 @@ ROOTPATH = ../../../.. MODULE = testruntime +TESTS += testpreverifiedlidmgr.H #@TODO RTC 132750 #TESTS += hdatservicetest.H #@TODO RTC:178802 diff --git a/src/usr/runtime/test/testpreverifiedlidmgr.H b/src/usr/runtime/test/testpreverifiedlidmgr.H new file mode 100644 index 000000000..4fca35b5f --- /dev/null +++ b/src/usr/runtime/test/testpreverifiedlidmgr.H @@ -0,0 +1,123 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/runtime/test/testpreverifiedlidmgr.H $ */ +/* */ +/* OpenPOWER HostBoot Project */ +/* */ +/* Contributors Listed Below - COPYRIGHT 2017 */ +/* [+] International Business Machines Corp. */ +/* */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); */ +/* you may not use this file except in compliance with the License. */ +/* You may obtain a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ +/* implied. See the License for the specific language governing */ +/* permissions and limitations under the License. */ +/* */ +/* IBM_PROLOG_END_TAG */ +#ifndef _TESTPREVERIFIEDLIDMGR_H +#define _TESTPREVERIFIEDLIDMGR_H + +#include <cxxtest/TestSuite.H> +#include <errl/errlmanager.H> +#include <runtime/preverifiedlidmgr.H> +#include <secureboot/service.H> +#include <usr/vmmconst.h> +#include <runtime/populate_hbruntime.H> +#include <pnor/pnorif.H> + +extern trace_desc_t* g_trac_runtime; + +class PreVerifiedLidMgrTest : public CxxTest::TestSuite +{ + public: + + void testPreVerifiedLidMgrInit() + { + // Initialize Pre verified lid manager with test address space and + // payload kind none + PreVerifiedLidMgr::initLock(PREVERLIDMGR_TEST_ADDR); + + // Get Instance of Pre-Verified lid manager + auto l_preVerLidMgr = PreVerifiedLidMgr::getInstance(); + + if (l_preVerLidMgr.cv_payloadKind != TARGETING::PAYLOAD_KIND_NONE) + { + TS_FAIL("testPreVerifiedLidMgrInit> payload kind incorrect"); + } + + if (l_preVerLidMgr.cv_resvMemInfo.curAddr != PREVERLIDMGR_TEST_ADDR) + { + TS_FAIL("testPreVerifiedLidMgrInit> payload kind incorrect"); + } + + PreVerifiedLidMgr::unlock(); + } + + void testLoadFromPnor() + { + TRACFCOMP( g_trac_runtime, ENTER_MRK"testLoadFromPnor start" ); + + errlHndl_t l_errl = nullptr; + + do { + + // Initialize Pre verified lid manager with test address space and + // payload kind none + PreVerifiedLidMgr::initLock(PREVERLIDMGR_TEST_ADDR); + + // Get Instance of Pre-Verified lid manager + auto l_preVerLidMgr = PreVerifiedLidMgr::getInstance(); + + // Clear lids loaded cache as other test cases fill it in. + l_preVerLidMgr.cv_lidsLoaded.clear(); + + // Handle all Pre verified PNOR sections + for (const auto secId : RUNTIME::preVerifiedPnorSections) + { + l_errl = RUNTIME::hbResvLoadSecureSection(secId); + if (l_errl) + { + TS_FAIL("testLoadFromPnor> Failed to Load Pnor Section %s", + PNOR::SectionIdToString(secId)); + errlCommit(l_errl, RUNTIME_COMP_ID); + break; + } + } + if (l_errl) + { + break; + } + + // Each section has 2 lids each (Header, Content) except the RINGOVD + // section. It only has 1 or is inhibited in secure mode + size_t l_numSections = RUNTIME::preVerifiedPnorSections.size(); + size_t l_expectedLids = (2 * l_numSections) - 1; + if (SECUREBOOT::enabled()) + { + l_expectedLids--; + } + + // Ensure the expected number of lids were loaded. + if (l_preVerLidMgr.cv_lidsLoaded.size() != l_expectedLids) + { + TS_FAIL("testLoadFromPnor> Num of lids loaded not correct"); + break; + } + + } while(0); + + PreVerifiedLidMgr::unlock(); + + TRACFCOMP( g_trac_runtime, EXIT_MRK"testLoadFromPnor complete" ); + } +}; + +#endif
\ No newline at end of file |