qemu-riscv.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>,
	Daniel Henrique Barboza <dbarboza@ventanamicro.com>,
	qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com,
	bmeng@tinylab.org, liwei1518@gmail.com,
	zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com,
	lvivier@redhat.com, pbonzini@redhat.com
Subject: Re: [PATCH v2 1/6] libqos/virtio.c: init all elems in qvring_indirect_desc_setup()
Date: Fri, 1 Mar 2024 19:45:00 +0100	[thread overview]
Message-ID: <33e7f83b-329f-4cd3-9a8c-6f4436de0616@redhat.com> (raw)
In-Reply-To: <37256c80-5209-4e56-8bc2-28ee59ec42f1@tls.msk.ru>

On 01/03/2024 16.57, Michael Tokarev wrote:
> 17.02.2024 22:26, Daniel Henrique Barboza:
> 
>> diff --git a/tests/qtest/libqos/virtio.c b/tests/qtest/libqos/virtio.c
>> index 410513225f..4f39124eba 100644
>> --- a/tests/qtest/libqos/virtio.c
>> +++ b/tests/qtest/libqos/virtio.c
>> @@ -280,14 +280,27 @@ QVRingIndirectDesc 
>> *qvring_indirect_desc_setup(QTestState *qs, QVirtioDevice *d,
>>       indirect->elem = elem;
>>       indirect->desc = guest_alloc(alloc, sizeof(struct vring_desc) * elem);
>> -    for (i = 0; i < elem - 1; ++i) {
>> +    for (i = 0; i < elem; ++i) {
>>           /* indirect->desc[i].addr */
>>           qvirtio_writeq(d, qs, indirect->desc + (16 * i), 0);
>> -        /* indirect->desc[i].flags */
>> -        qvirtio_writew(d, qs, indirect->desc + (16 * i) + 12,
>> -                       VRING_DESC_F_NEXT);
>> -        /* indirect->desc[i].next */
>> -        qvirtio_writew(d, qs, indirect->desc + (16 * i) + 14, i + 1);
>> +
>> +        /*
>> +         * If it's not the last element of the ring, set
>> +         * the chain (VRING_DESC_F_NEXT) flag and
>> +         * desc->next. Clear the last element - there's
>> +         * no guarantee that guest_alloc() will do it.
>> +         */
>> +        if (i != elem - 1) {
>> +            /* indirect->desc[i].flags */
>> +            qvirtio_writew(d, qs, indirect->desc + (16 * i) + 12,
>> +                           VRING_DESC_F_NEXT);
>> +
>> +            /* indirect->desc[i].next */
>> +            qvirtio_writew(d, qs, indirect->desc + (16 * i) + 14, i + 1);
>> +        } else {
>> +            qvirtio_writew(d, qs, indirect->desc + (16 * i) + 12, 0);
>> +            qvirtio_writew(d, qs, indirect->desc + (16 * i) + 14, 0);
>> +        }
>>       }
> 
> In my view it would be cleaner to add 2 extra function calls after this
> loop for the i==elem-1 case:
> 
>      for (i = 0; i < elem - 1; ++i) {
>          /* indirect->desc[i].addr */
>          qvirtio_writeq(d, qs, indirect->desc + (16 * i), 0);
>          /* indirect->desc[i].flags */
>          qvirtio_writew(d, qs, indirect->desc + (16 * i) + 12,
>                         VRING_DESC_F_NEXT);
>          /* indirect->desc[i].next */
>          qvirtio_writew(d, qs, indirect->desc + (16 * i) + 14, i + 1);
> 
>      }
> 
>       /* clear last element */
>       qvirtio_writeq(d, qs, indirect->desc + (16 * i), 0);
>       qvirtio_writew(d, qs, indirect->desc + (16 * i) + 12, 0);
>       qvirtio_writew(d, qs, indirect->desc + (16 * i) + 14, 0);
> 
> 
> FWIW, -- it's too late to change it now I think.

Sorry, too late, since the first two patches looked like some good (and 
riscv-independent) libqos fixes, I went ahead and stuck them into my pull 
request today. Feel free to send a follow up patch if it bugs you too much.

  Thomas



  reply	other threads:[~2024-03-01 18:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-17 19:26 [PATCH v2 0/6] libqos, riscv: libqos fixes, add riscv machine Daniel Henrique Barboza
2024-02-17 19:26 ` [PATCH v2 1/6] libqos/virtio.c: init all elems in qvring_indirect_desc_setup() Daniel Henrique Barboza
2024-03-01 15:57   ` Michael Tokarev
2024-03-01 18:45     ` Thomas Huth [this message]
2024-02-17 19:26 ` [PATCH v2 2/6] libqos/virtio.c: fix 'avail_event' offset in qvring_init() Daniel Henrique Barboza
2024-02-17 19:26 ` [PATCH v2 3/6] hw/riscv/virt.c: create '/soc/pci@...' fdt node earlier Daniel Henrique Barboza
2024-02-17 19:26 ` [PATCH v2 4/6] hw/riscv/virt.c: add virtio-iommu-pci hotplug support Daniel Henrique Barboza
2024-02-17 19:26 ` [PATCH v2 5/6] hw/riscv/virt.c: make aclint compatible with 'qtest' accel Daniel Henrique Barboza
2024-02-17 19:26 ` [PATCH v2 6/6] tests/libqos: add riscv/virt machine nodes Daniel Henrique Barboza
2024-02-23  5:38 ` [PATCH v2 0/6] libqos, riscv: libqos fixes, add riscv machine Alistair Francis

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=33e7f83b-329f-4cd3-9a8c-6f4436de0616@redhat.com \
    --to=thuth@redhat.com \
    --cc=alistair.francis@wdc.com \
    --cc=bmeng@tinylab.org \
    --cc=dbarboza@ventanamicro.com \
    --cc=liwei1518@gmail.com \
    --cc=lvivier@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=palmer@rivosinc.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=zhiwei_liu@linux.alibaba.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).