linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Can crypto API provide information about hw acceleration?
@ 2019-05-14 16:33 David Sterba
  2019-05-14 21:34 ` Eric Biggers
  0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2019-05-14 16:33 UTC (permalink / raw)
  To: linux-crypto; +Cc: linux-kernel

Hi,

Q: is there a way to query the crypto layer whether a given algorithm
(digest, crypto) is accelerated by the driver?

This information can be used to decide if eg. a checksum should can be
calculated right away or offloaded to a thread. This is done in btrfs,
(fs/btrfs/disk-io.c:check_async_write).

At this moment it contains a static check for a cpu feature, and only
for x86. I briefly searched the arch/ directory for implementations of
crc32c that possibly use hw aid and there are several of them. Adding a
static check a-la x86 for the other architectures (arm, ppc, mips,
sparc, s390) is wrong, so I'm looking for a clean solution.

The struct shash_alg definition of the algorithms does not say anything
about the acceleration. The closest thing is the cra_priority, but I
don't know if this is reliable information. The default implementations
seem to have 100, and acceleated 200 or 300.

This would be probably sufficient, but I'd like a confirmation from
crypto people.

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Can crypto API provide information about hw acceleration?
  2019-05-14 16:33 Can crypto API provide information about hw acceleration? David Sterba
@ 2019-05-14 21:34 ` Eric Biggers
  2019-05-15 12:55   ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2019-05-14 21:34 UTC (permalink / raw)
  To: dsterba, linux-crypto, linux-kernel

On Tue, May 14, 2019 at 06:33:48PM +0200, David Sterba wrote:
> Hi,
> 
> Q: is there a way to query the crypto layer whether a given algorithm
> (digest, crypto) is accelerated by the driver?
> 
> This information can be used to decide if eg. a checksum should can be
> calculated right away or offloaded to a thread. This is done in btrfs,
> (fs/btrfs/disk-io.c:check_async_write).
> 
> At this moment it contains a static check for a cpu feature, and only
> for x86. I briefly searched the arch/ directory for implementations of
> crc32c that possibly use hw aid and there are several of them. Adding a
> static check a-la x86 for the other architectures (arm, ppc, mips,
> sparc, s390) is wrong, so I'm looking for a clean solution.
> 
> The struct shash_alg definition of the algorithms does not say anything
> about the acceleration. The closest thing is the cra_priority, but I
> don't know if this is reliable information. The default implementations
> seem to have 100, and acceleated 200 or 300.
> 
> This would be probably sufficient, but I'd like a confirmation from
> crypto people.
> 

There's only one default implementation of crc32c, not multiple, and it has
priority 100.  All other crc32c implementations have priority > 100.  So yes,
you can check the priority (which would require adding a function to
lib/libcrc32c.c to get it).  Alternatively you could check whether the driver
name is "crc32c-generic" or not.

- Eric

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Can crypto API provide information about hw acceleration?
  2019-05-14 21:34 ` Eric Biggers
@ 2019-05-15 12:55   ` David Sterba
  0 siblings, 0 replies; 3+ messages in thread
From: David Sterba @ 2019-05-15 12:55 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-crypto, linux-kernel

On Tue, May 14, 2019 at 02:34:10PM -0700, Eric Biggers wrote:
> On Tue, May 14, 2019 at 06:33:48PM +0200, David Sterba wrote:
> > Hi,
> > 
> > Q: is there a way to query the crypto layer whether a given algorithm
> > (digest, crypto) is accelerated by the driver?
> > 
> > This information can be used to decide if eg. a checksum should can be
> > calculated right away or offloaded to a thread. This is done in btrfs,
> > (fs/btrfs/disk-io.c:check_async_write).
> > 
> > At this moment it contains a static check for a cpu feature, and only
> > for x86. I briefly searched the arch/ directory for implementations of
> > crc32c that possibly use hw aid and there are several of them. Adding a
> > static check a-la x86 for the other architectures (arm, ppc, mips,
> > sparc, s390) is wrong, so I'm looking for a clean solution.
> > 
> > The struct shash_alg definition of the algorithms does not say anything
> > about the acceleration. The closest thing is the cra_priority, but I
> > don't know if this is reliable information. The default implementations
> > seem to have 100, and acceleated 200 or 300.
> > 
> > This would be probably sufficient, but I'd like a confirmation from
> > crypto people.
> > 
> 
> There's only one default implementation of crc32c, not multiple, and it has
> priority 100.  All other crc32c implementations have priority > 100.  So yes,
> you can check the priority (which would require adding a function to
> lib/libcrc32c.c to get it).  Alternatively you could check whether the driver
> name is "crc32c-generic" or not.

Thanks, the driver name check seems to be ok for my needs. At mount time
the struct crypto_shash is initialized and this provides the driver
name, then a bit is set whether it's generic or not and later used to
decide whether to offload.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-15 12:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-14 16:33 Can crypto API provide information about hw acceleration? David Sterba
2019-05-14 21:34 ` Eric Biggers
2019-05-15 12:55   ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).