From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0063.outbound.protection.outlook.com [104.47.33.63]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9B37F21DFE904 for ; Mon, 7 Aug 2017 04:57:17 -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=IlLH7kBjNSe5tVQOXkNUYIhQJonIrxySuj7VBYQSEF8=; b=m5dL4rSxWcMe6Yhd07NWJFKzxO5KgIMj59upIZ+yg28vMWvHLU279IPbm3M5nS9QV7ltPo8k4J3pr2iQBbZWO7iZWIh5VTsYAYzq9vx0D5U21UnPHyHLEgZzfniGcuAFrlugzfvJ2doygOiJGqt2nVf2uYYxjhq+hY4srLMqwHo= 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 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:31 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Mon, 7 Aug 2017 07:58:59 -0400 Message-Id: <1502107139-412-15-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: 2c97f3f5-a9fa-47f7-294a-08d4dd8bc395 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:l22PuZtPsOSPq3iYWEnUWuLbmLajMYAH7EZPtjiZN0kugdlc05fjbvvXXRW05CRWx/okbY8UU61jkM3nRXApXxAJyjMXMiz3JhUAOEb9v+4dxYWv7AC0HlLmTzJaf+hlpskF6B0TmSikfRTO81mvhOqfX1c/D3pZ0wkOAinH6vYJ4iflkP08Toer/3XVAF5AV0kYULZ9E3OfUTM2VK+kSVHpargbClD9uM0KYMcypF+zjXRdnax/q+QlQHwi8xWK; 25:qxlGYFi1139ZowYjN1X7ANCPm8/uRZEjPocWxrdev/iGO08HudivCtmK9wC/ZdWlb3a4OoAF9nkQ/k3hMA0TKJrfQP6mSSQ6wKalWgnIMHusJx0ws0tz1i3VTn1WuDWpy3md0a+puUmGxKgcyF1/3UoIYBOtIVvdc9L2k1tRg53+Gx+Gjrh62BwCwQjiNMbiIOWgUsBz2yVESTg/Drwccd/JrIfCJXBs30nCOEKhy172pvUhWej7Iy1mMSxxyg+cjXq6s/PxxH18pe/CrFBLUopCJ0P8pSeE6qa6eqdTsCyaZZU5pwINKt4ztF8hItrRG+yxQPbNWL029+siV2xEhA==; 31:inq3UR/k1tK1uo2iJYCUq2QhH87pIxJjaFiE3XuHp1YTpwCsO/AqtdoB7gcCPOHvUfJo67ulGJBfmC1yqD1gglKaTRxnHIOQtMScRzEos5oBO+E22qXnCDMjmyqGV0w8Bmffa+hNjDMOL36SAvFd+A9dnjKBwD8DqUr9rasEdJy241jNzSi5rOnhj+y/i2RXqxPlR+EKG4DUWoAYnH9CnFhDqDtdE6zCkZynoRtSkxM= X-MS-TrafficTypeDiagnostic: SN1PR12MB0159: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0159; 20:AMvIHMPOQWD3pumdj5cnlErBxFxG2WdJjyU4yrf1i/nkYH2MbxicsFXhATu2B18J0S58CtgP6O84ZHHGdfs0+T1+JXcoaoZORJNmQTFkeQzXGv7WdWE0CVC3hXkXZqYhyh2u+Dbol73KxU5461++/sJIA0VMFyunDODtujVuNkTihsIa1Y0c+fPIQFGqiI9t8sZ0+tLl53NQTrlJqGiZ7o1OJtJj5W+68ct585njchK55C8ofFQEsDPbVyCo31tZV0d0T7wuyZSfpIAdhcjuHbVxZ2CFI2o7NHRSkTPndVauOssgm5r43OCJQalkY1V+LnowPAJzihTEjkc7HL/6thNy26VPsVKoG1ShNgSM9GTVYXoGpWEHfb9hQQ0X/EtY/aYQnKIvPsKExBDreHcIxHHO/crmriugmzpeP3z4J3gGGPR4aSz97JcGIs4lnOGf7esLaAtXV7CyuC4jwIfRayr0T1zHInkONQmQ63pPJbw7XRxJ4O4H+KHsMKcZxqMj; 4:2nlqfwrmyc+hd0/dk0yK8c6kd0ApMcCgK+CURO6yeILu3Fq7VHTHAeitEmfNALWe3pxjfRCOvEvVR1lgIXJKTRTMDzaCFAsm0D8mK2u7Pa8Da/xMelo3o2dmyH+J+ZTdvAkMy7JEhCB5Nb6FpSTESlQpueuiyB2JhizyQpEo1TkCHc2+DkHP37egW3z3z6UQdCd0+X/vKyFDlwSrIE27RKE52zmHC/iAFKA+/8wwWPU+MEjOQP4S6ZXa3y734ylXOJ23Lg8Osd2ihTX2uNVVX63pZscSUPjnZfpa5lBnG6Q1q9rxz590tVdQOGNRkhcO7Ya06BgpIzkMil8v1TtfAQ== 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)(39400400002)(39850400002)(39450400003)(39410400002)(39840400002)(39860400002)(199003)(51234002)(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 (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0159; 23:VY7+V5bEuXv5lXe2yADgRWh8jTxCyeNq0GluZMNnR?= =?us-ascii?Q?k2EfFY5ezEHhmEMSOBAP2YvZLXbNUZ2/5rI8aYaYoZdOJJCHHUQ8FC7B/50v?= =?us-ascii?Q?qGKdsZPhayM80m2IZ1VpnlQkbopsi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xPv8ChLGp1hQBSGlNE6mdW90sYQpDh7aq2W/VMLv+hfBjY2DinLMNZwvLUPLmtp5ASqRECjiaD/ScLvbV4B7KU0LJ4MND9oyltf3BleF9AyENl4wE315Q4NZS10O8QBIUNhaf4SV0HmYHj8vWuNprTDSW/kv1eiiHyOUA7VaBJEhA+b8WoAlHfGoKvU2kpD+hlDRVuRKtQk6h1mwB84eZa7loWZ72DM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0159; 20:aZGy5e7Z6WblstVoPv+jvkHdPpWGclbkADM3n5W2acEt4lk+O+IgPAl9u0iSUg8iVjNTM3nRvZ2XDMxcQpVlKw91XmfunqiR1OgYqETvTgfvaHFwtwtjBCXaE7ron6I+4e9hSWLq871imqsoSY+WLlAPDliYHNaQdzn5ffPWkDZyoFP3YfO/UiuNjUo2SERlwczLY0CfhAvgeYwmseY8RdY8e+QimW1LDotSR+rbeK3EPIwPTzKLSSkrb6YU8gsB X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2017 11:59:31.2609 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0159 Subject: [PATCH v1 14/14] OvmfPkg/VirtioRngDxe: Use DeviceAddresses in vring descriptors 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, 07 Aug 2017 11:57:18 -0000 Content-Type: text/plain The patch uses newly introduced VIRTIO_DEVICE_PROTOCOL.MapSharedBuffer() to map system memory to device address and programs the vring descriptors with device addresses. 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/VirtioRngDxe/VirtioRng.h | 1 + OvmfPkg/VirtioRngDxe/VirtioRng.c | 47 +++++++++++++++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/VirtioRngDxe/VirtioRng.h b/OvmfPkg/VirtioRngDxe/VirtioRng.h index 998f9fae48c2..b372d84c1ebc 100644 --- a/OvmfPkg/VirtioRngDxe/VirtioRng.h +++ b/OvmfPkg/VirtioRngDxe/VirtioRng.h @@ -38,6 +38,7 @@ typedef struct { EFI_EVENT ExitBoot; // DriverBindingStart 0 VRING Ring; // VirtioRingInit 2 EFI_RNG_PROTOCOL Rng; // VirtioRngInit 1 + VOID *RingMap; // VirtioRngInit 1 } VIRTIO_RNG_DEV; #define VIRTIO_ENTROPY_SOURCE_FROM_RNG(RngPointer) \ diff --git a/OvmfPkg/VirtioRngDxe/VirtioRng.c b/OvmfPkg/VirtioRngDxe/VirtioRng.c index e20602ac7225..5ff54867616a 100644 --- a/OvmfPkg/VirtioRngDxe/VirtioRng.c +++ b/OvmfPkg/VirtioRngDxe/VirtioRng.c @@ -140,11 +140,15 @@ VirtioRngGetRNG ( UINT32 Len; UINT32 BufferSize; EFI_STATUS Status; + UINTN NumPages; + EFI_PHYSICAL_ADDRESS DeviceAddress; + VOID *Mapping; if (This == NULL || RNGValueLength == 0 || RNGValue == NULL) { return EFI_INVALID_PARAMETER; } + Dev = VIRTIO_ENTROPY_SOURCE_FROM_RNG (This); // // We only support the raw algorithm, so reject requests for anything else // @@ -153,12 +157,18 @@ VirtioRngGetRNG ( return EFI_UNSUPPORTED; } - Buffer = (volatile UINT8 *)AllocatePool (RNGValueLength); - if (Buffer == NULL) { + NumPages = EFI_SIZE_TO_PAGES (RNGValueLength); + Status = VirtioAllocateSharedPages (Dev->VirtIo, NumPages, (VOID *)&Buffer); + if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } - Dev = VIRTIO_ENTROPY_SOURCE_FROM_RNG (This); + Status = VirtioMapSharedBufferWrite (Dev->VirtIo, (VOID *)Buffer, + RNGValueLength, &DeviceAddress, &Mapping); + if (EFI_ERROR (Status)) { + VirtioFreeSharedPages (Dev->VirtIo, NumPages, (VOID *)Buffer); + return EFI_DEVICE_ERROR; + } // // The Virtio RNG device may return less data than we asked it to, and can @@ -170,7 +180,7 @@ VirtioRngGetRNG ( VirtioPrepare (&Dev->Ring, &Indices); VirtioAppendDesc (&Dev->Ring, - (UINTN)Buffer + Index, + (UINTN)DeviceAddress + Index, BufferSize, VRING_DESC_F_WRITE, &Indices); @@ -178,19 +188,22 @@ VirtioRngGetRNG ( if (VirtioFlush (Dev->VirtIo, 0, &Dev->Ring, &Indices, &Len) != EFI_SUCCESS) { Status = EFI_DEVICE_ERROR; + VirtioUnmapSharedBuffer (Dev->VirtIo, Mapping); goto FreeBuffer; } ASSERT (Len > 0); ASSERT (Len <= BufferSize); } + VirtioUnmapSharedBuffer (Dev->VirtIo, Mapping); + for (Index = 0; Index < RNGValueLength; Index++) { RNGValue[Index] = Buffer[Index]; } Status = EFI_SUCCESS; FreeBuffer: - FreePool ((VOID *)Buffer); + VirtioFreeSharedPages (Dev->VirtIo, NumPages, (VOID *)Buffer); return Status; } @@ -281,6 +294,11 @@ VirtioRngInit ( goto Failed; } + Status = VirtioRingMap (Dev->VirtIo, &Dev->Ring, &Dev->RingMap); + 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. @@ -332,6 +350,11 @@ VirtioRngInit ( return EFI_SUCCESS; ReleaseQueue: + if (Dev->RingMap != NULL) { + VirtioRingUnmap (Dev->VirtIo, &Dev->Ring, Dev->RingMap); + Dev->RingMap = NULL; + } + VirtioRingUninit (Dev->VirtIo, &Dev->Ring); Failed: @@ -359,6 +382,11 @@ VirtioRngUninit ( // the old comms area. // Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); + + if (Dev->RingMap != NULL) { + VirtioRingUnmap (Dev->VirtIo, &Dev->Ring, Dev->RingMap); + } + VirtioRingUninit (Dev->VirtIo, &Dev->Ring); } @@ -385,6 +413,15 @@ VirtioRngExitBoot ( // Dev = Context; Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); + + // + // If Ring mapping exist then umap it so that hypervisor will not able to + // get readable data after device reset. + // + if (Dev->RingMap != NULL) { + VirtioRingUnmap (Dev->VirtIo, &Dev->Ring, Dev->RingMap); + Dev->RingMap = NULL; + } } -- 2.7.4