[dpdk-dev] [PATCH 06/10] vdpa/sfc: add support for dev conf and dev close ops

Vijay Kumar Srivastava vsrivast at xilinx.com
Fri Sep 3 15:22:19 CEST 2021


Hi Maxime, 

>-----Original Message-----
>From: Maxime Coquelin <maxime.coquelin at redhat.com>
>Sent: Monday, August 30, 2021 5:06 PM
>To: Vijay Kumar Srivastava <vsrivast at xilinx.com>; dev at dpdk.org
>Cc: chenbo.xia at intel.com; andrew.rybchenko at oktetlabs.ru; Vijay Kumar
>Srivastava <vsrivast at xilinx.com>
>Subject: Re: [PATCH 06/10] vdpa/sfc: add support for dev conf and dev close
>ops
>
>
>
>On 7/6/21 6:44 PM, Vijay Srivastava wrote:
>> From: Vijay Kumar Srivastava <vsrivast at xilinx.com>

[snip]
	
>rte_vfio_container_dma_unmap(vfio_container_fd,
>> +						mem_reg->host_user_addr,
>> +						mem_reg->guest_phys_addr,
>> +						mem_reg->size);
>> +			if (rc < 0) {
>> +				sfc_vdpa_err(dev,
>> +					     "DMA unmap failed : %s",
>> +					     rte_strerror(rte_errno));
>> +				goto error;
>> +			}
>> +		}
>> +	}
>> +
>> +	free(vhost_mem);
>> +
>> +	return 0;
>> +
>> +failed_vfio_dma_map:
>> +	for (j = 0; j < i; j++) {
>> +		mem_reg = &vhost_mem->regions[j];
>> +		rc = rte_vfio_container_dma_unmap(vfio_container_fd,
>> +						  mem_reg->host_user_addr,
>> +						  mem_reg->guest_phys_addr,
>> +						  mem_reg->size);
>> +	}
>> +
>> +error:
>> +	if (vhost_mem)
>
>The NULL check is not necessary, free() takes care of doing it.

OK.

>> +		free(vhost_mem);
>> +
>> +	return rc;
>> +}
>> +
>>  static int
>>  sfc_vdpa_mem_bar_init(struct sfc_vdpa_adapter *sva,
>>  		      const efx_bar_region_t *mem_ebrp) diff --git
>> a/drivers/vdpa/sfc/sfc_vdpa_ops.c b/drivers/vdpa/sfc/sfc_vdpa_ops.c
>
>...
>
>>
>> +static uint64_t
>> +hva_to_gpa(int vid, uint64_t hva)
>> +{
>> +	struct rte_vhost_memory *vhost_mem = NULL;
>> +	struct rte_vhost_mem_region *mem_reg = NULL;
>> +	uint32_t i;
>> +	uint64_t gpa = 0;
>> +
>> +	if (rte_vhost_get_mem_table(vid, &vhost_mem) < 0)
>> +		goto error;
>> +
>> +	for (i = 0; i < vhost_mem->nregions; i++) {
>> +		mem_reg = &vhost_mem->regions[i];
>> +
>> +		if (hva >= mem_reg->host_user_addr &&
>> +				hva < mem_reg->host_user_addr + mem_reg-
>>size) {
>> +			gpa = (hva - mem_reg->host_user_addr) +
>> +				mem_reg->guest_phys_addr;
>> +			break;
>> +		}
>> +	}
>> +
>> +error:
>> +	if (vhost_mem)
>
>Ditto.
>
>> +		free(vhost_mem);
>> +	return gpa;
>> +}
>> +
>> +static int
>> +sfc_vdpa_enable_vfio_intr(struct sfc_vdpa_ops_data *ops_data) {
>> +	int rc;
>> +	int *irq_fd_ptr;
>> +	int vfio_dev_fd;
>> +	uint32_t i, num_vring;
>> +	struct rte_vhost_vring vring;
>> +	struct vfio_irq_set *irq_set;
>> +	struct rte_pci_device *pci_dev;
>> +	char irq_set_buf[SFC_VDPA_MSIX_IRQ_SET_BUF_LEN];
>> +	void *dev;
>> +
>> +	num_vring = rte_vhost_get_vring_num(ops_data->vid);
>> +	dev = ops_data->dev_handle;
>> +	vfio_dev_fd = sfc_vdpa_adapter_by_dev_handle(dev)->vfio_dev_fd;
>> +	pci_dev = sfc_vdpa_adapter_by_dev_handle(dev)->pdev;
>> +
>> +	irq_set = (struct vfio_irq_set *)irq_set_buf;
>> +	irq_set->argsz = sizeof(irq_set_buf);
>> +	irq_set->count = num_vring + 1;
>> +	irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
>> +			 VFIO_IRQ_SET_ACTION_TRIGGER;
>> +	irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX;
>> +	irq_set->start = 0;
>> +	irq_fd_ptr = (int *)&irq_set->data;
>> +	irq_fd_ptr[RTE_INTR_VEC_ZERO_OFFSET] = pci_dev->intr_handle.fd;
>> +
>> +	for (i = 0; i < num_vring; i++) {
>> +		rte_vhost_get_vhost_vring(ops_data->vid, i, &vring);
>
>This function may fail (even if really unlikely that it happens), maybe better to
>avoid using non-initialized callfd value if it happened.
>
OK. I will do it in the v2.

[snip]


More information about the dev mailing list