From nobody Sun May 19 19:10:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99600+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99600+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1675434225; cv=none; d=zohomail.com; s=zohoarc; b=DYnxJN9P9ttCqbouEEQifx+Pj2ycjWIBLUGPNlcziEnTWZUGZU1BYkPjLVCD4W7Nu7YkH6IYJ5nrRbdZ3IV/pcZv6j0e9qn+Auw0aMXzwSAuLu81s4Md5xBBkqHnmXS5s9CV3C9a3iQ3buJEfYV3sn37Cpg2OI66wMKOGoiwYzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675434225; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=ZDHDv5JbYCdTXa4q3oV+/uVZnLm88/IkgzLv7evL/OA=; b=kMGLBCzNb3iQdg888M1xq6JgLNOPyCDTqxH0Bz0OhkDQxC9gqYMraJM0FcRe1VPTXcvKi/T3K+K0pbRaW6pvp3o9gYtTrfRSDa51ktSjPU10A2MiABb1fKaQJdhxtL5u+jzRXtLLxPF4ZS/lSPMqS8yPNzoovYCphRqoFy+nJK4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99600+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1675434225275913.7114289525528; Fri, 3 Feb 2023 06:23:45 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id dPVnYY1788612xKIaIGjFSR3; Fri, 03 Feb 2023 06:23:44 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.11554.1675434223273493871 for ; Fri, 03 Feb 2023 06:23:43 -0800 X-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 5C1D84B3; Fri, 3 Feb 2023 06:24:24 -0800 (PST) X-Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E99293F71E; Fri, 3 Feb 2023 06:23:40 -0800 (PST) From: "Sudeep Holla" To: devel@edk2.groups.io Cc: Sudeep Holla , Leif Lindholm , Ard Biesheuvel , Pierre Gondois , Girish Pathak , Jeff Brasen , Pierre Gondois , Sami Mujawar Subject: [edk2-devel] [PATCH v2] ArmPkg/ArmScmiDxe: Fix the calculation of RequiredArraySize in ClockDescribeRates() Date: Fri, 3 Feb 2023 14:23:38 +0000 Message-Id: <20230203142338.3403641-1-sudeep.holla@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sudeep.holla@arm.com X-Gm-Message-State: jk7aYGWuL76U8c04wkVuqcDJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1675434224; bh=tLsqsvmDsVRkxsUFFtxDeCwHSGdW+2gj3FmkrJ0MQi4=; h=Cc:Date:From:Reply-To:Subject:To; b=n3DQk7TeIMuYR0I8N5ooXnxtpGSuzV9PPIbKzgAzsD/Leh/dpYSAizCIuO9xjzC2KIE 7xLRRlLXsqF6EzxXSWrV7GMvQ/dmsRmbA1/BQ3T73YRPniOLnV/KylHVlwVUUR7t/m43n r9a651HPV4BodefqQFAZrOAinhfYZf+OteQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1675434226497100001 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Pierre Gondois Tested-by: Pierre Gondois Reported-by: Sami Mujawar Signed-off-by: Sudeep Holla Reviewed-by: Sami Mujawar Tested-by: Sami Mujawar --- ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) v1->v2: - Removed the unnecessary and incorrect loop to populate the clock rate triplets(as suggested by Pierre) Note the real delta is just 7 lines deletion when viewed with ignored spacechanges. diff --git a/ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c b/ArmPkg/Drivers= /ArmScmiDxe/ScmiClockProtocol.c index 12a7e6df5d43..f092208a6601 100644 --- a/ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c +++ b/ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c @@ -236,12 +236,7 @@ ClockDescribeRates ( *TotalRates =3D NUM_RATES (DescribeRates->NumRatesFlags) + NUM_REMAIN_RATES (DescribeRates->NumRatesFlags); =20 - if (*Format =3D=3D ScmiClockRateFormatDiscrete) { - RequiredArraySize =3D (*TotalRates) * sizeof (UINT64); - } else { - // We need to return triplet of 64 bit value for each rate - RequiredArraySize =3D (*TotalRates) * 3 * sizeof (UINT64); - } + RequiredArraySize =3D (*TotalRates) * sizeof (UINT64); =20 if (RequiredArraySize > (*RateArraySize)) { *RateArraySize =3D RequiredArraySize; @@ -259,23 +254,21 @@ ClockDescribeRates ( ConvertTo64Bit (Rate->Low, Rate->High); } } else { - for (RateNo =3D 0; RateNo < NUM_RATES (DescribeRates->NumRatesFlags)= ; RateNo++) { - // Linear clock rates from minimum to maximum in steps - // Minimum clock rate. - Rate =3D &DescribeRates->Rates[= RateOffset++]; - RateArray[RateIndex].ContinuousRate.Min =3D - ConvertTo64Bit (Rate->Low, Rate->High); + // Linear clock rates from minimum to maximum in steps + // Minimum clock rate. + Rate =3D &DescribeRates->Rates[Ra= teOffset++]; + RateArray[RateIndex].ContinuousRate.Min =3D + ConvertTo64Bit (Rate->Low, Rate->High); =20 - Rate =3D &DescribeRates->Rates[RateOffset++]; - // Maximum clock rate. - RateArray[RateIndex].ContinuousRate.Max =3D - ConvertTo64Bit (Rate->Low, Rate->High); + Rate =3D &DescribeRates->Rates[RateOffset++]; + // Maximum clock rate. + RateArray[RateIndex].ContinuousRate.Max =3D + ConvertTo64Bit (Rate->Low, Rate->High); =20 - Rate =3D &DescribeRates->Rates[RateOffset++]; - // Step. - RateArray[RateIndex++].ContinuousRate.Step =3D - ConvertTo64Bit (Rate->Low, Rate->High); - } + Rate =3D &DescribeRates->Rates[RateOffset++]; + // Step. + RateArray[RateIndex++].ContinuousRate.Step =3D + ConvertTo64Bit (Rate->Low, Rate->High); } } while (NUM_REMAIN_RATES (DescribeRates->NumRatesFlags) !=3D 0); =20 --=20 2.39.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99600): https://edk2.groups.io/g/devel/message/99600 Mute This Topic: https://groups.io/mt/96723380/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-