From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0065.outbound.protection.outlook.com [104.47.40.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D35F121D0A251 for ; Mon, 14 Aug 2017 04:35:01 -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=/Ikaa8wk/A/7xCr3PGSpNQggOWsNPHQ+Ccqquq0oXyQ=; b=YiF47NyA2MHAzaaWBUTFJnj+Pc/vPnqoqkSeR6Q4TEm7Ex+n6gIk4Z5o41B/L7MuBU1KNdpULw2JzfFZtOmDEkU672ZGGJQ5gesmG5pnSijlwZJ9sraj5UcFYw56pYBf3NVd3qdCLjehoyCvVchDGXCMxewUBnpKL9h89E9jpeI= 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 BY2PR12MB0145.namprd12.prod.outlook.com (10.162.82.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1341.21; Mon, 14 Aug 2017 11:37:23 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Mon, 14 Aug 2017 07:36:40 -0400 Message-Id: <1502710605-8058-19-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502710605-8058-1-git-send-email-brijesh.singh@amd.com> References: <1502710605-8058-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR15CA0043.namprd15.prod.outlook.com (10.173.226.157) To BY2PR12MB0145.namprd12.prod.outlook.com (10.162.82.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 13abbb4a-efe9-482e-3089-08d4e308d4f0 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:BY2PR12MB0145; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 3:yXcMV9CciElkJsQWdmJ1o7QLdJiISdo3hE6qSQV7yG2jhbhXN1Dvbh4SHbC33VEOnXqoMCppRqY4U1dEmKiDvjX4jZR+XmUe23UlQ+QRRfbmdnD6Zf4Cw4PF1oMQofVTlBKR91zbb4C4z3RSsAfc7y+c8CUQJPNjHdyhgk9oe8pbI8hwR8nrue5JYKn4GAvu9RqR5lNogjgB/YArpa4znV7WT0znoWX/78TtUn4cz3kofP2nb1WqIC5Jsocq/sqQ; 25:KPw/8gFA9UrGMlaIradfwBvxEy6g/80P3P9RagocIZrEid367Xir/4oqKbScF3ub+VbOFWQvt00uEQiFjnpIlgzvDCSblO3Q4AX8EVAk6YwLI2vdYWYcqHIkt4hlksrKpdUhdxIgalR1+qPI1PKOCKR4N4YUnv4rVTaoaMEo9T5NUSTEuizN+fFQVHwEICiDm0SowD+tlrP0WvJ+DNVV39xFl2x0AdHkKpr2XJxPtQmZ2u01GD+B8Bb+eeO2XbhXpbOoLT+x5wlxOziglN0zpk9H0OSk0ZUrzAhzQ05RvtFDaLsRMvAd+GY3QiHluo1CNnmRB+UIMgB9vBjzHtYdIQ==; 31:ui6aB/Y2mnzXJfUNyt7ZSjENt2ryzrWYg0EhC+Lso5CRntmVJHAZFRd1WHGPMF6uS7x/Qv6+P3eP8fiRCRH+mQtzFZ05qeW4tVB7G9YFDWzWo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7FD0He78aRQ= 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)(8121501046)(5005006)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123558100)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BY2PR12MB0145; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BY2PR12MB0145; X-Forefront-PRVS: 039975700A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(39860400002)(199003)(189002)(51234002)(54906002)(5003940100001)(6116002)(3846002)(53936002)(97736004)(86362001)(36756003)(81156014)(81166006)(110136004)(8676002)(189998001)(50986999)(76176999)(5660300001)(2361001)(25786009)(2351001)(50226002)(4326008)(7350300001)(33646002)(478600001)(53416004)(42186005)(2906002)(105586002)(7736002)(305945005)(106356001)(48376002)(50466002)(47776003)(66066001)(6486002)(6916009)(2950100002)(6666003)(68736007)(101416001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0145; 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; BY2PR12MB0145; 23:nrs30Rnd44INqUHFeBMfcrW39sQSKn2emc94NTWuI?= =?us-ascii?Q?ilKdDeD3wi29nImLFFiUwynFV5dmXSrQUhyARgGRjlJfTqJuG8QbHlX4UKSB?= =?us-ascii?Q?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5gnyD9b+0ugZv8nA/MVHZ+3NsCgI0rWwCzdyOHu2bqN/CwnERdHPESaZX6GDwM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 20:MW/V7lG94wYVzOUjQEwYFskMdDD8WZ3Oyp2MqWXEc2VEpZiZEXshdu1XbtFk9rxB6wXGlAfbURzhYHUjKyvZCx8o+dyC9CdEyrFRhyrxqb4g2PZVPGHxGPFRMkAPEUGh1IDZPRjPcC1/uMlFEsZJlarcSFExZMVB+E8QQyUTguS/Cgn0nC+n9Goeo/vZ7Fb2l62gsMAxHib4PzbIRF1tHXmo7apOWwuUjAu13sW8lnuS34pOfQyp+clNK+dBstbj X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2017 11:37:23.1743 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0145 Subject: [PATCH v2 18/23] 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, 14 Aug 2017 11:35:02 -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 | 148 +++++++++++++++++--- 2 files changed, 133 insertions(+), 16 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 a983b3df7b9c..65e9bda0827a 100644 --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c @@ -409,8 +409,13 @@ 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; ZeroMem ((VOID*) &Request, sizeof (Request)); ZeroMem ((VOID*) &Response, sizeof (Response)); @@ -418,9 +423,41 @@ 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. + // + Status = Dev->VirtIo->AllocateSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *Response), + (VOID *) &Response + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterCommonBuffer, + (VOID *) Response, + sizeof (*Response), + &DeviceAddress, + &ResponseMapping + ); + if (EFI_ERROR (Status)) { + goto Free_Response_Buffer; + } + Status = PopulateRequest (Dev, TargetValue, Lun, Packet, &Request); if (EFI_ERROR (Status)) { - return Status; + goto Unmap_Response_Buffer; } VirtioPrepare (&Dev->Ring, &Indices); @@ -428,7 +465,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 +474,51 @@ VirtioScsiPassThru ( ASSERT (Dev->Ring.QueueSize >= 4); // + // Map the scsi-blk request header HostAddress to DeviceAddress + // + Status = VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterRead, + (VOID *) &Request, + sizeof Request, + &DeviceAddress, + &RequestMapping); + if (EFI_ERROR (Status)) { + goto Unmap_Response_Buffer; + } + + // // 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, + // + // Map the buffer address to a device address + // + Status = VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterRead, + Packet->OutDataBuffer, + Packet->OutTransferLength, + &DeviceAddress, + &OutDataMapping + ); + if (EFI_ERROR (Status)) { + goto Unmap_Request_Buffer; + } + 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 +527,22 @@ VirtioScsiPassThru ( // enqueue "datain" if any, to be written by the host // if (Packet->InTransferLength > 0) { - VirtioAppendDesc (&Dev->Ring, (UINTN) Packet->InDataBuffer, + // + // Map the buffer address to a device address + // + Status = VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterWrite, + Packet->InDataBuffer, + Packet->InTransferLength, + &DeviceAddress, + &InDataMapping + ); + if (EFI_ERROR (Status)) { + goto Unmap_Out_Buffer; + } + + VirtioAppendDesc (&Dev->Ring, (UINTN) DeviceAddress, Packet->InTransferLength, VRING_DESC_F_WRITE, &Indices); } @@ -480,7 +560,29 @@ VirtioScsiPassThru ( return EFI_DEVICE_ERROR; } - return ParseResponse (Packet, &Response); + Status = ParseResponse (Packet, Response); + + if (Packet->InTransferLength > 0) { + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, InDataMapping); + } + +Unmap_Out_Buffer: + if (Packet->OutTransferLength > 0) { + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, OutDataMapping); + } + +Unmap_Request_Buffer: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, RequestMapping); +Unmap_Response_Buffer: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, ResponseMapping); +Free_Response_Buffer: + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *Response), + (VOID *) Response + ); + + return Status; } @@ -707,7 +809,7 @@ VirtioScsiInit ( { UINT8 NextDevStat; EFI_STATUS Status; - + UINT64 RingBaseShift; UINT64 Features; UINT16 MaxChannel; // for validation only UINT32 NumQueues; // for validation only @@ -838,18 +940,24 @@ VirtioScsiInit ( goto Failed; } + Status = VirtioRingMap (Dev->VirtIo, &Dev->Ring, &RingBaseShift, + &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. // Status = Dev->VirtIo->SetQueueNum (Dev->VirtIo, QueueSize); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } Status = Dev->VirtIo->SetQueueAlign (Dev->VirtIo, EFI_PAGE_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } // @@ -857,7 +965,7 @@ VirtioScsiInit ( // Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring, 0); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } // @@ -867,7 +975,7 @@ VirtioScsiInit ( Features &= ~(UINT64)VIRTIO_F_VERSION_1; Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } } @@ -877,11 +985,11 @@ VirtioScsiInit ( // Status = VIRTIO_CFG_WRITE (Dev, CdbSize, VIRTIO_SCSI_CDB_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } Status = VIRTIO_CFG_WRITE (Dev, SenseSize, VIRTIO_SCSI_SENSE_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } // @@ -890,7 +998,7 @@ VirtioScsiInit ( NextDevStat |= VSTAT_DRIVER_OK; Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } // @@ -926,6 +1034,8 @@ VirtioScsiInit ( return EFI_SUCCESS; +UnmapQueue: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingBufMapping); ReleaseQueue: VirtioRingUninit (Dev->VirtIo, &Dev->Ring); @@ -995,6 +1105,12 @@ 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. + // + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingBufMapping); } -- 2.7.4