From nobody Thu Dec 26 13:24:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1505132240684186.37636753412585; Mon, 11 Sep 2017 05:17:20 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4038F21CEB0FC; Mon, 11 Sep 2017 05:14:20 -0700 (PDT) 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 311332095BB98 for ; Mon, 11 Sep 2017 05:14:16 -0700 (PDT) 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:09 +0000 X-Original-To: edk2-devel@lists.01.org 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=aFChEmc/BCfH4CvuPDeguLbTIvCkfeymCbNPSM7woII=; b=2YGW3HlSeDKxJ1FmqIdghPCTtJEdym9ZVZZqSixB3e2MjVDB6NuvZ+xO1VHJcfWyKuF2bZKxqJ06J7wNHo1KMqAga1DuK+0738cf1QzuSrUsShjfIutl3NNJk0ToaiBuv1jSzZiSY8bg70h4xblkhihdbeVScVZM7GiIenk9tDY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Mon, 11 Sep 2017 07:16:52 -0500 Message-Id: <20170911121657.34992-4-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: c22ade39-8ccb-4ec3-b675-08d4f90f06f4 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:DNpKp99kMnhD0PORWGezHlZnqPWqgjZASYoPskewEcONEibvBxUw4C4EIbuwQzGwtrBakvJ3fcZNioVTzJsKRrQjRgeNwMiPoNYZz+j6DFeftskKyVSKOFWJNO8JLY96sExuPwBJwXjGsWIjtRanGmqH+zX9uZ6fodqlWLD5noW0tMDcp8ERjtYID+d+q1pZmovfLb8ADxodCU3TfusYUwdrDUSb2k0xNYxTYMMlE6sn+4QMofZfjoPvL7wuj7NY; 25:GnEwQkK1QZNNUJKH8GYEMk0qHOvyZiRAiUIbhXjVYF34uhyIR1SuKinomfVblUA324aY2D5fmazfLXhPxJ8CD3XUhDRj/iOnMjDh9+/DZhXfbi6JPqlk6h29SZHUYzKn6MMRv1ximGxo/MKkClsFl/F1ZFQKCLYe+CPdNuAoBpidkzyvwADJiRbsw88z+llHq6sxQsS8PitQjT6D8PIN6nTHZ96YEHLwj7gu2Td4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309TF9ti8noABhoqGDqpkWXQsdIc2m9BUH+kL30VcAPVI9V4tn5KvNYsWJnUHX7MHAI2dBfz/kBA6i1FpodW9N4rQOV+giajHcQ5GO16yUouLePe0hMY9vXYsc/83w2bvP+vmYCyDVAqBv1OvvyBVlRv/5f7R/WX/ZncGy1HtxbDvJy2NM7Do440/R8rxzm6d0OaS4w== 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)(6029001)(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 (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0158; 23:AqsjEQhg5puoaJtatTWWUnTPWKf0qMJKtQhFyckxO?= =?us-ascii?Q?HspalbEzTjE3GFt2aYAEGrrDEp9rMGqm3vk0KD+rYPFAlw8qsQukvba+yylm?= =?us-ascii?Q?9WTrNA4x/gsnbU33R0YKYxj7nlZEAdULQLZz8jVAHlAqNOsvxIg677eaQApb?= =?us-ascii?Q?MgG7jsXTfu+D0hMbgSjGwwnI+MF4DM2GVnXvfLXGrYDZZxggWwrJx/9xsZBc?= =?us-ascii?Q?9IT0/7SCiLGOBI32tSKUJIt8VN/w+V0gbPWr4IUiNfmhyu3SVbg6pAFjphEc?= =?us-ascii?Q?l81pIagOWY7oQcBb9EEdOzcsF6iHijRI9q7k1M+FO3ljMqT1W1byeia1WF6G?= =?us-ascii?Q?dBc9HFOkD6fFJRYMBgKhcr8W8fksE2jKMCKTbyx5H6cInQXHrNxMeJz/WjDi?= =?us-ascii?Q?UGhBUrt8CXSBFZ7jlEPDX9keAfG/Tk/OaeRHDyNgb3pNyU88rEQ1N3nZoO+Y?= =?us-ascii?Q?ji6uZiOMtCxFNAhX+uFycZpb5LlegIxl0RUPG2M1Dba0btiSomCv21yRJa8U?= =?us-ascii?Q?Ms9aCtGp+Pmyy180X5RL4YOeM+kK2a3IYH9ms+BvUsxGOt6Cjd/uZSalrHzM?= =?us-ascii?Q?FKUYjT4DOYfezI1LP985UkUWWcGb8YnBt3D2L6TjyUFgxpCgycVpdAzkY17L?= =?us-ascii?Q?pU2GX4StjKJlZ8qcyeAN0eFIl+6OxgwbA7ZDmImUl9crn7xHCa+u6rNT5njx?= =?us-ascii?Q?EFgbdxqKb9Thlhm4+fOfwt6LbevXzucWkGfEBAmrn1i8tJKw7Nf175fwT/c9?= =?us-ascii?Q?8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Rw1OT+5pYxZF+HvP5/z5HDuEgkcu3ECtJEU4M1Ltwl5yTZjYJWztqfAT/86aJDoBmWngnSX4Tz/ErJh/1iOcKLdLfC6Dy6AWbN2Z9nDtGyGO4GFBi10nB+9RpWRdnmBmNoSTCi43ys6mcZPTEA+5CkYL/94i8OTPiPbcGSTcmLaOlEwP0xFINNBQKwbX9Ixs62rvGyDK0/nI6u7at4N5aX6//5899mvY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:NRgMJbEXr12HVrmzkUc9TXAx6UgWKe0lHnR0A5uZGBS/eQVUfCGBUePDOlxp5Tubjkbbe635hetgmG749KCLyJ0mWl5Pe1PCaPLQZkf4e0uTcNtLNMHsVyBTSomxs4saPdQgeOtaKDZKoF3uP6VOOxBzVyrsrnFc1u5fY23NRFIU/su7iLBqKuPdcIOq8gJjOA4VtOKcSyc91t00+Ekd6t3I/8+/0FFEbrCiHSpxVfxQYXR6/Jfm53RJkTPu2Mq4 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2017 12:17:09.8859 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [edk2] [PATCH v2 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: , Cc: Jordan Justen , Tom Lendacky , Brijesh Singh , Laszlo Ersek , Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 | 77 +++++++++++++++----- OvmfPkg/VirtioNetDxe/SnpReceive.c | 5 +- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 7 +- OvmfPkg/VirtioNetDxe/TechNotes.txt | 2 +- 5 files changed, 74 insertions(+), 21 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index 6762fc9d1d6e..7d5f33b01dc8 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -4,6 +4,7 @@ Protocol instances for virtio-net devices. =20 Copyright (C) 2013, Red Hat, Inc. + Copyright (c) 2017, AMD Inc, All rights reserved.
=20 This program and the accompanying materials are licensed and made availa= ble under the terms and conditions of the BSD License which accompanies this @@ -86,6 +87,8 @@ typedef struct { // VirtioNetInitRing UINT8 *RxBuf; // VirtioNetInitRx UINT16 RxLastUsed; // VirtioNetInitRx + UINTN RxBufNrPages; // VirtioNetInitRx + VOID *RxBufMap; // VirtioNetInitRx =20 VRING TxRing; // VirtioNetInitRing VOID *TxRingMap; // VirtioRingMap and @@ -95,6 +98,7 @@ typedef struct { UINT16 *TxFreeStack; // VirtioNetInitTx VIRTIO_1_0_NET_REQ TxSharedReq; // VirtioNetInitTx UINT16 TxLastUsed; // VirtioNetInitTx + EFI_PHYSICAL_ADDRESS RxBufDeviceBase; // VirtioNetInitRx } VNET_DEV; =20 =20 diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.c index 8eabdbff6f5e..54c808c501bf 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -242,8 +242,10 @@ VirtioNetInitTx ( @param[in,out] Dev The VNET_DEV driver instance about to enter the EfiSimpleNetworkInitialized state. =20 - @retval EFI_OUT_OF_RESOURCES Failed to allocate RX destination area. - @return Status codes from VIRTIO_CFG_WRITE(). + @retval EFI_OUT_OF_RESOURCES Failed to allocate or map RX destination a= rea. + @return Status codes from VIRTIO_CFG_WRITE() or + VIRTIO_DEVICE_PROTOCOL.AllocateSharedPages= or + VirtioMapAllBytesInSharedBuffer(). @retval EFI_SUCCESS RX setup successful. The device is live an= d may already be writing to the receive area. */ @@ -255,13 +257,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; =20 // // In VirtIo 1.0, the NumBuffers field is mandatory. In 0.9.5, it depend= s on @@ -286,11 +290,37 @@ VirtioNetInitRx ( // RxAlwaysPending =3D (UINT16) MIN (Dev->RxRing.QueueSize / 2, VNET_MAX_PE= NDING); =20 - Dev->RxBuf =3D AllocatePool (RxAlwaysPending * RxBufSize); - if (Dev->RxBuf =3D=3D 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 =3D RxAlwaysPending * RxBufSize; + Dev->RxBufNrPages =3D EFI_SIZE_TO_PAGES (NumBytes); + Status =3D Dev->VirtIo->AllocateSharedPages ( + Dev->VirtIo, + Dev->RxBufNrPages, + &RxBuffer + ); + if (EFI_ERROR (Status)) { + return Status; } =20 + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterCommonBuffer, + RxBuffer, + NumBytes, + &Dev->RxBufDeviceBase, + &Dev->RxBufMap + ); + if (EFI_ERROR (Status)) { + goto FreeSharedBuffer; + } + + Dev->RxBuf =3D RxBuffer; + // // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device // @@ -310,7 +340,7 @@ VirtioNetInitRx ( // link each chain into (from) the available ring as well // DescIdx =3D 0; - RxPtr =3D Dev->RxBuf; + RxBufDeviceAddress =3D Dev->RxBufDeviceBase; for (PktIdx =3D 0; PktIdx < RxAlwaysPending; ++PktIdx) { // // virtio-0.9.5, 2.4.1.2 Updating the Available Ring @@ -321,16 +351,16 @@ VirtioNetInitRx ( // // virtio-0.9.5, 2.4.1.1 Placing Buffers into the Descriptor Table // - Dev->RxRing.Desc[DescIdx].Addr =3D (UINTN) RxPtr; + Dev->RxRing.Desc[DescIdx].Addr =3D RxBufDeviceAddress; Dev->RxRing.Desc[DescIdx].Len =3D (UINT32) VirtioNetReqSize; Dev->RxRing.Desc[DescIdx].Flags =3D VRING_DESC_F_WRITE | VRING_DESC_F_= NEXT; Dev->RxRing.Desc[DescIdx].Next =3D (UINT16) (DescIdx + 1); - RxPtr +=3D Dev->RxRing.Desc[DescIdx++].Len; + RxBufDeviceAddress +=3D Dev->RxRing.Desc[DescIdx++].Len; =20 - Dev->RxRing.Desc[DescIdx].Addr =3D (UINTN) RxPtr; + Dev->RxRing.Desc[DescIdx].Addr =3D RxBufDeviceAddress; Dev->RxRing.Desc[DescIdx].Len =3D (UINT32) (RxBufSize - VirtioNetReq= Size); Dev->RxRing.Desc[DescIdx].Flags =3D VRING_DESC_F_WRITE; - RxPtr +=3D Dev->RxRing.Desc[DescIdx++].Len; + RxBufDeviceAddress +=3D Dev->RxRing.Desc[DescIdx++].Len; } =20 // @@ -351,10 +381,21 @@ VirtioNetInitRx ( Status =3D Dev->VirtIo->SetQueueNotify (Dev->VirtIo, VIRTIO_NET_Q_RX); if (EFI_ERROR (Status)) { Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); - FreePool (Dev->RxBuf); + goto UnmapSharedBuffer; } =20 return Status; + +UnmapSharedBuffer: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap); + +FreeSharedBuffer: + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + Dev->RxBufNrPages, + RxBuffer + ); + return Status; } =20 =20 diff --git a/OvmfPkg/VirtioNetDxe/SnpReceive.c b/OvmfPkg/VirtioNetDxe/SnpRe= ceive.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; =20 if (This =3D=3D NULL || BufferSize =3D=3D NULL || Buffer =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -143,7 +144,9 @@ VirtioNetReceive ( *HeaderSize =3D Dev->Snm.MediaHeaderSize; } =20 - RxPtr =3D (UINT8 *)(UINTN) Dev->RxRing.Desc[DescIdx + 1].Addr; + RxBufOffset =3D (UINTN)(Dev->RxRing.Desc[DescIdx + 1].Addr - + Dev->RxBufDeviceBase); + RxPtr =3D Dev->RxBuf + RxBufOffset; CopyMem (Buffer, RxPtr, RxLen); =20 if (DestAddr !=3D 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 + ); } =20 =20 diff --git a/OvmfPkg/VirtioNetDxe/TechNotes.txt b/OvmfPkg/VirtioNetDxe/Tech= Notes.txt index 0891e8210489..f39426fb13e4 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, A= 4 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. --=20 2.9.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel