From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.158.5]) by mx.groups.io with SMTP id smtpd.web08.6762.1623932234883079693 for ; Thu, 17 Jun 2021 05:17:15 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=DlFOLfjk; spf=pass (domain: linux.ibm.com, ip: 148.163.158.5, mailfrom: dovmurik@linux.ibm.com) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15HC4Ln1071801; Thu, 17 Jun 2021 08:17:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=wKTwpCeZNnxCw+j+sFfurxJNizF5KMZTOxJNzhfq+hM=; b=DlFOLfjkYsSEeOItRJx+7gY68H6LD2Qyuey62m3j3O6Bz8uuGtloca6uWobYcQYfLEOn FDt0MNOSjJYaiMJ/co5T7T5ksWL+yaYslqxs6khEwqB5eFkSB9dpHKxPB7KDGL5B/Xzh HFX0yFFvxYre55Ui9w0zwOWwJquLmXojCwHjWGFweEaNv0VEz8RkQrycH5iP6o/dz5xc 8fYaBydrvgU2B3DWJD0ppn7gZqWP8nuohZfgDMEjr7vtOt7NWOaMsWMmZ0XV8+mGAshV XU6KWs5KHIXEjGhOvZ1cVyUd7KyN/red80fd+Pn4ADN5zBeGB7RSoqp4rEydPyHUK0Jq UA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3985cj1sqh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 17 Jun 2021 08:17:13 -0400 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 15HC5BRi075951; Thu, 17 Jun 2021 08:17:13 -0400 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0b-001b2d01.pphosted.com with ESMTP id 3985cj1sq0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 17 Jun 2021 08:17:13 -0400 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 15HCCCRV004543; Thu, 17 Jun 2021 12:17:11 GMT Received: from b03cxnp07027.gho.boulder.ibm.com (b03cxnp07027.gho.boulder.ibm.com [9.17.130.14]) by ppma02dal.us.ibm.com with ESMTP id 394mjaamde-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 17 Jun 2021 12:17:11 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 15HCHA5p24248774 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Jun 2021 12:17:10 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3CD33C605F; Thu, 17 Jun 2021 12:17:10 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BFA09C605D; Thu, 17 Jun 2021 12:17:09 +0000 (GMT) Received: from localhost.localdomain (unknown [9.2.130.16]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 17 Jun 2021 12:17:09 +0000 (GMT) From: "Dov Murik" To: devel@edk2.groups.io Cc: Dov Murik , Laszlo Ersek , Ard Biesheuvel , Jordan Justen , James Bottomley , Tobin Feldman-Fitzthum Subject: [PATCH v2 2/3] OvmfPkg/GenericQemuLoadImageLib: Read cmdline from QemuKernelLoaderFs Date: Thu, 17 Jun 2021 12:16:59 +0000 Message-Id: <20210617121700.2883073-3-dovmurik@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617121700.2883073-1-dovmurik@linux.ibm.com> References: <20210617121700.2883073-1-dovmurik@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: rCnKQpi5E3H_5zh6Cz_tC8e_qFiztkEH X-Proofpoint-ORIG-GUID: lI2JZPIgWxU9DfWwL4QHX2KZ2Y8Vnu0w X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-06-17_05:2021-06-15,2021-06-17 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 clxscore=1015 priorityscore=1501 adultscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 malwarescore=0 impostorscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106170079 Content-Transfer-Encoding: quoted-printable Remove the QemuFwCfgLib interface used to read the QEMU cmdline (-append argument) and the initrd size. Instead, use the synthetic filesystem QemuKernelLoaderFs which has three files: "kernel", "initrd", and "cmdline". Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Jordan Justen Cc: James Bottomley Cc: Tobin Feldman-Fitzthum Signed-off-by: Dov Murik --- OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.inf | 2 = +- OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c | 145 = ++++++++++++++++++-- 2 files changed, 133 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLi= b.inf b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.inf index b262cb926a4d..f462fd6922cf 100644 --- a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.inf +++ b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.inf @@ -27,12 +27,12 @@ [LibraryClasses] DebugLib=0D MemoryAllocationLib=0D PrintLib=0D - QemuFwCfgLib=0D UefiBootServicesTableLib=0D =0D [Protocols]=0D gEfiDevicePathProtocolGuid=0D gEfiLoadedImageProtocolGuid=0D + gEfiSimpleFileSystemProtocolGuid=0D =0D [Guids]=0D gQemuKernelLoaderFsMediaGuid=0D diff --git a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLi= b.c b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c index 114db7e8441f..f520456e3b24 100644 --- a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c +++ b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c @@ -11,9 +11,9 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D -#include =0D #include =0D #include =0D #include =0D @@ -30,6 +30,11 @@ typedef struct { KERNEL_FILE_DEVPATH FileNode;=0D EFI_DEVICE_PATH_PROTOCOL EndNode;=0D } KERNEL_VENMEDIA_FILE_DEVPATH;=0D +=0D +typedef struct {=0D + VENDOR_DEVICE_PATH VenMediaNode;=0D + EFI_DEVICE_PATH_PROTOCOL EndNode;=0D +} SINGLE_VENMEDIA_NODE_DEVPATH;=0D #pragma pack ()=0D =0D STATIC CONST KERNEL_VENMEDIA_FILE_DEVPATH mKernelDevicePath =3D {=0D @@ -51,6 +56,78 @@ STATIC CONST KERNEL_VENMEDIA_FILE_DEVPATH mKernelDeviceP= ath =3D { }=0D };=0D =0D +STATIC CONST SINGLE_VENMEDIA_NODE_DEVPATH mQemuKernelLoaderFileSystemDevic= ePath =3D {=0D + {=0D + {=0D + MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP,=0D + { sizeof (VENDOR_DEVICE_PATH) }=0D + },=0D + QEMU_KERNEL_LOADER_FS_MEDIA_GUID=0D + }, {=0D + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,=0D + { sizeof (EFI_DEVICE_PATH_PROTOCOL) }=0D + }=0D +};=0D +=0D +STATIC=0D +EFI_STATUS=0D +GetQemuKernelLoaderBlobSize (=0D + IN EFI_FILE_HANDLE Root,=0D + IN CHAR16 *FileName,=0D + OUT UINTN *Size=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_FILE_HANDLE FileHandle;=0D + UINT64 FileSize;=0D +=0D + Status =3D Root->Open (Root, &FileHandle, FileName, EFI_FILE_MODE_READ, = 0);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D + Status =3D FileHandleGetSize (FileHandle, &FileSize);=0D + if (EFI_ERROR (Status)) {=0D + goto CloseFile;=0D + }=0D + *Size =3D FileSize;=0D + Status =3D EFI_SUCCESS;=0D +CloseFile:=0D + FileHandle->Close (FileHandle);=0D + return Status;=0D +}=0D +=0D +STATIC=0D +EFI_STATUS=0D +ReadWholeQemuKernelLoaderBlob (=0D + IN EFI_FILE_HANDLE Root,=0D + IN CHAR16 *FileName,=0D + IN UINTN Size,=0D + OUT VOID *Buffer=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_FILE_HANDLE FileHandle;=0D + UINTN ReadSize;=0D +=0D + Status =3D Root->Open (Root, &FileHandle, FileName, EFI_FILE_MODE_READ, = 0);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D + ReadSize =3D Size;=0D + Status =3D FileHandle->Read (FileHandle, &ReadSize, Buffer);=0D + if (EFI_ERROR (Status)) {=0D + goto CloseFile;=0D + }=0D + if (ReadSize !=3D Size) {=0D + Status =3D EFI_PROTOCOL_ERROR;=0D + goto CloseFile;=0D + }=0D + Status =3D EFI_SUCCESS;=0D +CloseFile:=0D + FileHandle->Close (FileHandle);=0D + return Status;=0D +}=0D +=0D /**=0D Download the kernel, the initial ramdisk, and the kernel command line fr= om=0D QEMU's fw_cfg. The kernel will be instructed via its command line to loa= d=0D @@ -76,12 +153,16 @@ QemuLoadKernelImage ( OUT EFI_HANDLE *ImageHandle=0D )=0D {=0D - EFI_STATUS Status;=0D - EFI_HANDLE KernelImageHandle;=0D - EFI_LOADED_IMAGE_PROTOCOL *KernelLoadedImage;=0D - UINTN CommandLineSize;=0D - CHAR8 *CommandLine;=0D - UINTN InitrdSize;=0D + EFI_STATUS Status;=0D + EFI_HANDLE KernelImageHandle;=0D + EFI_LOADED_IMAGE_PROTOCOL *KernelLoadedImage;=0D + EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;=0D + EFI_HANDLE FsVolumeHandle;=0D + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FsProtocol;=0D + EFI_FILE_HANDLE Root;=0D + UINTN CommandLineSize;=0D + CHAR8 *CommandLine;=0D + UINTN InitrdSize;=0D =0D //=0D // Load the image. This should call back into the QEMU EFI loader file s= ystem.=0D @@ -124,8 +205,38 @@ QemuLoadKernelImage ( );=0D ASSERT_EFI_ERROR (Status);=0D =0D - QemuFwCfgSelectItem (QemuFwCfgItemCommandLineSize);=0D - CommandLineSize =3D (UINTN)QemuFwCfgRead32 ();=0D + //=0D + // Open the Qemu Kernel Loader abstract filesystem (volume) which will b= e=0D + // used to read the "initrd" and "cmdline" synthetic files.=0D + //=0D + DevicePathNode =3D (EFI_DEVICE_PATH_PROTOCOL *)&mQemuKernelLoaderFileSys= temDevicePath;=0D + Status =3D gBS->LocateDevicePath (=0D + &gEfiSimpleFileSystemProtocolGuid,=0D + &DevicePathNode,=0D + &FsVolumeHandle=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + Status =3D gBS->HandleProtocol (=0D + FsVolumeHandle,=0D + &gEfiSimpleFileSystemProtocolGuid,=0D + (VOID **)&FsProtocol=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + Status =3D FsProtocol->OpenVolume (FsVolumeHandle, &Root);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + Status =3D GetQemuKernelLoaderBlobSize (Root, L"cmdline", &CommandLineSi= ze);=0D + if (EFI_ERROR (Status)) {=0D + goto CloseRoot;=0D + }=0D =0D if (CommandLineSize =3D=3D 0) {=0D KernelLoadedImage->LoadOptionsSize =3D 0;=0D @@ -136,8 +247,11 @@ QemuLoadKernelImage ( goto UnloadImage;=0D }=0D =0D - QemuFwCfgSelectItem (QemuFwCfgItemCommandLineData);=0D - QemuFwCfgReadBytes (CommandLineSize, CommandLine);=0D + Status =3D ReadWholeQemuKernelLoaderBlob (Root, L"cmdline", CommandLin= eSize,=0D + CommandLine);=0D + if (EFI_ERROR (Status)) {=0D + goto FreeCommandLine;=0D + }=0D =0D //=0D // Verify NUL-termination of the command line.=0D @@ -155,8 +269,10 @@ QemuLoadKernelImage ( KernelLoadedImage->LoadOptionsSize =3D (UINT32)((CommandLineSize - 1) = * 2);=0D }=0D =0D - QemuFwCfgSelectItem (QemuFwCfgItemInitrdSize);=0D - InitrdSize =3D (UINTN)QemuFwCfgRead32 ();=0D + Status =3D GetQemuKernelLoaderBlobSize (Root, L"initrd", &InitrdSize);=0D + if (EFI_ERROR (Status)) {=0D + goto FreeCommandLine;=0D + }=0D =0D if (InitrdSize > 0) {=0D //=0D @@ -193,6 +309,7 @@ QemuLoadKernelImage ( }=0D =0D *ImageHandle =3D KernelImageHandle;=0D + Root->Close (Root);=0D return EFI_SUCCESS;=0D =0D FreeCommandLine:=0D @@ -201,6 +318,8 @@ FreeCommandLine: }=0D UnloadImage:=0D gBS->UnloadImage (KernelImageHandle);=0D +CloseRoot:=0D + Root->Close (Root);=0D =0D return Status;=0D }=0D --=20 2.25.1