From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by mx.groups.io with SMTP id smtpd.web09.11014.1583134195900579336 for ; Sun, 01 Mar 2020 23:29:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=dCaKDT9j; spf=pass (domain: linaro.org, ip: 209.85.128.66, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wm1-f66.google.com with SMTP id 6so1382775wmi.5 for ; Sun, 01 Mar 2020 23:29:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=d5voujgMcqxW38PUrPPX8MfOOV92e+FDiJkujxWu2cQ=; b=dCaKDT9jPdcsaP9t+RPwUdYkoiuq47xnmcFmdtOHXg9nzhS+uow6uq0QxANkCpE9RJ FlWfGhVTv/Vu2WfgJMIEnYxIw+uGMdqT1e3JF5WirZ8ikA7SKC7DBtYFNWhyggeo6GxP I4AZxcp1PhgSzBqf1sHy9i8DTWSJoVF3C3OJEntvQwDg/kc8TNnYa+vuVJmIRV+3YZLE bTXYYpZD7OLyJ/PHFMxXNiU8UKtNj1AKl23XsJ+h5I3Hnlm/7Cj71JPfkn5pfzSSUajY ET+YbAfNzTRhGC4cTpzb83oUa4YO74ZeQ/f6YIr6RVtWtB+tH+wK7nlblMU0SBgPO1jq mPZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=d5voujgMcqxW38PUrPPX8MfOOV92e+FDiJkujxWu2cQ=; b=P3nckK5QSKL+muowd7tb5jnQUyS+Gq8xHsKf+qUE4aQmX9f0OsqphK783vjNZjkJWW rwWXm3edmP//nuYTDvkfT/woixdtdHWfIaerlNAg/YPQ+zB4PMGoT0mh4knlEVkVLpem 5wnfws2k8d1KL/2PATkK87rYJUER32h0GW2XuB7QtiF0hHKvKpUAb+jMKKarlBRDQzDt +1sMXoLQNwQMalJSw9NOeYgkl8AZ1POqXXy/210wCvOuQ1jUknjszrEOX5Ot0wtxo+WS NktZ9GqKwC5+PFq3HDEF4yft0yAV6v/iPx6tb4/SXIqb5XYZmVutnR3SxF0iqp2K+cYu QjZQ== X-Gm-Message-State: APjAAAVXVFKU7hAgLyWnkfU0/WN9SzCRyIZUr5lQp950otVcLHAk+655 DbKeDSHI5a91HmE+BRzQCiLBaLEB9LBmHw== X-Google-Smtp-Source: APXvYqxeF31XiU5P2jzlyUfKfKTw5oVsiKCgsSyN+FDWSHjPEvhDezAl09w2p24EBL1z+fZdAbIbGg== X-Received: by 2002:a05:600c:34b:: with SMTP id u11mr18081136wmd.69.1583134193840; Sun, 01 Mar 2020 23:29:53 -0800 (PST) Return-Path: Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id z131sm6347153wmg.25.2020.03.01.23.29.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 23:29:52 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [PATCH 11/13] OvmfPkg/PlatformBootManagerLib: switch to QemuLoadImageLib Date: Mon, 2 Mar 2020 08:29:34 +0100 Message-Id: <20200302072936.29221-12-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200302072936.29221-1-ard.biesheuvel@linaro.org> References: <20200302072936.29221-1-ard.biesheuvel@linaro.org> Replace the open coded sequence to load Linux on x86 with a short and generic sequence invoking QemuLoadImageLib, which can be provided by a generic version that only supports the LoadImage and StartImage boot services, and one that incorporates the entire legacy loading sequence as well. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2566 Signed-off-by: Ard Biesheuvel --- OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 2 +- OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c | 157 +++----------------- 2 files changed, 24 insertions(+), 135 deletions(-) diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index f89cce187942..40ac5dd7f9d5 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -48,7 +48,7 @@ [LibraryClasses] NvVarsFileLib QemuFwCfgLib QemuFwCfgS3Lib - LoadLinuxLib + QemuLoadImageLib QemuBootOrderLib ReportStatusCodeLib UefiLib diff --git a/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c b/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c index ddfef925edd3..a15b48d360d2 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c +++ b/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c @@ -9,11 +9,8 @@ #include #include -#include -#include -#include +#include #include -#include #include @@ -23,146 +20,38 @@ TryRunningQemuKernel ( ) { EFI_STATUS Status; - UINTN KernelSize; - UINTN KernelInitialSize; - VOID *KernelBuf; - UINTN SetupSize; - VOID *SetupBuf; - UINTN CommandLineSize; - CHAR8 *CommandLine; - UINTN InitrdSize; - VOID* InitrdData; - - SetupBuf = NULL; - SetupSize = 0; - KernelBuf = NULL; - KernelInitialSize = 0; - CommandLine = NULL; - CommandLineSize = 0; - InitrdData = NULL; - InitrdSize = 0; - - if (!QemuFwCfgIsAvailable ()) { - return EFI_NOT_FOUND; - } - - QemuFwCfgSelectItem (QemuFwCfgItemKernelSize); - KernelSize = (UINTN) QemuFwCfgRead64 (); - - QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupSize); - SetupSize = (UINTN) QemuFwCfgRead64 (); - - if (KernelSize == 0 || SetupSize == 0) { - DEBUG ((EFI_D_INFO, "qemu -kernel was not used.\n")); - return EFI_NOT_FOUND; - } - - SetupBuf = LoadLinuxAllocateKernelSetupPages (EFI_SIZE_TO_PAGES (SetupSize)); - if (SetupBuf == NULL) { - DEBUG ((EFI_D_ERROR, "Unable to allocate memory for kernel setup!\n")); - return EFI_OUT_OF_RESOURCES; - } - - DEBUG ((EFI_D_INFO, "Setup size: 0x%x\n", (UINT32) SetupSize)); - DEBUG ((EFI_D_INFO, "Reading kernel setup image ...")); - QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupData); - QemuFwCfgReadBytes (SetupSize, SetupBuf); - DEBUG ((EFI_D_INFO, " [done]\n")); - - Status = LoadLinuxCheckKernelSetup (SetupBuf, SetupSize); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - Status = LoadLinuxInitializeKernelSetup (SetupBuf); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - KernelInitialSize = LoadLinuxGetKernelSize (SetupBuf, KernelSize); - if (KernelInitialSize == 0) { - Status = EFI_UNSUPPORTED; - goto FreeAndReturn; - } - - KernelBuf = LoadLinuxAllocateKernelPages ( - SetupBuf, - EFI_SIZE_TO_PAGES (KernelInitialSize)); - if (KernelBuf == NULL) { - DEBUG ((EFI_D_ERROR, "Unable to allocate memory for kernel!\n")); - Status = EFI_OUT_OF_RESOURCES; - goto FreeAndReturn; - } - - DEBUG ((EFI_D_INFO, "Kernel size: 0x%x\n", (UINT32) KernelSize)); - DEBUG ((EFI_D_INFO, "Reading kernel image ...")); - QemuFwCfgSelectItem (QemuFwCfgItemKernelData); - QemuFwCfgReadBytes (KernelSize, KernelBuf); - DEBUG ((EFI_D_INFO, " [done]\n")); - - QemuFwCfgSelectItem (QemuFwCfgItemCommandLineSize); - CommandLineSize = (UINTN) QemuFwCfgRead64 (); - - if (CommandLineSize > 0) { - CommandLine = LoadLinuxAllocateCommandLinePages ( - EFI_SIZE_TO_PAGES (CommandLineSize)); - QemuFwCfgSelectItem (QemuFwCfgItemCommandLineData); - QemuFwCfgReadBytes (CommandLineSize, CommandLine); - } else { - CommandLine = NULL; - } - - Status = LoadLinuxSetCommandLine (SetupBuf, CommandLine); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - QemuFwCfgSelectItem (QemuFwCfgItemInitrdSize); - InitrdSize = (UINTN) QemuFwCfgRead64 (); - - if (InitrdSize > 0) { - InitrdData = LoadLinuxAllocateInitrdPages ( - SetupBuf, - EFI_SIZE_TO_PAGES (InitrdSize) - ); - DEBUG ((EFI_D_INFO, "Initrd size: 0x%x\n", (UINT32) InitrdSize)); - DEBUG ((EFI_D_INFO, "Reading initrd image ...")); - QemuFwCfgSelectItem (QemuFwCfgItemInitrdData); - QemuFwCfgReadBytes (InitrdSize, InitrdData); - DEBUG ((EFI_D_INFO, " [done]\n")); - } else { - InitrdData = NULL; - } - - Status = LoadLinuxSetInitrd (SetupBuf, InitrdData, InitrdSize); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; + EFI_HANDLE KernelImageHandle; + + Status = QemuLoadKernelImage (&KernelImageHandle); + if (EFI_ERROR (Status)) { + if (Status != EFI_SECURITY_VIOLATION) { + return Status; + } + // + // From the resource allocation perspective, EFI_SECURITY_VIOLATION means + // "success", so we must roll back the image loading. + // + goto UnloadKernelImage; } // - // Signal the EVT_SIGNAL_READY_TO_BOOT event + // Signal the EFI_EVENT_GROUP_READY_TO_BOOT event. // EfiSignalEventReadyToBoot(); REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT)); - Status = LoadLinux (KernelBuf, SetupBuf); + // + // Start the image. + // + Status = QemuStartKernelImage (KernelImageHandle); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "%a: StartImage(): %r\n", __FUNCTION__, Status)); + } -FreeAndReturn: - if (SetupBuf != NULL) { - FreePages (SetupBuf, EFI_SIZE_TO_PAGES (SetupSize)); - } - if (KernelBuf != NULL) { - FreePages (KernelBuf, EFI_SIZE_TO_PAGES (KernelInitialSize)); - } - if (CommandLine != NULL) { - FreePages (CommandLine, EFI_SIZE_TO_PAGES (CommandLineSize)); - } - if (InitrdData != NULL) { - FreePages (InitrdData, EFI_SIZE_TO_PAGES (InitrdSize)); - } +UnloadKernelImage: + QemuUnloadKernelImage (KernelImageHandle); return Status; } - -- 2.17.1