From patchwork Fri Sep 13 14:50:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144871 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCD8A14E5 for ; Fri, 13 Sep 2019 14:53:29 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A9AAD20830 for ; Fri, 13 Sep 2019 14:53:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="ZfPBukPD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9AAD20830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mvG-0005fa-0d; Fri, 13 Sep 2019 14:51:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mvE-0005eq-Em for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 14:51:40 +0000 X-Inumbo-ID: eb493062-d635-11e9-978d-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id eb493062-d635-11e9-978d-bc764e2007e4; Fri, 13 Sep 2019 14:51:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568386268; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jTKvjUp5MG+SlTcncG/XYtjxy0nl66C15Z37YLYDQ0Q=; b=ZfPBukPDr9GKJ6LqeFQtte3N1p3xbXh5Ibimvawxr73gdydKkcG7a709 eMI/AZ+xSQnhw6bSkgmmqrYw99Yjmbsz6Y6fq18/dcv0ajuIunGtOycaf zDz80FzGDA8aH1G3JJOYUCPSYIYv12pWxVMBHsHyY8xiNS63rneZXgpB6 Q=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com 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: Date: Fri, 13 Sep 2019 15:50:54 +0100 Message-ID: <20190913145100.303433-6-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 05/11] OvmfPkg/XenBusDxe: Construct paths without allocation X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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=2190 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 @@ typedef struct { CONST VOID *Data; - UINT32 Len; + UINTN Len; } WRITE_REQUEST; /* Register callback to watch subtree (node) in the XenStore. */ @@ -260,6 +260,35 @@ XenStoreFindWatch ( return NULL; } +/** + Fill the first three slots of a WRITE_REQUEST array. + + When those three slots are concatenated to generate a string, the resulting + 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 = Path; + WriteRequest[0].Len = AsciiStrSize (Path); + if (SubPath != NULL && SubPath[0] != '\0') { + // + // Remove the \0 from the first part of the request. + // + WriteRequest[0].Len--; + WriteRequest[1].Data = "/"; + WriteRequest[1].Len = 1; + WriteRequest[2].Data = SubPath; + WriteRequest[2].Len = 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. @@ -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]; - WriteRequest.Data = (VOID *) Body; - WriteRequest.Len = (UINT32)AsciiStrSize (Body); + XenStorePrepareWriteRequest (WriteRequest, Body, SubPath); - return XenStoreTalkv (Transaction, RequestType, &WriteRequest, 1, + return XenStoreTalkv (Transaction, RequestType, WriteRequest, 3, LenPtr, Result); } @@ -1113,15 +1143,12 @@ XenStoreListDirectory ( OUT CONST CHAR8 ***DirectoryListPtr ) { - CHAR8 *Path; CHAR8 *TempStr; UINT32 Len = 0; XENSTORE_STATUS Status; - Path = XenStoreJoin (DirectoryPath, Node); - Status = XenStoreSingle (Transaction, XS_DIRECTORY, Path, &Len, + Status = XenStoreSingle (Transaction, XS_DIRECTORY, DirectoryPath, Node, &Len, (VOID **) &TempStr); - FreePool (Path); if (Status != XENSTORE_STATUS_SUCCESS) { return Status; } @@ -1160,13 +1187,11 @@ XenStoreRead ( OUT VOID **Result ) { - CHAR8 *Path; VOID *Value; XENSTORE_STATUS Status; - Path = XenStoreJoin (DirectoryPath, Node); - Status = XenStoreSingle (Transaction, XS_READ, Path, LenPtr, &Value); - FreePool (Path); + Status = XenStoreSingle (Transaction, XS_READ, DirectoryPath, Node, + LenPtr, &Value); if (Status != 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]; - Path = XenStoreJoin (DirectoryPath, Node); + XenStorePrepareWriteRequest (WriteRequest, DirectoryPath, Node); + WriteRequest[3].Data = Str; + WriteRequest[3].Len = AsciiStrLen (Str); - WriteRequest[0].Data = (VOID *) Path; - WriteRequest[0].Len = (UINT32)AsciiStrSize (Path); - WriteRequest[1].Data = (VOID *) Str; - WriteRequest[1].Len = (UINT32)AsciiStrLen (Str); - - Status = XenStoreTalkv (Transaction, XS_WRITE, WriteRequest, 2, NULL, NULL); - FreePool (Path); - - return Status; + return XenStoreTalkv (Transaction, XS_WRITE, WriteRequest, 4, NULL, NULL); } XENSTORE_STATUS @@ -1207,12 +1224,9 @@ XenStoreRemove ( IN CONST CHAR8 *Node ) { - CHAR8 *Path; XENSTORE_STATUS Status; - Path = XenStoreJoin (DirectoryPath, Node); - Status = XenStoreSingle (Transaction, XS_RM, Path, NULL, NULL); - FreePool (Path); + Status = XenStoreSingle (Transaction, XS_RM, DirectoryPath, Node, NULL, NULL); return Status; } @@ -1226,7 +1240,7 @@ XenStoreTransactionStart ( XENSTORE_STATUS Status; Status = XenStoreSingle (XST_NIL, XS_TRANSACTION_START, "", NULL, - (VOID **) &IdStr); + NULL, (VOID **) &IdStr); if (Status == XENSTORE_STATUS_SUCCESS) { Transaction->Id = (UINT32)AsciiStrDecimalToUintn (IdStr); FreePool (IdStr); @@ -1246,7 +1260,7 @@ XenStoreTransactionEnd ( AbortStr[0] = Abort ? 'F' : 'T'; AbortStr[1] = '\0'; - return XenStoreSingle (Transaction, XS_TRANSACTION_END, AbortStr, NULL, NULL); + return XenStoreSingle (Transaction, XS_TRANSACTION_END, AbortStr, NULL, NULL, NULL); } XENSTORE_STATUS