[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v7] Preserve the EFI System Resource Table for dom0


  • To: Demi Marie Obenour <demi@xxxxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 23 Jun 2022 09:16:16 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lDgs1HB882nMw2vbqio/+G1oDHLLiit74yvDM7dk/N0=; b=V8520zKTOp3BHiXWm5Jh7gLMeNMksoLg2fzjibTfTYCItrafKrZyinGZfjn8VlJPcPagcko8HRG9ec4fMwd2yXmkdW6omdEyi6I4e11rFHpeZfpV/HxcshCSPQRYboz+L4zfvN/UPnQAvkZpFSBZOkmTJjkuRTeGfZ5navBPMM+4tSkoKGce2esvvdCvZ/vNhR10SBunaWVly5VnZIKqL3UzDpe33U0VOOZu1vKPGenwCDO5nPg/lPYF8J9+EDGhmu5XSwfTxlK8zmd28Nwh+k+SmFw5t8cF38EEHAnFsy5IqFp1gOSW3lh3b39o3lLyWcN+6FycR3QxFl5xO84f+g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nk3kMSdt9SsMHqiK+3P6Kzz0oRoIglibiGBSPLO57TEeqKJUyJ9kE0I8wpyWwazU2xJkwBLOv+M9+R4/dcOoDiHdfMs+KOSTKcaN8C8EEPBubRXPD4HEsYfm+iC7MQvEUJPgLz/HDpIgzfVZ0h8Wkv3UK3gnAZqo8DeIkoJToVPfXoMYYM7zad9ecM6EmoLlUNzdIiT4s7CKLrm6lRrpwx3WwwcxXQp54gCajBtbRSVEsuzLyJtVZ2sAfhOawuTmsN6yJ9qrPNT+J/BK8AHEJoIgt3b+Q7oGclG1kUNmBkA3BPKu2B1t8nJzXwJjLxxpw7H7ZfLfpIbftgayYmNaNg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 23 Jun 2022 07:16:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 22.06.2022 03:23, Demi Marie Obenour wrote:
> @@ -1051,6 +1110,62 @@ static void __init 
> efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop
>  #define INVALID_VIRTUAL_ADDRESS (0xBAAADUL << \
>                                   (EFI_PAGE_SHIFT + BITS_PER_LONG - 32))
>  
> +static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable)
> +{
> +    EFI_STATUS status;
> +    UINTN info_size = 0, map_key;
> +    unsigned int i;
> +    void *memory_map = NULL;
> +
> +    for (;;) {

Nit: Style:

    for ( ; ; )
    {

> +        status = efi_bs->GetMemoryMap(&info_size, memory_map, &map_key,
> +                                      &efi_mdesc_size, &mdesc_ver);

Unless you have a reason to (which I don't see), please don't alter
global variables here. 

> +        if ( status == EFI_SUCCESS && memory_map != NULL )
> +            break;
> +        if ( status == EFI_BUFFER_TOO_SMALL || memory_map == NULL ) {

Nit: Brace placement.

> +            info_size *= 2;

Doubling the buffer size seems excessive to me. If you really want it
like that, I think this deserves saying a word in the description. As
said before, the same increment as in efi_exit_boot() would look best
to me, for consistency.

> +            if ( memory_map != NULL )
> +                efi_bs->FreePool(memory_map);
> +            status = efi_bs->AllocatePool(EfiLoaderData, info_size, 
> &memory_map);
> +            if ( status == EFI_SUCCESS )
> +                continue;
> +        }
> +        return;

Perhaps emit a message?

> +    }
> +
> +    /* Try to obtain the ESRT.  Errors are not fatal. */
> +    for ( i = 0; i < info_size; i += efi_mdesc_size )
> +    {
> +        /*
> +         * ESRT needs to be moved to memory of type EfiRuntimeServicesData
> +         * so that the memory it is in will not be used for other purposes.
> +         */
> +        void *new_esrt = NULL;
> +        size_t esrt_size = get_esrt_size(efi_memmap + i);
> +
> +        if ( !esrt_size )
> +            continue;
> +        if ( ((EFI_MEMORY_DESCRIPTOR *)(efi_memmap + i))->Type ==
> +             EfiRuntimeServicesData )
> +            return; /* ESRT already safe from reuse */

"break" here so that ...

> +        status = efi_bs->AllocatePool(EfiRuntimeServicesData, esrt_size,
> +                                      &new_esrt);
> +        if ( status == EFI_SUCCESS && new_esrt )
> +        {
> +            memcpy(new_esrt, (void *)esrt, esrt_size);
> +            status = efi_bs->InstallConfigurationTable(&esrt_guid, new_esrt);
> +            if ( status != EFI_SUCCESS )
> +            {
> +                PrintErr(L"Cannot install new ESRT\r\n");
> +                efi_bs->FreePool(new_esrt);
> +            }
> +        }
> +        else
> +            PrintErr(L"Cannot allocate memory for ESRT\r\n");
> +        break;
> +    }

... you can free the memory map here.

> @@ -1067,6 +1182,13 @@ static void __init efi_exit_boot(EFI_HANDLE 
> ImageHandle, EFI_SYSTEM_TABLE *Syste
>      if ( !efi_memmap )
>          blexit(L"Unable to allocate memory for EFI memory map");
>  
> +    status = SystemTable->BootServices->GetMemoryMap(&efi_memmap_size,
> +                                                     efi_memmap, &map_key,
> +                                                     &efi_mdesc_size,
> +                                                     &mdesc_ver);
> +    if ( EFI_ERROR(status) )
> +        PrintErrMesg(L"Cannot obtain memory map", status);
> +
>      for ( retry = false; ; retry = true )
>      {
>          efi_memmap_size = info_size;

What is this change about? If it really is needed for some reason, I
further don't see why you don't use efi_bs (it cannot be used inside
the loop, but is fine to use ahead of it).

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.