From: Stephan Mueller <smueller@chronox.de>
To: Vinod <vkoul@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
Stanimir Varbanov <stanimir.varbanov@linaro.org>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
Matt Mackall <mpm@selenic.com>, Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH 3/3] hwrng: msm - Add support for prng v2
Date: Wed, 27 Jun 2018 08:43:16 +0200 [thread overview]
Message-ID: <170012246.0U45yCEtus@tauon.chronox.de> (raw)
In-Reply-To: <20180627062701.GF22377@vkoul-mobl>
Am Mittwoch, 27. Juni 2018, 08:27:01 CEST schrieb Vinod:
Hi Vinod,
> Hi Stephan,
>
> Thanks for the answers, they are helpful.
>
> On 27-06-18, 08:13, Stephan Mueller wrote:
> > > I have two follow up question on crypto:
> > > - If there a way to avoid using a global variable in driver to hold the
> > >
> > > pointer for driver memory? Looks like exynos driver does that.
> > >
> > > I understand that the crypto callback don't provide driver context as
> > > they copy the data structures passed in registration API, but a
> > > simpler
> > > way to get driver context would be desirable.
> >
> > Sure the kernel crypto API can and has to maintain a per-instance data
> > structure.
> >
> > See the crypto/drbg.c for instance.
> >
> > static int drbg_kcapi_random(struct crypto_rng *tfm,
> >
> > const u8 *src, unsigned int slen,
> > u8 *dst, unsigned int dlen)
> >
> > {
> >
> > struct drbg_state *drbg = crypto_rng_ctx(tfm);
> >
> > static int drbg_kcapi_seed(struct crypto_rng *tfm,
> >
> > const u8 *seed, unsigned int slen)
> >
> > {
> >
> > struct drbg_state *drbg = crypto_rng_ctx(tfm);
> >
> > The key is:
> > alg->base.cra_ctxsize = sizeof(struct drbg_state);
> >
> > during initialization since the kernel crypto API allocates that buffer
> > for
> > you and releases it during deallocation.
>
> The difference here is that memory is allocated by crypto and driver has
> no way to pass "it's" own data while doing registration. Ideally
> registration should accept a pointer/long and pass that back on a
> callbacks
Looking at your code, it seems you do what makes sense: there is only one
instance of the driver, if at all. Thus, having qcom_rng_dev as static makes
sense. The kernel crypto API allows arbitrary instances of the RNG as well as
frequent allocations and deallocations. And this is why there must be a
disconnect between the one hardware-resource driver-instance data structure
and the (potentially) multiple crypto API RNG instances and their data
structures.
>
> Currently am doing bunch of initialization in .probe (platform driver)
> and I think recommendation would be to move that to .cra_init, which seem
> plausible but I don't have pdev to read hw_resource etc.. so would still
> need to get that.
It seems that your allocation during probe relates to the hardware resource
where you only have one in the system. Thus, doing the allocation here makes
sense. And, you do not want to perform probe or such resource allocation once
per crypto API RNG instance allocation. As said, there can be multiple or even
they can be allocated and deallocated frequently. This in particular applies
if your driver's "stdrng" has the highest prio which means that it will be
allocated and deallocated frequently.
Ciao
Stephan
next prev parent reply other threads:[~2018-06-27 6:43 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-18 14:12 [PATCH 0/3]: hwrng: Add support for qcpm v2 hwrng Vinod Koul
2018-06-18 14:12 ` [PATCH 1/3] hwrng: msm - Move hwrng to a table Vinod Koul
2018-06-18 15:58 ` Stephen Boyd
2018-06-18 16:54 ` Vinod
2018-06-18 14:12 ` [PATCH 2/3] dt-bindings: rng: Add new compatible qcom,prng-v2 Vinod Koul
2018-06-18 14:12 ` [PATCH 3/3] hwrng: msm - Add support for prng v2 Vinod Koul
2018-06-18 18:21 ` Bjorn Andersson
2018-06-18 20:24 ` Stephen Boyd
2018-06-19 4:06 ` Vinod
2018-06-19 4:04 ` Vinod
2018-06-19 14:28 ` Herbert Xu
2018-06-20 5:32 ` Vinod
2018-06-20 14:37 ` Herbert Xu
2018-06-20 17:45 ` PrasannaKumar Muralidharan
2018-06-21 4:17 ` Vinod
2018-06-21 9:56 ` Stanimir Varbanov
2018-06-21 10:15 ` Herbert Xu
2018-06-21 11:27 ` Stanimir Varbanov
2018-06-21 11:53 ` Herbert Xu
2018-06-22 8:27 ` Stanimir Varbanov
2018-06-22 14:38 ` Herbert Xu
2018-06-22 14:48 ` Vinod
2018-06-22 14:50 ` Herbert Xu
[not found] ` <70ED61EB-BD3E-48D1-8B4D-D7835494C035@chronox.de>
2018-06-27 5:08 ` Vinod
2018-06-27 6:13 ` Stephan Mueller
2018-06-27 6:27 ` Vinod
2018-06-27 6:43 ` Stephan Mueller [this message]
2018-06-27 7:01 ` Vinod
2018-06-27 7:51 ` Stephan Mueller
2018-06-22 15:33 ` Stanimir Varbanov
2018-06-28 22:04 ` Timur Tabi
2018-06-29 8:37 ` Vinod
2018-07-01 6:27 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=170012246.0U45yCEtus@tauon.chronox.de \
--to=smueller@chronox.de \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpm@selenic.com \
--cc=stanimir.varbanov@linaro.org \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox