From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0085.outbound.protection.outlook.com [104.47.33.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1DB7921DF969F for ; Mon, 7 Aug 2017 04:57: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=1h1RLOuEB3SdUkAR7BnSPoXHYqbdS4tUg0ZDcOu8kng=; b=KtzSRfoKBkubz/e/yInexrGcfHiVKaLYJnKXwZtGX5jKh/EmIhPJYYf4Gd3VxF2cid1MKYDly43AKas6bIw8awSE4GbqsKuBcPFpyHMyprz89rKbRCZn186gM5VpZiOPlAxra5jpVzlUEOcrmm9CxDLfNiVxe2Ewnznb3A2Amqk= 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:29 +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:57 -0400 Message-Id: <1502107139-412-13-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: a5758ce0-4720-48bf-b08b-08d4dd8bc29f 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:GLM7PJ+Kl6McBuUE1s3exBA6v5XcI1Um2W4fAL6K6EyPOBbyosN/c0TQBRcMNDATqKPWWoDR0lPx0bd2VscxUu2q5jX9ZR5QNPw+MAX7wnGMlpgyHGz9cgxSlrrgfuzk6qEAs+3TDpJkSjQQkPer7oCqfmnekuDOo3IxUuy47nEP8fUgOPMJj5eqMM7tVu6Eu3LbayHIwFSXwcI/1hoUTiMn/uHOUG34iJHPTNe8BkJ9lztJaesH5NHQro38r45c; 25:vzqe6HNL9ezcYrKWi7qsVlVG0RoyN8v9Ap15BJQEXWy/ifEY3L34HqbJqgqYdJDrjzL0DihSIbHh69cPtOFRwGnV7kQLfwRFcerEHHGXSsk4mrGDIDBl8jnfEdbF40XCmUHhKMqMw8K1Q3la5nSjV+JAUudvX4gC6zIfGNLOpcOneSqyq09FKBUCkaPGE6haGFTsn6MnvsDhhMDLpjI78uxKEB9lh0NSxw9zrYJndeWfvylozgU89rvp/TJ2Y7VIUsfE4WOnGyFrcoGcMdHX/wzsUux2wnAqyHWMoTt0psMwx+lTsmEUGQs5uCGVHCue2QQLBeME7K7ZsTvaEBI9VQ==; 31:fB2IZET/hsHNs4YeWjZAJYAOWnslf8Au0jTwqESDJk4y8szCdzrtTKqyOnDUwUUh+q1SUoLNq4TIkRZG/574J3c0JTNXoTaUXm5IDDGu5fe07/z2hy7dfKfYiAkFe8+wiOPY9353IbA4Xxo6Dpm9matVwJLrCmIIt3j0wJ7pQnhXeUpnzdgjYsKBi64uWbImUO3cAUZCL2gMoZt7fyOUkeQIaITAQP4diDOirDLLyFE= X-MS-TrafficTypeDiagnostic: SN1PR12MB0159: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0159; 20:AppllFPF0tr0P794yWDtDU0FWmJRX09DQs1qOiy02V0KJqFykR7qXZFauwylQZYiR65OMQcHcTkOHiDqFh/O/VGsAjNZESbXCWOmuOcl0MlbkpuiH9bcP6FAglIkWJtFMo2TX6j3dXTXmvEoo+5Vj0LjDdusKApzGNFzM2H3LmJ62OExl7ZWHpDcdBzAyuuptIQHO9CazUbFTG6t/8ueSr612cwt1eOcHRHLoCTSCLpX75j328eV1nU8UnUN+09Ei/ETZcLVoHIPOopkEpC89IszNuGUQ3La5B20dJKoz3vELfi7z9XYIHCShqyDGV+16MwW+BlG3RrvrRb/SirCl8NslbDNZ7gmaLxVEf7xSOXST6bQxFCBB1DXCmB0vmFehPsQJfOZ9gZX5bv5YJx1bXg2vmoLBVeJeBPCWytb14K/cP0tqWE/gTtHe6BqWwo52zYItILx+GMcXeM2oIhcd6V4B9/LvDzSMRfWFzP/Za+yIpWvW5cdEB1aXAvW0yau; 4:BjVUe4x9Dj400p8ckPRpDZhjGoo5knuLZkGpkDj5CQ0iZAP2Ux0QFT2HNJIJopexEDvAAS3Bz0F1SHnqyp7bTJkWakh+X+LVEy+O2LCJa03nqnJlhasCx5vlElzW9hGUivjHNnEmaNO4II8R4UEAC/GIiWepqmEFze3NHawpEZUVeOP2bFo2U/2mhDoeKjnpMMa+Qp71TGigPjqPwww6ZWuo2N6ElTY0+OWkU0XlUMvAnoIGeSOCsmV5R+FbEv/ovqyGYB1plGVrd5Rdvqv4jo1Iz1mSUUSJ8UIduvBuaWzwh90imk7ehxQ3PWLWnO2Mbr4GJ8nxwxz8K+KobeInSw== 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)(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)(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:VgsFtWesqNKY5+yrAGtw/NFzJOOHbA2IFQU8x7rtT?= =?us-ascii?Q?3MoIPJLHfx+5XLljUBTo5KtB6wvvA27cGL6E27KK+UBaLjqquhFtlzSreWXQ?= =?us-ascii?Q?2WcfWTAP7hG5kDL3m9TLyfUseD+AS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myiH1b4QCaf2GTNUPsC2QRrg63KuFgPLHBOGzp86+1AZSt0ZrxXEyap+FFF88IsdyksGi1Z7pC3TzZu79FfQytVeFaHDvMlhwl5EKElzAdCZoZfGZxvFGol123S4lOdvlJTztdManKapq0F9iyIwa+jeBRc+6T1MDRn7kJZ7Tk/E0qONIdh9Yh1/gXbUbz5N+6c+18bz7A0eUwzfN6DO/7b240bMM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0159; 20:XnsI1k9LqOJtcy213kLPyCgblMJg883VtQkYohgsvsHsf+1IyEJ0O12QGGUFU3MOBk5l0kLWaJv3Lp3wL2N/31ReAyo3VahJxCnUwHmmk4KnSV1AmBDKB5Pls3xDw7CELdMOVpKce3m7L+HhH7IKQWbS5Ejepvn1CmjrUNyMS6uP0pgUoAZkwc8OQvW7BxWT27nGAX4IOP3RX0Sr7bvjVKIGBLNlngq9XBfBTlRonq5D0UxrEaao0vyBSt7h5LGx X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2017 11:59:29.7303 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0159 Subject: [PATCH v1 12/14] OvmfPkg/VirtioNetDxe: Dynamically allocate 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, 07 Aug 2017 11:57:16 -0000 Content-Type: text/plain A network packets are transmitted by placing then into a transmit queue, each packet is preceded by a VIRTIO_1_0_NET_REQ header. VirtioNetInitTx(), builds the header once and fills the vring descriptors with the system physical address of header. The patch uses VirtIo->AllocateSharedPages() to allocate the header buffer and map it with BusMasterCommonBuffer so that it can be equally accessed by both processor and device. We could map it with BusMasterRead but since the header pointer is used after it was added into vring hence I choose to dynamically allocate it and map it with BusMasterCommonBuffer to avoid the code complexity. 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/Events.c | 5 +++ OvmfPkg/VirtioNetDxe/SnpInitialize.c | 41 ++++++++++++++++---- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 9 +++++ 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/VirtioNet.h index a4661bd5d2fe..873069e9de82 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -94,7 +94,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/Events.c b/OvmfPkg/VirtioNetDxe/Events.c index 171b144518a9..0004898eab6e 100644 --- a/OvmfPkg/VirtioNetDxe/Events.c +++ b/OvmfPkg/VirtioNetDxe/Events.c @@ -107,4 +107,9 @@ VirtioNetExitBoot ( VirtioUnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap); Dev->RxBufMap = NULL; } + + if (Dev->TxSharedReqMap != NULL) { + VirtioUnmapSharedBuffer (Dev->VirtIo, Dev->TxSharedReqMap); + Dev->TxSharedReqMap = NULL; + } } diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c index 59c9f1ed3516..9df9f7af32cc 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -18,6 +18,7 @@ **/ #include +#include #include #include @@ -139,8 +140,10 @@ VirtioNetInitTx ( IN OUT VNET_DEV *Dev ) { - UINTN TxSharedReqSize; - UINTN PktIdx; + UINTN TxSharedReqSize; + UINTN PktIdx; + UINTN NumPages; + EFI_STATUS Status; Dev->TxMaxPending = (UINT16) MIN (Dev->TxRing.QueueSize / 2, VNET_MAX_PENDING); @@ -152,12 +155,34 @@ VirtioNetInitTx ( } // + // Allocate TxSharedReq header and map with BusMasterCommonBuffer so that it + // can be accessed equally by both processor and device. + // + NumPages = EFI_SIZE_TO_PAGES (sizeof *(Dev->TxSharedReq)); + Status = VirtioAllocateSharedPages (Dev->VirtIo, NumPages, + (VOID *) &Dev->TxSharedReq); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = VirtioMapSharedBufferCommon (Dev->VirtIo, + (VOID *) Dev->TxSharedReq, sizeof *(Dev->TxSharedReq), + &Dev->TxSharedReqMap); + if (EFI_ERROR (Status)) { + VirtioFreeSharedPages (Dev->VirtIo, NumPages, + (VOID *) Dev->TxSharedReqMap); + return Status; + } + + ZeroMem ((VOID *) Dev->TxSharedReq, sizeof *(Dev->TxSharedReq)); + + // // 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; @@ -169,7 +194,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 = (UINTN) Dev->TxSharedReq; Dev->TxRing.Desc[DescIdx].Len = (UINT32) TxSharedReqSize; Dev->TxRing.Desc[DescIdx].Flags = VRING_DESC_F_NEXT; Dev->TxRing.Desc[DescIdx].Next = (UINT16) (DescIdx + 1); @@ -184,13 +209,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 diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c index 48cd4900911c..3ed7132be531 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -57,5 +57,14 @@ VirtioNetShutdownTx ( IN OUT VNET_DEV *Dev ) { + if (Dev->TxSharedReqMap != NULL) { + VirtioUnmapSharedBuffer (Dev->VirtIo, Dev->TxSharedReqMap); + Dev->TxSharedReqMap = NULL; + } + + VirtioFreeSharedPages (Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *(Dev->TxSharedReq)), + (VOID *) Dev->TxSharedReq); + FreePool (Dev->TxFreeStack); } -- 2.7.4