Message ID | 20220406034346.74409-7-xuanzhuo@linux.alibaba.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | virtio pci support VIRTIO_F_RING_RESET (refactor vring) | expand |
在 2022/4/6 上午11:43, 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 <xuanzhuo@linux.alibaba.com> > --- > drivers/virtio/virtio_ring.c | 53 ++++++++++++++++++++++++------------ > 1 file changed, 36 insertions(+), 17 deletions(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 33fddfb907a6..72d5ae063fa0 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -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, This is not used in this function. Thanks > + 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); >
On Tue, 12 Apr 2022 11:22:33 +0800, Jason Wang <jasowang@redhat.com> wrote: > > 在 2022/4/6 上午11:43, 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 <xuanzhuo@linux.alibaba.com> > > --- > > drivers/virtio/virtio_ring.c | 53 ++++++++++++++++++++++++------------ > > 1 file changed, 36 insertions(+), 17 deletions(-) > > > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > > index 33fddfb907a6..72d5ae063fa0 100644 > > --- a/drivers/virtio/virtio_ring.c > > +++ b/drivers/virtio/virtio_ring.c > > @@ -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, > > > This is not used in this function. The next version will fix it. Thanks. > > Thanks > > > > + 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); > > >
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 33fddfb907a6..72d5ae063fa0 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -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);
Separate the logic of split to create vring queue. This feature is required for subsequent virtuqueue reset vring. Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> --- drivers/virtio/virtio_ring.c | 53 ++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 17 deletions(-)