Skip to content

Commit

Permalink
Open Untrusted Communication for SP
Browse files Browse the repository at this point in the history
Change-Id: I87c7fe74349521eaec6ebf373e99f13eb1bf74f8
CQ:SW412793
Backport:release-fips910
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/51742
Reviewed-by: Nicholas E. Bofferding <bofferdn@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>
Reviewed-by: Michael Baiocchi <mbaiocch@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
  • Loading branch information
Stephen Cprek authored and dcrowell77 committed Jan 17, 2018
1 parent 329b814 commit 26bbcd9
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 6 deletions.
24 changes: 22 additions & 2 deletions src/include/usr/runtime/runtime.H
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2012,2017 */
/* Contributors Listed Below - COPYRIGHT 2012,2018 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -163,7 +163,17 @@ enum SectionId
RESERVED_MEM, //< Hostboot's Reserved Mainstore Memory
HRMOR_STASH, //< Pointer to address in reserved memory
// where PHYP can write HRMOR
LAST_SECTION = HRMOR_STASH //< Placeholder for arrays
CPU_CTRL, // Spira-H CPU controls area
LAST_SECTION = CPU_CTRL //< Placeholder for arrays
};

/**
* Range of SBE unsecure memory region to open
*/
enum SbeUnsecureMemoryRegions
{
SP_HOST_UNTRUSTED_COMM_AREA_ADDR = 0,
SP_HOST_UNTRUSTED_COMM_AREA_SIZE = 64*MEGABYTE,
};

/**
Expand Down Expand Up @@ -249,6 +259,16 @@ void setPayloadBaseAddress(uint64_t i_payloadAddress);
*/
void rediscover_hdat( void );

/**
* @brief Open necessary unsecure SBE windows for SP -> host communication
* Currently opens two windows
* 1. CPU controls SP ATTN areas
* 2. SP_HOST_UNTRUSTED_COMM_AREA_ADDR
*
* @return errlHndl_t Returns nullptr on success; otherwise errlog
*/
errlHndl_t openUntrustedSpCommArea();

}

#endif
16 changes: 15 additions & 1 deletion src/usr/isteps/istep21/call_host_runtime_setup.C
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2015,2017 */
/* Contributors Listed Below - COPYRIGHT 2015,2018 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -665,6 +665,7 @@ void* call_host_runtime_setup (void *io_pArgs)
}
}


// Fill in Hostboot runtime data for all nodes
// (adjunct partition)
// Write the HB runtime data into mainstore
Expand All @@ -677,6 +678,19 @@ void* call_host_runtime_setup (void *io_pArgs)
break;
}

// Open untrusted SP communication area if there is a PAYLOAD
// NOTE: Must be after all HDAT processing
if( !(TARGETING::is_no_load()) )
{
l_err = RUNTIME::openUntrustedSpCommArea();
if (l_err)
{
TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"Failed openUntrustedSpCommArea" );
break;
}
}

} while(0);

if( l_err )
Expand Down
31 changes: 30 additions & 1 deletion src/usr/runtime/hdatservice.C
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2012,2017 */
/* Contributors Listed Below - COPYRIGHT 2012,2018 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -927,6 +927,31 @@ errlHndl_t hdatService::getHostDataSection( SectionId i_section,
o_dataSize = MDT_MAINSTORE_ADDR_SECTION_HYP_HB_COMM_ADDR_SIZE; // 8 bytes

}
// SPIRA-H CPU Controls
else if ( RUNTIME::CPU_CTRL == i_section )
{
// Find the right tuple and verify it makes sense
errhdl = getAndCheckTuple(i_section, tuple);
if( errhdl )
{
break;
}
TRACDCOMP( g_trac_runtime, "CPU_CTRL tuple=%p", tuple );

uint64_t base_addr = 0;
errhdl = getSpiraTupleVA(tuple, base_addr);
if( errhdl )
{
break;
}

TRACDCOMP( g_trac_runtime, "cpu_ctrl_data=%p", base_addr );

// set the base address and size for the section
record_size = tuple->hdatActualSize;
o_dataSize = record_size;
o_dataAddr = base_addr;
}
// Not sure how we could get here...
else
{
Expand Down Expand Up @@ -1506,6 +1531,10 @@ errlHndl_t hdatService::getAndCheckTuple(const SectionId i_section,
l_spiraS = SPIRAS_MDT;
l_spiraL = SPIRAL_MDT;
break;
case RUNTIME::CPU_CTRL:
l_spiraH = SPIRAH_CPU_CTRL;
l_spiraL = SPIRAL_CPU_CTRL;
break;
default:
TRACFCOMP(g_trac_runtime, ERR_MRK"getAndCheckTuple> section %d not supported",
i_section );
Expand Down
22 changes: 21 additions & 1 deletion src/usr/runtime/hdatstructs.H
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2012,2017 */
/* Contributors Listed Below - COPYRIGHT 2012,2018 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -418,4 +418,24 @@ struct hbHypCommArea_t
}
} PACKED;

/** @brief The fields in the CPU Controls Legacy structure are a set of
* address / length pairs as shown below
*/
struct hdatCpuCtrlPair_t
{
uint64_t address; // 0x0000 Absolute main store adress relative to HRMOR
uint64_t size; // 0x0008 Data structure size in bytes
}__attribute__ ((packed));

/** @brief CPU Controls Legacy Structure pointed to by the CPU Controls Header
* Area pointer in the CPU Controls
*/
struct hdatCpuCtrlInfo_t
{
hdatCpuCtrlPair_t spAddrTable; // SP Address Table (SPAT)
hdatCpuCtrlPair_t spAttnArea1; // SP Attention Area 1
hdatCpuCtrlPair_t spAttnArea2; // SP Attention Area 2
hdatCpuCtrlPair_t servRoutineData; // Service Routines Data Area
} __attribute__ ((packed));

#endif
105 changes: 104 additions & 1 deletion src/usr/runtime/populate_hbruntime.C
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2016,2017 */
/* Contributors Listed Below - COPYRIGHT 2016,2018 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -75,6 +75,7 @@
#include <util/utilmclmgr.H>
#include <pnor/pnor_reasoncodes.H>
#include <runtime/common/runtime_utils.H>
#include <limits.h>

namespace RUNTIME
{
Expand Down Expand Up @@ -2327,5 +2328,107 @@ errlHndl_t persistent_rwAttrRuntimeCheck( void )
return l_err;
} // end persistent_rwAttrRuntimeCheck

errlHndl_t openUntrustedSpCommArea()
{
TRACFCOMP( g_trac_runtime, ENTER_MRK "openUntrustedSpCommArea()");
errlHndl_t l_err = nullptr;

do {
TARGETING::Target * l_sys = nullptr;
TARGETING::targetService().getTopLevelTarget(l_sys);
assert(l_sys != nullptr, "openUntrustedSpCommArea: top level target nullptr");

// Get Payload HRMOR
uint64_t l_hrmor = l_sys->getAttr<TARGETING::ATTR_PAYLOAD_BASE>() * MEGABYTE;

// pass 0 since there is only one record
const uint64_t l_instance = 0;
uint64_t l_cpuCtrlDataAddr = 0;
size_t l_cpuCtrlDataSizeMax = 0;

// Get the address of the Spira-H CPU control section
l_err = RUNTIME::get_host_data_section( RUNTIME::CPU_CTRL,
l_instance,
l_cpuCtrlDataAddr,
l_cpuCtrlDataSizeMax);
if(l_err != nullptr)
{
TRACFCOMP( g_trac_runtime, ERR_MRK "openUntrustedSpCommArea(): get_host_data_section() failed for CPU_CTRL HDAT section");
break;
}

// Traverse CPU Controls Header Area pointer to find CPU Controls Structure
auto const l_pCpuCtrlHdr =
reinterpret_cast<hdatHDIF_t*>(l_cpuCtrlDataAddr);
auto const l_pCpuDataPointer =
reinterpret_cast<hdatHDIFDataHdr_t*>(l_cpuCtrlDataAddr +
l_pCpuCtrlHdr->hdatDataPtrOffset);
auto const l_pCpuCtrlInfo =
reinterpret_cast<hdatCpuCtrlInfo_t*>(l_cpuCtrlDataAddr +
l_pCpuDataPointer->hdatOffset);

// Get Address of First SP ATTN area and size of both SP ATTN areas
// Add HRMOR to address as it's relative to the HRMOR
uint64_t l_spAttnStartAddr = l_pCpuCtrlInfo->spAttnArea1.address + l_hrmor;
size_t l_spAttnCombinedSize = l_pCpuCtrlInfo->spAttnArea1.size +
l_pCpuCtrlInfo->spAttnArea2.size;

TRACFCOMP( g_trac_runtime, "openUntrustedSpCommArea() SP ATTN addr = 0x%016llx combined size 0x%X",
l_spAttnStartAddr,
l_spAttnCombinedSize);

// Open unsecure SBE memory regions
// Loop through all functional Procs
TARGETING::TargetHandleList l_procChips;
getAllChips(l_procChips, TARGETING::TYPE_PROC);
for (const auto & l_procChip : l_procChips)
{
// Get Instance ID of proc for trace
uint32_t l_id = l_procChip->getAttr<TARGETING::ATTR_HBRT_HYP_ID>();

// Open SP ATTN region
l_err = SBEIO::openUnsecureMemRegion(l_spAttnStartAddr,
l_spAttnCombinedSize,
true, //true=Read-Write
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_spAttnStartAddr,
l_spAttnCombinedSize);
break;
}

// Only open additional SBE window in PHYP mode
if(TARGETING::is_phyp_load())
{
l_err = SBEIO::openUnsecureMemRegion(
RUNTIME::SP_HOST_UNTRUSTED_COMM_AREA_ADDR,
RUNTIME::SP_HOST_UNTRUSTED_COMM_AREA_SIZE,
true, //true=Read-Write
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,
RUNTIME::SP_HOST_UNTRUSTED_COMM_AREA_ADDR,
RUNTIME::SP_HOST_UNTRUSTED_COMM_AREA_SIZE);
break;
}
}
}
if(l_err)
{
break;
}

} while(0);

TRACFCOMP( g_trac_runtime, EXIT_MRK"openUntrustedSpCommArea()");

return l_err;
}

} //namespace RUNTIME

0 comments on commit 26bbcd9

Please sign in to comment.