virtio pci support VIRTIO_F_RING_RESET (refactor vring)
Subsystems (12)
Xuan Zhuo
reviewerv9 cover virtio pci support VIRTIO_F_RING_RESET (refactor vring)
The virtio spec already supports the virtio queue reset function. This patch set is to add this function to the kernel. The relevant virtio spec information is here:
https://github.com/oasis-tcs/virtio-spec/issues/124
Also regarding MMIO support for queue reset, I plan to support it after this patch is passed.
This patch set implements the refactoring of vring. Finally, the virtuque_resize() interface is provided based on the reset function of the transport layer.
Test environment:
Host: 4.19.91
Qemu: QEMU emulator version 6.2.50 (with vq reset support) Test Cmd: ethtool -G eth1 rx $1 tx $2; ethtool -g eth1
The default is split mode, modify Qemu virtio-net to add PACKED feature to test packed mode.
Qemu code:
https://github.com/fengidri/qemu/compare/89f3bfa3265554d1d591ee4d7f1197b6e3397e84...master
In order to simplify the review of this patch set, the function of reusing the old buffers after resize will be introduced in subsequent patch sets.
Please review. Thanks.
v9:
1. Provide a virtqueue_resize() interface directly
2. A patch set including vring resize, virtio pci reset, virtio-net resize
3. No more separate structs
v8:
1. Provide a virtqueue_reset() interface directly
2. Split the two patch sets, this is the first part
3. Add independent allocation helper for allocating state, extra
v7:
1. fix #6 subject typo
2. fix #6 ring_size_in_bytes is uninitialized
3. check by: make W=12
v6:
1. virtio_pci: use synchronize_irq(irq) to sync the irq callbacks
2. Introduce virtqueue_reset_vring() to implement the reset of vring during the reset process. May use the old vring if num of the vq not change.
3. find_vqs() support sizes to special the max size of each vq
v5:
1. add virtio-net support set_ringparam
v4:
1. just the code of virtio, without virtio-net
2. Performing reset on a queue is divided into these steps:
1. reset_vq: reset one vq
2. recycle the buffer from vq by virtqueue_detach_unused_buf()
3. release the ring of the vq by vring_release_virtqueue()
4. enable_reset_vq: re-enable the reset queue
3. Simplify the parameters of enable_reset_vq()
4. add container structures for virtio_pci_common_cfg
v3:
1. keep vq, irq unreleased
Xuan Zhuo (32):
virtio: add helper virtqueue_get_vring_max_size()
virtio: struct virtio_config_ops add callbacks for queue_reset
virtio_ring: update the document of the virtqueue_detach_unused_buf
for queue reset
virtio_ring: remove the arg vq of vring_alloc_desc_extra()
virtio_ring: extract the logic of freeing vring
virtio_ring: split: extract the logic of alloc queue
virtio_ring: split: extract the logic of alloc state and extra
virtio_ring: split: extract the logic of attach vring
virtio_ring: split: extract the logic of vq init
virtio_ring: split: introduce virtqueue_reinit_split()
virtio_ring: split: introduce virtqueue_resize_split()
virtio_ring: packed: extract the logic of alloc queue
virtio_ring: packed: extract the logic of alloc state and extra
virtio_ring: packed: extract the logic of attach vring
virtio_ring: packed: extract the logic of vq init
virtio_ring: packed: introduce virtqueue_reinit_packed()
virtio_ring: packed: introduce virtqueue_resize_packed()
virtio_ring: introduce virtqueue_resize()
virtio_pci: struct virtio_pci_common_cfg add queue_notify_data
virtio: queue_reset: add VIRTIO_F_RING_RESET
virtio_pci: queue_reset: update struct virtio_pci_common_cfg and
option functions
virtio_pci: queue_reset: extract the logic of active vq for modern pci
virtio_pci: queue_reset: support VIRTIO_F_RING_RESET
virtio: find_vqs() add arg sizes
virtio_pci: support the arg sizes of find_vqs()
virtio_mmio: support the arg sizes of find_vqs()
virtio: add helper virtio_find_vqs_ctx_size()
virtio_net: set the default max ring size by find_vqs()
virtio_net: get ringparam by virtqueue_get_vring_max_size()
virtio_net: split free_unused_bufs()
virtio_net: support rx/tx queue resize
virtio_net: support set_ringparam
arch/um/drivers/virtio_uml.c | 3 +- drivers/net/virtio_net.c | 219 +++++++- drivers/platform/mellanox/mlxbf-tmfifo.c | 3 + drivers/remoteproc/remoteproc_virtio.c | 3 + drivers/s390/virtio/virtio_ccw.c | 4 + drivers/virtio/virtio_mmio.c | 11 +- drivers/virtio/virtio_pci_common.c | 28 +- drivers/virtio/virtio_pci_common.h | 3 +- drivers/virtio/virtio_pci_legacy.c | 8 +- drivers/virtio/virtio_pci_modern.c | 149 +++++- drivers/virtio/virtio_pci_modern_dev.c | 36 ++ drivers/virtio/virtio_ring.c | 626 ++++++++++++++++++----- drivers/virtio/virtio_vdpa.c | 3 + include/linux/virtio.h | 6 + include/linux/virtio_config.h | 38 +- include/linux/virtio_pci_modern.h | 2 + include/uapi/linux/virtio_config.h | 7 +- include/uapi/linux/virtio_pci.h | 14 + 18 files changed, 964 insertions(+), 199 deletions(-)
--
2.31.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Xuan Zhuo
reviewerPATCH v9 1/32 virtio: add helper virtqueue_get_vring_max_size()
Record the maximum queue num supported by the device.
virtio-net can display the maximum (supported by hardware) ring size in ethtool -g eth0.
When the subsequent patch implements vring reset, it can judge whether the ring size passed by the driver is legal based on this.
--- arch/um/drivers/virtio_uml.c | 1 + drivers/platform/mellanox/mlxbf-tmfifo.c | 2 ++ drivers/remoteproc/remoteproc_virtio.c | 2 ++ drivers/s390/virtio/virtio_ccw.c | 3 +++ drivers/virtio/virtio_mmio.c | 2 ++ drivers/virtio/virtio_pci_legacy.c | 2 ++ drivers/virtio/virtio_pci_modern.c | 2 ++ drivers/virtio/virtio_ring.c | 14 ++++++++++++++ drivers/virtio/virtio_vdpa.c | 2 ++ include/linux/virtio.h | 2 ++ 10 files changed, 32 insertions(+)
arch/um/drivers/virtio_uml.c +1 -0
@@ -945,6 +945,7 @@ static struct virtqueue *vu_setup_vq(struct virtio_device *vdev, goto error_create; } vq->priv = info; + vq->num_max = num; num =virtqueue_get_vring_size (vq); if (vu_dev->protocol_features &
drivers/platform/mellanox/mlxbf-tmfifo.c +2 -0
@@ -959,6 +959,8 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev, goto error; } + vq->num_max = vring->num; + vqs[i] = vq; vring->vq = vq; vq->priv = vring;
drivers/remoteproc/remoteproc_virtio.c +2 -0
@@ -125,6 +125,8 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev,return ERR_PTR (-ENOMEM ); } + vq->num_max = len; + rvring->vq = vq; vq->priv = rvring;
drivers/s390/virtio/virtio_ccw.c +3 -0
@@ -529,6 +529,9 @@ static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev, err = -ENOMEM ; goto out_err; } + + vq->num_max = info->num; +/* it may have been reduced */ info->num =virtqueue_get_vring_size (vq);
drivers/virtio/virtio_mmio.c +2 -0
@@ -390,6 +390,8 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index, goto error_new_virtqueue; } + vq->num_max = num; +/* Activate the queue */ writel (virtqueue_get_vring_size (vq), vm_dev->base +VIRTIO_MMIO_QUEUE_NUM );if (vm_dev->version ==1 ) {
drivers/virtio/virtio_pci_legacy.c +2 -0
@@ -135,6 +135,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!vq)return ERR_PTR (-ENOMEM ); + vq->num_max = num; + q_pfn =virtqueue_get_desc_addr (vq) >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ;if (q_pfn >>32 ) { dev_err(&vp_dev->pci_dev->dev,
drivers/virtio/virtio_pci_modern.c +2 -0
@@ -218,6 +218,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!vq)return ERR_PTR (-ENOMEM ); + vq->num_max = num; +/* activate the queue */ vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); vp_modern_queue_address(mdev, index, virtqueue_get_desc_addr(vq),
drivers/virtio/virtio_ring.c +14 -0
@@ -2371,6 +2371,20 @@ void vring_transport_features(struct virtio_device *vdev) }EXPORT_SYMBOL_GPL (vring_transport_features); +/** +* virtqueue_get_vring_max_size - return the max size of the virtqueue's vring +* @_vq: the struct virtqueue containing the vring of interest. +* +* Returns the max size of the vring. +* +* Unlike other operations, this need not be serialized. +*/ +unsigned int virtqueue_get_vring_max_size (struct virtqueue *_vq) +{ +return _vq->num_max; +} +EXPORT_SYMBOL_GPL (virtqueue_get_vring_max_size); +/** * virtqueue_get_vring_size - return the size of the virtqueue's vring * @_vq: the struct virtqueue containing the vring of interest.
drivers/virtio/virtio_vdpa.c +2 -0
@@ -183,6 +183,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, goto error_new_virtqueue; } + vq->num_max = max_num; +/* Setup virtqueue callback */ cb.callback = virtio_vdpa_virtqueue_cb; cb.private = info;
include/linux/virtio.h +2 -0
@@ -31,6 +31,7 @@ struct virtqueue {struct virtio_device *vdev;unsigned int index;unsigned int num_free; +unsigned int num_max;void *priv; };
@@ -80,6 +81,7 @@ bool virtqueue_enable_cb_delayed(struct virtqueue *vq);void *virtqueue_detach_unused_buf (struct virtqueue *vq); +unsigned int virtqueue_get_vring_max_size (struct virtqueue *vq);unsigned int virtqueue_get_vring_size (struct virtqueue *vq);bool virtqueue_is_broken (struct virtqueue *vq);
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 01/32] virtio: add helper virtqueue_get_vring_max_size()
Quoted 52 lines · Xuan Zhuo
Record the maximum queue num supported by the device.
virtio-net can display the maximum (supported by hardware) ring size in ethtool -g eth0.
When the subsequent patch implements vring reset, it can judge whether the ring size passed by the driver is legal based on this.
Signed-off-by Xuan Zhuo <[email protected]>--- arch/um/drivers/virtio_uml.c | 1 + drivers/platform/mellanox/mlxbf-tmfifo.c | 2 ++ drivers/remoteproc/remoteproc_virtio.c | 2 ++ drivers/s390/virtio/virtio_ccw.c | 3 +++ drivers/virtio/virtio_mmio.c | 2 ++ drivers/virtio/virtio_pci_legacy.c | 2 ++ drivers/virtio/virtio_pci_modern.c | 2 ++ drivers/virtio/virtio_ring.c | 14 ++++++++++++++ drivers/virtio/virtio_vdpa.c | 2 ++ include/linux/virtio.h | 2 ++ 10 files changed, 32 insertions(+)arch/um/drivers/virtio_uml.c +1
-0@@ -945,6 +945,7 @@ static struct virtqueue *vu_setup_vq(struct virtio_device *vdev, goto error_create; } vq->priv = info; + vq->num_max = num; num =virtqueue_get_vring_size (vq); if (vu_dev->protocol_features &drivers/platform/mellanox/mlxbf-tmfifo.c +2
-0@@ -959,6 +959,8 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev, goto error; } + vq->num_max = vring->num; + vqs[i] = vq; vring->vq = vq; vq->priv = vring;drivers/remoteproc/remoteproc_virtio.c +0
-0
drivers/remoteproc/remoteproc_virtio.c static struct virtqueue *rp_find_vq(struct virtio_device *vdev, · line 128
Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1
-0@@ -125,6 +125,8 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev,return ERR_PTR (-ENOMEM ); } + vq->num_max = len;
I wonder if this is correct.
It looks to me len is counted in bytes:
/**
* struct rproc_vring - remoteproc vring state
* @va: virtual address
* @len: length, in bytes
* @da: device address
* @align: vring alignment
* @notifyid: rproc-specific unique vring index
* @rvdev: remote vdev
* @vq: the virtqueue of this vring
*/
struct rproc_vring {
void *va;
int len;
u32 da;
u32 align;
int notifyid;
struct rproc_vdev *rvdev;
struct virtqueue *vq;
};
Other looks good.
Thanks
Quoted 108 lines
drivers/remoteproc/remoteproc_virtio.c +1
-0+ rvring->vq = vq; vq->priv = rvring;drivers/s390/virtio/virtio_ccw.c +3
-0@@ -529,6 +529,9 @@ static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev, err = -ENOMEM ; goto out_err; } + + vq->num_max = info->num; +/* it may have been reduced */ info->num =virtqueue_get_vring_size (vq);drivers/virtio/virtio_mmio.c +2
-0@@ -390,6 +390,8 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index, goto error_new_virtqueue; } + vq->num_max = num; +/* Activate the queue */ writel (virtqueue_get_vring_size (vq), vm_dev->base +VIRTIO_MMIO_QUEUE_NUM );if (vm_dev->version ==1 ) {drivers/virtio/virtio_pci_legacy.c +2
-0@@ -135,6 +135,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!vq)return ERR_PTR (-ENOMEM ); + vq->num_max = num; + q_pfn =virtqueue_get_desc_addr (vq) >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ;if (q_pfn >>32 ) { dev_err(&vp_dev->pci_dev->dev,drivers/virtio/virtio_pci_modern.c +2
-0@@ -218,6 +218,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!vq)return ERR_PTR (-ENOMEM ); + vq->num_max = num; +/* activate the queue */ vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); vp_modern_queue_address(mdev, index, virtqueue_get_desc_addr(vq),drivers/virtio/virtio_ring.c +14
-0@@ -2371,6 +2371,20 @@ void vring_transport_features(struct virtio_device *vdev) }EXPORT_SYMBOL_GPL (vring_transport_features); +/** +* virtqueue_get_vring_max_size - return the max size of the virtqueue's vring +* @_vq: the struct virtqueue containing the vring of interest. +* +* Returns the max size of the vring. +* +* Unlike other operations, this need not be serialized. +*/ +unsigned int virtqueue_get_vring_max_size (struct virtqueue *_vq) +{ +return _vq->num_max; +} +EXPORT_SYMBOL_GPL (virtqueue_get_vring_max_size); +/** * virtqueue_get_vring_size - return the size of the virtqueue's vring * @_vq: the struct virtqueue containing the vring of interest. drivers/virtio/virtio_vdpa.c +2
-0@@ -183,6 +183,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, goto error_new_virtqueue; } + vq->num_max = max_num; +/* Setup virtqueue callback */ cb.callback = virtio_vdpa_virtqueue_cb; cb.private = info;include/linux/virtio.h +1
-0@@ -31,6 +31,7 @@ struct virtqueue {struct virtio_device *vdev;unsigned int index;unsigned int num_free; +unsigned int num_max;void *priv; };
include/linux/virtio.h bool virtqueue_enable_cb_delayed(struct virtqueue *vq); · line 87
Quoted 7 lines
include/linux/virtio.h +1
-0@@ -80,6 +81,7 @@ bool virtqueue_enable_cb_delayed(struct virtqueue *vq);void *virtqueue_detach_unused_buf (struct virtqueue *vq); +unsigned int virtqueue_get_vring_max_size (struct virtqueue *vq);unsigned int virtqueue_get_vring_size (struct virtqueue *vq);bool virtqueue_is_broken (struct virtqueue *vq);
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 01/32] virtio: add helper virtqueue_get_vring_max_size()
Quoted 75 lines · Jason Wang
Quoted 52 lines · Xuan Zhuo
Record the maximum queue num supported by the device.
virtio-net can display the maximum (supported by hardware) ring size in ethtool -g eth0.
When the subsequent patch implements vring reset, it can judge whether the ring size passed by the driver is legal based on this.
Signed-off-by Xuan Zhuo <[email protected]>--- arch/um/drivers/virtio_uml.c | 1 + drivers/platform/mellanox/mlxbf-tmfifo.c | 2 ++ drivers/remoteproc/remoteproc_virtio.c | 2 ++ drivers/s390/virtio/virtio_ccw.c | 3 +++ drivers/virtio/virtio_mmio.c | 2 ++ drivers/virtio/virtio_pci_legacy.c | 2 ++ drivers/virtio/virtio_pci_modern.c | 2 ++ drivers/virtio/virtio_ring.c | 14 ++++++++++++++ drivers/virtio/virtio_vdpa.c | 2 ++ include/linux/virtio.h | 2 ++ 10 files changed, 32 insertions(+)arch/um/drivers/virtio_uml.c +1
-0@@ -945,6 +945,7 @@ static struct virtqueue *vu_setup_vq(struct virtio_device *vdev, goto error_create; } vq->priv = info; + vq->num_max = num; num =virtqueue_get_vring_size (vq); if (vu_dev->protocol_features &drivers/platform/mellanox/mlxbf-tmfifo.c +2
-0@@ -959,6 +959,8 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev, goto error; } + vq->num_max = vring->num; + vqs[i] = vq; vring->vq = vq; vq->priv = vring;drivers/remoteproc/remoteproc_virtio.c +0
-0drivers/remoteproc/remoteproc_virtio.c static struct virtqueue *rp_find_vq(struct virtio_device *vdev, · line 128
Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1
-0@@ -125,6 +125,8 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev,return ERR_PTR (-ENOMEM ); } + vq->num_max = len;I wonder if this is correct.
It looks to me len is counted in bytes:
/**
* structrproc_vring- remoteproc vring state
* @va: virtual address
* @len: length, in bytes
* @da: device address
* @align: vring alignment
* @notifyid: rproc-specific unique vring index
* @rvdev: remote vdev
* @vq: the virtqueue of this vring
*/
structrproc_vring{
Quoted 9 lines
void *va;
int len;
u32 da;
u32 align;
int notifyid;
structrproc_vdev*rvdev;
struct virtqueue *vq;
};
I think this comment is incorrect because here len is passed as num to vring_new_virtqueue().
There is also this usage:
/* actual size of vring (in bytes) */ size = PAGE_ALIGN(vring_size(rvring->len, rvring->align));
And this value comes from here:
static int
rproc_parse_vring(struct rproc_vdev *rvdev, struct fw_rsc_vdev *rsc, int i)
{
struct rproc *rproc = rvdev->rproc;
struct device *dev = &rproc->dev;
struct fw_rsc_vdev_vring *vring = &rsc->vring[i];
struct rproc_vring *rvring = &rvdev->vring[i];
dev_dbg(dev, "vdev rsc: vring%d: da 0x%x, qsz %d, align %d\n",
i, vring->da, vring->num, vring->align);
/* verify queue size and vring alignment are sane */
if (!vring->num || !vring->align) {
dev_err(dev, "invalid qsz (%d) or alignment (%d)\n",
vring->num, vring->align);
return -EINVAL;
}
> rvring->len = vring->num;
rvring->align = vring->align;
rvring->rvdev = rvdev;
return 0;
}/**
* struct fw_rsc_vdev_vring - vring descriptor entry
* @da: device address
* @align: the alignment between the consumer and producer parts of the vring
* @num: num of buffers supported by this vring (must be power of two)
* @notifyid: a unique rproc-wide notify index for this vring. This notify
* index is used when kicking a remote processor, to let it know that this
* vring is triggered.
* @pa: physical address
*
* This descriptor is not a resource entry by itself; it is part of the
* vdev resource type (see below).
*
* Note that @da should either contain the device address where
* the remote processor is expecting the vring, or indicate that
* dynamically allocation of the vring's device address is supported. */
struct fw_rsc_vdev_vring {
u32 da;
u32 align;
u32 num;
u32 notifyid;
u32 pa;
} __packed;So I think the 'len' here may have changed its meaning in a version update.
Thanks.
Quoted 122 lines
Other looks good.
Thanks
Quoted 115 lines
drivers/remoteproc/remoteproc_virtio.c +1
-0+ rvring->vq = vq; vq->priv = rvring;drivers/s390/virtio/virtio_ccw.c +3
-0@@ -529,6 +529,9 @@ static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev, err = -ENOMEM ; goto out_err; } + + vq->num_max = info->num; +/* it may have been reduced */ info->num =virtqueue_get_vring_size (vq);drivers/virtio/virtio_mmio.c +2
-0@@ -390,6 +390,8 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index, goto error_new_virtqueue; } + vq->num_max = num; +/* Activate the queue */ writel (virtqueue_get_vring_size (vq), vm_dev->base +VIRTIO_MMIO_QUEUE_NUM );if (vm_dev->version ==1 ) {drivers/virtio/virtio_pci_legacy.c +2
-0@@ -135,6 +135,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!vq)return ERR_PTR (-ENOMEM ); + vq->num_max = num; + q_pfn =virtqueue_get_desc_addr (vq) >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ;if (q_pfn >>32 ) { dev_err(&vp_dev->pci_dev->dev,drivers/virtio/virtio_pci_modern.c +2
-0@@ -218,6 +218,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!vq)return ERR_PTR (-ENOMEM ); + vq->num_max = num; +/* activate the queue */ vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); vp_modern_queue_address(mdev, index, virtqueue_get_desc_addr(vq),drivers/virtio/virtio_ring.c +14
-0@@ -2371,6 +2371,20 @@ void vring_transport_features(struct virtio_device *vdev) }EXPORT_SYMBOL_GPL (vring_transport_features); +/** +* virtqueue_get_vring_max_size - return the max size of the virtqueue's vring +* @_vq: the struct virtqueue containing the vring of interest. +* +* Returns the max size of the vring. +* +* Unlike other operations, this need not be serialized. +*/ +unsigned int virtqueue_get_vring_max_size (struct virtqueue *_vq) +{ +return _vq->num_max; +} +EXPORT_SYMBOL_GPL (virtqueue_get_vring_max_size); +/** * virtqueue_get_vring_size - return the size of the virtqueue's vring * @_vq: the struct virtqueue containing the vring of interest. drivers/virtio/virtio_vdpa.c +2
-0@@ -183,6 +183,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, goto error_new_virtqueue; } + vq->num_max = max_num; +/* Setup virtqueue callback */ cb.callback = virtio_vdpa_virtqueue_cb; cb.private = info;include/linux/virtio.h +2
-0@@ -31,6 +31,7 @@ struct virtqueue {struct virtio_device *vdev;unsigned int index;unsigned int num_free; +unsigned int num_max;void *priv; };@@ -80,6 +81,7 @@ bool virtqueue_enable_cb_delayed(struct virtqueue *vq);void *virtqueue_detach_unused_buf (struct virtqueue *vq); +unsigned int virtqueue_get_vring_max_size (struct virtqueue *vq);unsigned int virtqueue_get_vring_size (struct virtqueue *vq);bool virtqueue_is_broken (struct virtqueue *vq);
Re: [PATCH v9 01/32] virtio: add helper virtqueue_get_vring_max_size()
Quoted 148 lines · Xuan Zhuo
Quoted 74 lines · Jason Wang
Quoted 52 lines · Xuan Zhuo
Record the maximum queue num supported by the device.
virtio-net can display the maximum (supported by hardware) ring size in ethtool -g eth0.
When the subsequent patch implements vring reset, it can judge whether the ring size passed by the driver is legal based on this.
Signed-off-by Xuan Zhuo <[email protected]>--- arch/um/drivers/virtio_uml.c | 1 + drivers/platform/mellanox/mlxbf-tmfifo.c | 2 ++ drivers/remoteproc/remoteproc_virtio.c | 2 ++ drivers/s390/virtio/virtio_ccw.c | 3 +++ drivers/virtio/virtio_mmio.c | 2 ++ drivers/virtio/virtio_pci_legacy.c | 2 ++ drivers/virtio/virtio_pci_modern.c | 2 ++ drivers/virtio/virtio_ring.c | 14 ++++++++++++++ drivers/virtio/virtio_vdpa.c | 2 ++ include/linux/virtio.h | 2 ++ 10 files changed, 32 insertions(+)arch/um/drivers/virtio_uml.c +1
-0@@ -945,6 +945,7 @@ static struct virtqueue *vu_setup_vq(struct virtio_device *vdev, goto error_create; } vq->priv = info; + vq->num_max = num; num =virtqueue_get_vring_size (vq); if (vu_dev->protocol_features &drivers/platform/mellanox/mlxbf-tmfifo.c +2
-0@@ -959,6 +959,8 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev, goto error; } + vq->num_max = vring->num; + vqs[i] = vq; vring->vq = vq; vq->priv = vring;drivers/remoteproc/remoteproc_virtio.c +0
-0drivers/remoteproc/remoteproc_virtio.c static struct virtqueue *rp_find_vq(struct virtio_device *vdev, · line 128
Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1
-0@@ -125,6 +125,8 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev,return ERR_PTR (-ENOMEM ); } + vq->num_max = len;I wonder if this is correct.
It looks to me len is counted in bytes:
/**
* structrproc_vring- remoteproc vring state
* @va: virtual address
* @len: length, in bytes
* @da: device address
* @align: vring alignment
* @notifyid: rproc-specific unique vring index
* @rvdev: remote vdev
* @vq: the virtqueue of this vring
*/Quoted 10 lines
struct rproc_vring { void *va; int len; u32 da; u32 align; int notifyid; struct rproc_vdev *rvdev; struct virtqueue *vq; };I think this comment is incorrect because here len is passed as num to
vring_new_virtqueue().There is also this usage:
/* actual size of vring (in bytes) */ size = PAGE_ALIGN(vring_size(rvring->len, rvring->align));And this value comes from here:
static int rproc_parse_vring(struct rproc_vdev *rvdev, struct fw_rsc_vdev *rsc, int i) { struct rproc *rproc = rvdev->rproc; struct device *dev = &rproc->dev; struct fw_rsc_vdev_vring *vring = &rsc->vring[i]; struct rproc_vring *rvring = &rvdev->vring[i]; dev_dbg(dev, "vdev rsc: vring%d: da 0x%x, qsz %d, align %d\n", i, vring->da, vring->num, vring->align); /* verify queue size and vring alignment are sane */ if (!vring->num || !vring->align) { dev_err(dev, "invalid qsz (%d) or alignment (%d)\n", vring->num, vring->align); return -EINVAL; } > rvring->len = vring->num; rvring->align = vring->align; rvring->rvdev = rvdev; return 0; }/**
* structfw_rsc_vdev_vring- vring descriptor entry
* @da: device address
* @align: the alignment between the consumer and producer parts of the vring
* @num: num of buffers supported by this vring (must be power of two)
* @notifyid: a unique rproc-wide notify index for this vring. This notify
* index is used when kicking a remote processor, to let it know that this
* vring is triggered.
* @pa: physical address
*
* This descriptor is not a resource entry by itself; it is part of the
* vdev resource type (see below).
*
* Note that @da should either contain the device address where
* the remote processor is expecting the vring, or indicate that
* dynamically allocation of the vring's device address is supported. */struct fw_rsc_vdev_vring { u32 da; u32 align; u32 num; u32 notifyid; u32 pa; } __packed;
Quoted 1 line
So I think the 'len' here may have changed its meaning in a version update.
I think you're right, let's have a patch to fix the comment (probably with the name since len is confusing here).
Thanks
Quoted 126 lines
Thanks.
Quoted 122 lines
Other looks good.
Thanks
Quoted 115 lines
drivers/remoteproc/remoteproc_virtio.c +1
-0+ rvring->vq = vq; vq->priv = rvring;drivers/s390/virtio/virtio_ccw.c +3
-0@@ -529,6 +529,9 @@ static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev, err = -ENOMEM ; goto out_err; } + + vq->num_max = info->num; +/* it may have been reduced */ info->num =virtqueue_get_vring_size (vq);drivers/virtio/virtio_mmio.c +2
-0@@ -390,6 +390,8 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index, goto error_new_virtqueue; } + vq->num_max = num; +/* Activate the queue */ writel (virtqueue_get_vring_size (vq), vm_dev->base +VIRTIO_MMIO_QUEUE_NUM );if (vm_dev->version ==1 ) {drivers/virtio/virtio_pci_legacy.c +2
-0@@ -135,6 +135,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!vq)return ERR_PTR (-ENOMEM ); + vq->num_max = num; + q_pfn =virtqueue_get_desc_addr (vq) >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ;if (q_pfn >>32 ) { dev_err(&vp_dev->pci_dev->dev,drivers/virtio/virtio_pci_modern.c +2
-0@@ -218,6 +218,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!vq)return ERR_PTR (-ENOMEM ); + vq->num_max = num; +/* activate the queue */ vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); vp_modern_queue_address(mdev, index, virtqueue_get_desc_addr(vq),drivers/virtio/virtio_ring.c +14
-0@@ -2371,6 +2371,20 @@ void vring_transport_features(struct virtio_device *vdev) }EXPORT_SYMBOL_GPL (vring_transport_features); +/** +* virtqueue_get_vring_max_size - return the max size of the virtqueue's vring +* @_vq: the struct virtqueue containing the vring of interest. +* +* Returns the max size of the vring. +* +* Unlike other operations, this need not be serialized. +*/ +unsigned int virtqueue_get_vring_max_size (struct virtqueue *_vq) +{ +return _vq->num_max; +} +EXPORT_SYMBOL_GPL (virtqueue_get_vring_max_size); +/** * virtqueue_get_vring_size - return the size of the virtqueue's vring * @_vq: the struct virtqueue containing the vring of interest. drivers/virtio/virtio_vdpa.c +2
-0@@ -183,6 +183,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, goto error_new_virtqueue; } + vq->num_max = max_num; +/* Setup virtqueue callback */ cb.callback = virtio_vdpa_virtqueue_cb; cb.private = info;include/linux/virtio.h +2
-0@@ -31,6 +31,7 @@ struct virtqueue {struct virtio_device *vdev;unsigned int index;unsigned int num_free; +unsigned int num_max;void *priv; };@@ -80,6 +81,7 @@ bool virtqueue_enable_cb_delayed(struct virtqueue *vq);void *virtqueue_detach_unused_buf (struct virtqueue *vq); +unsigned int virtqueue_get_vring_max_size (struct virtqueue *vq);unsigned int virtqueue_get_vring_size (struct virtqueue *vq);bool virtqueue_is_broken (struct virtqueue *vq);
Xuan Zhuo
reviewerPATCH v9 2/32 virtio: struct virtio_config_ops add callbacks for queue_reset
In reply to Xuan ZhuoPerforming 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.
--- include/linux/virtio_config.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/linux/virtio_config.h +12 -0
@@ -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. */
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 02/32] virtio: struct virtio_config_ops add callbacks for queue_reset
Quoted 6 lines · 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).
Quoted 14 lines
In order to support queue reset, add two
callbacks(reset_vq, enable_reset_vq)in structvirtio_config_opsto implement steps 1 and 4.Signed-off-by Xuan Zhuo <[email protected]>--- include/linux/virtio_config.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/linux/virtio_config.h +0
-0
include/linux/virtio_config.h struct virtio_shm_region { · line 81
Quoted 8 lines
include/linux/virtio_config.h +5
-0@@ -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
Quoted 17 lines
include/linux/virtio_config.h +7
-0+* 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. */
Re: [PATCH v9 02/32] virtio: struct virtio_config_ops add callbacks for queue_reset
Quoted 24 lines · Jason Wang
Quoted 6 lines · 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 queueNit: it looks to me we'd better say it's an example (since step 3 or even 2 is not a must).
Quoted 9 lines
In order to support queue reset, add two
callbacks(reset_vq, enable_reset_vq)in structvirtio_config_opsto implement steps 1 and 4.Signed-off-by Xuan Zhuo <[email protected]>--- include/linux/virtio_config.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Quoted 16 lines
include/linux/virtio_config.h struct virtio_shm_region { · line 81
Quoted 13 lines
include/linux/virtio_config.h +5
-0@@ -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/[email protected]/
Thanks
Quoted 28 lines
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 synchronizationThanks
Quoted 16 lines
include/linux/virtio_config.h +7
-0+* 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); };
Quoted 1 line
include/linux/virtio_config.h struct virtio_config_ops { · line 117
Quoted 1 line
include/linux/virtio_config.h +0
-0/* If driver didn't advertise the feature, it will never appear. */
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 3/32 virtio_ring: update the document of the virtqueue_detach_unused_buf for queue reset
In reply to Xuan ZhuoAdded documentation for virtqueue_detach_unused_buf, allowing it to be called on queue reset.
--- drivers/virtio/virtio_ring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/virtio/virtio_ring.c +2 -2
@@ -2127,8 +2127,8 @@ EXPORT_SYMBOL_GPL(virtqueue_enable_cb_delayed);* @_vq: the struct virtqueue we're talking about. * * Returns NULL or the "data" token handed to virtqueue_add_*(). -* This is not valid on an active queue; it is useful only for device -* shutdown. +* This is not valid on an active queue; it is useful for device +* shutdown or the reset queue. */ void *virtqueue_detach_unused_buf (struct virtqueue *_vq) {
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 03/32] virtio_ring: update the document of the virtqueue_detach_unused_buf for queue reset
Quoted 4 lines · Xuan Zhuo
Added documentation for
virtqueue_detach_unused_buf, allowing it to be called on queue reset.Signed-off-by Xuan Zhuo <[email protected]>
Quoted 9 lines
--- drivers/virtio/virtio_ring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/virtio/virtio_ring.c +0
-0
drivers/virtio/virtio_ring.c EXPORT_SYMBOL_GPL(virtqueue_enable_cb_delayed); · line 2134
Quoted 10 lines
drivers/virtio/virtio_ring.c +2
-2@@ -2127,8 +2127,8 @@ EXPORT_SYMBOL_GPL(virtqueue_enable_cb_delayed);* @_vq: the struct virtqueue we're talking about. * * Returns NULL or the "data" token handed to virtqueue_add_*(). -* This is not valid on an active queue; it is useful only for device -* shutdown. +* This is not valid on an active queue; it is useful for device +* shutdown or the reset queue. */ void *virtqueue_detach_unused_buf (struct virtqueue *_vq) {
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 4/32 virtio_ring: remove the arg vq of vring_alloc_desc_extra()
In reply to Xuan ZhuoThe parameter vq of vring_alloc_desc_extra() is useless. This patch removes this parameter.
Subsequent patches will call this function to avoid passing useless arguments.
--- drivers/virtio/virtio_ring.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/virtio/virtio_ring.c +3 -4
@@ -1636,8 +1636,7 @@ static void *virtqueue_detach_unused_buf_packed(struct virtqueue *_vq)return NULL ; } -static struct vring_desc_extra *vring_alloc_desc_extra (struct vring_virtqueue *vq, -unsigned int num) +static struct vring_desc_extra *vring_alloc_desc_extra (unsigned int num) {struct vring_desc_extra *desc_extra;unsigned int i;
@@ -1755,7 +1754,7 @@ static struct virtqueue *vring_create_virtqueue_packed(/* Put everything in free lists. */ vq->free_head =0 ; - vq->packed.desc_extra =vring_alloc_desc_extra (vq, num); + vq->packed.desc_extra =vring_alloc_desc_extra (num);if (!vq->packed.desc_extra) goto err_desc_extra;
@@ -2233,7 +2232,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,if (!vq->split.desc_state) goto err_state; - vq->split.desc_extra =vring_alloc_desc_extra (vq, vring.num); + vq->split.desc_extra =vring_alloc_desc_extra (vring.num);if (!vq->split.desc_extra) goto err_extra;
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 04/32] virtio_ring: remove the arg vq of vring_alloc_desc_extra()
Quoted 7 lines · Xuan Zhuo
The parameter vq of
vring_alloc_desc_extra()is useless. This patch removes this parameter.Subsequent patches will call this function to avoid passing useless arguments.
Signed-off-by Xuan Zhuo <[email protected]>
Quoted 36 lines
--- drivers/virtio/virtio_ring.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/virtio/virtio_ring.c +3
-4@@ -1636,8 +1636,7 @@ static void *virtqueue_detach_unused_buf_packed(struct virtqueue *_vq)return NULL ; } -static struct vring_desc_extra *vring_alloc_desc_extra (struct vring_virtqueue *vq, -unsigned int num) +static struct vring_desc_extra *vring_alloc_desc_extra (unsigned int num) {struct vring_desc_extra *desc_extra;unsigned int i;@@ -1755,7 +1754,7 @@ static struct virtqueue *vring_create_virtqueue_packed(/* Put everything in free lists. */ vq->free_head =0 ; - vq->packed.desc_extra =vring_alloc_desc_extra (vq, num); + vq->packed.desc_extra =vring_alloc_desc_extra (num);if (!vq->packed.desc_extra) goto err_desc_extra;@@ -2233,7 +2232,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,if (!vq->split.desc_state) goto err_state; - vq->split.desc_extra =vring_alloc_desc_extra (vq, vring.num); + vq->split.desc_extra =vring_alloc_desc_extra (vring.num);if (!vq->split.desc_extra) goto err_extra;
Xuan Zhuo
reviewerPATCH v9 5/32 virtio_ring: extract the logic of freeing vring
In reply to Xuan ZhuoIntroduce vring_free() to free the vring of vq.
Subsequent patches will use vring_free() alone.
--- drivers/virtio/virtio_ring.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/virtio/virtio_ring.c +13 -5
@@ -2301,14 +2301,10 @@ struct virtqueue *vring_new_virtqueue(unsigned int index, }EXPORT_SYMBOL_GPL (vring_new_virtqueue); -void vring_del_virtqueue (struct virtqueue *_vq) +static void vring_free (struct virtqueue *_vq) {struct vring_virtqueue *vq =to_vvq (_vq); -spin_lock (&vq->vq.vdev->vqs_list_lock); -list_del (&_vq->list); -spin_unlock (&vq->vq.vdev->vqs_list_lock); -if (vq->we_own_ring) {if (vq->packed_ring) { vring_free_queue(vq->vq.vdev,
@@ -2339,6 +2335,18 @@ void vring_del_virtqueue(struct virtqueue *_vq)kfree (vq->split.desc_state);kfree (vq->split.desc_extra); } +} + +void vring_del_virtqueue (struct virtqueue *_vq) +{ +struct vring_virtqueue *vq =to_vvq (_vq); + +spin_lock (&vq->vq.vdev->vqs_list_lock); +list_del (&_vq->list); +spin_unlock (&vq->vq.vdev->vqs_list_lock); + +vring_free (_vq); +kfree (vq); }EXPORT_SYMBOL_GPL (vring_del_virtqueue);
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 05/32] virtio_ring: extract the logic of freeing vring
Quoted 5 lines · Xuan Zhuo
Introduce
vring_free()to free the vring of vq.Subsequent patches will use
vring_free()alone.Signed-off-by Xuan Zhuo <[email protected]>
Quoted 33 lines
--- drivers/virtio/virtio_ring.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)drivers/virtio/virtio_ring.c +6
-5@@ -2301,14 +2301,10 @@ struct virtqueue *vring_new_virtqueue(unsigned int index, }EXPORT_SYMBOL_GPL (vring_new_virtqueue); -void vring_del_virtqueue (struct virtqueue *_vq) +static void vring_free (struct virtqueue *_vq) {struct vring_virtqueue *vq =to_vvq (_vq); -spin_lock (&vq->vq.vdev->vqs_list_lock); -list_del (&_vq->list); -spin_unlock (&vq->vq.vdev->vqs_list_lock); -if (vq->we_own_ring) {if (vq->packed_ring) { vring_free_queue(vq->vq.vdev,@@ -2339,6 +2335,18 @@ void vring_del_virtqueue(struct virtqueue *_vq)kfree (vq->split.desc_state);kfree (vq->split.desc_extra); } +} + +void vring_del_virtqueue (struct virtqueue *_vq) +{ +struct vring_virtqueue *vq =to_vvq (_vq);
drivers/virtio/virtio_ring.c void vring_del_virtqueue(struct virtqueue *_vq) · line 2352
Quoted 10 lines
drivers/virtio/virtio_ring.c +7
-0+ +spin_lock (&vq->vq.vdev->vqs_list_lock); +list_del (&_vq->list); +spin_unlock (&vq->vq.vdev->vqs_list_lock); + +vring_free (_vq); +kfree (vq); }EXPORT_SYMBOL_GPL (vring_del_virtqueue);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Xuan Zhuo
reviewerPATCH v9 6/32 virtio_ring: split: extract the logic of alloc queue
In reply to Xuan ZhuoSeparate the logic of split to create vring queue.
This feature is required for subsequent virtuqueue reset vring.
--- drivers/virtio/virtio_ring.c | 53 ++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 17 deletions(-)
drivers/virtio/virtio_ring.c +36 -17
@@ -915,23 +915,15 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ; } -static struct virtqueue *vring_create_virtqueue_split ( -unsigned int index, -unsigned int num, -unsigned int vring_align, -struct virtio_device *vdev, -bool weak_barriers, -bool may_reduce_num, -bool context, -bool (*notify)(struct virtqueue *), -void (*callback)(struct virtqueue *), -const char *name) +static void *vring_alloc_queue_split (struct virtio_device *vdev, +dma_addr_t *dma_addr, +u32 *n, +unsigned int vring_align, +bool weak_barriers, +bool may_reduce_num) { -struct virtqueue *vq;void *queue =NULL ; -dma_addr_t dma_addr; -size_t queue_size_in_bytes; -struct vring vring; +u32 num = *n;/* We assume num is a power of 2. */ if (num & (num -1 )) {
@@ -942,7 +934,7 @@ static struct virtqueue *vring_create_virtqueue_split(/* TODO: allocate each queue chunk individually */ for (; num &&vring_size (num, vring_align) >PAGE_SIZE ; num /=2 ) { queue =vring_alloc_queue (vdev,vring_size (num, vring_align), - &dma_addr, + dma_addr,GFP_KERNEL |__GFP_NOWARN|__GFP_ZERO);if (queue)break ;
@@ -956,11 +948,38 @@ static struct virtqueue *vring_create_virtqueue_split(if (!queue) {/* Try to get a single page. You are my only hope! */ queue =vring_alloc_queue (vdev,vring_size (num, vring_align), - &dma_addr,GFP_KERNEL |__GFP_ZERO); + dma_addr,GFP_KERNEL |__GFP_ZERO); }if (!queue)return NULL ; + *n = num; +return queue; +} + +static struct virtqueue *vring_create_virtqueue_split ( +unsigned int index, +unsigned int num, +unsigned int vring_align, +struct virtio_device *vdev, +bool weak_barriers, +bool may_reduce_num, +bool context, +bool (*notify)(struct virtqueue *), +void (*callback)(struct virtqueue *), +const char *name) +{ +size_t queue_size_in_bytes; +struct virtqueue *vq; +dma_addr_t dma_addr; +struct vring vring; +void *queue; + + queue =vring_alloc_queue_split (vdev, &dma_addr, &num, vring_align, + weak_barriers, may_reduce_num); +if (!queue) +return NULL ; + queue_size_in_bytes =vring_size (num, vring_align);vring_init (&vring, num, queue, vring_align);
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 06/32] virtio_ring: split: extract the logic of alloc queue
Quoted 23 lines · Xuan Zhuo
Separate the logic of split to create vring queue.
This feature is required for subsequent virtuqueue reset vring.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 53 ++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 17 deletions(-)drivers/virtio/virtio_ring.c +0
-6@@ -915,23 +915,15 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ; } -static struct virtqueue *vring_create_virtqueue_split( - unsigned int index, - unsigned int num, - unsigned int vring_align, - struct virtio_device *vdev, - bool weak_barriers,
drivers/virtio/virtio_ring.c static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq) · line 922
Quoted 10 lines
drivers/virtio/virtio_ring.c +5
-5-bool may_reduce_num, - bool context, - bool (*notify)(struct virtqueue *), - void (*callback)(struct virtqueue *), - const char *name) +static void *vring_alloc_queue_split(struct virtio_device *vdev, + dma_addr_t *dma_addr, + u32 *n, + unsigned int vring_align, + bool weak_barriers,
This is not used in this function.
Thanks
Quoted 50 lines
drivers/virtio/virtio_ring.c +24
-6+ bool may_reduce_num) { -struct virtqueue *vq;void *queue =NULL ; -dma_addr_t dma_addr; -size_t queue_size_in_bytes; -struct vring vring; +u32 num = *n;/* We assume num is a power of 2. */ if (num & (num -1 )) {@@ -942,7 +934,7 @@ static struct virtqueue *vring_create_virtqueue_split(/* TODO: allocate each queue chunk individually */ for (; num &&vring_size (num, vring_align) >PAGE_SIZE ; num /=2 ) { queue =vring_alloc_queue (vdev,vring_size (num, vring_align), - &dma_addr, + dma_addr,GFP_KERNEL |__GFP_NOWARN|__GFP_ZERO);if (queue)break ;@@ -956,11 +948,38 @@ static struct virtqueue *vring_create_virtqueue_split(if (!queue) {/* Try to get a single page. You are my only hope! */ queue =vring_alloc_queue (vdev,vring_size (num, vring_align), - &dma_addr,GFP_KERNEL |__GFP_ZERO); + dma_addr,GFP_KERNEL |__GFP_ZERO); }if (!queue)return NULL ; + *n = num; +return queue; +} + +static struct virtqueue *vring_create_virtqueue_split ( +unsigned int index, +unsigned int num, +unsigned int vring_align, +struct virtio_device *vdev, +bool weak_barriers, +bool may_reduce_num, +bool context, +bool (*notify)(struct virtqueue *), +void (*callback)(struct virtqueue *), +const char *name) +{ +size_t queue_size_in_bytes; +struct virtqueue *vq; +dma_addr_t dma_addr; +struct vring vring;
drivers/virtio/virtio_ring.c static struct virtqueue *vring_create_virtqueue_split( · line 985
Quoted 10 lines
drivers/virtio/virtio_ring.c +7
-0+void *queue; + + queue =vring_alloc_queue_split (vdev, &dma_addr, &num, vring_align, + weak_barriers, may_reduce_num); +if (!queue) +return NULL ; + queue_size_in_bytes =vring_size (num, vring_align);vring_init (&vring, num, queue, vring_align);
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 06/32] virtio_ring: split: extract the logic of alloc queue
Quoted 30 lines · Jason Wang
Quoted 28 lines · Xuan Zhuo
Separate the logic of split to create vring queue.
This feature is required for subsequent virtuqueue reset vring.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 53 ++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 17 deletions(-)drivers/virtio/virtio_ring.c +0
-11@@ -915,23 +915,15 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ; } -static struct virtqueue *vring_create_virtqueue_split ( -unsigned int index, -unsigned int num, -unsigned int vring_align, -struct virtio_device *vdev, -bool weak_barriers, -bool may_reduce_num, -bool context, -bool (*notify)(struct virtqueue *), -void (*callback)(struct virtqueue *), -const char *name)
Quoted 8 lines
drivers/virtio/virtio_ring.c static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq) · line 922
Quoted 5 lines
drivers/virtio/virtio_ring.c +5
-0+static void *vring_alloc_queue_split(struct virtio_device *vdev, + dma_addr_t *dma_addr, + u32 *n, + unsigned int vring_align, + bool weak_barriers,This is not used in this function.
The next version will fix it.
Thanks.
Quoted 56 lines
Thanks
Quoted 52 lines
drivers/virtio/virtio_ring.c +26
-6+ bool may_reduce_num) { -struct virtqueue *vq;void *queue =NULL ; -dma_addr_t dma_addr; -size_t queue_size_in_bytes; -struct vring vring; +u32 num = *n;/* We assume num is a power of 2. */ if (num & (num -1 )) {@@ -942,7 +934,7 @@ static struct virtqueue *vring_create_virtqueue_split(/* TODO: allocate each queue chunk individually */ for (; num &&vring_size (num, vring_align) >PAGE_SIZE ; num /=2 ) { queue =vring_alloc_queue (vdev,vring_size (num, vring_align), - &dma_addr, + dma_addr,GFP_KERNEL |__GFP_NOWARN|__GFP_ZERO);if (queue)break ;@@ -956,11 +948,38 @@ static struct virtqueue *vring_create_virtqueue_split(if (!queue) {/* Try to get a single page. You are my only hope! */ queue =vring_alloc_queue (vdev,vring_size (num, vring_align), - &dma_addr,GFP_KERNEL |__GFP_ZERO); + dma_addr,GFP_KERNEL |__GFP_ZERO); }if (!queue)return NULL ; + *n = num; +return queue; +} + +static struct virtqueue *vring_create_virtqueue_split ( +unsigned int index, +unsigned int num, +unsigned int vring_align, +struct virtio_device *vdev, +bool weak_barriers, +bool may_reduce_num, +bool context, +bool (*notify)(struct virtqueue *), +void (*callback)(struct virtqueue *), +const char *name) +{ +size_t queue_size_in_bytes; +struct virtqueue *vq; +dma_addr_t dma_addr; +struct vring vring; +void *queue; +
Quoted 9 lines
drivers/virtio/virtio_ring.c static struct virtqueue *vring_create_virtqueue_split( · line 985
Quoted 8 lines
drivers/virtio/virtio_ring.c +5
-0+ queue =vring_alloc_queue_split (vdev, &dma_addr, &num, vring_align, + weak_barriers, may_reduce_num); +if (!queue) +return NULL ; + queue_size_in_bytes =vring_size (num, vring_align);vring_init (&vring, num, queue, vring_align);
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 7/32 virtio_ring: split: extract the logic of alloc state and extra
In reply to Xuan ZhuoSeparate the logic of creating desc_state, desc_extra, and subsequent patches will call it independently.
--- drivers/virtio/virtio_ring.c | 53 ++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 15 deletions(-)
drivers/virtio/virtio_ring.c +38 -15
@@ -198,6 +198,7 @@ struct vring_virtqueue {#endif }; +static struct vring_desc_extra *vring_alloc_desc_extra (unsigned int num);/* * Helpers.
@@ -915,6 +916,33 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ; } +static int vring_alloc_state_extra_split (u32 num, +struct vring_desc_state_split **desc_state, +struct vring_desc_extra **desc_extra) +{ +struct vring_desc_state_split *state; +struct vring_desc_extra *extra; + + state =kmalloc_array (num,sizeof (struct vring_desc_state_split ),GFP_KERNEL ); +if (!state) + goto err_state; + + extra =vring_alloc_desc_extra (num); +if (!extra) + goto err_extra; + +memset (state,0 , num *sizeof (struct vring_desc_state_split )); + + *desc_state = state; + *desc_extra = extra; +return 0 ; + +err_extra: +kfree (state); +err_state: +return -ENOMEM ; +} + static void *vring_alloc_queue_split(struct virtio_device *vdev, dma_addr_t *dma_addr, u32 *n,
@@ -2196,7 +2224,10 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,void (*callback)(struct virtqueue *), const char *name) { + struct vring_desc_state_split *state; +struct vring_desc_extra *extra;struct vring_virtqueue *vq; +int err;if (virtio_has_feature (vdev,VIRTIO_F_RING_PACKED ))return NULL ;
@@ -2246,30 +2277,22 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->split.avail_flags_shadow); } - vq->split.desc_state =kmalloc_array (vring.num, -sizeof (struct vring_desc_state_split ),GFP_KERNEL ); -if (!vq->split.desc_state) - goto err_state; + err =vring_alloc_state_extra_split (vring.num, &state, &extra); +if (err) { +kfree (vq); +return NULL ; + } - vq->split.desc_extra =vring_alloc_desc_extra (vring.num); -if (!vq->split.desc_extra) - goto err_extra; + vq->split.desc_state = state; + vq->split.desc_extra = extra;/* Put everything in free lists. */ vq->free_head =0 ; -memset (vq->split.desc_state,0 , vring.num * -sizeof (struct vring_desc_state_split ));spin_lock (&vdev->vqs_list_lock);list_add_tail (&vq->vq.list, &vdev->vqs);spin_unlock (&vdev->vqs_list_lock);return &vq->vq; - -err_extra: -kfree (vq->split.desc_state); -err_state: -kfree (vq); -return NULL ; }EXPORT_SYMBOL_GPL (__vring_new_virtqueue);
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 07/32] virtio_ring: split: extract the logic of alloc state and extra
Quoted 66 lines · Xuan Zhuo
Separate the logic of creating
desc_state,desc_extra, and subsequent patches will call it independently.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 53 ++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 15 deletions(-)drivers/virtio/virtio_ring.c +31
-0@@ -198,6 +198,7 @@ struct vring_virtqueue {#endif }; +static struct vring_desc_extra *vring_alloc_desc_extra (unsigned int num);/* * Helpers. @@ -915,6 +916,33 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ; } +static int vring_alloc_state_extra_split (u32 num, +struct vring_desc_state_split **desc_state, +struct vring_desc_extra **desc_extra) +{ +struct vring_desc_state_split *state; +struct vring_desc_extra *extra; + + state =kmalloc_array (num,sizeof (struct vring_desc_state_split ),GFP_KERNEL ); +if (!state) + goto err_state; + + extra =vring_alloc_desc_extra (num); +if (!extra) + goto err_extra; + +memset (state,0 , num *sizeof (struct vring_desc_state_split )); + + *desc_state = state; + *desc_extra = extra; +return 0 ; + +err_extra: +kfree (state); +err_state: +return -ENOMEM ; +} + static void *vring_alloc_queue_split(struct virtio_device *vdev, dma_addr_t *dma_addr, u32 *n,@@ -2196,7 +2224,10 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,void (*callback)(struct virtqueue *), const char *name) { + struct vring_desc_state_split *state; +struct vring_desc_extra *extra;struct vring_virtqueue *vq; +int err;if (virtio_has_feature (vdev,VIRTIO_F_RING_PACKED ))return NULL ;
drivers/virtio/virtio_ring.c struct virtqueue *__vring_new_virtqueue(unsigned int index, · line 2280
Quoted 8 lines
drivers/virtio/virtio_ring.c +1
-4@@ -2246,30 +2277,22 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->split.avail_flags_shadow); } - vq->split.desc_state =kmalloc_array (vring.num, -sizeof (struct vring_desc_state_split ),GFP_KERNEL ); -if (!vq->split.desc_state) - goto err_state; + err =vring_alloc_state_extra_split (vring.num, &state, &extra);
Nit: we can pass e.g &vq->split.desc_state here to avoid extra temp variable and assignment.
Other looks good.
Thanks
Quoted 19 lines
drivers/virtio/virtio_ring.c +6
-5+if (err) { +kfree (vq); +return NULL ; + } - vq->split.desc_extra =vring_alloc_desc_extra (vring.num); -if (!vq->split.desc_extra) - goto err_extra; + vq->split.desc_state = state; + vq->split.desc_extra = extra;/* Put everything in free lists. */ vq->free_head =0 ; -memset (vq->split.desc_state,0 , vring.num * -sizeof (struct vring_desc_state_split ));spin_lock (&vdev->vqs_list_lock);list_add_tail (&vq->vq.list, &vdev->vqs);spin_unlock (&vdev->vqs_list_lock);
drivers/virtio/virtio_ring.c struct virtqueue *__vring_new_virtqueue(unsigned int index, · line 2298
Quoted 10 lines
drivers/virtio/virtio_ring.c +0
-6return &vq->vq; - -err_extra: -kfree (vq->split.desc_state); -err_state: -kfree (vq); -return NULL ; }EXPORT_SYMBOL_GPL (__vring_new_virtqueue);
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 07/32] virtio_ring: split: extract the logic of alloc state and extra
Quoted 71 lines · Jason Wang
Quoted 69 lines · Xuan Zhuo
Separate the logic of creating
desc_state,desc_extra, and subsequent patches will call it independently.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 53 ++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 15 deletions(-)drivers/virtio/virtio_ring.c +31
-0@@ -198,6 +198,7 @@ struct vring_virtqueue {#endif }; +static struct vring_desc_extra *vring_alloc_desc_extra (unsigned int num);/* * Helpers. @@ -915,6 +916,33 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ; } +static int vring_alloc_state_extra_split (u32 num, +struct vring_desc_state_split **desc_state, +struct vring_desc_extra **desc_extra) +{ +struct vring_desc_state_split *state; +struct vring_desc_extra *extra; + + state =kmalloc_array (num,sizeof (struct vring_desc_state_split ),GFP_KERNEL ); +if (!state) + goto err_state; + + extra =vring_alloc_desc_extra (num); +if (!extra) + goto err_extra; + +memset (state,0 , num *sizeof (struct vring_desc_state_split )); + + *desc_state = state; + *desc_extra = extra; +return 0 ; + +err_extra: +kfree (state); +err_state: +return -ENOMEM ; +} + static void *vring_alloc_queue_split(struct virtio_device *vdev, dma_addr_t *dma_addr, u32 *n,@@ -2196,7 +2224,10 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,void (*callback)(struct virtqueue *), const char *name) { + struct vring_desc_state_split *state; +struct vring_desc_extra *extra;struct vring_virtqueue *vq; +int err;if (virtio_has_feature (vdev,VIRTIO_F_RING_PACKED ))return NULL ;@@ -2246,30 +2277,22 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->split.avail_flags_shadow); }
Quoted 9 lines
drivers/virtio/virtio_ring.c struct virtqueue *__vring_new_virtqueue(unsigned int index, · line 2280
Quoted 5 lines
drivers/virtio/virtio_ring.c +1
-4- vq->split.desc_state =kmalloc_array (vring.num, -sizeof (struct vring_desc_state_split ),GFP_KERNEL ); -if (!vq->split.desc_state) - goto err_state; + err =vring_alloc_state_extra_split (vring.num, &state, &extra);Nit: we can pass e.g
&vq->split.desc_statehere to avoid extra temp variable and assignment.
The reason for not doing this is that when we implement resize later, when we call vring_alloc_state_extra_split(), we want to keep the old desc_state, and desc_extra because we want to release them.
As discussed in patch 11, 12, struct vring_virtqueue_split will optimize this logic.
Thanks.
Quoted 22 lines
Other looks good.
Thanks
Quoted 16 lines
drivers/virtio/virtio_ring.c +6
-5+if (err) { +kfree (vq); +return NULL ; + } - vq->split.desc_extra =vring_alloc_desc_extra (vring.num); -if (!vq->split.desc_extra) - goto err_extra; + vq->split.desc_state = state; + vq->split.desc_extra = extra;/* Put everything in free lists. */ vq->free_head =0 ; -memset (vq->split.desc_state,0 , vring.num * -sizeof (struct vring_desc_state_split ));
Quoted 14 lines
drivers/virtio/virtio_ring.c struct virtqueue *__vring_new_virtqueue(unsigned int index, · line 2298
Quoted 13 lines
drivers/virtio/virtio_ring.c +0
-6spin_lock (&vdev->vqs_list_lock);list_add_tail (&vq->vq.list, &vdev->vqs);spin_unlock (&vdev->vqs_list_lock);return &vq->vq; - -err_extra: -kfree (vq->split.desc_state); -err_state: -kfree (vq); -return NULL ; }EXPORT_SYMBOL_GPL (__vring_new_virtqueue);
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 8/32 virtio_ring: split: extract the logic of attach vring
In reply to Xuan ZhuoSeparate the logic of attach vring, subsequent patches will call it separately.
--- drivers/virtio/virtio_ring.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/virtio/virtio_ring.c +14 -6
@@ -916,6 +916,19 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ; } +static void vring_virtqueue_attach_split (struct vring_virtqueue *vq, +struct vring vring, +struct vring_desc_state_split *desc_state, +struct vring_desc_extra *desc_extra) +{ + vq->split.vring = vring; + vq->split.queue_dma_addr =0 ; + vq->split.queue_size_in_bytes =0 ; + + vq->split.desc_state = desc_state; + vq->split.desc_extra = desc_extra; +} +static int vring_alloc_state_extra_split (u32 num,struct vring_desc_state_split **desc_state,struct vring_desc_extra **desc_extra)
@@ -2262,10 +2275,6 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) vq->weak_barriers = false; - vq->split.queue_dma_addr =0 ; - vq->split.queue_size_in_bytes =0 ; - - vq->split.vring = vring; vq->split.avail_flags_shadow =0 ; vq->split.avail_idx_shadow =0 ;
@@ -2283,8 +2292,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,return NULL ; } - vq->split.desc_state = state; - vq->split.desc_extra = extra; +vring_virtqueue_attach_split (vq, vring, state, extra);/* Put everything in free lists. */ vq->free_head =0 ;
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 08/32] virtio_ring: split: extract the logic of attach vring
Quoted 14 lines · Xuan Zhuo
Separate the logic of attach vring, subsequent patches will call it separately.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)drivers/virtio/virtio_ring.c +0
-0@@ -916,6 +916,19 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ;
drivers/virtio/virtio_ring.c static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq) · line 926
Quoted 10 lines
drivers/virtio/virtio_ring.c +8
-0} +static void vring_virtqueue_attach_split (struct vring_virtqueue *vq, +struct vring vring, +struct vring_desc_state_split *desc_state, +struct vring_desc_extra *desc_extra) +{ + vq->split.vring = vring; + vq->split.queue_dma_addr =0 ; + vq->split.queue_size_in_bytes =0 ;
Any reason to add the above two assignment in attach? It seems belong to free or reset.
Thanks
Quoted 20 lines
drivers/virtio/virtio_ring.c +5
-4+ + vq->split.desc_state = desc_state; + vq->split.desc_extra = desc_extra; +} +static int vring_alloc_state_extra_split (u32 num,struct vring_desc_state_split **desc_state,struct vring_desc_extra **desc_extra)@@ -2262,10 +2275,6 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) vq->weak_barriers = false; - vq->split.queue_dma_addr =0 ; - vq->split.queue_size_in_bytes =0 ; - - vq->split.vring = vring; vq->split.avail_flags_shadow =0 ; vq->split.avail_idx_shadow =0 ;
drivers/virtio/virtio_ring.c struct virtqueue *__vring_new_virtqueue(unsigned int index, · line 2298
Quoted 9 lines
drivers/virtio/virtio_ring.c +1
-2@@ -2283,8 +2292,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,return NULL ; } - vq->split.desc_state = state; - vq->split.desc_extra = extra; +vring_virtqueue_attach_split (vq, vring, state, extra);/* Put everything in free lists. */ vq->free_head =0 ;
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 08/32] virtio_ring: split: extract the logic of attach vring
Quoted 18 lines · Jason Wang
Quoted 16 lines · Xuan Zhuo
Separate the logic of attach vring, subsequent patches will call it separately.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)drivers/virtio/virtio_ring.c +0
-0@@ -916,6 +916,19 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ; }
Quoted 12 lines
drivers/virtio/virtio_ring.c static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq) · line 926
Quoted 8 lines
drivers/virtio/virtio_ring.c +8
-0+static void vring_virtqueue_attach_split (struct vring_virtqueue *vq, +struct vring vring, +struct vring_desc_state_split *desc_state, +struct vring_desc_extra *desc_extra) +{ + vq->split.vring = vring; + vq->split.queue_dma_addr =0 ; + vq->split.queue_size_in_bytes =0 ;Any reason to add the above two assignment in attach? It seems belong to free or reset.
As discussed in patch 11, since there is no dma_addr in __vring_new_virtqueue(), the corresponding vq->split.queue_dma_addr cannot be set, so the purpose here is just to initialize it.
In the next version, struct vring_virtqueue_split will be passed to vring_virtqueue_attach_split() to make the logic here look more reasonable.
Thanks.
Quoted 27 lines
Thanks
Quoted 23 lines
drivers/virtio/virtio_ring.c +5
-4+ + vq->split.desc_state = desc_state; + vq->split.desc_extra = desc_extra; +} +static int vring_alloc_state_extra_split (u32 num,struct vring_desc_state_split **desc_state,struct vring_desc_extra **desc_extra)@@ -2262,10 +2275,6 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) vq->weak_barriers = false; - vq->split.queue_dma_addr =0 ; - vq->split.queue_size_in_bytes =0 ; - - vq->split.vring = vring; vq->split.avail_flags_shadow =0 ; vq->split.avail_idx_shadow =0 ;@@ -2283,8 +2292,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,return NULL ; }
Quoted 7 lines
drivers/virtio/virtio_ring.c struct virtqueue *__vring_new_virtqueue(unsigned int index, · line 2298
Quoted 6 lines
drivers/virtio/virtio_ring.c +1
-2- vq->split.desc_state = state; - vq->split.desc_extra = extra; +vring_virtqueue_attach_split (vq, vring, state, extra);/* Put everything in free lists. */ vq->free_head =0 ;
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 9/32 virtio_ring: split: extract the logic of vq init
In reply to Xuan ZhuoSeparate the logic of initializing vq, and subsequent patches will call it separately.
The feature of this part is that it does not depend on the information passed by the upper layer and can be called repeatedly.
--- drivers/virtio/virtio_ring.c | 68 ++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 30 deletions(-)
drivers/virtio/virtio_ring.c +38 -30
@@ -916,6 +916,43 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ; } +static void vring_virtqueue_init_split (struct vring_virtqueue *vq, +struct virtio_device *vdev, +bool own_ring) +{ + vq->packed_ring = false; + vq->vq.num_free = vq->split.vring.num; + vq->we_own_ring = own_ring; + vq->broken = false; + vq->last_used_idx =0 ; + vq->event_triggered = false; + vq->num_added =0 ; + vq->use_dma_api =vring_use_dma_api (vdev); +#ifdef DEBUG + vq->in_use = false; + vq->last_add_time_valid = false; +#endif + + vq->event =virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX ); + +if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) + vq->weak_barriers = false; + + vq->split.avail_flags_shadow =0 ; + vq->split.avail_idx_shadow =0 ; + +/* No callback? Tell other side not to bother us. */ +if (!vq->vq.callback) { + vq->split.avail_flags_shadow |=VRING_AVAIL_F_NO_INTERRUPT ; +if (!vq->event) + vq->split.vring.avail->flags =cpu_to_virtio16 (vdev, + vq->split.avail_flags_shadow); + } + +/* Put everything in free lists. */ + vq->free_head =0 ; +} + static void vring_virtqueue_attach_split(struct vring_virtqueue *vq, struct vring vring, struct vring_desc_state_split *desc_state,
@@ -2249,42 +2286,15 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,if (!vq)return NULL ; - vq->packed_ring = false; vq->vq.callback = callback; vq->vq.vdev = vdev; vq->vq.name = name; - vq->vq.num_free = vring.num; vq->vq.index = index; - vq->we_own_ring = false; vq->notify = notify; vq->weak_barriers = weak_barriers; - vq->broken = false; - vq->last_used_idx =0 ; - vq->event_triggered = false; - vq->num_added =0 ; - vq->use_dma_api =vring_use_dma_api (vdev); -#ifdef DEBUG - vq->in_use = false; - vq->last_add_time_valid = false; -#endif vq->indirect =virtio_has_feature (vdev,VIRTIO_RING_F_INDIRECT_DESC ) && !context; - vq->event =virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX ); - -if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) - vq->weak_barriers = false; - - vq->split.avail_flags_shadow =0 ; - vq->split.avail_idx_shadow =0 ; - -/* No callback? Tell other side not to bother us. */ -if (!callback) { - vq->split.avail_flags_shadow |=VRING_AVAIL_F_NO_INTERRUPT ; -if (!vq->event) - vq->split.vring.avail->flags =cpu_to_virtio16 (vdev, - vq->split.avail_flags_shadow); - } err =vring_alloc_state_extra_split (vring.num, &state, &extra);if (err) {
@@ -2293,9 +2303,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, }vring_virtqueue_attach_split (vq, vring, state, extra); - -/* Put everything in free lists. */ - vq->free_head =0 ; +vring_virtqueue_init_split (vq, vdev, false);spin_lock (&vdev->vqs_list_lock);list_add_tail (&vq->vq.list, &vdev->vqs);
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 09/32] virtio_ring: split: extract the logic of vq init
Quoted 44 lines · Xuan Zhuo
Separate the logic of initializing vq, and subsequent patches will call it separately.
The feature of this part is that it does not depend on the information passed by the upper layer and can be called repeatedly.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 68 ++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 30 deletions(-)drivers/virtio/virtio_ring.c +25
-0@@ -916,6 +916,43 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ; } +static void vring_virtqueue_init_split (struct vring_virtqueue *vq, +struct virtio_device *vdev, +bool own_ring) +{ + vq->packed_ring = false; + vq->vq.num_free = vq->split.vring.num; + vq->we_own_ring = own_ring; + vq->broken = false; + vq->last_used_idx =0 ; + vq->event_triggered = false; + vq->num_added =0 ; + vq->use_dma_api =vring_use_dma_api (vdev); +#ifdef DEBUG + vq->in_use = false; + vq->last_add_time_valid = false; +#endif + + vq->event =virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX ); + +if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) + vq->weak_barriers = false; + + vq->split.avail_flags_shadow =0 ; + vq->split.avail_idx_shadow =0 ; +
drivers/virtio/virtio_ring.c static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq) · line 953
Quoted 10 lines
drivers/virtio/virtio_ring.c +10
-0+/* No callback? Tell other side not to bother us. */ +if (!vq->vq.callback) { + vq->split.avail_flags_shadow |=VRING_AVAIL_F_NO_INTERRUPT ; +if (!vq->event) + vq->split.vring.avail->flags =cpu_to_virtio16 (vdev, + vq->split.avail_flags_shadow); + } + +/* Put everything in free lists. */ + vq->free_head =0 ;
It's not clear what kind of initialization that we want to do here. E.g it mixes split specific setups with some general setups which is kind of duplication of vring_virtqueue_init_packed().
I wonder if it's better to only do split specific setups here and have a common helper to do the setup that is irrelevant to ring layout.
Thanks
Quoted 49 lines
drivers/virtio/virtio_ring.c +2
-27+} + static void vring_virtqueue_attach_split(struct vring_virtqueue *vq, struct vring vring, struct vring_desc_state_split *desc_state,@@ -2249,42 +2286,15 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,if (!vq)return NULL ; - vq->packed_ring = false; vq->vq.callback = callback; vq->vq.vdev = vdev; vq->vq.name = name; - vq->vq.num_free = vring.num; vq->vq.index = index; - vq->we_own_ring = false; vq->notify = notify; vq->weak_barriers = weak_barriers; - vq->broken = false; - vq->last_used_idx =0 ; - vq->event_triggered = false; - vq->num_added =0 ; - vq->use_dma_api =vring_use_dma_api (vdev); -#ifdef DEBUG - vq->in_use = false; - vq->last_add_time_valid = false; -#endif vq->indirect =virtio_has_feature (vdev,VIRTIO_RING_F_INDIRECT_DESC ) && !context; - vq->event =virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX ); - -if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) - vq->weak_barriers = false; - - vq->split.avail_flags_shadow =0 ; - vq->split.avail_idx_shadow =0 ; - -/* No callback? Tell other side not to bother us. */ -if (!callback) { - vq->split.avail_flags_shadow |=VRING_AVAIL_F_NO_INTERRUPT ; -if (!vq->event) - vq->split.vring.avail->flags =cpu_to_virtio16 (vdev, - vq->split.avail_flags_shadow); - } err =vring_alloc_state_extra_split (vring.num, &state, &extra);if (err) {
drivers/virtio/virtio_ring.c struct virtqueue *__vring_new_virtqueue(unsigned int index, · line 2309
Quoted 10 lines
drivers/virtio/virtio_ring.c +1
-3@@ -2293,9 +2303,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, }vring_virtqueue_attach_split (vq, vring, state, extra); - -/* Put everything in free lists. */ - vq->free_head =0 ; +vring_virtqueue_init_split (vq, vdev, false);spin_lock (&vdev->vqs_list_lock);list_add_tail (&vq->vq.list, &vdev->vqs);
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 09/32] virtio_ring: split: extract the logic of vq init
Quoted 62 lines · Jason Wang
Quoted 44 lines · Xuan Zhuo
Separate the logic of initializing vq, and subsequent patches will call it separately.
The feature of this part is that it does not depend on the information passed by the upper layer and can be called repeatedly.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 68 ++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 30 deletions(-)drivers/virtio/virtio_ring.c +25
-0@@ -916,6 +916,43 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq)return NULL ; } +static void vring_virtqueue_init_split (struct vring_virtqueue *vq, +struct virtio_device *vdev, +bool own_ring) +{ + vq->packed_ring = false; + vq->vq.num_free = vq->split.vring.num; + vq->we_own_ring = own_ring; + vq->broken = false; + vq->last_used_idx =0 ; + vq->event_triggered = false; + vq->num_added =0 ; + vq->use_dma_api =vring_use_dma_api (vdev); +#ifdef DEBUG + vq->in_use = false; + vq->last_add_time_valid = false; +#endif + + vq->event =virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX ); + +if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) + vq->weak_barriers = false; + + vq->split.avail_flags_shadow =0 ; + vq->split.avail_idx_shadow =0 ; +drivers/virtio/virtio_ring.c static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq) · line 953
Quoted 10 lines
drivers/virtio/virtio_ring.c +10
-0+/* No callback? Tell other side not to bother us. */ +if (!vq->vq.callback) { + vq->split.avail_flags_shadow |=VRING_AVAIL_F_NO_INTERRUPT ; +if (!vq->event) + vq->split.vring.avail->flags =cpu_to_virtio16 (vdev, + vq->split.avail_flags_shadow); + } + +/* Put everything in free lists. */ + vq->free_head =0 ;It's not clear what kind of initialization that we want to do here. E.g it mixes split specific setups with some general setups which is kind of duplication of
vring_virtqueue_init_packed().
Quoted 2 lines
I wonder if it's better to only do split specific setups here and have a common helper to do the setup that is irrelevant to ring layout.
Yes, you are right, I didn't notice this situation before.
Thanks.
Quoted 64 lines
Thanks
Quoted 59 lines
drivers/virtio/virtio_ring.c +3
-30+} + static void vring_virtqueue_attach_split(struct vring_virtqueue *vq, struct vring vring, struct vring_desc_state_split *desc_state,@@ -2249,42 +2286,15 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,if (!vq)return NULL ; - vq->packed_ring = false; vq->vq.callback = callback; vq->vq.vdev = vdev; vq->vq.name = name; - vq->vq.num_free = vring.num; vq->vq.index = index; - vq->we_own_ring = false; vq->notify = notify; vq->weak_barriers = weak_barriers; - vq->broken = false; - vq->last_used_idx =0 ; - vq->event_triggered = false; - vq->num_added =0 ; - vq->use_dma_api =vring_use_dma_api (vdev); -#ifdef DEBUG - vq->in_use = false; - vq->last_add_time_valid = false; -#endif vq->indirect =virtio_has_feature (vdev,VIRTIO_RING_F_INDIRECT_DESC ) && !context; - vq->event =virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX ); - -if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) - vq->weak_barriers = false; - - vq->split.avail_flags_shadow =0 ; - vq->split.avail_idx_shadow =0 ; - -/* No callback? Tell other side not to bother us. */ -if (!callback) { - vq->split.avail_flags_shadow |=VRING_AVAIL_F_NO_INTERRUPT ; -if (!vq->event) - vq->split.vring.avail->flags =cpu_to_virtio16 (vdev, - vq->split.avail_flags_shadow); - } err =vring_alloc_state_extra_split (vring.num, &state, &extra);if (err) {@@ -2293,9 +2303,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, }vring_virtqueue_attach_split (vq, vring, state, extra); - -/* Put everything in free lists. */ - vq->free_head =0 ; +vring_virtqueue_init_split (vq, vdev, false);spin_lock (&vdev->vqs_list_lock);list_add_tail (&vq->vq.list, &vdev->vqs);
Xuan Zhuo
reviewerPATCH v9 10/32 virtio_ring: split: introduce virtqueue_reinit_split()
In reply to Xuan ZhuoIntroduce a function to initialize vq without allocating new ring, desc_state, desc_extra.
Subsequent patches will call this function after reset vq to reinitialize vq.
--- drivers/virtio/virtio_ring.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/virtio/virtio_ring.c +19 -0
@@ -953,6 +953,25 @@ static void vring_virtqueue_init_split(struct vring_virtqueue *vq, vq->free_head =0 ; } +static void virtqueue_reinit_split (struct vring_virtqueue *vq) +{ +struct virtio_device *vdev = vq->vq.vdev; +int size, i; + +memset (vq->split.vring.desc,0 , vq->split.queue_size_in_bytes); + + size =sizeof (struct vring_desc_state_split ) * vq->split.vring.num; +memset (vq->split.desc_state,0 , size); + + size =sizeof (struct vring_desc_extra ) * vq->split.vring.num; +memset (vq->split.desc_extra,0 , size); + +for (i =0 ; i < vq->split.vring.num -1 ; i++) + vq->split.desc_extra[i].next = i +1 ; + +vring_virtqueue_init_split (vq, vdev, true); +} + static void vring_virtqueue_attach_split(struct vring_virtqueue *vq, struct vring vring, struct vring_desc_state_split *desc_state,
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 10/32] virtio_ring: split: introduce virtqueue_reinit_split()
Quoted 7 lines · Xuan Zhuo
Introduce a function to initialize vq without allocating new ring,
desc_state,desc_extra.Subsequent patches will call this function after reset vq to reinitialize vq.
Signed-off-by Xuan Zhuo <[email protected]>
Quoted 34 lines
--- drivers/virtio/virtio_ring.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/virtio/virtio_ring.c +19
-0@@ -953,6 +953,25 @@ static void vring_virtqueue_init_split(struct vring_virtqueue *vq, vq->free_head =0 ; } +static void virtqueue_reinit_split (struct vring_virtqueue *vq) +{ +struct virtio_device *vdev = vq->vq.vdev; +int size, i; + +memset (vq->split.vring.desc,0 , vq->split.queue_size_in_bytes); + + size =sizeof (struct vring_desc_state_split ) * vq->split.vring.num; +memset (vq->split.desc_state,0 , size); + + size =sizeof (struct vring_desc_extra ) * vq->split.vring.num; +memset (vq->split.desc_extra,0 , size); + +for (i =0 ; i < vq->split.vring.num -1 ; i++) + vq->split.desc_extra[i].next = i +1 ; + +vring_virtqueue_init_split (vq, vdev, true); +} + static void vring_virtqueue_attach_split(struct vring_virtqueue *vq, struct vring vring, struct vring_desc_state_split *desc_state,
Xuan Zhuo
reviewerPATCH v9 11/32 virtio_ring: split: introduce virtqueue_resize_split()
In reply to Xuan Zhuovirtio ring split supports resize.
Only after the new vring is successfully allocated based on the new num, we will release the old vring. In any case, an error is returned, indicating that the vring still points to the old vring.
In the case of an error, the caller must re-initialize(virtqueue_reinit_split()) the virtqueue to ensure that the vring can be used.
In addition, vring_align, may_reduce_num are necessary for reallocating vring, so they are retained for creating vq.
--- drivers/virtio/virtio_ring.c | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/virtio/virtio_ring.c +47 -0
@@ -139,6 +139,12 @@ struct vring_virtqueue {/* DMA address and size information */ dma_addr_t queue_dma_addr;size_t queue_size_in_bytes; + +/* The parameters for creating vrings are reserved for +* creating new vring. +*/ +u32 vring_align; +bool may_reduce_num; } split;/* Available for packed ring */
@@ -199,6 +205,7 @@ struct vring_virtqueue { };static struct vring_desc_extra *vring_alloc_desc_extra (unsigned int num); +static void vring_free (struct virtqueue *_vq);/* * Helpers.
@@ -1088,6 +1095,8 @@ static struct virtqueue *vring_create_virtqueue_split(return NULL ; } +to_vvq (vq)->split.vring_align = vring_align; +to_vvq (vq)->split.may_reduce_num = may_reduce_num;to_vvq (vq)->split.queue_dma_addr = dma_addr;to_vvq (vq)->split.queue_size_in_bytes = queue_size_in_bytes;to_vvq (vq)->we_own_ring = true;
@@ -1095,6 +1104,44 @@ static struct virtqueue *vring_create_virtqueue_split(return vq; } +static int virtqueue_resize_split (struct virtqueue *_vq,u32 num) +{ +struct vring_virtqueue *vq =to_vvq (_vq); +struct virtio_device *vdev = _vq->vdev; +struct vring_desc_state_split *state; +struct vring_desc_extra *extra; +size_t queue_size_in_bytes; +dma_addr_t dma_addr; +struct vring vring; +int err = -ENOMEM ; +void *queue; + + queue =vring_alloc_queue_split (vdev, &dma_addr, &num, + vq->split.vring_align, + vq->weak_barriers, + vq->split.may_reduce_num); +if (!queue) +return -ENOMEM ; + + queue_size_in_bytes =vring_size (num, vq->split.vring_align); + + err =vring_alloc_state_extra_split (num, &state, &extra); +if (err) { +vring_free_queue (vdev, queue_size_in_bytes, queue, dma_addr); +return -ENOMEM ; + } + +vring_free (&vq->vq); + +vring_init (&vring, num, queue, vq->split.vring_align); +vring_virtqueue_attach_split (vq, vring, state, extra); + vq->split.queue_dma_addr = dma_addr; + vq->split.queue_size_in_bytes = queue_size_in_bytes; + +vring_virtqueue_init_split (vq, vdev, true); +return 0 ; +} +/* * Packed ring specific functions - *_packed().
Signature · 6 lines
2.31.0 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v9 11/32] virtio_ring: split: introduce virtqueue_resize_split()
Quoted 44 lines · Xuan Zhuo
virtio ring split supports resize.
Only after the new vring is successfully allocated based on the new num, we will release the old vring. In any case, an error is returned, indicating that the vring still points to the old vring.
In the case of an error, the caller must re-initialize(virtqueue_reinit_split()) the virtqueue to ensure that the vring can be used.
In addition,
vring_align,may_reduce_numare necessary for reallocating vring, so they are retained for creating vq.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)drivers/virtio/virtio_ring.c +7
-0@@ -139,6 +139,12 @@ struct vring_virtqueue {/* DMA address and size information */ dma_addr_t queue_dma_addr;size_t queue_size_in_bytes; + +/* The parameters for creating vrings are reserved for +* creating new vring. +*/ +u32 vring_align; +bool may_reduce_num; } split;/* Available for packed ring */ @@ -199,6 +205,7 @@ struct vring_virtqueue { };static struct vring_desc_extra *vring_alloc_desc_extra (unsigned int num); +static void vring_free (struct virtqueue *_vq);/* * Helpers.
drivers/virtio/virtio_ring.c static struct virtqueue *vring_create_virtqueue_split( · line 1099
Quoted 5 lines
drivers/virtio/virtio_ring.c +2
-0@@ -1088,6 +1095,8 @@ static struct virtqueue *vring_create_virtqueue_split(return NULL ; } +to_vvq (vq)->split.vring_align = vring_align; +to_vvq (vq)->split.may_reduce_num = may_reduce_num;
It looks to me the above should belong to patch 6.
Quoted 30 lines
drivers/virtio/virtio_ring.c +23
-0to_vvq (vq)->split.queue_dma_addr = dma_addr;to_vvq (vq)->split.queue_size_in_bytes = queue_size_in_bytes;to_vvq (vq)->we_own_ring = true;@@ -1095,6 +1104,44 @@ static struct virtqueue *vring_create_virtqueue_split(return vq; } +static int virtqueue_resize_split (struct virtqueue *_vq,u32 num) +{ +struct vring_virtqueue *vq =to_vvq (_vq); +struct virtio_device *vdev = _vq->vdev; +struct vring_desc_state_split *state; +struct vring_desc_extra *extra; +size_t queue_size_in_bytes; +dma_addr_t dma_addr; +struct vring vring; +int err = -ENOMEM ; +void *queue; + + queue =vring_alloc_queue_split (vdev, &dma_addr, &num, + vq->split.vring_align, + vq->weak_barriers, + vq->split.may_reduce_num); +if (!queue) +return -ENOMEM ; + + queue_size_in_bytes =vring_size (num, vq->split.vring_align); + + err =vring_alloc_state_extra_split (num, &state, &extra); +if (err) {
drivers/virtio/virtio_ring.c static struct virtqueue *vring_create_virtqueue_split( · line 1139
Quoted 10 lines
drivers/virtio/virtio_ring.c +10
-0+vring_free_queue (vdev, queue_size_in_bytes, queue, dma_addr); +return -ENOMEM ; + } + +vring_free (&vq->vq); + +vring_init (&vring, num, queue, vq->split.vring_align); +vring_virtqueue_attach_split (vq, vring, state, extra); + vq->split.queue_dma_addr = dma_addr; + vq->split.queue_size_in_bytes = queue_size_in_bytes;
I wonder if it's better to move the above assignments to vring_virtqueue_attach_split().
Other looks good.
Thanks
drivers/virtio/virtio_ring.c static struct virtqueue *vring_create_virtqueue_split( · line 1147
Quoted 8 lines
drivers/virtio/virtio_ring.c +5
-0+ +vring_virtqueue_init_split (vq, vdev, true); +return 0 ; +} +/* * Packed ring specific functions - *_packed().
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 11/32] virtio_ring: split: introduce virtqueue_resize_split()
Quoted 49 lines · Jason Wang
Quoted 47 lines · Xuan Zhuo
virtio ring split supports resize.
Only after the new vring is successfully allocated based on the new num, we will release the old vring. In any case, an error is returned, indicating that the vring still points to the old vring.
In the case of an error, the caller must re-initialize(virtqueue_reinit_split()) the virtqueue to ensure that the vring can be used.
In addition,
vring_align,may_reduce_numare necessary for reallocating vring, so they are retained for creating vq.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)drivers/virtio/virtio_ring.c +7
-0@@ -139,6 +139,12 @@ struct vring_virtqueue {/* DMA address and size information */ dma_addr_t queue_dma_addr;size_t queue_size_in_bytes; + +/* The parameters for creating vrings are reserved for +* creating new vring. +*/ +u32 vring_align; +bool may_reduce_num; } split;/* Available for packed ring */ @@ -199,6 +205,7 @@ struct vring_virtqueue { };static struct vring_desc_extra *vring_alloc_desc_extra (unsigned int num); +static void vring_free (struct virtqueue *_vq);/* * Helpers. @@ -1088,6 +1095,8 @@ static struct virtqueue *vring_create_virtqueue_split(return NULL ; }
Quoted 5 lines
drivers/virtio/virtio_ring.c static struct virtqueue *vring_create_virtqueue_split( · line 1099
Quoted 2 lines
drivers/virtio/virtio_ring.c +2
-0+to_vvq (vq)->split.vring_align = vring_align; +to_vvq (vq)->split.may_reduce_num = may_reduce_num;It looks to me the above should belong to patch 6.
patch 6 just extracts a function, no logical modification.
to_vvq(vq)->split.may_reduce_num is newly added, so I don't think it should be merged into patch 6.
Quoted 38 lines
Quoted 38 lines
drivers/virtio/virtio_ring.c +29
-0to_vvq (vq)->split.queue_dma_addr = dma_addr;to_vvq (vq)->split.queue_size_in_bytes = queue_size_in_bytes;to_vvq (vq)->we_own_ring = true;@@ -1095,6 +1104,44 @@ static struct virtqueue *vring_create_virtqueue_split(return vq; } +static int virtqueue_resize_split (struct virtqueue *_vq,u32 num) +{ +struct vring_virtqueue *vq =to_vvq (_vq); +struct virtio_device *vdev = _vq->vdev; +struct vring_desc_state_split *state; +struct vring_desc_extra *extra; +size_t queue_size_in_bytes; +dma_addr_t dma_addr; +struct vring vring; +int err = -ENOMEM ; +void *queue; + + queue =vring_alloc_queue_split (vdev, &dma_addr, &num, + vq->split.vring_align, + vq->weak_barriers, + vq->split.may_reduce_num); +if (!queue) +return -ENOMEM ; + + queue_size_in_bytes =vring_size (num, vq->split.vring_align); + + err =vring_alloc_state_extra_split (num, &state, &extra); +if (err) { +vring_free_queue (vdev, queue_size_in_bytes, queue, dma_addr); +return -ENOMEM ; + } + +vring_free (&vq->vq); +
Quoted 8 lines
drivers/virtio/virtio_ring.c static struct virtqueue *vring_create_virtqueue_split( · line 1139
Quoted 4 lines
drivers/virtio/virtio_ring.c +4
-0+vring_init (&vring, num, queue, vq->split.vring_align); +vring_virtqueue_attach_split (vq, vring, state, extra); + vq->split.queue_dma_addr = dma_addr; + vq->split.queue_size_in_bytes = queue_size_in_bytes;I wonder if it's better to move the above assignments to
vring_virtqueue_attach_split().
I also think so, the reason for not doing this is that there is no dma_addr and queue_size_in_bytes when vring_virtqueue_attach_split is called in __vring_new_virtqueue.
As discussed in patch 12, we can pass the struct struct vring_virtqueue_split to vring_virtqueue_attach_split(). This is much more convenient.
Thanks.
Quoted 6 lines
Other looks good.
Thanks
Quoted 9 lines
drivers/virtio/virtio_ring.c static struct virtqueue *vring_create_virtqueue_split( · line 1147
Quoted 8 lines
drivers/virtio/virtio_ring.c +5
-0+ +vring_virtqueue_init_split (vq, vdev, true); +return 0 ; +} +/* * Packed ring specific functions - *_packed().
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 12/32 virtio_ring: packed: extract the logic of alloc queue
In reply to Xuan ZhuoSeparate the logic of packed to create vring queue.
For the convenience of passing parameters, add a structure vring_packed.
This feature is required for subsequent virtuqueue reset vring.
--- drivers/virtio/virtio_ring.c | 70 ++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 14 deletions(-)
drivers/virtio/virtio_ring.c +56 -14
@@ -1817,19 +1817,17 @@ static struct vring_desc_extra *vring_alloc_desc_extra(unsigned int num)return desc_extra; } -static struct virtqueue *vring_create_virtqueue_packed ( -unsigned int index, -unsigned int num, -unsigned int vring_align, -struct virtio_device *vdev, -bool weak_barriers, -bool may_reduce_num, -bool context, -bool (*notify)(struct virtqueue *), -void (*callback)(struct virtqueue *), -const char *name) +static int vring_alloc_queue_packed (struct virtio_device *vdev, +u32 num, +struct vring_packed_desc **_ring, +struct vring_packed_desc_event **_driver, +struct vring_packed_desc_event **_device, +dma_addr_t *_ring_dma_addr, +dma_addr_t *_driver_event_dma_addr, +dma_addr_t *_device_event_dma_addr, +size_t *_ring_size_in_bytes, +size_t *_event_size_in_bytes) { -struct vring_virtqueue *vq;struct vring_packed_desc *ring;struct vring_packed_desc_event *driver, *device;dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr;
@@ -1857,6 +1855,52 @@ static struct virtqueue *vring_create_virtqueue_packed(if (!device) goto err_device; + *_ring = ring; + *_driver = driver; + *_device = device; + *_ring_dma_addr = ring_dma_addr; + *_driver_event_dma_addr = driver_event_dma_addr; + *_device_event_dma_addr = device_event_dma_addr; + *_ring_size_in_bytes = ring_size_in_bytes; + *_event_size_in_bytes = event_size_in_bytes; + +return 0 ; + +err_device: +vring_free_queue (vdev, event_size_in_bytes, driver, driver_event_dma_addr); + +err_driver: +vring_free_queue (vdev, ring_size_in_bytes, ring, ring_dma_addr); + +err_ring: +return -ENOMEM ; +} + +static struct virtqueue *vring_create_virtqueue_packed ( +unsigned int index, +unsigned int num, +unsigned int vring_align, +struct virtio_device *vdev, +bool weak_barriers, +bool may_reduce_num, +bool context, +bool (*notify)(struct virtqueue *), +void (*callback)(struct virtqueue *), +const char *name) +{ +dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr; +struct vring_packed_desc_event *driver, *device; +size_t ring_size_in_bytes, event_size_in_bytes; +struct vring_packed_desc *ring; +struct vring_virtqueue *vq; + +if (vring_alloc_queue_packed (vdev, num, &ring, &driver, &device, + &ring_dma_addr, &driver_event_dma_addr, + &device_event_dma_addr, + &ring_size_in_bytes, + &event_size_in_bytes)) + goto err_ring; + vq =kmalloc (sizeof (*vq),GFP_KERNEL );if (!vq) goto err_vq;
@@ -1939,9 +1983,7 @@ static struct virtqueue *vring_create_virtqueue_packed(kfree (vq); err_vq:vring_free_queue (vdev, event_size_in_bytes, device, device_event_dma_addr); -err_device:vring_free_queue (vdev, event_size_in_bytes, driver, driver_event_dma_addr); -err_driver:vring_free_queue (vdev, ring_size_in_bytes, ring, ring_dma_addr); err_ring:return NULL ;
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 12/32] virtio_ring: packed: extract the logic of alloc queue
Quoted 48 lines · Xuan Zhuo
Separate the logic of packed to create vring queue.
For the convenience of passing parameters, add a structure
vring_packed.This feature is required for subsequent virtuqueue reset vring.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 70 ++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 14 deletions(-)drivers/virtio/virtio_ring.c +10
-12@@ -1817,19 +1817,17 @@ static struct vring_desc_extra *vring_alloc_desc_extra(unsigned int num)return desc_extra; } -static struct virtqueue *vring_create_virtqueue_packed ( -unsigned int index, -unsigned int num, -unsigned int vring_align, -struct virtio_device *vdev, -bool weak_barriers, -bool may_reduce_num, -bool context, -bool (*notify)(struct virtqueue *), -void (*callback)(struct virtqueue *), -const char *name) +static int vring_alloc_queue_packed (struct virtio_device *vdev, +u32 num, +struct vring_packed_desc **_ring, +struct vring_packed_desc_event **_driver, +struct vring_packed_desc_event **_device, +dma_addr_t *_ring_dma_addr, +dma_addr_t *_driver_event_dma_addr, +dma_addr_t *_device_event_dma_addr, +size_t *_ring_size_in_bytes, +size_t *_event_size_in_bytes) { -struct vring_virtqueue *vq;struct vring_packed_desc *ring;struct vring_packed_desc_event *driver, *device;dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr;@@ -1857,6 +1855,52 @@ static struct virtqueue *vring_create_virtqueue_packed(if (!device)
drivers/virtio/virtio_ring.c static struct virtqueue *vring_create_virtqueue_packed( · line 1865
Quoted 10 lines
drivers/virtio/virtio_ring.c +8
-0goto err_device; + *_ring = ring; + *_driver = driver; + *_device = device; + *_ring_dma_addr = ring_dma_addr; + *_driver_event_dma_addr = driver_event_dma_addr; + *_device_event_dma_addr = device_event_dma_addr; + *_ring_size_in_bytes = ring_size_in_bytes; + *_event_size_in_bytes = event_size_in_bytes;
I wonder if we can simply factor out split and packed from struct vring_virtqueue:
struct vring_virtqueue {
union {
struct {} split;
struct {} packed;
};
};
to
struct vring_virtqueue_split {};
struct vring_virtqueue_packed {};
Then we can do things like:
vring_create_virtqueue_packed(struct virtio_device *vdev, u32 num, struct vring_virtqueue_packed *packed);
and
vring_vritqueue_attach_packed(struct vring_virtqueue *vq, struct vring_virtqueue_packed packed);
Thanks
Quoted 51 lines
drivers/virtio/virtio_ring.c +38
-2+ +return 0 ; + +err_device: +vring_free_queue (vdev, event_size_in_bytes, driver, driver_event_dma_addr); + +err_driver: +vring_free_queue (vdev, ring_size_in_bytes, ring, ring_dma_addr); + +err_ring: +return -ENOMEM ; +} + +static struct virtqueue *vring_create_virtqueue_packed ( +unsigned int index, +unsigned int num, +unsigned int vring_align, +struct virtio_device *vdev, +bool weak_barriers, +bool may_reduce_num, +bool context, +bool (*notify)(struct virtqueue *), +void (*callback)(struct virtqueue *), +const char *name) +{ +dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr; +struct vring_packed_desc_event *driver, *device; +size_t ring_size_in_bytes, event_size_in_bytes; +struct vring_packed_desc *ring; +struct vring_virtqueue *vq; + +if (vring_alloc_queue_packed (vdev, num, &ring, &driver, &device, + &ring_dma_addr, &driver_event_dma_addr, + &device_event_dma_addr, + &ring_size_in_bytes, + &event_size_in_bytes)) + goto err_ring; + vq =kmalloc (sizeof (*vq),GFP_KERNEL );if (!vq) goto err_vq;@@ -1939,9 +1983,7 @@ static struct virtqueue *vring_create_virtqueue_packed(kfree (vq); err_vq:vring_free_queue (vdev, event_size_in_bytes, device, device_event_dma_addr); -err_device:vring_free_queue (vdev, event_size_in_bytes, driver, driver_event_dma_addr); -err_driver:vring_free_queue (vdev, ring_size_in_bytes, ring, ring_dma_addr); err_ring:return NULL ;
Xuan Zhuo
reviewerRe: [PATCH v9 12/32] virtio_ring: packed: extract the logic of alloc queue
Quoted 79 lines · Jason Wang
Quoted 48 lines · Xuan Zhuo
Separate the logic of packed to create vring queue.
For the convenience of passing parameters, add a structure
vring_packed.This feature is required for subsequent virtuqueue reset vring.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 70 ++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 14 deletions(-)drivers/virtio/virtio_ring.c +10
-12@@ -1817,19 +1817,17 @@ static struct vring_desc_extra *vring_alloc_desc_extra(unsigned int num)return desc_extra; } -static struct virtqueue *vring_create_virtqueue_packed ( -unsigned int index, -unsigned int num, -unsigned int vring_align, -struct virtio_device *vdev, -bool weak_barriers, -bool may_reduce_num, -bool context, -bool (*notify)(struct virtqueue *), -void (*callback)(struct virtqueue *), -const char *name) +static int vring_alloc_queue_packed (struct virtio_device *vdev, +u32 num, +struct vring_packed_desc **_ring, +struct vring_packed_desc_event **_driver, +struct vring_packed_desc_event **_device, +dma_addr_t *_ring_dma_addr, +dma_addr_t *_driver_event_dma_addr, +dma_addr_t *_device_event_dma_addr, +size_t *_ring_size_in_bytes, +size_t *_event_size_in_bytes) { -struct vring_virtqueue *vq;struct vring_packed_desc *ring;struct vring_packed_desc_event *driver, *device;dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr;@@ -1857,6 +1855,52 @@ static struct virtqueue *vring_create_virtqueue_packed(if (!device)drivers/virtio/virtio_ring.c static struct virtqueue *vring_create_virtqueue_packed( · line 1865
Quoted 10 lines
drivers/virtio/virtio_ring.c +8
-0goto err_device; + *_ring = ring; + *_driver = driver; + *_device = device; + *_ring_dma_addr = ring_dma_addr; + *_driver_event_dma_addr = driver_event_dma_addr; + *_device_event_dma_addr = device_event_dma_addr; + *_ring_size_in_bytes = ring_size_in_bytes; + *_event_size_in_bytes = event_size_in_bytes;I wonder if we can simply factor out split and packed from struct
vring_virtqueue:struct
vring_virtqueue{
union {
struct {} split;
struct {} packed;
};
};to
struct
vring_virtqueue_split{};
structvring_virtqueue_packed{};Then we can do things like:
Quoted 7 lines
vring_create_virtqueue_packed(struct virtio_device *vdev, u32 num, struct vring_virtqueue_packed *packed);and
vring_vritqueue_attach_packed(struct vring_virtqueue *vq, struct vring_virtqueue_packed packed);
This idea is very similar to my previous idea, just without introducing a new structure.
I'd be more than happy to revise this.
Thanks.
Quoted 56 lines
Thanks
Quoted 51 lines
drivers/virtio/virtio_ring.c +38
-2+ +return 0 ; + +err_device: +vring_free_queue (vdev, event_size_in_bytes, driver, driver_event_dma_addr); + +err_driver: +vring_free_queue (vdev, ring_size_in_bytes, ring, ring_dma_addr); + +err_ring: +return -ENOMEM ; +} + +static struct virtqueue *vring_create_virtqueue_packed ( +unsigned int index, +unsigned int num, +unsigned int vring_align, +struct virtio_device *vdev, +bool weak_barriers, +bool may_reduce_num, +bool context, +bool (*notify)(struct virtqueue *), +void (*callback)(struct virtqueue *), +const char *name) +{ +dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr; +struct vring_packed_desc_event *driver, *device; +size_t ring_size_in_bytes, event_size_in_bytes; +struct vring_packed_desc *ring; +struct vring_virtqueue *vq; + +if (vring_alloc_queue_packed (vdev, num, &ring, &driver, &device, + &ring_dma_addr, &driver_event_dma_addr, + &device_event_dma_addr, + &ring_size_in_bytes, + &event_size_in_bytes)) + goto err_ring; + vq =kmalloc (sizeof (*vq),GFP_KERNEL );if (!vq) goto err_vq;@@ -1939,9 +1983,7 @@ static struct virtqueue *vring_create_virtqueue_packed(kfree (vq); err_vq:vring_free_queue (vdev, event_size_in_bytes, device, device_event_dma_addr); -err_device:vring_free_queue (vdev, event_size_in_bytes, driver, driver_event_dma_addr); -err_driver:vring_free_queue (vdev, ring_size_in_bytes, ring, ring_dma_addr); err_ring:return NULL ;
Re: [PATCH v9 12/32] virtio_ring: packed: extract the logic of alloc queue
Quoted 84 lines · Xuan Zhuo
Quoted 82 lines · Jason Wang
Quoted 48 lines · Xuan Zhuo
Separate the logic of packed to create vring queue.
For the convenience of passing parameters, add a structure
vring_packed.This feature is required for subsequent virtuqueue reset vring.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 70 ++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 14 deletions(-)drivers/virtio/virtio_ring.c +10
-12@@ -1817,19 +1817,17 @@ static struct vring_desc_extra *vring_alloc_desc_extra(unsigned int num)return desc_extra; } -static struct virtqueue *vring_create_virtqueue_packed ( -unsigned int index, -unsigned int num, -unsigned int vring_align, -struct virtio_device *vdev, -bool weak_barriers, -bool may_reduce_num, -bool context, -bool (*notify)(struct virtqueue *), -void (*callback)(struct virtqueue *), -const char *name) +static int vring_alloc_queue_packed (struct virtio_device *vdev, +u32 num, +struct vring_packed_desc **_ring, +struct vring_packed_desc_event **_driver, +struct vring_packed_desc_event **_device, +dma_addr_t *_ring_dma_addr, +dma_addr_t *_driver_event_dma_addr, +dma_addr_t *_device_event_dma_addr, +size_t *_ring_size_in_bytes, +size_t *_event_size_in_bytes) { -struct vring_virtqueue *vq;struct vring_packed_desc *ring;struct vring_packed_desc_event *driver, *device;dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr;@@ -1857,6 +1855,52 @@ static struct virtqueue *vring_create_virtqueue_packed(if (!device)drivers/virtio/virtio_ring.c static struct virtqueue *vring_create_virtqueue_packed( · line 1865
Quoted 10 lines
drivers/virtio/virtio_ring.c +8
-0goto err_device; + *_ring = ring; + *_driver = driver; + *_device = device; + *_ring_dma_addr = ring_dma_addr; + *_driver_event_dma_addr = driver_event_dma_addr; + *_device_event_dma_addr = device_event_dma_addr; + *_ring_size_in_bytes = ring_size_in_bytes; + *_event_size_in_bytes = event_size_in_bytes;I wonder if we can simply factor out split and packed from struct
vring_virtqueue:struct vring_virtqueue { union { struct {} split; struct {} packed; }; };to
struct
vring_virtqueue_split{};
structvring_virtqueue_packed{};Then we can do things like:
vring_create_virtqueue_packed(struct virtio_device *vdev, u32 num, struct vring_virtqueue_packed *packed);
Quoted 7 lines
Quoted 4 lines
and
vring_vritqueue_attach_packed(struct vring_virtqueue *vq, struct vring_virtqueue_packed packed);This idea is very similar to my previous idea, just without introducing a new structure.
Yes, it's better to not introduce new structures if it's possible.
Quoted 2 lines
I'd be more than happy to revise this.
Good to know this.
Thanks
Quoted 61 lines
Thanks.
Quoted 56 lines
Thanks
Quoted 51 lines
drivers/virtio/virtio_ring.c +38
-2+ +return 0 ; + +err_device: +vring_free_queue (vdev, event_size_in_bytes, driver, driver_event_dma_addr); + +err_driver: +vring_free_queue (vdev, ring_size_in_bytes, ring, ring_dma_addr); + +err_ring: +return -ENOMEM ; +} + +static struct virtqueue *vring_create_virtqueue_packed ( +unsigned int index, +unsigned int num, +unsigned int vring_align, +struct virtio_device *vdev, +bool weak_barriers, +bool may_reduce_num, +bool context, +bool (*notify)(struct virtqueue *), +void (*callback)(struct virtqueue *), +const char *name) +{ +dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr; +struct vring_packed_desc_event *driver, *device; +size_t ring_size_in_bytes, event_size_in_bytes; +struct vring_packed_desc *ring; +struct vring_virtqueue *vq; + +if (vring_alloc_queue_packed (vdev, num, &ring, &driver, &device, + &ring_dma_addr, &driver_event_dma_addr, + &device_event_dma_addr, + &ring_size_in_bytes, + &event_size_in_bytes)) + goto err_ring; + vq =kmalloc (sizeof (*vq),GFP_KERNEL );if (!vq) goto err_vq;@@ -1939,9 +1983,7 @@ static struct virtqueue *vring_create_virtqueue_packed(kfree (vq); err_vq:vring_free_queue (vdev, event_size_in_bytes, device, device_event_dma_addr); -err_device:vring_free_queue (vdev, event_size_in_bytes, driver, driver_event_dma_addr); -err_driver:vring_free_queue (vdev, ring_size_in_bytes, ring, ring_dma_addr); err_ring:return NULL ;
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 13/32 virtio_ring: packed: extract the logic of alloc state and extra
In reply to Xuan ZhuoSeparate the logic for alloc desc_state and desc_extra, which will be called separately by subsequent patches.
Use struct vring_packed to pass desc_state, desc_extra.
--- drivers/virtio/virtio_ring.c | 51 ++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 14 deletions(-)
drivers/virtio/virtio_ring.c +37 -14
@@ -1876,6 +1876,34 @@ static int vring_alloc_queue_packed(struct virtio_device *vdev,return -ENOMEM ; } +static int vring_alloc_state_extra_packed (u32 num, +struct vring_desc_state_packed **desc_state, +struct vring_desc_extra **desc_extra) +{ +struct vring_desc_state_packed *state; +struct vring_desc_extra *extra; + + state =kmalloc_array (num,sizeof (struct vring_desc_state_packed ),GFP_KERNEL ); +if (!state) + goto err_desc_state; + +memset (state,0 , num *sizeof (struct vring_desc_state_packed )); + + extra =vring_alloc_desc_extra (num); +if (!extra) + goto err_desc_extra; + + *desc_state = state; + *desc_extra = extra; + +return 0 ; + +err_desc_extra: +kfree (state); +err_desc_state: +return -ENOMEM ; +} + static struct virtqueue *vring_create_virtqueue_packed( unsigned int index, unsigned int num,
@@ -1891,8 +1919,11 @@ static struct virtqueue *vring_create_virtqueue_packed(dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr;struct vring_packed_desc_event *driver, *device;size_t ring_size_in_bytes, event_size_in_bytes; +struct vring_desc_state_packed *state; +struct vring_desc_extra *extra;struct vring_packed_desc *ring;struct vring_virtqueue *vq; +int err; if (vring_alloc_queue_packed(vdev, num, &ring, &driver, &device, &ring_dma_addr, &driver_event_dma_addr,
@@ -1949,22 +1980,16 @@ static struct virtqueue *vring_create_virtqueue_packed( vq->packed.event_flags_shadow =0 ; vq->packed.avail_used_flags =1 <<VRING_PACKED_DESC_F_AVAIL ; - vq->packed.desc_state =kmalloc_array (num, -sizeof (struct vring_desc_state_packed ), -GFP_KERNEL ); -if (!vq->packed.desc_state) - goto err_desc_state; + err =vring_alloc_state_extra_packed (num, &state, &extra); +if (err) + goto err_state_extra; -memset (vq->packed.desc_state,0 , - num *sizeof (struct vring_desc_state_packed )); + vq->packed.desc_state = state; + vq->packed.desc_extra = extra;/* Put everything in free lists. */ vq->free_head =0 ; - vq->packed.desc_extra =vring_alloc_desc_extra (num); -if (!vq->packed.desc_extra) - goto err_desc_extra; -/* No callback? Tell other side not to bother us. */ if (!callback) { vq->packed.event_flags_shadow =VRING_PACKED_EVENT_FLAG_DISABLE ;
@@ -1977,9 +2002,7 @@ static struct virtqueue *vring_create_virtqueue_packed(spin_unlock (&vdev->vqs_list_lock);return &vq->vq; -err_desc_extra: -kfree (vq->packed.desc_state); -err_desc_state: +err_state_extra:kfree (vq); err_vq:vring_free_queue (vdev, event_size_in_bytes, device, device_event_dma_addr);
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 14/32 virtio_ring: packed: extract the logic of attach vring
In reply to Xuan ZhuoSeparate the logic of attach vring, the subsequent patch will call it separately.
--- drivers/virtio/virtio_ring.c | 47 +++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 14 deletions(-)
drivers/virtio/virtio_ring.c +33 -14
@@ -1904,6 +1904,35 @@ static int vring_alloc_state_extra_packed(u32 num,return -ENOMEM ; } +static void vring_virtqueue_attach_packed (struct vring_virtqueue *vq, +u32 num, +struct vring_packed_desc *ring, +struct vring_packed_desc_event *driver, +struct vring_packed_desc_event *device, +dma_addr_t ring_dma_addr, +dma_addr_t driver_event_dma_addr, +dma_addr_t device_event_dma_addr, +size_t ring_size_in_bytes, +size_t event_size_in_bytes, +struct vring_desc_state_packed *state, +struct vring_desc_extra *extra) +{ + vq->packed.ring_dma_addr = ring_dma_addr; + vq->packed.driver_event_dma_addr = driver_event_dma_addr; + vq->packed.device_event_dma_addr = device_event_dma_addr; + + vq->packed.ring_size_in_bytes = ring_size_in_bytes; + vq->packed.event_size_in_bytes = event_size_in_bytes; + + vq->packed.vring.num = num; + vq->packed.vring.desc = ring; + vq->packed.vring.driver = driver; + vq->packed.vring.device = device; + + vq->packed.desc_state = state; + vq->packed.desc_extra = extra; +} + static struct virtqueue *vring_create_virtqueue_packed( unsigned int index, unsigned int num,
@@ -1962,18 +1991,6 @@ static struct virtqueue *vring_create_virtqueue_packed(if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) vq->weak_barriers = false; - vq->packed.ring_dma_addr = ring_dma_addr; - vq->packed.driver_event_dma_addr = driver_event_dma_addr; - vq->packed.device_event_dma_addr = device_event_dma_addr; - - vq->packed.ring_size_in_bytes = ring_size_in_bytes; - vq->packed.event_size_in_bytes = event_size_in_bytes; - - vq->packed.vring.num = num; - vq->packed.vring.desc = ring; - vq->packed.vring.driver = driver; - vq->packed.vring.device = device; - vq->packed.next_avail_idx =0 ; vq->packed.avail_wrap_counter =1 ; vq->packed.used_wrap_counter =1 ;
@@ -1984,8 +2001,10 @@ static struct virtqueue *vring_create_virtqueue_packed(if (err) goto err_state_extra; - vq->packed.desc_state = state; - vq->packed.desc_extra = extra; +vring_virtqueue_attach_packed (vq, num, ring, driver, device, + ring_dma_addr, driver_event_dma_addr, + device_event_dma_addr, ring_size_in_bytes, + event_size_in_bytes, state, extra);/* Put everything in free lists. */ vq->free_head =0 ;
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 15/32 virtio_ring: packed: extract the logic of vq init
In reply to Xuan ZhuoSeparate the logic of initializing vq, and subsequent patches will call it separately.
The characteristic of this part of the logic is that it does not depend on the information passed by the upper layer, and can be called repeatedly.
--- drivers/virtio/virtio_ring.c | 71 ++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 32 deletions(-)
drivers/virtio/virtio_ring.c +39 -32
@@ -1933,6 +1933,44 @@ static void vring_virtqueue_attach_packed(struct vring_virtqueue *vq, vq->packed.desc_extra = extra; } +static void vring_virtqueue_init_packed (struct vring_virtqueue *vq, +struct virtio_device *vdev) +{ + vq->vq.num_free = vq->packed.vring.num; + vq->we_own_ring = true; + vq->broken = false; + vq->last_used_idx =0 ; + vq->event_triggered = false; + vq->num_added =0 ; + vq->packed_ring = true; + vq->use_dma_api =vring_use_dma_api (vdev); +#ifdef DEBUG + vq->in_use = false; + vq->last_add_time_valid = false; +#endif + + vq->event =virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX ); + +if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) + vq->weak_barriers = false; + + vq->packed.next_avail_idx =0 ; + vq->packed.avail_wrap_counter =1 ; + vq->packed.used_wrap_counter =1 ; + vq->packed.event_flags_shadow =0 ; + vq->packed.avail_used_flags =1 <<VRING_PACKED_DESC_F_AVAIL ; + +/* Put everything in free lists. */ + vq->free_head =0 ; + +/* No callback? Tell other side not to bother us. */ +if (!vq->vq.callback) { + vq->packed.event_flags_shadow =VRING_PACKED_EVENT_FLAG_DISABLE ; + vq->packed.vring.driver->flags = +cpu_to_le16 (vq->packed.event_flags_shadow); + } +} + static struct virtqueue *vring_create_virtqueue_packed( unsigned int index, unsigned int num,
@@ -1968,34 +2006,12 @@ static struct virtqueue *vring_create_virtqueue_packed( vq->vq.callback = callback; vq->vq.vdev = vdev; vq->vq.name = name; - vq->vq.num_free = num; vq->vq.index = index; - vq->we_own_ring = true; vq->notify = notify; vq->weak_barriers = weak_barriers; - vq->broken = false; - vq->last_used_idx =0 ; - vq->event_triggered = false; - vq->num_added =0 ; - vq->packed_ring = true; - vq->use_dma_api =vring_use_dma_api (vdev); -#ifdef DEBUG - vq->in_use = false; - vq->last_add_time_valid = false; -#endif vq->indirect =virtio_has_feature (vdev,VIRTIO_RING_F_INDIRECT_DESC ) && !context; - vq->event =virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX ); - -if (virtio_has_feature (vdev,VIRTIO_F_ORDER_PLATFORM )) - vq->weak_barriers = false; - - vq->packed.next_avail_idx =0 ; - vq->packed.avail_wrap_counter =1 ; - vq->packed.used_wrap_counter =1 ; - vq->packed.event_flags_shadow =0 ; - vq->packed.avail_used_flags =1 <<VRING_PACKED_DESC_F_AVAIL ; err =vring_alloc_state_extra_packed (num, &state, &extra);if (err)
@@ -2005,16 +2021,7 @@ static struct virtqueue *vring_create_virtqueue_packed( ring_dma_addr, driver_event_dma_addr, device_event_dma_addr, ring_size_in_bytes, event_size_in_bytes, state, extra); - -/* Put everything in free lists. */ - vq->free_head =0 ; - -/* No callback? Tell other side not to bother us. */ -if (!callback) { - vq->packed.event_flags_shadow =VRING_PACKED_EVENT_FLAG_DISABLE ; - vq->packed.vring.driver->flags = -cpu_to_le16 (vq->packed.event_flags_shadow); - } +vring_virtqueue_init_packed (vq, vdev);spin_lock (&vdev->vqs_list_lock);list_add_tail (&vq->vq.list, &vdev->vqs);
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 16/32 virtio_ring: packed: introduce virtqueue_reinit_packed()
In reply to Xuan ZhuoIntroduce a function to initialize vq without allocating new ring, desc_state, desc_extra.
Subsequent patches will call this function after reset vq to reinitialize vq.
--- drivers/virtio/virtio_ring.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/virtio/virtio_ring.c +21 -0
@@ -1971,6 +1971,27 @@ static void vring_virtqueue_init_packed(struct vring_virtqueue *vq, } } +static void virtqueue_reinit_packed (struct vring_virtqueue *vq) +{ +struct virtio_device *vdev = vq->vq.vdev; +int size, i; + +memset (vq->packed.vring.device,0 , vq->packed.event_size_in_bytes); +memset (vq->packed.vring.driver,0 , vq->packed.event_size_in_bytes); +memset (vq->packed.vring.desc,0 , vq->packed.ring_size_in_bytes); + + size =sizeof (struct vring_desc_state_packed ) * vq->packed.vring.num; +memset (vq->packed.desc_state,0 , size); + + size =sizeof (struct vring_desc_extra ) * vq->packed.vring.num; +memset (vq->packed.desc_extra,0 , size); + +for (i =0 ; i < vq->packed.vring.num -1 ; i++) + vq->packed.desc_extra[i].next = i +1 ; + +vring_virtqueue_init_packed (vq, vdev); +} + static struct virtqueue *vring_create_virtqueue_packed( unsigned int index, unsigned int num,
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 17/32 virtio_ring: packed: introduce virtqueue_resize_packed()
In reply to Xuan Zhuovirtio ring packed supports resize.
Only after the new vring is successfully allocated based on the new num, we will release the old vring. In any case, an error is returned, indicating that the vring still points to the old vring.
In the case of an error, the caller must re-initialize(by virtqueue_reinit_packed()) the virtqueue to ensure that the vring can be used.
--- drivers/virtio/virtio_ring.c | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
drivers/virtio/virtio_ring.c +40 -0
@@ -2059,6 +2059,46 @@ static struct virtqueue *vring_create_virtqueue_packed(return NULL ; } +static int virtqueue_resize_packed (struct virtqueue *_vq,u32 num) +{ +dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr; +struct vring_packed_desc_event *driver, *device; +size_t ring_size_in_bytes, event_size_in_bytes; +struct vring_virtqueue *vq =to_vvq (_vq); +struct virtio_device *vdev = _vq->vdev; +struct vring_desc_state_packed *state; +struct vring_desc_extra *extra; +struct vring_packed_desc *ring; +int err; + +if (vring_alloc_queue_packed (vdev, num, &ring, &driver, &device, + &ring_dma_addr, &driver_event_dma_addr, + &device_event_dma_addr, + &ring_size_in_bytes, &event_size_in_bytes)) + goto err_ring; + + + err =vring_alloc_state_extra_packed (num, &state, &extra); +if (err) + goto err_state_extra; + +vring_free (&vq->vq); + +vring_virtqueue_attach_packed (vq, num, ring, driver, device, + ring_dma_addr, driver_event_dma_addr, + device_event_dma_addr, ring_size_in_bytes, + event_size_in_bytes, state, extra); +vring_virtqueue_init_packed (vq, vdev); +return 0 ; + +err_state_extra: +vring_free_queue (vdev, event_size_in_bytes, device, device_event_dma_addr); +vring_free_queue (vdev, event_size_in_bytes, driver, driver_event_dma_addr); +vring_free_queue (vdev, ring_size_in_bytes, ring, ring_dma_addr); +err_ring: +return -ENOMEM ; +} +/* * Generic functions and exported symbols.
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 18/32 virtio_ring: introduce virtqueue_resize()
In reply to Xuan ZhuoIntroduce virtqueue_resize() to implement the resize of vring. Based on these, the driver can dynamically adjust the size of the vring. For example: ethtool -G.
virtqueue_resize() implements resize based on the vq reset function. In case of failure to allocate a new vring, it will give up resize and use the original vring.
During this process, if the re-enable reset vq fails, the vq can no longer be used. Although the probability of this situation is not high.
The parameter recycle is used to recycle the buffer that is no longer used.
--- drivers/virtio/virtio_ring.c | 69 ++++++++++++++++++++++++++++++++++++ include/linux/virtio.h | 3 ++ 2 files changed, 72 insertions(+)
drivers/virtio/virtio_ring.c +69 -0
@@ -2554,6 +2554,75 @@ struct virtqueue *vring_create_virtqueue( }EXPORT_SYMBOL_GPL (vring_create_virtqueue); +/** +* virtqueue_resize - resize the vring of vq +* @_vq: the struct virtqueue we're talking about. +* @num: new ring num +* @recycle: callback for recycle the useless buffer +* +* When it is really necessary to create a new vring, it will set the current vq +* into the reset state. Then call the passed callback to recycle the buffer +* that is no longer used. Only after the new vring is successfully created, the +* old vring will be released. +* +* Caller must ensure we don't call this with other virtqueue operations +* at the same time (except where noted). +* +* Returns zero or a negative error. +*/ +int virtqueue_resize (struct virtqueue *_vq,u32 num, +void (*recycle)(struct virtqueue *vq,void *buf)) +{ +struct vring_virtqueue *vq =to_vvq (_vq); +struct virtio_device *vdev = vq->vq.vdev; +bool packed; +void *buf; +int err; + +if (!vq->we_own_ring) +return -EINVAL ; + +if (num > vq->vq.num_max) +return -E2BIG ; + +if (!num) +return -EINVAL ; + + packed =virtio_has_feature (vdev,VIRTIO_F_RING_PACKED ) ? true : false; + +if ((packed ? vq->packed.vring.num : vq->split.vring.num) == num) +return 0 ; + +if (!vdev->config->reset_vq) +return -ENOENT ; + +if (!vdev->config->enable_reset_vq) +return -ENOENT ; + + err = vdev->config->reset_vq (_vq); +if (err) +return err; + +while ((buf =virtqueue_detach_unused_buf (_vq)) !=NULL ) +recycle (_vq, buf); + +if (packed) { + err =virtqueue_resize_packed (_vq, num); +if (err) +virtqueue_reinit_packed (vq); + }else { + err =virtqueue_resize_split (_vq, num); +if (err) +virtqueue_reinit_split (vq); + } + +if (vdev->config->enable_reset_vq (_vq)) +return -EBUSY ; + +return err; +} +EXPORT_SYMBOL_GPL (virtqueue_resize); +/* Only available for split ring */ struct virtqueue *vring_new_virtqueue(unsigned int index, unsigned int num,
include/linux/virtio.h +3 -0
@@ -91,6 +91,9 @@ dma_addr_t virtqueue_get_desc_addr(struct virtqueue *vq);dma_addr_t virtqueue_get_avail_addr (struct virtqueue *vq);dma_addr_t virtqueue_get_used_addr (struct virtqueue *vq); +int virtqueue_resize (struct virtqueue *vq,u32 num, +void (*recycle)(struct virtqueue *vq,void *buf)); +/** * virtio_device - representation of a device using virtio * @index: unique position on the virtio bus
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 18/32] virtio_ring: introduce virtqueue_resize()
Quoted 33 lines · Xuan Zhuo
Introduce
virtqueue_resize()to implement the resize of vring. Based on these, the driver can dynamically adjust the size of the vring. For example: ethtool -G.
virtqueue_resize()implements resize based on the vq reset function. In case of failure to allocate a new vring, it will give up resize and use the original vring.During this process, if the re-enable reset vq fails, the vq can no longer be used. Although the probability of this situation is not high.
The parameter recycle is used to recycle the buffer that is no longer used.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 69 ++++++++++++++++++++++++++++++++++++ include/linux/virtio.h | 3 ++ 2 files changed, 72 insertions(+)drivers/virtio/virtio_ring.c +5
-0@@ -2554,6 +2554,75 @@ struct virtqueue *vring_create_virtqueue( }EXPORT_SYMBOL_GPL (vring_create_virtqueue); +/** +* virtqueue_resize - resize the vring of vq +* @_vq: the struct virtqueue we're talking about. +* @num: new ring num +* @recycle: callback for recycle the useless buffer
drivers/virtio/virtio_ring.c struct virtqueue *vring_create_virtqueue( · line 2571
Quoted 10 lines
drivers/virtio/virtio_ring.c +10
-0+* +* When it is really necessary to create a new vring, it will set the current vq +* into the reset state. Then call the passed callback to recycle the buffer +* that is no longer used. Only after the new vring is successfully created, the +* old vring will be released. +* +* Caller must ensure we don't call this with other virtqueue operations +* at the same time (except where noted). +* +* Returns zero or a negative error.
Should we document that the virtqueue is kept unchanged (still available) on (specific) failure?
Quoted 31 lines
drivers/virtio/virtio_ring.c +31
-0+*/ +int virtqueue_resize (struct virtqueue *_vq,u32 num, +void (*recycle)(struct virtqueue *vq,void *buf)) +{ +struct vring_virtqueue *vq =to_vvq (_vq); +struct virtio_device *vdev = vq->vq.vdev; +bool packed; +void *buf; +int err; + +if (!vq->we_own_ring) +return -EINVAL ; + +if (num > vq->vq.num_max) +return -E2BIG ; + +if (!num) +return -EINVAL ; + + packed =virtio_has_feature (vdev,VIRTIO_F_RING_PACKED ) ? true : false; + +if ((packed ? vq->packed.vring.num : vq->split.vring.num) == num) +return 0 ; + +if (!vdev->config->reset_vq) +return -ENOENT ; + +if (!vdev->config->enable_reset_vq) +return -ENOENT ; + + err = vdev->config->reset_vq (_vq);
drivers/virtio/virtio_ring.c struct virtqueue *vring_create_virtqueue( · line 2612
Quoted 10 lines
drivers/virtio/virtio_ring.c +10
-0+if (err) +return err; + +while ((buf =virtqueue_detach_unused_buf (_vq)) !=NULL ) +recycle (_vq, buf); + +if (packed) { + err =virtqueue_resize_packed (_vq, num); +if (err) +virtqueue_reinit_packed (vq);
Calling reinit here seems a little bit odd, it looks more like a reset of the virtqueue. Consider we may re-use virtqueue reset for more purpose, I wonder if we need a helper like:
virtqueue_resize() {
vdev->config->reset_vq(_vq);
if (packed)
virtqueue_reinit_packed(_vq)
else
virtqueue_reinit_split(_vq)
}
Thanks
Quoted 21 lines
drivers/virtio/virtio_ring.c +13
-0+ }else { + err =virtqueue_resize_split (_vq, num); +if (err) +virtqueue_reinit_split (vq); + } + +if (vdev->config->enable_reset_vq (_vq)) +return -EBUSY ; + +return err; +} +EXPORT_SYMBOL_GPL (virtqueue_resize); +/* Only available for split ring */ struct virtqueue *vring_new_virtqueue(unsigned int index, unsigned int num,include/linux/virtio.h +0
-0
include/linux/virtio.h dma_addr_t virtqueue_get_desc_addr(struct virtqueue *vq); · line 99
Quoted 9 lines
include/linux/virtio.h +3
-0@@ -91,6 +91,9 @@ dma_addr_t virtqueue_get_desc_addr(struct virtqueue *vq);dma_addr_t virtqueue_get_avail_addr (struct virtqueue *vq);dma_addr_t virtqueue_get_used_addr (struct virtqueue *vq); +int virtqueue_resize (struct virtqueue *vq,u32 num, +void (*recycle)(struct virtqueue *vq,void *buf)); +/** * virtio_device - representation of a device using virtio * @index: unique position on the virtio bus
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 18/32] virtio_ring: introduce virtqueue_resize()
Quoted 41 lines · Jason Wang
Quoted 39 lines · Xuan Zhuo
Introduce
virtqueue_resize()to implement the resize of vring. Based on these, the driver can dynamically adjust the size of the vring. For example: ethtool -G.
virtqueue_resize()implements resize based on the vq reset function. In case of failure to allocate a new vring, it will give up resize and use the original vring.During this process, if the re-enable reset vq fails, the vq can no longer be used. Although the probability of this situation is not high.
The parameter recycle is used to recycle the buffer that is no longer used.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 69 ++++++++++++++++++++++++++++++++++++ include/linux/virtio.h | 3 ++ 2 files changed, 72 insertions(+)drivers/virtio/virtio_ring.c +11
-0@@ -2554,6 +2554,75 @@ struct virtqueue *vring_create_virtqueue( }EXPORT_SYMBOL_GPL (vring_create_virtqueue); +/** +* virtqueue_resize - resize the vring of vq +* @_vq: the struct virtqueue we're talking about. +* @num: new ring num +* @recycle: callback for recycle the useless buffer +* +* When it is really necessary to create a new vring, it will set the current vq +* into the reset state. Then call the passed callback to recycle the buffer +* that is no longer used. Only after the new vring is successfully created, the +* old vring will be released. +*
Quoted 9 lines
drivers/virtio/virtio_ring.c struct virtqueue *vring_create_virtqueue( · line 2571
Quoted 4 lines
drivers/virtio/virtio_ring.c +4
-0+* Caller must ensure we don't call this with other virtqueue operations +* at the same time (except where noted). +* +* Returns zero or a negative error. Should we document that the virtqueue is kept unchanged (still available) on (specific) failure?
OK.
Quoted 48 lines
Quoted 32 lines
drivers/virtio/virtio_ring.c +31
-0+*/ +int virtqueue_resize (struct virtqueue *_vq,u32 num, +void (*recycle)(struct virtqueue *vq,void *buf)) +{ +struct vring_virtqueue *vq =to_vvq (_vq); +struct virtio_device *vdev = vq->vq.vdev; +bool packed; +void *buf; +int err; + +if (!vq->we_own_ring) +return -EINVAL ; + +if (num > vq->vq.num_max) +return -E2BIG ; + +if (!num) +return -EINVAL ; + + packed =virtio_has_feature (vdev,VIRTIO_F_RING_PACKED ) ? true : false; + +if ((packed ? vq->packed.vring.num : vq->split.vring.num) == num) +return 0 ; + +if (!vdev->config->reset_vq) +return -ENOENT ; + +if (!vdev->config->enable_reset_vq) +return -ENOENT ; + + err = vdev->config->reset_vq (_vq);drivers/virtio/virtio_ring.c struct virtqueue *vring_create_virtqueue( · line 2612
Quoted 10 lines
drivers/virtio/virtio_ring.c +10
-0+if (err) +return err; + +while ((buf =virtqueue_detach_unused_buf (_vq)) !=NULL ) +recycle (_vq, buf); + +if (packed) { + err =virtqueue_resize_packed (_vq, num); +if (err) +virtqueue_reinit_packed (vq);Calling reinit here seems a little bit odd, it looks more like a reset of the virtqueue. Consider we may re-use virtqueue reset for more purpose, I wonder if we need a helper like:
Quoted 7 lines
virtqueue_resize(){
vdev->config->reset_vq(_vq);
if (packed)
virtqueue_reinit_packed(_vq)
else
virtqueue_reinit_split(_vq)
}
Yes, currently we are implementing resize. This is used to implement set_ringparam()
Later, when we implement virtio_net + AF_XDP, what we want is reset not resize, so we need to implement a helper:
virtqueue_reset() {
vdev->config->reset_vq(_vq);
if (packed)
virtqueue_reinit_packed(_vq)
else
virtqueue_reinit_split(_vq)
}
So I use virtqueue_reinit_* as a separate function not only to deal with the case of resize failure, but also to consider the subsequent implementation of virtqueue_reset()
Thanks.
Quoted 35 lines
Thanks
Quoted 30 lines
drivers/virtio/virtio_ring.c +13
-0+ }else { + err =virtqueue_resize_split (_vq, num); +if (err) +virtqueue_reinit_split (vq); + } + +if (vdev->config->enable_reset_vq (_vq)) +return -EBUSY ; + +return err; +} +EXPORT_SYMBOL_GPL (virtqueue_resize); +/* Only available for split ring */ struct virtqueue *vring_new_virtqueue(unsigned int index, unsigned int num,include/linux/virtio.h +3
-0@@ -91,6 +91,9 @@ dma_addr_t virtqueue_get_desc_addr(struct virtqueue *vq);dma_addr_t virtqueue_get_avail_addr (struct virtqueue *vq);dma_addr_t virtqueue_get_used_addr (struct virtqueue *vq); +int virtqueue_resize (struct virtqueue *vq,u32 num, +void (*recycle)(struct virtqueue *vq,void *buf)); +/** * virtio_device - representation of a device using virtio * @index: unique position on the virtio bus
Xuan Zhuo
reviewerRe: [PATCH v9 18/32] virtio_ring: introduce virtqueue_resize()
In reply to Jason WangQuoted 87 lines · Jason Wang
Quoted 33 lines · Xuan Zhuo
Introduce
virtqueue_resize()to implement the resize of vring. Based on these, the driver can dynamically adjust the size of the vring. For example: ethtool -G.
virtqueue_resize()implements resize based on the vq reset function. In case of failure to allocate a new vring, it will give up resize and use the original vring.During this process, if the re-enable reset vq fails, the vq can no longer be used. Although the probability of this situation is not high.
The parameter recycle is used to recycle the buffer that is no longer used.
Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_ring.c | 69 ++++++++++++++++++++++++++++++++++++ include/linux/virtio.h | 3 ++ 2 files changed, 72 insertions(+)drivers/virtio/virtio_ring.c +5
-0@@ -2554,6 +2554,75 @@ struct virtqueue *vring_create_virtqueue( }EXPORT_SYMBOL_GPL (vring_create_virtqueue); +/** +* virtqueue_resize - resize the vring of vq +* @_vq: the struct virtqueue we're talking about. +* @num: new ring num +* @recycle: callback for recycle the useless buffer drivers/virtio/virtio_ring.c struct virtqueue *vring_create_virtqueue( · line 2571
Quoted 10 lines
drivers/virtio/virtio_ring.c +10
-0+* +* When it is really necessary to create a new vring, it will set the current vq +* into the reset state. Then call the passed callback to recycle the buffer +* that is no longer used. Only after the new vring is successfully created, the +* old vring will be released. +* +* Caller must ensure we don't call this with other virtqueue operations +* at the same time (except where noted). +* +* Returns zero or a negative error. Should we document that the virtqueue is kept unchanged (still available) on (specific) failure?
Quoted 36 lines
drivers/virtio/virtio_ring.c +36
-0+*/ +int virtqueue_resize (struct virtqueue *_vq,u32 num, +void (*recycle)(struct virtqueue *vq,void *buf)) +{ +struct vring_virtqueue *vq =to_vvq (_vq); +struct virtio_device *vdev = vq->vq.vdev; +bool packed; +void *buf; +int err; + +if (!vq->we_own_ring) +return -EINVAL ; + +if (num > vq->vq.num_max) +return -E2BIG ; + +if (!num) +return -EINVAL ; + + packed =virtio_has_feature (vdev,VIRTIO_F_RING_PACKED ) ? true : false; + +if ((packed ? vq->packed.vring.num : vq->split.vring.num) == num) +return 0 ; + +if (!vdev->config->reset_vq) +return -ENOENT ; + +if (!vdev->config->enable_reset_vq) +return -ENOENT ; + + err = vdev->config->reset_vq (_vq); +if (err) +return err; + +while ((buf =virtqueue_detach_unused_buf (_vq)) !=NULL ) +recycle (_vq, buf);
Quoted 8 lines
drivers/virtio/virtio_ring.c struct virtqueue *vring_create_virtqueue( · line 2612
Quoted 5 lines
drivers/virtio/virtio_ring.c +5
-0+ +if (packed) { + err =virtqueue_resize_packed (_vq, num); +if (err) +virtqueue_reinit_packed (vq);Calling reinit here seems a little bit odd, it looks more like a reset
I also feel that this is a bit odd, I will put virtqueue_reinit_* into virtqueue_resize_*.
Thanks.
Quoted 45 lines
of the virtqueue. Consider we may re-use virtqueue reset for more purpose, I wonder if we need a helper like:
virtqueue_resize(){
vdev->config->reset_vq(_vq);
if (packed)
virtqueue_reinit_packed(_vq)
else
virtqueue_reinit_split(_vq)
}Thanks
Quoted 30 lines
drivers/virtio/virtio_ring.c +13
-0+ }else { + err =virtqueue_resize_split (_vq, num); +if (err) +virtqueue_reinit_split (vq); + } + +if (vdev->config->enable_reset_vq (_vq)) +return -EBUSY ; + +return err; +} +EXPORT_SYMBOL_GPL (virtqueue_resize); +/* Only available for split ring */ struct virtqueue *vring_new_virtqueue(unsigned int index, unsigned int num,include/linux/virtio.h +3
-0@@ -91,6 +91,9 @@ dma_addr_t virtqueue_get_desc_addr(struct virtqueue *vq);dma_addr_t virtqueue_get_avail_addr (struct virtqueue *vq);dma_addr_t virtqueue_get_used_addr (struct virtqueue *vq); +int virtqueue_resize (struct virtqueue *vq,u32 num, +void (*recycle)(struct virtqueue *vq,void *buf)); +/** * virtio_device - representation of a device using virtio * @index: unique position on the virtio bus
Xuan Zhuo
reviewerPATCH v9 19/32 virtio_pci: struct virtio_pci_common_cfg add queue_notify_data
In reply to Xuan ZhuoAdd queue_notify_data in struct virtio_pci_common_cfg, which comes from here https://github.com/oasis-tcs/virtio-spec/issues/89
For not breaks uABI, add a new struct virtio_pci_common_cfg_notify.
Since I want to add queue_reset after queue_notify_data, I submitted this patch first.
--- include/uapi/linux/virtio_pci.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/uapi/linux/virtio_pci.h +7 -0
@@ -166,6 +166,13 @@ struct virtio_pci_common_cfg {__le32 queue_used_hi;/* read-write */ }; +struct virtio_pci_common_cfg_notify { +struct virtio_pci_common_cfg cfg; + +__le16 queue_notify_data;/* read-write */ +__le16 padding; +}; +/* Fields in VIRTIO_PCI_CAP_PCI_CFG: */ struct virtio_pci_cfg_cap {struct virtio_pci_cap cap;
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 20/32 virtio: queue_reset: add VIRTIO_F_RING_RESET
In reply to Xuan ZhuoAdded VIRTIO_F_RING_RESET, it came from here
https://github.com/oasis-tcs/virtio-spec/issues/124
This feature indicates that the driver can reset a queue individually.
--- include/uapi/linux/virtio_config.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
include/uapi/linux/virtio_config.h +6 -1
@@ -52,7 +52,7 @@* rest are per-device feature bits. */ #define VIRTIO_TRANSPORT_F_START 28 -#define VIRTIO_TRANSPORT_F_END 38 +#define VIRTIO_TRANSPORT_F_END 41#ifndef VIRTIO_CONFIG_NO_LEGACY /* Do we get callbacks when the ring is completely used, even if we've
@@ -92,4 +92,9 @@* Does the device support Single Root I/O Virtualization? */ #define VIRTIO_F_SR_IOV 37 + +/* +* This feature indicates that the driver can reset a queue individually. +*/ +#define VIRTIO_F_RING_RESET 40#endif /* _UAPI_LINUX_VIRTIO_CONFIG_H */
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 21/32 virtio_pci: queue_reset: update struct virtio_pci_common_cfg and option functions
In reply to Xuan ZhuoAdd queue_reset in virtio_pci_common_cfg, and add related operation functions.
For not breaks uABI, add a new struct virtio_pci_common_cfg_reset.
--- drivers/virtio/virtio_pci_modern_dev.c | 36 ++++++++++++++++++++++++++ include/linux/virtio_pci_modern.h | 2 ++ include/uapi/linux/virtio_pci.h | 7 +++++ 3 files changed, 45 insertions(+)
drivers/virtio/virtio_pci_modern_dev.c +36 -0
@@ -3,6 +3,7 @@#include <linux/virtio_pci_modern.h> #include <linux/module.h> #include <linux/pci.h> +#include <linux/delay.h> /* * vp_modern_map_capability - map a part of virtio pci capability
@@ -463,6 +464,41 @@ void vp_modern_set_status(struct virtio_pci_modern_device *mdev, }EXPORT_SYMBOL_GPL (vp_modern_set_status); +/* +* vp_modern_get_queue_reset - get the queue reset status +* @mdev: the modern virtio-pci device +* @index: queue index +*/ +int vp_modern_get_queue_reset (struct virtio_pci_modern_device *mdev,u16 index) +{ +struct virtio_pci_common_cfg_reset __iomem *cfg; + + cfg = (struct virtio_pci_common_cfg_reset __iomem *)mdev->common; + +vp_iowrite16 (index, &cfg->cfg.queue_select); +return vp_ioread16 (&cfg->queue_reset); +} +EXPORT_SYMBOL_GPL (vp_modern_get_queue_reset); + +/* +* vp_modern_set_queue_reset - reset the queue +* @mdev: the modern virtio-pci device +* @index: queue index +*/ +void vp_modern_set_queue_reset (struct virtio_pci_modern_device *mdev,u16 index) +{ +struct virtio_pci_common_cfg_reset __iomem *cfg; + + cfg = (struct virtio_pci_common_cfg_reset __iomem *)mdev->common; + +vp_iowrite16 (index, &cfg->cfg.queue_select); +vp_iowrite16 (1 , &cfg->queue_reset); + +while (vp_ioread16 (&cfg->queue_reset) !=1 ) +msleep (1 ); +} +EXPORT_SYMBOL_GPL (vp_modern_set_queue_reset); +/* * vp_modern_queue_vector - set the MSIX vector for a specific virtqueue * @mdev: the modern virtio-pci device
include/linux/virtio_pci_modern.h +2 -0
@@ -106,4 +106,6 @@ void __iomem * vp_modern_map_vq_notify(struct virtio_pci_modern_device *mdev, u16 index, resource_size_t *pa);int vp_modern_probe (struct virtio_pci_modern_device *mdev);void vp_modern_remove (struct virtio_pci_modern_device *mdev); +int vp_modern_get_queue_reset (struct virtio_pci_modern_device *mdev,u16 index); +void vp_modern_set_queue_reset (struct virtio_pci_modern_device *mdev,u16 index);#endif
include/uapi/linux/virtio_pci.h +7 -0
@@ -173,6 +173,13 @@ struct virtio_pci_common_cfg_notify {__le16 padding; }; +struct virtio_pci_common_cfg_reset { +struct virtio_pci_common_cfg cfg; + +__le16 queue_notify_data;/* read-write */ +__le16 queue_reset;/* read-write */ +}; +/* Fields in VIRTIO_PCI_CAP_PCI_CFG: */ struct virtio_pci_cfg_cap {struct virtio_pci_cap cap;
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 21/32] virtio_pci: queue_reset: update struct virtio_pci_common_cfg and option functions
Quoted 82 lines · Xuan Zhuo
Add
queue_resetinvirtio_pci_common_cfg, and add related operation functions.For not breaks uABI, add a new struct
virtio_pci_common_cfg_reset.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_pci_modern_dev.c | 36 ++++++++++++++++++++++++++ include/linux/virtio_pci_modern.h | 2 ++ include/uapi/linux/virtio_pci.h | 7 +++++ 3 files changed, 45 insertions(+)drivers/virtio/virtio_pci_modern_dev.c +36
-0@@ -3,6 +3,7 @@#include <linux/virtio_pci_modern.h> #include <linux/module.h> #include <linux/pci.h> +#include <linux/delay.h> /* * vp_modern_map_capability - map a part of virtio pci capability @@ -463,6 +464,41 @@ void vp_modern_set_status(struct virtio_pci_modern_device *mdev, }EXPORT_SYMBOL_GPL (vp_modern_set_status); +/* +* vp_modern_get_queue_reset - get the queue reset status +* @mdev: the modern virtio-pci device +* @index: queue index +*/ +int vp_modern_get_queue_reset (struct virtio_pci_modern_device *mdev,u16 index) +{ +struct virtio_pci_common_cfg_reset __iomem *cfg; + + cfg = (struct virtio_pci_common_cfg_reset __iomem *)mdev->common; + +vp_iowrite16 (index, &cfg->cfg.queue_select); +return vp_ioread16 (&cfg->queue_reset); +} +EXPORT_SYMBOL_GPL (vp_modern_get_queue_reset); + +/* +* vp_modern_set_queue_reset - reset the queue +* @mdev: the modern virtio-pci device +* @index: queue index +*/ +void vp_modern_set_queue_reset (struct virtio_pci_modern_device *mdev,u16 index) +{ +struct virtio_pci_common_cfg_reset __iomem *cfg; + + cfg = (struct virtio_pci_common_cfg_reset __iomem *)mdev->common; + +vp_iowrite16 (index, &cfg->cfg.queue_select); +vp_iowrite16 (1 , &cfg->queue_reset); + +while (vp_ioread16 (&cfg->queue_reset) !=1 ) +msleep (1 ); +} +EXPORT_SYMBOL_GPL (vp_modern_set_queue_reset); +/* * vp_modern_queue_vector - set the MSIX vector for a specific virtqueue * @mdev: the modern virtio-pci device include/linux/virtio_pci_modern.h +2
-0@@ -106,4 +106,6 @@ void __iomem * vp_modern_map_vq_notify(struct virtio_pci_modern_device *mdev, u16 index, resource_size_t *pa);int vp_modern_probe (struct virtio_pci_modern_device *mdev);void vp_modern_remove (struct virtio_pci_modern_device *mdev); +int vp_modern_get_queue_reset (struct virtio_pci_modern_device *mdev,u16 index); +void vp_modern_set_queue_reset (struct virtio_pci_modern_device *mdev,u16 index);#endif include/uapi/linux/virtio_pci.h +0
-0
include/uapi/linux/virtio_pci.h struct virtio_pci_common_cfg_notify { · line 181
Quoted 9 lines
include/uapi/linux/virtio_pci.h +6
-0@@ -173,6 +173,13 @@ struct virtio_pci_common_cfg_notify {__le16 padding; }; +struct virtio_pci_common_cfg_reset { +struct virtio_pci_common_cfg cfg; + +__le16 queue_notify_data;/* read-write */ +__le16 queue_reset;/* read-write */ +};
I prefer to use a separate patch for the uAPI change.
Other looks good.
Thanks
include/uapi/linux/virtio_pci.h struct virtio_pci_common_cfg_notify { · line 185
Quoted 4 lines
include/uapi/linux/virtio_pci.h +1
-0+/* Fields in VIRTIO_PCI_CAP_PCI_CFG: */ struct virtio_pci_cfg_cap {struct virtio_pci_cap cap;
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 22/32 virtio_pci: queue_reset: extract the logic of active vq for modern pci
In reply to Xuan ZhuoIntroduce vp_active_vq() to configure vring to backend after vq attach vring. And configure vq vector if necessary.
--- drivers/virtio/virtio_pci_modern.c | 46 ++++++++++++++++++------------ 1 file changed, 28 insertions(+), 18 deletions(-)
drivers/virtio/virtio_pci_modern.c +28 -18
@@ -176,6 +176,29 @@ static void vp_reset(struct virtio_device *vdev)vp_disable_cbs (vdev); } +static int vp_active_vq (struct virtqueue *vq,u16 msix_vec) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +unsigned long index; + + index = vq->index; + +/* activate the queue */ +vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); +vp_modern_queue_address (mdev, index,virtqueue_get_desc_addr (vq), +virtqueue_get_avail_addr (vq), +virtqueue_get_used_addr (vq)); + +if (msix_vec !=VIRTIO_MSI_NO_VECTOR ) { + msix_vec =vp_modern_queue_vector (mdev, index, msix_vec); +if (msix_vec ==VIRTIO_MSI_NO_VECTOR ) +return -EBUSY ; + } + +return 0 ; +} +static u16 vp_config_vector (struct virtio_pci_device *vp_dev,u16 vector) {return vp_modern_config_vector (&vp_dev->mdev, vector);
@@ -220,32 +243,19 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, vq->num_max = num; -/* activate the queue */ -vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); -vp_modern_queue_address (mdev, index,virtqueue_get_desc_addr (vq), -virtqueue_get_avail_addr (vq), -virtqueue_get_used_addr (vq)); + err =vp_active_vq (vq, msix_vec); +if (err) + goto err; vq->priv = (void __force *)vp_modern_map_vq_notify (mdev, index,NULL );if (!vq->priv) { err = -ENOMEM ; - goto err_map_notify; - } - -if (msix_vec !=VIRTIO_MSI_NO_VECTOR ) { - msix_vec =vp_modern_queue_vector (mdev, index, msix_vec); -if (msix_vec ==VIRTIO_MSI_NO_VECTOR ) { - err = -EBUSY ; - goto err_assign_vector; - } + goto err; }return vq; -err_assign_vector: -if (!mdev->notify_base) -pci_iounmap (mdev->pci_dev, (void __iomem __force *)vq->priv); -err_map_notify: +err:vring_del_virtqueue (vq);return ERR_PTR (err); }
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 22/32] virtio_pci: queue_reset: extract the logic of active vq for modern pci
Quoted 65 lines · Xuan Zhuo
Introduce
vp_active_vq()to configure vring to backend after vq attach vring. And configure vq vector if necessary.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_pci_modern.c | 46 ++++++++++++++++++------------ 1 file changed, 28 insertions(+), 18 deletions(-)drivers/virtio/virtio_pci_modern.c +26
-12@@ -176,6 +176,29 @@ static void vp_reset(struct virtio_device *vdev)vp_disable_cbs (vdev); } +static int vp_active_vq (struct virtqueue *vq,u16 msix_vec) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +unsigned long index; + + index = vq->index; + +/* activate the queue */ +vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); +vp_modern_queue_address (mdev, index,virtqueue_get_desc_addr (vq), +virtqueue_get_avail_addr (vq), +virtqueue_get_used_addr (vq)); + +if (msix_vec !=VIRTIO_MSI_NO_VECTOR ) { + msix_vec =vp_modern_queue_vector (mdev, index, msix_vec); +if (msix_vec ==VIRTIO_MSI_NO_VECTOR ) +return -EBUSY ; + } + +return 0 ; +} +static u16 vp_config_vector (struct virtio_pci_device *vp_dev,u16 vector) {return vp_modern_config_vector (&vp_dev->mdev, vector);@@ -220,32 +243,19 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, vq->num_max = num; -/* activate the queue */ -vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); -vp_modern_queue_address (mdev, index,virtqueue_get_desc_addr (vq), -virtqueue_get_avail_addr (vq), -virtqueue_get_used_addr (vq)); + err =vp_active_vq (vq, msix_vec); +if (err) + goto err; vq->priv = (void __force *)vp_modern_map_vq_notify (mdev, index,NULL );if (!vq->priv) { err = -ENOMEM ; - goto err_map_notify; - } - -if (msix_vec !=VIRTIO_MSI_NO_VECTOR ) { - msix_vec =vp_modern_queue_vector (mdev, index, msix_vec); -if (msix_vec ==VIRTIO_MSI_NO_VECTOR ) { - err = -EBUSY ;
drivers/virtio/virtio_pci_modern.c static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, · line 247
Quoted 10 lines
drivers/virtio/virtio_pci_modern.c +1
-5- goto err_assign_vector; - } + goto err; }return vq; -err_assign_vector: -if (!mdev->notify_base) -pci_iounmap (mdev->pci_dev, (void __iomem __force *)vq->priv);
We need keep this or anything I missed?
Thanks
drivers/virtio/virtio_pci_modern.c static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, · line 261
Quoted 5 lines
drivers/virtio/virtio_pci_modern.c +1
-1-err_map_notify: +err:vring_del_virtqueue (vq);return ERR_PTR (err); }
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 22/32] virtio_pci: queue_reset: extract the logic of active vq for modern pci
Quoted 72 lines · Jason Wang
Quoted 70 lines · Xuan Zhuo
Introduce
vp_active_vq()to configure vring to backend after vq attach vring. And configure vq vector if necessary.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_pci_modern.c | 46 ++++++++++++++++++------------ 1 file changed, 28 insertions(+), 18 deletions(-)drivers/virtio/virtio_pci_modern.c +27
-14@@ -176,6 +176,29 @@ static void vp_reset(struct virtio_device *vdev)vp_disable_cbs (vdev); } +static int vp_active_vq (struct virtqueue *vq,u16 msix_vec) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +unsigned long index; + + index = vq->index; + +/* activate the queue */ +vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); +vp_modern_queue_address (mdev, index,virtqueue_get_desc_addr (vq), +virtqueue_get_avail_addr (vq), +virtqueue_get_used_addr (vq)); + +if (msix_vec !=VIRTIO_MSI_NO_VECTOR ) { + msix_vec =vp_modern_queue_vector (mdev, index, msix_vec); +if (msix_vec ==VIRTIO_MSI_NO_VECTOR ) +return -EBUSY ; + } + +return 0 ; +} +static u16 vp_config_vector (struct virtio_pci_device *vp_dev,u16 vector) {return vp_modern_config_vector (&vp_dev->mdev, vector);@@ -220,32 +243,19 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, vq->num_max = num; -/* activate the queue */ -vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); -vp_modern_queue_address (mdev, index,virtqueue_get_desc_addr (vq), -virtqueue_get_avail_addr (vq), -virtqueue_get_used_addr (vq)); + err =vp_active_vq (vq, msix_vec); +if (err) + goto err; vq->priv = (void __force *)vp_modern_map_vq_notify (mdev, index,NULL );if (!vq->priv) { err = -ENOMEM ; - goto err_map_notify; - } - -if (msix_vec !=VIRTIO_MSI_NO_VECTOR ) { - msix_vec =vp_modern_queue_vector (mdev, index, msix_vec); -if (msix_vec ==VIRTIO_MSI_NO_VECTOR ) { - err = -EBUSY ; - goto err_assign_vector; - } + goto err; }
Quoted 8 lines
drivers/virtio/virtio_pci_modern.c static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, · line 247
Quoted 5 lines
drivers/virtio/virtio_pci_modern.c +0
-3return vq; -err_assign_vector: -if (!mdev->notify_base) -pci_iounmap (mdev->pci_dev, (void __iomem __force *)vq->priv);We need keep this or anything I missed?
I think so, after modification, vp_modern_map_vq_notify is the last step before returning vq. If it fails, then vq->priv is equal to NULL, so there is no need to execute pci_iounmap.
Did I miss something?
Thanks.
Quoted 10 lines
Thanks
Quoted 5 lines
drivers/virtio/virtio_pci_modern.c +1
-1-err_map_notify: +err:vring_del_virtqueue (vq);return ERR_PTR (err); }
Jason Wang
Acked-byRe: [PATCH v9 22/32] virtio_pci: queue_reset: extract the logic of active vq for modern pci
Quoted 83 lines · Xuan Zhuo
Quoted 72 lines · Jason Wang
Quoted 70 lines · Xuan Zhuo
Introduce
vp_active_vq()to configure vring to backend after vq attach vring. And configure vq vector if necessary.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_pci_modern.c | 46 ++++++++++++++++++------------ 1 file changed, 28 insertions(+), 18 deletions(-)drivers/virtio/virtio_pci_modern.c +27
-14@@ -176,6 +176,29 @@ static void vp_reset(struct virtio_device *vdev)vp_disable_cbs (vdev); } +static int vp_active_vq (struct virtqueue *vq,u16 msix_vec) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +unsigned long index; + + index = vq->index; + +/* activate the queue */ +vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); +vp_modern_queue_address (mdev, index,virtqueue_get_desc_addr (vq), +virtqueue_get_avail_addr (vq), +virtqueue_get_used_addr (vq)); + +if (msix_vec !=VIRTIO_MSI_NO_VECTOR ) { + msix_vec =vp_modern_queue_vector (mdev, index, msix_vec); +if (msix_vec ==VIRTIO_MSI_NO_VECTOR ) +return -EBUSY ; + } + +return 0 ; +} +static u16 vp_config_vector (struct virtio_pci_device *vp_dev,u16 vector) {return vp_modern_config_vector (&vp_dev->mdev, vector);@@ -220,32 +243,19 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, vq->num_max = num; -/* activate the queue */ -vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq)); -vp_modern_queue_address (mdev, index,virtqueue_get_desc_addr (vq), -virtqueue_get_avail_addr (vq), -virtqueue_get_used_addr (vq)); + err =vp_active_vq (vq, msix_vec); +if (err) + goto err; vq->priv = (void __force *)vp_modern_map_vq_notify (mdev, index,NULL );if (!vq->priv) { err = -ENOMEM ; - goto err_map_notify; - } - -if (msix_vec !=VIRTIO_MSI_NO_VECTOR ) { - msix_vec =vp_modern_queue_vector (mdev, index, msix_vec); -if (msix_vec ==VIRTIO_MSI_NO_VECTOR ) { - err = -EBUSY ; - goto err_assign_vector; - } + goto err; }Quoted 8 lines
drivers/virtio/virtio_pci_modern.c static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, · line 247
Quoted 5 lines
drivers/virtio/virtio_pci_modern.c +0
-3return vq; -err_assign_vector: -if (!mdev->notify_base) -pci_iounmap (mdev->pci_dev, (void __iomem __force *)vq->priv);We need keep this or anything I missed?
Quoted 5 lines
I think so, after modification,
vp_modern_map_vq_notifyis the last step before returning vq. If it fails, thenvq->privis equal to NULL, so there is no need to executepci_iounmap.Did I miss something?
Nope I miss that the vector is configured before the mapping.
So
Thanks
Quoted 14 lines
Thanks.
Quoted 10 lines
Thanks
Quoted 5 lines
drivers/virtio/virtio_pci_modern.c +1
-1-err_map_notify: +err:vring_del_virtqueue (vq);return ERR_PTR (err); }
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 23/32 virtio_pci: queue_reset: support VIRTIO_F_RING_RESET
In reply to Xuan ZhuoThis patch implements virtio pci support for QUEUE RESET.
Performing reset on a queue is divided into these steps:
1. notify the device to reset the queue
2. recycle the buffer submitted
3. reset the vring (may re-alloc)
4. mmap vring to device, and enable the queue
This patch implements virtio_reset_vq(), virtio_enable_resetq() in the pci scenario.
--- drivers/virtio/virtio_pci_common.c | 8 +-- drivers/virtio/virtio_pci_modern.c | 84 ++++++++++++++++++++++++++++++ drivers/virtio/virtio_ring.c | 2 + include/linux/virtio.h | 1 + 4 files changed, 92 insertions(+), 3 deletions(-)
drivers/virtio/virtio_pci_common.c +5 -3
@@ -248,9 +248,11 @@ static void vp_del_vq(struct virtqueue *vq)struct virtio_pci_vq_info *info = vp_dev->vqs[vq->index];unsigned long flags; -spin_lock_irqsave (&vp_dev->lock, flags); -list_del (&info->node); -spin_unlock_irqrestore (&vp_dev->lock, flags); +if (!vq->reset) { +spin_lock_irqsave (&vp_dev->lock, flags); +list_del (&info->node); +spin_unlock_irqrestore (&vp_dev->lock, flags); + } vp_dev->del_vq (info);kfree (info);
drivers/virtio/virtio_pci_modern.c +84 -0
108 lines not on this page · raw message
drivers/virtio/virtio_ring.c +2 -0
@@ -2028,6 +2028,7 @@ static struct virtqueue *vring_create_virtqueue_packed( vq->vq.vdev = vdev; vq->vq.name = name; vq->vq.index = index; + vq->vq.reset = false; vq->notify = notify; vq->weak_barriers = weak_barriers;
@@ -2508,6 +2509,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->vq.vdev = vdev; vq->vq.name = name; vq->vq.index = index; + vq->vq.reset = false; vq->notify = notify; vq->weak_barriers = weak_barriers;
include/linux/virtio.h +1 -0
@@ -33,6 +33,7 @@ struct virtqueue {unsigned int num_free;unsigned int num_max;void *priv; +bool reset; }; int virtqueue_add_outbuf(struct virtqueue *vq,
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 23/32] virtio_pci: queue_reset: support VIRTIO_F_RING_RESET
Quoted 25 lines · Xuan Zhuo
This patch implements virtio pci support for QUEUE RESET.
Performing reset on a queue is divided into these steps:
1. notify the device to reset the queue
2. recycle the buffer submitted
3. reset the vring (may re-alloc)
4. mmap vring to device, and enable the queueThis patch implements
virtio_reset_vq(),virtio_enable_resetq()in the pci scenario.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_pci_common.c | 8 +-- drivers/virtio/virtio_pci_modern.c | 84 ++++++++++++++++++++++++++++++ drivers/virtio/virtio_ring.c | 2 + include/linux/virtio.h | 1 + 4 files changed, 92 insertions(+), 3 deletions(-)drivers/virtio/virtio_pci_common.c +0
-0
drivers/virtio/virtio_pci_common.c static void vp_del_vq(struct virtqueue *vq) · line 251
Quoted 7 lines
drivers/virtio/virtio_pci_common.c +1
-3@@ -248,9 +248,11 @@ static void vp_del_vq(struct virtqueue *vq)struct virtio_pci_vq_info *info = vp_dev->vqs[vq->index];unsigned long flags; -spin_lock_irqsave (&vp_dev->lock, flags); -list_del (&info->node); -spin_unlock_irqrestore (&vp_dev->lock, flags); +if (!vq->reset) {
On which condition that we may hit this path?
Quoted 46 lines
drivers/virtio/virtio_pci_common.c +4
-0+spin_lock_irqsave (&vp_dev->lock, flags); +list_del (&info->node); +spin_unlock_irqrestore (&vp_dev->lock, flags); + } vp_dev->del_vq (info);kfree (info);drivers/virtio/virtio_pci_modern.c +24
-0@@ -34,6 +34,9 @@ static void vp_transport_features(struct virtio_device *vdev, u64 features)if ((features &BIT_ULL (VIRTIO_F_SR_IOV )) &&pci_find_ext_capability (pci_dev,PCI_EXT_CAP_ID_SRIOV ))__virtio_set_bit (vdev,VIRTIO_F_SR_IOV ); + +if (features &BIT_ULL (VIRTIO_F_RING_RESET )) +__virtio_set_bit (vdev,VIRTIO_F_RING_RESET ); }/* virtio config->finalize_features() implementation */ @@ -199,6 +202,83 @@ static int vp_active_vq(struct virtqueue *vq, u16 msix_vec)return 0 ; } +static int vp_modern_reset_vq (struct virtqueue *vq) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +struct virtio_pci_vq_info *info; +unsigned long flags; + +if (!virtio_has_feature (vq->vdev,VIRTIO_F_RING_RESET )) +return -ENOENT ; + +vp_modern_set_queue_reset (mdev, vq->index); + + info = vp_dev->vqs[vq->index]; + +/* delete vq from irq handler */ +spin_lock_irqsave (&vp_dev->lock, flags); +list_del (&info->node); +spin_unlock_irqrestore (&vp_dev->lock, flags); + +INIT_LIST_HEAD (&info->node); +
drivers/virtio/virtio_pci_modern.c static int vp_active_vq(struct virtqueue *vq, u16 msix_vec) · line 235
Quoted 10 lines
drivers/virtio/virtio_pci_modern.c +10
-0+/* For the case where vq has an exclusive irq, to prevent the irq from +* being received again and the pending irq, call disable_irq(). +* +* In the scenario based on shared interrupts, vq will be searched from +* the queue virtqueues. Since the previous list_del() has been deleted +* from the queue, it is impossible for vq to be called in this case. +* There is no need to close the corresponding interrupt. +*/ +if (vp_dev->per_vq_vectors && info->msix_vector !=VIRTIO_MSI_NO_VECTOR ) +disable_irq (pci_irq_vector (vp_dev->pci_dev, info->msix_vector));
See the previous discussion and the revert of the first try to harden the interrupt. We probably can't use disable_irq() since it conflicts with the affinity managed IRQ that is used by some drivers.
We need to use synchonize_irq() and per virtqueue flag instead. As mentioned in previous patches, this could be done on top of my rework on the IRQ hardening .
Quoted 30 lines
drivers/virtio/virtio_pci_modern.c +30
-0+ + vq->reset = true; + +return 0 ; +} + +static int vp_modern_enable_reset_vq (struct virtqueue *vq) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +struct virtio_pci_vq_info *info; +unsigned long flags, index; +int err; + +if (!vq->reset) +return -EBUSY ; + + index = vq->index; + info = vp_dev->vqs[index]; + +/* check queue reset status */ +if (vp_modern_get_queue_reset (mdev, index) !=1 ) +return -EBUSY ; + + err =vp_active_vq (vq, info->msix_vector); +if (err) +return err; + +if (vq->callback) { +spin_lock_irqsave (&vp_dev->lock, flags);
drivers/virtio/virtio_pci_modern.c static int vp_active_vq(struct virtqueue *vq, u16 msix_vec) · line 275
Quoted 10 lines
drivers/virtio/virtio_pci_modern.c +10
-0+list_add (&info->node, &vp_dev->virtqueues); +spin_unlock_irqrestore (&vp_dev->lock, flags); + }else { +INIT_LIST_HEAD (&info->node); + } + +vp_modern_set_queue_enable (&vp_dev->mdev, index, true); + +if (vp_dev->per_vq_vectors && info->msix_vector !=VIRTIO_MSI_NO_VECTOR ) +enable_irq (pci_irq_vector (vp_dev->pci_dev, info->msix_vector));
We had the same issue as disable_irq().
Thanks
Quoted 52 lines
drivers/virtio/virtio_pci_modern.c +10
-0+ + vq->reset = false; + +return 0 ; +} +static u16 vp_config_vector (struct virtio_pci_device *vp_dev,u16 vector) {return vp_modern_config_vector (&vp_dev->mdev, vector);@@ -407,6 +487,8 @@ static const struct virtio_config_ops virtio_pci_config_nodev_ops = { .set_vq_affinity = vp_set_vq_affinity, .get_vq_affinity = vp_get_vq_affinity, .get_shm_region = vp_get_shm_region, + .reset_vq = vp_modern_reset_vq, + .enable_reset_vq = vp_modern_enable_reset_vq, };static const struct virtio_config_ops virtio_pci_config_ops = {@@ -425,6 +507,8 @@ static const struct virtio_config_ops virtio_pci_config_ops = { .set_vq_affinity = vp_set_vq_affinity, .get_vq_affinity = vp_get_vq_affinity, .get_shm_region = vp_get_shm_region, + .reset_vq = vp_modern_reset_vq, + .enable_reset_vq = vp_modern_enable_reset_vq, };/* the PCI probing function */ drivers/virtio/virtio_ring.c +2
-0@@ -2028,6 +2028,7 @@ static struct virtqueue *vring_create_virtqueue_packed( vq->vq.vdev = vdev; vq->vq.name = name; vq->vq.index = index; + vq->vq.reset = false; vq->notify = notify; vq->weak_barriers = weak_barriers;@@ -2508,6 +2509,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->vq.vdev = vdev; vq->vq.name = name; vq->vq.index = index; + vq->vq.reset = false; vq->notify = notify; vq->weak_barriers = weak_barriers;include/linux/virtio.h +0
-0
include/linux/virtio.h struct virtqueue { · line 39
Quoted 7 lines
include/linux/virtio.h +1
-0@@ -33,6 +33,7 @@ struct virtqueue {unsigned int num_free;unsigned int num_max;void *priv; +bool reset; }; int virtqueue_add_outbuf(struct virtqueue *vq,
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 23/32] virtio_pci: queue_reset: support VIRTIO_F_RING_RESET
Quoted 101 lines · Jason Wang
Quoted 25 lines · Xuan Zhuo
This patch implements virtio pci support for QUEUE RESET.
Performing reset on a queue is divided into these steps:
1. notify the device to reset the queue
2. recycle the buffer submitted
3. reset the vring (may re-alloc)
4. mmap vring to device, and enable the queueThis patch implements
virtio_reset_vq(),virtio_enable_resetq()in the pci scenario.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_pci_common.c | 8 +-- drivers/virtio/virtio_pci_modern.c | 84 ++++++++++++++++++++++++++++++ drivers/virtio/virtio_ring.c | 2 + include/linux/virtio.h | 1 + 4 files changed, 92 insertions(+), 3 deletions(-)drivers/virtio/virtio_pci_common.c +0
-0drivers/virtio/virtio_pci_common.c static void vp_del_vq(struct virtqueue *vq) · line 251
Quoted 7 lines
drivers/virtio/virtio_pci_common.c +1
-3@@ -248,9 +248,11 @@ static void vp_del_vq(struct virtqueue *vq)struct virtio_pci_vq_info *info = vp_dev->vqs[vq->index];unsigned long flags; -spin_lock_irqsave (&vp_dev->lock, flags); -list_del (&info->node); -spin_unlock_irqrestore (&vp_dev->lock, flags); +if (!vq->reset) {On which condition that we may hit this path?
Quoted 46 lines
drivers/virtio/virtio_pci_common.c +4
-0+spin_lock_irqsave (&vp_dev->lock, flags); +list_del (&info->node); +spin_unlock_irqrestore (&vp_dev->lock, flags); + } vp_dev->del_vq (info);kfree (info);drivers/virtio/virtio_pci_modern.c +24
-0@@ -34,6 +34,9 @@ static void vp_transport_features(struct virtio_device *vdev, u64 features)if ((features &BIT_ULL (VIRTIO_F_SR_IOV )) &&pci_find_ext_capability (pci_dev,PCI_EXT_CAP_ID_SRIOV ))__virtio_set_bit (vdev,VIRTIO_F_SR_IOV ); + +if (features &BIT_ULL (VIRTIO_F_RING_RESET )) +__virtio_set_bit (vdev,VIRTIO_F_RING_RESET ); }/* virtio config->finalize_features() implementation */ @@ -199,6 +202,83 @@ static int vp_active_vq(struct virtqueue *vq, u16 msix_vec)return 0 ; } +static int vp_modern_reset_vq (struct virtqueue *vq) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +struct virtio_pci_vq_info *info; +unsigned long flags; + +if (!virtio_has_feature (vq->vdev,VIRTIO_F_RING_RESET )) +return -ENOENT ; + +vp_modern_set_queue_reset (mdev, vq->index); + + info = vp_dev->vqs[vq->index]; + +/* delete vq from irq handler */ +spin_lock_irqsave (&vp_dev->lock, flags); +list_del (&info->node); +spin_unlock_irqrestore (&vp_dev->lock, flags); + +INIT_LIST_HEAD (&info->node); +drivers/virtio/virtio_pci_modern.c static int vp_active_vq(struct virtqueue *vq, u16 msix_vec) · line 235
Quoted 10 lines
drivers/virtio/virtio_pci_modern.c +10
-0+/* For the case where vq has an exclusive irq, to prevent the irq from +* being received again and the pending irq, call disable_irq(). +* +* In the scenario based on shared interrupts, vq will be searched from +* the queue virtqueues. Since the previous list_del() has been deleted +* from the queue, it is impossible for vq to be called in this case. +* There is no need to close the corresponding interrupt. +*/ +if (vp_dev->per_vq_vectors && info->msix_vector !=VIRTIO_MSI_NO_VECTOR ) +disable_irq (pci_irq_vector (vp_dev->pci_dev, info->msix_vector));See the previous discussion and the revert of the first try to harden the interrupt. We probably can't use
disable_irq()since it conflicts with the affinity managed IRQ that is used by some drivers.
Quoted 3 lines
We need to use
synchonize_irq()and per virtqueue flag instead. As mentioned in previous patches, this could be done on top of my rework on the IRQ hardening .
OK, the next version will contain hardened features by per virtqueue flag.
Thanks.
Quoted 109 lines
Quoted 32 lines
drivers/virtio/virtio_pci_modern.c +30
-0+ + vq->reset = true; + +return 0 ; +} + +static int vp_modern_enable_reset_vq (struct virtqueue *vq) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +struct virtio_pci_vq_info *info; +unsigned long flags, index; +int err; + +if (!vq->reset) +return -EBUSY ; + + index = vq->index; + info = vp_dev->vqs[index]; + +/* check queue reset status */ +if (vp_modern_get_queue_reset (mdev, index) !=1 ) +return -EBUSY ; + + err =vp_active_vq (vq, info->msix_vector); +if (err) +return err; + +if (vq->callback) { +spin_lock_irqsave (&vp_dev->lock, flags);drivers/virtio/virtio_pci_modern.c static int vp_active_vq(struct virtqueue *vq, u16 msix_vec) · line 275
Quoted 10 lines
drivers/virtio/virtio_pci_modern.c +10
-0+list_add (&info->node, &vp_dev->virtqueues); +spin_unlock_irqrestore (&vp_dev->lock, flags); + }else { +INIT_LIST_HEAD (&info->node); + } + +vp_modern_set_queue_enable (&vp_dev->mdev, index, true); + +if (vp_dev->per_vq_vectors && info->msix_vector !=VIRTIO_MSI_NO_VECTOR ) +enable_irq (pci_irq_vector (vp_dev->pci_dev, info->msix_vector));We had the same issue as
disable_irq().Thanks
Quoted 59 lines
drivers/virtio/virtio_pci_modern.c +10
-0+ + vq->reset = false; + +return 0 ; +} +static u16 vp_config_vector (struct virtio_pci_device *vp_dev,u16 vector) {return vp_modern_config_vector (&vp_dev->mdev, vector);@@ -407,6 +487,8 @@ static const struct virtio_config_ops virtio_pci_config_nodev_ops = { .set_vq_affinity = vp_set_vq_affinity, .get_vq_affinity = vp_get_vq_affinity, .get_shm_region = vp_get_shm_region, + .reset_vq = vp_modern_reset_vq, + .enable_reset_vq = vp_modern_enable_reset_vq, };static const struct virtio_config_ops virtio_pci_config_ops = {@@ -425,6 +507,8 @@ static const struct virtio_config_ops virtio_pci_config_ops = { .set_vq_affinity = vp_set_vq_affinity, .get_vq_affinity = vp_get_vq_affinity, .get_shm_region = vp_get_shm_region, + .reset_vq = vp_modern_reset_vq, + .enable_reset_vq = vp_modern_enable_reset_vq, };/* the PCI probing function */ drivers/virtio/virtio_ring.c +2
-0@@ -2028,6 +2028,7 @@ static struct virtqueue *vring_create_virtqueue_packed( vq->vq.vdev = vdev; vq->vq.name = name; vq->vq.index = index; + vq->vq.reset = false; vq->notify = notify; vq->weak_barriers = weak_barriers;@@ -2508,6 +2509,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->vq.vdev = vdev; vq->vq.name = name; vq->vq.index = index; + vq->vq.reset = false; vq->notify = notify; vq->weak_barriers = weak_barriers;include/linux/virtio.h +1
-0@@ -33,6 +33,7 @@ struct virtqueue {unsigned int num_free;unsigned int num_max;void *priv; +bool reset; }; int virtqueue_add_outbuf(struct virtqueue *vq,
Re: [PATCH v9 23/32] virtio_pci: queue_reset: support VIRTIO_F_RING_RESET
Quoted 103 lines · Xuan Zhuo
Quoted 101 lines · Jason Wang
Quoted 25 lines · Xuan Zhuo
This patch implements virtio pci support for QUEUE RESET.
Performing reset on a queue is divided into these steps:
1. notify the device to reset the queue
2. recycle the buffer submitted
3. reset the vring (may re-alloc)
4. mmap vring to device, and enable the queueThis patch implements
virtio_reset_vq(),virtio_enable_resetq()in the pci scenario.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_pci_common.c | 8 +-- drivers/virtio/virtio_pci_modern.c | 84 ++++++++++++++++++++++++++++++ drivers/virtio/virtio_ring.c | 2 + include/linux/virtio.h | 1 + 4 files changed, 92 insertions(+), 3 deletions(-)drivers/virtio/virtio_pci_common.c +0
-0drivers/virtio/virtio_pci_common.c static void vp_del_vq(struct virtqueue *vq) · line 251
Quoted 7 lines
drivers/virtio/virtio_pci_common.c +1
-3@@ -248,9 +248,11 @@ static void vp_del_vq(struct virtqueue *vq)struct virtio_pci_vq_info *info = vp_dev->vqs[vq->index];unsigned long flags; -spin_lock_irqsave (&vp_dev->lock, flags); -list_del (&info->node); -spin_unlock_irqrestore (&vp_dev->lock, flags); +if (!vq->reset) {On which condition that we may hit this path?
Quoted 46 lines
drivers/virtio/virtio_pci_common.c +4
-0+spin_lock_irqsave (&vp_dev->lock, flags); +list_del (&info->node); +spin_unlock_irqrestore (&vp_dev->lock, flags); + } vp_dev->del_vq (info);kfree (info);drivers/virtio/virtio_pci_modern.c +24
-0@@ -34,6 +34,9 @@ static void vp_transport_features(struct virtio_device *vdev, u64 features)if ((features &BIT_ULL (VIRTIO_F_SR_IOV )) &&pci_find_ext_capability (pci_dev,PCI_EXT_CAP_ID_SRIOV ))__virtio_set_bit (vdev,VIRTIO_F_SR_IOV ); + +if (features &BIT_ULL (VIRTIO_F_RING_RESET )) +__virtio_set_bit (vdev,VIRTIO_F_RING_RESET ); }/* virtio config->finalize_features() implementation */ @@ -199,6 +202,83 @@ static int vp_active_vq(struct virtqueue *vq, u16 msix_vec)return 0 ; } +static int vp_modern_reset_vq (struct virtqueue *vq) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +struct virtio_pci_vq_info *info; +unsigned long flags; + +if (!virtio_has_feature (vq->vdev,VIRTIO_F_RING_RESET )) +return -ENOENT ; + +vp_modern_set_queue_reset (mdev, vq->index); + + info = vp_dev->vqs[vq->index]; + +/* delete vq from irq handler */ +spin_lock_irqsave (&vp_dev->lock, flags); +list_del (&info->node); +spin_unlock_irqrestore (&vp_dev->lock, flags); + +INIT_LIST_HEAD (&info->node); +drivers/virtio/virtio_pci_modern.c static int vp_active_vq(struct virtqueue *vq, u16 msix_vec) · line 235
Quoted 10 lines
drivers/virtio/virtio_pci_modern.c +10
-0+/* For the case where vq has an exclusive irq, to prevent the irq from +* being received again and the pending irq, call disable_irq(). +* +* In the scenario based on shared interrupts, vq will be searched from +* the queue virtqueues. Since the previous list_del() has been deleted +* from the queue, it is impossible for vq to be called in this case. +* There is no need to close the corresponding interrupt. +*/ +if (vp_dev->per_vq_vectors && info->msix_vector !=VIRTIO_MSI_NO_VECTOR ) +disable_irq (pci_irq_vector (vp_dev->pci_dev, info->msix_vector));See the previous discussion and the revert of the first try to harden the interrupt. We probably can't use
disable_irq()since it conflicts with the affinity managed IRQ that is used by some drivers.
Quoted 5 lines
Quoted 3 lines
We need to use
synchonize_irq()and per virtqueue flag instead. As mentioned in previous patches, this could be done on top of my rework on the IRQ hardening .OK, the next version will contain hardened features by per virtqueue flag.
Actually, I'm working on a new version of hardening. I plan to switch to the virtqueue flag so we will be fine here if we do the resize work on top.
I will cc you in the new version.
Thanks
Quoted 113 lines
Thanks.
Quoted 109 lines
Quoted 32 lines
drivers/virtio/virtio_pci_modern.c +30
-0+ + vq->reset = true; + +return 0 ; +} + +static int vp_modern_enable_reset_vq (struct virtqueue *vq) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +struct virtio_pci_vq_info *info; +unsigned long flags, index; +int err; + +if (!vq->reset) +return -EBUSY ; + + index = vq->index; + info = vp_dev->vqs[index]; + +/* check queue reset status */ +if (vp_modern_get_queue_reset (mdev, index) !=1 ) +return -EBUSY ; + + err =vp_active_vq (vq, info->msix_vector); +if (err) +return err; + +if (vq->callback) { +spin_lock_irqsave (&vp_dev->lock, flags);drivers/virtio/virtio_pci_modern.c static int vp_active_vq(struct virtqueue *vq, u16 msix_vec) · line 275
Quoted 10 lines
drivers/virtio/virtio_pci_modern.c +10
-0+list_add (&info->node, &vp_dev->virtqueues); +spin_unlock_irqrestore (&vp_dev->lock, flags); + }else { +INIT_LIST_HEAD (&info->node); + } + +vp_modern_set_queue_enable (&vp_dev->mdev, index, true); + +if (vp_dev->per_vq_vectors && info->msix_vector !=VIRTIO_MSI_NO_VECTOR ) +enable_irq (pci_irq_vector (vp_dev->pci_dev, info->msix_vector));We had the same issue as
disable_irq().Thanks
Quoted 59 lines
drivers/virtio/virtio_pci_modern.c +10
-0+ + vq->reset = false; + +return 0 ; +} +static u16 vp_config_vector (struct virtio_pci_device *vp_dev,u16 vector) {return vp_modern_config_vector (&vp_dev->mdev, vector);@@ -407,6 +487,8 @@ static const struct virtio_config_ops virtio_pci_config_nodev_ops = { .set_vq_affinity = vp_set_vq_affinity, .get_vq_affinity = vp_get_vq_affinity, .get_shm_region = vp_get_shm_region, + .reset_vq = vp_modern_reset_vq, + .enable_reset_vq = vp_modern_enable_reset_vq, };static const struct virtio_config_ops virtio_pci_config_ops = {@@ -425,6 +507,8 @@ static const struct virtio_config_ops virtio_pci_config_ops = { .set_vq_affinity = vp_set_vq_affinity, .get_vq_affinity = vp_get_vq_affinity, .get_shm_region = vp_get_shm_region, + .reset_vq = vp_modern_reset_vq, + .enable_reset_vq = vp_modern_enable_reset_vq, };/* the PCI probing function */ drivers/virtio/virtio_ring.c +2
-0@@ -2028,6 +2028,7 @@ static struct virtqueue *vring_create_virtqueue_packed( vq->vq.vdev = vdev; vq->vq.name = name; vq->vq.index = index; + vq->vq.reset = false; vq->notify = notify; vq->weak_barriers = weak_barriers;@@ -2508,6 +2509,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->vq.vdev = vdev; vq->vq.name = name; vq->vq.index = index; + vq->vq.reset = false; vq->notify = notify; vq->weak_barriers = weak_barriers;include/linux/virtio.h +1
-0@@ -33,6 +33,7 @@ struct virtqueue {unsigned int num_free;unsigned int num_max;void *priv; +bool reset; }; int virtqueue_add_outbuf(struct virtqueue *vq,
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 23/32] virtio_pci: queue_reset: support VIRTIO_F_RING_RESET
In reply to Jason WangQuoted 30 lines · Jason Wang
Quoted 28 lines · Xuan Zhuo
This patch implements virtio pci support for QUEUE RESET.
Performing reset on a queue is divided into these steps:
1. notify the device to reset the queue
2. recycle the buffer submitted
3. reset the vring (may re-alloc)
4. mmap vring to device, and enable the queueThis patch implements
virtio_reset_vq(),virtio_enable_resetq()in the pci scenario.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/virtio/virtio_pci_common.c | 8 +-- drivers/virtio/virtio_pci_modern.c | 84 ++++++++++++++++++++++++++++++ drivers/virtio/virtio_ring.c | 2 + include/linux/virtio.h | 1 + 4 files changed, 92 insertions(+), 3 deletions(-)drivers/virtio/virtio_pci_common.c +0
-0@@ -248,9 +248,11 @@ static void vp_del_vq(struct virtqueue *vq)struct virtio_pci_vq_info *info = vp_dev->vqs[vq->index];unsigned long flags;
Quoted 7 lines
drivers/virtio/virtio_pci_common.c static void vp_del_vq(struct virtqueue *vq) · line 251
Quoted 4 lines
drivers/virtio/virtio_pci_common.c +1
-3-spin_lock_irqsave (&vp_dev->lock, flags); -list_del (&info->node); -spin_unlock_irqrestore (&vp_dev->lock, flags); +if (!vq->reset) {On which condition that we may hit this path?
As discussed in patch 31, it may fail when renable vq.
Thanks.
Quoted 174 lines
Quoted 48 lines
drivers/virtio/virtio_pci_common.c +4
-0+spin_lock_irqsave (&vp_dev->lock, flags); +list_del (&info->node); +spin_unlock_irqrestore (&vp_dev->lock, flags); + } vp_dev->del_vq (info);kfree (info);drivers/virtio/virtio_pci_modern.c +24
-0@@ -34,6 +34,9 @@ static void vp_transport_features(struct virtio_device *vdev, u64 features)if ((features &BIT_ULL (VIRTIO_F_SR_IOV )) &&pci_find_ext_capability (pci_dev,PCI_EXT_CAP_ID_SRIOV ))__virtio_set_bit (vdev,VIRTIO_F_SR_IOV ); + +if (features &BIT_ULL (VIRTIO_F_RING_RESET )) +__virtio_set_bit (vdev,VIRTIO_F_RING_RESET ); }/* virtio config->finalize_features() implementation */ @@ -199,6 +202,83 @@ static int vp_active_vq(struct virtqueue *vq, u16 msix_vec)return 0 ; } +static int vp_modern_reset_vq (struct virtqueue *vq) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +struct virtio_pci_vq_info *info; +unsigned long flags; + +if (!virtio_has_feature (vq->vdev,VIRTIO_F_RING_RESET )) +return -ENOENT ; + +vp_modern_set_queue_reset (mdev, vq->index); + + info = vp_dev->vqs[vq->index]; + +/* delete vq from irq handler */ +spin_lock_irqsave (&vp_dev->lock, flags); +list_del (&info->node); +spin_unlock_irqrestore (&vp_dev->lock, flags); + +INIT_LIST_HEAD (&info->node); +drivers/virtio/virtio_pci_modern.c static int vp_active_vq(struct virtqueue *vq, u16 msix_vec) · line 235
Quoted 10 lines
drivers/virtio/virtio_pci_modern.c +10
-0+/* For the case where vq has an exclusive irq, to prevent the irq from +* being received again and the pending irq, call disable_irq(). +* +* In the scenario based on shared interrupts, vq will be searched from +* the queue virtqueues. Since the previous list_del() has been deleted +* from the queue, it is impossible for vq to be called in this case. +* There is no need to close the corresponding interrupt. +*/ +if (vp_dev->per_vq_vectors && info->msix_vector !=VIRTIO_MSI_NO_VECTOR ) +disable_irq (pci_irq_vector (vp_dev->pci_dev, info->msix_vector));See the previous discussion and the revert of the first try to harden the interrupt. We probably can't use
disable_irq()since it conflicts with the affinity managed IRQ that is used by some drivers.We need to use
synchonize_irq()and per virtqueue flag instead. As mentioned in previous patches, this could be done on top of my rework on the IRQ hardening .Quoted 30 lines
drivers/virtio/virtio_pci_modern.c +30
-0+ + vq->reset = true; + +return 0 ; +} + +static int vp_modern_enable_reset_vq (struct virtqueue *vq) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +struct virtio_pci_vq_info *info; +unsigned long flags, index; +int err; + +if (!vq->reset) +return -EBUSY ; + + index = vq->index; + info = vp_dev->vqs[index]; + +/* check queue reset status */ +if (vp_modern_get_queue_reset (mdev, index) !=1 ) +return -EBUSY ; + + err =vp_active_vq (vq, info->msix_vector); +if (err) +return err; + +if (vq->callback) { +spin_lock_irqsave (&vp_dev->lock, flags);drivers/virtio/virtio_pci_modern.c static int vp_active_vq(struct virtqueue *vq, u16 msix_vec) · line 275
Quoted 10 lines
drivers/virtio/virtio_pci_modern.c +10
-0+list_add (&info->node, &vp_dev->virtqueues); +spin_unlock_irqrestore (&vp_dev->lock, flags); + }else { +INIT_LIST_HEAD (&info->node); + } + +vp_modern_set_queue_enable (&vp_dev->mdev, index, true); + +if (vp_dev->per_vq_vectors && info->msix_vector !=VIRTIO_MSI_NO_VECTOR ) +enable_irq (pci_irq_vector (vp_dev->pci_dev, info->msix_vector));We had the same issue as
disable_irq().Thanks
Quoted 58 lines
drivers/virtio/virtio_pci_modern.c +10
-0+ + vq->reset = false; + +return 0 ; +} +static u16 vp_config_vector (struct virtio_pci_device *vp_dev,u16 vector) {return vp_modern_config_vector (&vp_dev->mdev, vector);@@ -407,6 +487,8 @@ static const struct virtio_config_ops virtio_pci_config_nodev_ops = { .set_vq_affinity = vp_set_vq_affinity, .get_vq_affinity = vp_get_vq_affinity, .get_shm_region = vp_get_shm_region, + .reset_vq = vp_modern_reset_vq, + .enable_reset_vq = vp_modern_enable_reset_vq, };static const struct virtio_config_ops virtio_pci_config_ops = {@@ -425,6 +507,8 @@ static const struct virtio_config_ops virtio_pci_config_ops = { .set_vq_affinity = vp_set_vq_affinity, .get_vq_affinity = vp_get_vq_affinity, .get_shm_region = vp_get_shm_region, + .reset_vq = vp_modern_reset_vq, + .enable_reset_vq = vp_modern_enable_reset_vq, };/* the PCI probing function */ drivers/virtio/virtio_ring.c +2
-0@@ -2028,6 +2028,7 @@ static struct virtqueue *vring_create_virtqueue_packed( vq->vq.vdev = vdev; vq->vq.name = name; vq->vq.index = index; + vq->vq.reset = false; vq->notify = notify; vq->weak_barriers = weak_barriers;@@ -2508,6 +2509,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->vq.vdev = vdev; vq->vq.name = name; vq->vq.index = index; + vq->vq.reset = false; vq->notify = notify; vq->weak_barriers = weak_barriers;include/linux/virtio.h +1
-0@@ -33,6 +33,7 @@ struct virtqueue {unsigned int num_free;unsigned int num_max;void *priv; +bool reset; };
Quoted 2 lines
include/linux/virtio.h struct virtqueue { · line 39
Quoted 1 line
include/linux/virtio.h +0
-0int virtqueue_add_outbuf(struct virtqueue *vq,
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 24/32 virtio: find_vqs() add arg sizes
In reply to Xuan Zhuofind_vqs() adds a new parameter sizes to specify the size of each vq vring.
0 means use the maximum size supported by the backend.
In the split scenario, the meaning of size is the largest size, because it may be limited by memory, the virtio core will try a smaller size. And the size is power of 2.
--- arch/um/drivers/virtio_uml.c | 2 +- drivers/platform/mellanox/mlxbf-tmfifo.c | 1 + drivers/remoteproc/remoteproc_virtio.c | 1 + drivers/s390/virtio/virtio_ccw.c | 1 + drivers/virtio/virtio_mmio.c | 1 + drivers/virtio/virtio_pci_common.c | 2 +- drivers/virtio/virtio_pci_common.h | 2 +- drivers/virtio/virtio_pci_modern.c | 7 +++++-- drivers/virtio/virtio_vdpa.c | 1 + include/linux/virtio_config.h | 14 +++++++++----- 10 files changed, 22 insertions(+), 10 deletions(-)
arch/um/drivers/virtio_uml.c +1 -1
@@ -998,7 +998,7 @@ static struct virtqueue *vu_setup_vq(struct virtio_device *vdev,static int vu_find_vqs (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx, +const char *const names[],u32 sizes[],const bool *ctx,struct irq_affinity *desc) {struct virtio_uml_device *vu_dev =to_virtio_uml_device (vdev);
drivers/platform/mellanox/mlxbf-tmfifo.c +1 -0
@@ -928,6 +928,7 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev,struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], + u32 sizes[], const bool *ctx, struct irq_affinity *desc) {
drivers/remoteproc/remoteproc_virtio.c +1 -0
@@ -158,6 +158,7 @@ static int rproc_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs,struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], + u32 sizes[], const bool * ctx, struct irq_affinity *desc) {
drivers/s390/virtio/virtio_ccw.c +1 -0
@@ -634,6 +634,7 @@ static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], + u32 sizes[], const bool *ctx, struct irq_affinity *desc) {
drivers/virtio/virtio_mmio.c +1 -0
@@ -461,6 +461,7 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs,struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], + u32 sizes[], const bool *ctx, struct irq_affinity *desc) {
drivers/virtio/virtio_pci_common.c +1 -1
@@ -427,7 +427,7 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,/* the config->find_vqs() implementation */ int vp_find_vqs (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx, +const char *const names[],u32 sizes[],const bool *ctx,struct irq_affinity *desc) {int err;
drivers/virtio/virtio_pci_common.h +1 -1
@@ -113,7 +113,7 @@ void vp_del_vqs(struct virtio_device *vdev);/* the config->find_vqs() implementation */ int vp_find_vqs (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx, +const char *const names[],u32 sizes[],const bool *ctx,struct irq_affinity *desc);const char *vp_bus_name (struct virtio_device *vdev);
drivers/virtio/virtio_pci_modern.c +5 -2
@@ -343,12 +343,15 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,static int vp_modern_find_vqs (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx, +const char *const names[], +u32 sizes[], +const bool *ctx,struct irq_affinity *desc) {struct virtio_pci_device *vp_dev =to_vp_device (vdev);struct virtqueue *vq; -int rc =vp_find_vqs (vdev, nvqs, vqs, callbacks, names, ctx, desc); +int rc =vp_find_vqs (vdev, nvqs, vqs, callbacks, names, sizes, ctx, + desc);if (rc)return rc;
drivers/virtio/virtio_vdpa.c +1 -0
@@ -269,6 +269,7 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned nvqs,struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], + u32 sizes[], const bool *ctx, struct irq_affinity *desc) {
include/linux/virtio_config.h +9 -5
@@ -57,6 +57,7 @@ struct virtio_shm_region {* include a NULL entry for vqs that do not need a callback * names: array of virtqueue names (mainly for debugging) * include a NULL entry for vqs unused by driver +* sizes: array of virtqueue sizes * Returns 0 on success or error status * @del_vqs: free virtqueues found by find_vqs(). * @get_features: get the array of feature bits for this device.
@@ -98,7 +99,9 @@ struct virtio_config_ops {void (*reset)(struct virtio_device *vdev);int (*find_vqs)(struct virtio_device *,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx, +const char *const names[], +u32 sizes[], +const bool *ctx,struct irq_affinity *desc);void (*del_vqs)(struct virtio_device *);u64 (*get_features)(struct virtio_device *vdev);
@@ -206,7 +209,7 @@ struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev,const char *names[] = { n };struct virtqueue *vq;int err = vdev->config->find_vqs (vdev,1 , &vq, callbacks, names,NULL , -NULL ); +NULL ,NULL );if (err <0 )return ERR_PTR (err);return vq;
@@ -218,7 +221,8 @@ int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,const char *const names[], struct irq_affinity *desc) { - return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, NULL, desc); + return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, NULL, +NULL ,desc ); } static inline
@@ -227,8 +231,8 @@ int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs, const char * const names[], const bool *ctx, struct irq_affinity *desc) { - return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, ctx, -desc ); + return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, NULL, +ctx ,desc ); }/**
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 24/32] virtio: find_vqs() add arg sizes
Quoted 4 lines · Xuan Zhuo
find_vqs()adds a new parameter sizes to specify the size of each vq vring.0 means use the maximum size supported by the backend.
Does this mean driver still need to prepare a array of 0 or it can simply pass NULL to find_vqs()?
Thanks
Quoted 185 lines
In the split scenario, the meaning of size is the largest size, because it may be limited by memory, the virtio core will try a smaller size. And the size is power of 2.
Signed-off-by Xuan Zhuo <[email protected]>Acked-by Hans de Goede <[email protected]>Reviewed-by Mathieu Poirier <[email protected]>--- arch/um/drivers/virtio_uml.c | 2 +- drivers/platform/mellanox/mlxbf-tmfifo.c | 1 + drivers/remoteproc/remoteproc_virtio.c | 1 + drivers/s390/virtio/virtio_ccw.c | 1 + drivers/virtio/virtio_mmio.c | 1 + drivers/virtio/virtio_pci_common.c | 2 +- drivers/virtio/virtio_pci_common.h | 2 +- drivers/virtio/virtio_pci_modern.c | 7 +++++-- drivers/virtio/virtio_vdpa.c | 1 + include/linux/virtio_config.h | 14 +++++++++----- 10 files changed, 22 insertions(+), 10 deletions(-)arch/um/drivers/virtio_uml.c +1
-1@@ -998,7 +998,7 @@ static struct virtqueue *vu_setup_vq(struct virtio_device *vdev,static int vu_find_vqs (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx, +const char *const names[],u32 sizes[],const bool *ctx,struct irq_affinity *desc) {struct virtio_uml_device *vu_dev =to_virtio_uml_device (vdev);drivers/platform/mellanox/mlxbf-tmfifo.c +1
-0@@ -928,6 +928,7 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev,struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], + u32 sizes[], const bool *ctx, struct irq_affinity *desc) {drivers/remoteproc/remoteproc_virtio.c +1
-0@@ -158,6 +158,7 @@ static int rproc_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs,struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], + u32 sizes[], const bool * ctx, struct irq_affinity *desc) {drivers/s390/virtio/virtio_ccw.c +1
-0@@ -634,6 +634,7 @@ static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], + u32 sizes[], const bool *ctx, struct irq_affinity *desc) {drivers/virtio/virtio_mmio.c +1
-0@@ -461,6 +461,7 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs,struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], + u32 sizes[], const bool *ctx, struct irq_affinity *desc) {drivers/virtio/virtio_pci_common.c +1
-1@@ -427,7 +427,7 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,/* the config->find_vqs() implementation */ int vp_find_vqs (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx, +const char *const names[],u32 sizes[],const bool *ctx,struct irq_affinity *desc) {int err;drivers/virtio/virtio_pci_common.h +1
-1@@ -113,7 +113,7 @@ void vp_del_vqs(struct virtio_device *vdev);/* the config->find_vqs() implementation */ int vp_find_vqs (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx, +const char *const names[],u32 sizes[],const bool *ctx,struct irq_affinity *desc);const char *vp_bus_name (struct virtio_device *vdev);drivers/virtio/virtio_pci_modern.c +5
-2@@ -343,12 +343,15 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,static int vp_modern_find_vqs (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx, +const char *const names[], +u32 sizes[], +const bool *ctx,struct irq_affinity *desc) {struct virtio_pci_device *vp_dev =to_vp_device (vdev);struct virtqueue *vq; -int rc =vp_find_vqs (vdev, nvqs, vqs, callbacks, names, ctx, desc); +int rc =vp_find_vqs (vdev, nvqs, vqs, callbacks, names, sizes, ctx, + desc);if (rc)return rc;drivers/virtio/virtio_vdpa.c +1
-0@@ -269,6 +269,7 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned nvqs,struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], + u32 sizes[], const bool *ctx, struct irq_affinity *desc) {include/linux/virtio_config.h +7
-3@@ -57,6 +57,7 @@ struct virtio_shm_region {* include a NULL entry for vqs that do not need a callback * names: array of virtqueue names (mainly for debugging) * include a NULL entry for vqs unused by driver +* sizes: array of virtqueue sizes * Returns 0 on success or error status * @del_vqs: free virtqueues found by find_vqs(). * @get_features: get the array of feature bits for this device. @@ -98,7 +99,9 @@ struct virtio_config_ops {void (*reset)(struct virtio_device *vdev);int (*find_vqs)(struct virtio_device *,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx, +const char *const names[], +u32 sizes[], +const bool *ctx,struct irq_affinity *desc);void (*del_vqs)(struct virtio_device *);u64 (*get_features)(struct virtio_device *vdev);@@ -206,7 +209,7 @@ struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev,const char *names[] = { n };struct virtqueue *vq;int err = vdev->config->find_vqs (vdev,1 , &vq, callbacks, names,NULL , -NULL ); +NULL ,NULL );if (err <0 )return ERR_PTR (err);return vq;@@ -218,7 +221,8 @@ int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,const char *const names[], struct irq_affinity *desc) { - return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, NULL, desc); + return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, NULL, +NULL ,desc ); } static inline
include/linux/virtio_config.h int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs, · line 238
Quoted 10 lines
include/linux/virtio_config.h +2
-2@@ -227,8 +231,8 @@ int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs, const char * const names[], const bool *ctx, struct irq_affinity *desc) { - return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, ctx, -desc ); + return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, NULL, +ctx ,desc ); }/**
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 25/32 virtio_pci: support the arg sizes of find_vqs()
In reply to Xuan ZhuoVirtio PCI supports new parameter sizes of find_vqs().
--- drivers/virtio/virtio_pci_common.c | 18 ++++++++++-------- drivers/virtio/virtio_pci_common.h | 1 + drivers/virtio/virtio_pci_legacy.c | 6 +++++- drivers/virtio/virtio_pci_modern.c | 10 +++++++--- 4 files changed, 23 insertions(+), 12 deletions(-)
drivers/virtio/virtio_pci_common.c +10 -8
@@ -208,6 +208,7 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,static struct virtqueue *vp_setup_vq (struct virtio_device *vdev,unsigned index,void (*callback)(struct virtqueue *vq),const char *name, +u32 size,bool ctx,u16 msix_vec) {
@@ -220,7 +221,7 @@ static struct virtqueue *vp_setup_vq(struct virtio_device *vdev, unsigned index,if (!info)return ERR_PTR (-ENOMEM ); - vq = vp_dev->setup_vq (vp_dev, info, index, callback, name, ctx, + vq = vp_dev->setup_vq (vp_dev, info, index, callback, name, size, ctx, msix_vec);if (IS_ERR (vq)) goto out_info;
@@ -314,7 +315,7 @@ void vp_del_vqs(struct virtio_device *vdev)static int vp_find_vqs_msix (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],bool per_vq_vectors, +const char *const names[],u32 sizes[],bool per_vq_vectors,const bool *ctx,struct irq_affinity *desc) {
@@ -357,8 +358,8 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,else msix_vec =VP_MSIX_VQ_VECTOR ; vqs[i] =vp_setup_vq (vdev, queue_idx++, callbacks[i], names[i], - ctx ? ctx[i] : false, - msix_vec); + sizes ? sizes[i] :0 , + ctx ? ctx[i] : false, msix_vec);if (IS_ERR (vqs[i])) { err =PTR_ERR (vqs[i]); goto error_find;
@@ -388,7 +389,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,static int vp_find_vqs_intx (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx) +const char *const names[],u32 sizes[],const bool *ctx) {struct virtio_pci_device *vp_dev =to_vp_device (vdev);int i, err, queue_idx =0 ;
@@ -410,6 +411,7 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,continue ; } vqs[i] =vp_setup_vq (vdev, queue_idx++, callbacks[i], names[i], + sizes ? sizes[i] :0 , ctx ? ctx[i] : false,VIRTIO_MSI_NO_VECTOR );if (IS_ERR (vqs[i])) {
@@ -433,15 +435,15 @@ int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,int err;/* Try MSI-X with one vector per queue. */ - err =vp_find_vqs_msix (vdev, nvqs, vqs, callbacks, names, true, ctx, desc); + err =vp_find_vqs_msix (vdev, nvqs, vqs, callbacks, names, sizes, true, ctx, desc);if (!err)return 0 ;/* Fallback: MSI-X with one vector for config, one shared for queues. */ - err =vp_find_vqs_msix (vdev, nvqs, vqs, callbacks, names, false, ctx, desc); + err =vp_find_vqs_msix (vdev, nvqs, vqs, callbacks, names, sizes, false, ctx, desc);if (!err)return 0 ;/* Finally fall back to regular interrupts. */ -return vp_find_vqs_intx (vdev, nvqs, vqs, callbacks, names, ctx); +return vp_find_vqs_intx (vdev, nvqs, vqs, callbacks, names, sizes, ctx); }const char *vp_bus_name (struct virtio_device *vdev)
drivers/virtio/virtio_pci_common.h +1 -0
@@ -81,6 +81,7 @@ struct virtio_pci_device {unsigned idx, void (*callback)(struct virtqueue *vq), const char *name, + u32 size, bool ctx, u16 msix_vec);void (*del_vq)(struct virtio_pci_vq_info *info);
drivers/virtio/virtio_pci_legacy.c +5 -1
@@ -112,6 +112,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,unsigned index, void (*callback)(struct virtqueue *vq), const char *name, + u32 size, bool ctx, u16 msix_vec) {
@@ -125,10 +126,13 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!num ||vp_legacy_get_queue_enable (&vp_dev->ldev, index))return ERR_PTR (-ENOENT ); +if (!size || size > num) + size = num; + info->msix_vector = msix_vec;/* create the vring */ - vq =vring_create_virtqueue (index, num, + vq =vring_create_virtqueue (index, size,VIRTIO_PCI_VRING_ALIGN , &vp_dev->vdev, true, false, ctx, vp_notify, callback, name);
drivers/virtio/virtio_pci_modern.c +7 -3
@@ -289,6 +289,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,unsigned index, void (*callback)(struct virtqueue *vq), const char *name, + u32 size, bool ctx, u16 msix_vec) {
@@ -306,15 +307,18 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!num ||vp_modern_get_queue_enable (mdev, index))return ERR_PTR (-ENOENT ); -if (num & (num -1 )) { -dev_warn (&vp_dev->pci_dev->dev,"bad queue size %u" , num); +if (!size || size > num) + size = num; + +if (size & (size -1 )) { +dev_warn (&vp_dev->pci_dev->dev,"bad queue size %u" , size);return ERR_PTR (-EINVAL ); } info->msix_vector = msix_vec;/* create the vring */ - vq =vring_create_virtqueue (index, num, + vq =vring_create_virtqueue (index, size,SMP_CACHE_BYTES , &vp_dev->vdev, true, true, ctx, vp_notify, callback, name);
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 25/32] virtio_pci: support the arg sizes of find_vqs()
Quoted 3 lines · Xuan Zhuo
Virtio PCI supports new parameter sizes of
find_vqs().Signed-off-by Xuan Zhuo <[email protected]>
Quoted 147 lines
--- drivers/virtio/virtio_pci_common.c | 18 ++++++++++-------- drivers/virtio/virtio_pci_common.h | 1 + drivers/virtio/virtio_pci_legacy.c | 6 +++++- drivers/virtio/virtio_pci_modern.c | 10 +++++++--- 4 files changed, 23 insertions(+), 12 deletions(-)drivers/virtio/virtio_pci_common.c +10
-8@@ -208,6 +208,7 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,static struct virtqueue *vp_setup_vq (struct virtio_device *vdev,unsigned index,void (*callback)(struct virtqueue *vq),const char *name, +u32 size,bool ctx,u16 msix_vec) {@@ -220,7 +221,7 @@ static struct virtqueue *vp_setup_vq(struct virtio_device *vdev, unsigned index,if (!info)return ERR_PTR (-ENOMEM ); - vq = vp_dev->setup_vq (vp_dev, info, index, callback, name, ctx, + vq = vp_dev->setup_vq (vp_dev, info, index, callback, name, size, ctx, msix_vec);if (IS_ERR (vq)) goto out_info;@@ -314,7 +315,7 @@ void vp_del_vqs(struct virtio_device *vdev)static int vp_find_vqs_msix (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],bool per_vq_vectors, +const char *const names[],u32 sizes[],bool per_vq_vectors,const bool *ctx,struct irq_affinity *desc) {@@ -357,8 +358,8 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,else msix_vec =VP_MSIX_VQ_VECTOR ; vqs[i] =vp_setup_vq (vdev, queue_idx++, callbacks[i], names[i], - ctx ? ctx[i] : false, - msix_vec); + sizes ? sizes[i] :0 , + ctx ? ctx[i] : false, msix_vec);if (IS_ERR (vqs[i])) { err =PTR_ERR (vqs[i]); goto error_find;@@ -388,7 +389,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,static int vp_find_vqs_intx (struct virtio_device *vdev,unsigned nvqs,struct virtqueue *vqs[],vq_callback_t *callbacks[], -const char *const names[],const bool *ctx) +const char *const names[],u32 sizes[],const bool *ctx) {struct virtio_pci_device *vp_dev =to_vp_device (vdev);int i, err, queue_idx =0 ;@@ -410,6 +411,7 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,continue ; } vqs[i] =vp_setup_vq (vdev, queue_idx++, callbacks[i], names[i], + sizes ? sizes[i] :0 , ctx ? ctx[i] : false,VIRTIO_MSI_NO_VECTOR );if (IS_ERR (vqs[i])) {@@ -433,15 +435,15 @@ int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,int err;/* Try MSI-X with one vector per queue. */ - err =vp_find_vqs_msix (vdev, nvqs, vqs, callbacks, names, true, ctx, desc); + err =vp_find_vqs_msix (vdev, nvqs, vqs, callbacks, names, sizes, true, ctx, desc);if (!err)return 0 ;/* Fallback: MSI-X with one vector for config, one shared for queues. */ - err =vp_find_vqs_msix (vdev, nvqs, vqs, callbacks, names, false, ctx, desc); + err =vp_find_vqs_msix (vdev, nvqs, vqs, callbacks, names, sizes, false, ctx, desc);if (!err)return 0 ;/* Finally fall back to regular interrupts. */ -return vp_find_vqs_intx (vdev, nvqs, vqs, callbacks, names, ctx); +return vp_find_vqs_intx (vdev, nvqs, vqs, callbacks, names, sizes, ctx); }const char *vp_bus_name (struct virtio_device *vdev)drivers/virtio/virtio_pci_common.h +1
-0@@ -81,6 +81,7 @@ struct virtio_pci_device {unsigned idx, void (*callback)(struct virtqueue *vq), const char *name, + u32 size, bool ctx, u16 msix_vec);void (*del_vq)(struct virtio_pci_vq_info *info);drivers/virtio/virtio_pci_legacy.c +5
-1@@ -112,6 +112,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,unsigned index, void (*callback)(struct virtqueue *vq), const char *name, + u32 size, bool ctx, u16 msix_vec) {@@ -125,10 +126,13 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!num ||vp_legacy_get_queue_enable (&vp_dev->ldev, index))return ERR_PTR (-ENOENT ); +if (!size || size > num) + size = num; + info->msix_vector = msix_vec;/* create the vring */ - vq =vring_create_virtqueue (index, num, + vq =vring_create_virtqueue (index, size,VIRTIO_PCI_VRING_ALIGN , &vp_dev->vdev, true, false, ctx, vp_notify, callback, name);drivers/virtio/virtio_pci_modern.c +6
-2@@ -289,6 +289,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,unsigned index, void (*callback)(struct virtqueue *vq), const char *name, + u32 size, bool ctx, u16 msix_vec) {@@ -306,15 +307,18 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (!num ||vp_modern_get_queue_enable (mdev, index))return ERR_PTR (-ENOENT ); -if (num & (num -1 )) { -dev_warn (&vp_dev->pci_dev->dev,"bad queue size %u" , num); +if (!size || size > num) + size = num; + +if (size & (size -1 )) { +dev_warn (&vp_dev->pci_dev->dev,"bad queue size %u" , size);return ERR_PTR (-EINVAL );
drivers/virtio/virtio_pci_modern.c static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, · line 324
Quoted 10 lines
drivers/virtio/virtio_pci_modern.c +1
-1} info->msix_vector = msix_vec;/* create the vring */ - vq =vring_create_virtqueue (index, num, + vq =vring_create_virtqueue (index, size,SMP_CACHE_BYTES , &vp_dev->vdev, true, true, ctx, vp_notify, callback, name);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Xuan Zhuo
reviewerPATCH v9 26/32 virtio_mmio: support the arg sizes of find_vqs()
In reply to Xuan ZhuoVirtio MMIO support the new parameter sizes of find_vqs().
--- drivers/virtio/virtio_mmio.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/virtio/virtio_mmio.c +6 -2
@@ -347,7 +347,7 @@ static void vm_del_vqs(struct virtio_device *vdev)static struct virtqueue *vm_setup_vq (struct virtio_device *vdev,unsigned index,void (*callback)(struct virtqueue *vq), -const char *name,bool ctx) +const char *name,u32 size,bool ctx) {struct virtio_mmio_device *vm_dev =to_virtio_mmio_device (vdev);struct virtio_mmio_vq_info *info;
@@ -382,8 +382,11 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index, goto error_new_virtqueue; } +if (!size || size > num) + size = num; +/* Create the vring */ - vq =vring_create_virtqueue (index, num,VIRTIO_MMIO_VRING_ALIGN , vdev, + vq =vring_create_virtqueue (index, size,VIRTIO_MMIO_VRING_ALIGN , vdev, true, true, ctx, vm_notify, callback, name);if (!vq) { err = -ENOMEM ;
@@ -484,6 +487,7 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs, } vqs[i] =vm_setup_vq (vdev, queue_idx++, callbacks[i], names[i], + sizes ? sizes[i] :0 , ctx ? ctx[i] : false);if (IS_ERR (vqs[i])) {vm_del_vqs (vdev);
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 26/32] virtio_mmio: support the arg sizes of find_vqs()
Quoted 4 lines · Xuan Zhuo
Virtio MMIO support the new parameter sizes of
find_vqs().Signed-off-by Xuan Zhuo <[email protected]>---
Quoted 30 lines
drivers/virtio/virtio_mmio.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/virtio/virtio_mmio.c +5
-2@@ -347,7 +347,7 @@ static void vm_del_vqs(struct virtio_device *vdev)static struct virtqueue *vm_setup_vq (struct virtio_device *vdev,unsigned index,void (*callback)(struct virtqueue *vq), -const char *name,bool ctx) +const char *name,u32 size,bool ctx) {struct virtio_mmio_device *vm_dev =to_virtio_mmio_device (vdev);struct virtio_mmio_vq_info *info;@@ -382,8 +382,11 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index, goto error_new_virtqueue; } +if (!size || size > num) + size = num; +/* Create the vring */ - vq =vring_create_virtqueue (index, num,VIRTIO_MMIO_VRING_ALIGN , vdev, + vq =vring_create_virtqueue (index, size,VIRTIO_MMIO_VRING_ALIGN , vdev, true, true, ctx, vm_notify, callback, name);if (!vq) { err = -ENOMEM ;
drivers/virtio/virtio_mmio.c static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs, · line 493
Quoted 7 lines
drivers/virtio/virtio_mmio.c +1
-0@@ -484,6 +487,7 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs, } vqs[i] =vm_setup_vq (vdev, queue_idx++, callbacks[i], names[i], + sizes ? sizes[i] :0 , ctx ? ctx[i] : false);if (IS_ERR (vqs[i])) {vm_del_vqs (vdev);
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 27/32 virtio: add helper virtio_find_vqs_ctx_size()
In reply to Xuan ZhuoIntroduce helper virtio_find_vqs_ctx_size() to call find_vqs and specify the maximum size of each vq ring.
--- include/linux/virtio_config.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/linux/virtio_config.h +12 -0
@@ -235,6 +235,18 @@ int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs, ctx, desc); } +static inline +int virtio_find_vqs_ctx_size (struct virtio_device *vdev,u32 nvqs, +struct virtqueue *vqs[], +vq_callback_t *callbacks[], +const char *const names[], +u32 sizes[], +const bool *ctx,struct irq_affinity *desc) +{ +return vdev->config->find_vqs (vdev, nvqs, vqs, callbacks, names, sizes, + ctx, desc); +} +/** * virtio_device_ready - enable vq use in probe function * @vdev: the device
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 27/32] virtio: add helper virtio_find_vqs_ctx_size()
Quoted 4 lines · Xuan Zhuo
Introduce helper
virtio_find_vqs_ctx_size()to callfind_vqsand specify the maximum size of each vq ring.Signed-off-by Xuan Zhuo <[email protected]>
Quoted 17 lines
--- include/linux/virtio_config.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/linux/virtio_config.h +5
-0@@ -235,6 +235,18 @@ int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs, ctx, desc); } +static inline +int virtio_find_vqs_ctx_size(struct virtio_device *vdev, u32 nvqs, + struct virtqueue *vqs[], + vq_callback_t *callbacks[], + const char * const names[],
include/linux/virtio_config.h int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs, · line 252
Quoted 10 lines
include/linux/virtio_config.h +7
-0+u32 sizes[], + const bool *ctx, struct irq_affinity *desc) +{ + return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, sizes, +ctx ,desc ); +} +/** * virtio_device_ready - enable vq use in probe function * @vdev: the device
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 28/32 virtio_net: set the default max ring size by find_vqs()
In reply to Xuan ZhuoUse virtio_find_vqs_ctx_size() to specify the maximum ring size of tx, rx at the same time.
| rx/tx ring size
-------------------------------------------
speed == UNKNOWN or < 10G| 1024 speed < 40G | 4096 speed >= 40G | 8192
Call virtnet_update_settings() once before calling init_vqs() to update speed.
--- drivers/net/virtio_net.c | 42 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-)
drivers/net/virtio_net.c +38 -4
@@ -2861,6 +2861,29 @@ static unsigned int mergeable_min_buf_len(struct virtnet_info *vi, struct virtqu (unsigned int)GOOD_PACKET_LEN); } +static void virtnet_config_sizes (struct virtnet_info *vi,u32 *sizes) +{ +u32 i, rx_size, tx_size; + +if (vi->speed ==SPEED_UNKNOWN || vi->speed <SPEED_10000 ) { + rx_size =1024 ; + tx_size =1024 ; + + }else if (vi->speed <SPEED_40000 ) { + rx_size =1024 *4 ; + tx_size =1024 *4 ; + + }else { + rx_size =1024 *8 ; + tx_size =1024 *8 ; + } + +for (i =0 ; i < vi->max_queue_pairs; i++) { + sizes[rxq2vq (i)] = rx_size; + sizes[txq2vq (i)] = tx_size; + } +} +static int virtnet_find_vqs (struct virtnet_info *vi) {vq_callback_t **callbacks;
@@ -2868,6 +2891,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)int ret = -ENOMEM ;int i, total_vqs;const char **names; +u32 *sizes;bool *ctx;/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
@@ -2895,10 +2919,15 @@ static int virtnet_find_vqs(struct virtnet_info *vi) ctx =NULL ; } + sizes =kmalloc_array (total_vqs,sizeof (*sizes),GFP_KERNEL ); +if (!sizes) + goto err_sizes; +/* Parameters for control virtqueue, if any */ if (vi->has_cvq) { callbacks[total_vqs -1 ] =NULL ; names[total_vqs -1 ] ="control" ; + sizes[total_vqs -1 ] =64 ; }/* Allocate/initialize parameters for send/receive virtqueues */
@@ -2913,8 +2942,10 @@ static int virtnet_find_vqs(struct virtnet_info *vi) ctx[rxq2vq (i)] = true; } - ret =virtio_find_vqs_ctx (vi->vdev, total_vqs, vqs, callbacks, - names, ctx,NULL ); +virtnet_config_sizes (vi, sizes); + + ret =virtio_find_vqs_ctx_size (vi->vdev, total_vqs, vqs, callbacks, + names, sizes, ctx,NULL );if (ret) goto err_find;
@@ -2934,6 +2965,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi) err_find: +kfree (sizes); +err_sizes:kfree (ctx); err_ctx:kfree (names);
@@ -3252,6 +3285,9 @@ static int virtnet_probe(struct virtio_device *vdev) vi->curr_queue_pairs =num_online_cpus (); vi->max_queue_pairs = max_queue_pairs; +virtnet_init_settings (dev); +virtnet_update_settings (vi); +/* Allocate/initialize the rx/tx queues, and invoke find_vqs */ err =init_vqs (vi);if (err)
@@ -3264,8 +3300,6 @@ static int virtnet_probe(struct virtio_device *vdev)netif_set_real_num_tx_queues (dev, vi->curr_queue_pairs);netif_set_real_num_rx_queues (dev, vi->curr_queue_pairs); -virtnet_init_settings (dev); -if (virtio_has_feature (vdev,VIRTIO_NET_F_STANDBY )) { vi->failover =net_failover_create (vi->dev);if (IS_ERR (vi->failover)) {
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 28/32] virtio_net: set the default max ring size by find_vqs()
Quoted 9 lines · Xuan Zhuo
Use
virtio_find_vqs_ctx_size()to specify the maximum ring size of tx, rx at the same time.| rx/tx ring size
-------------------------------------------speed == UNKNOWN or < 10G| 1024 speed < 40G | 4096 speed >= 40G | 8192
Quoted 5 lines
Call
virtnet_update_settings()once before callinginit_vqs()to update speed.Signed-off-by Xuan Zhuo <[email protected]>---
Quoted 94 lines
drivers/net/virtio_net.c | 42 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-)drivers/net/virtio_net.c +38
-2@@ -2861,6 +2861,29 @@ static unsigned int mergeable_min_buf_len(struct virtnet_info *vi, struct virtqu (unsigned int)GOOD_PACKET_LEN); } +static void virtnet_config_sizes (struct virtnet_info *vi,u32 *sizes) +{ +u32 i, rx_size, tx_size; + +if (vi->speed ==SPEED_UNKNOWN || vi->speed <SPEED_10000 ) { + rx_size =1024 ; + tx_size =1024 ; + + }else if (vi->speed <SPEED_40000 ) { + rx_size =1024 *4 ; + tx_size =1024 *4 ; + + }else { + rx_size =1024 *8 ; + tx_size =1024 *8 ; + } + +for (i =0 ; i < vi->max_queue_pairs; i++) { + sizes[rxq2vq (i)] = rx_size; + sizes[txq2vq (i)] = tx_size; + } +} +static int virtnet_find_vqs (struct virtnet_info *vi) {vq_callback_t **callbacks;@@ -2868,6 +2891,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)int ret = -ENOMEM ;int i, total_vqs;const char **names; +u32 *sizes;bool *ctx;/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by @@ -2895,10 +2919,15 @@ static int virtnet_find_vqs(struct virtnet_info *vi) ctx =NULL ; } + sizes =kmalloc_array (total_vqs,sizeof (*sizes),GFP_KERNEL ); +if (!sizes) + goto err_sizes; +/* Parameters for control virtqueue, if any */ if (vi->has_cvq) { callbacks[total_vqs -1 ] =NULL ; names[total_vqs -1 ] ="control" ; + sizes[total_vqs -1 ] =64 ; }/* Allocate/initialize parameters for send/receive virtqueues */ @@ -2913,8 +2942,10 @@ static int virtnet_find_vqs(struct virtnet_info *vi) ctx[rxq2vq (i)] = true; } - ret =virtio_find_vqs_ctx (vi->vdev, total_vqs, vqs, callbacks, - names, ctx,NULL ); +virtnet_config_sizes (vi, sizes); + + ret =virtio_find_vqs_ctx_size (vi->vdev, total_vqs, vqs, callbacks, + names, sizes, ctx,NULL );if (ret) goto err_find;@@ -2934,6 +2965,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi) err_find: +kfree (sizes); +err_sizes:kfree (ctx); err_ctx:kfree (names);@@ -3252,6 +3285,9 @@ static int virtnet_probe(struct virtio_device *vdev) vi->curr_queue_pairs =num_online_cpus (); vi->max_queue_pairs = max_queue_pairs; +virtnet_init_settings (dev); +virtnet_update_settings (vi); +/* Allocate/initialize the rx/tx queues, and invoke find_vqs */ err =init_vqs (vi);if (err)
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3305
Quoted 8 lines
drivers/net/virtio_net.c +0
-2@@ -3264,8 +3300,6 @@ static int virtnet_probe(struct virtio_device *vdev)netif_set_real_num_tx_queues (dev, vi->curr_queue_pairs);netif_set_real_num_rx_queues (dev, vi->curr_queue_pairs); -virtnet_init_settings (dev); -if (virtio_has_feature (vdev,VIRTIO_NET_F_STANDBY )) { vi->failover =net_failover_create (vi->dev);if (IS_ERR (vi->failover)) {
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 29/32 virtio_net: get ringparam by virtqueue_get_vring_max_size()
In reply to Xuan ZhuoUse virtqueue_get_vring_max_size() in virtnet_get_ringparam() to set tx,rx_max_pending.
--- drivers/net/virtio_net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/virtio_net.c +4 -4
@@ -2177,10 +2177,10 @@ static void virtnet_get_ringparam(struct net_device *dev, {struct virtnet_info *vi =netdev_priv (dev); - ring->rx_max_pending =virtqueue_get_vring_size (vi->rq[0 ].vq); - ring->tx_max_pending =virtqueue_get_vring_size (vi->sq[0 ].vq); - ring->rx_pending = ring->rx_max_pending; - ring->tx_pending = ring->tx_max_pending; + ring->rx_max_pending =virtqueue_get_vring_max_size (vi->rq[0 ].vq); + ring->tx_max_pending =virtqueue_get_vring_max_size (vi->sq[0 ].vq); + ring->rx_pending =virtqueue_get_vring_size (vi->rq[0 ].vq); + ring->tx_pending =virtqueue_get_vring_size (vi->sq[0 ].vq); }
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 29/32] virtio_net: get ringparam by virtqueue_get_vring_max_size()
Quoted 5 lines · Xuan Zhuo
Use
virtqueue_get_vring_max_size()invirtnet_get_ringparam()to set tx,rx_max_pending.Signed-off-by Xuan Zhuo <[email protected]>---
Quoted 12 lines
drivers/net/virtio_net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/net/virtio_net.c +0
-1@@ -2177,10 +2177,10 @@ static void virtnet_get_ringparam(struct net_device *dev, {struct virtnet_info *vi =netdev_priv (dev); - ring->rx_max_pending =virtqueue_get_vring_size (vi->rq[0 ].vq);
drivers/net/virtio_net.c static void virtnet_get_ringparam(struct net_device *dev, · line 2186
Quoted 10 lines
drivers/net/virtio_net.c +4
-3- ring->tx_max_pending =virtqueue_get_vring_size (vi->sq[0 ].vq); - ring->rx_pending = ring->rx_max_pending; - ring->tx_pending = ring->tx_max_pending; + ring->rx_max_pending =virtqueue_get_vring_max_size (vi->rq[0 ].vq); + ring->tx_max_pending =virtqueue_get_vring_max_size (vi->sq[0 ].vq); + ring->rx_pending =virtqueue_get_vring_size (vi->rq[0 ].vq); + ring->tx_pending =virtqueue_get_vring_size (vi->sq[0 ].vq); }
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 30/32 virtio_net: split free_unused_bufs()
In reply to Xuan ZhuoThis patch separates two functions for freeing sq buf and rq buf from free_unused_bufs().
When supporting the enable/disable tx/rq queue in the future, it is necessary to support separate recovery of a sq buf or a rq buf.
--- drivers/net/virtio_net.c | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-)
drivers/net/virtio_net.c +25 -16
@@ -2804,6 +2804,27 @@ static void free_receive_page_frags(struct virtnet_info *vi)put_page (vi->rq[i].alloc_frag.page); } +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf) +{ +if (!is_xdp_frame (buf)) +dev_kfree_skb (buf); +else +xdp_return_frame (ptr_to_xdp (buf)); +} + +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf) +{ +struct virtnet_info *vi = vq->vdev->priv; +int i =vq2rxq (vq); + +if (vi->mergeable_rx_bufs) +put_page (virt_to_head_page (buf)); +else if (vi->big_packets) +give_pages (&vi->rq[i], buf); +else +put_page (virt_to_head_page (buf)); +} +static void free_unused_bufs (struct virtnet_info *vi) {void *buf;
@@ -2811,26 +2832,14 @@ static void free_unused_bufs(struct virtnet_info *vi)for (i =0 ; i < vi->max_queue_pairs; i++) {struct virtqueue *vq = vi->sq[i].vq; -while ((buf =virtqueue_detach_unused_buf (vq)) !=NULL ) { -if (!is_xdp_frame (buf)) -dev_kfree_skb (buf); -else -xdp_return_frame (ptr_to_xdp (buf)); - } +while ((buf =virtqueue_detach_unused_buf (vq)) !=NULL ) +virtnet_sq_free_unused_buf (vq, buf); }for (i =0 ; i < vi->max_queue_pairs; i++) {struct virtqueue *vq = vi->rq[i].vq; - -while ((buf =virtqueue_detach_unused_buf (vq)) !=NULL ) { -if (vi->mergeable_rx_bufs) { -put_page (virt_to_head_page (buf)); - }else if (vi->big_packets) { -give_pages (&vi->rq[i], buf); - }else { -put_page (virt_to_head_page (buf)); - } - } +while ((buf =virtqueue_detach_unused_buf (vq)) !=NULL ) +virtnet_rq_free_unused_buf (vq, buf); } }
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 31/32 virtio_net: support rx/tx queue resize
In reply to Xuan ZhuoThis patch implements the resize function of the rx, tx queues. Based on this function, it is possible to modify the ring num of the queue.
There may be an exception during the resize process, the resize may fail, or the vq can no longer be used. Either way, we must execute napi_enable(). Because napi_disable is similar to a lock, napi_enable must be called after calling napi_disable.
--- drivers/net/virtio_net.c | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
drivers/net/virtio_net.c +81 -0
@@ -251,6 +251,9 @@ struct padded_vnet_hdr {char padding[4 ]; }; +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf); +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf); +static bool is_xdp_frame (void *ptr) {return (unsigned long )ptr &VIRTIO_XDP_FLAG ;
@@ -1369,6 +1372,15 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) {napi_enable (napi); +/* Check if vq is in reset state. The normal reset/resize process will +* be protected by napi. However, the protection of napi is only enabled +* during the operation, and the protection of napi will end after the +* operation is completed. If re-enable fails during the process, vq +* will remain unavailable with reset state. +*/ +if (vq->reset) +return ; +/* If all buffers were filled by other side before we napi_enabled, we * won't get another interrupt, so process any outstanding packets now. * Call local_bh_enable after to trigger softIRQ processing.
@@ -1413,6 +1425,15 @@ static void refill_work(struct work_struct *work)struct receive_queue *rq = &vi->rq[i];napi_disable (&rq->napi); + +/* Check if vq is in reset state. See more in +* virtnet_napi_enable() +*/ +if (rq->vq->reset) { +virtnet_napi_enable (rq->vq, &rq->napi); +continue ; + } + still_empty = !try_fill_recv (vi, rq,GFP_KERNEL );virtnet_napi_enable (rq->vq, &rq->napi);
@@ -1523,6 +1544,10 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)if (!sq->napi.weight ||is_xdp_raw_buffer_queue (vi, index))return ; +/* Check if vq is in reset state. See more in virtnet_napi_enable() */ +if (sq->vq->reset) +return ; +if (__netif_tx_trylock (txq)) { do { virtqueue_disable_cb(sq->vq);
@@ -1769,6 +1794,62 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +static int virtnet_rx_resize (struct virtnet_info *vi, +struct receive_queue *rq,u32 ring_num) +{ +int err; + +napi_disable (&rq->napi); + + err =virtqueue_resize (rq->vq, ring_num, virtnet_rq_free_unused_buf); +if (err) + goto err; + +if (!try_fill_recv (vi, rq,GFP_KERNEL )) +schedule_delayed_work (&vi->refill,0 ); + +virtnet_napi_enable (rq->vq, &rq->napi); +return 0 ; + +err: +netdev_err (vi->dev, +"reset rx reset vq fail: rx queue index: %td err: %d\n" , + rq - vi->rq, err); +virtnet_napi_enable (rq->vq, &rq->napi); +return err; +} + +static int virtnet_tx_resize (struct virtnet_info *vi, +struct send_queue *sq,u32 ring_num) +{ +struct netdev_queue *txq; +int err, qindex; + + qindex = sq - vi->sq; + +virtnet_napi_tx_disable (&sq->napi); + + txq =netdev_get_tx_queue (vi->dev, qindex); +__netif_tx_lock_bh (txq); +netif_stop_subqueue (vi->dev, qindex); +__netif_tx_unlock_bh (txq); + + err =virtqueue_resize (sq->vq, ring_num, virtnet_sq_free_unused_buf); +if (err) + goto err; + +netif_start_subqueue (vi->dev, qindex); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return 0 ; + +err: +netdev_err (vi->dev, +"reset tx reset vq fail: tx queue index: %td err: %d\n" , + sq - vi->sq, err); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return err; +} +/* * Send command via the control virtqueue and check status. Commands * supported by the hypervisor, as indicated by feature bits, should
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 31/32] virtio_net: support rx/tx queue resize
Quoted 30 lines · Xuan Zhuo
This patch implements the resize function of the rx, tx queues. Based on this function, it is possible to modify the ring num of the queue.
There may be an exception during the resize process, the resize may fail, or the vq can no longer be used. Either way, we must execute
napi_enable(). Becausenapi_disableis similar to a lock,napi_enablemust be called after callingnapi_disable.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/virtio_net.c | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)drivers/net/virtio_net.c +3
-0@@ -251,6 +251,9 @@ struct padded_vnet_hdr {char padding[4 ]; }; +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf); +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf); +static bool is_xdp_frame (void *ptr) {return (unsigned long )ptr &VIRTIO_XDP_FLAG ;@@ -1369,6 +1372,15 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) {
drivers/net/virtio_net.c static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) · line 1382
Quoted 10 lines
drivers/net/virtio_net.c +8
-0napi_enable (napi); +/* Check if vq is in reset state. The normal reset/resize process will +* be protected by napi. However, the protection of napi is only enabled +* during the operation, and the protection of napi will end after the +* operation is completed. If re-enable fails during the process, vq +* will remain unavailable with reset state. +*/ +if (vq->reset) +return ;
I don't get when could we hit this condition.
Quoted 6 lines
drivers/net/virtio_net.c +1
-0+/* If all buffers were filled by other side before we napi_enabled, we * won't get another interrupt, so process any outstanding packets now. * Call local_bh_enable after to trigger softIRQ processing. @@ -1413,6 +1425,15 @@ static void refill_work(struct work_struct *work)struct receive_queue *rq = &vi->rq[i];
drivers/net/virtio_net.c static void refill_work(struct work_struct *work) · line 1435
Quoted 10 lines
drivers/net/virtio_net.c +8
-0napi_disable (&rq->napi); + +/* Check if vq is in reset state. See more in +* virtnet_napi_enable() +*/ +if (rq->vq->reset) { +virtnet_napi_enable (rq->vq, &rq->napi); +continue ; + }
Can we do something similar in virtnet_close() by canceling the work?
drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct receive_queue *rq) · line 1549
Quoted 11 lines
drivers/net/virtio_net.c +4
-0+ still_empty = !try_fill_recv (vi, rq,GFP_KERNEL );virtnet_napi_enable (rq->vq, &rq->napi);@@ -1523,6 +1544,10 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)if (!sq->napi.weight ||is_xdp_raw_buffer_queue (vi, index))return ; +/* Check if vq is in reset state. See more in virtnet_napi_enable() */ +if (sq->vq->reset) +return ;
We've disabled TX napi, any chance we can still hit this?
Quoted 47 lines
drivers/net/virtio_net.c +40
-0+if (__netif_tx_trylock (txq)) { do { virtqueue_disable_cb(sq->vq);@@ -1769,6 +1794,62 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +static int virtnet_rx_resize (struct virtnet_info *vi, +struct receive_queue *rq,u32 ring_num) +{ +int err; + +napi_disable (&rq->napi); + + err =virtqueue_resize (rq->vq, ring_num, virtnet_rq_free_unused_buf); +if (err) + goto err; + +if (!try_fill_recv (vi, rq,GFP_KERNEL )) +schedule_delayed_work (&vi->refill,0 ); + +virtnet_napi_enable (rq->vq, &rq->napi); +return 0 ; + +err: +netdev_err (vi->dev, +"reset rx reset vq fail: rx queue index: %td err: %d\n" , + rq - vi->rq, err); +virtnet_napi_enable (rq->vq, &rq->napi); +return err; +} + +static int virtnet_tx_resize (struct virtnet_info *vi, +struct send_queue *sq,u32 ring_num) +{ +struct netdev_queue *txq; +int err, qindex; + + qindex = sq - vi->sq; + +virtnet_napi_tx_disable (&sq->napi); + + txq =netdev_get_tx_queue (vi->dev, qindex); +__netif_tx_lock_bh (txq); +netif_stop_subqueue (vi->dev, qindex); +__netif_tx_unlock_bh (txq);
drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1845
Quoted 10 lines
drivers/net/virtio_net.c +10
-0+ + err =virtqueue_resize (sq->vq, ring_num, virtnet_sq_free_unused_buf); +if (err) + goto err; + +netif_start_subqueue (vi->dev, qindex); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return 0 ; + +err:
I guess we can still start the queue in this case? (Since we don't change the queue if resize fails).
drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1855
Quoted 10 lines
drivers/net/virtio_net.c +7
-0+netdev_err (vi->dev, +"reset tx reset vq fail: tx queue index: %td err: %d\n" , + sq - vi->sq, err); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return err; +} +/* * Send command via the control virtqueue and check status. Commands * supported by the hypervisor, as indicated by feature bits, should
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 31/32] virtio_net: support rx/tx queue resize
Quoted 34 lines · Jason Wang
Quoted 32 lines · Xuan Zhuo
This patch implements the resize function of the rx, tx queues. Based on this function, it is possible to modify the ring num of the queue.
There may be an exception during the resize process, the resize may fail, or the vq can no longer be used. Either way, we must execute
napi_enable(). Becausenapi_disableis similar to a lock,napi_enablemust be called after callingnapi_disable.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/virtio_net.c | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)drivers/net/virtio_net.c +3
-0@@ -251,6 +251,9 @@ struct padded_vnet_hdr {char padding[4 ]; }; +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf); +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf); +static bool is_xdp_frame (void *ptr) {return (unsigned long )ptr &VIRTIO_XDP_FLAG ;@@ -1369,6 +1372,15 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) {napi_enable (napi);
Quoted 11 lines
drivers/net/virtio_net.c static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) · line 1382
Quoted 8 lines
drivers/net/virtio_net.c +8
-0+/* Check if vq is in reset state. The normal reset/resize process will +* be protected by napi. However, the protection of napi is only enabled +* during the operation, and the protection of napi will end after the +* operation is completed. If re-enable fails during the process, vq +* will remain unavailable with reset state. +*/ +if (vq->reset) +return ;I don't get when could we hit this condition.
In patch 23, the code to implement re-enable vq is as follows:
+static int vp_modern_enable_reset_vq(struct virtqueue *vq) +{
+ struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
+ struct virtio_pci_modern_device *mdev = &vp_dev->mdev;
+ struct virtio_pci_vq_info *info;
+ unsigned long flags, index;
+ int err;
+
+ if (!vq->reset)
+ return -EBUSY;
+
+ index = vq->index;
+ info = vp_dev->vqs[index];
+
+ /* check queue reset status */
+ if (vp_modern_get_queue_reset(mdev, index) != 1)
+ return -EBUSY;
+
+ err = vp_active_vq(vq, info->msix_vector);
+ if (err)
+ return err;
+
+ if (vq->callback) {
+ spin_lock_irqsave(&vp_dev->lock, flags);
+ list_add(&info->node, &vp_dev->virtqueues);
+ spin_unlock_irqrestore(&vp_dev->lock, flags);
+ } else {
+ INIT_LIST_HEAD(&info->node);
+ }
+
+ vp_modern_set_queue_enable(&vp_dev->mdev, index, true);
+
+ if (vp_dev->per_vq_vectors && info->msix_vector != VIRTIO_MSI_NO_VECTOR)
+ enable_irq(pci_irq_vector(vp_dev->pci_dev, info->msix_vector));
+
+ vq->reset = false;
+
+ return 0;
+}
There are three situations where an error will be returned. These are the situations I want to handle.
But I'm rethinking the question, and I feel like you're right, although the hardware setup may fail. We can no longer sync with the hardware. But using it as a normal vq doesn't have any problems.
Quoted 9 lines
Quoted 9 lines
drivers/net/virtio_net.c +1
-0+/* If all buffers were filled by other side before we napi_enabled, we * won't get another interrupt, so process any outstanding packets now. * Call local_bh_enable after to trigger softIRQ processing. @@ -1413,6 +1425,15 @@ static void refill_work(struct work_struct *work)struct receive_queue *rq = &vi->rq[i];
Quoted 12 lines
drivers/net/virtio_net.c static void refill_work(struct work_struct *work) · line 1435
Quoted 9 lines
drivers/net/virtio_net.c +8
-0napi_disable (&rq->napi); + +/* Check if vq is in reset state. See more in +* virtnet_napi_enable() +*/ +if (rq->vq->reset) { +virtnet_napi_enable (rq->vq, &rq->napi); +continue ; + }Can we do something similar in
virtnet_close()by canceling the work?
I think there is no need to cancel the work here, because napi_disable will wait for the napi_enable of the resize. So if the re-enable failed vq is used as a normal vq, this logic can be removed.
Quoted 10 lines
Quoted 10 lines
drivers/net/virtio_net.c +1
-0+ still_empty = !try_fill_recv (vi, rq,GFP_KERNEL );virtnet_napi_enable (rq->vq, &rq->napi);@@ -1523,6 +1544,10 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)if (!sq->napi.weight ||is_xdp_raw_buffer_queue (vi, index))return ;
Quoted 6 lines
drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct receive_queue *rq) · line 1549
Quoted 3 lines
drivers/net/virtio_net.c +3
-0+/* Check if vq is in reset state. See more in virtnet_napi_enable() */ +if (sq->vq->reset) +return ;We've disabled TX napi, any chance we can still hit this?
Same as above.
Quoted 55 lines
Quoted 55 lines
drivers/net/virtio_net.c +46
-0+if (__netif_tx_trylock (txq)) { do { virtqueue_disable_cb(sq->vq);@@ -1769,6 +1794,62 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +static int virtnet_rx_resize (struct virtnet_info *vi, +struct receive_queue *rq,u32 ring_num) +{ +int err; + +napi_disable (&rq->napi); + + err =virtqueue_resize (rq->vq, ring_num, virtnet_rq_free_unused_buf); +if (err) + goto err; + +if (!try_fill_recv (vi, rq,GFP_KERNEL )) +schedule_delayed_work (&vi->refill,0 ); + +virtnet_napi_enable (rq->vq, &rq->napi); +return 0 ; + +err: +netdev_err (vi->dev, +"reset rx reset vq fail: rx queue index: %td err: %d\n" , + rq - vi->rq, err); +virtnet_napi_enable (rq->vq, &rq->napi); +return err; +} + +static int virtnet_tx_resize (struct virtnet_info *vi, +struct send_queue *sq,u32 ring_num) +{ +struct netdev_queue *txq; +int err, qindex; + + qindex = sq - vi->sq; + +virtnet_napi_tx_disable (&sq->napi); + + txq =netdev_get_tx_queue (vi->dev, qindex); +__netif_tx_lock_bh (txq); +netif_stop_subqueue (vi->dev, qindex); +__netif_tx_unlock_bh (txq); + + err =virtqueue_resize (sq->vq, ring_num, virtnet_sq_free_unused_buf); +if (err) + goto err; + +netif_start_subqueue (vi->dev, qindex);
Quoted 8 lines
drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1845
Quoted 4 lines
drivers/net/virtio_net.c +4
-0+virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return 0 ; + +err:I guess we can still start the queue in this case? (Since we don't change the queue if resize fails).
Yes, you are right.
Thanks.
Quoted 13 lines
Quoted 12 lines
drivers/net/virtio_net.c +7
-0+netdev_err (vi->dev, +"reset tx reset vq fail: tx queue index: %td err: %d\n" , + sq - vi->sq, err); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return err; +} +/* * Send command via the control virtqueue and check status. Commands * supported by the hypervisor, as indicated by feature bits, should
Re: [PATCH v9 31/32] virtio_net: support rx/tx queue resize
Quoted 92 lines · Xuan Zhuo
Quoted 34 lines · Jason Wang
Quoted 32 lines · Xuan Zhuo
This patch implements the resize function of the rx, tx queues. Based on this function, it is possible to modify the ring num of the queue.
There may be an exception during the resize process, the resize may fail, or the vq can no longer be used. Either way, we must execute
napi_enable(). Becausenapi_disableis similar to a lock,napi_enablemust be called after callingnapi_disable.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/virtio_net.c | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)drivers/net/virtio_net.c +3
-0@@ -251,6 +251,9 @@ struct padded_vnet_hdr {char padding[4 ]; }; +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf); +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf); +static bool is_xdp_frame (void *ptr) {return (unsigned long )ptr &VIRTIO_XDP_FLAG ;@@ -1369,6 +1372,15 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) {napi_enable (napi);Quoted 11 lines
drivers/net/virtio_net.c static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) · line 1382
Quoted 8 lines
drivers/net/virtio_net.c +8
-0+/* Check if vq is in reset state. The normal reset/resize process will +* be protected by napi. However, the protection of napi is only enabled +* during the operation, and the protection of napi will end after the +* operation is completed. If re-enable fails during the process, vq +* will remain unavailable with reset state. +*/ +if (vq->reset) +return ;I don't get when could we hit this condition.
In patch 23, the code to implement re-enable vq is as follows:
(quoted diff) +39
-0+static int vp_modern_enable_reset_vq(struct virtqueue *vq) +{ + struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev); + struct virtio_pci_modern_device *mdev = &vp_dev->mdev; + struct virtio_pci_vq_info *info; + unsigned long flags, index; + int err; + + if (!vq->reset) + return -EBUSY; + + index = vq->index; + info = vp_dev->vqs[index]; + + /* check queue reset status */ + if (vp_modern_get_queue_reset(mdev, index) != 1) + return -EBUSY; + + err = vp_active_vq(vq, info->msix_vector); + if (err) + return err; + + if (vq->callback) { + spin_lock_irqsave(&vp_dev->lock, flags); + list_add(&info->node, &vp_dev->virtqueues); + spin_unlock_irqrestore(&vp_dev->lock, flags); + } else { + INIT_LIST_HEAD(&info->node); + } + + vp_modern_set_queue_enable(&vp_dev->mdev, index, true); + + if (vp_dev->per_vq_vectors && info->msix_vector != VIRTIO_MSI_NO_VECTOR) + enable_irq(pci_irq_vector(vp_dev->pci_dev, info->msix_vector)); + + vq->reset = false; + + return 0; +}
Quoted 2 lines
There are three situations where an error will be returned. These are the situations I want to handle.
Right, but it looks harmless if we just schedule the NAPI without the check.
Quoted 4 lines
But I'm rethinking the question, and I feel like you're right, although the hardware setup may fail. We can no longer sync with the hardware. But using it as a normal vq doesn't have any problems.
Note that we should make sure the buggy(malicous) device won't crash the codes by changing the queue_reset value at its will.
Quoted 23 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/virtio_net.c +1
-0+/* If all buffers were filled by other side before we napi_enabled, we * won't get another interrupt, so process any outstanding packets now. * Call local_bh_enable after to trigger softIRQ processing. @@ -1413,6 +1425,15 @@ static void refill_work(struct work_struct *work)struct receive_queue *rq = &vi->rq[i];Quoted 12 lines
drivers/net/virtio_net.c static void refill_work(struct work_struct *work) · line 1435
Quoted 9 lines
drivers/net/virtio_net.c +8
-0napi_disable (&rq->napi); + +/* Check if vq is in reset state. See more in +* virtnet_napi_enable() +*/ +if (rq->vq->reset) { +virtnet_napi_enable (rq->vq, &rq->napi); +continue ; + }Can we do something similar in
virtnet_close()by canceling the work?
Quoted 3 lines
I think there is no need to cancel the work here, because
napi_disablewill wait for thenapi_enableof the resize. So if the re-enable failed vq is used as a normal vq, this logic can be removed.
Actually I meant the part of virtnet_rx_resize().
If we don't synchronize with the refill work, it might enable NAPI unexpectedly?
Thanks
Quoted 85 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/virtio_net.c +1
-0+ still_empty = !try_fill_recv (vi, rq,GFP_KERNEL );virtnet_napi_enable (rq->vq, &rq->napi);@@ -1523,6 +1544,10 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)if (!sq->napi.weight ||is_xdp_raw_buffer_queue (vi, index))return ;Quoted 6 lines
drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct receive_queue *rq) · line 1549
Quoted 3 lines
drivers/net/virtio_net.c +3
-0+/* Check if vq is in reset state. See more in virtnet_napi_enable() */ +if (sq->vq->reset) +return ;We've disabled TX napi, any chance we can still hit this?
Same as above.
Quoted 55 lines
Quoted 55 lines
drivers/net/virtio_net.c +46
-0+if (__netif_tx_trylock (txq)) { do { virtqueue_disable_cb(sq->vq);@@ -1769,6 +1794,62 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +static int virtnet_rx_resize (struct virtnet_info *vi, +struct receive_queue *rq,u32 ring_num) +{ +int err; + +napi_disable (&rq->napi); + + err =virtqueue_resize (rq->vq, ring_num, virtnet_rq_free_unused_buf); +if (err) + goto err; + +if (!try_fill_recv (vi, rq,GFP_KERNEL )) +schedule_delayed_work (&vi->refill,0 ); + +virtnet_napi_enable (rq->vq, &rq->napi); +return 0 ; + +err: +netdev_err (vi->dev, +"reset rx reset vq fail: rx queue index: %td err: %d\n" , + rq - vi->rq, err); +virtnet_napi_enable (rq->vq, &rq->napi); +return err; +} + +static int virtnet_tx_resize (struct virtnet_info *vi, +struct send_queue *sq,u32 ring_num) +{ +struct netdev_queue *txq; +int err, qindex; + + qindex = sq - vi->sq; + +virtnet_napi_tx_disable (&sq->napi); + + txq =netdev_get_tx_queue (vi->dev, qindex); +__netif_tx_lock_bh (txq); +netif_stop_subqueue (vi->dev, qindex); +__netif_tx_unlock_bh (txq); + + err =virtqueue_resize (sq->vq, ring_num, virtnet_sq_free_unused_buf); +if (err) + goto err; + +netif_start_subqueue (vi->dev, qindex);Quoted 8 lines
drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1845
Quoted 4 lines
drivers/net/virtio_net.c +4
-0+virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return 0 ; + +err:I guess we can still start the queue in this case? (Since we don't change the queue if resize fails).
Quoted 18 lines
Yes, you are right.
Thanks.
Quoted 13 lines
Quoted 12 lines
drivers/net/virtio_net.c +7
-0+netdev_err (vi->dev, +"reset tx reset vq fail: tx queue index: %td err: %d\n" , + sq - vi->sq, err); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return err; +} +/* * Send command via the control virtqueue and check status. Commands * supported by the hypervisor, as indicated by feature bits, should
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Xuan Zhuo
reviewerRe: [PATCH v9 31/32] virtio_net: support rx/tx queue resize
Quoted 93 lines · Jason Wang
Quoted 92 lines · Xuan Zhuo
Quoted 34 lines · Jason Wang
Quoted 32 lines · Xuan Zhuo
This patch implements the resize function of the rx, tx queues. Based on this function, it is possible to modify the ring num of the queue.
There may be an exception during the resize process, the resize may fail, or the vq can no longer be used. Either way, we must execute
napi_enable(). Becausenapi_disableis similar to a lock,napi_enablemust be called after callingnapi_disable.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/virtio_net.c | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)drivers/net/virtio_net.c +3
-0@@ -251,6 +251,9 @@ struct padded_vnet_hdr {char padding[4 ]; }; +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf); +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf); +static bool is_xdp_frame (void *ptr) {return (unsigned long )ptr &VIRTIO_XDP_FLAG ;@@ -1369,6 +1372,15 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) {napi_enable (napi);Quoted 11 lines
drivers/net/virtio_net.c static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) · line 1382
Quoted 8 lines
drivers/net/virtio_net.c +8
-0+/* Check if vq is in reset state. The normal reset/resize process will +* be protected by napi. However, the protection of napi is only enabled +* during the operation, and the protection of napi will end after the +* operation is completed. If re-enable fails during the process, vq +* will remain unavailable with reset state. +*/ +if (vq->reset) +return ;I don't get when could we hit this condition.
In patch 23, the code to implement re-enable vq is as follows:
(quoted diff) +39
-0+static int vp_modern_enable_reset_vq(struct virtqueue *vq) +{ + struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev); + struct virtio_pci_modern_device *mdev = &vp_dev->mdev; + struct virtio_pci_vq_info *info; + unsigned long flags, index; + int err; + + if (!vq->reset) + return -EBUSY; + + index = vq->index; + info = vp_dev->vqs[index]; + + /* check queue reset status */ + if (vp_modern_get_queue_reset(mdev, index) != 1) + return -EBUSY; + + err = vp_active_vq(vq, info->msix_vector); + if (err) + return err; + + if (vq->callback) { + spin_lock_irqsave(&vp_dev->lock, flags); + list_add(&info->node, &vp_dev->virtqueues); + spin_unlock_irqrestore(&vp_dev->lock, flags); + } else { + INIT_LIST_HEAD(&info->node); + } + + vp_modern_set_queue_enable(&vp_dev->mdev, index, true); + + if (vp_dev->per_vq_vectors && info->msix_vector != VIRTIO_MSI_NO_VECTOR) + enable_irq(pci_irq_vector(vp_dev->pci_dev, info->msix_vector)); + + vq->reset = false; + + return 0; +}
Quoted 4 lines
Quoted 2 lines
There are three situations where an error will be returned. These are the situations I want to handle.
Right, but it looks harmless if we just schedule the NAPI without the check.
Yes.
Quoted 7 lines
Quoted 4 lines
But I'm rethinking the question, and I feel like you're right, although the hardware setup may fail. We can no longer sync with the hardware. But using it as a normal vq doesn't have any problems.
Note that we should make sure the buggy(malicous) device won't crash the codes by changing the
queue_resetvalue at its will.
I will keep an eye on this situation.
Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 10 lines
drivers/net/virtio_net.c +1
-0+/* If all buffers were filled by other side before we napi_enabled, we * won't get another interrupt, so process any outstanding packets now. * Call local_bh_enable after to trigger softIRQ processing. @@ -1413,6 +1425,15 @@ static void refill_work(struct work_struct *work)struct receive_queue *rq = &vi->rq[i];drivers/net/virtio_net.c static void refill_work(struct work_struct *work) · line 1435
Quoted 10 lines
drivers/net/virtio_net.c +8
-0napi_disable (&rq->napi); + +/* Check if vq is in reset state. See more in +* virtnet_napi_enable() +*/ +if (rq->vq->reset) { +virtnet_napi_enable (rq->vq, &rq->napi); +continue ; + }Can we do something similar in
virtnet_close()by canceling the work?
Quoted 7 lines
Quoted 3 lines
I think there is no need to cancel the work here, because
napi_disablewill wait for thenapi_enableof the resize. So if the re-enable failed vq is used as a normal vq, this logic can be removed.Actually I meant the part of
virtnet_rx_resize().If we don't synchronize with the refill work, it might enable NAPI unexpectedly?
I don't think this situation will be encountered, because napi_disable is mutually exclusive, so there will be no unexpected napi enable.
Is there something I misunderstood?
Thanks.
Quoted 107 lines
Thanks
Quoted 103 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/virtio_net.c +1
-0+ still_empty = !try_fill_recv (vi, rq,GFP_KERNEL );virtnet_napi_enable (rq->vq, &rq->napi);@@ -1523,6 +1544,10 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)if (!sq->napi.weight ||is_xdp_raw_buffer_queue (vi, index))return ;Quoted 6 lines
drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct receive_queue *rq) · line 1549
Quoted 3 lines
drivers/net/virtio_net.c +3
-0+/* Check if vq is in reset state. See more in virtnet_napi_enable() */ +if (sq->vq->reset) +return ;We've disabled TX napi, any chance we can still hit this?
Same as above.
Quoted 55 lines
Quoted 55 lines
drivers/net/virtio_net.c +46
-0+if (__netif_tx_trylock (txq)) { do { virtqueue_disable_cb(sq->vq);@@ -1769,6 +1794,62 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +static int virtnet_rx_resize (struct virtnet_info *vi, +struct receive_queue *rq,u32 ring_num) +{ +int err; + +napi_disable (&rq->napi); + + err =virtqueue_resize (rq->vq, ring_num, virtnet_rq_free_unused_buf); +if (err) + goto err; + +if (!try_fill_recv (vi, rq,GFP_KERNEL )) +schedule_delayed_work (&vi->refill,0 ); + +virtnet_napi_enable (rq->vq, &rq->napi); +return 0 ; + +err: +netdev_err (vi->dev, +"reset rx reset vq fail: rx queue index: %td err: %d\n" , + rq - vi->rq, err); +virtnet_napi_enable (rq->vq, &rq->napi); +return err; +} + +static int virtnet_tx_resize (struct virtnet_info *vi, +struct send_queue *sq,u32 ring_num) +{ +struct netdev_queue *txq; +int err, qindex; + + qindex = sq - vi->sq; + +virtnet_napi_tx_disable (&sq->napi); + + txq =netdev_get_tx_queue (vi->dev, qindex); +__netif_tx_lock_bh (txq); +netif_stop_subqueue (vi->dev, qindex); +__netif_tx_unlock_bh (txq); + + err =virtqueue_resize (sq->vq, ring_num, virtnet_sq_free_unused_buf); +if (err) + goto err; + +netif_start_subqueue (vi->dev, qindex);Quoted 8 lines
drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1845
Quoted 4 lines
drivers/net/virtio_net.c +4
-0+virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return 0 ; + +err:I guess we can still start the queue in this case? (Since we don't change the queue if resize fails).
Yes, you are right.
Thanks.
Quoted 13 lines
Quoted 12 lines
drivers/net/virtio_net.c +7
-0+netdev_err (vi->dev, +"reset tx reset vq fail: tx queue index: %td err: %d\n" , + sq - vi->sq, err); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return err; +} +/* * Send command via the control virtqueue and check status. Commands * supported by the hypervisor, as indicated by feature bits, should
Re: [PATCH v9 31/32] virtio_net: support rx/tx queue resize
Quoted 140 lines · Xuan Zhuo
Quoted 93 lines · Jason Wang
Quoted 92 lines · Xuan Zhuo
Quoted 34 lines · Jason Wang
Quoted 32 lines · Xuan Zhuo
This patch implements the resize function of the rx, tx queues. Based on this function, it is possible to modify the ring num of the queue.
There may be an exception during the resize process, the resize may fail, or the vq can no longer be used. Either way, we must execute
napi_enable(). Becausenapi_disableis similar to a lock,napi_enablemust be called after callingnapi_disable.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/virtio_net.c | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)drivers/net/virtio_net.c +3
-0@@ -251,6 +251,9 @@ struct padded_vnet_hdr {char padding[4 ]; }; +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf); +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf); +static bool is_xdp_frame (void *ptr) {return (unsigned long )ptr &VIRTIO_XDP_FLAG ;@@ -1369,6 +1372,15 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) {napi_enable (napi);Quoted 11 lines
drivers/net/virtio_net.c static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) · line 1382
Quoted 8 lines
drivers/net/virtio_net.c +8
-0+/* Check if vq is in reset state. The normal reset/resize process will +* be protected by napi. However, the protection of napi is only enabled +* during the operation, and the protection of napi will end after the +* operation is completed. If re-enable fails during the process, vq +* will remain unavailable with reset state. +*/ +if (vq->reset) +return ;I don't get when could we hit this condition.
In patch 23, the code to implement re-enable vq is as follows:
(quoted diff) +39
-0+static int vp_modern_enable_reset_vq(struct virtqueue *vq) +{ + struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev); + struct virtio_pci_modern_device *mdev = &vp_dev->mdev; + struct virtio_pci_vq_info *info; + unsigned long flags, index; + int err; + + if (!vq->reset) + return -EBUSY; + + index = vq->index; + info = vp_dev->vqs[index]; + + /* check queue reset status */ + if (vp_modern_get_queue_reset(mdev, index) != 1) + return -EBUSY; + + err = vp_active_vq(vq, info->msix_vector); + if (err) + return err; + + if (vq->callback) { + spin_lock_irqsave(&vp_dev->lock, flags); + list_add(&info->node, &vp_dev->virtqueues); + spin_unlock_irqrestore(&vp_dev->lock, flags); + } else { + INIT_LIST_HEAD(&info->node); + } + + vp_modern_set_queue_enable(&vp_dev->mdev, index, true); + + if (vp_dev->per_vq_vectors && info->msix_vector != VIRTIO_MSI_NO_VECTOR) + enable_irq(pci_irq_vector(vp_dev->pci_dev, info->msix_vector)); + + vq->reset = false; + + return 0; +}Quoted 4 lines
Quoted 2 lines
There are three situations where an error will be returned. These are the situations I want to handle.
Right, but it looks harmless if we just schedule the NAPI without the check.
Yes.
Quoted 7 lines
Quoted 4 lines
But I'm rethinking the question, and I feel like you're right, although the hardware setup may fail. We can no longer sync with the hardware. But using it as a normal vq doesn't have any problems.
Note that we should make sure the buggy(malicous) device won't crash the codes by changing the
queue_resetvalue at its will.I will keep an eye on this situation.
Quoted 28 lines
Quoted 27 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/virtio_net.c +1
-0+/* If all buffers were filled by other side before we napi_enabled, we * won't get another interrupt, so process any outstanding packets now. * Call local_bh_enable after to trigger softIRQ processing. @@ -1413,6 +1425,15 @@ static void refill_work(struct work_struct *work)struct receive_queue *rq = &vi->rq[i];Quoted 12 lines
drivers/net/virtio_net.c static void refill_work(struct work_struct *work) · line 1435
Quoted 9 lines
drivers/net/virtio_net.c +8
-0napi_disable (&rq->napi); + +/* Check if vq is in reset state. See more in +* virtnet_napi_enable() +*/ +if (rq->vq->reset) { +virtnet_napi_enable (rq->vq, &rq->napi); +continue ; + }Can we do something similar in
virtnet_close()by canceling the work?I think there is no need to cancel the work here, because
napi_disablewill wait for thenapi_enableof the resize. So if the re-enable failed vq is used as a normal vq, this logic can be removed.
Quoted 8 lines
Quoted 3 lines
Actually I meant the part of
virtnet_rx_resize().If we don't synchronize with the refill work, it might enable NAPI unexpectedly?
I don't think this situation will be encountered, because
napi_disableis mutually exclusive, so there will be no unexpected napi enable.Is there something I misunderstood?
So in virtnet_rx_resize() we do:
napi_disable()
...resize()
...napi_enalbe()
How can we guarantee that the work is not run after the napi_disable()?
Thanks
Quoted 111 lines
Thanks.
Quoted 107 lines
Thanks
Quoted 103 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/virtio_net.c +1
-0+ still_empty = !try_fill_recv (vi, rq,GFP_KERNEL );virtnet_napi_enable (rq->vq, &rq->napi);@@ -1523,6 +1544,10 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)if (!sq->napi.weight ||is_xdp_raw_buffer_queue (vi, index))return ;Quoted 6 lines
drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct receive_queue *rq) · line 1549
Quoted 3 lines
drivers/net/virtio_net.c +3
-0+/* Check if vq is in reset state. See more in virtnet_napi_enable() */ +if (sq->vq->reset) +return ;We've disabled TX napi, any chance we can still hit this?
Same as above.
Quoted 55 lines
Quoted 55 lines
drivers/net/virtio_net.c +46
-0+if (__netif_tx_trylock (txq)) { do { virtqueue_disable_cb(sq->vq);@@ -1769,6 +1794,62 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +static int virtnet_rx_resize (struct virtnet_info *vi, +struct receive_queue *rq,u32 ring_num) +{ +int err; + +napi_disable (&rq->napi); + + err =virtqueue_resize (rq->vq, ring_num, virtnet_rq_free_unused_buf); +if (err) + goto err; + +if (!try_fill_recv (vi, rq,GFP_KERNEL )) +schedule_delayed_work (&vi->refill,0 ); + +virtnet_napi_enable (rq->vq, &rq->napi); +return 0 ; + +err: +netdev_err (vi->dev, +"reset rx reset vq fail: rx queue index: %td err: %d\n" , + rq - vi->rq, err); +virtnet_napi_enable (rq->vq, &rq->napi); +return err; +} + +static int virtnet_tx_resize (struct virtnet_info *vi, +struct send_queue *sq,u32 ring_num) +{ +struct netdev_queue *txq; +int err, qindex; + + qindex = sq - vi->sq; + +virtnet_napi_tx_disable (&sq->napi); + + txq =netdev_get_tx_queue (vi->dev, qindex); +__netif_tx_lock_bh (txq); +netif_stop_subqueue (vi->dev, qindex); +__netif_tx_unlock_bh (txq); + + err =virtqueue_resize (sq->vq, ring_num, virtnet_sq_free_unused_buf); +if (err) + goto err; + +netif_start_subqueue (vi->dev, qindex);Quoted 8 lines
drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1845
Quoted 4 lines
drivers/net/virtio_net.c +4
-0+virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return 0 ; + +err:I guess we can still start the queue in this case? (Since we don't change the queue if resize fails).
Yes, you are right.
Thanks.
Quoted 13 lines
Quoted 12 lines
drivers/net/virtio_net.c +7
-0+netdev_err (vi->dev, +"reset tx reset vq fail: tx queue index: %td err: %d\n" , + sq - vi->sq, err); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return err; +} +/* * Send command via the control virtqueue and check status. Commands * supported by the hypervisor, as indicated by feature bits, should
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 31/32] virtio_net: support rx/tx queue resize
Quoted 152 lines · Jason Wang
Quoted 140 lines · Xuan Zhuo
Quoted 93 lines · Jason Wang
Quoted 92 lines · Xuan Zhuo
Quoted 34 lines · Jason Wang
Quoted 32 lines · Xuan Zhuo
This patch implements the resize function of the rx, tx queues. Based on this function, it is possible to modify the ring num of the queue.
There may be an exception during the resize process, the resize may fail, or the vq can no longer be used. Either way, we must execute
napi_enable(). Becausenapi_disableis similar to a lock,napi_enablemust be called after callingnapi_disable.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/virtio_net.c | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)drivers/net/virtio_net.c +3
-0@@ -251,6 +251,9 @@ struct padded_vnet_hdr {char padding[4 ]; }; +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf); +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf); +static bool is_xdp_frame (void *ptr) {return (unsigned long )ptr &VIRTIO_XDP_FLAG ;@@ -1369,6 +1372,15 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) {napi_enable (napi);Quoted 11 lines
drivers/net/virtio_net.c static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) · line 1382
Quoted 8 lines
drivers/net/virtio_net.c +8
-0+/* Check if vq is in reset state. The normal reset/resize process will +* be protected by napi. However, the protection of napi is only enabled +* during the operation, and the protection of napi will end after the +* operation is completed. If re-enable fails during the process, vq +* will remain unavailable with reset state. +*/ +if (vq->reset) +return ;I don't get when could we hit this condition.
In patch 23, the code to implement re-enable vq is as follows:
(quoted diff) +39
-0+static int vp_modern_enable_reset_vq(struct virtqueue *vq) +{ + struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev); + struct virtio_pci_modern_device *mdev = &vp_dev->mdev; + struct virtio_pci_vq_info *info; + unsigned long flags, index; + int err; + + if (!vq->reset) + return -EBUSY; + + index = vq->index; + info = vp_dev->vqs[index]; + + /* check queue reset status */ + if (vp_modern_get_queue_reset(mdev, index) != 1) + return -EBUSY; + + err = vp_active_vq(vq, info->msix_vector); + if (err) + return err; + + if (vq->callback) { + spin_lock_irqsave(&vp_dev->lock, flags); + list_add(&info->node, &vp_dev->virtqueues); + spin_unlock_irqrestore(&vp_dev->lock, flags); + } else { + INIT_LIST_HEAD(&info->node); + } + + vp_modern_set_queue_enable(&vp_dev->mdev, index, true); + + if (vp_dev->per_vq_vectors && info->msix_vector != VIRTIO_MSI_NO_VECTOR) + enable_irq(pci_irq_vector(vp_dev->pci_dev, info->msix_vector)); + + vq->reset = false; + + return 0; +}Quoted 4 lines
Quoted 2 lines
There are three situations where an error will be returned. These are the situations I want to handle.
Right, but it looks harmless if we just schedule the NAPI without the check.
Yes.
Quoted 7 lines
Quoted 4 lines
But I'm rethinking the question, and I feel like you're right, although the hardware setup may fail. We can no longer sync with the hardware. But using it as a normal vq doesn't have any problems.
Note that we should make sure the buggy(malicous) device won't crash the codes by changing the
queue_resetvalue at its will.I will keep an eye on this situation.
Quoted 28 lines
Quoted 27 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/virtio_net.c +1
-0+/* If all buffers were filled by other side before we napi_enabled, we * won't get another interrupt, so process any outstanding packets now. * Call local_bh_enable after to trigger softIRQ processing. @@ -1413,6 +1425,15 @@ static void refill_work(struct work_struct *work)struct receive_queue *rq = &vi->rq[i];Quoted 12 lines
drivers/net/virtio_net.c static void refill_work(struct work_struct *work) · line 1435
Quoted 9 lines
drivers/net/virtio_net.c +8
-0napi_disable (&rq->napi); + +/* Check if vq is in reset state. See more in +* virtnet_napi_enable() +*/ +if (rq->vq->reset) { +virtnet_napi_enable (rq->vq, &rq->napi); +continue ; + }Can we do something similar in
virtnet_close()by canceling the work?I think there is no need to cancel the work here, because
napi_disablewill wait for thenapi_enableof the resize. So if the re-enable failed vq is used as a normal vq, this logic can be removed.Quoted 8 lines
Quoted 3 lines
Actually I meant the part of
virtnet_rx_resize().If we don't synchronize with the refill work, it might enable NAPI unexpectedly?
I don't think this situation will be encountered, because
napi_disableis mutually exclusive, so there will be no unexpected napi enable.Is there something I misunderstood?
So in
virtnet_rx_resize()we do:
Quoted 7 lines
napi_disable()
...resize()
...napi_enalbe()How can we guarantee that the work is not run after the
napi_disable()?
I think you're talking about a situation like this:
virtnet_rx_resize refill work
-----------------------------------------------------------
napi_disable()
... napi_disable()
resize() ...
napi_enable()
...
napi_enalbe()
But in fact:
virtnet_rx_resize refill work
-----------------------------------------------------------
napi_disable()
... napi_disable() <----[0]
resize() |
... |
napi_enalbe() |
napi_disable() <---- [1] here success
napi_enable()Because virtnet_rx_resize() has already executed napi_disable(), napi_disalbe() of [0] will wait until [1] to complete.
I'm not sure if my understanding is correct.
Thanks.
Quoted 115 lines
Thanks
Quoted 111 lines
Thanks.
Quoted 107 lines
Thanks
Quoted 103 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/virtio_net.c +1
-0+ still_empty = !try_fill_recv (vi, rq,GFP_KERNEL );virtnet_napi_enable (rq->vq, &rq->napi);@@ -1523,6 +1544,10 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)if (!sq->napi.weight ||is_xdp_raw_buffer_queue (vi, index))return ;Quoted 6 lines
drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct receive_queue *rq) · line 1549
Quoted 3 lines
drivers/net/virtio_net.c +3
-0+/* Check if vq is in reset state. See more in virtnet_napi_enable() */ +if (sq->vq->reset) +return ;We've disabled TX napi, any chance we can still hit this?
Same as above.
Quoted 55 lines
Quoted 55 lines
drivers/net/virtio_net.c +46
-0+if (__netif_tx_trylock (txq)) { do { virtqueue_disable_cb(sq->vq);@@ -1769,6 +1794,62 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +static int virtnet_rx_resize (struct virtnet_info *vi, +struct receive_queue *rq,u32 ring_num) +{ +int err; + +napi_disable (&rq->napi); + + err =virtqueue_resize (rq->vq, ring_num, virtnet_rq_free_unused_buf); +if (err) + goto err; + +if (!try_fill_recv (vi, rq,GFP_KERNEL )) +schedule_delayed_work (&vi->refill,0 ); + +virtnet_napi_enable (rq->vq, &rq->napi); +return 0 ; + +err: +netdev_err (vi->dev, +"reset rx reset vq fail: rx queue index: %td err: %d\n" , + rq - vi->rq, err); +virtnet_napi_enable (rq->vq, &rq->napi); +return err; +} + +static int virtnet_tx_resize (struct virtnet_info *vi, +struct send_queue *sq,u32 ring_num) +{ +struct netdev_queue *txq; +int err, qindex; + + qindex = sq - vi->sq; + +virtnet_napi_tx_disable (&sq->napi); + + txq =netdev_get_tx_queue (vi->dev, qindex); +__netif_tx_lock_bh (txq); +netif_stop_subqueue (vi->dev, qindex); +__netif_tx_unlock_bh (txq); + + err =virtqueue_resize (sq->vq, ring_num, virtnet_sq_free_unused_buf); +if (err) + goto err; + +netif_start_subqueue (vi->dev, qindex);Quoted 8 lines
drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1845
Quoted 4 lines
drivers/net/virtio_net.c +4
-0+virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return 0 ; + +err:I guess we can still start the queue in this case? (Since we don't change the queue if resize fails).
Yes, you are right.
Thanks.
Quoted 13 lines
Quoted 12 lines
drivers/net/virtio_net.c +7
-0+netdev_err (vi->dev, +"reset tx reset vq fail: tx queue index: %td err: %d\n" , + sq - vi->sq, err); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return err; +} +/* * Send command via the control virtqueue and check status. Commands * supported by the hypervisor, as indicated by feature bits, should
Re: [PATCH v9 31/32] virtio_net: support rx/tx queue resize
Quoted 167 lines · Xuan Zhuo
Quoted 134 lines · Jason Wang
Quoted 124 lines · Xuan Zhuo
Quoted 89 lines · Jason Wang
Quoted 88 lines · Xuan Zhuo
Quoted 33 lines · Jason Wang
Quoted 32 lines · Xuan Zhuo
This patch implements the resize function of the rx, tx queues. Based on this function, it is possible to modify the ring num of the queue.
There may be an exception during the resize process, the resize may fail, or the vq can no longer be used. Either way, we must execute
napi_enable(). Becausenapi_disableis similar to a lock,napi_enablemust be called after callingnapi_disable.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/virtio_net.c | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)drivers/net/virtio_net.c +3
-0@@ -251,6 +251,9 @@ struct padded_vnet_hdr {char padding[4 ]; }; +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf); +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf); +static bool is_xdp_frame (void *ptr) {return (unsigned long )ptr &VIRTIO_XDP_FLAG ;@@ -1369,6 +1372,15 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) {napi_enable (napi);Quoted 10 lines
drivers/net/virtio_net.c static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) · line 1382
Quoted 8 lines
drivers/net/virtio_net.c +8
-0+/* Check if vq is in reset state. The normal reset/resize process will +* be protected by napi. However, the protection of napi is only enabled +* during the operation, and the protection of napi will end after the +* operation is completed. If re-enable fails during the process, vq +* will remain unavailable with reset state. +*/ +if (vq->reset) +return ;I don't get when could we hit this condition.
In patch 23, the code to implement re-enable vq is as follows:
(quoted diff) +39
-0+static int vp_modern_enable_reset_vq(struct virtqueue *vq) +{ + struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev); + struct virtio_pci_modern_device *mdev = &vp_dev->mdev; + struct virtio_pci_vq_info *info; + unsigned long flags, index; + int err; + + if (!vq->reset) + return -EBUSY; + + index = vq->index; + info = vp_dev->vqs[index]; + + /* check queue reset status */ + if (vp_modern_get_queue_reset(mdev, index) != 1) + return -EBUSY; + + err = vp_active_vq(vq, info->msix_vector); + if (err) + return err; + + if (vq->callback) { + spin_lock_irqsave(&vp_dev->lock, flags); + list_add(&info->node, &vp_dev->virtqueues); + spin_unlock_irqrestore(&vp_dev->lock, flags); + } else { + INIT_LIST_HEAD(&info->node); + } + + vp_modern_set_queue_enable(&vp_dev->mdev, index, true); + + if (vp_dev->per_vq_vectors && info->msix_vector != VIRTIO_MSI_NO_VECTOR) + enable_irq(pci_irq_vector(vp_dev->pci_dev, info->msix_vector)); + + vq->reset = false; + + return 0; +}Quoted 3 lines
Quoted 2 lines
There are three situations where an error will be returned. These are the situations I want to handle.
Right, but it looks harmless if we just schedule the NAPI without the check.
Yes.
Quoted 5 lines
Quoted 3 lines
But I'm rethinking the question, and I feel like you're right, although the hardware setup may fail. We can no longer sync with the hardware. But using it as a normal vq doesn't have any problems.
Note that we should make sure the buggy(malicous) device won't crash the codes by changing the
queue_resetvalue at its will.I will keep an eye on this situation.
Quoted 22 lines
Quoted 22 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/virtio_net.c +1
-0+/* If all buffers were filled by other side before we napi_enabled, we * won't get another interrupt, so process any outstanding packets now. * Call local_bh_enable after to trigger softIRQ processing. @@ -1413,6 +1425,15 @@ static void refill_work(struct work_struct *work)struct receive_queue *rq = &vi->rq[i];Quoted 11 lines
drivers/net/virtio_net.c static void refill_work(struct work_struct *work) · line 1435
Quoted 9 lines
drivers/net/virtio_net.c +8
-0napi_disable (&rq->napi); + +/* Check if vq is in reset state. See more in +* virtnet_napi_enable() +*/ +if (rq->vq->reset) { +virtnet_napi_enable (rq->vq, &rq->napi); +continue ; + }Can we do something similar in
virtnet_close()by canceling the work?I think there is no need to cancel the work here, because
napi_disablewill wait for thenapi_enableof the resize. So if the re-enable failed vq is used as a normal vq, this logic can be removed.Quoted 7 lines
Quoted 3 lines
Actually I meant the part of
virtnet_rx_resize().If we don't synchronize with the refill work, it might enable NAPI unexpectedly?
I don't think this situation will be encountered, because
napi_disableis mutually exclusive, so there will be no unexpected napi enable.Is there something I misunderstood?
So in
virtnet_rx_resize()we do:Quoted 7 lines
napi_disable()
...resize()
...napi_enalbe()How can we guarantee that the work is not run after the
napi_disable()?I think you're talking about a situation like this:
virtnet_rx_resizerefill work
-----------------------------------------------------------
napi_disable()
...napi_disable()
resize()...
napi_enable()
...
napi_enalbe()But in fact:
virtnet_rx_resizerefill work
-----------------------------------------------------------
napi_disable()
...napi_disable()<----[0]resize() | ... | napi_enalbe() | napi_disable() <---- [1] here success napi_enable()
Quoted 4 lines
Because
virtnet_rx_resize()has already executednapi_disable(),napi_disalbe()of [0] will wait until [1] to complete.I'm not sure if my understanding is correct.
I think you're right here.
Thanks
Quoted 92 lines
Thanks.
Quoted 89 lines
Thanks
Quoted 87 lines
Thanks.
Quoted 85 lines
Thanks
Quoted 83 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/virtio_net.c +1
-0+ still_empty = !try_fill_recv (vi, rq,GFP_KERNEL );virtnet_napi_enable (rq->vq, &rq->napi);@@ -1523,6 +1544,10 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)if (!sq->napi.weight ||is_xdp_raw_buffer_queue (vi, index))return ;Quoted 5 lines
drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct receive_queue *rq) · line 1549
Quoted 3 lines
drivers/net/virtio_net.c +3
-0+/* Check if vq is in reset state. See more in virtnet_napi_enable() */ +if (sq->vq->reset) +return ;We've disabled TX napi, any chance we can still hit this?
Same as above.
Quoted 53 lines
Quoted 53 lines
drivers/net/virtio_net.c +45
-0+if (__netif_tx_trylock (txq)) { do { virtqueue_disable_cb(sq->vq);@@ -1769,6 +1794,62 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +static int virtnet_rx_resize (struct virtnet_info *vi, +struct receive_queue *rq,u32 ring_num) +{ +int err; + +napi_disable (&rq->napi); + + err =virtqueue_resize (rq->vq, ring_num, virtnet_rq_free_unused_buf); +if (err) + goto err; + +if (!try_fill_recv (vi, rq,GFP_KERNEL )) +schedule_delayed_work (&vi->refill,0 ); + +virtnet_napi_enable (rq->vq, &rq->napi); +return 0 ; + +err: +netdev_err (vi->dev, +"reset rx reset vq fail: rx queue index: %td err: %d\n" , + rq - vi->rq, err); +virtnet_napi_enable (rq->vq, &rq->napi); +return err; +} + +static int virtnet_tx_resize (struct virtnet_info *vi, +struct send_queue *sq,u32 ring_num) +{ +struct netdev_queue *txq; +int err, qindex; + + qindex = sq - vi->sq; + +virtnet_napi_tx_disable (&sq->napi); + + txq =netdev_get_tx_queue (vi->dev, qindex); +__netif_tx_lock_bh (txq); +netif_stop_subqueue (vi->dev, qindex); +__netif_tx_unlock_bh (txq); + + err =virtqueue_resize (sq->vq, ring_num, virtnet_sq_free_unused_buf); +if (err) + goto err; +Quoted 8 lines
drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1845
Quoted 5 lines
drivers/net/virtio_net.c +5
-0+netif_start_subqueue (vi->dev, qindex); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return 0 ; + +err:I guess we can still start the queue in this case? (Since we don't change the queue if resize fails).
Yes, you are right.
Thanks.
Quoted 1 line
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1855
Quoted 10 lines
drivers/net/virtio_net.c +7
-0+netdev_err (vi->dev, +"reset tx reset vq fail: tx queue index: %td err: %d\n" , + sq - vi->sq, err); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return err; +} +/* * Send command via the control virtqueue and check status. Commands * supported by the hypervisor, as indicated by feature bits, should
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 31/32] virtio_net: support rx/tx queue resize
In reply to Jason WangQuoted 76 lines · Jason Wang
Quoted 30 lines · Xuan Zhuo
This patch implements the resize function of the rx, tx queues. Based on this function, it is possible to modify the ring num of the queue.
There may be an exception during the resize process, the resize may fail, or the vq can no longer be used. Either way, we must execute
napi_enable(). Becausenapi_disableis similar to a lock,napi_enablemust be called after callingnapi_disable.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/virtio_net.c | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)drivers/net/virtio_net.c +3
-0@@ -251,6 +251,9 @@ struct padded_vnet_hdr {char padding[4 ]; }; +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf); +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf); +static bool is_xdp_frame (void *ptr) {return (unsigned long )ptr &VIRTIO_XDP_FLAG ;@@ -1369,6 +1372,15 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) {drivers/net/virtio_net.c static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) · line 1382
Quoted 10 lines
drivers/net/virtio_net.c +8
-0napi_enable (napi); +/* Check if vq is in reset state. The normal reset/resize process will +* be protected by napi. However, the protection of napi is only enabled +* during the operation, and the protection of napi will end after the +* operation is completed. If re-enable fails during the process, vq +* will remain unavailable with reset state. +*/ +if (vq->reset) +return ;I don't get when could we hit this condition.
Quoted 6 lines
drivers/net/virtio_net.c +1
-0+/* If all buffers were filled by other side before we napi_enabled, we * won't get another interrupt, so process any outstanding packets now. * Call local_bh_enable after to trigger softIRQ processing. @@ -1413,6 +1425,15 @@ static void refill_work(struct work_struct *work)struct receive_queue *rq = &vi->rq[i];drivers/net/virtio_net.c static void refill_work(struct work_struct *work) · line 1435
Quoted 10 lines
drivers/net/virtio_net.c +8
-0napi_disable (&rq->napi); + +/* Check if vq is in reset state. See more in +* virtnet_napi_enable() +*/ +if (rq->vq->reset) { +virtnet_napi_enable (rq->vq, &rq->napi); +continue ; + }Can we do something similar in
virtnet_close()by canceling the work?Quoted 8 lines
drivers/net/virtio_net.c +1
-0+ still_empty = !try_fill_recv (vi, rq,GFP_KERNEL );virtnet_napi_enable (rq->vq, &rq->napi);@@ -1523,6 +1544,10 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)if (!sq->napi.weight ||is_xdp_raw_buffer_queue (vi, index))return ;
Quoted 6 lines
drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct receive_queue *rq) · line 1549
Quoted 3 lines
drivers/net/virtio_net.c +3
-0+/* Check if vq is in reset state. See more in virtnet_napi_enable() */ +if (sq->vq->reset) +return ;We've disabled TX napi, any chance we can still hit this?
static int virtnet_poll(struct napi_struct *napi, int budget)
{
struct receive_queue *rq =
container_of(napi, struct receive_queue, napi);
struct virtnet_info *vi = rq->vq->vdev->priv;
struct send_queue *sq;
unsigned int received;
unsigned int xdp_xmit = 0;
virtnet_poll_cleantx(rq);...
}
This is called by rx poll. Although it is the logic of tx, it is not driven by tx napi, but is called in rx poll.
Thanks.
Quoted 76 lines
Quoted 49 lines
drivers/net/virtio_net.c +40
-0+if (__netif_tx_trylock (txq)) { do { virtqueue_disable_cb(sq->vq);@@ -1769,6 +1794,62 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +static int virtnet_rx_resize (struct virtnet_info *vi, +struct receive_queue *rq,u32 ring_num) +{ +int err; + +napi_disable (&rq->napi); + + err =virtqueue_resize (rq->vq, ring_num, virtnet_rq_free_unused_buf); +if (err) + goto err; + +if (!try_fill_recv (vi, rq,GFP_KERNEL )) +schedule_delayed_work (&vi->refill,0 ); + +virtnet_napi_enable (rq->vq, &rq->napi); +return 0 ; + +err: +netdev_err (vi->dev, +"reset rx reset vq fail: rx queue index: %td err: %d\n" , + rq - vi->rq, err); +virtnet_napi_enable (rq->vq, &rq->napi); +return err; +} + +static int virtnet_tx_resize (struct virtnet_info *vi, +struct send_queue *sq,u32 ring_num) +{ +struct netdev_queue *txq; +int err, qindex; + + qindex = sq - vi->sq; + +virtnet_napi_tx_disable (&sq->napi); + + txq =netdev_get_tx_queue (vi->dev, qindex); +__netif_tx_lock_bh (txq); +netif_stop_subqueue (vi->dev, qindex); +__netif_tx_unlock_bh (txq);drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1845
Quoted 10 lines
drivers/net/virtio_net.c +10
-0+ + err =virtqueue_resize (sq->vq, ring_num, virtnet_sq_free_unused_buf); +if (err) + goto err; + +netif_start_subqueue (vi->dev, qindex); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return 0 ; + +err:I guess we can still start the queue in this case? (Since we don't change the queue if resize fails).
Quoted 10 lines
drivers/net/virtio_net.c +7
-0+netdev_err (vi->dev, +"reset tx reset vq fail: tx queue index: %td err: %d\n" , + sq - vi->sq, err); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return err; +} +/* * Send command via the control virtqueue and check status. Commands * supported by the hypervisor, as indicated by feature bits, should
Re: [PATCH v9 31/32] virtio_net: support rx/tx queue resize
Quoted 96 lines · Xuan Zhuo
Quoted 76 lines · Jason Wang
Quoted 30 lines · Xuan Zhuo
This patch implements the resize function of the rx, tx queues. Based on this function, it is possible to modify the ring num of the queue.
There may be an exception during the resize process, the resize may fail, or the vq can no longer be used. Either way, we must execute
napi_enable(). Becausenapi_disableis similar to a lock,napi_enablemust be called after callingnapi_disable.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/virtio_net.c | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)drivers/net/virtio_net.c +3
-0@@ -251,6 +251,9 @@ struct padded_vnet_hdr {char padding[4 ]; }; +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf); +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf); +static bool is_xdp_frame (void *ptr) {return (unsigned long )ptr &VIRTIO_XDP_FLAG ;@@ -1369,6 +1372,15 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) {drivers/net/virtio_net.c static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) · line 1382
Quoted 10 lines
drivers/net/virtio_net.c +8
-0napi_enable (napi); +/* Check if vq is in reset state. The normal reset/resize process will +* be protected by napi. However, the protection of napi is only enabled +* during the operation, and the protection of napi will end after the +* operation is completed. If re-enable fails during the process, vq +* will remain unavailable with reset state. +*/ +if (vq->reset) +return ;I don't get when could we hit this condition.
Quoted 6 lines
drivers/net/virtio_net.c +1
-0+/* If all buffers were filled by other side before we napi_enabled, we * won't get another interrupt, so process any outstanding packets now. * Call local_bh_enable after to trigger softIRQ processing. @@ -1413,6 +1425,15 @@ static void refill_work(struct work_struct *work)struct receive_queue *rq = &vi->rq[i];drivers/net/virtio_net.c static void refill_work(struct work_struct *work) · line 1435
Quoted 10 lines
drivers/net/virtio_net.c +8
-0napi_disable (&rq->napi); + +/* Check if vq is in reset state. See more in +* virtnet_napi_enable() +*/ +if (rq->vq->reset) { +virtnet_napi_enable (rq->vq, &rq->napi); +continue ; + }Can we do something similar in
virtnet_close()by canceling the work?Quoted 8 lines
drivers/net/virtio_net.c +1
-0+ still_empty = !try_fill_recv (vi, rq,GFP_KERNEL );virtnet_napi_enable (rq->vq, &rq->napi);@@ -1523,6 +1544,10 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)if (!sq->napi.weight ||is_xdp_raw_buffer_queue (vi, index))return ;Quoted 6 lines
drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct receive_queue *rq) · line 1549
Quoted 3 lines
drivers/net/virtio_net.c +3
-0+/* Check if vq is in reset state. See more in virtnet_napi_enable() */ +if (sq->vq->reset) +return ;We've disabled TX napi, any chance we can still hit this?
static int
virtnet_poll(struct napi_struct *napi, int budget){ struct receive_queue *rq = container_of(napi, struct receive_queue, napi); struct virtnet_info *vi = rq->vq->vdev->priv; struct send_queue *sq; unsigned int received; unsigned int xdp_xmit = 0; virtnet_poll_cleantx(rq);
Quoted 5 lines
...
}This is called by rx poll. Although it is the logic of tx, it is not driven by tx napi, but is called in rx poll.
Ok, but we need guarantee the memory ordering in this case. Disable RX napi could be a solution for this.
Thanks
Quoted 81 lines
Thanks.
Quoted 76 lines
Quoted 49 lines
drivers/net/virtio_net.c +40
-0+if (__netif_tx_trylock (txq)) { do { virtqueue_disable_cb(sq->vq);@@ -1769,6 +1794,62 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +static int virtnet_rx_resize (struct virtnet_info *vi, +struct receive_queue *rq,u32 ring_num) +{ +int err; + +napi_disable (&rq->napi); + + err =virtqueue_resize (rq->vq, ring_num, virtnet_rq_free_unused_buf); +if (err) + goto err; + +if (!try_fill_recv (vi, rq,GFP_KERNEL )) +schedule_delayed_work (&vi->refill,0 ); + +virtnet_napi_enable (rq->vq, &rq->napi); +return 0 ; + +err: +netdev_err (vi->dev, +"reset rx reset vq fail: rx queue index: %td err: %d\n" , + rq - vi->rq, err); +virtnet_napi_enable (rq->vq, &rq->napi); +return err; +} + +static int virtnet_tx_resize (struct virtnet_info *vi, +struct send_queue *sq,u32 ring_num) +{ +struct netdev_queue *txq; +int err, qindex; + + qindex = sq - vi->sq; + +virtnet_napi_tx_disable (&sq->napi); + + txq =netdev_get_tx_queue (vi->dev, qindex); +__netif_tx_lock_bh (txq); +netif_stop_subqueue (vi->dev, qindex); +__netif_tx_unlock_bh (txq);drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1845
Quoted 10 lines
drivers/net/virtio_net.c +10
-0+ + err =virtqueue_resize (sq->vq, ring_num, virtnet_sq_free_unused_buf); +if (err) + goto err; + +netif_start_subqueue (vi->dev, qindex); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return 0 ; + +err:I guess we can still start the queue in this case? (Since we don't change the queue if resize fails).
Quoted 10 lines
drivers/net/virtio_net.c +7
-0+netdev_err (vi->dev, +"reset tx reset vq fail: tx queue index: %td err: %d\n" , + sq - vi->sq, err); +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return err; +} +/* * Send command via the control virtqueue and check status. Commands * supported by the hypervisor, as indicated by feature bits, should
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerRe: [PATCH v9 31/32] virtio_net: support rx/tx queue resize
Quoted 100 lines · Jason Wang
Quoted 99 lines · Xuan Zhuo
Quoted 76 lines · Jason Wang
Quoted 30 lines · Xuan Zhuo
This patch implements the resize function of the rx, tx queues. Based on this function, it is possible to modify the ring num of the queue.
There may be an exception during the resize process, the resize may fail, or the vq can no longer be used. Either way, we must execute
napi_enable(). Becausenapi_disableis similar to a lock,napi_enablemust be called after callingnapi_disable.Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/virtio_net.c | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)drivers/net/virtio_net.c +3
-0@@ -251,6 +251,9 @@ struct padded_vnet_hdr {char padding[4 ]; }; +static void virtnet_sq_free_unused_buf (struct virtqueue *vq,void *buf); +static void virtnet_rq_free_unused_buf (struct virtqueue *vq,void *buf); +static bool is_xdp_frame (void *ptr) {return (unsigned long )ptr &VIRTIO_XDP_FLAG ;@@ -1369,6 +1372,15 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) {drivers/net/virtio_net.c static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) · line 1382
Quoted 10 lines
drivers/net/virtio_net.c +8
-0napi_enable (napi); +/* Check if vq is in reset state. The normal reset/resize process will +* be protected by napi. However, the protection of napi is only enabled +* during the operation, and the protection of napi will end after the +* operation is completed. If re-enable fails during the process, vq +* will remain unavailable with reset state. +*/ +if (vq->reset) +return ;I don't get when could we hit this condition.
Quoted 6 lines
drivers/net/virtio_net.c +1
-0+/* If all buffers were filled by other side before we napi_enabled, we * won't get another interrupt, so process any outstanding packets now. * Call local_bh_enable after to trigger softIRQ processing. @@ -1413,6 +1425,15 @@ static void refill_work(struct work_struct *work)struct receive_queue *rq = &vi->rq[i];drivers/net/virtio_net.c static void refill_work(struct work_struct *work) · line 1435
Quoted 10 lines
drivers/net/virtio_net.c +8
-0napi_disable (&rq->napi); + +/* Check if vq is in reset state. See more in +* virtnet_napi_enable() +*/ +if (rq->vq->reset) { +virtnet_napi_enable (rq->vq, &rq->napi); +continue ; + }Can we do something similar in
virtnet_close()by canceling the work?Quoted 8 lines
drivers/net/virtio_net.c +1
-0+ still_empty = !try_fill_recv (vi, rq,GFP_KERNEL );virtnet_napi_enable (rq->vq, &rq->napi);@@ -1523,6 +1544,10 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)if (!sq->napi.weight ||is_xdp_raw_buffer_queue (vi, index))return ;Quoted 6 lines
drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct receive_queue *rq) · line 1549
Quoted 3 lines
drivers/net/virtio_net.c +3
-0+/* Check if vq is in reset state. See more in virtnet_napi_enable() */ +if (sq->vq->reset) +return ;We've disabled TX napi, any chance we can still hit this?
static int
virtnet_poll(struct napi_struct *napi, int budget){ struct receive_queue *rq = container_of(napi, struct receive_queue, napi); struct virtnet_info *vi = rq->vq->vdev->priv; struct send_queue *sq; unsigned int received; unsigned int xdp_xmit = 0; virtnet_poll_cleantx(rq);...
}
Quoted 5 lines
Quoted 2 lines
This is called by rx poll. Although it is the logic of tx, it is not driven by tx napi, but is called in rx poll.
Ok, but we need guarantee the memory ordering in this case. Disable RX napi could be a solution for this.
Yes, I have realized this too. I have two solutions, disable rx napi or the following.
Thanks.
drivers/net/virtio_net.c +36 -0
@@ -135,6 +135,7 @@ struct send_queue {struct virtnet_sq_stats stats;struct napi_struct napi; +bool reset; };/* Internal representation of a receive virtqueue */
@@ -1583,6 +1587,11 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)return ;if (__netif_tx_trylock (txq)) { +if (sq->reset) { +__netif_tx_unlock (txq); +return ; + } + do { virtqueue_disable_cb(sq->vq); free_old_xmit_skbs(sq, true);
@@ -1828,6 +1837,56 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +static int virtnet_tx_resize (struct virtnet_info *vi, +struct send_queue *sq,u32 ring_num) +{ +struct netdev_queue *txq; +int err, qindex; + + qindex = sq - vi->sq; + +virtnet_napi_tx_disable (&sq->napi); + + txq =netdev_get_tx_queue (vi->dev, qindex); + +__netif_tx_lock_bh (txq); +netif_stop_subqueue (vi->dev, qindex); + sq->reset = true; +__netif_tx_unlock_bh (txq); + + err =virtqueue_resize (sq->vq, ring_num, virtnet_sq_free_unused_buf); +if (err) +netdev_err (vi->dev,"resize tx fail: tx queue index: %d err: %d\n" , qindex, err); + +__netif_tx_lock_bh (txq); + sq->reset = false; +netif_start_subqueue (vi->dev, qindex); +__netif_tx_unlock_bh (txq); + +virtnet_napi_tx_enable (vi, sq->vq, &sq->napi); +return err; +} +
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerPATCH v9 32/32 virtio_net: support set_ringparam
In reply to Xuan ZhuoSupport set_ringparam based on virtio queue reset.
Users can use ethtool -G eth0 <ring_num> to modify the ring size of virtio-net.
--- drivers/net/virtio_net.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/net/virtio_net.c +47 -0
@@ -2264,6 +2264,52 @@ static void virtnet_get_ringparam(struct net_device *dev, ring->tx_pending =virtqueue_get_vring_size (vi->sq[0 ].vq); } +static int virtnet_set_ringparam (struct net_device *dev, +struct ethtool_ringparam *ring, +struct kernel_ethtool_ringparam *kernel_ring, +struct netlink_ext_ack *extack) +{ +struct virtnet_info *vi =netdev_priv (dev); +u32 rx_pending, tx_pending; +struct receive_queue *rq; +struct send_queue *sq; +int i, err; + +if (ring->rx_mini_pending || ring->rx_jumbo_pending) +return -EINVAL ; + + rx_pending =virtqueue_get_vring_size (vi->rq[0 ].vq); + tx_pending =virtqueue_get_vring_size (vi->sq[0 ].vq); + +if (ring->rx_pending == rx_pending && + ring->tx_pending == tx_pending) +return 0 ; + +if (ring->rx_pending >virtqueue_get_vring_max_size (vi->rq[0 ].vq)) +return -EINVAL ; + +if (ring->tx_pending >virtqueue_get_vring_max_size (vi->sq[0 ].vq)) +return -EINVAL ; + +for (i =0 ; i < vi->max_queue_pairs; i++) { + rq = vi->rq + i; + sq = vi->sq + i; + +if (ring->tx_pending != tx_pending) { + err =virtnet_tx_resize (vi, sq, ring->tx_pending); +if (err) +return err; + } + +if (ring->rx_pending != rx_pending) { + err =virtnet_rx_resize (vi, rq, ring->rx_pending); +if (err) +return err; + } + } + +return 0 ; +}static void virtnet_get_drvinfo (struct net_device *dev,struct ethtool_drvinfo *info)
@@ -2497,6 +2543,7 @@ static const struct ethtool_ops virtnet_ethtool_ops = { .get_drvinfo = virtnet_get_drvinfo, .get_link = ethtool_op_get_link, .get_ringparam = virtnet_get_ringparam, + .set_ringparam = virtnet_set_ringparam, .get_strings = virtnet_get_strings, .get_sset_count = virtnet_get_sset_count, .get_ethtool_stats = virtnet_get_ethtool_stats,
Signature · 7 lines
2.31.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v9 32/32] virtio_net: support set_ringparam
Quoted 6 lines · Xuan Zhuo
Support
set_ringparambased on virtio queue reset.Users can use ethtool -G eth0 <
ring_num> to modify the ring size of virtio-net.Signed-off-by Xuan Zhuo <[email protected]>
(One thing that I see is that, when resize fails, the param reported via get_ringparam might be wrong, this is a corner case but might worth to fix in the future).
Quoted 69 lines
--- drivers/net/virtio_net.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)drivers/net/virtio_net.c +47
-0@@ -2264,6 +2264,52 @@ static void virtnet_get_ringparam(struct net_device *dev, ring->tx_pending =virtqueue_get_vring_size (vi->sq[0 ].vq); } +static int virtnet_set_ringparam (struct net_device *dev, +struct ethtool_ringparam *ring, +struct kernel_ethtool_ringparam *kernel_ring, +struct netlink_ext_ack *extack) +{ +struct virtnet_info *vi =netdev_priv (dev); +u32 rx_pending, tx_pending; +struct receive_queue *rq; +struct send_queue *sq; +int i, err; + +if (ring->rx_mini_pending || ring->rx_jumbo_pending) +return -EINVAL ; + + rx_pending =virtqueue_get_vring_size (vi->rq[0 ].vq); + tx_pending =virtqueue_get_vring_size (vi->sq[0 ].vq); + +if (ring->rx_pending == rx_pending && + ring->tx_pending == tx_pending) +return 0 ; + +if (ring->rx_pending >virtqueue_get_vring_max_size (vi->rq[0 ].vq)) +return -EINVAL ; + +if (ring->tx_pending >virtqueue_get_vring_max_size (vi->sq[0 ].vq)) +return -EINVAL ; + +for (i =0 ; i < vi->max_queue_pairs; i++) { + rq = vi->rq + i; + sq = vi->sq + i; + +if (ring->tx_pending != tx_pending) { + err =virtnet_tx_resize (vi, sq, ring->tx_pending); +if (err) +return err; + } + +if (ring->rx_pending != rx_pending) { + err =virtnet_rx_resize (vi, rq, ring->rx_pending); +if (err) +return err; + } + } + +return 0 ; +}static void virtnet_get_drvinfo (struct net_device *dev,struct ethtool_drvinfo *info)@@ -2497,6 +2543,7 @@ static const struct ethtool_ops virtnet_ethtool_ops = { .get_drvinfo = virtnet_get_drvinfo, .get_link = ethtool_op_get_link, .get_ringparam = virtnet_get_ringparam, + .set_ringparam = virtnet_set_ringparam, .get_strings = virtnet_get_strings, .get_sset_count = virtnet_get_sset_count, .get_ethtool_stats = virtnet_get_ethtool_stats,
Michael S. Tsirkin
maintainerQuoted 8 lines · Xuan Zhuo
The virtio spec already supports the virtio queue reset function. This patch set is to add this function to the kernel. The relevant virtio spec information is here:
https://github.com/oasis-tcs/virtio-spec/issues/124Also regarding MMIO support for queue reset, I plan to support it after this patch is passed.
Regarding the spec, there's now an issue proposing
some changes to the interface. What do you think about that proposal? Could you respond on that thread on the virtio TC mailing list?
Quoted 113 lines
This patch set implements the refactoring of vring. Finally, the
virtuque_resize()interface is provided based on the reset function of the transport layer.Test environment:
Host: 4.19.91
Qemu: QEMU emulator version 6.2.50 (with vq reset support) Test Cmd: ethtool -G eth1 rx $1 tx $2; ethtool -g eth1The default is split mode, modify Qemu virtio-net to add PACKED feature to test packed mode.
Qemu code:
https://github.com/fengidri/qemu/compare/89f3bfa3265554d1d591ee4d7f1197b6e3397e84...masterIn order to simplify the review of this patch set, the function of reusing the old buffers after resize will be introduced in subsequent patch sets.
Please review. Thanks.
v9:
1. Provide avirtqueue_resize()interface directly
2. A patch set including vring resize, virtio pci reset, virtio-net resize
3. No more separate structsv8:
1. Provide avirtqueue_reset()interface directly
2. Split the two patch sets, this is the first part
3. Add independent allocation helper for allocating state, extrav7:
1. fix #6 subject typo
2. fix #6ring_size_in_bytesis uninitialized
3. check by: make W=12v6:
1.virtio_pci: usesynchronize_irq(irq)to sync the irq callbacks
2. Introducevirtqueue_reset_vring()to implement the reset of vring during the reset process. May use the old vring if num of the vq not change.
3.find_vqs()support sizes to special the max size of each vqv5:
1. add virtio-net supportset_ringparamv4:
1. just the code of virtio, without virtio-net
2. Performing reset on a queue is divided into these steps:
1.reset_vq: reset one vq
2. recycle the buffer from vq byvirtqueue_detach_unused_buf()
3. release the ring of the vq byvring_release_virtqueue()
4.enable_reset_vq: re-enable the reset queue
3. Simplify the parameters ofenable_reset_vq()
4. add container structures forvirtio_pci_common_cfgv3:
1. keep vq, irq unreleasedXuan Zhuo (32):
virtio: add helpervirtqueue_get_vring_max_size()
virtio: structvirtio_config_opsadd callbacks forqueue_reset
virtio_ring: update the document of thevirtqueue_detach_unused_buf
for queue reset
virtio_ring: remove the arg vq ofvring_alloc_desc_extra()
virtio_ring: extract the logic of freeing vring
virtio_ring: split: extract the logic of alloc queue
virtio_ring: split: extract the logic of alloc state and extra
virtio_ring: split: extract the logic of attach vring
virtio_ring: split: extract the logic of vq init
virtio_ring: split: introducevirtqueue_reinit_split()
virtio_ring: split: introducevirtqueue_resize_split()
virtio_ring: packed: extract the logic of alloc queue
virtio_ring: packed: extract the logic of alloc state and extra
virtio_ring: packed: extract the logic of attach vring
virtio_ring: packed: extract the logic of vq init
virtio_ring: packed: introducevirtqueue_reinit_packed()
virtio_ring: packed: introducevirtqueue_resize_packed()
virtio_ring: introducevirtqueue_resize()
virtio_pci: structvirtio_pci_common_cfgaddqueue_notify_data
virtio:queue_reset: addVIRTIO_F_RING_RESET
virtio_pci:queue_reset: update structvirtio_pci_common_cfgand
option functions
virtio_pci:queue_reset: extract the logic of active vq for modern pci
virtio_pci:queue_reset: supportVIRTIO_F_RING_RESET
virtio:find_vqs()add arg sizes
virtio_pci: support the arg sizes offind_vqs()
virtio_mmio: support the arg sizes offind_vqs()
virtio: add helpervirtio_find_vqs_ctx_size()
virtio_net: set the default max ring size byfind_vqs()
virtio_net: get ringparam byvirtqueue_get_vring_max_size()
virtio_net: splitfree_unused_bufs()
virtio_net: support rx/tx queue resize
virtio_net: supportset_ringparamarch/um/drivers/virtio_uml.c | 3 +- drivers/net/virtio_net.c | 219 +++++++- drivers/platform/mellanox/mlxbf-tmfifo.c | 3 + drivers/remoteproc/remoteproc_virtio.c | 3 + drivers/s390/virtio/virtio_ccw.c | 4 + drivers/virtio/virtio_mmio.c | 11 +- drivers/virtio/virtio_pci_common.c | 28 +- drivers/virtio/virtio_pci_common.h | 3 +- drivers/virtio/virtio_pci_legacy.c | 8 +- drivers/virtio/virtio_pci_modern.c | 149 +++++- drivers/virtio/virtio_pci_modern_dev.c | 36 ++ drivers/virtio/virtio_ring.c | 626 ++++++++++++++++++----- drivers/virtio/virtio_vdpa.c | 3 + include/linux/virtio.h | 6 + include/linux/virtio_config.h | 38 +- include/linux/virtio_pci_modern.h | 2 + include/uapi/linux/virtio_config.h | 7 +- include/uapi/linux/virtio_pci.h | 14 + 18 files changed, 964 insertions(+), 199 deletions(-)
Quoted 2 lines
--
2.31.0
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Xuan Zhuo
reviewerQuoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Xuan Zhuo
The virtio spec already supports the virtio queue reset function. This patch set is to add this function to the kernel. The relevant virtio spec information is here:
Quoted 8 lines
Quoted 4 lines
https://github.com/oasis-tcs/virtio-spec/issues/124Also regarding MMIO support for queue reset, I plan to support it after this patch is passed.
Regarding the spec, there's now an issue proposing
some changes to the interface. What do you think about that proposal? Could you respond on that thread on the virtio TC mailing list?
I have read that thread. And also asked some questions. I will follow that thread.
Grateful.
Quoted 115 lines
Quoted 115 lines
This patch set implements the refactoring of vring. Finally, the
virtuque_resize()interface is provided based on the reset function of the transport layer.Test environment:
Host: 4.19.91
Qemu: QEMU emulator version 6.2.50 (with vq reset support) Test Cmd: ethtool -G eth1 rx $1 tx $2; ethtool -g eth1The default is split mode, modify Qemu virtio-net to add PACKED feature to test packed mode.
Qemu code:
https://github.com/fengidri/qemu/compare/89f3bfa3265554d1d591ee4d7f1197b6e3397e84...masterIn order to simplify the review of this patch set, the function of reusing the old buffers after resize will be introduced in subsequent patch sets.
Please review. Thanks.
v9:
1. Provide avirtqueue_resize()interface directly
2. A patch set including vring resize, virtio pci reset, virtio-net resize
3. No more separate structsv8:
1. Provide avirtqueue_reset()interface directly
2. Split the two patch sets, this is the first part
3. Add independent allocation helper for allocating state, extrav7:
1. fix #6 subject typo
2. fix #6ring_size_in_bytesis uninitialized
3. check by: make W=12v6:
1.virtio_pci: usesynchronize_irq(irq)to sync the irq callbacks
2. Introducevirtqueue_reset_vring()to implement the reset of vring during the reset process. May use the old vring if num of the vq not change.
3.find_vqs()support sizes to special the max size of each vqv5:
1. add virtio-net supportset_ringparamv4:
1. just the code of virtio, without virtio-net
2. Performing reset on a queue is divided into these steps:
1.reset_vq: reset one vq
2. recycle the buffer from vq byvirtqueue_detach_unused_buf()
3. release the ring of the vq byvring_release_virtqueue()
4.enable_reset_vq: re-enable the reset queue
3. Simplify the parameters ofenable_reset_vq()
4. add container structures forvirtio_pci_common_cfgv3:
1. keep vq, irq unreleasedXuan Zhuo (32):
virtio: add helpervirtqueue_get_vring_max_size()
virtio: structvirtio_config_opsadd callbacks forqueue_reset
virtio_ring: update the document of thevirtqueue_detach_unused_buf
for queue reset
virtio_ring: remove the arg vq ofvring_alloc_desc_extra()
virtio_ring: extract the logic of freeing vring
virtio_ring: split: extract the logic of alloc queue
virtio_ring: split: extract the logic of alloc state and extra
virtio_ring: split: extract the logic of attach vring
virtio_ring: split: extract the logic of vq init
virtio_ring: split: introducevirtqueue_reinit_split()
virtio_ring: split: introducevirtqueue_resize_split()
virtio_ring: packed: extract the logic of alloc queue
virtio_ring: packed: extract the logic of alloc state and extra
virtio_ring: packed: extract the logic of attach vring
virtio_ring: packed: extract the logic of vq init
virtio_ring: packed: introducevirtqueue_reinit_packed()
virtio_ring: packed: introducevirtqueue_resize_packed()
virtio_ring: introducevirtqueue_resize()
virtio_pci: structvirtio_pci_common_cfgaddqueue_notify_data
virtio:queue_reset: addVIRTIO_F_RING_RESET
virtio_pci:queue_reset: update structvirtio_pci_common_cfgand
option functions
virtio_pci:queue_reset: extract the logic of active vq for modern pci
virtio_pci:queue_reset: supportVIRTIO_F_RING_RESET
virtio:find_vqs()add arg sizes
virtio_pci: support the arg sizes offind_vqs()
virtio_mmio: support the arg sizes offind_vqs()
virtio: add helpervirtio_find_vqs_ctx_size()
virtio_net: set the default max ring size byfind_vqs()
virtio_net: get ringparam byvirtqueue_get_vring_max_size()
virtio_net: splitfree_unused_bufs()
virtio_net: support rx/tx queue resize
virtio_net: supportset_ringparamarch/um/drivers/virtio_uml.c | 3 +- drivers/net/virtio_net.c | 219 +++++++- drivers/platform/mellanox/mlxbf-tmfifo.c | 3 + drivers/remoteproc/remoteproc_virtio.c | 3 + drivers/s390/virtio/virtio_ccw.c | 4 + drivers/virtio/virtio_mmio.c | 11 +- drivers/virtio/virtio_pci_common.c | 28 +- drivers/virtio/virtio_pci_common.h | 3 +- drivers/virtio/virtio_pci_legacy.c | 8 +- drivers/virtio/virtio_pci_modern.c | 149 +++++- drivers/virtio/virtio_pci_modern_dev.c | 36 ++ drivers/virtio/virtio_ring.c | 626 ++++++++++++++++++----- drivers/virtio/virtio_vdpa.c | 3 + include/linux/virtio.h | 6 + include/linux/virtio_config.h | 38 +- include/linux/virtio_pci_modern.h | 2 + include/uapi/linux/virtio_config.h | 7 +- include/uapi/linux/virtio_pci.h | 14 + 18 files changed, 964 insertions(+), 199 deletions(-)
Quoted 3 lines
Quoted 2 lines
--
2.31.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization