Skip to content

Commit

Permalink
vDPA/ifcvf: dynamic allocate vq data stores
Browse files Browse the repository at this point in the history
This commit dynamically allocates the data
stores for the virtqueues based on
virtio_pci_common_cfg.num_queues.

Signed-off-by: Zhu Lingshan <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
  • Loading branch information
ls-zhu authored and mstsirkin committed Jul 3, 2023
1 parent bc9a2b3 commit 7712832
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions drivers/vdpa/ifcvf/ifcvf_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev)
}

hw->nr_vring = vp_ioread16(&hw->common_cfg->num_queues);
hw->vring = kzalloc(sizeof(struct vring_info) * hw->nr_vring, GFP_KERNEL);
if (!hw->vring)
return -ENOMEM;

for (i = 0; i < hw->nr_vring; i++) {
vp_iowrite16(i, &hw->common_cfg->queue_select);
Expand Down
2 changes: 1 addition & 1 deletion drivers/vdpa/ifcvf/ifcvf_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct ifcvf_hw {
u64 dev_features;
struct virtio_pci_common_cfg __iomem *common_cfg;
void __iomem *dev_cfg;
struct vring_info vring[IFCVF_MAX_QUEUES];
struct vring_info *vring;
void __iomem * const *base;
char config_msix_name[256];
struct vdpa_callback config_cb;
Expand Down
2 changes: 2 additions & 0 deletions drivers/vdpa/ifcvf/ifcvf_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
return 0;

err:
kfree(ifcvf_mgmt_dev->vf.vring);
kfree(ifcvf_mgmt_dev);
return ret;
}
Expand All @@ -840,6 +841,7 @@ static void ifcvf_remove(struct pci_dev *pdev)

ifcvf_mgmt_dev = pci_get_drvdata(pdev);
vdpa_mgmtdev_unregister(&ifcvf_mgmt_dev->mdev);
kfree(ifcvf_mgmt_dev->vf.vring);
kfree(ifcvf_mgmt_dev);
}

Expand Down

0 comments on commit 7712832

Please sign in to comment.