From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0052.outbound.protection.outlook.com [104.47.40.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6CCD721D0A277 for ; Mon, 14 Aug 2017 04:35:02 -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=jBfgK1GkNHw1yM0dwjEJX1T/P7DaaaVQzyvFOrFvRds=; b=sTqKwJLSKv9tXxW2UAT0HQohFbhgUU8b65LxGpWmnoX8KCyAwSYFrFLaBY2TJNoVLR0/ky9pELSZo6xS2WKGpHbuS3nhbCXqCi8e+Dq8TRr4Gpwh7xH5CPNvD7sg4xWruA277pJSEBvP8lzQUaBd16xt3ez15wgWSJ3QQFbBqqQ= 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:24 +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:41 -0400 Message-Id: <1502710605-8058-20-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: 383a7a89-6cb2-45f0-64ea-08d4e308d586 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:aGw4tmdf3bj6VUYZAN8xktwaH8oGzznOE+WbxXUYQE8GrV1OIhw6JJtez6xJWKZW08hF5R2Rh0RsaREhWtYKM0Jaz+lmRkT7iAm9AKMKqAtTemGhRzNrJSHGoTYlwa9apPx2kAq7P0I2cYc8W9EvNVJ5nXWUUgxK3Lor8iYBZmVQNSc/Pb0jnSxZZXV9QqeyzToUOyI3SKOofr0x/ASW0NjCq1ZbClvGwR46wshUeyL10y/WD9ExKIN/IrFYJZrP; 25:tTJC3vwTZwECFgG/4PJzMHxH+avMTsgLCZ4/K0TPHm79676b/pnM7ol4mLUo1UxYlxILOF7mZDB85fw4oBPrnA8/W56As0PmcEmebP7Fc64V1T9Tfjs3Cd2gGHI4U1sMSs4gUjYDaIbJ3w7Y9tFCiLUmzJKpCWqlp0k8I2Av54nX8xf8pTI1gbQtsAaK9DsgO6biQhdfv4Cy0q5nWfcYOe8ZiZ3S7xEM1Wmcx2i9KL+XFAi73gDPwnbYyAmJthwEq32xsrrfSare3BTDHM8/k9dopNc9djod5SWIlDTsrOEQp7iPosQgNvQHV9j88TjSY2VXax9D7YbZ8B7LOXsWTQ==; 31:+squoLxYMeFkuNQlhPix6pDE0VcNMjPICMJwkw8tiFpNelcRQXzBUKCutNywlgWAB+m7x0jHv4SwHhdQsnKHY1bqO7oaKlriUSdlGARr/q3X1pPmtQAXIPzZleXV03kEeu1anJPCE5pwP3sVrOCEh2FanNtmYPP6w0nYID89IikgICDns3FaRbYIBsLom+kU6InqbQSsNpuyjCYJXxH/VZldwvCzGBWd0OvwmT+k8Xk= X-MS-TrafficTypeDiagnostic: BY2PR12MB0145: X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 20:OlbucGhrXrWiX44s3aI6aDP/5vSJChM8HDNDzcXuC5jk+fwZhraVwpSqnbtdwoTAw3eZy0X+UCX1e/vdOooZ2t4hEfnFqTmr6Of1QwgTZ0LUxqv/yikPwRdytAB4Hp6oPl1YLXF90E0eYC35GYX24dqAUuf/znLe3V+1inWcGdc3VpMx9UXuNygvlHCznkvw3r3DQu4OzF3OM5aakKZ6U0XuN7f41Qtuazwpy4arj453RMjYKxc92mGjs1ZFy1EghrNc9ODhKJQ7iGQLskgTsS9ndA7saayUc7NpkJWhBZ4SXXF1BVPGIqDwzos256sxm/qGm7CyR58SYqmUKSg2w+wOv0vBM2Z7fdTaRtL+oMWcHdcTGCARbHX1qxrbsvXElhrMB+SC3AMXyxevmsjhh3OJJ+2OHjDbt4IVDphPMtI1qcTZMpbNMlftP5c10g9OTSqmgonGms5Mk1TLBFpFUe9xgMx340H0wk99JZZU5IiBvPbKW8w7AyfFFLGNoYY9; 4:kArnQpWuSu3Niy2nLJLhkjce/Hou1DE34+t7ZavoQ79RFEOubbQRvRHycVwkdMmIAVF1HVPEPdhiwJbkynDHEfYX+GrJcTqNx/3az8GaHmn0953gaqIxnD4TfXYxJLiholeysgVt746U61Zo31GbnZILx6WmVu6Xg1b1cpZ4rgyu86xgQ9F5frGmNgh3OnxVn4ge3fjtBQ/5kAMxlZiqXMI1chFLcapI0Li9aTW0ohCDtbYDMzeomUpveYxd+FgMYdynhu30y7eq6iuKe7+opKTbWriXDC7+Sa8VWyNpxetO1wV/CaarpDtV8/yzd7vk11mdZ04EVDFJ1NcxJgJV0Z0p3UsPYgH/ngmFKHO1aTs= X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699)(17755550239193); 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)(51234002)(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:FNPa9V3BmZtOVzwFcbkUUn7C6xL9k/kUtyoVs0Kuc?= =?us-ascii?Q?wKMpMUy8osY3GqdP+RybGVbxcjvss9kHyIWJk4b6EnJHTqH9XU6C+uion9+i?= =?us-ascii?Q?4yCVmFOAMFmGJMNgsS0evrmC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hrRaww7QZZFQ4aEqVUt+3YeFiGjwviTpH3Yd0FcV4cZqGQnzTZd6hk3ui1GNebo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 20:cv7a5YTX2/hjpqdEnlWMwq9yU3gV3XgL991Wtlh/HvA8/pAsoMWXwGXXyU7zVdoQWM+ERXg45GJaI3CZgZX0Prb02B6ltvh2Co5IgZLZtWQP3lhvAD330ofM3sclhWtrABVMRyAbHBSE0NCPRz1PYTwcOFfKahMv4RlO2vkk+pvWiWX6tD3utDDXjNxQp5YrvjkNMpocCnR9u3ltmuxz9hzbRsKy+W3xhH4DHWvMG8vrFvEZXj6CmsKBleC8TRfb X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2017 11:37:24.1586 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0145 Subject: [PATCH v2 19/23] OvmfPkg/VirtioNetDxe: alloc Tx and Rx rings using AllocateSharedPage() 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:02 -0000 Content-Type: text/plain The Tx and Rx rings are accessed by both guest and hypervisor, allocate the rings using newly added VirtIo->AllocateSharedPages() and map it with BusMasterCommonBuffer so that it can be accessed by both 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 | 2 ++ OvmfPkg/VirtioNetDxe/Events.c | 7 +++++ OvmfPkg/VirtioNetDxe/SnpInitialize.c | 28 +++++++++++++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/VirtioNet.h index 710859bc6115..2964c946e26e 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -82,10 +82,12 @@ typedef struct { EFI_HANDLE MacHandle; // VirtioNetDriverBindingStart VRING RxRing; // VirtioNetInitRing + VOID *RxRingMap; // VirtioNetInitRing UINT8 *RxBuf; // VirtioNetInitRx UINT16 RxLastUsed; // VirtioNetInitRx VRING TxRing; // VirtioNetInitRing + VOID *TxRingMap; // VirtioNetInitRing UINT16 TxMaxPending; // VirtioNetInitTx UINT16 TxCurPending; // VirtioNetInitTx UINT16 *TxFreeStack; // VirtioNetInitTx diff --git a/OvmfPkg/VirtioNetDxe/Events.c b/OvmfPkg/VirtioNetDxe/Events.c index 5be1af6ffbee..e832d40f7be4 100644 --- a/OvmfPkg/VirtioNetDxe/Events.c +++ b/OvmfPkg/VirtioNetDxe/Events.c @@ -88,4 +88,11 @@ VirtioNetExitBoot ( if (Dev->Snm.State == EfiSimpleNetworkInitialized) { Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); } + + // + // Unmap Tx and Rx rings so that hypervisor can not get readable data + // after device is reset. + // + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxRingMap); + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxRingMap); } diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c index 0ecfe044a977..be2761d3d068 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -35,6 +35,7 @@ the network device. @param[out] Ring The virtio-ring inside the VNET_DEV structure, corresponding to Selector. + @param[out] Mapping A token return from the Map. @retval EFI_UNSUPPORTED The queue size reported by the virtio-net device is too small. @@ -49,11 +50,13 @@ EFIAPI VirtioNetInitRing ( IN OUT VNET_DEV *Dev, IN UINT16 Selector, - OUT VRING *Ring + OUT VRING *Ring, + OUT VOID **Mapping ) { EFI_STATUS Status; UINT16 QueueSize; + UINT64 RingBaseShift; // // step 4b -- allocate selected queue @@ -79,30 +82,37 @@ VirtioNetInitRing ( return Status; } + Status = VirtioRingMap (Dev->VirtIo, Ring, &RingBaseShift, Mapping); + if (EFI_ERROR (Status)) { + goto ReleaseQueue; + } + // // Additional steps for MMIO: align the queue appropriately, and set the // size. If anything fails from here on, we must release the ring resources. // Status = Dev->VirtIo->SetQueueNum (Dev->VirtIo, QueueSize); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } Status = Dev->VirtIo->SetQueueAlign (Dev->VirtIo, EFI_PAGE_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } // // step 4c -- report GPFN (guest-physical frame number) of queue // - Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, Ring, 0); + Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, Ring, RingBaseShift); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } return EFI_SUCCESS; +UnmapQueue: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Mapping); ReleaseQueue: VirtioRingUninit (Dev->VirtIo, Ring); @@ -456,12 +466,14 @@ VirtioNetInitialize ( // // step 4b, 4c -- allocate and report virtqueues // - Status = VirtioNetInitRing (Dev, VIRTIO_NET_Q_RX, &Dev->RxRing); + Status = VirtioNetInitRing (Dev, VIRTIO_NET_Q_RX, &Dev->RxRing, + &Dev->RxRingMap); if (EFI_ERROR (Status)) { goto DeviceFailed; } - Status = VirtioNetInitRing (Dev, VIRTIO_NET_Q_TX, &Dev->TxRing); + Status = VirtioNetInitRing (Dev, VIRTIO_NET_Q_TX, &Dev->TxRing, + &Dev->TxRingMap); if (EFI_ERROR (Status)) { goto ReleaseRxRing; } @@ -510,9 +522,11 @@ AbortDevice: Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); ReleaseTxRing: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxRingMap); VirtioRingUninit (Dev->VirtIo, &Dev->TxRing); ReleaseRxRing: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxRingMap); VirtioRingUninit (Dev->VirtIo, &Dev->RxRing); DeviceFailed: -- 2.7.4