Skip to content

Commit 60407e1

Browse files
authored
Merge pull request #24 from wolfSSL/qat_mem_fixes
Fixes for memory stability on QuickAssist
2 parents 63cc16f + f54c455 commit 60407e1

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

wolfcrypt/src/port/intel/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ Note: If you have the older driver installed you may need to remove it or unload
2929

3030

3131
```
32-
wget https://01.org/sites/default/files/downloads/qat1.7.l.4.4.0-00023.tar.gz
32+
curl -o qat1.7.l.4.5.0-00034.tar.gz https://01.org/sites/default/files/downloads/qat1.7.l.4.5.0-00034.tar.gz
3333
mkdir QAT1.7
34-
mv qat1.7.l.4.4.0-00023.tar.gz QAT1.7
34+
mv qat1.7.l.4.5.0-00034.tar.gz QAT1.7
3535
cd QAT1.7
36-
tar -xvzf qat1.7.l.4.4.0-00023.tar.gz
36+
tar -xvzf qat1.7.l.4.5.0-00034.tar.gz
3737

3838
./configure
3939
make

wolfcrypt/src/port/intel/quickassist.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ int IntelQaInit(void* threadId)
505505
}
506506

507507
/* assign device id */
508-
devId = (g_instCounter % g_numInstances);;
508+
devId = (g_instCounter % g_numInstances);
509509
g_instCounter++;
510510

511511
pthread_mutex_unlock(&g_Hwlock);
@@ -1685,7 +1685,6 @@ static void IntelQaRsaPublicFree(WC_ASYNC_DEV* dev)
16851685
XFREE(opData->inputData.pData, dev->heap, DYNAMIC_TYPE_ASYNC_NUMA);
16861686
opData->inputData.pData = NULL;
16871687
}
1688-
XMEMSET(opData->pPublicKey, 0, sizeof(CpaCyRsaPublicKey));
16891688
XMEMSET(opData, 0, sizeof(CpaCyRsaEncryptOpData));
16901689
}
16911690
if (outBuf) {

wolfcrypt/src/port/intel/quickassist_mem.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ typedef struct qaeMemHeader {
174174
pthread_t threadId;
175175
#endif
176176
size_t size;
177-
int count;
177+
word16 count;
178+
word16 isNuma:1;
179+
word16 reservedBits:15; /* use for future bits */
178180
word16 type;
179181
word16 numa_page_offset; /* use QAE_NOT_NUMA_PAGE if not NUMA */
180182
} ALIGN16 qaeMemHeader;
@@ -240,8 +242,6 @@ static WC_INLINE int qaeMemTypeIsNuma(int type)
240242
case DYNAMIC_TYPE_ASYNC_NUMA:
241243
case DYNAMIC_TYPE_ASYNC_NUMA64:
242244
case DYNAMIC_TYPE_WOLF_BIGINT:
243-
case DYNAMIC_TYPE_OUT_BUFFER:
244-
case DYNAMIC_TYPE_IN_BUFFER:
245245
case DYNAMIC_TYPE_PRIVATE_KEY:
246246
case DYNAMIC_TYPE_PUBLIC_KEY:
247247
case DYNAMIC_TYPE_AES_BUFFER:
@@ -256,7 +256,18 @@ static WC_INLINE int qaeMemTypeIsNuma(int type)
256256
isNuma = 1;
257257
break;
258258
}
259+
case DYNAMIC_TYPE_OUT_BUFFER:
260+
case DYNAMIC_TYPE_IN_BUFFER:
261+
{
262+
#if !defined(WC_ASYNC_NO_CRYPT) && !defined(WC_ASYNC_NO_HASH)
263+
isNuma = 1;
264+
#else
265+
isNuma = 0;
266+
#endif
267+
break;
268+
}
259269
default:
270+
isNuma = 0;
260271
break;
261272
}
262273
return isNuma;
@@ -351,7 +362,7 @@ static void _qaeMemFree(void *ptr, void* heap, int type
351362
#endif
352363

353364
/* free type */
354-
if (header->numa_page_offset != QAE_NOT_NUMA_PAGE) {
365+
if (header->isNuma && header->numa_page_offset != QAE_NOT_NUMA_PAGE) {
355366
#ifdef QAT_V2
356367
qaeMemFreeNUMA(&ptr);
357368
#else
@@ -397,7 +408,7 @@ static void* _qaeMemAlloc(size_t size, void* heap, int type
397408
alignment, &page_offset);
398409
#endif
399410
}
400-
if (ptr == NULL) {
411+
else if (ptr == NULL) {
401412
isNuma = 0;
402413
ptr = malloc(size + sizeof(qaeMemHeader));
403414
}
@@ -411,6 +422,7 @@ static void* _qaeMemAlloc(size_t size, void* heap, int type
411422
header->size = size;
412423
header->type = type;
413424
header->count = 1;
425+
header->isNuma = isNuma;
414426
header->numa_page_offset = page_offset;
415427
#ifdef USE_QAE_THREAD_LS
416428
header->threadId = pthread_self();

0 commit comments

Comments
 (0)