ArmVirtPkg, OvmfPkg: virtio filesystem driver
cover ArmVirtPkg, OvmfPkg: virtio filesystem driver
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097 Repo: https://pagure.io/lersek/edk2.git Branch: virtio-fs (@ b8fd76d649d2)
The first commit and the bugzilla ticket state the use case.
References, including setup instructions:
- https://libvirt.org/kbase/virtiofs.html
- https://virtio-fs.gitlab.io/
Useful UEFI shell commands for testing: output redirections, attrib, connect, cp, disconnect, edit, eficompress, efidecompress, hexedit, ls, map, mkdir, mv, rm, setsize, timezone, touch, type, vol.
The series is largely structured as follows:
- helper functions and FUSE command wrappers are implemented as required by the next EFI_FILE_PROTOCOL interface,
- said EFI_FILE_PROTOCOL interface is implemented,
- lather, rinse, repeat.
Thanks,
Laszlo
Laszlo Ersek (48):
OvmfPkg: introduce VirtioFsDxe
ArmVirtPkg: include VirtioFsDxe in the ArmVirtQemu* platforms OvmfPkg/VirtioFsDxe: DriverBinding: open VirtioDevice, install
SimpleFs
OvmfPkg/VirtioFsDxe: implement virtio device (un)initialization OvmfPkg/VirtioFsDxe: add a scatter-gather list data type OvmfPkg/VirtioFsDxe: introduce the basic FUSE request/response headers OvmfPkg/VirtioFsDxe: map "errno" values to EFI_STATUS OvmfPkg/VirtioFsDxe: submit the FUSE_INIT request to the device OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_OPENDIR OvmfPkg/VirtioFsDxe: add shared wrapper for FUSE_RELEASE /
FUSE_RELEASEDIR
OvmfPkg/VirtioFsDxe: implement
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume()
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_FORGET OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_FSYNC /
FUSE_FSYNCDIR
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_FLUSH OvmfPkg/VirtioFsDxe: flush, sync, release and forget in Close() /
Delete()
OvmfPkg/VirtioFsDxe: add helper for appending and sanitizing paths OvmfPkg/VirtioFsDxe: manage path lifecycle in OpenVolume, Close,
Delete
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_OPEN OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_MKDIR OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_CREATE OvmfPkg/VirtioFsDxe: convert FUSE inode attributes to EFI_FILE_INFO OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_LOOKUP OvmfPkg/VirtioFsDxe: split canon. path into last parent + last
component
OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_UNLINK / FUSE_RMDIR OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_GETATTR OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Open() OvmfPkg/VirtioFsDxe: erase the dir. entry in
EFI_FILE_PROTOCOL.Delete()
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_STATFS OvmfPkg/VirtioFsDxe: add helper for formatting UEFI basenames OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.GetInfo() OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.GetPosition,
.SetPosition
OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_READ /
FUSE_READDIRPLUS
OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Read() for regular
files
OvmfPkg/VirtioFsDxe: convert FUSE dirent filename to EFI_FILE_INFO OvmfPkg/VirtioFsDxe: add EFI_FILE_INFO cache fields to VIRTIO_FS_FILE OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Read() for
directories
OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Flush() OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_WRITE OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Write() OvmfPkg/VirtioFsDxe: handle the volume label in
EFI_FILE_PROTOCOL.SetInfo
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_RENAME2 OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination
path
OvmfPkg/VirtioFsDxe: handle file rename/move in
EFI_FILE_PROTOCOL.SetInfo
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_SETATTR OvmfPkg/VirtioFsDxe: add helper for determining file size update OvmfPkg/VirtioFsDxe: add helper for determining access time updates OvmfPkg/VirtioFsDxe: add helper for determining file mode bits update OvmfPkg/VirtioFsDxe: handle attribute updates in
EFI_FILE_PROTOCOL.SetInfo
ArmVirtPkg/ArmVirtQemu.dsc | 3 +- ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 3 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 3 +- OvmfPkg/Include/IndustryStandard/Virtio10.h | 5 + OvmfPkg/Include/IndustryStandard/VirtioFs.h | 454 ++++ OvmfPkg/OvmfPkgIa32.dsc | 2 + OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 2 + OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.dsc | 2 + OvmfPkg/OvmfPkgX64.fdf | 1 + OvmfPkg/VirtioFsDxe/DriverBinding.c | 232 ++ OvmfPkg/VirtioFsDxe/FuseFlush.c | 111 + OvmfPkg/VirtioFsDxe/FuseForget.c | 85 + OvmfPkg/VirtioFsDxe/FuseFsync.c | 121 + OvmfPkg/VirtioFsDxe/FuseGetAttr.c | 116 + OvmfPkg/VirtioFsDxe/FuseInit.c | 142 ++ OvmfPkg/VirtioFsDxe/FuseLookup.c | 148 ++ OvmfPkg/VirtioFsDxe/FuseMkDir.c | 134 ++ OvmfPkg/VirtioFsDxe/FuseOpen.c | 126 + OvmfPkg/VirtioFsDxe/FuseOpenDir.c | 120 + OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c | 155 ++ OvmfPkg/VirtioFsDxe/FuseRead.c | 191 ++ OvmfPkg/VirtioFsDxe/FuseRelease.c | 121 + OvmfPkg/VirtioFsDxe/FuseRename.c | 131 ++ OvmfPkg/VirtioFsDxe/FuseSetAttr.c | 174 ++ OvmfPkg/VirtioFsDxe/FuseStatFs.c | 102 + OvmfPkg/VirtioFsDxe/FuseUnlink.c | 114 + OvmfPkg/VirtioFsDxe/FuseWrite.c | 155 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 2416 ++++++++++++++++++++ OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 68 + OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 110 + OvmfPkg/VirtioFsDxe/SimpleFsFlush.c | 42 + OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c | 209 ++ OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c | 27 + OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 505 ++++ OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 98 + OvmfPkg/VirtioFsDxe/SimpleFsRead.c | 434 ++++ OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c | 582 +++++ OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c | 67 + OvmfPkg/VirtioFsDxe/SimpleFsWrite.c | 81 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 544 +++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 136 ++ 43 files changed, 8271 insertions(+), 3 deletions(-) create mode 100644 OvmfPkg/Include/IndustryStandard/VirtioFs.h create mode 100644 OvmfPkg/VirtioFsDxe/DriverBinding.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseFlush.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseForget.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseFsync.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseGetAttr.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseInit.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseLookup.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseMkDir.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseOpen.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseOpenDir.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseRead.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseRelease.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseRename.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseSetAttr.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseStatFs.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseUnlink.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseWrite.c create mode 100644 OvmfPkg/VirtioFsDxe/Helpers.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsClose.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsDelete.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsFlush.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsOpen.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsRead.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsWrite.c create mode 100644 OvmfPkg/VirtioFsDxe/VirtioFsDxe.h create mode 100644 OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf
base-commit: e6ae24e1d676bb2bdc0fc715b49b04908f41fc10
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 1/48 OvmfPkg: introduce VirtioFsDxe
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 <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.fdf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 92 ++++++++++++++++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 112 ++++++++++++++++++++ 8 files changed, 210 insertions(+)
OvmfPkg/OvmfPkgIa32.dsc +1 -0
@@ -807,16 +807,17 @@ [Components] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
OvmfPkg/OvmfPkgIa32X64.dsc +1 -0
@@ -821,16 +821,17 @@ [Components.X64] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
OvmfPkg/OvmfPkgX64.dsc +1 -0
@@ -817,16 +817,17 @@ [Components] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
OvmfPkg/OvmfPkgIa32.fdf +1 -0
@@ -285,16 +285,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf !if $(TOOL_CHAIN_TAG) != "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf !endif INF ShellPkg/Application/Shell/Shell.inf
OvmfPkg/OvmfPkgIa32X64.fdf +1 -0
@@ -286,16 +286,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf !if $(TOOL_CHAIN_TAG) != "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf !endif INF ShellPkg/Application/Shell/Shell.inf
OvmfPkg/OvmfPkgX64.fdf +1 -0
@@ -295,16 +295,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf !if $(TOOL_CHAIN_TAG) != "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf !endif INF ShellPkg/Application/Shell/Shell.inf
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf new file +92 -0
92 lines not on this page · raw message
OvmfPkg/VirtioFsDxe/DriverBinding.c new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
Re: [Virtio-fs] [edk2 PATCH 01/48] OvmfPkg: introduce VirtioFsDxe
Quoted 190 lines · Laszlo Ersek
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.htmlVirtioFsDxe will bind virtio-fs devices, and produce
EFI_SIMPLE_FILE_SYSTEM_PROTOCOLinstances on them.In the longer term, assuming QEMU will create "bootorder"
fw_cfgfile 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_PROTOCOLwith stub member functions. InstallEFI_COMPONENT_NAME2_PROTOCOLwith 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 <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097Signed-off-by Laszlo Ersek <[email protected]>--- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.fdf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 92 ++++++++++++++++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 112 ++++++++++++++++++++ 8 files changed, 210 insertions(+)OvmfPkg/OvmfPkgIa32.dsc +1
-0@@ -807,16 +807,17 @@ [Components] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.infOvmfPkg/OvmfPkgIa32X64.dsc +1
-0@@ -821,16 +821,17 @@ [Components.X64] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.infOvmfPkg/OvmfPkgX64.dsc +1
-0@@ -817,16 +817,17 @@ [Components] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.infOvmfPkg/OvmfPkgIa32.fdf +1
-0@@ -285,16 +285,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf !if $(TOOL_CHAIN_TAG) != "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf !endif INF ShellPkg/Application/Shell/Shell.infOvmfPkg/OvmfPkgIa32X64.fdf +1
-0@@ -286,16 +286,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf !if $(TOOL_CHAIN_TAG) != "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf !endif INF ShellPkg/Application/Shell/Shell.infOvmfPkg/OvmfPkgX64.fdf +1
-0@@ -295,16 +295,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf !if $(TOOL_CHAIN_TAG) != "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf !endif INF ShellPkg/Application/Shell/Shell.infOvmfPkg/VirtioFsDxe/VirtioFsDxe.inf new file +12
-0@@ -0,0 +1,92 @@ +## @file +# Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices. +# +# Copyright (C) 2020, Red Hat, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +# Permission Model of this driver: +# +# Regardless of the UID and GID values this driver send in the FUSE request +# header, the daemon (that is, the Virtio Filesystem device) always acts with
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf line 22
Quoted 10 lines
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf new file +10
-0+# root privileges on the host side. The only time the daemon considers said UID +# and GID fields is when creating a new file or directory. Thus, the guest +# driver cannot rely on the host for enforcing any file mode permissions, +# regardless of the "personality" that the guest driver poses as, because +# "root" on the host side ignores all file mode bits. +# +# Therefore the guest driver has to do its own permission checking, and use the +# host-side file mode bits only as a kind of "metadata storage" or "reminder" +# -- hopefully in a way that makes some sense on the host side too. +#
Can you please explain why this is safe? Or should virtio-fs only be used with guests that can be trusted with root privileges on the host?
Signature · 1 line
Ard.
Quoted 189 lines
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf new file +70
-0+# The complete mapping between the EFI_FILE_PROTOCOL and the host-side file +# mode bits is described below. +# +# - The guest driver poses as UID 0, GID 0, PID 1. +# +# - If and only if all "w" bits are missing from a file on the host side, then +# the file or directory is reported as EFI_FILE_READ_ONLY in the guest. When +# setting EFI_FILE_READ_ONLY in the guest, all "w" bits (0222) are cleared on +# the host; when clearing EFI_FILE_READ_ONLY in the guest, all "w" bits are +# set on the host. Viewed from the host side, this sort of reflects that an +# EFI_FILE_READ_ONLY file should not be written by anyone. +# +# - The attributes EFI_FILE_HIDDEN, EFI_FILE_SYSTEM, EFI_FILE_RESERVED, and +# EFI_FILE_ARCHIVE are never reported in the guest, and they are silently +# ignored when a SetInfo() call or a file-creating Open() call requests them. +# +# - On the host, files are created with 0666 file mode bits, directories are +# created with 0777 file mode bits. +# +# - In the guest, the EFI_FILE_READ_ONLY attribute only controls the permitted +# open mode. In particular, on directories, the EFI_FILE_READ_ONLY attribute +# does not prevent the creation or deletion of entries inside the directory; +# EFI_FILE_READ_ONLY only prevents the renaming, deleting, flushing (syncing) +# and touching of the directory itself (with "touching" meaning updating the +# timestamps). The fact that EFI_FILE_READ_ONLY being set on a directory is +# irrelevant in the guest with regard to entry creation/deletion, is +# well-mirrored by the fact that virtiofsd -- which runs as root, regardless +# of guest driver personality -- ignores the absence of "w" permissions on a +# host-side directory, when creating or removing entries in it. +# +# - When an EFI_FILE_PROTOCOL is opened read-only, then the Delete(), Write() +# and Flush() member functions are disabled for it. Additionally, SetInfo() +# is restricted to flipping the EFI_FILE_READ_ONLY bit (which takes effect at +# the next Open()). +# +# - As a consequence of the above, for deleting a directory, it must be +# presented in the guest as openable for writing. +# +# - We diverge from the UEFI spec, and permit Flush() on a directory that has +# been opened read-write; otherwise the only way to invoke FUSE_FSYNCDIR on a +# directory would be to Close() it. +# +# - OpenVolume() opens the root directory for read-only access. The Open() +# member function may open it for read-write access. While the root directory +# cannot be renamed or deleted, opening it for read-write access is useful +# for calling Flush(), according to the previous paragraph, or for updating +# the root directory's timestamps with SetInfo(). +## + +[Defines] + INF_VERSION = 1.29 + BASE_NAME = VirtioFsDxe + FILE_GUID = 7BD9DDF7-8B83-488E-AEC9-24C78610289C + MODULE_TYPE = UEFI_DRIVER + ENTRY_POINT = VirtioFsEntryPoint + +[Packages] + MdePkg/MdePkg.dec + +[Sources] + DriverBinding.c + +[LibraryClasses] + BaseLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEfiComponentName2ProtocolGuid ## PRODUCES + gEfiDriverBindingProtocolGuid ## PRODUCESOvmfPkg/VirtioFsDxe/DriverBinding.c new file +112
-0@@ -0,0 +1,112 @@ +/** @file +Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Library/BaseLib.h> // AsciiStrCmp() +#include <Library/UefiBootServicesTableLib.h> // gBS +#include <Protocol/ComponentName2.h> // EFI_COMPONENT_NAME2_PROTOCOL +#include <Protocol/DriverBinding.h> // EFI_DRIVER_BINDING_PROTOCOL + +// +// UEFI Driver Model protocol instances. +// +STATIC EFI_DRIVER_BINDING_PROTOCOL mDriverBinding; +STATIC EFI_COMPONENT_NAME2_PROTOCOL mComponentName2; + +// +// UEFI Driver Model protocol member functions. +// +EFI_STATUS +EFIAPI +VirtioFsBindingSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ +return EFI_UNSUPPORTED ; +} + +EFI_STATUS +EFIAPI +VirtioFsBindingStart ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ +return EFI_DEVICE_ERROR ; +} + +EFI_STATUS +EFIAPI +VirtioFsBindingStop ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer OPTIONAL + ) +{ +return EFI_DEVICE_ERROR ; +} + +EFI_STATUS +EFIAPI +VirtioFsGetDriverName ( + IN EFI_COMPONENT_NAME2_PROTOCOL *This, + IN CHAR8 *Language, + OUT CHAR16 **DriverName + ) +{ +if (AsciiStrCmp (Language,"en" ) !=0 ) { +return EFI_UNSUPPORTED ; + } + *DriverName =L"Virtio Filesystem Driver" ; +return EFI_SUCCESS ; +} + +EFI_STATUS +EFIAPI +VirtioFsGetControllerName ( + IN EFI_COMPONENT_NAME2_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE ChildHandle OPTIONAL, + IN CHAR8 *Language, + OUT CHAR16 **ControllerName + ) +{ +return EFI_UNSUPPORTED ; +} + +// +// Entry point of this driver. +// +EFI_STATUS +EFIAPI +VirtioFsEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ +EFI_STATUS Status; + + mDriverBinding.Supported = VirtioFsBindingSupported; + mDriverBinding.Start = VirtioFsBindingStart; + mDriverBinding.Stop = VirtioFsBindingStop; + mDriverBinding.Version =0x10 ; + mDriverBinding.ImageHandle = ImageHandle; + mDriverBinding.DriverBindingHandle = ImageHandle; + + mComponentName2.GetDriverName = VirtioFsGetDriverName; + mComponentName2.GetControllerName = VirtioFsGetControllerName; + mComponentName2.SupportedLanguages ="en" ; + + Status = gBS->InstallMultipleProtocolInterfaces (&ImageHandle, + &gEfiDriverBindingProtocolGuid, &mDriverBinding, + &gEfiComponentName2ProtocolGuid, &mComponentName2,NULL ); +return Status; +}
Re: [Virtio-fs] [edk2 PATCH 01/48] OvmfPkg: introduce VirtioFsDxe
Quoted 196 lines · * Ard Biesheuvel ([email protected]) wrote:
Quoted 195 lines · Laszlo Ersek
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.htmlVirtioFsDxe will bind virtio-fs devices, and produce
EFI_SIMPLE_FILE_SYSTEM_PROTOCOLinstances on them.In the longer term, assuming QEMU will create "bootorder"
fw_cfgfile 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_PROTOCOLwith stub member functions. InstallEFI_COMPONENT_NAME2_PROTOCOLwith 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 <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097Signed-off-by Laszlo Ersek <[email protected]>--- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.fdf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 92 ++++++++++++++++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 112 ++++++++++++++++++++ 8 files changed, 210 insertions(+)OvmfPkg/OvmfPkgIa32.dsc +1
-0@@ -807,16 +807,17 @@ [Components] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.infOvmfPkg/OvmfPkgIa32X64.dsc +1
-0@@ -821,16 +821,17 @@ [Components.X64] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.infOvmfPkg/OvmfPkgX64.dsc +1
-0@@ -817,16 +817,17 @@ [Components] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.infOvmfPkg/OvmfPkgIa32.fdf +1
-0@@ -285,16 +285,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf !if $(TOOL_CHAIN_TAG) != "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf !endif INF ShellPkg/Application/Shell/Shell.infOvmfPkg/OvmfPkgIa32X64.fdf +1
-0@@ -286,16 +286,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf !if $(TOOL_CHAIN_TAG) != "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf !endif INF ShellPkg/Application/Shell/Shell.infOvmfPkg/OvmfPkgX64.fdf +1
-0@@ -295,16 +295,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf !if $(TOOL_CHAIN_TAG) != "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf !endif INF ShellPkg/Application/Shell/Shell.infOvmfPkg/VirtioFsDxe/VirtioFsDxe.inf new file +17
-0@@ -0,0 +1,92 @@ +## @file +# Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices. +# +# Copyright (C) 2020, Red Hat, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +# Permission Model of this driver: +# +# Regardless of the UID and GID values this driver send in the FUSE request +# header, the daemon (that is, the Virtio Filesystem device) always acts with +# root privileges on the host side. The only time the daemon considers said UID +# and GID fields is when creating a new file or directory. Thus, the guest +# driver cannot rely on the host for enforcing any file mode permissions, +# regardless of the "personality" that the guest driver poses as, because +# "root" on the host side ignores all file mode bits.
Quoted 8 lines
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf line 22
Quoted 5 lines
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf new file +5
-0+# +# Therefore the guest driver has to do its own permission checking, and use the +# host-side file mode bits only as a kind of "metadata storage" or "reminder" +# -- hopefully in a way that makes some sense on the host side too. +#Can you please explain why this is safe? Or should virtio-fs only be used with guests that can be trusted with root privileges on the host?
The daemon sandboxes itself and generally you only expose a private area of a filesystem to the guest; i.e. a per-guest rootfs or temporary or whatever.
Dave
Quoted 200 lines
Signature · 1 line
Ard.Quoted 179 lines
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf new file +70
-0+# The complete mapping between the EFI_FILE_PROTOCOL and the host-side file +# mode bits is described below. +# +# - The guest driver poses as UID 0, GID 0, PID 1. +# +# - If and only if all "w" bits are missing from a file on the host side, then +# the file or directory is reported as EFI_FILE_READ_ONLY in the guest. When +# setting EFI_FILE_READ_ONLY in the guest, all "w" bits (0222) are cleared on +# the host; when clearing EFI_FILE_READ_ONLY in the guest, all "w" bits are +# set on the host. Viewed from the host side, this sort of reflects that an +# EFI_FILE_READ_ONLY file should not be written by anyone. +# +# - The attributes EFI_FILE_HIDDEN, EFI_FILE_SYSTEM, EFI_FILE_RESERVED, and +# EFI_FILE_ARCHIVE are never reported in the guest, and they are silently +# ignored when a SetInfo() call or a file-creating Open() call requests them. +# +# - On the host, files are created with 0666 file mode bits, directories are +# created with 0777 file mode bits. +# +# - In the guest, the EFI_FILE_READ_ONLY attribute only controls the permitted +# open mode. In particular, on directories, the EFI_FILE_READ_ONLY attribute +# does not prevent the creation or deletion of entries inside the directory; +# EFI_FILE_READ_ONLY only prevents the renaming, deleting, flushing (syncing) +# and touching of the directory itself (with "touching" meaning updating the +# timestamps). The fact that EFI_FILE_READ_ONLY being set on a directory is +# irrelevant in the guest with regard to entry creation/deletion, is +# well-mirrored by the fact that virtiofsd -- which runs as root, regardless +# of guest driver personality -- ignores the absence of "w" permissions on a +# host-side directory, when creating or removing entries in it. +# +# - When an EFI_FILE_PROTOCOL is opened read-only, then the Delete(), Write() +# and Flush() member functions are disabled for it. Additionally, SetInfo() +# is restricted to flipping the EFI_FILE_READ_ONLY bit (which takes effect at +# the next Open()). +# +# - As a consequence of the above, for deleting a directory, it must be +# presented in the guest as openable for writing. +# +# - We diverge from the UEFI spec, and permit Flush() on a directory that has +# been opened read-write; otherwise the only way to invoke FUSE_FSYNCDIR on a +# directory would be to Close() it. +# +# - OpenVolume() opens the root directory for read-only access. The Open() +# member function may open it for read-write access. While the root directory +# cannot be renamed or deleted, opening it for read-write access is useful +# for calling Flush(), according to the previous paragraph, or for updating +# the root directory's timestamps with SetInfo(). +## + +[Defines] + INF_VERSION = 1.29 + BASE_NAME = VirtioFsDxe + FILE_GUID = 7BD9DDF7-8B83-488E-AEC9-24C78610289C + MODULE_TYPE = UEFI_DRIVER + ENTRY_POINT = VirtioFsEntryPoint + +[Packages] + MdePkg/MdePkg.dec + +[Sources] + DriverBinding.c + +[LibraryClasses] + BaseLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEfiComponentName2ProtocolGuid ## PRODUCES + gEfiDriverBindingProtocolGuid ## PRODUCESOvmfPkg/VirtioFsDxe/DriverBinding.c new file +102
-0@@ -0,0 +1,112 @@ +/** @file +Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Library/BaseLib.h> // AsciiStrCmp() +#include <Library/UefiBootServicesTableLib.h> // gBS +#include <Protocol/ComponentName2.h> // EFI_COMPONENT_NAME2_PROTOCOL +#include <Protocol/DriverBinding.h> // EFI_DRIVER_BINDING_PROTOCOL + +// +// UEFI Driver Model protocol instances. +// +STATIC EFI_DRIVER_BINDING_PROTOCOL mDriverBinding; +STATIC EFI_COMPONENT_NAME2_PROTOCOL mComponentName2; + +// +// UEFI Driver Model protocol member functions. +// +EFI_STATUS +EFIAPI +VirtioFsBindingSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ +return EFI_UNSUPPORTED ; +} + +EFI_STATUS +EFIAPI +VirtioFsBindingStart ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ +return EFI_DEVICE_ERROR ; +} + +EFI_STATUS +EFIAPI +VirtioFsBindingStop ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer OPTIONAL + ) +{ +return EFI_DEVICE_ERROR ; +} + +EFI_STATUS +EFIAPI +VirtioFsGetDriverName ( + IN EFI_COMPONENT_NAME2_PROTOCOL *This, + IN CHAR8 *Language, + OUT CHAR16 **DriverName + ) +{ +if (AsciiStrCmp (Language,"en" ) !=0 ) { +return EFI_UNSUPPORTED ; + } + *DriverName =L"Virtio Filesystem Driver" ; +return EFI_SUCCESS ; +} + +EFI_STATUS +EFIAPI +VirtioFsGetControllerName ( + IN EFI_COMPONENT_NAME2_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE ChildHandle OPTIONAL, + IN CHAR8 *Language, + OUT CHAR16 **ControllerName + ) +{ +return EFI_UNSUPPORTED ; +} + +// +// Entry point of this driver. +// +EFI_STATUS +EFIAPI +VirtioFsEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ +EFI_STATUS Status; + + mDriverBinding.Supported = VirtioFsBindingSupported; + mDriverBinding.Start = VirtioFsBindingStart; + mDriverBinding.Stop = VirtioFsBindingStop; + mDriverBinding.Version =0x10 ; + mDriverBinding.ImageHandle = ImageHandle; + mDriverBinding.DriverBindingHandle = ImageHandle;OvmfPkg/VirtioFsDxe/DriverBinding.c line 112
Quoted 10 lines
OvmfPkg/VirtioFsDxe/DriverBinding.c new file +10
-0+ + mComponentName2.GetDriverName = VirtioFsGetDriverName; + mComponentName2.GetControllerName = VirtioFsGetControllerName; + mComponentName2.SupportedLanguages ="en" ; + + Status = gBS->InstallMultipleProtocolInterfaces (&ImageHandle, + &gEfiDriverBindingProtocolGuid, &mDriverBinding, + &gEfiComponentName2ProtocolGuid, &mComponentName2,NULL ); +return Status; +}_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Virtio-fs] [edk2 PATCH 01/48] OvmfPkg: introduce VirtioFsDxe
(I'm breaking my PTO rules for this, because writing this driver was a very intense experience for me, and it's not like I can put it out of my mind from a Friday to a Saturday, after waking with it and going to bed with it for three weeks... I just couldn't resist checking the mailing list archive, and then logging in.)
Quoted 2 lines · Dr. David Alan Gilbert
Quoted 1 line · * Ard Biesheuvel ([email protected]) wrote:
On 12/16/20 10:10 PM, Laszlo Ersek wrote:
[...]
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf new file +9
-0+# Permission Model of this driver: +# +# Regardless of the UID and GID values this driver send in the FUSE request +# header, the daemon (that is, the Virtio Filesystem device) always acts with +# root privileges on the host side. The only time the daemon considers said UID +# and GID fields is when creating a new file or directory. Thus, the guest +# driver cannot rely on the host for enforcing any file mode permissions, +# regardless of the "personality" that the guest driver poses as, because +# "root" on the host side ignores all file mode bits.Quoted 8 lines
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf line 22
Quoted 5 lines
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf new file +5
-0+# +# Therefore the guest driver has to do its own permission checking, and use the +# host-side file mode bits only as a kind of "metadata storage" or "reminder" +# -- hopefully in a way that makes some sense on the host side too. +#Can you please explain why this is safe? Or should virtio-fs only be used with guests that can be trusted with root privileges on the host?
Quoted 3 lines
The daemon sandboxes itself and generally you only expose a private area of a filesystem to the guest; i.e. a per-guest rootfs or temporary or whatever.
Stefan wrote a document about this:
[PULL 059/111] virtiofsd: add security guide document
https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg05464.html
some excerpts:
Review
Quoted 4 lines
(quoted diff) +4
-0+Security Requirements +===================== +Guests have root access to the shared directory. This is necessary for root +file systems on virtio-fs and similar use cases.
and
Review
Quoted 11 lines
(quoted diff) +11
-0+Deployment Best Practices +========================= +The shared directory should be a separate file system so that untrusted guests +cannot cause a denial-of-service by using up all available inodes or exhausting +free space. + +If the shared directory is also accessible from a host mount namespace, it is +recommended to keep a parent directory with rwx------ permissions so that other +users on the host are unable to access any setuid executables or device nodes +in the shared directory. The `nosuid` and `nodev` mount options can also be +used to prevent this issue.
This document, originally proposed as "docs/tools/virtiofsd-security.rst", doesn't seem to have made it to the QEMU tree yet; it was put aside while a good location for it would be figured out. See this subthread under the v1 PULL:
https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg05733.html
and then see the PULL v2 changelog -- "drop the docs while we discuss where they should live":
https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg05780.html
(If there have been developments in this area since then, I'm not aware of them; sorry if my info on the docs' location is out-of-date.)
Thanks!
Laszlo
PATCH 2/48 ArmVirtPkg: include VirtioFsDxe in the ArmVirtQemu* platforms
In reply to Laszlo ErsekInclude the VirtioFsDxe driver in the ArmVirtPkg platforms that include Virtio10Dxe. (The virtio-fs device is virtio-1.0-only.)
Cc: Ard Biesheuvel <[email protected]>
Cc: Leif Lindholm <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- ArmVirtPkg/ArmVirtQemu.dsc | 3 ++- ArmVirtPkg/ArmVirtQemuKernel.dsc | 3 ++- ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-)
ArmVirtPkg/ArmVirtQemu.dsc +2 -1
@@ -403,23 +403,24 @@ [Components.common] ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf ArmVirtPkg/HighMemDxe/HighMemDxe.inf OvmfPkg/VirtioBlkDxe/VirtioBlk.inf OvmfPkg/VirtioScsiDxe/VirtioScsi.inf OvmfPkg/VirtioNetDxe/VirtioNet.inf OvmfPkg/VirtioRngDxe/VirtioRng.inf # - # FAT filesystem + GPT/MBR partitioning + UDF filesystem + # FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs # MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf # # Bds # MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf { <LibraryClasses> DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
ArmVirtPkg/ArmVirtQemuKernel.dsc +2 -1
@@ -339,23 +339,24 @@ [Components.common] ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf ArmVirtPkg/HighMemDxe/HighMemDxe.inf OvmfPkg/VirtioBlkDxe/VirtioBlk.inf OvmfPkg/VirtioScsiDxe/VirtioScsi.inf OvmfPkg/VirtioNetDxe/VirtioNet.inf OvmfPkg/VirtioRngDxe/VirtioRng.inf # - # FAT filesystem + GPT/MBR partitioning + UDF filesystem + # FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs # MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf # # Bds # MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf { <LibraryClasses> DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc +2 -1
@@ -72,23 +72,24 @@ [FV.FvMain] INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf # - # FAT filesystem + GPT/MBR partitioning + UDF filesystem + # FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs # INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf # # Status Code Routing # INF MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf # # Platform Driver
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 3/48 OvmfPkg/VirtioFsDxe: DriverBinding: open VirtioDevice, install SimpleFs
In reply to Laszlo ErsekComplete the Supported, Start, and Stop member functions of EFI_DRIVER_BINDING_PROTOCOL sufficiently for exercising the UEFI driver model:
- bind virtio-fs devices,
- produce placeholder EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on them.
On the "TO_START" (= Virtio) side, the VirtioFsBindingSupported() function verifies the Virtio subsystem ID for the virtio-fs device (decimal 26 -- see
<https://github.com/oasis-tcs/virtio-spec/blob/87fa6b5d8155/virtio-fs.tex>).
Beyond that, no actual Virtio setup is performed for now. Those bits are going to be implemented later in this series.
On the "BY_START" (= UEFI filesystem) side, the VirtioFsOpenVolume() function -- which is the sole EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member function -- is a stub; it always returns EFI_NO_MEDIA, for now.
The "CONNECT", "DISCONNECT", and "MAP -R" UEFI Shell commands can be used to test this patch.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/Virtio10.h | 5 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 7 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 52 +++++++++++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 94 +++++++++++++++++++- OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 26 ++++++ 5 files changed, 181 insertions(+), 3 deletions(-)
OvmfPkg/Include/IndustryStandard/Virtio10.h +5 -0
@@ -12,16 +12,21 @@#include <IndustryStandard/Pci23.h> #include <IndustryStandard/Virtio095.h> // // Subsystem Device IDs (to be) introduced in VirtIo 1.0 // #define VIRTIO_SUBSYSTEM_GPU_DEVICE 16 +// +// Subsystem Device IDs from the VirtIo spec at git commit 87fa6b5d8155; +// <https://github.com/oasis-tcs/virtio-spec/tree/87fa6b5d8155>. +// +#define VIRTIO_SUBSYSTEM_FILESYSTEM 26// // Structures for parsing the VirtIo 1.0 specific PCI capabilities from the // config space // #pragma pack (1) typedef struct { EFI_PCI_CAPABILITY_VENDOR_HDR VendorHdr;
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +7 -0
@@ -73,20 +73,27 @@ [Defines] INF_VERSION = 1.29 BASE_NAME = VirtioFsDxe FILE_GUID = 7BD9DDF7-8B83-488E-AEC9-24C78610289C MODULE_TYPE = UEFI_DRIVER ENTRY_POINT = VirtioFsEntryPoint [Packages] MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c + SimpleFsOpenVolume.c + VirtioFsDxe.h [LibraryClasses] BaseLib + DebugLib + MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint [Protocols] gEfiComponentName2ProtocolGuid ## PRODUCES gEfiDriverBindingProtocolGuid ## PRODUCES + gEfiSimpleFileSystemProtocolGuid ## BY_START + gVirtioDeviceProtocolGuid ## TO_START
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h new file +52 -0
52 lines not on this page · raw message
OvmfPkg/VirtioFsDxe/DriverBinding.c +91 -3
152 lines not on this page · raw message
OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c new file +26 -0
@@ -0,0 +1,26 @@ +/** @file +EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume() member function for the Virtio +Filesystem driver. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** +Open the root directory on the Virtio Filesystem. + +Refer to EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME for the interface +contract. +**/ +EFI_STATUS +EFIAPI +VirtioFsOpenVolume ( + IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **Root + ) +{ +return EFI_NO_MEDIA ; +}
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 4/48 OvmfPkg/VirtioFsDxe: implement virtio device (un)initialization
In reply to Laszlo ErsekAdd the VirtioFsInit(), VirtioFsUninit(), and VirtioFsExitBoot() functions.
In VirtioFsInit():
- Verify the host-side config of the virtio-fs device.
- Save the filesystem label ("tag") for later, from the configuration area of the virtio-fs device.
- Save the virtio queue size for later as well.
- Set up the virtio ring for sending requests.
In VirtioFsUninit():
- Reset the device.
- Tear down the virtio ring.
In VirtioFsExitBoot():
- Reset the device.
With this patch, the UEFI connect / disconnect controller operations involve virtio setup / teardown; they are visible in the virtio-fs daemon's log file. The virtiofsd log also confirms the device reset in VirtioFsExitBoot(), when an OS is booted while the virtio-fs device is bound.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 52 ++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 2 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 35 +++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 26 +- OvmfPkg/VirtioFsDxe/Helpers.c | 299 ++++++++++++++++++++ 5 files changed, 412 insertions(+), 2 deletions(-)
OvmfPkg/Include/IndustryStandard/VirtioFs.h new file +52 -0
@@ -0,0 +1,52 @@ +/** @file +Type and macro definitions specific to the Virtio Filesystem device. + +At the time of this writing, the latest released Virtio specification (v1.1) +does not include the virtio-fs device. The development version of the +specification defines it however; see the latest version at +<https://github.com/oasis-tcs/virtio-spec/blob/87fa6b5d8155/virtio-fs.tex>. + +This header file is minimal, and only defines the types and macros that are +necessary for the OvmfPkg implementation. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef VIRTIO_FS_H_ +#define VIRTIO_FS_H_ + +#include <IndustryStandard/Virtio.h> + +// +// Lowest numbered queue for sending normal priority requests. +// +#define VIRTIO_FS_REQUEST_QUEUE 1 + +// +// Number of bytes in the "VIRTIO_FS_CONFIG.Tag" field. +// +#define VIRTIO_FS_TAG_BYTES 36 + +// +// Device configuration layout. +// +#pragma pack (1) +typedef struct { +// +// The Tag field can be considered the filesystem label, or a mount point +// hint. It is UTF-8 encoded, and padded to full size with NUL bytes. If the +// encoded bytes take up the entire Tag field, then there is no NUL +// terminator. +// +UINT8 Tag[VIRTIO_FS_TAG_BYTES ]; +// +// The total number of request virtqueues exposed by the device (i.e., +// excluding the "hiprio" queue). +// +UINT32 NumReqQueues; +}VIRTIO_FS_CONFIG ; +#pragma pack () + +#endif // VIRTIO_FS_H_
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +2 -0
@@ -77,23 +77,25 @@ [Defines] ENTRY_POINT = VirtioFsEntryPoint [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c + Helpers.c SimpleFsOpenVolume.c VirtioFsDxe.h [LibraryClasses] BaseLib DebugLib MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint + VirtioLib [Protocols] gEfiComponentName2ProtocolGuid ## PRODUCES gEfiDriverBindingProtocolGuid ## PRODUCES gEfiSimpleFileSystemProtocolGuid ## BY_START gVirtioDeviceProtocolGuid ## TO_START
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +35 -0
@@ -6,42 +6,77 @@SPDX-License-Identifier: BSD-2-Clause-Patent **/ #ifndef VIRTIO_FS_DXE_H_ #define VIRTIO_FS_DXE_H_ #include <Base.h> // SIGNATURE_64() +#include <IndustryStandard/VirtioFs.h> // VIRTIO_FS_TAG_BYTES #include <Library/DebugLib.h> // CR() #include <Protocol/SimpleFileSystem.h> // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL #include <Protocol/VirtioDevice.h> // VIRTIO_DEVICE_PROTOCOL +#include <Uefi/UefiBaseType.h> // EFI_EVENT #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S') +// +// Filesystem label encoded in UCS-2, transformed from the UTF-8 representation +// in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII code +// points (U+0020 through U+007E) are supported. +// +typedef CHAR16 VIRTIO_FS_LABEL [VIRTIO_FS_TAG_BYTES +1 ]; +// // Main context structure, expressing an EFI_SIMPLE_FILE_SYSTEM_PROTOCOL // interface on top of the Virtio Filesystem device. // typedef struct {// // Parts of this structure are initialized / torn down in various functions // at various call depths. The table to the right should make it easier to // track them. // // field init function init depth // ----------- ------------------ ---------- UINT64 Signature;// DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio;// DriverBindingStart 0 +VIRTIO_FS_LABEL Label;// VirtioFsInit 1 +UINT16 QueueSize;// VirtioFsInit 1 +VRING Ring;// VirtioRingInit 2 +VOID *RingMap;// VirtioRingMap 2 +EFI_EVENT ExitBoot;// DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs;// DriverBindingStart 0 }VIRTIO_FS ;#define VIRTIO_FS_FROM_SIMPLE_FS (SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); +// +// Initialization and helper routines for the Virtio Filesystem device. +// + +EFI_STATUS +VirtioFsInit ( + IN OUT VIRTIO_FS *VirtioFs + ); + +VOID +VirtioFsUninit ( + IN OUT VIRTIO_FS *VirtioFs + ); + +VOID +EFIAPI +VirtioFsExitBoot ( + IN EFI_EVENT ExitBootEvent, + IN VOID *VirtioFsAsVoid + ); +// // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem // driver. // EFI_STATUS EFIAPI VirtioFsOpenVolume (
OvmfPkg/VirtioFsDxe/DriverBinding.c +24 -2
@@ -1,17 +1,16 @@/** @file Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices. Copyright (C) 2020, Red Hat, Inc. SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include <IndustryStandard/Virtio.h> // VIRTIO_SUBSYSTEM_FILESYSTEM #include <Library/BaseLib.h> // AsciiStrCmp() #include <Library/MemoryAllocationLib.h> // AllocatePool() #include <Library/UefiBootServicesTableLib.h> // gBS #include <Protocol/ComponentName2.h> // EFI_COMPONENT_NAME2_PROTOCOL #include <Protocol/DriverBinding.h> // EFI_DRIVER_BINDING_PROTOCOL #include "VirtioFsDxe.h"
@@ -75,28 +74,46 @@ VirtioFsBindingStart ( Status = gBS->OpenProtocol (ControllerHandle, &gVirtioDeviceProtocolGuid, (VOID **)&VirtioFs->Virtio, This->DriverBindingHandle, ControllerHandle,EFI_OPEN_PROTOCOL_BY_DRIVER );if (EFI_ERROR (Status)) { goto FreeVirtioFs; } + Status =VirtioFsInit (VirtioFs); +if (EFI_ERROR (Status)) { + goto CloseVirtio; + } + + Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES ,TPL_CALLBACK , + VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot); +if (EFI_ERROR (Status)) { + goto UninitVirtioFs; + } + VirtioFs->SimpleFs.Revision =EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION ; VirtioFs->SimpleFs.OpenVolume = VirtioFsOpenVolume; Status = gBS->InstallProtocolInterface (&ControllerHandle, &gEfiSimpleFileSystemProtocolGuid,EFI_NATIVE_INTERFACE , &VirtioFs->SimpleFs);if (EFI_ERROR (Status)) { - goto CloseVirtio; + goto CloseExitBoot; }return EFI_SUCCESS ; +CloseExitBoot: + CloseStatus = gBS->CloseEvent (VirtioFs->ExitBoot); +ASSERT_EFI_ERROR (CloseStatus); + +UninitVirtioFs: +VirtioFsUninit (VirtioFs); + CloseVirtio: CloseStatus = gBS->CloseProtocol (ControllerHandle, &gVirtioDeviceProtocolGuid, This->DriverBindingHandle, ControllerHandle);ASSERT_EFI_ERROR (CloseStatus); FreeVirtioFs:FreePool (VirtioFs);
@@ -128,16 +145,21 @@ VirtioFsBindingStop ( VirtioFs =VIRTIO_FS_FROM_SIMPLE_FS (SimpleFs); Status = gBS->UninstallProtocolInterface (ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, SimpleFs);if (EFI_ERROR (Status)) {return Status; } + Status = gBS->CloseEvent (VirtioFs->ExitBoot); +ASSERT_EFI_ERROR (Status); + +VirtioFsUninit (VirtioFs); + Status = gBS->CloseProtocol (ControllerHandle, &gVirtioDeviceProtocolGuid, This->DriverBindingHandle, ControllerHandle);ASSERT_EFI_ERROR (Status);FreePool (VirtioFs);return EFI_SUCCESS ; }
OvmfPkg/VirtioFsDxe/Helpers.c new file +299 -0
299 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 5/48 OvmfPkg/VirtioFsDxe: add a scatter-gather list data type
In reply to Laszlo ErsekIn preparation for the variously structured FUSE request/response exchanges that virtio-fs uses, introduce a scatter-gather list data type. This will let us express FUSE request-response pairs flexibly.
Add a function for validating whether a (request buffer list, response buffer list) pair is well-formed, and supported by the Virtio Filesystem device's queue depth.
Add another function for mapping and submitting a validated pair of scatter-gather lists to the Virtio Filesystem device.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 60 +++ OvmfPkg/VirtioFsDxe/Helpers.c | 401 ++++++++++++++++++++ 2 files changed, 461 insertions(+)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +60 -0
@@ -46,16 +46,62 @@ typedef struct {VOID *RingMap;// VirtioRingMap 2 EFI_EVENT ExitBoot;// DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs;// DriverBindingStart 0 }VIRTIO_FS ;#define VIRTIO_FS_FROM_SIMPLE_FS (SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); +// +// Structure for describing a contiguous buffer, potentially mapped for Virtio +// transfer. +// +typedef struct { +// +// The following fields originate from the owner of the buffer. +// +VOID *Buffer; +UINTN Size; +// +// All of the fields below, until the end of the structure, are +// zero-initialized when the structure is initially validated. +// +// Mapped, MappedAddress and Mapping are updated when the buffer is mapped +// for VirtioOperationBusMasterRead or VirtioOperationBusMasterWrite. They +// are again updated when the buffer is unmapped. +// +BOOLEAN Mapped; +EFI_PHYSICAL_ADDRESS MappedAddress; +VOID *Mapping; +// +// Transferred is updated after VirtioFlush() returns successfully: +// - for VirtioOperationBusMasterRead, Transferred is set to Size; +// - for VirtioOperationBusMasterWrite, Transferred is calculated from the +// UsedLen output parameter of VirtioFlush(). +// +UINTN Transferred; +}VIRTIO_FS_IO_VECTOR ; + +// +// Structure for describing a list of IO Vectors. +// +typedef struct { +// +// The following fields originate from the owner of the buffers. +// +VIRTIO_FS_IO_VECTOR *IoVec; +UINTN NumVec; +// +// TotalSize is calculated when the scatter-gather list is initially +// validated. +// +UINT32 TotalSize; +}VIRTIO_FS_SCATTER_GATHER_LIST ; +// // Initialization and helper routines for the Virtio Filesystem device. // EFI_STATUS VirtioFsInit ( IN OUT VIRTIO_FS *VirtioFs );
@@ -67,16 +113,30 @@ VirtioFsUninit (VOID EFIAPIVirtioFsExitBoot ( IN EFI_EVENT ExitBootEvent, IN VOID *VirtioFsAsVoid ); +EFI_STATUS +VirtioFsSgListsValidate ( + IN VIRTIO_FS *VirtioFs, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL + ); + +EFI_STATUS +VirtioFsSgListsSubmit ( + IN OUT VIRTIO_FS *VirtioFs, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL + ); +// // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem // driver. // EFI_STATUS EFIAPI VirtioFsOpenVolume (
OvmfPkg/VirtioFsDxe/Helpers.c +401 -0
409 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 6/48 OvmfPkg/VirtioFsDxe: introduce the basic FUSE request/response headers
In reply to Laszlo ErsekIntroduce the VIRTIO_FS_FUSE_REQUEST and VIRTIO_FS_FUSE_RESPONSE structures, which are the common headers for the various FUSE request/response structures.
Introduce the VirtioFsFuseNewRequest() helper function for populating VIRTIO_FS_FUSE_REQUEST, from parameters and from a VIRTIO_FS-level request counter.
Introduce the VirtioFsFuseCheckResponse() helper function for verifying most FUSE response types that begin with the VIRTIO_FS_FUSE_RESPONSE header.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 49 +++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 17 ++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 5 + OvmfPkg/VirtioFsDxe/Helpers.c | 216 ++++++++++++++++++++ 4 files changed, 287 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +49 -0
@@ -44,9 +44,58 @@ typedef struct {// // The total number of request virtqueues exposed by the device (i.e., // excluding the "hiprio" queue). // UINT32 NumReqQueues; }VIRTIO_FS_CONFIG ;#pragma pack () +// +// FUSE-related definitions follow. +// +// From virtio-v1.1-cs01-87fa6b5d8155, 5.11 File System Device: "[...] The +// driver acts as the FUSE client mounting the file system. The virtio file +// system device provides the mechanism for transporting FUSE requests [...]" +// +// Unfortunately, the documentation of the FUSE wire protocol is lacking. The +// Virtio spec (as of this writing) simply defers to +// "include/uapi/linux/fuse.h" in the Linux kernel source -- see the reference +// in virtio spec file "introduction.tex", at commit 87fa6b5d8155. +// +// Of course, "include/uapi/linux/fuse.h" is a moving target (the virtio spec +// does not specify a particular FUSE interface version). The OvmfPkg code +// targets version 7.31, because that's the lowest version that the QEMU +// virtio-fs daemon supports at this time -- see QEMU commit 72c42e2d6551 +// ("virtiofsd: Trim out compatibility code", 2020-01-23). +// +// Correspondingly, Linux's "include/uapi/linux/fuse.h" is consulted as checked +// out at commit (c6ff213fe5b8^) = d78092e4937d ("fuse: fix page dereference +// after free", 2020-09-18); that is, right before commit c6ff213fe5b8 ("fuse: +// add submount support to <uapi/linux/fuse.h>", 2020-09-18) introduces FUSE +// interface version 7.32. +// +#define VIRTIO_FS_FUSE_MAJOR 7 +#define VIRTIO_FS_FUSE_MINOR 31 + +#pragma pack (1) +// +// Request-response headers common to all request types. +// +typedef struct { +UINT32 Len; +UINT32 Opcode; +UINT64 Unique; +UINT64 NodeId; +UINT32 Uid; +UINT32 Gid; +UINT32 Pid; +UINT32 Padding; +}VIRTIO_FS_FUSE_REQUEST ; + +typedef struct { +UINT32 Len; +INT32 Error; +UINT64 Unique; +}VIRTIO_FS_FUSE_RESPONSE ; +#pragma pack () +#endif // VIRTIO_FS_H_
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +17 -0
@@ -39,16 +39,17 @@ typedef struct {// field init function init depth // ----------- ------------------ ---------- UINT64 Signature;// DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio;// DriverBindingStart 0 VIRTIO_FS_LABEL Label;// VirtioFsInit 1 UINT16 QueueSize;// VirtioFsInit 1 VRING Ring;// VirtioRingInit 2 VOID *RingMap;// VirtioRingMap 2 +UINT64 RequestId;// DriverBindingStart 0 EFI_EVENT ExitBoot;// DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs;// DriverBindingStart 0 }VIRTIO_FS ;#define VIRTIO_FS_FROM_SIMPLE_FS (SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG);//
@@ -127,16 +128,32 @@ VirtioFsSgListsValidate (EFI_STATUS VirtioFsSgListsSubmit ( IN OUT VIRTIO_FS *VirtioFs, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL ); +EFI_STATUS +VirtioFsFuseNewRequest ( + IN OUT VIRTIO_FS *VirtioFs, + OUT VIRTIO_FS_FUSE_REQUEST *Request, + IN UINT32 RequestSize, + IN UINT32 Opcode, + IN UINT64 NodeId + ); + +EFI_STATUS +VirtioFsFuseCheckResponse ( + IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, + IN UINT64 RequestId, + OUT UINTN *TailBufferFill + ); +// // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem // driver. // EFI_STATUS EFIAPI VirtioFsOpenVolume (
OvmfPkg/VirtioFsDxe/DriverBinding.c +5 -0
@@ -79,16 +79,21 @@ VirtioFsBindingStart ( goto FreeVirtioFs; } Status =VirtioFsInit (VirtioFs);if (EFI_ERROR (Status)) { goto CloseVirtio; } +// +// Initialize the FUSE request counter. +// + VirtioFs->RequestId =1 ; + Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES ,TPL_CALLBACK , VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot);if (EFI_ERROR (Status)) { goto UninitVirtioFs; } VirtioFs->SimpleFs.Revision =EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION ; VirtioFs->SimpleFs.OpenVolume = VirtioFsOpenVolume;
OvmfPkg/VirtioFsDxe/Helpers.c +216 -0
224 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
Re: [Virtio-fs] [edk2 PATCH 06/48] OvmfPkg/VirtioFsDxe: introduce the basic FUSE request/response headers
Quoted 44 lines · * Laszlo Ersek ([email protected]) wrote:
Introduce the
VIRTIO_FS_FUSE_REQUESTandVIRTIO_FS_FUSE_RESPONSEstructures, which are the common headers for the various FUSE request/response structures.Introduce the
VirtioFsFuseNewRequest()helper function for populatingVIRTIO_FS_FUSE_REQUEST, from parameters and from a VIRTIO_FS-level request counter.Introduce the
VirtioFsFuseCheckResponse()helper function for verifying most FUSE response types that begin with theVIRTIO_FS_FUSE_RESPONSEheader.Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097Signed-off-by Laszlo Ersek <[email protected]>--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 49 +++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 17 ++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 5 + OvmfPkg/VirtioFsDxe/Helpers.c | 216 ++++++++++++++++++++ 4 files changed, 287 insertions(+)OvmfPkg/Include/IndustryStandard/VirtioFs.h +7
-0@@ -44,9 +44,58 @@ typedef struct {// // The total number of request virtqueues exposed by the device (i.e., // excluding the "hiprio" queue). // UINT32 NumReqQueues; }VIRTIO_FS_CONFIG ;#pragma pack () +// +// FUSE-related definitions follow. +// +// From virtio-v1.1-cs01-87fa6b5d8155, 5.11 File System Device: "[...] The +// driver acts as the FUSE client mounting the file system. The virtio file +// system device provides the mechanism for transporting FUSE requests [...]" +//
OvmfPkg/Include/IndustryStandard/VirtioFs.h typedef struct { · line 68
Quoted 10 lines
OvmfPkg/Include/IndustryStandard/VirtioFs.h +10
-0+// Unfortunately, the documentation of the FUSE wire protocol is lacking. The +// Virtio spec (as of this writing) simply defers to +// "include/uapi/linux/fuse.h" in the Linux kernel source -- see the reference +// in virtio spec file "introduction.tex", at commit 87fa6b5d8155. +// +// Of course, "include/uapi/linux/fuse.h" is a moving target (the virtio spec +// does not specify a particular FUSE interface version). The OvmfPkg code +// targets version 7.31, because that's the lowest version that the QEMU +// virtio-fs daemon supports at this time -- see QEMU commit 72c42e2d6551 +// ("virtiofsd: Trim out compatibility code", 2020-01-23).
Fuse has it's own in built protocol versioning and negotiation, and as I remember it's the version of the header in the Linux kernel that's the definitive version. I think it would have also been safe just to take the latest released kernel version
Dave
Quoted 351 lines
OvmfPkg/Include/IndustryStandard/VirtioFs.h +31
-0+// Correspondingly, Linux's "include/uapi/linux/fuse.h" is consulted as checked +// out at commit (c6ff213fe5b8^) = d78092e4937d ("fuse: fix page dereference +// after free", 2020-09-18); that is, right before commit c6ff213fe5b8 ("fuse: +// add submount support to <uapi/linux/fuse.h>", 2020-09-18) introduces FUSE +// interface version 7.32. +// +#define VIRTIO_FS_FUSE_MAJOR 7 +#define VIRTIO_FS_FUSE_MINOR 31 + +#pragma pack (1) +// +// Request-response headers common to all request types. +// +typedef struct { +UINT32 Len; +UINT32 Opcode; +UINT64 Unique; +UINT64 NodeId; +UINT32 Uid; +UINT32 Gid; +UINT32 Pid; +UINT32 Padding; +}VIRTIO_FS_FUSE_REQUEST ; + +typedef struct { +UINT32 Len; +INT32 Error; +UINT64 Unique; +}VIRTIO_FS_FUSE_RESPONSE ; +#pragma pack () +#endif // VIRTIO_FS_H_ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +17
-0@@ -39,16 +39,17 @@ typedef struct {// field init function init depth // ----------- ------------------ ---------- UINT64 Signature;// DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio;// DriverBindingStart 0 VIRTIO_FS_LABEL Label;// VirtioFsInit 1 UINT16 QueueSize;// VirtioFsInit 1 VRING Ring;// VirtioRingInit 2 VOID *RingMap;// VirtioRingMap 2 +UINT64 RequestId;// DriverBindingStart 0 EFI_EVENT ExitBoot;// DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs;// DriverBindingStart 0 }VIRTIO_FS ;#define VIRTIO_FS_FROM_SIMPLE_FS (SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG);// @@ -127,16 +128,32 @@ VirtioFsSgListsValidate (EFI_STATUS VirtioFsSgListsSubmit ( IN OUT VIRTIO_FS *VirtioFs, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL ); +EFI_STATUS +VirtioFsFuseNewRequest ( + IN OUT VIRTIO_FS *VirtioFs, + OUT VIRTIO_FS_FUSE_REQUEST *Request, + IN UINT32 RequestSize, + IN UINT32 Opcode, + IN UINT64 NodeId + ); + +EFI_STATUS +VirtioFsFuseCheckResponse ( + IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, + IN UINT64 RequestId, + OUT UINTN *TailBufferFill + ); +// // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem // driver. // EFI_STATUS EFIAPI VirtioFsOpenVolume (OvmfPkg/VirtioFsDxe/DriverBinding.c +5
-0@@ -79,16 +79,21 @@ VirtioFsBindingStart ( goto FreeVirtioFs; } Status =VirtioFsInit (VirtioFs);if (EFI_ERROR (Status)) { goto CloseVirtio; } +// +// Initialize the FUSE request counter. +// + VirtioFs->RequestId =1 ; + Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES ,TPL_CALLBACK , VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot);if (EFI_ERROR (Status)) { goto UninitVirtioFs; } VirtioFs->SimpleFs.Revision =EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION ; VirtioFs->SimpleFs.OpenVolume = VirtioFsOpenVolume;OvmfPkg/VirtioFsDxe/Helpers.c +216
-0@@ -693,8 +693,224 @@ VirtioFsSgListsSubmit (if (!EFI_ERROR (Status) &&EFI_ERROR (UnmapStatus)) { Status = UnmapStatus; } } }return Status; } + +/** +Set up the fields of a new VIRTIO_FS_FUSE_REQUEST object. + +The function may only be called after VirtioFsInit() returns successfully and +before VirtioFsUninit() is called. + +@param[in,out] VirtioFs The Virtio Filesystem device that the request is +being prepared for. The "VirtioFs->RequestId" field +will be copied into "Request->Unique". On output (on +successful return), "VirtioFs->RequestId" will be +incremented. + +@param[out] Request The VIRTIO_FS_FUSE_REQUEST object whose fields are to +be set. + +@param[in] RequestSize The total size of the request, including +sizeof(VIRTIO_FS_FUSE_REQUEST). + +@param[in] Opcode The VIRTIO_FS_FUSE_OPCODE that identifies the command +to send. + +@param[in] NodeId The inode number of the file that the request refers +to. + +@retval EFI_INVALID_PARAMETER RequestSize is smaller than +sizeof(VIRTIO_FS_FUSE_REQUEST). + +@retval EFI_OUT_OF_RESOURCES "VirtioFs->RequestId" is MAX_UINT64, and can +be incremented no more. + +@retval EFI_SUCCESS Request has been populated, +"VirtioFs->RequestId" has been incremented. +**/ +EFI_STATUS +VirtioFsFuseNewRequest ( + IN OUT VIRTIO_FS *VirtioFs, + OUT VIRTIO_FS_FUSE_REQUEST *Request, + IN UINT32 RequestSize, + IN UINT32 Opcode, + IN UINT64 NodeId + ) +{ +if (RequestSize <sizeof *Request) { +return EFI_INVALID_PARAMETER ; + } + +if (VirtioFs->RequestId ==MAX_UINT64 ) { +return EFI_OUT_OF_RESOURCES ; + } + + Request->Len = RequestSize; + Request->Opcode = Opcode; + Request->Unique = VirtioFs->RequestId++; + Request->NodeId = NodeId; + Request->Uid =0 ; + Request->Gid =0 ; + Request->Pid =1 ; + Request->Padding =0 ; + +return EFI_SUCCESS ; +} + +/** +Check the common FUSE response format. + +The first buffer in the response scatter-gather list is assumed a +VIRTIO_FS_FUSE_RESPONSE structure. Subsequent response buffers, if any, up to +and excluding the last one, are assumed fixed size. The last response buffer +may or may not be fixed size, as specified by the caller. + +This function may only be called after VirtioFsSgListsSubmit() returns +successfully. + +@param[in] ResponseSgList The scatter-gather list that describes the +response part of the exchange -- the buffers that +the Virtio Filesystem device filled in during the +virtio transfer. + +@param[in] RequestId The request identifier to which the response is +expected to belong. + +@param[out] TailBufferFill If NULL, then the last buffer in ResponseSgList +is considered fixed size. Otherwise, the last +buffer is considered variable size, and on +successful return, TailBufferFill reports the +number of bytes in the last buffer. + +@retval EFI_INVALID_PARAMETER TailBufferFill is not NULL (i.e., the last +buffer is considered variable size), and +ResponseSgList->NumVec is 1. + +@retval EFI_INVALID_PARAMETER The allocated size of the first buffer does +not match sizeof(VIRTIO_FS_FUSE_RESPONSE). + +@retval EFI_PROTOCOL_ERROR The VIRTIO_FS_FUSE_RESPONSE structure in the +first buffer has not been fully populated. + +@retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Len" in the first +buffer does not equal the sum of the +individual buffer sizes (as populated). + +@retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Unique" in the first +buffer does not equal RequestId. + +@retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Error" in the first +buffer is zero, but a subsequent fixed size +buffer has not been fully populated. + +@retval EFI_DEVICE_ERROR "VIRTIO_FS_FUSE_RESPONSE.Error" in the first +buffer is nonzero. The caller may investigate +"VIRTIO_FS_FUSE_RESPONSE.Error". Note that the +completeness of the subsequent fixed size +buffers is not verified in this case. + +@retval EFI_SUCCESS Verification successful. +**/ +EFI_STATUS +VirtioFsFuseCheckResponse ( + IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, + IN UINT64 RequestId, + OUT UINTN *TailBufferFill + ) +{ +UINTN NumFixedSizeVec; +VIRTIO_FS_FUSE_RESPONSE *CommonResp; +UINT32 TotalTransferred; +UINTN Idx; + +// +// Ensured by VirtioFsSgListsValidate(). +// +ASSERT (ResponseSgList->NumVec >0 ); + +if (TailBufferFill ==NULL ) { +// +// All buffers are considered fixed size. +// + NumFixedSizeVec = ResponseSgList->NumVec; + }else { +// +// If the last buffer is variable size, then we need that buffer to be +// different from the first buffer, which is considered a +// VIRTIO_FS_FUSE_RESPONSE (fixed size) structure. +// +if (ResponseSgList->NumVec ==1 ) { +return EFI_INVALID_PARAMETER ; + } + NumFixedSizeVec = ResponseSgList->NumVec -1 ; + } + +// +// The first buffer is supposed to carry a (fully populated) +// VIRTIO_FS_FUSE_RESPONSE structure. +// +if (ResponseSgList->IoVec[0 ].Size !=sizeof *CommonResp) { +return EFI_INVALID_PARAMETER ; + } +if (ResponseSgList->IoVec[0 ].Transferred != ResponseSgList->IoVec[0 ].Size) { +return EFI_PROTOCOL_ERROR ; + } + +// +// FUSE must report the same number of bytes, written by the Virtio +// Filesystem device, as the virtio transport does. +// + CommonResp = ResponseSgList->IoVec[0 ].Buffer; + TotalTransferred =0 ; +for (Idx =0 ; Idx < ResponseSgList->NumVec; Idx++) { +// +// Integer overflow and truncation are not possible, based on +// VirtioFsSgListsValidate() and VirtioFsSgListsSubmit(). +// + TotalTransferred += (UINT32 )ResponseSgList->IoVec[Idx].Transferred; + } +if (CommonResp->Len != TotalTransferred) { +return EFI_PROTOCOL_ERROR ; + } + +// +// Enforce that FUSE match our request ID in the response. +// +if (CommonResp->Unique != RequestId) { +return EFI_PROTOCOL_ERROR ; + } + +// +// If there is an explicit error report, skip checking the transfer +// counts for the rest of the fixed size buffers. +// +if (CommonResp->Error !=0 ) { +return EFI_DEVICE_ERROR ; + } + +// +// There was no error reported, so we require that the Virtio Filesystem +// device populate all fixed size buffers. We checked this for the very first +// buffer above; let's check the rest (if any). +// +ASSERT (NumFixedSizeVec >=1 ); +for (Idx =1 ; Idx < NumFixedSizeVec; Idx++) { +if (ResponseSgList->IoVec[Idx].Transferred != + ResponseSgList->IoVec[Idx].Size) { +return EFI_PROTOCOL_ERROR ; + } + } + +// +// If the last buffer is considered variable size, report its filled size. +// +if (TailBufferFill !=NULL ) { + *TailBufferFill = ResponseSgList->IoVec[NumFixedSizeVec].Transferred; + } + +return EFI_SUCCESS ; +}Signature · 8 lines
2.19.1.3.g30247aa5d201 _______________________________________________ Virtio-fs mailing list [email protected] https://www.redhat.com/mailman/listinfo/virtio-fs
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Virtio-fs] [edk2 PATCH 06/48] OvmfPkg/VirtioFsDxe: introduce the basic FUSE request/response headers
Quoted 52 lines · Dr. David Alan Gilbert
Quoted 51 lines · * Laszlo Ersek ([email protected]) wrote:
Introduce the
VIRTIO_FS_FUSE_REQUESTandVIRTIO_FS_FUSE_RESPONSEstructures, which are the common headers for the various FUSE request/response structures.Introduce the
VirtioFsFuseNewRequest()helper function for populatingVIRTIO_FS_FUSE_REQUEST, from parameters and from a VIRTIO_FS-level request counter.Introduce the
VirtioFsFuseCheckResponse()helper function for verifying most FUSE response types that begin with theVIRTIO_FS_FUSE_RESPONSEheader.Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097Signed-off-by Laszlo Ersek <[email protected]>--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 49 +++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 17 ++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 5 + OvmfPkg/VirtioFsDxe/Helpers.c | 216 ++++++++++++++++++++ 4 files changed, 287 insertions(+)OvmfPkg/Include/IndustryStandard/VirtioFs.h +14
-0@@ -44,9 +44,58 @@ typedef struct {// // The total number of request virtqueues exposed by the device (i.e., // excluding the "hiprio" queue). // UINT32 NumReqQueues; }VIRTIO_FS_CONFIG ;#pragma pack () +// +// FUSE-related definitions follow. +// +// From virtio-v1.1-cs01-87fa6b5d8155, 5.11 File System Device: "[...] The +// driver acts as the FUSE client mounting the file system. The virtio file +// system device provides the mechanism for transporting FUSE requests [...]" +// +// Unfortunately, the documentation of the FUSE wire protocol is lacking. The +// Virtio spec (as of this writing) simply defers to +// "include/uapi/linux/fuse.h" in the Linux kernel source -- see the reference +// in virtio spec file "introduction.tex", at commit 87fa6b5d8155. +// +// Of course, "include/uapi/linux/fuse.h" is a moving target (the virtio spec +// does not specify a particular FUSE interface version). The OvmfPkg code
Quoted 8 lines
OvmfPkg/Include/IndustryStandard/VirtioFs.h typedef struct { · line 68
Quoted 3 lines
OvmfPkg/Include/IndustryStandard/VirtioFs.h +3
-0+// targets version 7.31, because that's the lowest version that the QEMU +// virtio-fs daemon supports at this time -- see QEMU commit 72c42e2d6551 +// ("virtiofsd: Trim out compatibility code", 2020-01-23). Fuse has it's own in built protocol versioning and negotiation, and as I remember it's the version of the header in the Linux kernel that's the definitive version. I think it would have also been safe just to take the latest released kernel version
7.32 (kernel commit c6ff213fe5b8) introduces "submount support", which does not seem relevant. The strategy we follow in "OvmfPkg/Include/IndustryStandard" is: never include or convert header files from other projects whole-sale; always evaluate every structure and macro one by one for necessity, and if a definition is really needed for the driver being implemented, add that definition manually, and natively to the edk2 coding style.
This approach has caused zero friction or extra maintenance work over the years, and it allows for a native look & feel. (It's a different question what people think of edk2's "native" look and feel :))
A counter-example is the Xen headers in "OvmfPkg/Include/IndustryStandard/Xen", which were mass-imported and then fixed up separately for edk2 compatibility at some point -- much to my dismay. They feel totally foreign in edk2 and they've never stopped being a thorn in my side. It's not just the headers of course: when you *use* those macros and typedefs in the actual driver code, it shows.
So, as long as it's up to me, OVMF never "just takes" but "adds from zero", and I do stick with the absolute minimum needed.
Thanks,
Laszlo
Quoted 354 lines
Dave
Quoted 351 lines
OvmfPkg/Include/IndustryStandard/VirtioFs.h +31
-0+// Correspondingly, Linux's "include/uapi/linux/fuse.h" is consulted as checked +// out at commit (c6ff213fe5b8^) = d78092e4937d ("fuse: fix page dereference +// after free", 2020-09-18); that is, right before commit c6ff213fe5b8 ("fuse: +// add submount support to <uapi/linux/fuse.h>", 2020-09-18) introduces FUSE +// interface version 7.32. +// +#define VIRTIO_FS_FUSE_MAJOR 7 +#define VIRTIO_FS_FUSE_MINOR 31 + +#pragma pack (1) +// +// Request-response headers common to all request types. +// +typedef struct { +UINT32 Len; +UINT32 Opcode; +UINT64 Unique; +UINT64 NodeId; +UINT32 Uid; +UINT32 Gid; +UINT32 Pid; +UINT32 Padding; +}VIRTIO_FS_FUSE_REQUEST ; + +typedef struct { +UINT32 Len; +INT32 Error; +UINT64 Unique; +}VIRTIO_FS_FUSE_RESPONSE ; +#pragma pack () +#endif // VIRTIO_FS_H_ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +17
-0@@ -39,16 +39,17 @@ typedef struct {// field init function init depth // ----------- ------------------ ---------- UINT64 Signature;// DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio;// DriverBindingStart 0 VIRTIO_FS_LABEL Label;// VirtioFsInit 1 UINT16 QueueSize;// VirtioFsInit 1 VRING Ring;// VirtioRingInit 2 VOID *RingMap;// VirtioRingMap 2 +UINT64 RequestId;// DriverBindingStart 0 EFI_EVENT ExitBoot;// DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs;// DriverBindingStart 0 }VIRTIO_FS ;#define VIRTIO_FS_FROM_SIMPLE_FS (SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG);// @@ -127,16 +128,32 @@ VirtioFsSgListsValidate (EFI_STATUS VirtioFsSgListsSubmit ( IN OUT VIRTIO_FS *VirtioFs, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL ); +EFI_STATUS +VirtioFsFuseNewRequest ( + IN OUT VIRTIO_FS *VirtioFs, + OUT VIRTIO_FS_FUSE_REQUEST *Request, + IN UINT32 RequestSize, + IN UINT32 Opcode, + IN UINT64 NodeId + ); + +EFI_STATUS +VirtioFsFuseCheckResponse ( + IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, + IN UINT64 RequestId, + OUT UINTN *TailBufferFill + ); +// // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem // driver. // EFI_STATUS EFIAPI VirtioFsOpenVolume (OvmfPkg/VirtioFsDxe/DriverBinding.c +5
-0@@ -79,16 +79,21 @@ VirtioFsBindingStart ( goto FreeVirtioFs; } Status =VirtioFsInit (VirtioFs);if (EFI_ERROR (Status)) { goto CloseVirtio; } +// +// Initialize the FUSE request counter. +// + VirtioFs->RequestId =1 ; + Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES ,TPL_CALLBACK , VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot);if (EFI_ERROR (Status)) { goto UninitVirtioFs; } VirtioFs->SimpleFs.Revision =EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION ; VirtioFs->SimpleFs.OpenVolume = VirtioFsOpenVolume;OvmfPkg/VirtioFsDxe/Helpers.c +216
-0@@ -693,8 +693,224 @@ VirtioFsSgListsSubmit (if (!EFI_ERROR (Status) &&EFI_ERROR (UnmapStatus)) { Status = UnmapStatus; } } }return Status; } + +/** +Set up the fields of a new VIRTIO_FS_FUSE_REQUEST object. + +The function may only be called after VirtioFsInit() returns successfully and +before VirtioFsUninit() is called. + +@param[in,out] VirtioFs The Virtio Filesystem device that the request is +being prepared for. The "VirtioFs->RequestId" field +will be copied into "Request->Unique". On output (on +successful return), "VirtioFs->RequestId" will be +incremented. + +@param[out] Request The VIRTIO_FS_FUSE_REQUEST object whose fields are to +be set. + +@param[in] RequestSize The total size of the request, including +sizeof(VIRTIO_FS_FUSE_REQUEST). + +@param[in] Opcode The VIRTIO_FS_FUSE_OPCODE that identifies the command +to send. + +@param[in] NodeId The inode number of the file that the request refers +to. + +@retval EFI_INVALID_PARAMETER RequestSize is smaller than +sizeof(VIRTIO_FS_FUSE_REQUEST). + +@retval EFI_OUT_OF_RESOURCES "VirtioFs->RequestId" is MAX_UINT64, and can +be incremented no more. + +@retval EFI_SUCCESS Request has been populated, +"VirtioFs->RequestId" has been incremented. +**/ +EFI_STATUS +VirtioFsFuseNewRequest ( + IN OUT VIRTIO_FS *VirtioFs, + OUT VIRTIO_FS_FUSE_REQUEST *Request, + IN UINT32 RequestSize, + IN UINT32 Opcode, + IN UINT64 NodeId + ) +{ +if (RequestSize <sizeof *Request) { +return EFI_INVALID_PARAMETER ; + } + +if (VirtioFs->RequestId ==MAX_UINT64 ) { +return EFI_OUT_OF_RESOURCES ; + } + + Request->Len = RequestSize; + Request->Opcode = Opcode; + Request->Unique = VirtioFs->RequestId++; + Request->NodeId = NodeId; + Request->Uid =0 ; + Request->Gid =0 ; + Request->Pid =1 ; + Request->Padding =0 ; + +return EFI_SUCCESS ; +} + +/** +Check the common FUSE response format. + +The first buffer in the response scatter-gather list is assumed a +VIRTIO_FS_FUSE_RESPONSE structure. Subsequent response buffers, if any, up to +and excluding the last one, are assumed fixed size. The last response buffer +may or may not be fixed size, as specified by the caller. + +This function may only be called after VirtioFsSgListsSubmit() returns +successfully. + +@param[in] ResponseSgList The scatter-gather list that describes the +response part of the exchange -- the buffers that +the Virtio Filesystem device filled in during the +virtio transfer. + +@param[in] RequestId The request identifier to which the response is +expected to belong. + +@param[out] TailBufferFill If NULL, then the last buffer in ResponseSgList +is considered fixed size. Otherwise, the last +buffer is considered variable size, and on +successful return, TailBufferFill reports the +number of bytes in the last buffer. + +@retval EFI_INVALID_PARAMETER TailBufferFill is not NULL (i.e., the last +buffer is considered variable size), and +ResponseSgList->NumVec is 1. + +@retval EFI_INVALID_PARAMETER The allocated size of the first buffer does +not match sizeof(VIRTIO_FS_FUSE_RESPONSE). + +@retval EFI_PROTOCOL_ERROR The VIRTIO_FS_FUSE_RESPONSE structure in the +first buffer has not been fully populated. + +@retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Len" in the first +buffer does not equal the sum of the +individual buffer sizes (as populated). + +@retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Unique" in the first +buffer does not equal RequestId. + +@retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Error" in the first +buffer is zero, but a subsequent fixed size +buffer has not been fully populated. + +@retval EFI_DEVICE_ERROR "VIRTIO_FS_FUSE_RESPONSE.Error" in the first +buffer is nonzero. The caller may investigate +"VIRTIO_FS_FUSE_RESPONSE.Error". Note that the +completeness of the subsequent fixed size +buffers is not verified in this case. + +@retval EFI_SUCCESS Verification successful. +**/ +EFI_STATUS +VirtioFsFuseCheckResponse ( + IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, + IN UINT64 RequestId, + OUT UINTN *TailBufferFill + ) +{ +UINTN NumFixedSizeVec; +VIRTIO_FS_FUSE_RESPONSE *CommonResp; +UINT32 TotalTransferred; +UINTN Idx; + +// +// Ensured by VirtioFsSgListsValidate(). +// +ASSERT (ResponseSgList->NumVec >0 ); + +if (TailBufferFill ==NULL ) { +// +// All buffers are considered fixed size. +// + NumFixedSizeVec = ResponseSgList->NumVec; + }else { +// +// If the last buffer is variable size, then we need that buffer to be +// different from the first buffer, which is considered a +// VIRTIO_FS_FUSE_RESPONSE (fixed size) structure. +// +if (ResponseSgList->NumVec ==1 ) { +return EFI_INVALID_PARAMETER ; + } + NumFixedSizeVec = ResponseSgList->NumVec -1 ; + } + +// +// The first buffer is supposed to carry a (fully populated) +// VIRTIO_FS_FUSE_RESPONSE structure. +// +if (ResponseSgList->IoVec[0 ].Size !=sizeof *CommonResp) { +return EFI_INVALID_PARAMETER ; + } +if (ResponseSgList->IoVec[0 ].Transferred != ResponseSgList->IoVec[0 ].Size) { +return EFI_PROTOCOL_ERROR ; + } + +// +// FUSE must report the same number of bytes, written by the Virtio +// Filesystem device, as the virtio transport does. +// + CommonResp = ResponseSgList->IoVec[0 ].Buffer; + TotalTransferred =0 ; +for (Idx =0 ; Idx < ResponseSgList->NumVec; Idx++) { +// +// Integer overflow and truncation are not possible, based on +// VirtioFsSgListsValidate() and VirtioFsSgListsSubmit(). +// + TotalTransferred += (UINT32 )ResponseSgList->IoVec[Idx].Transferred; + } +if (CommonResp->Len != TotalTransferred) { +return EFI_PROTOCOL_ERROR ; + } + +// +// Enforce that FUSE match our request ID in the response. +// +if (CommonResp->Unique != RequestId) { +return EFI_PROTOCOL_ERROR ; + } + +// +// If there is an explicit error report, skip checking the transfer +// counts for the rest of the fixed size buffers. +// +if (CommonResp->Error !=0 ) { +return EFI_DEVICE_ERROR ; + } + +// +// There was no error reported, so we require that the Virtio Filesystem +// device populate all fixed size buffers. We checked this for the very first +// buffer above; let's check the rest (if any). +// +ASSERT (NumFixedSizeVec >=1 ); +for (Idx =1 ; Idx < NumFixedSizeVec; Idx++) { +if (ResponseSgList->IoVec[Idx].Transferred != + ResponseSgList->IoVec[Idx].Size) { +return EFI_PROTOCOL_ERROR ; + } + } + +// +// If the last buffer is considered variable size, report its filled size. +// +if (TailBufferFill !=NULL ) { + *TailBufferFill = ResponseSgList->IoVec[NumFixedSizeVec].Transferred; + } + +return EFI_SUCCESS ; +}Signature · 8 lines
2.19.1.3.g30247aa5d201 _______________________________________________ Virtio-fs mailing list [email protected] https://www.redhat.com/mailman/listinfo/virtio-fs
Re: [Virtio-fs] [edk2 PATCH 06/48] OvmfPkg/VirtioFsDxe: introduce the basic FUSE request/response headers
Quoted 62 lines · * Laszlo Ersek ([email protected]) wrote:
Quoted 52 lines · Dr. David Alan Gilbert
Quoted 51 lines · * Laszlo Ersek ([email protected]) wrote:
Introduce the
VIRTIO_FS_FUSE_REQUESTandVIRTIO_FS_FUSE_RESPONSEstructures, which are the common headers for the various FUSE request/response structures.Introduce the
VirtioFsFuseNewRequest()helper function for populatingVIRTIO_FS_FUSE_REQUEST, from parameters and from a VIRTIO_FS-level request counter.Introduce the
VirtioFsFuseCheckResponse()helper function for verifying most FUSE response types that begin with theVIRTIO_FS_FUSE_RESPONSEheader.Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097Signed-off-by Laszlo Ersek <[email protected]>--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 49 +++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 17 ++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 5 + OvmfPkg/VirtioFsDxe/Helpers.c | 216 ++++++++++++++++++++ 4 files changed, 287 insertions(+)OvmfPkg/Include/IndustryStandard/VirtioFs.h +14
-0@@ -44,9 +44,58 @@ typedef struct {// // The total number of request virtqueues exposed by the device (i.e., // excluding the "hiprio" queue). // UINT32 NumReqQueues; }VIRTIO_FS_CONFIG ;#pragma pack () +// +// FUSE-related definitions follow. +// +// From virtio-v1.1-cs01-87fa6b5d8155, 5.11 File System Device: "[...] The +// driver acts as the FUSE client mounting the file system. The virtio file +// system device provides the mechanism for transporting FUSE requests [...]" +// +// Unfortunately, the documentation of the FUSE wire protocol is lacking. The +// Virtio spec (as of this writing) simply defers to +// "include/uapi/linux/fuse.h" in the Linux kernel source -- see the reference +// in virtio spec file "introduction.tex", at commit 87fa6b5d8155. +// +// Of course, "include/uapi/linux/fuse.h" is a moving target (the virtio spec +// does not specify a particular FUSE interface version). The OvmfPkg code Quoted 8 lines
OvmfPkg/Include/IndustryStandard/VirtioFs.h typedef struct { · line 68
Quoted 3 lines
OvmfPkg/Include/IndustryStandard/VirtioFs.h +3
-0+// targets version 7.31, because that's the lowest version that the QEMU +// virtio-fs daemon supports at this time -- see QEMU commit 72c42e2d6551 +// ("virtiofsd: Trim out compatibility code", 2020-01-23). Fuse has it's own in built protocol versioning and negotiation, and as I remember it's the version of the header in the Linux kernel that's the definitive version. I think it would have also been safe just to take the latest released kernel version
Quoted 7 lines
7.32 (kernel commit
c6ff213fe5b8) introduces "submount support", which does not seem relevant. The strategy we follow in "OvmfPkg/Include/IndustryStandard" is: never include or convert header files from other projects whole-sale; always evaluate every structure and macro one by one for necessity, and if a definition is really needed for the driver being implemented, add that definition manually, and natively to the edk2 coding style.
The 'submount support' is probably something you don't need; note that you may end up with multiple files with the same inode number (if the host fs has submounts).
Quoted 11 lines
This approach has caused zero friction or extra maintenance work over the years, and it allows for a native look & feel. (It's a different question what people think of edk2's "native" look and feel :))
A counter-example is the Xen headers in "OvmfPkg/Include/IndustryStandard/Xen", which were mass-imported and then fixed up separately for edk2 compatibility at some point -- much to my dismay. They feel totally foreign in edk2 and they've never stopped being a thorn in my side. It's not just the headers of course: when you *use* those macros and typedefs in the actual driver code, it shows.
Quoted 2 lines
So, as long as it's up to me, OVMF never "just takes" but "adds from zero", and I do stick with the absolute minimum needed.
Yep that's fine.
Dave
Quoted 358 lines
Thanks,
LaszloQuoted 354 lines
Dave
Quoted 351 lines
OvmfPkg/Include/IndustryStandard/VirtioFs.h +31
-0+// Correspondingly, Linux's "include/uapi/linux/fuse.h" is consulted as checked +// out at commit (c6ff213fe5b8^) = d78092e4937d ("fuse: fix page dereference +// after free", 2020-09-18); that is, right before commit c6ff213fe5b8 ("fuse: +// add submount support to <uapi/linux/fuse.h>", 2020-09-18) introduces FUSE +// interface version 7.32. +// +#define VIRTIO_FS_FUSE_MAJOR 7 +#define VIRTIO_FS_FUSE_MINOR 31 + +#pragma pack (1) +// +// Request-response headers common to all request types. +// +typedef struct { +UINT32 Len; +UINT32 Opcode; +UINT64 Unique; +UINT64 NodeId; +UINT32 Uid; +UINT32 Gid; +UINT32 Pid; +UINT32 Padding; +}VIRTIO_FS_FUSE_REQUEST ; + +typedef struct { +UINT32 Len; +INT32 Error; +UINT64 Unique; +}VIRTIO_FS_FUSE_RESPONSE ; +#pragma pack () +#endif // VIRTIO_FS_H_ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +17
-0@@ -39,16 +39,17 @@ typedef struct {// field init function init depth // ----------- ------------------ ---------- UINT64 Signature;// DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio;// DriverBindingStart 0 VIRTIO_FS_LABEL Label;// VirtioFsInit 1 UINT16 QueueSize;// VirtioFsInit 1 VRING Ring;// VirtioRingInit 2 VOID *RingMap;// VirtioRingMap 2 +UINT64 RequestId;// DriverBindingStart 0 EFI_EVENT ExitBoot;// DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs;// DriverBindingStart 0 }VIRTIO_FS ;#define VIRTIO_FS_FROM_SIMPLE_FS (SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG);// @@ -127,16 +128,32 @@ VirtioFsSgListsValidate (EFI_STATUS VirtioFsSgListsSubmit ( IN OUT VIRTIO_FS *VirtioFs, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL ); +EFI_STATUS +VirtioFsFuseNewRequest ( + IN OUT VIRTIO_FS *VirtioFs, + OUT VIRTIO_FS_FUSE_REQUEST *Request, + IN UINT32 RequestSize, + IN UINT32 Opcode, + IN UINT64 NodeId + ); + +EFI_STATUS +VirtioFsFuseCheckResponse ( + IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, + IN UINT64 RequestId, + OUT UINTN *TailBufferFill + ); +// // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem // driver. // EFI_STATUS EFIAPI VirtioFsOpenVolume (OvmfPkg/VirtioFsDxe/DriverBinding.c +5
-0@@ -79,16 +79,21 @@ VirtioFsBindingStart ( goto FreeVirtioFs; } Status =VirtioFsInit (VirtioFs);if (EFI_ERROR (Status)) { goto CloseVirtio; } +// +// Initialize the FUSE request counter. +// + VirtioFs->RequestId =1 ; + Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES ,TPL_CALLBACK , VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot);if (EFI_ERROR (Status)) { goto UninitVirtioFs; } VirtioFs->SimpleFs.Revision =EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION ; VirtioFs->SimpleFs.OpenVolume = VirtioFsOpenVolume;OvmfPkg/VirtioFsDxe/Helpers.c +216
-0@@ -693,8 +693,224 @@ VirtioFsSgListsSubmit (if (!EFI_ERROR (Status) &&EFI_ERROR (UnmapStatus)) { Status = UnmapStatus; } } }return Status; } + +/** +Set up the fields of a new VIRTIO_FS_FUSE_REQUEST object. + +The function may only be called after VirtioFsInit() returns successfully and +before VirtioFsUninit() is called. + +@param[in,out] VirtioFs The Virtio Filesystem device that the request is +being prepared for. The "VirtioFs->RequestId" field +will be copied into "Request->Unique". On output (on +successful return), "VirtioFs->RequestId" will be +incremented. + +@param[out] Request The VIRTIO_FS_FUSE_REQUEST object whose fields are to +be set. + +@param[in] RequestSize The total size of the request, including +sizeof(VIRTIO_FS_FUSE_REQUEST). + +@param[in] Opcode The VIRTIO_FS_FUSE_OPCODE that identifies the command +to send. + +@param[in] NodeId The inode number of the file that the request refers +to. + +@retval EFI_INVALID_PARAMETER RequestSize is smaller than +sizeof(VIRTIO_FS_FUSE_REQUEST). + +@retval EFI_OUT_OF_RESOURCES "VirtioFs->RequestId" is MAX_UINT64, and can +be incremented no more. + +@retval EFI_SUCCESS Request has been populated, +"VirtioFs->RequestId" has been incremented. +**/ +EFI_STATUS +VirtioFsFuseNewRequest ( + IN OUT VIRTIO_FS *VirtioFs, + OUT VIRTIO_FS_FUSE_REQUEST *Request, + IN UINT32 RequestSize, + IN UINT32 Opcode, + IN UINT64 NodeId + ) +{ +if (RequestSize <sizeof *Request) { +return EFI_INVALID_PARAMETER ; + } + +if (VirtioFs->RequestId ==MAX_UINT64 ) { +return EFI_OUT_OF_RESOURCES ; + } + + Request->Len = RequestSize; + Request->Opcode = Opcode; + Request->Unique = VirtioFs->RequestId++; + Request->NodeId = NodeId; + Request->Uid =0 ; + Request->Gid =0 ; + Request->Pid =1 ; + Request->Padding =0 ; + +return EFI_SUCCESS ; +} + +/** +Check the common FUSE response format. + +The first buffer in the response scatter-gather list is assumed a +VIRTIO_FS_FUSE_RESPONSE structure. Subsequent response buffers, if any, up to +and excluding the last one, are assumed fixed size. The last response buffer +may or may not be fixed size, as specified by the caller. + +This function may only be called after VirtioFsSgListsSubmit() returns +successfully. + +@param[in] ResponseSgList The scatter-gather list that describes the +response part of the exchange -- the buffers that +the Virtio Filesystem device filled in during the +virtio transfer. + +@param[in] RequestId The request identifier to which the response is +expected to belong. + +@param[out] TailBufferFill If NULL, then the last buffer in ResponseSgList +is considered fixed size. Otherwise, the last +buffer is considered variable size, and on +successful return, TailBufferFill reports the +number of bytes in the last buffer. + +@retval EFI_INVALID_PARAMETER TailBufferFill is not NULL (i.e., the last +buffer is considered variable size), and +ResponseSgList->NumVec is 1. + +@retval EFI_INVALID_PARAMETER The allocated size of the first buffer does +not match sizeof(VIRTIO_FS_FUSE_RESPONSE). + +@retval EFI_PROTOCOL_ERROR The VIRTIO_FS_FUSE_RESPONSE structure in the +first buffer has not been fully populated. + +@retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Len" in the first +buffer does not equal the sum of the +individual buffer sizes (as populated). + +@retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Unique" in the first +buffer does not equal RequestId. + +@retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Error" in the first +buffer is zero, but a subsequent fixed size +buffer has not been fully populated. + +@retval EFI_DEVICE_ERROR "VIRTIO_FS_FUSE_RESPONSE.Error" in the first +buffer is nonzero. The caller may investigate +"VIRTIO_FS_FUSE_RESPONSE.Error". Note that the +completeness of the subsequent fixed size +buffers is not verified in this case. + +@retval EFI_SUCCESS Verification successful. +**/ +EFI_STATUS +VirtioFsFuseCheckResponse ( + IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, + IN UINT64 RequestId, + OUT UINTN *TailBufferFill + ) +{ +UINTN NumFixedSizeVec; +VIRTIO_FS_FUSE_RESPONSE *CommonResp; +UINT32 TotalTransferred; +UINTN Idx; + +// +// Ensured by VirtioFsSgListsValidate(). +// +ASSERT (ResponseSgList->NumVec >0 ); + +if (TailBufferFill ==NULL ) { +// +// All buffers are considered fixed size. +// + NumFixedSizeVec = ResponseSgList->NumVec; + }else { +// +// If the last buffer is variable size, then we need that buffer to be +// different from the first buffer, which is considered a +// VIRTIO_FS_FUSE_RESPONSE (fixed size) structure. +// +if (ResponseSgList->NumVec ==1 ) { +return EFI_INVALID_PARAMETER ; + } + NumFixedSizeVec = ResponseSgList->NumVec -1 ; + } + +// +// The first buffer is supposed to carry a (fully populated) +// VIRTIO_FS_FUSE_RESPONSE structure. +// +if (ResponseSgList->IoVec[0 ].Size !=sizeof *CommonResp) { +return EFI_INVALID_PARAMETER ; + } +if (ResponseSgList->IoVec[0 ].Transferred != ResponseSgList->IoVec[0 ].Size) { +return EFI_PROTOCOL_ERROR ; + } + +// +// FUSE must report the same number of bytes, written by the Virtio +// Filesystem device, as the virtio transport does. +// + CommonResp = ResponseSgList->IoVec[0 ].Buffer; + TotalTransferred =0 ; +for (Idx =0 ; Idx < ResponseSgList->NumVec; Idx++) { +// +// Integer overflow and truncation are not possible, based on +// VirtioFsSgListsValidate() and VirtioFsSgListsSubmit(). +// + TotalTransferred += (UINT32 )ResponseSgList->IoVec[Idx].Transferred; + } +if (CommonResp->Len != TotalTransferred) { +return EFI_PROTOCOL_ERROR ; + } + +// +// Enforce that FUSE match our request ID in the response. +// +if (CommonResp->Unique != RequestId) { +return EFI_PROTOCOL_ERROR ; + } + +// +// If there is an explicit error report, skip checking the transfer +// counts for the rest of the fixed size buffers. +// +if (CommonResp->Error !=0 ) { +return EFI_DEVICE_ERROR ; + } + +// +// There was no error reported, so we require that the Virtio Filesystem +// device populate all fixed size buffers. We checked this for the very first +// buffer above; let's check the rest (if any). +// +ASSERT (NumFixedSizeVec >=1 ); +for (Idx =1 ; Idx < NumFixedSizeVec; Idx++) { +if (ResponseSgList->IoVec[Idx].Transferred != + ResponseSgList->IoVec[Idx].Size) { +return EFI_PROTOCOL_ERROR ; + } + } + +// +// If the last buffer is considered variable size, report its filled size. +// +if (TailBufferFill !=NULL ) { + *TailBufferFill = ResponseSgList->IoVec[NumFixedSizeVec].Transferred; + } + +return EFI_SUCCESS ; +}Signature · 8 lines
2.19.1.3.g30247aa5d201 _______________________________________________ Virtio-fs mailing list [email protected] https://www.redhat.com/mailman/listinfo/virtio-fs
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Virtio-fs] [edk2 PATCH 06/48] OvmfPkg/VirtioFsDxe: introduce the basic FUSE request/response headers
In reply to Laszlo ErsekQuoted 2 lines · Laszlo Ersek
So, as long as it's up to me, OVMF never "just takes" but "adds from zero", and I do stick with the absolute minimum needed.
... I mean this specific patch only adds the two most basic headers really (VIRTIO_FS_FUSE_REQUEST, VIRTIO_FS_FUSE_RESPONSE), and the rest of the structs are introduced gradually over the series -- only when an actual FUSE request type needs to be sent for the desired functionality. So it's not a "dump of definitions" at any point in the series.
The complete set of structures+flags, defined in the FUSE 7.31 interface version, never lands in its entirety in "OvmfPkg/Include/IndustryStandard".
Thanks,
Laszlo
PATCH 7/48 OvmfPkg/VirtioFsDxe: map "errno" values to EFI_STATUS
In reply to Laszlo ErsekThe VirtioFsFuseCheckResponse() function dedicates the EFI_DEVICE_ERROR status code to the case when the Virtio Filesystem device explicitly returns an error via the "VIRTIO_FS_FUSE_RESPONSE.Error" field.
Said field effectively carries a Linux "errno" value. Introduce a helper function for mapping "errno" values to (hopefully) reasonable EFI_STATUS codes. This way we'll be able to propagate "errno" values as EFI_STATUS return codes along the UEFI call stack -- in some detail anyway.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 5 + OvmfPkg/VirtioFsDxe/Helpers.c | 200 ++++++++++++++++++++ 2 files changed, 205 insertions(+)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +5 -0
@@ -144,16 +144,21 @@ VirtioFsFuseNewRequest (EFI_STATUS VirtioFsFuseCheckResponse ( IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, IN UINT64 RequestId, OUT UINTN *TailBufferFill ); +EFI_STATUS +VirtioFsErrnoToEfiStatus ( + IN INT32 Errno + ); +// // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem // driver. // EFI_STATUS EFIAPI VirtioFsOpenVolume (
OvmfPkg/VirtioFsDxe/Helpers.c +200 -0
208 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 8/48 OvmfPkg/VirtioFsDxe: submit the FUSE_INIT request to the device
In reply to Laszlo ErsekSubmit the FUSE_INIT request to the Virtio Filesystem device, for starting the FUSE session.
The FUSE_INIT request is logged by the virtio-fs daemon, with this patch applied, when (for example) using the "CONNECT" UEFI shell command.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 31 +++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 13 +- OvmfPkg/VirtioFsDxe/DriverBinding.c | 8 +- OvmfPkg/VirtioFsDxe/FuseInit.c | 132 ++++++++++++++++++++ OvmfPkg/VirtioFsDxe/Helpers.c | 5 +- 6 files changed, 182 insertions(+), 8 deletions(-)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +31 -0
@@ -71,16 +71,23 @@ typedef struct {// out at commit (c6ff213fe5b8^) = d78092e4937d ("fuse: fix page dereference // after free", 2020-09-18); that is, right before commit c6ff213fe5b8 ("fuse: // add submount support to <uapi/linux/fuse.h>", 2020-09-18) introduces FUSE // interface version 7.32. // #define VIRTIO_FS_FUSE_MAJOR 7#define VIRTIO_FS_FUSE_MINOR 31 +// +// FUSE operation codes. +// +typedef enum { + VirtioFsFuseOpInit =26 , +}VIRTIO_FS_FUSE_OPCODE ; +#pragma pack (1)// // Request-response headers common to all request types. // typedef struct { UINT32 Len; UINT32 Opcode; UINT64 Unique;
@@ -91,11 +98,35 @@ typedef struct { UINT32 Padding; }VIRTIO_FS_FUSE_REQUEST ;typedef struct {UINT32 Len;INT32 Error;UINT64 Unique; }VIRTIO_FS_FUSE_RESPONSE ; + +// +// Headers for VirtioFsFuseOpInit. +// +typedef struct { +UINT32 Major; +UINT32 Minor; +UINT32 MaxReadahead; +UINT32 Flags; +}VIRTIO_FS_FUSE_INIT_REQUEST ; + +typedef struct { +UINT32 Major; +UINT32 Minor; +UINT32 MaxReadahead; +UINT32 Flags; +UINT16 MaxBackground; +UINT16 CongestionThreshold; +UINT32 MaxWrite; +UINT32 TimeGran; +UINT16 MaxPages; +UINT16 MapAlignment; +UINT32 Unused[8 ]; +}VIRTIO_FS_FUSE_INIT_RESPONSE ;#pragma pack ()#endif // VIRTIO_FS_H_
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -77,16 +77,17 @@ [Defines] ENTRY_POINT = VirtioFsEntryPoint [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c + FuseInit.c Helpers.c SimpleFsOpenVolume.c VirtioFsDxe.h [LibraryClasses] BaseLib DebugLib MemoryAllocationLib
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +11 -2
@@ -39,17 +39,17 @@ typedef struct {// field init function init depth // ----------- ------------------ ---------- UINT64 Signature;// DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio;// DriverBindingStart 0 VIRTIO_FS_LABEL Label;// VirtioFsInit 1 UINT16 QueueSize;// VirtioFsInit 1 VRING Ring;// VirtioRingInit 2 VOID *RingMap;// VirtioRingMap 2 -UINT64 RequestId;// DriverBindingStart 0 +UINT64 RequestId;// FuseInitSession 1 EFI_EVENT ExitBoot;// DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs;// DriverBindingStart 0 }VIRTIO_FS ;#define VIRTIO_FS_FROM_SIMPLE_FS (SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG);//
@@ -133,32 +133,41 @@ VirtioFsSgListsSubmit ( IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL );EFI_STATUS VirtioFsFuseNewRequest ( IN OUT VIRTIO_FS *VirtioFs, OUT VIRTIO_FS_FUSE_REQUEST *Request, IN UINT32 RequestSize, - IN UINT32 Opcode, + IN VIRTIO_FS_FUSE_OPCODE Opcode, IN UINT64 NodeId );EFI_STATUS VirtioFsFuseCheckResponse ( IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, IN UINT64 RequestId, OUT UINTN *TailBufferFill );EFI_STATUS VirtioFsErrnoToEfiStatus ( IN INT32 Errno ); +// +// Wrapper functions for FUSE commands (primitives). +// + +EFI_STATUS +VirtioFsFuseInitSession ( + IN OUT VIRTIO_FS *VirtioFs + ); +// // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem // driver. // EFI_STATUS EFIAPI VirtioFsOpenVolume (
OvmfPkg/VirtioFsDxe/DriverBinding.c +4 -4
@@ -79,20 +79,20 @@ VirtioFsBindingStart ( goto FreeVirtioFs; } Status =VirtioFsInit (VirtioFs);if (EFI_ERROR (Status)) { goto CloseVirtio; } -// -// Initialize the FUSE request counter. -// - VirtioFs->RequestId =1 ; + Status =VirtioFsFuseInitSession (VirtioFs); +if (EFI_ERROR (Status)) { + goto UninitVirtioFs; + } Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES ,TPL_CALLBACK , VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot);if (EFI_ERROR (Status)) { goto UninitVirtioFs; } VirtioFs->SimpleFs.Revision =EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION ;
OvmfPkg/VirtioFsDxe/FuseInit.c new file +132 -0
132 lines not on this page · raw message
OvmfPkg/VirtioFsDxe/Helpers.c +3 -2
@@ -716,33 +716,34 @@ VirtioFsSgListsSubmit (@param[in] RequestSize The total size of the request, including sizeof(VIRTIO_FS_FUSE_REQUEST). @param[in] Opcode The VIRTIO_FS_FUSE_OPCODE that identifies the command to send. @param[in] NodeId The inode number of the file that the request refers -to. +to. When Opcode is VirtioFsFuseOpInit, NodeId is +ignored by the Virtio Filesystem device. @retval EFI_INVALID_PARAMETER RequestSize is smaller than sizeof(VIRTIO_FS_FUSE_REQUEST). @retval EFI_OUT_OF_RESOURCES "VirtioFs->RequestId" is MAX_UINT64, and can be incremented no more. @retval EFI_SUCCESS Request has been populated, "VirtioFs->RequestId" has been incremented. **/ EFI_STATUS VirtioFsFuseNewRequest ( IN OUT VIRTIO_FS *VirtioFs, OUT VIRTIO_FS_FUSE_REQUEST *Request, IN UINT32 RequestSize, - IN UINT32 Opcode, + IN VIRTIO_FS_FUSE_OPCODE Opcode, IN UINT64 NodeId ) {if (RequestSize <sizeof *Request) {return EFI_INVALID_PARAMETER ; }if (VirtioFs->RequestId ==MAX_UINT64 ) {
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 9/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_OPENDIR
In reply to Laszlo ErsekAdd the VirtioFsFuseOpenDir() function, for sending the FUSE_OPENDIR command to the Virtio Filesystem device.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 15 +++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 ++ OvmfPkg/VirtioFsDxe/FuseOpenDir.c | 120 ++++++++++++++++++++ 4 files changed, 143 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +15 -0
@@ -76,16 +76,17 @@ typedef struct {#define VIRTIO_FS_FUSE_MAJOR 7#define VIRTIO_FS_FUSE_MINOR 31// // FUSE operation codes. // typedef enum { VirtioFsFuseOpInit =26 , + VirtioFsFuseOpOpenDir =27 , }VIRTIO_FS_FUSE_OPCODE ;#pragma pack (1)// // Request-response headers common to all request types. // typedef struct { UINT32 Len;
@@ -122,11 +123,25 @@ typedef struct {UINT16 MaxBackground;UINT16 CongestionThreshold;UINT32 MaxWrite;UINT32 TimeGran;UINT16 MaxPages;UINT16 MapAlignment; UINT32 Unused[8]; }VIRTIO_FS_FUSE_INIT_RESPONSE ; + +// +// Headers for VirtioFsFuseOpOpenDir. +// +typedef struct { +UINT32 Flags; +UINT32 Unused; +}VIRTIO_FS_FUSE_OPEN_REQUEST ; + +typedef struct { +UINT64 FileHandle; +UINT32 OpenFlags; +UINT32 Padding; +}VIRTIO_FS_FUSE_OPEN_RESPONSE ;#pragma pack ()#endif // VIRTIO_FS_H_
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -78,16 +78,17 @@ [Defines] [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c FuseInit.c + FuseOpenDir.c Helpers.c SimpleFsOpenVolume.c VirtioFsDxe.h [LibraryClasses] BaseLib DebugLib MemoryAllocationLib
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +7 -0
@@ -158,16 +158,23 @@ VirtioFsErrnoToEfiStatus (// Wrapper functions for FUSE commands (primitives). // EFI_STATUS VirtioFsFuseInitSession ( IN OUT VIRTIO_FS *VirtioFs ); +EFI_STATUS +VirtioFsFuseOpenDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + OUT UINT64 *FuseHandle + ); +// // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem // driver. // EFI_STATUS EFIAPI VirtioFsOpenVolume (
OvmfPkg/VirtioFsDxe/FuseOpenDir.c new file +120 -0
120 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 10/48 OvmfPkg/VirtioFsDxe: add shared wrapper for FUSE_RELEASE / FUSE_RELEASEDIR
In reply to Laszlo ErsekThe FUSE_RELEASE and FUSE_RELEASEDIR commands only differ in the opcode. Add a common function called VirtioFsFuseReleaseFileOrDir() for sending either command.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 12 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseRelease.c | 121 ++++++++++++++++++++ 4 files changed, 142 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +12 -0
@@ -75,18 +75,20 @@ typedef struct {// #define VIRTIO_FS_FUSE_MAJOR 7#define VIRTIO_FS_FUSE_MINOR 31// // FUSE operation codes. // typedef enum { + VirtioFsFuseOpRelease =18 , VirtioFsFuseOpInit =26 , VirtioFsFuseOpOpenDir =27 , + VirtioFsFuseOpReleaseDir =29 , }VIRTIO_FS_FUSE_OPCODE ;#pragma pack (1)// // Request-response headers common to all request types. // typedef struct { UINT32 Len;
@@ -100,16 +102,26 @@ typedef struct { }VIRTIO_FS_FUSE_REQUEST ;typedef struct {UINT32 Len;INT32 Error;UINT64 Unique; }VIRTIO_FS_FUSE_RESPONSE ; +// +// Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir. +// +typedef struct { +UINT64 FileHandle; +UINT32 Flags; +UINT32 ReleaseFlags; +UINT64 LockOwner; +}VIRTIO_FS_FUSE_RELEASE_REQUEST ; +// // Headers for VirtioFsFuseOpInit. // typedef struct { UINT32 Major; UINT32 Minor; UINT32 MaxReadahead; UINT32 Flags;
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -79,16 +79,17 @@ [Defines] [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c FuseInit.c FuseOpenDir.c + FuseRelease.c Helpers.c SimpleFsOpenVolume.c VirtioFsDxe.h [LibraryClasses] BaseLib DebugLib MemoryAllocationLib
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +8 -0
@@ -153,16 +153,24 @@ EFI_STATUSVirtioFsErrnoToEfiStatus ( IN INT32 Errno );// // Wrapper functions for FUSE commands (primitives). // +EFI_STATUS +VirtioFsFuseReleaseFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir + ); +EFI_STATUS VirtioFsFuseInitSession ( IN OUT VIRTIO_FS *VirtioFs ); EFI_STATUS VirtioFsFuseOpenDir ( IN OUT VIRTIO_FS *VirtioFs,
OvmfPkg/VirtioFsDxe/FuseRelease.c new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 11/48 OvmfPkg/VirtioFsDxe: implement EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume()
In reply to Laszlo ErsekWith the help of the VirtioFsFuseOpenDir() and VirtioFsFuseReleaseFileOrDir() functions introduced previously, we can now open and close the root directory. So let's implement EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume().
OpenVolume() creates a new EFI_FILE_PROTOCOL object -- a reference to the root directory of the filesystem. Thus, we have to start tracking references to EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, lest we unbind the virtio-fs device while files are open.
There are two methods that release an EFI_FILE_PROTOCOL object: the Close() and the Delete() member functions. In particular, they are not allowed to fail with regard to resource management -- they must release resources unconditionally. Thus, for rolling back the resource accounting that we do in EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume(), we have to implement the first versions of EFI_FILE_PROTOCOL.Close() and EFI_FILE_PROTOCOL.Delete() in this patch as well.
With this patch applied, the UEFI shell can enter the root directory of the Virtio Filesystem (such as with the "FS3:" shell command), and the "DIR" shell command exercises FUSE_OPENDIR and FUSE_RELEASEDIR, according to the virtiofsd log. The "DIR" command reports the root directory as if it were empty; probably because at this time, we only allow the shell to open and to close the root directory, but not to read it.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 5 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 10 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 117 ++++++++++++++++++++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 5 + OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 48 ++++++++ OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 29 +++++ OvmfPkg/VirtioFsDxe/SimpleFsFlush.c | 18 +++ OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c | 21 ++++ OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c | 20 ++++ OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 22 ++++ OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 57 +++++++++- OvmfPkg/VirtioFsDxe/SimpleFsRead.c | 20 ++++ OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c | 21 ++++ OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c | 20 ++++ OvmfPkg/VirtioFsDxe/SimpleFsWrite.c | 20 ++++ 15 files changed, 432 insertions(+), 1 deletion(-)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +5 -0
@@ -71,16 +71,21 @@ typedef struct {// out at commit (c6ff213fe5b8^) = d78092e4937d ("fuse: fix page dereference // after free", 2020-09-18); that is, right before commit c6ff213fe5b8 ("fuse: // add submount support to <uapi/linux/fuse.h>", 2020-09-18) introduces FUSE // interface version 7.32. // #define VIRTIO_FS_FUSE_MAJOR 7#define VIRTIO_FS_FUSE_MINOR 31 +// +// The inode number of the root directory. +// +#define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 +// // FUSE operation codes. // typedef enum { VirtioFsFuseOpRelease = 18, VirtioFsFuseOpInit = 26, VirtioFsFuseOpOpenDir = 27, VirtioFsFuseOpReleaseDir = 29,
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +10 -0
@@ -81,17 +81,27 @@ [Packages] OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c FuseInit.c FuseOpenDir.c FuseRelease.c Helpers.c + SimpleFsClose.c + SimpleFsDelete.c + SimpleFsFlush.c + SimpleFsGetInfo.c + SimpleFsGetPosition.c + SimpleFsOpen.c SimpleFsOpenVolume.c + SimpleFsRead.c + SimpleFsSetInfo.c + SimpleFsSetPosition.c + SimpleFsWrite.c VirtioFsDxe.h [LibraryClasses] BaseLib DebugLib MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +117 -0
174 lines not on this page · raw message
OvmfPkg/VirtioFsDxe/DriverBinding.c +5 -0
@@ -90,16 +90,17 @@ VirtioFsBindingStart ( } Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES ,TPL_CALLBACK , VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot);if (EFI_ERROR (Status)) { goto UninitVirtioFs; } +InitializeListHead (&VirtioFs->OpenFiles); VirtioFs->SimpleFs.Revision =EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION ; VirtioFs->SimpleFs.OpenVolume = VirtioFsOpenVolume; Status = gBS->InstallProtocolInterface (&ControllerHandle, &gEfiSimpleFileSystemProtocolGuid,EFI_NATIVE_INTERFACE , &VirtioFs->SimpleFs);if (EFI_ERROR (Status)) { goto CloseExitBoot;
@@ -144,16 +145,20 @@ VirtioFsBindingStop ( This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL);if (EFI_ERROR (Status)) {return Status; } VirtioFs =VIRTIO_FS_FROM_SIMPLE_FS (SimpleFs); +if (!IsListEmpty (&VirtioFs->OpenFiles)) { +return EFI_ACCESS_DENIED ; + } + Status = gBS->UninstallProtocolInterface (ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, SimpleFs);if (EFI_ERROR (Status)) {return Status; } Status = gBS->CloseEvent (VirtioFs->ExitBoot);ASSERT_EFI_ERROR (Status);
OvmfPkg/VirtioFsDxe/SimpleFsClose.c new file +48 -0
48 lines not on this page · raw message
OvmfPkg/VirtioFsDxe/SimpleFsDelete.c new file +29 -0
@@ -0,0 +1,29 @@ +/** @file +EFI_FILE_PROTOCOL.Delete() member function for the Virtio Filesystem driver. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileDelete ( + IN EFI_FILE_PROTOCOL *This + ) +{ +// +// At this point, the implementation is only suitable for closing the +// VIRTIO_FS_FILE that was created by VirtioFsOpenVolume(). +// +// Actually deleting the root directory is not possible, so we're only going +// to release resources, and return EFI_WARN_DELETE_FAILURE. +// +// In order to release resources, VirtioFsSimpleFileClose() is just right +// here. +// +VirtioFsSimpleFileClose (This); +return EFI_WARN_DELETE_FAILURE ; +}
OvmfPkg/VirtioFsDxe/SimpleFsFlush.c new file +18 -0
@@ -0,0 +1,18 @@ +/** @file +EFI_FILE_PROTOCOL.Flush() member function for the Virtio Filesystem driver. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileFlush ( + IN EFI_FILE_PROTOCOL *This + ) +{ +return EFI_NO_MEDIA ; +}
OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c new file +21 -0
@@ -0,0 +1,21 @@ +/** @file +EFI_FILE_PROTOCOL.GetInfo() member function for the Virtio Filesystem driver. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileGetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ +return EFI_NO_MEDIA ; +}
OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c new file +20 -0
@@ -0,0 +1,20 @@ +/** @file +EFI_FILE_PROTOCOL.GetPosition() member function for the Virtio Filesystem +driver. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileGetPosition ( + IN EFI_FILE_PROTOCOL *This, + OUT UINT64 *Position + ) +{ +return EFI_DEVICE_ERROR ; +}
OvmfPkg/VirtioFsDxe/SimpleFsOpen.c new file +22 -0
@@ -0,0 +1,22 @@ +/** @file +EFI_FILE_PROTOCOL.Open() member function for the Virtio Filesystem driver. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileOpen ( + IN EFI_FILE_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **NewHandle, + IN CHAR16 *FileName, + IN UINT64 OpenMode, + IN UINT64 Attributes + ) +{ +return EFI_NO_MEDIA ; +}
OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +56 -1
81 lines not on this page · raw message
OvmfPkg/VirtioFsDxe/SimpleFsRead.c new file +20 -0
@@ -0,0 +1,20 @@ +/** @file +EFI_FILE_PROTOCOL.Read() member function for the Virtio Filesystem driver. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileRead ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ +return EFI_NO_MEDIA ; +}
OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c new file +21 -0
@@ -0,0 +1,21 @@ +/** @file +EFI_FILE_PROTOCOL.SetInfo() member function for the Virtio Filesystem driver. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileSetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ +return EFI_NO_MEDIA ; +}
OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c new file +20 -0
@@ -0,0 +1,20 @@ +/** @file +EFI_FILE_PROTOCOL.SetPosition() member function for the Virtio Filesystem +driver. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileSetPosition ( + IN EFI_FILE_PROTOCOL *This, + IN UINT64 Position + ) +{ +return EFI_DEVICE_ERROR ; +}
OvmfPkg/VirtioFsDxe/SimpleFsWrite.c new file +20 -0
@@ -0,0 +1,20 @@ +/** @file +EFI_FILE_PROTOCOL.Write() member function for the Virtio Filesystem driver. + +Copyright (C) 2020, Red Hat, Inc. + +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileWrite ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + IN VOID *Buffer + ) +{ +return EFI_NO_MEDIA ; +}
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 12/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_FORGET
In reply to Laszlo ErsekAdd the VirtioFsFuseForget() function, for sending the FUSE_FORGET command to the Virtio Filesystem device.
This is an unusual command in that it doesn't generate any response from the FUSE server.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 8 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 6 ++ OvmfPkg/VirtioFsDxe/FuseForget.c | 85 ++++++++++++++++++++ 4 files changed, 100 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +8 -0
@@ -80,16 +80,17 @@ typedef struct {// The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1// // FUSE operation codes. // typedef enum { + VirtioFsFuseOpForget =2 , VirtioFsFuseOpRelease =18 , VirtioFsFuseOpInit =26 , VirtioFsFuseOpOpenDir =27 , VirtioFsFuseOpReleaseDir =29 , }VIRTIO_FS_FUSE_OPCODE ;#pragma pack (1)//
@@ -107,16 +108,23 @@ typedef struct { }VIRTIO_FS_FUSE_REQUEST ;typedef struct {UINT32 Len;INT32 Error;UINT64 Unique; }VIRTIO_FS_FUSE_RESPONSE ; +// +// Header for VirtioFsFuseOpForget. +// +typedef struct { +UINT64 NumberOfLookups; +}VIRTIO_FS_FUSE_FORGET_REQUEST ; +// // Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir. // typedef struct { UINT64 FileHandle; UINT32 Flags; UINT32 ReleaseFlags; UINT64 LockOwner;
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -77,16 +77,17 @@ [Defines] ENTRY_POINT = VirtioFsEntryPoint [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c + FuseForget.c FuseInit.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +6 -0
@@ -190,16 +190,22 @@ EFI_STATUSVirtioFsErrnoToEfiStatus ( IN INT32 Errno );// // Wrapper functions for FUSE commands (primitives). // +EFI_STATUS +VirtioFsFuseForget ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId + ); +EFI_STATUS VirtioFsFuseReleaseFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir );
OvmfPkg/VirtioFsDxe/FuseForget.c new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 13/48 OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_FSYNC / FUSE_FSYNCDIR
In reply to Laszlo ErsekThe FUSE_FSYNC and FUSE_FSYNCDIR commands only differ in the opcode. Add a common function for wrapping both.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 11 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseFsync.c | 121 ++++++++++++++++++++ 4 files changed, 141 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +11 -0
@@ -82,19 +82,21 @@ typedef struct {#define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1// // FUSE operation codes. // typedef enum { VirtioFsFuseOpForget =2 , VirtioFsFuseOpRelease =18 , + VirtioFsFuseOpFsync =20 , VirtioFsFuseOpInit =26 , VirtioFsFuseOpOpenDir =27 , VirtioFsFuseOpReleaseDir =29 , + VirtioFsFuseOpFsyncDir =30 , }VIRTIO_FS_FUSE_OPCODE ;#pragma pack (1)// // Request-response headers common to all request types. // typedef struct { UINT32 Len;
@@ -125,16 +127,25 @@ typedef struct {// typedef struct {UINT64 FileHandle;UINT32 Flags;UINT32 ReleaseFlags;UINT64 LockOwner; }VIRTIO_FS_FUSE_RELEASE_REQUEST ; +// +// Header for VirtioFsFuseOpFsync and VirtioFsFuseOpFsyncDir. +// +typedef struct { +UINT64 FileHandle; +UINT32 FsyncFlags; +UINT32 Padding; +}VIRTIO_FS_FUSE_FSYNC_REQUEST ; +// // Headers for VirtioFsFuseOpInit. // typedef struct { UINT32 Major; UINT32 Minor; UINT32 MaxReadahead; UINT32 Flags;
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -78,16 +78,17 @@ [Defines] [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c FuseForget.c + FuseFsync.c FuseInit.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +8 -0
@@ -204,16 +204,24 @@ VirtioFsFuseForget (EFI_STATUS VirtioFsFuseReleaseFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir ); +EFI_STATUS +VirtioFsFuseFsyncFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir + ); +EFI_STATUS VirtioFsFuseInitSession ( IN OUT VIRTIO_FS *VirtioFs ); EFI_STATUS VirtioFsFuseOpenDir ( IN OUT VIRTIO_FS *VirtioFs,
OvmfPkg/VirtioFsDxe/FuseFsync.c new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 14/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_FLUSH
In reply to Laszlo ErsekAdd the VirtioFsFuseFlush() function, for sending the FUSE_FLUSH command to the Virtio Filesystem device.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 11 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 ++ OvmfPkg/VirtioFsDxe/FuseFlush.c | 111 ++++++++++++++++++++ 4 files changed, 130 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +11 -0
@@ -83,16 +83,17 @@ typedef struct {// // FUSE operation codes. // typedef enum { VirtioFsFuseOpForget =2 , VirtioFsFuseOpRelease =18 , VirtioFsFuseOpFsync =20 , + VirtioFsFuseOpFlush =25 , VirtioFsFuseOpInit =26 , VirtioFsFuseOpOpenDir =27 , VirtioFsFuseOpReleaseDir =29 , VirtioFsFuseOpFsyncDir =30 , }VIRTIO_FS_FUSE_OPCODE ;#pragma pack (1)//
@@ -136,16 +137,26 @@ typedef struct {// Header for VirtioFsFuseOpFsync and VirtioFsFuseOpFsyncDir. // typedef struct {UINT64 FileHandle;UINT32 FsyncFlags;UINT32 Padding; }VIRTIO_FS_FUSE_FSYNC_REQUEST ; +// +// Header for VirtioFsFuseOpFlush. +// +typedef struct { +UINT64 FileHandle; +UINT32 Unused; +UINT32 Padding; +UINT64 LockOwner; +}VIRTIO_FS_FUSE_FLUSH_REQUEST ; +// // Headers for VirtioFsFuseOpInit. // typedef struct { UINT32 Major; UINT32 Minor; UINT32 MaxReadahead; UINT32 Flags;
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -77,16 +77,17 @@ [Defines] ENTRY_POINT = VirtioFsEntryPoint [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c + FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +7 -0
@@ -212,16 +212,23 @@ VirtioFsFuseReleaseFileOrDir (EFI_STATUS VirtioFsFuseFsyncFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir ); +EFI_STATUS +VirtioFsFuseFlush ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle + ); +EFI_STATUS VirtioFsFuseInitSession ( IN OUT VIRTIO_FS *VirtioFs ); EFI_STATUS VirtioFsFuseOpenDir ( IN OUT VIRTIO_FS *VirtioFs,
OvmfPkg/VirtioFsDxe/FuseFlush.c new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 15/48 OvmfPkg/VirtioFsDxe: flush, sync, release and forget in Close() / Delete()
In reply to Laszlo ErsekThe two member functions that free the EFI_FILE_PROTOCOL object are Close() and Delete(). Before we create VIRTIO_FS_FILE objects with EFI_FILE_PROTOCOL.Open() later in this patch series, extend each of these "destructor" functions to get rid of the FuseHandle and NodeId resources properly -- in a way that matches each function's own purpose.
For the time being, VirtioFsSimpleFileDelete() only gets a reminder about its core task (namely, removing the file), as the needed machinery will become only later. But we can already outline the "task list", and deal with the FuseHandle and NodeId resources. The "task list" of VirtioFsSimpleFileDelete() is different from that of VirtioFsSimpleFileClose(), thus both destructors diverge at this point.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 1 + OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 34 ++++++++---- OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 55 +++++++++++++++++--- OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 1 + 4 files changed, 74 insertions(+), 17 deletions(-)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +1 -0
@@ -105,16 +105,17 @@ typedef struct {// // Private context structure that exposes EFI_FILE_PROTOCOL on top of an open // FUSE file reference. // typedef struct { UINT64 Signature; EFI_FILE_PROTOCOL SimpleFile; BOOLEAN IsDirectory; + BOOLEAN IsOpenForWriting; VIRTIO_FS *OwnerFs; LIST_ENTRY OpenFilesEntry; // // In the FUSE wire protocol, every request except FUSE_INIT refers to a // file, namely by the "VIRTIO_FS_FUSE_REQUEST.NodeId" field; that is, by the // inode number of the file. However, some of the FUSE requests that we need // for some of the EFI_FILE_PROTOCOL member functions require an open file // handle *in addition* to the inode number. For simplicity, whenever a
OvmfPkg/VirtioFsDxe/SimpleFsClose.c +25 -9
@@ -19,30 +19,46 @@ VirtioFsSimpleFileClose ( {VIRTIO_FS_FILE *VirtioFsFile;VIRTIO_FS *VirtioFs; VirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); VirtioFs = VirtioFsFile->OwnerFs;// -// At this point, the implementation is only suitable for closing the -// VIRTIO_FS_FILE that was created by VirtioFsOpenVolume(). +// All actions in this function are "best effort"; the UEFI spec requires +// EFI_FILE_PROTOCOL.Close() to sync all data to the device, but it also +// requires EFI_FILE_PROTOCOL.Close() to release resources unconditionally, +// and to return EFI_SUCCESS unconditionally. // -ASSERT (VirtioFsFile->IsDirectory); -ASSERT (VirtioFsFile->NodeId ==VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID ); -// -// Close the root directory. -// -// Ignore any errors, because EFI_FILE_PROTOCOL.Close() is required to -// release the EFI_FILE_PROTOCOL object unconditionally. +// Flush, sync, release, and (if needed) forget. If any action fails, we +// still try the others. // +if (VirtioFsFile->IsOpenForWriting) { +if (!VirtioFsFile->IsDirectory) { +VirtioFsFuseFlush (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle); + } + +VirtioFsFuseFsyncFileOrDir (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory); + } +VirtioFsFuseReleaseFileOrDir (VirtioFs, VirtioFsFile->NodeId, VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory); +// +// VirtioFsFile->FuseHandle is gone at this point, but VirtioFsFile->NodeId +// is still valid. If we've known VirtioFsFile->NodeId from a lookup, then +// now we should ask the server to forget it *once*. +// +if (VirtioFsFile->NodeId !=VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID ) { +VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId); + } +// // One fewer file left open for the owner filesystem. // RemoveEntryList (&VirtioFsFile->OpenFilesEntry);FreePool (VirtioFsFile);return EFI_SUCCESS ; }
OvmfPkg/VirtioFsDxe/SimpleFsDelete.c +47 -8
76 lines not on this page · raw message
OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +1 -0
@@ -57,16 +57,17 @@ VirtioFsOpenVolume ( VirtioFsFile->SimpleFile.Read = VirtioFsSimpleFileRead; VirtioFsFile->SimpleFile.Write = VirtioFsSimpleFileWrite; VirtioFsFile->SimpleFile.GetPosition = VirtioFsSimpleFileGetPosition; VirtioFsFile->SimpleFile.SetPosition = VirtioFsSimpleFileSetPosition; VirtioFsFile->SimpleFile.GetInfo = VirtioFsSimpleFileGetInfo; VirtioFsFile->SimpleFile.SetInfo = VirtioFsSimpleFileSetInfo; VirtioFsFile->SimpleFile.Flush = VirtioFsSimpleFileFlush; VirtioFsFile->IsDirectory = TRUE; + VirtioFsFile->IsOpenForWriting = FALSE; VirtioFsFile->OwnerFs = VirtioFs; VirtioFsFile->NodeId =VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID ; VirtioFsFile->FuseHandle = RootDirHandle;// // One more file open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry);
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 16/48 OvmfPkg/VirtioFsDxe: add helper for appending and sanitizing paths
In reply to Laszlo ErsekEFI_FILE_PROTOCOL.Open() -- for opening files -- and EFI_FILE_PROTOCOL.SetInfo() -- for renaming files -- will require us to append a relative UEFI pathname to an absolute base pathname. In turn, components of the resultant pathnames will have to be sent to virtiofsd, which does not consume UEFI-style pathnames.
We're going to maintain the base pathnames in canonical POSIX format:
- absolute (starts with "/"),
- dot (.) and dot-dot (..) components resolved/removed,
- uses forward slashes,
- sequences of slashes collapsed,
- printable ASCII character set,
- CHAR8 encoding,
- no trailing slash except for the root directory itself,
- length at most VIRTIO_FS_MAX_PATHNAME_LENGTH.
Add a helper function that can append a UEFI pathname to such a base pathname, and produce the result in conformance with the same invariants.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 32 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 474 ++++++++++++++++++++ 3 files changed, 507 insertions(+)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -99,16 +99,17 @@ [Sources] SimpleFsRead.c SimpleFsSetInfo.c SimpleFsSetPosition.c SimpleFsWrite.c VirtioFsDxe.h [LibraryClasses] BaseLib + BaseMemoryLib DebugLib MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint VirtioLib [Protocols] gEfiComponentName2ProtocolGuid ## PRODUCES
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +32 -0
@@ -17,16 +17,40 @@#include <Protocol/VirtioDevice.h> // VIRTIO_DEVICE_PROTOCOL #include <Uefi/UefiBaseType.h> // EFI_EVENT #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S')#define VIRTIO_FS_FILE_SIG \ SIGNATURE_64 ('V', 'I', 'O', 'F', 'S', 'F', 'I', 'L') +// +// The following limit applies to two kinds of pathnames. +// +// - The length of a POSIX-style, canonical pathname *at rest* never exceeds +// VIRTIO_FS_MAX_PATHNAME_LENGTH. (Length is defined as the number of CHAR8 +// elements in the canonical pathname, excluding the terminating '\0'.) This +// is an invariant that is ensured for canonical pathnames created, and that +// is assumed about canonical pathname inputs (which all originate +// internally). +// +// - If the length of a UEFI-style pathname *argument*, originating directly or +// indirectly from the EFI_FILE_PROTOCOL caller, exceeds +// VIRTIO_FS_MAX_PATHNAME_LENGTH, then the argument is rejected. (Length is +// defined as the number of CHAR16 elements in the UEFI-style pathname, +// excluding the terminating L'\0'.) This is a restriction that's checked on +// external UEFI-style pathname inputs. +// +// The limit is not expected to be a practical limitation; it's only supposed +// to prevent attempts at overflowing size calculations. For both kinds of +// pathnames, separate limits could be used; a common limit is used purely for +// simplicity. +// +#define VIRTIO_FS_MAX_PATHNAME_LENGTH ((UINTN)65535) +// // Filesystem label encoded in UCS-2, transformed from the UTF-8 representation // in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII code // points (U+0020 through U+007E) are supported. // typedef CHAR16 VIRTIO_FS_LABEL [VIRTIO_FS_TAG_BYTES +1 ];//
@@ -187,16 +211,24 @@ VirtioFsFuseCheckResponse ( OUT UINTN *TailBufferFill );EFI_STATUS VirtioFsErrnoToEfiStatus ( IN INT32 Errno ); +EFI_STATUS +VirtioFsAppendPath ( + IN CHAR8 *LhsPath8, + IN CHAR16 *RhsPath16, + OUT CHAR8 **ResultPath8, + OUT BOOLEAN *RootEscape + ); +// // Wrapper functions for FUSE commands (primitives). // EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId
OvmfPkg/VirtioFsDxe/Helpers.c +474 -0
498 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 17/48 OvmfPkg/VirtioFsDxe: manage path lifecycle in OpenVolume, Close, Delete
In reply to Laszlo ErsekAdd a canonical pathname field to VIRTIO_FS_FILE.
Initialize the new field in EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume().
Release the new field in EFI_FILE_PROTOCOL.Close() and EFI_FILE_PROTOCOL.Delete().
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 1 + OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 1 + OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 1 + OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 13 ++++++++++++- 4 files changed, 15 insertions(+), 1 deletion(-)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +1 -0
@@ -132,16 +132,17 @@ typedef struct {// typedef struct { UINT64 Signature; EFI_FILE_PROTOCOL SimpleFile; BOOLEAN IsDirectory; BOOLEAN IsOpenForWriting; VIRTIO_FS *OwnerFs; LIST_ENTRY OpenFilesEntry; + CHAR8 *CanonicalPathname; // // In the FUSE wire protocol, every request except FUSE_INIT refers to a // file, namely by the "VIRTIO_FS_FUSE_REQUEST.NodeId" field; that is, by the // inode number of the file. However, some of the FUSE requests that we need // for some of the EFI_FILE_PROTOCOL member functions require an open file // handle *in addition* to the inode number. For simplicity, whenever a // VIRTIO_FS_FILE object is created, primarily defined by its NodeId field, // we also *open* the referenced file at once, and save the returned file
OvmfPkg/VirtioFsDxe/SimpleFsClose.c +1 -0
@@ -54,11 +54,12 @@ VirtioFsSimpleFileClose (VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId); }// // One fewer file left open for the owner filesystem. // RemoveEntryList (&VirtioFsFile->OpenFilesEntry); +FreePool (VirtioFsFile->CanonicalPathname);FreePool (VirtioFsFile);return EFI_SUCCESS ; }
OvmfPkg/VirtioFsDxe/SimpleFsDelete.c +1 -0
@@ -58,11 +58,12 @@ VirtioFsSimpleFileDelete (VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId); }// // One fewer file left open for the owner filesystem. // RemoveEntryList (&VirtioFsFile->OpenFilesEntry); +FreePool (VirtioFsFile->CanonicalPathname);FreePool (VirtioFsFile);return Status; }
OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +12 -1
@@ -23,32 +23,39 @@ EFIAPIVirtioFsOpenVolume ( IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **Root ) { VIRTIO_FS *VirtioFs;VIRTIO_FS_FILE *VirtioFsFile;EFI_STATUS Status; +CHAR8 *CanonicalPathname;UINT64 RootDirHandle; VirtioFs =VIRTIO_FS_FROM_SIMPLE_FS (This); VirtioFsFile =AllocatePool (sizeof *VirtioFsFile);if (VirtioFsFile ==NULL ) {return EFI_OUT_OF_RESOURCES ; } + CanonicalPathname =AllocateCopyPool (sizeof "/" ,"/" ); +if (CanonicalPathname ==NULL ) { + Status =EFI_OUT_OF_RESOURCES ; + goto FreeVirtioFsFile; + } +// // Open the root directory. // Status =VirtioFsFuseOpenDir (VirtioFs,VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID , &RootDirHandle);if (EFI_ERROR (Status)) { - goto FreeVirtioFsFile; + goto FreeCanonicalPathname; }// // Populate the new VIRTIO_FS_FILE object. // VirtioFsFile->Signature =VIRTIO_FS_FILE_SIG ; VirtioFsFile->SimpleFile.Revision =EFI_FILE_PROTOCOL_REVISION ; VirtioFsFile->SimpleFile.Open = VirtioFsSimpleFileOpen;
@@ -59,24 +66,28 @@ VirtioFsOpenVolume ( VirtioFsFile->SimpleFile.GetPosition = VirtioFsSimpleFileGetPosition; VirtioFsFile->SimpleFile.SetPosition = VirtioFsSimpleFileSetPosition; VirtioFsFile->SimpleFile.GetInfo = VirtioFsSimpleFileGetInfo; VirtioFsFile->SimpleFile.SetInfo = VirtioFsSimpleFileSetInfo; VirtioFsFile->SimpleFile.Flush = VirtioFsSimpleFileFlush; VirtioFsFile->IsDirectory = TRUE; VirtioFsFile->IsOpenForWriting = FALSE; VirtioFsFile->OwnerFs = VirtioFs; + VirtioFsFile->CanonicalPathname = CanonicalPathname; VirtioFsFile->NodeId =VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID ; VirtioFsFile->FuseHandle = RootDirHandle;// // One more file open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry); *Root = &VirtioFsFile->SimpleFile;return EFI_SUCCESS ; +FreeCanonicalPathname: +FreePool (CanonicalPathname); + FreeVirtioFsFile:FreePool (VirtioFsFile);return Status; }
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 18/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_OPEN
In reply to Laszlo ErsekAdd the VirtioFsFuseOpen() function, for sending the FUSE_OPEN command to the Virtio Filesystem device.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 35 +++--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseOpen.c | 126 ++++++++++++++++++++ 4 files changed, 156 insertions(+), 14 deletions(-)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +21 -14
@@ -76,21 +76,28 @@ typedef struct {#define VIRTIO_FS_FUSE_MAJOR 7#define VIRTIO_FS_FUSE_MINOR 31// // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 +// +// Flags for VirtioFsFuseOpOpen. +// +#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0 +#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 +// // FUSE operation codes. // typedef enum { VirtioFsFuseOpForget =2 , + VirtioFsFuseOpOpen =14 , VirtioFsFuseOpRelease =18 , VirtioFsFuseOpFsync =20 , VirtioFsFuseOpFlush =25 , VirtioFsFuseOpInit =26 , VirtioFsFuseOpOpenDir =27 , VirtioFsFuseOpReleaseDir =29 , VirtioFsFuseOpFsyncDir =30 , }VIRTIO_FS_FUSE_OPCODE ;
@@ -118,16 +125,30 @@ typedef struct {// // Header for VirtioFsFuseOpForget. // typedef struct {UINT64 NumberOfLookups; }VIRTIO_FS_FUSE_FORGET_REQUEST ; +// +// Headers for VirtioFsFuseOpOpen and VirtioFsFuseOpOpenDir. +// +typedef struct { +UINT32 Flags; +UINT32 Unused; +}VIRTIO_FS_FUSE_OPEN_REQUEST ; + +typedef struct { +UINT64 FileHandle; +UINT32 OpenFlags; +UINT32 Padding; +}VIRTIO_FS_FUSE_OPEN_RESPONSE ; +// // Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir. // typedef struct { UINT64 FileHandle; UINT32 Flags; UINT32 ReleaseFlags; UINT64 LockOwner;
@@ -170,25 +191,11 @@ typedef struct {UINT16 MaxBackground;UINT16 CongestionThreshold;UINT32 MaxWrite;UINT32 TimeGran;UINT16 MaxPages;UINT16 MapAlignment; UINT32 Unused[8]; }VIRTIO_FS_FUSE_INIT_RESPONSE ; - -// -// Headers for VirtioFsFuseOpOpenDir. -// -typedef struct { -UINT32 Flags; -UINT32 Unused; -}VIRTIO_FS_FUSE_OPEN_REQUEST ; - -typedef struct { -UINT64 FileHandle; -UINT32 OpenFlags; -UINT32 Padding; -}VIRTIO_FS_FUSE_OPEN_RESPONSE ;#pragma pack ()#endif // VIRTIO_FS_H_
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -81,16 +81,17 @@ [Packages] OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c + FuseOpen.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +8 -0
@@ -230,16 +230,24 @@ VirtioFsAppendPath (// EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId ); +EFI_STATUS +VirtioFsFuseOpen ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN BOOLEAN ReadWrite, + OUT UINT64 *FuseHandle + ); +EFI_STATUS VirtioFsFuseReleaseFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir );
OvmfPkg/VirtioFsDxe/FuseOpen.c new file +126 -0
126 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 19/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_MKDIR
In reply to Laszlo ErsekAdd the VirtioFsFuseMkDir() function, for sending the FUSE_MKDIR command to the Virtio Filesystem device.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 55 ++++++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseMkDir.c | 134 ++++++++++++++++++++ 4 files changed, 198 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +55 -0
@@ -76,27 +76,35 @@ typedef struct {#define VIRTIO_FS_FUSE_MAJOR 7#define VIRTIO_FS_FUSE_MINOR 31// // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 +// +// File mode bitmasks. +// +#define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u +#define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u +#define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u +// // Flags for VirtioFsFuseOpOpen. // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2// // FUSE operation codes. // typedef enum { VirtioFsFuseOpForget = 2, + VirtioFsFuseOpMkDir = 9, VirtioFsFuseOpOpen = 14, VirtioFsFuseOpRelease = 18, VirtioFsFuseOpFsync = 20, VirtioFsFuseOpFlush = 25, VirtioFsFuseOpInit = 26, VirtioFsFuseOpOpenDir = 27, VirtioFsFuseOpReleaseDir = 29, VirtioFsFuseOpFsyncDir = 30,
@@ -118,23 +126,70 @@ typedef struct { }VIRTIO_FS_FUSE_REQUEST ;typedef struct {UINT32 Len;INT32 Error;UINT64 Unique; }VIRTIO_FS_FUSE_RESPONSE ; +// +// Structure with which the Virtio Filesystem device reports a NodeId to the +// FUSE client (i.e., to the Virtio Filesystem driver). This structure is a +// part of the response headers for operations that inform the FUSE client of +// an inode. +// +typedef struct { +UINT64 NodeId; +UINT64 Generation; +UINT64 EntryValid; +UINT64 AttrValid; +UINT32 EntryValidNsec; +UINT32 AttrValidNsec; +}VIRTIO_FS_FUSE_NODE_RESPONSE ; + +// +// Structure describing the host-side attributes of an inode. This structure is +// a part of the response headers for operations that inform the FUSE client of +// an inode. +// +typedef struct { +UINT64 Ino; +UINT64 Size; +UINT64 Blocks; +UINT64 Atime; +UINT64 Mtime; +UINT64 Ctime; +UINT32 AtimeNsec; +UINT32 MtimeNsec; +UINT32 CtimeNsec; +UINT32 Mode; +UINT32 Nlink; +UINT32 Uid; +UINT32 Gid; +UINT32 Rdev; +UINT32 Blksize; +UINT32 Padding; +}VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE ; +// // Header for VirtioFsFuseOpForget. // typedef struct {UINT64 NumberOfLookups; }VIRTIO_FS_FUSE_FORGET_REQUEST ; +// +// Header for VirtioFsFuseOpMkDir. +// +typedef struct { +UINT32 Mode; +UINT32 Umask; +}VIRTIO_FS_FUSE_MKDIR_REQUEST ; +// // Headers for VirtioFsFuseOpOpen and VirtioFsFuseOpOpenDir. // typedef struct {UINT32 Flags;UINT32 Unused; }VIRTIO_FS_FUSE_OPEN_REQUEST ;
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -81,16 +81,17 @@ [Packages] OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c + FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +8 -0
@@ -230,16 +230,24 @@ VirtioFsAppendPath (// EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId ); +EFI_STATUS +VirtioFsFuseMkDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId + ); +EFI_STATUS VirtioFsFuseOpen ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN BOOLEAN ReadWrite, OUT UINT64 *FuseHandle );
OvmfPkg/VirtioFsDxe/FuseMkDir.c new file +134 -0
134 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 20/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_CREATE
In reply to Laszlo ErsekAdd the VirtioFsFuseOpenOrCreate() function, for sending the FUSE_CREATE command to the Virtio Filesystem device.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 17 +++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 9 ++ OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c | 155 ++++++++++++++++++++ 4 files changed, 182 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +17 -0
@@ -80,18 +80,24 @@ typedef struct {// The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1// // File mode bitmasks. // #define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u +#define VIRTIO_FS_FUSE_MODE_PERM_RUSR 0000400u +#define VIRTIO_FS_FUSE_MODE_PERM_WUSR 0000200u#define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u +#define VIRTIO_FS_FUSE_MODE_PERM_RGRP 0000040u +#define VIRTIO_FS_FUSE_MODE_PERM_WGRP 0000020u#define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u +#define VIRTIO_FS_FUSE_MODE_PERM_ROTH 0000004u +#define VIRTIO_FS_FUSE_MODE_PERM_WOTH 0000002u// // Flags for VirtioFsFuseOpOpen. // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2//
@@ -103,16 +109,17 @@ typedef enum { VirtioFsFuseOpOpen =14 , VirtioFsFuseOpRelease =18 , VirtioFsFuseOpFsync =20 , VirtioFsFuseOpFlush =25 , VirtioFsFuseOpInit =26 , VirtioFsFuseOpOpenDir =27 , VirtioFsFuseOpReleaseDir =29 , VirtioFsFuseOpFsyncDir =30 , + VirtioFsFuseOpCreate =35 , } VIRTIO_FS_FUSE_OPCODE;#pragma pack (1)// // Request-response headers common to all request types. // typedef struct { UINT32 Len;
@@ -246,11 +253,21 @@ typedef struct {UINT16 MaxBackground;UINT16 CongestionThreshold;UINT32 MaxWrite;UINT32 TimeGran;UINT16 MaxPages;UINT16 MapAlignment; UINT32 Unused[8]; }VIRTIO_FS_FUSE_INIT_RESPONSE ; + +// +// Header for VirtioFsFuseOpCreate. +// +typedef struct { +UINT32 Flags; +UINT32 Mode; +UINT32 Umask; +UINT32 Padding; +}VIRTIO_FS_FUSE_CREATE_REQUEST ;#pragma pack ()#endif // VIRTIO_FS_H_
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -84,16 +84,17 @@ [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c FuseMkDir.c FuseOpen.c FuseOpenDir.c + FuseOpenOrCreate.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c SimpleFsOpen.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +9 -0
@@ -281,16 +281,25 @@ VirtioFsFuseInitSession (EFI_STATUS VirtioFsFuseOpenDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT UINT64 *FuseHandle ); +EFI_STATUS +VirtioFsFuseOpenOrCreate ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT UINT64 *FuseHandle + ); +// // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem // driver. // EFI_STATUS EFIAPI VirtioFsOpenVolume (
OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c new file +155 -0
155 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 21/48 OvmfPkg/VirtioFsDxe: convert FUSE inode attributes to EFI_FILE_INFO
In reply to Laszlo ErsekIntroduce the VirtioFsFuseAttrToEfiFileInfo() function, for converting FUSE inode attributes to EFI_FILE_INFO.
The EpochToEfiTime() function from EmbeddedPkg's TimeBaseLib proves invaluable for converting the file access times.
This is the first time we consume TimeBaseLib in OvmfPkg, so add the necessary lib class resolution. We need not modify any ArmVirtPkg DSC
files: see commit af5fed90bfbf ("ArmPlatformPkg,ArmVirtPkg: delete redundant PL031 functions", 2017-05-10).
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/Include/IndustryStandard/VirtioFs.h | 3 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 2 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 119 ++++++++++++++++++++ 7 files changed, 134 insertions(+)
OvmfPkg/OvmfPkgIa32.dsc +1 -0
@@ -120,16 +120,17 @@ [SkuIds] [LibraryClasses] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf + TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
OvmfPkg/OvmfPkgIa32X64.dsc +1 -0
@@ -124,16 +124,17 @@ [SkuIds] [LibraryClasses] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf + TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
OvmfPkg/OvmfPkgX64.dsc +1 -0
@@ -124,16 +124,17 @@ [SkuIds] [LibraryClasses] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf + TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
OvmfPkg/Include/IndustryStandard/VirtioFs.h +3 -0
@@ -79,16 +79,19 @@ typedef struct {// // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1// // File mode bitmasks. // +#define VIRTIO_FS_FUSE_MODE_TYPE_MASK 0170000u +#define VIRTIO_FS_FUSE_MODE_TYPE_REG 0100000u +#define VIRTIO_FS_FUSE_MODE_TYPE_DIR 0040000u#define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u#define VIRTIO_FS_FUSE_MODE_PERM_RUSR 0000400u#define VIRTIO_FS_FUSE_MODE_PERM_WUSR 0000200u#define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u#define VIRTIO_FS_FUSE_MODE_PERM_RGRP 0000040u#define VIRTIO_FS_FUSE_MODE_PERM_WGRP 0000020u#define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u#define VIRTIO_FS_FUSE_MODE_PERM_ROTH 0000004u
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +2 -0
@@ -72,16 +72,17 @@ [Defines] INF_VERSION = 1.29 BASE_NAME = VirtioFsDxe FILE_GUID = 7BD9DDF7-8B83-488E-AEC9-24C78610289C MODULE_TYPE = UEFI_DRIVER ENTRY_POINT = VirtioFsEntryPoint [Packages] + EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c
@@ -105,16 +106,17 @@ [Sources] SimpleFsWrite.c VirtioFsDxe.h [LibraryClasses] BaseLib BaseMemoryLib DebugLib MemoryAllocationLib + TimeBaseLib UefiBootServicesTableLib UefiDriverEntryPoint VirtioLib [Protocols] gEfiComponentName2ProtocolGuid ## PRODUCES gEfiDriverBindingProtocolGuid ## PRODUCES gEfiSimpleFileSystemProtocolGuid ## BY_START
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +7 -0
@@ -6,16 +6,17 @@SPDX-License-Identifier: BSD-2-Clause-Patent **/ #ifndef VIRTIO_FS_DXE_H_ #define VIRTIO_FS_DXE_H_ #include <Base.h> // SIGNATURE_64() +#include <Guid/FileInfo.h> // EFI_FILE_INFO #include <IndustryStandard/VirtioFs.h> // VIRTIO_FS_TAG_BYTES #include <Library/DebugLib.h> // CR() #include <Protocol/SimpleFileSystem.h> // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL #include <Protocol/VirtioDevice.h> // VIRTIO_DEVICE_PROTOCOL #include <Uefi/UefiBaseType.h> // EFI_EVENT #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S')
@@ -220,16 +221,22 @@ VirtioFsErrnoToEfiStatus (EFI_STATUS VirtioFsAppendPath ( IN CHAR8 *LhsPath8, IN CHAR16 *RhsPath16, OUT CHAR8 **ResultPath8, OUT BOOLEAN *RootEscape ); +EFI_STATUS +VirtioFsFuseAttrToEfiFileInfo ( + IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, + OUT EFI_FILE_INFO *FileInfo + ); +// // Wrapper functions for FUSE commands (primitives). // EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId
OvmfPkg/VirtioFsDxe/Helpers.c +119 -0
143 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 22/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_LOOKUP
In reply to Laszlo ErsekAdd the VirtioFsFuseLookup() function, for sending the FUSE_LOOKUP command to the Virtio Filesystem device.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 6 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 9 ++ OvmfPkg/VirtioFsDxe/FuseLookup.c | 148 ++++++++++++++++++++ 4 files changed, 164 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +6 -0
@@ -76,16 +76,21 @@ typedef struct {#define VIRTIO_FS_FUSE_MAJOR 7#define VIRTIO_FS_FUSE_MINOR 31// // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 +// +// Distinguished errno values. +// +#define VIRTIO_FS_FUSE_ERRNO_ENOENT (-2) +// // File mode bitmasks. // #define VIRTIO_FS_FUSE_MODE_TYPE_MASK 0170000u#define VIRTIO_FS_FUSE_MODE_TYPE_REG 0100000u#define VIRTIO_FS_FUSE_MODE_TYPE_DIR 0040000u#define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u#define VIRTIO_FS_FUSE_MODE_PERM_RUSR 0000400u
@@ -102,16 +107,17 @@ typedef struct {// #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2// // FUSE operation codes. // typedef enum { + VirtioFsFuseOpLookup = 1, VirtioFsFuseOpForget = 2, VirtioFsFuseOpMkDir = 9, VirtioFsFuseOpOpen = 14, VirtioFsFuseOpRelease = 18, VirtioFsFuseOpFsync = 20, VirtioFsFuseOpFlush = 25, VirtioFsFuseOpInit = 26, VirtioFsFuseOpOpenDir = 27,
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -82,16 +82,17 @@ [Packages] OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c + FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +9 -0
@@ -231,16 +231,25 @@ VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo );// // Wrapper functions for FUSE commands (primitives). // +EFI_STATUS +VirtioFsFuseLookup ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 DirNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr + ); +EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId );EFI_STATUS VirtioFsFuseMkDir (
OvmfPkg/VirtioFsDxe/FuseLookup.c new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 23/48 OvmfPkg/VirtioFsDxe: split canon. path into last parent + last component
In reply to Laszlo ErsekGiven a canonical pathname (as defined by VirtioFsAppendPath()), different from "/", introduce a helper function for:
- looking up the NodeId of the most specific parent directory, and
- exposing the last component stand-alone (which is therefore a direct child of said parent directory).
This splitting operation will be necessary in multiple subsequent patches.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 131 ++++++++++++++++++++ 2 files changed, 139 insertions(+)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +8 -0
@@ -221,16 +221,24 @@ VirtioFsErrnoToEfiStatus (EFI_STATUS VirtioFsAppendPath ( IN CHAR8 *LhsPath8, IN CHAR16 *RhsPath16, OUT CHAR8 **ResultPath8, OUT BOOLEAN *RootEscape ); +EFI_STATUS +VirtioFsLookupMostSpecificParentDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN OUT CHAR8 *Path, + OUT UINT64 *DirNodeId, + OUT CHAR8 **LastComponent + ); +EFI_STATUS VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo );// // Wrapper functions for FUSE commands (primitives).
OvmfPkg/VirtioFsDxe/Helpers.c +131 -0
147 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 24/48 OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_UNLINK / FUSE_RMDIR
In reply to Laszlo ErsekThe FUSE_UNLINK and FUSE_RMDIR commands only differ in the opcode. Add a common function for wrapping both.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 2 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseUnlink.c | 114 ++++++++++++++++++++ 4 files changed, 125 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +2 -0
@@ -110,16 +110,18 @@ typedef struct {// // FUSE operation codes. // typedef enum { VirtioFsFuseOpLookup = 1, VirtioFsFuseOpForget = 2, VirtioFsFuseOpMkDir = 9, + VirtioFsFuseOpUnlink = 10, + VirtioFsFuseOpRmDir = 11, VirtioFsFuseOpOpen = 14, VirtioFsFuseOpRelease = 18, VirtioFsFuseOpFsync = 20, VirtioFsFuseOpFlush = 25, VirtioFsFuseOpInit = 26, VirtioFsFuseOpOpenDir = 27, VirtioFsFuseOpReleaseDir = 29, VirtioFsFuseOpFsyncDir = 30,
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -88,16 +88,17 @@ [Sources] FuseFsync.c FuseInit.c FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRelease.c + FuseUnlink.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c SimpleFsOpen.c SimpleFsOpenVolume.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +8 -0
@@ -262,16 +262,24 @@ VirtioFsFuseForget (EFI_STATUS VirtioFsFuseMkDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 ParentNodeId, IN CHAR8 *Name, OUT UINT64 *NodeId ); +EFI_STATUS +VirtioFsFuseRemoveFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + IN BOOLEAN IsDir + ); +EFI_STATUS VirtioFsFuseOpen ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN BOOLEAN ReadWrite, OUT UINT64 *FuseHandle );
OvmfPkg/VirtioFsDxe/FuseUnlink.c new file +114 -0
114 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 25/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_GETATTR
In reply to Laszlo ErsekAdd the VirtioFsFuseGetAttr() function, for sending the FUSE_GETATTR command to the Virtio Filesystem device.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 16 +++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 ++ OvmfPkg/VirtioFsDxe/FuseGetAttr.c | 116 ++++++++++++++++++++ 4 files changed, 140 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +16 -0
@@ -109,16 +109,17 @@ typedef struct {#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2// // FUSE operation codes. // typedef enum { VirtioFsFuseOpLookup = 1, VirtioFsFuseOpForget = 2, + VirtioFsFuseOpGetAttr = 3, VirtioFsFuseOpMkDir = 9, VirtioFsFuseOpUnlink = 10, VirtioFsFuseOpRmDir = 11, VirtioFsFuseOpOpen = 14, VirtioFsFuseOpRelease = 18, VirtioFsFuseOpFsync = 20, VirtioFsFuseOpFlush = 25, VirtioFsFuseOpInit = 26,
@@ -190,16 +191,31 @@ typedef struct {// // Header for VirtioFsFuseOpForget. // typedef struct {UINT64 NumberOfLookups; }VIRTIO_FS_FUSE_FORGET_REQUEST ; +// +// Headers for VirtioFsFuseOpGetAttr. +// +typedef struct { +UINT32 GetAttrFlags; +UINT32 Dummy; +UINT64 FileHandle; +}VIRTIO_FS_FUSE_GETATTR_REQUEST ; + +typedef struct { +UINT64 AttrValid; +UINT32 AttrValidNsec; +UINT32 Dummy; +}VIRTIO_FS_FUSE_GETATTR_RESPONSE ; +// // Header for VirtioFsFuseOpMkDir. // typedef struct {UINT32 Mode;UINT32 Umask; }VIRTIO_FS_FUSE_MKDIR_REQUEST ;
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -81,16 +81,17 @@ [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c + FuseGetAttr.c FuseInit.c FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRelease.c FuseUnlink.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +7 -0
@@ -254,16 +254,23 @@ VirtioFsFuseLookup ( );EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId ); +EFI_STATUS +VirtioFsFuseGetAttr ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr + ); +EFI_STATUS VirtioFsFuseMkDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 ParentNodeId, IN CHAR8 *Name, OUT UINT64 *NodeId );
OvmfPkg/VirtioFsDxe/FuseGetAttr.c new file +116 -0
116 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 26/48 OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Open()
In reply to Laszlo ErsekUsing the functions introduced previously, we can now implement VirtioFsSimpleFileOpen().
This lets the "MKDIR" command to work in the UEFI shell, for example.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 480 +++++++++++++++++++- 1 file changed, 479 insertions(+), 1 deletion(-)
OvmfPkg/VirtioFsDxe/SimpleFsOpen.c +479 -1
@@ -1,22 +1,500 @@/** @file EFI_FILE_PROTOCOL.Open() member function for the Virtio Filesystem driver. Copyright (C) 2020, Red Hat, Inc. SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include <Library/BaseLib.h> // AsciiStrCmp() +#include <Library/MemoryAllocationLib.h> // AllocatePool() +#include "VirtioFsDxe.h" +/** +Open the root directory, possibly for writing. + +@param[in,out] VirtioFs The Virtio Filesystem device whose root directory +should be opened. + +@param[out] NewHandle The new EFI_FILE_PROTOCOL instance through which +the root directory can be accessed. + +@param[in] OpenForWriting TRUE if the root directory should be opened for +read-write access. FALSE if the root directory +should be opened for read-only access. Opening the +root directory for read-write access is useful for +calling EFI_FILE_PROTOCOL.Flush() or +EFI_FILE_PROTOCOL.SetInfo() later, for syncing or +touching the root directory, respectively. + +@retval EFI_SUCCESS The root directory has been opened successfully. + +@retval EFI_ACCESS_DENIED OpenForWriting is TRUE, but the root directory is +marked as read-only. + +@return Error codes propagated from underlying functions. +**/ +STATIC +EFI_STATUS +OpenRootDirectory ( + IN OUT VIRTIO_FS *VirtioFs, + OUT EFI_FILE_PROTOCOL **NewHandle, + IN BOOLEAN OpenForWriting + ) +{ +EFI_STATUS Status; +VIRTIO_FS_FILE *NewVirtioFsFile; + +// +// VirtioFsOpenVolume() opens the root directory for read-only access. If the +// current request is to open the root directory for read-write access, so +// that EFI_FILE_PROTOCOL.Flush() or EFI_FILE_PROTOCOL.SetInfo()+timestamps +// can be used on the root directory later, then we have to check for write +// permission first. +// +if (OpenForWriting) { +VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; +EFI_FILE_INFO FileInfo; + + Status =VirtioFsFuseGetAttr (VirtioFs,VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID , + &FuseAttr); +if (EFI_ERROR (Status)) { +return Status; + } + Status =VirtioFsFuseAttrToEfiFileInfo (&FuseAttr, &FileInfo); +if (EFI_ERROR (Status)) { +return Status; + } +if ((FileInfo.Attribute &EFI_FILE_READ_ONLY ) !=0 ) { +return EFI_ACCESS_DENIED ; + } + } + + Status =VirtioFsOpenVolume (&VirtioFs->SimpleFs, NewHandle); +if (EFI_ERROR (Status)) { +return Status; + } + + NewVirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (*NewHandle); + NewVirtioFsFile->IsOpenForWriting = OpenForWriting; +return EFI_SUCCESS ; +} + +/** +Open an existent regular file or non-root directory. + +@param[in,out] VirtioFs The Virtio Filesystem device on which the +regular file or directory should be opened. + +@param[in] DirNodeId The inode number of the immediate parent +directory of the regular file or directory to +open. + +@param[in] Name The single-component filename of the regular +file or directory to open, under the immediate +parent directory identified by DirNodeId. + +@param[in] OpenForWriting TRUE if the regular file or directory should be +opened for read-write access. FALSE if the +regular file or directory should be opened for +read-only access. Opening a directory for +read-write access is useful for deleting, +renaming, syncing or touching the directory +later. + +@param[out] NodeId The inode number of the regular file or +directory, returned by the Virtio Filesystem +device. + +@param[out] FuseHandle The open handle to the regular file or +directory, returned by the Virtio Filesystem +device. + +@param[out] NodeIsDirectory Set to TRUE on output if Name was found to refer +to a directory. Set to FALSE if Name was found +to refer to a regular file. + +@retval EFI_SUCCESS The regular file or directory has been looked up +and opened successfully. + +@retval EFI_ACCESS_DENIED OpenForWriting is TRUE, but the regular file or +directory is marked read-only. + +@retval EFI_NOT_FOUND A directory entry called Name was not found in the +directory identified by DirNodeId. (EFI_NOT_FOUND +is not returned for any other condition.) + +@return Errors propagated from underlying functions. If +the error code to propagate were EFI_NOT_FOUND, it +is remapped to EFI_DEVICE_ERROR. +**/ +STATIC +EFI_STATUS +OpenExistentFileOrDirectory ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 DirNodeId, + IN CHAR8 *Name, + IN BOOLEAN OpenForWriting, + OUT UINT64 *NodeId, + OUT UINT64 *FuseHandle, + OUT BOOLEAN *NodeIsDirectory + ) +{ +EFI_STATUS Status; +UINT64 ResolvedNodeId; +VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; +EFI_FILE_INFO FileInfo; +BOOLEAN IsDirectory; +UINT64 NewFuseHandle; + + Status =VirtioFsFuseLookup (VirtioFs, DirNodeId, Name, &ResolvedNodeId, + &FuseAttr); +if (EFI_ERROR (Status)) { +return Status; + } + Status =VirtioFsFuseAttrToEfiFileInfo (&FuseAttr, &FileInfo); +if (EFI_ERROR (Status)) { + goto ForgetResolvedNodeId; + } + +if (OpenForWriting && (FileInfo.Attribute &EFI_FILE_READ_ONLY ) !=0 ) { + Status =EFI_ACCESS_DENIED ; + goto ForgetResolvedNodeId; + } + + IsDirectory = (BOOLEAN )((FileInfo.Attribute &EFI_FILE_DIRECTORY ) !=0 ); +if (IsDirectory) { +// +// If OpenForWriting is TRUE here, that's not passed to +// VirtioFsFuseOpenDir(); it does not affect the FUSE_OPENDIR request we +// send. OpenForWriting=TRUE will only permit attempts to delete, rename, +// flush (sync), and touch the directory. +// + Status =VirtioFsFuseOpenDir (VirtioFs, ResolvedNodeId, &NewFuseHandle); + }else { + Status =VirtioFsFuseOpen (VirtioFs, ResolvedNodeId, OpenForWriting, + &NewFuseHandle); + } +if (EFI_ERROR (Status)) { + goto ForgetResolvedNodeId; + } + + *NodeId = ResolvedNodeId; + *FuseHandle = NewFuseHandle; + *NodeIsDirectory = IsDirectory; +return EFI_SUCCESS ; + +ForgetResolvedNodeId: +VirtioFsFuseForget (VirtioFs, ResolvedNodeId); +return (Status ==EFI_NOT_FOUND ) ?EFI_DEVICE_ERROR : Status; +} + +/** +Create a directory. + +@param[in,out] VirtioFs The Virtio Filesystem device on which the directory +should be created. + +@param[in] DirNodeId The inode number of the immediate parent directory +of the directory to create. + +@param[in] Name The single-component filename of the directory to +create, under the immediate parent directory +identified by DirNodeId. + +@param[out] NodeId The inode number of the directory created, returned +by the Virtio Filesystem device. + +@param[out] FuseHandle The open handle to the directory created, returned +by the Virtio Filesystem device. + +@retval EFI_SUCCESS The directory has been created successfully. + +@return Errors propagated from underlying functions. +**/ +STATIC +EFI_STATUS +CreateDirectory ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 DirNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT UINT64 *FuseHandle + ) +{ +EFI_STATUS Status; +UINT64 NewChildDirNodeId; +UINT64 NewFuseHandle; + + Status =VirtioFsFuseMkDir (VirtioFs, DirNodeId, Name, &NewChildDirNodeId); +if (EFI_ERROR (Status)) { +return Status; + } + + Status =VirtioFsFuseOpenDir (VirtioFs, NewChildDirNodeId, &NewFuseHandle); +if (EFI_ERROR (Status)) { + goto RemoveNewChildDir; + } + + *NodeId = NewChildDirNodeId; + *FuseHandle = NewFuseHandle; +return EFI_SUCCESS ; + +RemoveNewChildDir: +VirtioFsFuseRemoveFileOrDir (VirtioFs, DirNodeId, Name, TRUE/* IsDir */ ); +VirtioFsFuseForget (VirtioFs, NewChildDirNodeId); +return Status; +} + +/** +Create a regular file. + +@param[in,out] VirtioFs The Virtio Filesystem device on which the regular +file should be created. + +@param[in] DirNodeId The inode number of the immediate parent directory +of the regular file to create. + +@param[in] Name The single-component filename of the regular file to +create, under the immediate parent directory +identified by DirNodeId. + +@param[out] NodeId The inode number of the regular file created, +returned by the Virtio Filesystem device. + +@param[out] FuseHandle The open handle to the regular file created, +returned by the Virtio Filesystem device. + +@retval EFI_SUCCESS The regular file has been created successfully. + +@return Errors propagated from underlying functions. +**/ +STATIC +EFI_STATUS +CreateRegularFile ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 DirNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT UINT64 *FuseHandle + ) +{ +return VirtioFsFuseOpenOrCreate (VirtioFs, DirNodeId, Name, NodeId, + FuseHandle); +} +EFI_STATUS EFIAPIVirtioFsSimpleFileOpen ( IN EFI_FILE_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **NewHandle, IN CHAR16 *FileName, IN UINT64 OpenMode, IN UINT64 Attributes ) { -return EFI_NO_MEDIA ; +VIRTIO_FS_FILE *VirtioFsFile; +VIRTIO_FS *VirtioFs; +BOOLEAN OpenForWriting; +BOOLEAN PermitCreation; +BOOLEAN CreateDirectoryIfCreating; +VIRTIO_FS_FILE *NewVirtioFsFile; +EFI_STATUS Status; +CHAR8 *NewCanonicalPath; +BOOLEAN RootEscape; +UINT64 DirNodeId; +CHAR8 *LastComponent; +UINT64 NewNodeId; +UINT64 NewFuseHandle; +BOOLEAN NewNodeIsDirectory; + + VirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs = VirtioFsFile->OwnerFs; + +// +// Validate OpenMode. +// +switch (OpenMode) { +case EFI_FILE_MODE_READ : + OpenForWriting = FALSE; + PermitCreation = FALSE; +break ; +case EFI_FILE_MODE_READ |EFI_FILE_MODE_WRITE : + OpenForWriting = TRUE; + PermitCreation = FALSE; +break ; +case EFI_FILE_MODE_READ |EFI_FILE_MODE_WRITE |EFI_FILE_MODE_CREATE : + OpenForWriting = TRUE; + PermitCreation = TRUE; +break ; +default : +return EFI_INVALID_PARAMETER ; + } + +// +// Validate the Attributes requested for the case when the file ends up being +// created, provided creation is permitted. +// +if (PermitCreation) { +if ((Attributes & ~EFI_FILE_VALID_ATTR ) !=0 ) { +// +// Unknown attribute requested. +// +return EFI_INVALID_PARAMETER ; + } + +ASSERT (OpenForWriting); +if ((Attributes &EFI_FILE_READ_ONLY ) !=0 ) { +DEBUG (( +DEBUG_ERROR , + ("%a: Label=\"%s\" CanonicalPathname=\"%a\" FileName=\"%s\" " +"OpenMode=0x%Lx Attributes=0x%Lx: nonsensical request to possibly " +"create a file marked read-only, for read-write access\n" ), + __FUNCTION__, + VirtioFs->Label, + VirtioFsFile->CanonicalPathname, + FileName, + OpenMode, + Attributes + )); +return EFI_INVALID_PARAMETER ; + } + CreateDirectoryIfCreating = (BOOLEAN )((Attributes & +EFI_FILE_DIRECTORY ) !=0 ); + } + +// +// Referring to a file relative to a regular file makes no sense (or at least +// it cannot be implemented consistently with how a file is referred to +// relative to a directory). +// +if (!VirtioFsFile->IsDirectory) { +DEBUG (( +DEBUG_ERROR , + ("%a: Label=\"%s\" CanonicalPathname=\"%a\" FileName=\"%s\": " +"nonsensical request to open a file or directory relative to a regular " +"file\n" ), + __FUNCTION__, + VirtioFs->Label, + VirtioFsFile->CanonicalPathname, + FileName + )); +return EFI_INVALID_PARAMETER ; + } + +// +// Allocate the new VIRTIO_FS_FILE object. +// + NewVirtioFsFile =AllocatePool (sizeof *NewVirtioFsFile); +if (NewVirtioFsFile ==NULL ) { +return EFI_OUT_OF_RESOURCES ; + } + +// +// Create the canonical pathname at which the desired file is expected to +// exist. +// + Status =VirtioFsAppendPath (VirtioFsFile->CanonicalPathname, FileName, + &NewCanonicalPath, &RootEscape); +if (EFI_ERROR (Status)) { + goto FreeNewVirtioFsFile; + } +if (RootEscape) { + Status =EFI_ACCESS_DENIED ; + goto FreeNewCanonicalPath; + } + +// +// If the desired file is the root directory, just open the volume one more +// time, without looking up anything. +// +if (AsciiStrCmp (NewCanonicalPath,"/" ) ==0 ) { +FreePool (NewCanonicalPath); +FreePool (NewVirtioFsFile); +return OpenRootDirectory (VirtioFs, NewHandle, OpenForWriting); + } + +// +// Split the new canonical pathname into most specific parent directory +// (given by DirNodeId) and last pathname component (i.e., immediate child +// within that parent directory). +// + Status =VirtioFsLookupMostSpecificParentDir (VirtioFs, NewCanonicalPath, + &DirNodeId, &LastComponent); +if (EFI_ERROR (Status)) { + goto FreeNewCanonicalPath; + } + +// +// Try to open LastComponent directly under DirNodeId, as an existent regular +// file or directory. +// + Status =OpenExistentFileOrDirectory (VirtioFs, DirNodeId, LastComponent, + OpenForWriting, &NewNodeId, &NewFuseHandle, &NewNodeIsDirectory); +// +// If LastComponent could not be found under DirNodeId, but the request +// allows us to create a new entry, attempt creating the requested regular +// file or directory. +// +if (Status ==EFI_NOT_FOUND && PermitCreation) { +ASSERT (OpenForWriting); +if (CreateDirectoryIfCreating) { + Status =CreateDirectory (VirtioFs, DirNodeId, LastComponent, &NewNodeId, + &NewFuseHandle); + }else { + Status =CreateRegularFile (VirtioFs, DirNodeId, LastComponent, + &NewNodeId, &NewFuseHandle); + } + NewNodeIsDirectory = CreateDirectoryIfCreating; + } + +// +// Regardless of the branch taken, we're done with DirNodeId. +// +if (DirNodeId !=VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID ) { +VirtioFsFuseForget (VirtioFs, DirNodeId); + } + +if (EFI_ERROR (Status)) { + goto FreeNewCanonicalPath; + } + +// +// Populate the new VIRTIO_FS_FILE object. +// + NewVirtioFsFile->Signature =VIRTIO_FS_FILE_SIG ; + NewVirtioFsFile->SimpleFile.Revision =EFI_FILE_PROTOCOL_REVISION ; + NewVirtioFsFile->SimpleFile.Open = VirtioFsSimpleFileOpen; + NewVirtioFsFile->SimpleFile.Close = VirtioFsSimpleFileClose; + NewVirtioFsFile->SimpleFile.Delete = VirtioFsSimpleFileDelete; + NewVirtioFsFile->SimpleFile.Read = VirtioFsSimpleFileRead; + NewVirtioFsFile->SimpleFile.Write = VirtioFsSimpleFileWrite; + NewVirtioFsFile->SimpleFile.GetPosition = VirtioFsSimpleFileGetPosition; + NewVirtioFsFile->SimpleFile.SetPosition = VirtioFsSimpleFileSetPosition; + NewVirtioFsFile->SimpleFile.GetInfo = VirtioFsSimpleFileGetInfo; + NewVirtioFsFile->SimpleFile.SetInfo = VirtioFsSimpleFileSetInfo; + NewVirtioFsFile->SimpleFile.Flush = VirtioFsSimpleFileFlush; + NewVirtioFsFile->IsDirectory = NewNodeIsDirectory; + NewVirtioFsFile->IsOpenForWriting = OpenForWriting; + NewVirtioFsFile->OwnerFs = VirtioFs; + NewVirtioFsFile->CanonicalPathname = NewCanonicalPath; + NewVirtioFsFile->NodeId = NewNodeId; + NewVirtioFsFile->FuseHandle = NewFuseHandle; + +// +// One more file is now open for the filesystem. +// +InsertTailList (&VirtioFs->OpenFiles, &NewVirtioFsFile->OpenFilesEntry); + + *NewHandle = &NewVirtioFsFile->SimpleFile; +return EFI_SUCCESS ; + +FreeNewCanonicalPath: +FreePool (NewCanonicalPath); + +FreeNewVirtioFsFile: +FreePool (NewVirtioFsFile); + +return Status; }
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 27/48 OvmfPkg/VirtioFsDxe: erase the dir. entry in EFI_FILE_PROTOCOL.Delete()
In reply to Laszlo ErsekAt this point, the infrastructure is available for looking up the directly containing directory of the file in EFI_FILE_PROTOCOL.Delete(), and to remove the file in that directory by last pathname component. Do so.
The "RM" UEFI shell command will start working only later in the series; the shell needs more EFI_FILE_PROTOCOL members to function before it calls Delete().
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 44 ++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-)
OvmfPkg/VirtioFsDxe/SimpleFsDelete.c +41 -3
@@ -41,19 +41,57 @@ VirtioFsSimpleFileDelete (VirtioFsFuseReleaseFileOrDir (VirtioFs, VirtioFsFile->NodeId, VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory);// // VirtioFsFile->FuseHandle is gone at this point, but VirtioFsFile->NodeId // is still valid. Continue with removing the file or directory. The result // of this operation determines the return status of the function. // -// TODO -// - Status =EFI_WARN_DELETE_FAILURE ; +if (VirtioFsFile->IsOpenForWriting) { +UINT64 ParentNodeId; +CHAR8 *LastComponent; + +// +// Split our canonical pathname into most specific parent directory +// (identified by NodeId), and single-component filename within that +// directory. If This stands for the root directory "/", then the following +// function call will gracefully fail. +// + Status =VirtioFsLookupMostSpecificParentDir ( + VirtioFs, + VirtioFsFile->CanonicalPathname, + &ParentNodeId, + &LastComponent + ); +if (!EFI_ERROR (Status)) { +// +// Attempt the actual removal. Regardless of the outcome, ParentNodeId +// must be forgotten right after (unless it stands for the root +// directory). +// + Status =VirtioFsFuseRemoveFileOrDir ( + VirtioFs, + ParentNodeId, + LastComponent, + VirtioFsFile->IsDirectory + ); +if (ParentNodeId !=VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID ) { +VirtioFsFuseForget (VirtioFs, ParentNodeId); + } + } +if (EFI_ERROR (Status)) { +// +// Map any failure to the spec-mandated warning code. +// + Status =EFI_WARN_DELETE_FAILURE ; + } + }else { + Status =EFI_WARN_DELETE_FAILURE ; + }// // Finally, if we've known VirtioFsFile->NodeId from a lookup, then we should // also ask the server to forget it *once*. // if (VirtioFsFile->NodeId !=VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID ) {VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId); }
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 28/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_STATFS
In reply to Laszlo ErsekAdd the VirtioFsFuseStatFs() function, for sending the FUSE_STATFS command to the Virtio Filesystem device.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 17 ++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 ++ OvmfPkg/VirtioFsDxe/FuseStatFs.c | 102 ++++++++++++++++++++ 4 files changed, 127 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +17 -0
@@ -114,16 +114,17 @@ typedef struct { typedef enum { VirtioFsFuseOpLookup = 1, VirtioFsFuseOpForget = 2, VirtioFsFuseOpGetAttr = 3, VirtioFsFuseOpMkDir = 9, VirtioFsFuseOpUnlink = 10, VirtioFsFuseOpRmDir = 11, VirtioFsFuseOpOpen = 14, + VirtioFsFuseOpStatFs = 17, VirtioFsFuseOpRelease = 18, VirtioFsFuseOpFsync = 20, VirtioFsFuseOpFlush = 25, VirtioFsFuseOpInit = 26, VirtioFsFuseOpOpenDir = 27, VirtioFsFuseOpReleaseDir = 29, VirtioFsFuseOpFsyncDir = 30, VirtioFsFuseOpCreate = 35,
@@ -228,16 +229,32 @@ typedef struct { }VIRTIO_FS_FUSE_OPEN_REQUEST ;typedef struct {UINT64 FileHandle;UINT32 OpenFlags;UINT32 Padding; }VIRTIO_FS_FUSE_OPEN_RESPONSE ; +// +// Header for VirtioFsFuseOpStatFs. +// +typedef struct { +UINT64 Blocks; +UINT64 Bfree; +UINT64 Bavail; +UINT64 Files; +UINT64 Ffree; +UINT32 Bsize; +UINT32 Namelen; +UINT32 Frsize; +UINT32 Padding; +UINT32 Spare[6 ]; +}VIRTIO_FS_FUSE_STATFS_RESPONSE ; +// // Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir. // typedef struct { UINT64 FileHandle; UINT32 Flags; UINT32 ReleaseFlags; UINT64 LockOwner;
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -89,16 +89,17 @@ [Sources] FuseGetAttr.c FuseInit.c FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRelease.c + FuseStatFs.c FuseUnlink.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c SimpleFsOpen.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +7 -0
@@ -285,16 +285,23 @@ VirtioFsFuseRemoveFileOrDir (EFI_STATUS VirtioFsFuseOpen ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN BOOLEAN ReadWrite, OUT UINT64 *FuseHandle ); +EFI_STATUS +VirtioFsFuseStatFs ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr + ); +EFI_STATUS VirtioFsFuseReleaseFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir );
OvmfPkg/VirtioFsDxe/FuseStatFs.c new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 29/48 OvmfPkg/VirtioFsDxe: add helper for formatting UEFI basenames
In reply to Laszlo ErsekThe EFI_FILE_INFO structure, which is output by EFI_FILE_PROTOCOL.GetInfo(), ends with a flexible CHAR16 array called "FileName". Add the VirtioFsGetBasename() function, for determining the required array size, and for filling the array as well.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 +++ OvmfPkg/VirtioFsDxe/Helpers.c | 61 ++++++++++++++++++++ 2 files changed, 68 insertions(+)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +7 -0
@@ -229,16 +229,23 @@ VirtioFsAppendPath (EFI_STATUS VirtioFsLookupMostSpecificParentDir ( IN OUT VIRTIO_FS *VirtioFs, IN OUT CHAR8 *Path, OUT UINT64 *DirNodeId, OUT CHAR8 **LastComponent ); +EFI_STATUS +VirtioFsGetBasename ( + IN CHAR8 *Path, + OUT CHAR16 *Basename OPTIONAL, + IN OUT UINTN *BasenameSize + ); +EFI_STATUS VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo );// // Wrapper functions for FUSE commands (primitives).
OvmfPkg/VirtioFsDxe/Helpers.c +61 -0
77 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 30/48 OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.GetInfo()
In reply to Laszlo ErsekUsing the functions introduced previously, we can now implement VirtioFsSimpleFileGetInfo().
This allows the "VOL" command to work in the UEFI shell.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 5 + OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c | 190 +++++++++++++++++++- 2 files changed, 194 insertions(+), 1 deletion(-)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +5 -0
@@ -120,8 +120,13 @@ [LibraryClasses] UefiDriverEntryPoint VirtioLib [Protocols] gEfiComponentName2ProtocolGuid ## PRODUCES gEfiDriverBindingProtocolGuid ## PRODUCES gEfiSimpleFileSystemProtocolGuid ## BY_START gVirtioDeviceProtocolGuid ## TO_START + +[Guids] + gEfiFileInfoGuid + gEfiFileSystemInfoGuid + gEfiFileSystemVolumeLabelInfoIdGuid
OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c +189 -1
210 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 31/48 OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.GetPosition, .SetPosition
In reply to Laszlo ErsekUsing the functions introduced previously, we can now implement VirtioFsSimpleFileGetPosition() and VirtioFsSimpleFileSetPosition().
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 1 + OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c | 9 ++++- OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 1 + OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 1 + OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c | 40 +++++++++++++++++++- 5 files changed, 50 insertions(+), 2 deletions(-)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +1 -0
@@ -134,16 +134,17 @@ typedef struct { typedef struct { UINT64 Signature; EFI_FILE_PROTOCOL SimpleFile; BOOLEAN IsDirectory; BOOLEAN IsOpenForWriting; VIRTIO_FS *OwnerFs; LIST_ENTRY OpenFilesEntry; CHAR8 *CanonicalPathname; + UINT64 FilePosition; // // In the FUSE wire protocol, every request except FUSE_INIT refers to a // file, namely by the "VIRTIO_FS_FUSE_REQUEST.NodeId" field; that is, by the // inode number of the file. However, some of the FUSE requests that we need // for some of the EFI_FILE_PROTOCOL member functions require an open file // handle *in addition* to the inode number. For simplicity, whenever a // VIRTIO_FS_FILE object is created, primarily defined by its NodeId field, // we also *open* the referenced file at once, and save the returned file
OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c +8 -1
@@ -11,10 +11,17 @@EFI_STATUS EFIAPIVirtioFsSimpleFileGetPosition ( IN EFI_FILE_PROTOCOL *This, OUT UINT64 *Position ) { -return EFI_DEVICE_ERROR ; +VIRTIO_FS_FILE *VirtioFsFile; + + VirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); +if (VirtioFsFile->IsDirectory) { +return EFI_UNSUPPORTED ; + } + *Position = VirtioFsFile->FilePosition; +return EFI_SUCCESS ; }
OvmfPkg/VirtioFsDxe/SimpleFsOpen.c +1 -0
@@ -474,16 +474,17 @@ VirtioFsSimpleFileOpen ( NewVirtioFsFile->SimpleFile.SetPosition = VirtioFsSimpleFileSetPosition; NewVirtioFsFile->SimpleFile.GetInfo = VirtioFsSimpleFileGetInfo; NewVirtioFsFile->SimpleFile.SetInfo = VirtioFsSimpleFileSetInfo; NewVirtioFsFile->SimpleFile.Flush = VirtioFsSimpleFileFlush; NewVirtioFsFile->IsDirectory = NewNodeIsDirectory; NewVirtioFsFile->IsOpenForWriting = OpenForWriting; NewVirtioFsFile->OwnerFs = VirtioFs; NewVirtioFsFile->CanonicalPathname = NewCanonicalPath; + NewVirtioFsFile->FilePosition =0 ; NewVirtioFsFile->NodeId = NewNodeId; NewVirtioFsFile->FuseHandle = NewFuseHandle;// // One more file is now open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &NewVirtioFsFile->OpenFilesEntry);
OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +1 -0
@@ -67,16 +67,17 @@ VirtioFsOpenVolume ( VirtioFsFile->SimpleFile.SetPosition = VirtioFsSimpleFileSetPosition; VirtioFsFile->SimpleFile.GetInfo = VirtioFsSimpleFileGetInfo; VirtioFsFile->SimpleFile.SetInfo = VirtioFsSimpleFileSetInfo; VirtioFsFile->SimpleFile.Flush = VirtioFsSimpleFileFlush; VirtioFsFile->IsDirectory = TRUE; VirtioFsFile->IsOpenForWriting = FALSE; VirtioFsFile->OwnerFs = VirtioFs; VirtioFsFile->CanonicalPathname = CanonicalPathname; + VirtioFsFile->FilePosition =0 ; VirtioFsFile->NodeId =VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID ; VirtioFsFile->FuseHandle = RootDirHandle;// // One more file open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry);
OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c +39 -1
@@ -11,10 +11,48 @@EFI_STATUS EFIAPIVirtioFsSimpleFileSetPosition ( IN EFI_FILE_PROTOCOL *This, IN UINT64 Position ) { -return EFI_DEVICE_ERROR ; +VIRTIO_FS_FILE *VirtioFsFile; +VIRTIO_FS *VirtioFs; +EFI_STATUS Status; +VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; + + VirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + +// +// Directories can only be rewound, per spec. +// +if (VirtioFsFile->IsDirectory) { +if (Position !=0 ) { +return EFI_UNSUPPORTED ; + } + VirtioFsFile->FilePosition =0 ; +return EFI_SUCCESS ; + } + +// +// Regular file. +// +if (Position <MAX_UINT64 ) { +// +// Caller is requesting absolute file position. +// + VirtioFsFile->FilePosition = Position; +return EFI_SUCCESS ; + } + +// +// Caller is requesting a seek to EOF. +// + VirtioFs = VirtioFsFile->OwnerFs; + Status =VirtioFsFuseGetAttr (VirtioFs, VirtioFsFile->NodeId, &FuseAttr); +if (EFI_ERROR (Status)) { +return Status; + } + VirtioFsFile->FilePosition = FuseAttr.Size; +return EFI_SUCCESS ; }
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 32/48 OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_READ / FUSE_READDIRPLUS
In reply to Laszlo ErsekAdd the VirtioFsFuseReadFileOrDir() function, for sending the FUSE_READ or FUSE_READDIRPLUS command to the Virtio Filesystem device.
Parsing the structured FUSE_READDIRPLUS output is complex, and cannot be integrated into the wrapper function. Given that fact, FUSE_READ and FUSE_READDIRPLUS turn out to need identical low-level handling, except for the opcode. Hence the shared wrapper function.
(It's prudent to verify whether the FUSE server supports FUSE_READDIRPLUS, so update the session init code accordingly.)
This is the first FUSE request wrapper function that deals with a variable size tail buffer.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 67 +++++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 11 ++ OvmfPkg/VirtioFsDxe/FuseInit.c | 10 +- OvmfPkg/VirtioFsDxe/FuseRead.c | 191 ++++++++++++++++++++ 5 files changed, 276 insertions(+), 4 deletions(-)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +67 -0
@@ -103,36 +103,71 @@ typedef struct {#define VIRTIO_FS_FUSE_MODE_PERM_WOTH 0000002u// // Flags for VirtioFsFuseOpOpen. // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 +// +// Flags for VirtioFsFuseOpInit. +// +#define VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS BIT13 + +/** +Macro for calculating the size of a directory stream entry. + +The macro may evaluate Namelen multiple times. + +The macro evaluates to a UINTN value that is safe to cast to UINT32. + +@param[in] Namelen The size of the filename byte array that follows +VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE in the directory +stream, as reported by +VIRTIO_FS_FUSE_STATFS_RESPONSE.Namelen or +VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE.Namelen. The filename +byte array is not NUL-terminated. + +@retval 0 Namelen was zero or greater than SIZE_4KB. + +@return The number of bytes in the directory entry, including the +VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE header. +**/ +#define VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE (Namelen) \ + ((Namelen) == 0 || (Namelen) > SIZE_4KB ? \ + (UINTN)0 : \ + ALIGN_VALUE ( \ + sizeof (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE) + (UINTN)(Namelen), \ + sizeof (UINT64) \ + ) \ + ) +// // FUSE operation codes. // typedef enum { VirtioFsFuseOpLookup =1 , VirtioFsFuseOpForget =2 , VirtioFsFuseOpGetAttr =3 , VirtioFsFuseOpMkDir =9 , VirtioFsFuseOpUnlink =10 , VirtioFsFuseOpRmDir =11 , VirtioFsFuseOpOpen =14 , + VirtioFsFuseOpRead =15 , VirtioFsFuseOpStatFs =17 , VirtioFsFuseOpRelease =18 , VirtioFsFuseOpFsync =20 , VirtioFsFuseOpFlush =25 , VirtioFsFuseOpInit =26 , VirtioFsFuseOpOpenDir =27 , VirtioFsFuseOpReleaseDir =29 , VirtioFsFuseOpFsyncDir =30 , VirtioFsFuseOpCreate =35 , + VirtioFsFuseOpReadDirPlus =44 , }VIRTIO_FS_FUSE_OPCODE ;#pragma pack (1)// // Request-response headers common to all request types. // typedef struct { UINT32 Len;
@@ -229,16 +264,29 @@ typedef struct { }VIRTIO_FS_FUSE_OPEN_REQUEST ;typedef struct {UINT64 FileHandle;UINT32 OpenFlags;UINT32 Padding; }VIRTIO_FS_FUSE_OPEN_RESPONSE ; +// +// Header for VirtioFsFuseOpRead and VirtioFsFuseOpReadDirPlus. +// +typedef struct { +UINT64 FileHandle; +UINT64 Offset; +UINT32 Size; +UINT32 ReadFlags; +UINT64 LockOwner; +UINT32 Flags; +UINT32 Padding; +}VIRTIO_FS_FUSE_READ_REQUEST ; +// // Header for VirtioFsFuseOpStatFs. // typedef struct { UINT64 Blocks; UINT64 Bfree; UINT64 Bavail; UINT64 Files;
@@ -307,11 +355,30 @@ typedef struct {// Header for VirtioFsFuseOpCreate. // typedef struct {UINT32 Flags;UINT32 Mode;UINT32 Umask;UINT32 Padding; }VIRTIO_FS_FUSE_CREATE_REQUEST ; + +// +// Header for VirtioFsFuseOpReadDirPlus. +// +// Diverging from the rest of the headers, this structure embeds other +// structures. The reason is that a scatter list cannot be used to receive +// NodeResp and AttrResp separately; the record below is followed by a variable +// size filename byte array, and then such pairs are repeated a number of +// times. Thus, later header start offsets depend on earlier filename array +// sizes. +// +typedef struct { +VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp; +VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp; +UINT64 NodeId; +UINT64 CookieForNextEntry; +UINT32 Namelen; +UINT32 Type; +}VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE ;#pragma pack ()#endif // VIRTIO_FS_H_
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -88,16 +88,17 @@ [Sources] FuseFsync.c FuseGetAttr.c FuseInit.c FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c + FuseRead.c FuseRelease.c FuseStatFs.c FuseUnlink.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +11 -0
@@ -293,16 +293,27 @@ VirtioFsFuseRemoveFileOrDir (EFI_STATUS VirtioFsFuseOpen ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN BOOLEAN ReadWrite, OUT UINT64 *FuseHandle ); +EFI_STATUS +VirtioFsFuseReadFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir, + IN UINT64 Offset, + IN OUT UINT32 *Size, + OUT VOID *Data + ); +EFI_STATUS VirtioFsFuseStatFs ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr );EFI_STATUS
OvmfPkg/VirtioFsDxe/FuseInit.c +6 -4
@@ -21,17 +21,18 @@ before VirtioFsUninit() is called. @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_INIT request to. The FUSE request counter "VirtioFs->RequestId" is set to 1 on output. @retval EFI_SUCCESS The FUSE session has been started. - @retval EFI_UNSUPPORTED FUSE interface version negotiation failed. + @retval EFI_UNSUPPORTED FUSE interface version or feature negotiation + failed. @return The "errno" value mapped to an EFI_STATUS code, if the Virtio Filesystem device explicitly reported an error. @return Error codes propagated from VirtioFsSgListsValidate(), VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
@@ -92,17 +93,17 @@ VirtioFsFuseInitSession ( }// // Populate the FUSE_INIT-specific fields. // InitReq.Major =VIRTIO_FS_FUSE_MAJOR ; InitReq.Minor =VIRTIO_FS_FUSE_MINOR ; InitReq.MaxReadahead =0 ; - InitReq.Flags =0 ; + InitReq.Flags =VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS ;// // Submit the request. // Status =VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);if (EFI_ERROR (Status)) {return Status; }
@@ -116,17 +117,18 @@ VirtioFsFuseInitSession (DEBUG ((DEBUG_ERROR ,"%a: Label=\"%s\" Errno=%d\n" , __FUNCTION__, VirtioFs->Label, CommonResp.Error)); Status =VirtioFsErrnoToEfiStatus (CommonResp.Error); }return Status; }// -// Check FUSE interface version compatibility. +// Check FUSE interface version / feature compatibility. // if (InitResp.Major < InitReq.Major || - (InitResp.Major == InitReq.Major && InitResp.Minor < InitReq.Minor)) { + (InitResp.Major == InitReq.Major && InitResp.Minor < InitReq.Minor) || + (InitResp.Flags &VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS ) ==0 ) {return EFI_UNSUPPORTED ; }return EFI_SUCCESS ; }
OvmfPkg/VirtioFsDxe/FuseRead.c new file +191 -0
191 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 33/48 OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Read() for regular files
In reply to Laszlo ErsekUsing the functions introduced previously, we can now implement VirtioFsSimpleFileRead(); for regular files at first.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/SimpleFsRead.c | 75 +++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-)
OvmfPkg/VirtioFsDxe/SimpleFsRead.c +74 -1
@@ -3,18 +3,91 @@Copyright (C) 2020, Red Hat, Inc. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "VirtioFsDxe.h" +/** +Read from a regular file. +**/ +STATIC +EFI_STATUS +ReadRegularFile ( + IN OUT VIRTIO_FS_FILE *VirtioFsFile, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ +VIRTIO_FS *VirtioFs; +EFI_STATUS Status; +VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; +UINTN Transferred; +UINTN Left; + + VirtioFs = VirtioFsFile->OwnerFs; +// +// The UEFI spec forbids reads that start beyond the end of the file. +// + Status =VirtioFsFuseGetAttr (VirtioFs, VirtioFsFile->NodeId, &FuseAttr); +if (EFI_ERROR (Status) || VirtioFsFile->FilePosition > FuseAttr.Size) { +return EFI_DEVICE_ERROR ; + } + + Status =EFI_SUCCESS ; + Transferred =0 ; + Left = *BufferSize; +while (Left >0 ) { +UINT32 ReadSize; + +// +// FUSE_READ cannot express a >=4GB buffer size. +// + ReadSize = (UINT32 )MIN ((UINTN )MAX_UINT32 , Left); + Status =VirtioFsFuseReadFileOrDir ( + VirtioFs, + VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, + FALSE,// IsDir + VirtioFsFile->FilePosition + Transferred, + &ReadSize, + (UINT8 *)Buffer + Transferred + ); +if (EFI_ERROR (Status) || ReadSize ==0 ) { +break ; + } + Transferred += ReadSize; + Left -= ReadSize; + } + + *BufferSize = Transferred; + VirtioFsFile->FilePosition += Transferred; +// +// If we managed to read some data, return success. If zero bytes were +// transferred due to zero-sized buffer on input or due to EOF on first read, +// return SUCCESS. Otherwise, return the error due to which zero bytes were +// transferred. +// +return (Transferred >0 ) ?EFI_SUCCESS : Status; +} +EFI_STATUS EFIAPIVirtioFsSimpleFileRead ( IN EFI_FILE_PROTOCOL *This, IN OUT UINTN *BufferSize, OUT VOID *Buffer ) { -return EFI_NO_MEDIA ; +VIRTIO_FS_FILE *VirtioFsFile; +EFI_STATUS Status; + + VirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + +if (VirtioFsFile->IsDirectory) { + Status =EFI_NO_MEDIA ; + }else { + Status =ReadRegularFile (VirtioFsFile, BufferSize, Buffer); + } +return Status; }
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 34/48 OvmfPkg/VirtioFsDxe: convert FUSE dirent filename to EFI_FILE_INFO
In reply to Laszlo ErsekIntroduce the VirtioFsFuseDirentPlusToEfiFileInfo() function, for converting the VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE filename byte array to EFI_FILE_INFO.
This new function updates those EFI_FILE_INFO fields (Size, FileName) that the earlier helper function VirtioFsFuseAttrToEfiFileInfo() does not set.
Both functions together will be able to fill in EFI_FILE_INFO completely, from FUSE_READDIRPLUS.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 6 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 79 ++++++++++++++++++++ 2 files changed, 85 insertions(+)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +6 -0
@@ -243,16 +243,22 @@ VirtioFsGetBasename ( );EFI_STATUS VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo ); +EFI_STATUS +VirtioFsFuseDirentPlusToEfiFileInfo ( + IN VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *FuseDirent, + IN OUT EFI_FILE_INFO *FileInfo + ); +// // Wrapper functions for FUSE commands (primitives). // EFI_STATUS VirtioFsFuseLookup ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 DirNodeId,
OvmfPkg/VirtioFsDxe/Helpers.c +79 -0
87 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 35/48 OvmfPkg/VirtioFsDxe: add EFI_FILE_INFO cache fields to VIRTIO_FS_FILE
In reply to Laszlo ErsekFor reading through a directory stream with tolerable performance, we'll have to call FUSE_READDIRPLUS each time with such a buffer that can deliver a good number of variable size records (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE elements). Every time we'll do that, we'll turn the whole bunch into an array of EFI_FILE_INFOs immediately. EFI_FILE_PROTOCOL.Read() invocations (on directories) will be served from this EFI_FILE_INFO cache.
Add the fields for the EFI_FILE_INFO cache to VIRTIO_FS_FILE:
- initialize them in Open() and OpenVolume(),
- release the cache in Close() and Delete(),
- also release the cache when the directory is rewound, in SetPosition().
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 19 +++++++++++++++++++ OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 3 +++ OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 3 +++ OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 4 ++++ OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 4 ++++ OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c | 9 +++++++++ 6 files changed, 42 insertions(+)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +19 -0
@@ -42,16 +42,21 @@// // The limit is not expected to be a practical limitation; it's only supposed // to prevent attempts at overflowing size calculations. For both kinds of // pathnames, separate limits could be used; a common limit is used purely for // simplicity. // #define VIRTIO_FS_MAX_PATHNAME_LENGTH ((UINTN)65535) +// +// Maximum value for VIRTIO_FS_FILE.NumFileInfo. +// +#define VIRTIO_FS_FILE_MAX_FILE_INFO 256 +// // Filesystem label encoded in UCS-2, transformed from the UTF-8 representation // in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII code // points (U+0020 through U+007E) are supported. // typedef CHAR16 VIRTIO_FS_LABEL [VIRTIO_FS_TAG_BYTES +1 ];//
@@ -149,16 +154,30 @@ typedef struct {// VIRTIO_FS_FILE object is created, primarily defined by its NodeId field, // we also *open* the referenced file at once, and save the returned file // handle in the FuseHandle field. This way, when an EFI_FILE_PROTOCOL member // function must send a FUSE request that needs the file handle *in addition* // to the inode number, FuseHandle will be at our disposal at once. // UINT64 NodeId;UINT64 FuseHandle; +// +// EFI_FILE_INFO objects cached for an in-flight directory read. +// +// For reading through a directory stream with tolerable performance, we have +// to call FUSE_READDIRPLUS each time with such a buffer that can deliver a +// good number of variable size records (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE +// elements). Every time we do that, we turn the whole bunch into an array of +// EFI_FILE_INFOs immediately. EFI_FILE_PROTOCOL.Read() invocations (on +// directories) will be served from this EFI_FILE_INFO cache. +// +UINT8 *FileInfoArray; +UINTN SingleFileInfoSize; +UINTN NumFileInfo; +UINTN NextFileInfo; }VIRTIO_FS_FILE ;#define VIRTIO_FS_FILE_FROM_SIMPLE_FILE (SimpleFileReference) \ CR (SimpleFileReference, VIRTIO_FS_FILE, SimpleFile, VIRTIO_FS_FILE_SIG);#define VIRTIO_FS_FILE_FROM_OPEN_FILES_ENTRY (OpenFilesEntryReference) \ CR (OpenFilesEntryReference, VIRTIO_FS_FILE, OpenFilesEntry, \ VIRTIO_FS_FILE_SIG);
OvmfPkg/VirtioFsDxe/SimpleFsClose.c +3 -0
@@ -55,11 +55,14 @@ VirtioFsSimpleFileClose ( }// // One fewer file left open for the owner filesystem. // RemoveEntryList (&VirtioFsFile->OpenFilesEntry);FreePool (VirtioFsFile->CanonicalPathname); +if (VirtioFsFile->FileInfoArray !=NULL ) { +FreePool (VirtioFsFile->FileInfoArray); + }FreePool (VirtioFsFile);return EFI_SUCCESS ; }
OvmfPkg/VirtioFsDxe/SimpleFsDelete.c +3 -0
@@ -97,11 +97,14 @@ VirtioFsSimpleFileDelete ( }// // One fewer file left open for the owner filesystem. // RemoveEntryList (&VirtioFsFile->OpenFilesEntry);FreePool (VirtioFsFile->CanonicalPathname); +if (VirtioFsFile->FileInfoArray !=NULL ) { +FreePool (VirtioFsFile->FileInfoArray); + }FreePool (VirtioFsFile);return Status; }
OvmfPkg/VirtioFsDxe/SimpleFsOpen.c +4 -0
@@ -477,16 +477,20 @@ VirtioFsSimpleFileOpen ( NewVirtioFsFile->SimpleFile.Flush = VirtioFsSimpleFileFlush; NewVirtioFsFile->IsDirectory = NewNodeIsDirectory; NewVirtioFsFile->IsOpenForWriting = OpenForWriting; NewVirtioFsFile->OwnerFs = VirtioFs; NewVirtioFsFile->CanonicalPathname = NewCanonicalPath; NewVirtioFsFile->FilePosition =0 ; NewVirtioFsFile->NodeId = NewNodeId; NewVirtioFsFile->FuseHandle = NewFuseHandle; + NewVirtioFsFile->FileInfoArray =NULL ; + NewVirtioFsFile->SingleFileInfoSize =0 ; + NewVirtioFsFile->NumFileInfo =0 ; + NewVirtioFsFile->NextFileInfo =0 ;// // One more file is now open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &NewVirtioFsFile->OpenFilesEntry); *NewHandle = &NewVirtioFsFile->SimpleFile;return EFI_SUCCESS ;
OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +4 -0
@@ -70,16 +70,20 @@ VirtioFsOpenVolume ( VirtioFsFile->SimpleFile.Flush = VirtioFsSimpleFileFlush; VirtioFsFile->IsDirectory = TRUE; VirtioFsFile->IsOpenForWriting = FALSE; VirtioFsFile->OwnerFs = VirtioFs; VirtioFsFile->CanonicalPathname = CanonicalPathname; VirtioFsFile->FilePosition =0 ; VirtioFsFile->NodeId =VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID ; VirtioFsFile->FuseHandle = RootDirHandle; + VirtioFsFile->FileInfoArray =NULL ; + VirtioFsFile->SingleFileInfoSize =0 ; + VirtioFsFile->NumFileInfo =0 ; + VirtioFsFile->NextFileInfo =0 ;// // One more file open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry); *Root = &VirtioFsFile->SimpleFile;return EFI_SUCCESS ;
OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c +9 -0
@@ -2,16 +2,18 @@EFI_FILE_PROTOCOL.SetPosition() member function for the Virtio Filesystem driver. Copyright (C) 2020, Red Hat, Inc. SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include <Library/MemoryAllocationLib.h> // FreePool() +#include "VirtioFsDxe.h" EFI_STATUS EFIAPIVirtioFsSimpleFileSetPosition ( IN EFI_FILE_PROTOCOL *This, IN UINT64 Position )
@@ -26,16 +28,23 @@ VirtioFsSimpleFileSetPosition (// // Directories can only be rewound, per spec. // if (VirtioFsFile->IsDirectory) {if (Position !=0 ) {return EFI_UNSUPPORTED ; } VirtioFsFile->FilePosition =0 ; +if (VirtioFsFile->FileInfoArray !=NULL ) { +FreePool (VirtioFsFile->FileInfoArray); + VirtioFsFile->FileInfoArray =NULL ; + } + VirtioFsFile->SingleFileInfoSize =0 ; + VirtioFsFile->NumFileInfo =0 ; + VirtioFsFile->NextFileInfo =0 ;return EFI_SUCCESS ; }// // Regular file. // if (Position <MAX_UINT64 ) {//
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 36/48 OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Read() for directories
In reply to Laszlo ErsekUsing the functions introduced previously, we can now implement VirtioFsSimpleFileRead() for directories as well.
This patch completes the read-only support for virtio-fs. Commands like "TYPE" and "DIR" work in the UEFI shell.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/SimpleFsRead.c | 343 +++++++++++++++++++- 1 file changed, 342 insertions(+), 1 deletion(-)
OvmfPkg/VirtioFsDxe/SimpleFsRead.c +342 -1
@@ -1,18 +1,359 @@/** @file EFI_FILE_PROTOCOL.Read() member function for the Virtio Filesystem driver. Copyright (C) 2020, Red Hat, Inc. SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include <Library/BaseMemoryLib.h> // CopyMem() +#include <Library/MemoryAllocationLib.h> // AllocatePool() +#include "VirtioFsDxe.h" +/** +Populate a caller-allocated EFI_FILE_INFO object from +VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE. + +@param[in] Dirent The entry read from the directory stream. The +caller is responsible for ensuring that +Dirent->Namelen describe valid storage. + +@param[in] SingleFileInfoSize The allocated size of FileInfo. + +@param[out] FileInfo The EFI_FILE_INFO object to populate. On +success, all fields in FileInfo will be +updated, setting FileInfo->Size to the +actually used size (which will not exceed +SingleFileInfoSize). + +@retval EFI_SUCCESS FileInfo has been filled in. + +@return Error codes propagated from +VirtioFsFuseDirentPlusToEfiFileInfo() and +VirtioFsFuseAttrToEfiFileInfo(). The contents of +FileInfo are indeterminate. +**/ +STATIC +EFI_STATUS +PopulateFileInfo ( + IN VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *Dirent, + IN UINTN SingleFileInfoSize, + OUT EFI_FILE_INFO *FileInfo + ) +{ +EFI_STATUS Status; + +// +// Convert the name, set the actual size. +// + FileInfo->Size = SingleFileInfoSize; + Status =VirtioFsFuseDirentPlusToEfiFileInfo (Dirent, FileInfo); +if (EFI_ERROR (Status)) { +return Status; + } +// +// Populate the scalar fields. +// + Status =VirtioFsFuseAttrToEfiFileInfo (&Dirent->AttrResp, FileInfo); +return Status; +} + +/** +Refill the EFI_FILE_INFO cache from the directory stream. +**/ +STATIC +EFI_STATUS +RefillFileInfoCache ( + IN OUT VIRTIO_FS_FILE *VirtioFsFile + ) +{ +VIRTIO_FS *VirtioFs; +EFI_STATUS Status; +VIRTIO_FS_FUSE_STATFS_RESPONSE FilesysAttr; +UINT32 DirentBufSize; +UINT8 *DirentBuf; +UINTN SingleFileInfoSize; +UINT8 *FileInfoArray; +UINT64 DirStreamCookie; +UINT64 CacheEndsAtCookie; +UINTN NumFileInfo; + +// +// Allocate a DirentBuf that can receive at least +// VIRTIO_FS_FILE_MAX_FILE_INFO directory entries, based on the maximum +// filename length supported by the filesystem. Note that the multiplication +// is safe from overflow due to the VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE() +// check. +// + VirtioFs = VirtioFsFile->OwnerFs; + Status =VirtioFsFuseStatFs (VirtioFs, VirtioFsFile->NodeId, &FilesysAttr); +if (EFI_ERROR (Status)) { +return Status; + } + DirentBufSize = (UINT32 )VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE ( + FilesysAttr.Namelen); +if (DirentBufSize ==0 ) { +return EFI_UNSUPPORTED ; + } + DirentBufSize *=VIRTIO_FS_FILE_MAX_FILE_INFO ; + DirentBuf =AllocatePool (DirentBufSize); +if (DirentBuf ==NULL ) { +return EFI_OUT_OF_RESOURCES ; + } + +// +// Allocate the EFI_FILE_INFO cache. A single EFI_FILE_INFO element is sized +// accordingly to the maximum filename length supported by the filesystem. +// +// Note that the calculation below cannot overflow, due to the filename limit +// imposed by the VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE() check above. The +// calculation takes the L'\0' character that we'll need to append into +// account. +// + SingleFileInfoSize = (OFFSET_OF (EFI_FILE_INFO , FileName) + + ((UINTN )FilesysAttr.Namelen +1 ) *sizeof (CHAR16 )); + FileInfoArray =AllocatePool ( +VIRTIO_FS_FILE_MAX_FILE_INFO * SingleFileInfoSize + ); +if (FileInfoArray ==NULL ) { + Status =EFI_OUT_OF_RESOURCES ; + goto FreeDirentBuf; + } + +// +// Pick up reading the directory stream where the previous cache ended. +// + DirStreamCookie = VirtioFsFile->FilePosition; + CacheEndsAtCookie = VirtioFsFile->FilePosition; + NumFileInfo =0 ; +do { +UINT32 Remaining; +UINT32 Consumed; + +// +// Fetch a chunk of the directory stream. The chunk may hold more entries +// than what we can fit in the cache. The chunk may also not entirely fill +// the cache, especially after filtering out entries that cannot be +// supported under UEFI (sockets, FIFOs, filenames with backslashes, etc). +// + Remaining = DirentBufSize; + Status =VirtioFsFuseReadFileOrDir ( + VirtioFs, + VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, + TRUE,// IsDir + DirStreamCookie,// Offset + &Remaining,// Size + DirentBuf// Data + ); +if (EFI_ERROR (Status)) { + goto FreeFileInfoArray; + } + +if (Remaining ==0 ) { +// +// The directory stream ends. +// +break ; + } + +// +// Iterate over all records in DirentBuf. Primarily, forget them all. +// Secondarily, if a record proves transformable to EFI_FILE_INFO, add it +// to the EFI_FILE_INFO cache (unless the cache is full). +// + Consumed =0 ; +while (Remaining >=sizeof (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE )) { +VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *Dirent; +UINT32 DirentSize; + + Dirent = (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *)(DirentBuf + Consumed); + DirentSize = (UINT32 )VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE ( + Dirent->Namelen); +if (DirentSize ==0 ) { +// +// This means one of two things: (a) Dirent->Namelen is zero, or (b) +// (b) Dirent->Namelen is unsupportably large. (a) is just invalid for +// the Virtio Filesystem device to send, while (b) shouldn't happen +// because "FilesysAttr.Namelen" -- the maximum filename length +// supported by the filesystem -- proved acceptable above. +// + Status =EFI_PROTOCOL_ERROR ; + goto FreeFileInfoArray; + } +if (DirentSize > Remaining) { +// +// Dirent->Namelen suggests that the filename byte array (plus any +// padding) are truncated. This should never happen; the Virtio +// Filesystem device is supposed to send complete entries only. +// + Status =EFI_PROTOCOL_ERROR ; + goto FreeFileInfoArray; + } +if (Dirent->Namelen > FilesysAttr.Namelen) { +// +// This is possible without tripping the truncation check above, due to +// how entries are padded. The condition means that Dirent->Namelen is +// reportedly larger than the filesystem limit, without spilling into +// the next alignment bucket. Should never happen. +// + Status =EFI_PROTOCOL_ERROR ; + goto FreeFileInfoArray; + } + +// +// If we haven't filled the EFI_FILE_INFO cache yet, attempt transforming +// Dirent to EFI_FILE_INFO. +// +if (NumFileInfo <VIRTIO_FS_FILE_MAX_FILE_INFO ) { +EFI_FILE_INFO *FileInfo; + + FileInfo = (EFI_FILE_INFO *)(FileInfoArray + + (NumFileInfo * SingleFileInfoSize)); + Status =PopulateFileInfo (Dirent, SingleFileInfoSize, FileInfo); +if (!EFI_ERROR (Status)) { +// +// Dirent has been transformed and cached successfully. +// + NumFileInfo++; +// +// The next time we refill the cache, restart reading the directory +// stream right after the entry that we've just transformed and +// cached. +// + CacheEndsAtCookie = Dirent->CookieForNextEntry; + } +// +// If Dirent wasn't transformable to an EFI_FILE_INFO, we'll just skip +// it. +// + } + +// +// Make the Virtio Filesystem device forget the NodeId in this directory +// entry, as we'll need it no more. (The "." and ".." entries need no +// FUSE_FORGET requests, when returned by FUSE_READDIRPLUS -- and so the +// Virtio Filesystem device reports their NodeId fields as zero.) +// +if (Dirent->NodeResp.NodeId !=0 ) { +VirtioFsFuseForget (VirtioFs, Dirent->NodeResp.NodeId); + } + +// +// Advance to the next entry in DirentBuf. +// + DirStreamCookie = Dirent->CookieForNextEntry; + Consumed += DirentSize; + Remaining -= DirentSize; + } + +if (Remaining >0 ) { +// +// This suggests that a VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE header was +// truncated. This should never happen; the Virtio Filesystem device is +// supposed to send complete entries only. +// + Status =EFI_PROTOCOL_ERROR ; + goto FreeFileInfoArray; + } +// +// Fetch another DirentBuf from the directory stream, unless we've filled +// the EFI_FILE_INFO cache. +// + }while (NumFileInfo <VIRTIO_FS_FILE_MAX_FILE_INFO ); + +// +// Commit the results. (Note that the result may be an empty cache.) +// +if (VirtioFsFile->FileInfoArray !=NULL ) { +FreePool (VirtioFsFile->FileInfoArray); + } + VirtioFsFile->FileInfoArray = FileInfoArray; + VirtioFsFile->SingleFileInfoSize = SingleFileInfoSize; + VirtioFsFile->NumFileInfo = NumFileInfo; + VirtioFsFile->NextFileInfo =0 ; + VirtioFsFile->FilePosition = CacheEndsAtCookie; + +FreePool (DirentBuf); +return EFI_SUCCESS ; + +FreeFileInfoArray: +FreePool (FileInfoArray); + +FreeDirentBuf: +FreePool (DirentBuf); + +return Status; +} + +/** +Read an entry from the EFI_FILE_INFO cache. +**/ +STATIC +EFI_STATUS +ReadFileInfoCache ( + IN OUT VIRTIO_FS_FILE *VirtioFsFile, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ +EFI_FILE_INFO *FileInfo; +UINTN CallerAllocated; + +// +// Refill the cache if needed. If the refill doesn't produce any new +// EFI_FILE_INFO, report End of Directory, by setting (*BufferSize) to 0. +// +if (VirtioFsFile->NextFileInfo == VirtioFsFile->NumFileInfo) { +EFI_STATUS Status; + + Status =RefillFileInfoCache (VirtioFsFile); +if (EFI_ERROR (Status)) { +return (Status ==EFI_BUFFER_TOO_SMALL ) ?EFI_DEVICE_ERROR : Status; + } +if (VirtioFsFile->NumFileInfo ==0 ) { + *BufferSize =0 ; +return EFI_SUCCESS ; + } + } + FileInfo = (EFI_FILE_INFO *)(VirtioFsFile->FileInfoArray + + (VirtioFsFile->NextFileInfo * + VirtioFsFile->SingleFileInfoSize)); + +// +// Check if the caller is ready to accept FileInfo. If not, we'll just +// present the required size for now. +// +// (The (UINTN) cast below is safe because FileInfo->Size has been reduced +// from VirtioFsFile->SingleFileInfoSize, in +// +// RefillFileInfoCache() +// PopulateFileInfo() +// VirtioFsFuseDirentPlusToEfiFileInfo() +// +// and VirtioFsFile->SingleFileInfoSize was computed from +// FilesysAttr.Namelen, which had been accepted by +// VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE().) +// + CallerAllocated = *BufferSize; + *BufferSize = (UINTN )FileInfo->Size; +if (CallerAllocated < *BufferSize) { +return EFI_BUFFER_TOO_SMALL ; + } +// +// Output FileInfo, and remove it from the cache. +// +CopyMem (Buffer, FileInfo, *BufferSize); + VirtioFsFile->NextFileInfo++; +return EFI_SUCCESS ; +} +/** Read from a regular file. **/ STATIC EFI_STATUS ReadRegularFile ( IN OUT VIRTIO_FS_FILE *VirtioFsFile, IN OUT UINTN *BufferSize,
@@ -80,14 +421,14 @@ VirtioFsSimpleFileRead ( ) {VIRTIO_FS_FILE *VirtioFsFile;EFI_STATUS Status; VirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);if (VirtioFsFile->IsDirectory) { - Status =EFI_NO_MEDIA ; + Status =ReadFileInfoCache (VirtioFsFile, BufferSize, Buffer); }else { Status =ReadRegularFile (VirtioFsFile, BufferSize, Buffer); }return Status; }
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 37/48 OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Flush()
In reply to Laszlo ErsekFor directories, implement EFI_FILE_PROTOCOL.Flush() by sending the FUSE_FSYNCDIR command to the Virtio Filesystem device.
For regular files, send FUSE_FLUSH, followed by FUSE_FSYNC.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/SimpleFsFlush.c | 26 +++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
OvmfPkg/VirtioFsDxe/SimpleFsFlush.c +25 -1
@@ -9,10 +9,34 @@#include "VirtioFsDxe.h" EFI_STATUS EFIAPIVirtioFsSimpleFileFlush ( IN EFI_FILE_PROTOCOL *This ) { -return EFI_NO_MEDIA ; +VIRTIO_FS_FILE *VirtioFsFile; +VIRTIO_FS *VirtioFs; +EFI_STATUS Status; + + VirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs = VirtioFsFile->OwnerFs; + +if (!VirtioFsFile->IsOpenForWriting) { +return EFI_ACCESS_DENIED ; + } + +// +// FUSE_FLUSH is for regular files only. +// +if (!VirtioFsFile->IsDirectory) { + Status =VirtioFsFuseFlush (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle); +if (EFI_ERROR (Status)) { +return Status; + } + } + + Status =VirtioFsFuseFsyncFileOrDir (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory); +return Status; }
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 38/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_WRITE
In reply to Laszlo ErsekAdd the VirtioFsFuseWrite() function, for sending the FUSE_WRITE command to the Virtio Filesystem device.
(For avoiding oversized FUSE_WRITE commands, save the maximum write buffer size that is advertized by the FUSE server, in the session init code.)
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 19 +++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 11 ++ OvmfPkg/VirtioFsDxe/FuseInit.c | 12 +- OvmfPkg/VirtioFsDxe/FuseWrite.c | 155 ++++++++++++++++++++ 5 files changed, 196 insertions(+), 2 deletions(-)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +19 -0
@@ -148,16 +148,17 @@ typedef enum { VirtioFsFuseOpLookup =1 , VirtioFsFuseOpForget =2 , VirtioFsFuseOpGetAttr =3 , VirtioFsFuseOpMkDir =9 , VirtioFsFuseOpUnlink =10 , VirtioFsFuseOpRmDir =11 , VirtioFsFuseOpOpen =14 , VirtioFsFuseOpRead =15 , + VirtioFsFuseOpWrite =16 , VirtioFsFuseOpStatFs =17 , VirtioFsFuseOpRelease =18 , VirtioFsFuseOpFsync =20 , VirtioFsFuseOpFlush =25 , VirtioFsFuseOpInit =26 , VirtioFsFuseOpOpenDir =27 , VirtioFsFuseOpReleaseDir =29 , VirtioFsFuseOpFsyncDir = 30,
@@ -277,16 +278,34 @@ typedef struct {UINT64 Offset;UINT32 Size;UINT32 ReadFlags;UINT64 LockOwner;UINT32 Flags;UINT32 Padding; }VIRTIO_FS_FUSE_READ_REQUEST ; +// +// Headers for VirtioFsFuseOpWrite. +// +typedef struct { +UINT64 FileHandle; +UINT64 Offset; +UINT32 Size; +UINT32 WriteFlags; +UINT64 LockOwner; +UINT32 Flags; +UINT32 Padding; +}VIRTIO_FS_FUSE_WRITE_REQUEST ; + +typedef struct { +UINT32 Size; +UINT32 Padding; +}VIRTIO_FS_FUSE_WRITE_RESPONSE ; +// // Header for VirtioFsFuseOpStatFs. // typedef struct { UINT64 Blocks; UINT64 Bfree; UINT64 Bavail; UINT64 Files;
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -92,16 +92,17 @@ [Sources] FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRead.c FuseRelease.c FuseStatFs.c FuseUnlink.c + FuseWrite.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c SimpleFsOpen.c SimpleFsOpenVolume.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +11 -0
@@ -73,16 +73,17 @@ typedef struct {// ----------- ------------------ ---------- UINT64 Signature;// DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio;// DriverBindingStart 0 VIRTIO_FS_LABEL Label;// VirtioFsInit 1 UINT16 QueueSize;// VirtioFsInit 1 VRING Ring;// VirtioRingInit 2 VOID *RingMap;// VirtioRingMap 2 UINT64 RequestId;// FuseInitSession 1 +UINT32 MaxWrite;// FuseInitSession 1 EFI_EVENT ExitBoot;// DriverBindingStart 0 LIST_ENTRY OpenFiles;// DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs;// DriverBindingStart 0 }VIRTIO_FS ;#define VIRTIO_FS_FROM_SIMPLE_FS (SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG);
@@ -329,16 +330,26 @@ VirtioFsFuseReadFileOrDir ( IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir, IN UINT64 Offset, IN OUT UINT32 *Size, OUT VOID *Data ); +EFI_STATUS +VirtioFsFuseWrite ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN UINT64 Offset, + IN OUT UINT32 *Size, + IN VOID *Data + ); +EFI_STATUS VirtioFsFuseStatFs ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr );EFI_STATUS
OvmfPkg/VirtioFsDxe/FuseInit.c +10 -2
@@ -17,17 +17,20 @@ session is started by sending a FUSE_INIT request as defined by the FUSE protocol on one request virtqueue." The function may only be called after VirtioFsInit() returns successfully and before VirtioFsUninit() is called. @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_INIT request to. The FUSE request counter - "VirtioFs->RequestId" is set to 1 on output. + "VirtioFs->RequestId" is set to 1 on output. The + maximum write buffer size exposed in the FUSE_INIT + response is saved in "VirtioFs->MaxWrite", on + output. @retval EFI_SUCCESS The FUSE session has been started. @retval EFI_UNSUPPORTED FUSE interface version or feature negotiation failed. @return The "errno" value mapped to an EFI_STATUS code, if the Virtio Filesystem device explicitly reported an
@@ -121,14 +124,19 @@ VirtioFsFuseInitSession (return Status; }// // Check FUSE interface version / feature compatibility. // if (InitResp.Major < InitReq.Major || (InitResp.Major == InitReq.Major && InitResp.Minor < InitReq.Minor) || - (InitResp.Flags &VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS ) ==0 ) { + (InitResp.Flags &VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS ) ==0 || + InitResp.MaxWrite <SIZE_4KB ) {return EFI_UNSUPPORTED ; } +// +// Save the maximum write buffer size for FUSE_WRITE requests. +// + VirtioFs->MaxWrite = InitResp.MaxWrite;return EFI_SUCCESS ; }
OvmfPkg/VirtioFsDxe/FuseWrite.c new file +155 -0
155 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 39/48 OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Write()
In reply to Laszlo ErsekUsing the functions introduced previously, we can now implement VirtioFsSimpleFileWrite().
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/SimpleFsWrite.c | 63 +++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-)
OvmfPkg/VirtioFsDxe/SimpleFsWrite.c +62 -1
@@ -11,10 +11,71 @@EFI_STATUS EFIAPIVirtioFsSimpleFileWrite ( IN EFI_FILE_PROTOCOL *This, IN OUT UINTN *BufferSize, IN VOID *Buffer ) { -return EFI_NO_MEDIA ; +VIRTIO_FS_FILE *VirtioFsFile; +VIRTIO_FS *VirtioFs; +EFI_STATUS Status; +UINTN Transferred; +UINTN Left; + + VirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs = VirtioFsFile->OwnerFs; + +if (VirtioFsFile->IsDirectory) { +return EFI_UNSUPPORTED ; + } +if (!VirtioFsFile->IsOpenForWriting) { +return EFI_ACCESS_DENIED ; + } + + Status =EFI_SUCCESS ; + Transferred =0 ; + Left = *BufferSize; +while (Left >0 ) { +UINT32 WriteSize; + +// +// Honor the write buffer size limit. +// + WriteSize = (UINT32 )MIN ((UINTN )VirtioFs->MaxWrite, Left); + Status =VirtioFsFuseWrite ( + VirtioFs, + VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, + VirtioFsFile->FilePosition + Transferred, + &WriteSize, + (UINT8 *)Buffer + Transferred + ); +if (!EFI_ERROR (Status) && WriteSize ==0 ) { +// +// Progress should have been made. +// + Status =EFI_DEVICE_ERROR ; + } +if (EFI_ERROR (Status)) { +break ; + } + Transferred += WriteSize; + Left -= WriteSize; + } + + *BufferSize = Transferred; + VirtioFsFile->FilePosition += Transferred; +// +// According to the UEFI spec, +// +// - 'Partial writes only occur when there has been a data error during the +// write attempt (such as "file space full")', and +// +// - (as an example) EFI_VOLUME_FULL is returned when 'The volume is full'. +// +// These together imply that after a partial write, we have to return an +// error. In other words, (Transferred > 0) is inconsequential for the return +// value. +// +return Status; }
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 40/48 OvmfPkg/VirtioFsDxe: handle the volume label in EFI_FILE_PROTOCOL.SetInfo
In reply to Laszlo ErsekThe least complicated third of EFI_FILE_PROTOCOL.SetInfo() is to handle the EFI_FILE_SYSTEM_INFO and EFI_FILE_SYSTEM_VOLUME_LABEL setting requests. Both of those can only change the volume label -- which the Virtio Filesystem device does not support.
Verify the input for well-formedness, and report success only if the volume label is being set to its current value.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c | 226 +++++++++++++++++++- 1 file changed, 225 insertions(+), 1 deletion(-)
OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c +225 -1
@@ -1,21 +1,245 @@/** @file EFI_FILE_PROTOCOL.SetInfo() member function for the Virtio Filesystem driver. Copyright (C) 2020, Red Hat, Inc. SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include <Guid/FileSystemInfo.h> // gEfiFileSystemInfoGuid +#include <Guid/FileSystemVolumeLabelInfo.h> // gEfiFileSystemVolumeLabelInfo... +#include <Library/BaseLib.h> // StrCmp() +#include <Library/BaseMemoryLib.h> // CompareGuid() +#include "VirtioFsDxe.h" +/** +Validate a buffer that the EFI_FILE_PROTOCOL.SetInfo() caller passes in for a +particular InformationType GUID. + +The structure to be validated is supposed to end with a variable-length, +NUL-terminated CHAR16 Name string. + +@param[in] SizeByProtocolCaller The BufferSize parameter as provided by the +EFI_FILE_PROTOCOL.SetInfo() caller. + +@param[in] MinimumStructSize The minimum structure size that is required +for the given InformationType GUID, +including a single CHAR16 element from the +trailing Name field. + +@param[in] IsSizeByInfoPresent TRUE if and only if the expected structure +starts with a UINT64 Size field that reports +the actual structure size. + +@param[in] Buffer The Buffer parameter as provided by the +EFI_FILE_PROTOCOL.SetInfo() caller. + +@retval EFI_SUCCESS Validation successful, Buffer is well-formed. + +@retval EFI_BAD_BUFFER_SIZE The EFI_FILE_PROTOCOL.SetInfo() +caller provided a BufferSize that is smaller +than the minimum structure size required for +the given InformationType GUID. + +@retval EFI_INVALID_PARAMETER IsSizeByInfoPresent is TRUE, and the leading +UINT64 Size field does not match the +EFI_FILE_PROTOCOL.SetInfo() caller-provided +BufferSize. + +@retval EFI_INVALID_PARAMETER The trailing Name field does not consist of a +whole multiple of CHAR16 elements. + +@retval EFI_INVALID_PARAMETER The trailing Name field is not NUL-terminated. +**/ +STATIC +EFI_STATUS +ValidateInfoStructure ( + IN UINTN SizeByProtocolCaller, + IN UINTN MinimumStructSize, + IN BOOLEAN IsSizeByInfoPresent, + IN VOID *Buffer + ) +{ +UINTN NameFieldByteOffset; +UINTN NameFieldBytes; +UINTN NameFieldChar16s; +CHAR16 *NameField; + +// +// Make sure the internal function asking for validation passes in sane +// values. +// +ASSERT (MinimumStructSize >=sizeof (CHAR16 )); + NameFieldByteOffset = MinimumStructSize -sizeof (CHAR16 ); + +if (IsSizeByInfoPresent) { +ASSERT (MinimumStructSize >=sizeof (UINT64 ) +sizeof (CHAR16 )); +ASSERT (NameFieldByteOffset >=sizeof (UINT64 )); + } + +// +// Check whether the protocol caller provided enough bytes for the minimum +// size of this info structure. +// +if (SizeByProtocolCaller < MinimumStructSize) { +return EFI_BAD_BUFFER_SIZE ; + } + +// +// If the info structure starts with a UINT64 Size field, check if that +// agrees with the protocol caller-provided size. +// +if (IsSizeByInfoPresent) { +UINT64 *SizeByInfo; + + SizeByInfo = Buffer; +if (*SizeByInfo != SizeByProtocolCaller) { +return EFI_INVALID_PARAMETER ; + } + } + +// +// The CHAR16 Name field at the end of the structure must have an even number +// of bytes. +// +// The subtraction below cannot underflow, and yields at least +// sizeof(CHAR16). +// +ASSERT (SizeByProtocolCaller >= NameFieldByteOffset); + NameFieldBytes = SizeByProtocolCaller - NameFieldByteOffset; +ASSERT (NameFieldBytes >=sizeof (CHAR16 )); +if (NameFieldBytes %sizeof (CHAR16 ) !=0 ) { +return EFI_INVALID_PARAMETER ; + } + +// +// The CHAR16 Name field at the end of the structure must be NUL-terminated. +// + NameFieldChar16s = NameFieldBytes /sizeof (CHAR16 ); +ASSERT (NameFieldChar16s >=1 ); + + NameField = (CHAR16 *)((UINT8 *)Buffer + NameFieldByteOffset); +if (NameField[NameFieldChar16s -1 ] !=L'\0' ) { +return EFI_INVALID_PARAMETER ; + } + +return EFI_SUCCESS ; +} + +/** +Process an EFI_FILE_SYSTEM_INFO setting request. +**/ +STATIC +EFI_STATUS +SetFileSystemInfo ( + IN EFI_FILE_PROTOCOL *This, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ +VIRTIO_FS_FILE *VirtioFsFile; +VIRTIO_FS *VirtioFs; +EFI_STATUS Status; +EFI_FILE_SYSTEM_INFO *FileSystemInfo; + + VirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs = VirtioFsFile->OwnerFs; + +// +// Validate if Buffer passes as EFI_FILE_SYSTEM_INFO. +// + Status =ValidateInfoStructure ( + BufferSize,// SizeByProtocolCaller +OFFSET_OF (EFI_FILE_SYSTEM_INFO , + VolumeLabel) +sizeof (CHAR16 ),// MinimumStructSize + TRUE,// IsSizeByInfoPresent + Buffer + ); +if (EFI_ERROR (Status)) { +return Status; + } + FileSystemInfo = Buffer; + +// +// EFI_FILE_SYSTEM_INFO fields other than VolumeLabel cannot be changed, per +// spec. +// +// If the label is being changed to its current value, report success; +// otherwise, reject the request, as the Virtio Filesystem device does not +// support changing the label. +// +if (StrCmp (FileSystemInfo->VolumeLabel, VirtioFs->Label) ==0 ) { +return EFI_SUCCESS ; + } +return EFI_WRITE_PROTECTED ; +} + +/** +Process an EFI_FILE_SYSTEM_VOLUME_LABEL setting request. +**/ +STATIC +EFI_STATUS +SetFileSystemVolumeLabelInfo ( + IN EFI_FILE_PROTOCOL *This, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ +VIRTIO_FS_FILE *VirtioFsFile; +VIRTIO_FS *VirtioFs; +EFI_STATUS Status; +EFI_FILE_SYSTEM_VOLUME_LABEL *FileSystemVolumeLabel; + + VirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs = VirtioFsFile->OwnerFs; + +// +// Validate if Buffer passes as EFI_FILE_SYSTEM_VOLUME_LABEL. +// + Status =ValidateInfoStructure ( + BufferSize,// SizeByProtocolCaller +OFFSET_OF (EFI_FILE_SYSTEM_VOLUME_LABEL , + VolumeLabel) +sizeof (CHAR16 ),// MinimumStructSize + FALSE,// IsSizeByInfoPresent + Buffer + ); +if (EFI_ERROR (Status)) { +return Status; + } + FileSystemVolumeLabel = Buffer; + +// +// If the label is being changed to its current value, report success; +// otherwise, reject the request, as the Virtio Filesystem device does not +// support changing the label. +// +if (StrCmp (FileSystemVolumeLabel->VolumeLabel, VirtioFs->Label) ==0 ) { +return EFI_SUCCESS ; + } +return EFI_WRITE_PROTECTED ; +} +EFI_STATUS EFIAPIVirtioFsSimpleFileSetInfo ( IN EFI_FILE_PROTOCOL *This, IN EFI_GUID *InformationType, IN UINTN BufferSize, IN VOID *Buffer ) { -return EFI_NO_MEDIA ; +if (CompareGuid (InformationType, &gEfiFileInfoGuid)) { +return EFI_UNSUPPORTED ; + } + +if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { +return SetFileSystemInfo (This, BufferSize, Buffer); + } + +if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) { +return SetFileSystemVolumeLabelInfo (This, BufferSize, Buffer); + } + +return EFI_UNSUPPORTED ; }
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 41/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_RENAME2
In reply to Laszlo ErsekAdd the VirtioFsFuseRename() function, for sending the FUSE_RENAME2 command to the Virtio Filesystem device.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 15 +++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 9 ++ OvmfPkg/VirtioFsDxe/FuseRename.c | 131 ++++++++++++++++++++ 4 files changed, 156 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +15 -0
@@ -136,16 +136,21 @@ typedef struct { ((Namelen) ==0 || (Namelen) >SIZE_4KB ? \ (UINTN )0 : \ALIGN_VALUE ( \sizeof (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE ) + (UINTN )(Namelen), \sizeof (UINT64 ) \ ) \ ) +// +// Flags for VirtioFsFuseOpRename2. +// +#define VIRTIO_FS_FUSE_RENAME2_REQ_F_NOREPLACE BIT0 +// // FUSE operation codes. // typedef enum { VirtioFsFuseOpLookup = 1, VirtioFsFuseOpForget = 2, VirtioFsFuseOpGetAttr = 3, VirtioFsFuseOpMkDir = 9,
@@ -159,16 +164,17 @@ typedef enum { VirtioFsFuseOpFsync =20 , VirtioFsFuseOpFlush =25 , VirtioFsFuseOpInit =26 , VirtioFsFuseOpOpenDir =27 , VirtioFsFuseOpReleaseDir =29 , VirtioFsFuseOpFsyncDir =30 , VirtioFsFuseOpCreate =35 , VirtioFsFuseOpReadDirPlus =44 , + VirtioFsFuseOpRename2 =45 , } VIRTIO_FS_FUSE_OPCODE;#pragma pack (1)// // Request-response headers common to all request types. // typedef struct { UINT32 Len;
@@ -393,11 +399,20 @@ typedef struct {typedef struct {VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp;VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp;UINT64 NodeId;UINT64 CookieForNextEntry;UINT32 Namelen;UINT32 Type; }VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE ; + +// +// Header for VirtioFsFuseOpRename2. +// +typedef struct { +UINT64 NewDir; +UINT32 Flags; +UINT32 Padding; +}VIRTIO_FS_FUSE_RENAME2_REQUEST ;#pragma pack ()#endif // VIRTIO_FS_H_
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -90,16 +90,17 @@ [Sources] FuseInit.c FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRead.c FuseRelease.c + FuseRename.c FuseStatFs.c FuseUnlink.c FuseWrite.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +9 -0
@@ -391,16 +391,25 @@ EFI_STATUSVirtioFsFuseOpenOrCreate ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 ParentNodeId, IN CHAR8 *Name, OUT UINT64 *NodeId, OUT UINT64 *FuseHandle ); +EFI_STATUS +VirtioFsFuseRename ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 OldParentNodeId, + IN CHAR8 *OldName, + IN UINT64 NewParentNodeId, + IN CHAR8 *NewName + ); +// // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem // driver. // EFI_STATUS EFIAPI VirtioFsOpenVolume (
OvmfPkg/VirtioFsDxe/FuseRename.c new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 42/48 OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination path
In reply to Laszlo ErsekThe EFI_FILE_PROTOCOL.SetInfo() member is somewhat under-specified; one of its modes of operation is renaming/moving the file.
In order to create the destination pathname in canonical format, 2*2=4 cases have to be considered. For the sake of discussion, assume the current canonical pathname of a VIRTIO_FS_FILE is "/home/user/f1.txt". Then, consider the following rename/move requests from EFI_FILE_PROTOCOL.SetInfo():
Destination requested Destination Move into Destination in by SetInfo() relative? directory? canonical format --------------------- ----------- ---------- ----------------------- L"\\dir\\f2.txt" no no "/dir/f2.txt" L"\\dir\\" no yes "/dir/f1.txt" L"dir\\f2.txt" yes no "/home/user/dir/f2.txt" L"dir\\" yes yes "/home/user/dir/f1.txt"
Add the VirtioFsComposeRenameDestination() function, for composing the last column from the current canonical pathname and the SetInfo() input.
The function works on the following principles:
- The prefix of the destination path is "/", if the SetInfo() rename request is absolute.
Otherwise, the dest prefix is the "current directory" (the most specific parent directory) of the original pathname (in the above example, "/home/user").
- The suffix of the destination path is precisely the SetInfo() request string, if the "move into directory" convenience format -- the trailing backslash -- is not used. (In the above example, L"\\dir\\f2.txt" and L"dir\\f2.txt".)
Otherwise, the suffix is the SetInfo() request, plus the original basename (in the above example, L"\\dir\\f1.txt" and L"dir\\f1.txt").
- The complete destination is created by fusing the dest prefix and the dest suffix, using the VirtioFsAppendPath() function.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 + OvmfPkg/VirtioFsDxe/Helpers.c | 194 ++++++++++++++++++++ 2 files changed, 202 insertions(+)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +8 -0
@@ -257,16 +257,24 @@ VirtioFsLookupMostSpecificParentDir (EFI_STATUS VirtioFsGetBasename ( IN CHAR8 *Path, OUT CHAR16 *Basename OPTIONAL, IN OUT UINTN *BasenameSize ); +EFI_STATUS +VirtioFsComposeRenameDestination ( + IN CHAR8 *LhsPath8, + IN CHAR16 *RhsPath16, + OUT CHAR8 **ResultPath8, + OUT BOOLEAN *RootEscape + ); +EFI_STATUS VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo );EFI_STATUS VirtioFsFuseDirentPlusToEfiFileInfo (
OvmfPkg/VirtioFsDxe/Helpers.c +194 -0
210 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
Re: [Virtio-fs] [edk2 PATCH 42/48] OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination path
Quoted 9 lines · Laszlo Ersek
The
EFI_FILE_PROTOCOL.SetInfo()member is somewhat under-specified; one of its modes of operation is renaming/moving the file.In order to create the destination pathname in canonical format, 2*2=4 cases have to be considered. For the sake of discussion, assume the current canonical pathname of a
VIRTIO_FS_FILEis "/home/user/f1.txt". Then, consider the following rename/move requests fromEFI_FILE_PROTOCOL.SetInfo():
Quoted 4 lines
Destination requested Destination Move into Destination in by SetInfo() relative? directory? canonical format --------------------- ----------- ---------- ----------------------- L"\\dir\\f2.txt" no no "/dir/f2.txt"
What happens in the above case if /dir/f2.txt is an existing directory?
Quoted 282 lines
L"\\dir\\" no yes "/dir/f1.txt" L"dir\\f2.txt" yes no "/home/user/dir/f2.txt" L"dir\\" yes yes "/home/user/dir/f1.txt"Add the
VirtioFsComposeRenameDestination()function, for composing the last column from the current canonical pathname and theSetInfo()input.The function works on the following principles:
- The prefix of the destination path is "/", if the
SetInfo()rename request is absolute.Otherwise, the dest prefix is the "current directory" (the most specific parent directory) of the original pathname (in the above example, "
/home/user").- The suffix of the destination path is precisely the
SetInfo()request string, if the "move into directory" convenience format -- the trailing backslash -- is not used. (In the above example, L"\\dir\\f2.txt" and L"dir\\f2.txt".)Otherwise, the suffix is the
SetInfo()request, plus the original basename (in the above example, L"\\dir\\f1.txt" and L"dir\\f1.txt").- The complete destination is created by fusing the dest prefix and the dest suffix, using the
VirtioFsAppendPath()function.Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097Signed-off-by Laszlo Ersek <[email protected]>--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 + OvmfPkg/VirtioFsDxe/Helpers.c | 194 ++++++++++++++++++++ 2 files changed, 202 insertions(+)OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +8
-0@@ -257,16 +257,24 @@ VirtioFsLookupMostSpecificParentDir (EFI_STATUS VirtioFsGetBasename ( IN CHAR8 *Path, OUT CHAR16 *Basename OPTIONAL, IN OUT UINTN *BasenameSize ); +EFI_STATUS +VirtioFsComposeRenameDestination ( + IN CHAR8 *LhsPath8, + IN CHAR16 *RhsPath16, + OUT CHAR8 **ResultPath8, + OUT BOOLEAN *RootEscape + ); +EFI_STATUS VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo );EFI_STATUS VirtioFsFuseDirentPlusToEfiFileInfo (OvmfPkg/VirtioFsDxe/Helpers.c +194
-0@@ -1778,16 +1778,210 @@ VirtioFsGetBasename ( }for (Idx = LastComponent; Idx < PathSize; Idx++) { Basename[Idx - LastComponent] = Path[Idx]; }return EFI_SUCCESS ; } +/** +Format the destination of a rename/move operation as a dynamically allocated +canonical pathname. + +Any dot-dot in RhsPath16 that would remove the root directory is dropped, and +reported through RootEscape, without failing the function call. + +@param[in] LhsPath8 The source pathname operand of the rename/move +operation, expressed as a canonical pathname (as +defined in the description of VirtioFsAppendPath()). +The root directory "/" cannot be renamed/moved, and +will be rejected. + +@param[in] RhsPath16 The destination pathname operand expressed as a +UEFI-style CHAR16 pathname. + +If RhsPath16 starts with a backslash, then RhsPath16 +is considered absolute. Otherwise, RhsPath16 is +interpreted relative to the most specific parent +directory found in LhsPath8. + +Independently, if RhsPath16 ends with a backslash +(i.e., RhsPath16 is given in the "move into +directory" convenience form), then RhsPath16 is +interpreted with the basename of LhsPath8 appended. +Otherwise, the last pathname component of RhsPath16 +is taken as the last pathname component of the +rename/move destination. + +An empty RhsPath16 is rejected. + +@param[out] ResultPath8 The POSIX-style, canonical format pathname that +leads to the renamed/moved file. After use, the +caller is responsible for freeing ResultPath8. + +@param[out] RootEscape Set to TRUE if at least one dot-dot component in +RhsPath16 attempted to escape the root directory; +set to FALSE otherwise. + +@retval EFI_SUCCESS ResultPath8 has been produced. RootEscape has +been output. + +@retval EFI_INVALID_PARAMETER LhsPath8 is "/". + +@retval EFI_INVALID_PARAMETER RhsPath16 is zero-length. + +@retval EFI_INVALID_PARAMETER RhsPath16 failed the +VIRTIO_FS_MAX_PATHNAME_LENGTH check. + +@retval EFI_OUT_OF_RESOURCES Memory allocation failed. + +@retval EFI_OUT_OF_RESOURCES ResultPath8 would have failed the +VIRTIO_FS_MAX_PATHNAME_LENGTH check. + +@retval EFI_UNSUPPORTED RhsPath16 contains a character that either +falls outside of the printable ASCII set, or +is a forward slash. +**/ +EFI_STATUS +VirtioFsComposeRenameDestination ( + IN CHAR8 *LhsPath8, + IN CHAR16 *RhsPath16, + OUT CHAR8 **ResultPath8, + OUT BOOLEAN *RootEscape + ) +{ +// +// Lengths are expressed as numbers of characters (CHAR8 or CHAR16), +// excluding terminating NULs. Sizes are expressed as byte counts, including +// the bytes taken up by terminating NULs. +// +UINTN RhsLen; +UINTN LhsBasename16Size; +EFI_STATUS Status; +UINTN LhsBasenameLen; +UINTN DestSuffix16Size; +CHAR16 *DestSuffix16; +CHAR8 *DestPrefix8; + +// +// An empty destination operand for the rename/move operation is not allowed. +// + RhsLen =StrLen (RhsPath16); +if (RhsLen ==0 ) { +return EFI_INVALID_PARAMETER ; + } +// +// Enforce length restriction on RhsPath16. +// +if (RhsLen >VIRTIO_FS_MAX_PATHNAME_LENGTH ) { +return EFI_INVALID_PARAMETER ; + } + +// +// Determine the length of the basename of LhsPath8. +// + LhsBasename16Size =0 ; + Status =VirtioFsGetBasename (LhsPath8,NULL , &LhsBasename16Size); +ASSERT (Status ==EFI_BUFFER_TOO_SMALL ); +ASSERT (LhsBasename16Size >=sizeof (CHAR16 )); +ASSERT (LhsBasename16Size %sizeof (CHAR16 ) ==0 ); + LhsBasenameLen = LhsBasename16Size /sizeof (CHAR16 ) -1 ; +if (LhsBasenameLen ==0 ) { +// +// The root directory cannot be renamed/moved. +// +return EFI_INVALID_PARAMETER ; + } + +// +// Resolve the "move into directory" convenience form in RhsPath16. +// +if (RhsPath16[RhsLen -1 ] ==L'\\' ) { +// +// Append the basename of LhsPath8 as a CHAR16 string to RhsPath16. +// + DestSuffix16Size = RhsLen *sizeof (CHAR16 ) + LhsBasename16Size; + DestSuffix16 =AllocatePool (DestSuffix16Size); +if (DestSuffix16 ==NULL ) { +return EFI_OUT_OF_RESOURCES ; + } +CopyMem (DestSuffix16, RhsPath16, RhsLen *sizeof (CHAR16 )); + Status =VirtioFsGetBasename (LhsPath8, DestSuffix16 + RhsLen, + &LhsBasename16Size); +ASSERT_EFI_ERROR (Status); + }else { +// +// Just create a copy of RhsPath16. +// + DestSuffix16Size = (RhsLen +1 ) *sizeof (CHAR16 ); + DestSuffix16 =AllocateCopyPool (DestSuffix16Size, RhsPath16); +if (DestSuffix16 ==NULL ) { +return EFI_OUT_OF_RESOURCES ; + } + } + +// +// If the destination operand is absolute, it will be interpreted relative to +// the root directory. +// +// Otherwise (i.e., if the destination operand is relative), then create the +// canonical pathname that the destination operand is interpreted relatively +// to; that is, the canonical pathname of the most specific parent directory +// found in LhsPath8. +// +if (DestSuffix16[0 ] ==L'\\' ) { + DestPrefix8 =AllocateCopyPool (sizeof "/" ,"/" ); +if (DestPrefix8 ==NULL ) { + Status =EFI_OUT_OF_RESOURCES ; + goto FreeDestSuffix16; + } + }else { +UINTN LhsLen; +UINTN DestPrefixLen; + +// +// Strip the basename of LhsPath8. +// + LhsLen =AsciiStrLen (LhsPath8); +ASSERT (LhsBasenameLen < LhsLen); + DestPrefixLen = LhsLen - LhsBasenameLen; +ASSERT (LhsPath8[DestPrefixLen -1 ] =='/' ); +// +// If we're not at the root directory, strip the slash too. +// +if (DestPrefixLen >1 ) { + DestPrefixLen--; + } + DestPrefix8 =AllocatePool (DestPrefixLen +1 ); +if (DestPrefix8 ==NULL ) { + Status =EFI_OUT_OF_RESOURCES ; + goto FreeDestSuffix16; + } +CopyMem (DestPrefix8, LhsPath8, DestPrefixLen); + DestPrefix8[DestPrefixLen] ='\0' ; + } + +// +// Now combine DestPrefix8 and DestSuffix16 into the final canonical +// pathname. +// + Status =VirtioFsAppendPath (DestPrefix8, DestSuffix16, ResultPath8, + RootEscape); + +FreePool (DestPrefix8); +// +// Fall through. +// +FreeDestSuffix16: +FreePool (DestSuffix16); + +return Status; +} +/** Convert select fields of a VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to corresponding fields in EFI_FILE_INFO. @param[in] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to convert the relevant fields from. @param[out] FileInfo The EFI_FILE_INFO structure to modify. Importantly, the
Re: [Virtio-fs] [edk2 PATCH 42/48] OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination path
Quoted 10 lines · Ard Biesheuvel
Quoted 9 lines · Laszlo Ersek
The
EFI_FILE_PROTOCOL.SetInfo()member is somewhat under-specified; one of its modes of operation is renaming/moving the file.In order to create the destination pathname in canonical format, 2*2=4 cases have to be considered. For the sake of discussion, assume the current canonical pathname of a
VIRTIO_FS_FILEis "/home/user/f1.txt". Then, consider the following rename/move requests fromEFI_FILE_PROTOCOL.SetInfo():
Quoted 6 lines
Quoted 4 lines
Destination requested Destination Move into Destination in by SetInfo() relative? directory? canonical format --------------------- ----------- ---------- ----------------------- L"\\dir\\f2.txt" no no "/dir/f2.txt"What happens in the above case if /dir/f2.txt is an existing directory?
Short answer:
The present patch only constructs the destination pathname. The rename attempt you describe is caught
- either by the subsequent patch, if the existing dest directory is open by the guest driver,
- or else, by the host kernel, due to the RENAME_NOREPLACE flag set in the patch before this one.
Long (very long) answer, in opposite order of the above cases:
- If "/dir/f2.txt" were an existing name (regardless of the type of the host-side inode that it referred to), then the FUSE_RENAME2 request would fail: the host kernel would reject the renameat2() system call made by virtiofsd. This would be due to the RENAME_NOREPLACE flag:
https://man7.org/linux/man-pages/man2/rename.2.html include/uapi/linux/fs.h
which is set in
[edk2 PATCH 41/48]
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_RENAME2
using the macro name VIRTIO_FS_FUSE_RENAME2_REQ_F_NOREPLACE.
Thus, if the request reached the host kernel, an -EEXIST errno would come back to the guest driver.
(
- If the movement source were a non-directory and the destination were a directory, then that would fail (also in the host kernel at the latest) even with the simpler (flag-less) FUSE_RENAME request, which virtiofsd translates to the renameat() syscall, with -EISDIR.
- If both source and destination were directories, and the destination were not empty, then even the flag-less renameat() would fail with -ENOTEMPTY.
- If both source and destination were directories, and the destination were empty, then renameat() would replace the destination [*]; but renameat2() with RENAME_NOREPLACE will not.
[*] mkdir source-dir target-dir
ls -lid source-dir target-dir
touch source-dir/file.txt
mv -T source-dir target-dir
ls -lid target-dir
ls -l target-dir/file.txt
)
Then, in addition to RENAME_NOREPLACE, there's a guest-side check in
[edk2 PATCH 43/48]
OvmfPkg/VirtioFsDxe: handle file rename/move in EFI_FILE_PROTOCOL.SetInfo
that was inspired by "FatPkg/EnhancedFatDxe". Namely:
Quoted 18 lines
(quoted diff) +18
-0+ // + // Check if the rename would break the canonical pathnames of other + // VIRTIO_FS_FILE instances of the same VIRTIO_FS. + // + if (VirtioFsFile->IsDirectory) { + UINTN PathLen; + LIST_ENTRY *OpenFilesEntry; + + PathLen = AsciiStrLen (VirtioFsFile->CanonicalPathname); + BASE_LIST_FOR_EACH (OpenFilesEntry, &VirtioFs->OpenFiles) { + VIRTIO_FS_FILE *OtherFile; + + OtherFile = VIRTIO_FS_FILE_FROM_OPEN_FILES_ENTRY (OpenFilesEntry); + if (OtherFile != VirtioFsFile && + AsciiStrnCmp (VirtioFsFile->CanonicalPathname, + OtherFile->CanonicalPathname, PathLen) == 0 && + (OtherFile->CanonicalPathname[PathLen] == '\0' || + OtherFile->CanonicalPathname[PathLen] == '/')) {
Review
Quoted 10 lines
(quoted diff) +10
-0+ // + // OtherFile refers to the same directory as VirtioFsFile, or is a + // (possibly indirect) child of the directory referred to by + // VirtioFsFile. + // + Status = EFI_ACCESS_DENIED; + goto FreeDestination; + } + } + }
This is why "VIRTIO_FS.OpenFiles" is a list, and not just a reference count -- for this simple guest-side check, I needed to go through the other open VIRTIO_FS_FILEs for the same VIRTIO_FS one by one. Just knowing how many of them existed wouldn't be enough.
This guest-side check is by no means foolproof; after all, you can do whatever you want on the host side, underneath the guest driver's feet.
But, catching such "async tricks" is not a goal for this driver. EFI_FILE_PROTOCOL is not equipped to deal with such async changes by design. At best, it can return EFI_MEDIA_CHANGED, when (e.g.) removable media is replaced. But even if I could detect such a situation in the virtio-fs driver, it would be counter-productive: when a host-side file changes, that's something the guest wants to pick up one way or another, we don't want the driver to switch to returning EFI_MEDIA_CHANGED for all further requests indiscriminately.
Synchronization between host and guest is pretty simple for the interactive use case: whenever your shell prompt returns, on the host or in the guest (meaning the UEFI shell prompt in the latter), you can Alt-TAB to the other terminal, and manipulate files from there.
Synchronization between host-side and guest-side scripts should be possible with polling directory listings, and renaming / moving regular files (files should be prepared in "private" directories, and then moved into place when done, for the other side to notice).
So, the above guest-side check exists for the usual case when the relevant sub-hierarchy of the shared directory doesn't change asynchronously to VIRTIO_FS_FILE's being open; when the guest-side check fires in this optimistic situation, the FUSE_RENAME2 request isn't even sent. And for when the guest-side check isn't good enough, that's when the RENAME_NOREPLACE flag becomes relevant -- I wanted to avoid unwittingly deleting entries in the shared directory by guest-initiated renames.
Sorry about the long answer. I feel it's not really possible to address your question without talking about asynchrony between host and guest. I had thought about it before, and I figured, shoehorning a shared filesystem into a non-shared filesystem abstraction should be acceptable this way. The use case is to support Alt-TABbing between your guest and host terminals, and running such UEFI unit tests in the guest that take input from the host filesystem and produce output to the host filesystem. A highly async / parallel operation is a non-goal.
Thanks!
Laszlo
Quoted 284 lines
Quoted 283 lines
L"\\dir\\" no yes "/dir/f1.txt" L"dir\\f2.txt" yes no "/home/user/dir/f2.txt" L"dir\\" yes yes "/home/user/dir/f1.txt"Add the
VirtioFsComposeRenameDestination()function, for composing the last column from the current canonical pathname and theSetInfo()input.The function works on the following principles:
- The prefix of the destination path is "/", if the
SetInfo()rename request is absolute.Otherwise, the dest prefix is the "current directory" (the most specific parent directory) of the original pathname (in the above example, "
/home/user").- The suffix of the destination path is precisely the
SetInfo()request string, if the "move into directory" convenience format -- the trailing backslash -- is not used. (In the above example, L"\\dir\\f2.txt" and L"dir\\f2.txt".)Otherwise, the suffix is the
SetInfo()request, plus the original basename (in the above example, L"\\dir\\f1.txt" and L"dir\\f1.txt").- The complete destination is created by fusing the dest prefix and the dest suffix, using the
VirtioFsAppendPath()function.Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097Signed-off-by Laszlo Ersek <[email protected]>--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 + OvmfPkg/VirtioFsDxe/Helpers.c | 194 ++++++++++++++++++++ 2 files changed, 202 insertions(+)OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +8
-0@@ -257,16 +257,24 @@ VirtioFsLookupMostSpecificParentDir (EFI_STATUS VirtioFsGetBasename ( IN CHAR8 *Path, OUT CHAR16 *Basename OPTIONAL, IN OUT UINTN *BasenameSize ); +EFI_STATUS +VirtioFsComposeRenameDestination ( + IN CHAR8 *LhsPath8, + IN CHAR16 *RhsPath16, + OUT CHAR8 **ResultPath8, + OUT BOOLEAN *RootEscape + ); +EFI_STATUS VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo );EFI_STATUS VirtioFsFuseDirentPlusToEfiFileInfo (OvmfPkg/VirtioFsDxe/Helpers.c +194
-0@@ -1778,16 +1778,210 @@ VirtioFsGetBasename ( }for (Idx = LastComponent; Idx < PathSize; Idx++) { Basename[Idx - LastComponent] = Path[Idx]; }return EFI_SUCCESS ; } +/** +Format the destination of a rename/move operation as a dynamically allocated +canonical pathname. + +Any dot-dot in RhsPath16 that would remove the root directory is dropped, and +reported through RootEscape, without failing the function call. + +@param[in] LhsPath8 The source pathname operand of the rename/move +operation, expressed as a canonical pathname (as +defined in the description of VirtioFsAppendPath()). +The root directory "/" cannot be renamed/moved, and +will be rejected. + +@param[in] RhsPath16 The destination pathname operand expressed as a +UEFI-style CHAR16 pathname. + +If RhsPath16 starts with a backslash, then RhsPath16 +is considered absolute. Otherwise, RhsPath16 is +interpreted relative to the most specific parent +directory found in LhsPath8. + +Independently, if RhsPath16 ends with a backslash +(i.e., RhsPath16 is given in the "move into +directory" convenience form), then RhsPath16 is +interpreted with the basename of LhsPath8 appended. +Otherwise, the last pathname component of RhsPath16 +is taken as the last pathname component of the +rename/move destination. + +An empty RhsPath16 is rejected. + +@param[out] ResultPath8 The POSIX-style, canonical format pathname that +leads to the renamed/moved file. After use, the +caller is responsible for freeing ResultPath8. + +@param[out] RootEscape Set to TRUE if at least one dot-dot component in +RhsPath16 attempted to escape the root directory; +set to FALSE otherwise. + +@retval EFI_SUCCESS ResultPath8 has been produced. RootEscape has +been output. + +@retval EFI_INVALID_PARAMETER LhsPath8 is "/". + +@retval EFI_INVALID_PARAMETER RhsPath16 is zero-length. + +@retval EFI_INVALID_PARAMETER RhsPath16 failed the +VIRTIO_FS_MAX_PATHNAME_LENGTH check. + +@retval EFI_OUT_OF_RESOURCES Memory allocation failed. + +@retval EFI_OUT_OF_RESOURCES ResultPath8 would have failed the +VIRTIO_FS_MAX_PATHNAME_LENGTH check. + +@retval EFI_UNSUPPORTED RhsPath16 contains a character that either +falls outside of the printable ASCII set, or +is a forward slash. +**/ +EFI_STATUS +VirtioFsComposeRenameDestination ( + IN CHAR8 *LhsPath8, + IN CHAR16 *RhsPath16, + OUT CHAR8 **ResultPath8, + OUT BOOLEAN *RootEscape + ) +{ +// +// Lengths are expressed as numbers of characters (CHAR8 or CHAR16), +// excluding terminating NULs. Sizes are expressed as byte counts, including +// the bytes taken up by terminating NULs. +// +UINTN RhsLen; +UINTN LhsBasename16Size; +EFI_STATUS Status; +UINTN LhsBasenameLen; +UINTN DestSuffix16Size; +CHAR16 *DestSuffix16; +CHAR8 *DestPrefix8; + +// +// An empty destination operand for the rename/move operation is not allowed. +// + RhsLen =StrLen (RhsPath16); +if (RhsLen ==0 ) { +return EFI_INVALID_PARAMETER ; + } +// +// Enforce length restriction on RhsPath16. +// +if (RhsLen >VIRTIO_FS_MAX_PATHNAME_LENGTH ) { +return EFI_INVALID_PARAMETER ; + } + +// +// Determine the length of the basename of LhsPath8. +// + LhsBasename16Size =0 ; + Status =VirtioFsGetBasename (LhsPath8,NULL , &LhsBasename16Size); +ASSERT (Status ==EFI_BUFFER_TOO_SMALL ); +ASSERT (LhsBasename16Size >=sizeof (CHAR16 )); +ASSERT (LhsBasename16Size %sizeof (CHAR16 ) ==0 ); + LhsBasenameLen = LhsBasename16Size /sizeof (CHAR16 ) -1 ; +if (LhsBasenameLen ==0 ) { +// +// The root directory cannot be renamed/moved. +// +return EFI_INVALID_PARAMETER ; + } + +// +// Resolve the "move into directory" convenience form in RhsPath16. +// +if (RhsPath16[RhsLen -1 ] ==L'\\' ) { +// +// Append the basename of LhsPath8 as a CHAR16 string to RhsPath16. +// + DestSuffix16Size = RhsLen *sizeof (CHAR16 ) + LhsBasename16Size; + DestSuffix16 =AllocatePool (DestSuffix16Size); +if (DestSuffix16 ==NULL ) { +return EFI_OUT_OF_RESOURCES ; + } +CopyMem (DestSuffix16, RhsPath16, RhsLen *sizeof (CHAR16 )); + Status =VirtioFsGetBasename (LhsPath8, DestSuffix16 + RhsLen, + &LhsBasename16Size); +ASSERT_EFI_ERROR (Status); + }else { +// +// Just create a copy of RhsPath16. +// + DestSuffix16Size = (RhsLen +1 ) *sizeof (CHAR16 ); + DestSuffix16 =AllocateCopyPool (DestSuffix16Size, RhsPath16); +if (DestSuffix16 ==NULL ) { +return EFI_OUT_OF_RESOURCES ; + } + } + +// +// If the destination operand is absolute, it will be interpreted relative to +// the root directory. +// +// Otherwise (i.e., if the destination operand is relative), then create the +// canonical pathname that the destination operand is interpreted relatively +// to; that is, the canonical pathname of the most specific parent directory +// found in LhsPath8. +// +if (DestSuffix16[0 ] ==L'\\' ) { + DestPrefix8 =AllocateCopyPool (sizeof "/" ,"/" ); +if (DestPrefix8 ==NULL ) { + Status =EFI_OUT_OF_RESOURCES ; + goto FreeDestSuffix16; + } + }else { +UINTN LhsLen; +UINTN DestPrefixLen; + +// +// Strip the basename of LhsPath8. +// + LhsLen =AsciiStrLen (LhsPath8); +ASSERT (LhsBasenameLen < LhsLen); + DestPrefixLen = LhsLen - LhsBasenameLen; +ASSERT (LhsPath8[DestPrefixLen -1 ] =='/' ); +// +// If we're not at the root directory, strip the slash too. +// +if (DestPrefixLen >1 ) { + DestPrefixLen--; + } + DestPrefix8 =AllocatePool (DestPrefixLen +1 ); +if (DestPrefix8 ==NULL ) { + Status =EFI_OUT_OF_RESOURCES ; + goto FreeDestSuffix16; + } +CopyMem (DestPrefix8, LhsPath8, DestPrefixLen); + DestPrefix8[DestPrefixLen] ='\0' ; + } + +// +// Now combine DestPrefix8 and DestSuffix16 into the final canonical +// pathname. +// + Status =VirtioFsAppendPath (DestPrefix8, DestSuffix16, ResultPath8, + RootEscape); + +FreePool (DestPrefix8); +// +// Fall through. +// +FreeDestSuffix16: +FreePool (DestSuffix16); + +return Status; +} +/** Convert select fields of a VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to corresponding fields in EFI_FILE_INFO. @param[in] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to convert the relevant fields from. @param[out] FileInfo The EFI_FILE_INFO structure to modify. Importantly, the
Re: [Virtio-fs] [edk2 PATCH 42/48] OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination path
Quoted 21 lines · Laszlo Ersek
Quoted 10 lines · Ard Biesheuvel
Quoted 9 lines · Laszlo Ersek
The
EFI_FILE_PROTOCOL.SetInfo()member is somewhat under-specified; one of its modes of operation is renaming/moving the file.In order to create the destination pathname in canonical format, 2*2=4 cases have to be considered. For the sake of discussion, assume the current canonical pathname of a
VIRTIO_FS_FILEis "/home/user/f1.txt". Then, consider the following rename/move requests fromEFI_FILE_PROTOCOL.SetInfo():Quoted 6 lines
Quoted 4 lines
Destination requested Destination Move into Destination in by SetInfo() relative? directory? canonical format --------------------- ----------- ---------- ----------------------- L"\\dir\\f2.txt" no no "/dir/f2.txt"What happens in the above case if /dir/f2.txt is an existing directory?
Short answer:
Quoted 8 lines
The present patch only constructs the destination pathname. The rename attempt you describe is caught
- either by the subsequent patch, if the existing dest directory is open by the guest driver,
- or else, by the host kernel, due to the
RENAME_NOREPLACEflag set in the patch before this one.
... I'm sorry, I need to correct a bit: the guest-side check I quoted below is not meant to protect from the destination being overwritten, it is supposed to protect against the *source disappearing* (and against breaking other VIRTIO_FS_FILEs' canonical pathnames due to that). So, the answer to your question is: it is caught by RENAME_NOREPLACE.
Everything else I said stands, it's just that the particular guest-side check is related to a different question -- namely, "what if '/home/user/f1.txt' is a directory".
Thanks, and sorry about the confusion,
Laszlo
Quoted 128 lines
Long (very long) answer, in opposite order of the above cases:
- If "/dir/f2.txt" were an existing name (regardless of the type of the host-side inode that it referred to), then the
FUSE_RENAME2request would fail: the host kernel would reject therenameat2()system call made by virtiofsd. This would be due to theRENAME_NOREPLACEflag:https://man7.org/linux/man-pages/man2/rename.2.html include/uapi/linux/fs.hwhich is set in
[edk2 PATCH 41/48]
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_RENAME2using the macro name
VIRTIO_FS_FUSE_RENAME2_REQ_F_NOREPLACE.Thus, if the request reached the host kernel, an
-EEXISTerrno would come back to the guest driver.(
- If the movement source were a non-directory and the destination were a directory, then that would fail (also in the host kernel at the latest) even with the simpler (flag-less)
FUSE_RENAMErequest, which virtiofsd translates to therenameat()syscall, with-EISDIR.- If both source and destination were directories, and the destination were not empty, then even the flag-less
renameat()would fail with-ENOTEMPTY.- If both source and destination were directories, and the destination were empty, then
renameat()would replace the destination [*]; butrenameat2()withRENAME_NOREPLACEwill not.[*] mkdir source-dir target-dir
ls -lid source-dir target-dir
touchsource-dir/file.txt
mv -T source-dir target-dir
ls -lid target-dir
ls -ltarget-dir/file.txt)
Then, in addition to
RENAME_NOREPLACE, there's a guest-side check in[edk2 PATCH 43/48]
OvmfPkg/VirtioFsDxe: handle file rename/move in EFI_FILE_PROTOCOL.SetInfothat was inspired by "FatPkg/EnhancedFatDxe". Namely:
Quoted 18 lines
(quoted diff) +18
-0+ // + // Check if the rename would break the canonical pathnames of other + // VIRTIO_FS_FILE instances of the same VIRTIO_FS. + // + if (VirtioFsFile->IsDirectory) { + UINTN PathLen; + LIST_ENTRY *OpenFilesEntry; + + PathLen = AsciiStrLen (VirtioFsFile->CanonicalPathname); + BASE_LIST_FOR_EACH (OpenFilesEntry, &VirtioFs->OpenFiles) { + VIRTIO_FS_FILE *OtherFile; + + OtherFile = VIRTIO_FS_FILE_FROM_OPEN_FILES_ENTRY (OpenFilesEntry); + if (OtherFile != VirtioFsFile && + AsciiStrnCmp (VirtioFsFile->CanonicalPathname, + OtherFile->CanonicalPathname, PathLen) == 0 && + (OtherFile->CanonicalPathname[PathLen] == '\0' || + OtherFile->CanonicalPathname[PathLen] == '/')) {Review
Quoted 10 lines
(quoted diff) +10
-0+ // + // OtherFile refers to the same directory as VirtioFsFile, or is a + // (possibly indirect) child of the directory referred to by + // VirtioFsFile. + // + Status = EFI_ACCESS_DENIED; + goto FreeDestination; + } + } + }This is why "VIRTIO_FS.OpenFiles" is a list, and not just a reference count -- for this simple guest-side check, I needed to go through the other open
VIRTIO_FS_FILEsfor the sameVIRTIO_FSone by one. Just knowing how many of them existed wouldn't be enough.This guest-side check is by no means foolproof; after all, you can do whatever you want on the host side, underneath the guest driver's feet.
But, catching such "async tricks" is not a goal for this driver.
EFI_FILE_PROTOCOLis not equipped to deal with such async changes by design. At best, it can returnEFI_MEDIA_CHANGED, when (e.g.) removable media is replaced. But even if I could detect such a situation in the virtio-fs driver, it would be counter-productive: when a host-side file changes, that's something the guest wants to pick up one way or another, we don't want the driver to switch to returningEFI_MEDIA_CHANGEDfor all further requests indiscriminately.Synchronization between host and guest is pretty simple for the interactive use case: whenever your shell prompt returns, on the host or in the guest (meaning the UEFI shell prompt in the latter), you can Alt-TAB to the other terminal, and manipulate files from there.
Synchronization between host-side and guest-side scripts should be possible with polling directory listings, and renaming / moving regular files (files should be prepared in "private" directories, and then moved into place when done, for the other side to notice).
So, the above guest-side check exists for the usual case when the relevant sub-hierarchy of the shared directory doesn't change asynchronously to VIRTIO_FS_FILE's being open; when the guest-side check fires in this optimistic situation, the
FUSE_RENAME2request isn't even sent. And for when the guest-side check isn't good enough, that's when theRENAME_NOREPLACEflag becomes relevant -- I wanted to avoid unwittingly deleting entries in the shared directory by guest-initiated renames.Sorry about the long answer. I feel it's not really possible to address your question without talking about asynchrony between host and guest. I had thought about it before, and I figured, shoehorning a shared filesystem into a non-shared filesystem abstraction should be acceptable this way. The use case is to support Alt-TABbing between your guest and host terminals, and running such UEFI unit tests in the guest that take input from the host filesystem and produce output to the host filesystem. A highly async / parallel operation is a non-goal.
Thanks!
Laszlo
PATCH 43/48 OvmfPkg/VirtioFsDxe: handle file rename/move in EFI_FILE_PROTOCOL.SetInfo
In reply to Laszlo ErsekUsing the functions introduced previously, we can now implement the rename operation in VirtioFsSimpleFileSetInfo().
Attribute updates come later.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c | 234 +++++++++++++++++++- 1 file changed, 233 insertions(+), 1 deletion(-)
OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c +233 -1
@@ -5,16 +5,17 @@SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include <Guid/FileSystemInfo.h> // gEfiFileSystemInfoGuid #include <Guid/FileSystemVolumeLabelInfo.h> // gEfiFileSystemVolumeLabelInfo... #include <Library/BaseLib.h> // StrCmp() #include <Library/BaseMemoryLib.h> // CompareGuid() +#include <Library/MemoryAllocationLib.h> // FreePool() #include "VirtioFsDxe.h" /** Validate a buffer that the EFI_FILE_PROTOCOL.SetInfo() caller passes in for a particular InformationType GUID. The structure to be validated is supposed to end with a variable-length,
@@ -122,16 +123,247 @@ ValidateInfoStructure ( NameField = (CHAR16 *)((UINT8 *)Buffer + NameFieldByteOffset);if (NameField[NameFieldChar16s -1 ] !=L'\0' ) {return EFI_INVALID_PARAMETER ; }return EFI_SUCCESS ; } +/** +Rename a VIRTIO_FS_FILE as requested in EFI_FILE_INFO.FileName. + +@param[in,out] VirtioFsFile The VIRTIO_FS_FILE to rename. + +@param[in] NewFileName The new file name requested by +EFI_FILE_PROTOCOL.SetInfo(). + +@retval EFI_SUCCESS The canonical format destination path that is +determined from the input value of +VirtioFsFile->CanonicalPathname and from +NewFileName is identical to the input value of +VirtioFsFile->CanonicalPathname. This means that +EFI_FILE_INFO does not constitute a rename +request. VirtioFsFile has not been changed. + +@retval EFI_SUCCESS VirtioFsFile has been renamed. +VirtioFsFile->CanonicalPathname has assumed the +destination pathname in canonical format. + +@retval EFI_ACCESS_DENIED VirtioFsFile refers to the root directory, and +NewFileName expresses an actual rename/move +request. + +@retval EFI_ACCESS_DENIED VirtioFsFile is the (possibly indirect) parent +directory of at least one other VIRTIO_FS_FILE +that is open for the same Virtio Filesystem +(identified by VirtioFsFile->OwnerFs). Renaming +VirtioFsFile would invalidate the canonical +pathnames of those VIRTIO_FS_FILE instances; +therefore the request has been rejected. + +@retval EFI_ACCESS_DENIED VirtioFsFile is not open for writing, but +NewFileName expresses an actual rename/move +request. + +@retval EFI_NOT_FOUND At least one dot-dot component in NewFileName +attempted to escape the root directory. + +@return Error codes propagated from underlying functions. +**/ +STATIC +EFI_STATUS +Rename ( + IN OUT VIRTIO_FS_FILE *VirtioFsFile, + IN CHAR16 *NewFileName + ) +{ + +VIRTIO_FS *VirtioFs; +EFI_STATUS Status; +CHAR8 *Destination; +BOOLEAN RootEscape; +UINT64 OldParentDirNodeId; +CHAR8 *OldLastComponent; +UINT64 NewParentDirNodeId; +CHAR8 *NewLastComponent; + + VirtioFs = VirtioFsFile->OwnerFs; + +// +// The root directory cannot be renamed. +// +if (AsciiStrCmp (VirtioFsFile->CanonicalPathname,"/" ) ==0 ) { +if (StrCmp (NewFileName,L"" ) ==0 ) { +// +// Not a rename request anyway. +// +return EFI_SUCCESS ; + } +return EFI_ACCESS_DENIED ; + } + +// +// Compose the canonical pathname for the destination. +// + Status =VirtioFsComposeRenameDestination (VirtioFsFile->CanonicalPathname, + NewFileName, &Destination, &RootEscape); +if (EFI_ERROR (Status)) { +return Status; + } +if (RootEscape) { + Status =EFI_NOT_FOUND ; + goto FreeDestination; + } +// +// If the rename would leave VirtioFsFile->CanonicalPathname unchanged, then +// EFI_FILE_PROTOCOL.SetInfo() isn't asking for a rename actually. +// +if (AsciiStrCmp (VirtioFsFile->CanonicalPathname, Destination) ==0 ) { + Status =EFI_SUCCESS ; + goto FreeDestination; + } +// +// Check if the rename would break the canonical pathnames of other +// VIRTIO_FS_FILE instances of the same VIRTIO_FS. +// +if (VirtioFsFile->IsDirectory) { +UINTN PathLen; +LIST_ENTRY *OpenFilesEntry; + + PathLen =AsciiStrLen (VirtioFsFile->CanonicalPathname); + BASE_LIST_FOR_EACH (OpenFilesEntry, &VirtioFs->OpenFiles) { +VIRTIO_FS_FILE *OtherFile; + + OtherFile =VIRTIO_FS_FILE_FROM_OPEN_FILES_ENTRY (OpenFilesEntry); +if (OtherFile != VirtioFsFile && +AsciiStrnCmp (VirtioFsFile->CanonicalPathname, + OtherFile->CanonicalPathname, PathLen) ==0 && + (OtherFile->CanonicalPathname[PathLen] =='\0' || + OtherFile->CanonicalPathname[PathLen] =='/' )) { +// +// OtherFile refers to the same directory as VirtioFsFile, or is a +// (possibly indirect) child of the directory referred to by +// VirtioFsFile. +// + Status =EFI_ACCESS_DENIED ; + goto FreeDestination; + } + } + } +// +// From this point on, the file needs to be open for writing. +// +if (!VirtioFsFile->IsOpenForWriting) { + Status =EFI_ACCESS_DENIED ; + goto FreeDestination; + } +// +// Split both source and destination canonical pathnames into (most specific +// parent directory, last component) pairs. +// + Status =VirtioFsLookupMostSpecificParentDir (VirtioFs, + VirtioFsFile->CanonicalPathname, &OldParentDirNodeId, + &OldLastComponent); +if (EFI_ERROR (Status)) { + goto FreeDestination; + } + Status =VirtioFsLookupMostSpecificParentDir (VirtioFs, Destination, + &NewParentDirNodeId, &NewLastComponent); +if (EFI_ERROR (Status)) { + goto ForgetOldParentDirNodeId; + } +// +// Perform the rename. If the destination path exists, the rename will fail. +// + Status =VirtioFsFuseRename (VirtioFs, OldParentDirNodeId, OldLastComponent, + NewParentDirNodeId, NewLastComponent); +if (EFI_ERROR (Status)) { + goto ForgetNewParentDirNodeId; + } + +// +// Swap in the new canonical pathname. +// +FreePool (VirtioFsFile->CanonicalPathname); + VirtioFsFile->CanonicalPathname = Destination; + Destination =NULL ; + Status =EFI_SUCCESS ; + +// +// Fall through. +// +ForgetNewParentDirNodeId: +if (NewParentDirNodeId !=VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID ) { +VirtioFsFuseForget (VirtioFs, NewParentDirNodeId); + } + +ForgetOldParentDirNodeId: +if (OldParentDirNodeId !=VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID ) { +VirtioFsFuseForget (VirtioFs, OldParentDirNodeId); + } + +FreeDestination: +if (Destination !=NULL ) { +FreePool (Destination); + } +return Status; +} + +/** +Process an EFI_FILE_INFO setting request. +**/ +STATIC +EFI_STATUS +SetFileInfo ( + IN EFI_FILE_PROTOCOL *This, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ +VIRTIO_FS_FILE *VirtioFsFile; +EFI_STATUS Status; +EFI_FILE_INFO *FileInfo; + + VirtioFsFile =VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + +// +// Validate if Buffer passes as EFI_FILE_INFO. +// + Status =ValidateInfoStructure ( + BufferSize,// SizeByProtocolCaller +OFFSET_OF (EFI_FILE_INFO , + FileName) +sizeof (CHAR16 ),// MinimumStructSize + TRUE,// IsSizeByInfoPresent + Buffer + ); +if (EFI_ERROR (Status)) { +return Status; + } + FileInfo = Buffer; + +// +// Perform the rename/move request, if any. +// + Status =Rename (VirtioFsFile, FileInfo->FileName); +if (EFI_ERROR (Status)) { +return Status; + } +// +// Update any attributes requested. +// + Status =EFI_UNSUPPORTED ; +// +// The UEFI spec does not speak about partial failure in +// EFI_FILE_PROTOCOL.SetInfo(); we won't try to roll back the rename (if +// there was one) in case the attribute updates fail. +// +return Status; +} +/** Process an EFI_FILE_SYSTEM_INFO setting request. **/ STATIC EFI_STATUS SetFileSystemInfo ( IN EFI_FILE_PROTOCOL *This, IN UINTN BufferSize,
@@ -225,17 +457,17 @@ EFIAPIVirtioFsSimpleFileSetInfo ( IN EFI_FILE_PROTOCOL *This, IN EFI_GUID *InformationType, IN UINTN BufferSize, IN VOID *Buffer ) { if (CompareGuid (InformationType, &gEfiFileInfoGuid)) { - return EFI_UNSUPPORTED; + return SetFileInfo (This, BufferSize, Buffer); }if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {return SetFileSystemInfo (This, BufferSize, Buffer); }if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {return SetFileSystemVolumeLabelInfo (This, BufferSize, Buffer);
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 44/48 OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_SETATTR
In reply to Laszlo ErsekAdd the VirtioFsFuseSetAttr() function, for sending the FUSE_SETATTR command to the Virtio Filesystem device.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 35 +++- OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 10 ++ OvmfPkg/VirtioFsDxe/FuseSetAttr.c | 174 ++++++++++++++++++++ 4 files changed, 219 insertions(+), 1 deletion(-)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +34 -1
@@ -97,16 +97,25 @@ typedef struct {#define VIRTIO_FS_FUSE_MODE_PERM_WUSR 0000200u#define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u#define VIRTIO_FS_FUSE_MODE_PERM_RGRP 0000040u#define VIRTIO_FS_FUSE_MODE_PERM_WGRP 0000020u#define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u#define VIRTIO_FS_FUSE_MODE_PERM_ROTH 0000004u#define VIRTIO_FS_FUSE_MODE_PERM_WOTH 0000002u +// +// Flags for VirtioFsFuseOpSetAttr, in the VIRTIO_FS_FUSE_SETATTR_REQUEST.Valid +// field. +// +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE BIT0 +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE BIT3 +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME BIT4 +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_MTIME BIT5 +// // Flags for VirtioFsFuseOpOpen. // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2// // Flags for VirtioFsFuseOpInit.
@@ -148,16 +157,17 @@ typedef struct {// // FUSE operation codes. // typedef enum { VirtioFsFuseOpLookup = 1, VirtioFsFuseOpForget = 2, VirtioFsFuseOpGetAttr = 3, + VirtioFsFuseOpSetAttr = 4, VirtioFsFuseOpMkDir = 9, VirtioFsFuseOpUnlink = 10, VirtioFsFuseOpRmDir = 11, VirtioFsFuseOpOpen = 14, VirtioFsFuseOpRead = 15, VirtioFsFuseOpWrite = 16, VirtioFsFuseOpStatFs = 17, VirtioFsFuseOpRelease = 18,
@@ -235,30 +245,53 @@ typedef struct {// // Header for VirtioFsFuseOpForget. // typedef struct {UINT64 NumberOfLookups; }VIRTIO_FS_FUSE_FORGET_REQUEST ;// -// Headers for VirtioFsFuseOpGetAttr. +// Headers for VirtioFsFuseOpGetAttr (VIRTIO_FS_FUSE_GETATTR_RESPONSE is also +// for VirtioFsFuseOpSetAttr). // typedef struct {UINT32 GetAttrFlags;UINT32 Dummy;UINT64 FileHandle; }VIRTIO_FS_FUSE_GETATTR_REQUEST ;typedef struct {UINT64 AttrValid;UINT32 AttrValidNsec;UINT32 Dummy; }VIRTIO_FS_FUSE_GETATTR_RESPONSE ; +// +// Header for VirtioFsFuseOpSetAttr. +// +typedef struct { +UINT32 Valid; +UINT32 Padding; +UINT64 FileHandle; +UINT64 Size; +UINT64 LockOwner; +UINT64 Atime; +UINT64 Mtime; +UINT64 Ctime; +UINT32 AtimeNsec; +UINT32 MtimeNsec; +UINT32 CtimeNsec; +UINT32 Mode; +UINT32 Unused4; +UINT32 Uid; +UINT32 Gid; +UINT32 Unused5; +}VIRTIO_FS_FUSE_SETATTR_REQUEST ; +// // Header for VirtioFsFuseOpMkDir. // typedef struct {UINT32 Mode;UINT32 Umask; }VIRTIO_FS_FUSE_MKDIR_REQUEST ;
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +1 -0
@@ -91,16 +91,17 @@ [Sources] FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRead.c FuseRelease.c FuseRename.c + FuseSetAttr.c FuseStatFs.c FuseUnlink.c FuseWrite.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +10 -0
@@ -303,16 +303,26 @@ VirtioFsFuseForget (EFI_STATUS VirtioFsFuseGetAttr ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr ); +EFI_STATUS +VirtioFsFuseSetAttr ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 *Size OPTIONAL, + IN UINT64 *Atime OPTIONAL, + IN UINT64 *Mtime OPTIONAL, + IN UINT32 *Mode OPTIONAL + ); +EFI_STATUS VirtioFsFuseMkDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 ParentNodeId, IN CHAR8 *Name, OUT UINT64 *NodeId );
OvmfPkg/VirtioFsDxe/FuseSetAttr.c new file +174 -0
174 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 45/48 OvmfPkg/VirtioFsDxe: add helper for determining file size update
In reply to Laszlo ErsekAdd the VirtioFsGetFuseSizeUpdate() function, for determining whether an EFI_FILE_PROTOCOL.SetInfo() invocation requests a file size update.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++++ OvmfPkg/VirtioFsDxe/Helpers.c | 40 ++++++++++++++++++++ 2 files changed, 48 insertions(+)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +8 -0
@@ -277,16 +277,24 @@ VirtioFsFuseAttrToEfiFileInfo ( );EFI_STATUS VirtioFsFuseDirentPlusToEfiFileInfo ( IN VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *FuseDirent, IN OUT EFI_FILE_INFO *FileInfo ); +VOID +VirtioFsGetFuseSizeUpdate ( + IN EFI_FILE_INFO *Info, + IN EFI_FILE_INFO *NewInfo, + OUT BOOLEAN *Update, + OUT UINT64 *Size + ); +// // Wrapper functions for FUSE commands (primitives). // EFI_STATUS VirtioFsFuseLookup ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 DirNodeId,
OvmfPkg/VirtioFsDxe/Helpers.c +40 -0
@@ -2168,8 +2168,48 @@ VirtioFsFuseDirentPlusToEfiFileInfo ( FileInfo->FileName[Idx++] =L'\0' ;// // Set the (possibly reduced) size. // FileInfo->Size = FileInfoSize;return EFI_SUCCESS ; } + +/** +Given an EFI_FILE_INFO object received in an EFI_FILE_PROTOCOL.SetInfo() +call, determine whether updating the size of the file is necessary, relative +to an EFI_FILE_INFO object describing the current state of the file. + +@param[in] Info The EFI_FILE_INFO describing the current state of the +file. The caller is responsible for populating Info on +input with VirtioFsFuseAttrToEfiFileInfo(), from the +current FUSE attributes of the file. The Info->Size and +Info->FileName members are ignored. + +@param[in] NewInfo The EFI_FILE_INFO object received in the +EFI_FILE_PROTOCOL.SetInfo() call. + +@param[out] Update Set to TRUE on output if the file size needs to be +updated. Set to FALSE otherwise. + +@param[out] Size If Update is set to TRUE, then Size provides the new file +size to set. Otherwise, Size is not written to. +**/ +VOID +VirtioFsGetFuseSizeUpdate ( + IN EFI_FILE_INFO *Info, + IN EFI_FILE_INFO *NewInfo, + OUT BOOLEAN *Update, + OUT UINT64 *Size + ) +{ +BOOLEAN IsDirectory; + + IsDirectory = (BOOLEAN )((Info->Attribute &EFI_FILE_DIRECTORY ) !=0 ); + +if (IsDirectory || Info->FileSize == NewInfo->FileSize) { + *Update = FALSE; +return ; + } + *Update = TRUE; + *Size = NewInfo->FileSize; +}
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 46/48 OvmfPkg/VirtioFsDxe: add helper for determining access time updates
In reply to Laszlo ErsekAdd the VirtioFsGetFuseTimeUpdates() function, for determining whether an EFI_FILE_PROTOCOL.SetInfo() invocation requests access time updates.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 10 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 106 ++++++++++++++++++++ 2 files changed, 116 insertions(+)
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +10 -0
@@ -285,16 +285,26 @@ VirtioFsFuseDirentPlusToEfiFileInfo (VOID VirtioFsGetFuseSizeUpdate ( IN EFI_FILE_INFO *Info, IN EFI_FILE_INFO *NewInfo, OUT BOOLEAN *Update, OUT UINT64 *Size ); +EFI_STATUS +VirtioFsGetFuseTimeUpdates ( + IN EFI_FILE_INFO *Info, + IN EFI_FILE_INFO *NewInfo, + OUT BOOLEAN *UpdateAtime, + OUT BOOLEAN *UpdateMtime, + OUT UINT64 *Atime, + OUT UINT64 *Mtime + ); +// // Wrapper functions for FUSE commands (primitives). // EFI_STATUS VirtioFsFuseLookup ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 DirNodeId,
OvmfPkg/VirtioFsDxe/Helpers.c +106 -0
114 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 47/48 OvmfPkg/VirtioFsDxe: add helper for determining file mode bits update
In reply to Laszlo ErsekAdd the VirtioFsGetFuseModeUpdate() function, for determining whether an EFI_FILE_PROTOCOL.SetInfo() invocation requests an update to the file mode bits.
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 3 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 95 ++++++++++++++++++++ 3 files changed, 106 insertions(+)
OvmfPkg/Include/IndustryStandard/VirtioFs.h +3 -0
@@ -90,22 +90,25 @@ typedef struct {// File mode bitmasks. // #define VIRTIO_FS_FUSE_MODE_TYPE_MASK 0170000u#define VIRTIO_FS_FUSE_MODE_TYPE_REG 0100000u#define VIRTIO_FS_FUSE_MODE_TYPE_DIR 0040000u#define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u#define VIRTIO_FS_FUSE_MODE_PERM_RUSR 0000400u#define VIRTIO_FS_FUSE_MODE_PERM_WUSR 0000200u +#define VIRTIO_FS_FUSE_MODE_PERM_XUSR 0000100u#define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u#define VIRTIO_FS_FUSE_MODE_PERM_RGRP 0000040u#define VIRTIO_FS_FUSE_MODE_PERM_WGRP 0000020u +#define VIRTIO_FS_FUSE_MODE_PERM_XGRP 0000010u#define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u#define VIRTIO_FS_FUSE_MODE_PERM_ROTH 0000004u#define VIRTIO_FS_FUSE_MODE_PERM_WOTH 0000002u +#define VIRTIO_FS_FUSE_MODE_PERM_XOTH 0000001u// // Flags for VirtioFsFuseOpSetAttr, in the VIRTIO_FS_FUSE_SETATTR_REQUEST.Valid // field. // #define VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE BIT0#define VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE BIT3#define VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME BIT4
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +8 -0
@@ -295,16 +295,24 @@ VirtioFsGetFuseTimeUpdates ( IN EFI_FILE_INFO *Info, IN EFI_FILE_INFO *NewInfo, OUT BOOLEAN *UpdateAtime, OUT BOOLEAN *UpdateMtime, OUT UINT64 *Atime, OUT UINT64 *Mtime ); +EFI_STATUS +VirtioFsGetFuseModeUpdate ( + IN EFI_FILE_INFO *Info, + IN EFI_FILE_INFO *NewInfo, + OUT BOOLEAN *Update, + OUT UINT32 *Mode + ); +// // Wrapper functions for FUSE commands (primitives). // EFI_STATUS VirtioFsFuseLookup ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 DirNodeId,
OvmfPkg/VirtioFsDxe/Helpers.c +95 -0
103 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g30247aa5d201
PATCH 48/48 OvmfPkg/VirtioFsDxe: handle attribute updates in EFI_FILE_PROTOCOL.SetInfo
In reply to Laszlo ErsekUsing the functions introduced previously, we can now update file attributes in VirtioFsSimpleFileSetInfo().
Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
--- OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c | 107 +++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-)
OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c +106 -1
@@ -303,16 +303,121 @@ Rename ( FreeDestination:if (Destination !=NULL ) {FreePool (Destination); }return Status; } +/** +Update the attributes of a VIRTIO_FS_FILE as requested in EFI_FILE_INFO. + +@param[in,out] VirtioFsFile The VIRTIO_FS_FILE to update the attributes of. + +@param[in] NewFileInfo The new attributes requested by +EFI_FILE_PROTOCOL.SetInfo(). NewFileInfo->Size +and NewFileInfo->FileName are ignored. + +@retval EFI_SUCCESS No attributes had to be updated. + +@retval EFI_SUCCESS The required set of attribute updates has been +determined and performed successfully. + +@retval EFI_ACCESS_DENIED NewFileInfo requests an update to a property +different from the EFI_FILE_READ_ONLY bit in the +Attribute field, but VirtioFsFile is not open for +writing. + +@return Error codes propagated from underlying functions. +**/ +STATIC +EFI_STATUS +UpdateAttributes ( + IN OUT VIRTIO_FS_FILE *VirtioFsFile, + IN EFI_FILE_INFO *NewFileInfo + ) +{ +VIRTIO_FS *VirtioFs; +EFI_STATUS Status; +VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; +EFI_FILE_INFO FileInfo; +BOOLEAN UpdateFileSize; +UINT64 FileSize; +BOOLEAN UpdateAtime; +BOOLEAN UpdateMtime; +UINT64 Atime; +UINT64 Mtime; +BOOLEAN UpdateMode; +UINT32 Mode; + + VirtioFs = VirtioFsFile->OwnerFs; + +// +// Fetch the current attributes first, so we can build the difference between +// them and NewFileInfo. +// + Status =VirtioFsFuseGetAttr (VirtioFs, VirtioFsFile->NodeId, &FuseAttr); +if (EFI_ERROR (Status)) { +return Status; + } + Status =VirtioFsFuseAttrToEfiFileInfo (&FuseAttr, &FileInfo); +if (EFI_ERROR (Status)) { +return Status; + } +// +// Collect the updates. +// +if (VirtioFsFile->IsDirectory) { + UpdateFileSize = FALSE; + }else { +VirtioFsGetFuseSizeUpdate (&FileInfo, NewFileInfo, &UpdateFileSize, + &FileSize); + } + + Status =VirtioFsGetFuseTimeUpdates (&FileInfo, NewFileInfo, &UpdateAtime, + &UpdateMtime, &Atime, &Mtime); +if (EFI_ERROR (Status)) { +return Status; + } + + Status =VirtioFsGetFuseModeUpdate (&FileInfo, NewFileInfo, &UpdateMode, + &Mode); +if (EFI_ERROR (Status)) { +return Status; + } + +// +// If no attribute updates are necessary, we're done. +// +if (!UpdateFileSize && !UpdateAtime && !UpdateMtime && !UpdateMode) { +return EFI_SUCCESS ; + } +// +// If the file is not open for writing, then only Mode may be updated (for +// toggling EFI_FILE_READ_ONLY). +// +if (!VirtioFsFile->IsOpenForWriting && + (UpdateFileSize || UpdateAtime || UpdateMtime)) { +return EFI_ACCESS_DENIED ; + } +// +// Send the FUSE_SETATTR request now. +// + Status =VirtioFsFuseSetAttr ( + VirtioFs, + VirtioFsFile->NodeId, + UpdateFileSize ? &FileSize :NULL , + UpdateAtime ? &Atime :NULL , + UpdateMtime ? &Mtime :NULL , + UpdateMode ? &Mode :NULL + ); +return Status; +} +/** Process an EFI_FILE_INFO setting request. **/ STATIC EFI_STATUS SetFileInfo ( IN EFI_FILE_PROTOCOL *This, IN UINTN BufferSize,
@@ -345,17 +450,17 @@ SetFileInfo (// Status =Rename (VirtioFsFile, FileInfo->FileName);if (EFI_ERROR (Status)) {return Status; }// // Update any attributes requested. // - Status =EFI_UNSUPPORTED ; + Status =UpdateAttributes (VirtioFsFile, FileInfo);// // The UEFI spec does not speak about partial failure in // EFI_FILE_PROTOCOL.SetInfo(); we won't try to roll back the rename (if // there was one) in case the attribute updates fail. // return Status; }
Signature · 1 line
2.19.1.3.g30247aa5d201
Quoted 85 lines · Laszlo Ersek
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097 Repo: https://pagure.io/lersek/edk2.git Branch: virtio-fs (@ b8fd76d649d2)The first commit and the bugzilla ticket state the use case.
References, including setup instructions:
- https://libvirt.org/kbase/virtiofs.html
- https://virtio-fs.gitlab.io/Useful UEFI shell commands for testing: output redirections, attrib, connect, cp, disconnect, edit, eficompress, efidecompress, hexedit, ls, map, mkdir, mv, rm, setsize, timezone, touch, type, vol.
The series is largely structured as follows:
- helper functions and FUSE command wrappers are implemented as required by the nextEFI_FILE_PROTOCOLinterface,
- saidEFI_FILE_PROTOCOLinterface is implemented,
- lather, rinse, repeat.Cc Ard Biesheuvel <[email protected]>Cc Jordan Justen <[email protected]>Cc Leif Lindholm <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Thanks,
LaszloLaszlo Ersek (48):
OvmfPkg: introduce VirtioFsDxe
ArmVirtPkg: include VirtioFsDxe in the ArmVirtQemu* platforms OvmfPkg/VirtioFsDxe: DriverBinding: open VirtioDevice, install
SimpleFs
OvmfPkg/VirtioFsDxe: implement virtio device (un)initialization OvmfPkg/VirtioFsDxe: add a scatter-gather list data type OvmfPkg/VirtioFsDxe: introduce the basic FUSE request/response headers OvmfPkg/VirtioFsDxe: map "errno" values toEFI_STATUSOvmfPkg/VirtioFsDxe: submit theFUSE_INITrequest to the device OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_OPENDIROvmfPkg/VirtioFsDxe: add shared wrapper forFUSE_RELEASE/
FUSE_RELEASEDIR
OvmfPkg/VirtioFsDxe: implement
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume()
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_FORGETOvmfPkg/VirtioFsDxe: add a shared wrapper forFUSE_FSYNC/
FUSE_FSYNCDIR
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_FLUSHOvmfPkg/VirtioFsDxe: flush, sync, release and forget inClose()/
Delete()
OvmfPkg/VirtioFsDxe: add helper for appending and sanitizing paths OvmfPkg/VirtioFsDxe: manage path lifecycle in OpenVolume, Close,
Delete
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_OPENOvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_MKDIROvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_CREATEOvmfPkg/VirtioFsDxe: convert FUSE inode attributes toEFI_FILE_INFOOvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_LOOKUPOvmfPkg/VirtioFsDxe: split canon. path into last parent + last
component
OvmfPkg/VirtioFsDxe: add a shared wrapper forFUSE_UNLINK/FUSE_RMDIROvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_GETATTROvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Open()OvmfPkg/VirtioFsDxe: erase the dir. entry in
EFI_FILE_PROTOCOL.Delete()
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_STATFSOvmfPkg/VirtioFsDxe: add helper for formatting UEFI basenames OvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.GetInfo()OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.GetPosition,
.SetPosition
OvmfPkg/VirtioFsDxe: add a shared wrapper forFUSE_READ/
FUSE_READDIRPLUS
OvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Read()for regular
files
OvmfPkg/VirtioFsDxe: convert FUSE dirent filename toEFI_FILE_INFOOvmfPkg/VirtioFsDxe: addEFI_FILE_INFOcache fields toVIRTIO_FS_FILEOvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Read()for
directories
OvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Flush()OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_WRITEOvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Write()OvmfPkg/VirtioFsDxe: handle the volume label in
EFI_FILE_PROTOCOL.SetInfo
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_RENAME2OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination
path
Quoted 9 lines
OvmfPkg/VirtioFsDxe: handle file rename/move in
EFI_FILE_PROTOCOL.SetInfo
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_SETATTROvmfPkg/VirtioFsDxe: add helper for determining file size update OvmfPkg/VirtioFsDxe: add helper for determining access time updates OvmfPkg/VirtioFsDxe: add helper for determining file mode bits update OvmfPkg/VirtioFsDxe: handle attribute updates in
EFI_FILE_PROTOCOL.SetInfo
This looks carefully crafted, and modulo my two questions, I won't be able to spend more time on this than I have going through these patches today.
So please feel free to merge this whenever you feel it's ready.
For the series,
Quoted 81 lines
ArmVirtPkg/ArmVirtQemu.dsc | 3 +- ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 3 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 3 +- OvmfPkg/Include/IndustryStandard/Virtio10.h | 5 + OvmfPkg/Include/IndustryStandard/VirtioFs.h | 454 ++++ OvmfPkg/OvmfPkgIa32.dsc | 2 + OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 2 + OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.dsc | 2 + OvmfPkg/OvmfPkgX64.fdf | 1 + OvmfPkg/VirtioFsDxe/DriverBinding.c | 232 ++ OvmfPkg/VirtioFsDxe/FuseFlush.c | 111 + OvmfPkg/VirtioFsDxe/FuseForget.c | 85 + OvmfPkg/VirtioFsDxe/FuseFsync.c | 121 + OvmfPkg/VirtioFsDxe/FuseGetAttr.c | 116 + OvmfPkg/VirtioFsDxe/FuseInit.c | 142 ++ OvmfPkg/VirtioFsDxe/FuseLookup.c | 148 ++ OvmfPkg/VirtioFsDxe/FuseMkDir.c | 134 ++ OvmfPkg/VirtioFsDxe/FuseOpen.c | 126 + OvmfPkg/VirtioFsDxe/FuseOpenDir.c | 120 + OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c | 155 ++ OvmfPkg/VirtioFsDxe/FuseRead.c | 191 ++ OvmfPkg/VirtioFsDxe/FuseRelease.c | 121 + OvmfPkg/VirtioFsDxe/FuseRename.c | 131 ++ OvmfPkg/VirtioFsDxe/FuseSetAttr.c | 174 ++ OvmfPkg/VirtioFsDxe/FuseStatFs.c | 102 + OvmfPkg/VirtioFsDxe/FuseUnlink.c | 114 + OvmfPkg/VirtioFsDxe/FuseWrite.c | 155 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 2416 ++++++++++++++++++++ OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 68 + OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 110 + OvmfPkg/VirtioFsDxe/SimpleFsFlush.c | 42 + OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c | 209 ++ OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c | 27 + OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 505 ++++ OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 98 + OvmfPkg/VirtioFsDxe/SimpleFsRead.c | 434 ++++ OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c | 582 +++++ OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c | 67 + OvmfPkg/VirtioFsDxe/SimpleFsWrite.c | 81 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 544 +++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 136 ++ 43 files changed, 8271 insertions(+), 3 deletions(-) create mode 100644 OvmfPkg/Include/IndustryStandard/VirtioFs.h create mode 100644 OvmfPkg/VirtioFsDxe/DriverBinding.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseFlush.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseForget.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseFsync.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseGetAttr.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseInit.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseLookup.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseMkDir.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseOpen.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseOpenDir.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseRead.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseRelease.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseRename.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseSetAttr.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseStatFs.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseUnlink.c create mode 100644 OvmfPkg/VirtioFsDxe/FuseWrite.c create mode 100644 OvmfPkg/VirtioFsDxe/Helpers.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsClose.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsDelete.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsFlush.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsOpen.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsRead.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c create mode 100644 OvmfPkg/VirtioFsDxe/SimpleFsWrite.c create mode 100644 OvmfPkg/VirtioFsDxe/VirtioFsDxe.h create mode 100644 OvmfPkg/VirtioFsDxe/VirtioFsDxe.infbase-commit:
e6ae24e1d676bb2bdc0fc715b49b04908f41fc10
Quoted 100 lines · Ard Biesheuvel
Quoted 85 lines · Laszlo Ersek
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097 Repo: https://pagure.io/lersek/edk2.git Branch: virtio-fs (@ b8fd76d649d2)The first commit and the bugzilla ticket state the use case.
References, including setup instructions:
- https://libvirt.org/kbase/virtiofs.html
- https://virtio-fs.gitlab.io/Useful UEFI shell commands for testing: output redirections, attrib, connect, cp, disconnect, edit, eficompress, efidecompress, hexedit, ls, map, mkdir, mv, rm, setsize, timezone, touch, type, vol.
The series is largely structured as follows:
- helper functions and FUSE command wrappers are implemented as required by the nextEFI_FILE_PROTOCOLinterface,
- saidEFI_FILE_PROTOCOLinterface is implemented,
- lather, rinse, repeat.Cc Ard Biesheuvel <[email protected]>Cc Jordan Justen <[email protected]>Cc Leif Lindholm <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Thanks,
LaszloLaszlo Ersek (48):
OvmfPkg: introduce VirtioFsDxe
ArmVirtPkg: include VirtioFsDxe in the ArmVirtQemu* platforms OvmfPkg/VirtioFsDxe: DriverBinding: open VirtioDevice, install
SimpleFs
OvmfPkg/VirtioFsDxe: implement virtio device (un)initialization OvmfPkg/VirtioFsDxe: add a scatter-gather list data type OvmfPkg/VirtioFsDxe: introduce the basic FUSE request/response headers OvmfPkg/VirtioFsDxe: map "errno" values toEFI_STATUSOvmfPkg/VirtioFsDxe: submit theFUSE_INITrequest to the device OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_OPENDIROvmfPkg/VirtioFsDxe: add shared wrapper forFUSE_RELEASE/
FUSE_RELEASEDIR
OvmfPkg/VirtioFsDxe: implement
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume()
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_FORGETOvmfPkg/VirtioFsDxe: add a shared wrapper forFUSE_FSYNC/
FUSE_FSYNCDIR
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_FLUSHOvmfPkg/VirtioFsDxe: flush, sync, release and forget inClose()/
Delete()
OvmfPkg/VirtioFsDxe: add helper for appending and sanitizing paths OvmfPkg/VirtioFsDxe: manage path lifecycle in OpenVolume, Close,
Delete
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_OPENOvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_MKDIROvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_CREATEOvmfPkg/VirtioFsDxe: convert FUSE inode attributes toEFI_FILE_INFOOvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_LOOKUPOvmfPkg/VirtioFsDxe: split canon. path into last parent + last
component
OvmfPkg/VirtioFsDxe: add a shared wrapper forFUSE_UNLINK/FUSE_RMDIROvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_GETATTROvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Open()OvmfPkg/VirtioFsDxe: erase the dir. entry in
EFI_FILE_PROTOCOL.Delete()
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_STATFSOvmfPkg/VirtioFsDxe: add helper for formatting UEFI basenames OvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.GetInfo()OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.GetPosition,
.SetPosition
OvmfPkg/VirtioFsDxe: add a shared wrapper forFUSE_READ/
FUSE_READDIRPLUS
OvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Read()for regular
files
OvmfPkg/VirtioFsDxe: convert FUSE dirent filename toEFI_FILE_INFOOvmfPkg/VirtioFsDxe: addEFI_FILE_INFOcache fields toVIRTIO_FS_FILEOvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Read()for
directories
OvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Flush()OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_WRITEOvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Write()OvmfPkg/VirtioFsDxe: handle the volume label in
EFI_FILE_PROTOCOL.SetInfo
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_RENAME2OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination
pathQuoted 9 lines
OvmfPkg/VirtioFsDxe: handle file rename/move in
EFI_FILE_PROTOCOL.SetInfo
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_SETATTROvmfPkg/VirtioFsDxe: add helper for determining file size update OvmfPkg/VirtioFsDxe: add helper for determining access time updates OvmfPkg/VirtioFsDxe: add helper for determining file mode bits update OvmfPkg/VirtioFsDxe: handle attribute updates in
EFI_FILE_PROTOCOL.SetInfoThis looks carefully crafted, and modulo my two questions, I won't be able to spend more time on this than I have going through these patches today.
Quoted 5 lines
So please feel free to merge this whenever you feel it's ready.
For the series,
Acked-by Ard Biesheuvel <[email protected]>
Thank you.
Before I posted the series, I tested it very thoroughly, including build tests (at every patch, and a Local CI run as well). I created a test plan and went through it meticulously (it took hours).
The only thing I couldn't test that way was (obviously) building on Windows. So clearly now that I've tried merging the series at
<https://github.com/tianocore/edk2/pull/1248>, that's what fails. Because, this is the first time that EmbeddedPkg/TimeBaseLib is seen by the Visual Studio compiler, and Visual Studio complains:
Quoted 6 lines
ERROR - Compiler #2220 from
d:\a\1\s\EmbeddedPkg\Library\TimeBaseLib\TimeBaseLib.c(111): the
following warning is treated as an error
WARNING - Compiler #4244 from
d:\a\1\s\EmbeddedPkg\Library\TimeBaseLib\TimeBaseLib.c(111): '=':
conversion from 'UINTN' to 'UINT32', possible loss of data
It happens to be correct:
99 /** 100 Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) 101 **/ 102 UINT32 103 EFIAPI 104 EfiTimeToEpoch (
105 IN EFI_TIME *Time
106 )
107 {
108 UINT32 EpochDays; // Number of days elapsed since EPOCH_JULIAN_DAY
109 UINT32 EpochSeconds;
110
111 EpochDays = EfiGetEpochDays (Time);
112
113 EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second;
114
115 return EpochSeconds;
116 }
This was discussed on the list earlier, when the function was duplicated for the HTTP dynamic command:
- https://edk2.groups.io/g/devel/message/64933
- https://edk2.groups.io/g/devel/message/65186
Compare EfiTimeToEpoch() in "ShellPkg/DynamicCommand/HttpDynamicCommand/Http.c".
430 STATIC
431 UINTN
432 EFIAPI
433 EfiTimeToEpoch (
434 IN EFI_TIME *Time
435 )
436 {
437 //
438 // Number of days elapsed since EPOCH_JULIAN_DAY.
439 //
440 UINTN EpochDays;
441 UINTN EpochSeconds; 442
443 EpochDays = EfiGetEpochDays (Time);
444
445 EpochSeconds = (EpochDays * SEC_PER_DAY) +
446 ((UINTN)Time->Hour * SEC_PER_HOUR) +
447 (Time->Minute * SEC_PER_MIN) + Time->Second;
448
449 return EpochSeconds;
450 }
So, in order to merge this series, I'll first have to fix EfiTimeToEpoch() in EmbeddedPkg :(
I wish the fixed version in "ShellPkg/DynamicCommand/HttpDynamicCommand/Http.c" had been contributed back to EmbeddedPkg.
Anyway, that is for 2021.
Thank you for checking the series so quickly; I know it's a lot! Laszlo
Ard Biesheuvel
Acked-byQuoted 181 lines · Laszlo Ersek
Quoted 100 lines · Ard Biesheuvel
Quoted 85 lines · Laszlo Ersek
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097 Repo: https://pagure.io/lersek/edk2.git Branch: virtio-fs (@ b8fd76d649d2)The first commit and the bugzilla ticket state the use case.
References, including setup instructions:
- https://libvirt.org/kbase/virtiofs.html
- https://virtio-fs.gitlab.io/Useful UEFI shell commands for testing: output redirections, attrib, connect, cp, disconnect, edit, eficompress, efidecompress, hexedit, ls, map, mkdir, mv, rm, setsize, timezone, touch, type, vol.
The series is largely structured as follows:
- helper functions and FUSE command wrappers are implemented as required by the nextEFI_FILE_PROTOCOLinterface,
- saidEFI_FILE_PROTOCOLinterface is implemented,
- lather, rinse, repeat.Cc Ard Biesheuvel <[email protected]>Cc Jordan Justen <[email protected]>Cc Leif Lindholm <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Thanks,
LaszloLaszlo Ersek (48):
OvmfPkg: introduce VirtioFsDxe
ArmVirtPkg: include VirtioFsDxe in the ArmVirtQemu* platforms OvmfPkg/VirtioFsDxe: DriverBinding: open VirtioDevice, install
SimpleFs
OvmfPkg/VirtioFsDxe: implement virtio device (un)initialization OvmfPkg/VirtioFsDxe: add a scatter-gather list data type OvmfPkg/VirtioFsDxe: introduce the basic FUSE request/response headers OvmfPkg/VirtioFsDxe: map "errno" values toEFI_STATUSOvmfPkg/VirtioFsDxe: submit theFUSE_INITrequest to the device OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_OPENDIROvmfPkg/VirtioFsDxe: add shared wrapper forFUSE_RELEASE/
FUSE_RELEASEDIR
OvmfPkg/VirtioFsDxe: implement
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume()
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_FORGETOvmfPkg/VirtioFsDxe: add a shared wrapper forFUSE_FSYNC/
FUSE_FSYNCDIR
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_FLUSHOvmfPkg/VirtioFsDxe: flush, sync, release and forget inClose()/
Delete()
OvmfPkg/VirtioFsDxe: add helper for appending and sanitizing paths OvmfPkg/VirtioFsDxe: manage path lifecycle in OpenVolume, Close,
Delete
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_OPENOvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_MKDIROvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_CREATEOvmfPkg/VirtioFsDxe: convert FUSE inode attributes toEFI_FILE_INFOOvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_LOOKUPOvmfPkg/VirtioFsDxe: split canon. path into last parent + last
component
OvmfPkg/VirtioFsDxe: add a shared wrapper forFUSE_UNLINK/FUSE_RMDIROvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_GETATTROvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Open()OvmfPkg/VirtioFsDxe: erase the dir. entry in
EFI_FILE_PROTOCOL.Delete()
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_STATFSOvmfPkg/VirtioFsDxe: add helper for formatting UEFI basenames OvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.GetInfo()OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.GetPosition,
.SetPosition
OvmfPkg/VirtioFsDxe: add a shared wrapper forFUSE_READ/
FUSE_READDIRPLUS
OvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Read()for regular
files
OvmfPkg/VirtioFsDxe: convert FUSE dirent filename toEFI_FILE_INFOOvmfPkg/VirtioFsDxe: addEFI_FILE_INFOcache fields toVIRTIO_FS_FILEOvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Read()for
directories
OvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Flush()OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_WRITEOvmfPkg/VirtioFsDxe: implementEFI_FILE_PROTOCOL.Write()OvmfPkg/VirtioFsDxe: handle the volume label in
EFI_FILE_PROTOCOL.SetInfo
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_RENAME2OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination
pathQuoted 9 lines
OvmfPkg/VirtioFsDxe: handle file rename/move in
EFI_FILE_PROTOCOL.SetInfo
OvmfPkg/VirtioFsDxe: implement the wrapper function forFUSE_SETATTROvmfPkg/VirtioFsDxe: add helper for determining file size update OvmfPkg/VirtioFsDxe: add helper for determining access time updates OvmfPkg/VirtioFsDxe: add helper for determining file mode bits update OvmfPkg/VirtioFsDxe: handle attribute updates in
EFI_FILE_PROTOCOL.SetInfoThis looks carefully crafted, and modulo my two questions, I won't be able to spend more time on this than I have going through these patches today.
Quoted 5 lines
So please feel free to merge this whenever you feel it's ready.
For the series,
Acked-by Ard Biesheuvel <[email protected]>Thank you.
Before I posted the series, I tested it very thoroughly, including build tests (at every patch, and a Local CI run as well). I created a test plan and went through it meticulously (it took hours).
The only thing I couldn't test that way was (obviously) building on Windows. So clearly now that I've tried merging the series at
<https://github.com/tianocore/edk2/pull/1248>, that's what fails. Because, this is the first time that EmbeddedPkg/TimeBaseLib is seen by the Visual Studio compiler, and Visual Studio complains:Quoted 6 lines
ERROR - Compiler #2220 from
d:\a\1\s\EmbeddedPkg\Library\TimeBaseLib\TimeBaseLib.c(111): the
following warning is treated as an error
WARNING - Compiler #4244 from
d:\a\1\s\EmbeddedPkg\Library\TimeBaseLib\TimeBaseLib.c(111): '=':
conversion from 'UINTN' to 'UINT32', possible loss of dataIt happens to be correct:
99 /** 100 Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) 101 **/ 102 UINT32 103 EFIAPI 104 EfiTimeToEpoch ( 105 IN EFI_TIME *Time 106 ) 107 { 108 UINT32 EpochDays; // Number of days elapsed since EPOCH_JULIAN_DAY 109 UINT32 EpochSeconds; 110 111 EpochDays = EfiGetEpochDays (Time); 112 113 EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second; 114 115 return EpochSeconds; 116 }This was discussed on the list earlier, when the function was duplicated for the HTTP dynamic command:
- https://edk2.groups.io/g/devel/message/64933
- https://edk2.groups.io/g/devel/message/65186Compare
EfiTimeToEpoch()in "ShellPkg/DynamicCommand/HttpDynamicCommand/Http.c".430 STATIC 431 UINTN 432 EFIAPI 433 EfiTimeToEpoch ( 434 IN EFI_TIME *Time 435 ) 436 { 437 // 438 // Number of days elapsed since EPOCH_JULIAN_DAY. 439 // 440 UINTN EpochDays; 441 UINTN EpochSeconds; 442 443 EpochDays = EfiGetEpochDays (Time); 444 445 EpochSeconds = (EpochDays * SEC_PER_DAY) + 446 ((UINTN)Time->Hour * SEC_PER_HOUR) + 447 (Time->Minute * SEC_PER_MIN) + Time->Second; 448 449 return EpochSeconds; 450 }So, in order to merge this series, I'll first have to fix
EfiTimeToEpoch()in EmbeddedPkg :(
Quoted 9 lines
I wish the fixed version in "
ShellPkg/DynamicCommand/HttpDynamicCommand/Http.c" had been contributed back to EmbeddedPkg.Anyway, that is for 2021.
Thank you for checking the series so quickly; I know it's a lot! Laszlo
Thanks for clearing up the outstanding questions.
For the EmbeddedPkg change from UINT32 to UINTN
although I suppose you will have to preserve the prototype, so adding a (UINT32) cast to line 111 is probably the best approach here.
Signature · 1 line
Ard.
Quoted 67 lines · Ard Biesheuvel
Quoted 65 lines · Laszlo Ersek
The only thing I couldn't test that way was (obviously) building on Windows. So clearly now that I've tried merging the series at
<https://github.com/tianocore/edk2/pull/1248>, that's what fails. Because, this is the first time that EmbeddedPkg/TimeBaseLib is seen by the Visual Studio compiler, and Visual Studio complains:Quoted 6 lines
ERROR - Compiler #2220 from
d:\a\1\s\EmbeddedPkg\Library\TimeBaseLib\TimeBaseLib.c(111): the
following warning is treated as an error
WARNING - Compiler #4244 from
d:\a\1\s\EmbeddedPkg\Library\TimeBaseLib\TimeBaseLib.c(111): '=':
conversion from 'UINTN' to 'UINT32', possible loss of dataIt happens to be correct:
99 /** 100 Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) 101 **/ 102 UINT32 103 EFIAPI 104 EfiTimeToEpoch ( 105 IN EFI_TIME *Time 106 ) 107 { 108 UINT32 EpochDays; // Number of days elapsed since EPOCH_JULIAN_DAY 109 UINT32 EpochSeconds; 110 111 EpochDays = EfiGetEpochDays (Time); 112 113 EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second; 114 115 return EpochSeconds; 116 }This was discussed on the list earlier, when the function was duplicated for the HTTP dynamic command:
- https://edk2.groups.io/g/devel/message/64933
- https://edk2.groups.io/g/devel/message/65186Compare
EfiTimeToEpoch()in "ShellPkg/DynamicCommand/HttpDynamicCommand/Http.c".430 STATIC 431 UINTN 432 EFIAPI 433 EfiTimeToEpoch ( 434 IN EFI_TIME *Time 435 ) 436 { 437 // 438 // Number of days elapsed since EPOCH_JULIAN_DAY. 439 // 440 UINTN EpochDays; 441 UINTN EpochSeconds; 442 443 EpochDays = EfiGetEpochDays (Time); 444 445 EpochSeconds = (EpochDays * SEC_PER_DAY) + 446 ((UINTN)Time->Hour * SEC_PER_HOUR) + 447 (Time->Minute * SEC_PER_MIN) + Time->Second; 448 449 return EpochSeconds; 450 }
Quoted 8 lines
Quoted 8 lines
So, in order to merge this series, I'll first have to fix
EfiTimeToEpoch()in EmbeddedPkg :(I wish the fixed version in "
ShellPkg/DynamicCommand/HttpDynamicCommand/Http.c" had been contributed back to EmbeddedPkg.Anyway, that is for 2021.
(given the fantastic opportunities provided by the COVID-19 pandemic, to catch up with family and friends around Christmas /s, I might as well treat the discussion of this patch series during my PTO as something welcome that takes my mind off of how much I miss the people I can't meet this year)
Quoted 8 lines
Thanks for clearing up the outstanding questions.
For the EmbeddedPkg change from UINT32 to UINTN
Acked-by Ard Biesheuvel <[email protected]>although I suppose you will have to preserve the prototype, so adding a (UINT32) cast to line 111 is probably the best approach here.
I ended up installing a brand new Windows 10 + VS2019 virtual machine, as I got fed up with the nasty surprises in the PRs (and I refuse to publish my work-in-progress branch just for the sake of setting off CI on it).
Two consequences:
(1) I'll squash the following trivial updates into two of the patches, for my next merge request attempt:
5: bb254f89067a ! 7: 17a76bbec317 OvmfPkg/VirtioFsDxe: add a scatter-gather list data type
@@ -20,6 +20,8 @@
Message-Id: <[email protected]>
+ [[email protected]: suppress useless VS2019 warning about signed/unsigned
+ comparison in VirtioFsSgListsValidate()]
diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
@@ -213,7 +215,7 @@
+ // can be added to the virtio queue, after the other descriptors added
+ // previously.
+ //
-+ if (SgList->NumVec > MAX_UINT16 - DescriptorsNeeded ||
++ if (SgList->NumVec > (UINTN)(MAX_UINT16 - DescriptorsNeeded) ||
+ DescriptorsNeeded + SgList->NumVec > VirtioFs->QueueSize) {
+ return EFI_UNSUPPORTED;
+ }
and
46: 4f42ecc2d9bb ! 48: b807d3c0b54b OvmfPkg/VirtioFsDxe: add helper for determining access time updates
@@ -12,6 +12,8 @@
Message-Id: <[email protected]>
+ [[email protected]: suppress bogus VS2019 warning about lack of
+ initialization for ZeroTime]
diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
@@ -92,7 +94,7 @@
+ EFI_TIME *Time[3];
+ EFI_TIME *NewTime[ARRAY_SIZE (Time)];
+ UINTN Idx;
-+ STATIC CONST EFI_TIME ZeroTime;
++ STATIC CONST EFI_TIME ZeroTime = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ BOOLEAN Change[ARRAY_SIZE (Time)];
+ UINT64 Seconds[ARRAY_SIZE (Time)];
+
(2) I've written three patches in total for fixing EfiTimeToEpoch(), including the prototype:
(2a) edk2-platforms:
1 Silicon/Marvell/RealTimeClockLib: make EpochSeconds, WakeupSeconds UINTN
Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)(other RealTimeClockLib instances / EfiTimeToEpoch() callers in edk2-platforms need no updates; furthermore, edk2-non-osi contains no EfiTimeToEpoch() calls at all)
(2b) edk2:
1 ArmPlatformPkg/PL031RealTimeClockLib: cast EfiTimeToEpoch() val. to UINT32
ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)2 EmbeddedPkg/TimeBaseLib: remove useless truncation to 32-bit
EmbeddedPkg/Include/Library/TimeBaseLib.h | 2 +-
EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)If you're reading this before 2021, please let me know if you'd tolerate receiving these patches for approval still in 2020. (The edk2-platforms patch theoretically belongs to Leif and Marcin, but if Leif has stopped consuming work email (which we all should have by now, I guess...), then I believe you could ACK that patch in Leif's stead.)
Thanks,
Laszlo
Quoted 171 lines · Laszlo Ersek
Quoted 67 lines · Ard Biesheuvel
Quoted 65 lines · Laszlo Ersek
The only thing I couldn't test that way was (obviously) building on Windows. So clearly now that I've tried merging the series at
<https://github.com/tianocore/edk2/pull/1248>, that's what fails. Because, this is the first time that EmbeddedPkg/TimeBaseLib is seen by the Visual Studio compiler, and Visual Studio complains:Quoted 6 lines
ERROR - Compiler #2220 from
d:\a\1\s\EmbeddedPkg\Library\TimeBaseLib\TimeBaseLib.c(111): the
following warning is treated as an error
WARNING - Compiler #4244 from
d:\a\1\s\EmbeddedPkg\Library\TimeBaseLib\TimeBaseLib.c(111): '=':
conversion from 'UINTN' to 'UINT32', possible loss of dataIt happens to be correct:
99 /** 100 Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) 101 **/ 102 UINT32 103 EFIAPI 104 EfiTimeToEpoch ( 105 IN EFI_TIME *Time 106 ) 107 { 108 UINT32 EpochDays; // Number of days elapsed since EPOCH_JULIAN_DAY 109 UINT32 EpochSeconds; 110 111 EpochDays = EfiGetEpochDays (Time); 112 113 EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second; 114 115 return EpochSeconds; 116 }This was discussed on the list earlier, when the function was duplicated for the HTTP dynamic command:
- https://edk2.groups.io/g/devel/message/64933
- https://edk2.groups.io/g/devel/message/65186Compare
EfiTimeToEpoch()in "ShellPkg/DynamicCommand/HttpDynamicCommand/Http.c".430 STATIC 431 UINTN 432 EFIAPI 433 EfiTimeToEpoch ( 434 IN EFI_TIME *Time 435 ) 436 { 437 // 438 // Number of days elapsed since EPOCH_JULIAN_DAY. 439 // 440 UINTN EpochDays; 441 UINTN EpochSeconds; 442 443 EpochDays = EfiGetEpochDays (Time); 444 445 EpochSeconds = (EpochDays * SEC_PER_DAY) + 446 ((UINTN)Time->Hour * SEC_PER_HOUR) + 447 (Time->Minute * SEC_PER_MIN) + Time->Second; 448 449 return EpochSeconds; 450 }Quoted 8 lines
Quoted 8 lines
So, in order to merge this series, I'll first have to fix
EfiTimeToEpoch()in EmbeddedPkg :(I wish the fixed version in "
ShellPkg/DynamicCommand/HttpDynamicCommand/Http.c" had been contributed back to EmbeddedPkg.Anyway, that is for 2021.
(given the fantastic opportunities provided by the COVID-19 pandemic, to catch up with family and friends around Christmas /s, I might as well treat the discussion of this patch series during my PTO as something welcome that takes my mind off of how much I miss the people I can't meet this year)
Quoted 8 lines
Thanks for clearing up the outstanding questions.
For the EmbeddedPkg change from UINT32 to UINTN
Acked-by Ard Biesheuvel <[email protected]>although I suppose you will have to preserve the prototype, so adding a (UINT32) cast to line 111 is probably the best approach here.
I ended up installing a brand new Windows 10 + VS2019 virtual machine, as I got fed up with the nasty surprises in the PRs (and I refuse to publish my work-in-progress branch just for the sake of setting off CI on it).
Two consequences:
(1) I'll squash the following trivial updates into two of the patches, for my next merge request attempt:
5:
bb254f89067a! 7:17a76bbec317OvmfPkg/VirtioFsDxe: add a scatter-gather list data type
@@ -20,6 +20,8 @@Signed-off-by Laszlo Ersek <[email protected]>Message-Id: <[email protected]>
Acked-by Ard Biesheuvel <[email protected]>+ [[email protected]: suppress useless VS2019 warning about signed/unsigned
+ comparison inVirtioFsSgListsValidate()]diff --git
a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.hb/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h---a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
@@ -213,7 +215,7 @@
+ // can be added to the virtio queue, after the other descriptors added
+ // previously.
+ //
-+ if (SgList->NumVec>MAX_UINT16- DescriptorsNeeded ||
++ if (SgList->NumVec> (UINTN)(MAX_UINT16 - DescriptorsNeeded) ||
+ DescriptorsNeeded +SgList->NumVec>VirtioFs->QueueSize) {
+ returnEFI_UNSUPPORTED;
+ }and
46:
4f42ecc2d9bb! 48:b807d3c0b54bOvmfPkg/VirtioFsDxe: add helper for determining access time updates
@@ -12,6 +12,8 @@Signed-off-by Laszlo Ersek <[email protected]>Message-Id: <[email protected]>
Acked-by Ard Biesheuvel <[email protected]>+ [[email protected]: suppress bogus VS2019 warning about lack of
+ initialization for ZeroTime]diff --git
a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.hb/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h---a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
@@ -92,7 +94,7 @@
+EFI_TIME*Time[3];
+EFI_TIME*NewTime[ARRAY_SIZE (Time)];
+ UINTN Idx;
-+ STATIC CONSTEFI_TIMEZeroTime;
++ STATIC CONSTEFI_TIMEZeroTime = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ BOOLEAN Change[ARRAY_SIZE (Time)];
+ UINT64 Seconds[ARRAY_SIZE (Time)];
+(2) I've written three patches in total for fixing
EfiTimeToEpoch(), including the prototype:(2a) edk2-platforms:
1 Silicon/Marvell/RealTimeClockLib: make EpochSeconds, WakeupSeconds UINTN
Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)(other RealTimeClockLib instances /
EfiTimeToEpoch()callers in edk2-platforms need no updates; furthermore, edk2-non-osi contains noEfiTimeToEpoch()calls at all)(2b) edk2:
1 ArmPlatformPkg/PL031RealTimeClockLib: cast
EfiTimeToEpoch()val. to UINT32ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)2 EmbeddedPkg/TimeBaseLib: remove useless truncation to 32-bit
EmbeddedPkg/Include/Library/TimeBaseLib.h | 2 +- EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 6 lines
If you're reading this before 2021, please let me know if you'd tolerate receiving these patches for approval still in 2020. (The edk2-platforms patch theoretically belongs to Leif and Marcin, but if Leif has stopped consuming work email (which we all should have by now, I guess...), then I believe you could ACK that patch in Leif's stead.)
No problem.
Signature · 1 line
Ard.
Quoted 172 lines · Ard Biesheuvel
Quoted 171 lines · Laszlo Ersek
Quoted 67 lines · Ard Biesheuvel
Quoted 65 lines · Laszlo Ersek
The only thing I couldn't test that way was (obviously) building on Windows. So clearly now that I've tried merging the series at
<https://github.com/tianocore/edk2/pull/1248>, that's what fails. Because, this is the first time that EmbeddedPkg/TimeBaseLib is seen by the Visual Studio compiler, and Visual Studio complains:Quoted 6 lines
ERROR - Compiler #2220 from
d:\a\1\s\EmbeddedPkg\Library\TimeBaseLib\TimeBaseLib.c(111): the
following warning is treated as an error
WARNING - Compiler #4244 from
d:\a\1\s\EmbeddedPkg\Library\TimeBaseLib\TimeBaseLib.c(111): '=':
conversion from 'UINTN' to 'UINT32', possible loss of dataIt happens to be correct:
99 /** 100 Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) 101 **/ 102 UINT32 103 EFIAPI 104 EfiTimeToEpoch ( 105 IN EFI_TIME *Time 106 ) 107 { 108 UINT32 EpochDays; // Number of days elapsed since EPOCH_JULIAN_DAY 109 UINT32 EpochSeconds; 110 111 EpochDays = EfiGetEpochDays (Time); 112 113 EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second; 114 115 return EpochSeconds; 116 }This was discussed on the list earlier, when the function was duplicated for the HTTP dynamic command:
- https://edk2.groups.io/g/devel/message/64933
- https://edk2.groups.io/g/devel/message/65186Compare
EfiTimeToEpoch()in "ShellPkg/DynamicCommand/HttpDynamicCommand/Http.c".430 STATIC 431 UINTN 432 EFIAPI 433 EfiTimeToEpoch ( 434 IN EFI_TIME *Time 435 ) 436 { 437 // 438 // Number of days elapsed since EPOCH_JULIAN_DAY. 439 // 440 UINTN EpochDays; 441 UINTN EpochSeconds; 442 443 EpochDays = EfiGetEpochDays (Time); 444 445 EpochSeconds = (EpochDays * SEC_PER_DAY) + 446 ((UINTN)Time->Hour * SEC_PER_HOUR) + 447 (Time->Minute * SEC_PER_MIN) + Time->Second; 448 449 return EpochSeconds; 450 }Quoted 8 lines
Quoted 8 lines
So, in order to merge this series, I'll first have to fix
EfiTimeToEpoch()in EmbeddedPkg :(I wish the fixed version in "
ShellPkg/DynamicCommand/HttpDynamicCommand/Http.c" had been contributed back to EmbeddedPkg.Anyway, that is for 2021.
(given the fantastic opportunities provided by the COVID-19 pandemic, to catch up with family and friends around Christmas /s, I might as well treat the discussion of this patch series during my PTO as something welcome that takes my mind off of how much I miss the people I can't meet this year)
Quoted 8 lines
Thanks for clearing up the outstanding questions.
For the EmbeddedPkg change from UINT32 to UINTN
Acked-by Ard Biesheuvel <[email protected]>although I suppose you will have to preserve the prototype, so adding a (UINT32) cast to line 111 is probably the best approach here.
I ended up installing a brand new Windows 10 + VS2019 virtual machine, as I got fed up with the nasty surprises in the PRs (and I refuse to publish my work-in-progress branch just for the sake of setting off CI on it).
Two consequences:
(1) I'll squash the following trivial updates into two of the patches, for my next merge request attempt:
5:
bb254f89067a! 7:17a76bbec317OvmfPkg/VirtioFsDxe: add a scatter-gather list data type
@@ -20,6 +20,8 @@Signed-off-by Laszlo Ersek <[email protected]>Message-Id: <[email protected]>
Acked-by Ard Biesheuvel <[email protected]>+ [[email protected]: suppress useless VS2019 warning about signed/unsigned
+ comparison inVirtioFsSgListsValidate()]diff --git
a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.hb/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h---a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
@@ -213,7 +215,7 @@
+ // can be added to the virtio queue, after the other descriptors added
+ // previously.
+ //
-+ if (SgList->NumVec>MAX_UINT16- DescriptorsNeeded ||
++ if (SgList->NumVec> (UINTN)(MAX_UINT16 - DescriptorsNeeded) ||
+ DescriptorsNeeded +SgList->NumVec>VirtioFs->QueueSize) {
+ returnEFI_UNSUPPORTED;
+ }and
46:
4f42ecc2d9bb! 48:b807d3c0b54bOvmfPkg/VirtioFsDxe: add helper for determining access time updates
@@ -12,6 +12,8 @@Signed-off-by Laszlo Ersek <[email protected]>Message-Id: <[email protected]>
Acked-by Ard Biesheuvel <[email protected]>+ [[email protected]: suppress bogus VS2019 warning about lack of
+ initialization for ZeroTime]diff --git
a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.hb/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h---a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
@@ -92,7 +94,7 @@
+EFI_TIME*Time[3];
+EFI_TIME*NewTime[ARRAY_SIZE (Time)];
+ UINTN Idx;
-+ STATIC CONSTEFI_TIMEZeroTime;
++ STATIC CONSTEFI_TIMEZeroTime = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ BOOLEAN Change[ARRAY_SIZE (Time)];
+ UINT64 Seconds[ARRAY_SIZE (Time)];
+(2) I've written three patches in total for fixing
EfiTimeToEpoch(), including the prototype:(2a) edk2-platforms:
1 Silicon/Marvell/RealTimeClockLib: make EpochSeconds, WakeupSeconds UINTN
Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)(other RealTimeClockLib instances /
EfiTimeToEpoch()callers in edk2-platforms need no updates; furthermore, edk2-non-osi contains noEfiTimeToEpoch()calls at all)(2b) edk2:
1 ArmPlatformPkg/PL031RealTimeClockLib: cast
EfiTimeToEpoch()val. to UINT32ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)2 EmbeddedPkg/TimeBaseLib: remove useless truncation to 32-bit
EmbeddedPkg/Include/Library/TimeBaseLib.h | 2 +- EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 9 lines
Quoted 6 lines
If you're reading this before 2021, please let me know if you'd tolerate receiving these patches for approval still in 2020. (The edk2-platforms patch theoretically belongs to Leif and Marcin, but if Leif has stopped consuming work email (which we all should have by now, I guess...), then I believe you could ACK that patch in Leif's stead.)
No problem.
Merged as commit range c06635ea3f4b..35ed29f207fd, via
<https://github.com/tianocore/edk2/pull/1256>.
I've also added <https://bugzilla.tianocore.org/show_bug.cgi?id=3097> to
<https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Release-Planning#proposed-features>.
Thank you, Ard!
Laszlo