From: Hawkins Jiawei <yin31149@gmail.com>
To: Eugenio Perez Martin <eperezma@redhat.com>
Cc: jasowang@redhat.com, mst@redhat.com, qemu-devel@nongnu.org,
18801353760@163.com
Subject: Re: [PATCH v3 2/8] vdpa: Use iovec for vhost_vdpa_net_cvq_add()
Date: Sun, 20 Aug 2023 10:33:10 +0800 [thread overview]
Message-ID: <CAKrof1PA3C=AWRKx9XMpR+o_3MebgpTic5ecf_4ttuwVLegvzA@mail.gmail.com> (raw)
In-Reply-To: <CAJaqyWeGSdnv-s0X=ZqhQPw7tQ7BtjJuvD_1e5nqbCyN-tFknA@mail.gmail.com>
On 2023/8/18 23:23, Eugenio Perez Martin wrote:
> On Wed, Jul 19, 2023 at 9:54 AM Hawkins Jiawei <yin31149@gmail.com> wrote:
>>
>> Next patches in this series will no longer perform an
>> immediate poll and check of the device's used buffers
>> for each CVQ state load command. Consequently, there
>> will be multiple pending buffers in the shadow VirtQueue,
>> making it a must for every control command to have its
>> own buffer.
>>
>> To achieve this, this patch refactor vhost_vdpa_net_cvq_add()
>> to accept `struct iovec`, which eliminates the coupling of
>> control commands to `s->cvq_cmd_out_buffer` and `s->status`,
>> allowing them to use their own buffer.
>>
>> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
>> ---
>> net/vhost-vdpa.c | 38 ++++++++++++++++++++------------------
>> 1 file changed, 20 insertions(+), 18 deletions(-)
>>
>> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
>> index d1dd140bf6..6b16c8ece0 100644
>> --- a/net/vhost-vdpa.c
>> +++ b/net/vhost-vdpa.c
>> @@ -596,22 +596,14 @@ static void vhost_vdpa_net_cvq_stop(NetClientState *nc)
>> vhost_vdpa_net_client_stop(nc);
>> }
>>
>> -static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, size_t out_len,
>> - size_t in_len)
>> +static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s,
>> + struct iovec *out_sg, size_t out_num,
>> + struct iovec *in_sg, size_t in_num)
>> {
>> - /* Buffers for the device */
>> - const struct iovec out = {
>> - .iov_base = s->cvq_cmd_out_buffer,
>> - .iov_len = out_len,
>> - };
>> - const struct iovec in = {
>> - .iov_base = s->status,
>> - .iov_len = sizeof(virtio_net_ctrl_ack),
>> - };
>> VhostShadowVirtqueue *svq = g_ptr_array_index(s->vhost_vdpa.shadow_vqs, 0);
>> int r;
>>
>> - r = vhost_svq_add(svq, &out, 1, &in, 1, NULL);
>> + r = vhost_svq_add(svq, out_sg, out_num, in_sg, in_num, NULL);
>> if (unlikely(r != 0)) {
>> if (unlikely(r == -ENOSPC)) {
>> qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n",
>> @@ -637,6 +629,15 @@ static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s, uint8_t class,
>> .cmd = cmd,
>> };
>> size_t data_size = iov_size(data_sg, data_num);
>> + /* Buffers for the device */
>> + struct iovec out = {
>> + .iov_base = s->cvq_cmd_out_buffer,
>> + .iov_len = sizeof(ctrl) + data_size,
>> + };
>> + struct iovec in = {
>> + .iov_base = s->status,
>> + .iov_len = sizeof(*s->status),
>> + };
>>
>> assert(data_size < vhost_vdpa_net_cvq_cmd_page_len() - sizeof(ctrl));
>>
>> @@ -647,8 +648,7 @@ static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s, uint8_t class,
>> 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));
>> + return vhost_vdpa_net_cvq_add(s, &out, 1, &in, 1);
>> }
>>
>> static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)
>> @@ -1222,9 +1222,7 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq,
>> struct iovec out = {
>> .iov_base = s->cvq_cmd_out_buffer,
>> };
>> - /* in buffer used for device model */
>> - const struct iovec in = {
>> - .iov_base = &status,
>> + struct iovec in = {
>
> What if instead of reusing "in" we declare a new struct iovec in the
> condition that calls vhost_vdpa_net_cvq_add? Something in the line of
> "device_in".
>
> I'm also ok with this code, but splitting them would reduce the
> possibility of sending the wrong one to the device / virtio device
> model by mistake.
Hi Eugenio,
Ok, I will refactor this part of code according to your suggestion in
the v4 patch.
Thanks!
>
> Thanks!
>
>> .iov_len = sizeof(status),
>> };
>> ssize_t dev_written = -EINVAL;
>> @@ -1232,6 +1230,8 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq,
>> out.iov_len = iov_to_buf(elem->out_sg, elem->out_num, 0,
>> s->cvq_cmd_out_buffer,
>> vhost_vdpa_net_cvq_cmd_page_len());
>> + /* In buffer used for the vdpa device */
>> + in.iov_base = s->status;
>>
>> ctrl = s->cvq_cmd_out_buffer;
>> if (ctrl->class == VIRTIO_NET_CTRL_ANNOUNCE) {
>> @@ -1260,7 +1260,7 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq,
>> goto out;
>> }
>> } else {
>> - dev_written = vhost_vdpa_net_cvq_add(s, out.iov_len, sizeof(status));
>> + dev_written = vhost_vdpa_net_cvq_add(s, &out, 1, &in, 1);
>> if (unlikely(dev_written < 0)) {
>> goto out;
>> }
>> @@ -1276,6 +1276,8 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq,
>> }
>>
>> status = VIRTIO_NET_ERR;
>> + /* In buffer used for the device model */
>> + in.iov_base = &status;
>> virtio_net_handle_ctrl_iov(svq->vdev, &in, 1, &out, 1);
>> if (status != VIRTIO_NET_OK) {
>> error_report("Bad CVQ processing in model");
>> --
>> 2.25.1
>>
>
next prev parent reply other threads:[~2023-08-20 2:33 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-19 7:53 [PATCH v3 0/8] vdpa: Send all CVQ state load commands in parallel Hawkins Jiawei
2023-07-19 7:53 ` [PATCH v3 1/8] vhost: Add argument to vhost_svq_poll() Hawkins Jiawei
2023-08-18 15:08 ` Eugenio Perez Martin
2023-08-20 2:20 ` Hawkins Jiawei
2023-07-19 7:53 ` [PATCH v3 2/8] vdpa: Use iovec for vhost_vdpa_net_cvq_add() Hawkins Jiawei
2023-08-18 15:23 ` Eugenio Perez Martin
2023-08-20 2:33 ` Hawkins Jiawei [this message]
2023-07-19 7:53 ` [PATCH v3 3/8] vhost: Expose vhost_svq_available_slots() Hawkins Jiawei
2023-08-18 15:24 ` Eugenio Perez Martin
2023-07-19 7:53 ` [PATCH v3 4/8] vdpa: Avoid using vhost_vdpa_net_load_*() outside vhost_vdpa_net_load() Hawkins Jiawei
2023-08-18 15:39 ` Eugenio Perez Martin
2023-08-20 2:45 ` Hawkins Jiawei
2023-07-19 7:53 ` [PATCH v3 5/8] vdpa: Check device ack in vhost_vdpa_net_load_rx_mode() Hawkins Jiawei
2023-08-18 15:41 ` Eugenio Perez Martin
2023-07-19 7:53 ` [PATCH v3 6/8] vdpa: Move vhost_svq_poll() to the caller of vhost_vdpa_net_cvq_add() Hawkins Jiawei
2023-08-18 15:48 ` Eugenio Perez Martin
2023-08-20 2:52 ` Hawkins Jiawei
2023-07-19 7:53 ` [PATCH v3 7/8] vdpa: Add cursors to vhost_vdpa_net_loadx() Hawkins Jiawei
2023-07-19 7:53 ` [PATCH v3 8/8] vdpa: Send cvq state load commands in parallel Hawkins Jiawei
2023-08-18 17:27 ` Eugenio Perez Martin
2023-08-20 3:34 ` Hawkins Jiawei
2023-07-19 9:11 ` [PATCH v3 0/8] vdpa: Send all CVQ " Michael S. Tsirkin
2023-07-19 12:35 ` Hawkins Jiawei
2023-07-19 12:44 ` Lei Yang
2023-07-19 15:24 ` Hawkins Jiawei
2023-07-19 22:54 ` Lei Yang
2023-07-20 8:53 ` Lei Yang
2023-07-20 10:32 ` Hawkins Jiawei
2023-07-19 12:46 ` Michael S. Tsirkin
2023-07-19 15:11 ` Hawkins Jiawei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKrof1PA3C=AWRKx9XMpR+o_3MebgpTic5ecf_4ttuwVLegvzA@mail.gmail.com' \
--to=yin31149@gmail.com \
--cc=18801353760@163.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).