From patchwork Fri Sep 13 14:50:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 271EB14E5 for ; Fri, 13 Sep 2019 14:52:29 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0289B20830 for ; Fri, 13 Sep 2019 14:52:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="KBaY5nnE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0289B20830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mup-0005TM-Tx; Fri, 13 Sep 2019 14:51:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mup-0005TD-Dt for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 14:51:15 +0000 X-Inumbo-ID: e9569524-d635-11e9-978d-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e9569524-d635-11e9-978d-bc764e2007e4; Fri, 13 Sep 2019 14:51:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568386265; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TMDZnDSkQb+NUTB+SGoIs+MGs//spkp8cNqNd9g8ssE=; b=KBaY5nnE2VgJzPyW9Zf8OCQ5ceOtoJiIhXeBfQ0lxzBrfY1M5POVkZTE 4sWjy0Ks0MkVg5qYWqJzLDFODYPlMYPgWCCf+4fx1IOH77oJHkICDo1Ah s2BFHqVPnsOZbCI1noTUY0f33DEaVUDYv3srYa0MIC32dCX5nr+L8KxIc Q=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 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: Date: Fri, 13 Sep 2019 15:50:50 +0100 Message-ID: <20190913145100.303433-2-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 01/11] OvmfPkg/XenBusDxe: Fix missing \n in DEBUG messages X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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/EventChannel.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 != 0) { - DEBUG ((EFI_D_ERROR, "ERROR: alloc_unbound failed with rc=%d", ReturnCode)); + DEBUG ((DEBUG_ERROR, "ERROR: alloc_unbound failed with rc=%d\n", + ReturnCode)); return ReturnCode; } *Port = 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 = XenStoreProcessMessage (); if (Status != XENSTORE_STATUS_SUCCESS && Status != 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, cleaning up...")); + DEBUG ((DEBUG_WARN, "XenStore: RegisteredWatches is not empty, cleaning up...\n")); Entry = GetFirstNode (&xs.RegisteredWatches); while (!IsNull (&xs.RegisteredWatches, Entry)) { Watch = 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 = GetFirstNode (&xs.WatchEvents); while (!IsNull (&xs.WatchEvents, Entry)) { XENSTORE_MESSAGE *Message = XENSTORE_MESSAGE_FROM_LINK (Entry); From patchwork Fri Sep 13 14:50:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144865 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1978A14E5 for ; Fri, 13 Sep 2019 14:53:00 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EAA7020830 for ; Fri, 13 Sep 2019 14:52:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="JKbGcEW3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EAA7020830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8muv-0005Us-8l; Fri, 13 Sep 2019 14:51:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8muu-0005Uc-DS for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 14:51:20 +0000 X-Inumbo-ID: ea028ffa-d635-11e9-978d-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ea028ffa-d635-11e9-978d-bc764e2007e4; Fri, 13 Sep 2019 14:51:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568386266; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0dgQPbTWjI6SwMzyC59lA5IDiOJiBrPsrvs1zX2XlKE=; b=JKbGcEW3my7JlqprIRuVcv9Vi9hqJo4UoL2h1u2YiLDjFjk9iPOH+s6a 2cqsbVf4aoicNwJT+wavXBEmDG3GCHe+oHYY1Ys68Zb3cH7QppU+WgYva h8ytXtNVWv8ZJJkERZVBtgNXfqsgtWRJy2CHnV5y3l2Qgv0T+T5nMbqUp k=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 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: Date: Fri, 13 Sep 2019 15:50:51 +0100 Message-ID: <20190913145100.303433-3-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 02/11] OvmfPkg/XenBusDxe: Have XenStoreFindWatch take a pointer X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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=2190 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; - WantedWatch = (VOID *) AsciiStrHexToUintn (Token); - if (IsListEmpty (&xs.RegisteredWatches)) { return NULL; } @@ -268,7 +266,7 @@ XenStoreFindWatch ( !IsNull (&xs.RegisteredWatches, Entry); Entry = GetNextNode (&xs.RegisteredWatches, Entry)) { Watch = XENSTORE_WATCH_FROM_LINK (Entry); - if (Watch == WantedWatch) + if ((VOID *) Watch == Token) return Watch; } @@ -632,12 +630,16 @@ XenStoreProcessMessage ( Body[Message->Header.len] = '\0'; if (Message->Header.type == XS_WATCH_EVENT) { + VOID *ConvertedToken; + Message->u.Watch.Vector = Split(Body, Message->Header.len, &Message->u.Watch.VectorSize); + ConvertedToken = + (VOID *) AsciiStrHexToUintn (Message->u.Watch.Vector[XS_WATCH_TOKEN]); + EfiAcquireLock (&xs.RegisteredWatchesLock); - Message->u.Watch.Handle = - XenStoreFindWatch (Message->u.Watch.Vector[XS_WATCH_TOKEN]); + Message->u.Watch.Handle = XenStoreFindWatch (ConvertedToken); DEBUG ((EFI_D_INFO, "XenStore: Watch event %a\n", Message->u.Watch.Vector[XS_WATCH_TOKEN])); if (Message->u.Watch.Handle != NULL) { @@ -1384,8 +1386,7 @@ XenStoreUnregisterWatch ( ASSERT (Watch->Signature == XENSTORE_WATCH_SIGNATURE); - AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch); - if (XenStoreFindWatch (Token) == NULL) { + if (XenStoreFindWatch (Watch) == NULL) { return; } @@ -1393,6 +1394,7 @@ XenStoreUnregisterWatch ( RemoveEntryList (&Watch->Link); EfiReleaseLock (&xs.RegisteredWatchesLock); + AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch); XenStoreUnwatch (Watch->Node, Token); /* Cancel pending watch events. */ From patchwork Fri Sep 13 14:50:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144859 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D5C8184E for ; Fri, 13 Sep 2019 14:52:42 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F27F020830 for ; Fri, 13 Sep 2019 14:52:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="UA+i7eh9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F27F020830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mv0-0005XL-Px; Fri, 13 Sep 2019 14:51:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8muz-0005Wq-E3 for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 14:51:25 +0000 X-Inumbo-ID: ea17d95a-d635-11e9-b299-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ea17d95a-d635-11e9-b299-bc764e2007e4; Fri, 13 Sep 2019 14:51:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568386266; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MvZAqnUeNYGp3dUJM1f4tBOK3u+vLW3v45E5PKUzDSQ=; b=UA+i7eh9deZfbcz2CCLYFiHIKLkYbbMu6p4H/19RasEAfLWrEfxVwy9e +B5MI7JYRs19M2bARbpbVd4/FAELPynwgH7JWx79tMDA2rjatIUMKNOYi 5sTARt61Yd/GntyljTi6ENZKSA9PbwhirdrLaP1IH0YYl5Ww0E0uCBK6y k=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 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: Date: Fri, 13 Sep 2019 15:50:52 +0100 Message-ID: <20190913145100.303433-4-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 03/11] OvmfPkg/XenBusDxe: Rework watch events reception X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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=2190 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 /* Path being watched. */ CHAR8 *Node; + + BOOLEAN Triggered; }; #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; - /** - * 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] = '\0'; if (Message->Header.type == XS_WATCH_EVENT) { - VOID *ConvertedToken; + CONST CHAR8 *WatchEventPath; + CONST CHAR8 *WatchEventToken; + VOID *ConvertedToken; + XENSTORE_WATCH *Watch; - Message->u.Watch.Vector = Split(Body, Message->Header.len, - &Message->u.Watch.VectorSize); + // + // Parse WATCH_EVENT messages + // \0\0 + // + WatchEventPath = Body; + WatchEventToken = WatchEventPath + AsciiStrSize (WatchEventPath); - ConvertedToken = - (VOID *) AsciiStrHexToUintn (Message->u.Watch.Vector[XS_WATCH_TOKEN]); + ConvertedToken = (VOID *) AsciiStrHexToUintn (WatchEventToken); EfiAcquireLock (&xs.RegisteredWatchesLock); - Message->u.Watch.Handle = XenStoreFindWatch (ConvertedToken); - DEBUG ((EFI_D_INFO, "XenStore: Watch event %a\n", - Message->u.Watch.Vector[XS_WATCH_TOKEN])); - if (Message->u.Watch.Handle != NULL) { - EfiAcquireLock (&xs.WatchEventsLock); - InsertHeadList (&xs.WatchEvents, &Message->Link); - EfiReleaseLock (&xs.WatchEventsLock); + Watch = XenStoreFindWatch (ConvertedToken); + DEBUG ((DEBUG_INFO, "XenStore: Watch event %a\n", WatchEventToken)); + if (Watch != NULL) { + Watch->Triggered = 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 = Body; EfiAcquireLock (&xs.ReplyLock); @@ -936,40 +926,29 @@ XenStoreUnwatch ( STATIC XENSTORE_STATUS XenStoreWaitWatch ( - VOID *Token + IN VOID *Token ) { - XENSTORE_MESSAGE *Message; - LIST_ENTRY *Entry = NULL; - LIST_ENTRY *Last = NULL; + XENSTORE_WATCH *Watch; XENSTORE_STATUS Status; + EfiAcquireLock (&xs.RegisteredWatchesLock); + Watch = XenStoreFindWatch (Token); + EfiReleaseLock (&xs.RegisteredWatchesLock); + if (Watch == NULL) { + return XENSTORE_STATUS_EINVAL; + } + while (TRUE) { - EfiAcquireLock (&xs.WatchEventsLock); - if (IsListEmpty (&xs.WatchEvents) || - Last == GetFirstNode (&xs.WatchEvents)) { - EfiReleaseLock (&xs.WatchEventsLock); - Status = XenStoreProcessMessage (); - if (Status != XENSTORE_STATUS_SUCCESS && Status != XENSTORE_STATUS_EAGAIN) { - return Status; - } - continue; + if (Watch->Triggered) { + Watch->Triggered = FALSE; + return XENSTORE_STATUS_SUCCESS; } - for (Entry = GetFirstNode (&xs.WatchEvents); - Entry != Last && !IsNull (&xs.WatchEvents, Entry); - Entry = GetNextNode (&xs.WatchEvents, Entry)) { - Message = XENSTORE_MESSAGE_FROM_LINK (Entry); - if (Message->u.Watch.Handle == Token) { - RemoveEntryList (Entry); - EfiReleaseLock (&xs.WatchEventsLock); - FreePool((VOID*)Message->u.Watch.Vector); - FreePool(Message); - return XENSTORE_STATUS_SUCCESS; - } + Status = XenStoreProcessMessage (); + if (Status != XENSTORE_STATUS_SUCCESS && Status != XENSTORE_STATUS_EAGAIN) { + return Status; } - Last = GetFirstNode (&xs.WatchEvents); - EfiReleaseLock (&xs.WatchEventsLock); } } @@ -1052,12 +1031,10 @@ XenStoreInit ( xs.XenStore, xs.EventChannel)); InitializeListHead (&xs.ReplyList); - InitializeListHead (&xs.WatchEvents); InitializeListHead (&xs.RegisteredWatches); EfiInitializeLock (&xs.ReplyLock, TPL_NOTIFY); EfiInitializeLock (&xs.RegisteredWatchesLock, TPL_NOTIFY); - EfiInitializeLock (&xs.WatchEventsLock, TPL_NOTIFY); /* Initialize the shared memory rings to talk to xenstored */ Status = XenStoreInitComms (&xs); @@ -1088,23 +1065,6 @@ XenStoreDeinit ( } } - // - // 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 = GetFirstNode (&xs.WatchEvents); - while (!IsNull (&xs.WatchEvents, Entry)) { - XENSTORE_MESSAGE *Message = XENSTORE_MESSAGE_FROM_LINK (Entry); - Entry = 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; ASSERT (Watch->Signature == XENSTORE_WATCH_SIGNATURE); @@ -1397,20 +1356,6 @@ XenStoreUnregisterWatch ( AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch); XenStoreUnwatch (Watch->Node, Token); - /* Cancel pending watch events. */ - EfiAcquireLock (&xs.WatchEventsLock); - Entry = GetFirstNode (&xs.WatchEvents); - while (!IsNull (&xs.WatchEvents, Entry)) { - XENSTORE_MESSAGE *Message = XENSTORE_MESSAGE_FROM_LINK (Entry); - Entry = GetNextNode (&xs.WatchEvents, Entry); - if (Message->u.Watch.Handle == Watch) { - RemoveEntryList (&Message->Link); - FreePool ((VOID*)Message->u.Watch.Vector); - FreePool (Message); - } - } - EfiReleaseLock (&xs.WatchEventsLock); - FreePool (Watch->Node); FreePool (Watch); } From patchwork Fri Sep 13 14:50:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144863 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F3721599 for ; Fri, 13 Sep 2019 14:52:58 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B17D20830 for ; Fri, 13 Sep 2019 14:52:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="N0b4e/W5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B17D20830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mul-0005SL-KX; Fri, 13 Sep 2019 14:51:11 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8muk-0005S7-Dy for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 14:51:10 +0000 X-Inumbo-ID: e99354f0-d635-11e9-b299-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e99354f0-d635-11e9-b299-bc764e2007e4; Fri, 13 Sep 2019 14:51:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568386265; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8kxur/mrODtHigFPsFoV90xNxdXr64amXia1NhFTkes=; b=N0b4e/W5dW6nfvwep+5p1iF2qPT1FEbXhArZAzuznhziwVdVTG9M6RD7 mfghzSKqendhLDteUvq3Xomr58ZoOnVvczjTUd5GqM4tHeTC0v7kb/2Z2 KJwaAn3yCP+GZoD3le5iYVyqxtcb8grV2IooSbzVqW6FkZgDwvdkgrnYl I=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 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: Date: Fri, 13 Sep 2019 15:50:53 +0100 Message-ID: <20190913145100.303433-5-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 04/11] OvmfPkg/XenBusDxe: Avoid Allocate in XenStoreVSPrint X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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=2190 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; - VA_COPY (Marker2, Marker); - BufSize = SPrintLengthAsciiFormat (FormatString, Marker2) + 1; - VA_END (Marker2); - Buf = AllocateZeroPool (BufSize); - AsciiVSPrint (Buf, BufSize, FormatString, Marker); - Status = XenStoreWrite (Transaction, DirectoryPath, Node, Buf); - FreePool (Buf); + Count = AsciiVSPrint (Buf, sizeof (Buf), FormatString, Marker); + ASSERT (Count > 0); + ASSERT (Count < sizeof (Buf)); + if ((Count == 0) || (Count >= sizeof (Buf))) { + return XENSTORE_STATUS_EINVAL; + } - return Status; + return XenStoreWrite (Transaction, DirectoryPath, Node, Buf); } XENSTORE_STATUS From patchwork Fri Sep 13 14:50:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144871 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCD8A14E5 for ; Fri, 13 Sep 2019 14:53:29 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A9AAD20830 for ; Fri, 13 Sep 2019 14:53:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="ZfPBukPD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9AAD20830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mvG-0005fa-0d; Fri, 13 Sep 2019 14:51:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mvE-0005eq-Em for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 14:51:40 +0000 X-Inumbo-ID: eb493062-d635-11e9-978d-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id eb493062-d635-11e9-978d-bc764e2007e4; Fri, 13 Sep 2019 14:51:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568386268; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jTKvjUp5MG+SlTcncG/XYtjxy0nl66C15Z37YLYDQ0Q=; b=ZfPBukPDr9GKJ6LqeFQtte3N1p3xbXh5Ibimvawxr73gdydKkcG7a709 eMI/AZ+xSQnhw6bSkgmmqrYw99Yjmbsz6Y6fq18/dcv0ajuIunGtOycaf zDz80FzGDA8aH1G3JJOYUCPSYIYv12pWxVMBHsHyY8xiNS63rneZXgpB6 Q=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: lYc55WjN7DLFF/94kPZhz/5fiRMImHBHN9+v6Yr2BSEsGGkaV0QxtOu/syDD4oBCrr8YaS5gMD TdBOTowDeAFuDbK5Sp4NROknBTxyrQrajgwZsxYmnEdjXSRYQFhOTfsLt6HfJ/j5nFcMWXQPPA 7IxbwL6n4ifCH7D/F8IZWHvvZd64d91ZUbBVXJMAVEjg9gynWSxHBSNKi2TQ6JYhwEQ8xH79g2 OC6euPSkxNZxleGuTbhaEr+PPAmJwNeHyOKaPneZUDfdZH/4EypDz8Iy/vahUMBrcQFYFKSXcR dJM= X-SBRS: 2.7 X-MesageID: 5595149 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,501,1559534400"; d="scan'208";a="5595149" From: Anthony PERARD To: Date: Fri, 13 Sep 2019 15:50:54 +0100 Message-ID: <20190913145100.303433-6-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 05/11] OvmfPkg/XenBusDxe: Construct paths without allocation X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" When doing an action with a path and subpath in the xenstore, XenStoreJoin is called to generate "$path/$subpath". But this function do an allocation of memory which isn't necessary. Instead we will construct the path with WRITE_REQUEST and data used to generate the path will be copied directly to the xenstore shared ring. Also change WRITE_REQUEST.Len type, it only contain sizes and doesn't need to be exactly 32bits. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190 Signed-off-by: Anthony PERARD Reviewed-by: Laszlo Ersek --- OvmfPkg/XenBusDxe/XenStore.c | 78 +++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index 7b71dc156d..ca7be12d68 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -53,7 +53,7 @@ typedef struct { CONST VOID *Data; - UINT32 Len; + UINTN Len; } WRITE_REQUEST; /* Register callback to watch subtree (node) in the XenStore. */ @@ -260,6 +260,35 @@ XenStoreFindWatch ( return NULL; } +/** + Fill the first three slots of a WRITE_REQUEST array. + + When those three slots are concatenated to generate a string, the resulting + string will be "$Path\0" or "$Path/$SubPath\0" if SubPath is provided. +**/ +STATIC +VOID +XenStorePrepareWriteRequest ( + IN OUT WRITE_REQUEST *WriteRequest, + IN CONST CHAR8 *Path, + IN CONST CHAR8 *SubPath OPTIONAL + ) +{ + SetMem(WriteRequest, 3 * sizeof (WRITE_REQUEST), 0); + WriteRequest[0].Data = Path; + WriteRequest[0].Len = AsciiStrSize (Path); + if (SubPath != NULL && SubPath[0] != '\0') { + // + // Remove the \0 from the first part of the request. + // + WriteRequest[0].Len--; + WriteRequest[1].Data = "/"; + WriteRequest[1].Len = 1; + WriteRequest[2].Data = SubPath; + WriteRequest[2].Len = AsciiStrSize (SubPath); + } +} + // // Public Utility Functions // API comments for these methods can be found in XenStore.h @@ -842,6 +871,7 @@ XenStoreTalkv ( @param Transaction The transaction to use for this request. @param RequestType The type of message to send. @param Body The body of the request. + @param SubPath If !NULL and not "", "/$SubPath" is append to Body. @param LenPtr The returned length of the reply. @param Result The returned body of the reply. @@ -854,16 +884,16 @@ XenStoreSingle ( IN CONST XENSTORE_TRANSACTION *Transaction, IN enum xsd_sockmsg_type RequestType, IN CONST CHAR8 *Body, + IN CONST CHAR8 *SubPath OPTIONAL, OUT UINT32 *LenPtr OPTIONAL, OUT VOID **Result OPTIONAL ) { - WRITE_REQUEST WriteRequest; + WRITE_REQUEST WriteRequest[3]; - WriteRequest.Data = (VOID *) Body; - WriteRequest.Len = (UINT32)AsciiStrSize (Body); + XenStorePrepareWriteRequest (WriteRequest, Body, SubPath); - return XenStoreTalkv (Transaction, RequestType, &WriteRequest, 1, + return XenStoreTalkv (Transaction, RequestType, WriteRequest, 3, LenPtr, Result); } @@ -1113,15 +1143,12 @@ XenStoreListDirectory ( OUT CONST CHAR8 ***DirectoryListPtr ) { - CHAR8 *Path; CHAR8 *TempStr; UINT32 Len = 0; XENSTORE_STATUS Status; - Path = XenStoreJoin (DirectoryPath, Node); - Status = XenStoreSingle (Transaction, XS_DIRECTORY, Path, &Len, + Status = XenStoreSingle (Transaction, XS_DIRECTORY, DirectoryPath, Node, &Len, (VOID **) &TempStr); - FreePool (Path); if (Status != XENSTORE_STATUS_SUCCESS) { return Status; } @@ -1160,13 +1187,11 @@ XenStoreRead ( OUT VOID **Result ) { - CHAR8 *Path; VOID *Value; XENSTORE_STATUS Status; - Path = XenStoreJoin (DirectoryPath, Node); - Status = XenStoreSingle (Transaction, XS_READ, Path, LenPtr, &Value); - FreePool (Path); + Status = XenStoreSingle (Transaction, XS_READ, DirectoryPath, Node, + LenPtr, &Value); if (Status != XENSTORE_STATUS_SUCCESS) { return Status; } @@ -1183,21 +1208,13 @@ XenStoreWrite ( IN CONST CHAR8 *Str ) { - CHAR8 *Path; - WRITE_REQUEST WriteRequest[2]; - XENSTORE_STATUS Status; + WRITE_REQUEST WriteRequest[4]; - Path = XenStoreJoin (DirectoryPath, Node); + XenStorePrepareWriteRequest (WriteRequest, DirectoryPath, Node); + WriteRequest[3].Data = Str; + WriteRequest[3].Len = AsciiStrLen (Str); - WriteRequest[0].Data = (VOID *) Path; - WriteRequest[0].Len = (UINT32)AsciiStrSize (Path); - WriteRequest[1].Data = (VOID *) Str; - WriteRequest[1].Len = (UINT32)AsciiStrLen (Str); - - Status = XenStoreTalkv (Transaction, XS_WRITE, WriteRequest, 2, NULL, NULL); - FreePool (Path); - - return Status; + return XenStoreTalkv (Transaction, XS_WRITE, WriteRequest, 4, NULL, NULL); } XENSTORE_STATUS @@ -1207,12 +1224,9 @@ XenStoreRemove ( IN CONST CHAR8 *Node ) { - CHAR8 *Path; XENSTORE_STATUS Status; - Path = XenStoreJoin (DirectoryPath, Node); - Status = XenStoreSingle (Transaction, XS_RM, Path, NULL, NULL); - FreePool (Path); + Status = XenStoreSingle (Transaction, XS_RM, DirectoryPath, Node, NULL, NULL); return Status; } @@ -1226,7 +1240,7 @@ XenStoreTransactionStart ( XENSTORE_STATUS Status; Status = XenStoreSingle (XST_NIL, XS_TRANSACTION_START, "", NULL, - (VOID **) &IdStr); + NULL, (VOID **) &IdStr); if (Status == XENSTORE_STATUS_SUCCESS) { Transaction->Id = (UINT32)AsciiStrDecimalToUintn (IdStr); FreePool (IdStr); @@ -1246,7 +1260,7 @@ XenStoreTransactionEnd ( AbortStr[0] = Abort ? 'F' : 'T'; AbortStr[1] = '\0'; - return XenStoreSingle (Transaction, XS_TRANSACTION_END, AbortStr, NULL, NULL); + return XenStoreSingle (Transaction, XS_TRANSACTION_END, AbortStr, NULL, NULL, NULL); } XENSTORE_STATUS From patchwork Fri Sep 13 14:50:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144869 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3F4314E5 for ; Fri, 13 Sep 2019 14:53:16 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 83C2920830 for ; Fri, 13 Sep 2019 14:53:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="cWQ4IXjb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83C2920830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mv5-0005Zk-4l; Fri, 13 Sep 2019 14:51:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mv4-0005ZV-EF for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 14:51:30 +0000 X-Inumbo-ID: ea7d0a82-d635-11e9-978d-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ea7d0a82-d635-11e9-978d-bc764e2007e4; Fri, 13 Sep 2019 14:51:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568386267; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZzMuAekQ0s9/ThuMWqy291Ul+rre0jXW0+bqi1wWX1E=; b=cWQ4IXjbUU/KB+uNsRiF29db7dCnVirMA9WX1skaT/za5pkaFfDTg7Ne ZsLR+TyqlShaoYzoFhcxduCp0yoZmenkhVQSBmOJiU0A6byeLK6llxr6o hzBD9ScZnypGi1JL5SlMQph8ZMo5aIJtyo+uDh8fuj32O0P7idwHj0Ieu A=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 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: Date: Fri, 13 Sep 2019 15:50:55 +0100 Message-ID: <20190913145100.303433-7-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 06/11] OvmfPkg/XenBusDxe: Rework XenStoreProcessMessage to avoid allocating memory X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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=2190 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) - -/** - * 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 { XENBUS_DEVICE *Dev; - /** - * 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 { /** 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; // @@ -148,6 +119,12 @@ static XENSTORE_PRIVATE xs; // Private Utility Functions // +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. + @param ExpectedRequestId Block until a reply to with this ID is seen. + @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 = AllocateZeroPool (sizeof (XENSTORE_MESSAGE)); - Message->Signature = XENSTORE_MESSAGE_SIGNATURE; - Status = XenStoreReadStore (&Message->Header, sizeof (Message->Header)); - if (Status != XENSTORE_STATUS_SUCCESS) { - FreePool (Message); - DEBUG ((EFI_D_ERROR, "XenStore: Error read store (%d)\n", Status)); - return Status; - } - - Body = AllocatePool (Message->Header.len + 1); - Status = XenStoreReadStore (Body, Message->Header.len); - if (Status != XENSTORE_STATUS_SUCCESS) { - FreePool (Body); - FreePool (Message); - DEBUG ((EFI_D_ERROR, "XenStore: Error read store (%d)\n", Status)); - return Status; - } - Body[Message->Header.len] = '\0'; + struct xsd_sockmsg Header; + CHAR8 *Payload; + XENSTORE_STATUS Status; - if (Message->Header.type == XS_WATCH_EVENT) { - CONST CHAR8 *WatchEventPath; - CONST CHAR8 *WatchEventToken; - VOID *ConvertedToken; - XENSTORE_WATCH *Watch; + while (TRUE) { - // - // Parse WATCH_EVENT messages - // \0\0 - // - WatchEventPath = Body; - WatchEventToken = WatchEventPath + AsciiStrSize (WatchEventPath); + Status = XenStoreReadStore (&Header, sizeof (Header)); + if (Status != XENSTORE_STATUS_SUCCESS) { + DEBUG ((DEBUG_ERROR, "XenStore: Error read store (%d)\n", Status)); + return Status; + } - ConvertedToken = (VOID *) AsciiStrHexToUintn (WatchEventToken); + ASSERT (Header.len <= 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 = XENSTORE_PAYLOAD_MAX; + } - EfiAcquireLock (&xs.RegisteredWatchesLock); - Watch = XenStoreFindWatch (ConvertedToken); - DEBUG ((DEBUG_INFO, "XenStore: Watch event %a\n", WatchEventToken)); - if (Watch != NULL) { - Watch->Triggered = TRUE; - } else { - DEBUG ((EFI_D_WARN, "XenStore: Watch handle %a not found\n", - WatchEventToken)); + Payload = xs.Buffer; + Status = XenStoreReadStore (Payload, Header.len); + if (Status != 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 = Body; - EfiAcquireLock (&xs.ReplyLock); - InsertTailList (&xs.ReplyList, &Message->Link); - EfiReleaseLock (&xs.ReplyLock); + Payload[Header.len] = '\0'; + + if (Header.type == XS_WATCH_EVENT) { + CONST CHAR8 *WatchEventPath; + CONST CHAR8 *WatchEventToken; + VOID *ConvertedToken; + XENSTORE_WATCH *Watch; + + // + // Parse WATCH_EVENT messages + // \0\0 + // + WatchEventPath = Payload; + WatchEventToken = WatchEventPath + AsciiStrSize (WatchEventPath); + + ConvertedToken = (VOID *) AsciiStrHexToUintn (WatchEventToken); + + EfiAcquireLock (&xs.RegisteredWatchesLock); + Watch = XenStoreFindWatch (ConvertedToken); + DEBUG ((DEBUG_INFO, "XenStore: Watch event %a\n", WatchEventToken)); + if (Watch != NULL) { + Watch->Triggered = TRUE; + } else { + DEBUG ((DEBUG_WARN, "XenStore: Watch handle %a not found\n", + WatchEventToken)); + } + EfiReleaseLock (&xs.RegisteredWatchesLock); + + if (Header.req_id == ExpectedRequestId + && Header.tx_id == ExpectedTransactionId + && Buffer == NULL) { + // + // We were waiting for a watch event + // + return XENSTORE_STATUS_SUCCESS; + } + } else if (Header.req_id == ExpectedRequestId + && Header.tx_id == ExpectedTransactionId) { + Status = XENSTORE_STATUS_SUCCESS; + if (Header.type == XS_ERROR) { + Status = XenStoreGetError (Payload); + } else if (Buffer != NULL) { + ASSERT (BufferSize != NULL); + ASSERT (*BufferSize >= Header.len); + CopyMem (Buffer, Payload, MIN (Header.len + 1, *BufferSize)); + *BufferSize = Header.len; + } else { + // + // Payload should be "OK" if the function sending a request doesn't + // expect a reply. + // + ASSERT (Header.len == 3); + ASSERT (AsciiStrCmp (Payload, "OK") == 0); + } + return Status; + } + } return XENSTORE_STATUS_SUCCESS; @@ -736,51 +749,6 @@ XenStoreGetError ( return XENSTORE_STATUS_EINVAL; } -/** - 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 = XenStoreProcessMessage (); - if (Status != XENSTORE_STATUS_SUCCESS && Status != XENSTORE_STATUS_EAGAIN) { - DEBUG ((DEBUG_ERROR, "XenStore, error while reading the ring (%d).\n", - Status)); - return Status; - } - } - EfiAcquireLock (&xs.ReplyLock); - Entry = GetFirstNode (&xs.ReplyList); - Message = XENSTORE_MESSAGE_FROM_LINK (Entry); - RemoveEntryList (Entry); - EfiReleaseLock (&xs.ReplyLock); - - *TypePtr = Message->Header.type; - if (LenPtr != NULL) { - *LenPtr = Message->Header.len; - } - Body = Message->u.Reply.Body; - - FreePool (Message); - *Result = Body; - return XENSTORE_STATUS_SUCCESS; -} - /** Send a message with an optionally muti-part body to the XenStore service. @@ -806,16 +774,17 @@ XenStoreTalkv ( ) { struct xsd_sockmsg Message; - void *Return = NULL; - UINT32 Index; - XENSTORE_STATUS Status; + UINTN Index; + XENSTORE_STATUS Status; + VOID *Buffer; + UINTN BufferSize; if (Transaction == XST_NIL) { Message.tx_id = 0; } else { Message.tx_id = Transaction->Id; } - Message.req_id = 0; + Message.req_id = xs.NextRequestId++; Message.type = RequestType; Message.len = 0; for (Index = 0; Index < NumRequests; Index++) { @@ -836,29 +805,36 @@ XenStoreTalkv ( } } - Status = XenStoreReadReply ((enum xsd_sockmsg_type *)&Message.type, LenPtr, &Return); - -Error: - if (Status != XENSTORE_STATUS_SUCCESS) { - return Status; + if (ResultPtr) { + Buffer = AllocatePool (XENSTORE_PAYLOAD_MAX + 1); + BufferSize = XENSTORE_PAYLOAD_MAX; + } else { + Buffer = NULL; + BufferSize = 0; } - if (Message.type == XS_ERROR) { - Status = XenStoreGetError (Return); - FreePool (Return); + // + // Wait for a reply to our request + // + Status = XenStoreProcessMessage (Message.req_id, Message.tx_id, + &BufferSize, Buffer); + + if (Status != XENSTORE_STATUS_SUCCESS) { + DEBUG ((DEBUG_ERROR, "XenStore, error while reading the ring (%d).\n", + Status)); + FreePool (Buffer); return Status; } - /* Reply is either error or an echo of our request message type. */ - ASSERT ((enum xsd_sockmsg_type)Message.type == RequestType); - if (ResultPtr) { - *ResultPtr = Return; - } else { - FreePool (Return); + *ResultPtr = Buffer; + if (LenPtr) { + *LenPtr = BufferSize; + } } - return XENSTORE_STATUS_SUCCESS; +Error: + return Status; } /** @@ -975,7 +951,7 @@ XenStoreWaitWatch ( return XENSTORE_STATUS_SUCCESS; } - Status = XenStoreProcessMessage (); + Status = XenStoreProcessMessage (0, 0, NULL, NULL); if (Status != XENSTORE_STATUS_SUCCESS && Status != 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)); - InitializeListHead (&xs.ReplyList); InitializeListHead (&xs.RegisteredWatches); - EfiInitializeLock (&xs.ReplyLock, TPL_NOTIFY); EfiInitializeLock (&xs.RegisteredWatchesLock, TPL_NOTIFY); + xs.NextRequestId = 1; + /* Initialize the shared memory rings to talk to xenstored */ Status = XenStoreInitComms (&xs); @@ -1095,19 +1071,6 @@ XenStoreDeinit ( } } - if (!IsListEmpty (&xs.ReplyList)) { - XENSTORE_MESSAGE *Message; - LIST_ENTRY *Entry; - Entry = GetFirstNode (&xs.ReplyList); - while (!IsNull (&xs.ReplyList, Entry)) { - Message = XENSTORE_MESSAGE_FROM_LINK (Entry); - Entry = GetNextNode (&xs.ReplyList, Entry); - RemoveEntryList (&Message->Link); - FreePool (Message->u.Reply.Body); - FreePool (Message); - } - } - gBS->CloseEvent (xs.EventChannelEvent); if (xs.XenStore->server_features & XENSTORE_SERVER_FEATURE_RECONNECTION) { From patchwork Fri Sep 13 14:50:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144861 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A1371599 for ; Fri, 13 Sep 2019 14:52:49 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2B1C720830 for ; Fri, 13 Sep 2019 14:52:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="FJITqDQy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B1C720830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mvA-0005ch-Jt; Fri, 13 Sep 2019 14:51:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mv9-0005cF-F1 for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 14:51:35 +0000 X-Inumbo-ID: eae47942-d635-11e9-b299-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id eae47942-d635-11e9-b299-bc764e2007e4; Fri, 13 Sep 2019 14:51:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568386268; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7vAMP6WvPUtOvRnFJ3uSAyOGdR7QEFy0Yg9wrogbifM=; b=FJITqDQyRaAieDPKXPljBvEHq4EhRZvWm5Luk8rGBQPj0vXHZWjfPBY1 ERqkt8iSdt0E8KBKCXN3H9mJO/e9mjGEjX+MnoDXimRuPzLhGSH9JRWO5 rkD39FmwpWmxXnOQAbGK8hh4TKqAaODrUYfk/SpKKTeQgj9uc7mHM9vy5 I=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 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: Date: Fri, 13 Sep 2019 15:50:56 +0100 Message-ID: <20190913145100.303433-8-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 07/11] OvmfPkg/XenBusDxe: Use on stack buffer in internal functions X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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=2190 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 = NULL; + XenbusState State; + CHAR8 Buffer[4]; + UINTN BufferSize; XENSTORE_STATUS Status; - Status = XenStoreRead (XST_NIL, Path, "state", NULL, (VOID **)&Ptr); + BufferSize = sizeof (Buffer) - 1; + Status = XenStoreRead (XST_NIL, Path, "state", &BufferSize, Buffer); if (Status != XENSTORE_STATUS_SUCCESS) { State = XenbusStateClosed; } else { - State = AsciiStrDecimalToUintn (Ptr); - } - - if (Ptr != NULL) { - FreePool (Ptr); + Buffer[BufferSize] = '\0'; + State = AsciiStrDecimalToUintn (Buffer); } return State; @@ -129,8 +128,11 @@ XenBusAddDevice ( 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 = sizeof (BackendPath); Child = XenBusDeviceInitialized (Dev, DevicePath); if (Child != NULL) { @@ -155,17 +157,18 @@ XenBusAddDevice ( } StatusXenStore = XenStoreRead (XST_NIL, DevicePath, "backend", - NULL, (VOID **) &BackendPath); + &BackendPathSize, BackendPath); if (StatusXenStore != XENSTORE_STATUS_SUCCESS) { DEBUG ((EFI_D_ERROR, "xenbus: %a no backend path.\n", DevicePath)); Status = EFI_NOT_FOUND; goto out; } + BackendPath[BackendPathSize] = '\0'; Private = AllocateCopyPool (sizeof (*Private), &gXenBusPrivateData); Private->XenBusIo.Type = AsciiStrDup (Type); Private->XenBusIo.Node = AsciiStrDup (DevicePath); - Private->XenBusIo.Backend = BackendPath; + Private->XenBusIo.Backend = AsciiStrDup (BackendPath); Private->XenBusIo.DeviceId = (UINT16)AsciiStrDecimalToUintn (Id); Private->Dev = Dev; @@ -309,17 +312,20 @@ XenBusSetState ( ) { enum xenbus_state CurrentState; - XENSTORE_STATUS Status; - CHAR8 *Temp; + XENSTORE_STATUS Status; + CHAR8 Buffer[4]; + UINTN BufferSize; + + BufferSize = sizeof (Buffer) - 1; DEBUG ((EFI_D_INFO, "XenBus: Set state to %d\n", NewState)); - Status = XenStoreRead (Transaction, This->Node, "state", NULL, (VOID **)&Temp); + Status = XenStoreRead (Transaction, This->Node, "state", &BufferSize, Buffer); if (Status != XENSTORE_STATUS_SUCCESS) { goto Out; } - CurrentState = AsciiStrDecimalToUintn (Temp); - FreePool (Temp); + Buffer[BufferSize] = '\0'; + CurrentState = AsciiStrDecimalToUintn (Buffer); if (CurrentState == 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. @return XENSTORE_STATUS_SUCCESS on success. Otherwise an errno indicating 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; if (Transaction == XST_NIL) { Message.tx_id = 0; @@ -805,32 +804,15 @@ XenStoreTalkv ( } } - if (ResultPtr) { - Buffer = AllocatePool (XENSTORE_PAYLOAD_MAX + 1); - BufferSize = XENSTORE_PAYLOAD_MAX; - } else { - Buffer = NULL; - BufferSize = 0; - } - // // Wait for a reply to our request // Status = XenStoreProcessMessage (Message.req_id, Message.tx_id, - &BufferSize, Buffer); + BufferSize, Buffer); if (Status != XENSTORE_STATUS_SUCCESS) { DEBUG ((DEBUG_ERROR, "XenStore, error while reading the ring (%d).\n", Status)); - FreePool (Buffer); - return Status; - } - - if (ResultPtr) { - *ResultPtr = Buffer; - if (LenPtr) { - *LenPtr = BufferSize; - } } 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. @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); return XenStoreTalkv (Transaction, RequestType, WriteRequest, 3, - LenPtr, Result); + BufferSize, Buffer); } // @@ -1106,13 +1089,16 @@ XenStoreListDirectory ( OUT CONST CHAR8 ***DirectoryListPtr ) { - CHAR8 *TempStr; - UINT32 Len = 0; + CHAR8 *TempStr; + UINTN Len; XENSTORE_STATUS Status; + TempStr = AllocatePool (XENSTORE_PAYLOAD_MAX); + Len = XENSTORE_PAYLOAD_MAX; Status = XenStoreSingle (Transaction, XS_DIRECTORY, DirectoryPath, Node, &Len, - (VOID **) &TempStr); + TempStr); if (Status != XENSTORE_STATUS_SUCCESS) { + FreePool (TempStr); return Status; } @@ -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 = XenStoreSingle (Transaction, XS_READ, DirectoryPath, Node, - LenPtr, &Value); - if (Status != XENSTORE_STATUS_SUCCESS) { - return Status; - } - - *Result = Value; - return XENSTORE_STATUS_SUCCESS; + ASSERT (BufferSize != NULL); + ASSERT (Buffer != NULL); + return XenStoreSingle (Transaction, XS_READ, DirectoryPath, Node, + BufferSize, Buffer); } XENSTORE_STATUS @@ -1199,14 +1178,16 @@ XenStoreTransactionStart ( OUT XENSTORE_TRANSACTION *Transaction ) { - CHAR8 *IdStr; + CHAR8 IdStr[XENSTORE_PAYLOAD_MAX]; + UINTN BufferSize; XENSTORE_STATUS Status; + BufferSize = sizeof (IdStr); + Status = XenStoreSingle (XST_NIL, XS_TRANSACTION_START, "", NULL, - NULL, (VOID **) &IdStr); + &BufferSize, IdStr); if (Status == XENSTORE_STATUS_SUCCESS) { Transaction->Id = (UINT32)AsciiStrDecimalToUintn (IdStr); - FreePool (IdStr); } 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 = XENSTORE_PAYLOAD_MAX + 1; + Buffer = AllocatePool (BufferSize); + if (Buffer == NULL) { + return XENSTORE_STATUS_ENOMEM; + } + + Status = XenStoreRead (Transaction, This->Node, Node, &BufferSize, Buffer); + + if (Status == XENSTORE_STATUS_SUCCESS) { + *Value = Buffer; + } else { + FreePool (Buffer); + } + return Status; } 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 = XENSTORE_PAYLOAD_MAX + 1; + Buffer = AllocatePool (BufferSize); + if (Buffer == NULL) { + return XENSTORE_STATUS_ENOMEM; + } + + Status = XenStoreRead (Transaction, This->Backend, Node, &BufferSize, Buffer); + + if (Status == XENSTORE_STATUS_SUCCESS) { + *Value = Buffer; + } else { + FreePool (Buffer); + } + return Status; } 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 ( ); /** - Get the contents of a single "file". Returns the contents in *Result which - 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. @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. @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 ); /** From patchwork Fri Sep 13 14:50:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144873 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C8CA1599 for ; Fri, 13 Sep 2019 14:53:35 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3E0D020830 for ; Fri, 13 Sep 2019 14:53:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="Qd8ecEvH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E0D020830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mvP-0005lP-TS; Fri, 13 Sep 2019 14:51:51 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mvO-0005ki-F8 for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 14:51:50 +0000 X-Inumbo-ID: ec2efe8a-d635-11e9-978d-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ec2efe8a-d635-11e9-978d-bc764e2007e4; Fri, 13 Sep 2019 14:51:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568386270; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tOSh+NJLlZFM+kXJseLdwaIWhBFcG6mp1z5k4/rrlEY=; b=Qd8ecEvHtVmoRkm3LOlbU1mBFMQgZo0RIOnF1aPhLoCn4b86LMqraWK+ MpEVC8jz8dBfE+mHuch1ui3yZwYmkvzyRSn3bTqw0shRu8/hheYE/8Wnd xstJRRq/+6+3RmvJutNiZogzEEBH59hbQipvBx5QUOdges4VYaYr6bOEH s=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 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: Date: Fri, 13 Sep 2019 15:50:57 +0100 Message-ID: <20190913145100.303433-9-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 08/11] OvmfPkg/XenBus: Change XENBUS_PROTOCOL to not return allocated memory X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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=2190 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/XenBus.h index 8ff5ca3575..c22bdfb368 100644 --- a/OvmfPkg/Include/Protocol/XenBus.h +++ b/OvmfPkg/Include/Protocol/XenBus.h @@ -35,6 +35,12 @@ typedef struct #define XST_NIL ((XENSTORE_TRANSACTION *) NULL) +// +// 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 = 0, XENSTORE_STATUS_FAIL, @@ -64,19 +70,17 @@ typedef enum { /// /** - 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. @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 Buffer. + On output, the size of the data written to Buffer. + @param Buffer A pointer to a buffer into which the data read will be saved. @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 ); /** - 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. @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 Buffer. + On output, the size of the data written to Buffer. + @param Buffer A pointer to a buffer into which the data read will be saved. @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 ); /** 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 = XENSTORE_PAYLOAD_MAX + 1; - Buffer = AllocatePool (BufferSize); - if (Buffer == NULL) { - return XENSTORE_STATUS_ENOMEM; - } - - Status = XenStoreRead (Transaction, This->Node, Node, &BufferSize, Buffer); - - if (Status == XENSTORE_STATUS_SUCCESS) { - *Value = Buffer; - } else { - FreePool (Buffer); - } - return Status; + return XenStoreRead (Transaction, This->Node, Node, BufferSize, Buffer); } 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 = XENSTORE_PAYLOAD_MAX + 1; - Buffer = AllocatePool (BufferSize); - if (Buffer == NULL) { - return XENSTORE_STATUS_ENOMEM; - } - - Status = XenStoreRead (Transaction, This->Backend, Node, &BufferSize, Buffer); - - if (Status == XENSTORE_STATUS_SUCCESS) { - *Value = Buffer; - } else { - FreePool (Buffer); - } - return Status; + return XenStoreRead (Transaction, This->Backend, Node, BufferSize, Buffer); } 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 ); 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 ); XENSTORE_STATUS diff --git a/OvmfPkg/XenPvBlkDxe/BlockFront.c b/OvmfPkg/XenPvBlkDxe/BlockFront.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 = sizeof (Buffer) - 1; if (!FromBackend) { - Status = This->XsRead (This, XST_NIL, Node, (VOID**)&Ptr); + Status = This->XsRead (This, XST_NIL, Node, &BufferSize, Buffer); } else { - Status = This->XsBackendRead (This, XST_NIL, Node, (VOID**)&Ptr); + Status = This->XsBackendRead (This, XST_NIL, Node, &BufferSize, Buffer); } if (Status != XENSTORE_STATUS_SUCCESS) { return Status; } + Buffer[BufferSize] = '\0'; // AsciiStrDecimalToUint64 will ASSERT if Ptr overflow UINT64. - *ValuePtr = AsciiStrDecimalToUint64 (Ptr); - FreePool (Ptr); + *ValuePtr = AsciiStrDecimalToUint64 (Buffer); return Status; } @@ -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; ASSERT (NodeName != NULL); + BufferSize = sizeof (Buffer) - 1; + Dev = AllocateZeroPool (sizeof (XEN_BLOCK_FRONT_DEVICE)); Dev->Signature = XEN_BLOCK_FRONT_SIGNATURE; Dev->NodeName = NodeName; Dev->XenBusIo = XenBusIo; Dev->DeviceId = XenBusIo->DeviceId; - XenBusIo->XsRead (XenBusIo, XST_NIL, "device-type", (VOID**)&DeviceType); - if (AsciiStrCmp (DeviceType, "cdrom") == 0) { + BufferSize = sizeof (Buffer) - 1; + XenBusIo->XsRead (XenBusIo, XST_NIL, "device-type", &BufferSize, Buffer); + Buffer[BufferSize] = '\0'; + if (AsciiStrCmp (Buffer, "cdrom") == 0) { Dev->MediaInfo.CdRom = TRUE; } else { Dev->MediaInfo.CdRom = FALSE; } - FreePool (DeviceType); if (Dev->MediaInfo.CdRom) { - Status = XenBusIo->XsBackendRead (XenBusIo, XST_NIL, "params", (VOID**)&Params); + BufferSize = sizeof (Buffer) - 1; + Status = XenBusIo->XsBackendRead (XenBusIo, XST_NIL, "params", + &BufferSize, Buffer); if (Status != XENSTORE_STATUS_SUCCESS) { DEBUG ((EFI_D_ERROR, "%a: Failed to read params (%d)\n", __FUNCTION__, Status)); goto Error; } - if (AsciiStrLen (Params) == 0 || AsciiStrCmp (Params, "aio:") == 0) { - FreePool (Params); + Buffer[BufferSize] = '\0'; + if (AsciiStrLen (Buffer) == 0 || AsciiStrCmp (Buffer, "aio:") == 0) { DEBUG ((EFI_D_INFO, "%a: Empty cdrom\n", __FUNCTION__)); goto Error; } - FreePool (Params); } Status = XenBusReadUint64 (XenBusIo, "backend-id", FALSE, &Value); From patchwork Fri Sep 13 14:50:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144867 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 322E714E5 for ; Fri, 13 Sep 2019 14:53:01 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 035CF20830 for ; Fri, 13 Sep 2019 14:53:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="aWjhOprH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 035CF20830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mvK-0005iP-H3; Fri, 13 Sep 2019 14:51:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mvJ-0005hu-FW for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 14:51:45 +0000 X-Inumbo-ID: ebaddf8a-d635-11e9-b299-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ebaddf8a-d635-11e9-b299-bc764e2007e4; Fri, 13 Sep 2019 14:51:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568386269; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IOs1gvcTUToUpQsObk2JavC2UIX7VvOdxsW6CAsBJ5Y=; b=aWjhOprH/Z8iWBw1Xj9He1/SglSOktYPb2qAn5jYEj0hXYjoQAqzmg5q rR+y2G73PKeCvw0cbHZMonzHhjgwm7b+mgQPcv5AVd52ifZFu0AUaBthB qyL/w0xm6HaqkOtye0OlU1KhZGb8x00tt2PMKXvvPDBlV6AflXel6Z/IE o=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 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: Date: Fri, 13 Sep 2019 15:50:58 +0100 Message-ID: <20190913145100.303433-10-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 09/11] OvmfPkg/XenBusDxe: Fix NotifyExitBoot to avoid Memory Allocation Services X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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=2190 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/XenBus.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 ); +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=NULL. + + @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 + ); + /// /// 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; } +STATIC +VOID +EFIAPI +XenBusRegisterExitCallback ( + IN XENBUS_PROTOCOL *This, + IN XENBUS_EXIT_CALLBACK NotifyFunction, + IN VOID *NotifyContext + ) +{ + XENBUS_PRIVATE_DATA *Dev; + + Dev = XENBUS_PRIVATE_DATA_FROM_THIS (This); + + Dev->ExitCallback = NotifyFunction; + Dev->ExitCallbackContext = NotifyContext; +} + STATIC XENBUS_PRIVATE_DATA gXenBusPrivateData = { XENBUS_PRIVATE_DATA_SIGNATURE, // Signature { NULL, NULL }, // Link @@ -364,6 +381,7 @@ STATIC XENBUS_PRIVATE_DATA gXenBusPrivateData = { XenBusRegisterWatchBackend, // XenBusIo.RegisterWatchBackend XenBusUnregisterWatch, // XenBusIo.UnregisterWatch XenBusWaitForWatch, // XenBusIo.WaitForWatch + XenBusRegisterExitCallback, // XenBusIo.RegisterExitCallback 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 = Context; + XENBUS_DEVICE *Dev; + LIST_ENTRY *Entry; + XENBUS_PRIVATE_DATA *Child; - gBS->DisconnectController(Dev->ControllerHandle, - Dev->This->DriverBindingHandle, NULL); + Dev = Context; + + // + // First, ask every driver using xenbus to disconnect without + // deallocating memory. + // + for (Entry = GetFirstNode (&Dev->ChildList); + !IsNodeAtEnd (&Dev->ChildList, Entry); + Entry = GetNextNode (&Dev->ChildList, Entry)) { + Child = XENBUS_PRIVATE_DATA_FROM_LINK (Entry); + if (Child->ExitCallback != NULL) { + Child->ExitCallback (Child->ExitCallbackContext); + } + } + + // + // Now, we can reset the devices used by XenBusDxe. + // + XenStoreResetWatches (); + XenStoreResetRing (Dev); + XenGrantTableDeinit (Dev); } /** 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; #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 ( } } + XenStoreResetRing (Dev); + gBS->CloseEvent (xs.EventChannelEvent); + xs.XenStore = NULL; +} + +VOID +XenStoreResetRing ( + IN XENBUS_DEVICE *Dev + ) +{ if (xs.XenStore->server_features & XENSTORE_SERVER_FEATURE_RECONNECTION) { xs.XenStore->connection = XENSTORE_RECONNECT; XenEventChannelNotify (xs.Dev, xs.EventChannel); @@ -1072,7 +1082,17 @@ XenStoreDeinit ( xs.XenStore->req_cons = xs.XenStore->req_prod = 0; xs.XenStore->rsp_cons = xs.XenStore->rsp_prod = 0; } - xs.XenStore = NULL; +} + +VOID +XenStoreResetWatches ( + VOID + ) +{ + XENSTORE_STATUS Status; + + Status = XenStoreSingle (XST_NIL, XS_RESET_WATCHES, "", NULL, NULL, NULL); + ASSERT (Status == XENSTORE_STATUS_SUCCESS); } // 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 ); +/** + 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 + ); + // // XENBUS protocol From patchwork Fri Sep 13 14:50:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144891 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77DCB184E for ; Fri, 13 Sep 2019 15:12:36 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 547FD2089F for ; Fri, 13 Sep 2019 15:12:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="T6XSWmbq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 547FD2089F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8nDX-0008GO-2L; Fri, 13 Sep 2019 15:10:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8nDV-0008G9-5t for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 15:10:33 +0000 X-Inumbo-ID: a0e59576-d638-11e9-978d-bc764e2007e4 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a0e59576-d638-11e9-978d-bc764e2007e4; Fri, 13 Sep 2019 15:10:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568387432; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fVtIWB8XtGXW3UOkFZ6oQfQBixo0HT+FOB0oQh+RJ3A=; b=T6XSWmbqzNrgAvcF1YjrXPBKWnovR1XouN5csSAu5PTHrG+eJdwsu68r Ip5gGdUzTEfV/jXaGEEDqDneutt6COVefGbglXkTEAe8iQZm6UrYQc9IL qr6gC1yKg9oJzNFpwXF2wencwfoapP/QAmpJ1y9xV0ZwfONtp5Y9oF7oI w=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (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: Date: Fri, 13 Sep 2019 15:50:59 +0100 Message-ID: <20190913145100.303433-11-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 10/11] OvmfPkg/XenPvBlkDxe: Use XenBusIo->RegisterExitCallback X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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=2190 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/BlockFront.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)); *DevPtr = Dev; + + XenBusIo->RegisterExitCallback (XenBusIo, XenPvBlockFrontReset, Dev); return EFI_SUCCESS; Error2: @@ -326,13 +328,16 @@ XenPvBlockFrontInitialization ( VOID XenPvBlockFrontShutdown ( - IN XEN_BLOCK_FRONT_DEVICE *Dev + IN XEN_BLOCK_FRONT_DEVICE *Dev, + IN BOOLEAN ResetOnly ) { XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo; XENSTORE_STATUS Status; UINT64 Value; + XenBusIo->RegisterExitCallback (XenBusIo, NULL, NULL); + XenPvBlockSync (Dev); Status = XenBusIo->SetState (XenBusIo, XST_NIL, XenbusStateClosing); @@ -393,12 +398,38 @@ XenPvBlockFrontShutdown ( } 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"); - 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 = Context; + + XenPvBlockFrontShutdown (Dev, TRUE); } STATIC diff --git a/OvmfPkg/XenPvBlkDxe/BlockFront.h b/OvmfPkg/XenPvBlkDxe/BlockFront.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 ); +/** + @param ResetOnly Set to TRUE when called during the ExitBootServices. +**/ VOID XenPvBlockFrontShutdown ( - IN XEN_BLOCK_FRONT_DEVICE *Dev + IN XEN_BLOCK_FRONT_DEVICE *Dev, + IN BOOLEAN ResetOnly + ); + +VOID +EFIAPI +XenPvBlockFrontReset ( + IN VOID *Context ); VOID diff --git a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c index bfe7b1a754..3031406980 100644 --- a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c +++ b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c @@ -312,7 +312,7 @@ XenPvBlkDxeDriverBindingStart ( UninitBlockFront: FreePool (Media); - XenPvBlockFrontShutdown (Dev); + XenPvBlockFrontShutdown (Dev, FALSE); CloseProtocol: gBS->CloseProtocol (ControllerHandle, &gXenBusProtocolGuid, This->DriverBindingHandle, ControllerHandle); @@ -377,7 +377,7 @@ XenPvBlkDxeDriverBindingStop ( Media = BlockIo->Media; Dev = XEN_BLOCK_FRONT_FROM_BLOCK_IO (BlockIo); - XenPvBlockFrontShutdown (Dev); + XenPvBlockFrontShutdown (Dev, FALSE); FreePool (Media); From patchwork Fri Sep 13 14:51:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11144889 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD6B714DB for ; Fri, 13 Sep 2019 15:12:07 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9953220640 for ; Fri, 13 Sep 2019 15:12:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="e0WzgLkx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9953220640 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8nDW-0008GI-PZ; Fri, 13 Sep 2019 15:10:34 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8nDV-0008G8-4V for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 15:10:33 +0000 X-Inumbo-ID: 9f57229d-d638-11e9-95ae-12813bfff9fa Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9f57229d-d638-11e9-95ae-12813bfff9fa; Fri, 13 Sep 2019 15:10:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568387430; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ITFjy2x5OkCUAwDcBerVqJU99vxj+sJ3ZPgRNJRyHgA=; b=e0WzgLkxhsvTzVA1LIZc8PPhRHABtCRkpGcydQRmSKLoMGXxFKjDaxex alVkNPs9iTdV6cD9W+3awNu/xmO2LkWy4AgE5GsNEEVQLpGN2HAPsnmII jD637lHnPSMOh/Y9fc68CQ23mOhUk5Iav6l2ACTPA3XRj+0arMeMhCJwB M=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (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: Date: Fri, 13 Sep 2019 15:51:00 +0100 Message-ID: <20190913145100.303433-12-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 11/11] OvmfPkg/XenBusDxe: Fix XenStoreWaitForEvent use during EBS X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony Perard , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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=2190 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 ( Dev = Context; + Dev->ExitBootNotified = 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; 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]; + // + // 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); WaitList[0] = xs.EventChannelEvent; WaitList[1] = TimerEvent; Status = gBS->WaitForEvent (2, WaitList, &Index); - ASSERT (Status != EFI_INVALID_PARAMETER); + ASSERT_EFI_ERROR (Status); gBS->CloseEvent (TimerEvent); - if (Status == EFI_UNSUPPORTED) { - return EFI_SUCCESS; - } if (Index == 1) { return EFI_TIMEOUT; } else {