Skip to content

Commit 0b7359c

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio updates from Michael Tsirkin: - vdpa/mlx5: support for resumable vqs - virtio_scsi: mq_poll support - 3virtio_pmem: support SHMEM_REGION - virtio_balloon: stay awake while adjusting balloon - virtio: support for no-reset virtio PCI PM - Fixes, cleanups * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vdpa/mlx5: Add mkey leak detection vdpa/mlx5: Introduce reference counting to mrs vdpa/mlx5: Use vq suspend/resume during .set_map vdpa/mlx5: Mark vq state for modification in hw vq vdpa/mlx5: Mark vq addrs for modification in hw vq vdpa/mlx5: Introduce per vq and device resume vdpa/mlx5: Allow modifying multiple vq fields in one modify command vdpa/mlx5: Expose resumable vq capability vdpa: Block vq property changes in DRIVER_OK vdpa: Track device suspended state scsi: virtio_scsi: Add mq_poll support virtio_pmem: support feature SHMEM_REGION virtio_balloon: stay awake while adjusting balloon vdpa: Remove usage of the deprecated ida_simple_xx() API virtio: Add support for no-reset virtio PCI PM virtio_net: fix missing dma unmap for resize vhost-vdpa: account iommu allocations vdpa: Fix an error handling path in eni_vdpa_probe()
2 parents da3c45c + f16d651 commit 0b7359c

13 files changed

Lines changed: 478 additions & 65 deletions

File tree

drivers/nvdimm/virtio_pmem.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,27 @@ static int init_vq(struct virtio_pmem *vpmem)
2929
return 0;
3030
};
3131

32+
static int virtio_pmem_validate(struct virtio_device *vdev)
33+
{
34+
struct virtio_shm_region shm_reg;
35+
36+
if (virtio_has_feature(vdev, VIRTIO_PMEM_F_SHMEM_REGION) &&
37+
!virtio_get_shm_region(vdev, &shm_reg, (u8)VIRTIO_PMEM_SHMEM_REGION_ID)
38+
) {
39+
dev_notice(&vdev->dev, "failed to get shared memory region %d\n",
40+
VIRTIO_PMEM_SHMEM_REGION_ID);
41+
__virtio_clear_bit(vdev, VIRTIO_PMEM_F_SHMEM_REGION);
42+
}
43+
return 0;
44+
}
45+
3246
static int virtio_pmem_probe(struct virtio_device *vdev)
3347
{
3448
struct nd_region_desc ndr_desc = {};
3549
struct nd_region *nd_region;
3650
struct virtio_pmem *vpmem;
3751
struct resource res;
52+
struct virtio_shm_region shm_reg;
3853
int err = 0;
3954

4055
if (!vdev->config->get) {
@@ -57,10 +72,16 @@ static int virtio_pmem_probe(struct virtio_device *vdev)
5772
goto out_err;
5873
}
5974

60-
virtio_cread_le(vpmem->vdev, struct virtio_pmem_config,
61-
start, &vpmem->start);
62-
virtio_cread_le(vpmem->vdev, struct virtio_pmem_config,
63-
size, &vpmem->size);
75+
if (virtio_has_feature(vdev, VIRTIO_PMEM_F_SHMEM_REGION)) {
76+
virtio_get_shm_region(vdev, &shm_reg, (u8)VIRTIO_PMEM_SHMEM_REGION_ID);
77+
vpmem->start = shm_reg.addr;
78+
vpmem->size = shm_reg.len;
79+
} else {
80+
virtio_cread_le(vpmem->vdev, struct virtio_pmem_config,
81+
start, &vpmem->start);
82+
virtio_cread_le(vpmem->vdev, struct virtio_pmem_config,
83+
size, &vpmem->size);
84+
}
6485

6586
res.start = vpmem->start;
6687
res.end = vpmem->start + vpmem->size - 1;
@@ -122,10 +143,17 @@ static void virtio_pmem_remove(struct virtio_device *vdev)
122143
virtio_reset_device(vdev);
123144
}
124145

146+
static unsigned int features[] = {
147+
VIRTIO_PMEM_F_SHMEM_REGION,
148+
};
149+
125150
static struct virtio_driver virtio_pmem_driver = {
151+
.feature_table = features,
152+
.feature_table_size = ARRAY_SIZE(features),
126153
.driver.name = KBUILD_MODNAME,
127154
.driver.owner = THIS_MODULE,
128155
.id_table = id_table,
156+
.validate = virtio_pmem_validate,
129157
.probe = virtio_pmem_probe,
130158
.remove = virtio_pmem_remove,
131159
};

drivers/scsi/virtio_scsi.c

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
#define VIRTIO_SCSI_EVENT_LEN 8
3838
#define VIRTIO_SCSI_VQ_BASE 2
3939

40+
static unsigned int virtscsi_poll_queues;
41+
module_param(virtscsi_poll_queues, uint, 0644);
42+
MODULE_PARM_DESC(virtscsi_poll_queues,
43+
"The number of dedicated virtqueues for polling I/O");
44+
4045
/* Command queue element */
4146
struct virtio_scsi_cmd {
4247
struct scsi_cmnd *sc;
@@ -76,6 +81,7 @@ struct virtio_scsi {
7681
struct virtio_scsi_event_node event_list[VIRTIO_SCSI_EVENT_LEN];
7782

7883
u32 num_queues;
84+
int io_queues[HCTX_MAX_TYPES];
7985

8086
struct hlist_node node;
8187

@@ -722,9 +728,49 @@ static int virtscsi_abort(struct scsi_cmnd *sc)
722728
static void virtscsi_map_queues(struct Scsi_Host *shost)
723729
{
724730
struct virtio_scsi *vscsi = shost_priv(shost);
725-
struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
731+
int i, qoff;
732+
733+
for (i = 0, qoff = 0; i < shost->nr_maps; i++) {
734+
struct blk_mq_queue_map *map = &shost->tag_set.map[i];
735+
736+
map->nr_queues = vscsi->io_queues[i];
737+
map->queue_offset = qoff;
738+
qoff += map->nr_queues;
739+
740+
if (map->nr_queues == 0)
741+
continue;
742+
743+
/*
744+
* Regular queues have interrupts and hence CPU affinity is
745+
* defined by the core virtio code, but polling queues have
746+
* no interrupts so we let the block layer assign CPU affinity.
747+
*/
748+
if (i == HCTX_TYPE_POLL)
749+
blk_mq_map_queues(map);
750+
else
751+
blk_mq_virtio_map_queues(map, vscsi->vdev, 2);
752+
}
753+
}
754+
755+
static int virtscsi_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
756+
{
757+
struct virtio_scsi *vscsi = shost_priv(shost);
758+
struct virtio_scsi_vq *virtscsi_vq = &vscsi->req_vqs[queue_num];
759+
unsigned long flags;
760+
unsigned int len;
761+
int found = 0;
762+
void *buf;
763+
764+
spin_lock_irqsave(&virtscsi_vq->vq_lock, flags);
765+
766+
while ((buf = virtqueue_get_buf(virtscsi_vq->vq, &len)) != NULL) {
767+
virtscsi_complete_cmd(vscsi, buf);
768+
found++;
769+
}
770+
771+
spin_unlock_irqrestore(&virtscsi_vq->vq_lock, flags);
726772

727-
blk_mq_virtio_map_queues(qmap, vscsi->vdev, 2);
773+
return found;
728774
}
729775

730776
static void virtscsi_commit_rqs(struct Scsi_Host *shost, u16 hwq)
@@ -751,6 +797,7 @@ static const struct scsi_host_template virtscsi_host_template = {
751797
.this_id = -1,
752798
.cmd_size = sizeof(struct virtio_scsi_cmd),
753799
.queuecommand = virtscsi_queuecommand,
800+
.mq_poll = virtscsi_mq_poll,
754801
.commit_rqs = virtscsi_commit_rqs,
755802
.change_queue_depth = virtscsi_change_queue_depth,
756803
.eh_abort_handler = virtscsi_abort,
@@ -795,13 +842,14 @@ static int virtscsi_init(struct virtio_device *vdev,
795842
{
796843
int err;
797844
u32 i;
798-
u32 num_vqs;
845+
u32 num_vqs, num_poll_vqs, num_req_vqs;
799846
vq_callback_t **callbacks;
800847
const char **names;
801848
struct virtqueue **vqs;
802849
struct irq_affinity desc = { .pre_vectors = 2 };
803850

804-
num_vqs = vscsi->num_queues + VIRTIO_SCSI_VQ_BASE;
851+
num_req_vqs = vscsi->num_queues;
852+
num_vqs = num_req_vqs + VIRTIO_SCSI_VQ_BASE;
805853
vqs = kmalloc_array(num_vqs, sizeof(struct virtqueue *), GFP_KERNEL);
806854
callbacks = kmalloc_array(num_vqs, sizeof(vq_callback_t *),
807855
GFP_KERNEL);
@@ -812,15 +860,31 @@ static int virtscsi_init(struct virtio_device *vdev,
812860
goto out;
813861
}
814862

863+
num_poll_vqs = min_t(unsigned int, virtscsi_poll_queues,
864+
num_req_vqs - 1);
865+
vscsi->io_queues[HCTX_TYPE_DEFAULT] = num_req_vqs - num_poll_vqs;
866+
vscsi->io_queues[HCTX_TYPE_READ] = 0;
867+
vscsi->io_queues[HCTX_TYPE_POLL] = num_poll_vqs;
868+
869+
dev_info(&vdev->dev, "%d/%d/%d default/read/poll queues\n",
870+
vscsi->io_queues[HCTX_TYPE_DEFAULT],
871+
vscsi->io_queues[HCTX_TYPE_READ],
872+
vscsi->io_queues[HCTX_TYPE_POLL]);
873+
815874
callbacks[0] = virtscsi_ctrl_done;
816875
callbacks[1] = virtscsi_event_done;
817876
names[0] = "control";
818877
names[1] = "event";
819-
for (i = VIRTIO_SCSI_VQ_BASE; i < num_vqs; i++) {
878+
for (i = VIRTIO_SCSI_VQ_BASE; i < num_vqs - num_poll_vqs; i++) {
820879
callbacks[i] = virtscsi_req_done;
821880
names[i] = "request";
822881
}
823882

883+
for (; i < num_vqs; i++) {
884+
callbacks[i] = NULL;
885+
names[i] = "request_poll";
886+
}
887+
824888
/* Discover virtqueues and write information to configuration. */
825889
err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
826890
if (err)
@@ -874,6 +938,7 @@ static int virtscsi_probe(struct virtio_device *vdev)
874938

875939
sg_elems = virtscsi_config_get(vdev, seg_max) ?: 1;
876940
shost->sg_tablesize = sg_elems;
941+
shost->nr_maps = 1;
877942
vscsi = shost_priv(shost);
878943
vscsi->vdev = vdev;
879944
vscsi->num_queues = num_queues;
@@ -883,6 +948,9 @@ static int virtscsi_probe(struct virtio_device *vdev)
883948
if (err)
884949
goto virtscsi_init_failed;
885950

951+
if (vscsi->io_queues[HCTX_TYPE_POLL])
952+
shost->nr_maps = HCTX_TYPE_POLL + 1;
953+
886954
shost->can_queue = virtqueue_get_vring_size(vscsi->req_vqs[0].vq);
887955

888956
cmd_per_lun = virtscsi_config_get(vdev, cmd_per_lun) ?: 1;

drivers/vdpa/alibaba/eni_vdpa.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static int eni_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
497497
if (!eni_vdpa->vring) {
498498
ret = -ENOMEM;
499499
ENI_ERR(pdev, "failed to allocate virtqueues\n");
500-
goto err;
500+
goto err_remove_vp_legacy;
501501
}
502502

503503
for (i = 0; i < eni_vdpa->queues; i++) {
@@ -509,11 +509,13 @@ static int eni_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
509509
ret = vdpa_register_device(&eni_vdpa->vdpa, eni_vdpa->queues);
510510
if (ret) {
511511
ENI_ERR(pdev, "failed to register to vdpa bus\n");
512-
goto err;
512+
goto err_remove_vp_legacy;
513513
}
514514

515515
return 0;
516516

517+
err_remove_vp_legacy:
518+
vp_legacy_remove(&eni_vdpa->ldev);
517519
err:
518520
put_device(&eni_vdpa->vdpa.dev);
519521
return ret;

drivers/vdpa/mlx5/core/mlx5_vdpa.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ struct mlx5_vdpa_mr {
3535
struct vhost_iotlb *iotlb;
3636

3737
bool user_mr;
38+
39+
refcount_t refcount;
40+
struct list_head mr_list;
3841
};
3942

4043
struct mlx5_vdpa_resources {
@@ -93,6 +96,7 @@ struct mlx5_vdpa_dev {
9396
u32 generation;
9497

9598
struct mlx5_vdpa_mr *mr[MLX5_VDPA_NUM_AS];
99+
struct list_head mr_list_head;
96100
/* serialize mr access */
97101
struct mutex mr_mtx;
98102
struct mlx5_control_vq cvq;
@@ -118,8 +122,10 @@ int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey);
118122
struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
119123
struct vhost_iotlb *iotlb);
120124
void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev);
121-
void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev,
122-
struct mlx5_vdpa_mr *mr);
125+
void mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev,
126+
struct mlx5_vdpa_mr *mr);
127+
void mlx5_vdpa_put_mr(struct mlx5_vdpa_dev *mvdev,
128+
struct mlx5_vdpa_mr *mr);
123129
void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev,
124130
struct mlx5_vdpa_mr *mr,
125131
unsigned int asid);

0 commit comments

Comments
 (0)