[v2,0/2] virtio: abstract virtqueue related methods

Message ID 20230517025424.601141-1-pizhenwei@bytedance.com
Headers
Series virtio: abstract virtqueue related methods |

Message

zhenwei pi May 17, 2023, 2:54 a.m. UTC
  v1 -> v2:
- Suggested by MST, use fast path for vring based performance
sensitive API.
- Reduce changes in tools/virtio.

Add test result(no obvious change):
Before:
time ./vringh_test --parallel
Using CPUS 0 and 191
Guest: notified 10036893, pinged 68278
Host: notified 68278, pinged 3093532

real	0m14.463s
user	0m6.437s
sys	0m8.010s

After:
time ./vringh_test --parallel
Using CPUS 0 and 191
Guest: notified 10036709, pinged 68347
Host: notified 68347, pinged 3085292

real	0m14.196s
user	0m6.289s
sys	0m7.885s

v1:
Hi,

3 weeks ago, I posted a proposal 'Virtio Over Fabrics':
https://lists.oasis-open.org/archives/virtio-comment/202304/msg00442.html

Jason and Stefan pointed out that a non-vring based virtqueue has a
chance to overwrite virtqueue instead of using vring virtqueue.

Then I try to abstract virtqueue related methods in this series, the
details changes see the comment of patch 'virtio: abstract virtqueue related methods'.

Something is still remained:
- __virtqueue_break/__virtqueue_unbreak is supposed to use by internal
  virtio core, I'd like to rename them to vring_virtqueue_break
  /vring_virtqueue_unbreak. Is this reasonable?
- virtqueue_get_desc_addr/virtqueue_get_avail_addr/virtqueue_get_used_addr
  /virtqueue_get_vring is vring specific, I'd like to rename them like
  vring_virtqueue_get_desc_addr. Is this reasonable?
- there are still some functions in virtio_ring.c with prefix *virtqueue*,
  for example 'virtqueue_add_split', just keep it or rename it to
  'vring_virtqueue_add_split'?
zhenwei pi (2):
  virtio: abstract virtqueue related methods
  tools/virtio: implement virtqueue in test

 drivers/virtio/virtio_ring.c | 285 +++++-----------------
 include/linux/virtio.h       | 441 +++++++++++++++++++++++++++++++----
 include/linux/virtio_ring.h  |  26 +++
 tools/virtio/linux/virtio.h  | 355 +++++++++++++++++++++++++---
 4 files changed, 807 insertions(+), 300 deletions(-)
  

Comments

Michael S. Tsirkin May 17, 2023, 3:46 a.m. UTC | #1
On Wed, May 17, 2023 at 10:54:22AM +0800, zhenwei pi wrote:
> v1 -> v2:
> - Suggested by MST, use fast path for vring based performance
> sensitive API.
> - Reduce changes in tools/virtio.
> 
> Add test result(no obvious change):
> Before:
> time ./vringh_test --parallel
> Using CPUS 0 and 191
> Guest: notified 10036893, pinged 68278
> Host: notified 68278, pinged 3093532
> 
> real	0m14.463s
> user	0m6.437s
> sys	0m8.010s
> 
> After:
> time ./vringh_test --parallel
> Using CPUS 0 and 191
> Guest: notified 10036709, pinged 68347
> Host: notified 68347, pinged 3085292
> 
> real	0m14.196s
> user	0m6.289s
> sys	0m7.885s
> 
> v1:
> Hi,
> 
> 3 weeks ago, I posted a proposal 'Virtio Over Fabrics':
> https://lists.oasis-open.org/archives/virtio-comment/202304/msg00442.html
> 
> Jason and Stefan pointed out that a non-vring based virtqueue has a
> chance to overwrite virtqueue instead of using vring virtqueue.
> 
> Then I try to abstract virtqueue related methods in this series, the
> details changes see the comment of patch 'virtio: abstract virtqueue related methods'.
> 
> Something is still remained:
> - __virtqueue_break/__virtqueue_unbreak is supposed to use by internal
>   virtio core, I'd like to rename them to vring_virtqueue_break
>   /vring_virtqueue_unbreak. Is this reasonable?

Why? These just set a flag?

> - virtqueue_get_desc_addr/virtqueue_get_avail_addr/virtqueue_get_used_addr
>   /virtqueue_get_vring is vring specific, I'd like to rename them like
>   vring_virtqueue_get_desc_addr. Is this reasonable?
> - there are still some functions in virtio_ring.c with prefix *virtqueue*,
>   for example 'virtqueue_add_split', just keep it or rename it to
>   'vring_virtqueue_add_split'?
> zhenwei pi (2):
>   virtio: abstract virtqueue related methods
>   tools/virtio: implement virtqueue in test
> 
>  drivers/virtio/virtio_ring.c | 285 +++++-----------------
>  include/linux/virtio.h       | 441 +++++++++++++++++++++++++++++++----
>  include/linux/virtio_ring.h  |  26 +++
>  tools/virtio/linux/virtio.h  | 355 +++++++++++++++++++++++++---
>  4 files changed, 807 insertions(+), 300 deletions(-)
> 
> -- 
> 2.20.1
  
zhenwei pi May 17, 2023, 3:51 a.m. UTC | #2
On 5/17/23 11:46, Michael S. Tsirkin wrote:
> On Wed, May 17, 2023 at 10:54:22AM +0800, zhenwei pi wrote:
>> v1 -> v2:
>> - Suggested by MST, use fast path for vring based performance
>> sensitive API.
>> - Reduce changes in tools/virtio.
>>
>> Add test result(no obvious change):
>> Before:
>> time ./vringh_test --parallel
>> Using CPUS 0 and 191
>> Guest: notified 10036893, pinged 68278
>> Host: notified 68278, pinged 3093532
>>
>> real	0m14.463s
>> user	0m6.437s
>> sys	0m8.010s
>>
>> After:
>> time ./vringh_test --parallel
>> Using CPUS 0 and 191
>> Guest: notified 10036709, pinged 68347
>> Host: notified 68347, pinged 3085292
>>
>> real	0m14.196s
>> user	0m6.289s
>> sys	0m7.885s
>>
>> v1:
>> Hi,
>>
>> 3 weeks ago, I posted a proposal 'Virtio Over Fabrics':
>> https://lists.oasis-open.org/archives/virtio-comment/202304/msg00442.html
>>
>> Jason and Stefan pointed out that a non-vring based virtqueue has a
>> chance to overwrite virtqueue instead of using vring virtqueue.
>>
>> Then I try to abstract virtqueue related methods in this series, the
>> details changes see the comment of patch 'virtio: abstract virtqueue related methods'.
>>
>> Something is still remained:
>> - __virtqueue_break/__virtqueue_unbreak is supposed to use by internal
>>    virtio core, I'd like to rename them to vring_virtqueue_break
>>    /vring_virtqueue_unbreak. Is this reasonable?
> 
> Why? These just set a flag?
> 

Rename '__virtqueue_break' to 'vring_virtqueue_break', to make symbols 
exported from virtio_ring.ko have unified prefix 'vring_virtqueue_xxx'.

>> - virtqueue_get_desc_addr/virtqueue_get_avail_addr/virtqueue_get_used_addr
>>    /virtqueue_get_vring is vring specific, I'd like to rename them like
>>    vring_virtqueue_get_desc_addr. Is this reasonable?
>> - there are still some functions in virtio_ring.c with prefix *virtqueue*,
>>    for example 'virtqueue_add_split', just keep it or rename it to
>>    'vring_virtqueue_add_split'?
>> zhenwei pi (2):
>>    virtio: abstract virtqueue related methods
>>    tools/virtio: implement virtqueue in test
>>
>>   drivers/virtio/virtio_ring.c | 285 +++++-----------------
>>   include/linux/virtio.h       | 441 +++++++++++++++++++++++++++++++----
>>   include/linux/virtio_ring.h  |  26 +++
>>   tools/virtio/linux/virtio.h  | 355 +++++++++++++++++++++++++---
>>   4 files changed, 807 insertions(+), 300 deletions(-)
>>
>> -- 
>> 2.20.1
>
  
Michael S. Tsirkin May 17, 2023, 3:57 a.m. UTC | #3
On Wed, May 17, 2023 at 11:51:03AM +0800, zhenwei pi wrote:
> 
> 
> On 5/17/23 11:46, Michael S. Tsirkin wrote:
> > On Wed, May 17, 2023 at 10:54:22AM +0800, zhenwei pi wrote:
> > > v1 -> v2:
> > > - Suggested by MST, use fast path for vring based performance
> > > sensitive API.
> > > - Reduce changes in tools/virtio.
> > > 
> > > Add test result(no obvious change):
> > > Before:
> > > time ./vringh_test --parallel
> > > Using CPUS 0 and 191
> > > Guest: notified 10036893, pinged 68278
> > > Host: notified 68278, pinged 3093532
> > > 
> > > real	0m14.463s
> > > user	0m6.437s
> > > sys	0m8.010s
> > > 
> > > After:
> > > time ./vringh_test --parallel
> > > Using CPUS 0 and 191
> > > Guest: notified 10036709, pinged 68347
> > > Host: notified 68347, pinged 3085292
> > > 
> > > real	0m14.196s
> > > user	0m6.289s
> > > sys	0m7.885s
> > > 
> > > v1:
> > > Hi,
> > > 
> > > 3 weeks ago, I posted a proposal 'Virtio Over Fabrics':
> > > https://lists.oasis-open.org/archives/virtio-comment/202304/msg00442.html
> > > 
> > > Jason and Stefan pointed out that a non-vring based virtqueue has a
> > > chance to overwrite virtqueue instead of using vring virtqueue.
> > > 
> > > Then I try to abstract virtqueue related methods in this series, the
> > > details changes see the comment of patch 'virtio: abstract virtqueue related methods'.
> > > 
> > > Something is still remained:
> > > - __virtqueue_break/__virtqueue_unbreak is supposed to use by internal
> > >    virtio core, I'd like to rename them to vring_virtqueue_break
> > >    /vring_virtqueue_unbreak. Is this reasonable?
> > 
> > Why? These just set a flag?
> > 
> 
> Rename '__virtqueue_break' to 'vring_virtqueue_break', to make symbols
> exported from virtio_ring.ko have unified prefix 'vring_virtqueue_xxx'.

I just do not see why you need these callbacks at all.

> > > - virtqueue_get_desc_addr/virtqueue_get_avail_addr/virtqueue_get_used_addr
> > >    /virtqueue_get_vring is vring specific, I'd like to rename them like
> > >    vring_virtqueue_get_desc_addr. Is this reasonable?
> > > - there are still some functions in virtio_ring.c with prefix *virtqueue*,
> > >    for example 'virtqueue_add_split', just keep it or rename it to
> > >    'vring_virtqueue_add_split'?
> > > zhenwei pi (2):
> > >    virtio: abstract virtqueue related methods
> > >    tools/virtio: implement virtqueue in test
> > > 
> > >   drivers/virtio/virtio_ring.c | 285 +++++-----------------
> > >   include/linux/virtio.h       | 441 +++++++++++++++++++++++++++++++----
> > >   include/linux/virtio_ring.h  |  26 +++
> > >   tools/virtio/linux/virtio.h  | 355 +++++++++++++++++++++++++---
> > >   4 files changed, 807 insertions(+), 300 deletions(-)
> > > 
> > > -- 
> > > 2.20.1
> > 
> 
> -- 
> zhenwei pi
  
zhenwei pi May 17, 2023, 4:58 a.m. UTC | #4
On 5/17/23 11:57, Michael S. Tsirkin wrote:
> On Wed, May 17, 2023 at 11:51:03AM +0800, zhenwei pi wrote:
>>
>>
>> On 5/17/23 11:46, Michael S. Tsirkin wrote:
>>> On Wed, May 17, 2023 at 10:54:22AM +0800, zhenwei pi wrote:
>>>> v1 -> v2:
>>>> - Suggested by MST, use fast path for vring based performance
>>>> sensitive API.
>>>> - Reduce changes in tools/virtio.
>>>>
>>>> Add test result(no obvious change):
>>>> Before:
>>>> time ./vringh_test --parallel
>>>> Using CPUS 0 and 191
>>>> Guest: notified 10036893, pinged 68278
>>>> Host: notified 68278, pinged 3093532
>>>>
>>>> real	0m14.463s
>>>> user	0m6.437s
>>>> sys	0m8.010s
>>>>
>>>> After:
>>>> time ./vringh_test --parallel
>>>> Using CPUS 0 and 191
>>>> Guest: notified 10036709, pinged 68347
>>>> Host: notified 68347, pinged 3085292
>>>>
>>>> real	0m14.196s
>>>> user	0m6.289s
>>>> sys	0m7.885s
>>>>
>>>> v1:
>>>> Hi,
>>>>
>>>> 3 weeks ago, I posted a proposal 'Virtio Over Fabrics':
>>>> https://lists.oasis-open.org/archives/virtio-comment/202304/msg00442.html
>>>>
>>>> Jason and Stefan pointed out that a non-vring based virtqueue has a
>>>> chance to overwrite virtqueue instead of using vring virtqueue.
>>>>
>>>> Then I try to abstract virtqueue related methods in this series, the
>>>> details changes see the comment of patch 'virtio: abstract virtqueue related methods'.
>>>>
>>>> Something is still remained:
>>>> - __virtqueue_break/__virtqueue_unbreak is supposed to use by internal
>>>>     virtio core, I'd like to rename them to vring_virtqueue_break
>>>>     /vring_virtqueue_unbreak. Is this reasonable?
>>>
>>> Why? These just set a flag?
>>>
>>
>> Rename '__virtqueue_break' to 'vring_virtqueue_break', to make symbols
>> exported from virtio_ring.ko have unified prefix 'vring_virtqueue_xxx'.
> 
> I just do not see why you need these callbacks at all.
> 

I use these callbacks for break/unbreak device like:
static inline void virtio_break_device(struct virtio_device *dev)
{
	struct virtqueue *vq;

	spin_lock(&dev->vqs_list_lock);
	list_for_each_entry(vq, &dev->vqs, list) {
		vq->__break(vq);
	}
	spin_unlock(&dev->vqs_list_lock);
}

>>>> - virtqueue_get_desc_addr/virtqueue_get_avail_addr/virtqueue_get_used_addr
>>>>     /virtqueue_get_vring is vring specific, I'd like to rename them like
>>>>     vring_virtqueue_get_desc_addr. Is this reasonable?
>>>> - there are still some functions in virtio_ring.c with prefix *virtqueue*,
>>>>     for example 'virtqueue_add_split', just keep it or rename it to
>>>>     'vring_virtqueue_add_split'?
>>>> zhenwei pi (2):
>>>>     virtio: abstract virtqueue related methods
>>>>     tools/virtio: implement virtqueue in test
>>>>
>>>>    drivers/virtio/virtio_ring.c | 285 +++++-----------------
>>>>    include/linux/virtio.h       | 441 +++++++++++++++++++++++++++++++----
>>>>    include/linux/virtio_ring.h  |  26 +++
>>>>    tools/virtio/linux/virtio.h  | 355 +++++++++++++++++++++++++---
>>>>    4 files changed, 807 insertions(+), 300 deletions(-)
>>>>
>>>> -- 
>>>> 2.20.1
>>>
>>
>> -- 
>> zhenwei pi
>
  
Michael S. Tsirkin May 17, 2023, 6:10 a.m. UTC | #5
On Wed, May 17, 2023 at 12:58:10PM +0800, zhenwei pi wrote:
> On 5/17/23 11:57, Michael S. Tsirkin wrote:
> > On Wed, May 17, 2023 at 11:51:03AM +0800, zhenwei pi wrote:
> > > 
> > > 
> > > On 5/17/23 11:46, Michael S. Tsirkin wrote:
> > > > On Wed, May 17, 2023 at 10:54:22AM +0800, zhenwei pi wrote:
> > > > > v1 -> v2:
> > > > > - Suggested by MST, use fast path for vring based performance
> > > > > sensitive API.
> > > > > - Reduce changes in tools/virtio.
> > > > > 
> > > > > Add test result(no obvious change):
> > > > > Before:
> > > > > time ./vringh_test --parallel
> > > > > Using CPUS 0 and 191
> > > > > Guest: notified 10036893, pinged 68278
> > > > > Host: notified 68278, pinged 3093532
> > > > > 
> > > > > real	0m14.463s
> > > > > user	0m6.437s
> > > > > sys	0m8.010s
> > > > > 
> > > > > After:
> > > > > time ./vringh_test --parallel
> > > > > Using CPUS 0 and 191
> > > > > Guest: notified 10036709, pinged 68347
> > > > > Host: notified 68347, pinged 3085292
> > > > > 
> > > > > real	0m14.196s
> > > > > user	0m6.289s
> > > > > sys	0m7.885s
> > > > > 
> > > > > v1:
> > > > > Hi,
> > > > > 
> > > > > 3 weeks ago, I posted a proposal 'Virtio Over Fabrics':
> > > > > https://lists.oasis-open.org/archives/virtio-comment/202304/msg00442.html
> > > > > 
> > > > > Jason and Stefan pointed out that a non-vring based virtqueue has a
> > > > > chance to overwrite virtqueue instead of using vring virtqueue.
> > > > > 
> > > > > Then I try to abstract virtqueue related methods in this series, the
> > > > > details changes see the comment of patch 'virtio: abstract virtqueue related methods'.
> > > > > 
> > > > > Something is still remained:
> > > > > - __virtqueue_break/__virtqueue_unbreak is supposed to use by internal
> > > > >     virtio core, I'd like to rename them to vring_virtqueue_break
> > > > >     /vring_virtqueue_unbreak. Is this reasonable?
> > > > 
> > > > Why? These just set a flag?
> > > > 
> > > 
> > > Rename '__virtqueue_break' to 'vring_virtqueue_break', to make symbols
> > > exported from virtio_ring.ko have unified prefix 'vring_virtqueue_xxx'.
> > 
> > I just do not see why you need these callbacks at all.
> > 
> 
> I use these callbacks for break/unbreak device like:
> static inline void virtio_break_device(struct virtio_device *dev)
> {
> 	struct virtqueue *vq;
> 
> 	spin_lock(&dev->vqs_list_lock);
> 	list_for_each_entry(vq, &dev->vqs, list) {
> 		vq->__break(vq);
> 	}
> 	spin_unlock(&dev->vqs_list_lock);
> }

why do this? backend knows they are broken.

> > > > > - virtqueue_get_desc_addr/virtqueue_get_avail_addr/virtqueue_get_used_addr
> > > > >     /virtqueue_get_vring is vring specific, I'd like to rename them like
> > > > >     vring_virtqueue_get_desc_addr. Is this reasonable?
> > > > > - there are still some functions in virtio_ring.c with prefix *virtqueue*,
> > > > >     for example 'virtqueue_add_split', just keep it or rename it to
> > > > >     'vring_virtqueue_add_split'?
> > > > > zhenwei pi (2):
> > > > >     virtio: abstract virtqueue related methods
> > > > >     tools/virtio: implement virtqueue in test
> > > > > 
> > > > >    drivers/virtio/virtio_ring.c | 285 +++++-----------------
> > > > >    include/linux/virtio.h       | 441 +++++++++++++++++++++++++++++++----
> > > > >    include/linux/virtio_ring.h  |  26 +++
> > > > >    tools/virtio/linux/virtio.h  | 355 +++++++++++++++++++++++++---
> > > > >    4 files changed, 807 insertions(+), 300 deletions(-)
> > > > > 
> > > > > -- 
> > > > > 2.20.1
> > > > 
> > > 
> > > -- 
> > > zhenwei pi
> > 
> 
> -- 
> zhenwei pi
  
zhenwei pi May 17, 2023, 6:21 a.m. UTC | #6
On 5/17/23 14:10, Michael S. Tsirkin wrote:
> On Wed, May 17, 2023 at 12:58:10PM +0800, zhenwei pi wrote:
>> On 5/17/23 11:57, Michael S. Tsirkin wrote:
>>> On Wed, May 17, 2023 at 11:51:03AM +0800, zhenwei pi wrote:
>>>>
>>>>
>>>> On 5/17/23 11:46, Michael S. Tsirkin wrote:
>>>>> On Wed, May 17, 2023 at 10:54:22AM +0800, zhenwei pi wrote:
>>>>>> v1 -> v2:
>>>>>> - Suggested by MST, use fast path for vring based performance
>>>>>> sensitive API.
>>>>>> - Reduce changes in tools/virtio.
>>>>>>
>>>>>> Add test result(no obvious change):
>>>>>> Before:
>>>>>> time ./vringh_test --parallel
>>>>>> Using CPUS 0 and 191
>>>>>> Guest: notified 10036893, pinged 68278
>>>>>> Host: notified 68278, pinged 3093532
>>>>>>
>>>>>> real	0m14.463s
>>>>>> user	0m6.437s
>>>>>> sys	0m8.010s
>>>>>>
>>>>>> After:
>>>>>> time ./vringh_test --parallel
>>>>>> Using CPUS 0 and 191
>>>>>> Guest: notified 10036709, pinged 68347
>>>>>> Host: notified 68347, pinged 3085292
>>>>>>
>>>>>> real	0m14.196s
>>>>>> user	0m6.289s
>>>>>> sys	0m7.885s
>>>>>>
>>>>>> v1:
>>>>>> Hi,
>>>>>>
>>>>>> 3 weeks ago, I posted a proposal 'Virtio Over Fabrics':
>>>>>> https://lists.oasis-open.org/archives/virtio-comment/202304/msg00442.html
>>>>>>
>>>>>> Jason and Stefan pointed out that a non-vring based virtqueue has a
>>>>>> chance to overwrite virtqueue instead of using vring virtqueue.
>>>>>>
>>>>>> Then I try to abstract virtqueue related methods in this series, the
>>>>>> details changes see the comment of patch 'virtio: abstract virtqueue related methods'.
>>>>>>
>>>>>> Something is still remained:
>>>>>> - __virtqueue_break/__virtqueue_unbreak is supposed to use by internal
>>>>>>      virtio core, I'd like to rename them to vring_virtqueue_break
>>>>>>      /vring_virtqueue_unbreak. Is this reasonable?
>>>>>
>>>>> Why? These just set a flag?
>>>>>
>>>>
>>>> Rename '__virtqueue_break' to 'vring_virtqueue_break', to make symbols
>>>> exported from virtio_ring.ko have unified prefix 'vring_virtqueue_xxx'.
>>>
>>> I just do not see why you need these callbacks at all.
>>>
>>
>> I use these callbacks for break/unbreak device like:
>> static inline void virtio_break_device(struct virtio_device *dev)
>> {
>> 	struct virtqueue *vq;
>>
>> 	spin_lock(&dev->vqs_list_lock);
>> 	list_for_each_entry(vq, &dev->vqs, list) {
>> 		vq->__break(vq);
>> 	}
>> 	spin_unlock(&dev->vqs_list_lock);
>> }
> 
> why do this? backend knows they are broken.
> 

I grep 'virtio_break_device' in the latest code:
arch/um/drivers/virtio_uml.c:1147:	virtio_break_device(&vu_dev->vdev);
arch/um/drivers/virtio_uml.c:1285:	virtio_break_device(&vu_dev->vdev);
drivers/crypto/virtio/virtio_crypto_core.c:269:	 
virtio_break_device(vcrypto->vdev);
drivers/s390/virtio/virtio_ccw.c:1251:			virtio_break_device(&vcdev->vdev);
drivers/s390/virtio/virtio_ccw.c:1268:		virtio_break_device(&vcdev->vdev);
drivers/firmware/arm_scmi/virtio.c:489: 
virtio_break_device(vioch->vqueue->vdev);
drivers/char/virtio_console.c:1956:	virtio_break_device(vdev);

Some virtio drivers use 'virtio_break_device'...

>>>>>> - virtqueue_get_desc_addr/virtqueue_get_avail_addr/virtqueue_get_used_addr
>>>>>>      /virtqueue_get_vring is vring specific, I'd like to rename them like
>>>>>>      vring_virtqueue_get_desc_addr. Is this reasonable?
>>>>>> - there are still some functions in virtio_ring.c with prefix *virtqueue*,
>>>>>>      for example 'virtqueue_add_split', just keep it or rename it to
>>>>>>      'vring_virtqueue_add_split'?
>>>>>> zhenwei pi (2):
>>>>>>      virtio: abstract virtqueue related methods
>>>>>>      tools/virtio: implement virtqueue in test
>>>>>>
>>>>>>     drivers/virtio/virtio_ring.c | 285 +++++-----------------
>>>>>>     include/linux/virtio.h       | 441 +++++++++++++++++++++++++++++++----
>>>>>>     include/linux/virtio_ring.h  |  26 +++
>>>>>>     tools/virtio/linux/virtio.h  | 355 +++++++++++++++++++++++++---
>>>>>>     4 files changed, 807 insertions(+), 300 deletions(-)
>>>>>>
>>>>>> -- 
>>>>>> 2.20.1
>>>>>
>>>>
>>>> -- 
>>>> zhenwei pi
>>>
>>
>> -- 
>> zhenwei pi
>
  
Michael S. Tsirkin May 17, 2023, 10:13 a.m. UTC | #7
On Wed, May 17, 2023 at 02:21:09PM +0800, zhenwei pi wrote:
> On 5/17/23 14:10, Michael S. Tsirkin wrote:
> > On Wed, May 17, 2023 at 12:58:10PM +0800, zhenwei pi wrote:
> > > On 5/17/23 11:57, Michael S. Tsirkin wrote:
> > > > On Wed, May 17, 2023 at 11:51:03AM +0800, zhenwei pi wrote:
> > > > > 
> > > > > 
> > > > > On 5/17/23 11:46, Michael S. Tsirkin wrote:
> > > > > > On Wed, May 17, 2023 at 10:54:22AM +0800, zhenwei pi wrote:
> > > > > > > v1 -> v2:
> > > > > > > - Suggested by MST, use fast path for vring based performance
> > > > > > > sensitive API.
> > > > > > > - Reduce changes in tools/virtio.
> > > > > > > 
> > > > > > > Add test result(no obvious change):
> > > > > > > Before:
> > > > > > > time ./vringh_test --parallel
> > > > > > > Using CPUS 0 and 191
> > > > > > > Guest: notified 10036893, pinged 68278
> > > > > > > Host: notified 68278, pinged 3093532
> > > > > > > 
> > > > > > > real	0m14.463s
> > > > > > > user	0m6.437s
> > > > > > > sys	0m8.010s
> > > > > > > 
> > > > > > > After:
> > > > > > > time ./vringh_test --parallel
> > > > > > > Using CPUS 0 and 191
> > > > > > > Guest: notified 10036709, pinged 68347
> > > > > > > Host: notified 68347, pinged 3085292
> > > > > > > 
> > > > > > > real	0m14.196s
> > > > > > > user	0m6.289s
> > > > > > > sys	0m7.885s
> > > > > > > 
> > > > > > > v1:
> > > > > > > Hi,
> > > > > > > 
> > > > > > > 3 weeks ago, I posted a proposal 'Virtio Over Fabrics':
> > > > > > > https://lists.oasis-open.org/archives/virtio-comment/202304/msg00442.html
> > > > > > > 
> > > > > > > Jason and Stefan pointed out that a non-vring based virtqueue has a
> > > > > > > chance to overwrite virtqueue instead of using vring virtqueue.
> > > > > > > 
> > > > > > > Then I try to abstract virtqueue related methods in this series, the
> > > > > > > details changes see the comment of patch 'virtio: abstract virtqueue related methods'.
> > > > > > > 
> > > > > > > Something is still remained:
> > > > > > > - __virtqueue_break/__virtqueue_unbreak is supposed to use by internal
> > > > > > >      virtio core, I'd like to rename them to vring_virtqueue_break
> > > > > > >      /vring_virtqueue_unbreak. Is this reasonable?
> > > > > > 
> > > > > > Why? These just set a flag?
> > > > > > 
> > > > > 
> > > > > Rename '__virtqueue_break' to 'vring_virtqueue_break', to make symbols
> > > > > exported from virtio_ring.ko have unified prefix 'vring_virtqueue_xxx'.
> > > > 
> > > > I just do not see why you need these callbacks at all.
> > > > 
> > > 
> > > I use these callbacks for break/unbreak device like:
> > > static inline void virtio_break_device(struct virtio_device *dev)
> > > {
> > > 	struct virtqueue *vq;
> > > 
> > > 	spin_lock(&dev->vqs_list_lock);
> > > 	list_for_each_entry(vq, &dev->vqs, list) {
> > > 		vq->__break(vq);
> > > 	}
> > > 	spin_unlock(&dev->vqs_list_lock);
> > > }
> > 
> > why do this? backend knows they are broken.
> > 
> 
> I grep 'virtio_break_device' in the latest code:
> arch/um/drivers/virtio_uml.c:1147:	virtio_break_device(&vu_dev->vdev);
> arch/um/drivers/virtio_uml.c:1285:	virtio_break_device(&vu_dev->vdev);
> drivers/crypto/virtio/virtio_crypto_core.c:269:	
> virtio_break_device(vcrypto->vdev);
> drivers/s390/virtio/virtio_ccw.c:1251:			virtio_break_device(&vcdev->vdev);
> drivers/s390/virtio/virtio_ccw.c:1268:		virtio_break_device(&vcdev->vdev);
> drivers/firmware/arm_scmi/virtio.c:489:
> virtio_break_device(vioch->vqueue->vdev);
> drivers/char/virtio_console.c:1956:	virtio_break_device(vdev);
> 
> Some virtio drivers use 'virtio_break_device'...

You should read the code and understand what it does,
not just grep things and make assumptions.
What virtio_break_device does is stop linux from sending
new requests.


> > > > > > > - virtqueue_get_desc_addr/virtqueue_get_avail_addr/virtqueue_get_used_addr
> > > > > > >      /virtqueue_get_vring is vring specific, I'd like to rename them like
> > > > > > >      vring_virtqueue_get_desc_addr. Is this reasonable?
> > > > > > > - there are still some functions in virtio_ring.c with prefix *virtqueue*,
> > > > > > >      for example 'virtqueue_add_split', just keep it or rename it to
> > > > > > >      'vring_virtqueue_add_split'?
> > > > > > > zhenwei pi (2):
> > > > > > >      virtio: abstract virtqueue related methods
> > > > > > >      tools/virtio: implement virtqueue in test
> > > > > > > 
> > > > > > >     drivers/virtio/virtio_ring.c | 285 +++++-----------------
> > > > > > >     include/linux/virtio.h       | 441 +++++++++++++++++++++++++++++++----
> > > > > > >     include/linux/virtio_ring.h  |  26 +++
> > > > > > >     tools/virtio/linux/virtio.h  | 355 +++++++++++++++++++++++++---
> > > > > > >     4 files changed, 807 insertions(+), 300 deletions(-)
> > > > > > > 
> > > > > > > -- 
> > > > > > > 2.20.1
> > > > > > 
> > > > > 
> > > > > -- 
> > > > > zhenwei pi
> > > > 
> > > 
> > > -- 
> > > zhenwei pi
> > 
> 
> -- 
> zhenwei pi