Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp152729imm; Fri, 5 Oct 2018 01:14:44 -0700 (PDT) X-Google-Smtp-Source: ACcGV62mebL5vNmeKdBEHJHHHgp1Nv2sU4AaoETCVb8xv06MnTf3vqsLPlQKcQg7H2lgkuD54bOu X-Received: by 2002:a63:9612:: with SMTP id c18-v6mr8846744pge.21.1538727284005; Fri, 05 Oct 2018 01:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538727283; cv=none; d=google.com; s=arc-20160816; b=EpunqQVwwgX3FgWoSEbC5xcARysriOG4tJukg4+OM0fmHlY1IZaB4OYwXfBFGK+w6G DHspi5WTgW2j5oQ4oUQz+u2VCwn1HXyM0rgYyma6Kj7Rnx4p55j7u+zBQbJ8GiCjNnjO p1N3125C9/pdFzU2Re7L8e618UQKf3+9EpMdjCxKikmEdR2QLsLNqPVgjyWmDYuBhEYy /PPnJt4Xt1OhpY/8fp0AmpW4jI5btd2huhDd3i71dWbw/aZCpeJddiep6ZGF2QfE8dB1 YasZGh0Sq92ZDQtmaG0BrybpQj4jjX9jeXYRkSB0tMHRUixdj/RUca2vYvW+tcFCEEcl c6og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=W4XNrL/HVz1JFq0EC5F2/AltrGoh1ZboRDNEWdxrwVU=; b=k3XcmP98MZGWY6YJ+P1+UFgY2tGq+xwXG+MC/b2Zu5mXLd157GEZiEnnlirqbz7mWq SaqhEEHAEdwU1sAA21m9lZESFPoV9MkBj8QoVwGKetvO3WVMM3SPrCMiVH9XT8MJKCun 3JsrmXqd4Wv4Gk+sifvAjhRFt6C2l0WEO8NHMTsq2QePi+vBpzuXDb1G+3nEM+ME3ALC T3I9NkL4ph1euyi4QLMS2S7GOieDmbG2ooVD3JZx7j6HQaTHiwfh+rYwjBSGlFwoBp+X Ze21a4r9SHXr4/IDZB/ix+LPa4P8uvDgqUYGH/h2C1X9dL8YHiSiBzdvP+Q83MwInHiJ WoZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jnwyIatH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p66-v6si8006765pfp.237.2018.10.05.01.14.28; Fri, 05 Oct 2018 01:14:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jnwyIatH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728570AbeJEPL0 (ORCPT + 99 others); Fri, 5 Oct 2018 11:11:26 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46040 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728498AbeJEPL0 (ORCPT ); Fri, 5 Oct 2018 11:11:26 -0400 Received: by mail-wr1-f67.google.com with SMTP id q5-v6so12553743wrw.12 for ; Fri, 05 Oct 2018 01:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=W4XNrL/HVz1JFq0EC5F2/AltrGoh1ZboRDNEWdxrwVU=; b=jnwyIatHaYA2n3cTx6guJoyPbr+L3fOA9AOBqx0Y2oMaeF96hobAONVdvSUned1y3s StByQ8z+FybmB6IbckDsErTVElZPazLc7iw2ihFw0/S6pZiXC3Q6LPbxewFO5smDCYZf uOH6PjRG3nJAjWfuYmqeU3mfvrJ5BOnGliwTE= 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=W4XNrL/HVz1JFq0EC5F2/AltrGoh1ZboRDNEWdxrwVU=; b=OIf9aQMLs19DcnnidxZLwv6T347RFRoG/dXws7ToGCpsQuLOTufIvcJBq25vFubTpR ZIHXHXs4DWI9FAUZ2Igw5W9+hj2R0Vb19jyu5e0YYv2wB+TSyltgos6IBRBNshCwiJ7J RPCTEsDBD7Q22f8+rOfU+u7D+hf0jivHi+iTjdH7dUiWSONHuZe7x9XC72rQPOu2Qwd8 qb9ARxsI1XPqBTYw+sHmSTmheMOsJD3dMt77IC116tqOpn+CVVubRY/hv19CJHNUc3FH cvqTK0kxyRqJ/enswfsk8WrLj8vGjX7bq6zNLXfrMUE46M7xRr+eRUjPcnDidXO/zF5f S8qg== X-Gm-Message-State: ABuFfoj9sFlN0Etl3LbvdhiSS7IwyDAPKV19SPoPQT2nes31YYugfcPi KCZJ0hlF00HzKtmW1PuRrxlvNVRRkj8= X-Received: by 2002:a5d:40cd:: with SMTP id b13-v6mr7838866wrq.133.1538727228189; Fri, 05 Oct 2018 01:13:48 -0700 (PDT) Received: from localhost.localdomain ([2a01:cb1d:112:6f00:697e:67d9:a05d:22c7]) by smtp.gmail.com with ESMTPSA id t4-v6sm6565620wrb.45.2018.10.05.01.13.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Oct 2018 01:13:47 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , "Jason A . Donenfeld" , Eric Biggers , Samuel Neves , Andy Lutomirski , Arnd Bergmann , Herbert Xu , "David S. Miller" , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Thomas Gleixner , Ingo Molnar , Kees Cook , "Martin K. Petersen" , Greg Kroah-Hartman , Andrew Morton , Richard Weinberger , Peter Zijlstra , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org Subject: [RFC PATCH 6/9] crypto: crc-t10dif/arm - move PMULL based code into core library Date: Fri, 5 Oct 2018 10:13:30 +0200 Message-Id: <20181005081333.15018-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181005081333.15018-1-ard.biesheuvel@linaro.org> References: <20181005081333.15018-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the PMULL based routines out of the crypto API into the core CRC-T10DIF library. Signed-off-by: Ard Biesheuvel --- arch/arm/crypto/crct10dif-ce-glue.c | 78 ++++++-------------- 1 file changed, 22 insertions(+), 56 deletions(-) diff --git a/arch/arm/crypto/crct10dif-ce-glue.c b/arch/arm/crypto/crct10dif-ce-glue.c index d428355cf38d..2020d9c29ff1 100644 --- a/arch/arm/crypto/crct10dif-ce-glue.c +++ b/arch/arm/crypto/crct10dif-ce-glue.c @@ -10,12 +10,11 @@ #include #include +#include #include #include #include -#include - #include #include @@ -23,74 +22,42 @@ asmlinkage u16 crc_t10dif_pmull(u16 init_crc, const u8 buf[], u32 len); -static int crct10dif_init(struct shash_desc *desc) +static __u16 crct10dif_update_arm(__u16 crc, const u8 *data, unsigned int length) { - u16 *crc = shash_desc_ctx(desc); - - *crc = 0; - return 0; -} - -static int crct10dif_update(struct shash_desc *desc, const u8 *data, - unsigned int length) -{ - u16 *crc = shash_desc_ctx(desc); unsigned int l; - if (!may_use_simd()) { - *crc = crc_t10dif_generic(*crc, data, length); - } else { - if (unlikely((u32)data % CRC_T10DIF_PMULL_CHUNK_SIZE)) { - l = min_t(u32, length, CRC_T10DIF_PMULL_CHUNK_SIZE - - ((u32)data % CRC_T10DIF_PMULL_CHUNK_SIZE)); + if (!may_use_simd()) + return crc_t10dif_generic(crc, data, length); - *crc = crc_t10dif_generic(*crc, data, l); + if (unlikely((u32)data % CRC_T10DIF_PMULL_CHUNK_SIZE)) { + l = min_t(u32, length, CRC_T10DIF_PMULL_CHUNK_SIZE - + ((u32)data % CRC_T10DIF_PMULL_CHUNK_SIZE)); - length -= l; - data += l; - } - if (length > 0) { - kernel_neon_begin(); - *crc = crc_t10dif_pmull(*crc, data, length); - kernel_neon_end(); - } - } - return 0; -} + crc = crc_t10dif_generic(crc, data, l); -static int crct10dif_final(struct shash_desc *desc, u8 *out) -{ - u16 *crc = shash_desc_ctx(desc); - - *(u16 *)out = *crc; - return 0; + length -= l; + data += l; + } + if (length > 0) { + kernel_neon_begin(); + crc = crc_t10dif_pmull(crc, data, length); + kernel_neon_end(); + } + return crc; } -static struct shash_alg crc_t10dif_alg = { - .digestsize = CRC_T10DIF_DIGEST_SIZE, - .init = crct10dif_init, - .update = crct10dif_update, - .final = crct10dif_final, - .descsize = CRC_T10DIF_DIGEST_SIZE, - - .base.cra_name = "crct10dif", - .base.cra_driver_name = "crct10dif-arm-ce", - .base.cra_priority = 200, - .base.cra_blocksize = CRC_T10DIF_BLOCK_SIZE, - .base.cra_module = THIS_MODULE, -}; - static int __init crc_t10dif_mod_init(void) { - if (!(elf_hwcap2 & HWCAP2_PMULL)) - return -ENODEV; + SET_FFP(crc_t10dif_update_arch, crct10dif_update_arm); - return crypto_register_shash(&crc_t10dif_alg); + return 0; } static void __exit crc_t10dif_mod_exit(void) { - crypto_unregister_shash(&crc_t10dif_alg); + RESET_FFP(crc_t10dif_update_arch); + /* wait for all users to switch back to the old version */ + synchronize_rcu(); } module_init(crc_t10dif_mod_init); @@ -98,4 +65,3 @@ module_exit(crc_t10dif_mod_exit); MODULE_AUTHOR("Ard Biesheuvel "); MODULE_LICENSE("GPL v2"); -MODULE_ALIAS_CRYPTO("crct10dif"); -- 2.11.0