From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=40.107.70.47; helo=nam04-sn1-obe.outbound.protection.outlook.com; envelope-from=brijesh.singh@amd.com; receiver=edk2-devel@lists.01.org Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700047.outbound.protection.outlook.com [40.107.70.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D6C6621B02845 for ; Wed, 27 Jun 2018 09:34:43 -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:X-MS-Exchange-SenderADCheck; bh=RAJTWwsNA2C/RTgSugSc3rx6heneuE9v/MC7ztSiMA4=; b=31a0qvquXDbCf1K3kYN6q+fsLokgpIiceLJfB9SkdkmWnckf45UdTfF1fPIW85sXnEka0I0wHbDr/PrV3O3mZCOc1MY6g3OmhJIPhp5EqUeQ/xq+XYZNEzAgOteZmHDK3zupKBhzu+gUKZoHbhPSrGltMi/C9zoFniFFZPhZrII= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [10.236.136.62] (165.204.77.1) by MW2PR12MB2460.namprd12.prod.outlook.com (2603:10b6:907:9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.884.23; Wed, 27 Jun 2018 16:34:40 +0000 Cc: brijesh.singh@amd.com, Tom Lendacky , Star Zeng , Eric Dong , "Jordan Justen (Intel address)" To: Laszlo Ersek , edk2-devel@lists.01.org References: <1530042365-9979-1-git-send-email-brijesh.singh@amd.com> From: Brijesh Singh Message-ID: Date: Wed, 27 Jun 2018 11:34:36 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR0401CA0045.namprd04.prod.outlook.com (2603:10b6:4:73::22) To MW2PR12MB2460.namprd12.prod.outlook.com (2603:10b6:907:9::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2fc1dc28-c7d8-4271-25c3-08d5dc4be1c5 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600026)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:MW2PR12MB2460; X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2460; 3:I3g8UcjmLHMhMUum0d5ePr96YPBMzFVqPLEhSVMwmMI8T0BllRP69X0BDtysIGJINszBa3Ia9oYoSPPfHzo/RLZPmIS94o2Ixhc7f2W80fbJqGPV6u0zoOsASry/IFfw1KujiHjzYQBFXk/PX4d28rAnWeKf/EWOPCVKMhecsDmgv6togVA1GRzNB6YZP7qNX1emfCw6aaHNB7eUA/wl+mYeMO37/oCfcekdmgZExCcxgvancqCeEQj72s4HJZ1n; 25:Q+XyJ0ix+XPiOc7En9KBkYu8YMuYj1aJr2Rt9Pm5uj8dQxTcThkrLdjL4vIggZdz0ZmKr5nbrbOE72fUlc7CN6/FlhF30lQUJUTNxPAMCcYZhpEbEim/UmdsTc+N+sROODBEFhK3tCLoK6EAvu5cv+6jYFmu/wdYSwoOBhxZgJGrII2rdyiHFvHhMOdi9OEe4NZ9OBzb1BfulvisvkBQlO5gEfj1lBoWni/YIUemZZbwC2Z8OwF4p76MIDfAtRArAij8XBiP9J+KuNcv3039un4MCDOsRPTtiW7sqnC0X0mlxVtYC8HXnRex17qir4wNWuNPuCnDsYpDRT5VZSMWHw==; 31:Sl8MD91gRZKvV5rViIkVD0CkQq607M2/MD1aNrDsDcn9Ke6YJC+/H4A5y57/qHSF+VjZj2B7DYkkM6U3QAPKl/z5amgR32McMB8Nx/FQIFu0DPlRTZSpSmlzZAHEKu6L4LWdUAYLZ8y1WrU4AG8672dWvXU13ok5Ecyf64DvYFTjp9YieIKmVvN916v109/hXzPNs3Jl8JKT6P5wCDqUcJcnap+3y21COjndK+T/5Xo= X-MS-TrafficTypeDiagnostic: MW2PR12MB2460: X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2460; 20:ROjFbeQlKEc2bjk7w0Zba+wHWzi3D5cnU5iNn/eHMU5JEQGhVn8fqT7cRzk8E9cUySlSqqpEtRvshPdPkeBBeWahJ/vb0uBM2m9WCPql3y6sm97e/6rEsjAvi/ADXB8ZgK3R5IiTNORv/o9GbhmYgnJRqQpqTgiddvmH3yTtRMRIHtXtr1vnciP6eHaXbZfmyqJ+6ESny6YgTDukCAjzySDUX4QHKWdFZflzElkECqfE34JXvBH6JeD2QoKEiS8qUSozIrbs23lNnoNwJeIEh7keP36uw7fmDWplTAue9ugjsjgC2yTe9w5JAKXthLBy5r6P+Eas2yOUcoHueuFqelIKLztCVjw66IDZNzMSZxi7XqjPGri4UBBD/av9jq9I3b++wm/OXZAeEWyDfX1RxF5qT4r1lvE7H9IaudFjPr2uVtQS5OY/fMpIZCYf+XRuPLAT8ctJli84zN3DJBJMSDzMYyEopEDRKT9aq6FUoQ67TadFN/4ZiEaiTIzALwe/; 4:dnGT5qy2j4DeBkbU3Ou2K9AY71dVT8VowkuvjHuAd4oNWr4IxDYLqsH+2X0yThfu6dVby6NUxzk6CyurhNe8nWLeCeDw4djRprNgshHWxuIZGDXBBaMAGP/iMg87ySHPVmeb4vtgYkErsudwNMxDoxKCztW3JoF0sxPTbjADuMVn7tD+5kIrM23ZvzS76yUDgvHfYReyv2meEslHkjdxJtro2n/tQARNx0A7b48K9YDOEplpGGgLvhRJZjUyY+Xj9i/DI2dyttzdo0grTvAUa+XdUL9hTGiym2cStC1sV5r5YwXpCoohbod50iJwFN42 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(3231254)(944501410)(52105095)(10201501046)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:MW2PR12MB2460; BCL:0; PCL:0; RULEID:; SRVR:MW2PR12MB2460; X-Forefront-PRVS: 0716E70AB6 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6049001)(376002)(39860400002)(346002)(136003)(396003)(366004)(189003)(199004)(31014005)(51914003)(52314003)(64126003)(23676004)(6486002)(229853002)(47776003)(6666003)(50466002)(5660300001)(305945005)(65956001)(97736004)(66066001)(7736002)(81166006)(54906003)(65826007)(956004)(316002)(31686004)(16576012)(65806001)(14444005)(52146003)(11346002)(8936002)(105586002)(476003)(8676002)(81156014)(67846002)(25786009)(446003)(53936002)(230700001)(486006)(36756003)(76176011)(2906002)(106356001)(3846002)(4326008)(6246003)(2616005)(68736007)(52116002)(58126008)(77096007)(44832011)(561944003)(386003)(186003)(86362001)(2486003)(53546011)(16526019)(6116002)(31696002)(478600001)(26005)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:MW2PR12MB2460; H:[10.236.136.62]; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNVzJQUjEyTUIyNDYwOzIzOnBQWCtrNFNoSlRiaDREUkdub1BaSThrcW1I?= =?utf-8?B?OVZ5UEp6ZnEyTmR6cHRaaERZOVd4NW41bVh4Y0dTK2prSnlLWFZKVTVmejM5?= =?utf-8?B?SFJDMWlMNEIvK0JZS0JWY1crQjI4M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IF5JSR+MQ2M25RhNGy1B9qgvJhQ6E7oOe3zmxX623wx9D7Y8qD9i5WY0K4ZODCBKCBhzs5A==; 5:w/4cP5b0Y61w+xVn8QSralotth8Q5N0d7lua1iPGNRgcrfbGet0ohd+vkiNdNkpaLxKQlQpxJbH8dRz2JzOCRK1rBsVa9VnqOfjQoC1xS01e5hz/t4lFusMdb5sALrOeMf5T9q8bY1M2MzkFy6M04XgjjIUx3pB/xWyU+J0DoDQ=; 24:KoD4xbjzYXyagiBpmDSuHVnuwxuzkJTc8ZDrNebuFCvBN/ORxUWuls+FUTbhiYcAJ+Lardw+Zf3JDU8Bj7Nh1+bJTLdg7iChjTjev4ZWhiU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2460; 7:5/Iz6vN4M1LR2+PzWImr+x+uomBSmp4pCOEASEluUiKuI6CZ8xybPbVXSB3XrS8IxZ1YuQ5B39R5bYpPozooHn7/eaRYXGeY8iRF6rn6Wtn3DSlEt7BmdPz9dgGATbnw1x4i1u5az/n01JWrKIC1AIms+8OEcvcYXWpN7yawFSG3+e9Fbf8pK1OeVzKsoZbRHtpWCm49+sn6l7jsd5sCJXOKhS3bDohZVNujXhYw1PGH/es0T18rrJ4qxsBL9ysp; 20:OxvySrrreTLQIxZkUYDClKDFI+o4trf7JB1Jiy4Q+ogkddDCDcoJ9u1iegr9G6xppPpKrb0h5p0ob2EXLijHcErZEUwieF4XAvyPNIarHChhdrGZXViJHSTZF+RygMlJaL4+Kc0poPcUd02dY8DPPVyVMiKacpVI8A1OO6/VSbzX0fXVmgvlejGVrRK70ACsysZvb/CeknAAgBJEVAl3ifA0CZHYjtCPRPfltvaLqIhJ8Cu+Jl79wa/GkhUtjvuv X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2018 16:34:40.5151 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2fc1dc28-c7d8-4271-25c3-08d5dc4be1c5 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2460 Subject: Re: [RFC PATCH 1/1] OvmfPkg/QemuFlash: Fix Runtime variable access when SEV is enabled X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jun 2018 16:34:44 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Thanks for the quick feedback Laszlo ! On 06/27/2018 07:54 AM, Laszlo Ersek wrote: > On 06/26/18 21:46, Brijesh Singh wrote: >> Problem statement: >> ------------------ >> Fedora-28 contains 4.16 kernel -- which has all the required support to >> run as an SEV guest. When the installer is launched from SEV guest then >> it fails to install the bootloader. The installer was failing to update >> the 'BootOrder' UEFI runtime variable. >> >> Root Cause Analysis >> -------------------- >> Since QemuFlash storage memory is accessed by both guest and hypervisor >> hence we need to map this memory range as unencrypted. AmdSevDxe maps the >> range as "unencrypted" but later FtwNotificationEvent() in >> MdeModule/Universal/Variable/RuntimeDxe/VariableDxe.c resets the mapping >> and the memory region gets remapped as "encrypted". > > Is this a new issue, or has it always been there, and we just failed to > notice it? > The issue has been always there and we never noticed. I noticed it after I saw installation failure. I can easily reproduce it with simple efibootmgr command: 'efibootmgr -o 0003,0004' -- e.g change boot order > BTW, I don't understand why FtwNotificationEvent() in > "MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c" has to mark > the flash range as EFI_MEMORY_RUNTIME. I thought that this action > belonged in the flash driver itself, and we do that already in > MarkMemoryRangeForRuntimeAccess(), in file > "OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c". > > The variable driver does not own the pflash chip (the pflash driver owns > it), so I believe the variable driver shouldn't mess with the mapping > attributes. > > Here's a suggestion -- Star, Eric, can you please comment? In the > FtwNotificationEvent() function, after we get the memory descriptor for > the pflash range, first check whether EFI_MEMORY_RUNTIME is already set. > If it is, don't do anything; if it isn't, add the attribute. > > This should cause no observable change on any non-SEV platform, and it > should remove the gDS->SetMemorySpaceAttributes() call for OVMF (where > it breaks things for SEV). > If Star and Eric agrees with your proposal then I can create a patch to fix this issue. >> After that, any access >> to the flash will end up going through the encryption engine. I did try >> hacking EDK2 to restore the C-bit > > (I continue to be annoyed that the memory encryption bit is not exposed > in the GCD memory space attributes explicitly.) > >> but that was not sufficient because UEFI >> runtime services are mapped as "encrypted" in OS page table > > What do you mean here? Runtime services *code* or runtime services > *data*? Code must obviously be remain encrypted (otherwise we cannot > execute it in SEV). Runtime Services Data should also be mapped as > encrypted (it is normal RAM that is not used for guest<->hypervisor > exchange). > Sorry, I was meaning to say both the "code" and "data" are mapped as encrypted by the OS. >> hence we end up accessing the flash as encrypted when OS requests to update the variables. > > I don't understand the "hence" here; I don't see how the implication > follows. runtime services code and data should be encrypted. Runtime > MMIO should be un-encrypted. > > Ohh, wait, in MarkMemoryRangeForRuntimeAccess(), we use > "EfiGcdMemoryTypeSystemMemory". I don't have a clue why that is a good > idea. That should have been EfiGcdMemoryTypeMemoryMappedIo. > Right, the memory is marked as 'system ram' and not 'mmio'. Just to experiment, I did try changing it to 'mmio' to see if OS will map this region as "unencrypted" but ovmf fails with below error message after changing it from systemRAM->mmio ConvertPages: failed to find range FFC00000 - FFFFFFFF ASSERT_EFI_ERROR (Status = Not Found) ASSERT [FvbServicesRuntimeDxe] /home/amd/workdir/upstream/edk2/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServie.c(864): !EFI_ERROR (Status) Since this efi runtime data is mapped as C=1 by the OS, hence when OS asks efi to update the runtime variable we end up accessing the memory region with C=1 (runtime services are executed using OS pagetable). > ... Anyway, I think first we should go with the "check > EFI_MEMORY_RUNTIME attribute before setting it", in FtwNotificationEvent(). > >> >> A possible solution >> --------------------- >> To solve the issue, after QemuFlash is probed, I allocate an encrypted >> buffer and initialize this buffer with the contents from the flash memory. >> When SEV is enabled, we use newly allocated encrypted buffer in >> FwInstance->FvBase instead of the original flash region. The idea is if >> caller grabs the FwInstance->FvBase pointer and tries to access the >> FvVolumeHeader then it should get the data from the encrypted buffer. >> But if caller wants read/writes to/from the flash device then we internally >> use the original "unencrypted" flash region to access the data. > > No, this is neither safe, nor a desirable design. While hacking this I knew it was not an idle approach but wanted to start the discussion to find an acceptable solution. > > Safety: all accesses (via both pointers and FVB protocol members) that > higher-level drives *think* go to the pflash chip must *actually* go to > the pflash chip. > Agreed, if all the access to the flash chip was going to go through FVB protocol members then we could use bounce buffer at the lowest level. > Design: it had taken us years to get rid of various memory-emulated fake > variable stores. They *all* suck in one way or another, with various > obscure UEFI spec incompatibilities and corner cases. A strictly > pflash-based varstore is not what we should compromise on. > >> With this >> patch, I have verified that OS is able to update the runtime variable and >> FC-28 installer is successfully able to complete the installation process. >> >> If you all agree with approach then I can rework any feedbacks and remove >> the rfc tag from the patch. If you have better suggestions then I am open >> to explore those as well. > > I'd like to understand the following: > > (1) why does FtwNotificationEvent() set the EFI_MEMORY_RUNTIME attribute > itself, for the pflash range? -- in my opinion, that belongs in the > flash driver. > > (2) Whether Star and Eric agree with setting the EFI_MEMORY_RUNTIME > attribute in FtwNotificationEvent() only if the attribute is not already > present. > > (3) The implication that you describe, between runtime services/code > being mapped encrypted, and restoring the C-bit failing. > > (4) Whether we should modify MarkMemoryRangeForRuntimeAccess() to > install the range into GCD as MMIO. (I feel *very* uncomfortable about > this, however; the current code has existed as-is for years, and > regressions look very risky.) > > My strong preference would be a patch for (2). I think (2) will solve the complete issue, we still need to figure how to communicate the OS to map this flash memory range as 'unencrypted' so that efi runtime services can update the variables correctly. > > Thanks, > Laszlo > >> Cc: Laszlo Ersek >> Contributed-under: TianoCore Contribution Agreement 1.1 >> Signed-off-by: Brijesh Singh >> --- >> .../FvbServicesRuntimeDxe.inf | 1 + >> .../FwBlockService.c | 37 +++++++++++++++++++--- >> 2 files changed, 34 insertions(+), 4 deletions(-) >> >> diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf >> index d7b4ec06c4e6..6bb5c2093790 100644 >> --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf >> +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf >> @@ -54,6 +54,7 @@ [LibraryClasses] >> DevicePathLib >> DxeServicesTableLib >> MemoryAllocationLib >> + MemEncryptSevLib >> PcdLib >> UefiBootServicesTableLib >> UefiDriverEntryPoint >> diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c >> index 558b395dff4a..e82b4ff70961 100644 >> --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c >> +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c >> @@ -36,6 +36,7 @@ >> #include >> #include >> #include >> +#include >> >> #include "FwBlockService.h" >> #include "QemuFlash.h" >> @@ -966,6 +967,7 @@ FvbInitialize ( >> UINTN Length; >> UINTN NumOfBlocks; >> RETURN_STATUS PcdStatus; >> + EFI_PHYSICAL_ADDRESS CryptedAddress; >> >> if (EFI_ERROR (QemuFlashInitialize ())) { >> // >> @@ -986,6 +988,24 @@ FvbInitialize ( >> BaseAddress = (UINTN) PcdGet32 (PcdOvmfFdBaseAddress); >> Length = PcdGet32 (PcdOvmfFirmwareFdSize); >> >> + // >> + // When SEV is enabled, allocate a encrypted buffer which will contain a >> + // encrypted copy of the Flash image. >> + // >> + if (MemEncryptSevIsEnabled ()) { >> + Status = gBS->AllocatePages ( >> + AllocateAnyPages, >> + EfiRuntimeServicesData, >> + EFI_SIZE_TO_PAGES(PcdGet32 (PcdOvmfFirmwareFdSize)), >> + &CryptedAddress >> + ); >> + ASSERT_EFI_ERROR (Status); >> + >> + CopyMem((VOID *)CryptedAddress, (VOID *)BaseAddress, Length); >> + >> + BaseAddress = CryptedAddress; >> + } >> + >> Status = InitializeVariableFvHeader (); >> if (EFI_ERROR (Status)) { >> DEBUG ((EFI_D_INFO, >> @@ -1091,24 +1111,33 @@ FvbInitialize ( >> // >> InstallProtocolInterfaces (FvbDevice); >> >> - MarkMemoryRangeForRuntimeAccess (BaseAddress, Length); >> + MarkMemoryRangeForRuntimeAccess ( >> + (UINTN) PcdGet32 (PcdOvmfFdBaseAddress), >> + Length >> + ); >> >> // >> // Set several PCD values to point to flash >> // >> PcdStatus = PcdSet64S ( >> PcdFlashNvStorageVariableBase64, >> - (UINTN) PcdGet32 (PcdOvmfFlashNvStorageVariableBase) >> + BaseAddress >> ); >> ASSERT_RETURN_ERROR (PcdStatus); >> PcdStatus = PcdSet32S ( >> PcdFlashNvStorageFtwWorkingBase, >> - PcdGet32 (PcdOvmfFlashNvStorageFtwWorkingBase) >> + BaseAddress + >> + PcdGet32(PcdFlashNvStorageVariableSize) + >> + PcdGet32(PcdOvmfFlashNvStorageEventLogSize) >> ); >> + >> ASSERT_RETURN_ERROR (PcdStatus); >> PcdStatus = PcdSet32S ( >> PcdFlashNvStorageFtwSpareBase, >> - PcdGet32 (PcdOvmfFlashNvStorageFtwSpareBase) >> + BaseAddress + >> + PcdGet32(PcdFlashNvStorageVariableSize) + >> + PcdGet32(PcdOvmfFlashNvStorageEventLogSize) + >> + PcdGet32(PcdFlashNvStorageFtwWorkingSize) >> ); >> ASSERT_RETURN_ERROR (PcdStatus); >> >> >