Skip to content

Commit

Permalink
vdpa/virtio: remove flag of HA context remove
Browse files Browse the repository at this point in the history
The flag ctx_remove_enabled is designed for RPC remove and application
quit, since now application quit will not call device remove, the flag
is not needed anymore.

Signed-off-by: Chenbo Xia <chenbox@nvidia.com>
  • Loading branch information
Ch3n60x authored and kailiangz1 committed Apr 24, 2024
1 parent 6467cbb commit f7336d0
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 59 deletions.
2 changes: 0 additions & 2 deletions app/vfe-vdpa/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,6 @@ void vdpa_with_socket_path_stop(const char *vf_name)
return;
}

rte_vdpa_vf_ctrl_ctx_remove(true);

if (vport->ifname[0] != '\0') {
close_vdpa(vport);
memset(vport, 0, sizeof(*vport));
Expand Down
2 changes: 0 additions & 2 deletions app/vfe-vdpa/vdpa_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ static cJSON *vdpa_pf_dev_remove(const char *pf_name)

virtio_ha_dev_lock();

rte_vdpa_pf_ctrl_ctx_remove(true);

ret = rte_vdpa_pf_dev_remove(pf_name);

virtio_ha_dev_unlock();
Expand Down
10 changes: 1 addition & 9 deletions drivers/common/virtio_mi/lm.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ TAILQ_HEAD(virtio_vdpa_mi_privs, virtio_vdpa_pf_priv) virtio_mi_priv_list =
TAILQ_HEAD_INITIALIZER(virtio_mi_priv_list);
static pthread_mutex_t mi_priv_list_lock = PTHREAD_MUTEX_INITIALIZER;
static struct virtio_ha_pf_drv_ctx cached_ctx;
static bool ctx_remove_enabled;

static struct virtio_admin_ctrl *
virtio_vdpa_send_admin_command_split(struct virtadmin_ctl *avq,
Expand Down Expand Up @@ -1037,12 +1036,6 @@ virtio_vdpa_blk_dev_get_adminq_idx(struct virtio_vdpa_pf_priv *priv __rte_unused
return 0;
}

void
rte_vdpa_pf_ctrl_ctx_remove(bool enable)
{
ctx_remove_enabled = enable;
}

static struct virtio_vdpa_dev_ops virtio_vdpa_net_dev_ops = {
.get_required_features = virtio_vdpa_get_net_dev_required_features,
.get_adminq_idx = virtio_vdpa_net_dev_get_adminq_idx,
Expand Down Expand Up @@ -1213,8 +1206,7 @@ virtio_vdpa_mi_dev_remove(struct rte_pci_device *pci_dev)
pthread_mutex_unlock(&mi_priv_list_lock);

if (found) {
if (ctx_remove_enabled)
virtio_ha_pf_ctx_remove(&priv->pf_name);
virtio_ha_pf_ctx_remove(&priv->pf_name);
virtio_vdpa_admin_queue_free(priv);
virtio_pci_dev_reset(priv->vpdev,VIRTIO_VDPA_REMOVE_RESET_TIME_OUT);
virtio_pci_dev_free(priv->vpdev);
Expand Down
1 change: 0 additions & 1 deletion drivers/common/virtio_mi/version.map
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ DPDK_22 {
rte_vdpa_pf_dev_add;
rte_vdpa_pf_dev_remove;
rte_vdpa_get_pf_list;
rte_vdpa_pf_ctrl_ctx_remove;

local: *;
};
2 changes: 0 additions & 2 deletions drivers/common/virtio_mi/virtio_lm.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,5 @@ int
rte_vdpa_pf_dev_remove(const char *pf_name);
int
rte_vdpa_get_pf_list(struct virtio_vdpa_pf_info *pf_info, int max_pf_num);
void
rte_vdpa_pf_ctrl_ctx_remove(bool enable);

#endif /* _VIRTIO_LM_H_ */
1 change: 0 additions & 1 deletion drivers/vdpa/virtio/version.map
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ DPDK_22 {
rte_vdpa_get_vf_list;
rte_vdpa_get_vf_info;
rte_vdpa_vf_dev_debug;
rte_vdpa_vf_ctrl_ctx_remove;

local: *;
};
69 changes: 28 additions & 41 deletions drivers/vdpa/virtio/virtio_vdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ static TAILQ_HEAD(virtio_vdpa_iommu_domains, virtio_vdpa_iommu_domain) virtio_io


static struct virtio_ha_vf_drv_ctx cached_ctx;
static bool ctx_remove_enabled;

static void
virtio_ha_vf_drv_ctx_set(const struct virtio_dev_name *vf, const void *ctx)
Expand Down Expand Up @@ -802,37 +801,36 @@ virtio_vdpa_dev_cleanup(int vid)
priv->vrings[i]->conf_enable = false;
}

if (ctx_remove_enabled) {
ret = virtio_ha_vf_vhost_fd_remove(&priv->vf_name, &priv->pf_name);
if (ret < 0)
DRV_LOG(ERR, "Failed to remove vhost fd: %s", vdev->device->name);
ret = virtio_ha_vf_vhost_fd_remove(&priv->vf_name, &priv->pf_name);
if (ret < 0)
DRV_LOG(ERR, "Failed to remove vhost fd: %s", vdev->device->name);

ret = virtio_ha_vf_mem_tbl_remove(&priv->vf_name, &priv->pf_name);
if (ret < 0)
DRV_LOG(ERR, "Failed to remove mem table: %s", vdev->device->name);
ret = virtio_ha_vf_mem_tbl_remove(&priv->vf_name, &priv->pf_name);
if (ret < 0)
DRV_LOG(ERR, "Failed to remove mem table: %s", vdev->device->name);

iommu_domain = priv->iommu_domain;
pthread_mutex_lock(&iommu_domain->domain_lock);
if (priv->mem_tbl_set) {
iommu_domain->mem_tbl_ref_cnt--;
priv->mem_tbl_set = false;
}
if (iommu_domain->mem_tbl_ref_cnt == 0) {
for (i = 0; i < iommu_domain->mem.nregions; i++) {
reg = &iommu_domain->mem.regions[i];
if (virtio_vdpa_dev_dma_unmap(priv->vfio_container_fd,
reg->host_phys_addr, reg->host_user_addr, reg->guest_phys_addr,
reg->size) < 0) {
DRV_LOG(ERR, "%s vdpa unmap DMA failed ret:%d",
priv->vdev->device->name, ret);
goto err;
}
iommu_domain = priv->iommu_domain;
pthread_mutex_lock(&iommu_domain->domain_lock);
if (priv->mem_tbl_set) {
iommu_domain->mem_tbl_ref_cnt--;
priv->mem_tbl_set = false;
}
if (iommu_domain->mem_tbl_ref_cnt == 0) {
for (i = 0; i < iommu_domain->mem.nregions; i++) {
reg = &iommu_domain->mem.regions[i];
if (virtio_vdpa_dev_dma_unmap(priv->vfio_container_fd,
reg->host_phys_addr, reg->host_user_addr, reg->guest_phys_addr,
reg->size) < 0) {
DRV_LOG(ERR, "%s vdpa unmap DMA failed ret:%d",
priv->vdev->device->name, ret);
goto err;
}
err:
iommu_domain->mem.nregions = 0;
}
pthread_mutex_unlock(&iommu_domain->domain_lock);
err:
iommu_domain->mem.nregions = 0;
}
pthread_mutex_unlock(&iommu_domain->domain_lock);

return 0;
}

Expand Down Expand Up @@ -1993,15 +1991,6 @@ virtio_vdpa_get_vfid(const char *pf_name, const char *vf_name, int *vfid)
return -ENODEV;
}

/* Control remove/cleanup behavior of this driver. When ctx_remove_enabled is true,
* device context will be removed from HA service, otherwise it will not.
*/
void
rte_vdpa_vf_ctrl_ctx_remove(bool enable)
{
ctx_remove_enabled = enable;
}

static int
virtio_vdpa_dev_do_remove(struct rte_pci_device *pci_dev, struct virtio_vdpa_priv *priv)
{
Expand Down Expand Up @@ -2095,11 +2084,9 @@ virtio_vdpa_dev_do_remove(struct rte_pci_device *pci_dev, struct virtio_vdpa_pri
if (priv->vdpa_dp_map)
rte_memzone_free(priv->vdpa_dp_map);

if (ctx_remove_enabled) {
ret = virtio_ha_vf_devargs_fds_remove(&priv->vf_name, &priv->pf_name);
if (ret < 0)
DRV_LOG(ERR, "Failed to remove vf devargs and fds: %s", priv->vf_name.dev_bdf);
}
ret = virtio_ha_vf_devargs_fds_remove(&priv->vf_name, &priv->pf_name);
if (ret < 0)
DRV_LOG(ERR, "Failed to remove vf devargs and fds: %s", priv->vf_name.dev_bdf);

rte_free(priv);

Expand Down
1 change: 0 additions & 1 deletion drivers/vdpa/virtio/virtio_vdpa.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,4 @@ int virtio_vdpa_dirty_desc_get(struct virtio_vdpa_priv *priv, int qix, uint64_t
int virtio_vdpa_used_vring_addr_get(struct virtio_vdpa_priv *priv, int qix, uint64_t *used_vring_addr, uint32_t *used_vring_len);
const struct rte_memzone * virtio_vdpa_dev_dp_map_get(struct virtio_vdpa_priv *priv, size_t len);
uint64_t virtio_vdpa_gpa_to_hva(int vid, uint64_t gpa);
void rte_vdpa_vf_ctrl_ctx_remove(bool enable);
#endif /* _VIRTIO_VDPA_H_ */

0 comments on commit f7336d0

Please sign in to comment.