Re: [PATCH 20/29] crypto: talitos - Replace SEC1/SEC2 conditionals with ops dispatch

From: Christophe Leroy (CS GROUP)

Date: Thu Jun 04 2026 - 11:36:47 EST




Le 04/06/2026 à 15:05, Paul Louvel a écrit :
On Thu Jun 4, 2026 at 11:37 AM CEST, Christophe Leroy (CS GROUP) wrote:


Le 28/05/2026 à 11:08, Paul Louvel a écrit :
Replace the if/else is_sec1 dispatches in callers with indirect calls
through priv->ops. Add static const sec1_ops and sec2_ops structs
populated with the SEC1 and SEC2 function variants, and set priv->ops
at probe time based on the detected hardware.

Why is that needed ?

I understand your objective at the end is to get rid of that is_sec1
boolean that is carried over the entire call chain but using ops for
that seems overkill.

What about changing it to a helper using static branches, something like
(untested) :

#if defined(CONFIG_CRYPTO_DEV_TALITOS1) &&
defined(CONFIG_CRYPTO_DEV_TALITOS2)
DECLARE_STATIC_KEY_FALSE(talitos_is_sec1);
static __always_inline bool is_sec1(void)
{
return static_branch_unlikely(&talitos_is_sec1);
}

static inline void talitos_init_branch(bool is_sec1)
{
if (is_sec1)
static_branch_enable(&talitos_is_sec1);
}
#else
static __always_inline bool is_sec1(void)
{
return IS_ENABLED(CONFIG_CRYPTO_DEV_TALITOS1);
}

static inline void talitos_init_branch(bool is_sec1)
{
BUILD_BUG_ON(is_sec1 && !IS_ENABLED(CONFIG_CRYPTO_DEV_TALITOS1));
}
#endif


Thanks you for that suggestion.
This was a lack of knowledge about this mechanism.

static_branch is nice for small inlined helpers.

For bigger time critical functions, you have static calls.

See exemple in commit e59596a2d6a7 ("powerpc: Use static call for get_irq()")

This has become even more efficient since commit f50b45626e05 ("powerpc/static_call: Implement inline static calls")

Christophe