Commit Graph

11 Commits

Author SHA1 Message Date
Lucas Karpinski bed8a6b445 crypto: qcom-rng - Convert to platform remove callback returning void
JIRA: https://issues.redhat.com/browse/RHEL-36682

commit 37548f1dd35de924bb9a1b1dafdb4d4bffd42ddd
Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date:   Fri Oct 20 09:55:55 2023 +0200

    crypto: qcom-rng - Convert to platform remove callback returning void

    The .remove() callback for a platform driver returns an int which makes
    many driver authors wrongly assume it's possible to do error handling by
    returning an error code. However the value returned is ignored (apart
    from emitting a warning) and this typically results in resource leaks.

    To improve here there is a quest to make the remove callback return
    void. In the first step of this quest all drivers are converted to
    .remove_new(), which already returns void. Eventually after all drivers
    are converted, .remove_new() will be renamed to .remove().

    Trivially convert this driver from always returning zero in the remove
    callback to the void returning variant.

    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Lucas Karpinski <lkarpins@redhat.com>
2024-05-16 16:05:23 -04:00
Lucas Karpinski cecb634c73 crypto: qcom-rng - Add hw_random interface support
JIRA: https://issues.redhat.com/browse/RHEL-36682

commit f29cd5bb64c258f29b4c49452532481f50eb43ca
Author: Om Prakash Singh <quic_omprsing@quicinc.com>
Date:   Tue Oct 3 09:10:21 2023 +0200

    crypto: qcom-rng - Add hw_random interface support

    Add hw_random interface support in qcom-rng driver as new IP block
    in Qualcomm SoC has inbuilt NIST SP800 90B compliant entropic source
    to generate true random number.

    Keeping current rng_alg interface as well for random number generation
    using Kernel Crypto API.

    Signed-off-by: Om Prakash Singh <quic_omprsing@quicinc.com>
    Reviewed-by: Bjorn Andersson <quic_bjorande@quicinc.com>
    Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
    Acked-by: Om Prakash Singh <quic_omprsing@quicinc.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Lucas Karpinski <lkarpins@redhat.com>
2024-05-16 16:05:23 -04:00
Lucas Karpinski 7bc294f868 crypto: qcom-rng: Make the core clock optional regardless of ACPI presence
JIRA: https://issues.redhat.com/browse/RHEL-36682

commit cdb8b7e1692a81f26030050ec30aadd2e7538fef
Author: Konrad Dybcio <konrad.dybcio@linaro.org>
Date:   Fri Aug 11 22:50:57 2023 +0200

    crypto: qcom-rng: Make the core clock optional regardless of ACPI presence

    Some newer SoCs (like SM8450) do not require a clock vote for the PRNG
    to function. Make it entirely optional and rely on the bindings checker
    to ensure platforms that need it, consume one.

    Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
    Reviewed-by: Bjorn Andersson <andersson@kernel.org>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Lucas Karpinski <lkarpins@redhat.com>
2024-05-16 16:05:23 -04:00
Lucas Karpinski d5f06dcf82 crypto: qcom-rng - Fix qcom_rng_of_match unused warning
JIRA: https://issues.redhat.com/browse/RHEL-36682

commit 882aa6525cabcfa0cea61e1a19c9af4c543118ac
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Fri Jul 29 17:35:31 2022 +0800

    crypto: qcom-rng - Fix qcom_rng_of_match unused warning

    Module device tables need to be declared as maybe_unused because
    they will be unused when built-in and the corresponding option is
    also disabled.

    This patch adds the maybe_unused attributes to OF and ACPI.  This
    also allows us to remove the ifdef around the ACPI data structure.

    Reported-by: kernel test robot <lkp@intel.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
    Reviewed-by: Vinod Koul <vkoul@kernel.org>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Lucas Karpinski <lkarpins@redhat.com>
2024-05-16 16:05:23 -04:00
Brian Masney 51178150f4 crypto: qcom-rng - fix infinite loop on requests not multiple of WORD_SZ
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121062
Upstream Status: commit 16287397ec5c08aa58db6acf7dbc55470d78087d

commit 16287397ec5c08aa58db6acf7dbc55470d78087d
Author: Ondrej Mosnacek <omosnace@redhat.com>
Date:   Tue May 3 13:50:10 2022 +0200

    crypto: qcom-rng - fix infinite loop on requests not multiple of WORD_SZ

    The commit referenced in the Fixes tag removed the 'break' from the else
    branch in qcom_rng_read(), causing an infinite loop whenever 'max' is
    not a multiple of WORD_SZ. This can be reproduced e.g. by running:

        kcapi-rng -b 67 >/dev/null

    There are many ways to fix this without adding back the 'break', but
    they all seem more awkward than simply adding it back, so do just that.

    Tested on a machine with Qualcomm Amberwing processor.

    Fixes: a680b1832ced ("crypto: qcom-rng - ensure buffer for generate is completely filled")
    Cc: stable@vger.kernel.org
    Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
    Reviewed-by: Brian Masney <bmasney@redhat.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Brian Masney <bmasney@redhat.com>
2023-04-10 10:05:11 -04:00
Brian Masney c0799d1521 crypto: qcom-rng - ensure buffer for generate is completely filled
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121062
Upstream Status: commit a680b1832ced3b5fa7c93484248fd221ea0d614b

commit a680b1832ced3b5fa7c93484248fd221ea0d614b
Author: Brian Masney <bmasney@redhat.com>
Date:   Thu Mar 10 18:24:59 2022 -0500

    crypto: qcom-rng - ensure buffer for generate is completely filled

    The generate function in struct rng_alg expects that the destination
    buffer is completely filled if the function returns 0. qcom_rng_read()
    can run into a situation where the buffer is partially filled with
    randomness and the remaining part of the buffer is zeroed since
    qcom_rng_generate() doesn't check the return value. This issue can
    be reproduced by running the following from libkcapi:

        kcapi-rng -b 9000000 > OUTFILE

    The generated OUTFILE will have three huge sections that contain all
    zeros, and this is caused by the code where the test
    'val & PRNG_STATUS_DATA_AVAIL' fails.

    Let's fix this issue by ensuring that qcom_rng_read() always returns
    with a full buffer if the function returns success. Let's also have
    qcom_rng_generate() return the correct value.

    Here's some statistics from the ent project
    (https://www.fourmilab.ch/random/) that shows information about the
    quality of the generated numbers:

        $ ent -c qcom-random-before
        Value Char Occurrences Fraction
          0           606748   0.067416
          1            33104   0.003678
          2            33001   0.003667
        ...
        253   �        32883   0.003654
        254   �        33035   0.003671
        255   �        33239   0.003693

        Total:       9000000   1.000000

        Entropy = 7.811590 bits per byte.

        Optimum compression would reduce the size
        of this 9000000 byte file by 2 percent.

        Chi square distribution for 9000000 samples is 9329962.81, and
        randomly would exceed this value less than 0.01 percent of the
        times.

        Arithmetic mean value of data bytes is 119.3731 (127.5 = random).
        Monte Carlo value for Pi is 3.197293333 (error 1.77 percent).
        Serial correlation coefficient is 0.159130 (totally uncorrelated =
        0.0).

    Without this patch, the results of the chi-square test is 0.01%, and
    the numbers are certainly not random according to ent's project page.
    The results improve with this patch:

        $ ent -c qcom-random-after
        Value Char Occurrences Fraction
          0            35432   0.003937
          1            35127   0.003903
          2            35424   0.003936
        ...
        253   �        35201   0.003911
        254   �        34835   0.003871
        255   �        35368   0.003930

        Total:       9000000   1.000000

        Entropy = 7.999979 bits per byte.

        Optimum compression would reduce the size
        of this 9000000 byte file by 0 percent.

        Chi square distribution for 9000000 samples is 258.77, and randomly
        would exceed this value 42.24 percent of the times.

        Arithmetic mean value of data bytes is 127.5006 (127.5 = random).
        Monte Carlo value for Pi is 3.141277333 (error 0.01 percent).
        Serial correlation coefficient is 0.000468 (totally uncorrelated =
        0.0).

    This change was tested on a Nexus 5 phone (msm8974 SoC).

    Signed-off-by: Brian Masney <bmasney@redhat.com>
    Fixes: ceec5f5b59 ("crypto: qcom-rng - Add Qcom prng driver")
    Cc: stable@vger.kernel.org # 4.19+
    Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
    Reviewed-by: Andrew Halaney <ahalaney@redhat.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Brian Masney <bmasney@redhat.com>
2023-04-10 10:05:10 -04:00
Herbert Xu 0c3dc787a6 crypto: algapi - Remove skbuff.h inclusion
The header file algapi.h includes skbuff.h unnecessarily since
all we need is a forward declaration for struct sk_buff.  This
patch removes that inclusion.

Unfortunately skbuff.h pulls in a lot of things and drivers over
the years have come to rely on it so this patch adds a lot of
missing inclusions that result from this.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-08-20 14:04:28 +10:00
YueHaibing 2229c74079 crypto: qcom-rng - use devm_platform_ioremap_resource() to simplify code
Use devm_platform_ioremap_resource() to simplify the code a bit.
This is detected by coccinelle.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2019-08-09 15:12:03 +10:00
Timur Tabi d96542ac10 crypto: qcom-rng - Add ACPI support
Add support for probing on ACPI systems, with ACPI HID QCOM8160.

On ACPI systems, clocks are always enabled, the PRNG should
already be enabled, and the register region is read-only.
The driver only verifies that the hardware is already
enabled never tries to disable or configure it.

Signed-off-by: Timur Tabi <timur@codeaurora.org>
Tested-by: Jeffrey Hugo <jhugo@codeaurora.org>
[port to crypto API]
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2018-07-27 19:04:32 +08:00
Vinod Koul ba3ab6371c crypto: qcom-rng - Add support for prng-ee
Qcom 8996 and later chips features multiple Execution Environments
(EE) and secure world is typically responsible for configuring the
prng.

Add driver data for qcom,prng as 0 and qcom,prng-ee as 1 and use
that to skip initialization routine.

Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2018-07-27 19:04:32 +08:00
Vinod Koul ceec5f5b59 crypto: qcom-rng - Add Qcom prng driver
This ports the Qcom prng from older hw_random driver.

No change of functionality and move from hw_random to crypto
APIs is done.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2018-07-27 19:04:31 +08:00