From: Gavin Shan <gshan@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org,
jasowang@redhat.com, shan.gavin@gmail.com
Subject: Re: [PATCH v2 2/4] vhost: Drop variable last_avail_idx in vhost_get_vq_desc()
Date: Tue, 30 Apr 2024 09:00:21 +1000 [thread overview]
Message-ID: <4e133a86-a2e5-43ed-acd0-fe6f1aa9eed2@redhat.com> (raw)
In-Reply-To: <20240429144522-mutt-send-email-mst@kernel.org>
On 4/30/24 04:45, Michael S. Tsirkin wrote:
> On Mon, Apr 29, 2024 at 08:13:58PM +1000, Gavin Shan wrote:
>> The local variable @last_avail_idx is equivalent to vq->last_avail_idx.
>> So the code can be simplified a bit by dropping the local variable
>> @last_avail_idx.
>>
>> No functional change intended.
>>
>> Signed-off-by: Gavin Shan <gshan@redhat.com>
>> ---
>> drivers/vhost/vhost.c | 7 +++----
>> 1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
>> index 7aa623117aab..b278c0333a66 100644
>> --- a/drivers/vhost/vhost.c
>> +++ b/drivers/vhost/vhost.c
>> @@ -2524,7 +2524,6 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
>> {
>> struct vring_desc desc;
>> unsigned int i, head, found = 0;
>> - u16 last_avail_idx = vq->last_avail_idx;
>> __virtio16 ring_head;
>> int ret, access;
>>
>> @@ -2539,10 +2538,10 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
>>
>> /* Grab the next descriptor number they're advertising, and increment
>> * the index we've seen. */
>> - if (unlikely(vhost_get_avail_head(vq, &ring_head, last_avail_idx))) {
>> + if (unlikely(vhost_get_avail_head(vq, &ring_head, vq->last_avail_idx))) {
>> vq_err(vq, "Failed to read head: idx %d address %p\n",
>> - last_avail_idx,
>> - &vq->avail->ring[last_avail_idx % vq->num]);
>> + vq->last_avail_idx,
>> + &vq->avail->ring[vq->last_avail_idx % vq->num]);
>> return -EFAULT;
>> }
>
> I don't see the big advantage and the line is long now.
>
The point is to avoid the local variable @last_avail_idx since it's equivalent
to vq->last_avail_idx, as stated in the commit log. Besides, it paves the way
for PATCH[v2 3/4] where the whole logic fetching the head and sanity check is
moved to vhost_get_avail_head(), so that vhost_get_vq_desc() is simplified
I will drop PATCH[2, 3, 4] as you suggested.
Thanks,
Gavin
next prev parent reply other threads:[~2024-04-29 23:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-29 10:13 [PATCH v2 0/4] vhost: Cleanup Gavin Shan
2024-04-29 10:13 ` [PATCH v2 1/4] vhost: Improve vhost_get_avail_idx() with smp_rmb() Gavin Shan
2024-04-29 18:44 ` Michael S. Tsirkin
2024-04-29 23:18 ` Gavin Shan
2024-04-29 10:13 ` [PATCH v2 2/4] vhost: Drop variable last_avail_idx in vhost_get_vq_desc() Gavin Shan
2024-04-29 18:45 ` Michael S. Tsirkin
2024-04-29 23:00 ` Gavin Shan [this message]
2024-04-29 10:13 ` [PATCH v2 3/4] vhost: Improve vhost_get_avail_head() Gavin Shan
2024-04-29 18:48 ` Michael S. Tsirkin
2024-04-29 10:14 ` [PATCH v2 4/4] vhost: Reformat vhost_{get, put}_user() Gavin Shan
2024-04-29 18:49 ` Michael S. Tsirkin
2024-04-29 18:50 ` [PATCH v2 0/4] vhost: Cleanup Michael S. Tsirkin
2024-04-29 23:31 ` Gavin Shan
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=4e133a86-a2e5-43ed-acd0-fe6f1aa9eed2@redhat.com \
--to=gshan@redhat.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=shan.gavin@gmail.com \
--cc=virtualization@lists.linux.dev \
/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