Skip to content

Commit 1d24692

Browse files
YongjiXiemstsirkin
authored andcommitted
vdpa: Add set/get_vq_affinity callbacks in vdpa_config_ops
This introduces set/get_vq_affinity callbacks in vdpa_config_ops to support virtqueue affinity management for vdpa device drivers. Signed-off-by: Xie Yongji <[email protected]> Acked-by: Jason Wang <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent aaf0594 commit 1d24692

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

drivers/virtio/virtio_vdpa.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,32 @@ static const char *virtio_vdpa_bus_name(struct virtio_device *vdev)
337337
return dev_name(&vdpa->dev);
338338
}
339339

340+
static int virtio_vdpa_set_vq_affinity(struct virtqueue *vq,
341+
const struct cpumask *cpu_mask)
342+
{
343+
struct virtio_vdpa_device *vd_dev = to_virtio_vdpa_device(vq->vdev);
344+
struct vdpa_device *vdpa = vd_dev->vdpa;
345+
const struct vdpa_config_ops *ops = vdpa->config;
346+
unsigned int index = vq->index;
347+
348+
if (ops->set_vq_affinity)
349+
return ops->set_vq_affinity(vdpa, index, cpu_mask);
350+
351+
return 0;
352+
}
353+
354+
static const struct cpumask *
355+
virtio_vdpa_get_vq_affinity(struct virtio_device *vdev, int index)
356+
{
357+
struct vdpa_device *vdpa = vd_get_vdpa(vdev);
358+
const struct vdpa_config_ops *ops = vdpa->config;
359+
360+
if (ops->get_vq_affinity)
361+
return ops->get_vq_affinity(vdpa, index);
362+
363+
return NULL;
364+
}
365+
340366
static const struct virtio_config_ops virtio_vdpa_config_ops = {
341367
.get = virtio_vdpa_get,
342368
.set = virtio_vdpa_set,
@@ -349,6 +375,8 @@ static const struct virtio_config_ops virtio_vdpa_config_ops = {
349375
.get_features = virtio_vdpa_get_features,
350376
.finalize_features = virtio_vdpa_finalize_features,
351377
.bus_name = virtio_vdpa_bus_name,
378+
.set_vq_affinity = virtio_vdpa_set_vq_affinity,
379+
.get_vq_affinity = virtio_vdpa_get_vq_affinity,
352380
};
353381

354382
static void virtio_vdpa_release_dev(struct device *_d)

include/linux/vdpa.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ struct vdpa_map_file {
250250
* @vdev: vdpa device
251251
* Returns the iova range supported by
252252
* the device.
253+
* @set_vq_affinity: Set the affinity of virtqueue (optional)
254+
* @vdev: vdpa device
255+
* @idx: virtqueue index
256+
* @cpu_mask: the affinity mask
257+
* Returns integer: success (0) or error (< 0)
258+
* @get_vq_affinity: Get the affinity of virtqueue (optional)
259+
* @vdev: vdpa device
260+
* @idx: virtqueue index
261+
* Returns the affinity mask
253262
* @set_group_asid: Set address space identifier for a
254263
* virtqueue group (optional)
255264
* @vdev: vdpa device
@@ -340,6 +349,10 @@ struct vdpa_config_ops {
340349
const void *buf, unsigned int len);
341350
u32 (*get_generation)(struct vdpa_device *vdev);
342351
struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);
352+
int (*set_vq_affinity)(struct vdpa_device *vdev, u16 idx,
353+
const struct cpumask *cpu_mask);
354+
const struct cpumask *(*get_vq_affinity)(struct vdpa_device *vdev,
355+
u16 idx);
343356

344357
/* DMA ops */
345358
int (*set_map)(struct vdpa_device *vdev, unsigned int asid,

0 commit comments

Comments
 (0)