From nobody Mon Feb 9 18:43:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69052+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69052+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608157901; cv=none; d=zohomail.com; s=zohoarc; b=MTCRoxM/v1VzV/QE1OzvoXOs2hom7FevqX6XBQAjCmG1G3kJUzRCkGbe/D5sYRLPbf6My/LJekISHqukXlURQo5LW/q7TCZlrqJ8cL0GNi+C/yL35f7kNzOe5zDZbflENoZztNMFfik4KDCRQf9I/F6O1F8P1LvBwZKqB9Orn7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608157901; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ejEI88Iw8D4VgI/a4h+Q5wGjbYrgbL22p0p0JfEe8rQ=; b=lo2BjyMSGPVKL4/jxL/aYhp2i1ke9blDG3FpG3ORpCYiT/0uo1hR+dWL/WVUys67YE5cKF9cXph4t6Cj+ulst70oNiYTSviphp5LepJaJn9N/ANAu2qPbcOKne3hfD74cD/pAima3WHHtyAHMc+fUI/wG9GR2Dtqda8IBlt3wOE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69052+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608157901671647.2699616418305; Wed, 16 Dec 2020 14:31:41 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1zqqYY1788612x9br6wEqeDW; Wed, 16 Dec 2020 14:31:41 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web12.4883.1608157899824662842 for ; Wed, 16 Dec 2020 14:31:40 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-520-uOoMrRvrMPC2yu5bpKVxNg-1; Wed, 16 Dec 2020 17:31:35 -0500 X-MC-Unique: uOoMrRvrMPC2yu5bpKVxNg-1 X-Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CFD52800D62; Wed, 16 Dec 2020 22:31:33 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B7C960C15; Wed, 16 Dec 2020 22:31:28 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 38/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_WRITE Date: Wed, 16 Dec 2020 22:11:15 +0100 Message-Id: <20201216211125.19496-39-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: Nvdj9Eu3hI7xxzYSmJ6Opg0Ax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608157901; bh=ejEI88Iw8D4VgI/a4h+Q5wGjbYrgbL22p0p0JfEe8rQ=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=LrKxIxwvtQ7Z0O4kKy+MgsqjacwV/SNhqum4JZWaccMAoBlcUNIa1o+GsmXgo01YDDW PbMnaHIkUINQ631cQQeyLzu0ZN+cibZK7PuJhwhN8gjTu/Oue2/8TQTtAsIdc4EVho8l/ 2VBZBEmJupmOpzXYXZyE6prW7LGHlgUPJ50= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add 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 Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek --- 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(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index fa8c40019f4e..0b7b3ff80edd 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -148,16 +148,17 @@ typedef enum { VirtioFsFuseOpLookup =3D 1, VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpGetAttr =3D 3, VirtioFsFuseOpMkDir =3D 9, VirtioFsFuseOpUnlink =3D 10, VirtioFsFuseOpRmDir =3D 11, VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRead =3D 15, + VirtioFsFuseOpWrite =3D 16, VirtioFsFuseOpStatFs =3D 17, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, @@ -277,16 +278,34 @@ typedef struct { UINT64 Offset; UINT32 Size; UINT32 ReadFlags; UINT64 LockOwner; UINT32 Flags; UINT32 Padding; } VIRTIO_FS_FUSE_READ_REQUEST; =20 +// +// 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; diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 39c77c7c4ee9..2c145da5f5ae 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -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 diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index a704acdd520e..132a63400527 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -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; =20 #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); =20 @@ -329,16 +330,26 @@ VirtioFsFuseReadFileOrDir ( IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir, IN UINT64 Offset, IN OUT UINT32 *Size, OUT VOID *Data ); =20 +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 ); =20 EFI_STATUS diff --git a/OvmfPkg/VirtioFsDxe/FuseInit.c b/OvmfPkg/VirtioFsDxe/FuseInit.c index 7aa6ee75caf6..431842804912 100644 --- a/OvmfPkg/VirtioFsDxe/FuseInit.c +++ b/OvmfPkg/VirtioFsDxe/FuseInit.c @@ -17,17 +17,20 @@ session is started by sending a FUSE_INIT request as defined by the FUSE protocol on one request virtqueue." =20 The function may only be called after VirtioFsInit() returns successfull= y and before VirtioFsUninit() is called. =20 @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_I= NIT 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_I= NIT + response is saved in "VirtioFs->MaxWrite", on + output. =20 @retval EFI_SUCCESS The FUSE session has been started. =20 @retval EFI_UNSUPPORTED FUSE interface version or feature negotiation failed. =20 @return The "errno" value mapped to an EFI_STATUS code,= if the Virtio Filesystem device explicitly reporte= d an @@ -121,14 +124,19 @@ VirtioFsFuseInitSession ( return Status; } =20 // // Check FUSE interface version / feature compatibility. // if (InitResp.Major < InitReq.Major || (InitResp.Major =3D=3D InitReq.Major && InitResp.Minor < InitReq.Min= or) || - (InitResp.Flags & VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS) =3D=3D 0= ) { + (InitResp.Flags & VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS) =3D=3D 0= || + InitResp.MaxWrite < SIZE_4KB) { return EFI_UNSUPPORTED; } =20 + // + // Save the maximum write buffer size for FUSE_WRITE requests. + // + VirtioFs->MaxWrite =3D InitResp.MaxWrite; return EFI_SUCCESS; } diff --git a/OvmfPkg/VirtioFsDxe/FuseWrite.c b/OvmfPkg/VirtioFsDxe/FuseWrit= e.c new file mode 100644 index 000000000000..cc552bd667ba --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseWrite.c @@ -0,0 +1,155 @@ +/** @file + FUSE_WRITE wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Write a chunk to a regular file, by sending the FUSE_WRITE request to the + Virtio Filesystem device. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_W= RITE + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] NodeId The inode number of the regular file to write t= o. + + @param[in] FuseHandle The open handle to the regular file to write to. + + @param[in] Offset The absolute file position at which to start + writing. + + @param[in,out] Size On input, the number of bytes to write. On + successful return, the number of bytes actually + written, which may be smaller than the value on + input. + + @param[in] Data The buffer to write to the regular file. + + @retval EFI_SUCCESS Write successful. The caller is responsible= for + checking Size to learn the actual byte count + transferred. + + @retval EFI_BAD_BUFFER_SIZE On input, Size is larger than + "VirtioFs->MaxWrite". + + @return The "errno" value mapped to an EFI_STATUS c= ode, + if the Virtio Filesystem device explicitly + reported an error. + + @return Error codes propagated from + VirtioFsSgListsValidate(), + VirtioFsFuseNewRequest(), + VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseWrite ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN UINT64 Offset, + IN OUT UINT32 *Size, + IN VOID *Data + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_WRITE_REQUEST WriteReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[3]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_WRITE_RESPONSE WriteResp; + VIRTIO_FS_IO_VECTOR RespIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Honor the write buffer size limit of the Virtio Filesystem device. + // + if (*Size > VirtioFs->MaxWrite) { + return EFI_BAD_BUFFER_SIZE; + } + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &WriteReq; + ReqIoVec[1].Size =3D sizeof WriteReq; + ReqIoVec[2].Buffer =3D Data; + ReqIoVec[2].Size =3D *Size; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &WriteResp; + RespIoVec[1].Size =3D sizeof WriteResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpWrite, NodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_WRITE-specific fields. + // + WriteReq.FileHandle =3D FuseHandle; + WriteReq.Offset =3D Offset; + WriteReq.Size =3D *Size; + WriteReq.WriteFlags =3D 0; + WriteReq.LockOwner =3D 0; + WriteReq.Flags =3D 0; + WriteReq.Padding =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu FuseHandle=3D%= Lu " + "Offset=3D0x%Lx Size=3D0x%x Data@%p Errno=3D%d\n", __FUNCTION__, + VirtioFs->Label, NodeId, FuseHandle, Offset, *Size, Data, + CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; + } + + // + // Report the actual transfer size. + // + *Size =3D WriteResp.Size; + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69052): https://edk2.groups.io/g/devel/message/69052 Mute This Topic: https://groups.io/mt/79024273/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-