From nobody Thu May 2 18:38:31 2024 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+47209+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568386268; cv=none; d=zoho.com; s=zohoarc; b=X1B/xKmFsnwyN5XuNSsA5xt4JxpDeB4yViTP896vaFL0jYrxuvCg/uJrnN5VAWKOjGqa20Q4U1DdFzxK3YqIeECBVdXGBXOhCu1U/YY5giwkqHlchkdnIebtMixcpH0CJ5b2Hia2OFdw9mK0S8S7w3x6EzmGA0JcRzvcmwR1qN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568386268; 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=MVTEu5P3WnIxm8D9Ekm5yr0p0TBFyF+zhhkfdfFyNW0=; b=fxFopbv/pmRE/nRM22db4zGc1oGWG5s0QIfpfjc+hSxJWwjQA7fIiYuiEkPmQhs95J25MRDlQ/wGsySks21v4arfUXlr1h35TxCsE9natQU26mdQl11CV6EqWzOKbo+CqT4HlvsOFtcp+XpkYMDcEvftrq/bQ4qwNvkGhVyl+A0= 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+47209+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568386268682561.6843788702113; Fri, 13 Sep 2019 07:51:08 -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:07 -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+47209+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: 4Hql/g6wgD0dtdgcSReno+60nynt9cq3NEgkzAMMz78rXu2yIKmZTaQYh9bhI3YX/qZLFZ9N9j hSDZl2dEMQcHhJZMZFlh7skOsLGeXg+Vu0/72xoOy90JpjJdYPQC319Sw8bI9EiOFkgWyHJi+4 CyqHFhx1xVqwO7o9jBNKf7eV5JCoeP8Qfwpo0/e5Wd3CEL034QC1qfTWUDqibwx2q1hYzoCVQJ uB2WUECwlkAVSw9crC7dIInmVuXNoqctsxSeTZeCfxGMNGkGAONcDZNpQme9eFzn3J9g9qPPSW /oU= X-SBRS: 2.7 X-MesageID: 5595139 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="5595139" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 01/11] OvmfPkg/XenBusDxe: Fix missing \n in DEBUG messages Date: Fri, 13 Sep 2019 15:50:50 +0100 Message-ID: <20190913145100.303433-2-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=1568386267; bh=MVTEu5P3WnIxm8D9Ekm5yr0p0TBFyF+zhhkfdfFyNW0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=q0ZcoZYURIDR++HE9upNoWWtIp3da2PWtHQLt/kODTWg9FxDupV9qFWkvCmCAiZa1FG e2LrojGpe0ihdGVBZogGfwODVzqfCChjN1egl4Cor1y9ZFlUBca8jpha3/H0ZxLGWMjyq YeYTM6XiUi6sc/lszLdgtOia1JjEZrviwQs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Fix missing \n in DEBUG messages in XenBusDxe and use DEBUG_*. Signed-off-by: Anthony PERARD Reviewed-by: Laszlo Ersek --- OvmfPkg/XenBusDxe/EventChannel.c | 3 ++- OvmfPkg/XenBusDxe/XenStore.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/XenBusDxe/EventChannel.c b/OvmfPkg/XenBusDxe/EventChan= nel.c index 6900071782..c6b3871781 100644 --- a/OvmfPkg/XenBusDxe/EventChannel.c +++ b/OvmfPkg/XenBusDxe/EventChannel.c @@ -44,7 +44,8 @@ XenBusEventChannelAllocate ( EVTCHNOP_alloc_unbound, &Parameter); if (ReturnCode !=3D 0) { - DEBUG ((EFI_D_ERROR, "ERROR: alloc_unbound failed with rc=3D%d", Retur= nCode)); + DEBUG ((DEBUG_ERROR, "ERROR: alloc_unbound failed with rc=3D%d\n", + ReturnCode)); return ReturnCode; } *Port =3D Parameter.port; diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index 34890ae40b..7253d8ae37 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -738,7 +738,7 @@ XenStoreReadReply ( XENSTORE_STATUS Status; Status =3D XenStoreProcessMessage (); if (Status !=3D XENSTORE_STATUS_SUCCESS && Status !=3D XENSTORE_STATUS= _EAGAIN) { - DEBUG ((EFI_D_ERROR, "XenStore, error while reading the ring (%d).", + DEBUG ((DEBUG_ERROR, "XenStore, error while reading the ring (%d).\n= ", Status)); return Status; } @@ -1076,7 +1076,7 @@ XenStoreDeinit ( if (!IsListEmpty (&xs.RegisteredWatches)) { XENSTORE_WATCH *Watch; LIST_ENTRY *Entry; - DEBUG ((EFI_D_WARN, "XenStore: RegisteredWatches is not empty, cleanin= g up...")); + DEBUG ((DEBUG_WARN, "XenStore: RegisteredWatches is not empty, cleanin= g up...\n")); Entry =3D GetFirstNode (&xs.RegisteredWatches); while (!IsNull (&xs.RegisteredWatches, Entry)) { Watch =3D XENSTORE_WATCH_FROM_LINK (Entry); @@ -1092,7 +1092,7 @@ XenStoreDeinit ( // if (!IsListEmpty (&xs.WatchEvents)) { LIST_ENTRY *Entry; - DEBUG ((EFI_D_WARN, "XenStore: WatchEvents is not empty, cleaning up..= .")); + DEBUG ((DEBUG_WARN, "XenStore: WatchEvents is not empty, cleaning up..= .\n")); Entry =3D GetFirstNode (&xs.WatchEvents); while (!IsNull (&xs.WatchEvents, Entry)) { XENSTORE_MESSAGE *Message =3D XENSTORE_MESSAGE_FROM_LINK (Entry); --=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 (#47209): https://edk2.groups.io/g/devel/message/47209 Mute This Topic: https://groups.io/mt/34128010/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- From nobody Thu May 2 18:38:31 2024 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+47211+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568386269; cv=none; d=zoho.com; s=zohoarc; b=Y3XTsXPFPEL5dSPd2boL5Kw4aztGCNqJN2ie3WkO6g12wuaIQX0C5SetFDclzxQKhkAGTX1HRkuHgSL+vwuEw0FtFd7TDPyyIUsI8aLX23SCjH3kD5MDsvQez0bNR1d4+QkScVRwW7l83s6VQoOabrrM+NCZ7Fzq2+MWYSH4Eug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568386269; 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=EaBxBEOmBN572uz4IEOjGT9MsmqGL/zUBeBNlEfV5yc=; b=HO/K7T54Q0tHvN7mKp53+QO+LhmOayFzFM7UMLl8d21RZCWMQG2Fi0vX6cqi1LhRMSq7RXmQMCePBLr4i7y1OrE1F9Hq3cQepttg8R2k7StoPmgGlA3W8nGjhaWeGwGeoYb9rRKqw+z6vhDq0k8hby30p/kitgyEOIVS6IYibI4= 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+47211+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568386269926939.5424940682858; Fri, 13 Sep 2019 07:51:09 -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:08 -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+47211+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: fvXAh7vfsFBYYx1H2SUTubk8+N9uU775f/lCrfgTcHdbuAv7+PqStRzuACH/445eASrBRcD9+u fV5fsmNVu812Mt+KoTolZCm+6MdE14faMFCRTY+Ffrsz356q2Fs6fmJuPRnR6htTemMfoYhrJe DIMYhg9c97TxBKuLAoCn0bIx89Dc73hG5EaleRX+1PuVg4K7N7m5T78BuyIjBnFbRRGCO/appB XIqMoWxJZQGYE0gREuK7I0hMk/nUAo1575xNGeFSilN0Z9bGnQXU0X5S+EgPX8y8N6Pg93ymG3 EL4= X-SBRS: 2.7 X-MesageID: 5595142 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="5595142" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 02/11] OvmfPkg/XenBusDxe: Have XenStoreFindWatch take a pointer Date: Fri, 13 Sep 2019 15:50:51 +0100 Message-ID: <20190913145100.303433-3-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=1568386269; bh=EaBxBEOmBN572uz4IEOjGT9MsmqGL/zUBeBNlEfV5yc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=MGbobJHKxuoLmUfWGTTjFmtapgS/cnwMu5PzLogUZItIOMyqXfVA/5wrt5fnHMm01x9 myi3SzxeoUSAvcYkj7oVyT4HyOgT2zgUay1sEgz0gKuEaxdF8eKgWfC7gW1+ICUxcrl8s LKxYsC5oHi2rS2i0lGSRvYEcP/RNv7uPRIU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Rework XenStoreFindWatch() to be able to search for a registered watch with a pointer instead of a string. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2190 Signed-off-by: Anthony PERARD Reviewed-by: Laszlo Ersek --- OvmfPkg/XenBusDxe/XenStore.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index 7253d8ae37..727641a0fe 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -253,14 +253,12 @@ Split ( STATIC XENSTORE_WATCH * XenStoreFindWatch ( - IN CONST CHAR8 *Token + IN VOID *Token ) { - XENSTORE_WATCH *Watch, *WantedWatch; + XENSTORE_WATCH *Watch; LIST_ENTRY *Entry; =20 - WantedWatch =3D (VOID *) AsciiStrHexToUintn (Token); - if (IsListEmpty (&xs.RegisteredWatches)) { return NULL; } @@ -268,7 +266,7 @@ XenStoreFindWatch ( !IsNull (&xs.RegisteredWatches, Entry); Entry =3D GetNextNode (&xs.RegisteredWatches, Entry)) { Watch =3D XENSTORE_WATCH_FROM_LINK (Entry); - if (Watch =3D=3D WantedWatch) + if ((VOID *) Watch =3D=3D Token) return Watch; } =20 @@ -632,12 +630,16 @@ XenStoreProcessMessage ( Body[Message->Header.len] =3D '\0'; =20 if (Message->Header.type =3D=3D XS_WATCH_EVENT) { + VOID *ConvertedToken; + Message->u.Watch.Vector =3D Split(Body, Message->Header.len, &Message->u.Watch.VectorSize); =20 + ConvertedToken =3D + (VOID *) AsciiStrHexToUintn (Message->u.Watch.Vector[XS_WATCH_TOKEN]= ); + EfiAcquireLock (&xs.RegisteredWatchesLock); - Message->u.Watch.Handle =3D - XenStoreFindWatch (Message->u.Watch.Vector[XS_WATCH_TOKEN]); + Message->u.Watch.Handle =3D XenStoreFindWatch (ConvertedToken); DEBUG ((EFI_D_INFO, "XenStore: Watch event %a\n", Message->u.Watch.Vector[XS_WATCH_TOKEN])); if (Message->u.Watch.Handle !=3D NULL) { @@ -1384,8 +1386,7 @@ XenStoreUnregisterWatch ( =20 ASSERT (Watch->Signature =3D=3D XENSTORE_WATCH_SIGNATURE); =20 - AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch); - if (XenStoreFindWatch (Token) =3D=3D NULL) { + if (XenStoreFindWatch (Watch) =3D=3D NULL) { return; } =20 @@ -1393,6 +1394,7 @@ XenStoreUnregisterWatch ( RemoveEntryList (&Watch->Link); EfiReleaseLock (&xs.RegisteredWatchesLock); =20 + AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch); XenStoreUnwatch (Watch->Node, Token); =20 /* Cancel pending watch events. */ --=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 (#47211): https://edk2.groups.io/g/devel/message/47211 Mute This Topic: https://groups.io/mt/34128012/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- From nobody Thu May 2 18:38:31 2024 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+47212+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568386270; cv=none; d=zoho.com; s=zohoarc; b=ON7GLxXiuwFCDWJxKrp8vTQjhpjdUBFSYBp3Ki01VQMskVZnj3N+sdDgpzYSb7ZXGBgi3wIV88L68zDImaxQNxbRVE4qDid+D1YODCqO8mbcXRzag4cEsdGU1XpYuWMun6Bqwxv9W50dGF2HKdxvVETAkZR2Xr48kb0JDZUdZD0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568386270; 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=F/NWw7NTYEkktubu5OdMXgmPDBcS8txgVcnBUBm47YA=; b=D9ikVxfQ7n4D1UWMqZ8pQRWN9jmdg+nOdWfhTTdaxg+fYLFrzxBGsyx8rzxlo62JEjpZrnnHU0j+66fDe8DoeaVojTLfMwhroRLsBigq+VFqPVx1prkrIPOlgY2qZXVqBhsX2XkuwwdDS/0RLmh7uo8fUmdvUKCCYm9NWYMQvzI= 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+47212+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568386270359231.59458256339371; Fri, 13 Sep 2019 07:51:10 -0700 (PDT) Return-Path: X-Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by groups.io with SMTP; Fri, 13 Sep 2019 07:51:08 -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+47212+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: Kkw8joFoPfJcyD06wlGUtDNzcZybS1NWu35zlpTd2l6qS2xWUlwyJC1djiW51SaGCekGGp5C2Z /rG3VU+jfd0wNRA1PTD8hBPuCgWSDaYVA9mkhbWYcCN4PSXpLtKmqgl8b7WWhACnzwdfj6hOuE 9/q2hGRl+0HXEVoOjX7V+K8lLbjJImSLqoz6/Lk+LZleMBZWzj2U934Y1+/SZfKp5LwvAs93f0 MajbpmgOLcm5ZL81/oXiaGro86McIZd4LVz0W/V8XoMl5kr6ySqpz4wiaez75u1cOMYlukCpo2 LGU= X-SBRS: 2.7 X-MesageID: 5595144 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="5595144" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 03/11] OvmfPkg/XenBusDxe: Rework watch events reception Date: Fri, 13 Sep 2019 15:50:52 +0100 Message-ID: <20190913145100.303433-4-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=1568386269; bh=F/NWw7NTYEkktubu5OdMXgmPDBcS8txgVcnBUBm47YA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=UzFAYlcrAjO6P2H0SlRBGyz8lA3Jb/jeomBBaEGmNET58oRvMgg3AJtCe/d4qbio9+u cbajr648yz/xwYZNDMwPEMOGYH3x/RUOmau8Lqq1ldBILBhPaoRTMVj6RpZ06A3NQ7Wv1 ygEx0eYIrKZFlyt12poLKV6mX5qQAELJ2LU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This patch rework the reception of xenstore watch event to avoid allocation. Instead of queuing watch events, we simply mark a XENSTORE_WATCH as "triggered". We don't need to know how many time we received the event, only that it happened. That avoid to allocate a XENSTORE_MESSAGE for every watch events. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2190 Signed-off-by: Anthony PERARD Acked-by: Laszlo Ersek --- OvmfPkg/XenBusDxe/XenStore.c | 125 ++++++++++------------------------- 1 file changed, 35 insertions(+), 90 deletions(-) diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index 727641a0fe..5cc900190a 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -65,6 +65,8 @@ struct _XENSTORE_WATCH =20 /* Path being watched. */ CHAR8 *Node; + + BOOLEAN Triggered; }; =20 #define XENSTORE_WATCH_FROM_LINK(l) \ @@ -86,13 +88,6 @@ typedef struct { struct { CHAR8 *Body; } Reply; - - /* Queued watch events. */ - struct { - XENSTORE_WATCH *Handle; - CONST CHAR8 **Vector; - UINT32 VectorSize; - } Watch; } u; } XENSTORE_MESSAGE; #define XENSTORE_MESSAGE_FROM_LINK(r) \ @@ -133,14 +128,6 @@ typedef struct { /** Lock protecting the registered watches list. */ EFI_LOCK RegisteredWatchesLock; =20 - /** - * List of pending watch callback events. - */ - LIST_ENTRY WatchEvents; - - /** Lock protecting the watch calback list. */ - EFI_LOCK WatchEventsLock; - /** * The event channel for communicating with the * XenStore service. @@ -630,29 +617,32 @@ XenStoreProcessMessage ( Body[Message->Header.len] =3D '\0'; =20 if (Message->Header.type =3D=3D XS_WATCH_EVENT) { - VOID *ConvertedToken; + CONST CHAR8 *WatchEventPath; + CONST CHAR8 *WatchEventToken; + VOID *ConvertedToken; + XENSTORE_WATCH *Watch; =20 - Message->u.Watch.Vector =3D Split(Body, Message->Header.len, - &Message->u.Watch.VectorSize); + // + // Parse WATCH_EVENT messages + // \0\0 + // + WatchEventPath =3D Body; + WatchEventToken =3D WatchEventPath + AsciiStrSize (WatchEventPath); =20 - ConvertedToken =3D - (VOID *) AsciiStrHexToUintn (Message->u.Watch.Vector[XS_WATCH_TOKEN]= ); + ConvertedToken =3D (VOID *) AsciiStrHexToUintn (WatchEventToken); =20 EfiAcquireLock (&xs.RegisteredWatchesLock); - Message->u.Watch.Handle =3D XenStoreFindWatch (ConvertedToken); - DEBUG ((EFI_D_INFO, "XenStore: Watch event %a\n", - Message->u.Watch.Vector[XS_WATCH_TOKEN])); - if (Message->u.Watch.Handle !=3D NULL) { - EfiAcquireLock (&xs.WatchEventsLock); - InsertHeadList (&xs.WatchEvents, &Message->Link); - EfiReleaseLock (&xs.WatchEventsLock); + Watch =3D XenStoreFindWatch (ConvertedToken); + DEBUG ((DEBUG_INFO, "XenStore: Watch event %a\n", WatchEventToken)); + if (Watch !=3D NULL) { + Watch->Triggered =3D TRUE; } else { DEBUG ((EFI_D_WARN, "XenStore: Watch handle %a not found\n", - Message->u.Watch.Vector[XS_WATCH_TOKEN])); - FreePool((VOID*)Message->u.Watch.Vector); - FreePool(Message); + WatchEventToken)); } EfiReleaseLock (&xs.RegisteredWatchesLock); + FreePool (Message); + FreePool (Body); } else { Message->u.Reply.Body =3D Body; EfiAcquireLock (&xs.ReplyLock); @@ -936,40 +926,29 @@ XenStoreUnwatch ( STATIC XENSTORE_STATUS XenStoreWaitWatch ( - VOID *Token + IN VOID *Token ) { - XENSTORE_MESSAGE *Message; - LIST_ENTRY *Entry =3D NULL; - LIST_ENTRY *Last =3D NULL; + XENSTORE_WATCH *Watch; XENSTORE_STATUS Status; =20 + EfiAcquireLock (&xs.RegisteredWatchesLock); + Watch =3D XenStoreFindWatch (Token); + EfiReleaseLock (&xs.RegisteredWatchesLock); + if (Watch =3D=3D NULL) { + return XENSTORE_STATUS_EINVAL; + } + while (TRUE) { - EfiAcquireLock (&xs.WatchEventsLock); - if (IsListEmpty (&xs.WatchEvents) || - Last =3D=3D GetFirstNode (&xs.WatchEvents)) { - EfiReleaseLock (&xs.WatchEventsLock); - Status =3D XenStoreProcessMessage (); - if (Status !=3D XENSTORE_STATUS_SUCCESS && Status !=3D XENSTORE_STAT= US_EAGAIN) { - return Status; - } - continue; + if (Watch->Triggered) { + Watch->Triggered =3D FALSE; + return XENSTORE_STATUS_SUCCESS; } =20 - for (Entry =3D GetFirstNode (&xs.WatchEvents); - Entry !=3D Last && !IsNull (&xs.WatchEvents, Entry); - Entry =3D GetNextNode (&xs.WatchEvents, Entry)) { - Message =3D XENSTORE_MESSAGE_FROM_LINK (Entry); - if (Message->u.Watch.Handle =3D=3D Token) { - RemoveEntryList (Entry); - EfiReleaseLock (&xs.WatchEventsLock); - FreePool((VOID*)Message->u.Watch.Vector); - FreePool(Message); - return XENSTORE_STATUS_SUCCESS; - } + Status =3D XenStoreProcessMessage (); + if (Status !=3D XENSTORE_STATUS_SUCCESS && Status !=3D XENSTORE_STATUS= _EAGAIN) { + return Status; } - Last =3D GetFirstNode (&xs.WatchEvents); - EfiReleaseLock (&xs.WatchEventsLock); } } =20 @@ -1052,12 +1031,10 @@ XenStoreInit ( xs.XenStore, xs.EventChannel)); =20 InitializeListHead (&xs.ReplyList); - InitializeListHead (&xs.WatchEvents); InitializeListHead (&xs.RegisteredWatches); =20 EfiInitializeLock (&xs.ReplyLock, TPL_NOTIFY); EfiInitializeLock (&xs.RegisteredWatchesLock, TPL_NOTIFY); - EfiInitializeLock (&xs.WatchEventsLock, TPL_NOTIFY); =20 /* Initialize the shared memory rings to talk to xenstored */ Status =3D XenStoreInitComms (&xs); @@ -1088,23 +1065,6 @@ XenStoreDeinit ( } } =20 - // - // Emptying the list WatchEvents, but this list should already be empty = after - // having cleanup the list RegisteredWatches. - // - if (!IsListEmpty (&xs.WatchEvents)) { - LIST_ENTRY *Entry; - DEBUG ((DEBUG_WARN, "XenStore: WatchEvents is not empty, cleaning up..= .\n")); - Entry =3D GetFirstNode (&xs.WatchEvents); - while (!IsNull (&xs.WatchEvents, Entry)) { - XENSTORE_MESSAGE *Message =3D XENSTORE_MESSAGE_FROM_LINK (Entry); - Entry =3D GetNextNode (&xs.WatchEvents, Entry); - RemoveEntryList (&Message->Link); - FreePool ((VOID*)Message->u.Watch.Vector); - FreePool (Message); - } - } - if (!IsListEmpty (&xs.ReplyList)) { XENSTORE_MESSAGE *Message; LIST_ENTRY *Entry; @@ -1382,7 +1342,6 @@ XenStoreUnregisterWatch ( ) { CHAR8 Token[sizeof (Watch) * 2 + 1]; - LIST_ENTRY *Entry; =20 ASSERT (Watch->Signature =3D=3D XENSTORE_WATCH_SIGNATURE); =20 @@ -1397,20 +1356,6 @@ XenStoreUnregisterWatch ( AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch); XenStoreUnwatch (Watch->Node, Token); =20 - /* Cancel pending watch events. */ - EfiAcquireLock (&xs.WatchEventsLock); - Entry =3D GetFirstNode (&xs.WatchEvents); - while (!IsNull (&xs.WatchEvents, Entry)) { - XENSTORE_MESSAGE *Message =3D XENSTORE_MESSAGE_FROM_LINK (Entry); - Entry =3D GetNextNode (&xs.WatchEvents, Entry); - if (Message->u.Watch.Handle =3D=3D Watch) { - RemoveEntryList (&Message->Link); - FreePool ((VOID*)Message->u.Watch.Vector); - FreePool (Message); - } - } - EfiReleaseLock (&xs.WatchEventsLock); - FreePool (Watch->Node); FreePool (Watch); } --=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 (#47212): https://edk2.groups.io/g/devel/message/47212 Mute This Topic: https://groups.io/mt/34128013/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- From nobody Thu May 2 18:38:31 2024 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+47210+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568386273; cv=none; d=zoho.com; s=zohoarc; b=e38ekTU7NYDhOHYMkFDJGK0J+7hxPh3UdWUQEI7rXhZqyJMq4e2FKI4ErZ/nCPjZF8CFWD1JV5sD4wa0i/d0TYLllZIMxJ0jXp8RbIKo2eI/H/wrnPz2SE3cGsemK0qMWgJCmLXJoUCmAw+deHQJgwQf+c+Mzwx1XTC1P3mItv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568386273; 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=/DqPuuzwvO/VjOt67ia7N81X6LFOnJU4/iwohIWQKAI=; b=gPoNem5mCGFlzF/lwcaSzLgP/IzK3zDZ3MydKRVSz/PCLlLjkFiLhzG6xLkMPmAMggMvcuPuvjfv0VucoXqqWb9+l2RkXtYZVXnuFW880tldMYFqZitxnILyXtrB0WcP7EWp714D3UjgxDvYjF65xkVJmXQO9xbrS3r27oMtUr0= 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+47210+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568386273676188.93919432305518; Fri, 13 Sep 2019 07:51:13 -0700 (PDT) Return-Path: X-Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by groups.io with SMTP; Fri, 13 Sep 2019 07:51:07 -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+47210+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: gA8UT5Ch/OGw3w+nTY3r6fio4u+BqYgSmlqKBXYupu999GYVV1zWWNJMsTOlVTQEyEErzLtXLU mLzxzSmCiCVgWqDW53Y+5bwfcIU0U1BqnnpheC4Wtt2VxFFnCTWffh7V5aBu5dxIeJFFsPJ27Z yYf4HTPPw1syuAYKXHZgzu8X6tmAR1FOwsdtomnRs0imfr+As4/BQ3io9d7+fBB8zNKurs0nav FTZoL0DNZfnYVjdaXjLfggT7kUxErUZCtbJKqf5lvKvGvzCiKL6wJO7HO+617LRq6MYVETNG+0 3mA= X-SBRS: 2.7 X-MesageID: 5595140 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="5595140" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 04/11] OvmfPkg/XenBusDxe: Avoid Allocate in XenStoreVSPrint Date: Fri, 13 Sep 2019 15:50:53 +0100 Message-ID: <20190913145100.303433-5-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=1568386273; bh=/DqPuuzwvO/VjOt67ia7N81X6LFOnJU4/iwohIWQKAI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=j3nAwvjPmh2spcAfH4e+6SPqxDJ69KnraL0M0obo9xGONSVD8p5eAKaVA52IM9mHSUb KArQf3p1hgQuZeWDnoCeoRwe2amaCi48pwHCt+Flgpkm0aEv7mxERSXqdsCzfuO6ZtGRN S3uRq0JuAnrlfzY7799cbnmZkh+HrD8tU30= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" In order to be able to use XenStoreVSPrint during the ExitBootServices, we remove the allocation done by the function and use the stack instead. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2190 Signed-off-by: Anthony PERARD Reviewed-by: Laszlo Ersek --- OvmfPkg/XenBusDxe/XenStore.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index 5cc900190a..7b71dc156d 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -1259,20 +1259,17 @@ XenStoreVSPrint ( IN VA_LIST Marker ) { - CHAR8 *Buf; - XENSTORE_STATUS Status; - UINTN BufSize; - VA_LIST Marker2; + CHAR8 Buf[XENSTORE_PAYLOAD_MAX]; + UINTN Count; =20 - VA_COPY (Marker2, Marker); - BufSize =3D SPrintLengthAsciiFormat (FormatString, Marker2) + 1; - VA_END (Marker2); - Buf =3D AllocateZeroPool (BufSize); - AsciiVSPrint (Buf, BufSize, FormatString, Marker); - Status =3D XenStoreWrite (Transaction, DirectoryPath, Node, Buf); - FreePool (Buf); + Count =3D AsciiVSPrint (Buf, sizeof (Buf), FormatString, Marker); + ASSERT (Count > 0); + ASSERT (Count < sizeof (Buf)); + if ((Count =3D=3D 0) || (Count >=3D sizeof (Buf))) { + return XENSTORE_STATUS_EINVAL; + } =20 - return Status; + return XenStoreWrite (Transaction, DirectoryPath, Node, Buf); } =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 (#47210): https://edk2.groups.io/g/devel/message/47210 Mute This Topic: https://groups.io/mt/34128011/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- From nobody Thu May 2 18:38:31 2024 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- From nobody Thu May 2 18:38:31 2024 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+47216+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568386270; cv=none; d=zoho.com; s=zohoarc; b=J0eFXrJc3Pe4rk73jc4boe6Qr6NqUkdmiLYqJtsuTeBQN/7funWEPJDhNse6WJlbEsXKZwPPmFJxwG9sQ7IJpXH6isd+3m9rYYqNNqNb/dUI9pBA89hQF2Ep4fEbbvy0Fw6M1jY22gDJ4Owqyq3eSyyC8rswb5E3enA45J2jqj4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568386270; 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=+BAoHXea8lZvNbVJajLun2fwHKwbKtalLfHvTB/X45Y=; b=JufYCv7Y7+XgChOt4wMD17BEHWPyVu5Vfr6N9ZVCPRlPcrJZYWeGorgiUZj+dzLYtUjsmDSlTccFx1bCOvXebJNKQi+fcHNcDzhdmlJ3kun/8zshm3g/eVqmIkiuHQmcbpW2YoVTGTgvV6yc1FsWBxZmF83N5W43r/UnDzZWak8= 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+47216+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568386270811505.5460206815711; Fri, 13 Sep 2019 07:51:10 -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+47216+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: 438aV6qfDMfFLKwz7+b256cgHR6jsDeUAT3aYMe98K54x5Kw+DD+JjwzgHc0JvX/ZDk39Y6COc tuIPX1b4FHKirXWaUEVlBDTuKgbOHruuqK6Cl3NaBYCr2+zodcDGmX9FnAeQQ2nwExGXQfyMot CzFPsAZMaVTYa2pR9Sv7OypMAoRznJ/lGIv3gounik3jQz8Tenu/xmIM+hAfoI4ayUDL+we9Tc in9zbAQitbvc/j2aq7/QvZJg0wYQe3E+mvgn+pPQUY3gFzlqv1/SgSwFpnijMNa4Ct6h9f2lA6 vBk= X-SBRS: 2.7 X-MesageID: 5595146 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="5595146" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 06/11] OvmfPkg/XenBusDxe: Rework XenStoreProcessMessage to avoid allocating memory Date: Fri, 13 Sep 2019 15:50:55 +0100 Message-ID: <20190913145100.303433-7-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=+BAoHXea8lZvNbVJajLun2fwHKwbKtalLfHvTB/X45Y=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=LNy9zAR+NNvpd/SmiOPlSq2knYPumVJ44SBrQ5yzad5PYlitJEF27By/lUg/kF5anF0 IeLC3aZ/siYU3qgO0s+nO1//3hu05Us4fxTqPtRoDFoEo7IKWlx0xTgHyHIc5fRg2Av3q jHWxyEDPGNxpWuxTdblKPl7hEhtDDhHEKmE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This patch rework XenStoreProcessMessage in order to avoid memory allocation when a reply is expected. Instead of allocating a buffer for this reply, we are going to copy to a buffer passed by the caller. For messages that aren't fully received, they will be stored in a buffer that have been allocated at the initialisation of the driver. A temporary memory allocation is made in XenStoreTalkv but that will be removed in a further patch. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2190 Signed-off-by: Anthony PERARD Acked-by: Laszlo Ersek --- OvmfPkg/XenBusDxe/XenStore.c | 297 +++++++++++++++-------------------- 1 file changed, 130 insertions(+), 167 deletions(-) diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index ca7be12d68..004d3b6022 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -72,27 +72,6 @@ struct _XENSTORE_WATCH #define XENSTORE_WATCH_FROM_LINK(l) \ CR (l, XENSTORE_WATCH, Link, XENSTORE_WATCH_SIGNATURE) =20 - -/** - * Structure capturing messages received from the XenStore service. - */ -#define XENSTORE_MESSAGE_SIGNATURE SIGNATURE_32 ('X', 'S', 's', 'm') -typedef struct { - UINT32 Signature; - LIST_ENTRY Link; - - struct xsd_sockmsg Header; - - union { - /* Queued replies. */ - struct { - CHAR8 *Body; - } Reply; - } u; -} XENSTORE_MESSAGE; -#define XENSTORE_MESSAGE_FROM_LINK(r) \ - CR (r, XENSTORE_MESSAGE, Link, XENSTORE_MESSAGE_SIGNATURE) - /** * Container for all XenStore related state. */ @@ -105,21 +84,6 @@ typedef struct { =20 XENBUS_DEVICE *Dev; =20 - /** - * A list of replies to our requests. - * - * The reply list is filled by xs_rcv_thread(). It - * is consumed by the context that issued the request - * to which a reply is made. The requester blocks in - * XenStoreReadReply (). - * - * /note Only one requesting context can be active at a time. - */ - LIST_ENTRY ReplyList; - - /** Lock protecting the reply list. */ - EFI_LOCK ReplyLock; - /** * List of registered watches. */ @@ -136,6 +100,13 @@ typedef struct { =20 /** Handle for XenStore events. */ EFI_EVENT EventChannelEvent; + + /** Buffer used to copy payloads from the xenstore ring */ + // The + 1 is to allow to have a \0. + CHAR8 Buffer[XENSTORE_PAYLOAD_MAX + 1]; + + /** ID used when sending messages to xenstored */ + UINTN NextRequestId; } XENSTORE_PRIVATE; =20 // @@ -148,6 +119,12 @@ static XENSTORE_PRIVATE xs; // Private Utility Functions // =20 +STATIC +XENSTORE_STATUS +XenStoreGetError ( + CONST CHAR8 *ErrorStr + ); + /** Count and optionally record pointers to a number of NUL terminated strings in a buffer. @@ -613,70 +590,106 @@ XenStoreReadStore ( Block reading the next message from the XenStore service and process the result. =20 + @param ExpectedRequestId Block until a reply to with this ID is see= n. + @param ExpectedTransactionId Idem, but should also match this ID. + @param BufferSize IN: size of the buffer + OUT: The returned length of the reply. + @param Buffer The returned body of the reply. + @return XENSTORE_STATUS_SUCCESS on success. Otherwise an errno value indicating the type of failure encountered. **/ STATIC XENSTORE_STATUS XenStoreProcessMessage ( - VOID + IN UINT32 ExpectedRequestId, + IN UINT32 ExpectedTransactionId, + IN OUT UINTN *BufferSize OPTIONAL, + IN OUT CHAR8 *Buffer OPTIONAL ) { - XENSTORE_MESSAGE *Message; - CHAR8 *Body; - XENSTORE_STATUS Status; - - Message =3D AllocateZeroPool (sizeof (XENSTORE_MESSAGE)); - Message->Signature =3D XENSTORE_MESSAGE_SIGNATURE; - Status =3D XenStoreReadStore (&Message->Header, sizeof (Message->Header)= ); - if (Status !=3D XENSTORE_STATUS_SUCCESS) { - FreePool (Message); - DEBUG ((EFI_D_ERROR, "XenStore: Error read store (%d)\n", Status)); - return Status; - } - - Body =3D AllocatePool (Message->Header.len + 1); - Status =3D XenStoreReadStore (Body, Message->Header.len); - if (Status !=3D XENSTORE_STATUS_SUCCESS) { - FreePool (Body); - FreePool (Message); - DEBUG ((EFI_D_ERROR, "XenStore: Error read store (%d)\n", Status)); - return Status; - } - Body[Message->Header.len] =3D '\0'; + struct xsd_sockmsg Header; + CHAR8 *Payload; + XENSTORE_STATUS Status; =20 - if (Message->Header.type =3D=3D XS_WATCH_EVENT) { - CONST CHAR8 *WatchEventPath; - CONST CHAR8 *WatchEventToken; - VOID *ConvertedToken; - XENSTORE_WATCH *Watch; + while (TRUE) { =20 - // - // Parse WATCH_EVENT messages - // \0\0 - // - WatchEventPath =3D Body; - WatchEventToken =3D WatchEventPath + AsciiStrSize (WatchEventPath); + Status =3D XenStoreReadStore (&Header, sizeof (Header)); + if (Status !=3D XENSTORE_STATUS_SUCCESS) { + DEBUG ((DEBUG_ERROR, "XenStore: Error read store (%d)\n", Status)); + return Status; + } =20 - ConvertedToken =3D (VOID *) AsciiStrHexToUintn (WatchEventToken); + ASSERT (Header.len <=3D XENSTORE_PAYLOAD_MAX); + if (Header.len > XENSTORE_PAYLOAD_MAX) { + DEBUG ((DEBUG_ERROR, "XenStore: Message payload over %d (is %d)\n", + XENSTORE_PAYLOAD_MAX, Header.len)); + Header.len =3D XENSTORE_PAYLOAD_MAX; + } =20 - EfiAcquireLock (&xs.RegisteredWatchesLock); - Watch =3D XenStoreFindWatch (ConvertedToken); - DEBUG ((DEBUG_INFO, "XenStore: Watch event %a\n", WatchEventToken)); - if (Watch !=3D NULL) { - Watch->Triggered =3D TRUE; - } else { - DEBUG ((EFI_D_WARN, "XenStore: Watch handle %a not found\n", - WatchEventToken)); + Payload =3D xs.Buffer; + Status =3D XenStoreReadStore (Payload, Header.len); + if (Status !=3D XENSTORE_STATUS_SUCCESS) { + DEBUG ((DEBUG_ERROR, "XenStore: Error read store (%d)\n", Status)); + return Status; } - EfiReleaseLock (&xs.RegisteredWatchesLock); - FreePool (Message); - FreePool (Body); - } else { - Message->u.Reply.Body =3D Body; - EfiAcquireLock (&xs.ReplyLock); - InsertTailList (&xs.ReplyList, &Message->Link); - EfiReleaseLock (&xs.ReplyLock); + Payload[Header.len] =3D '\0'; + + if (Header.type =3D=3D XS_WATCH_EVENT) { + CONST CHAR8 *WatchEventPath; + CONST CHAR8 *WatchEventToken; + VOID *ConvertedToken; + XENSTORE_WATCH *Watch; + + // + // Parse WATCH_EVENT messages + // \0\0 + // + WatchEventPath =3D Payload; + WatchEventToken =3D WatchEventPath + AsciiStrSize (WatchEventPath); + + ConvertedToken =3D (VOID *) AsciiStrHexToUintn (WatchEventToken); + + EfiAcquireLock (&xs.RegisteredWatchesLock); + Watch =3D XenStoreFindWatch (ConvertedToken); + DEBUG ((DEBUG_INFO, "XenStore: Watch event %a\n", WatchEventToken)); + if (Watch !=3D NULL) { + Watch->Triggered =3D TRUE; + } else { + DEBUG ((DEBUG_WARN, "XenStore: Watch handle %a not found\n", + WatchEventToken)); + } + EfiReleaseLock (&xs.RegisteredWatchesLock); + + if (Header.req_id =3D=3D ExpectedRequestId + && Header.tx_id =3D=3D ExpectedTransactionId + && Buffer =3D=3D NULL) { + // + // We were waiting for a watch event + // + return XENSTORE_STATUS_SUCCESS; + } + } else if (Header.req_id =3D=3D ExpectedRequestId + && Header.tx_id =3D=3D ExpectedTransactionId) { + Status =3D XENSTORE_STATUS_SUCCESS; + if (Header.type =3D=3D XS_ERROR) { + Status =3D XenStoreGetError (Payload); + } else if (Buffer !=3D NULL) { + ASSERT (BufferSize !=3D NULL); + ASSERT (*BufferSize >=3D Header.len); + CopyMem (Buffer, Payload, MIN (Header.len + 1, *BufferSize)); + *BufferSize =3D Header.len; + } else { + // + // Payload should be "OK" if the function sending a request doesn't + // expect a reply. + // + ASSERT (Header.len =3D=3D 3); + ASSERT (AsciiStrCmp (Payload, "OK") =3D=3D 0); + } + return Status; + } + } =20 return XENSTORE_STATUS_SUCCESS; @@ -736,51 +749,6 @@ XenStoreGetError ( return XENSTORE_STATUS_EINVAL; } =20 -/** - Block waiting for a reply to a message request. - - @param TypePtr The returned type of the reply. - @param LenPtr The returned body length of the reply. - @param Result The returned body of the reply. -**/ -STATIC -XENSTORE_STATUS -XenStoreReadReply ( - OUT enum xsd_sockmsg_type *TypePtr, - OUT UINT32 *LenPtr OPTIONAL, - OUT VOID **Result - ) -{ - XENSTORE_MESSAGE *Message; - LIST_ENTRY *Entry; - CHAR8 *Body; - - while (IsListEmpty (&xs.ReplyList)) { - XENSTORE_STATUS Status; - Status =3D XenStoreProcessMessage (); - if (Status !=3D XENSTORE_STATUS_SUCCESS && Status !=3D XENSTORE_STATUS= _EAGAIN) { - DEBUG ((DEBUG_ERROR, "XenStore, error while reading the ring (%d).\n= ", - Status)); - return Status; - } - } - EfiAcquireLock (&xs.ReplyLock); - Entry =3D GetFirstNode (&xs.ReplyList); - Message =3D XENSTORE_MESSAGE_FROM_LINK (Entry); - RemoveEntryList (Entry); - EfiReleaseLock (&xs.ReplyLock); - - *TypePtr =3D Message->Header.type; - if (LenPtr !=3D NULL) { - *LenPtr =3D Message->Header.len; - } - Body =3D Message->u.Reply.Body; - - FreePool (Message); - *Result =3D Body; - return XENSTORE_STATUS_SUCCESS; -} - /** Send a message with an optionally muti-part body to the XenStore service. =20 @@ -806,16 +774,17 @@ XenStoreTalkv ( ) { struct xsd_sockmsg Message; - void *Return =3D NULL; - UINT32 Index; - XENSTORE_STATUS Status; + UINTN Index; + XENSTORE_STATUS Status; + VOID *Buffer; + UINTN BufferSize; =20 if (Transaction =3D=3D XST_NIL) { Message.tx_id =3D 0; } else { Message.tx_id =3D Transaction->Id; } - Message.req_id =3D 0; + Message.req_id =3D xs.NextRequestId++; Message.type =3D RequestType; Message.len =3D 0; for (Index =3D 0; Index < NumRequests; Index++) { @@ -836,29 +805,36 @@ XenStoreTalkv ( } } =20 - Status =3D XenStoreReadReply ((enum xsd_sockmsg_type *)&Message.type, Le= nPtr, &Return); - -Error: - if (Status !=3D XENSTORE_STATUS_SUCCESS) { - return Status; + if (ResultPtr) { + Buffer =3D AllocatePool (XENSTORE_PAYLOAD_MAX + 1); + BufferSize =3D XENSTORE_PAYLOAD_MAX; + } else { + Buffer =3D NULL; + BufferSize =3D 0; } =20 - if (Message.type =3D=3D XS_ERROR) { - Status =3D XenStoreGetError (Return); - FreePool (Return); + // + // Wait for a reply to our request + // + Status =3D XenStoreProcessMessage (Message.req_id, Message.tx_id, + &BufferSize, Buffer); + + if (Status !=3D XENSTORE_STATUS_SUCCESS) { + DEBUG ((DEBUG_ERROR, "XenStore, error while reading the ring (%d).\n", + Status)); + FreePool (Buffer); return Status; } =20 - /* Reply is either error or an echo of our request message type. */ - ASSERT ((enum xsd_sockmsg_type)Message.type =3D=3D RequestType); - if (ResultPtr) { - *ResultPtr =3D Return; - } else { - FreePool (Return); + *ResultPtr =3D Buffer; + if (LenPtr) { + *LenPtr =3D BufferSize; + } } =20 - return XENSTORE_STATUS_SUCCESS; +Error: + return Status; } =20 /** @@ -975,7 +951,7 @@ XenStoreWaitWatch ( return XENSTORE_STATUS_SUCCESS; } =20 - Status =3D XenStoreProcessMessage (); + Status =3D XenStoreProcessMessage (0, 0, NULL, NULL); if (Status !=3D XENSTORE_STATUS_SUCCESS && Status !=3D XENSTORE_STATUS= _EAGAIN) { return Status; } @@ -1060,12 +1036,12 @@ XenStoreInit ( DEBUG ((EFI_D_INFO, "XenBusInit: XenBus rings @%p, event channel %x\n", xs.XenStore, xs.EventChannel)); =20 - InitializeListHead (&xs.ReplyList); InitializeListHead (&xs.RegisteredWatches); =20 - EfiInitializeLock (&xs.ReplyLock, TPL_NOTIFY); EfiInitializeLock (&xs.RegisteredWatchesLock, TPL_NOTIFY); =20 + xs.NextRequestId =3D 1; + /* Initialize the shared memory rings to talk to xenstored */ Status =3D XenStoreInitComms (&xs); =20 @@ -1095,19 +1071,6 @@ XenStoreDeinit ( } } =20 - if (!IsListEmpty (&xs.ReplyList)) { - XENSTORE_MESSAGE *Message; - LIST_ENTRY *Entry; - Entry =3D GetFirstNode (&xs.ReplyList); - while (!IsNull (&xs.ReplyList, Entry)) { - Message =3D XENSTORE_MESSAGE_FROM_LINK (Entry); - Entry =3D GetNextNode (&xs.ReplyList, Entry); - RemoveEntryList (&Message->Link); - FreePool (Message->u.Reply.Body); - FreePool (Message); - } - } - gBS->CloseEvent (xs.EventChannelEvent); =20 if (xs.XenStore->server_features & XENSTORE_SERVER_FEATURE_RECONNECTION)= { --=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 (#47216): https://edk2.groups.io/g/devel/message/47216 Mute This Topic: https://groups.io/mt/34128017/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- From nobody Thu May 2 18:38:31 2024 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+47213+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568386271; cv=none; d=zoho.com; s=zohoarc; b=bBEwDSrAVf6OwPF7uNsRdKAgccCnNPW5ociui3mPKFJr5i1bRU0eJEzieCU8PTNOgAlyHSO2J4UY0ZbdVtkGpwUpk65btmUbnJuzlW2kyFlRVdTY7dOrQdcv+vsAVqbej4oLTWHq0F/3JTIon1xaG7h/F6HtQTUemSs5sOgHsws= 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=K0VgrrlVlXccbPMu6xYw+E3QVhPwSD6znzZIKYjMKMk=; b=UnyenhJOqiTE9+0dosGd5O0yaKoaamhArwQayR0UuLCflv7TjVZ5unnxHPQq2cP+MN7rWqh4dM7stFur/jQlP1oCN0bnSYLJzchGfJ5GxpsH3bdOfM4JTvwQItSQv44bAUZI4rXCdJS9bG19GPndT65RmwR19zO7JhL1L2kjssY= 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+47213+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568386271075404.55109601359095; 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+47213+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: SQpEESrH0HvRSJaZCPM1lFvVPSi/dk4bKcioDSpKcogGwUMge2QvhatUfzWBoEXnD35c0eAM9k l9N4FjJ5+2vRDZ8w4+TJ+71QZMEezuNb39hKkKa/76/QW9NJznKuFn5GsN1k9azylgyNgG/sKj YpBVcCzWdZUBOvmdVTvNiN/p/CW0wMos/4R9N6n/+X0NBTHwpUUWbFu9WeZqCccyNWgNv9Tzve 0GVpQOhmu5sB9l7zq92Pl1GnRVd4mp/UWOQdjKslx3E/sg/ke5sJHbG5pj2QnOhntYyORijqdm LwU= X-SBRS: 2.7 X-MesageID: 5595147 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="5595147" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 07/11] OvmfPkg/XenBusDxe: Use on stack buffer in internal functions Date: Fri, 13 Sep 2019 15:50:56 +0100 Message-ID: <20190913145100.303433-8-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=K0VgrrlVlXccbPMu6xYw+E3QVhPwSD6znzZIKYjMKMk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=UXW897KzT6amCt8UPbtEJcx3eBqwB9KqPhlzu8fNtUd1raD1LctATVEv3/hJCz9Pr4r 5LM7PqyUwHcrbprkEGjbKk0nNHjzSe0PugpWOYcMGAFtLSI67fQ4t+TsyZpi/1px9CDsM c3kUU2AYJCjBfdWcO3DoS+bk9Qi4KrUWNhg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" We will use a buffer on the stack instead of allocating memory for internal functions that are expecting a reply from xenstore. The external interface XENBUS_PROTOCOL isn't changed yet, so allocation are made for XsRead and XsBackendRead. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2190 Signed-off-by: Anthony PERARD --- OvmfPkg/XenBusDxe/XenBus.c | 40 ++++++------ OvmfPkg/XenBusDxe/XenStore.c | 115 ++++++++++++++++++++--------------- OvmfPkg/XenBusDxe/XenStore.h | 17 +++--- 3 files changed, 95 insertions(+), 77 deletions(-) diff --git a/OvmfPkg/XenBusDxe/XenBus.c b/OvmfPkg/XenBusDxe/XenBus.c index bb8ddbc4d4..78835ec7b3 100644 --- a/OvmfPkg/XenBusDxe/XenBus.c +++ b/OvmfPkg/XenBusDxe/XenBus.c @@ -89,19 +89,18 @@ XenBusReadDriverState ( IN CONST CHAR8 *Path ) { - XenbusState State; - CHAR8 *Ptr =3D NULL; + XenbusState State; + CHAR8 Buffer[4]; + UINTN BufferSize; XENSTORE_STATUS Status; =20 - Status =3D XenStoreRead (XST_NIL, Path, "state", NULL, (VOID **)&Ptr); + BufferSize =3D sizeof (Buffer) - 1; + Status =3D XenStoreRead (XST_NIL, Path, "state", &BufferSize, Buffer); if (Status !=3D XENSTORE_STATUS_SUCCESS) { State =3D XenbusStateClosed; } else { - State =3D AsciiStrDecimalToUintn (Ptr); - } - - if (Ptr !=3D NULL) { - FreePool (Ptr); + Buffer[BufferSize] =3D '\0'; + State =3D AsciiStrDecimalToUintn (Buffer); } =20 return State; @@ -129,8 +128,11 @@ XenBusAddDevice ( =20 if (XenStorePathExists (XST_NIL, DevicePath, "")) { XENBUS_PRIVATE_DATA *Child; - enum xenbus_state State; - CHAR8 *BackendPath; + enum xenbus_state State; + CHAR8 BackendPath[XENSTORE_ABS_PATH_MAX + 1]; + UINTN BackendPathSize; + + BackendPathSize =3D sizeof (BackendPath); =20 Child =3D XenBusDeviceInitialized (Dev, DevicePath); if (Child !=3D NULL) { @@ -155,17 +157,18 @@ XenBusAddDevice ( } =20 StatusXenStore =3D XenStoreRead (XST_NIL, DevicePath, "backend", - NULL, (VOID **) &BackendPath); + &BackendPathSize, BackendPath); if (StatusXenStore !=3D XENSTORE_STATUS_SUCCESS) { DEBUG ((EFI_D_ERROR, "xenbus: %a no backend path.\n", DevicePath)); Status =3D EFI_NOT_FOUND; goto out; } + BackendPath[BackendPathSize] =3D '\0'; =20 Private =3D AllocateCopyPool (sizeof (*Private), &gXenBusPrivateData); Private->XenBusIo.Type =3D AsciiStrDup (Type); Private->XenBusIo.Node =3D AsciiStrDup (DevicePath); - Private->XenBusIo.Backend =3D BackendPath; + Private->XenBusIo.Backend =3D AsciiStrDup (BackendPath); Private->XenBusIo.DeviceId =3D (UINT16)AsciiStrDecimalToUintn (Id); Private->Dev =3D Dev; =20 @@ -309,17 +312,20 @@ XenBusSetState ( ) { enum xenbus_state CurrentState; - XENSTORE_STATUS Status; - CHAR8 *Temp; + XENSTORE_STATUS Status; + CHAR8 Buffer[4]; + UINTN BufferSize; + + BufferSize =3D sizeof (Buffer) - 1; =20 DEBUG ((EFI_D_INFO, "XenBus: Set state to %d\n", NewState)); =20 - Status =3D XenStoreRead (Transaction, This->Node, "state", NULL, (VOID *= *)&Temp); + Status =3D XenStoreRead (Transaction, This->Node, "state", &BufferSize, = Buffer); if (Status !=3D XENSTORE_STATUS_SUCCESS) { goto Out; } - CurrentState =3D AsciiStrDecimalToUintn (Temp); - FreePool (Temp); + Buffer[BufferSize] =3D '\0'; + CurrentState =3D AsciiStrDecimalToUintn (Buffer); if (CurrentState =3D=3D NewState) { goto Out; } diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index 004d3b6022..b9588bb8c6 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -756,8 +756,9 @@ XenStoreGetError ( @param RequestType The type of message to send. @param WriteRequest Pointers to the body sections of the request. @param NumRequests The number of body sections in the request. - @param LenPtr The returned length of the reply. - @param ResultPtr The returned body of the reply. + @param BufferSize IN: size of the buffer + OUT: The returned length of the reply. + @param Buffer The returned body of the reply. =20 @return XENSTORE_STATUS_SUCCESS on success. Otherwise an errno indicat= ing the cause of failure. @@ -769,15 +770,13 @@ XenStoreTalkv ( IN enum xsd_sockmsg_type RequestType, IN CONST WRITE_REQUEST *WriteRequest, IN UINT32 NumRequests, - OUT UINT32 *LenPtr OPTIONAL, - OUT VOID **ResultPtr OPTIONAL + IN OUT UINTN *BufferSize OPTIONAL, + OUT VOID *Buffer OPTIONAL ) { struct xsd_sockmsg Message; UINTN Index; XENSTORE_STATUS Status; - VOID *Buffer; - UINTN BufferSize; =20 if (Transaction =3D=3D XST_NIL) { Message.tx_id =3D 0; @@ -805,32 +804,15 @@ XenStoreTalkv ( } } =20 - if (ResultPtr) { - Buffer =3D AllocatePool (XENSTORE_PAYLOAD_MAX + 1); - BufferSize =3D XENSTORE_PAYLOAD_MAX; - } else { - Buffer =3D NULL; - BufferSize =3D 0; - } - // // Wait for a reply to our request // Status =3D XenStoreProcessMessage (Message.req_id, Message.tx_id, - &BufferSize, Buffer); + BufferSize, Buffer); =20 if (Status !=3D XENSTORE_STATUS_SUCCESS) { DEBUG ((DEBUG_ERROR, "XenStore, error while reading the ring (%d).\n", Status)); - FreePool (Buffer); - return Status; - } - - if (ResultPtr) { - *ResultPtr =3D Buffer; - if (LenPtr) { - *LenPtr =3D BufferSize; - } } =20 Error: @@ -848,8 +830,9 @@ XenStoreTalkv ( @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. + @param BufferSize IN: sizef of the buffer + OUT: The returned length of the reply. + @param Buffer The returned body of the reply. =20 @return 0 on success. Otherwise an errno indicating the cause of failure. @@ -861,8 +844,8 @@ XenStoreSingle ( IN enum xsd_sockmsg_type RequestType, IN CONST CHAR8 *Body, IN CONST CHAR8 *SubPath OPTIONAL, - OUT UINT32 *LenPtr OPTIONAL, - OUT VOID **Result OPTIONAL + IN OUT UINTN *BufferSize OPTIONAL, + OUT VOID *Buffer OPTIONAL ) { WRITE_REQUEST WriteRequest[3]; @@ -870,7 +853,7 @@ XenStoreSingle ( XenStorePrepareWriteRequest (WriteRequest, Body, SubPath); =20 return XenStoreTalkv (Transaction, RequestType, WriteRequest, 3, - LenPtr, Result); + BufferSize, Buffer); } =20 // @@ -1106,13 +1089,16 @@ XenStoreListDirectory ( OUT CONST CHAR8 ***DirectoryListPtr ) { - CHAR8 *TempStr; - UINT32 Len =3D 0; + CHAR8 *TempStr; + UINTN Len; XENSTORE_STATUS Status; =20 + TempStr =3D AllocatePool (XENSTORE_PAYLOAD_MAX); + Len =3D XENSTORE_PAYLOAD_MAX; Status =3D XenStoreSingle (Transaction, XS_DIRECTORY, DirectoryPath, Nod= e, &Len, - (VOID **) &TempStr); + TempStr); if (Status !=3D XENSTORE_STATUS_SUCCESS) { + FreePool (TempStr); return Status; } =20 @@ -1146,21 +1132,14 @@ XenStoreRead ( IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *DirectoryPath, IN CONST CHAR8 *Node, - OUT UINT32 *LenPtr OPTIONAL, - OUT VOID **Result + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ) { - VOID *Value; - XENSTORE_STATUS Status; - - Status =3D XenStoreSingle (Transaction, XS_READ, DirectoryPath, Node, - LenPtr, &Value); - if (Status !=3D XENSTORE_STATUS_SUCCESS) { - return Status; - } - - *Result =3D Value; - return XENSTORE_STATUS_SUCCESS; + ASSERT (BufferSize !=3D NULL); + ASSERT (Buffer !=3D NULL); + return XenStoreSingle (Transaction, XS_READ, DirectoryPath, Node, + BufferSize, Buffer); } =20 XENSTORE_STATUS @@ -1199,14 +1178,16 @@ XenStoreTransactionStart ( OUT XENSTORE_TRANSACTION *Transaction ) { - CHAR8 *IdStr; + CHAR8 IdStr[XENSTORE_PAYLOAD_MAX]; + UINTN BufferSize; XENSTORE_STATUS Status; =20 + BufferSize =3D sizeof (IdStr); + Status =3D XenStoreSingle (XST_NIL, XS_TRANSACTION_START, "", NULL, - NULL, (VOID **) &IdStr); + &BufferSize, IdStr); if (Status =3D=3D XENSTORE_STATUS_SUCCESS) { Transaction->Id =3D (UINT32)AsciiStrDecimalToUintn (IdStr); - FreePool (IdStr); } =20 return Status; @@ -1358,7 +1339,24 @@ XenBusXenStoreRead ( OUT VOID **Value ) { - return XenStoreRead (Transaction, This->Node, Node, NULL, Value); + XENSTORE_STATUS Status; + UINTN BufferSize; + VOID *Buffer; + + BufferSize =3D XENSTORE_PAYLOAD_MAX + 1; + Buffer =3D AllocatePool (BufferSize); + if (Buffer =3D=3D NULL) { + return XENSTORE_STATUS_ENOMEM; + } + + Status =3D XenStoreRead (Transaction, This->Node, Node, &BufferSize, Buf= fer); + + if (Status =3D=3D XENSTORE_STATUS_SUCCESS) { + *Value =3D Buffer; + } else { + FreePool (Buffer); + } + return Status; } =20 XENSTORE_STATUS @@ -1370,7 +1368,24 @@ XenBusXenStoreBackendRead ( OUT VOID **Value ) { - return XenStoreRead (Transaction, This->Backend, Node, NULL, Value); + XENSTORE_STATUS Status; + UINTN BufferSize; + VOID *Buffer; + + BufferSize =3D XENSTORE_PAYLOAD_MAX + 1; + Buffer =3D AllocatePool (BufferSize); + if (Buffer =3D=3D NULL) { + return XENSTORE_STATUS_ENOMEM; + } + + Status =3D XenStoreRead (Transaction, This->Backend, Node, &BufferSize, = Buffer); + + if (Status =3D=3D XENSTORE_STATUS_SUCCESS) { + *Value =3D Buffer; + } else { + FreePool (Buffer); + } + return Status; } =20 XENSTORE_STATUS diff --git a/OvmfPkg/XenBusDxe/XenStore.h b/OvmfPkg/XenBusDxe/XenStore.h index effaad7336..13f7d132e6 100644 --- a/OvmfPkg/XenBusDxe/XenStore.h +++ b/OvmfPkg/XenBusDxe/XenStore.h @@ -64,29 +64,26 @@ XenStorePathExists ( ); =20 /** - Get the contents of a single "file". Returns the contents in *Result wh= ich - should be freed after use. The length of the value in bytes is returned= in - *LenPtr. + Get the contents of a single "file". Copy the contents in Buffer if + provided. The length of the value in bytes is returned in *BufferSize. =20 @param Transaction The XenStore transaction covering this request. @param DirectoryPath The dirname of the file to read. @param Node The basename of the file to read. - @param LenPtr The amount of data read. - @param Result The returned contents from this file. + @param BufferSize IN: size of the buffer + OUT: The returned length of the reply. + @param Buffer The returned body of the reply. =20 @return On success, XENSTORE_STATUS_SUCCESS. Otherwise an errno value indicating the type of failure. - - @note The results buffer is malloced and should be free'd by the - caller. **/ XENSTORE_STATUS XenStoreRead ( IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *DirectoryPath, IN CONST CHAR8 *Node, - OUT UINT32 *LenPtr OPTIONAL, - OUT VOID **Result + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ); =20 /** --=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 (#47213): https://edk2.groups.io/g/devel/message/47213 Mute This Topic: https://groups.io/mt/34128014/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- From nobody Thu May 2 18:38:31 2024 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+47217+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568386271; cv=none; d=zoho.com; s=zohoarc; b=ifBteeliprQkiFAv7im6vdfUkK/rBoqxoxdWpzPMhlO0TV/XKnfWe+ol2lpmw1GrLdIyeuBWRPL22xhiWAe99iFukiDIEzbDRHKE18J6C6VoTCo0XWe43bZI2f+S2R+mCh1shbv/DHJbL9sIQLKitcdM1rit4AwDHjXUOsqOfbw= 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=8YlGZk6oUzcsItAxxqQ1v6EuId4ETYPKEHnzYprluas=; b=Nt6psxpeXO1JxJpymgT60RjD16ifSGIc/A5M4tuMZLVqBbsRJuoGoU4JpSRcmtLH8MyWAJ/2vVY6mQmM/lsSsTL17UbmTdy7vFbLJxx6OwXEBFPdrdgz0yfeJTnf318/YXiVaafP29Xj89Znu8W/4TC1l7OxdXUvb27xQNDx8Is= 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+47217+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568386271881353.776140287731; 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:10 -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+47217+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: RuylfgGcqVmDM0HWqFvVTb6r7R49PW+toIafriwtLXe/fADmm1O5dAJePdatTR4U9SIm9LbcdE gqnRK1AopqtGDj6RCQpSsnIqGHjBH008UJeVm7kI5zw4zUOEo1qIw4Zf8x/Mpkj8zxxhKUTaCD BvzooSE052ejgBpepcaq4NAAJS/q9SQAk9yKL46BKmj3k0uhpb7PUKoC3IJd+ETHqy4h08phGI a3PGLOti5/nHeloggWVuWJ3UmjRnDxSf88winG10eO4LAhqdqKj6ufjwZfCjoJnBQflQ0qstyv P1s= X-SBRS: 2.7 X-MesageID: 5595152 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="5595152" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 08/11] OvmfPkg/XenBus: Change XENBUS_PROTOCOL to not return allocated memory Date: Fri, 13 Sep 2019 15:50:57 +0100 Message-ID: <20190913145100.303433-9-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=8YlGZk6oUzcsItAxxqQ1v6EuId4ETYPKEHnzYprluas=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=VDLVyGt+CtPKsJNe9WS0Aada2sAKqGHhNDUVFfvz0jKjnx5g4iF1DqTzpCg/XkRY0ea +z+cM/VzkCBdfPHkM98368b67YH63kblza85zXh2nCySacnn5PefuM8jSj+wKhFvgdMO/ H27vo6t0JIoFJoDliDe0f6Wm9shhcmKpX24= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" XsRead and XsBackendRead of the XENBUS_PROTOCOL return allocated memory but this isn't allowed during the ExitBootServices call. We need XsRead and XsBackendRead to disconnect from the device so XENBUS_PROTOCOL is changed to use a buffer supplied by a child driver. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2190 Signed-off-by: Anthony PERARD Acked-by: Laszlo Ersek --- OvmfPkg/Include/Protocol/XenBus.h | 32 ++++++++++++---------- OvmfPkg/XenBusDxe/XenStore.c | 44 +++++------------------------- OvmfPkg/XenBusDxe/XenStore.h | 6 +++-- OvmfPkg/XenPvBlkDxe/BlockFront.c | 45 ++++++++++++++++++------------- 4 files changed, 54 insertions(+), 73 deletions(-) diff --git a/OvmfPkg/Include/Protocol/XenBus.h b/OvmfPkg/Include/Protocol/X= enBus.h index 8ff5ca3575..c22bdfb368 100644 --- a/OvmfPkg/Include/Protocol/XenBus.h +++ b/OvmfPkg/Include/Protocol/XenBus.h @@ -35,6 +35,12 @@ typedef struct =20 #define XST_NIL ((XENSTORE_TRANSACTION *) NULL) =20 +// +// When reading a node from xenstore, if the size of the data to be read is +// unknown, this value can be use for the size of the buffer. +// +#define XENSTORE_PAYLOAD_MAX 4096 + typedef enum { XENSTORE_STATUS_SUCCESS =3D 0, XENSTORE_STATUS_FAIL, @@ -64,19 +70,17 @@ typedef enum { /// =20 /** - Get the contents of the node Node of the PV device. Returns the contents= in - *Result which should be freed after use. + Get the contents of the node Node of the PV device. =20 @param This A pointer to XENBUS_PROTOCOL instance. @param Transaction The XenStore transaction covering this request. @param Node The basename of the file to read. - @param Result The returned contents from this file. + @param BufferSize On input, a pointer to the size of the buffer at B= uffer. + On output, the size of the data written to Buffer. + @param Buffer A pointer to a buffer into which the data read wil= l be saved. =20 @return On success, XENSTORE_STATUS_SUCCESS. Otherwise an errno value indicating the type of failure. - - @note The results buffer is malloced and should be free'd by the - caller. **/ typedef XENSTORE_STATUS @@ -84,23 +88,22 @@ XENSTORE_STATUS IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Result + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ); =20 /** - Get the contents of the node Node of the PV device's backend. Returns the - contents in *Result which should be freed after use. + Get the contents of the node Node of the PV device's backend. =20 @param This A pointer to XENBUS_PROTOCOL instance. @param Transaction The XenStore transaction covering this request. @param Node The basename of the file to read. - @param Result The returned contents from this file. + @param BufferSize On input, a pointer to the size of the buffer at B= uffer. + On output, the size of the data written to Buffer. + @param Buffer A pointer to a buffer into which the data read wil= l be saved. =20 @return On success, XENSTORE_STATUS_SUCCESS. Otherwise an errno value indicating the type of failure. - - @note The results buffer is malloced and should be free'd by the - caller. **/ typedef XENSTORE_STATUS @@ -108,7 +111,8 @@ XENSTORE_STATUS IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Result + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ); =20 /** diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index b9588bb8c6..cb2d9e1215 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -1336,27 +1336,11 @@ XenBusXenStoreRead ( IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Value + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ) { - XENSTORE_STATUS Status; - UINTN BufferSize; - VOID *Buffer; - - BufferSize =3D XENSTORE_PAYLOAD_MAX + 1; - Buffer =3D AllocatePool (BufferSize); - if (Buffer =3D=3D NULL) { - return XENSTORE_STATUS_ENOMEM; - } - - Status =3D XenStoreRead (Transaction, This->Node, Node, &BufferSize, Buf= fer); - - if (Status =3D=3D XENSTORE_STATUS_SUCCESS) { - *Value =3D Buffer; - } else { - FreePool (Buffer); - } - return Status; + return XenStoreRead (Transaction, This->Node, Node, BufferSize, Buffer); } =20 XENSTORE_STATUS @@ -1365,27 +1349,11 @@ XenBusXenStoreBackendRead ( IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Value + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ) { - XENSTORE_STATUS Status; - UINTN BufferSize; - VOID *Buffer; - - BufferSize =3D XENSTORE_PAYLOAD_MAX + 1; - Buffer =3D AllocatePool (BufferSize); - if (Buffer =3D=3D NULL) { - return XENSTORE_STATUS_ENOMEM; - } - - Status =3D XenStoreRead (Transaction, This->Backend, Node, &BufferSize, = Buffer); - - if (Status =3D=3D XENSTORE_STATUS_SUCCESS) { - *Value =3D Buffer; - } else { - FreePool (Buffer); - } - return Status; + return XenStoreRead (Transaction, This->Backend, Node, BufferSize, Buffe= r); } =20 XENSTORE_STATUS diff --git a/OvmfPkg/XenBusDxe/XenStore.h b/OvmfPkg/XenBusDxe/XenStore.h index 13f7d132e6..ca8c080433 100644 --- a/OvmfPkg/XenBusDxe/XenStore.h +++ b/OvmfPkg/XenBusDxe/XenStore.h @@ -289,7 +289,8 @@ XenBusXenStoreRead ( IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Value + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ); =20 XENSTORE_STATUS @@ -298,7 +299,8 @@ XenBusXenStoreBackendRead ( IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Value + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ); =20 XENSTORE_STATUS diff --git a/OvmfPkg/XenPvBlkDxe/BlockFront.c b/OvmfPkg/XenPvBlkDxe/BlockFr= ont.c index 8dca4c82f0..25a398ccc4 100644 --- a/OvmfPkg/XenPvBlkDxe/BlockFront.c +++ b/OvmfPkg/XenPvBlkDxe/BlockFront.c @@ -41,19 +41,22 @@ XenBusReadUint64 ( ) { XENSTORE_STATUS Status; - CHAR8 *Ptr; + CHAR8 Buffer[22]; + UINTN BufferSize; + + BufferSize =3D sizeof (Buffer) - 1; =20 if (!FromBackend) { - Status =3D This->XsRead (This, XST_NIL, Node, (VOID**)&Ptr); + Status =3D This->XsRead (This, XST_NIL, Node, &BufferSize, Buffer); } else { - Status =3D This->XsBackendRead (This, XST_NIL, Node, (VOID**)&Ptr); + Status =3D This->XsBackendRead (This, XST_NIL, Node, &BufferSize, Buff= er); } if (Status !=3D XENSTORE_STATUS_SUCCESS) { return Status; } + Buffer[BufferSize] =3D '\0'; // AsciiStrDecimalToUint64 will ASSERT if Ptr overflow UINT64. - *ValuePtr =3D AsciiStrDecimalToUint64 (Ptr); - FreePool (Ptr); + *ValuePtr =3D AsciiStrDecimalToUint64 (Buffer); return Status; } =20 @@ -143,43 +146,47 @@ XenPvBlockFrontInitialization ( OUT XEN_BLOCK_FRONT_DEVICE **DevPtr ) { - XENSTORE_TRANSACTION Transaction; - CHAR8 *DeviceType; - blkif_sring_t *SharedRing; - XENSTORE_STATUS Status; + XENSTORE_TRANSACTION Transaction; + CHAR8 Buffer[XENSTORE_PAYLOAD_MAX + 1]; + UINTN BufferSize; + blkif_sring_t *SharedRing; + XENSTORE_STATUS Status; XEN_BLOCK_FRONT_DEVICE *Dev; - XenbusState State; - UINT64 Value; - CHAR8 *Params; + XenbusState State; + UINT64 Value; =20 ASSERT (NodeName !=3D NULL); =20 + BufferSize =3D sizeof (Buffer) - 1; + Dev =3D AllocateZeroPool (sizeof (XEN_BLOCK_FRONT_DEVICE)); Dev->Signature =3D XEN_BLOCK_FRONT_SIGNATURE; Dev->NodeName =3D NodeName; Dev->XenBusIo =3D XenBusIo; Dev->DeviceId =3D XenBusIo->DeviceId; =20 - XenBusIo->XsRead (XenBusIo, XST_NIL, "device-type", (VOID**)&DeviceType); - if (AsciiStrCmp (DeviceType, "cdrom") =3D=3D 0) { + BufferSize =3D sizeof (Buffer) - 1; + XenBusIo->XsRead (XenBusIo, XST_NIL, "device-type", &BufferSize, Buffer); + Buffer[BufferSize] =3D '\0'; + if (AsciiStrCmp (Buffer, "cdrom") =3D=3D 0) { Dev->MediaInfo.CdRom =3D TRUE; } else { Dev->MediaInfo.CdRom =3D FALSE; } - FreePool (DeviceType); =20 if (Dev->MediaInfo.CdRom) { - Status =3D XenBusIo->XsBackendRead (XenBusIo, XST_NIL, "params", (VOID= **)&Params); + BufferSize =3D sizeof (Buffer) - 1; + Status =3D XenBusIo->XsBackendRead (XenBusIo, XST_NIL, "params", + &BufferSize, Buffer); if (Status !=3D XENSTORE_STATUS_SUCCESS) { DEBUG ((EFI_D_ERROR, "%a: Failed to read params (%d)\n", __FUNCTION_= _, Status)); goto Error; } - if (AsciiStrLen (Params) =3D=3D 0 || AsciiStrCmp (Params, "aio:") =3D= =3D 0) { - FreePool (Params); + Buffer[BufferSize] =3D '\0'; + if (AsciiStrLen (Buffer) =3D=3D 0 || AsciiStrCmp (Buffer, "aio:") =3D= =3D 0) { DEBUG ((EFI_D_INFO, "%a: Empty cdrom\n", __FUNCTION__)); goto Error; } - FreePool (Params); } =20 Status =3D XenBusReadUint64 (XenBusIo, "backend-id", FALSE, &Value); --=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 (#47217): https://edk2.groups.io/g/devel/message/47217 Mute This Topic: https://groups.io/mt/34128018/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- From nobody Thu May 2 18:38:31 2024 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+47214+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568386270; cv=none; d=zoho.com; s=zohoarc; b=oUBarRT08LFcuqYUe6lcxpYBetc/YYkDdl8qdjOUiJv9cACyxc7bfNv669B+8OZQ0yg/4SlR8y2+w5gUlxxAMzCs1+/yRyAiNSSoTpT3mvcdBm9X3UOZB6g5B2AyuaRmUSP/buIoTfJ4NAAhWj6bmQVk9aERO4TFcQf7maDjbFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568386270; 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=efWbDUCT043b0v5rrf7YRir/dgWr203ycGScI9/lvsY=; b=WhxUvyHg78OQd6VNMSD7gMCZxm9nHeLmNSBHXekwAnJa54W3WSt9/JmMLcbjgXGQqqmbVh5f94ym03bvtkP78ioqrNy4/P2c8fMabwrDYKMz7ihpRo45ZnlDTckk096qalj7UOeyL+9GyXijrectGtma3XjlLEZ/aEJlDnNzvPc= 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+47214+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568386270478477.03793209133585; Fri, 13 Sep 2019 07:51:10 -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+47214+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: ddcTRW12wA0uCmjNrI/O8WX9I7vcQnpvyypnl+N45WWMhTtD3YHKTFyApqK06QfIrJ0jFIVjWV 0+FrEgmGJ8HS+arVzdX2Q7/QNtRLueOA8zLZBQAGIhgYkQkmUgRmlahB81EsMfTeJagTdupQ3t bEnvPZo8Dgugar8nvtXPW+oc5f4/lwmWdtB23E5AYccfR8/nmFUDE7NlL2jxlWtIGHYsby838H u6pFW87eAXTN9h8xFJWJK5KsyxbrZ5Eg74GC9ibSQ/1vxX2g5Tjua6w5GDTedj8RjYjn3dipOY Djc= X-SBRS: 2.7 X-MesageID: 5595150 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="5595150" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 09/11] OvmfPkg/XenBusDxe: Fix NotifyExitBoot to avoid Memory Allocation Services Date: Fri, 13 Sep 2019 15:50:58 +0100 Message-ID: <20190913145100.303433-10-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=efWbDUCT043b0v5rrf7YRir/dgWr203ycGScI9/lvsY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=w6jH7Mpgq6fPOpHg2E8EAF4/wg3qg8qo5ZQfrBgnjOBRwRZpG/rmmROIJHBI8xV4tvl zOmVaanRmGRpfgWzXgqVS3zetf64Bq0esyZ8mwXlYHRHp5HdwYUxWhNutntJkFE9MSMQN MofRhAQObZeojuR0SfwULfy9YRBCCKHhwOs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This patch fix the EVT_SIGNAL_EXIT_BOOT_SERVICES handler to avoid using the Memory Allocation Services. This comes with a new interface named RegisterExitCallback so that PV drivers can disconnect from the backend before XenBusDxe is teared down. Instead of using Disconnect() to tear down the XenBus driver and the children drivers, we are going to ask every driver using XENBUS_PROTOCOL to disconnect from the hardware via the callback set with RegisterExitCallback, then reset the xenstore shared ring and the grant table. Since there are no driver using RegisterExitCallback yet, no driver are going to be disconnected. Linux can deal with that. And that will be fixed by the next patch with a change for XenPvBlkDxe. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2190 Signed-off-by: Anthony PERARD --- OvmfPkg/Include/Protocol/XenBus.h | 35 +++++++++++++++++++++++++++++++ OvmfPkg/XenBusDxe/XenBus.c | 18 ++++++++++++++++ OvmfPkg/XenBusDxe/XenBusDxe.c | 27 +++++++++++++++++++++--- OvmfPkg/XenBusDxe/XenBusDxe.h | 2 ++ OvmfPkg/XenBusDxe/XenStore.c | 22 ++++++++++++++++++- OvmfPkg/XenBusDxe/XenStore.h | 21 +++++++++++++++++++ 6 files changed, 121 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/Include/Protocol/XenBus.h b/OvmfPkg/Include/Protocol/X= enBus.h index c22bdfb368..04986747c8 100644 --- a/OvmfPkg/Include/Protocol/XenBus.h +++ b/OvmfPkg/Include/Protocol/XenBus.h @@ -373,6 +373,38 @@ XENSTORE_STATUS IN VOID *Token ); =20 +typedef +VOID +(EFIAPI *XENBUS_EXIT_CALLBACK)( + IN VOID *Context + ); + +/** + Register a function to be called during the ExitBootServices event. + + NotifyFunction will be called when XenBusDxe is notified of + EVT_SIGNAL_EXIT_BOOT_SERVICES. The function should follow the same + requirements as if it as registered an event on + EVT_SIGNAL_EXIT_BOOT_SERVICES, i.e. no use of the Memory Allocation + Services. + + To unregister the function, call RegisterExitCallback with + NotifyFunction=3DNULL. + + @note There can only be one callback per driver. + + @param This A pointer to the XENBUS_PROTOCOL. + @param NotifyFunction The function to be called. + @param NotifyContext A context. +**/ +typedef +VOID +(EFIAPI *XENBUS_SET_EXIT_CALLBACK) ( + IN XENBUS_PROTOCOL *This, + IN XENBUS_EXIT_CALLBACK NotifyFunction, + IN VOID *NotifyContext + ); + =20 /// /// Protocol structure @@ -400,6 +432,9 @@ struct _XENBUS_PROTOCOL { XENBUS_REGISTER_WATCH_BACKEND RegisterWatchBackend; XENBUS_UNREGISTER_WATCH UnregisterWatch; XENBUS_WAIT_FOR_WATCH WaitForWatch; + + XENBUS_SET_EXIT_CALLBACK RegisterExitCallback; + // // Protocol data fields // diff --git a/OvmfPkg/XenBusDxe/XenBus.c b/OvmfPkg/XenBusDxe/XenBus.c index 78835ec7b3..54166505d2 100644 --- a/OvmfPkg/XenBusDxe/XenBus.c +++ b/OvmfPkg/XenBusDxe/XenBus.c @@ -343,6 +343,23 @@ XenBusSetState ( return Status; } =20 +STATIC +VOID +EFIAPI +XenBusRegisterExitCallback ( + IN XENBUS_PROTOCOL *This, + IN XENBUS_EXIT_CALLBACK NotifyFunction, + IN VOID *NotifyContext + ) +{ + XENBUS_PRIVATE_DATA *Dev; + + Dev =3D XENBUS_PRIVATE_DATA_FROM_THIS (This); + + Dev->ExitCallback =3D NotifyFunction; + Dev->ExitCallbackContext =3D NotifyContext; +} + STATIC XENBUS_PRIVATE_DATA gXenBusPrivateData =3D { XENBUS_PRIVATE_DATA_SIGNATURE, // Signature { NULL, NULL }, // Link @@ -364,6 +381,7 @@ STATIC XENBUS_PRIVATE_DATA gXenBusPrivateData =3D { XenBusRegisterWatchBackend, // XenBusIo.RegisterWatchBackend XenBusUnregisterWatch, // XenBusIo.UnregisterWatch XenBusWaitForWatch, // XenBusIo.WaitForWatch + XenBusRegisterExitCallback, // XenBusIo.RegisterExitCallback =20 NULL, // XenBusIo.Type 0, // XenBusIo.DeviceId diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.c b/OvmfPkg/XenBusDxe/XenBusDxe.c index 634c7b71eb..c71966a666 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.c +++ b/OvmfPkg/XenBusDxe/XenBusDxe.c @@ -258,10 +258,31 @@ NotifyExitBoot ( IN VOID *Context ) { - XENBUS_DEVICE *Dev =3D Context; + XENBUS_DEVICE *Dev; + LIST_ENTRY *Entry; + XENBUS_PRIVATE_DATA *Child; =20 - gBS->DisconnectController(Dev->ControllerHandle, - Dev->This->DriverBindingHandle, NULL); + Dev =3D Context; + + // + // First, ask every driver using xenbus to disconnect without + // deallocating memory. + // + for (Entry =3D GetFirstNode (&Dev->ChildList); + !IsNodeAtEnd (&Dev->ChildList, Entry); + Entry =3D GetNextNode (&Dev->ChildList, Entry)) { + Child =3D XENBUS_PRIVATE_DATA_FROM_LINK (Entry); + if (Child->ExitCallback !=3D NULL) { + Child->ExitCallback (Child->ExitCallbackContext); + } + } + + // + // Now, we can reset the devices used by XenBusDxe. + // + XenStoreResetWatches (); + XenStoreResetRing (Dev); + XenGrantTableDeinit (Dev); } =20 /** diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.h b/OvmfPkg/XenBusDxe/XenBusDxe.h index b1dcc3549c..0e91c24338 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.h +++ b/OvmfPkg/XenBusDxe/XenBusDxe.h @@ -94,6 +94,8 @@ typedef struct { XENBUS_PROTOCOL XenBusIo; XENBUS_DEVICE *Dev; XENBUS_DEVICE_PATH *DevicePath; + XENBUS_EXIT_CALLBACK ExitCallback; + VOID *ExitCallbackContext; } XENBUS_PRIVATE_DATA; =20 #define XENBUS_PRIVATE_DATA_FROM_THIS(a) \ diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index cb2d9e1215..4026c8a829 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -1054,8 +1054,18 @@ XenStoreDeinit ( } } =20 + XenStoreResetRing (Dev); + gBS->CloseEvent (xs.EventChannelEvent); =20 + xs.XenStore =3D NULL; +} + +VOID +XenStoreResetRing ( + IN XENBUS_DEVICE *Dev + ) +{ if (xs.XenStore->server_features & XENSTORE_SERVER_FEATURE_RECONNECTION)= { xs.XenStore->connection =3D XENSTORE_RECONNECT; XenEventChannelNotify (xs.Dev, xs.EventChannel); @@ -1072,7 +1082,17 @@ XenStoreDeinit ( xs.XenStore->req_cons =3D xs.XenStore->req_prod =3D 0; xs.XenStore->rsp_cons =3D xs.XenStore->rsp_prod =3D 0; } - xs.XenStore =3D NULL; +} + +VOID +XenStoreResetWatches ( + VOID + ) +{ + XENSTORE_STATUS Status; + + Status =3D XenStoreSingle (XST_NIL, XS_RESET_WATCHES, "", NULL, NULL, NU= LL); + ASSERT (Status =3D=3D XENSTORE_STATUS_SUCCESS); } =20 // diff --git a/OvmfPkg/XenBusDxe/XenStore.h b/OvmfPkg/XenBusDxe/XenStore.h index ca8c080433..62cd5e97bf 100644 --- a/OvmfPkg/XenBusDxe/XenStore.h +++ b/OvmfPkg/XenBusDxe/XenStore.h @@ -271,6 +271,27 @@ XenStoreDeinit ( IN XENBUS_DEVICE *Dev ); =20 +/** + Effectively reset all watches registered with xenstore. + + To be used by ExitBootServices +**/ +VOID +XenStoreResetWatches ( + VOID + ); + +/** + Reset the xenstore shared ring before handing it over to the next + operating system. + + To be used by ExitBootServices +**/ +VOID +XenStoreResetRing ( + IN XENBUS_DEVICE *Dev + ); + =20 // // XENBUS protocol --=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 (#47214): https://edk2.groups.io/g/devel/message/47214 Mute This Topic: https://groups.io/mt/34128015/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- From nobody Thu May 2 18:38:31 2024 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+47219+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568387432; cv=none; d=zoho.com; s=zohoarc; b=Yp1XqgA6usbg0tzMbCZxdaIzul9kv5a8w7GKVY79u3BL+L+T6Q0WS3pWJw7pQc87xNuNXamEBLOfGU0mZfiQTAmrfGrcEIfDiFxyia/xu/TfImIu0QQJLyIa4GrH9aZw7CBigij12j0IiHeMTc39j6lxgmmFFEyEIksBXoKtAhg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568387432; 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=D+8fE7sgX0zJBNVkoVVVZ0e04FsYsOI8/bUiiKeekOM=; b=SYrezhkNST8ujqeqMc2B0eQg03Lj3JNl/g9HbyU6FiAAvLDPmr09ftczpwN4Fh20fElBBoynJUs3TcBtBaa815ylHTbnYvwUzkO5M30Y+N03Km32lclO4akK7fJOmBzQihlgI4Cd3PKgsuRqtvtOmGJRXmPULIhqE9ovZBZVgWA= 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+47219+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568387432771415.61360660221897; Fri, 13 Sep 2019 08:10:32 -0700 (PDT) Return-Path: X-Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by groups.io with SMTP; Fri, 13 Sep 2019 08:10:31 -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+47219+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: None (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.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=esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: jKNjfD94l42Q3RU1kETUtDK3BoZfgdnGxZKNfArJEbDyFTLgaUPdTvRJiksIMPWuyRfkDwS6u/ N8186rlpfPEy5uUT1ADwebTEFk0jTEPMykNuGAp1S63AiUtiMP1oHwZ6YELGOw1C3S9kSbnTBY AVxG1Qq7zdVeZ32YQeUHm/YpdQa9Byi9fNKCRnNN83+Fm0KZp2CnUbUvBesosr7d0r5FKYf2hh Vjup/OKT6ogjiGcd5R0bVY/JvIfm2ZND9YS0A4uWk/DMlxHhJDgSBrVSTJkLyStEQhXwtal5ro yG4= X-SBRS: 2.7 X-MesageID: 5543184 X-Ironport-Server: esa3.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="5543184" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 10/11] OvmfPkg/XenPvBlkDxe: Use XenBusIo->RegisterExitCallback Date: Fri, 13 Sep 2019 15:50:59 +0100 Message-ID: <20190913145100.303433-11-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=1568387432; bh=D+8fE7sgX0zJBNVkoVVVZ0e04FsYsOI8/bUiiKeekOM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=DN8rlVQkmT5fQXe6sbRI+D34iwIL/zuj11OfhCv9LKc6vc25wrUX6N48rJHbO6rPpqo UVOf0V9A7N3TflWifmUpyr+xZBMk6fbPJ3TeexQhbGip+EUdFw1WDrvx9Gk0214u9YS1o 6Xjk9PFfYL/xVSbUUB53xv2c8Cq9FpErMhw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" In order to be able to reset the backend before handing it to the next operating system, it should be reset properly. This patch register a callback function to be called by XenBusDxe during the ExitBootServices event. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2190 Signed-off-by: Anthony PERARD --- OvmfPkg/XenPvBlkDxe/BlockFront.c | 37 ++++++++++++++++++++++++++++--- OvmfPkg/XenPvBlkDxe/BlockFront.h | 12 +++++++++- OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c | 4 ++-- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/XenPvBlkDxe/BlockFront.c b/OvmfPkg/XenPvBlkDxe/BlockFr= ont.c index 25a398ccc4..7c166888bd 100644 --- a/OvmfPkg/XenPvBlkDxe/BlockFront.c +++ b/OvmfPkg/XenPvBlkDxe/BlockFront.c @@ -309,6 +309,8 @@ XenPvBlockFrontInitialization ( Dev->MediaInfo.Sectors, Dev->MediaInfo.SectorSize)); =20 *DevPtr =3D Dev; + + XenBusIo->RegisterExitCallback (XenBusIo, XenPvBlockFrontReset, Dev); return EFI_SUCCESS; =20 Error2: @@ -326,13 +328,16 @@ XenPvBlockFrontInitialization ( =20 VOID XenPvBlockFrontShutdown ( - IN XEN_BLOCK_FRONT_DEVICE *Dev + IN XEN_BLOCK_FRONT_DEVICE *Dev, + IN BOOLEAN ResetOnly ) { XENBUS_PROTOCOL *XenBusIo =3D Dev->XenBusIo; XENSTORE_STATUS Status; UINT64 Value; =20 + XenBusIo->RegisterExitCallback (XenBusIo, NULL, NULL); + XenPvBlockSync (Dev); =20 Status =3D XenBusIo->SetState (XenBusIo, XST_NIL, XenbusStateClosing); @@ -393,12 +398,38 @@ XenPvBlockFrontShutdown ( } =20 Close: - XenBusIo->UnregisterWatch (XenBusIo, Dev->StateWatchToken); + if (!ResetOnly) { + XenBusIo->UnregisterWatch (XenBusIo, Dev->StateWatchToken); + } XenBusIo->XsRemove (XenBusIo, XST_NIL, "ring-ref"); XenBusIo->XsRemove (XenBusIo, XST_NIL, "event-channel"); XenBusIo->XsRemove (XenBusIo, XST_NIL, "protocol"); =20 - XenPvBlockFree (Dev); + if (ResetOnly) { + XenBusIo->GrantEndAccess (XenBusIo, Dev->RingRef); + XenBusIo->EventChannelClose (XenBusIo, Dev->EventChannel); + } else { + XenPvBlockFree (Dev); + } +} + +/** + To be called when ExitBootServices has been called. + + This should reset the PV backend without using memory allocation + services. +**/ +VOID +EFIAPI +XenPvBlockFrontReset ( + IN VOID *Context + ) +{ + XEN_BLOCK_FRONT_DEVICE *Dev; + + Dev =3D Context; + + XenPvBlockFrontShutdown (Dev, TRUE); } =20 STATIC diff --git a/OvmfPkg/XenPvBlkDxe/BlockFront.h b/OvmfPkg/XenPvBlkDxe/BlockFr= ont.h index 7c2d7f2c9e..ebce4fe434 100644 --- a/OvmfPkg/XenPvBlkDxe/BlockFront.h +++ b/OvmfPkg/XenPvBlkDxe/BlockFront.h @@ -67,9 +67,19 @@ XenPvBlockFrontInitialization ( OUT XEN_BLOCK_FRONT_DEVICE **DevPtr ); =20 +/** + @param ResetOnly Set to TRUE when called during the ExitBootService= s. +**/ VOID XenPvBlockFrontShutdown ( - IN XEN_BLOCK_FRONT_DEVICE *Dev + IN XEN_BLOCK_FRONT_DEVICE *Dev, + IN BOOLEAN ResetOnly + ); + +VOID +EFIAPI +XenPvBlockFrontReset ( + IN VOID *Context ); =20 VOID diff --git a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c b/OvmfPkg/XenPvBlkDxe/XenPvB= lkDxe.c index bfe7b1a754..3031406980 100644 --- a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c +++ b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c @@ -312,7 +312,7 @@ XenPvBlkDxeDriverBindingStart ( =20 UninitBlockFront: FreePool (Media); - XenPvBlockFrontShutdown (Dev); + XenPvBlockFrontShutdown (Dev, FALSE); CloseProtocol: gBS->CloseProtocol (ControllerHandle, &gXenBusProtocolGuid, This->DriverBindingHandle, ControllerHandle); @@ -377,7 +377,7 @@ XenPvBlkDxeDriverBindingStop ( =20 Media =3D BlockIo->Media; Dev =3D XEN_BLOCK_FRONT_FROM_BLOCK_IO (BlockIo); - XenPvBlockFrontShutdown (Dev); + XenPvBlockFrontShutdown (Dev, FALSE); =20 FreePool (Media); =20 --=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 (#47219): https://edk2.groups.io/g/devel/message/47219 Mute This Topic: https://groups.io/mt/34128218/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- From nobody Thu May 2 18:38:31 2024 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+47218+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568387432; cv=none; d=zoho.com; s=zohoarc; b=D4QH/grQS7TVkrpotvhJK9z/NL6YlqYOfdhkt/iDBR0FVQ2F8EpMHdCOgsa9VlOPgrAHbDUvzkT4WSz4BMVveYBFolz6HC8SvS5eXr1UmtwJZD04OjP/0MJZPImHaknoeKdlVYkAI3Sj1UXwfayheh4oCwIXZ90j3IU5NrCog5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568387432; 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=UxF3D2Xra5I57Uk1/RHdw/slFCQscyGfK9n2X0uRkds=; b=LQ798AnxKktcATSPt2cFFK5Fuap/gbZz3pAe2ZTv78Z5ycmxnd7MJsoeOUgy1wcXQDCDB3AK2+CtI6vnf3P2tcNogt8XsqxMaojFj02fZMSD7hg4KbgX9LEIRSXd/s/qAjbu1+1IOSebQZQ+a2Y4d03jH3dhkjCq/EvmsfzcYhc= 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+47218+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 156838743205177.40860034960792; Fri, 13 Sep 2019 08:10:32 -0700 (PDT) Return-Path: X-Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com [216.71.155.168]) by groups.io with SMTP; Fri, 13 Sep 2019 08:10:30 -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+47218+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: None (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: PUnTOLPs7rYqw+c+YwXX8tZtyXnY5cBfdAscbIj91Eq/nzPnOuK1SD3HhKlSe6GNvBVJwNYVzZ WBjQh6+m1mpmXKa3xQ3Ys3Uw+MKjJpVzQIINYuTbIzTsnwzEZoLYB38EJK02c4+T4qFYVPGaBh uyX6Cck5/AsUjg1ANjuuOnvayEa6qVjZn9InIWCyxNbr7im2Fl8+toiBEWxLY0r393iNuF/Vrr HXqr1oeCJEswBs5476XmRCCdfLpGqiCerwnlaFZz+VKxfpb/eD5sEB5/HvRdMUoeuocu3/pwg7 soc= X-SBRS: 2.7 X-MesageID: 5740999 X-Ironport-Server: esa5.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="5740999" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 11/11] OvmfPkg/XenBusDxe: Fix XenStoreWaitForEvent use during EBS Date: Fri, 13 Sep 2019 15:51:00 +0100 Message-ID: <20190913145100.303433-12-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=1568387431; bh=UxF3D2Xra5I57Uk1/RHdw/slFCQscyGfK9n2X0uRkds=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=w5c/3///aBGLxe+f2MhOBHW5LtDnv/rneYtgtPXw38DtUjhqPeCQqe6F2Ow3pGLJK4G kT4MIHvX3lfbc0Mb8Yr8UNCJnE4SHu8Slukx36O6sIa6lu+I+n1exeX9t0Tq2e+cML0Cy 0p3+r2JrrBu9YQPFzC+/v1HO5DlvbIZMFIc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" XenStoreWaitForEvent is going to be called when the ExitBootServices is signaled, but both CreateEvent and WaitForEvent can't be used. CreateEvent allocate some memory and WaitForEvent can only be used when TPL is TPL_APPLICATION. When ExitBootServices has been called, simply return immediately and let caller of XenStoreWaitForEvent do a busy loop. Also cleanup error handling in XenStoreWaitForEvent, WaitForEvent shouldn't return EFI_UNSUPPORTED anymore. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2190 Signed-off-by: Anthony PERARD --- OvmfPkg/XenBusDxe/XenBusDxe.c | 2 ++ OvmfPkg/XenBusDxe/XenBusDxe.h | 1 + OvmfPkg/XenBusDxe/XenStore.c | 13 +++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.c b/OvmfPkg/XenBusDxe/XenBusDxe.c index c71966a666..eb1503ad2b 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.c +++ b/OvmfPkg/XenBusDxe/XenBusDxe.c @@ -264,6 +264,8 @@ NotifyExitBoot ( =20 Dev =3D Context; =20 + Dev->ExitBootNotified =3D TRUE; + // // First, ask every driver using xenbus to disconnect without // deallocating memory. diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.h b/OvmfPkg/XenBusDxe/XenBusDxe.h index 0e91c24338..80162fc3ff 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.h +++ b/OvmfPkg/XenBusDxe/XenBusDxe.h @@ -79,6 +79,7 @@ struct _XENBUS_DEVICE { EFI_HANDLE ControllerHandle; XENIO_PROTOCOL *XenIo; EFI_EVENT ExitBootEvent; + BOOLEAN ExitBootNotified; EFI_DEVICE_PATH_PROTOCOL *DevicePath; LIST_ENTRY ChildList; =20 diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index 4026c8a829..4f126109d4 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -401,17 +401,22 @@ XenStoreWaitForEvent ( EFI_EVENT TimerEvent; EFI_EVENT WaitList[2]; =20 + // + // If the ExitBootServices event have been signaled, simply allow to have + // busy loop in the caller. + // + if (xs.Dev->ExitBootNotified) { + return EFI_SUCCESS; + } + gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent); gBS->SetTimer (TimerEvent, TimerRelative, Timeout); =20 WaitList[0] =3D xs.EventChannelEvent; WaitList[1] =3D TimerEvent; Status =3D gBS->WaitForEvent (2, WaitList, &Index); - ASSERT (Status !=3D EFI_INVALID_PARAMETER); + ASSERT_EFI_ERROR (Status); gBS->CloseEvent (TimerEvent); - if (Status =3D=3D EFI_UNSUPPORTED) { - return EFI_SUCCESS; - } if (Index =3D=3D 1) { return EFI_TIMEOUT; } else { --=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 (#47218): https://edk2.groups.io/g/devel/message/47218 Mute This Topic: https://groups.io/mt/34128216/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-