From nobody Sat Feb 7 06:20:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+47215+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568386271; cv=none; d=zoho.com; s=zohoarc; b=FHT1a2ipN6WehphitvjvpWB8OjXpFO2MXzcLKQ5L4SeHwyxSG1LKvN+6+97fCvCYW0ah/prXxm4NnCoT0cUz7tiA3YYEjjkV6kiiUGWIQJwTMizLkrt9QcDq7hukJ9myhpfw+Qlhpbjr43COoBwLnv0b1dAVwYujjlQ9rekqwbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568386271; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=dg0FrqZ+6rH220yz6+m7eTC004gGpo+cWw4VcBJ9Tt8=; b=BC/ElLLDXJbRt+M0cxAHs8+/FtDMftisjUpewmTT8GE+/BTTPfTkhl87HoNpi6/hoDrLlrALuN8lW3DBtd2+vnEhiTGvAdD6bBXdh3Y+M/QXDW2aqm6WjNGcA5WSNz0ke59EBWjlWsZqQAuxoq9VBL0aGuLW9r+ihRMKVc1tE3s= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+47215+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568386271664941.142170478157; Fri, 13 Sep 2019 07:51:11 -0700 (PDT) Return-Path: X-Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com []) by groups.io with SMTP; Fri, 13 Sep 2019 07:51:09 -0700 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+47215+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: lYc55WjN7DLFF/94kPZhz/5fiRMImHBHN9+v6Yr2BSEsGGkaV0QxtOu/syDD4oBCrr8YaS5gMD TdBOTowDeAFuDbK5Sp4NROknBTxyrQrajgwZsxYmnEdjXSRYQFhOTfsLt6HfJ/j5nFcMWXQPPA 7IxbwL6n4ifCH7D/F8IZWHvvZd64d91ZUbBVXJMAVEjg9gynWSxHBSNKi2TQ6JYhwEQ8xH79g2 OC6euPSkxNZxleGuTbhaEr+PPAmJwNeHyOKaPneZUDfdZH/4EypDz8Iy/vahUMBrcQFYFKSXcR dJM= X-SBRS: 2.7 X-MesageID: 5595149 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,501,1559534400"; d="scan'208";a="5595149" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 05/11] OvmfPkg/XenBusDxe: Construct paths without allocation Date: Fri, 13 Sep 2019 15:50:54 +0100 Message-ID: <20190913145100.303433-6-anthony.perard@citrix.com> In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,anthony.perard@citrix.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1568386270; bh=dg0FrqZ+6rH220yz6+m7eTC004gGpo+cWw4VcBJ9Tt8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ayUTON4KBxXIrEjlw4gfP/7KHRweMDuNuEWP11fVbT4+N1HVbRJHdY794oEC7GbVT+b G3miSymJR/udVyVxoXatPmqARUeAXWDzqZvpRXo1hOKOJJX/ss+lLUaO+CI4lYB5P0m7c I4FlT7OEAnJJYhOiG6s0nQlsj17i5IZFfRY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" When doing an action with a path and subpath in the xenstore, XenStoreJoin is called to generate "$path/$subpath". But this function do an allocation of memory which isn't necessary. Instead we will construct the path with WRITE_REQUEST and data used to generate the path will be copied directly to the xenstore shared ring. Also change WRITE_REQUEST.Len type, it only contain sizes and doesn't need to be exactly 32bits. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2190 Signed-off-by: Anthony PERARD Reviewed-by: Laszlo Ersek --- OvmfPkg/XenBusDxe/XenStore.c | 78 +++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index 7b71dc156d..ca7be12d68 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -53,7 +53,7 @@ =20 typedef struct { CONST VOID *Data; - UINT32 Len; + UINTN Len; } WRITE_REQUEST; =20 /* Register callback to watch subtree (node) in the XenStore. */ @@ -260,6 +260,35 @@ XenStoreFindWatch ( return NULL; } =20 +/** + Fill the first three slots of a WRITE_REQUEST array. + + When those three slots are concatenated to generate a string, the result= ing + string will be "$Path\0" or "$Path/$SubPath\0" if SubPath is provided. +**/ +STATIC +VOID +XenStorePrepareWriteRequest ( + IN OUT WRITE_REQUEST *WriteRequest, + IN CONST CHAR8 *Path, + IN CONST CHAR8 *SubPath OPTIONAL + ) +{ + SetMem(WriteRequest, 3 * sizeof (WRITE_REQUEST), 0); + WriteRequest[0].Data =3D Path; + WriteRequest[0].Len =3D AsciiStrSize (Path); + if (SubPath !=3D NULL && SubPath[0] !=3D '\0') { + // + // Remove the \0 from the first part of the request. + // + WriteRequest[0].Len--; + WriteRequest[1].Data =3D "/"; + WriteRequest[1].Len =3D 1; + WriteRequest[2].Data =3D SubPath; + WriteRequest[2].Len =3D AsciiStrSize (SubPath); + } +} + // // Public Utility Functions // API comments for these methods can be found in XenStore.h @@ -842,6 +871,7 @@ XenStoreTalkv ( @param Transaction The transaction to use for this request. @param RequestType The type of message to send. @param Body The body of the request. + @param SubPath If !NULL and not "", "/$SubPath" is append to Body. @param LenPtr The returned length of the reply. @param Result The returned body of the reply. =20 @@ -854,16 +884,16 @@ XenStoreSingle ( IN CONST XENSTORE_TRANSACTION *Transaction, IN enum xsd_sockmsg_type RequestType, IN CONST CHAR8 *Body, + IN CONST CHAR8 *SubPath OPTIONAL, OUT UINT32 *LenPtr OPTIONAL, OUT VOID **Result OPTIONAL ) { - WRITE_REQUEST WriteRequest; + WRITE_REQUEST WriteRequest[3]; =20 - WriteRequest.Data =3D (VOID *) Body; - WriteRequest.Len =3D (UINT32)AsciiStrSize (Body); + XenStorePrepareWriteRequest (WriteRequest, Body, SubPath); =20 - return XenStoreTalkv (Transaction, RequestType, &WriteRequest, 1, + return XenStoreTalkv (Transaction, RequestType, WriteRequest, 3, LenPtr, Result); } =20 @@ -1113,15 +1143,12 @@ XenStoreListDirectory ( OUT CONST CHAR8 ***DirectoryListPtr ) { - CHAR8 *Path; CHAR8 *TempStr; UINT32 Len =3D 0; XENSTORE_STATUS Status; =20 - Path =3D XenStoreJoin (DirectoryPath, Node); - Status =3D XenStoreSingle (Transaction, XS_DIRECTORY, Path, &Len, + Status =3D XenStoreSingle (Transaction, XS_DIRECTORY, DirectoryPath, Nod= e, &Len, (VOID **) &TempStr); - FreePool (Path); if (Status !=3D XENSTORE_STATUS_SUCCESS) { return Status; } @@ -1160,13 +1187,11 @@ XenStoreRead ( OUT VOID **Result ) { - CHAR8 *Path; VOID *Value; XENSTORE_STATUS Status; =20 - Path =3D XenStoreJoin (DirectoryPath, Node); - Status =3D XenStoreSingle (Transaction, XS_READ, Path, LenPtr, &Value); - FreePool (Path); + Status =3D XenStoreSingle (Transaction, XS_READ, DirectoryPath, Node, + LenPtr, &Value); if (Status !=3D XENSTORE_STATUS_SUCCESS) { return Status; } @@ -1183,21 +1208,13 @@ XenStoreWrite ( IN CONST CHAR8 *Str ) { - CHAR8 *Path; - WRITE_REQUEST WriteRequest[2]; - XENSTORE_STATUS Status; + WRITE_REQUEST WriteRequest[4]; =20 - Path =3D XenStoreJoin (DirectoryPath, Node); + XenStorePrepareWriteRequest (WriteRequest, DirectoryPath, Node); + WriteRequest[3].Data =3D Str; + WriteRequest[3].Len =3D AsciiStrLen (Str); =20 - WriteRequest[0].Data =3D (VOID *) Path; - WriteRequest[0].Len =3D (UINT32)AsciiStrSize (Path); - WriteRequest[1].Data =3D (VOID *) Str; - WriteRequest[1].Len =3D (UINT32)AsciiStrLen (Str); - - Status =3D XenStoreTalkv (Transaction, XS_WRITE, WriteRequest, 2, NULL, = NULL); - FreePool (Path); - - return Status; + return XenStoreTalkv (Transaction, XS_WRITE, WriteRequest, 4, NULL, NULL= ); } =20 XENSTORE_STATUS @@ -1207,12 +1224,9 @@ XenStoreRemove ( IN CONST CHAR8 *Node ) { - CHAR8 *Path; XENSTORE_STATUS Status; =20 - Path =3D XenStoreJoin (DirectoryPath, Node); - Status =3D XenStoreSingle (Transaction, XS_RM, Path, NULL, NULL); - FreePool (Path); + Status =3D XenStoreSingle (Transaction, XS_RM, DirectoryPath, Node, NULL= , NULL); =20 return Status; } @@ -1226,7 +1240,7 @@ XenStoreTransactionStart ( XENSTORE_STATUS Status; =20 Status =3D XenStoreSingle (XST_NIL, XS_TRANSACTION_START, "", NULL, - (VOID **) &IdStr); + NULL, (VOID **) &IdStr); if (Status =3D=3D XENSTORE_STATUS_SUCCESS) { Transaction->Id =3D (UINT32)AsciiStrDecimalToUintn (IdStr); FreePool (IdStr); @@ -1246,7 +1260,7 @@ XenStoreTransactionEnd ( AbortStr[0] =3D Abort ? 'F' : 'T'; AbortStr[1] =3D '\0'; =20 - return XenStoreSingle (Transaction, XS_TRANSACTION_END, AbortStr, NULL, = NULL); + return XenStoreSingle (Transaction, XS_TRANSACTION_END, AbortStr, NULL, = NULL, NULL); } =20 XENSTORE_STATUS --=20 Anthony PERARD -=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 (#47215): https://edk2.groups.io/g/devel/message/47215 Mute This Topic: https://groups.io/mt/34128016/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-