Re: [PATCH v11 04/12] vdpa: Add reset callback in vdpa_config_ops
From: Yongji Xie
Date: Mon Aug 23 2021 - 03:45:16 EST
On Mon, Aug 23, 2021 at 2:31 PM Jason Wang <jasowang@xxxxxxxxxx> wrote:
>
>
> 在 2021/8/18 下午8:06, Xie Yongji 写道:
> > This adds a new callback to support device specific reset
> > behavior. The vdpa bus driver will call the reset function
> > instead of setting status to zero during resetting if device
> > driver supports the new callback.
> >
> > Signed-off-by: Xie Yongji <xieyongji@xxxxxxxxxxxxx>
> > ---
> > drivers/vhost/vdpa.c | 9 +++++++--
> > include/linux/vdpa.h | 11 ++++++++++-
> > 2 files changed, 17 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> > index b07aa161f7ad..b1c91b4db0ba 100644
> > --- a/drivers/vhost/vdpa.c
> > +++ b/drivers/vhost/vdpa.c
> > @@ -157,7 +157,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
> > struct vdpa_device *vdpa = v->vdpa;
> > const struct vdpa_config_ops *ops = vdpa->config;
> > u8 status, status_old;
> > - int nvqs = v->nvqs;
> > + int ret, nvqs = v->nvqs;
> > u16 i;
> >
> > if (copy_from_user(&status, statusp, sizeof(status)))
> > @@ -172,7 +172,12 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
> > if (status != 0 && (ops->get_status(vdpa) & ~status) != 0)
> > return -EINVAL;
> >
> > - ops->set_status(vdpa, status);
> > + if (status == 0 && ops->reset) {
> > + ret = ops->reset(vdpa);
> > + if (ret)
> > + return ret;
> > + } else
> > + ops->set_status(vdpa, status);
> >
> > if ((status & VIRTIO_CONFIG_S_DRIVER_OK) && !(status_old & VIRTIO_CONFIG_S_DRIVER_OK))
> > for (i = 0; i < nvqs; i++)
> > diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
> > index 8a645f8f4476..af7ea5ad795f 100644
> > --- a/include/linux/vdpa.h
> > +++ b/include/linux/vdpa.h
> > @@ -196,6 +196,9 @@ struct vdpa_iova_range {
> > * @vdev: vdpa device
> > * Returns the iova range supported by
> > * the device.
> > + * @reset: Reset device (optional)
> > + * @vdev: vdpa device
> > + * Returns integer: success (0) or error (< 0)
>
>
> It looks to me we'd better make this mandatory. This help to reduce the
> confusion for the parent driver.
>
OK, will do it in next version.
Thanks,
Yongji