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 9A76FD8108C for ; Fri, 20 Oct 2023 12:53:26 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=z3datV6iOOhduLuHzl7wwgCAGtISe2GlbfgEoHroddU=; 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=1697806405; v=1; b=FzlAvJXVQa6W8HfLY5fMPdJXW2gbeJPm3Bvo2IMCVYS9gEB4dhR80t6YZ7lEvCNIZAFDrKTx iogWXY+HYvMMAShibGyLG9hT+GMe0G31ykmIDvjMrL1MIVOd/Mnr22AsIbjBzizeD76aiGrIg/v HCR4BrHyxnSDG0S11qzVOucY= X-Received: by 127.0.0.2 with SMTP id 8FSKYY7687511xxbpwzP1qee; Fri, 20 Oct 2023 05:53:25 -0700 X-Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by mx.groups.io with SMTP id smtpd.web11.53593.1697806404478408462 for ; Fri, 20 Oct 2023 05:53:24 -0700 X-Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2c50cf61f6dso12233291fa.2 for ; Fri, 20 Oct 2023 05:53:24 -0700 (PDT) X-Gm-Message-State: roWNlrW79tbb6ucjPZYSII9Sx7686176AA= X-Google-Smtp-Source: AGHT+IE38f9MLr9GpW86GHKPiYEAY3qlrrHSUBGpQ1d0Q0K5k4roieVw0UDUV3/Km4Mt9JloCw1yFA== X-Received: by 2002:a2e:9d02:0:b0:2c5:2133:a9fc with SMTP id t2-20020a2e9d02000000b002c52133a9fcmr1277450lji.40.1697806402343; Fri, 20 Oct 2023 05:53:22 -0700 (PDT) X-Received: from PC10319.67 ([82.97.198.254]) by smtp.googlemail.com with ESMTPSA id x22-20020a05651c105600b002b9e5fe86dasm350853ljm.81.2023.10.20.05.53.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 05:53:21 -0700 (PDT) From: "Konstantin Aladyshev" To: devel@edk2.groups.io Cc: abner.chang@amd.com, isaac.w.oram@intel.com, AbdulLateef.Attar@amd.com, nicklew@nvidia.com, Konstantin Aladyshev Subject: [edk2-devel] [PATCH edk2-platforms v2 13/15] ManageabilityPkg/PldmProtocol: Remove PLDM command table Date: Fri, 20 Oct 2023 15:53:00 +0300 Message-Id: <20231020125302.1459-14-aladyshev22@gmail.com> In-Reply-To: <20231020125302.1459-1-aladyshev22@gmail.com> References: <20231020125302.1459-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=FzlAvJXV; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none) 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 (#109863): https://edk2.groups.io/g/devel/message/109863 Mute This Topic: https://groups.io/mt/102080243/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-