[dpdk-dev] [PATCH v1 6/7] eal/interrupts: make interrupt handle structure opaque

Dmitry Kozlyuk dmitry.kozliuk at gmail.com
Sun Oct 3 20:16:19 CEST 2021


2021-09-03 18:11 (UTC+0530), Harman Kalra:
> [...]
> @@ -31,11 +54,40 @@ struct rte_intr_handle *rte_intr_handle_instance_alloc(int size,
>  	}
>  
>  	for (i = 0; i < size; i++) {
> +		if (from_hugepage)
> +			intr_handle[i].efds = rte_zmalloc(NULL,
> +				RTE_MAX_RXTX_INTR_VEC_ID * sizeof(uint32_t), 0);
> +		else
> +			intr_handle[i].efds = calloc(1,
> +				   RTE_MAX_RXTX_INTR_VEC_ID * sizeof(uint32_t));
> +		if (!intr_handle[i].efds) {
> +			RTE_LOG(ERR, EAL, "Fail to allocate event fd list\n");
> +			rte_errno = ENOMEM;
> +			goto fail;
> +		}
> +
> +		if (from_hugepage)
> +			intr_handle[i].elist = rte_zmalloc(NULL,
> +					RTE_MAX_RXTX_INTR_VEC_ID *
> +					sizeof(struct rte_epoll_event), 0);
> +		else
> +			intr_handle[i].elist = calloc(1,
> +					RTE_MAX_RXTX_INTR_VEC_ID *
> +					sizeof(struct rte_epoll_event));
> +		if (!intr_handle[i].elist) {
> +			RTE_LOG(ERR, EAL, "fail to allocate event fd list\n");
> +			rte_errno = ENOMEM;
> +			goto fail;
> +		}
>  		intr_handle[i].nb_intr = RTE_MAX_RXTX_INTR_VEC_ID;
>  		intr_handle[i].alloc_from_hugepage = from_hugepage;
>  	}
>  
>  	return intr_handle;
> +fail:
> +	free(intr_handle->efds);
> +	free(intr_handle);
> +	return NULL;

This is incorrect if "from_hugepage" is set.

>  }
>  
>  struct rte_intr_handle *rte_intr_handle_instance_index_get(
> @@ -73,12 +125,48 @@ int rte_intr_handle_instance_index_set(struct rte_intr_handle *intr_handle,
>  	}
>  
>  	intr_handle[index].fd = src->fd;
> -	intr_handle[index].vfio_dev_fd = src->vfio_dev_fd;
> +	intr_handle[index].dev_fd = src->dev_fd;
> +
>  	intr_handle[index].type = src->type;
>  	intr_handle[index].max_intr = src->max_intr;
>  	intr_handle[index].nb_efd = src->nb_efd;
>  	intr_handle[index].efd_counter_size = src->efd_counter_size;
>  
> +	if (intr_handle[index].nb_intr != src->nb_intr) {
> +		if (src->alloc_from_hugepage)
> +			intr_handle[index].efds =
> +				rte_realloc(intr_handle[index].efds,
> +					    src->nb_intr *
> +					    sizeof(uint32_t), 0);
> +		else
> +			intr_handle[index].efds =
> +				realloc(intr_handle[index].efds,
> +					src->nb_intr * sizeof(uint32_t));
> +		if (intr_handle[index].efds == NULL) {
> +			RTE_LOG(ERR, EAL, "Failed to realloc the efds list");
> +			rte_errno = ENOMEM;
> +			goto fail;
> +		}
> +
> +		if (src->alloc_from_hugepage)
> +			intr_handle[index].elist =
> +				rte_realloc(intr_handle[index].elist,
> +					    src->nb_intr *
> +					    sizeof(struct rte_epoll_event), 0);
> +		else
> +			intr_handle[index].elist =
> +				realloc(intr_handle[index].elist,
> +					src->nb_intr *
> +					sizeof(struct rte_epoll_event));
> +		if (intr_handle[index].elist == NULL) {
> +			RTE_LOG(ERR, EAL, "Failed to realloc the event list");
> +			rte_errno = ENOMEM;
> +			goto fail;
> +		}
> +
> +		intr_handle[index].nb_intr = src->nb_intr;
> +	}
> +

This implementation leaves "intr_handle" in an invalid state
and leaks memory on error paths.

>  	memcpy(intr_handle[index].efds, src->efds, src->nb_intr);
>  	memcpy(intr_handle[index].elist, src->elist, src->nb_intr);
>  
> @@ -87,6 +175,45 @@ int rte_intr_handle_instance_index_set(struct rte_intr_handle *intr_handle,
>  	return rte_errno;
>  }
>  
> +int rte_intr_handle_event_list_update(struct rte_intr_handle *intr_handle,
> +				      int size)
> +{
> +	if (intr_handle == NULL) {
> +		RTE_LOG(ERR, EAL, "Interrupt instance unallocated\n");
> +		rte_errno = ENOTSUP;
> +		goto fail;
> +	}
> +
> +	if (size == 0) {
> +		RTE_LOG(ERR, EAL, "Size can't be zero\n");
> +		rte_errno = EINVAL;
> +		goto fail;
> +	}
> +
> +	intr_handle->efds = realloc(intr_handle->efds,
> +					  size * sizeof(uint32_t));
> +	if (intr_handle->efds == NULL) {
> +		RTE_LOG(ERR, EAL, "Failed to realloc the efds list");
> +		rte_errno = ENOMEM;
> +		goto fail;
> +	}
> +
> +	intr_handle->elist = realloc(intr_handle->elist,
> +				     size * sizeof(struct rte_epoll_event));
> +	if (intr_handle->elist == NULL) {
> +		RTE_LOG(ERR, EAL, "Failed to realloc the event list");
> +		rte_errno = ENOMEM;
> +		goto fail;
> +	}
> +
> +	intr_handle->nb_intr = size;
> +
> +	return 0;
> +fail:
> +	return rte_errno;
> +}
> +
> +

Same here.

>  [...]
> diff --git a/lib/eal/include/rte_interrupts.h b/lib/eal/include/rte_interrupts.h
> index afc3262967..7dfb849eea 100644
> --- a/lib/eal/include/rte_interrupts.h
> +++ b/lib/eal/include/rte_interrupts.h
> @@ -25,9 +25,29 @@ extern "C" {
>  /** Interrupt handle */
>  struct rte_intr_handle;
>  
> -#define RTE_INTR_HANDLE_DEFAULT_SIZE  1
> +#define RTE_MAX_RXTX_INTR_VEC_ID      512
> +#define RTE_INTR_VEC_ZERO_OFFSET      0
> +#define RTE_INTR_VEC_RXTX_OFFSET      1
> +
> +/**
> + * The interrupt source type, e.g. UIO, VFIO, ALARM etc.
> + */
> +enum rte_intr_handle_type {
> +	RTE_INTR_HANDLE_UNKNOWN = 0,  /**< generic unknown handle */
> +	RTE_INTR_HANDLE_UIO,          /**< uio device handle */
> +	RTE_INTR_HANDLE_UIO_INTX,     /**< uio generic handle */
> +	RTE_INTR_HANDLE_VFIO_LEGACY,  /**< vfio device handle (legacy) */
> +	RTE_INTR_HANDLE_VFIO_MSI,     /**< vfio device handle (MSI) */
> +	RTE_INTR_HANDLE_VFIO_MSIX,    /**< vfio device handle (MSIX) */
> +	RTE_INTR_HANDLE_ALARM,        /**< alarm handle */
> +	RTE_INTR_HANDLE_EXT,          /**< external handler */
> +	RTE_INTR_HANDLE_VDEV,         /**< virtual device */
> +	RTE_INTR_HANDLE_DEV_EVENT,    /**< device event handle */
> +	RTE_INTR_HANDLE_VFIO_REQ,     /**< VFIO request handle */
> +	RTE_INTR_HANDLE_MAX           /**< count of elements */

Enums shouldn't have a _MAX member, can we remove it?

> +};
>  
> -#include "rte_eal_interrupts.h"
> +#define RTE_INTR_HANDLE_DEFAULT_SIZE  1

I find this constant more cluttering call sites than helpful.
If a handle is allocated with a calloc-like function, plain 1 reads just fine.


More information about the dev mailing list