Skip to content

Commit

Permalink
PRD: cleaned BitString::Pattern()
Browse files Browse the repository at this point in the history
This function had a off-by-one error that could access memory beyond
the available memory space.

Change-Id: I762d0e24f0cc7ecd42e7f9393b0dc5b3b8bddefc
RTC: 167819
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/35688
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Reviewed-by: Benjamin J. Weisenbeck <bweisenb@us.ibm.com>
Reviewed-by: Caleb N. Palmer <cnpalmer@us.ibm.com>
Reviewed-by: Zane C. Shelley <zshelle@us.ibm.com>
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/36201
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
  • Loading branch information
zane131 committed Feb 10, 2017
1 parent 500d417 commit a56b9bd
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 167 deletions.
4 changes: 2 additions & 2 deletions src/usr/diag/prdf/common/framework/register/iipscr.C
Expand Up @@ -197,13 +197,13 @@ void SCAN_COMM_REGISTER_CLASS::ClearBit
void SCAN_COMM_REGISTER_CLASS::clearAllBits()
{
BIT_STRING_CLASS & bitString = AccessBitString();
bitString.Pattern( 0, bitString.getBitLen(), 0x00000000, 32 );
bitString.clearAll();
}

void SCAN_COMM_REGISTER_CLASS::setAllBits()
{
BIT_STRING_CLASS & bitString = AccessBitString();
bitString.Pattern( 0, bitString.getBitLen(), 0xffffffff, 32 );
bitString.setAll();
}

//------------------------------------------------------------------------------
Expand Down
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2012,2014 */
/* Contributors Listed Below - COPYRIGHT 2012,2017 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -84,7 +84,7 @@ bitString(r.GetBitLength()),
bitStringMask(r.GetBitLength()),
xMaskScr(maskScr)
{
bitStringMask.Pattern(0);
bitStringMask.clearAll();
}

ErrorRegisterMask::ErrorRegisterMask
Expand All @@ -100,7 +100,7 @@ bitString(r.GetBitLength()),
bitStringMask(r.GetBitLength()),
xMaskScr(maskScr)
{
bitStringMask.Pattern(0); // clear software mask
bitStringMask.clearAll(); // clear software mask
}

// **********************************************************************
Expand Down
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2012,2016 */
/* Contributors Listed Below - COPYRIGHT 2012,2017 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -200,7 +200,7 @@ uint32_t ScomAccessor::Access(TargetHandle_t i_target,
}

case MopRegisterAccess::READ:
bs.Pattern(0x00000000); // clear all bits
bs.clearAll(); // clear all bits

rc = PRDF::PlatServices::getScom(i_target, bs, registerId);

Expand Down
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2012,2016 */
/* Contributors Listed Below - COPYRIGHT 2012,2017 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -122,7 +122,7 @@ class SummaryRegister : public SCAN_COMM_REGISTER_CLASS
const BIT_STRING_CLASS * GetBitString(
ATTENTION_TYPE i_type = INVALID_ATTENTION_TYPE) const
{
iv_bs->Clear();
iv_bs->clearAll();

PRDF::BitString tmp = *iv_child->GetBitString(i_type);

Expand Down
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2012,2015 */
/* Contributors Listed Below - COPYRIGHT 2012,2017 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -190,7 +190,7 @@ int32_t AndResetErrorRegister::Reset(const BitKey & bit_list,
if(bl_length !=0)
{
BIT_STRING_BUFFER_CLASS bs(xAndResetScr.GetBitLength());
bs.Pattern(0xffffffff,32); // set to all ones
bs.setAll(); // set to all ones
uint32_t i;
for(i = 0; i < bl_length; ++i) // Turn off all bits used to isolate problem
{
Expand Down
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2012,2015 */
/* Contributors Listed Below - COPYRIGHT 2012,2017 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -188,7 +188,7 @@ class AndOperator : public RegisterResetOperator
if(bl_length != 0) // Check for bits to reset
{
BIT_STRING_BUFFER_CLASS bs(writeReg->GetBitLength());
bs.Pattern(0xffffffff, 32); // set all to 1's.
bs.setAll(); // set all to 1's.

uint32_t i;
for(i = 0; i < bl_length; ++i) // Turn off all bits specified
Expand Down Expand Up @@ -309,7 +309,7 @@ class NotOperator : public RegisterResetOperator
else // RESETOPERATOR_MASK
{
BIT_STRING_BUFFER_CLASS bs(writeReg->GetBitLength());
bs.Pattern(0xffffffff, 32); // set all to 1's.
bs.setAll(); // set all to 1's.
writeReg->SetBitString(&bs); // Copy bit-string to register.
rc = writeReg->Write(); // Write hardware
}
Expand Down
6 changes: 3 additions & 3 deletions src/usr/diag/prdf/common/plat/p9/prdfP9ProcDomain.C
Expand Up @@ -214,17 +214,17 @@ void ProcDomain::SortForXstop()

// Get initial list (all chips).
BIT_STRING_BUFFER_CLASS l_current(GetSize());
l_current.Pattern(0,GetSize(),0xFFFFFFFF, 32); // turn on all bits.
l_current.setAll(); // turn on all bits.

// Do reduction.
// When done, l_prev will have the minimal list.
BIT_STRING_BUFFER_CLASS l_prev(GetSize());
l_prev.Clear();
l_prev.clearAll();

while ((!(l_current == l_prev)) && (!l_current.IsZero()))
{
l_prev = l_current;
l_current.Clear();
l_current.clearAll();

for (uint32_t i = 0; i < GetSize(); i++)
{
Expand Down
8 changes: 4 additions & 4 deletions src/usr/diag/prdf/common/util/prdfBitKey.C
Expand Up @@ -137,7 +137,7 @@ BitKey & BitKey::operator=(const BitKey & bit_list)
if(iv_Capacity)
{
BitString bs(iv_Capacity,DataPtr());
bs.Pattern(0x00000000);
bs.clearAll();
}
ReAllocate(bit_list.iv_Capacity);
if(IsDirect()) // implies bit_list is also direct
Expand Down Expand Up @@ -167,7 +167,7 @@ BitKey & BitKey::operator=(const BitString & bit_string)
if(iv_Capacity)
{
BitString bs(iv_Capacity,DataPtr());
bs.Pattern(0x00000000);
bs.clearAll();
}
ReAllocate(bit_string.getBitLen());
BitString dbs(iv_Capacity,DataPtr());
Expand All @@ -182,7 +182,7 @@ BitKey & BitKey::operator=(const char * string_ptr)
if(iv_Capacity)
{
BitString bs(iv_Capacity,DataPtr());
bs.Pattern(0x00000000);
bs.clearAll();
}

while(*string_ptr != '\0')
Expand Down Expand Up @@ -360,7 +360,7 @@ void BitKey::ReAllocate(uint32_t i_len)
{
uint32_t * newBuffer = new uint32_t[wordsize];
BitString dbs(iv_Capacity,newBuffer);
dbs.Pattern(0x00000000);
dbs.clearAll();
BitString sbs(oldSize,oldPtr);
dbs.SetBits(sbs);
iv_storage1 = 0;
Expand Down
98 changes: 32 additions & 66 deletions src/usr/diag/prdf/common/util/prdfBitString.C
Expand Up @@ -42,6 +42,35 @@ namespace PRDF
// BitString class
//##############################################################################

void BitString::setPattern( uint32_t i_sPos, uint32_t i_sLen,
CPU_WORD i_pattern, uint32_t i_pLen )
{
PRDF_ASSERT(nullptr != getBufAddr()); // must to have a valid address
PRDF_ASSERT(0 < i_sLen); // must have at least one bit
PRDF_ASSERT(i_sPos + i_sLen <= getBitLen()); // field must be within range
PRDF_ASSERT(0 < i_pLen); // must have at least one bit
PRDF_ASSERT(i_pLen <= CPU_WORD_BIT_LEN); // i_pLen length must be valid

// Get a bit string for the pattern subset (right justified).
BitStringOffset bso ( CPU_WORD_BIT_LEN - i_pLen, i_pLen, &i_pattern );

// Iterate the range in chunks the size of i_pLen.
uint32_t endPos = i_sPos + i_sLen;
for ( uint32_t pos = i_sPos; pos < endPos; pos += i_pLen )
{
// The true chunk size is either i_pLen or the leftovers at the end.
uint32_t len = std::min( i_pLen, endPos - pos );

// Get this chunk's pattern value, truncate (left justified) if needed.
CPU_WORD pattern = bso.GetField( 0, len );

// Set the pattern in this string.
SetField( pos, len, pattern );
}
}

//------------------------------------------------------------------------------

uint32_t BitString::GetSetCount(uint32_t bit_position,
uint32_t leng
) const
Expand Down Expand Up @@ -221,69 +250,6 @@ void BitString::SetBits
}
}

// ------------------------------------------------------------------------------------------------

// Function Specification //////////////////////////////////////////
//
// Title: Pattern
//
// Purpose: This function sets the the specified bits with the
// specifed pattern. The number of bits sets is
// specified by the length and begins at the specified
// offest. The pattern is repeated as often as necessary
// as specified by the pattern_bit_length.
//
// Side-effects: Bit String may be modified.
//
// Dependencies: Parameters must specifiy valid bits in both the
// bit string and the pattern.
//
// Time Complexity: O(m) where m is the number of bits to modify
// (parameter l)
//
// Examples: o(0), l(10), pattern(0xA), pattern_bit_length(4)
// Old String: 0000000000
// New String: 1010101010
//
// o(3), l(4), pattern(0x3), pattern_bit_length(3)
// Old String: 0001001000
// New String: 0000110000
//
// End Function Specification //////////////////////////////////////

void BitString::Pattern
(
uint32_t o,
uint32_t l,
CPU_WORD pattern,
uint32_t pattern_bit_length
)
{
PRDF_ASSERT(((o + l) <= iv_bitLen) &&
(pattern_bit_length <= CPU_WORD_BIT_LEN));

uint32_t current_offset;

// current_offset = offset + o;
current_offset = o;
while(true)
{
if(l > pattern_bit_length)
{
/* Set values using full CPU_WORDs */
SetField(current_offset, pattern_bit_length, pattern);
l -= pattern_bit_length;
current_offset += pattern_bit_length;
}
else
{
/* Set value in remainder of last CPU_WORD */
SetField(current_offset, l, pattern);
break;
}
}
}

// Function Specification //////////////////////////////////////////
//
// Title: Is Set
Expand Down Expand Up @@ -588,7 +554,7 @@ BitStringBuffer BitString::operator>>(uint32_t count) const
{
BitStringBuffer l_bsb(this->getBitLen());
BitString * l_bsbp = &l_bsb; // dg03a - stupid trick to get to GetRelativePosition()
// l_bsb.Clear();
// l_bsb.clearAll();
if(count < this->getBitLen())
{
//bso overlays bsb at offset = count
Expand All @@ -605,7 +571,7 @@ BitStringBuffer BitString::operator>>(uint32_t count) const
BitStringBuffer BitString::operator<<(uint32_t count) const
{
BitStringBuffer l_bsb(this->getBitLen());
// l_bsb.Clear();
// l_bsb.clearAll();
if(count < this->getBitLen())
{
// bso overlays *this at offset = count
Expand Down Expand Up @@ -686,7 +652,7 @@ void BitStringBuffer::initBuffer()
setBufAddr( new CPU_WORD[ getNumCpuWords(getBitLen()) ] );

// Clear the new buffer.
Clear();
if ( !IsZero() ) clearAll();
}

/*--------------------------------------------------------------------*/
Expand Down

0 comments on commit a56b9bd

Please sign in to comment.