Message ID | 20220406034346.74409-3-xuanzhuo@linux.alibaba.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | virtio pci support VIRTIO_F_RING_RESET (refactor vring) | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Guessing tree name failed - patch did not apply |
在 2022/4/6 上午11:43, Xuan Zhuo 写道: > Performing reset on a queue is divided into four steps: > > 1. transport: notify the device to reset the queue > 2. vring: recycle the buffer submitted > 3. vring: reset/resize the vring (may re-alloc) > 4. transport: mmap vring to device, and enable the queue Nit: it looks to me we'd better say it's an example (since step 3 or even 2 is not a must). > > In order to support queue reset, add two callbacks(reset_vq, > enable_reset_vq) in struct virtio_config_ops to implement steps 1 and 4. > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> > --- > include/linux/virtio_config.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h > index 4d107ad31149..d4adcd0e1c57 100644 > --- a/include/linux/virtio_config.h > +++ b/include/linux/virtio_config.h > @@ -74,6 +74,16 @@ struct virtio_shm_region { > * @set_vq_affinity: set the affinity for a virtqueue (optional). > * @get_vq_affinity: get the affinity for a virtqueue (optional). > * @get_shm_region: get a shared memory region based on the index. > + * @reset_vq: reset a queue individually (optional). > + * vq: the virtqueue > + * Returns 0 on success or error status > + * reset_vq will guarantee that the callbacks are disabled and synchronized. > + * Except for the callback, the caller should guarantee that the vring is I wonder what's the implications for virtio hardening[1]. In that series, we agree to have a synchronize_vqs() config ops to make sure callbacks are synchronized. It uses a global flag and a device wise synchronization mechanism. It looks to me we need to switch to 1) per virtqueue flag 2) per virtqueue synchronization Thanks > + * not accessed by any functions of virtqueue. > + * @enable_reset_vq: enable a reset queue > + * vq: the virtqueue > + * Returns 0 on success or error status > + * If reset_vq is set, then enable_reset_vq must also be set. > */ > typedef void vq_callback_t(struct virtqueue *); > struct virtio_config_ops { > @@ -100,6 +110,8 @@ struct virtio_config_ops { > int index); > bool (*get_shm_region)(struct virtio_device *vdev, > struct virtio_shm_region *region, u8 id); > + int (*reset_vq)(struct virtqueue *vq); > + int (*enable_reset_vq)(struct virtqueue *vq); > }; > > /* If driver didn't advertise the feature, it will never appear. */
On Tue, Apr 12, 2022 at 10:47 AM Jason Wang <jasowang@redhat.com> wrote: > > > 在 2022/4/6 上午11:43, Xuan Zhuo 写道: > > Performing reset on a queue is divided into four steps: > > > > 1. transport: notify the device to reset the queue > > 2. vring: recycle the buffer submitted > > 3. vring: reset/resize the vring (may re-alloc) > > 4. transport: mmap vring to device, and enable the queue > > > Nit: it looks to me we'd better say it's an example (since step 3 or > even 2 is not a must). > > > > > > In order to support queue reset, add two callbacks(reset_vq, > > enable_reset_vq) in struct virtio_config_ops to implement steps 1 and 4. > > > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> > > --- > > include/linux/virtio_config.h | 12 ++++++++++++ > > 1 file changed, 12 insertions(+) > > > > diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h > > index 4d107ad31149..d4adcd0e1c57 100644 > > --- a/include/linux/virtio_config.h > > +++ b/include/linux/virtio_config.h > > @@ -74,6 +74,16 @@ struct virtio_shm_region { > > * @set_vq_affinity: set the affinity for a virtqueue (optional). > > * @get_vq_affinity: get the affinity for a virtqueue (optional). > > * @get_shm_region: get a shared memory region based on the index. > > + * @reset_vq: reset a queue individually (optional). > > + * vq: the virtqueue > > + * Returns 0 on success or error status > > + * reset_vq will guarantee that the callbacks are disabled and synchronized. > > + * Except for the callback, the caller should guarantee that the vring is > > > I wonder what's the implications for virtio hardening[1]. In that For [1] I meant https://lore.kernel.org/lkml/20220406083538.16274-1-jasowang@redhat.com/ Thanks > series, we agree to have a synchronize_vqs() config ops to make sure > callbacks are synchronized. > > It uses a global flag and a device wise synchronization mechanism. It > looks to me we need to switch to > > 1) per virtqueue flag > 2) per virtqueue synchronization > > Thanks > > > > + * not accessed by any functions of virtqueue. > > + * @enable_reset_vq: enable a reset queue > > + * vq: the virtqueue > > + * Returns 0 on success or error status > > + * If reset_vq is set, then enable_reset_vq must also be set. > > */ > > typedef void vq_callback_t(struct virtqueue *); > > struct virtio_config_ops { > > @@ -100,6 +110,8 @@ struct virtio_config_ops { > > int index); > > bool (*get_shm_region)(struct virtio_device *vdev, > > struct virtio_shm_region *region, u8 id); > > + int (*reset_vq)(struct virtqueue *vq); > > + int (*enable_reset_vq)(struct virtqueue *vq); > > }; > > > > /* If driver didn't advertise the feature, it will never appear. */
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 4d107ad31149..d4adcd0e1c57 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -74,6 +74,16 @@ struct virtio_shm_region { * @set_vq_affinity: set the affinity for a virtqueue (optional). * @get_vq_affinity: get the affinity for a virtqueue (optional). * @get_shm_region: get a shared memory region based on the index. + * @reset_vq: reset a queue individually (optional). + * vq: the virtqueue + * Returns 0 on success or error status + * reset_vq will guarantee that the callbacks are disabled and synchronized. + * Except for the callback, the caller should guarantee that the vring is + * not accessed by any functions of virtqueue. + * @enable_reset_vq: enable a reset queue + * vq: the virtqueue + * Returns 0 on success or error status + * If reset_vq is set, then enable_reset_vq must also be set. */ typedef void vq_callback_t(struct virtqueue *); struct virtio_config_ops { @@ -100,6 +110,8 @@ struct virtio_config_ops { int index); bool (*get_shm_region)(struct virtio_device *vdev, struct virtio_shm_region *region, u8 id); + int (*reset_vq)(struct virtqueue *vq); + int (*enable_reset_vq)(struct virtqueue *vq); }; /* If driver didn't advertise the feature, it will never appear. */
Performing reset on a queue is divided into four steps: 1. transport: notify the device to reset the queue 2. vring: recycle the buffer submitted 3. vring: reset/resize the vring (may re-alloc) 4. transport: mmap vring to device, and enable the queue In order to support queue reset, add two callbacks(reset_vq, enable_reset_vq) in struct virtio_config_ops to implement steps 1 and 4. Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> --- include/linux/virtio_config.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)