From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0050.outbound.protection.outlook.com [104.47.41.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 83D6221E3EA67 for ; Thu, 14 Sep 2017 04:05:41 -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=IUKI7M0QVIEu1pHDULVf7XYDV3zS5Ygn0OSynTldqzM=; b=gplxm7Gy5UtXju7r2PCNJSAmNqgp3hcbah3gcWyRfkMtCrksBwp3o5/iINVjFB3wKa0Eelp7j339ZihIe9Ka1VrnsRnxX74GiOvL9GyHbdI4wBvOK4LIO/QENGBB4jGJWY8JnSgLkHHCaBj34bxKzqK3lsankQKwki/d7LfX5nA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from ubuntu-010236106000.amd.com (165.204.78.1) by DM2PR12MB0156.namprd12.prod.outlook.com (2a01:111:e400:50ce::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Thu, 14 Sep 2017 11:08:38 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Thu, 14 Sep 2017 06:08:18 -0500 Message-Id: <20170914110822.112540-5-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20170914110822.112540-1-brijesh.singh@amd.com> References: <20170914110822.112540-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: BN6PR08CA0083.namprd08.prod.outlook.com (2603:10b6:404:b6::21) To DM2PR12MB0156.namprd12.prod.outlook.com (2a01:111:e400:50ce::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 861ce9f8-838d-455b-8332-08d4fb60f39d 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:DM2PR12MB0156; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 3:UBvlSy0ncRemylO/hA1grYH6MWWBowmIjvNMkRH5KSxi9Q0LrBKHd+MmY/M6q0Gq7L6/w8iV7q1hyBNX7mhiSWLvK1M7xFH+6W1RJjfoX73fLrDbR5s0kPYX4OTwsopzfPT636wcdlx4uCMMH5Ru9BO+0rKt2TrndS3W4ePp6qLws0dduqC1hHpzlLmlNyZ20hd+jgi9rlFBAR69a2FsO+or2xcs1ugJyOPxi5YxWJvkXI71YG7rZFHn7RJuLdfl; 25:FUiPRgMvMXvkNCww3p0snM7QfpmDh71/kCRtaXbTpkJXKUmaGwusF9NmfLcmthvwWW5tfNKKjBZv2m7LyzwQmn+GIxUDtzOqwgXzGx0oZJ084OhCWyRtZ0OwYuJTTtukAlSS+EgdLzIAiW/ZdNDV4q7cchD1X6b3JZlGBYFonbFBjeQFr151kqxXNPHn1C8Gft4sl4ZffCbVotVDKr8FH26/WkXVj4MWX+eYtmBKJgvlR2uR0ILRcQuI8PTGV247R8cfrN1N+QKuK59+mioLrSs0HmwxJFtKSJXFoHxPNGjL2oZvTYhqRkttiDBdMczkHh8PBaXCvmYhmq9HWz9S3w==; 31:iEhDmvn01bgWphFJdMYk5UtretjzW6l0ga3W5vCvT7XP022GKRt8Ez+YuSVTRHGPt0Wt+yd5iV0qIz9ZOAKOVdduj6pZqKhjV7gx9kdSQDkeRBZalJJ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: 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)(10201501046)(93006095)(93001095)(3002001)(100000703101)(100105400095)(6055026)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(20161123564025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM2PR12MB0156; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM2PR12MB0156; X-Forefront-PRVS: 0430FA5CB7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(39860400002)(189002)(199003)(51234002)(189998001)(50986999)(76176999)(105586002)(106356001)(33646002)(2361001)(2351001)(5660300001)(6666003)(6916009)(2950100002)(6116002)(25786009)(36756003)(1076002)(101416001)(68736007)(3846002)(53416004)(16586007)(6486002)(478600001)(97736004)(50226002)(110136004)(81156014)(47776003)(48376002)(16526017)(81166006)(54906002)(8676002)(8936002)(7736002)(316002)(305945005)(2906002)(4326008)(53936002)(86362001)(5003940100001)(50466002)(66066001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0156; 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; DM2PR12MB0156; 23:x6MSxHY83fVCts07lOE/H/sfI8xmPFSkofcDs8KYu?= =?us-ascii?Q?uv+NY2uEe2lez5LNmUKy0SM1T5GTXul/8AEJw+F/cGzIBcU5LJEgFTTGCc+u?= =?us-ascii?Q?MZ+IPFklfkMRxqrR3GQDo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+WOuSoOG3sIMdZrIwDfOXOv5JzpPPKA073rMDm+0GANHDnOhdi51AwPP3WUOGtFq+UAzFrP61spF9Wfgvr9zuy3I= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 20:y55UxgZ3xWY+5rqk6PZLvt3HqnhnmNBtxY9EuV00BCBpsd/xaqHWm9qKsm5pQXRoMdsG6BEI+3Kaa/qxUCB+MDMAfLHzG26tmLG470e1ecYZ0rJqQfZ/4d9MrQJNFgHpEwkTumvAux3nmeMsHzbeer5ZTvDz3i5cT7nlejd4PdZDMUl2Lgo/021vtexrFOOhCJqiBxYMlBFYhJfh0Mg4YgsaJigtvcHoWpWQlCC48FY+0O3KK9l75E6Hh3ofeHxG X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2017 11:08:38.2450 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0156 Subject: [PATCH v3 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: Thu, 14 Sep 2017 11:05:41 -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 995593f4b236..027f75993e8e 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -97,7 +97,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 } VNET_DEV; diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c index b739875d4c01..9621f936d2cb 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..2fce8142d554 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)), + Dev->TxSharedReq + ); + FreePool (Dev->TxFreeStack); } -- 2.9.5