static__rte_always_inlineuint64_trte_vhost_va_from_guest_pa(structrte_vhost_memory*mem,uint64_tgpa,uint64_t*len)[static]
Convert guest physical address to host virtual address
Parametersmem the guest memory regions
gpa the guest physical address for querying
len the size of the requested area to map, updated with actual size mapped
Returns
the host virtual address on success, 0 on failure
Definition at line 375 of file rte_vhost.h.
voidrte_vhost_log_write(intvid,uint64_taddr,uint64_tlen)
Log the memory write start with given address.
This function only need be invoked when the live migration starts. Therefore, we won't need call it at
all in the most of time. For making the performance impact be minimum, it's suggested to do a check
before calling it:
if (unlikely(RTE_VHOST_NEED_LOG(features)))
rte_vhost_log_write(vid, addr, len);
Parametersvid vhost device ID
addr the starting address for write (in guest physical address space)
len the length to write
voidrte_vhost_log_used_vring(intvid,uint16_tvring_idx,uint64_toffset,uint64_tlen)
Log the used ring update start at given offset.
Same as rte_vhost_log_write, it's suggested to do a check before calling it:
if (unlikely(RTE_VHOST_NEED_LOG(features)))
rte_vhost_log_used_vring(vid, vring_idx, offset, len);
Parametersvid vhost device ID
vring_idx the vring index
offset the offset inside the used ring
len the length to write
__rte_experimentalvoidrte_vhost_notify_guest(intvid,uint16_tqueue_id)WarningEXPERIMENTAL: this API may change, or be removed, without prior notice.
Inject the offloaded interrupt into the vhost device's queue.
Seealso
guest_notify vhost device operation
Parametersvid vhost device ID
queue_id virtio queue index
intrte_vhost_driver_register(constchar*path,uint64_tflags)
Register vhost driver. path could be different for multiple instance support.
intrte_vhost_driver_attach_vdpa_device(constchar*path,structrte_vdpa_device*dev)
Set the vdpa device id, enforce single connection per socket
Parameterspath The vhost-user socket file path
dev vDPA device pointer
Returns
0 on success, -1 on failure
intrte_vhost_driver_detach_vdpa_device(constchar*path)
Unset the vdpa device id
Parameterspath The vhost-user socket file path
Returns
0 on success, -1 on failure
structrte_vdpa_device*rte_vhost_driver_get_vdpa_device(constchar*path)
Get the device id
Parameterspath The vhost-user socket file path
Returns
vDPA device pointer, NULL on failure
intrte_vhost_driver_get_vdpa_dev_type(constchar*path,uint32_t*type)
Get the device type of the vdpa device.
Parameterspath The vhost-user socket file path
type the device type of the vdpa device
Returns
0 on success, -1 on failure
intrte_vhost_driver_set_features(constchar*path,uint64_tfeatures)
Set the feature bits the vhost-user driver supports.
Parameterspath The vhost-user socket file path
features Supported features
Returns
0 on success, -1 on failure
intrte_vhost_driver_enable_features(constchar*path,uint64_tfeatures)
Enable vhost-user driver features.
Note that
• the param features should be a subset of the feature bits provided by rte_vhost_driver_set_features().
• it must be invoked before vhost-user negotiation starts.
Parameterspath The vhost-user socket file path
features Features to enable
Returns
0 on success, -1 on failure
intrte_vhost_driver_disable_features(constchar*path,uint64_tfeatures)
Disable vhost-user driver features.
The two notes at rte_vhost_driver_enable_features() also apply here.
Parameterspath The vhost-user socket file path
features Features to disable
Returns
0 on success, -1 on failure
intrte_vhost_driver_get_features(constchar*path,uint64_t*features)
Get the feature bits before feature negotiation.
Parameterspath The vhost-user socket file path
features A pointer to store the queried feature bits
Returns
0 on success, -1 on failure
intrte_vhost_driver_set_protocol_features(constchar*path,uint64_tprotocol_features)
Set the protocol feature bits before feature negotiation.
Parameterspath The vhost-user socket file path
protocol_features Supported protocol features
Returns
0 on success, -1 on failure
intrte_vhost_driver_get_protocol_features(constchar*path,uint64_t*protocol_features)
Get the protocol feature bits before feature negotiation.
Parameterspath The vhost-user socket file path
protocol_features A pointer to store the queried protocol feature bits
Returns
0 on success, -1 on failure
intrte_vhost_driver_get_queue_num(constchar*path,uint32_t*queue_num)
Get the queue number bits before feature negotiation.
Parameterspath The vhost-user socket file path
queue_num A pointer to store the queried queue number bits
Returns
0 on success, -1 on failure
intrte_vhost_driver_set_max_queue_num(constchar*path,uint32_tmax_queue_pairs)
Set the maximum number of queue pairs supported by the device. The value set is ignored for Vhost-user
backends. It is only taken into account with VDUSE backends.
Parameterspath The vhost-user socket file path
max_queue_pairs The maximum number of queue pairs
Returns
0 on success, -1 on failure
intrte_vhost_get_negotiated_features(intvid,uint64_t*features)
Get the feature bits after negotiation
Parametersvid Vhost device ID
features A pointer to store the queried feature bits
Returns
0 on success, -1 on failure
intrte_vhost_get_negotiated_protocol_features(intvid,uint64_t*protocol_features)
Get the protocol feature bits after negotiation
Parametersvid Vhost device ID
protocol_features A pointer to store the queried protocol feature bits
Returns
0 on success, -1 on failure
intrte_vhost_driver_start(constchar*path)
Start the vhost-user driver.
This function triggers the vhost-user negotiation.
Parameterspath The vhost-user socket file path
Returns
0 on success, -1 on failure
intrte_vhost_get_mtu(intvid,uint16_t*mtu)
Get the MTU value of the device if set in QEMU.
Parametersvid virtio-net device ID
mtu The variable to store the MTU value
Returns
0: success -EAGAIN: device not yet started -ENOTSUP: device does not support MTU feature
intrte_vhost_get_numa_node(intvid)
Get the numa node from which the virtio net device's memory is allocated.
Parametersvid vhost device ID
Returns
The numa node, -1 on failure
uint16_trte_vhost_get_vring_num(intvid)
Get the number of vrings the device supports.
Parametersvid vhost device ID
Returns
The number of vrings, 0 on failure
intrte_vhost_get_ifname(intvid,char*buf,size_tlen)
Get the virtio net device's ifname, which is the vhost-user socket file path.
Parametersvid vhost device ID
buf The buffer to stored the queried ifname
len The length of buf
Returns
0 on success, -1 on failure
uint16_trte_vhost_avail_entries(intvid,uint16_tqueue_id)
Get how many avail entries are left in the queue
Parametersvid vhost device ID
queue_id virtio queue index
Returns
num of avail entries left
uint16_trte_vhost_enqueue_burst(intvid,uint16_tqueue_id,structrte_mbuf**pkts,uint16_tcount)
This function adds buffers to the virtio devices RX virtqueue. Buffers can be received from the physical
port or from another virtual device. A packet count is returned to indicate the number of packets that
were successfully added to the RX queue.
Parametersvid vhost device ID
queue_id virtio queue index in mq case
pkts array to contain packets to be enqueued
count packets num to be enqueued
Returns
num of packets enqueued
uint16_trte_vhost_dequeue_burst(intvid,uint16_tqueue_id,structrte_mempool*mbuf_pool,structrte_mbuf**pkts,uint16_tcount)
This function gets guest buffers from the virtio device TX virtqueue, construct host mbufs, copies guest
buffer content to host mbufs and store them in pkts to be processed.
Parametersvid vhost device ID
queue_id virtio queue index in mq case
mbuf_pool mbuf_pool where host mbuf is allocated.
pkts array to contain packets to be dequeued
count packets num to be dequeued
Returns
num of packets dequeued
intrte_vhost_get_mem_table(intvid,structrte_vhost_memory**mem)
Get guest mem table: a list of memory regions.
An rte_vhost_vhost_memory object will be allocated internally, to hold the guest memory regions.
Application should free it at destroy_device() callback.
Parametersvid vhost device ID
mem To store the returned mem regions
Returns
0 on success, -1 on failure
intrte_vhost_get_vhost_vring(intvid,uint16_tvring_idx,structrte_vhost_vring*vring)
Get guest vring info, including the vring address, vring size, etc.
Parametersvid vhost device ID
vring_idx vring index
vring the structure to hold the requested vring info
Returns
0 on success, -1 on failure
intrte_vhost_get_vhost_ring_inflight(intvid,uint16_tvring_idx,structrte_vhost_ring_inflight*vring)
Get guest inflight vring info, including inflight ring and resubmit list.
Parametersvid vhost device ID
vring_idx vring index
vring the structure to hold the requested inflight vring info
Returns
0 on success, -1 on failure
intrte_vhost_set_inflight_desc_split(intvid,uint16_tvring_idx,uint16_tidx)
Set split inflight descriptor.
This function save descriptors that has been consumed in available ring
Parametersvid vhost device ID
vring_idx vring index
idx inflight entry index
Returns
0 on success, -1 on failure
intrte_vhost_set_inflight_desc_packed(intvid,uint16_tvring_idx,uint16_thead,uint16_tlast,uint16_t*inflight_entry)
Set packed inflight descriptor and get corresponding inflight entry
This function save descriptors that has been consumed
Parametersvid vhost device ID
vring_idx vring index
head head of descriptors
last last of descriptors
inflight_entry corresponding inflight entry
Returns
0 on success, -1 on failure
intrte_vhost_set_last_inflight_io_split(intvid,uint16_tvring_idx,uint16_tidx)
Save the head of list that the last batch of used descriptors.
Parametersvid vhost device ID
vring_idx vring index
idx descriptor entry index
Returns
0 on success, -1 on failure
intrte_vhost_set_last_inflight_io_packed(intvid,uint16_tvring_idx,uint16_thead)
Update the inflight free_head, used_idx and used_wrap_counter.
This function will update status first before updating descriptors to used
Parametersvid vhost device ID
vring_idx vring index
head head of descriptors
Returns
0 on success, -1 on failure
intrte_vhost_clr_inflight_desc_split(intvid,uint16_tvring_idx,uint16_tlast_used_idx,uint16_tidx)
Clear the split inflight status.
Parametersvid vhost device ID
vring_idx vring index
last_used_idx last used idx of used ring
idx inflight entry index
Returns
0 on success, -1 on failure
intrte_vhost_clr_inflight_desc_packed(intvid,uint16_tvring_idx,uint16_thead)
Clear the packed inflight status.
Parametersvid vhost device ID
vring_idx vring index
head inflight entry index
Returns
0 on success, -1 on failure
intrte_vhost_vring_call(intvid,uint16_tvring_idx)
Notify the guest that used descriptors have been added to the vring. This function acts as a memory
barrier.
Parametersvid vhost device ID
vring_idx vring index
Returns
0 on success, -1 on failure
intrte_vhost_vring_call_nonblock(intvid,uint16_tvring_idx)
Notify the guest that used descriptors have been added to the vring. This function acts as a memory
barrier. This function will return -EAGAIN when vq's access lock is held by other thread, user should try
again later.
Parametersvid vhost device ID
vring_idx vring index
Returns
0 on success, -1 on failure, -EAGAIN for another retry
uint32_trte_vhost_rx_queue_count(intvid,uint16_tqid)
Get vhost RX queue avail count.
Parametersvid vhost device ID
qid virtio queue index in mq case
Returns
num of desc available
intrte_vhost_get_monitor_addr(intvid,uint16_tqueue_id,structrte_vhost_power_monitor_cond*pmc)
Get power monitor address of the vhost device
Parametersvid vhost device ID
queue_id vhost queue ID
pmc power monitor condition
Returns
0 on success, -1 on failure
intrte_vhost_get_log_base(intvid,uint64_t*log_base,uint64_t*log_size)
Get log base and log size of the vhost device
Parametersvid vhost device ID
log_base vhost log base
log_size vhost log size
Returns
0 on success, -1 on failure
intrte_vhost_get_vring_base(intvid,uint16_tqueue_id,uint16_t*last_avail_idx,uint16_t*last_used_idx)
Get last_avail/used_idx of the vhost virtqueue
Parametersvid vhost device ID
queue_id vhost queue index
last_avail_idx vhost last_avail_idx to get
last_used_idx vhost last_used_idx to get
Returns
0 on success, -1 on failure
intrte_vhost_get_vring_base_from_inflight(intvid,uint16_tqueue_id,uint16_t*last_avail_idx,uint16_t*last_used_idx)
Get last_avail/last_used of the vhost virtqueue
This function is designed for the reconnection and it's specific for the packed ring as we can get the
two parameters from the inflight queueregion
Parametersvid vhost device ID
queue_id vhost queue index
last_avail_idx vhost last_avail_idx to get
last_used_idx vhost last_used_idx to get
Returns
0 on success, -1 on failure
intrte_vhost_set_vring_base(intvid,uint16_tqueue_id,uint16_tlast_avail_idx,uint16_tlast_used_idx)
Set last_avail/used_idx of the vhost virtqueue
Parametersvid vhost device ID
queue_id vhost queue index
last_avail_idx last_avail_idx to set
last_used_idx last_used_idx to set
Returns
0 on success, -1 on failure
intrte_vhost_extern_callback_register(intvid,structrte_vhost_user_extern_opsconst*constops,void*ctx)
Register external message handling callbacks
Parametersvid vhost device ID
ops virtio external callbacks to register
ctx additional context passed to the callbacks
Returns
0 on success, -1 on failure
structrte_vdpa_device*rte_vhost_get_vdpa_device(intvid)
Get vdpa device id for vhost device.
Parametersvid vhost device id
Returns
vDPA device pointer on success, NULL on failure
intrte_vhost_backend_config_change(intvid,boolneed_reply)
Notify the guest that should get virtio configuration space from backend.
Parametersvid vhost device ID
need_reply wait for the frontend response the status of this operation
Returns
0 on success, < 0 on failure
intrte_vhost_vring_stats_get_names(intvid,uint16_tqueue_id,structrte_vhost_stat_name*name,unsignedintsize)
Retrieve names of statistics of a Vhost virtqueue.
There is an assumption that 'stat_names' and 'stats' arrays are matched by array index:
stats_names[i].name => stats[i].value
Parametersvid vhost device ID
queue_id vhost queue index
name array of at least size elements to be filled. If set to NULL, the function returns the required
number of elements.
size The number of elements in stats_names array.
Returns
• Success if greater than 0 and lower or equal to size. The return value indicates the number of
elements filled in the names array.
• Failure if greater than size. The return value indicates the number of elements the names array
that should be given to succeed.
• Failure if lower than 0. The device ID or queue ID is invalid or
• statistics collection is not enabled.
intrte_vhost_vring_stats_get(intvid,uint16_tqueue_id,structrte_vhost_stat*stats,unsignedintn)
Retrieve statistics of a Vhost virtqueue.
There is an assumption that 'stat_names' and 'stats' arrays are matched by array index:
stats_names[i].name => stats[i].value
Parametersvid vhost device ID
queue_id vhost queue index
stats A pointer to a table of structure of type rte_vhost_stat to be filled with virtqueue statistics
ids and values.
n The number of elements in stats array.
Returns
• Success if greater than 0 and lower or equal to n. The return value indicates the number of
elements filled in the stats array.
• Failure if greater than n. The return value indicates the number of elements the stats array that
should be given to succeed.
• Failure if lower than 0. The device ID or queue ID is invalid, or statistics collection is not
enabled.
intrte_vhost_vring_stats_reset(intvid,uint16_tqueue_id)
Reset statistics of a Vhost virtqueue.
Parametersvid vhost device ID
queue_id vhost queue index
Returns
• Success if 0. Statistics have been reset.
• Failure if lower than 0. The device ID or queue ID is invalid, or statistics collection is not
enabled.