From patchwork Sun Jan 27 09:16:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 156687 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp2218837jaa; Sun, 27 Jan 2019 01:17:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN4vmqxjrdu1QdvC1cNglK4PdkNHdqBBGqZczo6NnO7kbMoSBPkCZCvdrfogLessj3h95jHo X-Received: by 2002:a62:18ce:: with SMTP id 197mr18270384pfy.88.1548580640260; Sun, 27 Jan 2019 01:17:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548580640; cv=none; d=google.com; s=arc-20160816; b=SPFydQpafn73bV2aTmAC4Moe07G/PG6JVzmAqw5xpGyPe0xKNGvVGWsXB804LmEoGn cYuOTIGmAzaetiUUSVDKPLUw12FkGziHwBpkoIviU0XO8Z1dtTOEvwStxX1uGytWdhkn 18/0S7sqcLyTu6zgewhom/cJKXkXv4nkCJ5Nx3gj+AYHoyYmU7bGBQWuX3h79+59jhme 3we1yErG5RAKyBwFaL7g1PVtwtdot4xtQdt1k8uTiyXeB3uevOo4u8I8B2fGnn20Yjlj 95ssxi94fsxBX/F4wpfQtApx+3OTAimT+UBWpC9SaKqw0bf/0w9B3in31elI3uwCHBBg H1FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=efcg/0yUjs1pm8V27XtFMWmj9BDdcImS71CJ7F3LlQw=; b=kt1iYWFKx7zjdCkdairPE5moMYxbAmnnL7b5L75dTwD0XwnMfHEVx0dAADzxDs0MXs 0vs98XOvzqFpjsdQIazft8zrVequ77Ux16zL0GQstXuL9UF3EMINDkTh7407mtaKTUxw lCP93DSxRf/z1BxTagj2JbbZg05JMrgM9EzTkVIInKdhrNpAVf0aUeBFKu28kovQvrSp Y6Xe7biJECFmXdwSo1IS2SSy1vRMoyBoEpy9zbqZICbxxcjbE+NauCY1wjBwS89ffOih HCc6KfT6M0CZ88xCYoK8k4DWRSe1ds2me6UiFhnigELSFi0+284uXQ5WBXEdlP1UeC2P 3ZUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jZTaJGSE; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 q19si1274538pfh.138.2019.01.27.01.17.20; Sun, 27 Jan 2019 01:17:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=jZTaJGSE; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 S1726505AbfA0JRS (ORCPT + 3 others); Sun, 27 Jan 2019 04:17:18 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35339 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726419AbfA0JRS (ORCPT ); Sun, 27 Jan 2019 04:17:18 -0500 Received: by mail-wm1-f67.google.com with SMTP id t200so10674535wmt.0 for ; Sun, 27 Jan 2019 01:17:16 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=efcg/0yUjs1pm8V27XtFMWmj9BDdcImS71CJ7F3LlQw=; b=jZTaJGSE32DaGdlVksqdLs+l9lWzTKelFKhE47NUJFPoXkjdPsPo6DGUE64TIEZetr XSFKNQAAmfwO5s1KxoE4qd18G9DYFi7JmR8y1XPMlw/CHKYme1cw66THlcn5u8UvNAwo /N0KCT2VGR/ZpjlUQ4nz5G1Ca0mFsh2vjSGS8= 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:mime-version:content-transfer-encoding; bh=efcg/0yUjs1pm8V27XtFMWmj9BDdcImS71CJ7F3LlQw=; b=IzY1EHWhQiXVXg2mEBpgfBSjPGilcFsOq78Fbloeoh5JcZfXxXGYW4BZzE5Wo4LLyA HftPLwL6G49eyvstel01LOiynx1BXToYULIfltAXh+Up4qp1xI+gt01rqVzwHKHiDbJk FaSaTq6Af6JBVCayY0w1/azbOE+XcBLd+U1TNQwfwqcaDnV3gfK/P65zyJh68YW6l34n JkS4i338oRMUYWVPaT3eJaoNSRFvrdZvyn2LqHo/aGbvsVDQHhM3rYfbLqrNAKqkk6P0 1oEIA2ngv+dmqZxCbxt0MplbOajq1BSa0iXzAN1zNtm5srBM2XAUOCeLN0cw60EIcttn +AXg== X-Gm-Message-State: AJcUukerHsdkvBedD904V4o21qJdYW7kxhIQau9T6t90uOPdCBdQn/kX EwH9GhjEXDHziCe4nxdJ3fP8ME67uktmAg== X-Received: by 2002:a1c:96c5:: with SMTP id y188mr1002476wmd.103.1548580635847; Sun, 27 Jan 2019 01:17:15 -0800 (PST) Received: from sudo.home ([2a01:cb1d:112:6f00:887d:32e9:9391:d3bf]) by smtp.gmail.com with ESMTPSA id o5sm45397013wrw.46.2019.01.27.01.17.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Jan 2019 01:17:14 -0800 (PST) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@kernel.org, Ard Biesheuvel Subject: [PATCH v3 2/4] crypto: arm64/crct10dif - revert to C code for short inputs Date: Sun, 27 Jan 2019 10:16:53 +0100 Message-Id: <20190127091655.6262-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190127091655.6262-1-ard.biesheuvel@linaro.org> References: <20190127091655.6262-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The SIMD routine ported from x86 used to have a special code path for inputs < 16 bytes, which got lost somewhere along the way. Instead, the current glue code aligns the input pointer to 16 bytes, which is not really necessary on this architecture (although it could be beneficial to performance to expose aligned data to the the NEON routine), but this could result in inputs of less than 16 bytes to be passed in. This not only fails the new extended tests that Eric has implemented, it also results in the code reading past the end of the input, which could potentially result in crashes when dealing with less than 16 bytes of input at the end of a page which is followed by an unmapped page. So update the glue code to only invoke the NEON routine if the input is at least 16 bytes. Reported-by: Eric Biggers Reviewed-by: Eric Biggers Fixes: 6ef5737f3931 ("crypto: arm64/crct10dif - port x86 SSE implementation to arm64") Cc: # v4.10+ Signed-off-by: Ard Biesheuvel --- arch/arm64/crypto/crct10dif-ce-glue.c | 25 +++++--------------- 1 file changed, 6 insertions(+), 19 deletions(-) -- 2.20.1 diff --git a/arch/arm64/crypto/crct10dif-ce-glue.c b/arch/arm64/crypto/crct10dif-ce-glue.c index b461d62023f2..567c24f3d224 100644 --- a/arch/arm64/crypto/crct10dif-ce-glue.c +++ b/arch/arm64/crypto/crct10dif-ce-glue.c @@ -39,26 +39,13 @@ static int crct10dif_update(struct shash_desc *desc, const u8 *data, unsigned int length) { u16 *crc = shash_desc_ctx(desc); - unsigned int l; - if (unlikely((u64)data % CRC_T10DIF_PMULL_CHUNK_SIZE)) { - l = min_t(u32, length, CRC_T10DIF_PMULL_CHUNK_SIZE - - ((u64)data % CRC_T10DIF_PMULL_CHUNK_SIZE)); - - *crc = crc_t10dif_generic(*crc, data, l); - - length -= l; - data += l; - } - - if (length > 0) { - if (may_use_simd()) { - kernel_neon_begin(); - *crc = crc_t10dif_pmull(*crc, data, length); - kernel_neon_end(); - } else { - *crc = crc_t10dif_generic(*crc, data, length); - } + if (length >= CRC_T10DIF_PMULL_CHUNK_SIZE && may_use_simd()) { + kernel_neon_begin(); + *crc = crc_t10dif_pmull(*crc, data, length); + kernel_neon_end(); + } else { + *crc = crc_t10dif_generic(*crc, data, length); } return 0;