Skip to content

Commit

Permalink
Remove code for zero copy mode
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Linsell <[email protected]>
  • Loading branch information
agrandi authored and stevelinsell committed Aug 5, 2016
1 parent cccfcb5 commit 5f8eb86
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 186 deletions.
34 changes: 0 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ is known to contain bugs and errors. As such, Intel&reg; does not
recommend the use of the software in its current state for your
production use.

* Zero Copy Mode is not supported in this release.
* When forking within an application it is not valid for
a cryptographic operation to be started in the parent process
and completed in the child process.
Expand Down Expand Up @@ -285,10 +284,6 @@ Engine is loaded correctly:
(input flags): NUMERIC
GET_OP_RETRIES: Get number of retries
(input flags): NO_INPUT
SET_V2P: Set function to be used for V2P translation
(input flags): NUMERIC
ENABLE_ZERO_COPY_MODE: Set zero copy mode
(input flags): NO_INPUT
SET_MSG_RETRY_COUNT: Set Message retry count
(input flags): NUMERIC
SET_POLL_INTERVAL: Set Poll Interval
Expand Down Expand Up @@ -442,35 +437,6 @@ Where:
This message may be sent at any time after engine
initialization.
Message String: SET_V2P
Param 3: function pointer cast to a long
Param 4: NULL
Description:
This message sets the function that the engine and the
Intel&reg; Quickassist Technology Driver will use for
converting virtual addresses to physical addresses for the
pinned contiguous memory buffers. A function pointer to
the appropriately signatured function should be
cast to a long and passed as Param 3. This message
is usually used in conjunction with the
ENABLE_ZERO_COPY_MODE message to allow applications
to manage memory allocations themselves. This message
must be sent between engine creation and engine
initialization and before sending
ENABLE_ZERO_COPY_MODE.
Message String: ENABLE_ZERO_COPY_MODE
Param 3: 0
Param 4: NULL
Description:
This message sets zero copy mode within the engine.
This reduces memory copies by assuming the
application is responsible for ensuring buffers
passed into the engine are contiguous pinned memory.
This message must be sent between engine creation
and engine initialization and should be called
after a SET_V2P message.
Message String: SET_MSG_RETRY_COUNT
Param 3: int cast to a long
Param 4: NULL
Expand Down
102 changes: 9 additions & 93 deletions e_qat.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@
#define unlikely(x) __builtin_expect (!!(x), 0)

/* Forward Declarations */
static CpaPhysicalAddr realVirtualToPhysical(void *virtualAddr);

static int qat_engine_finish(ENGINE *e);

/* Qat engine id declaration */
Expand Down Expand Up @@ -171,8 +169,6 @@ static pthread_mutex_t qat_engine_mutex = PTHREAD_MUTEX_INITIALIZER;

char *ICPConfigSectionName_libcrypto = "SHIM";

static CpaVirtualToPhysical myVirtualToPhysical = realVirtualToPhysical;
static int zero_copy_memory_mode = 0;
static int qat_inited = 0;
static useconds_t qat_poll_interval = QAT_POLL_PERIOD_IN_NS;
static int qat_msg_retry_count = QAT_CRYPTO_NUM_POLLING_RETRIES;
Expand Down Expand Up @@ -227,42 +223,12 @@ useconds_t getQatPollInterval()
}


int isZeroCopy()
{
return (zero_copy_memory_mode);
}


int isEventDriven()
{
return enable_event_driven_polling;
}


void enableZeroCopy()
{
CpaStatus status;

status =
CRYPTO_set_mem_ex_functions(qaeCryptoMemAlloc, qaeCryptoMemRealloc,
qaeCryptoMemFree);
if (CPA_FALSE == status) {
DEBUG("%s: CRYPTO_set_mem_functions failed\n", __func__);
/*
* Don't abort. This may be tried from a few places and will only
* succeed the first time.
*/
} else {
DEBUG("%s: CRYPTO_set_mem_functions succeeded\n", __func__);
}

/*
* If over-riding OPENSSL_malloc then buffers passed will already be
* pinned memory so we switch to zero copy mode
*/
zero_copy_memory_mode = 1;
}

/******************************************************************************
* function:
* incr_curr_inst(void)
Expand Down Expand Up @@ -728,7 +694,7 @@ static CpaStatus poll_instances(void)

/******************************************************************************
* function:
* realVirtualToPhysical(void *virtualAddr)
* virtualToPhysical(void *virtualAddr)
*
* @param virtualAddr [IN] - Virtual address.
*
Expand All @@ -742,36 +708,11 @@ static CpaStatus poll_instances(void)
* qae_mem_utils.c and qat_contig_mem/qat_contig_mem.c
*
******************************************************************************/
static CpaPhysicalAddr realVirtualToPhysical(void *virtualAddr)
static CpaPhysicalAddr virtualToPhysical(void *virtualAddr)
{
return qaeCryptoMemV2P(virtualAddr);
}

/******************************************************************************
* function:
* setMyVirtualToPhysical(CpaVirtualToPhysical fp)
*
* @param CpaVirtualToPhysical [IN] - Function pointer to translation function
*
* description:
* External API to allow users to specify their own virtual to physical
* address translation function.
*
******************************************************************************/
void setMyVirtualToPhysical(CpaVirtualToPhysical fp)
{
/*
* If user specifies a V2P function then the user is taking
* responsibility for allocating and freeing pinned memory so we switch
* to zero_copy_memory mode
*/
if (!qat_inited) {
myVirtualToPhysical = fp;
zero_copy_memory_mode = 1;
} else {
WARN("%s: can't set virtual to physical translation function after initialisation\n", __func__);
}
}

int qat_adjust_thread_affinity(pthread_t threadptr)
{
Expand Down Expand Up @@ -931,7 +872,7 @@ static int qat_engine_init(ENGINE *e)
for (instNum = 0; instNum < numInstances; instNum++) {
/* Set the address translation function */
status = cpaCySetAddressTranslation(qatInstanceHandles[instNum],
myVirtualToPhysical);
virtualToPhysical);
if (CPA_STATUS_SUCCESS != status) {
WARN("cpaCySetAddressTranslation failed, status=%d\n", status);
qat_engine_finish(e);
Expand Down Expand Up @@ -985,14 +926,12 @@ static int qat_engine_init(ENGINE *e)
#define QAT_CMD_POLL (ENGINE_CMD_BASE + 1)
#define QAT_CMD_SET_INSTANCE_FOR_THREAD (ENGINE_CMD_BASE + 2)
#define QAT_CMD_GET_OP_RETRIES (ENGINE_CMD_BASE + 3)
#define QAT_CMD_SET_V2P (ENGINE_CMD_BASE + 4)
#define QAT_CMD_ENABLE_ZERO_COPY_MODE (ENGINE_CMD_BASE + 5)
#define QAT_CMD_SET_MSG_RETRY_COUNTER (ENGINE_CMD_BASE + 6)
#define QAT_CMD_SET_POLL_INTERVAL (ENGINE_CMD_BASE + 7)
#define QAT_CMD_GET_POLLING_FD (ENGINE_CMD_BASE + 8)
#define QAT_CMD_ENABLE_EVENT_DRIVEN_MODE (ENGINE_CMD_BASE + 9)
#define QAT_CMD_GET_NUM_CRYPTO_INSTANCES (ENGINE_CMD_BASE + 10)
#define QAT_CMD_DISABLE_EVENT_DRIVEN_MODE (ENGINE_CMD_BASE + 11)
#define QAT_CMD_SET_MSG_RETRY_COUNTER (ENGINE_CMD_BASE + 4)
#define QAT_CMD_SET_POLL_INTERVAL (ENGINE_CMD_BASE + 5)
#define QAT_CMD_GET_POLLING_FD (ENGINE_CMD_BASE + 6)
#define QAT_CMD_ENABLE_EVENT_DRIVEN_MODE (ENGINE_CMD_BASE + 7)
#define QAT_CMD_GET_NUM_CRYPTO_INSTANCES (ENGINE_CMD_BASE + 8)
#define QAT_CMD_DISABLE_EVENT_DRIVEN_MODE (ENGINE_CMD_BASE + 9)

static const ENGINE_CMD_DEFN qat_cmd_defns[] = {
{
Expand All @@ -1015,16 +954,6 @@ static const ENGINE_CMD_DEFN qat_cmd_defns[] = {
"GET_OP_RETRIES",
"Get number of retries",
ENGINE_CMD_FLAG_NO_INPUT},
{
QAT_CMD_SET_V2P,
"SET_V2P",
"Set function to be used for V2P translation",
ENGINE_CMD_FLAG_NUMERIC},
{
QAT_CMD_ENABLE_ZERO_COPY_MODE,
"ENABLE_ZERO_COPY_MODE",
"Set zero copy mode",
ENGINE_CMD_FLAG_NO_INPUT},
{
QAT_CMD_SET_MSG_RETRY_COUNTER,
"SET_MSG_RETRY_COUNT",
Expand Down Expand Up @@ -1210,16 +1139,6 @@ qat_engine_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
*(int *)p = qatPerformOpRetries;
break;
}
case QAT_CMD_SET_V2P:
{
setMyVirtualToPhysical((CpaVirtualToPhysical) i);
break;
}
case QAT_CMD_ENABLE_ZERO_COPY_MODE:
{
enableZeroCopy();
break;
}
case QAT_CMD_SET_MSG_RETRY_COUNTER:
{
retVal = setQatMsgRetryCount((int)i);
Expand Down Expand Up @@ -1470,9 +1389,6 @@ static ENGINE *engine_qat(void)
QATerr(QAT_F_ENGINE_QAT, QAT_R_QAT_DEV_NOT_PRESENT);
return ret;
}
# ifdef QAT_ZERO_COPY_MODE
enableZeroCopy();
# endif

ret = ENGINE_new();

Expand Down
3 changes: 1 addition & 2 deletions e_qat.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ====================================================================
*
*
*
* BSD LICENSE
*
* Copyright(c) 2016 Intel Corporation.
Expand Down Expand Up @@ -211,7 +211,6 @@ CpaStatus myPerformOp(const CpaInstanceHandle instanceHandle,
int qat_setup_async_event_notification(int notificationNo);
int qat_pause_job(ASYNC_JOB *job, int notificationNo);
int qat_wake_job(ASYNC_JOB *job, int notificationNo);
int isZeroCopy();
useconds_t getQatPollInterval();
int getQatMsgRetryCount();
int getEnableExternalPolling();
Expand Down
64 changes: 28 additions & 36 deletions qat_ciphers.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* ====================================================================
*
*
*
* BSD LICENSE
*
*
* Copyright(c) 2016 Intel Corporation.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
Expand All @@ -19,7 +19,7 @@
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Expand All @@ -31,8 +31,8 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*
*
* ====================================================================
*/

Expand Down Expand Up @@ -364,7 +364,7 @@ qat_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids,
* @param evp_ctx [IN] - pointer to the evp context
*
* description:
* This function is to find the sha digest length
* This function is to find the sha digest length
* based on NID
* it will return Sha digest Length if successful and 0 on failure.
*
Expand Down Expand Up @@ -482,13 +482,13 @@ static int cipher_init_chained(EVP_CIPHER_CTX *evp_ctx,
WARN("[%s] Unable to get sha digest length\n", __func__);
goto end;
}

qat_ctx->session_data->hashSetupData.digestResultLenInBytes =
sha_digest_len;

if (sha_digest_len == SHA_DIGEST_LENGTH)
qat_ctx->session_data->hashSetupData.hashAlgorithm = CPA_CY_SYM_HASH_SHA1;
else
else
qat_ctx->session_data->hashSetupData.hashAlgorithm = CPA_CY_SYM_HASH_SHA256;

qat_ctx->hmac_key = OPENSSL_malloc(HMAC_KEY_SIZE);
Expand Down Expand Up @@ -689,7 +689,7 @@ int qat_aes_cbc_hmac_sha_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
SHA256_Final(hmac_key, &(evp_ctx->sha_key_wrap.sha256_key_wrap));
sessionSetupData->hashSetupData.
authModeSetupData.authKeyLenInBytes = HMAC_KEY_SIZE;
}
}
} else {
memcpy(hmac_key, ptr, arg);
sessionSetupData->hashSetupData.
Expand Down Expand Up @@ -1099,7 +1099,7 @@ int qat_aes_cbc_hmac_sha_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
return 0;
}
}

if ((sha_digest_len = qat_get_sha_digest_len(ctx)) == 0) {
WARN("[%s] --- Unable to get sha digest length\n", __func__);
return -1;
Expand Down Expand Up @@ -1135,19 +1135,15 @@ int qat_aes_cbc_hmac_sha_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
}

/* Build request/response buffers */
if (isZeroCopy()) {
evp_ctx->srcFlatBuffer[1].pData = (Cpa8U *) in;
evp_ctx->dstFlatBuffer[1].pData = (Cpa8U *) out;
} else {
evp_ctx->srcFlatBuffer[1].pData =
qaeCryptoMemAlloc(len, __FILE__, __LINE__);
if ((evp_ctx->srcFlatBuffer[1].pData) == NULL) {
WARN("[%s] --- src/dst buffer allocation.\n", __func__);
return 0;
}
evp_ctx->dstFlatBuffer[1].pData = evp_ctx->srcFlatBuffer[1].pData;
memcpy(evp_ctx->dstFlatBuffer[1].pData, in, len);
evp_ctx->srcFlatBuffer[1].pData =
qaeCryptoMemAlloc(len, __FILE__, __LINE__);
if ((evp_ctx->srcFlatBuffer[1].pData) == NULL) {
WARN("[%s] --- src/dst buffer allocation.\n", __func__);
return 0;
}
evp_ctx->dstFlatBuffer[1].pData = evp_ctx->srcFlatBuffer[1].pData;
memcpy(evp_ctx->dstFlatBuffer[1].pData, in, len);

evp_ctx->srcFlatBuffer[1].dataLenInBytes = len;
evp_ctx->srcBufferList.pUserData = NULL;
evp_ctx->dstFlatBuffer[1].dataLenInBytes = len;
Expand Down Expand Up @@ -1246,12 +1242,10 @@ int qat_aes_cbc_hmac_sha_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
&(evp_ctx->srcBufferList),
&(evp_ctx->dstBufferList),
&(evp_ctx->session_data->verifyDigest))) !=
CPA_STATUS_SUCCESS) {
if (!isZeroCopy()) {
qaeCryptoMemFree(evp_ctx->srcFlatBuffer[1].pData);
evp_ctx->srcFlatBuffer[1].pData = NULL;
evp_ctx->dstFlatBuffer[1].pData = NULL;
}
CPA_STATUS_SUCCESS) {
qaeCryptoMemFree(evp_ctx->srcFlatBuffer[1].pData);
evp_ctx->srcFlatBuffer[1].pData = NULL;
evp_ctx->dstFlatBuffer[1].pData = NULL;
cleanupOpDone(&opDone);
WARN("[%s] --- cpaCySymPerformOp failed sts=%d.\n", __func__,
sts);
Expand Down Expand Up @@ -1288,12 +1282,10 @@ int qat_aes_cbc_hmac_sha_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
AES_BLOCK_SIZE, EVP_CIPHER_CTX_iv_length(ctx));
evp_ctx->payload_length = NO_PAYLOAD_LENGTH_SPECIFIED;

if (!isZeroCopy()) {
memcpy(out, evp_ctx->dstFlatBuffer[1].pData, len);
qaeCryptoMemFree(evp_ctx->srcFlatBuffer[1].pData);
evp_ctx->srcFlatBuffer[1].pData = NULL;
evp_ctx->dstFlatBuffer[1].pData = NULL;
}
memcpy(out, evp_ctx->dstFlatBuffer[1].pData, len);
qaeCryptoMemFree(evp_ctx->srcFlatBuffer[1].pData);
evp_ctx->srcFlatBuffer[1].pData = NULL;
evp_ctx->dstFlatBuffer[1].pData = NULL;

return retVal;
}
Expand Down
Loading

0 comments on commit 5f8eb86

Please sign in to comment.