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 3DC8321E2BE40 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=FhRshVQzt0bJo6uetGEqjAb9wnaiPokIX14eq8fWG8I=; b=k80g5J4rLzeY+DJ4ycRMx30AxxuP2FhMETDDjBAobxkfxQtQx64vL08btphBxIUB+yd1pnbXcFE/mfxROtvPxqEkBCtATSBtY5GyEeAZ/45IJHRut3LC9s60T7BiUdZe1JxXKl0Nw08rwbj0Rou6ZzclbZol2AB7kc3cFFGhPfQ= 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:37 +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:17 -0500 Message-Id: <20170914110822.112540-4-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: b11a714b-4ddc-49a1-137c-08d4fb60f30c 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:cyii8KqZco7PHmU2v352tRF3EgsTzXnBM2dXSNQRNTfH8udGLuu+zfhq2OVrKN8GWj/G+CSu5Itu8ShHUZmrprYpOiVDhS5PTHM0zQRlidCvjZrtyWCI8n84gWHSKkaOlDRIXSGX725soXaF6pk7K7civLn1/8ZWaHW5KaWtj/yR+9XQhbnfRaCS+kPgpByLZCpwkjdMHwgRp++fNVtwDVH79/dPXI5janr9OaE8k/5bgllkH1Y023MgkYqZHdWZ; 25:vJaUyQW9xo0kDXmkdzEcEkGUxKFd4HyCG6jdlmxUUNsbi5ClD4LPihLcoBPIG2ZyWQAUgf6g17+g2mgBo5N7xLXgHhe/418qHFiSXZMxQaL+hPciBfZJGj+Gvf8tbvmxaxBsMAa2Q1eED/mJqxlnpdZLf3kdSHE4TkKbVmI56RhzLSjw6pFDHWDT0qPWDFZ0XDjknI6ZrNKB4CdX3apS5g9kMe8RYQDh2kpPJetfaVc1KBkaf5MECtfEPhNJdoJIqTLvoX9WR1jpslTUeF5JZu5mfgWNyCImFefK2jLUaG1ZKBm012FzxJZuttG3E7Nl+Ob6VgR/9w4iJtQ4OAyNgQ==; 31:hE4I/4SDDLj7r3TDhlsOdSbeyEekQV/xyk+DeYjRfwDlRe5uyQhziaBhJaujt1/pHEJinTFavpYbv5hPVQ4TJCIsLjDu0VHlRjXjkCc6Ov/0lUGozqpz7+kVEkAt5PmxlV+TKsPK6YZPnQW39vUKreUllzxARH87czhbOrM/l1/jD/LkzpixI5DVUr+v2JyVAhq9xB6Iq97WTCDOko6V+h/ycFfOMcGa7gXGY+epjWU= X-MS-TrafficTypeDiagnostic: DM2PR12MB0156: X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 20:uR06AYWLiEhrpe3TxLpXY3bNd+SSqBHPubjfZAshHxsPLuygl6Ov9kBM/kQt92Lj0ybFplFV3gAdoVJYFJohFffYtl8gZ6hfLUc2FI+jEdSq3vkMWr4DGlutO7a9eHAol5x8xq0W2/y4ulxs2q9uYky1O6IH19ddWll3PhfhGjS31PfhzsnZJC7jtgIA6CGyvsVKfiziuZSH/2Mlkx/bzdJRX7kxVKZapLLMhlhbS++W8997SzOrvVNzz7FigH6jopZERIYqLqa5mBEPAi+sh73+Ncl5T+lD0D9jwueLfjIBzlbuXLZ7ItDAjzDfndEo31TD68eA0PebYKG7abfai/XtzyayyzTUZKEz9h4skS1/ciWmlUqY/ahHKZKs/lJ4jH1a9ZkhX6yFCXqb2Pf3dBSPSibcUp/fFdptsDYx9qMlST4eACjeuy8jag6gL2H+fRQngazTh/47WL6TlMvLqrpxqbta26LC/RRREhDA8OIq8XiTOcJ8vFX0PT9Q2JNy; 4:sR1XTVWVWAYv/Sh0Qsr+6KRai3Ev3sLioAimIFw1TEEebi1xhfNbBtToqip6qznk+utUfutWdG/1JTX/XB6iCPujOMYoTPhTZeVX5WFaJCIT9NpHJZ+pyF0WM4T5pcYIaTIQWBagHDcd84IaNW/LRsdmdiG3TiqIvBjmm4q5bQirUq49lqoTMTIQnrtD/0RZ4MSGN6mrOX9cywOMzAHHWRMFCdP/iGTS5wm15qag8kklKTuhSxQ97WsKgzrPHopf5r4FK+E2Dx867+0TvRMcriGuucBndZ/xwbCQepHZxMLSs5QuX0Br3MeAbVzlFHhynlM04xNlUMtuHDdRlDB1hg== 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)(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)(6029001)(6009001)(346002)(376002)(39860400002)(189002)(199003)(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:B/BykwUDxb9nH6ZipenOYYTPaMdu3OSxPR6DV64dI?= =?us-ascii?Q?t2/fI0N/vkszFs3WQwHlfxdQQk0uM2q9yQjfgAgHZ5Fvn3UJ0wZBwH5xVjY2?= =?us-ascii?Q?yfcUFYl7ZI+lRNBbSACqT8BRW1pvXSthwc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XWm+N3jDWN861IojjvABruy0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 20:vxrz366YFnDb9oNw4X2vk9pqhyzRIOPTWXofOOtp/z5A7BUP5XW1rCH64Eob1fWRDJI5AgYSjUH9rzDQQoaGw/gH1kT3M+XJhqVRcYaZL+FpIqVAJBDiQuUQ7w86wx2xmxrT/LmvUnaOfeza3kjJdWCbW50sHqxOoZ6iIW4hGpGC8NDlKx49fAZxWDzpJE9lvLj80J1uoKi0oUPzhMSocG2sajwUTLIi8nzREOOQq1i5TUjG8mLLKwAug7FsRVVR X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2017 11:08:37.2763 (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 3/8] OvmfPkg/VirtioNetDxe: alloc RxBuf using AllocateSharedPages() 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 When device is behind the IOMMU, VirtioNetDxe is required to use the device address in bus master operations. RxBuf is allocated using AllocatePool() which returns the system physical address. The patch uses VIRTIO_DEVICE_PROTOCOL.AllocateSharedPages() to allocate the RxBuf and map with VirtioMapAllBytesInSharedBuffer() so that we can obtain the device address for RxBuf. 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 | 4 + OvmfPkg/VirtioNetDxe/SnpInitialize.c | 78 +++++++++++++++----- OvmfPkg/VirtioNetDxe/SnpReceive.c | 5 +- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 7 +- OvmfPkg/VirtioNetDxe/TechNotes.txt | 2 +- 5 files changed, 75 insertions(+), 21 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/VirtioNet.h index 6762fc9d1d6e..995593f4b236 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -4,6 +4,7 @@ Protocol instances for virtio-net devices. Copyright (C) 2013, Red Hat, Inc. + 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 @@ -86,6 +87,9 @@ typedef struct { // VirtioNetInitRing UINT8 *RxBuf; // VirtioNetInitRx UINT16 RxLastUsed; // VirtioNetInitRx + UINTN RxBufNrPages; // VirtioNetInitRx + EFI_PHYSICAL_ADDRESS RxBufDeviceBase; // VirtioNetInitRx + VOID *RxBufMap; // VirtioNetInitRx VRING TxRing; // VirtioNetInitRing VOID *TxRingMap; // VirtioRingMap and diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c index 8eabdbff6f5e..b739875d4c01 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -242,8 +242,9 @@ VirtioNetInitTx ( @param[in,out] Dev The VNET_DEV driver instance about to enter the EfiSimpleNetworkInitialized state. - @retval EFI_OUT_OF_RESOURCES Failed to allocate RX destination area. - @return Status codes from VIRTIO_CFG_WRITE(). + @return Status codes from VIRTIO_CFG_WRITE() or + VIRTIO_DEVICE_PROTOCOL.AllocateSharedPages or + VirtioMapAllBytesInSharedBuffer(). @retval EFI_SUCCESS RX setup successful. The device is live and may already be writing to the receive area. */ @@ -255,13 +256,15 @@ VirtioNetInitRx ( IN OUT VNET_DEV *Dev ) { - EFI_STATUS Status; - UINTN VirtioNetReqSize; - UINTN RxBufSize; - UINT16 RxAlwaysPending; - UINTN PktIdx; - UINT16 DescIdx; - UINT8 *RxPtr; + EFI_STATUS Status; + UINTN VirtioNetReqSize; + UINTN RxBufSize; + UINT16 RxAlwaysPending; + UINTN PktIdx; + UINT16 DescIdx; + UINTN NumBytes; + EFI_PHYSICAL_ADDRESS RxBufDeviceAddress; + VOID *RxBuffer; // // In VirtIo 1.0, the NumBuffers field is mandatory. In 0.9.5, it depends on @@ -286,11 +289,39 @@ VirtioNetInitRx ( // RxAlwaysPending = (UINT16) MIN (Dev->RxRing.QueueSize / 2, VNET_MAX_PENDING); - Dev->RxBuf = AllocatePool (RxAlwaysPending * RxBufSize); - if (Dev->RxBuf == NULL) { - return EFI_OUT_OF_RESOURCES; + // + // The RxBuf is shared between guest and hypervisor, use + // AllocateSharedPages() to allocate this memory region and map it with + // BusMasterCommonBuffer so that it can be accessed by both guest and + // hypervisor. + // + NumBytes = RxAlwaysPending * RxBufSize; + Dev->RxBufNrPages = EFI_SIZE_TO_PAGES (NumBytes); + Status = Dev->VirtIo->AllocateSharedPages ( + Dev->VirtIo, + Dev->RxBufNrPages, + &RxBuffer + ); + if (EFI_ERROR (Status)) { + return Status; } + ZeroMem (RxBuffer, NumBytes); + + Status = VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterCommonBuffer, + RxBuffer, + NumBytes, + &Dev->RxBufDeviceBase, + &Dev->RxBufMap + ); + if (EFI_ERROR (Status)) { + goto FreeSharedBuffer; + } + + Dev->RxBuf = RxBuffer; + // // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device // @@ -310,7 +341,7 @@ VirtioNetInitRx ( // link each chain into (from) the available ring as well // DescIdx = 0; - RxPtr = Dev->RxBuf; + RxBufDeviceAddress = Dev->RxBufDeviceBase; for (PktIdx = 0; PktIdx < RxAlwaysPending; ++PktIdx) { // // virtio-0.9.5, 2.4.1.2 Updating the Available Ring @@ -321,16 +352,16 @@ VirtioNetInitRx ( // // virtio-0.9.5, 2.4.1.1 Placing Buffers into the Descriptor Table // - Dev->RxRing.Desc[DescIdx].Addr = (UINTN) RxPtr; + Dev->RxRing.Desc[DescIdx].Addr = RxBufDeviceAddress; Dev->RxRing.Desc[DescIdx].Len = (UINT32) VirtioNetReqSize; Dev->RxRing.Desc[DescIdx].Flags = VRING_DESC_F_WRITE | VRING_DESC_F_NEXT; Dev->RxRing.Desc[DescIdx].Next = (UINT16) (DescIdx + 1); - RxPtr += Dev->RxRing.Desc[DescIdx++].Len; + RxBufDeviceAddress += Dev->RxRing.Desc[DescIdx++].Len; - Dev->RxRing.Desc[DescIdx].Addr = (UINTN) RxPtr; + Dev->RxRing.Desc[DescIdx].Addr = RxBufDeviceAddress; Dev->RxRing.Desc[DescIdx].Len = (UINT32) (RxBufSize - VirtioNetReqSize); Dev->RxRing.Desc[DescIdx].Flags = VRING_DESC_F_WRITE; - RxPtr += Dev->RxRing.Desc[DescIdx++].Len; + RxBufDeviceAddress += Dev->RxRing.Desc[DescIdx++].Len; } // @@ -351,10 +382,21 @@ VirtioNetInitRx ( Status = Dev->VirtIo->SetQueueNotify (Dev->VirtIo, VIRTIO_NET_Q_RX); if (EFI_ERROR (Status)) { Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); - FreePool (Dev->RxBuf); + goto UnmapSharedBuffer; } return Status; + +UnmapSharedBuffer: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap); + +FreeSharedBuffer: + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + Dev->RxBufNrPages, + RxBuffer + ); + return Status; } diff --git a/OvmfPkg/VirtioNetDxe/SnpReceive.c b/OvmfPkg/VirtioNetDxe/SnpReceive.c index 99abd7ebe454..c42489636ea0 100644 --- a/OvmfPkg/VirtioNetDxe/SnpReceive.c +++ b/OvmfPkg/VirtioNetDxe/SnpReceive.c @@ -82,6 +82,7 @@ VirtioNetReceive ( UINT8 *RxPtr; UINT16 AvailIdx; EFI_STATUS NotifyStatus; + UINTN RxBufOffset; if (This == NULL || BufferSize == NULL || Buffer == NULL) { return EFI_INVALID_PARAMETER; @@ -143,7 +144,9 @@ VirtioNetReceive ( *HeaderSize = Dev->Snm.MediaHeaderSize; } - RxPtr = (UINT8 *)(UINTN) Dev->RxRing.Desc[DescIdx + 1].Addr; + RxBufOffset = (UINTN)(Dev->RxRing.Desc[DescIdx + 1].Addr - + Dev->RxBufDeviceBase); + RxPtr = Dev->RxBuf + RxBufOffset; CopyMem (Buffer, RxPtr, RxLen); if (DestAddr != NULL) { diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c index 57c7395848bd..ee4f9ed36ecd 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -39,7 +39,12 @@ VirtioNetShutdownRx ( IN OUT VNET_DEV *Dev ) { - FreePool (Dev->RxBuf); + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap); + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + Dev->RxBufNrPages, + Dev->RxBuf + ); } diff --git a/OvmfPkg/VirtioNetDxe/TechNotes.txt b/OvmfPkg/VirtioNetDxe/TechNotes.txt index 37250b14a98c..fedbaee07ec7 100644 --- a/OvmfPkg/VirtioNetDxe/TechNotes.txt +++ b/OvmfPkg/VirtioNetDxe/TechNotes.txt @@ -247,7 +247,7 @@ In VirtioNetInitRx, the guest allocates the fixed size Receive Destination Area, which accommodates all packets delivered asynchronously by the host. To each packet, a slice of this area is dedicated; each slice is further subdivided into virtio-net request header and network packet data. The -(guest-physical) addresses of these sub-slices are denoted with A2, A3, A4 and +(device-physical) addresses of these sub-slices are denoted with A2, A3, A4 and so on. Importantly, an even-subscript "A" always belongs to a virtio-net request header, while an odd-subscript "A" always belongs to a packet sub-slice. -- 2.9.5