All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tim Chen <tim.c.chen@linux.intel.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
	"David S.Miller" <davem@davemloft.net>,
	Stephan Mueller <smueller@chronox.de>,
	Chandramouli Narayanan <mouli_7982@yahoo.com>,
	Vinodh Gopal <vinodh.gopal@intel.com>,
	James Guilford <james.guilford@intel.com>,
	Wajdi Feghali <wajdi.k.feghali@intel.com>,
	Jussi Kivilinna <jussi.kivilinna@iki.fi>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 5/5] crypto: AES CBC multi-buffer glue code
Date: Tue, 24 Nov 2015 10:30:06 -0800	[thread overview]
Message-ID: <1448389806.4933.112.camel@schen9-desk2.jf.intel.com> (raw)
In-Reply-To: <20151124094710.GA32679@gondor.apana.org.au>

On Tue, 2015-11-24 at 17:47 +0800, Herbert Xu wrote:
> On Thu, Nov 19, 2015 at 02:15:40PM -0800, Tim Chen wrote:
> > 
> > This patch introduces the multi-buffer job manager which is responsible
> > for submitting scatter-gather buffers from several AES CBC jobs
> > to the multi-buffer algorithm. The glue code interfaces with the
> > underlying algorithm that handles 8 data streams of AES CBC encryption
> > in parallel. AES key expansion and CBC decryption requests are performed
> > in a manner similar to the existing AESNI Intel glue driver.
> 
> The rest of this series all look good.
> 
> > +static int mb_aes_cbc_decrypt(struct blkcipher_desc *desc,
> > +			      struct scatterlist *dst, struct scatterlist *src,
> > +			      unsigned int nbytes)
> > +{
> > +	struct crypto_aes_ctx *aesni_ctx;
> > +	struct mcryptd_blkcipher_request_ctx *rctx =
> > +		container_of(desc, struct mcryptd_blkcipher_request_ctx, desc);
> > +	struct ablkcipher_request *req;
> > +	struct blkcipher_walk walk;
> > +	bool is_mcryptd_req;
> > +	int err;
> > +
> > +	/* note here whether it is mcryptd req */
> > +	is_mcryptd_req = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
> > +	req = cast_mcryptd_ctx_to_req(rctx);
> > +	aesni_ctx = aes_ctx(crypto_blkcipher_ctx(desc->tfm));
> > +
> > +	blkcipher_walk_init(&walk, dst, src, nbytes);
> > +	err = blkcipher_walk_virt(desc, &walk);
> > +	desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
> > +
> > +	kernel_fpu_begin();
> > +	while ((nbytes = walk.nbytes)) {
> > +		aesni_cbc_dec(aesni_ctx, walk.dst.virt.addr, walk.src.virt.addr,
> > +			      nbytes & AES_BLOCK_MASK, walk.iv);
> > +		nbytes &= AES_BLOCK_SIZE - 1;
> > +		err = blkcipher_walk_done(desc, &walk, nbytes);
> > +	}
> > +	kernel_fpu_end();
> > +	if (!is_mcryptd_req) {
> > +		/* synchronous request */
> > +		return err;
> > +	}
> > +
> > +	/* from mcryptd, we need to callback */
> > +	if (irqs_disabled())
> > +		rctx->complete(&req->base, err);
> 
> I really hate this bit though.  I know that you're doing the same
> thing in sha-mb but relying on blkcipher_desc to contain extra
> data given by the caller is not nice.
> 
> So the issue here seems to be that you're using the blkcipher
> interface which has no completion mechanism.  What if you used
> ablkcipher here instead, would you still need to play nasty games
> such as
> this?

I have considered using ablkcipher walk always 
by invoking mb_aes_cbc_decrypt only through mcryptd, 
and allowing me to cast things back to an ablkcipher request
and always do ablkcipher walk here. 
But that will incur extra latency overhead
through mcryptd.

On the decrypt path, we don't need to use multi-buffer algorithm
as aes-cbc decrypt can be parallelized inherently on a single
request.  So most of the time the outer layer algorithm
cbc_mb_async_ablk_decrypt can bypass mcryptd and
invoke mb_aes_cbc_decrypt synchronously
to do aes_cbc_dec when fpu is available.
This avoids the overhead of going through mcryptd.  Hence
the use of blkcipher on the inner layer.  For the mcryptd
path, we will complete a decrypt request in one shot so
blkcipher usage should be fine.

Thanksgiving holidays in US coming up so my response may
be a bit slow for the rest of the week.

Thanks.

Tim

  reply	other threads:[~2015-11-24 18:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1447977406.git.tim.c.chen@linux.intel.com>
2015-11-19 22:14 ` [PATCH v3 0/5] crypto: x86 AES-CBC encryption with multibuffer Tim Chen
2015-11-19 22:14 ` [PATCH v3 1/5] crypto: Multi-buffer encryptioin infrastructure support Tim Chen
2015-11-19 22:15 ` [PATCH v3 2/5] crypto: AES CBC multi-buffer data structures Tim Chen
2015-11-19 22:15 ` [PATCH v3 3/5] crypto: AES CBC multi-buffer scheduler Tim Chen
2015-11-19 22:15 ` [PATCH v3 4/5] crypto: AES CBC by8 encryption Tim Chen
2015-11-19 22:15 ` [PATCH v3 5/5] crypto: AES CBC multi-buffer glue code Tim Chen
2015-11-24  9:47   ` Herbert Xu
2015-11-24 18:30     ` Tim Chen [this message]
2015-11-26  8:49       ` Herbert Xu
2015-12-01 17:19         ` Tim Chen
2015-12-02 20:03           ` Tim Chen

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=1448389806.4933.112.camel@schen9-desk2.jf.intel.com \
    --to=tim.c.chen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=james.guilford@intel.com \
    --cc=jussi.kivilinna@iki.fi \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mouli_7982@yahoo.com \
    --cc=smueller@chronox.de \
    --cc=vinodh.gopal@intel.com \
    --cc=wajdi.k.feghali@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.