From patchwork Wed Mar 15 12:37:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 9625505 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 64003604A9 for ; Wed, 15 Mar 2017 12:40:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A88228617 for ; Wed, 15 Mar 2017 12:40:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F6E52861A; Wed, 15 Mar 2017 12:40:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCE2828617 for ; Wed, 15 Mar 2017 12:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751642AbdCOMit (ORCPT ); Wed, 15 Mar 2017 08:38:49 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:36626 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751111AbdCOMih (ORCPT ); Wed, 15 Mar 2017 08:38:37 -0400 Received: by mail-io0-f196.google.com with SMTP id 68so2825882ioh.3 for ; Wed, 15 Mar 2017 05:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ciz95vT6xHlrV2eCHaFqpOaw/uGpd6Ejts9FAw/yUYI=; b=oZIQrdm9zyaxoFfc1MlMwLlvqTxCau5iZ/Pt2TSVxUAZFQX/P81AFD0AW2hkXcrzxK 8A7tMolvr7kD1Bfotl9G7PrNJg5xk8HyMasQXcSMEvJ1WTzLxjwfSZJZOZOJMgYMWTwZ NUS4DvKDHV72VZ5JstPEcUH3Juu11GrB4oDjM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ciz95vT6xHlrV2eCHaFqpOaw/uGpd6Ejts9FAw/yUYI=; b=QL7x6yU35rDOdsUF+xIlLk7lGQNZkDzL8fVNA15LN65nBCIPZ2AZ0ylgKi0NDh5wzy +V+hgc0yKepgUfZpKf/khwYFC3SQIKJe4HMQR2oZZ1shN+EwS0ODr3vvD1vPGL7yo2oA nMk8Q87/UI2Yedra5i8z4uv+I1yhjfCf1j8P7A1Z+7qwKXlOBUklPUV1K5Na7IgU7/o/ DxCMYqccW0rRxNC3b5eKgL7G60ujbN5m3N810b4oVvTCLfnwBnGkzivcIcEEtleCYkxm yQZD5Ke4V5y2iSHi42qqMvx3A47HZxLDIYDzwgRwBGZLbi0di+wqv7F7bNbMLv7tW0hp ydhw== X-Gm-Message-State: AFeK/H0z9iln5hn+3L/Jk7ttjycTsDTo3KyPdJzgTOUVkezSfDhjY/aRjYVbNKmoPoFSZg== X-Received: by 10.107.19.97 with SMTP id b94mr4679533ioj.93.1489581516081; Wed, 15 Mar 2017 05:38:36 -0700 (PDT) Received: from connectitude.ibm.com (ppp121-45-212-55.lns20.cbr1.internode.on.net. [121.45.212.55]) by smtp.gmail.com with ESMTPSA id l5sm103945ita.13.2017.03.15.05.38.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Mar 2017 05:38:35 -0700 (PDT) From: Daniel Axtens To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org Cc: anton@samba.org, Daniel Axtens Subject: [PATCH 4/4] crypto: powerpc - Stress test for vpmsum implementations Date: Wed, 15 Mar 2017 23:37:37 +1100 Message-Id: <20170315123737.20234-4-dja@axtens.net> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170315123737.20234-1-dja@axtens.net> References: <20170315123737.20234-1-dja@axtens.net> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP vpmsum implementations often don't kick in for short test vectors. This is a simple test module that does a configurable number of random tests, each up to 64kB and each with random offsets. Both CRC-T10DIF and CRC32C are tested. Cc: Anton Blanchard Signed-off-by: Daniel Axtens --- Not super fussy about the inclusion or otherwise of this - it was very useful for debugging my code, and more tests are good :) Also, I originally found the bug in Anton's CRC32c using this. Tests pass on both BE 64 bit and LE 64 bit. --- arch/powerpc/crypto/Makefile | 1 + arch/powerpc/crypto/crc-vpmsum_test.c | 137 ++++++++++++++++++++++++++++++++++ crypto/Kconfig | 8 ++ 3 files changed, 146 insertions(+) create mode 100644 arch/powerpc/crypto/crc-vpmsum_test.c diff --git a/arch/powerpc/crypto/Makefile b/arch/powerpc/crypto/Makefile index e66aaf19764d..67eca3af9fc7 100644 --- a/arch/powerpc/crypto/Makefile +++ b/arch/powerpc/crypto/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_CRYPTO_SHA1_PPC_SPE) += sha1-ppc-spe.o obj-$(CONFIG_CRYPTO_SHA256_PPC_SPE) += sha256-ppc-spe.o obj-$(CONFIG_CRYPTO_CRC32C_VPMSUM) += crc32c-vpmsum.o obj-$(CONFIG_CRYPTO_CRCT10DIF_VPMSUM) += crct10dif-vpmsum.o +obj-$(CONFIG_CRYPTO_VPMSUM_TESTER) += crc-vpmsum_test.o aes-ppc-spe-y := aes-spe-core.o aes-spe-keys.o aes-tab-4k.o aes-spe-modes.o aes-spe-glue.o md5-ppc-y := md5-asm.o md5-glue.o diff --git a/arch/powerpc/crypto/crc-vpmsum_test.c b/arch/powerpc/crypto/crc-vpmsum_test.c new file mode 100644 index 000000000000..d58242557f33 --- /dev/null +++ b/arch/powerpc/crypto/crc-vpmsum_test.c @@ -0,0 +1,137 @@ +/* + * CRC vpmsum tester + * Copyright 2017 Daniel Axtens, IBM Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static unsigned long iterations = 10000; + +#define MAX_CRC_LENGTH 65535 + + +static int __init crc_test_init(void) +{ + u16 crc16 = 0, verify16 = 0; + u32 crc32 = 0, verify32 = 0; + __le32 verify32le = 0; + unsigned char *data; + unsigned long i; + int ret; + + struct crypto_shash *crct10dif_tfm; + struct crypto_shash *crc32c_tfm; + + if (!cpu_has_feature(CPU_FTR_ARCH_207S)) + return -ENODEV; + + data = kmalloc(MAX_CRC_LENGTH, GFP_KERNEL); + if (!data) + return -ENOMEM; + + crct10dif_tfm = crypto_alloc_shash("crct10dif", 0, 0); + + if (IS_ERR(crct10dif_tfm)) { + pr_err("Error allocating crc-t10dif\n"); + goto free_buf; + } + + crc32c_tfm = crypto_alloc_shash("crc32c", 0, 0); + + if (IS_ERR(crc32c_tfm)) { + pr_err("Error allocating crc32c\n"); + goto free_16; + } + + do { + SHASH_DESC_ON_STACK(crct10dif_shash, crct10dif_tfm); + SHASH_DESC_ON_STACK(crc32c_shash, crc32c_tfm); + + crct10dif_shash->tfm = crct10dif_tfm; + ret = crypto_shash_init(crct10dif_shash); + + if (ret) { + pr_err("Error initing crc-t10dif\n"); + goto free_32; + } + + + crc32c_shash->tfm = crc32c_tfm; + ret = crypto_shash_init(crc32c_shash); + + if (ret) { + pr_err("Error initing crc32c\n"); + goto free_32; + } + + pr_info("crc-vpmsum_test begins, %lu iterations\n", iterations); + for (i=0; i"); +MODULE_DESCRIPTION("Vector polynomial multiply-sum CRC tester"); +MODULE_LICENSE("GPL"); diff --git a/crypto/Kconfig b/crypto/Kconfig index 9cf63dd84364..6854c1fe54b7 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -522,6 +522,14 @@ config CRYPTO_CRCT10DIF_VPMSUM multiply-sum (vpmsum) instructions, introduced in POWER8. Enable on POWER8 and newer processors for improved performance. +config CRYPTO_VPMSUM_TESTER + tristate "Powerpc64 vpmsum hardware acceleration tester" + depends on CRYPTO_CRCT10DIF_VPMSUM && CRYPTO_CRC32C_VPMSUM + help + Stress test for CRC32c and CRC-T10DIF algorithms implemented with + POWER8 vpmsum instructions. + Unless you are testing these algorithms, you don't need this. + config CRYPTO_GHASH tristate "GHASH digest algorithm" select CRYPTO_GF128MUL