From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0040.outbound.protection.outlook.com [104.47.40.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C40C921D2E634 for ; Wed, 23 Aug 2017 05:20:35 -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=d2rbhAAgtrh//FRREhTr2WBIabjSragiyVuBHqAul4g=; b=oC98K7B7zxs8k1WP+xLc8bHasHp8s4EsPsggl8KAAb1jiVG+KXPXkv5yESFD0dUnmjhvCkzSLuX/RlxU2CEFgds64MgdXhpozWM3OWeG/5E6/la8HyhL/VgXnhVp13mWn4Q3P6sOl0y3CjPDi9jGfKFJJhCUjD4dQCJ1nAvZsno= 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 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.1.1362.18; Wed, 23 Aug 2017 12:23:04 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Wed, 23 Aug 2017 08:22:39 -0400 Message-Id: <1503490967-5559-16-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503490967-5559-1-git-send-email-brijesh.singh@amd.com> References: <1503490967-5559-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR12CA0069.namprd12.prod.outlook.com (2603:10b6:3:103::31) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 844ec527-f019-46b9-418a-08d4ea21b487 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:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 3:lVd3s2uCO+/jCi7VR1eyX99SK3IdH6DMv6WrfTRaSJxCJxdjTMqFMJ+wUtAgAnRxWNSzG3LsuTp0gT3EbKAqoKTgNjCXjl80blYJRjJsQEOMcPC5H7Mieq+aVEsMA07exLaSzU32p/AV9rGXIWYHFykx+Llf6+KOpTcmzyB2FWpCYrB2dWWKviwiJgLOnZDNsbcZflfCl6AK965P/fFFbuMkMuYyBe4h7sYCW2qB6FHFqgRBSleSGeJARvJ5N7LH; 25:0r25IBpT3dUvuOvdKyZ/Mu6s4LCZrf4j+fLoXhbZiNICJD62XILGCTn7s+kKSg614s3cpgdaeeCFL5N3hvPgB9XmJriWIZ66XnW2R/q+P84R0ZOc7J4HUTEMcUdqJB2TkdZRlidz25lwFscqyEpjglKmKMICs2vf8kkL5U/T5CvQ85RPkqfHNO58Iod+PCnGU6uHd9l7XyW8AQ8bPhz3ElcLbwm8XZw1x9UIGvLMs6XlTBAeBAhjmGD5RBTxoj94JGSc29dKD6f7BkmJmi+m0Kgdl3jOE9bYsHmRjI/dI4Lc3maaY/RKseZrhc939n5tVb8PLl9xX//mJh0r1BUqFQ==; 31:A/2TDBJzPSVAoBiOPlxvfEHYK+uPVxi9BYOWUbZEEn8FBEWitiyNrYt4u2Fx8vFI2Xl4N6gbIOksWTglWVO+KsXKfSrCynLtJWDAMmJUEgZ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oJ2c= 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)(5005006)(8121501046)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(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: 040866B734 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(39860400002)(189002)(199003)(51234002)(305945005)(47776003)(97736004)(101416001)(110136004)(6666003)(189998001)(478600001)(7736002)(3846002)(66066001)(5003940100001)(6116002)(6486002)(48376002)(86362001)(105586002)(2950100002)(4326008)(106356001)(36756003)(6916009)(50466002)(2906002)(50226002)(42186005)(2351001)(33646002)(53416004)(25786009)(7350300001)(81156014)(76176999)(5660300001)(68736007)(54906002)(8676002)(53936002)(50986999)(81166006)(2361001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; H:brijesh-build-machine.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; DM2PR12MB0155; 23:6KSEwfqWdTSgP06PBG2A/FcsOGmDm6CHOjfbk+31U?= =?us-ascii?Q?7UBWSw6fQ3eq8wquSd3qPpJDT7EBqNc8976PJWdZxEMzsEbuDQI8N4pJx+fR?= =?us-ascii?Q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Aqs8bz49/VpOnILIqNyEWsx2rte7nrn1J0NEhVz0AXoQ2Uayf/fXG5/i2BCULxnOOLe9bwvr2RRguKAvUlP01P02xvB6ivDk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:dic6nCaJwwPCoJsNmjlAleSML01XhG1xJYvyFHBJApESqCw2Nc9gy4+kNpKIhAbOkzgzna2xMEsyDXs8VBU0A/8zOb2RE1Pv3ksy2HBwzNFYci5tpibKmh1hH9xKyiA+q2OvPRe81fa+e83CmPlQp0xac/gZLtHCv1nxSrxFKjFGkF4WA9Qjt6pTavUDB3S7SVJe1kXmkek49NqTtmAjniFIurUtksyDJVNwCTFEITwzdhgMXrxaYxDJDwm52+Bq X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2017 12:23:04.7790 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [PATCH v3 15/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: Wed, 23 Aug 2017 12:20:36 -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 | 40 ++++++++++++++++---- OvmfPkg/VirtioNetDxe/SnpShutdown.c | 2 + 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/VirtioNet.h index 710859bc6115..d80d441b50a4 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; // VirtioRingMap UINT8 *RxBuf; // VirtioNetInitRx UINT16 RxLastUsed; // VirtioNetInitRx VRING TxRing; // VirtioNetInitRing + VOID *TxRingMap; // VirtioRingMap UINT16 TxMaxPending; // VirtioNetInitTx UINT16 TxCurPending; // VirtioNetInitTx UINT16 *TxFreeStack; // VirtioNetInitTx diff --git a/OvmfPkg/VirtioNetDxe/Events.c b/OvmfPkg/VirtioNetDxe/Events.c index 5be1af6ffbee..6950c4d56df1 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 will not be able 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..803a38bd4239 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -35,11 +35,13 @@ 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 VirtioRingMap(). @retval EFI_UNSUPPORTED The queue size reported by the virtio-net device is too small. @return Status codes from VIRTIO_CFG_WRITE(), - VIRTIO_CFG_READ() and VirtioRingInit(). + VIRTIO_CFG_READ(), VirtioRingInit() and + VirtioRingMap(). @retval EFI_SUCCESS Ring initialized. */ @@ -49,11 +51,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 +83,38 @@ 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 +468,22 @@ 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 +532,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: diff --git a/OvmfPkg/VirtioNetDxe/SnpShutdown.c b/OvmfPkg/VirtioNetDxe/SnpShutdown.c index 5e84191fbbdd..36f3253e77ad 100644 --- a/OvmfPkg/VirtioNetDxe/SnpShutdown.c +++ b/OvmfPkg/VirtioNetDxe/SnpShutdown.c @@ -67,7 +67,9 @@ VirtioNetShutdown ( Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); VirtioNetShutdownRx (Dev); VirtioNetShutdownTx (Dev); + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxRingMap); VirtioRingUninit (Dev->VirtIo, &Dev->TxRing); + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxRingMap); VirtioRingUninit (Dev->VirtIo, &Dev->RxRing); Dev->Snm.State = EfiSimpleNetworkStarted; -- 2.7.4