From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.8067.1675422660964785752 for ; Fri, 03 Feb 2023 03:11:01 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: pierre.gondois@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4BDA4C14; Fri, 3 Feb 2023 03:11:42 -0800 (PST) Received: from [10.34.100.128] (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0828E3F8D6; Fri, 3 Feb 2023 03:10:58 -0800 (PST) Message-ID: Date: Fri, 3 Feb 2023 12:10:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH] ArmPkg/ArmScmiDxe: Fix the calculation of RequiredArraySize in ClockDescribeRates() To: Sudeep Holla , devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Girish Pathak , Jeff Brasen , Sami Mujawar References: <20230202143015.3066988-1-sudeep.holla@arm.com> From: "PierreGondois" In-Reply-To: <20230202143015.3066988-1-sudeep.holla@arm.com> Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hello Sudeep, On 2/2/23 15:30, Sudeep Holla wrote: > As per the SCMI specification, section CLOCK_DESCRIBE_RATES mentions that > the value of num_rates_flags[11:0] in the response must be 3 if the return > format is the triplet. Due to the buggy firmware, this was not noticed for > long time. The firmware is now fixed resulting in ClockDescribeRates() to > fail with "Buffer Too Small" error as the RequiredArraySize gets miscalculated > as 72 instead of 24. > > Fix the issue by reusing the logic for both the return format which must > work if num_rates_flags has correct value as expected from the specification. > > Cc: Pierre Gondois > Cc: Girish Pathak > Cc: Jeff Brasen > Reported-by: Sami Mujawar > Signed-off-by: Sudeep Holla > --- > ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c | 7 +------ > 1 file changed, 1 insertion(+), 6 deletions(-) > > Hi All, > > Sorry for the resend, I hadn't subscribed before so resending after the > subscription. > > Regards, > Sudeep > > diff --git a/ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c b/ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c > index 12a7e6df5d43..1412717bc227 100644 > --- a/ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c > +++ b/ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c > @@ -236,12 +236,7 @@ ClockDescribeRates ( > *TotalRates = NUM_RATES (DescribeRates->NumRatesFlags) > + NUM_REMAIN_RATES (DescribeRates->NumRatesFlags); > > - if (*Format == ScmiClockRateFormatDiscrete) { > - RequiredArraySize = (*TotalRates) * sizeof (UINT64); > - } else { > - // We need to return triplet of 64 bit value for each rate > - RequiredArraySize = (*TotalRates) * 3 * sizeof (UINT64); > - } > + RequiredArraySize = (*TotalRates) * sizeof (UINT64); > > if (RequiredArraySize > (*RateArraySize)) { > *RateArraySize = RequiredArraySize; I think the following also needs to be modified: """ for (RateNo = 0; RateNo < NUM_RATES (DescribeRates->NumRatesFlags); RateNo++) { // Linear clock rates from minimum to maximum in steps // Minimum clock rate. Rate = &DescribeRates->Rates[RateOffset++]; RateArray[RateIndex].ContinuousRate.Min = ConvertTo64Bit (Rate->Low, Rate->High); Rate = &DescribeRates->Rates[RateOffset++]; // Maximum clock rate. RateArray[RateIndex].ContinuousRate.Max = ConvertTo64Bit (Rate->Low, Rate->High); Rate = &DescribeRates->Rates[RateOffset++]; // Step. RateArray[RateIndex++].ContinuousRate.Step = ConvertTo64Bit (Rate->Low, Rate->High); } """ If the clock format is continuous, then per spec: NUM_RATES (DescribeRates->NumRatesFlags) == 3 However 3 rates are read per loop here. So I think the loop needs to be removed aswell. Without this additional change, I get: """ Synchronous Exception at 0xA2D0E6EBD20F8604 Synchronous Exception at 0xA2D0E6EBD20F8604 PC 0xA2D0E6EBD20F8604 Recursive exception occurred while dumping the CPU state """ With the above loop removed: Reviewed-by: Pierre Gondois Tested-by: Pierre Gondois Regards, Pierre