From nobody Mon Feb 9 23:39:01 2026 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+109921+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+109921+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1698066329; cv=none; d=zohomail.com; s=zohoarc; b=iB0AgcHFRxCjgmNzWGzrAwutrBxLxCHHc3lzfzixgqiBtop1cpxMmfot0uyn6yoPqK/lrzmp7Vvo6Db1y78hqvjSkkCXgr0SDtIb5HFD82WS3rFqTAmMUh17dZfCb6n32pMx2OLy5/2nq05rf6fzmXz6wLtKx0CvB173wfJQnP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698066329; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=HWDSH2h8JlWNc5QVvWhE8QPOC9ugC1zHnIHXyP64NC0=; b=Zf3uMrhEBAaQ65o8C8pddqiOa/XlAcwgO/Pp6bVXvcasDwJPx4IR2Uy2mbYlwMrsl+nXLRPjEzDuITt/ZB7tm6iqgd/9H1Zd2noqMgeGmzeF33BX2+B1U5y1/5k34EzX9ZQFIgUvOO5S336RCGzvyP1NvPminJ1MSA2WVxpPDEA= 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+109921+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 1698066329753153.39062952361303; Mon, 23 Oct 2023 06:05:29 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=zEJapWRqAGN3O1Gmam843rkiN6Xv5O/PjfXLgENHTGI=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1698066329; v=1; b=TLsFLNjDEMk1lPR310JQ7Eo9zmm59pHg+6BeSRnWe2vDXRzAF4FcZnOjifhyrMmmD9JlnMlj mgM/Phquh/2fXE9UHhRAkHMBlWSDAMU9/wwKmL2fXfH3T3B5yW/gSoJxm3M/cOwFF6CnLEpPOtj JOZOxhuSyqIrl8Skjor3ixaY= X-Received: by 127.0.0.2 with SMTP id ZR6YYY1788612x9X3VeTvSiq; Mon, 23 Oct 2023 06:05:29 -0700 X-Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by mx.groups.io with SMTP id smtpd.web11.120296.1698066328513631540 for ; Mon, 23 Oct 2023 06:05:28 -0700 X-Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2c4fdf94666so42875641fa.2 for ; Mon, 23 Oct 2023 06:05:28 -0700 (PDT) X-Gm-Message-State: VccksvrGz6m3Fgpd45myagpax1787277AA= X-Google-Smtp-Source: AGHT+IGMgHzk2tRBnFSHEqoC3oZlcLrDkFutlYb2UsEmFe//ojy8UZFEwbMX8sVNwU2eJiksI1UCcg== X-Received: by 2002:a2e:9b0b:0:b0:2b9:36d5:729c with SMTP id u11-20020a2e9b0b000000b002b936d5729cmr6426089lji.47.1698066326257; Mon, 23 Oct 2023 06:05:26 -0700 (PDT) X-Received: from PC10319.67 ([82.97.198.254]) by smtp.googlemail.com with ESMTPSA id r11-20020a2e994b000000b002b9e0d19644sm1550081ljj.106.2023.10.23.06.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 06:05:25 -0700 (PDT) From: "Konstantin Aladyshev" To: devel@edk2.groups.io Cc: abner.chang@amd.com, AbdulLateef.Attar@amd.com, nicklew@nvidia.com, Konstantin Aladyshev Subject: [edk2-devel] [PATCH edk2-platforms v3 13/16] ManageabilityPkg/PldmProtocol: Remove PLDM command table Date: Mon, 23 Oct 2023 16:05:08 +0300 Message-Id: <20231023130511.4521-14-aladyshev22@gmail.com> In-Reply-To: <20231023130511.4521-1-aladyshev22@gmail.com> References: <20231023130511.4521-1-aladyshev22@gmail.com> MIME-Version: 1.0 Precedence: Bulk 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,aladyshev22@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1698066330959100053 Content-Type: text/plain; charset="utf-8" From: Abner Chang In case of the PLDM/MCTP communication response size doesn't have to be known beforehand, the caller just need to provide the buffer big enough to accomodate the response. Remove PLDM command table for retrieving the response payload size and correct the code to fix the response buffer size handling. Also update the message for error conditions. Signed-off-by: Abner Chang Signed-off-by: Konstantin Aladyshev --- .../PldmProtocol/Common/PldmProtocolCommon.c | 100 +++--------------- .../PldmProtocol/Common/PldmProtocolCommon.h | 3 + .../Universal/PldmProtocol/Dxe/PldmProtocol.c | 13 ++- 3 files changed, 31 insertions(+), 85 deletions(-) diff --git a/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmPr= otocolCommon.c b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/Pl= dmProtocolCommon.c index ea3d4a22b2..bc72ce07b3 100644 --- a/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolC= ommon.c +++ b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolC= ommon.c @@ -21,42 +21,6 @@ extern CHAR16 *mTransportName; extern UINT8 mPldmRequestInstanceId; =20 -PLDM_MESSAGE_PACKET_MAPPING PldmMessagePacketMappingTable[] =3D { - { PLDM_TYPE_SMBIOS, PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA_COMMAND_COD= E, sizeof (PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA_RESPONSE_FORMAT) }, - { PLDM_TYPE_SMBIOS, PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA_COMMAND_COD= E, sizeof (PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA_RESPONSE_FORMAT) }, - { PLDM_TYPE_SMBIOS, PLDM_SET_SMBIOS_STRUCTURE_TABLE_COMMAND_CODE, = sizeof (PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST_FORMAT) } -}; - -/** - This function returns the expected full size of PLDM response message. - - @param[in] PldmType PLDM message type. - @param[in] PldmCommand PLDM command of this PLDM type. - - @retval Zero No matched entry for this PldmType/PldmCommand. - @retval None-zero Size of full packet is returned. -**/ -UINT32 -GetFullPacketResponseSize ( - IN UINT8 PldmType, - IN UINT8 PldmCommand - ) -{ - INT16 Index; - PLDM_MESSAGE_PACKET_MAPPING *ThisEntry; - - ThisEntry =3D PldmMessagePacketMappingTable; - for (Index =3D 0; Index < (sizeof (PldmMessagePacketMappingTable)/ sizeo= f (PLDM_MESSAGE_PACKET_MAPPING)); Index++) { - if ((PldmType =3D=3D ThisEntry->PldmType) && (PldmCommand =3D=3D ThisE= ntry->PldmCommand)) { - return ThisEntry->ResponseSize; - } - - ThisEntry++; - } - - return 0; -} - /** This functions setup the final header/body/trailer packets for the acquired transport interface. @@ -267,10 +231,10 @@ CommonPldmSubmitCommand ( TransferToken.TransmitPackage.TransmitTimeoutInMillisecond =3D MANAGEABI= LITY_TRANSPORT_NO_TIMEOUT; =20 // Set receive packet. - FullPacketResponseDataSize =3D GetFullPacketResponseSize (PldmType, Pldm= Command); - if (FullPacketResponseDataSize =3D=3D 0) { - DEBUG ((DEBUG_ERROR, " No mapping entry in PldmMessagePacketMappingTa= ble for PLDM Type:%d Command %d\n", PldmType, PldmCommand)); - ASSERT (FALSE); + if (ResponseData =3D=3D NULL && *ResponseDataSize =3D=3D 0) { + FullPacketResponseDataSize =3D sizeof (PLDM_RESPONSE_HEADER); + } else { + FullPacketResponseDataSize =3D *ResponseDataSize + sizeof (PLDM_RESPON= SE_HEADER); } =20 FullPacketResponseData =3D (UINT8 *)AllocateZeroPool (FullPacketResponse= DataSize); @@ -306,6 +270,7 @@ CommonPldmSubmitCommand ( ); // // Check the response size. + // if (TransferToken.ReceivePackage.ReceiveSizeInByte < sizeof (PLDM_RESPON= SE_HEADER)) { DEBUG (( DEBUG_MANAGEABILITY_INFO, @@ -315,21 +280,13 @@ CommonPldmSubmitCommand ( TransferToken.ReceivePackage.ReceiveSizeInByte, FullPacketResponseDataSize )); - if (ResponseDataSize !=3D NULL) { - if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInBy= te) { - *ResponseDataSize =3D TransferToken.ReceivePackage.ReceiveSizeInBy= te; - } - } - - if (ResponseData !=3D NULL) { - CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *Resp= onseDataSize); - } - + HelperManageabilityDebugPrint ((VOID *)FullPacketResponseData, Transfe= rToken.ReceivePackage.ReceiveSizeInByte, "Failed response payload\n"); goto ErrorExit; } =20 // // Check the integrity of response. data. + // ResponseHeader =3D (PLDM_RESPONSE_HEADER *)FullPacketResponseData; if ((ResponseHeader->PldmHeader.DatagramBit !=3D (!PLDM_MESSAGE_HEADER_I= S_DATAGRAM)) || (ResponseHeader->PldmHeader.RequestBit !=3D PLDM_MESSAGE_HEADER_IS_R= ESPONSE) || @@ -343,22 +300,16 @@ CommonPldmSubmitCommand ( DEBUG ((DEBUG_ERROR, " Instance ID =3D %d (Expected value: %d)\n",= ResponseHeader->PldmHeader.InstanceId, mPldmRequestInstanceId)); DEBUG ((DEBUG_ERROR, " Pldm Type =3D %d (Expected value: %d)\n",= ResponseHeader->PldmHeader.PldmType, PldmType)); DEBUG ((DEBUG_ERROR, " Pldm Command =3D %d (Expected value: %d)\n",= ResponseHeader->PldmHeader.PldmTypeCommandCode, PldmCommand)); - if (ResponseDataSize !=3D NULL) { - if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInBy= te) { - *ResponseDataSize =3D TransferToken.ReceivePackage.ReceiveSizeInBy= te; - } - } - - if (ResponseData !=3D NULL) { - CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *Resp= onseDataSize); - } + DEBUG ((DEBUG_ERROR, " Pldm Completion Code =3D 0x%x\n", ResponseHe= ader->PldmCompletionCode)); =20 + HelperManageabilityDebugPrint ((VOID *)FullPacketResponseData, Transfe= rToken.ReceivePackage.ReceiveSizeInByte, "Failed response payload\n"); goto ErrorExit; } =20 // // Check the response size - if (TransferToken.ReceivePackage.ReceiveSizeInByte !=3D FullPacketRespon= seDataSize) { + // + if (TransferToken.ReceivePackage.ReceiveSizeInByte > FullPacketResponseD= ataSize) { DEBUG (( DEBUG_ERROR, "The response size is incorrect: Response size %d (Expected %d), Com= pletion code %d.\n", @@ -366,38 +317,21 @@ CommonPldmSubmitCommand ( FullPacketResponseDataSize, ResponseHeader->PldmCompletionCode )); - if (ResponseDataSize !=3D NULL) { - if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInBy= te) { - *ResponseDataSize =3D TransferToken.ReceivePackage.ReceiveSizeInBy= te; - } - } - - if (ResponseData !=3D NULL) { - CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *Resp= onseDataSize); - } =20 + HelperManageabilityDebugPrint ((VOID *)FullPacketResponseData, Transfe= rToken.ReceivePackage.ReceiveSizeInByte, "Failed response payload\n"); goto ErrorExit; } =20 - if (*ResponseDataSize !=3D (TransferToken.ReceivePackage.ReceiveSizeInBy= te - sizeof (PLDM_RESPONSE_HEADER))) { + if (*ResponseDataSize < GET_PLDM_MESSAGE_PAYLOAD_SIZE(TransferToken.Rece= ivePackage.ReceiveSizeInByte)) { DEBUG ((DEBUG_ERROR, " The size of response is not matched to Request= DataSize assigned by caller.\n")); DEBUG (( DEBUG_ERROR, "Caller expects %d, the response size minus PLDM_RESPONSE_HEADER siz= e is %d, Completion Code %d.\n", *ResponseDataSize, - TransferToken.ReceivePackage.ReceiveSizeInByte - sizeof (PLDM_RESPON= SE_HEADER), + GET_PLDM_MESSAGE_PAYLOAD_SIZE(TransferToken.ReceivePackage.ReceiveSi= zeInByte), ResponseHeader->PldmCompletionCode )); - if (ResponseDataSize !=3D NULL) { - if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInBy= te) { - *ResponseDataSize =3D TransferToken.ReceivePackage.ReceiveSizeInBy= te; - } - } - - if (ResponseData !=3D NULL) { - CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *Resp= onseDataSize); - } - + HelperManageabilityDebugPrint ((VOID *)FullPacketResponseData, GET_PLD= M_MESSAGE_PAYLOAD_SIZE(TransferToken.ReceivePackage.ReceiveSizeInByte), "Fa= iled response payload\n"); goto ErrorExit; } =20 @@ -406,10 +340,10 @@ CommonPldmSubmitCommand ( =20 // Copy response data (without header) to caller's buffer. if ((ResponseData !=3D NULL) && (*ResponseDataSize !=3D 0)) { - *ResponseDataSize =3D FullPacketResponseDataSize - sizeof (PLDM_RESPON= SE_HEADER); + *ResponseDataSize =3D GET_PLDM_MESSAGE_PAYLOAD_SIZE(TransferToken.Rece= ivePackage.ReceiveSizeInByte); CopyMem ( (VOID *)ResponseData, - (VOID *)(FullPacketResponseData + sizeof (PLDM_RESPONSE_HEADER)), + GET_PLDM_MESSAGE_PAYLOAD_PTR(FullPacketResponseData), *ResponseDataSize ); } diff --git a/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmPr= otocolCommon.h b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/Pl= dmProtocolCommon.h index 79431dd3b1..eb273c4f46 100644 --- a/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolC= ommon.h +++ b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolC= ommon.h @@ -12,6 +12,9 @@ #include #include =20 +#define GET_PLDM_MESSAGE_PAYLOAD_SIZE(PayloadSize) (PayloadSize - sizeof (= PLDM_RESPONSE_HEADER)) +#define GET_PLDM_MESSAGE_PAYLOAD_PTR(PayloadPtr) ((UINT8 *)PayloadPtr + si= zeof (PLDM_RESPONSE_HEADER)) + typedef struct { UINT8 PldmType; UINT8 PldmCommand; diff --git a/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProto= col.c b/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c index 726747416c..058f98e677 100644 --- a/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c +++ b/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c @@ -60,8 +60,17 @@ PldmSubmitCommand ( { EFI_STATUS Status; =20 - if ((RequestData =3D=3D NULL) && (ResponseData =3D=3D NULL)) { - DEBUG ((DEBUG_ERROR, "%a: Both RequestData and ResponseData are NULL\n= ", __func__)); + // + // Check the given input parameters. + // + if (RequestData =3D=3D NULL && RequestDataSize !=3D 0) { + DEBUG (( + DEBUG_ERROR, + "%a: RequestDataSize !=3D 0, however RequestData is NULL for PLDM ty= pe: 0x%x, Command: 0x%x.\n", + __func__, + PldmType, + Command + )); return EFI_INVALID_PARAMETER; } =20 --=20 2.34.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 (#109921): https://edk2.groups.io/g/devel/message/109921 Mute This Topic: https://groups.io/mt/102134663/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-