cederom commented on PR #4093:
URL: https://github.com/apache/nuttx-apps/pull/4093#issuecomment-7043528269
Thanks @ThePassionate, my remarks:
* please remember to provide test logs for reviewers to be able to repeat
local build and runtime!
* If you use AI you must provide `Assisted-by:` tag in the git commit
messages and PR descriptions.
* A failure after submitting leaves the request outstanding, and that can
break later tests. In async_cbc, async_sha256, async_cmac and async_aead, if
the request is submitted and then poll() times out or CIOCCRYPTRET fails, the
code goes to err: and frees the session without cancelling the reqid. Two
problems follow on a real hardware backend:
* The kernel request still points at cse->key (crde->crd_key = cse->key,
cryptodev.c:588), so CIOCFSESSION frees a key the hardware may still be
reading. It also still points at the caller’s stack iv[] and src. Only the
output is copied into a kernel buffer.
* In cryptof_poll, POLLIN means “the completion queue isn’t empty”. A late
completion left over from a failed case makes the next case’s poll() return at
once. Its CIOCCRYPTRET for the new reqid then returns EAGAIN, so one failure
turns into a run of false failures.
Fix: after a successful submit, send COP_FLAG_CANCEL for the reqid on
every error path. Optionally, loop poll → RET while it returns EAGAIN, so the
test doesn’t assume its own result is the one that woke it.
* On sim, the “cancel while in flight” path never runs. With a software
backend, cryptodev_op() finishes the request inline through crypto_invoke() →
callback. So by the time async_cancel cancels, the result is already on
crp_ret, and only the “already completed” branch runs. The in-flight branch
(setting CRYPTO_F_CANCEL, the callback discarding the result,
cryptodev_cancel_dispatch) is never reached, even though it’s the trickiest
part of #22062. The commit message says both cases are covered. Either reword
it (“on a software backend only the completed-result path is exercised”) or add
a case that is guaranteed to still be in flight. That needs a slow or hardware
backend, or a test hook.
* check_concurrent() mishandles a failed pthread_create (lines 847–853):
If the second or third create fails, the threads already started are never
joined. They keep writing to wa_* on the stack after the function returns.
pthread_create returns its error code and doesn’t set errno, so warn()
prints the wrong error.
Fix: create the threads one at a time, join whatever started, and use
warnx("pthread_create: %s", strerror(ret)).
* Minor remarks:
* Reused reqid: async_cancel uses 0x7001, which the GMAC case at line 933
also uses. That’s harmless when GMAC succeeds. But if GMAC times out, the
cancel test cancels GMAC’s stale request and passes for the wrong reason. Use a
distinct ID, e.g. 0x8001.
* Kconfig dependencies: TESTING_CRYPTO_ASYNC should at least depends on
!DISABLE_PTHREAD. Ideally it would also depend on the
software-crypto/AES-GCM/CMAC support it needs. Existing entries don’t declare
such dependencies either, so this is optional.
* Thread stacks: the workers run on the default pthread stack
(CONFIG_PTHREAD_STACK_DEFAULT, not TESTING_CRYPTO_STACKSIZE). worker_sha keeps
256+32 bytes locally and then calls warn()/printf. That’s fine on sim but could
be tight on small boards; consider pthread_attr_setstacksize().
* Headers: bool and uint32_t are used without <stdbool.h>/<stdint.h>. They
work only because other headers pull them in.
* Comment wording: the async_ctx_s comment says “cloned descriptor”, but
the code uses CRIOGET, which creates a new descriptor, not CIOCCLONE. The
comment at line 937 says “cancel a completed request”, while the commit message
says “in flight or queued”. Make them agree with point 2.
* String initialiser: g_aes_plain[16] = "Single block msg" drops the
terminating NUL. That’s valid C, but GCC 15’s
-Wunterminated-string-initialization (in -Wextra) will warn. aescbc.c does the
same, so this only matters if the CI toolchain moves to GCC 15 with -Werror.
* Early exit message: if async_open fails, main returns without printing
“async test failed”, so log-scraping CI sees no result line.
* Program name: async is a very generic NSH command name. clone sets a
precedent, but something like cryptoasync would be less likely to collide.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]