From nobody Fri Dec 27 18:21:58 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 1502107204452123.21641837956736; Mon, 7 Aug 2017 05:00:04 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DF14521DF969B; Mon, 7 Aug 2017 04:57:15 -0700 (PDT) Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0049.outbound.protection.outlook.com [104.47.33.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7BEED21DF37D1 for ; Mon, 7 Aug 2017 04:57:14 -0700 (PDT) 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 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=BC7x//gN5dw039pcx0lrefFsWkItYFUbUa0ZBS9zfeA=; b=aIY1P12JmeCrAQZOFnz/dwDe19P+vXqN8uIg+kVOJtRSJajBxo+uV7wLiXZtW5M7Rjst7iVfoxlmanSayEJQaJliipEL4INhEVsJzQJC9botDJZJ5dTyNh+zBJGc2gNJnqOgA/P6MXNn5w/aEjPyg8q01HT01kGbfxH0/QsTntE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Mon, 7 Aug 2017 07:58:56 -0400 Message-Id: <1502107139-412-12-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: 8df906e0-af13-4000-71de-08d4dd8bc234 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:Oqkb+E/k+SmLcjyVel0ab3v6H6JX4WBRNE612/Bn0wQsrjk5xL9iauTPSckCy6LRA3a9iwpMimie4ll8jpiDauff/ftB2VU59U3KkelJgFfieTptOF4BD1gy1wZjqqnmfA/fWJ+WT8rYGUogcNGd47X/uwLauck4rowYfZZXEhFg+AV3apXTn217O6wc8ylnQA62Xfwedm8iuABPC46I7jYaNvDqoesq3xzEvVBIPKBU+b6Y0qH6mBKrq0rfLp76; 25:Jdp2VfpMKYO207R7GJ7ya6qJM6ZYtPknlkqrr7muU/kM/N6veXpJ36A+AC2Oau4Wda8us9dN5xv4yivArNkV7CaK0Ue1HiZhPArpcx9I6NTG0QhnQLD0CHNe3xsKYdWAYLkMw1HpYOFsx4B6bUAtDY4Qt9d+cOU8lRSGBWyJEA1YJc64k+h4BvkeWEf9Ckao3t22CSDkz3iIYDIoJBHfGb1wuT8LZ1Y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0Uqe+4lawhxjpU+6estjOCMaS1VNAFJL8FAPsM/utnZ4i4jQbPv1173YnUhFoB4cd+Jx0tv9KEjJMfSetPst5RU/hC0aobwfS8z1Ee8AF4F/euniX/svDHkO5G34y7NUInqo/PZ50m1vkcSo/qi+BXKKKoKLJ5KpvFZqjF00VmC+IqhhEdKX5O6n38lKo9V8gLrhoRO39+M3A== 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)(6029001)(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 (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; SN1PR12MB0159; 23:NTSBD7GR54NfF02sSNqHV35P3wgSEnNSdrmr2VDJF?= =?us-ascii?Q?9M5z7FV7KDgG60i6CzPbhMqsDt5qqzyFIAMHhIU6e0PoSG1ftriyBXaNHz0e?= =?us-ascii?Q?qBzbLj196cE4sgtfv06GD93B8D98opm97bRbaFq5wNgr8XZDzWbqiJFU/vaq?= =?us-ascii?Q?e8/MPGNXNxD8XP2VzKvHg1CiJeiNSl2VzZBTXM+JYzosrVNEnltvAYJm3h64?= =?us-ascii?Q?TgBDEO336dvs7LNUkDoLM/2nZCe/zmBbaJFuBijYX0al86W0hDiL2OGdWjOF?= =?us-ascii?Q?l04+nNF+XFhGGJYv6TZY0nFa7+xQWp/rw8w3ZXxf1J3p85aDVsWupKCfWUTk?= =?us-ascii?Q?Ry7U/EdywFTjjJJ9G2L72zNhxm2SIccUdgXPbMCirJ8s8eNwFnLMiQIMULvM?= =?us-ascii?Q?cN+Nt3j0uy0uQ6x/it7k37DWoWuN6Q6vkCaZvIsEokXy4q0dr0ZVYsVP6L2l?= =?us-ascii?Q?dX9yjLm2he4lwm5jWmbY1qu4qbHdyGmrNAQjWaYw6UfLkHeY/0fCJncTcw40?= =?us-ascii?Q?K9onlkP55FkdW8amoB0xa23LUUqah2mOdBoxhutSRFxfSPJKwPeq+DaMSzN+?= =?us-ascii?Q?ZTXhhy0B/mHQ28vOph2xkgkOaCfMXoWkBJnUKfKWFHmCWgFueBFAZyFA59kE?= =?us-ascii?Q?A68atSyqEfFf055CAwwZnsSG+IZTLHLVvDH0Xoljb1QxR/WtxIO0neQ2ooVK?= =?us-ascii?Q?i8ehYcZ8Xpuv+Tp/8eI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+pZfDrT6SUUH7wLjWO9fN20Gvbt/wk3lY73keopnQhWKr0LmhamCfrbdn8+WVoYglaGPtQ==; 5:B+4OMl7O0+w9ld3VhMFf5J3iWBaHjZVxxMQkBiI5eS7uwDrD7eJbTatWDY1jhfp9Pj7jgS+/gGkb5E+YacA8GZ55KEK5Xfn+CjK4mERgE1/SrEYpBAyIUc56cRO4/z2FW0Pl6UtsQP9+qMcKw/ZP5Q==; 24:st8FJ4hLsuEu0Q0VtHMAFK0XoExRD0vcsdvIblGivEvw226+RvJYrxU9n+l1FiDO3QMwuXwnccUJFD/7Cpq6vF/65kZe3FHzJywVzafqnoM=; 7:QGZwGfMoNhRUzkzXnsQQpL7UmFuqQ/e4hcYrELboJbf80jSYgD2BudIik3YvxMKPVDToKKKCSDRJqhWQvtS2y0YmAszgPg7bItAz7byxPecoWf+sEcfVEX/tk3XyH0foooLru1GG/Hx2ljCRlKdic4bpzUhnSsEaWx0+rDzxMdNCA3EaAKmTJ5VfkAf5RhtnEOCpr2YLVnLlbAcf0oxAgeft1oGK3EJMsKkCTKZZ7i0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0159; 20:f3MmoO1s+5FqF2QGC5L/g0AVoCOAU0ROpMZtwX1MLY3xvhs4Ies2rkhoE6Gm4jqekuoQOUHq+9amVZrTMsBCLikdrs+b8/fx2DrQnbbSXpTSyKPBqt7uTdfGXn2lUzdxQK5Gwgm3RGoMVHHKzLiD8ZGuDjZ9vaOpUApHhtj3EY6tosTO6Gz2WrfmD34a5eMVD72NpIz4J3Fl4XLvIT2PcrutbMHyGE3ICQvSp2HeAVNdfMlNem8vP1mH0U1G0f4V X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2017 11:59:29.0275 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0159 Subject: [edk2] [PATCH v1 11/14] OvmfPkg/VirtioNetDxe: Allocate 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 , 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" RxBuf is shared between guest and hypervisor, use AllocateSharedPages() to allocate this memory region and Map() it with BusMasterCommonBuffer operation so that it can be accessed by guest and hypervisor. 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 | 33 +++++++++++++++++--- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 10 +++++- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index 2964c946e26e..a4661bd5d2fe 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 @@ -85,6 +86,8 @@ typedef struct { VOID *RxRingMap; // VirtioNetInitRing UINT8 *RxBuf; // VirtioNetInitRx UINT16 RxLastUsed; // VirtioNetInitRx + UINTN RxBufNoPages; // VirtioNetInitRx + VOID *RxBufMap; // VirtioNetInitRx =20 VRING TxRing; // VirtioNetInitRing VOID *TxRingMap; // VirtioNetInitRing diff --git a/OvmfPkg/VirtioNetDxe/Events.c b/OvmfPkg/VirtioNetDxe/Events.c index 9eb129ca2006..171b144518a9 100644 --- a/OvmfPkg/VirtioNetDxe/Events.c +++ b/OvmfPkg/VirtioNetDxe/Events.c @@ -102,4 +102,9 @@ VirtioNetExitBoot ( VirtioRingUnmap (Dev->VirtIo, &Dev->RxRing, Dev->RxRingMap); Dev->RxRingMap =3D NULL; } + + if (Dev->RxBufMap !=3D NULL) { + VirtioUnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap); + Dev->RxBufMap =3D NULL; + } } diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.c index cbc9c51cb643..59c9f1ed3516 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -244,6 +244,7 @@ VirtioNetInitRx ( UINTN PktIdx; UINT16 DescIdx; UINT8 *RxPtr; + UINTN NumBytes; =20 // // In VirtIo 1.0, the NumBuffers field is mandatory. In 0.9.5, it depend= s on @@ -268,9 +269,24 @@ 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 SharedPages() to + // allocate this memory region and Map() it using BusMasterCommonBuffer + // operation so that it can be accessed equally by both guest and + // hypervisor. + // + NumBytes =3D RxAlwaysPending * RxBufSize; + Dev->RxBufNoPages =3D EFI_SIZE_TO_PAGES (NumBytes); + Status =3D VirtioAllocateSharedPages (Dev->VirtIo, Dev->RxBufNoPages, + (VOID *) &Dev->RxBuf); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D VirtioMapSharedBufferCommon (Dev->VirtIo, Dev->RxBuf, NumByte= s, + &Dev->RxBufMap); + if (EFI_ERROR (Status)) { + goto Failed; } =20 // @@ -333,10 +349,19 @@ 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 Failed; } =20 return Status; + +Failed: + if (Dev->RxBufMap !=3D NULL) { + VirtioUnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap); + Dev->RxBufMap =3D NULL; + } + + VirtioFreeSharedPages (Dev->VirtIo, Dev->RxBufNoPages, (VOID *) Dev->RxB= uf); + return Status; } =20 =20 diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe= /SnpSharedHelpers.c index 9fedb72fdbd4..48cd4900911c 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -39,7 +39,15 @@ VirtioNetShutdownRx ( IN OUT VNET_DEV *Dev ) { - FreePool (Dev->RxBuf); + // + // If RxBuf mapping exist then unmap it. + // + if (Dev->RxBufMap !=3D NULL) { + VirtioUnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap); + Dev->RxBufMap =3D NULL; + } + + VirtioFreeSharedPages (Dev->VirtIo, Dev->RxBufNoPages, (VOID *) Dev->RxB= uf); } =20 =20 --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel