]> www.infradead.org Git - users/jedix/linux-maple.git/log
users/jedix/linux-maple.git
7 months agocrypto: caam - Pad SG length when allocating hash edesc
Herbert Xu [Thu, 12 Sep 2024 09:57:13 +0000 (17:57 +0800)]
crypto: caam - Pad SG length when allocating hash edesc

Because hardware will read in multiples of 4 SG entries, ensure
the allocated length is always padded.  This was already done
by some callers of ahash_edesc_alloc, but ahash_digest was conspicuously
missing.

In any case, doing it in the allocation function ensures that the
memory is always there.

Reported-by: Guangwu Zhang <guazhang@redhat.com>
Fixes: a5e5c13398f3 ("crypto: caam - fix S/G table passing page boundary")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: n2 - Set err to EINVAL if snprintf fails for hmac
Herbert Xu [Tue, 10 Sep 2024 09:30:24 +0000 (17:30 +0800)]
crypto: n2 - Set err to EINVAL if snprintf fails for hmac

Return EINVAL if the snprintf check fails when constructing the
algorithm names.

Fixes: 8c20982caca4 ("crypto: n2 - Silence gcc format-truncation false positive warnings")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/r/202409090726.TP0WfY7p-lkp@intel.com/
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: camm/qi - Use ERR_CAST() to return error-valued pointer
Chen Yufan [Fri, 6 Sep 2024 10:43:24 +0000 (18:43 +0800)]
crypto: camm/qi - Use ERR_CAST() to return error-valued pointer

Instead of directly casting and returning (void *) pointer, use ERR_CAST
to explicitly return an error-valued pointer. This makes the error handling
more explicit and improves code clarity.

Signed-off-by: Chen Yufan <chenyufan@vivo.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: mips/crc32 - Clean up useless assignment operations
WangYuli [Fri, 6 Sep 2024 06:40:02 +0000 (14:40 +0800)]
crypto: mips/crc32 - Clean up useless assignment operations

When entering the "len & sizeof(u32)" branch, len must be less than 8.
So after one operation, len must be less than 4.
At this time, "len -= sizeof(u32)" is not necessary for 64-bit CPUs.

After that, replace `while' loops with equivalent `for' to make the
code structure a little bit better by the way.

Suggested-by: Maciej W. Rozycki <macro@orcam.me.uk>
Link: https://lore.kernel.org/all/alpine.DEB.2.21.2406281713040.43454@angie.orcam.me.uk/
Suggested-by: Herbert Xu <herbert@gondor.apana.org.au>
Link: https://lore.kernel.org/all/ZtqZpzMH_qMQqzyc@gondor.apana.org.au/
Signed-off-by: Guan Wentao <guanwentao@uniontech.com>
Signed-off-by: WangYuli <wangyuli@uniontech.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: qcom-rng - rename *_of_data to *_match_data
Brian Masney [Fri, 6 Sep 2024 00:25:21 +0000 (20:25 -0400)]
crypto: qcom-rng - rename *_of_data to *_match_data

The qcom-rng driver supports both ACPI and device tree based systems.
Let's rename all instances of *of_data to *match_data so that it's
not implied that this driver only supports device tree-based systems.

Signed-off-by: Brian Masney <bmasney@redhat.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: qcom-rng - fix support for ACPI-based systems
Brian Masney [Fri, 6 Sep 2024 00:25:20 +0000 (20:25 -0400)]
crypto: qcom-rng - fix support for ACPI-based systems

The qcom-rng driver supports both ACPI and device tree-based systems.
ACPI support was broken when the hw_random interface support was added.
Let's go ahead and fix this by adding the appropriate driver data to the
ACPI match table, and change the of_device_get_match_data() call to
device_get_match_data() so that it will also work on ACPI-based systems.

This fix was boot tested on a Qualcomm Amberwing server (ACPI based) and
on a Qualcomm SA8775p Automotive Development Board (DT based). I also
verified that qcom-rng shows up in /proc/crypto on both systems.

Fixes: f29cd5bb64c2 ("crypto: qcom-rng - Add hw_random interface support")
Reported-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
Closes: https://lore.kernel.org/linux-arm-msm/20240828184019.GA21181@eaf/
Cc: stable@vger.kernel.org
Signed-off-by: Brian Masney <bmasney@redhat.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agodt-bindings: crypto: qcom,prng: document support for SA8255p
Nikunj Kela [Thu, 5 Sep 2024 19:06:05 +0000 (12:06 -0700)]
dt-bindings: crypto: qcom,prng: document support for SA8255p

Document SA8255p compatible for the True Random Number Generator.

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: aegis128 - Fix indentation issue in crypto_aegis128_process_crypt()
Riyan Dhiman [Tue, 3 Sep 2024 12:55:39 +0000 (18:25 +0530)]
crypto: aegis128 - Fix indentation issue in crypto_aegis128_process_crypt()

The code in crypto_aegis128_process_crypt() had an indentation
issue where spaces were used instead of tabs. This commit
corrects the indentation to use tabs, adhering to the
Linux kernel coding style guidelines.

Issue reported by checkpatch:
- ERROR: code indent should use tabs where possible

No functional changes are intended.

Signed-off-by: Riyan Dhiman <riyandhiman14@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: octeontx* - Select CRYPTO_AUTHENC
Herbert Xu [Thu, 5 Sep 2024 02:21:49 +0000 (10:21 +0800)]
crypto: octeontx* - Select CRYPTO_AUTHENC

Select CRYPTO_AUTHENC as the function crypto_authenec_extractkeys
may not be available without it.

Fixes: 311eea7e37c4 ("crypto: octeontx - Fix authenc setkey")
Fixes: 7ccb750dcac8 ("crypto: octeontx2 - Fix authenc setkey")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202409042013.gT2ZI4wR-lkp@intel.com/
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: testmgr - Hide ENOENT errors
Herbert Xu [Mon, 2 Sep 2024 23:33:40 +0000 (07:33 +0800)]
crypto: testmgr - Hide ENOENT errors

When a crypto algorithm with a higher priority is registered, it
kills the spawns of all lower-priority algorithms.  Thus it is to
be expected for an algorithm to go away at any time, even during
a self-test.  This is now much more common with asynchronous testing.

Remove the printk when an ENOENT is encountered during a self-test.
This is not really an error since the algorithm being tested is no
longer there (i.e., it didn't fail the test which is what we care
about).

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: qat - Remove trailing space after \n newline
Colin Ian King [Sun, 1 Sep 2024 16:07:17 +0000 (17:07 +0100)]
crypto: qat - Remove trailing space after \n newline

There is a extraneous space after a newline in a pr_err message.
Remove it.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: hisilicon/sec - Remove trailing space after \n newline
Colin Ian King [Sun, 1 Sep 2024 16:04:30 +0000 (17:04 +0100)]
crypto: hisilicon/sec - Remove trailing space after \n newline

There is a extraneous space after a newline in a dev_err message.
Remove it.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: algboss - Pass instance creation error up
Herbert Xu [Sun, 1 Sep 2024 08:06:56 +0000 (16:06 +0800)]
crypto: algboss - Pass instance creation error up

Pass any errors we get during instance creation up through the
larval.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: api - Fix generic algorithm self-test races
Herbert Xu [Sun, 1 Sep 2024 08:05:40 +0000 (16:05 +0800)]
crypto: api - Fix generic algorithm self-test races

On Fri, Aug 30, 2024 at 10:51:54AM -0700, Eric Biggers wrote:
>
> Given below in defconfig form, use 'make olddefconfig' to apply.  The failures
> are nondeterministic and sometimes there are different ones, for example:
>
> [    0.358017] alg: skcipher: failed to allocate transform for cbc(twofish-generic): -2
> [    0.358365] alg: self-tests for cbc(twofish) using cbc(twofish-generic) failed (rc=-2)
> [    0.358535] alg: skcipher: failed to allocate transform for cbc(camellia-generic): -2
> [    0.358918] alg: self-tests for cbc(camellia) using cbc(camellia-generic) failed (rc=-2)
> [    0.371533] alg: skcipher: failed to allocate transform for xts(ecb(aes-generic)): -2
> [    0.371922] alg: self-tests for xts(aes) using xts(ecb(aes-generic)) failed (rc=-2)
>
> Modules are not enabled, maybe that matters (I haven't checked yet).

Yes I think that was the key.  This triggers a massive self-test
run which executes in parallel and reveals a few race conditions
in the system.  I think it boils down to the following scenario:

Base algorithm X-generic, X-optimised
Template Y
Optimised algorithm Y-X-optimised

Everything gets registered, and then the self-tests are started.
When Y-X-optimised gets tested, it requests the creation of the
generic Y(X-generic).  Which then itself undergoes testing.

The race is that after Y(X-generic) gets registered, but just
before it gets tested, X-optimised finally finishes self-testing
which then causes all spawns of X-generic to be destroyed.  So
by the time the self-test for Y(X-generic) comes along, it can
no longer find the algorithm.  This error then bubbles up all
the way up to the self-test of Y-X-optimised which then fails.

Note that there is some complexity that I've omitted here because
when the generic self-test fails to find Y(X-generic) it actually
triggers the construction of it again which then fails for various
other reasons (these are not important because the construction
should *not* be triggered at this point).

So in a way the error is expected, and we should probably remove
the pr_err for the case where ENOENT is returned for the algorithm
that we're currently testing.

The solution is two-fold.  First when an algorithm undergoes
self-testing it should not trigger its construction.  Secondly
if an instance larval fails to materialise due to it being destroyed
by a more optimised algorithm coming along, it should obviously
retry the construction.

Remove the check in __crypto_alg_lookup that stops a larval from
matching new requests based on differences in the mask.  It is better
to block new requests even if it is wrong and then simply retry the
lookup.  If this ends up being the wrong larval it will sort iself
out during the retry.

Reduce the CRYPTO_ALG_TYPE_MASK bits in type during larval creation
as otherwise LSKCIPHER algorithms may not match SKCIPHER larvals.

Also block the instance creation during self-testing in the function
crypto_larval_lookup by checking for CRYPTO_ALG_TESTED in the mask
field.

Finally change the return value when crypto_alg_lookup fails in
crypto_larval_wait to EAGAIN to redo the lookup.

Fixes: 37da5d0ffa7b ("crypto: api - Do not wait for tests during registration")
Reported-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: hisilicon/qm - inject error before stopping queue
Weili Qian [Sat, 31 Aug 2024 11:48:31 +0000 (19:48 +0800)]
crypto: hisilicon/qm - inject error before stopping queue

The master ooo cannot be completely closed when the
accelerator core reports memory error. Therefore, the driver
needs to inject the qm error to close the master ooo. Currently,
the qm error is injected after stopping queue, memory may be
released immediately after stopping queue, causing the device to
access the released memory. Therefore, error is injected to close master
ooo before stopping queue to ensure that the device does not access
the released memory.

Fixes: 6c6dd5802c2d ("crypto: hisilicon/qm - add controller reset interface")
Signed-off-by: Weili Qian <qianweili@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: hisilicon/hpre - mask cluster timeout error
Weili Qian [Sat, 31 Aug 2024 11:48:30 +0000 (19:48 +0800)]
crypto: hisilicon/hpre - mask cluster timeout error

The timeout threshold of the hpre cluster is 16ms. When the CPU
and device share virtual address, page fault processing time may
exceed the threshold.

In the current test, there is a high probability that the
cluster times out. However, the cluster is waiting for the
completion of memory access, which is not an error, the device
does not need to be reset. If an error occurs in the cluster,
qm also reports the error. Therefore, the cluster timeout
error of hpre can be masked.

Fixes: d90fab0deb8e ("crypto: hisilicon/qm - get error type from hardware registers")
Signed-off-by: Weili Qian <qianweili@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: hisilicon/qm - reset device before enabling it
Weili Qian [Sat, 31 Aug 2024 11:48:29 +0000 (19:48 +0800)]
crypto: hisilicon/qm - reset device before enabling it

Before the device is enabled again, the device may still
store the previously processed data. If an error occurs in
the previous task, the device may fail to be enabled again.
Therefore, before enabling device, reset the device to restore
the initial state.

Signed-off-by: Weili Qian <qianweili@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: hisilicon/trng - modifying the order of header files
Chenghai Huang [Sat, 31 Aug 2024 09:50:09 +0000 (17:50 +0800)]
crypto: hisilicon/trng - modifying the order of header files

Header files is included Order-ref: standard library headers,
OS library headers, and project-specific headers. This patch
modifies the order of header files according to suggestions.

In addition, use %u to print unsigned int variables to prevent
overflow.

Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: hisilicon - add a lock for the qp send operation
Chenghai Huang [Sat, 31 Aug 2024 09:50:08 +0000 (17:50 +0800)]
crypto: hisilicon - add a lock for the qp send operation

Apply for a lock before the qp send operation to ensure no
resource race in multi-concurrency situations.

This modification has almost no impact on performance.

Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: hisilicon - fix missed error branch
Yang Shen [Sat, 31 Aug 2024 09:50:07 +0000 (17:50 +0800)]
crypto: hisilicon - fix missed error branch

If an error occurs in the process after the SGL is mapped
successfully, it need to unmap the SGL.

Otherwise, memory problems may occur.

Signed-off-by: Yang Shen <shenyang39@huawei.com>
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: ccp - do not request interrupt on cmd completion when irqs disabled
Amit Shah [Thu, 29 Aug 2024 10:20:07 +0000 (12:20 +0200)]
crypto: ccp - do not request interrupt on cmd completion when irqs disabled

While sending a command to the PSP, we always requested an interrupt
from the PSP after command completion.  This worked for most cases.  For
the special case of irqs being disabled -- e.g. when running within
crashdump or kexec contexts, we should not set the SEV_CMDRESP_IOC flag,
so the PSP knows to not attempt interrupt delivery.

Fixes: 8ef979584ea8 ("crypto: ccp: Add panic notifier for SEV/SNP firmware shutdown on kdump")
Based-on-patch-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Amit Shah <amit.shah@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: x86/aesni - update docs for aesni-intel module
Eric Biggers [Tue, 27 Aug 2024 18:50:01 +0000 (11:50 -0700)]
crypto: x86/aesni - update docs for aesni-intel module

Update the kconfig help and module description to reflect that VAES
instructions are now used in some cases.  Also fix XTR => XCTR.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agohwrng: mtk - Use devm_pm_runtime_enable
Guoqing Jiang [Mon, 26 Aug 2024 07:04:15 +0000 (15:04 +0800)]
hwrng: mtk - Use devm_pm_runtime_enable

Replace pm_runtime_enable with the devres-enabled version which
can trigger pm_runtime_disable.

Otherwise, the below appears during reload driver.

mtk_rng 1020f000.rng: Unbalanced pm_runtime_enable!

Fixes: 81d2b34508c6 ("hwrng: mtk - add runtime PM support")
Cc: <stable@vger.kernel.org>
Suggested-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: Guoqing Jiang <guoqing.jiang@canonical.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agoRevert "crypto: spacc - Add SPAcc Skcipher support"
Herbert Xu [Tue, 3 Sep 2024 23:09:51 +0000 (07:09 +0800)]
Revert "crypto: spacc - Add SPAcc Skcipher support"

This reverts the following commits:

87a3fcf5fec5fb59ec8f23d12a56bcf2b2ee6db7
58bf99100a6dfcc53ba4ab547f1394bb6873b2ac
3b1c9df662915a18a86f1a88364ee70875ed3b44
8bc1bfa02e37d63632f0cb65543e3e71acdccafb
c32f08d024e275059474b3c11c1fc2bc7f2de990
f036dd566453176d4eafb9701ebd69e7e59d6707
c76c9ec333432088a1c6f52650c149530fc5df5d
5d22d37aa8b93efaad797faf80db40ea59453481
b63483b37e813299445d2719488acab2b3f20544
2d6213bd592b4731b53ece3492f9d1d18e97eb5e
fc61c658c94cb7405ca6946d8f2a2b71cef49845
cb67c924b2a7b561bd7f4f2bd66766337c1007b7
06af76b46c78f4729fe2f9712a74502c90d87554
9f1a7ab4d31ef30fbf8adb0985300049469f2270
8ebb14deef0f374f7ca0d34a1ad720ba0a7b79f3
c8981d9230d808e62c65349d0b255c7f4b9087d6

They were submitted with no device tree bindings.

Reported-by: Rob Herring <robh@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: hisilicon/zip - Optimize performance by replacing rw_lock with spinlock
Kuan-Wei Chiu [Fri, 23 Aug 2024 18:38:56 +0000 (02:38 +0800)]
crypto: hisilicon/zip - Optimize performance by replacing rw_lock with spinlock

The req_lock is currently implemented as a rw_lock, but there are no
instances where read_lock() is called. This means that the lock is
effectively only used by writers, making it functionally equivalent to
a simple spinlock.

As stated in Documentation/locking/spinlocks.rst:
"Reader-writer locks require more atomic memory operations than simple
spinlocks. Unless the reader critical section is long, you are better
off just using spinlocks."

Since the rw_lock in this case incurs additional atomic memory
operations without any benefit from reader-writer locking, it is more
efficient to replace it with a spinlock. This patch implements that
replacement to optimize the driver's performance.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: img-hash - use devm_clk_get_enabled() helpers
Chunhai Guo [Fri, 23 Aug 2024 09:52:12 +0000 (03:52 -0600)]
crypto: img-hash - use devm_clk_get_enabled() helpers

Simplify the code by replacing devm_clk_get() and clk_prepare_enable()
with devm_clk_get_enabled(), which also avoids the call to
clk_disable_unprepare().

Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: atmel - use devm_clk_get_prepared() helpers
Chunhai Guo [Fri, 23 Aug 2024 09:42:49 +0000 (03:42 -0600)]
crypto: atmel - use devm_clk_get_prepared() helpers

Simplify the code by replacing devm_clk_get() and clk_prepare() with
devm_clk_get_prepared(), which also avoids the call to clk_unprepare().

Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agopadata: Honor the caller's alignment in case of chunk_size 0
Kamlesh Gurudasani [Wed, 21 Aug 2024 21:02:52 +0000 (02:32 +0530)]
padata: Honor the caller's alignment in case of chunk_size 0

In the case where we are forcing the ps.chunk_size to be at least 1,
we are ignoring the caller's alignment.

Move the forcing of ps.chunk_size to be at least 1 before rounding it
up to caller's alignment, so that caller's alignment is honored.

While at it, use max() to force the ps.chunk_size to be at least 1 to
improve readability.

Fixes: 6d45e1c948a8 ("padata: Fix possible divide-by-0 panic in padata_mt_helper()")
Signed-off-by: Kamlesh Gurudasani <kamlesh@ti.com>
Acked-by:  Waiman Long <longman@redhat.com>
Acked-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agodt-bindings: crypto: fsl,sec-v4.0: add second register space for rtic
Frank Li [Wed, 21 Aug 2024 19:20:48 +0000 (15:20 -0400)]
dt-bindings: crypto: fsl,sec-v4.0: add second register space for rtic

Add two description for register space of rtic. There are two register
space, one is for control and status, the other optional space is
recoverable error indication register space.

Fix below CHECK_DTBS error:
arch/arm64/boot/dts/freescale/fsl-ls1012a-frdm.dtb: crypto@1700000: rtic@60000:reg: [[393216, 256], [396800, 24]] is too long
        from schema $id: http://devicetree.org/schemas/crypto/fsl,sec-v4.0.yaml#

Signed-off-by: Frank Li <Frank.Li@nxp.com>
Acked-by: Conor Dooley <conor.dooley@microchip.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agohwrng: rockchip - handle devm_pm_runtime_enable errors
Martin Kaiser [Wed, 21 Aug 2024 18:12:35 +0000 (20:12 +0200)]
hwrng: rockchip - handle devm_pm_runtime_enable errors

It's unlikely that devm_pm_runtime_enable ever fails. Still, it makes
sense to read the return value and handle errors.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agohwrng: rockchip - rst is used only during probe
Martin Kaiser [Wed, 21 Aug 2024 18:12:34 +0000 (20:12 +0200)]
hwrng: rockchip - rst is used only during probe

The driver uses the rst variable only for an initial reset when the chip
is probed. There's no need to store rst in the driver's private data, we
can make it a local variable in the probe function.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agohwrng: mxc-rnga - Use devm_clk_get_enabled() helpers
Huan Yang [Tue, 20 Aug 2024 09:47:11 +0000 (17:47 +0800)]
hwrng: mxc-rnga - Use devm_clk_get_enabled() helpers

The devm_clk_get_enabled() helpers:
    - call devm_clk_get()
    - call clk_prepare_enable() and register what is needed in order to
     call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

Signed-off-by: Huan Yang <link@vivo.com>
Reviewed-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: crypto4xx - Remove unused declaration crypto4xx_free_ctx()
Yue Haibing [Tue, 20 Aug 2024 08:25:25 +0000 (16:25 +0800)]
crypto: crypto4xx - Remove unused declaration crypto4xx_free_ctx()

This function is never implemented and used since introduction in
commit 049359d65527 ("crypto: amcc - Add crypt4xx driver").

Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: amlogic - Remove unused declaration meson_enqueue()
Yue Haibing [Tue, 20 Aug 2024 08:25:24 +0000 (16:25 +0800)]
crypto: amlogic - Remove unused declaration meson_enqueue()

This function is never implemented and used since introduction in
commit 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for
amlogic GXL").

Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: ccp - Remove unused declaration sp_get_master()
Yue Haibing [Tue, 20 Aug 2024 08:25:23 +0000 (16:25 +0800)]
crypto: ccp - Remove unused declaration sp_get_master()

This function is never implemented and used since introduction in
commit 720419f01832 ("crypto: ccp - Introduce the AMD Secure Processor
device").

Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: octeontx - Remove unused declaration otx_cpt_callback()
Yue Haibing [Tue, 20 Aug 2024 08:25:22 +0000 (16:25 +0800)]
crypto: octeontx - Remove unused declaration otx_cpt_callback()

This function is never implemented and used since introduction in
commit 10b4f09491bf ("crypto: marvell - add the Virtual Function
driver for CPT")

Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: sl3516 - Remove unused declaration sl3516_ce_enqueue()
Yue Haibing [Tue, 20 Aug 2024 08:25:21 +0000 (16:25 +0800)]
crypto: sl3516 - Remove unused declaration sl3516_ce_enqueue()

This function is never implemented and used since introduction in
commit 46c5338db7bd ("crypto: sl3516 - Add sl3516 crypto engine")

Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: safexcel - Remove unused declaration safexcel_ring_first_rptr()
Yue Haibing [Tue, 20 Aug 2024 08:25:20 +0000 (16:25 +0800)]
crypto: safexcel - Remove unused declaration safexcel_ring_first_rptr()

Commit 9744fec95f06 ("crypto: inside-secure - remove request list to
improve performance") declar this but never implemented.

Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: tools/ccp - Remove unused variable
Zhu Jun [Tue, 20 Aug 2024 07:42:42 +0000 (00:42 -0700)]
crypto: tools/ccp - Remove unused variable

the variable is never referenced in the code, just remove them.

Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: jitter - Use min() to simplify jent_read_entropy()
Thorsten Blum [Mon, 19 Aug 2024 14:18:44 +0000 (16:18 +0200)]
crypto: jitter - Use min() to simplify jent_read_entropy()

Use the min() macro to simplify the jent_read_entropy() function and
improve its readability.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
7 months agocrypto: ccp - Properly unregister /dev/sev on sev PLATFORM_STATUS failure
Pavan Kumar Paluri [Thu, 15 Aug 2024 12:25:00 +0000 (07:25 -0500)]
crypto: ccp - Properly unregister /dev/sev on sev PLATFORM_STATUS failure

In case of sev PLATFORM_STATUS failure, sev_get_api_version() fails
resulting in sev_data field of psp_master nulled out. This later becomes
a problem when unloading the ccp module because the device has not been
unregistered (via misc_deregister()) before clearing the sev_data field
of psp_master. As a result, on reloading the ccp module, a duplicate
device issue is encountered as can be seen from the dmesg log below.

on reloading ccp module via modprobe ccp

Call Trace:
  <TASK>
  dump_stack_lvl+0xd7/0xf0
  dump_stack+0x10/0x20
  sysfs_warn_dup+0x5c/0x70
  sysfs_create_dir_ns+0xbc/0xd
  kobject_add_internal+0xb1/0x2f0
  kobject_add+0x7a/0xe0
  ? srso_alias_return_thunk+0x5/0xfbef5
  ? get_device_parent+0xd4/0x1e0
  ? __pfx_klist_children_get+0x10/0x10
  device_add+0x121/0x870
  ? srso_alias_return_thunk+0x5/0xfbef5
  device_create_groups_vargs+0xdc/0x100
  device_create_with_groups+0x3f/0x60
  misc_register+0x13b/0x1c0
  sev_dev_init+0x1d4/0x290 [ccp]
  psp_dev_init+0x136/0x300 [ccp]
  sp_init+0x6f/0x80 [ccp]
  sp_pci_probe+0x2a6/0x310 [ccp]
  ? srso_alias_return_thunk+0x5/0xfbef5
  local_pci_probe+0x4b/0xb0
  work_for_cpu_fn+0x1a/0x30
  process_one_work+0x203/0x600
  worker_thread+0x19e/0x350
  ? __pfx_worker_thread+0x10/0x10
  kthread+0xeb/0x120
  ? __pfx_kthread+0x10/0x10
  ret_from_fork+0x3c/0x60
  ? __pfx_kthread+0x10/0x10
  ret_from_fork_asm+0x1a/0x30
  </TASK>
  kobject: kobject_add_internal failed for sev with -EEXIST, don't try to register things with the same name in the same directory.
  ccp 0000:22:00.1: sev initialization failed
  ccp 0000:22:00.1: psp initialization failed
  ccp 0000:a2:00.1: no command queues available
  ccp 0000:a2:00.1: psp enabled

Address this issue by unregistering the /dev/sev before clearing out
sev_data in case of PLATFORM_STATUS failure.

Fixes: 200664d5237f ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support")
Cc: stable@vger.kernel.org
Signed-off-by: Pavan Kumar Paluri <papaluri@amd.com>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: simd - Do not call crypto_alloc_tfm during registration
Herbert Xu [Sat, 17 Aug 2024 06:58:35 +0000 (14:58 +0800)]
crypto: simd - Do not call crypto_alloc_tfm during registration

Algorithm registration is usually carried out during module init,
where as little work as possible should be carried out.  The SIMD
code violated this rule by allocating a tfm, this then triggers a
full test of the algorithm which may dead-lock in certain cases.

SIMD is only allocating the tfm to get at the alg object, which is
in fact already available as it is what we are registering.  Use
that directly and remove the crypto_alloc_tfm call.

Also remove some obsolete and unused SIMD API.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: api - Do not wait for tests during registration
Herbert Xu [Sat, 17 Aug 2024 06:57:40 +0000 (14:57 +0800)]
crypto: api - Do not wait for tests during registration

As registration is usually carried out during module init, this
is a context where as little work as possible should be carried
out.  Testing may trigger module loads of underlying components,
which could even lead back to the module that is registering at
the moment.  This may lead to dead-locks outside of the Crypto API.

Avoid this by not waiting for the tests to complete.  They will
be scheduled but completion will be asynchronous.  Any users will
still wait for completion.

Reported-by: Russell King <linux@armlinux.org.uk>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: api - Remove instance larval fulfilment
Herbert Xu [Sat, 17 Aug 2024 06:56:51 +0000 (14:56 +0800)]
crypto: api - Remove instance larval fulfilment

In order to allow testing to complete asynchronously after the
registration process, instance larvals need to complete prior
to having a test result.  Support this by redoing the lookup for
instance larvals after completion.   This should locate the pending
test larval and then repeat the wait on that (if it is still pending).

As the lookup is now repeated there is no longer any need to compute
the fulfilment status and all that code can be removed.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: octeontx2 - Fix authenc setkey
Herbert Xu [Sat, 17 Aug 2024 04:36:19 +0000 (12:36 +0800)]
crypto: octeontx2 - Fix authenc setkey

Use the generic crypto_authenc_extractkeys helper instead of custom
parsing code that is slightly broken.  Also fix a number of memory
leaks by moving memory allocation from setkey to init_tfm (setkey
can be called multiple times over the life of a tfm).

Finally accept all hash key lengths by running the digest over
extra-long keys.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: octeontx - Fix authenc setkey
Herbert Xu [Sat, 17 Aug 2024 04:13:23 +0000 (12:13 +0800)]
crypto: octeontx - Fix authenc setkey

Use the generic crypto_authenc_extractkeys helper instead of custom
parsing code that is slightly broken.  Also fix a number of memory
leaks by moving memory allocation from setkey to init_tfm (setkey
can be called multiple times over the life of a tfm).

Finally accept all hash key lengths by running the digest over
extra-long keys.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Fixed return to CRYPTO_OK
Pavitrakumar M [Fri, 16 Aug 2024 12:03:33 +0000 (17:33 +0530)]
crypto: spacc - Fixed return to CRYPTO_OK

Removed CRYPTO_USED_JB and returning CRYPTO_OK instead.

Signed-off-by: Bhoomika K <bhoomikak@vayavyalabs.com>
Signed-off-by: Pavitrakumar M <pavitrakumarm@vayavyalabs.com>
Acked-by: Ruud Derwig <Ruud.Derwig@synopsys.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Fix counter width checks
Pavitrakumar M [Fri, 16 Aug 2024 12:03:32 +0000 (17:33 +0530)]
crypto: spacc - Fix counter width checks

This patch fixes counter width checks according to the version extension3
register. The counter widths can be 8, 16, 32 and 64 bits as per the
extension3 register.

Signed-off-by: Bhoomika K <bhoomikak@vayavyalabs.com>
Signed-off-by: Pavitrakumar M <pavitrakumarm@vayavyalabs.com>
Acked-by: Ruud Derwig <Ruud.Derwig@synopsys.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: qat - fix "Full Going True" macro definition
Svyatoslav Pankratov [Thu, 15 Aug 2024 15:47:23 +0000 (16:47 +0100)]
crypto: qat - fix "Full Going True" macro definition

The macro `ADF_RP_INT_SRC_SEL_F_RISE_MASK` is currently set to the value
`0100b` which means "Empty Going False". This might cause an incorrect
restore of the bank state during live migration.

Fix the definition of the macro to properly represent the "Full Going
True" state which is encoded as `0011b`.

Fixes: bbfdde7d195f ("crypto: qat - add bank save and restore flows")
Signed-off-by: Svyatoslav Pankratov <svyatoslav.pankratov@intel.com>
Reviewed-by: Xin Zeng <xin.zeng@intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Check for allocation failure in spacc_skcipher_fallback()
Dan Carpenter [Thu, 15 Aug 2024 11:20:20 +0000 (14:20 +0300)]
crypto: spacc - Check for allocation failure in spacc_skcipher_fallback()

Check for crypto_alloc_skcipher() failure.

Fixes: c8981d9230d8 ("crypto: spacc - Add SPAcc Skcipher support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Fix NULL vs IS_ERR() check in spacc_aead_fallback()
Dan Carpenter [Thu, 15 Aug 2024 11:20:12 +0000 (14:20 +0300)]
crypto: spacc - Fix NULL vs IS_ERR() check in spacc_aead_fallback()

The crypto_alloc_aead() function doesn't return NULL pointers, it returns
error pointers.  Fix the error checking.

Fixes: 06af76b46c78 ("crypto: spacc - Add SPAcc aead support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Fix uninitialized variable in spacc_aead_process()
Dan Carpenter [Thu, 15 Aug 2024 11:20:04 +0000 (14:20 +0300)]
crypto: spacc - Fix uninitialized variable in spacc_aead_process()

Smatch complains that:

    drivers/crypto/dwc-spacc/spacc_aead.c:1031 spacc_aead_process()
    error: uninitialized symbol 'ptaadsize'.

This could happen if, for example, tctx->mode was CRYPTO_MODE_NULL and
req->cryptlen was less than icvremove.

Fixes: 06af76b46c78 ("crypto: spacc - Add SPAcc aead support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Use crypto_authenc_extractkeys
Herbert Xu [Thu, 15 Aug 2024 08:51:38 +0000 (16:51 +0800)]
crypto: spacc - Use crypto_authenc_extractkeys

Use the crypto_authenc_extractkeys helper rather than ad-hoc parsing.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Add a new line in spacc_open()
Dan Carpenter [Wed, 14 Aug 2024 21:12:03 +0000 (00:12 +0300)]
crypto: spacc - Add a new line in spacc_open()

Put the break statement should be on its own line.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Fix off by one in spacc_isenabled()
Dan Carpenter [Wed, 14 Aug 2024 21:11:58 +0000 (00:11 +0300)]
crypto: spacc - Fix off by one in spacc_isenabled()

The spacc->config.modes[] array has CRYPTO_MODE_LAST number of elements
so this > comparison should be >= to prevent an out of bounds access.

Fixes: c8981d9230d8 ("crypto: spacc - Add SPAcc Skcipher support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Fix bounds checking on spacc->job[]
Dan Carpenter [Wed, 14 Aug 2024 21:11:51 +0000 (00:11 +0300)]
crypto: spacc - Fix bounds checking on spacc->job[]

This bounds checking is off by one.  The > should be >=.  The
spacc->job[] array is allocated in spacc_init() and it has
SPACC_MAX_JOBS elements.

Fixes: 8ebb14deef0f ("crypto: spacc - Enable SPAcc AUTODETECT")
Fixes: c8981d9230d8 ("crypto: spacc - Add SPAcc Skcipher support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: ccp - Add additional information about an SEV firmware upgrade
Tom Lendacky [Wed, 14 Aug 2024 20:42:40 +0000 (15:42 -0500)]
crypto: ccp - Add additional information about an SEV firmware upgrade

Print additional information, in the form of the old and new versions of
the SEV firmware, so that it can be seen what the base firmware was before
the upgrade.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Ashish Kalra <ashish.kalra@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: x86/sha256 - Add parentheses around macros' single arguments
Fangrui Song [Wed, 14 Aug 2024 04:48:02 +0000 (21:48 -0700)]
crypto: x86/sha256 - Add parentheses around macros' single arguments

The macros FOUR_ROUNDS_AND_SCHED and DO_4ROUNDS rely on an
unexpected/undocumented behavior of the GNU assembler, which might
change in the future
(https://sourceware.org/bugzilla/show_bug.cgi?id=32073).

    M (1) (2) // 1 arg !? Future: 2 args
    M 1 + 2   // 1 arg !? Future: 3 args

    M 1 2     // 2 args

Add parentheses around the single arguments to support future GNU
assembler and LLVM integrated assembler (when the IsOperator hack from
the following link is dropped).

Link: https://github.com/llvm/llvm-project/commit/055006475e22014b28a070db1bff41ca15f322f0
Signed-off-by: Fangrui Song <maskray@google.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: keembay - fix module autoloading
Liao Chen [Wed, 14 Aug 2024 02:44:06 +0000 (02:44 +0000)]
crypto: keembay - fix module autoloading

Add MODULE_DEVICE_TABLE(), so modules could be properly autoloaded
based on the alias from of_device_id table.

Signed-off-by: Liao Chen <liaochen4@huawei.com>
Acked-by: Daniele Alessandrelli <daniele.alessandrelli@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: jitter - set default OSR to 3
Stephan Mueller [Mon, 12 Aug 2024 06:25:42 +0000 (08:25 +0200)]
crypto: jitter - set default OSR to 3

The user space Jitter RNG library uses the oversampling rate of 3 which
implies that each time stamp is credited with 1/3 bit of entropy. To
obtain 256 bits of entropy, 768 time stamps need to be sampled. The
increase in OSR is applied based on a report where the Jitter RNG is
used on a system exhibiting a challenging environment to collect
entropy.

This OSR default value is now applied to the Linux kernel version of
the Jitter RNG as well.

The increase in the OSR from 1 to 3 also implies that the Jitter RNG is
now slower by default.

Reported-by: Jeff Barnes <jeffbarnes@microsoft.com>
Signed-off-by: Stephan Mueller <smueller@chronox.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: octeontx2 - Remove custom swap functions in favor of built-in sort swap
Kuan-Wei Chiu [Sun, 11 Aug 2024 06:28:17 +0000 (14:28 +0800)]
crypto: octeontx2 - Remove custom swap functions in favor of built-in sort swap

The custom swap functions used in octeontx2 driver do not perform any
special operations and can be replaced with the built-in swap function
of sort. This change not only reduces code size but also improves
efficiency, especially in scenarios where CONFIG_RETPOLINE is enabled,
as it makes indirect function calls more expensive.

By using the built-in swap, we avoid these costly indirect function
calls, leading to better performance.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: octeontx - Remove custom swap function in favor of built-in sort swap
Kuan-Wei Chiu [Sun, 11 Aug 2024 06:28:16 +0000 (14:28 +0800)]
crypto: octeontx - Remove custom swap function in favor of built-in sort swap

The custom swap function used in octeontx driver do not perform any
special operations and can be replaced with the built-in swap function
of sort. This change not only reduces code size but also improves
efficiency, especially in scenarios where CONFIG_RETPOLINE is enabled,
as it makes indirect function calls more expensive.

By using the built-in swap, we avoid these costly indirect function
calls, leading to better performance.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: rsa - Check MPI allocation errors
Herbert Xu [Sat, 10 Aug 2024 06:21:02 +0000 (14:21 +0800)]
crypto: rsa - Check MPI allocation errors

Fixes: 6637e11e4ad2 ("crypto: rsa - allow only odd e and restrict value in FIPS mode")
Fixes: f145d411a67e ("crypto: rsa - implement Chinese Remainder Theorem for faster private key operation")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: dh - Check mpi_rshift errors
Herbert Xu [Sat, 10 Aug 2024 06:20:59 +0000 (14:20 +0800)]
crypto: dh - Check mpi_rshift errors

Now that mpi_rshift can return errors, check them.

Fixes: 35d2bf20683f ("crypto: dh - calculate Q from P for the full public key verification")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: lib/mpi - Add error checks to extension
Herbert Xu [Sat, 10 Aug 2024 06:20:57 +0000 (14:20 +0800)]
crypto: lib/mpi - Add error checks to extension

The remaining functions added by commit
a8ea8bdd9df92a0e5db5b43900abb7a288b8a53e did not check for memory
allocation errors.  Add the checks and change the API to allow errors
to be returned.

Fixes: a8ea8bdd9df9 ("lib/mpi: Extend the MPI library")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agoRevert "lib/mpi: Extend the MPI library"
Herbert Xu [Sat, 10 Aug 2024 06:20:55 +0000 (14:20 +0800)]
Revert "lib/mpi: Extend the MPI library"

This partially reverts commit a8ea8bdd9df92a0e5db5b43900abb7a288b8a53e.

Most of it is no longer needed since sm2 has been removed.  However,
the following functions have been kept as they have developed other
uses:

mpi_copy

mpi_mod

mpi_test_bit
mpi_set_bit
mpi_rshift

mpi_add
mpi_sub
mpi_addm
mpi_subm

mpi_mul
mpi_mulm

mpi_tdiv_r
mpi_fdiv_r

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: arm/aes-neonbs - go back to using aes-arm directly
Eric Biggers [Fri, 9 Aug 2024 23:11:49 +0000 (16:11 -0700)]
crypto: arm/aes-neonbs - go back to using aes-arm directly

In aes-neonbs, instead of going through the crypto API for the parts
that the bit-sliced AES code doesn't handle, namely AES-CBC encryption
and single-block AES, just call the ARM scalar AES cipher directly.

This basically goes back to the original approach that was used before
commit b56f5cbc7e08 ("crypto: arm/aes-neonbs - resolve fallback cipher
at runtime").  Calling the ARM scalar AES cipher directly is faster,
simpler, and avoids any chance of bugs specific to the use of fallback
ciphers such as module loading deadlocks which have happened twice.  The
deadlocks turned out to be fixable in other ways, but there's no need to
rely on anything so fragile in the first place.

The rationale for the above-mentioned commit was to allow people to
choose to use a time-invariant AES implementation for the fallback
cipher.  There are a couple problems with that rationale, though:

- In practice the ARM scalar AES cipher (aes-arm) was used anyway, since
  it has a higher priority than aes-fixed-time.  Users *could* go out of
  their way to disable or blacklist aes-arm, or to lower its priority
  using NETLINK_CRYPTO, but very few users customize the crypto API to
  this extent.  Systems with the ARMv8 Crypto Extensions used aes-ce,
  but the bit-sliced algorithms are irrelevant on such systems anyway.

- Since commit 913a3aa07d16 ("crypto: arm/aes - add some hardening
  against cache-timing attacks"), the ARM scalar AES cipher is partially
  hardened against cache-timing attacks.  It actually works like
  aes-fixed-time, in that it disables interrupts and prefetches its
  lookup table.  It does use a larger table than aes-fixed-time, but
  even so, it is not clear that aes-fixed-time is meaningfully more
  time-invariant than aes-arm.  And of course, the real solution for
  time-invariant AES is to use a CPU that supports AES instructions.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agopadata: use integer wrap around to prevent deadlock on seq_nr overflow
VanGiang Nguyen [Fri, 9 Aug 2024 06:21:42 +0000 (06:21 +0000)]
padata: use integer wrap around to prevent deadlock on seq_nr overflow

When submitting more than 2^32 padata objects to padata_do_serial, the
current sorting implementation incorrectly sorts padata objects with
overflowed seq_nr, causing them to be placed before existing objects in
the reorder list. This leads to a deadlock in the serialization process
as padata_find_next cannot match padata->seq_nr and pd->processed
because the padata instance with overflowed seq_nr will be selected
next.

To fix this, we use an unsigned integer wrap around to correctly sort
padata objects in scenarios with integer overflow.

Fixes: bfde23ce200e ("padata: unbind parallel jobs from specific CPUs")
Cc: <stable@vger.kernel.org>
Co-developed-by: Christian Gafert <christian.gafert@rohde-schwarz.com>
Signed-off-by: Christian Gafert <christian.gafert@rohde-schwarz.com>
Co-developed-by: Max Ferger <max.ferger@rohde-schwarz.com>
Signed-off-by: Max Ferger <max.ferger@rohde-schwarz.com>
Signed-off-by: Van Giang Nguyen <vangiang.nguyen@rohde-schwarz.com>
Acked-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: nx - Use static_assert() to check struct sizes
Gustavo A. R. Silva [Thu, 8 Aug 2024 22:09:06 +0000 (16:09 -0600)]
crypto: nx - Use static_assert() to check struct sizes

Commit 1e6b251ce175 ("crypto: nx - Avoid -Wflex-array-member-not-at-end
warning") introduced tagged `struct nx842_crypto_header_hdr`. We want
to ensure that when new members need to be added to the flexible
structure, they are always included within this tagged struct.

So, we use `static_assert()` to ensure that the memory layout for
both the flexible structure and the tagged struct is the same after
any changes.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: qat - Use static_assert() to check struct sizes
Gustavo A. R. Silva [Thu, 8 Aug 2024 22:05:26 +0000 (16:05 -0600)]
crypto: qat - Use static_assert() to check struct sizes

Commit 140e4c85d540 ("crypto: qat - Avoid -Wflex-array-member-not-at-end
warnings") introduced tagged `struct qat_alg_buf_list_hdr`. We want to
ensure that when new members need to be added to the flexible structure,
they are always included within this tagged struct.

So, we use `static_assert()` to ensure that the memory layout for
both the flexible structure and the tagged struct is the same after
any changes.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Acked-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: arm64/poly1305 - move data to rodata section
Jia He [Tue, 6 Aug 2024 05:54:44 +0000 (05:54 +0000)]
crypto: arm64/poly1305 - move data to rodata section

When objtool gains support for ARM in the future, it may encounter issues
disassembling the following data in the .text section:
> .Lzeros:
> .long   0,0,0,0,0,0,0,0
> .asciz  "Poly1305 for ARMv8, CRYPTOGAMS by \@dot-asm"
> .align  2

Move it to .rodata which is a more appropriate section for read-only data.

There is a limit on how far the label can be from the instruction, hence
use "adrp" and low 12bits offset of the label to avoid the compilation
error.

Signed-off-by: Jia He <justin.he@arm.com>
Tested-by: Daniel Gomez <da.gomez@samsung.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: chacha20poly1305 - Annotate struct chachapoly_ctx with __counted_by()
Thorsten Blum [Mon, 5 Aug 2024 22:11:30 +0000 (00:11 +0200)]
crypto: chacha20poly1305 - Annotate struct chachapoly_ctx with __counted_by()

Add the __counted_by compiler attribute to the flexible array member
salt to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
CONFIG_FORTIFY_SOURCE.

Reviewed-by: Kees Cook <kees@kernel.org>
Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Add ifndef around MIN
Stephen Rothwell [Mon, 12 Aug 2024 00:42:35 +0000 (10:42 +1000)]
crypto: spacc - Add ifndef around MIN

Fixup for "crypto: spacc - Add SPAcc Skcipher support"
interacting with commit

  1a251f52cfdc ("minmax: make generic MIN() and MAX() macros available everywhere")

from Linus' tree.

Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Reintroduced MIN macro with ifndef around it.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: x86/aes-gcm - fix PREEMPT_RT issue in gcm_crypt()
Eric Biggers [Mon, 5 Aug 2024 18:27:13 +0000 (11:27 -0700)]
crypto: x86/aes-gcm - fix PREEMPT_RT issue in gcm_crypt()

On PREEMPT_RT, kfree() takes sleeping locks and must not be called with
preemption disabled.  Therefore, on PREEMPT_RT skcipher_walk_done() must
not be called from within a kernel_fpu_{begin,end}() pair, even when
it's the last call which is guaranteed to not allocate memory.

Therefore, move the last skcipher_walk_done() in gcm_crypt() to the end
of the function so that it goes after the kernel_fpu_end().  To make
this work cleanly, rework the data processing loop to handle only
non-last data segments.

Fixes: b06affb1cb58 ("crypto: x86/aes-gcm - add VAES and AVX512 / AVX10 optimized AES-GCM")
Reported-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Closes: https://lore.kernel.org/linux-crypto/20240802102333.itejxOsJ@linutronix.de
Signed-off-by: Eric Biggers <ebiggers@google.com>
Tested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agohwrng: cctrng - Add missing clk_disable_unprepare in cctrng_resume
Gaosheng Cui [Sat, 3 Aug 2024 06:49:23 +0000 (14:49 +0800)]
hwrng: cctrng - Add missing clk_disable_unprepare in cctrng_resume

Add the missing clk_disable_unprepare() before return in
cctrng_resume().

Fixes: a583ed310bb6 ("hwrng: cctrng - introduce Arm CryptoCell driver")
Cc: <stable@vger.kernel.org>
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agohwrng: bcm2835 - Add missing clk_disable_unprepare in bcm2835_rng_init
Gaosheng Cui [Sat, 3 Aug 2024 06:49:22 +0000 (14:49 +0800)]
hwrng: bcm2835 - Add missing clk_disable_unprepare in bcm2835_rng_init

Add the missing clk_disable_unprepare() before return in
bcm2835_rng_init().

Fixes: e5f9f41d5e62 ("hwrng: bcm2835 - add reset support")
Cc: <stable@vger.kernel.org>
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agoRevert "lib/mpi: Introduce ec implementation to MPI library"
Herbert Xu [Fri, 2 Aug 2024 06:09:00 +0000 (14:09 +0800)]
Revert "lib/mpi: Introduce ec implementation to MPI library"

This reverts commit d58bb7e55a8a65894cc02f27c3e2bf9403e7c40f.

It's no longer needed since sm2 has been removed.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agohwrng: rockchip - add hwrng driver for Rockchip RK3568 SoC
Aurelien Jarno [Tue, 30 Jul 2024 16:11:04 +0000 (17:11 +0100)]
hwrng: rockchip - add hwrng driver for Rockchip RK3568 SoC

Rockchip SoCs used to have a random number generator as part of their
crypto device, and support for it has to be added to the corresponding
driver. However newer Rockchip SoCs like the RK3568 have an independent
True Random Number Generator device. This patch adds a driver for it,
greatly inspired from the downstream driver.

The TRNG device does not seem to have a signal conditionner and the FIPS
140-2 test returns a lot of failures. They can be reduced by increasing
RK_RNG_SAMPLE_CNT, in a tradeoff between quality and speed. This value
has been adjusted to get ~90% of successes and the quality value has
been set accordingly.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
[daniel@makrotpia.org: code style fixes]
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agodt-bindings: rng: Add Rockchip RK3568 TRNG
Aurelien Jarno [Tue, 30 Jul 2024 16:08:19 +0000 (17:08 +0100)]
dt-bindings: rng: Add Rockchip RK3568 TRNG

Add the True Random Number Generator on the Rockchip RK3568 SoC.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: caam/qi* - Use cpumask_var_t instead of cpumask_t
Herbert Xu [Tue, 30 Jul 2024 03:41:55 +0000 (11:41 +0800)]
crypto: caam/qi* - Use cpumask_var_t instead of cpumask_t

Switch cpumask_t to cpumask_var_t as the former may be too big
for the stack:

  CC [M]  drivers/crypto/caam/qi.o
  CC [M]  drivers/crypto/caam/caamalg_qi2.o
../drivers/crypto/caam/qi.c: In function ‘caam_qi_init’:
../drivers/crypto/caam/qi.c:808:1: warning: the frame size of 1056 bytes is larger than 1024 bytes [-Wframe-larger-than=]
  808 | }
      | ^
  CHECK   ../drivers/crypto/caam/qi.c
../drivers/crypto/caam/caamalg_qi2.c: In function ‘dpaa2_dpseci_setup’:
../drivers/crypto/caam/caamalg_qi2.c:5135:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]
 5135 | }
      | ^

Also fix the error path handling in qi.c.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agohwrng: cn10k - Enable by default CN10K driver if Thunder SoC is enabled
Francesco Dolcini [Mon, 29 Jul 2024 11:36:40 +0000 (13:36 +0200)]
hwrng: cn10k - Enable by default CN10K driver if Thunder SoC is enabled

Before commit addea5858b66 ("hwrng: Kconfig - Do not enable by default
CN10K driver") the Marvell CN10K Random Number Generator was always
enabled when HW_RANDOM was enabled.

This was changed with that commit to prevent having this driver being
always enabled on arm64. To prevent introducing regression with some old
defconfig enable the driver when ARCH_THUNDER is enabled.

Fixes: addea5858b66 ("hwrng: Kconfig - Do not enable by default CN10K driver")
Closes: https://lore.kernel.org/all/SN7PR18MB53144B37B82ADEEC5D35AE0CE3AC2@SN7PR18MB5314.namprd18.prod.outlook.com/
Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Enable Driver compilation in crypto Kconfig and Makefile
Pavitrakumar M [Mon, 29 Jul 2024 04:13:50 +0000 (09:43 +0530)]
crypto: spacc - Enable Driver compilation in crypto Kconfig and Makefile

Signed-off-by: Bhoomika K <bhoomikak@vayavyalabs.com>
Signed-off-by: Pavitrakumar M <pavitrakumarm@vayavyalabs.com>
Acked-by: Ruud Derwig <Ruud.Derwig@synopsys.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Add SPAcc Kconfig and Makefile
Pavitrakumar M [Mon, 29 Jul 2024 04:13:49 +0000 (09:43 +0530)]
crypto: spacc - Add SPAcc Kconfig and Makefile

Signed-off-by: shwetar <shwetar@vayavyalabs.com>
Signed-off-by: Pavitrakumar M <pavitrakumarm@vayavyalabs.com>
Acked-by: Ruud Derwig <Ruud.Derwig@synopsys.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Add SPAcc aead support
Pavitrakumar M [Mon, 29 Jul 2024 04:13:48 +0000 (09:43 +0530)]
crypto: spacc - Add SPAcc aead support

Signed-off-by: shwetar <shwetar@vayavyalabs.com>
Signed-off-by: Pavitrakumar M <pavitrakumarm@vayavyalabs.com>
Acked-by: Ruud Derwig <Ruud.Derwig@synopsys.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Add SPAcc ahash support
Pavitrakumar M [Mon, 29 Jul 2024 04:13:47 +0000 (09:43 +0530)]
crypto: spacc - Add SPAcc ahash support

Signed-off-by: shwetar <shwetar@vayavyalabs.com>
Signed-off-by: Pavitrakumar M <pavitrakumarm@vayavyalabs.com>
Acked-by: Ruud Derwig <Ruud.Derwig@synopsys.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Enable SPAcc AUTODETECT
Pavitrakumar M [Mon, 29 Jul 2024 04:13:46 +0000 (09:43 +0530)]
crypto: spacc - Enable SPAcc AUTODETECT

Signed-off-by: Bhoomika K <bhoomikak@vayavyalabs.com>
Signed-off-by: Pavitrakumar M <pavitrakumarm@vayavyalabs.com>
Acked-by: Ruud Derwig <Ruud.Derwig@synopsys.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: spacc - Add SPAcc Skcipher support
Pavitrakumar M [Mon, 29 Jul 2024 04:13:45 +0000 (09:43 +0530)]
crypto: spacc - Add SPAcc Skcipher support

Signed-off-by: Bhoomika K <bhoomikak@vayavyalabs.com>
Signed-off-by: Pavitrakumar M <pavitrakumarm@vayavyalabs.com>
Acked-by: Ruud Derwig <Ruud.Derwig@synopsys.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agoRevert "crypto: arm64/poly1305 - move data to rodata section"
Herbert Xu [Tue, 6 Aug 2024 05:45:59 +0000 (13:45 +0800)]
Revert "crypto: arm64/poly1305 - move data to rodata section"

This reverts commit 47d96252099a7184b4bad852fcfa3c233c1d2f71.

It causes build issues as detected by the kernel test robot.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202408040817.OWKXtCv6-lkp@intel.com/
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: iaa - Fix potential use after free bug
Dan Carpenter [Wed, 24 Jul 2024 16:09:43 +0000 (11:09 -0500)]
crypto: iaa - Fix potential use after free bug

The free_device_compression_mode(iaa_device, device_mode) function frees
"device_mode" but it iss passed to iaa_compression_modes[i]->free() a few
lines later resulting in a use after free.

The good news is that, so far as I can tell, nothing implements the
->free() function and the use after free happens in dead code.  But, with
this fix, when something does implement it, we'll be ready.  :)

Fixes: b190447e0fa3 ("crypto: iaa - Add compression mode management along with fixed mode")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: ppc/curve25519 - add missing MODULE_DESCRIPTION() macro
Jeff Johnson [Fri, 19 Jul 2024 01:14:18 +0000 (18:14 -0700)]
crypto: ppc/curve25519 - add missing MODULE_DESCRIPTION() macro

Since commit 1fffe7a34c89 ("script: modpost: emit a warning when the
description is missing"), a module without a MODULE_DESCRIPTION() will
result in a warning with make W=1. The following warning is being
observed when building ppc64le with CRYPTO_CURVE25519_PPC64=m:

WARNING: modpost: missing MODULE_DESCRIPTION() in arch/powerpc/crypto/curve25519-ppc64le.o

Add the missing invocation of the MODULE_DESCRIPTION() macro.

Signed-off-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: qat - allow disabling SR-IOV VFs
Michal Witwicki [Wed, 17 Jul 2024 11:45:00 +0000 (07:45 -0400)]
crypto: qat - allow disabling SR-IOV VFs

The QAT driver allows enabling SR-IOV VFs but does not allow them to be
disabled through a write to sysfs.
Disabling SR-IOV VFs can be only achieved by bringing down and up a
device using the attribute /sys/bus/pci/devices/<BDF>/qat/state.

The documentation for the sysfs attribute `sriov_numvfs` specifies
that "a userspace application wanting to disable the VFs would write a
zero to this file".

Add support for disabling SR-IOV VFs by writing '0' to the
'sriov_numvfs' attribute in sysfs.

Enabling or disabling SR-IOV always requires adf_dev_down() to be
called. This action subsequently leads to the deletion of the
ADF_KERNEL_SEC configuration section. The keys ADF_NUM_CY and ADF_NUM_DC
within that section must be set to '0', otherwise, the driver will
register into the Linux Crypto Framework. Because of this, the
configuration in the ADF_KERNEL_SEC section must be added before every
sriov_enable.

Signed-off-by: Michal Witwicki <michal.witwicki@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: qat - ensure correct order in VF restarting handler
Michal Witwicki [Wed, 17 Jul 2024 11:44:59 +0000 (07:44 -0400)]
crypto: qat - ensure correct order in VF restarting handler

In the process of sending the ADF_PF2VF_MSGTYPE_RESTARTING message to
Virtual Functions (VFs), the Physical Function (PF) should set the
`vf->restarting` flag to true before dispatching the message.
This change is necessary to prevent a race condition where the handling
of the ADF_VF2PF_MSGTYPE_RESTARTING_COMPLETE message (which sets the
`vf->restarting` flag to false) runs immediately after the message is sent,
but before the flag is set to true.

Set the `vf->restarting` to true before sending the message
ADF_PF2VF_MSGTYPE_RESTARTING, if supported by the version of the
protocol and if the VF is started.

Fixes: ec26f8e6c784 ("crypto: qat - update PFVF protocol for recovery")
Signed-off-by: Michal Witwicki <michal.witwicki@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: qat - fix recovery flow for VFs
Michal Witwicki [Wed, 17 Jul 2024 11:44:58 +0000 (07:44 -0400)]
crypto: qat - fix recovery flow for VFs

When the PFVF protocol was updated to support version 5, i.e.
ADF_PFVF_COMPAT_FALLBACK, the compatibility version for the VF was
updated without supporting the message RESTARTING_COMPLETE required for
such version.

Add support for the ADF_VF2PF_MSGTYPE_RESTARTING_COMPLETE message in the
VF drivers. This message is sent by the VF driver to the PF to notify
the completion of the shutdown flow.

Fixes: ec26f8e6c784 ("crypto: qat - update PFVF protocol for recovery")
Signed-off-by: Michal Witwicki <michal.witwicki@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: qat - disable IOV in adf_dev_stop()
Michal Witwicki [Wed, 17 Jul 2024 11:44:57 +0000 (07:44 -0400)]
crypto: qat - disable IOV in adf_dev_stop()

Disabling IOV has the side effect of re-enabling the AEs that might
attempt to do DMAs into the heartbeat buffers.
Move the disable_iov() function in adf_dev_stop() before the AEs are
stopped.

Fixes: ed8ccaef52fa ("crypto: qat - Add support for SRIOV")
Signed-off-by: Michal Witwicki <michal.witwicki@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: qat - preserve ADF_GENERAL_SEC
Adam Guerin [Wed, 17 Jul 2024 11:44:56 +0000 (07:44 -0400)]
crypto: qat - preserve ADF_GENERAL_SEC

The ADF_GENERAL_SEC configuration section contains values that must be
preserved during state transitions (down -> up, up -> down).
This patch modifies the logic in adf_dev_shutdown() to maintain all
key values within this section, rather than selectively saving and
restoring only the ADF_SERVICES_ENABLED attribute.

To achieve this, a new function has been introduced that deletes all
configuration sections except for the one specified by name.
This function is invoked during adf_dev_down(), with ADF_GENERAL_SEC
as the argument. Consequently, the adf_dev_shutdown_cache_cfg() function
has been removed as it is now redundant.

Additionally, this patch eliminates the cache_config parameter from
the adf_dev_down() function since ADF_GENERAL_SEC should always be
retained. This change does not cause any side effects because all
entries in the key-value store are cleared when a module is unloaded.

Signed-off-by: Adam Guerin <adam.guerin@intel.com>
Co-developed-by: Michal Witwicki <michal.witwicki@intel.com>
Signed-off-by: Michal Witwicki <michal.witwicki@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: arm64/poly1305 - move data to rodata section
Jia He [Mon, 15 Jul 2024 07:20:23 +0000 (07:20 +0000)]
crypto: arm64/poly1305 - move data to rodata section

When objtool gains support for ARM in the future, it may encounter issues
disassembling the following data in the .text section:
> .Lzeros:
> .long   0,0,0,0,0,0,0,0
> .asciz  "Poly1305 for ARMv8, CRYPTOGAMS by \@dot-asm"
> .align  2

Move it to .rodata which is a more appropriate section for read-only data.

Signed-off-by: Jia He <justin.he@arm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
8 months agocrypto: xor - fix template benchmarking
Helge Deller [Mon, 8 Jul 2024 12:24:52 +0000 (14:24 +0200)]
crypto: xor - fix template benchmarking

Commit c055e3eae0f1 ("crypto: xor - use ktime for template benchmarking")
switched from using jiffies to ktime-based performance benchmarking.

This works nicely on machines which have a fine-grained ktime()
clocksource as e.g. x86 machines with TSC.
But other machines, e.g. my 4-way HP PARISC server, don't have such
fine-grained clocksources, which is why it seems that 800 xor loops
take zero seconds, which then shows up in the logs as:

 xor: measuring software checksum speed
    8regs           : -1018167296 MB/sec
    8regs_prefetch  : -1018167296 MB/sec
    32regs          : -1018167296 MB/sec
    32regs_prefetch : -1018167296 MB/sec

Fix this with some small modifications to the existing code to improve
the algorithm to always produce correct results without introducing
major delays for architectures with a fine-grained ktime()
clocksource:
a) Delay start of the timing until ktime() just advanced. On machines
with a fast ktime() this should be just one additional ktime() call.
b) Count the number of loops. Run at minimum 800 loops and finish
earliest when the ktime() counter has progressed.

With that the throughput can now be calculated more accurately under all
conditions.

Fixes: c055e3eae0f1 ("crypto: xor - use ktime for template benchmarking")
Signed-off-by: Helge Deller <deller@gmx.de>
Tested-by: John David Anglin <dave.anglin@bell.net>
v2:
- clean up coding style (noticed & suggested by Herbert Xu)
- rephrased & fixed typo in commit message

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
9 months agoLinux 6.11-rc1
Linus Torvalds [Sun, 28 Jul 2024 21:19:55 +0000 (14:19 -0700)]
Linux 6.11-rc1

9 months agoMerge tag 'kbuild-fixes-v6.11' of git://git.kernel.org/pub/scm/linux/kernel/git/masah...
Linus Torvalds [Sun, 28 Jul 2024 21:02:48 +0000 (14:02 -0700)]
Merge tag 'kbuild-fixes-v6.11' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild fixes from Masahiro Yamada:

 - Fix RPM package build error caused by an incorrect locale setup

 - Mark modules.weakdep as ghost in RPM package

 - Fix the odd combination of -S and -c in stack protector scripts,
   which is an error with the latest Clang

* tag 'kbuild-fixes-v6.11' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
  kbuild: Fix '-S -c' in x86 stack protector scripts
  kbuild: rpm-pkg: ghost modules.weakdep file
  kbuild: rpm-pkg: Fix C locale setup

9 months agominmax: simplify and clarify min_t()/max_t() implementation
Linus Torvalds [Sun, 28 Jul 2024 20:50:01 +0000 (13:50 -0700)]
minmax: simplify and clarify min_t()/max_t() implementation

This simplifies the min_t() and max_t() macros by no longer making them
work in the context of a C constant expression.

That means that you can no longer use them for static initializers or
for array sizes in type definitions, but there were only a couple of
such uses, and all of them were converted (famous last words) to use
MIN_T/MAX_T instead.

Cc: David Laight <David.Laight@aculab.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>