On Wed, Sep 14, 2022 at 2:21 PM Xuan Zhuo <[email protected]> wrote:
>
> On Wed, 14 Sep 2022 11:13:29 +0800, Jason Wang <[email protected]> wrote:
> >
> > 在 2022/9/12 11:10, Kangjie Xu 写道:
> > > Update vhost_net_virtqueue_reset() for vhost-user scenario.
> > >
> > > In order to reuse some functions, we process the idx for
> > > vhost-user scenario because vhost_get_vq_index behave
> > > differently for vhost-user.
> > >
> > > Signed-off-by: Kangjie Xu <[email protected]>
> > > Signed-off-by: Xuan Zhuo <[email protected]>
> > > ---
> > > hw/net/vhost_net.c | 3 +++
> > > 1 file changed, 3 insertions(+)
> > >
> > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> > > index ea896ea75b..25e5665489 100644
> > > --- a/hw/net/vhost_net.c
> > > +++ b/hw/net/vhost_net.c
> > > @@ -545,6 +545,9 @@ void vhost_net_virtqueue_reset(VirtIODevice *vdev,
> > > NetClientState *nc,
> > > assert(vhost_ops);
> > >
> > > idx = vhost_ops->vhost_get_vq_index(&net->dev, vq_index);
> > > + if (net->nc->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
> > > + idx -= net->dev.vq_index;
> > > + }
> >
> >
> > This looks tricky. Any reason we can't simply use vq_index for both
> > vhost-user and vhost-net?
>
>
> static int vhost_user_get_vq_index(struct vhost_dev *dev, int idx)
> {
> assert(idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs);
>
> return idx;
> }
>
>
> static int vhost_kernel_get_vq_index(struct vhost_dev *dev, int idx)
> {
> assert(idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs);
>
> return idx - dev->vq_index;
> }
>
> The implementation of these two callbacks is different. The structure of the
> two
> scenarios is different. We may need to do some optimizations in the future.
Yes, but what I meant is, you do
idx -= net->dev.vq_index;
and then
net->dev.vq_index + idx
This is a hint that we should have a better organization of the code.
Thanks
>
> Thanks.
>
>
> >
> > Thanks
> >
> >
> > >
> > > if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
> > > file.index = idx;
> >
>