From nobody Fri Dec 27 03:17:17 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 1503491044171353.65812215303686; Wed, 23 Aug 2017 05:24:04 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D1B9921E47D40; Wed, 23 Aug 2017 05:20:42 -0700 (PDT) Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0040.outbound.protection.outlook.com [104.47.40.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E85D621D2E628 for ; Wed, 23 Aug 2017 05:20:35 -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:04 +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=w1RaodsklB38EBptUS20FsdyP0QSPOgM9RMYMVPP9pI=; b=Xnd7DxgpFz5qyIzA2/8QOX5c8lhLegbtSbGcpkyF/rwGCjxh+cNOwBiORqIsXzutG8gRr/BMPLYuWG0I/6LMzQC5OY0iaMDOpjpkXQ92ejMZcmi+Pr96fvBQVBu3Aryl7Zo32bfvMOyHZHJ8nQf+Diw+/Eg2WP2ntrqvn5pVZD8= 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:38 -0400 Message-Id: <1503490967-5559-15-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: 06900425-d747-43b2-bb1b-08d4ea21b43f 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:NlduUbhUh65SaFEPx63vsPGziZyYzBS2B6xsYRhror2iY7ndgi4vKWG26yz/Pd+sJ7o/AkQfup7OmsYnf1XYGc8c2aOKsLzyCLFLQUGo3gCHHsGbXllL+F4ljhJUtTHOAOm92c5u24De1CDW3E4xbblsIPUx4C8kgJTqQRrG2rmmS46lzLa20Z4OY4Co47NAv/GxcskIBX1UQ3zL6jP6hRZTF13PapN0xLYa6TuXhoFx3etQdI5RtUrqMIVszffg; 25:FncrD5XtNntgAGRNlIFQUwwUq+JjGgbrB3C0Iz3in8drIQIeef9pL4XMEQvOoxAa3MgVaZy4S1bom9dk2GQHT6VYxQSXBUmVWKPKny3e09XvE9pEgNOZoQfVl0t5e+CDBbi/lqFPXfCy8Gr+KGMhZeHHLOrP8u+yKpVpAJNfYCUce1KWFyB/bBz63FwAdFtS/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Xjjk3DRMEghIBIMmYud5nPsy9lp1ZZh1/funRwTQQStZEDbZKT4PDPwtDtXDDND3aa2PkoKjwbx1ravnu1V+IyxGIR5sxAjhnfvkKkclwaZd4eiwC5A1312cFrG8CZi+d9aPpmULu8mLRtGz/fcaJxZttHrxc7XGWX51Mksd4xcZzBAizYaVqtS+FKTBiByXYLrTx/N12Qo2AnIwNwL4gZLchwiPerntyE7Nm4iKh0w7U3elrlbUq/bWhrOib2ILU7IcesWI= 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)(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:B5Ijmyb16O9AfM5koqpxsatM9+wPrSKigsTB24nvz?= =?us-ascii?Q?lLW8L0Ur+f5tK4qV6WbggDBgNCGsWLR/5cO8EA2+Rip5z7GgRHe6RafrV75T?= =?us-ascii?Q?PLC5QdRdzimCx3pFyML8BS9FxbSOmkKj8dkqsUvesT/1DiUgZSq6iGzeFhVC?= =?us-ascii?Q?7rJgVGJ3D1JIToNrygcwngiPMSKRI7T5b8N+a2pI4YSYM8OvKX+N86Z0Eqyj?= =?us-ascii?Q?AYTkktvhWCNulfH9k086pRsDa1VNSV+fx5d0YAOQQmuXnEo4ONT6+/W23P+D?= =?us-ascii?Q?3pixjlgyQY2Ks6waqr+4uuS+WiumySuaS+Aj14AfefCAb4uq0+S+4/Y9ewli?= =?us-ascii?Q?XLVqPN054ld5mtc2sXFaa2bY5Ayx9AdQWrGRxotj94c7mhCS2dNxgdO+FV4z?= =?us-ascii?Q?8Ha/IsLJ6MnqeILuujZvOMFW0ikL0/vUM0w/+CUoZYPA7jDd/zMTZ1ZI2N6o?= =?us-ascii?Q?k9ieKpuXJfqp9g876Az59mxo4ZJCx8FZwXMRk78m5YyjfF6eyEdb3uhDDVuF?= =?us-ascii?Q?u1YRE/HKhePUjaMKJD5i9CLwicmkkW/7kTe3L5Fk7SsvgxJ6kLRiipvZsgjc?= =?us-ascii?Q?NylCDCxdm7aQq1Qblu36Q9WXnO07m489/Zi0FpLnTC37uVUN7/Kf8jhD27Vg?= =?us-ascii?Q?TCrYrmxW+p1HMcrYtDfSrMz426cjzNy9k3Sk/I38tpNP13iokdvAXMTkrQbv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Klie8ECTBjtNEp6rPU7JZkoG2h0dJDoiXCV08cUKeEwkPXzIKernCSaKuLa8CL5S11rwIg==; 24:Wj9F42cnGcw1qRUSpn2w2jtlR9BBlndNj8moWRpoEsTmcHWQw/wuqUeSlkLemOH1YV+8dIJ4LDMtYLchZedvyAF9RrkrkbL5xASHFKqAH3Y=; 7:Yfqg1VdNNPP0Wry3AMGSfGCcEZ48Jc/SMOHuUeboIrQ03o7uSQfbF+cJz9w97OCA0cOUtF4JuPWm1BJ+vDVs7Dz5j9stlAGQ4iGA+VH6pNqgWjCO42DRPw/0skPkvobFXMYrPxMF8IOirm0MtoQuxgUbopwqgXQTjWfqQwLwZKdKDF/1IPvFHpquPllvdkDuf+2WUm9pcLgKkEyKD1tFeEuoCrNerXssQ+iAanrn7Vw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:NNBXziN61dS0BqdhwvUGjiDcDQX2ZrkEwL5foSrlNbaP0y0IN02eyL2RLLNEPZLkfNEJAP6af8quxvrNtGC73sa92QPrs9+dUpu5nip/H1/qPsS8OhEhyYF86vaEfoLVcHwkR6JifiSZjVAhX90NpDo98xTjYKKH8DiNJrdiv4I8p4UdliShTtNBukhH7+S9J/0ImabhJNFMhsrSidVzvXguJ7Vkg05WSBWBib379ZQyyWgYkdGLqboq+KJ7tR8e X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2017 12:23:04.3259 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [edk2] [PATCH v3 14/23] OvmfPkg/VirtioScsiDxe: 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 VirtioScsiPassThru() function, programs the vring descriptor using the host addresses pointed-by virtio-scsi request, response and memory that is referenced inside the request and response header. The patch uses newly introduced VIRTIO_DEVICE_PROTOCOL.MapSharedBuffer() function to map system memory to device address and programs the vring descriptors 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/VirtioScsiDxe/VirtioScsi.h | 1 + OvmfPkg/VirtioScsiDxe/VirtioScsi.c | 210 +++++++++++++++++--- 2 files changed, 186 insertions(+), 25 deletions(-) diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.h b/OvmfPkg/VirtioScsiDxe/Vir= tioScsi.h index 6d00567e8cb8..05a6bf567263 100644 --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.h +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.h @@ -60,6 +60,7 @@ typedef struct { VRING Ring; // VirtioRingInit 2 EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; // VirtioScsiInit 1 EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode; // VirtioScsiInit 1 + VOID *RingMap; // VirtioRingMap 2 } VSCSI_DEV; =20 #define VIRTIO_SCSI_FROM_PASS_THRU(PassThruPointer) \ diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/Vir= tioScsi.c index a983b3df7b9c..ed7fd1dd58a8 100644 --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c @@ -409,11 +409,19 @@ VirtioScsiPassThru ( UINT16 TargetValue; EFI_STATUS Status; volatile VIRTIO_SCSI_REQ Request; - volatile VIRTIO_SCSI_RESP Response; + volatile VIRTIO_SCSI_RESP *Response; + VOID *ResponseBuffer; DESC_INDICES Indices; + VOID *RequestMapping; + VOID *ResponseMapping; + VOID *InDataMapping; + VOID *OutDataMapping; + EFI_PHYSICAL_ADDRESS RequestDeviceAddress; + EFI_PHYSICAL_ADDRESS ResponseDeviceAddress; + EFI_PHYSICAL_ADDRESS InDataDeviceAddress; + EFI_PHYSICAL_ADDRESS OutDataDeviceAddress; =20 ZeroMem ((VOID*) &Request, sizeof (Request)); - ZeroMem ((VOID*) &Response, sizeof (Response)); =20 Dev =3D VIRTIO_SCSI_FROM_PASS_THRU (This); CopyMem (&TargetValue, Target, sizeof TargetValue); @@ -423,12 +431,93 @@ VirtioScsiPassThru ( return Status; } =20 + // + // Response header is bi-direction (we preset with host status and expec= t the + // device to update it). Allocate a response buffer which can be mapped = to + // access equally by both processor and device. + // + Status =3D Dev->VirtIo->AllocateSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *Response), + &ResponseBuffer + ); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterCommonBuffer, + ResponseBuffer, + sizeof (*Response), + &ResponseDeviceAddress, + &ResponseMapping + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto FreeResponseBuffer; + } + + Response =3D ResponseBuffer; + + // + // Map the scsi-blk Request header buffer host address to device address + // + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterRead, + (VOID *) &Request, + sizeof Request, + &RequestDeviceAddress, + &RequestMapping); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto UnmapResponseBuffer; + } + + // + // Map the input buffer host address to a device address + // + if (Packet->InTransferLength > 0) { + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterWrite, + Packet->InDataBuffer, + Packet->InTransferLength, + &InDataDeviceAddress, + &InDataMapping + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto UnmapRequestBuffer; + } + } + + // + // Map the output buffer host address to a device address + // + if (Packet->OutTransferLength > 0) { + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterRead, + Packet->OutDataBuffer, + Packet->OutTransferLength, + &OutDataDeviceAddress, + &OutDataMapping + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto UnmapInDataBuffer; + } + } + + VirtioPrepare (&Dev->Ring, &Indices); =20 // // preset a host status for ourselves that we do not accept as success // - Response.Response =3D VIRTIO_SCSI_S_FAILURE; + Response->Response =3D VIRTIO_SCSI_S_FAILURE; =20 // // ensured by VirtioScsiInit() -- this predicate, in combination with the @@ -439,31 +528,49 @@ VirtioScsiPassThru ( // // enqueue Request // - VirtioAppendDesc (&Dev->Ring, (UINTN) &Request, sizeof Request, - VRING_DESC_F_NEXT, &Indices); + VirtioAppendDesc ( + &Dev->Ring, + RequestDeviceAddress, + sizeof Request, + VRING_DESC_F_NEXT, + &Indices + ); =20 // // enqueue "dataout" if any // if (Packet->OutTransferLength > 0) { - VirtioAppendDesc (&Dev->Ring, (UINTN) Packet->OutDataBuffer, - Packet->OutTransferLength, VRING_DESC_F_NEXT, &Indices); + VirtioAppendDesc ( + &Dev->Ring, + OutDataDeviceAddress, + Packet->OutTransferLength, + VRING_DESC_F_NEXT, + &Indices + ); } =20 // // enqueue Response, to be written by the host // - VirtioAppendDesc (&Dev->Ring, (UINTN) &Response, sizeof Response, - VRING_DESC_F_WRITE | (Packet->InTransferLength > 0 ? - VRING_DESC_F_NEXT : 0), - &Indices); + VirtioAppendDesc ( + &Dev->Ring, + ResponseDeviceAddress, + sizeof *Response, + VRING_DESC_F_WRITE | (Packet->InTransferLength > 0 ? VRING_DESC_F_NEXT= : 0), + &Indices + ); =20 // // enqueue "datain" if any, to be written by the host // if (Packet->InTransferLength > 0) { - VirtioAppendDesc (&Dev->Ring, (UINTN) Packet->InDataBuffer, - Packet->InTransferLength, VRING_DESC_F_WRITE, &Indices); + VirtioAppendDesc ( + &Dev->Ring, + InDataDeviceAddress, + Packet->InTransferLength, + VRING_DESC_F_WRITE, + &Indices + ); } =20 // If kicking the host fails, we must fake a host adapter error. @@ -477,10 +584,36 @@ VirtioScsiPassThru ( Packet->HostAdapterStatus =3D EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER; Packet->TargetStatus =3D EFI_EXT_SCSI_STATUS_TARGET_GOOD; Packet->SenseDataLength =3D 0; - return EFI_DEVICE_ERROR; + Status =3D EFI_DEVICE_ERROR; + goto UnmapOutDataBuffer; } =20 - return ParseResponse (Packet, &Response); + Status =3D ParseResponse (Packet, Response); + +UnmapOutDataBuffer: + if (Packet->OutTransferLength > 0) { + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, OutDataMapping); + } + +UnmapInDataBuffer: + if (Packet->InTransferLength > 0) { + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, InDataMapping); + } + +UnmapRequestBuffer: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, RequestMapping); + +UnmapResponseBuffer: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, ResponseMapping); + +FreeResponseBuffer: + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *Response), + ResponseBuffer + ); + + return Status; } =20 =20 @@ -707,7 +840,7 @@ VirtioScsiInit ( { UINT8 NextDevStat; EFI_STATUS Status; - + UINT64 RingBaseShift; UINT64 Features; UINT16 MaxChannel; // for validation only UINT32 NumQueues; // for validation only @@ -839,25 +972,42 @@ VirtioScsiInit ( } =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 // @@ -867,7 +1017,7 @@ VirtioScsiInit ( Features &=3D ~(UINT64)VIRTIO_F_VERSION_1; Status =3D Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } } =20 @@ -877,11 +1027,11 @@ VirtioScsiInit ( // Status =3D VIRTIO_CFG_WRITE (Dev, CdbSize, VIRTIO_SCSI_CDB_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } Status =3D VIRTIO_CFG_WRITE (Dev, SenseSize, VIRTIO_SCSI_SENSE_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 // @@ -890,7 +1040,7 @@ VirtioScsiInit ( NextDevStat |=3D VSTAT_DRIVER_OK; Status =3D Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 // @@ -926,6 +1076,9 @@ VirtioScsiInit ( =20 return EFI_SUCCESS; =20 +UnmapQueue: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); + ReleaseQueue: VirtioRingUninit (Dev->VirtIo, &Dev->Ring); =20 @@ -965,6 +1118,7 @@ VirtioScsiUninit ( Dev->MaxLun =3D 0; Dev->MaxSectors =3D 0; =20 + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); VirtioRingUninit (Dev->VirtIo, &Dev->Ring); =20 SetMem (&Dev->PassThru, sizeof Dev->PassThru, 0x00); @@ -995,6 +1149,12 @@ VirtioScsiExitBoot ( // 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 reset. + // + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); } =20 =20 --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel