Jason Wang
2022-Apr-06 08:35 UTC
[PATCH V2 3/5] virtio: introduce config op to synchronize vring callbacks
This patch introduce a new virtio config ops to vring callbacks. Transport specific method is required to call synchornize_irq() on the IRQs. For the transport that doesn't provide synchronize_vqs(), use synchornize_rcu() as a fallback. Cc: Thomas Gleixner <tglx at linutronix.de> Cc: Peter Zijlstra <peterz at infradead.org> Cc: "Paul E. McKenney" <paulmck at kernel.org> Cc: Marc Zyngier <maz at kernel.org> Signed-off-by: Jason Wang <jasowang at redhat.com> --- include/linux/virtio_config.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index b341dd62aa4d..08b73d9bbff2 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -57,6 +57,8 @@ struct virtio_shm_region { * include a NULL entry for vqs unused by driver * Returns 0 on success or error status * @del_vqs: free virtqueues found by find_vqs(). + * @synchronize_vqs: synchronize with the virtqueue callbacks. + * vdev: the virtio_device * @get_features: get the array of feature bits for this device. * vdev: the virtio_device * Returns the first 64 feature bits (all we currently need). @@ -89,6 +91,7 @@ struct virtio_config_ops { const char * const names[], const bool *ctx, struct irq_affinity *desc); void (*del_vqs)(struct virtio_device *); + void (*synchronize_vqs)(struct virtio_device *); u64 (*get_features)(struct virtio_device *vdev); int (*finalize_features)(struct virtio_device *vdev); const char *(*bus_name)(struct virtio_device *vdev); @@ -217,6 +220,19 @@ int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs, desc); } +/** + * virtio_synchronize_vqs - synchronize with virtqueue callbacks + * @vdev: the device + */ +static inline +void virtio_synchronize_vqs(struct virtio_device *dev) +{ + if (dev->config->synchronize_vqs) + dev->config->synchronize_vqs(dev); + else + synchronize_rcu(); +} + /** * virtio_device_ready - enable vq use in probe function * @vdev: the device -- 2.25.1
Michael S. Tsirkin
2022-Apr-06 11:59 UTC
[PATCH V2 3/5] virtio: introduce config op to synchronize vring callbacks
On Wed, Apr 06, 2022 at 04:35:36PM +0800, Jason Wang wrote:> This patch introduceintroduces> a newnew> virtio config ops to vring > callbacks. Transport specific method is required to call > synchornize_irq() on the IRQs. For the transport that doesn't provide > synchronize_vqs(), use synchornize_rcu() as a fallback. > > Cc: Thomas Gleixner <tglx at linutronix.de> > Cc: Peter Zijlstra <peterz at infradead.org> > Cc: "Paul E. McKenney" <paulmck at kernel.org> > Cc: Marc Zyngier <maz at kernel.org> > Signed-off-by: Jason Wang <jasowang at redhat.com> > --- > include/linux/virtio_config.h | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h > index b341dd62aa4d..08b73d9bbff2 100644 > --- a/include/linux/virtio_config.h > +++ b/include/linux/virtio_config.h > @@ -57,6 +57,8 @@ struct virtio_shm_region { > * include a NULL entry for vqs unused by driver > * Returns 0 on success or error status > * @del_vqs: free virtqueues found by find_vqs(). > + * @synchronize_vqs: synchronize with the virtqueue callbacks. > + * vdev: the virtio_deviceI think I prefer synchronize_callbacks> * @get_features: get the array of feature bits for this device. > * vdev: the virtio_device > * Returns the first 64 feature bits (all we currently need). > @@ -89,6 +91,7 @@ struct virtio_config_ops { > const char * const names[], const bool *ctx, > struct irq_affinity *desc); > void (*del_vqs)(struct virtio_device *); > + void (*synchronize_vqs)(struct virtio_device *); > u64 (*get_features)(struct virtio_device *vdev); > int (*finalize_features)(struct virtio_device *vdev); > const char *(*bus_name)(struct virtio_device *vdev); > @@ -217,6 +220,19 @@ int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs, > desc); > } > > +/** > + * virtio_synchronize_vqs - synchronize with virtqueue callbacks > + * @vdev: the device > + */ > +static inline > +void virtio_synchronize_vqs(struct virtio_device *dev) > +{ > + if (dev->config->synchronize_vqs) > + dev->config->synchronize_vqs(dev); > + else > + synchronize_rcu();I am not sure about this fallback and the latency impact. Maybe synchronize_rcu_expedited is better here.> +} > + > /** > * virtio_device_ready - enable vq use in probe function > * @vdev: the device > -- > 2.25.1