Skip to content

Conversation

@jperon
Copy link
Collaborator

@jperon jperon commented Jul 24, 2025

Fixes #307

@jperon jperon requested review from Copilot and lneto July 24, 2025 16:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the synchronous compression implementation with an asynchronous one using the Linux kernel's acompress API. The change introduces a new low-level crypto.acompress module that provides asynchronous compression operations, while maintaining backward compatibility through a high-level crypto.comp Lua module that wraps the async operations to provide a synchronous interface.

Key changes:

  • Replaces synchronous luacrypto_comp.c with asynchronous luacrypto_acompress.c
  • Adds high-level Lua wrapper crypto/comp.lua to maintain synchronous API compatibility
  • Updates build configuration to use the new acompress module

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/luacrypto_comp.c Removed - old synchronous compression implementation
lib/luacrypto_acompress.c Added - new asynchronous compression implementation using kernel acompress API
lib/crypto/comp.lua Added - high-level Lua wrapper providing synchronous interface over async operations
tests/crypto/comp.lua Minor error message improvement for clarity
config.ld Updated documentation config to reference new files
Makefile Updated build config to use acompress module
Kbuild Updated kernel build config to use acompress module

@lneto lneto requested a review from sheharyaar July 24, 2025 16:04
@jperon jperon mentioned this pull request Aug 4, 2025
@jperon jperon force-pushed the jperon_crypto_acompress branch from 723e663 to 1df9379 Compare August 6, 2025 14:33
@jperon jperon force-pushed the jperon_crypto_acompress branch from 9a9b7c6 to c0e8987 Compare November 21, 2025 00:34
@jperon jperon force-pushed the jperon_crypto_acompress branch from c0e8987 to 59c56ec Compare November 21, 2025 06:58
Comment on lines 312 to 314
req->cb = LUA_NOREF;
req->buf = LUA_NOREF;
req->self = LUA_NOREF;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using a lua table for all you need will simplify a bit the implementation..

Comment on lines 236 to 237
if (ret != -EINPROGRESS) \
luacrypto_acomp_req_docall(obj, ret); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this.. shouldn't this function be called by the crypto_acomp request itself? why you are calling synchronously here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks to me that we are trying to turn an async API into sync.. I would follow the same approach the clients of this kernel API are doing.. can you point to kernel usage example, btw? my bet is that they have an API for checking result later on.. we could do the same..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call it synchronously only in the case when crypto_acomp_… has already completed (synchronously), in which case the callback would never be invoked automatically. If ret == -EINPROGRESS, the behavior remains asynchronous.

This follows the standard pattern used in the kernel. For example:

In xfrm_ipcomp.c: https://github.com/jonmason/ntb/blob/09ca5e67c4ab3c8bff7aef6085ee0cbb4337c3f8/net/xfrm/xfrm_ipcomp.c#L272
In crypto/acompress.c: https://github.com/torvalds/linux/blob/master/crypto/acompress.c#L278

Comment on lines 316 to 317
lua_pushvalue(L, 1); /* push TFM object */
req->tfm = luaL_ref(L, LUA_REGISTRYINDEX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a macro for this pattern on lunatik.h, right? couldn't we use it?

obj-$(CONFIG_LUNATIK_CRYPTO_AEAD) += lib/luacrypto_aead.o
obj-$(CONFIG_LUNATIK_CRYPTO_RNG) += lib/luacrypto_rng.o
obj-$(CONFIG_LUNATIK_CRYPTO_COMP) += lib/luacrypto_comp.o
obj-$(CONFIG_LUNATIK_CRYPTO_ACOMPRESS) += lib/luacrypto_acompress.o
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we keep comp for older kernels?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Build failing in latest release

3 participants