]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: introduce VirtioFsDxe
authorLaszlo Ersek <lersek@redhat.com>
Wed, 16 Dec 2020 21:10:38 +0000 (22:10 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 21 Dec 2020 17:16:23 +0000 (17:16 +0000)
The purpose of the driver is to ease file exchange (file sharing) between
the guest firmware and the virtualization host. The driver is supposed to
interoperate with QEMU's "virtiofsd" (Virtio Filesystem Daemon).

References:
- https://virtio-fs.gitlab.io/
- https://libvirt.org/kbase/virtiofs.html

VirtioFsDxe will bind virtio-fs devices, and produce
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on them.

In the longer term, assuming QEMU will create "bootorder" fw_cfg file
entries for virtio-fs devices, booting guest OSes from host-side
directories should become possible (dependent on the matching
QemuBootOrderLib enhancement).

Add the skeleton of the driver. Install EFI_DRIVER_BINDING_PROTOCOL with
stub member functions. Install EFI_COMPONENT_NAME2_PROTOCOL with final
member functions. This suffices for the DRIVERS command in the UEFI Shell
to list the driver with a human-readable name.

The file permission model is described immediately in the INF file as a
comment block, for future reference.

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20201216211125.19496-2-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
OvmfPkg/OvmfPkgIa32.dsc
OvmfPkg/OvmfPkgIa32.fdf
OvmfPkg/OvmfPkgIa32X64.dsc
OvmfPkg/OvmfPkgIa32X64.fdf
OvmfPkg/OvmfPkgX64.dsc
OvmfPkg/OvmfPkgX64.fdf
OvmfPkg/VirtioFsDxe/DriverBinding.c [new file with mode: 0644]
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf [new file with mode: 0644]

index 8eede796a8bdd6535869e611ca799aab18a93fec..4ff70674fb6e2dc898c88726b9b3152ea04f42b6 100644 (file)
   MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
   FatPkg/EnhancedFatDxe/Fat.inf\r
   MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf\r
+  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf\r
   MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf\r
   MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf\r
   OvmfPkg/SataControllerDxe/SataControllerDxe.inf\r
index c07b775d0a2d4f556220c8c3d391e2786483a0e2..f400c845b9c9c279d49c1a21c9b5c21dd3c1c6a6 100644 (file)
@@ -290,6 +290,7 @@ INF  MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResour
 \r
 INF  FatPkg/EnhancedFatDxe/Fat.inf\r
 INF  MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf\r
+INF  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf\r
 \r
 !if $(TOOL_CHAIN_TAG) != "XCODE5"\r
 INF  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf\r
index f9f82a48f4b925b470e38e4a30c2a22c6cf88acf..d40a59183c79f533b1c84b9547e93147b6c58c07 100644 (file)
   MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
   FatPkg/EnhancedFatDxe/Fat.inf\r
   MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf\r
+  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf\r
   MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf\r
   MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf\r
   OvmfPkg/SataControllerDxe/SataControllerDxe.inf\r
index 9adf1525c13548be70945e4e58709c2de9fc54f0..d055552fd09fd6ba60f5a2175c8f6726c2930cbf 100644 (file)
@@ -291,6 +291,7 @@ INF  MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResour
 \r
 INF  FatPkg/EnhancedFatDxe/Fat.inf\r
 INF  MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf\r
+INF  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf\r
 \r
 !if $(TOOL_CHAIN_TAG) != "XCODE5"\r
 INF  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf\r
index e59ae05b73aa77027f99a366569d78dc58dedfa7..ec7886235acf33ff1eac2496f84ab8eb42770e45 100644 (file)
   MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
   FatPkg/EnhancedFatDxe/Fat.inf\r
   MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf\r
+  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf\r
   MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf\r
   MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf\r
   OvmfPkg/SataControllerDxe/SataControllerDxe.inf\r
index 17ba9e177ac32d67185c7c86243595b32e15f546..1a2ef5bf2ae3d72549618823c9e9ba00e0435d1c 100644 (file)
@@ -300,6 +300,7 @@ INF  MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResour
 \r
 INF  FatPkg/EnhancedFatDxe/Fat.inf\r
 INF  MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf\r
+INF  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf\r
 \r
 !if $(TOOL_CHAIN_TAG) != "XCODE5"\r
 INF  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf\r
diff --git a/OvmfPkg/VirtioFsDxe/DriverBinding.c b/OvmfPkg/VirtioFsDxe/DriverBinding.c
new file mode 100644 (file)
index 0000000..ac0a633
--- /dev/null
@@ -0,0 +1,112 @@
+/** @file\r
+  Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices.\r
+\r
+  Copyright (C) 2020, Red Hat, Inc.\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#include <Library/BaseLib.h>                  // AsciiStrCmp()\r
+#include <Library/UefiBootServicesTableLib.h> // gBS\r
+#include <Protocol/ComponentName2.h>          // EFI_COMPONENT_NAME2_PROTOCOL\r
+#include <Protocol/DriverBinding.h>           // EFI_DRIVER_BINDING_PROTOCOL\r
+\r
+//\r
+// UEFI Driver Model protocol instances.\r
+//\r
+STATIC EFI_DRIVER_BINDING_PROTOCOL  mDriverBinding;\r
+STATIC EFI_COMPONENT_NAME2_PROTOCOL mComponentName2;\r
+\r
+//\r
+// UEFI Driver Model protocol member functions.\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioFsBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+  IN EFI_HANDLE                  ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL    *RemainingDevicePath OPTIONAL\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioFsBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+  IN EFI_HANDLE                  ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL    *RemainingDevicePath OPTIONAL\r
+  )\r
+{\r
+  return EFI_DEVICE_ERROR;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioFsBindingStop (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+  IN EFI_HANDLE                  ControllerHandle,\r
+  IN UINTN                       NumberOfChildren,\r
+  IN EFI_HANDLE                  *ChildHandleBuffer OPTIONAL\r
+  )\r
+{\r
+  return EFI_DEVICE_ERROR;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioFsGetDriverName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  if (AsciiStrCmp (Language, "en") != 0) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  *DriverName = L"Virtio Filesystem Driver";\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioFsGetControllerName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_HANDLE                   ChildHandle OPTIONAL,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **ControllerName\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+//\r
+// Entry point of this driver.\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioFsEntryPoint (\r
+  IN EFI_HANDLE       ImageHandle,\r
+  IN EFI_SYSTEM_TABLE *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  mDriverBinding.Supported           = VirtioFsBindingSupported;\r
+  mDriverBinding.Start               = VirtioFsBindingStart;\r
+  mDriverBinding.Stop                = VirtioFsBindingStop;\r
+  mDriverBinding.Version             = 0x10;\r
+  mDriverBinding.ImageHandle         = ImageHandle;\r
+  mDriverBinding.DriverBindingHandle = ImageHandle;\r
+\r
+  mComponentName2.GetDriverName      = VirtioFsGetDriverName;\r
+  mComponentName2.GetControllerName  = VirtioFsGetControllerName;\r
+  mComponentName2.SupportedLanguages = "en";\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (&ImageHandle,\r
+                  &gEfiDriverBindingProtocolGuid, &mDriverBinding,\r
+                  &gEfiComponentName2ProtocolGuid, &mComponentName2, NULL);\r
+  return Status;\r
+}\r
diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf
new file mode 100644 (file)
index 0000000..69cb44b
--- /dev/null
@@ -0,0 +1,92 @@
+## @file\r
+# Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices.\r
+#\r
+# Copyright (C) 2020, Red Hat, Inc.\r
+#\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+#\r
+# Permission Model of this driver:\r
+#\r
+# Regardless of the UID and GID values this driver send in the FUSE request\r
+# header, the daemon (that is, the Virtio Filesystem device) always acts with\r
+# root privileges on the host side. The only time the daemon considers said UID\r
+# and GID fields is when creating a new file or directory. Thus, the guest\r
+# driver cannot rely on the host for enforcing any file mode permissions,\r
+# regardless of the "personality" that the guest driver poses as, because\r
+# "root" on the host side ignores all file mode bits.\r
+#\r
+# Therefore the guest driver has to do its own permission checking, and use the\r
+# host-side file mode bits only as a kind of "metadata storage" or "reminder"\r
+# -- hopefully in a way that makes some sense on the host side too.\r
+#\r
+# The complete mapping between the EFI_FILE_PROTOCOL and the host-side file\r
+# mode bits is described below.\r
+#\r
+# - The guest driver poses as UID 0, GID 0, PID 1.\r
+#\r
+# - If and only if all "w" bits are missing from a file on the host side, then\r
+#   the file or directory is reported as EFI_FILE_READ_ONLY in the guest. When\r
+#   setting EFI_FILE_READ_ONLY in the guest, all "w" bits (0222) are cleared on\r
+#   the host; when clearing EFI_FILE_READ_ONLY in the guest, all "w" bits are\r
+#   set on the host. Viewed from the host side, this sort of reflects that an\r
+#   EFI_FILE_READ_ONLY file should not be written by anyone.\r
+#\r
+# - The attributes EFI_FILE_HIDDEN, EFI_FILE_SYSTEM, EFI_FILE_RESERVED, and\r
+#   EFI_FILE_ARCHIVE are never reported in the guest, and they are silently\r
+#   ignored when a SetInfo() call or a file-creating Open() call requests them.\r
+#\r
+# - On the host, files are created with 0666 file mode bits, directories are\r
+#   created with 0777 file mode bits.\r
+#\r
+# - In the guest, the EFI_FILE_READ_ONLY attribute only controls the permitted\r
+#   open mode. In particular, on directories, the EFI_FILE_READ_ONLY attribute\r
+#   does not prevent the creation or deletion of entries inside the directory;\r
+#   EFI_FILE_READ_ONLY only prevents the renaming, deleting, flushing (syncing)\r
+#   and touching of the directory itself (with "touching" meaning updating the\r
+#   timestamps). The fact that EFI_FILE_READ_ONLY being set on a directory is\r
+#   irrelevant in the guest with regard to entry creation/deletion, is\r
+#   well-mirrored by the fact that virtiofsd -- which runs as root, regardless\r
+#   of guest driver personality -- ignores the absence of "w" permissions on a\r
+#   host-side directory, when creating or removing entries in it.\r
+#\r
+# - When an EFI_FILE_PROTOCOL is opened read-only, then the Delete(), Write()\r
+#   and Flush() member functions are disabled for it. Additionally, SetInfo()\r
+#   is restricted to flipping the EFI_FILE_READ_ONLY bit (which takes effect at\r
+#   the next Open()).\r
+#\r
+# - As a consequence of the above, for deleting a directory, it must be\r
+#   presented in the guest as openable for writing.\r
+#\r
+# - We diverge from the UEFI spec, and permit Flush() on a directory that has\r
+#   been opened read-write; otherwise the only way to invoke FUSE_FSYNCDIR on a\r
+#   directory would be to Close() it.\r
+#\r
+# - OpenVolume() opens the root directory for read-only access. The Open()\r
+#   member function may open it for read-write access. While the root directory\r
+#   cannot be renamed or deleted, opening it for read-write access is useful\r
+#   for calling Flush(), according to the previous paragraph, or for updating\r
+#   the root directory's timestamps with SetInfo().\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                           = 1.29\r
+  BASE_NAME                             = VirtioFsDxe\r
+  FILE_GUID                             = 7BD9DDF7-8B83-488E-AEC9-24C78610289C\r
+  MODULE_TYPE                           = UEFI_DRIVER\r
+  ENTRY_POINT                           = VirtioFsEntryPoint\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+[Sources]\r
+  DriverBinding.c\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+\r
+[Protocols]\r
+  gEfiComponentName2ProtocolGuid        ## PRODUCES\r
+  gEfiDriverBindingProtocolGuid         ## PRODUCES\r