This is suggested by Michael S. Tsirkin according to [1] and the goal
is to apply smp_rmb() inside vhost_get_avail_idx() if needed. With it,
the caller of the function needn't to worry about memory barriers. Since
we're here, other cleanups are also applied.
[1] https://lore.kernel.org/virtualization/[email protected]/
PATCH[1] drops the local variable @last_avail_idx since it's equivalent
to vq->last_avail_idx
PATCH[2] improves vhost_get_avail_idx() so that smp_rmb() is applied if
needed. Besides, the sanity checks on the retrieved available
queue index are also squeezed to vhost_get_avail_idx()
PATCH[3] improves vhost_get_avail_head(), similar to what we're doing
for vhost_get_avail_idx(), so that the relevant sanity checks
on the head are squeezed to vhost_get_avail_head()
PATCH[4] Reformat vhost_{get, put}_user() by using tab instead of space
as the terminator for each line
Gavin Shan (4):
vhost: Drop variable last_avail_idx in vhost_get_vq_desc()
vhost: Improve vhost_get_avail_idx() with smp_rmb()
vhost: Improve vhost_get_avail_head()
vhost: Reformat vhost_{get, put}_user()
drivers/vhost/vhost.c | 199 +++++++++++++++++++-----------------------
1 file changed, 88 insertions(+), 111 deletions(-)
--
2.44.0
On Tue, Apr 23, 2024 at 01:24:03PM +1000, Gavin Shan wrote:
> This is suggested by Michael S. Tsirkin according to [1] and the goal
> is to apply smp_rmb() inside vhost_get_avail_idx() if needed. With it,
> the caller of the function needn't to worry about memory barriers. Since
> we're here, other cleanups are also applied.
Gavin I suggested another approach.
1. Start with the patch I sent (vhost: order avail ring reads after
index updates) just do a diff against latest.
simplify error handling a bit.
2. Do any other cleanups on top.
> [1] https://lore.kernel.org/virtualization/[email protected]/
>
> PATCH[1] drops the local variable @last_avail_idx since it's equivalent
> to vq->last_avail_idx
> PATCH[2] improves vhost_get_avail_idx() so that smp_rmb() is applied if
> needed. Besides, the sanity checks on the retrieved available
> queue index are also squeezed to vhost_get_avail_idx()
> PATCH[3] improves vhost_get_avail_head(), similar to what we're doing
> for vhost_get_avail_idx(), so that the relevant sanity checks
> on the head are squeezed to vhost_get_avail_head()
> PATCH[4] Reformat vhost_{get, put}_user() by using tab instead of space
> as the terminator for each line
>
> Gavin Shan (4):
> vhost: Drop variable last_avail_idx in vhost_get_vq_desc()
> vhost: Improve vhost_get_avail_idx() with smp_rmb()
> vhost: Improve vhost_get_avail_head()
> vhost: Reformat vhost_{get, put}_user()
>
> drivers/vhost/vhost.c | 199 +++++++++++++++++++-----------------------
> 1 file changed, 88 insertions(+), 111 deletions(-)
>
> --
> 2.44.0
On 4/29/24 17:02, Michael S. Tsirkin wrote:
> On Tue, Apr 23, 2024 at 01:24:03PM +1000, Gavin Shan wrote:
>> This is suggested by Michael S. Tsirkin according to [1] and the goal
>> is to apply smp_rmb() inside vhost_get_avail_idx() if needed. With it,
>> the caller of the function needn't to worry about memory barriers. Since
>> we're here, other cleanups are also applied.
>
>
> Gavin I suggested another approach.
> 1. Start with the patch I sent (vhost: order avail ring reads after
> index updates) just do a diff against latest.
> simplify error handling a bit.
> 2. Do any other cleanups on top.
>
My apologies, Michael. I didn't see your patch until now [1]
[1] https://lore.kernel.org/virtualization/[email protected]/
v2 was sent with your changes integrated and other cleanup are applied on
top of it. Please take a look when you getting a chance.
v2: https://lore.kernel.org/virtualization/[email protected]/T/#t
Thanks,
Gavin