Parav Pandit
2021-Oct-21 16:35 UTC
[PATCH linux-next v4 1/8] vdpa: Introduce and use vdpa device get, set config helpers
Subsequent patches enable get and set configuration either via management device or via vdpa device' config ops. This requires synchronization between multiple callers to get and set config callbacks. Features setting also influence the layout of the configuration fields endianness. To avoid exposing synchronization primitives to callers, introduce helper for setting the configuration and use it. Signed-off-by: Parav Pandit <parav at nvidia.com> Reviewed-by: Eli Cohen <elic at nvidia.com> Acked-by: Jason Wang <jasowang at redhat.com> --- drivers/vdpa/vdpa.c | 36 ++++++++++++++++++++++++++++++++++++ drivers/vhost/vdpa.c | 3 +-- include/linux/vdpa.h | 19 ++++--------------- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 1dc121a07a93..6fdfc11ecb13 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -289,6 +289,42 @@ void vdpa_mgmtdev_unregister(struct vdpa_mgmt_dev *mdev) } EXPORT_SYMBOL_GPL(vdpa_mgmtdev_unregister); +/** + * vdpa_get_config - Get one or more device configuration fields. + * @vdev: vdpa device to operate on + * @offset: starting byte offset of the field + * @buf: buffer pointer to read to + * @len: length of the configuration fields in bytes + */ +void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, + void *buf, unsigned int len) +{ + const struct vdpa_config_ops *ops = vdev->config; + + /* + * Config accesses aren't supposed to trigger before features are set. + * If it does happen we assume a legacy guest. + */ + if (!vdev->features_valid) + vdpa_set_features(vdev, 0); + ops->get_config(vdev, offset, buf, len); +} +EXPORT_SYMBOL_GPL(vdpa_get_config); + +/** + * vdpa_set_config - Set one or more device configuration fields. + * @vdev: vdpa device to operate on + * @offset: starting byte offset of the field + * @buf: buffer pointer to read from + * @length: length of the configuration fields in bytes + */ +void vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, + void *buf, unsigned int length) +{ + vdev->config->set_config(vdev, offset, buf, length); +} +EXPORT_SYMBOL_GPL(vdpa_set_config); + static bool mgmtdev_handle_match(const struct vdpa_mgmt_dev *mdev, const char *busname, const char *devname) { diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 39039e046117..01c59ce7e250 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -237,7 +237,6 @@ static long vhost_vdpa_set_config(struct vhost_vdpa *v, struct vhost_vdpa_config __user *c) { struct vdpa_device *vdpa = v->vdpa; - const struct vdpa_config_ops *ops = vdpa->config; struct vhost_vdpa_config config; unsigned long size = offsetof(struct vhost_vdpa_config, buf); u8 *buf; @@ -251,7 +250,7 @@ static long vhost_vdpa_set_config(struct vhost_vdpa *v, if (IS_ERR(buf)) return PTR_ERR(buf); - ops->set_config(vdpa, config.off, buf, config.len); + vdpa_set_config(vdpa, config.off, buf, config.len); kvfree(buf); return 0; diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 3972ab765de1..78395331a166 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -382,21 +382,10 @@ static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features) return ops->set_features(vdev, features); } -static inline void vdpa_get_config(struct vdpa_device *vdev, - unsigned int offset, void *buf, - unsigned int len) -{ - const struct vdpa_config_ops *ops = vdev->config; - - /* - * Config accesses aren't supposed to trigger before features are set. - * If it does happen we assume a legacy guest. - */ - if (!vdev->features_valid) - vdpa_set_features(vdev, 0); - ops->get_config(vdev, offset, buf, len); -} - +void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, + void *buf, unsigned int len); +void vdpa_set_config(struct vdpa_device *dev, unsigned int offset, + void *buf, unsigned int length); /** * struct vdpa_mgmtdev_ops - vdpa device ops * @dev_add: Add a vdpa device using alloc and register -- 2.25.4
Jason Wang
2021-Oct-25 06:03 UTC
[PATCH linux-next v4 1/8] vdpa: Introduce and use vdpa device get, set config helpers
? 2021/10/22 ??12:35, Parav Pandit ??:> Subsequent patches enable get and set configuration either > via management device or via vdpa device' config ops. > > This requires synchronization between multiple callers to get and set > config callbacks. Features setting also influence the layout of the > configuration fields endianness. > > To avoid exposing synchronization primitives to callers, introduce > helper for setting the configuration and use it. > > Signed-off-by: Parav Pandit <parav at nvidia.com> > Reviewed-by: Eli Cohen <elic at nvidia.com> > Acked-by: Jason Wang <jasowang at redhat.com> > --- > drivers/vdpa/vdpa.c | 36 ++++++++++++++++++++++++++++++++++++ > drivers/vhost/vdpa.c | 3 +-- > include/linux/vdpa.h | 19 ++++---------------Do we need to change virtio_vdpa_set() as well? Thanks> 3 files changed, 41 insertions(+), 17 deletions(-) > > diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c > index 1dc121a07a93..6fdfc11ecb13 100644 > --- a/drivers/vdpa/vdpa.c > +++ b/drivers/vdpa/vdpa.c > @@ -289,6 +289,42 @@ void vdpa_mgmtdev_unregister(struct vdpa_mgmt_dev *mdev) > } > EXPORT_SYMBOL_GPL(vdpa_mgmtdev_unregister); > > +/** > + * vdpa_get_config - Get one or more device configuration fields. > + * @vdev: vdpa device to operate on > + * @offset: starting byte offset of the field > + * @buf: buffer pointer to read to > + * @len: length of the configuration fields in bytes > + */ > +void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, > + void *buf, unsigned int len) > +{ > + const struct vdpa_config_ops *ops = vdev->config; > + > + /* > + * Config accesses aren't supposed to trigger before features are set. > + * If it does happen we assume a legacy guest. > + */ > + if (!vdev->features_valid) > + vdpa_set_features(vdev, 0); > + ops->get_config(vdev, offset, buf, len); > +} > +EXPORT_SYMBOL_GPL(vdpa_get_config); > + > +/** > + * vdpa_set_config - Set one or more device configuration fields. > + * @vdev: vdpa device to operate on > + * @offset: starting byte offset of the field > + * @buf: buffer pointer to read from > + * @length: length of the configuration fields in bytes > + */ > +void vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, > + void *buf, unsigned int length) > +{ > + vdev->config->set_config(vdev, offset, buf, length); > +} > +EXPORT_SYMBOL_GPL(vdpa_set_config); > + > static bool mgmtdev_handle_match(const struct vdpa_mgmt_dev *mdev, > const char *busname, const char *devname) > { > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c > index 39039e046117..01c59ce7e250 100644 > --- a/drivers/vhost/vdpa.c > +++ b/drivers/vhost/vdpa.c > @@ -237,7 +237,6 @@ static long vhost_vdpa_set_config(struct vhost_vdpa *v, > struct vhost_vdpa_config __user *c) > { > struct vdpa_device *vdpa = v->vdpa; > - const struct vdpa_config_ops *ops = vdpa->config; > struct vhost_vdpa_config config; > unsigned long size = offsetof(struct vhost_vdpa_config, buf); > u8 *buf; > @@ -251,7 +250,7 @@ static long vhost_vdpa_set_config(struct vhost_vdpa *v, > if (IS_ERR(buf)) > return PTR_ERR(buf); > > - ops->set_config(vdpa, config.off, buf, config.len); > + vdpa_set_config(vdpa, config.off, buf, config.len); > > kvfree(buf); > return 0; > diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h > index 3972ab765de1..78395331a166 100644 > --- a/include/linux/vdpa.h > +++ b/include/linux/vdpa.h > @@ -382,21 +382,10 @@ static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features) > return ops->set_features(vdev, features); > } > > -static inline void vdpa_get_config(struct vdpa_device *vdev, > - unsigned int offset, void *buf, > - unsigned int len) > -{ > - const struct vdpa_config_ops *ops = vdev->config; > - > - /* > - * Config accesses aren't supposed to trigger before features are set. > - * If it does happen we assume a legacy guest. > - */ > - if (!vdev->features_valid) > - vdpa_set_features(vdev, 0); > - ops->get_config(vdev, offset, buf, len); > -} > - > +void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, > + void *buf, unsigned int len); > +void vdpa_set_config(struct vdpa_device *dev, unsigned int offset, > + void *buf, unsigned int length); > /** > * struct vdpa_mgmtdev_ops - vdpa device ops > * @dev_add: Add a vdpa device using alloc and register