Skip to content

Commit

Permalink
Fix async wait context fds in case of failure
Browse files Browse the repository at this point in the history
Add warning messages to distinguish failure cases
Rename variables to use underscores instead of camelCase

Change-Id: Ib3f9c27343da30863f72b2ee07342bf607f93ef0
Signed-off-by: Steve Linsell <stevenx.linsell@intel.com>
  • Loading branch information
agrandi authored and stevelinsell committed Feb 3, 2017
1 parent 47f18b2 commit 8758644
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 181 deletions.
119 changes: 80 additions & 39 deletions e_qat.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ int qat_is_event_driven()
return enable_event_driven_polling;
}


/******************************************************************************
* function:
* incr_curr_inst(void)
Expand All @@ -227,42 +228,47 @@ static inline void incr_curr_inst(void)
******************************************************************************/
CpaInstanceHandle get_next_inst(void)
{
CpaInstanceHandle instanceHandle = NULL;
CpaInstanceHandle instance_handle = NULL;
ENGINE* e = NULL;

if (1 == enable_instance_for_thread) {
instanceHandle = pthread_getspecific(qatInstanceForThread);
instance_handle = pthread_getspecific(qatInstanceForThread);
/* If no thread specific data is found then return NULL
as there should be as the flag is set */
if (instanceHandle == NULL)
return instanceHandle;
if (instance_handle == NULL) {
WARN("[%s] Could not find thread specific data\n", __func__);
return instance_handle;
}
}

e = ENGINE_by_id(engine_qat_id);
if(e == NULL) {
instanceHandle = NULL;
return instanceHandle;
WARN("[%s] Function ENGINE_by_id returned NULL\n", __func__);
instance_handle = NULL;
return instance_handle;
}

if(!qat_engine_init(e)){
instanceHandle = NULL;
return instanceHandle;
WARN("[%s] Failure in qat_engine_init function\n", __func__);
instance_handle = NULL;
return instance_handle;
}

/* Anytime we use external polling then we want to loop
through the instances. Any time we are using internal polling
then we also want to loop through the instances assuming
one was not retrieved from thread specific data. */
if (1 == enable_external_polling || instanceHandle == NULL)
if (1 == enable_external_polling || instance_handle == NULL)
{
if (qat_instance_handles) {
instanceHandle = qat_instance_handles[curr_inst];
instance_handle = qat_instance_handles[curr_inst];
incr_curr_inst();
} else {
instanceHandle = NULL;
WARN("[%s] qat_instance_handles is NULL\n", __func__);
instance_handle = NULL;
}
}
return instanceHandle;
return instance_handle;
}

static void engine_fork_handler(void)
Expand Down Expand Up @@ -307,15 +313,15 @@ void qat_set_instance_for_thread(long instanceNum)

/******************************************************************************
* function:
* initOpDone(struct op_done *opDone)
* qat_init_op_done(struct op_done *opDone)
*
* @param opDone [IN] - pointer to op done callback structure
*
* description:
* Initialise the QAT operation "done" callback structure.
*
******************************************************************************/
void initOpDone(struct op_done *opDone)
void qat_init_op_done(struct op_done *opDone)
{
if (opDone == NULL) {
return;
Expand All @@ -330,18 +336,18 @@ void initOpDone(struct op_done *opDone)

/******************************************************************************
* function:
* initOpDonePipe(struct op_done_pipe *opdpipe, unsigned int npipes)
* qat_init_op_done_pipe(struct op_done_pipe *opdpipe, unsigned int npipes)
*
* @param opd [IN] - pointer to op_done_pipe callback structure
* @param npipes [IN] - number of pipes in the pipeline
* @param opdpipe [IN] - pointer to op_done_pipe callback structure
* @param npipes [IN] - number of pipes in the pipeline
*
* description:
* Initialise the QAT chained operation "done" callback structure.
* Setup async event notification if required. The function returns
* 1 for success and 0 for failure.
*
******************************************************************************/
int initOpDonePipe(struct op_done_pipe *opdpipe, unsigned int npipes)
int qat_init_op_done_pipe(struct op_done_pipe *opdpipe, unsigned int npipes)
{
if (opdpipe == NULL)
return 0;
Expand All @@ -358,7 +364,7 @@ int initOpDonePipe(struct op_done_pipe *opdpipe, unsigned int npipes)
if (opdpipe->opDone.job != NULL &&
(qat_setup_async_event_notification(0) == 0)) {
WARN("[%s]Failure to setup async event notifications\n", __func__);
cleanupOpDonePipe(opdpipe);
qat_cleanup_op_done_pipe(opdpipe);
return 0;
}

Expand All @@ -367,15 +373,15 @@ int initOpDonePipe(struct op_done_pipe *opdpipe, unsigned int npipes)

/******************************************************************************
* function:
* cleanupOpDone(struct op_done *opDone)
* qat_cleanup_op_done(struct op_done *opDone)
*
* @param opDone [IN] - pointer to op done callback structure
*
* description:
* Cleanup the data in the "done" callback structure.
*
******************************************************************************/
void cleanupOpDone(struct op_done *opDone)
void qat_cleanup_op_done(struct op_done *opDone)
{
if (opDone == NULL) {
return;
Expand All @@ -393,15 +399,15 @@ void cleanupOpDone(struct op_done *opDone)

/******************************************************************************
* function:
* cleanupOpDonePipe(struct op_done_pipe *opDone)
* qat_cleanup_op_done_pipe(struct op_done_pipe *opDone)
*
* @param opDone [IN] - pointer to op_done_pipe callback structure
*
* description:
* Cleanup the QAT chained operation "done" callback structure.
*
******************************************************************************/
void cleanupOpDonePipe(struct op_done_pipe *opdone)
void qat_cleanup_op_done_pipe(struct op_done_pipe *opdone)
{
if (opdone == NULL)
return;
Expand Down Expand Up @@ -458,26 +464,25 @@ void qat_crypto_callbackFn(void *callbackTag, CpaStatus status,

/******************************************************************************
* function:
* CpaStatus myPerformOp(const CpaInstanceHandle instanceHandle,
* CpaStatus myPerformOp(const CpaInstanceHandle instance_handle,
* void * pCallbackTag,
* const CpaCySymOpData *pOpData,
* const CpaBufferList *pSrcBuffer,
* CpaBufferList *pDstBuffer,
* CpaBoolean *pVerifyResult)
*
* @param ih [IN] - Instance handle
* @param instanceHandle [IN] - Instance handle
* @param pCallbackTag [IN] - Pointer to op_done struct
* @param pOpData [IN] - Operation parameters
* @param pSrcBuffer [IN] - Source buffer list
* @param pDstBuffer [OUT] - Destination buffer list
* @param pVerifyResult [OUT] - Whether hash verified or not
* @param instance_handle [IN] - Instance handle
* @param pCallbackTag [IN] - Pointer to op_done struct
* @param pOpData [IN] - Operation parameters
* @param pSrcBuffer [IN] - Source buffer list
* @param pDstBuffer [OUT] - Destination buffer list
* @param pVerifyResult [OUT] - Whether hash verified or not
*
* description:
* Wrapper around cpaCySymPerformOp which handles retries for us.
*
******************************************************************************/
CpaStatus myPerformOp(const CpaInstanceHandle instanceHandle,
CpaStatus myPerformOp(const CpaInstanceHandle instance_handle,
void *pCallbackTag,
const CpaCySymOpData * pOpData,
const CpaBufferList * pSrcBuffer,
Expand All @@ -487,7 +492,7 @@ CpaStatus myPerformOp(const CpaInstanceHandle instanceHandle,
struct op_done *opDone = (struct op_done *)pCallbackTag;
unsigned int uiRetry = 0;
do {
status = cpaCySymPerformOp(instanceHandle,
status = cpaCySymPerformOp(instance_handle,
pCallbackTag,
pOpData,
pSrcBuffer, pDstBuffer, pVerifyResult);
Expand Down Expand Up @@ -529,11 +534,15 @@ int qat_setup_async_event_notification(int notificationNo)
void *custom = NULL;
int ret = 0;

if ((job = ASYNC_get_current_job()) == NULL)
if ((job = ASYNC_get_current_job()) == NULL) {
WARN("[%s] Could not obtain current job\n", __func__);
return ret;
}

if ((waitctx = ASYNC_get_wait_ctx(job)) == NULL)
if ((waitctx = ASYNC_get_wait_ctx(job)) == NULL) {
WARN("[%s] Could not obtain wait context for job\n", __func__);
return ret;
}

if (ASYNC_WAIT_CTX_get_fd(waitctx, engine_qat_id, &efd,
&custom)) {
Expand All @@ -553,6 +562,38 @@ int qat_setup_async_event_notification(int notificationNo)
return ret;
}

int qat_clear_async_event_notification() {

ASYNC_JOB *job;
ASYNC_WAIT_CTX *waitctx;
OSSL_ASYNC_FD efd;
int ret = 0;
void *custom = NULL;

if ((job = ASYNC_get_current_job()) == NULL) {
WARN("[%s] Could not obtain current job\n", __func__);
return ret;
}

if ((waitctx = ASYNC_get_wait_ctx(job)) == NULL) {
WARN("[%s] Could not obtain wait context for job\n", __func__);
return ret;
}

if ((ret = ASYNC_WAIT_CTX_get_fd(waitctx, engine_qat_id, &efd, &custom)) == 0) {
WARN("[%s] Failure in ASYNC_WAIT_CTX_get_fd\n", __func__);
return ret;
}

qat_fd_cleanup(waitctx, engine_qat_id, efd, NULL);

if ((ret = ASYNC_WAIT_CTX_clear_fd(waitctx, engine_qat_id)) == 0) {
WARN("[%s] Failure in ASYNC_WAIT_CTX_clear_fd\n", __func__);
}

return ret;
}

int qat_pause_job(ASYNC_JOB *job, int notificationNo)
{
/* We will ignore notificationNo for the moment */
Expand Down Expand Up @@ -727,13 +768,13 @@ static void *event_poll_func(void *ih)
static CpaStatus poll_instances(void)
{
unsigned int poll_loop;
CpaInstanceHandle instanceHandle = NULL;
CpaInstanceHandle instance_handle = NULL;
CpaStatus internal_status = CPA_STATUS_SUCCESS,
ret_status = CPA_STATUS_SUCCESS;
if (enable_instance_for_thread)
instanceHandle = pthread_getspecific(qatInstanceForThread);
if (instanceHandle) {
ret_status = icp_sal_CyPollInstance(instanceHandle, 0);
instance_handle = pthread_getspecific(qatInstanceForThread);
if (instance_handle) {
ret_status = icp_sal_CyPollInstance(instance_handle, 0);
} else {
for (poll_loop = 0; poll_loop < qat_num_instances; poll_loop++) {
if (qat_instance_handles[poll_loop] != NULL) {
Expand Down
15 changes: 8 additions & 7 deletions e_qat.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ typedef struct qat_chained_ctx_t {
void *sw_ctx_data;
#endif
/* QAT Session Params */
CpaInstanceHandle instanceHandle;
CpaInstanceHandle instance_handle;
CpaCySymSessionSetupData *session_data;
CpaCySymSessionCtx session_ctx;
int init_flags;
Expand Down Expand Up @@ -181,7 +181,7 @@ typedef struct qat_ctx_t {
int init; /* has been initialised */
int copiedCtx; /* whether this is a copied context for
* initialisation purposes */
CpaInstanceHandle instanceHandle;
CpaInstanceHandle instance_handle;
Cpa32U nodeId;
/*
* the memory for the private meta data must be allocated as contiguous
Expand Down Expand Up @@ -230,19 +230,20 @@ struct op_done_pipe {
};

CpaInstanceHandle get_next_inst(void);
void initOpDone(struct op_done *opDone);
void cleanupOpDone(struct op_done *opDone);
int initOpDonePipe(struct op_done_pipe *opDone, unsigned int npipes);
void cleanupOpDonePipe(struct op_done_pipe *opDone);
void qat_init_op_done(struct op_done *opDone);
void qat_cleanup_op_done(struct op_done *opDone);
int qat_init_op_done_pipe(struct op_done_pipe *opDone, unsigned int npipes);
void qat_cleanup_op_done_pipe(struct op_done_pipe *opDone);
void qat_crypto_callbackFn(void *callbackTag, CpaStatus status,
const CpaCySymOp operationType, void *pOpData,
CpaBufferList * pDstBuffer,
CpaBoolean verifyResult);
CpaStatus myPerformOp(const CpaInstanceHandle instanceHandle,
CpaStatus myPerformOp(const CpaInstanceHandle instance_handle,
void *pCallbackTag, const CpaCySymOpData * pOpData,
const CpaBufferList * pSrcBuffer,
CpaBufferList * pDstBuffer, CpaBoolean * pVerifyResult);
int qat_setup_async_event_notification(int notificationNo);
int qat_clear_async_event_notification();
int qat_pause_job(ASYNC_JOB *job, int notificationNo);
int qat_wake_job(ASYNC_JOB *job, int notificationNo);
useconds_t getQatPollInterval();
Expand Down
22 changes: 14 additions & 8 deletions qat_asym_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int qat_mod_exp(BIGNUM *res, const BIGNUM *base, const BIGNUM *exp,
CpaFlatBuffer result = { 0, };
CpaStatus status = 0;
int retval = 1;
CpaInstanceHandle instanceHandle;
CpaInstanceHandle instance_handle;
int qatPerformOpRetries = 0;
ASYNC_JOB *job = NULL;
int iMsgRetry = getQatMsgRetryCount();
Expand Down Expand Up @@ -160,12 +160,6 @@ int qat_mod_exp(BIGNUM *res, const BIGNUM *base, const BIGNUM *exp,
goto exit;
}

if (NULL == (instanceHandle = get_next_inst())) {
WARN("instanceHandle is NULL\n");
retval = 0;
goto exit;
}

if ((job = ASYNC_get_current_job()) != NULL) {
if (qat_setup_async_event_notification(0) == 0) {
WARN("Failed to setup async event notifications\n");
Expand All @@ -175,7 +169,16 @@ int qat_mod_exp(BIGNUM *res, const BIGNUM *base, const BIGNUM *exp,
}

do {
status = cpaCyLnModExp(instanceHandle, NULL, NULL, &opData, &result);
if (NULL == (instance_handle = get_next_inst())) {
WARN("instance_handle is NULL\n");
if (job != NULL) {
qat_clear_async_event_notification();
}
retval = 0;
goto exit;
}

status = cpaCyLnModExp(instance_handle, NULL, NULL, &opData, &result);
if (status == CPA_STATUS_RETRY) {
if (job == NULL) {
usleep(ulPollInterval +
Expand All @@ -199,6 +202,9 @@ int qat_mod_exp(BIGNUM *res, const BIGNUM *base, const BIGNUM *exp,

if (CPA_STATUS_SUCCESS != status) {
WARN("cpaCyLnModExp failed, status=%d\n", status);
if (job != NULL) {
qat_clear_async_event_notification();
}
retval = 0;
goto exit;
}
Expand Down

0 comments on commit 8758644

Please sign in to comment.