* [PATCH] virtio-vdpa: add VIRTIO_F_NOTIFICATION_DATA feature support
@ 2023-04-02 8:10 Alvaro Karsz
2023-04-04 5:09 ` Jason Wang
2023-04-08 6:37 ` Michael S. Tsirkin
0 siblings, 2 replies; 8+ messages in thread
From: Alvaro Karsz @ 2023-04-02 8:10 UTC (permalink / raw)
To: mst, jasowang; +Cc: eperezma, viktor, virtualization
Add VIRTIO_F_NOTIFICATION_DATA support for vDPA transport.
If this feature is negotiated, the driver passes extra data when kicking
a virtqueue.
A device that offers this feature needs to implement the
kick_vq_with_data callback.
kick_vq_with_data receives the vDPA device and data.
data includes the vqn, next_off and next_wrap for packed virtqueues.
This patch follows a patch [1] by Viktor Prutyanov which adds support
for the MMIO, channel I/O and modern PCI transports.
This patch needs to be applied on top of Viktor's patch.
[1] https://lore.kernel.org/lkml/20230324195029.2410503-1-viktor@daynix.com/
Signed-off-by: Alvaro Karsz <alvaro.karsz@solid-run.com>
---
drivers/virtio/virtio_vdpa.c | 20 ++++++++++++++++++--
include/linux/vdpa.h | 6 ++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
index d7f5af62dda..bdaf30f7fbf 100644
--- a/drivers/virtio/virtio_vdpa.c
+++ b/drivers/virtio/virtio_vdpa.c
@@ -112,6 +112,17 @@ static bool virtio_vdpa_notify(struct virtqueue *vq)
return true;
}
+static bool virtio_vdpa_notify_with_data(struct virtqueue *vq)
+{
+ struct vdpa_device *vdpa = vd_get_vdpa(vq->vdev);
+ const struct vdpa_config_ops *ops = vdpa->config;
+ u32 data = vring_notification_data(vq);
+
+ ops->kick_vq_with_data(vdpa, data);
+
+ return true;
+}
+
static irqreturn_t virtio_vdpa_config_cb(void *private)
{
struct virtio_vdpa_device *vd_dev = private;
@@ -138,6 +149,7 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
struct device *dma_dev;
const struct vdpa_config_ops *ops = vdpa->config;
struct virtio_vdpa_vq_info *info;
+ bool (*notify)(struct virtqueue *vq);
struct vdpa_callback cb;
struct virtqueue *vq;
u64 desc_addr, driver_addr, device_addr;
@@ -154,6 +166,11 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
if (index >= vdpa->nvqs)
return ERR_PTR(-ENOENT);
+ if (__virtio_test_bit(vdev, VIRTIO_F_NOTIFICATION_DATA))
+ notify = virtio_vdpa_notify_with_data;
+ else
+ notify = virtio_vdpa_notify;
+
/* Queue shouldn't already be set up. */
if (ops->get_vq_ready(vdpa, index))
return ERR_PTR(-ENOENT);
@@ -183,8 +200,7 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
dma_dev = vdpa_get_dma_dev(vdpa);
vq = vring_create_virtqueue_dma(index, max_num, align, vdev,
true, may_reduce_num, ctx,
- virtio_vdpa_notify, callback,
- name, dma_dev);
+ notify, callback, name, dma_dev);
if (!vq) {
err = -ENOMEM;
goto error_new_virtqueue;
diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
index 43f59ef10cc..a83bb0501c5 100644
--- a/include/linux/vdpa.h
+++ b/include/linux/vdpa.h
@@ -143,6 +143,11 @@ struct vdpa_map_file {
* @kick_vq: Kick the virtqueue
* @vdev: vdpa device
* @idx: virtqueue index
+ * @kick_vq_with_data: Kick the virtqueue and supply extra data
+ * (only if VIRTIO_F_NOTIFICATION_DATA is negotiated)
+ * @vdev: vdpa device
+ * @data: includes vqn, next_off and next_wrap for
+ * packed virtqueues
* @set_vq_cb: Set the interrupt callback function for
* a virtqueue
* @vdev: vdpa device
@@ -300,6 +305,7 @@ struct vdpa_config_ops {
u64 device_area);
void (*set_vq_num)(struct vdpa_device *vdev, u16 idx, u32 num);
void (*kick_vq)(struct vdpa_device *vdev, u16 idx);
+ void (*kick_vq_with_data)(struct vdpa_device *vdev, u32 data);
void (*set_vq_cb)(struct vdpa_device *vdev, u16 idx,
struct vdpa_callback *cb);
void (*set_vq_ready)(struct vdpa_device *vdev, u16 idx, bool ready);
--
2.34.1
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio-vdpa: add VIRTIO_F_NOTIFICATION_DATA feature support
2023-04-02 8:10 [PATCH] virtio-vdpa: add VIRTIO_F_NOTIFICATION_DATA feature support Alvaro Karsz
@ 2023-04-04 5:09 ` Jason Wang
2023-04-04 7:20 ` Alvaro Karsz
2023-04-08 6:37 ` Michael S. Tsirkin
1 sibling, 1 reply; 8+ messages in thread
From: Jason Wang @ 2023-04-04 5:09 UTC (permalink / raw)
To: Alvaro Karsz; +Cc: eperezma, virtualization, viktor, mst
On Sun, Apr 2, 2023 at 4:10 PM Alvaro Karsz <alvaro.karsz@solid-run.com> wrote:
>
> Add VIRTIO_F_NOTIFICATION_DATA support for vDPA transport.
> If this feature is negotiated, the driver passes extra data when kicking
> a virtqueue.
>
> A device that offers this feature needs to implement the
> kick_vq_with_data callback.
>
> kick_vq_with_data receives the vDPA device and data.
> data includes the vqn, next_off and next_wrap for packed virtqueues.
>
> This patch follows a patch [1] by Viktor Prutyanov which adds support
> for the MMIO, channel I/O and modern PCI transports.
>
> This patch needs to be applied on top of Viktor's patch.
>
> [1] https://lore.kernel.org/lkml/20230324195029.2410503-1-viktor@daynix.com/
>
> Signed-off-by: Alvaro Karsz <alvaro.karsz@solid-run.com>
> ---
> drivers/virtio/virtio_vdpa.c | 20 ++++++++++++++++++--
> include/linux/vdpa.h | 6 ++++++
> 2 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
> index d7f5af62dda..bdaf30f7fbf 100644
> --- a/drivers/virtio/virtio_vdpa.c
> +++ b/drivers/virtio/virtio_vdpa.c
> @@ -112,6 +112,17 @@ static bool virtio_vdpa_notify(struct virtqueue *vq)
> return true;
> }
>
> +static bool virtio_vdpa_notify_with_data(struct virtqueue *vq)
> +{
> + struct vdpa_device *vdpa = vd_get_vdpa(vq->vdev);
> + const struct vdpa_config_ops *ops = vdpa->config;
> + u32 data = vring_notification_data(vq);
> +
> + ops->kick_vq_with_data(vdpa, data);
> +
> + return true;
> +}
> +
> static irqreturn_t virtio_vdpa_config_cb(void *private)
> {
> struct virtio_vdpa_device *vd_dev = private;
> @@ -138,6 +149,7 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
> struct device *dma_dev;
> const struct vdpa_config_ops *ops = vdpa->config;
> struct virtio_vdpa_vq_info *info;
> + bool (*notify)(struct virtqueue *vq);
> struct vdpa_callback cb;
> struct virtqueue *vq;
> u64 desc_addr, driver_addr, device_addr;
> @@ -154,6 +166,11 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
> if (index >= vdpa->nvqs)
> return ERR_PTR(-ENOENT);
>
> + if (__virtio_test_bit(vdev, VIRTIO_F_NOTIFICATION_DATA))
> + notify = virtio_vdpa_notify_with_data;
> + else
> + notify = virtio_vdpa_notify;
> +
> /* Queue shouldn't already be set up. */
> if (ops->get_vq_ready(vdpa, index))
> return ERR_PTR(-ENOENT);
> @@ -183,8 +200,7 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
> dma_dev = vdpa_get_dma_dev(vdpa);
> vq = vring_create_virtqueue_dma(index, max_num, align, vdev,
> true, may_reduce_num, ctx,
> - virtio_vdpa_notify, callback,
> - name, dma_dev);
> + notify, callback, name, dma_dev);
> if (!vq) {
> err = -ENOMEM;
> goto error_new_virtqueue;
> diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
> index 43f59ef10cc..a83bb0501c5 100644
> --- a/include/linux/vdpa.h
> +++ b/include/linux/vdpa.h
> @@ -143,6 +143,11 @@ struct vdpa_map_file {
> * @kick_vq: Kick the virtqueue
> * @vdev: vdpa device
> * @idx: virtqueue index
> + * @kick_vq_with_data: Kick the virtqueue and supply extra data
> + * (only if VIRTIO_F_NOTIFICATION_DATA is negotiated)
> + * @vdev: vdpa device
> + * @data: includes vqn, next_off and next_wrap for
> + * packed virtqueues
This needs some tweaking, VIRTIO_F_NOTIFICATION_DATA works for split
virtqueue as well.
Thanks
> * @set_vq_cb: Set the interrupt callback function for
> * a virtqueue
> * @vdev: vdpa device
> @@ -300,6 +305,7 @@ struct vdpa_config_ops {
> u64 device_area);
> void (*set_vq_num)(struct vdpa_device *vdev, u16 idx, u32 num);
> void (*kick_vq)(struct vdpa_device *vdev, u16 idx);
> + void (*kick_vq_with_data)(struct vdpa_device *vdev, u32 data);
> void (*set_vq_cb)(struct vdpa_device *vdev, u16 idx,
> struct vdpa_callback *cb);
> void (*set_vq_ready)(struct vdpa_device *vdev, u16 idx, bool ready);
> --
> 2.34.1
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio-vdpa: add VIRTIO_F_NOTIFICATION_DATA feature support
2023-04-04 5:09 ` Jason Wang
@ 2023-04-04 7:20 ` Alvaro Karsz
2023-04-04 8:05 ` Jason Wang
0 siblings, 1 reply; 8+ messages in thread
From: Alvaro Karsz @ 2023-04-04 7:20 UTC (permalink / raw)
To: Jason Wang; +Cc: eperezma, virtualization, viktor, mst
> > + * @kick_vq_with_data: Kick the virtqueue and supply extra data
> > + * (only if VIRTIO_F_NOTIFICATION_DATA is negotiated)
> > + * @vdev: vdpa device
> > + * @data: includes vqn, next_off and next_wrap for
> > + * packed virtqueues
>
> This needs some tweaking, VIRTIO_F_NOTIFICATION_DATA works for split
> virtqueue as well.
>
I meant that next_wrap is for packed VQs, but I see your point, it's no clear from the comment.
I'll fix it in v2.
Thanks
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio-vdpa: add VIRTIO_F_NOTIFICATION_DATA feature support
2023-04-04 7:20 ` Alvaro Karsz
@ 2023-04-04 8:05 ` Jason Wang
2023-04-04 8:16 ` Alvaro Karsz
0 siblings, 1 reply; 8+ messages in thread
From: Jason Wang @ 2023-04-04 8:05 UTC (permalink / raw)
To: Alvaro Karsz; +Cc: eperezma, virtualization, viktor, mst
On Tue, Apr 4, 2023 at 3:20 PM Alvaro Karsz <alvaro.karsz@solid-run.com> wrote:
>
> > > + * @kick_vq_with_data: Kick the virtqueue and supply extra data
> > > + * (only if VIRTIO_F_NOTIFICATION_DATA is negotiated)
> > > + * @vdev: vdpa device
> > > + * @data: includes vqn, next_off and next_wrap for
> > > + * packed virtqueues
> >
> > This needs some tweaking, VIRTIO_F_NOTIFICATION_DATA works for split
> > virtqueue as well.
> >
>
> I meant that next_wrap is for packed VQs, but I see your point, it's no clear from the comment.
> I'll fix it in v2.
next_wrap works for split as well, spec said
"
Without VIRTIO_F_RING_PACKED this is the most significant bit (bit 15)
of the available index.
"
Thanks
>
> Thanks
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio-vdpa: add VIRTIO_F_NOTIFICATION_DATA feature support
2023-04-04 8:05 ` Jason Wang
@ 2023-04-04 8:16 ` Alvaro Karsz
0 siblings, 0 replies; 8+ messages in thread
From: Alvaro Karsz @ 2023-04-04 8:16 UTC (permalink / raw)
To: Jason Wang; +Cc: eperezma, virtualization, viktor, mst
> > I meant that next_wrap is for packed VQs, but I see your point, it's no clear from the comment.
> > I'll fix it in v2.
>
> next_wrap works for split as well, spec said
>
> "
> Without VIRTIO_F_RING_PACKED this is the most significant bit (bit 15)
> of the available index.
> "
You're right, so we can write:
@kick_vq_with_data: Kick the virtqueue and supply extra data
(only if VIRTIO_F_NOTIFICATION_DATA is negotiated)
@vdev: vdpa device
@data for split virtqueue:
16 bits vqn and 16 bits next available index.
@data for packed virtqueue:
16 bits vqn, 15 least significant bits of
next available index and 1 bit next_wrap.
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio-vdpa: add VIRTIO_F_NOTIFICATION_DATA feature support
2023-04-02 8:10 [PATCH] virtio-vdpa: add VIRTIO_F_NOTIFICATION_DATA feature support Alvaro Karsz
2023-04-04 5:09 ` Jason Wang
@ 2023-04-08 6:37 ` Michael S. Tsirkin
2023-04-08 7:32 ` Alvaro Karsz
1 sibling, 1 reply; 8+ messages in thread
From: Michael S. Tsirkin @ 2023-04-08 6:37 UTC (permalink / raw)
To: Alvaro Karsz; +Cc: eperezma, viktor, virtualization
On Sun, Apr 02, 2023 at 11:10:34AM +0300, Alvaro Karsz wrote:
> Add VIRTIO_F_NOTIFICATION_DATA support for vDPA transport.
> If this feature is negotiated, the driver passes extra data when kicking
> a virtqueue.
>
> A device that offers this feature needs to implement the
> kick_vq_with_data callback.
>
> kick_vq_with_data receives the vDPA device and data.
> data includes the vqn, next_off and next_wrap for packed virtqueues.
>
> This patch follows a patch [1] by Viktor Prutyanov which adds support
> for the MMIO, channel I/O and modern PCI transports.
>
> This patch needs to be applied on top of Viktor's patch.
>
> [1] https://lore.kernel.org/lkml/20230324195029.2410503-1-viktor@daynix.com/
>
> Signed-off-by: Alvaro Karsz <alvaro.karsz@solid-run.com>
Hmm so I conclude that drivers without kick_vq_with_data
should not accept VIRTIO_F_NOTIFICATION_DATA then?
> ---
> drivers/virtio/virtio_vdpa.c | 20 ++++++++++++++++++--
> include/linux/vdpa.h | 6 ++++++
> 2 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
> index d7f5af62dda..bdaf30f7fbf 100644
> --- a/drivers/virtio/virtio_vdpa.c
> +++ b/drivers/virtio/virtio_vdpa.c
> @@ -112,6 +112,17 @@ static bool virtio_vdpa_notify(struct virtqueue *vq)
> return true;
> }
>
> +static bool virtio_vdpa_notify_with_data(struct virtqueue *vq)
> +{
> + struct vdpa_device *vdpa = vd_get_vdpa(vq->vdev);
> + const struct vdpa_config_ops *ops = vdpa->config;
> + u32 data = vring_notification_data(vq);
> +
> + ops->kick_vq_with_data(vdpa, data);
> +
> + return true;
> +}
> +
> static irqreturn_t virtio_vdpa_config_cb(void *private)
> {
> struct virtio_vdpa_device *vd_dev = private;
> @@ -138,6 +149,7 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
> struct device *dma_dev;
> const struct vdpa_config_ops *ops = vdpa->config;
> struct virtio_vdpa_vq_info *info;
> + bool (*notify)(struct virtqueue *vq);
> struct vdpa_callback cb;
> struct virtqueue *vq;
> u64 desc_addr, driver_addr, device_addr;
> @@ -154,6 +166,11 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
> if (index >= vdpa->nvqs)
> return ERR_PTR(-ENOENT);
>
> + if (__virtio_test_bit(vdev, VIRTIO_F_NOTIFICATION_DATA))
> + notify = virtio_vdpa_notify_with_data;
> + else
> + notify = virtio_vdpa_notify;
> +
> /* Queue shouldn't already be set up. */
> if (ops->get_vq_ready(vdpa, index))
> return ERR_PTR(-ENOENT);
> @@ -183,8 +200,7 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
> dma_dev = vdpa_get_dma_dev(vdpa);
> vq = vring_create_virtqueue_dma(index, max_num, align, vdev,
> true, may_reduce_num, ctx,
> - virtio_vdpa_notify, callback,
> - name, dma_dev);
> + notify, callback, name, dma_dev);
> if (!vq) {
> err = -ENOMEM;
> goto error_new_virtqueue;
> diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
> index 43f59ef10cc..a83bb0501c5 100644
> --- a/include/linux/vdpa.h
> +++ b/include/linux/vdpa.h
> @@ -143,6 +143,11 @@ struct vdpa_map_file {
> * @kick_vq: Kick the virtqueue
> * @vdev: vdpa device
> * @idx: virtqueue index
> + * @kick_vq_with_data: Kick the virtqueue and supply extra data
> + * (only if VIRTIO_F_NOTIFICATION_DATA is negotiated)
> + * @vdev: vdpa device
> + * @data: includes vqn, next_off and next_wrap for
> + * packed virtqueues
> * @set_vq_cb: Set the interrupt callback function for
> * a virtqueue
> * @vdev: vdpa device
> @@ -300,6 +305,7 @@ struct vdpa_config_ops {
> u64 device_area);
> void (*set_vq_num)(struct vdpa_device *vdev, u16 idx, u32 num);
> void (*kick_vq)(struct vdpa_device *vdev, u16 idx);
> + void (*kick_vq_with_data)(struct vdpa_device *vdev, u32 data);
> void (*set_vq_cb)(struct vdpa_device *vdev, u16 idx,
> struct vdpa_callback *cb);
> void (*set_vq_ready)(struct vdpa_device *vdev, u16 idx, bool ready);
> --
> 2.34.1
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio-vdpa: add VIRTIO_F_NOTIFICATION_DATA feature support
2023-04-08 6:37 ` Michael S. Tsirkin
@ 2023-04-08 7:32 ` Alvaro Karsz
2023-04-08 8:57 ` Michael S. Tsirkin
0 siblings, 1 reply; 8+ messages in thread
From: Alvaro Karsz @ 2023-04-08 7:32 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: eperezma, viktor, virtualization
> Hmm so I conclude that drivers without kick_vq_with_data
> should not accept VIRTIO_F_NOTIFICATION_DATA then?
Yes, vDPA drivers without kick_vq_with_data should not offer VIRTIO_F_NOTIFICATION_DATA in the first place.
We can be more forgiving in such cases and clear the feature bit + print a warning.
It may be easier to debug when creating a new vDPA driver.
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] virtio-vdpa: add VIRTIO_F_NOTIFICATION_DATA feature support
2023-04-08 7:32 ` Alvaro Karsz
@ 2023-04-08 8:57 ` Michael S. Tsirkin
0 siblings, 0 replies; 8+ messages in thread
From: Michael S. Tsirkin @ 2023-04-08 8:57 UTC (permalink / raw)
To: Alvaro Karsz; +Cc: eperezma, viktor, virtualization
On Sat, Apr 08, 2023 at 07:32:52AM +0000, Alvaro Karsz wrote:
> > Hmm so I conclude that drivers without kick_vq_with_data
> > should not accept VIRTIO_F_NOTIFICATION_DATA then?
>
> Yes, vDPA drivers without kick_vq_with_data should not offer VIRTIO_F_NOTIFICATION_DATA in the first place.
>
> We can be more forgiving in such cases and clear the feature bit + print a warning.
> It may be easier to debug when creating a new vDPA driver.
No need to warn I think, it might not be mandatory.
--
MST
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-04-08 8:57 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-02 8:10 [PATCH] virtio-vdpa: add VIRTIO_F_NOTIFICATION_DATA feature support Alvaro Karsz
2023-04-04 5:09 ` Jason Wang
2023-04-04 7:20 ` Alvaro Karsz
2023-04-04 8:05 ` Jason Wang
2023-04-04 8:16 ` Alvaro Karsz
2023-04-08 6:37 ` Michael S. Tsirkin
2023-04-08 7:32 ` Alvaro Karsz
2023-04-08 8:57 ` Michael S. Tsirkin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.