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);