@@ -85,6 +85,96 @@ pub struct VhostUserDirtyLogRegion {
85
85
pub mmap_handle : RawFd ,
86
86
}
87
87
88
+ /// Vhost memory access permission (VHOST_ACCESS_* mapping)
89
+ #[ repr( u8 ) ]
90
+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
91
+ pub enum VhostAccess {
92
+ /// No access.
93
+ No = 0 ,
94
+ /// Read-Only access.
95
+ ReadOnly = 1 ,
96
+ /// Write-Only access.
97
+ WriteOnly = 2 ,
98
+ /// Read and Write access.
99
+ ReadWrite = 3 ,
100
+ }
101
+
102
+ impl Default for VhostAccess {
103
+ fn default ( ) -> Self {
104
+ VhostAccess :: No
105
+ }
106
+ }
107
+
108
+ /// Vhost IOTLB message type (VHOST_IOTLB_* mapping)
109
+ #[ repr( u8 ) ]
110
+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
111
+ pub enum VhostIotlbType {
112
+ /// Empty message (not valid).
113
+ Empty = 0 ,
114
+ /// I/O virtual address mapping is missing or invalidated.
115
+ Miss = 1 ,
116
+ /// Update the I/O virtual address mapping.
117
+ Update = 2 ,
118
+ /// Invalidate the I/O virtual address mapping.
119
+ Invalidate = 3 ,
120
+ /// Access failed to an I/O virtual address.
121
+ AccessFail = 4 ,
122
+ /// Batch of multiple `Update` messages begins.
123
+ BatchBegin = 5 ,
124
+ /// Batch of multiple `Update` messages ends.
125
+ BatchEnd = 6 ,
126
+ }
127
+
128
+ impl Default for VhostIotlbType {
129
+ fn default ( ) -> Self {
130
+ VhostIotlbType :: Empty
131
+ }
132
+ }
133
+
134
+ /// Vhost IOTLB message structure.
135
+ #[ derive( Default , Clone , Copy ) ]
136
+ pub struct VhostIotlbMsg {
137
+ /// I/O virtual address.
138
+ pub iova : u64 ,
139
+ /// Size of the I/O mapping.
140
+ pub size : u64 ,
141
+ /// Virtual address in the current process.
142
+ pub userspace_addr : u64 ,
143
+ /// Access permissions.
144
+ pub perm : VhostAccess ,
145
+ /// Type of the message.
146
+ pub msg_type : VhostIotlbType ,
147
+ }
148
+
149
+ /// Vhost IOTLB message parser.
150
+ pub trait VhostIotlbMsgParser {
151
+ /// Parse the IOTLB message and fill a VhostIotlbMsg.
152
+ ///
153
+ /// # Arguments
154
+ /// * `msg` - IOTLB message parsed.
155
+ fn parse ( & self , msg : & mut VhostIotlbMsg ) -> Result < ( ) > ;
156
+ }
157
+
158
+ /// An interface for IOTLB messages support for vhost-based backend
159
+ pub trait VhostIotlbBackend : std:: marker:: Sized {
160
+ /// Send an IOTLB message to the vhost-based backend.
161
+ ///
162
+ /// # Arguments
163
+ /// * `msg` - IOTLB message to send.
164
+ fn send_iotlb_msg ( & self , msg : & VhostIotlbMsg ) -> Result < ( ) > ;
165
+
166
+ /// Parse a buffer received from the vhost-based backend and fill a VhostIotlbMsg.
167
+ ///
168
+ /// # Arguments
169
+ /// * `buffer` - Buffer containing the raw data received from the vhost-based backend.
170
+ /// * `msg` - IOTLB message parsed.
171
+ fn parse_iotlb_msg < T : Sized + VhostIotlbMsgParser > (
172
+ & self ,
173
+ buffer : & T ,
174
+ msg : & mut VhostIotlbMsg ,
175
+ ) -> Result < ( ) > ;
176
+ }
177
+
88
178
/// An interface for setting up vhost-based backend drivers with interior mutability.
89
179
///
90
180
/// Vhost devices are subset of virtio devices, which improve virtio device's performance by
0 commit comments