From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 9FDDC7803E4 for ; Mon, 23 Oct 2023 13:05:31 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=XdBVkvuQT4CVDXOeo20R6l4A6aWgMNRUlj7ajbqWClw=; 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=1698066330; v=1; b=vakFuIV4TqJgaxWMu5ad1IzC4/Bj9JCT/ECSFKArcI6xqxuwNQdLw2kW3Ipe/bXhoQPcxeTa tHJajHt083WofYoHXHlWGaUZ7eV1DsRIYJ/NnGp5nDPO4unCwHHbNmm5R1k52hRUCGoP7gtNn0s cCbbtD7LwSV5xeDcwEya7U2I= X-Received: by 127.0.0.2 with SMTP id vdogYY7687511xXhchl9gYox; Mon, 23 Oct 2023 06:05:30 -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: CWgje2AI4I08Fb05Fo9jEHZqx7686176AA= 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-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=vakFuIV4; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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;=0D extern UINT8 mPldmRequestInstanceId;=0D =0D -PLDM_MESSAGE_PACKET_MAPPING PldmMessagePacketMappingTable[] =3D {=0D - { PLDM_TYPE_SMBIOS, PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA_COMMAND_COD= E, sizeof (PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA_RESPONSE_FORMAT) },=0D - { PLDM_TYPE_SMBIOS, PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA_COMMAND_COD= E, sizeof (PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA_RESPONSE_FORMAT) },=0D - { PLDM_TYPE_SMBIOS, PLDM_SET_SMBIOS_STRUCTURE_TABLE_COMMAND_CODE, = sizeof (PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST_FORMAT) }=0D -};=0D -=0D -/**=0D - This function returns the expected full size of PLDM response message.=0D -=0D - @param[in] PldmType PLDM message type.=0D - @param[in] PldmCommand PLDM command of this PLDM type.=0D -=0D - @retval Zero No matched entry for this PldmType/PldmCommand.=0D - @retval None-zero Size of full packet is returned.=0D -**/=0D -UINT32=0D -GetFullPacketResponseSize (=0D - IN UINT8 PldmType,=0D - IN UINT8 PldmCommand=0D - )=0D -{=0D - INT16 Index;=0D - PLDM_MESSAGE_PACKET_MAPPING *ThisEntry;=0D -=0D - ThisEntry =3D PldmMessagePacketMappingTable;=0D - for (Index =3D 0; Index < (sizeof (PldmMessagePacketMappingTable)/ sizeo= f (PLDM_MESSAGE_PACKET_MAPPING)); Index++) {=0D - if ((PldmType =3D=3D ThisEntry->PldmType) && (PldmCommand =3D=3D ThisE= ntry->PldmCommand)) {=0D - return ThisEntry->ResponseSize;=0D - }=0D -=0D - ThisEntry++;=0D - }=0D -=0D - return 0;=0D -}=0D -=0D /**=0D This functions setup the final header/body/trailer packets for=0D the acquired transport interface.=0D @@ -267,10 +231,10 @@ CommonPldmSubmitCommand ( TransferToken.TransmitPackage.TransmitTimeoutInMillisecond =3D MANAGEABI= LITY_TRANSPORT_NO_TIMEOUT;=0D =0D // Set receive packet.=0D - FullPacketResponseDataSize =3D GetFullPacketResponseSize (PldmType, Pldm= Command);=0D - if (FullPacketResponseDataSize =3D=3D 0) {=0D - DEBUG ((DEBUG_ERROR, " No mapping entry in PldmMessagePacketMappingTa= ble for PLDM Type:%d Command %d\n", PldmType, PldmCommand));=0D - ASSERT (FALSE);=0D + if (ResponseData =3D=3D NULL && *ResponseDataSize =3D=3D 0) {=0D + FullPacketResponseDataSize =3D sizeof (PLDM_RESPONSE_HEADER);=0D + } else {=0D + FullPacketResponseDataSize =3D *ResponseDataSize + sizeof (PLDM_RESPON= SE_HEADER);=0D }=0D =0D FullPacketResponseData =3D (UINT8 *)AllocateZeroPool (FullPacketResponse= DataSize);=0D @@ -306,6 +270,7 @@ CommonPldmSubmitCommand ( );=0D //=0D // Check the response size.=0D + //=0D if (TransferToken.ReceivePackage.ReceiveSizeInByte < sizeof (PLDM_RESPON= SE_HEADER)) {=0D DEBUG ((=0D DEBUG_MANAGEABILITY_INFO,=0D @@ -315,21 +280,13 @@ CommonPldmSubmitCommand ( TransferToken.ReceivePackage.ReceiveSizeInByte,=0D FullPacketResponseDataSize=0D ));=0D - if (ResponseDataSize !=3D NULL) {=0D - if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInBy= te) {=0D - *ResponseDataSize =3D TransferToken.ReceivePackage.ReceiveSizeInBy= te;=0D - }=0D - }=0D -=0D - if (ResponseData !=3D NULL) {=0D - CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *Resp= onseDataSize);=0D - }=0D -=0D + HelperManageabilityDebugPrint ((VOID *)FullPacketResponseData, Transfe= rToken.ReceivePackage.ReceiveSizeInByte, "Failed response payload\n");=0D goto ErrorExit;=0D }=0D =0D //=0D // Check the integrity of response. data.=0D + //=0D ResponseHeader =3D (PLDM_RESPONSE_HEADER *)FullPacketResponseData;=0D if ((ResponseHeader->PldmHeader.DatagramBit !=3D (!PLDM_MESSAGE_HEADER_I= S_DATAGRAM)) ||=0D (ResponseHeader->PldmHeader.RequestBit !=3D PLDM_MESSAGE_HEADER_IS_R= ESPONSE) ||=0D @@ -343,22 +300,16 @@ CommonPldmSubmitCommand ( DEBUG ((DEBUG_ERROR, " Instance ID =3D %d (Expected value: %d)\n",= ResponseHeader->PldmHeader.InstanceId, mPldmRequestInstanceId));=0D DEBUG ((DEBUG_ERROR, " Pldm Type =3D %d (Expected value: %d)\n",= ResponseHeader->PldmHeader.PldmType, PldmType));=0D DEBUG ((DEBUG_ERROR, " Pldm Command =3D %d (Expected value: %d)\n",= ResponseHeader->PldmHeader.PldmTypeCommandCode, PldmCommand));=0D - if (ResponseDataSize !=3D NULL) {=0D - if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInBy= te) {=0D - *ResponseDataSize =3D TransferToken.ReceivePackage.ReceiveSizeInBy= te;=0D - }=0D - }=0D -=0D - if (ResponseData !=3D NULL) {=0D - CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *Resp= onseDataSize);=0D - }=0D + DEBUG ((DEBUG_ERROR, " Pldm Completion Code =3D 0x%x\n", ResponseHe= ader->PldmCompletionCode));=0D =0D + HelperManageabilityDebugPrint ((VOID *)FullPacketResponseData, Transfe= rToken.ReceivePackage.ReceiveSizeInByte, "Failed response payload\n");=0D goto ErrorExit;=0D }=0D =0D //=0D // Check the response size=0D - if (TransferToken.ReceivePackage.ReceiveSizeInByte !=3D FullPacketRespon= seDataSize) {=0D + //=0D + if (TransferToken.ReceivePackage.ReceiveSizeInByte > FullPacketResponseD= ataSize) {=0D DEBUG ((=0D DEBUG_ERROR,=0D "The response size is incorrect: Response size %d (Expected %d), Com= pletion code %d.\n",=0D @@ -366,38 +317,21 @@ CommonPldmSubmitCommand ( FullPacketResponseDataSize,=0D ResponseHeader->PldmCompletionCode=0D ));=0D - if (ResponseDataSize !=3D NULL) {=0D - if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInBy= te) {=0D - *ResponseDataSize =3D TransferToken.ReceivePackage.ReceiveSizeInBy= te;=0D - }=0D - }=0D -=0D - if (ResponseData !=3D NULL) {=0D - CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *Resp= onseDataSize);=0D - }=0D =0D + HelperManageabilityDebugPrint ((VOID *)FullPacketResponseData, Transfe= rToken.ReceivePackage.ReceiveSizeInByte, "Failed response payload\n");=0D goto ErrorExit;=0D }=0D =0D - if (*ResponseDataSize !=3D (TransferToken.ReceivePackage.ReceiveSizeInBy= te - sizeof (PLDM_RESPONSE_HEADER))) {=0D + if (*ResponseDataSize < GET_PLDM_MESSAGE_PAYLOAD_SIZE(TransferToken.Rece= ivePackage.ReceiveSizeInByte)) {=0D DEBUG ((DEBUG_ERROR, " The size of response is not matched to Request= DataSize assigned by caller.\n"));=0D DEBUG ((=0D DEBUG_ERROR,=0D "Caller expects %d, the response size minus PLDM_RESPONSE_HEADER siz= e is %d, Completion Code %d.\n",=0D *ResponseDataSize,=0D - TransferToken.ReceivePackage.ReceiveSizeInByte - sizeof (PLDM_RESPON= SE_HEADER),=0D + GET_PLDM_MESSAGE_PAYLOAD_SIZE(TransferToken.ReceivePackage.ReceiveSi= zeInByte),=0D ResponseHeader->PldmCompletionCode=0D ));=0D - if (ResponseDataSize !=3D NULL) {=0D - if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInBy= te) {=0D - *ResponseDataSize =3D TransferToken.ReceivePackage.ReceiveSizeInBy= te;=0D - }=0D - }=0D -=0D - if (ResponseData !=3D NULL) {=0D - CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *Resp= onseDataSize);=0D - }=0D -=0D + HelperManageabilityDebugPrint ((VOID *)FullPacketResponseData, GET_PLD= M_MESSAGE_PAYLOAD_SIZE(TransferToken.ReceivePackage.ReceiveSizeInByte), "Fa= iled response payload\n");=0D goto ErrorExit;=0D }=0D =0D @@ -406,10 +340,10 @@ CommonPldmSubmitCommand ( =0D // Copy response data (without header) to caller's buffer.=0D if ((ResponseData !=3D NULL) && (*ResponseDataSize !=3D 0)) {=0D - *ResponseDataSize =3D FullPacketResponseDataSize - sizeof (PLDM_RESPON= SE_HEADER);=0D + *ResponseDataSize =3D GET_PLDM_MESSAGE_PAYLOAD_SIZE(TransferToken.Rece= ivePackage.ReceiveSizeInByte);=0D CopyMem (=0D (VOID *)ResponseData,=0D - (VOID *)(FullPacketResponseData + sizeof (PLDM_RESPONSE_HEADER)),=0D + GET_PLDM_MESSAGE_PAYLOAD_PTR(FullPacketResponseData),=0D *ResponseDataSize=0D );=0D }=0D 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 =0D #include =0D =0D +#define GET_PLDM_MESSAGE_PAYLOAD_SIZE(PayloadSize) (PayloadSize - sizeof (= PLDM_RESPONSE_HEADER))=0D +#define GET_PLDM_MESSAGE_PAYLOAD_PTR(PayloadPtr) ((UINT8 *)PayloadPtr + si= zeof (PLDM_RESPONSE_HEADER))=0D +=0D typedef struct {=0D UINT8 PldmType;=0D UINT8 PldmCommand;=0D 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 ( {=0D EFI_STATUS Status;=0D =0D - if ((RequestData =3D=3D NULL) && (ResponseData =3D=3D NULL)) {=0D - DEBUG ((DEBUG_ERROR, "%a: Both RequestData and ResponseData are NULL\n= ", __func__));=0D + //=0D + // Check the given input parameters.=0D + //=0D + if (RequestData =3D=3D NULL && RequestDataSize !=3D 0) {=0D + DEBUG ((=0D + DEBUG_ERROR,=0D + "%a: RequestDataSize !=3D 0, however RequestData is NULL for PLDM ty= pe: 0x%x, Command: 0x%x.\n",=0D + __func__,=0D + PldmType,=0D + Command=0D + ));=0D return EFI_INVALID_PARAMETER;=0D }=0D =0D --=20 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-