• Eric Biggers's avatar
    fsverity: use shash API instead of ahash API · 8fcd94ad
    Eric Biggers authored
    The "ahash" API, like the other scatterlist-based crypto APIs such as
    "skcipher", comes with some well-known limitations.  First, it can't
    easily be used with vmalloc addresses.  Second, the request struct can't
    be allocated on the stack.  This adds complexity and a possible failure
    point that needs to be worked around, e.g. using a mempool.
    
    The only benefit of ahash over "shash" is that ahash is needed to access
    traditional memory-to-memory crypto accelerators, i.e. drivers/crypto/.
    However, this style of crypto acceleration has largely fallen out of
    favor and been superseded by CPU-based acceleration or inline crypto
    engines.  Also, ahash needs to be used asynchronously to take full
    advantage of such hardware, but fs/verity/ has never done this.
    
    On all systems that aren't actually using one of these ahash-only crypto
    accelerators, ahash just adds unnecessary overhead as it sits between
    the user and the underlying shash algorithms.
    
    Also, XFS is planned to cache fsverity Merkle tree blocks in the
    existing XFS buffer cache.  As a result, it will be possible for a
    single Merkle tree block to be split across discontiguous pages
    (https://lore.kernel.org/r/20230405233753.GU3223426@dread.disaster.area).
    This data will need to be hashed.  It is easiest to work with a vmapped
    address in this case.  However, ahash is incompatible with this.
    
    Therefore, let's convert fs/verity/ from ahash to shash.  This
    simplifies the code, and it should also slightly improve performance for
    everyone who wasn't actually using one of these ahash-only crypto
    accelerators, i.e. almost everyone (or maybe even everyone)!
    
    Link: https://lore.kernel.org/r/20230516052306.99600-1-ebiggers@kernel.orgReviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    Acked-by: default avatarArd Biesheuvel <ardb@kernel.org>
    Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
    8fcd94ad
fsverity_private.h 4.89 KB