From nobody Thu Dec 26 14:14:56 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 1505424190581537.6127001779164; Thu, 14 Sep 2017 14:23:10 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AC22221E977FF; Thu, 14 Sep 2017 14:20:04 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0054.outbound.protection.outlook.com [104.47.38.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CB74D21E3EA81 for ; Thu, 14 Sep 2017 14:20:00 -0700 (PDT) Received: from ubuntu-010236106000.amd.com (165.204.78.1) by DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) 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 21:22:57 +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=lhb8u4CKWsv1Sv0UutfwsAwROsLCFYd5/jN/iwyUghs=; b=b/Izd81Y9GIDjfYToSwZY6B1vWaiv/RIL/yzD+1m8Yw9MTF0p+7P+szFBkIeZB7WOzM9YBlOdkv3T76g2mDnaBRxLEyKi2mVfFzJpPN0PFG4E2aY14YZyerpNjkHfXB3oOUBoe6JCywzHsVsANC44ay6Z+902jgixXtUVej+4HU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Thu, 14 Sep 2017 16:22:42 -0500 Message-Id: <20170914212247.124937-4-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20170914212247.124937-1-brijesh.singh@amd.com> References: <20170914212247.124937-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM5PR20CA0014.namprd20.prod.outlook.com (2603:10b6:3:93::24) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4c20aeaf-308f-4ef5-7cc7-08d4fbb6c51a 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:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 3:DVDbqIsgBOS1jVAXRj3rJHIfY6yoHttio96FvH7InY679LuzP2iHRFJ8pU/owtROGSlFq6zCpS/LGlOJwksMIrJqCJQ4OnbDa+H0CNA7X0CYLleazdCpAS/VBBNJH8njzMmIM+bvoBhPO6PqpqmfU7gpi9PxNg+VNb/XlBgHHvT/bRZyUs5jx1MUvhbyYNr7jEVDYOQJ+y87pPOiny9i3ueE9ecg6gTMF0I1i19VMqrEN6cz91WAKtvpb1WRS9Tv; 25:bRtGhcitjjmQyczsjciAj/6IeKMsnRvPg24B5b709wveygwvdU5ypFY3AIP3g1gKdU18FUpAKe8XZiQ8WBsKnjMn0pdBNC1IHeMqSx1btb0Co70azSjyv3b8C/fb0k5e50yJdu875lgiCw1+AIFhOiQBNgSgd0fmck4yVt9x/umWdNKeMT7hkCBCVLBOS1gZFqSos8IwcgR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bCmXcYFPQddWOejEnu9y682xD4R4Of7XxMX0BjVCfA13CHLvslLwixgRzbPumOMdu7a1kCBj1RY1JNcvQkxwsFjj/GHhR81c+kyaTAJdkJbGpnqf20aMfDdmraYfJs3lqzngiDHB+MDxYLipg1It37ZEPhT4dBWjtTsew6ZjAyyRHhSFa4WAjJVH8p8Zqf61xbGptfRofbD9JH5lHD0abnYDgbGCV4h7Z0g== 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)(3002001)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(6055026)(6041248)(20161123555025)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM2PR12MB0155; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM2PR12MB0155; X-Forefront-PRVS: 0430FA5CB7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6029001)(6009001)(39860400002)(346002)(376002)(199003)(189002)(53936002)(4326008)(110136004)(50466002)(47776003)(50226002)(81156014)(81166006)(68736007)(54906002)(8676002)(2361001)(66066001)(2950100002)(6916009)(33646002)(2351001)(36756003)(106356001)(105586002)(53416004)(101416001)(48376002)(8936002)(25786009)(6486002)(97736004)(305945005)(7736002)(5660300001)(16526017)(16586007)(2906002)(5003940100001)(1076002)(6116002)(3846002)(316002)(50986999)(6666003)(76176999)(86362001)(478600001)(189998001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; H:ubuntu-010236106000.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; DM2PR12MB0155; 23:Ox3jJlHI/5Qr47NpQ+Dr1y5tazfUTFz/TShD+8uUv?= =?us-ascii?Q?g5nfUx+7Bx9mkpJnlzK75Gu65fpY94WEWSeqeZcHKHftX2cfEFNtdx4ya7xB?= =?us-ascii?Q?a1B/+iSl6rzXTm1pe98v0/VztXWsyHBLEwyPexazjyEQPeMAYBm24ALE1Bh6?= =?us-ascii?Q?dCH4Tws3gk/1YC15RRErUkt8ql+lCKdM4IaolZGaGekMYDInzeQCacP9XYJ0?= =?us-ascii?Q?fDzro1FF1MstmQyjWWrntk4ai/jJP4XLzHe0JAEWge5qTRzTID50gWur9ox+?= =?us-ascii?Q?DjzCIorHr8iAwNviyVOagNJXgf29kyb85RkmK2155VCi8gxxxorefcEtPACu?= =?us-ascii?Q?o+RuTAYYImGRxSigmjPwPE3l9KRem228Rim/qVmWYC0zl8A7+xzHRIIt22kN?= =?us-ascii?Q?E+nh2BF43p07cvLG1Rd/SDA87asbyQWpN3EZZ86+tpKYvk55mMoyHDHFIGE7?= =?us-ascii?Q?T0/qGFn/5SFo5r2EaKUIhyUBwRTCIiqTmE91BR259xL8W2TM/mOwPVnu8ebN?= =?us-ascii?Q?/1hPis0PgLRxYtVtvf8kPNOUyfYz9UiT9Ew5T9eYnCC+3+ZB0zeflpFPGahH?= =?us-ascii?Q?pAhNNruaQQHoz5JqQM6CdHFnZzsWHqwcscICiz2eWWx3UO9/DtSXxDrlT++G?= =?us-ascii?Q?UrsOXXhmJPoESbZBWCKKYZbA26od1C/2exwudobIm+4h4mOuahRwTVY/1kur?= =?us-ascii?Q?jNvPUZtXQ/+LepvfVxnOJTwGblKSmX3ZaFBPevZ5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vj+98O9HsaSD26KObWvuppcZ52RB+qxmuuWzHVixzwV2hbzme6PSXOAz7fo=; 24:K3OOPJz3CMfSszv7Es74iirkiQJg3+V2gMhlx2U7ZlT/84yFFY+hwFajbCRgwBvMPkg1O1o9XHpwvsVOMVBrxtd+58pIgQuwQsw+JivCMvw=; 7:PKP9J7I37ksI80I4gKVIlXUEFuESWeTy4xRATfewEWb8ZdTgvaBY2HPhF45znEsW6qsNNdmzSY++9+qqfSacIKJm71sTw6yma97v3lEG0wydgsfPIV08n8s0wsILpkJERsMRc3DsU9NO8r8UYmA0EdR9aAkDD9pMKlL7r6q25JPPcvAABvaNFSeTUQM+wljbyT0eRi1B/j82Avc2+NFQ4/j0SHOLb1gH5ztdjsGqiFw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:vutrkO/hB9doXCNVFHENOGOsnGVWUFTQogsTNNqyKci+steXwe6rlcvtf6O2Ch1rqujkm3ZYdOIRGNLo/KSBTXPtgRUcB5itqVjFo1rJTLgJAbOOpA6BAsjGzqbKg1bCXOeQbcJnoi7nWawvy0i9STg5unp6bd2pcmjcMPKn2AHA6Fi9otXE1RW4kBr8/akQosbsEG+4W7ZBnfT7fg71sopGTXoapd7b5DK6gVoX3TRsw4zzzGZ4BMSmtLNMqEZc X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2017 21:22:57.3674 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [edk2] [PATCH v4 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 Reviewed-by: Laszlo Ersek --- 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/Virtio= Net.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. =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,9 @@ typedef struct { // VirtioNetInitRing UINT8 *RxBuf; // VirtioNetInitRx UINT16 RxLastUsed; // VirtioNetInitRx + UINTN RxBufNrPages; // VirtioNetInitRx + EFI_PHYSICAL_ADDRESS RxBufDeviceBase; // VirtioNetInitRx + VOID *RxBufMap; // VirtioNetInitRx =20 VRING TxRing; // VirtioNetInitRing VOID *TxRingMap; // VirtioRingMap and diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.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. =20 - @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 an= d 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; =20 // // In VirtIo 1.0, the NumBuffers field is mandatory. In 0.9.5, it depend= s on @@ -286,11 +289,39 @@ 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 + ZeroMem (RxBuffer, NumBytes); + + 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 +341,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 +352,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 +382,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 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, 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.5 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel