From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0049.outbound.protection.outlook.com [104.47.33.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C676D21DF37D3 for ; Mon, 7 Aug 2017 04:57:13 -0700 (PDT) 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=smnO8r/DQzf/9O2/ne7B1EZfPDeZ6qipX19/BT5SjpA=; b=V51l6TAnN0mvfEP0jbeM4sLFS3hO/zwFGuFyPxfo1mkkwe7f9BUoQtEBF/SIhX6SfpXJuf3Yep/PAJadtjPs3EOhsClORvuCWxTrNEA6bNmCFhcJ3ABiJyynUt5emvgfHWjJRko5BVzzwgP98Fsm3u0/F76yJTlXektOh5YIhGs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from brijesh-build-machine.amd.com (165.204.77.1) by SN1PR12MB0159.namprd12.prod.outlook.com (10.162.3.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1320.16; Mon, 7 Aug 2017 11:59:27 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Mon, 7 Aug 2017 07:58:54 -0400 Message-Id: <1502107139-412-10-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502107139-412-1-git-send-email-brijesh.singh@amd.com> References: <1502107139-412-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CY4PR04CA0033.namprd04.prod.outlook.com (10.172.133.19) To SN1PR12MB0159.namprd12.prod.outlook.com (10.162.3.146) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7696ff2c-d891-48a7-9260-08d4dd8bc15b 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:SN1PR12MB0159; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0159; 3:MqmRL5NIql5Yog/JelXXoIacTJlUl+KVubepkhb3iySidreBpH2HEf8uxapItWhBJIweR2kl5NDCSPpcXgUto/+dJKL4N/NvZvqC1vOZScmGrTMWxZWIbQKRWdVcNyB01U6KqUsKHY+sqnP/mqLNetJ9VCrD63Izc6i6ArayD9g0PhbhgY2TjZf4vWn8Q2rBnwIrLfsr9pgL7d2t0lRVgycruFOBq0wzn1k3T4cAnwCkJcjGRcS5RjjMvenlFRxM; 25:uKXW0m73vAQrDFqY7Osn4JCy3I6jYjtdbnDViMOfjW8ou0dqfOJxuSk8N0HKedUG+JzXEfqMI3H+QSME4Q/q06XqtKVW13bj5uhnLRUEWxCXqOtvhJuhZZBRdyhyhZrlX++z00WHomhc/CVgvE4xfFwF5IXcFERSEFH/p2ENU5lb9uf7L+sXeEp6jsaWET2Sc8qCopVeJF4XNexIsnVnhoZ8CZGJhASjUn8e3bZfqDdC7Zt4l1Q1f7w3qKU8j8+0qUH7a2eU9XSw3qy0NhzlbRdW09tZqoyoBruUlzzw+uKKNha4IP0Nqq0GEsK8YacFXEuvifFLbJdstuCN7O5ZtQ==; 31:YTg9haTCJ+5wEBZo59mgYDAxTJyB4R32gyPJQQFzgZH9l2htXMv7ZN2Ui331N0/x7PWikozMqQnp46YM/mYBoGcFafpo/XmWREdRI9jli8rtneqVnJUGKdlvyCVcABwnakR1jKa6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Scan:(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)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123558100)(20161123560025)(20161123555025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0159; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0159; X-Forefront-PRVS: 0392679D18 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6009001)(39400400002)(39850400002)(39450400003)(39410400002)(39840400002)(39860400002)(199003)(51234002)(189002)(3846002)(6116002)(5660300001)(81156014)(81166006)(54906002)(8676002)(68736007)(50466002)(53936002)(53416004)(106356001)(2950100002)(105586002)(2351001)(42186005)(86362001)(6666003)(5003940100001)(36756003)(189998001)(33646002)(6916009)(97736004)(25786009)(2906002)(478600001)(110136004)(47776003)(38730400002)(76176999)(50986999)(66066001)(4326008)(2361001)(305945005)(50226002)(48376002)(7350300001)(101416001)(6486002)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0159; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0159; 23:FlF5Uv7uQC1KI8Ysv1f2wI0x+KfF+aSMlqiO2IGr9?= =?us-ascii?Q?apzzH2R6OCSy8XPA1LBENf9nsuO5v+l3eNdiQ7O8YdF5ziOs5F84wtjlN7/x?= =?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plt8G4CWi3SoMCoU=; 7:RtX+T3WiSqe3TFhBjjNe9UWXtGriarm4QMrtT1FgXepgSX0H9AobkVyz8VdxsJh2qqbsr500Wg4tMgarH1Iq2nNWFvg8WwcBl3le9Tg7vtWS3LZlr/VOpp0uiPDI1kuOEcyXqgQ9RSZscSzhk7Ib28KsK199NLURJmU37lohWyHXjWnV202MXQ1WQgLZ903xjrIemn1KvhM0K5XtW7QOfW3jDi2wtdM+tJTGRC2PfyE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0159; 20:fQ3ViRWkf/JB9QG/YAtm7o3ZW/vRfXbtNZmSoGXgZmh2rN7fF6oPimYoUw94sZ+cRFqA3Ns2frOXHGx30K1IZI86QJdazatStqv/ia1Pzd5EQ7ZfFtRNUC8VHb2pEJ52iUpeAr2LDQ0ThaWN9G7g+2Iyc/eVSwm/vmhIfdrPtUigWV+90Ojr9IGC6JgKGX3LTTy2QcMjzoaNWbp2DKo2H1zK3a/GUQIU0lj2dG+yxWDXS0XEh774hFSjZWCf9CE/ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2017 11:59:27.6062 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0159 Subject: [PATCH v1 09/14] OvmfPkg/VirtioScsiDxe: Use DeviceAddresses in vring descriptors 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: , X-List-Received-Date: Mon, 07 Aug 2017 11:57:14 -0000 Content-Type: text/plain The VirtioScsiPassThru(), 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 | 114 ++++++++++++++++++-- 2 files changed, 107 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.h b/OvmfPkg/VirtioScsiDxe/VirtioScsi.h index 6d00567e8cb8..bb1c5c70ef74 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 *RingBufMapping;// VirtioScsiInit 1 } VSCSI_DEV; #define VIRTIO_SCSI_FROM_PASS_THRU(PassThruPointer) \ diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c index c2f6f412ff40..779104567694 100644 --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c @@ -409,8 +409,14 @@ VirtioScsiPassThru ( UINT16 TargetValue; EFI_STATUS Status; volatile VIRTIO_SCSI_REQ Request; - volatile VIRTIO_SCSI_RESP Response; + VIRTIO_SCSI_RESP *Response; DESC_INDICES Indices; + VOID *RequestMapping; + VOID *ResponseMapping; + VOID *InDataMapping; + VOID *OutDataMapping; + EFI_PHYSICAL_ADDRESS DeviceAddress; + UINTN NumPages; ZeroMem ((VOID*) &Request, sizeof (Request)); ZeroMem ((VOID*) &Response, sizeof (Response)); @@ -418,9 +424,33 @@ VirtioScsiPassThru ( Dev = VIRTIO_SCSI_FROM_PASS_THRU (This); CopyMem (&TargetValue, Target, sizeof TargetValue); + Response = NULL; + ResponseMapping = NULL; + RequestMapping = NULL; + InDataMapping = NULL; + OutDataMapping = NULL; + + // + // Response header is bi-direction (we preset with host status and expect the + // device to update it). Allocate a response buffer which can be mapped to + // access equally by both processor and device. + // + NumPages = EFI_SIZE_TO_PAGES (sizeof (*Response)); + Status = VirtioAllocateSharedPages (Dev->VirtIo, NumPages, + (VOID *) &Response); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = VirtioMapSharedBufferCommon (Dev->VirtIo, (VOID *) Response, + sizeof (*Response), &ResponseMapping); + if (EFI_ERROR (Status)) { + goto Failed; + } + Status = PopulateRequest (Dev, TargetValue, Lun, Packet, &Request); if (EFI_ERROR (Status)) { - return Status; + goto Failed; } VirtioPrepare (&Dev->Ring, &Indices); @@ -428,7 +458,7 @@ VirtioScsiPassThru ( // // preset a host status for ourselves that we do not accept as success // - Response.Response = VIRTIO_SCSI_S_FAILURE; + Response->Response = VIRTIO_SCSI_S_FAILURE; // // ensured by VirtioScsiInit() -- this predicate, in combination with the @@ -437,23 +467,37 @@ VirtioScsiPassThru ( ASSERT (Dev->Ring.QueueSize >= 4); // + // Map the scsi-blk request header HostAddress to DeviceAddress + // + Status = VirtioMapSharedBufferRead (Dev->VirtIo, (VOID *) &Request, + sizeof Request, &DeviceAddress, &RequestMapping); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // // enqueue Request // - VirtioAppendDesc (&Dev->Ring, (UINTN) &Request, sizeof Request, + VirtioAppendDesc (&Dev->Ring, (UINTN) DeviceAddress, sizeof Request, VRING_DESC_F_NEXT, &Indices); // // enqueue "dataout" if any // if (Packet->OutTransferLength > 0) { - VirtioAppendDesc (&Dev->Ring, (UINTN) Packet->OutDataBuffer, + Status = VirtioMapSharedBufferRead (Dev->VirtIo, Packet->OutDataBuffer, + Packet->OutTransferLength, &DeviceAddress, &OutDataMapping); + if (EFI_ERROR (Status)) { + goto Failed; + } + VirtioAppendDesc (&Dev->Ring, (UINTN) DeviceAddress, Packet->OutTransferLength, VRING_DESC_F_NEXT, &Indices); } // // enqueue Response, to be written by the host // - VirtioAppendDesc (&Dev->Ring, (UINTN) &Response, sizeof Response, + VirtioAppendDesc (&Dev->Ring, (UINTN) Response, sizeof *Response, VRING_DESC_F_WRITE | (Packet->InTransferLength > 0 ? VRING_DESC_F_NEXT : 0), &Indices); @@ -462,7 +506,13 @@ VirtioScsiPassThru ( // enqueue "datain" if any, to be written by the host // if (Packet->InTransferLength > 0) { - VirtioAppendDesc (&Dev->Ring, (UINTN) Packet->InDataBuffer, + Status = VirtioMapSharedBufferWrite (Dev->VirtIo, Packet->InDataBuffer, + Packet->InTransferLength, &DeviceAddress, &InDataMapping); + if (EFI_ERROR (Status)) { + goto Failed; + } + + VirtioAppendDesc (&Dev->Ring, (UINTN) DeviceAddress, Packet->InTransferLength, VRING_DESC_F_WRITE, &Indices); } @@ -480,7 +530,28 @@ VirtioScsiPassThru ( return EFI_DEVICE_ERROR; } - return ParseResponse (Packet, &Response); + Status = ParseResponse (Packet, Response); + +Failed: + if (RequestMapping) { + VirtioUnmapSharedBuffer (Dev->VirtIo, RequestMapping); + } + + if (InDataMapping) { + VirtioUnmapSharedBuffer (Dev->VirtIo, InDataMapping); + } + + if (OutDataMapping) { + VirtioUnmapSharedBuffer (Dev->VirtIo, OutDataMapping); + } + + if (ResponseMapping) { + VirtioUnmapSharedBuffer (Dev->VirtIo, ResponseMapping); + } + + VirtioFreeSharedPages (Dev->VirtIo, NumPages, (VOID *) Response); + + return Status; } @@ -838,6 +909,11 @@ VirtioScsiInit ( goto Failed; } + Status = VirtioRingMap (Dev->VirtIo, &Dev->Ring, &Dev->RingBufMapping); + 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 resources. @@ -927,6 +1003,11 @@ VirtioScsiInit ( return EFI_SUCCESS; ReleaseQueue: + if (Dev->RingBufMapping != NULL) { + VirtioRingUnmap (Dev->VirtIo, &Dev->Ring, &Dev->RingBufMapping); + Dev->RingBufMapping = NULL; + } + VirtioRingUninit (Dev->VirtIo, &Dev->Ring); Failed: @@ -965,6 +1046,14 @@ VirtioScsiUninit ( Dev->MaxLun = 0; Dev->MaxSectors = 0; + // + // If Ring buffer is mapped then unmap it. + // + if (Dev->RingBufMapping != NULL) { + VirtioRingUnmap (Dev->VirtIo, &Dev->Ring, &Dev->RingBufMapping); + Dev->RingBufMapping = NULL; + } + VirtioRingUninit (Dev->VirtIo, &Dev->Ring); SetMem (&Dev->PassThru, sizeof Dev->PassThru, 0x00); @@ -995,6 +1084,15 @@ VirtioScsiExitBoot ( // Dev = Context; Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); + + // + // If Ring buffer mapping exist then unmap it so that hypervisor can + // not get readable data after device reset. + // + if (Dev->RingBufMapping != NULL) { + VirtioRingUnmap (Dev->VirtIo, &Dev->Ring, Dev->RingBufMapping); + Dev->RingBufMapping = NULL; + } } -- 2.7.4