Skip to content

Commit cdb4480

Browse files
fengidrimstsirkin
authored andcommitted
virtio_pci: support the arg sizes of find_vqs()
Virtio PCI supports new parameter sizes of find_vqs(). Signed-off-by: Xuan Zhuo <[email protected]> Acked-by: Jason Wang <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent a10fba0 commit cdb4480

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

drivers/virtio/virtio_pci_common.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
174174
static struct virtqueue *vp_setup_vq(struct virtio_device *vdev, unsigned int index,
175175
void (*callback)(struct virtqueue *vq),
176176
const char *name,
177+
u32 size,
177178
bool ctx,
178179
u16 msix_vec)
179180
{
@@ -186,7 +187,7 @@ static struct virtqueue *vp_setup_vq(struct virtio_device *vdev, unsigned int in
186187
if (!info)
187188
return ERR_PTR(-ENOMEM);
188189

189-
vq = vp_dev->setup_vq(vp_dev, info, index, callback, name, ctx,
190+
vq = vp_dev->setup_vq(vp_dev, info, index, callback, name, size, ctx,
190191
msix_vec);
191192
if (IS_ERR(vq))
192193
goto out_info;
@@ -283,7 +284,7 @@ void vp_del_vqs(struct virtio_device *vdev)
283284

284285
static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs,
285286
struct virtqueue *vqs[], vq_callback_t *callbacks[],
286-
const char * const names[], bool per_vq_vectors,
287+
const char * const names[], u32 sizes[], bool per_vq_vectors,
287288
const bool *ctx,
288289
struct irq_affinity *desc)
289290
{
@@ -326,8 +327,8 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs,
326327
else
327328
msix_vec = VP_MSIX_VQ_VECTOR;
328329
vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i],
329-
ctx ? ctx[i] : false,
330-
msix_vec);
330+
sizes ? sizes[i] : 0,
331+
ctx ? ctx[i] : false, msix_vec);
331332
if (IS_ERR(vqs[i])) {
332333
err = PTR_ERR(vqs[i]);
333334
goto error_find;
@@ -357,7 +358,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs,
357358

358359
static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs,
359360
struct virtqueue *vqs[], vq_callback_t *callbacks[],
360-
const char * const names[], const bool *ctx)
361+
const char * const names[], u32 sizes[], const bool *ctx)
361362
{
362363
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
363364
int i, err, queue_idx = 0;
@@ -379,6 +380,7 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs,
379380
continue;
380381
}
381382
vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i],
383+
sizes ? sizes[i] : 0,
382384
ctx ? ctx[i] : false,
383385
VIRTIO_MSI_NO_VECTOR);
384386
if (IS_ERR(vqs[i])) {
@@ -402,15 +404,15 @@ int vp_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
402404
int err;
403405

404406
/* Try MSI-X with one vector per queue. */
405-
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, true, ctx, desc);
407+
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, sizes, true, ctx, desc);
406408
if (!err)
407409
return 0;
408410
/* Fallback: MSI-X with one vector for config, one shared for queues. */
409-
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, false, ctx, desc);
411+
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, sizes, false, ctx, desc);
410412
if (!err)
411413
return 0;
412414
/* Finally fall back to regular interrupts. */
413-
return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names, ctx);
415+
return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names, sizes, ctx);
414416
}
415417

416418
const char *vp_bus_name(struct virtio_device *vdev)

drivers/virtio/virtio_pci_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct virtio_pci_device {
8080
unsigned int idx,
8181
void (*callback)(struct virtqueue *vq),
8282
const char *name,
83+
u32 size,
8384
bool ctx,
8485
u16 msix_vec);
8586
void (*del_vq)(struct virtio_pci_vq_info *info);

drivers/virtio/virtio_pci_legacy.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
112112
unsigned int index,
113113
void (*callback)(struct virtqueue *vq),
114114
const char *name,
115+
u32 size,
115116
bool ctx,
116117
u16 msix_vec)
117118
{
@@ -125,10 +126,13 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
125126
if (!num || vp_legacy_get_queue_enable(&vp_dev->ldev, index))
126127
return ERR_PTR(-ENOENT);
127128

129+
if (!size || size > num)
130+
size = num;
131+
128132
info->msix_vector = msix_vec;
129133

130134
/* create the vring */
131-
vq = vring_create_virtqueue(index, num,
135+
vq = vring_create_virtqueue(index, size,
132136
VIRTIO_PCI_VRING_ALIGN, &vp_dev->vdev,
133137
true, false, ctx,
134138
vp_notify, callback, name);

drivers/virtio/virtio_pci_modern.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
293293
unsigned int index,
294294
void (*callback)(struct virtqueue *vq),
295295
const char *name,
296+
u32 size,
296297
bool ctx,
297298
u16 msix_vec)
298299
{
@@ -310,15 +311,18 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
310311
if (!num || vp_modern_get_queue_enable(mdev, index))
311312
return ERR_PTR(-ENOENT);
312313

313-
if (num & (num - 1)) {
314-
dev_warn(&vp_dev->pci_dev->dev, "bad queue size %u", num);
314+
if (!size || size > num)
315+
size = num;
316+
317+
if (size & (size - 1)) {
318+
dev_warn(&vp_dev->pci_dev->dev, "bad queue size %u", size);
315319
return ERR_PTR(-EINVAL);
316320
}
317321

318322
info->msix_vector = msix_vec;
319323

320324
/* create the vring */
321-
vq = vring_create_virtqueue(index, num,
325+
vq = vring_create_virtqueue(index, size,
322326
SMP_CACHE_BYTES, &vp_dev->vdev,
323327
true, true, ctx,
324328
vp_notify, callback, name);

0 commit comments

Comments
 (0)