Skip to contentSkip to conversation

virtio-fs: add virtio file system device

PATCH Superseded Stefan Hajnoczi 2 participants 9 messages Feb 13, 2019 – Feb 18, 2019 3 messages not in the archive

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover virtio-fs: add virtio file system device

v2:
* Clean up core virtio file system device spec
* Add DAX window

These patches add the virtio file system device, which is based on Linux FUSE but includes the DAX window extension. Similar to virtio-scsi, which transports SCSI commands, virtio-fs transports FUSE requests and the protocol documentation is not duplicated here.

The DAX window allows file contents to be accessed directly from shared memory. This eliminates copying of data, reduces the number of vmexits, and reduces the guest's memory footprint. It also allows coherent mmap MAP_SHARED semantics between guests on the same host.

Michael Tsirkin has expressed an interest in security and live migration. I plan to add these sections in the next revision.

Please let me know which areas should be expanded or are missing.

Stefan Hajnoczi (2):
content: add virtio file system device
virtio-fs: add DAX window

 content.tex      |   3 +
 introduction.tex |   3 +
 virtio-fs.tex    | 223 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 229 insertions(+)
 create mode 100644 virtio-fs.tex
Signature · 6 lines
2.20.1


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
#1 lore raw

PATCH v2 1/2 content: add virtio file system device

The virtio file system device transports Linux FUSE requests between a FUSE daemon running on the host and the FUSE driver inside the guest.

The actual FUSE request definitions are not duplicated in the virtio specification, similar to how virtio-scsi does not document SCSI command details. FUSE request definitions are available here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/fuse.h

This patch documents the core virtio file system device, which is functional but lacks the DAX feature introduced in the next patch.

---
 content.tex      |   3 +
 introduction.tex |   3 +
 virtio-fs.tex    | 198 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+)
 create mode 100644 virtio-fs.tex
content.tex +3 -0
index 836ee52..ac41fdb 100644
@@ -2634,6 +2634,8 @@ Device ID  &  Virtio Device    \\
 \hline
 24         &   Memory device \\
 \hline
+26         &   file system device \\
+\hline
 \end{tabular}
 
 Some of the devices above are unspecified by this document,
@@ -5559,6 +5561,7 @@ descriptor for the \field{sense_len}, \field{residual},
 \input{virtio-input.tex}
 \input{virtio-crypto.tex}
 \input{virtio-vsock.tex}
+\input{virtio-fs.tex}
 
 \chapter{Reserved Feature Bits}\label{sec:Reserved Feature Bits}
 
introduction.tex +3 -0
index a4ac01d..6eeda5d 100644
@@ -60,6 +60,9 @@ Levels'', BCP 14, RFC 2119, March 1997. \newline\url{http://www.ietf.org/rfc/rfc
 	\phantomsection\label{intro:SCSI MMC}\textbf{[SCSI MMC]} &
         SCSI Multimedia Commands,
         \newline\url{http://www.t10.org/cgi-bin/ac.pl?t=f&f=mmc6r00.pdf}\\
+	\phantomsection\label{intro:FUSE}\textbf{[FUSE]} &
+	Linux FUSE interface,
+	\newline\url{https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/fuse.h}\\
 
 \end{longtable}
 
virtio-fs.tex new file +198 -0

198 lines not on this page · raw message

Signature · 6 lines
2.20.1


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
#2 lore raw

Re: [virtio-dev] [PATCH v2 1/2] content: add virtio file system device

Quoted 9 lines · Stefan Hajnoczi
virtio-fs.tex new file +9 -0
+Notifications are different from normal requests because they only contain
+device writable fields.  The driver sends notification replies on one of the
+request queues.  The format of notification requests is as follows:
+
+\begin{lstlisting}
+struct virtio_fs_notification_req {
+        // Device-writable part
+        struct fuse_out_header out;
+        u8 dataout[];

virtio-fs.tex line 189

Quoted 10 lines
virtio-fs.tex new file +10 -0
+};
+\end{lstlisting}
+
+\field{out} is the completion header common to all types of FUSE requests.  The
+\field{out.unique} field is 0 and the \field{out.error} field contains a
+FUSE_NOTIFY_* code.
+
+\field{dataout} consists of request-specific data, if any.  This is identical
+to the data written to the /dev/fuse device by a FUSE daemon.
+

What happens if notifications are lost because no request was there? virtio-scsi has a flag for that, would it make sense to add it here too?

Paolo

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#3 lore raw

Re: [virtio-dev] [PATCH v2 1/2] content: add virtio file system device

Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Stefan Hajnoczi
virtio-fs.tex new file +14 -0
+Notifications are different from normal requests because they only contain
+device writable fields.  The driver sends notification replies on one of the
+request queues.  The format of notification requests is as follows:
+
+\begin{lstlisting}
+struct virtio_fs_notification_req {
+        // Device-writable part
+        struct fuse_out_header out;
+        u8 dataout[];
+};
+\end{lstlisting}
+
+\field{out} is the completion header common to all types of FUSE requests.  The
+\field{out.unique} field is 0 and the \field{out.error} field contains a
Quoted 8 lines

virtio-fs.tex line 189

Quoted 5 lines
virtio-fs.tex new file +5 -0
+FUSE_NOTIFY_* code.
+
+\field{dataout} consists of request-specific data, if any.  This is identical
+to the data written to the /dev/fuse device by a FUSE daemon.
+

What happens if notifications are lost because no request was there? virtio-scsi has a flag for that, would it make sense to add it here too?

The FUSE protocol assumes notification delivery is reliable. Some notifications can be dropped with no or little impact on functionality, but others cannot because it would cause a hung operation.

Therefore the device must hold notifications until the driver makes buffers available. The question becomes what happens when the device runs out of space to hold notifications. At this point the device must be reset because no further progress is possible.

(In our current implementation notifications aren't used at all, but the virtio-fs spec should allow for it so that the full FUSE protocol is available for future applications.)

Miklos: What do you think from the FUSE protocol point of view?

Stefan

A message that is not in the archive (sent off-list or not yet received): CAOssrKdfYic5bSz-GkfZUbd=OrADwrVXPRTQiVgOFbzpiVwNZg@mail.gmail.com

#5 lore raw

Re: [virtio-dev] [PATCH v2 1/2] content: add virtio file system device

Quoted 50 lines · Miklos Szeredi
Quoted 35 lines · Stefan Hajnoczi
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Stefan Hajnoczi
virtio-fs.tex new file +14 -0
+Notifications are different from normal requests because they only contain
+device writable fields.  The driver sends notification replies on one of the
+request queues.  The format of notification requests is as follows:
+
+\begin{lstlisting}
+struct virtio_fs_notification_req {
+        // Device-writable part
+        struct fuse_out_header out;
+        u8 dataout[];
+};
+\end{lstlisting}
+
+\field{out} is the completion header common to all types of FUSE requests.  The
+\field{out.unique} field is 0 and the \field{out.error} field contains a
Quoted 8 lines

virtio-fs.tex line 189

Quoted 5 lines
virtio-fs.tex new file +5 -0
+FUSE_NOTIFY_* code.
+
+\field{dataout} consists of request-specific data, if any.  This is identical
+to the data written to the /dev/fuse device by a FUSE daemon.
+

What happens if notifications are lost because no request was there? virtio-scsi has a flag for that, would it make sense to add it here too?

The FUSE protocol assumes notification delivery is reliable. Some notifications can be dropped with no or little impact on functionality, but others cannot because it would cause a hung operation.

Therefore the device must hold notifications until the driver makes buffers available. The question becomes what happens when the device runs out of space to hold notifications. At this point the device must be reset because no further progress is possible.

Quoted 5 lines

(In our current implementation notifications aren't used at all, but the virtio-fs spec should allow for it so that the full FUSE protocol is available for future applications.)

Miklos: What do you think from the FUSE protocol point of view?

I think notifications would be limited in functionality in the virtio case. E.g. FUSE_NOTIFY_INVAL_INODE could be used if the server detects that cached attributes have become invalid. If this is a best effort thing (doesn't block other clients) then it's okay. But if it's for implementing strong coherency, then it doesn't work that well, since the broken client can block other clients from making progress.

Quoted 2 lines

So I'm not sure. Probably easier to leave notifications out of the implementation and the spec, until an actual use case arises.

I'd still like to discuss the options because it would be a real problem to spec the device without notifications and then find out the design cannot be extended when we need them.

When the device runs out of space to queue notifications for a slow client, that client must be kicked out so that others can continue. This seems like the most robust way to keep the file system available. Only the client that couldn't keep up is hurt.

In our implementation each virtiofsd has a single client, so I'm not sure the denial-of-service you described can occur (is that something that involves the ireg daemon?). The good thing is this means that virtiofsd may block until its sole client replenishes notifications buffers. No other clients are hurt!

Stefan

A message that is not in the archive (sent off-list or not yet received): CAOssrKcXftoaszAoNF3936rTP0KgD6mL4P=hoy54v2i+x-1o8A@mail.gmail.com

#7 lore raw

Re: [virtio-dev] [PATCH v2 1/2] content: add virtio file system device

Quoted 74 lines · Miklos Szeredi
Quoted 59 lines · Stefan Hajnoczi
Quoted 50 lines · Miklos Szeredi
Quoted 35 lines · Stefan Hajnoczi
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Stefan Hajnoczi
virtio-fs.tex new file +14 -0
+Notifications are different from normal requests because they only contain
+device writable fields.  The driver sends notification replies on one of the
+request queues.  The format of notification requests is as follows:
+
+\begin{lstlisting}
+struct virtio_fs_notification_req {
+        // Device-writable part
+        struct fuse_out_header out;
+        u8 dataout[];
+};
+\end{lstlisting}
+
+\field{out} is the completion header common to all types of FUSE requests.  The
+\field{out.unique} field is 0 and the \field{out.error} field contains a
Quoted 8 lines

virtio-fs.tex line 189

Quoted 5 lines
virtio-fs.tex new file +5 -0
+FUSE_NOTIFY_* code.
+
+\field{dataout} consists of request-specific data, if any.  This is identical
+to the data written to the /dev/fuse device by a FUSE daemon.
+

What happens if notifications are lost because no request was there? virtio-scsi has a flag for that, would it make sense to add it here too?

The FUSE protocol assumes notification delivery is reliable. Some notifications can be dropped with no or little impact on functionality, but others cannot because it would cause a hung operation.

Therefore the device must hold notifications until the driver makes buffers available. The question becomes what happens when the device runs out of space to hold notifications. At this point the device must be reset because no further progress is possible.

Quoted 5 lines

(In our current implementation notifications aren't used at all, but the virtio-fs spec should allow for it so that the full FUSE protocol is available for future applications.)

Miklos: What do you think from the FUSE protocol point of view?

I think notifications would be limited in functionality in the virtio case. E.g. FUSE_NOTIFY_INVAL_INODE could be used if the server detects that cached attributes have become invalid. If this is a best effort thing (doesn't block other clients) then it's okay. But if it's for implementing strong coherency, then it doesn't work that well, since the broken client can block other clients from making progress.

Quoted 2 lines

So I'm not sure. Probably easier to leave notifications out of the implementation and the spec, until an actual use case arises.

I'd still like to discuss the options because it would be a real problem to spec the device without notifications and then find out the design cannot be extended when we need them.

Quoted 8 lines

When the device runs out of space to queue notifications for a slow client, that client must be kicked out so that others can continue. This seems like the most robust way to keep the file system available. Only the client that couldn't keep up is hurt.

In our implementation each virtiofsd has a single client, so I'm not sure the denial-of-service you described can occur (is that something that involves the ireg daemon?).

The DoS would involve any mechanism synchronizing one client's metadata modification with another client's metadata retrieval. In our implementation it is hoped to bypass that synchronization by using the version number living in shared memory.

Quoted 7 lines
Quoted 3 lines

The good thing is this means that
virtiofsd may block until its sole client replenishes notifications buffers. No other clients are hurt!

Right, so the notification in itself is not a source of DoS, but for it to be useful, it would necessarily involve some higher level synchronization, no?

I think this depends on the file system. In some cases notifications require resource allocation and that leads to the problems we've been discussing. In other cases the file system daemon may be able to send notifications at a later point in time without resource exhaustion, so no flow control or synchronization is needed.

Here are my thoughts on each FUSE notification type:

FUSE_NOTIFY_POLL
Requires guaranteed delivery: Yes, to wake up a sleeping task Possibility of resource exhaustion: Yes, If other clients generate poll notifications via their activity, then the notifications buffers can be exhausted.

When is FUSE_NOTIFY_POLL used? I guess it's needed in cases where the file system is changed on the remote side. virtiofsd should implement this notification eventually so that virtio-fs clients notice changes.

FUSE_NOTIFY_INVAL_INODE
Alternative: Use version shared memory region instead*

FUSE_NOTIFY_INVAL_ENTRY
Alternative: Use version shared memory region instead*

FUSE_NOTIFY_STORE
Alternative: Use DAX instead

FUSE_NOTIFY_RETRIEVE
Alternative: Use DAX instead

FUSE_NOTIFY_DELETE
Alternative: Use version shared memory region instead*
(Does it handle deleted inodes?)

* The version shared memory region prevents clients from using stale data (good) but doesn't prompt the client that something has changed (bad). This means inotify or similar cannot rely on these notifications to detect changes if we use the version shared memory instead.

Stefan

A message that is not in the archive (sent off-list or not yet received): CAOssrKeZhTMbKET=MRjDpqmWNMj00b2MG4Gv6MY-kdKYf1=eyA@mail.gmail.com

#9 lore raw

Re: [virtio-dev] [PATCH v2 1/2] content: add virtio file system device

Quoted 4 lines · Miklos Szeredi

Indeed, inotify and friends would need notification support, but at the moment no network filesystem has that and the kernel doesn't have interfaces for filesystems to provide remote notifications, so this is quite theoretical at this point.

This discussion makes me more confident that virtio-fs doesn't need notifications yet.

I will remove them from the spec.

Stefan

#10 lore raw

PATCH v2 2/2 virtio-fs: add DAX window

In reply to Stefan Hajnoczi

Describe how shared memory region ID 0 is the DAX window and how FUSE_SETUPMAPPING maps file ranges into the window.

---
 virtio-fs.tex | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
virtio-fs.tex +25 -0
index ffbaa46..37ab5ea 100644
@@ -196,3 +196,28 @@ The device MUST set \field{out.unique} to 0 and set \field{out.error} to a FUSE_
 The driver MUST verify that \field{out.unique} is 0.
 
 Notifications queue buffers MUST be at least 8192 bytes long.
+
+\subsubsection{Device Operation: DAX Window}\label{sec:Device Types / File System Device / Device Operation / Device Operation: DAX Window}
+
+FUSE\_READ and FUSE\_WRITE requests transfer file contents between the
+driver-provided buffer and the device.  In cases where data transfer is
+undesirable, the device can map file contents into the DAX window shared memory
+region.  The driver then accesses file contents directly in device-owned memory
+without a data transfer.
+
+Shared memory region ID 0 is called the DAX window.  The driver maps a file
+range into the DAX window using the FUSE\_SETUPMAPPING request.  The mapping is
+removed using the FUSE\_REMOVEMAPPING request.
+
+After FUSE\_SETUPMAPPING has completed successfully the file range is accessible
+from the DAX window at the offset provided by the driver in the request.
+
+\devicenormative{\paragraph}{Device Operation: DAX Window}{Device Types / File System Device / Device Operation / Device Operation: DAX Window}
+
+The device MUST allow mappings that completely or partially overlap existing mappings within the DAX window.
+
+The device MUST reject mappings that would go beyond the end of the DAX window.
+
+\drivernormative{\paragraph}{Device Operation: DAX Window}{Device Types / File System Device / Device Operation / Device Operation: DAX Window}
+
+The driver SHOULD be prepared to find shared memory region ID 0 absent and fall back to FUSE\_READ and FUSE\_WRITE requests.
Signature · 6 lines
2.20.1


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
#11 lore raw

Re: [virtio-dev] [PATCH v2 2/2] virtio-fs: add DAX window

Quoted 21 lines · Stefan Hajnoczi

Describe how shared memory region ID 0 is the DAX window and how FUSE_SETUPMAPPING maps file ranges into the window.

---
 virtio-fs.tex | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
virtio-fs.tex +5 -0
index ffbaa46..37ab5ea 100644
@@ -196,3 +196,28 @@ The device MUST set \field{out.unique} to 0 and set \field{out.error} to a FUSE_
 The driver MUST verify that \field{out.unique} is 0.
 
 Notifications queue buffers MUST be at least 8192 bytes long.
+
+\subsubsection{Device Operation: DAX Window}\label{sec:Device Types / File System Device / Device Operation / Device Operation: DAX Window}
+
+FUSE\_READ and FUSE\_WRITE requests transfer file contents between the
+driver-provided buffer and the device.  In cases where data transfer is

virtio-fs.tex The device MUST set \field{out.unique} to 0 and set \field{out.error} to a FUSE_ · line 213

Quoted 10 lines
virtio-fs.tex +10 -0
+undesirable, the device can map file contents into the DAX window shared memory
+region.  The driver then accesses file contents directly in device-owned memory
+without a data transfer.
+
+Shared memory region ID 0 is called the DAX window.  The driver maps a file
+range into the DAX window using the FUSE\_SETUPMAPPING request.  The mapping is
+removed using the FUSE\_REMOVEMAPPING request.
+
+After FUSE\_SETUPMAPPING has completed successfully the file range is accessible
+from the DAX window at the offset provided by the driver in the request.

FYI: this is not upstream yet, see https://lkml.org/lkml/2018/12/10/573
for a definition.

Paolo

virtio-fs.tex The device MUST set \field{out.unique} to 0 and set \field{out.error} to a FUSE_ · line 223

Quoted 10 lines
virtio-fs.tex +9 -0
+\devicenormative{\paragraph}{Device Operation: DAX Window}{Device Types / File System Device / Device Operation / Device Operation: DAX Window}
+
+The device MUST allow mappings that completely or partially overlap existing mappings within the DAX window.
+
+The device MUST reject mappings that would go beyond the end of the DAX window.
+
+\drivernormative{\paragraph}{Device Operation: DAX Window}{Device Types / File System Device / Device Operation / Device Operation: DAX Window}
+
+The driver SHOULD be prepared to find shared memory region ID 0 absent and fall back to FUSE\_READ and FUSE\_WRITE requests.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]