From nobody Fri Dec 27 03:11:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1503491031666832.7960038136471; Wed, 23 Aug 2017 05:23:51 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 496C421E7903B; Wed, 23 Aug 2017 05:20:35 -0700 (PDT) Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0085.outbound.protection.outlook.com [104.47.40.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 457F521E49BA5 for ; Wed, 23 Aug 2017 05:20:31 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.1) by DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1362.18; Wed, 23 Aug 2017 12:23:03 +0000 X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=gKTaD4odvk7hMu8Yj+XReAgk88UGJSVVp9N09Vh5Zzc=; b=mfCrhWk88RiOuro01UP6I9eOYIFvHQFdJgUjjuLwpie/0GlzaOx2PHUI5bFJLy5Z9NQejVX/c+kTltbiQ8+auKqEbHWN85JLf1oDygqIjQ3S+e4eU/reBrZZba9K5vuiYbZdp+pgFX6YXezpfx3SJhb2WKheTdH226KsjPeRVV8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Wed, 23 Aug 2017 08:22:37 -0400 Message-Id: <1503490967-5559-14-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503490967-5559-1-git-send-email-brijesh.singh@amd.com> References: <1503490967-5559-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR12CA0069.namprd12.prod.outlook.com (2603:10b6:3:103::31) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ccf496de-0b08-45d6-1129-08d4ea21b3f1 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 3:981w4ilpq4pbd9DxVO2EFzIV8CCIDgTXIqLTh0lep1BFgXhs27LEslAnL/bxMwEVaGEm7kZIcwBHCZZeJjXq2GlAEZ2cRIt+ybx2cz+kAWJL+6vIwxHUoiGYQZSywOVxnb3Ot2JKNww8oJd8eZ2nlGkwCUIA/AQNOgGQ+5kHAqOY5EyVc0lpf0BOfoyd6y2E0fSnqtGYB2PfAHpPWuGFwl9YjGfO66/0YKwTwp3VxmbtAJ4EQkT8ZuHVulsS3E6X; 25:uS9U2gFqGup8dF4FMdq5DBd6WFeXXNArCfWnmeS304uRIF2P7T+CgL9RdDBNMAh8lbfGxyHqqOfpKxHEyPX3gc7qUi4dvi14mbBYbt/106G3Jz/QWRlTRUtIdvr1D/P5j5hn48g27kfSKLXVEN+rjcRiqgzwLyqQpdDUBJq3sschMXZKIxShdeHB5R0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FVGy9nzcKzRSt/WB7iYzc/tpMERyqFShbPmW7gxf94GD4iSslUMJRSoj5vbKvCHUBYunJm0NMKj1TWHWkC8njHRxk+4+ZoY7bgnr5e+sN1fJPXuQWjpBO1yrvwfMI4E1lEh1XQmNygOXZcq3hsQB1y6AZA62Daxxp8jd6Ixp2baOVecL9ZFAm15P/1dKateqM/wkPLr3XZKzj17buhM1IQ1VqKZ+mwY2hW6KqCQtSOaXR6FsIFXfuuWwESaf9I= X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699)(17755550239193); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM2PR12MB0155; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM2PR12MB0155; X-Forefront-PRVS: 040866B734 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(39860400002)(189002)(199003)(51234002)(575784001)(305945005)(47776003)(97736004)(101416001)(110136004)(6666003)(189998001)(478600001)(7736002)(3846002)(66066001)(5003940100001)(6116002)(6486002)(48376002)(86362001)(105586002)(2950100002)(4326008)(106356001)(36756003)(6916009)(50466002)(2906002)(50226002)(42186005)(2351001)(33646002)(53416004)(25786009)(7350300001)(81156014)(76176999)(5660300001)(68736007)(54906002)(8676002)(53936002)(50986999)(81166006)(2361001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR12MB0155; 23:IBJkKbUgcNdUCVnbyqfURpypG77X97bx4usUkK8fE?= =?us-ascii?Q?4EPqVBhKPoQe0/BAWD1pcDb8Fx8L8P77K3ndHer0gRRluEUWoQA+PWDfXxQr?= =?us-ascii?Q?9GEeoRMrWiMpiJkIC9d8Uy/38Q1dpbnqQAr6dBRx/kq+CdXXiZ+2zDAwZQVc?= =?us-ascii?Q?5xjn599/LutDyHgsrXhSvXl/2c8UQOOvwcLFxH1c1ZlWl3YRrgg1+14MGqe3?= =?us-ascii?Q?8hRN2KZShU1JtKrV4G0DVskLX9cWLRsQKZ66qmh4JkiM3Hv5mdTphjsmuoEJ?= =?us-ascii?Q?HaMz/SWQNSaVt/emDNV5vDN2XhFZ6INcH/6v1bnDelfYT1ZF/3sqxbIyqFsk?= =?us-ascii?Q?51YYcXNisX0ZHYK29Y/cpThG4xQhZlpfl0LB0ul+1pov7I+4dvGRmhcU9sai?= =?us-ascii?Q?rf1MO18xyqL8zv/UWTz1jN+Tq8+4+eOX8esYI89HYTzXUNojkVD4psuKUim5?= =?us-ascii?Q?cSlAota1/ZuBfc/3sLurwY++tgeNXYsx0dshHZ8VcTyKtI9PYfA4m3PjGZyR?= =?us-ascii?Q?WBIKVFScUTg43BPaKRmEWrjAVRB/6FDBfBn/IpbiYKG4DUol9Pwba6Q3fAa+?= =?us-ascii?Q?0hO1P8ga+TIiPfTRQRopXLmUhrXVqymxqWY6k85yNdhh93ocVu0OaEa1pWEN?= =?us-ascii?Q?zhDUKffZxpXw9wTCEuINH/AYYk9RI7JVOiUfMuPOSV+x1gS+QfOjgO4Y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6KgCsHrOKFB4ckvjZSybaReU6GAQYSQIoqgsUpAZLFAM1sKIZIFFwLuA+72FWS01dpIWAuiK4SnNOj4PqL8emDYAEJwQ==; 24:LCIv+YsBxKN6S8fPFS2s965nxoZ6/mxYGtMgXU6OKqoeiyLh/0PxKqYDI+WVKVBFosdb9150X5YRNW9VHWoHrHqMuYBSgA/FYMT8T8K9pgM=; 7:t8XPLdukAaU1SAML9DwS55qXU+AxbCvNXTM6fHy1lD8q15Jy8/8f7CEQyfU+WUS6ys8O21pC1nklm7hUMjGIB7hDo0HKHJWkr9Z49WPqz1AmqO2NbYOxfGcfia/BoanHrdK2MoCCwSD+I9KwSQf6Sc8B4E4LE/MfO2SWbaQ56zSgTLPHL7QIVnB8FHpQVmfuLg0hpds2kqC3e57svgta1V94Nz65yBCuW2oaIPNYmy4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:7QoeBBrHUjqtkZKBeMijqwbxeKpVlpUA+JtVoDlf4q3sOTConGZPoiVKfYkjo1jCZU8oH4XBeMeC3DzZu+ydVON/rk+MlYgew/oFOpau/LBSqnaDFSnff6jr6+ForLieTwA361OGwnhQFUDxxgluIy63UsFW1XtgE9ACKfPjWmEmSoIt8Nw+eGWgh6E9MLgSqAfDr6NR9DHzjrDJqofbAHo8MlSpJZEFR7jB9VtqkdO38+RhwWvOQAdXwMHpuKrZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2017 12:23:03.8103 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [edk2] [PATCH v3 13/23] OvmfPkg/VirtioBlkDxe: map host address to device address X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen , Tom Lendacky , Laszlo Ersek , Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The SynchronousRequest() function, programs the vring descriptor with the buffers pointed-by virtio-blk requests, status and memory that is referenced inside the request header. The patch uses VIRTIO_DEVICE_PROTOCOL.MapSharedBuffer() function to map host address to device address and programs the vring descriptor with device addresses. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Brijesh Singh --- OvmfPkg/VirtioBlkDxe/VirtioBlk.h | 1 + OvmfPkg/VirtioBlkDxe/VirtioBlk.c | 201 +++++++++++++++++--- 2 files changed, 180 insertions(+), 22 deletions(-) diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.h b/OvmfPkg/VirtioBlkDxe/Virtio= Blk.h index 6c402ca88ea4..9ec0b956b818 100644 --- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.h +++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.h @@ -41,6 +41,7 @@ typedef struct { VRING Ring; // VirtioRingInit 2 EFI_BLOCK_IO_PROTOCOL BlockIo; // VirtioBlkInit 1 EFI_BLOCK_IO_MEDIA BlockIoMedia; // VirtioBlkInit 1 + VOID *RingMap; // VirtioRingMap 2 } VBLK_DEV; =20 #define VIRTIO_BLK_FROM_BLOCK_IO(BlockIoPointer) \ diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/Virtio= Blk.c index bff15fe3add1..e23762743f75 100644 --- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c +++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c @@ -232,7 +232,8 @@ VerifyReadWriteRequest ( =20 @retval EFI_DEVICE_ERROR Failed to notify host side via VirtIo write= , or unable to parse host response, or host resp= onse - is not VIRTIO_BLK_S_OK. + is not VIRTIO_BLK_S_OK or failed to map Buf= fer + for a bus master operation. =20 **/ =20 @@ -249,8 +250,16 @@ SynchronousRequest ( { UINT32 BlockSize; volatile VIRTIO_BLK_REQ Request; - volatile UINT8 HostStatus; + volatile UINT8 *HostStatus; + VOID *HostStatusBuffer; DESC_INDICES Indices; + VOID *RequestMapping; + VOID *StatusMapping; + VOID *BufferMapping; + EFI_PHYSICAL_ADDRESS BufferDeviceAddress; + EFI_PHYSICAL_ADDRESS HostStatusDeviceAddress; + EFI_PHYSICAL_ADDRESS RequestDeviceAddress; + EFI_STATUS Status, Ret; =20 BlockSize =3D Dev->BlockIoMedia.BlockSize; =20 @@ -278,9 +287,88 @@ SynchronousRequest ( VirtioPrepare (&Dev->Ring, &Indices); =20 // + // Host status is bi-directional (we preset with a value and expect the = device + // to update it). Allocate a host status buffer which can be mapped to + // access equally by both processor and the device. + // + Status =3D Dev->VirtIo->AllocateSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *HostStatus), + &HostStatusBuffer + ); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + // + // Map virtio-blk request header + // + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterRead, + (VOID *) &Request, + sizeof Request, + &RequestDeviceAddress, + &RequestMapping + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto FreeHostStatusBuffer; + } + + // + // Map data buffer + // + if (BufferSize > 0) { + if (RequestIsWrite) { + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterRead, + (VOID *) Buffer, + BufferSize, + &BufferDeviceAddress, + &BufferMapping + ); + } else { + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterWrite, + (VOID *) Buffer, + BufferSize, + &BufferDeviceAddress, + &BufferMapping + ); + } + + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto UnmapRequestBuffer; + } + } + + // + // Map the Status Buffer with VirtioOperationBusMasterCommonBuffer so th= at + // both processor and device can access it. + // + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterCommonBuffer, + HostStatusBuffer, + sizeof *HostStatus, + &HostStatusDeviceAddress, + &StatusMapping + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto UnmapDataBuffer; + } + + HostStatus =3D HostStatusBuffer; + + // // preset a host status for ourselves that we do not accept as success // - HostStatus =3D VIRTIO_BLK_S_IOERR; + *HostStatus =3D VIRTIO_BLK_S_IOERR; =20 // // ensured by VirtioBlkInit() -- this predicate, in combination with the @@ -291,8 +379,13 @@ SynchronousRequest ( // // virtio-blk header in first desc // - VirtioAppendDesc (&Dev->Ring, (UINTN) &Request, sizeof Request, - VRING_DESC_F_NEXT, &Indices); + VirtioAppendDesc ( + &Dev->Ring, + RequestDeviceAddress, + sizeof Request, + VRING_DESC_F_NEXT, + &Indices + ); =20 // // data buffer for read/write in second desc @@ -311,27 +404,62 @@ SynchronousRequest ( // // VRING_DESC_F_WRITE is interpreted from the host's point of view. // - VirtioAppendDesc (&Dev->Ring, (UINTN) Buffer, (UINT32) BufferSize, + VirtioAppendDesc ( + &Dev->Ring, + BufferDeviceAddress, + (UINT32) BufferSize, VRING_DESC_F_NEXT | (RequestIsWrite ? 0 : VRING_DESC_F_WRITE), - &Indices); + &Indices + ); } =20 // // host status in last (second or third) desc // - VirtioAppendDesc (&Dev->Ring, (UINTN) &HostStatus, sizeof HostStatus, - VRING_DESC_F_WRITE, &Indices); + VirtioAppendDesc ( + &Dev->Ring, + HostStatusDeviceAddress, + sizeof *HostStatus, + VRING_DESC_F_WRITE, + &Indices + ); =20 // // virtio-blk's only virtqueue is #0, called "requestq" (see Appendix D). // - if (VirtioFlush (Dev->VirtIo, 0, &Dev->Ring, &Indices, - NULL) =3D=3D EFI_SUCCESS && - HostStatus =3D=3D VIRTIO_BLK_S_OK) { - return EFI_SUCCESS; + Status =3D VirtioFlush (Dev->VirtIo, 0, &Dev->Ring, &Indices, NULL); + + // + // Unmap the HostStatus buffer before accessing it + // + Ret =3D Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, StatusMapping); + if (EFI_ERROR (Ret)) { + Status =3D EFI_DEVICE_ERROR; + } + + if (!EFI_ERROR (Status) && + *HostStatus =3D=3D VIRTIO_BLK_S_OK) { + Status =3D EFI_SUCCESS; + } else { + Status =3D EFI_DEVICE_ERROR; } =20 - return EFI_DEVICE_ERROR; +UnmapDataBuffer: + if (BufferSize > 0) { + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, BufferMapping); + } + +UnmapRequestBuffer: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, RequestMapping); + +FreeHostStatusBuffer: + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *HostStatus), + HostStatusBuffer + ); + + return Status; } =20 =20 @@ -580,7 +708,8 @@ VirtioBlkDriverBindingSupported ( virtio-blk attributes the host provides. =20 @return Error codes from VirtioRingInit() or - VIRTIO_CFG_READ() / VIRTIO_CFG_WRITE(). + VIRTIO_CFG_READ() / VIRTIO_CFG_WRITE or + VirtioRingMap(). =20 **/ =20 @@ -601,6 +730,7 @@ VirtioBlkInit ( UINT8 AlignmentOffset; UINT32 OptIoSize; UINT16 QueueSize; + UINT64 RingBaseShift; =20 PhysicalBlockExp =3D 0; AlignmentOffset =3D 0; @@ -729,25 +859,42 @@ VirtioBlkInit ( } =20 // + // If anything fails from here on, we must release the ring resources + // + Status =3D VirtioRingMap ( + Dev->VirtIo, + &Dev->Ring, + &RingBaseShift, + &Dev->RingMap + ); + if (EFI_ERROR (Status)) { + goto ReleaseQueue; + } + + // // Additional steps for MMIO: align the queue appropriately, and set the - // size. If anything fails from here on, we must release the ring resour= ces. + // size. If anything fails from here on, we must unmap the ring resource= s. // Status =3D Dev->VirtIo->SetQueueNum (Dev->VirtIo, QueueSize); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 Status =3D Dev->VirtIo->SetQueueAlign (Dev->VirtIo, EFI_PAGE_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 // // step 4c -- Report GPFN (guest-physical frame number) of queue. // - Status =3D Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring, 0); + Status =3D Dev->VirtIo->SetQueueAddress ( + Dev->VirtIo, + &Dev->Ring, + RingBaseShift + ); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 =20 @@ -758,7 +905,7 @@ VirtioBlkInit ( Features &=3D ~(UINT64)VIRTIO_F_VERSION_1; Status =3D Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } } =20 @@ -768,7 +915,7 @@ VirtioBlkInit ( NextDevStat |=3D VSTAT_DRIVER_OK; Status =3D Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 // @@ -811,6 +958,9 @@ VirtioBlkInit ( } return EFI_SUCCESS; =20 +UnmapQueue: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); + ReleaseQueue: VirtioRingUninit (Dev->VirtIo, &Dev->Ring); =20 @@ -849,6 +999,7 @@ VirtioBlkUninit ( // Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); =20 + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); VirtioRingUninit (Dev->VirtIo, &Dev->Ring); =20 SetMem (&Dev->BlockIo, sizeof Dev->BlockIo, 0x00); @@ -885,6 +1036,12 @@ VirtioBlkExitBoot ( // Dev =3D Context; Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); + + // + // Unmap the ring buffer so that hypervisor will not be able to get + // readable data after device is reset. + // + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); } =20 /** --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel