From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0084.outbound.protection.outlook.com [104.47.32.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AF037208F7AD4 for ; Thu, 3 Aug 2017 07:33:03 -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=2V6l9CvyVjSBtbbtCkcIh9Oj2iDULgo2dKCYkpkM8ag=; b=RXZTb48P620xY/ElqmMhJJsoC6U3RkRSlV/m37B5QgYaS/pI9PLZoVKvuHYluZsnEv5AW2mcvu/6hSyLyAXESLgb1qYD63xg8TPRaTeYFmxrKxA+fnwCY+r+Hkk8eGT7wpI2Zu5ueRBjLjT1R0Kx6I/fgZcLQIkhTZQtUvLGyZI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [10.236.136.62] (165.204.77.1) by SN1PR12MB0157.namprd12.prod.outlook.com (10.162.3.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1304.22; Thu, 3 Aug 2017 14:35:11 +0000 Cc: brijesh.singh@amd.com, edk2-devel-01 , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Andrew Fish To: Laszlo Ersek References: <20170802212453.19221-1-lersek@redhat.com> <20170802212453.19221-11-lersek@redhat.com> <560549ae-700a-2a1c-db97-0851d3a12fe1@amd.com> <4eda3a9b-6be8-ef61-117a-ebff5e988629@redhat.com> <1a75582e-a3ba-d20c-75b8-c558cd373787@amd.com> From: Brijesh Singh Message-ID: Date: Thu, 3 Aug 2017 09:35:06 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1a75582e-a3ba-d20c-75b8-c558cd373787@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR1101CA0017.namprd11.prod.outlook.com (10.174.246.27) To SN1PR12MB0157.namprd12.prod.outlook.com (10.162.3.144) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a5faaea7-d6df-4aa4-bd37-08d4da7cd963 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:SN1PR12MB0157; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0157; 3:Wa8iBgVtXEeg55AR+eQ58MYpx+sd4eNBChjPyOYmaU+P7BJDzJFIXHGLW7wfo4Eze6ODf+Hd0Oq0FfnLVBV2f3FQcatXIc3g6CrvXZByyOfrQFQxvkutJHDOG01vd146b2Pdqy/k1VqVUDUHSGQ3nVjZYrJ7AzZGpRjYJ6J91YpXoAGhR/Ei+zuuJ/eJGc9e5vIY4YgWMHCv1IX5c5cdZCpuRakQs2Cc7RHYdj+RhNg8QftAvIe9LdVSzH2P7QBR; 25:ID4qs7cfP3Lt6FvAvI3RX4on1GlfzbPyfExkDMtaKr2cW3r8fXkX9mrqhEsL57DSGVyRlVcw36wmV8QD0nXpWBS1wtm7ZiC7byVVQT89VRobEWgnHErWy6Rh04z2ZG+xa3iiuod30PXTY+uEzH9AYiVF7a8k3VHsGHt3nsDIwYb45I9bUCvkSRl+Ha/exMAD3YOOwW9I9Dg1o/K2AwgbhtDoyJC5ADEWsPCM2SR7HB+qdvEs1VbQZnsRCJQy2v2AibE0pQzmpI57OyhPdDTx4ZAXBvGHkD1iSYlhO06eBAJE73YhH3WWQC1Xdms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zSd45/ZgKmuuy1d3F6Zmq4oBNTfdyqGGbf3D7wdrI0OWRMQ77mBqM9jNfoI1K2I1s= X-Exchange-Antispam-Report-Test: UriScan:(31960201722614); 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)(3002001)(100000703101)(100105400095)(93006095)(93001095)(6055026)(6041248)(20161123564025)(20161123560025)(20161123555025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0157; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0157; X-Forefront-PRVS: 03883BD916 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6049001)(6009001)(6029001)(39410400002)(39400400002)(39860400002)(39850400002)(39840400002)(39450400003)(189002)(199003)(377454003)(24454002)(6666003)(23676002)(2870700001)(2950100002)(7736002)(6916009)(305945005)(68736007)(6306002)(81156014)(31686004)(8666007)(53936002)(8676002)(229853002)(54906002)(50466002)(2906002)(4001350100001)(47776003)(65956001)(66066001)(65806001)(97736004)(76176999)(54356999)(83506001)(50986999)(189998001)(53546010)(64126003)(966005)(106356001)(3846002)(105586002)(90366009)(4326008)(25786009)(101416001)(31696002)(86362001)(36756003)(65826007)(5660300001)(81166006)(6246003)(42186005)(38730400002)(110136004)(77096006)(6486002)(478600001)(33646002)(7350300001)(93886004)(6116002)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0157; H:[10.236.136.62]; 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-Micros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DiSQ==; 5:78DD0zUMLuMy5Lna07MZUuTZG/iMdVJXNrqb07Ojhlz16gDjCG9zmeCQLyYU04+YJ2inSj98MWutQlzn4FSllU7UdEDjEs+X+URfCe5T8/CKaS0ZnkML+/T18fPX7G1WGF7O0UgxolPabry3yiCzQw==; 24:L8nr4Xq3OQqMe4tK3RksrUcWqazA//8TEHes0Gix/Z5Qq6erTe72F7RnMBX3/QgArYk8rANhOSWZGxed7lRSCHUHmdKxaEe0gVN565ryL3k=; 7:4RDToWoPQUglOjvIHFio2aQauBoDsXzDULRIFz+lGH+9iY8+qjpftaaGZe53CEMq06seg386eaIOgNLWGw+9yWXriCKAUMpYP4SgxtDaEQT04cIMag3o1qZZC0wFd5p/PyAtT3uNi1pRhKHqTVp8lg635FguFom9aJHgCE9bBwA78O/fgd8l1YW90z/Xx3gjwWgggynO7KTpS/X4NvLEYi9xbfyMPR5IBpfgRDs5boo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0157; 20:sM0CNV9ZYiUrYkz81V/LxU3CxmgqxKPC3reYwSEPxzXtpEabexRmKfaKVORV1GLrT5dp4uxpghmg/jIg8XkeDlxfAVW/8iA2IAKmwifH9I9I1T9T+iFfgiwBTvgA/JsGofuH6JxRGO3m07tpZnnNBhRrTANxo8h1KyiGStElHX8AOxEhESTHLgdPopa66zVMDVi8JpVpOfUZLTnpEmGRpyno6sOyVXf5MxMpBtMsvBzkfkb5OilmDqew9r5zVDIV X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2017 14:35:11.6574 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0157 Subject: Re: [PATCH 10/12] OvmfPkg/IoMmuDxe: implement in-place decryption/encryption for Map/Unmap 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: Thu, 03 Aug 2017 14:33:04 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Laszlo, One minor issue, I got compilation error with GCC48. /home/brijesh/codomania/edk2-new/edk2/OvmfPkg/IoMmuDxe/AmdSevIoMmu.c: In function ‘IoMmuUnmap’: /home/brijesh/codomania/edk2-new/edk2/OvmfPkg/IoMmuDxe/AmdSevIoMmu.c:408:25: error: ‘CommonBufferHeader’ may be used uninitialized in this function [-Werror=maybe-uninitialized] CommonBufferHeader->StashBuffer, Looks like we need to initialize CommonBufferHeader = NULL to keep GCC48 happy. thanks On 08/02/2017 08:09 PM, Brijesh Singh wrote: > > > On 8/2/17 7:13 PM, Laszlo Ersek wrote: >> (CC Andrew) >> >> On 08/03/17 01:01, Brijesh Singh wrote: >>> >>> On 8/2/17 4:24 PM, Laszlo Ersek wrote: >>> >>> [Snip] >>>> At the moment, we have the foll+ // The buffer at MapInfo->CryptedAddress comes from AllocateBuffer(). >>>> // >>>> MapInfo->PlainTextAddress = MapInfo->CryptedAddress; >>>> - >>>> // >>>> - // Therefore no mapping is necessary. >>>> + // Stash the crypted data. >>>> // >>>> - *DeviceAddress = MapInfo->PlainTextAddress; >>>> - *Mapping = NO_MAPPING; >>>> - FreePool (MapInfo); >>>> - return EFI_SUCCESS; >>>> + CommonBufferHeader = (COMMON_BUFFER_HEADER *)( >>>> + (UINTN)MapInfo->CryptedAddress - EFI_PAGE_SIZE >>>> + ); >>> One question, per spec, is it legal for client to call Map() at some >>> offset within allocated buffer ? >>> >>> e.g something like this: >>> >>> * AllocateBuffer (, 1, &Buffer); >>> * MapBuffer = Buffer + 10; >>> * Map (, BusMasterCommonBuffer, MappedBuffer, 10, ..) // Bascially Map >>> 10 bytes from offset 10 >> The input/output parameter names seem to counter-indicate such use. >> Namely, AllocateBuffer() outputs a "HostAddress" param, and Map() takes >> a "HostAddress" param. Plus we have sentences like this: >> >> Under PciIo.Map(): >> >>> ... only memory allocated via the AllocateBuffer() interface can be >>> mapped for this type of operation ... >> Under PciIo.AllocateBuffer(): >> >>> The AllocateBuffer() function allocates pages that are suitable for an >>> EfiPciOperationBusMasterCommonBuffer or >>> EfiPciOperationBusMasterCommonBuffer64 mapping. This means that the >>> buffer allocated by this function must support simultaneous access by >>> both the processor and a PCI Bus Master. The device address that the >>> PCI Bus Master uses to access *the* buffer can be retrieved with a >>> call to Map(). >> This second passage says *the* buffer. (Emphasis mine above.) >> >>> If this is legal then we may need to build MapInfo during >>> AllocateBuffer() to locate the "StashBuffer". >> Right, in that case we'd have to build a list of allocated ranges (an >> interval tree of sorts) in AllocateBuffer, and convert any >> CommonBuffer[64] Map() call to its containing allocation with a search. >> >> It would be worse than that, actually... The pattern you have raised >> could be taken one step further: do one AllocateBuffer(), and several >> CommonBuffer[64] Map()s into it :) What should happen if those maps are >> distinct? What should happen if they overlap? :) I can't even imagine >> what this would mean for SEV. >> >> ... There are guide-like sections in the generic description of >> EFI_PCI_IO_PROTOCOL; Andrew quoted them earlier: >> >> http://mid.mail-archive.com/A29CDE8F-C82A-4C92-ABF8-008A9BF8F230@apple.com >> >>> DMA Bus Master Common Buffer Operation >>> ====================================== >>> * Call AllocateBuffer() to allocate a common buffer. >>> * Call Map() for EfiPciIoOperationBusMasterCommonBuffer. >>> * Program the DMA Bus Master with the DeviceAddress returned by Map(). >>> * The common buffer can now be accessed equally by the processor and >>> the DMA bus master. >>> * Call Unmap(). >>> * Call FreeBuffer(). >> Look at page 854 (printed page number: 784) in UEFI 2.7. >> >> Thus, I don't think the usage you raise is permitted. > > Sounds good. I did a quick test on SEV hardware, everything seems to be > working well. I have started my stresstest and report the result tomorrow. > > -Brijesh >