From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0073.outbound.protection.outlook.com [104.47.38.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7D80E21CEB0E9 for ; Mon, 11 Sep 2017 05:14:16 -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=gnzz5afoT9y5J0eWXwd9Ci3lbBml+1NVVSJF/K7OjbU=; b=SlTzSksc92IEPAbP6c1/OSaby+JrkpCUKvka40U0dRYdUL8crge21YDPkFBNPIypW6BVFrbT4UxO7pv/Sd9/Z/s3gJk5bv6tOg1U/jhV6tv9K1LdCILovQgZiQw8L2utjzECNsnLlrZq2a8SHb9O+9UophFeU/7MWVcCkLi7eCo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from ubuntu-010236106000.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Mon, 11 Sep 2017 12:17:10 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Mon, 11 Sep 2017 07:16:53 -0500 Message-Id: <20170911121657.34992-5-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170911121657.34992-1-brijesh.singh@amd.com> References: <20170911121657.34992-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM3PR12CA0047.namprd12.prod.outlook.com (10.161.151.15) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 64e817e6-784b-4e96-d910-08d4f90f0758 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)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:8uvuBf5BBWaZ8H2vWwDx2N70eDpzu8L/Ye26pJcp+CPkcJUeKx3qgO5E8m2UQbY8UOlL9AfPRmqtQQKJ3b9/zt+edkZxmCtGL+kxNZnBXTsSkdlAa8iFO2mXIGfeDU/q2yegv2yo31FiQPe+YnkFRRFWbc1CRVYVqgc320Vwdg1q6BPLrzagHyELTe27qqu/EB+qXdxPOYXwrgHPNR/Q0GI7NmgrCXTCNEgp68J9DnE7Gf0R5ggd7vZNQvnCneCG; 25:OHy6vl5Z8GPhZ9Crw0aEMtBndbV82LJKiKDTXKp166s/vEnbvTjoeaJToAQXFfSNoIwY+P8+cdmy1i96TiM+9EPF0lo64ELswqfnv8armkIjhrop0bBZwxfDcodm9SKWSwSBzpAPSPZiO+HQ3ncIfXQrDMR/qiMC6G+tbrvflxlP5o/Yk6CnBL+9n7/CWFXFnJ11TAYTgZNdJ6SmBKvnARVDE+5qpxDVQcNxrFuy8aAMkRscbMjbJ6902SezFTxHqnam4xLteX9TRTbsOwSXHzyoLfZnzw7mmyZ2f6stwV/JhT8nCPGk1K2t7MrzH01MCwP+mMzrJXtdKR+0zyFUDA==; 31:3AQQ8r8PhhL/OYAf4u7/iSAC+7xXgR1H55Xpyfty9nYSC+xFQsaEl/CB42SvJTS9XcJfNg4urNmxqKy79HdsWcAPVBhVPnqvBlAFCcI2y1ZMokTWMVyjz8mm2TIlITu9cE2yh4HJ7W+UTXgkii/2gZ674goJ4vJUmEtx7y/RSNZ9J9/3RznNUe/Se58nSl0s+p3AxKA4yQkZlhkWxE+Zq/HKTZJzsPQZEijVkojkg30= X-MS-TrafficTypeDiagnostic: SN1PR12MB0158: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:I6uyR3MtETMyPvrBkNwkrh3TXMcfxtJhs2hgB953rrOgOUyviWnFsjQ6j04x/LseT9ltxunrYP0O1WWqACmjjYIDjAx758OUTxrrs9P9y/Q1Zx+VOzXC/RZivHljr4+2uXdKEXV2S5nHjNRwewInIviEqa9orz9rp21DQGpIQe3oE76XmO1AS5rWuvwwicsb66JxR9z56ExXOpG2fh+CefFaI8W6laJ0TbkSKj/puRM5itgG0D3LvbjF5nvdX40DfcoHIiQASz/Z4yMz5LUSs1Ke+RaLaBOwlH8EJdzQv6dBxx5e+IpW+vdytBW9AQi41v+ayR0cmMvQQ2FqBY48ldUhk3XXroogzwrVNAjKxS92RmJ4QnQ5KfvtxQiDp9vbMxQly/lRW6WqcfUZ/UCw87QP/qaKavJc3b98kCu/88AR59yLbnqGJrIbA2HE2jQJNe0Jv2wx91GPJrdA69ed2pz0vXuO7gT+WkTVbOnduHKBHuVtYVy9ATW1+XB5OwKk; 4:IS2yVx9pBw6l/cSNaJNyWOZjugR4Jqmx0/dYlieTckcH/obaU0nooCWwyaLA5+6feYNMjRsKGGyTVnEitcaI0a1i2v1xUUa/5JMYIPz1qC69ngc/Q4gjg9pL81pSEOBmqCZffhMFsE+/1Mq55GlXzzhsXLzntJV5Ivw8twSst3P120H+wtvVSTY1AqrUyhyYqGZEOQcFgGEwbQ5M6u4UxB+WSu+NqHdnoJa+WpjyypW/KxUyrAcfUJY9a9BQloxFYnGgYE20u6ZE80x1caf2Hy3QbO9KnStdGbd4WjF6Bwg7zpV6Hew2IbYwrgexBBQ+i8Bi2xk91omUbA/OI//AvA== X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123560025)(20161123564025)(20161123558100)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0158; X-Forefront-PRVS: 04270EF89C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(51234002)(189002)(199003)(110136004)(106356001)(7736002)(105586002)(101416001)(4326008)(53416004)(1076002)(2361001)(2906002)(305945005)(2351001)(5660300001)(189998001)(25786009)(33646002)(50986999)(76176999)(3846002)(6116002)(68736007)(8676002)(478600001)(81156014)(81166006)(42186005)(50466002)(54906002)(6666003)(50226002)(97736004)(48376002)(36756003)(6916009)(2950100002)(8936002)(66066001)(47776003)(86362001)(5003940100001)(6486002)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; SN1PR12MB0158; 23:Tagjmczn2S62/AFyqUh452cS3qVBfi2OoYqpt08C8?= =?us-ascii?Q?cPiIygZwT8DHRu8W0KOGR6MvZ4upIf61RxXU3omzgiNZW6vF/BXX95acjgc2?= =?us-ascii?Q?eKLCpZDlULYiJ+Qn80KlSjVmKor/iAQx+cQnc/IcLlOziy3En4T1ak3P1Zfa?= =?us-ascii?Q?bI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3mpR5uyoUXUIwoKGNqze1mh?= =?us-ascii?Q?B7iSGfqxsZQ270B15nD9/8xBLhcw0IKBkckk3pTMk27dMWDyw=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 6:qOyAyLnUjOS36xEeDt/9fUjW/TvdDMPXbpubbnj08YALZVjSTl6+0+2sEJbBlLYW4OLfKufEGM9XtfoMnnrOYf4p7PRblechoKiHeC7X6+I7OXsZvrzOmkmLKwjswcLjHm0rNcOtEJ6LZBMTbaux+2JnBzbvciOVrTx7lBL08VquTo2/XextZeAj7GFkMyzZVLwbY33F0SYs3xJYKAgZ6BXbELE5h2GIQtzIV8DBnzl3q5RPtBa9Bu7VUzbGQfCkY5ehyqzewb5b/AF6Qz+qB0Sflvy4NtMhG/s43/L075/iREw3kHremFo5YLA0FJt7XfuONtf2ZePxR1GyMzEYiw==; 5:S1pBtKvyHo/GDGfmX4k0rKjo+swSBXp/47mnLbZa7BLZOnQHD0lxhuzrTe4GzxIYK3kuvxKHaVtBmB+8JjhkVDQSkCU5sn3wnHRU6ILQgSYC3bEr+HmZlPze3P5tqz5VcHLUJxLue70Ft8F1cfZKXg==; 24:KLe/bym/lYt1RqJqLshIerb8nO2uswR3rsMTKe1DW15VsJ2BHGvcDmZSS9WaADX7c8rYkZDjQuCdknegFX0HhlINKSTO17xGs1217W6T7NM=; 7:WxYak+E98JTJVQ1ddZ4cviduol1MMGixon5qqCtNBszyi3QjS38a1WOyuLMVPOouOSh7cUQe/X/2DwPUbCII7OgISEO/sOm+QdJfVeKtcVwEt+VPRqA7QkxSq+rjXc0sGgqInceaEmMXVfhFWSmV64OMIyrcTvIPAzJaDlHsmRWtWBdnS925Ahm2ODWwCIefruc0c0/NX/4P3BKTJYbvSgJyQlLFWe1Y+YJRq4hHoXc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:2e49396xqa0qC6VbuuDiuiljnRgXq+ExCYuN4C8Ly0xcPPb/aUnmlfhxWy14qgWLkssXbUeGkROBnW9LuzPht7OmBK/oGnoikG/kwYKKWHMndy/huVvhr9vOGLYQtLXBNjJT/Up0TAnq31hJ4La2WbJyDLV3dS1UtsX1klrC2720wpGOe164cRMazse/QRy7Jmb0m+C8waX3O3pHDamVeZPl+dP/CJJiCUHH6a6dCenO5SFfftcsT36wQsdHvtYY X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2017 12:17:10.5265 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [PATCH v2 4/8] OvmfPkg/VirtioNetDxe: dynamically alloc transmit header 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, 11 Sep 2017 12:14:16 -0000 Content-Type: text/plain Each network packet is submitted for transmission by pushing the head descriptor of a two-part descriptor chain to the Available Ring of the TX queue. VirtioNetInitTx() sets up the the descriptor chains for all queueable packets in advance, and points all the head descriptors to the same shared, never modified, VIRTIO_1_0_NET_REQ header object (or its initial VIRTIO_NET_REQ sub-object, dependent on virtio version). VirtioNetInitTx() currently uses the header object's system physical address for populating the head descriptors. When device is behind the IOMMU, VirtioNet driver is required to provide the device address of VIRTIO_1_0_NET_REQ header. In this patch we dynamically allocate the header using AllocateSharedPages() and map with BusMasterCommonBuffer so that header can be accessed by both processor and the device. We map the header object for CommonBuffer operation because, in order to stick with the current code order, we populate the head descriptors with the header's device address first, and fill in the header itself second. 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/VirtioNetDxe/VirtioNet.h | 3 +- OvmfPkg/VirtioNetDxe/SnpInitialize.c | 64 +++++++++++++++++--- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 7 +++ 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/VirtioNet.h index 7d5f33b01dc8..3f48bcc6b67c 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -96,7 +96,8 @@ typedef struct { UINT16 TxMaxPending; // VirtioNetInitTx UINT16 TxCurPending; // VirtioNetInitTx UINT16 *TxFreeStack; // VirtioNetInitTx - VIRTIO_1_0_NET_REQ TxSharedReq; // VirtioNetInitTx + VIRTIO_1_0_NET_REQ *TxSharedReq; // VirtioNetInitTx + VOID *TxSharedReqMap; // VirtioNetInitTx UINT16 TxLastUsed; // VirtioNetInitTx EFI_PHYSICAL_ADDRESS RxBufDeviceBase; // VirtioNetInitRx } VNET_DEV; diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c index 54c808c501bf..6cedb406a172 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -18,6 +18,7 @@ **/ #include +#include #include #include @@ -147,6 +148,9 @@ ReleaseQueue: @retval EFI_OUT_OF_RESOURCES Failed to allocate the stack to track the heads of free descriptor chains. + @return Status codes from VIRTIO_DEVICE_PROTOCOL. + AllocateSharedPages() or + VirtioMapAllBytesInSharedBuffer() @retval EFI_SUCCESS TX setup successful. */ @@ -157,8 +161,11 @@ VirtioNetInitTx ( IN OUT VNET_DEV *Dev ) { - UINTN TxSharedReqSize; - UINTN PktIdx; + UINTN TxSharedReqSize; + UINTN PktIdx; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS DeviceAddress; + VOID *TxSharedReqBuffer; Dev->TxMaxPending = (UINT16) MIN (Dev->TxRing.QueueSize / 2, VNET_MAX_PENDING); @@ -170,12 +177,42 @@ VirtioNetInitTx ( } // + // Allocate TxSharedReq header and map with BusMasterCommonBuffer so that it + // can be accessed equally by both processor and device. + // + Status = Dev->VirtIo->AllocateSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *Dev->TxSharedReq), + &TxSharedReqBuffer + ); + if (EFI_ERROR (Status)) { + goto FreeTxFreeStack; + } + + ZeroMem (TxSharedReqBuffer, sizeof *Dev->TxSharedReq); + + Status = VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterCommonBuffer, + TxSharedReqBuffer, + sizeof *(Dev->TxSharedReq), + &DeviceAddress, + &Dev->TxSharedReqMap + ); + if (EFI_ERROR (Status)) { + goto FreeTxSharedReqBuffer; + } + + Dev->TxSharedReq = TxSharedReqBuffer; + + + // // In VirtIo 1.0, the NumBuffers field is mandatory. In 0.9.5, it depends on // VIRTIO_NET_F_MRG_RXBUF, which we never negotiate. // TxSharedReqSize = (Dev->VirtIo->Revision < VIRTIO_SPEC_REVISION (1, 0, 0)) ? - sizeof Dev->TxSharedReq.V0_9_5 : - sizeof Dev->TxSharedReq; + sizeof (Dev->TxSharedReq->V0_9_5) : + sizeof *Dev->TxSharedReq; for (PktIdx = 0; PktIdx < Dev->TxMaxPending; ++PktIdx) { UINT16 DescIdx; @@ -187,7 +224,7 @@ VirtioNetInitTx ( // For each possibly pending packet, lay out the descriptor for the common // (unmodified by the host) virtio-net request header. // - Dev->TxRing.Desc[DescIdx].Addr = (UINTN) &Dev->TxSharedReq; + Dev->TxRing.Desc[DescIdx].Addr = DeviceAddress; Dev->TxRing.Desc[DescIdx].Len = (UINT32) TxSharedReqSize; Dev->TxRing.Desc[DescIdx].Flags = VRING_DESC_F_NEXT; Dev->TxRing.Desc[DescIdx].Next = (UINT16) (DescIdx + 1); @@ -202,13 +239,13 @@ VirtioNetInitTx ( // // virtio-0.9.5, Appendix C, Packet Transmission // - Dev->TxSharedReq.V0_9_5.Flags = 0; - Dev->TxSharedReq.V0_9_5.GsoType = VIRTIO_NET_HDR_GSO_NONE; + Dev->TxSharedReq->V0_9_5.Flags = 0; + Dev->TxSharedReq->V0_9_5.GsoType = VIRTIO_NET_HDR_GSO_NONE; // // For VirtIo 1.0 only -- the field exists, but it is unused // - Dev->TxSharedReq.NumBuffers = 0; + Dev->TxSharedReq->NumBuffers = 0; // // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device @@ -223,6 +260,17 @@ VirtioNetInitTx ( *Dev->TxRing.Avail.Flags = (UINT16) VRING_AVAIL_F_NO_INTERRUPT; return EFI_SUCCESS; + +FreeTxSharedReqBuffer: + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *(Dev->TxSharedReq)), + TxSharedReqBuffer + ); +FreeTxFreeStack: + FreePool (Dev->TxFreeStack); + + return Status; } diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c index ee4f9ed36ecd..2ec3dc385a9f 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -54,6 +54,13 @@ VirtioNetShutdownTx ( IN OUT VNET_DEV *Dev ) { + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxSharedReqMap); + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *(Dev->TxSharedReq)), + (VOID *) Dev->TxSharedReq + ); + FreePool (Dev->TxFreeStack); } -- 2.9.4