Skip to content

An improper locking bug(e.g., deadlock) on caam.ring.jr_lock #4376

@ycaibb

Description

@ycaibb

Hi, developers, thank you for your checking. It seems the lock caam.ring.jr_lock is not released correctly when CAAM_ADR_SYNC(caam.ring.VirtualDesc, desc->idx * sizeof(unsigned int)) != 0 and other similar conditions in the function caamAddJob?

CAAM_LOCK_MUTEX(&caam.ring.jr_lock);
/* check input slot is available and then add */
if (CAAM_READ(0x1014) > 0) {
int i;
unsigned int *pt;
pt = (unsigned int*)caam.ring.VirtualDesc;
#if defined(WOLFSSL_CAAM_PRINT)
printf("Doing Job :\n");
#endif
for (i = 0; i < desc->idx; i = i + 1) {
pt[i] = desc->desc[i];
#if defined(WOLFSSL_CAAM_PRINT)
printf("\tCMD %02d [%p] = 0x%08X\n", i+1, pt + i,
desc->desc[i]);
#endif
}
pt = (unsigned int*)caam.ring.VirtualIn;
pt[0] = (unsigned int)caam.ring.Desc;
if (CAAM_ADR_SYNC(caam.ring.VirtualDesc,
desc->idx * sizeof(unsigned int)) != 0) {
return -1;
}
if (CAAM_ADR_SYNC(caam.ring.VirtualIn,
CAAM_JOBRING_SIZE * sizeof(unsigned int)) != 0) {
return -1;
}
#ifdef CAAM_DEBUG_MODE
caamDebugDesc(desc);
#else
#if defined(WOLFSSL_CAAM_DEBUG) || defined(WOLFSSL_CAAM_PRINT)
printf("started job 0x%08X done\n", (unsigned int)caam.ring.Desc);
#endif
CAAM_WRITE(CAAM_IRJAR0, 0x00000001);
#endif
}
else {
#if defined(WOLFSSL_CAAM_DEBUG) || defined(WOLFSSL_CAAM_PRINT)
printf("SLOT = 0x%08X, IRJAR0 = 0x%08X\n", CAAM_READ(0x1014),
CAAM_READ(CAAM_IRJAR0));
printf("Number of job in done queue = 0x%08X\n", CAAM_READ(0x103C));
#endif
CAAM_UNLOCK_MUTEX(&caam.ring.jr_lock);
return CAAM_WAITING;
}
CAAM_UNLOCK_MUTEX(&caam.ring.jr_lock);
return Success;

Best,

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions