From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0068.outbound.protection.outlook.com [104.47.40.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 15AED21D0A277 for ; Mon, 14 Aug 2017 04:35:07 -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=AdG9CClAiaKFx+VBu53mqO5txZGQUB/+gMsc6f+/Dis=; b=cXjbCbWprt5IIEC8pP74+3EevuxEOKYFFLurll/V1ylMOoOp2H7wR8vP5shNWM2Dmewt2ikSCXUMf8IkiWE/tVTtjIl1HzjpMX6vCBnRsF1uyKm4l9AW6Gg7HTBHWcXLamAMEq3Plv7Cy7nz+MqxfyX7rzU1Cmt8jHQJ+P5KxCo= 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:27 +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:44 -0400 Message-Id: <1502710605-8058-23-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: 7e84edf0-fc1e-46a6-9a1a-08d4e308d7c2 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:4QfoGxbcabrHaPZBN3Nb9dZIxoZ741G3ope/PYHGOAYTau7TSlSuSqfaNM4MiZS2SH1sBUoGJJaRrUu7SWY/UgxZuv9rr2MKFBRbKn658+oL/kicFXUYd2NmrC41xYtc/PJzcIfRzHu4VFuRJJY6Zp5RGnHJHCkxR5gipy3O4QI8g7AVSsm6PtfSfrcMQyj9BNKCTGI/qGeYO4BvyHx5ag53CrZ/4tR2HIKSaKP/ytKZ6tQ+wKBz1KSD7aHj0R1l; 25:pF4NV43ofPzIizDxGnEKPVvv2F47J0I1JMBOEKm6r3PcpbKbsz9B6HXUkd8eV/fhzbRlTkgP1hoY5VYJOu/ODpIq+X33JhrR/7P578onuhiEQHpMm61aRA+sC80xm0E1tuzdAWkIIZWXFlZuraVCRNSE9FLzntxEYgJvKvZxTJ4HnfmNB7+uQ58nscPr9ZhrjEew/ryTLoKeUIn+4LNVY9I7Tt7u8B8KVb7WzhzS5EoF14q4BhBudXpXkT0Olb6nboYHZ2NANmQ2SS/tGD77FX2t2oOMwIPtYnlHv6wL+eGx7zpwboFAdqfp/1bKtENCWJEjJ3LZ3UL5ELFoRqWdyw==; 31:Ns6TqhXZPeII3Ga+XY56oJk/p4mfW3L91pc+vbKzB8g1lSWvvU4UNbzkqlqT7O89rVR0LTLA+l+8rvkbcQ1bWQjcURkI7RB/95dncWLkY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/5rX7A= X-Exchange-Antispam-Report-Test: UriScan:(20558992708506)(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)(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)(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:SQE30cPOIPIcaDIp2jXP16IOfUMS8Goqm/FlRfb9n?= =?us-ascii?Q?CYSAgex4MlvhOahnI+2dImKXHfelT/nrHzZwRgHTNN+sFY+0kQ2aEmY9Rj19?= =?us-ascii?Q?MN3Yk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rva21mIBzgzOSSTw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 20:x24dgs/OVMKlutQr2wzoFn/D+vtwYAzKIPqUfrZ9skbTlfwOXEBnr38WbEgfHtY3/4fGE50VnHkPeG1JvtvRku1QQ20W2GnXB009VCzhMpltc4SjCMwjNcCRPaCfE5Zm3XDVgtmO5+cgsYB8g816pMwFYPJc95Ky9Ky5ZEHTb9GHywwzwn00W5xzh5m3HM5STznF+ZKcRJvr8EvcIMjWko50A/RVYpFxTQVFNswcnwt6U8UOgKBCv5n2h9Wq7kNS X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2017 11:37:27.8930 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0145 Subject: [PATCH v2 22/23] OvmfPkg/VirtioNetDxe: map transmit buffer host address to device address 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:07 -0000 Content-Type: text/plain Update VirtioNetTransmit() to map the callers transmit buffer to a device address and use the DeviceAddress in vring descriptors. Since the transmit buffers are returned back to caller in VirtioNetGetStatus() hence we maintain a simple list to map DeviceAddress to HostAddress. The list is used for mapping to HostAddress after the data is succesfully transmitted. 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 | 17 +++ OvmfPkg/VirtioNetDxe/SnpGetStatus.c | 19 +++- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 115 ++++++++++++++++++++ OvmfPkg/VirtioNetDxe/SnpTransmit.c | 26 ++++- OvmfPkg/VirtioRngDxe/VirtioRng.c | 2 +- 5 files changed, 169 insertions(+), 10 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/VirtioNet.h index 873069e9de82..6c5129f178cd 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -269,6 +269,23 @@ VirtioNetShutdownTx ( IN OUT VNET_DEV *Dev ); +EFI_STATUS +EFIAPI +VirtioMapTxBuf ( + IN VNET_DEV *Dev, + IN EFI_PHYSICAL_ADDRESS HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress + ); + +EFI_STATUS +EFIAPI +VirtioUnmapTxBuf ( + IN VNET_DEV *Dev, + OUT EFI_PHYSICAL_ADDRESS *HostAddress, + IN EFI_PHYSICAL_ADDRESS DeviceAddress + ); + // // event callbacks // diff --git a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c b/OvmfPkg/VirtioNetDxe/SnpGetStatus.c index 694940ea1d97..ddea29e65d57 100644 --- a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c +++ b/OvmfPkg/VirtioNetDxe/SnpGetStatus.c @@ -5,6 +5,7 @@ Copyright (C) 2013, Red Hat, Inc. Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, AMD Inc, All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this @@ -126,8 +127,10 @@ VirtioNetGetStatus ( *TxBuf = NULL; } else { - UINT16 UsedElemIdx; - UINT32 DescIdx; + UINT16 UsedElemIdx; + UINT32 DescIdx; + EFI_PHYSICAL_ADDRESS DeviceAddress; + EFI_PHYSICAL_ADDRESS HostAddress; // // fetch the first descriptor among those that the hypervisor reports @@ -141,9 +144,19 @@ VirtioNetGetStatus ( ASSERT (DescIdx < (UINT32) (2 * Dev->TxMaxPending - 1)); // + // Unmap the DeviceAddress + // + DeviceAddress = Dev->TxRing.Desc[DescIdx + 1].Addr; + Status = VirtioUnmapTxBuf (Dev, &HostAddress, DeviceAddress); + if (EFI_ERROR (Status)) { + goto Exit; + } + + // + // // report buffer address to caller that has been enqueued by caller // - *TxBuf = (VOID *)(UINTN) Dev->TxRing.Desc[DescIdx + 1].Addr; + *TxBuf = (VOID *)(UINTN) HostAddress; // // now this descriptor can be used again to enqueue a transmit buffer diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c index 6e7166144f2d..3dbfc272980a 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -14,10 +14,29 @@ **/ +#include #include #include "VirtioNet.h" +#define PRIVATE_TXBUF_SIGNATURE SIGNATURE_32 ('t', 'x', 'b', 'f') +typedef struct { + UINT32 Signature; + LIST_ENTRY Link; + EFI_PHYSICAL_ADDRESS HostAddress; + EFI_PHYSICAL_ADDRESS DeviceAddress; + VOID *Mapping; +} PRIVATE_TXBUF_ENTRY; +#define PRIVATE_TXBUF_FROM_LINK(a) CR (a, PRIVATE_TXBUF_ENTRY, Link, \ + PRIVATE_TXBUF_SIGNATURE) + +// +// List of Txbuf queued +// +STATIC LIST_ENTRY mTxBufMapList = INITIALIZE_LIST_HEAD_VARIABLE ( + mTxBufMapList + ); + /** Release RX and TX resources on the boundary of the EfiSimpleNetworkInitialized state. @@ -61,3 +80,99 @@ VirtioNetShutdownTx ( FreePool (Dev->TxFreeStack); } + +EFI_STATUS +EFIAPI +VirtioMapTxBuf ( + IN VNET_DEV *Dev, + IN EFI_PHYSICAL_ADDRESS HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress + ) +{ + EFI_STATUS Status; + PRIVATE_TXBUF_ENTRY *Private; + + Private = AllocatePool (sizeof (*Private)); + if (Private == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Private->Signature = PRIVATE_TXBUF_SIGNATURE; + Private->HostAddress = HostAddress; + + Status = VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterRead, + (VOID *) (UINTN) Private->HostAddress, + NumberOfBytes, + &Private->DeviceAddress, + &Private->Mapping + ); + if (EFI_ERROR (Status)) { + goto FreePool; + } + + *DeviceAddress = Private->DeviceAddress; + + // + // Add the mapping information into internal list so that we can retrieve + // the HostAddress from Unmap(). + // + InsertTailList (&mTxBufMapList, &Private->Link); + + return EFI_SUCCESS; + +FreePool: + FreePool (Private); + return Status; +} + +EFI_STATUS +EFIAPI +VirtioUnmapTxBuf ( + IN VNET_DEV *Dev, + OUT EFI_PHYSICAL_ADDRESS *HostAddress, + IN EFI_PHYSICAL_ADDRESS DeviceAddress + ) +{ + EFI_STATUS Status; + PRIVATE_TXBUF_ENTRY *Private; + LIST_ENTRY *Link; + BOOLEAN Found; + + Found = FALSE; + + // + // Iterate through internal txbuf list to find mapping for a given + // DeviceAddress. + // + for (Link = GetFirstNode (&mTxBufMapList) + ; !IsNull (&mTxBufMapList, Link) + ; Link = GetNextNode (&mTxBufMapList, Link) + ) { + Private = PRIVATE_TXBUF_FROM_LINK (Link); + if (Private->DeviceAddress == DeviceAddress) { + Found = TRUE; + break; + } + } + + // + // We failed to find mapping for the given DeviceAddress + // (this should never happen) + // + ASSERT (Found); + + Status = Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Private->Mapping); + if (EFI_ERROR (Status)) { + return Status; + } + + *HostAddress = Private->HostAddress; + + RemoveEntryList (&Private->Link); + FreePool (Private); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/VirtioNetDxe/SnpTransmit.c b/OvmfPkg/VirtioNetDxe/SnpTransmit.c index 7ca40d5d0650..9d7d017d5a6f 100644 --- a/OvmfPkg/VirtioNetDxe/SnpTransmit.c +++ b/OvmfPkg/VirtioNetDxe/SnpTransmit.c @@ -73,11 +73,12 @@ VirtioNetTransmit ( IN UINT16 *Protocol OPTIONAL ) { - VNET_DEV *Dev; - EFI_TPL OldTpl; - EFI_STATUS Status; - UINT16 DescIdx; - UINT16 AvailIdx; + VNET_DEV *Dev; + EFI_TPL OldTpl; + EFI_STATUS Status; + UINT16 DescIdx; + UINT16 AvailIdx; + EFI_PHYSICAL_ADDRESS DeviceAddress; if (This == NULL || BufferSize == 0 || Buffer == NULL) { return EFI_INVALID_PARAMETER; @@ -144,10 +145,23 @@ VirtioNetTransmit ( } // + // Map the transmit buffer HostAddress to a DeviceAddress + // + Status = VirtioMapTxBuf ( + Dev, + (EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, + BufferSize, + &DeviceAddress + ); + if (EFI_ERROR (Status)) { + goto Exit; + } + + // // virtio-0.9.5, 2.4.1 Supplying Buffers to The Device // DescIdx = Dev->TxFreeStack[Dev->TxCurPending++]; - Dev->TxRing.Desc[DescIdx + 1].Addr = (UINTN) Buffer; + Dev->TxRing.Desc[DescIdx + 1].Addr = (UINTN) DeviceAddress; Dev->TxRing.Desc[DescIdx + 1].Len = (UINT32) BufferSize; // diff --git a/OvmfPkg/VirtioRngDxe/VirtioRng.c b/OvmfPkg/VirtioRngDxe/VirtioRng.c index fc01f1996654..b19d90901430 100644 --- a/OvmfPkg/VirtioRngDxe/VirtioRng.c +++ b/OvmfPkg/VirtioRngDxe/VirtioRng.c @@ -162,7 +162,7 @@ VirtioRngGetRNG ( Dev = VIRTIO_ENTROPY_SOURCE_FROM_RNG (This); // - // Map the Buffers system phyiscal address to device address + // Map the Buffer host address to device address // Status = VirtioMapAllBytesInSharedBuffer ( Dev->VirtIo, -- 2.7.4