vdpa: Use iovec for vhost_vdpa_net_load_cmd()
According to VirtIO standard, "The driver MUST follow the VIRTIO_NET_CTRL_MAC_TABLE_SET command by a le32 number, followed by that number of non-multicast MAC addresses, followed by another le32 number, followed by that number of multicast addresses." Considering that these data is not stored in contiguous memory, this patch refactors vhost_vdpa_net_load_cmd() to accept scattered data, eliminating the need for an addtional data copy or packing the data into s->cvq_cmd_out_buffer outside of vhost_vdpa_net_load_cmd(). Signed-off-by: Hawkins Jiawei <yin31149@gmail.com> Message-Id: <3482cc50eebd13db4140b8b5dec9d0cc25b20b1b.1688743107.git.yin31149@gmail.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
7c228c5f33
commit
2848c6aa75
@ -626,29 +626,38 @@ static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, size_t out_len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s, uint8_t class,
|
static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s, uint8_t class,
|
||||||
uint8_t cmd, const void *data,
|
uint8_t cmd, const struct iovec *data_sg,
|
||||||
size_t data_size)
|
size_t data_num)
|
||||||
{
|
{
|
||||||
const struct virtio_net_ctrl_hdr ctrl = {
|
const struct virtio_net_ctrl_hdr ctrl = {
|
||||||
.class = class,
|
.class = class,
|
||||||
.cmd = cmd,
|
.cmd = cmd,
|
||||||
};
|
};
|
||||||
|
size_t data_size = iov_size(data_sg, data_num);
|
||||||
|
|
||||||
assert(data_size < vhost_vdpa_net_cvq_cmd_page_len() - sizeof(ctrl));
|
assert(data_size < vhost_vdpa_net_cvq_cmd_page_len() - sizeof(ctrl));
|
||||||
|
|
||||||
|
/* pack the CVQ command header */
|
||||||
memcpy(s->cvq_cmd_out_buffer, &ctrl, sizeof(ctrl));
|
memcpy(s->cvq_cmd_out_buffer, &ctrl, sizeof(ctrl));
|
||||||
memcpy(s->cvq_cmd_out_buffer + sizeof(ctrl), data, data_size);
|
|
||||||
|
|
||||||
return vhost_vdpa_net_cvq_add(s, sizeof(ctrl) + data_size,
|
/* pack the CVQ command command-specific-data */
|
||||||
|
iov_to_buf(data_sg, data_num, 0,
|
||||||
|
s->cvq_cmd_out_buffer + sizeof(ctrl), data_size);
|
||||||
|
|
||||||
|
return vhost_vdpa_net_cvq_add(s, data_size + sizeof(ctrl),
|
||||||
sizeof(virtio_net_ctrl_ack));
|
sizeof(virtio_net_ctrl_ack));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)
|
static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)
|
||||||
{
|
{
|
||||||
if (virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_CTRL_MAC_ADDR)) {
|
if (virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_CTRL_MAC_ADDR)) {
|
||||||
|
const struct iovec data = {
|
||||||
|
.iov_base = (void *)n->mac,
|
||||||
|
.iov_len = sizeof(n->mac),
|
||||||
|
};
|
||||||
ssize_t dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_MAC,
|
ssize_t dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_MAC,
|
||||||
VIRTIO_NET_CTRL_MAC_ADDR_SET,
|
VIRTIO_NET_CTRL_MAC_ADDR_SET,
|
||||||
n->mac, sizeof(n->mac));
|
&data, 1);
|
||||||
if (unlikely(dev_written < 0)) {
|
if (unlikely(dev_written < 0)) {
|
||||||
return dev_written;
|
return dev_written;
|
||||||
}
|
}
|
||||||
@ -671,9 +680,13 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
mq.virtqueue_pairs = cpu_to_le16(n->curr_queue_pairs);
|
mq.virtqueue_pairs = cpu_to_le16(n->curr_queue_pairs);
|
||||||
|
const struct iovec data = {
|
||||||
|
.iov_base = &mq,
|
||||||
|
.iov_len = sizeof(mq),
|
||||||
|
};
|
||||||
dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_MQ,
|
dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_MQ,
|
||||||
VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET, &mq,
|
VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET,
|
||||||
sizeof(mq));
|
&data, 1);
|
||||||
if (unlikely(dev_written < 0)) {
|
if (unlikely(dev_written < 0)) {
|
||||||
return dev_written;
|
return dev_written;
|
||||||
}
|
}
|
||||||
@ -712,9 +725,13 @@ static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
offloads = cpu_to_le64(n->curr_guest_offloads);
|
offloads = cpu_to_le64(n->curr_guest_offloads);
|
||||||
|
const struct iovec data = {
|
||||||
|
.iov_base = &offloads,
|
||||||
|
.iov_len = sizeof(offloads),
|
||||||
|
};
|
||||||
dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_GUEST_OFFLOADS,
|
dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_GUEST_OFFLOADS,
|
||||||
VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET,
|
VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET,
|
||||||
&offloads, sizeof(offloads));
|
&data, 1);
|
||||||
if (unlikely(dev_written < 0)) {
|
if (unlikely(dev_written < 0)) {
|
||||||
return dev_written;
|
return dev_written;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user